Commit 514e0a8d authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Move icon retrieviel to ModelNode

This allows to use the icon in other places.

Change-Id: I3c67351273f3be3c0fbe19eb58984cf54d057a3d
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 94e02994
......@@ -132,22 +132,6 @@ static inline QString msgUnknownItem(const QString &t)
return NavigatorTreeModel::tr("Unknown item: %1").arg(t);
}
static QIcon getTypeIcon(const ModelNode &modelNode)
{
if (modelNode.isValid()) {
// if node has no own icon, search for it in the itemlibrary
const ItemLibraryInfo *libraryInfo = modelNode.model()->metaInfo().itemLibraryInfo();
QList <ItemLibraryEntry> itemLibraryEntryList = libraryInfo->entriesForType(
modelNode.type(), modelNode.majorVersion(), modelNode.minorVersion());
if (!itemLibraryEntryList.isEmpty())
return itemLibraryEntryList.first().typeIcon();
else if (modelNode.metaInfo().isValid())
return QIcon(QStringLiteral(":/ItemLibrary/images/item-default-icon.png"));
}
return QIcon(QStringLiteral(":/ItemLibrary/images/item-invalid-icon.png"));
}
static bool isRootNodeOrAcceptedChild(const ModelNode &modelNode)
{
return modelNode.isRootNode() || acceptedModelNodeChildren(modelNode.parentProperty().parentModelNode()).contains(modelNode);
......@@ -272,7 +256,7 @@ QVariant NavigatorTreeModel::data(const QModelIndex &index, int role) const
if (currentQmlObjectNode.hasError())
return Utils::Icons::WARNING.icon();
return getTypeIcon(modelNode);
return modelNode.typeIcon();
} else if (role == Qt::ToolTipRole) {
if (currentQmlObjectNode.hasError()) {
QString errorString = currentQmlObjectNode.error();
......
......@@ -191,6 +191,7 @@ public:
bool isComponent() const;
bool isSubclassOf(const TypeName &typeName, int majorVersion = -1, int minorVersion = -1) const;
QIcon typeIcon() const;
private: // functions
Internal::InternalNodePointer internalNode() const;
......
......@@ -1178,4 +1178,20 @@ bool ModelNode::isSubclassOf(const TypeName &typeName, int majorVersion, int min
return false;
}
QIcon ModelNode::typeIcon() const
{
if (isValid()) {
// if node has no own icon, search for it in the itemlibrary
const ItemLibraryInfo *libraryInfo = model()->metaInfo().itemLibraryInfo();
QList <ItemLibraryEntry> itemLibraryEntryList = libraryInfo->entriesForType(
type(), majorVersion(), minorVersion());
if (!itemLibraryEntryList.isEmpty())
return itemLibraryEntryList.first().typeIcon();
else if (metaInfo().isValid())
return QIcon(QStringLiteral(":/ItemLibrary/images/item-default-icon.png"));
}
return QIcon(QStringLiteral(":/ItemLibrary/images/item-invalid-icon.png"));
}
}
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