forked from qt-creator/qt-creator
QmlDesigner.Navigator: Icons and error message on invalid id
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
#include <invalididexception.h>
|
#include <invalididexception.h>
|
||||||
|
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -272,8 +273,14 @@ void NavigatorTreeModel::handleChangedItem(QStandardItem *item)
|
|||||||
try {
|
try {
|
||||||
if (ModelNode::isValidId(item->text()))
|
if (ModelNode::isValidId(item->text()))
|
||||||
node.setId(item->text());
|
node.setId(item->text());
|
||||||
else
|
else {
|
||||||
|
QMessageBox errorDialog;
|
||||||
|
errorDialog.setModal(true);
|
||||||
|
errorDialog.setText(tr("Invalid id.\nOnly alphanumeric characters and underscore allowed.\nIds must begin with a lowercase letter."));
|
||||||
|
errorDialog.exec();
|
||||||
|
|
||||||
item->setText(node.id());
|
item->setText(node.id());
|
||||||
|
}
|
||||||
} catch (InvalidIdException &) {
|
} catch (InvalidIdException &) {
|
||||||
item->setText(node.id());
|
item->setText(node.id());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem &option,
|
|||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
return QSize(15,17);
|
return QSize(15,21);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IconCheckboxItemDelegate::paint(QPainter *painter,
|
void IconCheckboxItemDelegate::paint(QPainter *painter,
|
||||||
@@ -63,10 +63,6 @@ void IconCheckboxItemDelegate::paint(QPainter *painter,
|
|||||||
else
|
else
|
||||||
painter->drawPixmap(option.rect.x()+2,option.rect.y()+1,offPix);
|
painter->drawPixmap(option.rect.x()+2,option.rect.y()+1,offPix);
|
||||||
|
|
||||||
painter->setOpacity(1.0);
|
|
||||||
painter->setPen(QColor(_separator_line_color_));
|
|
||||||
painter->drawLine(option.rect.topLeft(),option.rect.bottomLeft());
|
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,19 +77,32 @@ void IdItemDelegate::paint(QPainter *painter,
|
|||||||
|
|
||||||
ModelNode node = m_TreeModel->nodeForIndex(index);
|
ModelNode node = m_TreeModel->nodeForIndex(index);
|
||||||
|
|
||||||
// QIcon icon=node.metaInfo().icon();
|
QIcon icon=node.metaInfo().icon();
|
||||||
// if (icon.isNull()) icon = QIcon(":/ItemLibrary/images/default-icon.png");
|
if (icon.isNull()) icon = QIcon(":/ItemLibrary/images/default-icon.png");
|
||||||
// QPixmap pixmap = icon.pixmap(option.rect.width(),option.rect.height());
|
QPixmap pixmap = icon.pixmap(option.rect.width(),option.rect.height()-4);
|
||||||
// painter->drawPixmap(option.rect.x()+1,option.rect.y(),pixmap);
|
painter->drawPixmap(option.rect.x()+5,option.rect.y()+2,pixmap);
|
||||||
|
|
||||||
QString myString = node.id();
|
QString myString = node.id();
|
||||||
if (myString.isEmpty())
|
if (myString.isEmpty())
|
||||||
myString = node.simplifiedTypeName();
|
myString = node.simplifiedTypeName();
|
||||||
|
|
||||||
|
// Check text length does not exceed available space
|
||||||
|
int extraSpace=12+pixmap.width();
|
||||||
|
QFontMetrics metric(painter->fontMetrics());
|
||||||
|
if (painter->fontMetrics().boundingRect(myString).width() > option.rect.width()-extraSpace)
|
||||||
|
{
|
||||||
|
QString origString(myString);
|
||||||
|
int cutpoint=origString.length()/2;
|
||||||
|
while (painter->fontMetrics().boundingRect(myString).width() > option.rect.width()-extraSpace)
|
||||||
|
{
|
||||||
|
cutpoint--;
|
||||||
|
myString = origString.left(cutpoint)+QLatin1String("...")+origString.right(cutpoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_TreeModel->isNodeInvisible( index ))
|
if (m_TreeModel->isNodeInvisible( index ))
|
||||||
painter->setOpacity(0.5);
|
painter->setOpacity(0.5);
|
||||||
// painter->drawText(option.rect.bottomLeft()+QPoint(4+pixmap.width(),-4),myString);
|
painter->drawText(option.rect.bottomLeft()+QPoint(8+pixmap.width(),-4),myString);
|
||||||
painter->drawText(option.rect.bottomLeft()+QPoint(4,-4),myString);
|
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user