Commit 14d4ebd3 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Decouple NameItemDelegate from model

We introduce a role for the model node.
This way we do not have to access the model directly.

Change-Id: If3eb006894e1d227ec9c58bbd99cdcd500cd62d7
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 4fe63ed7
......@@ -145,9 +145,14 @@ static QRect drawText(QPainter *painter,
return textFrame;
}
static bool isVisible(const QAbstractItemModel *model, const QModelIndex &modelIndex)
static bool isVisible(const QModelIndex &modelIndex)
{
return model->data(modelIndex, ItemIsVisibleRole).toBool();
return modelIndex.model()->data(modelIndex, ItemIsVisibleRole).toBool();
}
static ModelNode getModelNode(const QModelIndex &modelIndex)
{
return modelIndex.model()->data(modelIndex, ModelNodeRole).value<ModelNode>();
}
static void drawRedWavyUnderLine(QPainter *painter,
......@@ -175,7 +180,7 @@ void NameItemDelegate::paint(QPainter *painter,
int iconOffset = drawIcon(painter, styleOption, modelIndex);
if (!isVisible(modelIndex.model(), modelIndex))
if (!isVisible(modelIndex))
painter->setOpacity(0.5);
QRect textFrame = drawText(painter, styleOption, modelIndex, iconOffset);
......@@ -203,7 +208,7 @@ QWidget *NameItemDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & /*option*/,
const QModelIndex &index) const
{
if (!m_navigatorTreeModel->hasModelNodeForIndex(index))
if (!getModelNode(index).isValid())
return 0;
return new QLineEdit(parent);
......@@ -211,7 +216,7 @@ QWidget *NameItemDelegate::createEditor(QWidget *parent,
void NameItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
const ModelNode node = m_navigatorTreeModel->modelNodeForIndex(index);
const ModelNode node = getModelNode(index);
const QString value = node.id();
QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
......
......@@ -216,25 +216,28 @@ QVariant NavigatorTreeModel::data(const QModelIndex &index, int role) const
if (index.column() == 0) {
if (role == Qt::DisplayRole) {
return modelNode.displayName();
} else if (role == Qt::DecorationRole)
} else if (role == Qt::DecorationRole) {
if (currentQmlObjectNode.hasError())
return Utils::Icons::WARNING.icon();
return modelNode.typeIcon();
} else if (role == Qt::ToolTipRole) {
if (currentQmlObjectNode.hasError()) {
QString errorString = currentQmlObjectNode.error();
if (currentQmlObjectNode.isRootNode())
errorString.append(QString("\n%1").arg(tr("Changing the setting \"%1\" might solve the issue.").arg(
tr("Use QML emulation layer that is built with the selected Qt"))));
return modelNode.typeIcon();
} else if (role == Qt::ToolTipRole) {
if (currentQmlObjectNode.hasError()) {
QString errorString = currentQmlObjectNode.error();
if (currentQmlObjectNode.isRootNode())
errorString.append(QString("\n%1").arg(tr("Changing the setting \"%1\" might solve the issue.").arg(
tr("Use QML emulation layer that is built with the selected Qt"))));
return errorString;
return errorString;
}
if (modelNode.metaInfo().isValid())
return modelNode.type();
else
return msgUnknownItem(QString::fromUtf8(modelNode.type()));
} else if (role == ModelNodeRole) {
return QVariant::fromValue<ModelNode>(modelNode);
}
if (modelNode.metaInfo().isValid())
return modelNode.type();
else
return msgUnknownItem(QString::fromUtf8(modelNode.type()));
} else if (index.column() == 1) { //export
if (role == Qt::CheckStateRole)
return currentQmlObjectNode.isAliasExported() ? Qt::Checked : Qt::Unchecked;
......
......@@ -42,7 +42,8 @@ class NavigatorTreeModel;
enum NavigatorRoles {
ItemIsVisibleRole = Qt::UserRole,
RowIsPropertyRole = Qt::UserRole +1
RowIsPropertyRole = Qt::UserRole + 1,
ModelNodeRole = Qt::UserRole + 2
};
class NavigatorView : public AbstractView
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment