Skip to content
Snippets Groups Projects
Commit 15f2c634 authored by Kai Koehne's avatar Kai Koehne
Browse files

QuickDesigner: Clean up ItemLibraryInfo class

Remove dependencies to QMetaInfo & unify method names.

Reviewed-by: Thomas Hartmann
parent 1b6e3834
No related branches found
No related tags found
No related merge requests found
......@@ -171,24 +171,24 @@ void IdItemDelegate::paint(QPainter *painter,
if (icon.isNull())
{
// if node has no own icon, search for it in the itemlibrary
const NodeMetaInfo typeInfo = node.metaInfo();
const ItemLibraryInfo libraryInfo = node.metaInfo().metaInfo().itemLibraryInfo();
QList <ItemLibraryEntry> infoList = libraryInfo.entriesForNodeMetaInfo(node.metaInfo());
foreach (const ItemLibraryEntry &entry, infoList)
{
if (entry.typeName()==node.metaInfo().typeName()) {
QList <ItemLibraryEntry> infoList = libraryInfo.entriesForType(typeInfo.typeName(),
typeInfo.majorVersion(),
typeInfo.minorVersion());
foreach (const ItemLibraryEntry &entry, infoList) {
if (!icon.isNull()) {
icon = entry.icon();
break;
}
}
// if the library was also empty, use the default icon
}
}
// if the library was also empty, use the default icon
if (icon.isNull())
icon = QIcon(":/ItemLibrary/images/item-default-icon.png");
// If no icon is present, leave an empty space of 24 pixels anyway
int pixmapSide = 16;
QPixmap pixmap = icon.pixmap(pixmapSide, pixmapSide);
......
......@@ -32,20 +32,13 @@
#include "corelib_global.h"
#include <QExplicitlySharedDataPointer>
#include <QList>
#include <QString>
#include <QIcon>
#include "propertycontainer.h"
#include <qdeclarative.h>
#include <QSharedPointer>
namespace QmlDesigner {
class NodeMetaInfo;
namespace Internal {
class MetaInfoPrivate;
class ItemLibraryEntryData;
class ItemLibraryInfoPrivate;
......@@ -58,8 +51,8 @@ CORESHARED_EXPORT QDataStream& operator>>(QDataStream& stream, ItemLibraryEntry
class CORESHARED_EXPORT ItemLibraryEntry
{
friend class QmlDesigner::MetaInfo;
friend class QmlDesigner::Internal::MetaInfoParser;
//friend class QmlDesigner::MetaInfo;
//friend class QmlDesigner::Internal::MetaInfoParser;
friend CORESHARED_EXPORT QDataStream& QmlDesigner::operator<<(QDataStream& stream, const ItemLibraryEntry &itemLibraryEntry);
friend CORESHARED_EXPORT QDataStream& QmlDesigner::operator>>(QDataStream& stream, ItemLibraryEntry &itemLibraryEntry);
public:
......@@ -82,9 +75,7 @@ public:
QList<Property> properties() const;
void setTypeName(const QString &typeName);
void setMajorVersion(int majorNumber);
void setMinorVersion(int minorNumber);
void setType(const QString &typeName, int majorVersion, int minorVersion);
void setName(const QString &name);
void setIcon(const QIcon &icon);
void addProperty(const Property &p);
......@@ -110,12 +101,12 @@ public:
bool isValid();
QList<ItemLibraryEntry> entries() const;
QList<ItemLibraryEntry> entriesForNodeMetaInfo(const NodeMetaInfo &nodeMetaInfo) const;
QList<ItemLibraryEntry> entriesForType(const QString &typeName, int majorVersion, int minorVersion) const;
ItemLibraryEntry entry(const QString &name) const;
ItemLibraryEntry addItemLibraryEntry(const NodeMetaInfo &nodeMetaInfo, const QString &itemLibraryRepresentationName);
void remove(const NodeMetaInfo &nodeMetaInfo);
void clear();
void addEntry(const ItemLibraryEntry &entry);
bool removeEntry(const QString &name);
void clearEntries();
private:
static ItemLibraryInfo createItemLibraryInfo(const ItemLibraryInfo &parentInfo);
......
......@@ -58,8 +58,7 @@ public:
typedef QSharedPointer<ItemLibraryInfoPrivate> Pointer;
typedef QSharedPointer<ItemLibraryInfoPrivate> WeakPointer;
QMultiHash<NodeMetaInfo, ItemLibraryEntry> itemLibraryInfoHash;
QHash<QString, ItemLibraryEntry> itemLibraryInfoHashAll;
QHash<QString, ItemLibraryEntry> nameToEntryHash;
Pointer parentData;
};
......@@ -157,9 +156,11 @@ void ItemLibraryEntry::setName(const QString &name)
m_data->name = name;
}
void ItemLibraryEntry::setTypeName(const QString &typeName)
void ItemLibraryEntry::setType(const QString &typeName, int majorVersion, int minorVersion)
{
m_data->typeName = typeName;
m_data->majorVersion = majorVersion;
m_data->minorVersion = minorVersion;
}
void ItemLibraryEntry::setIcon(const QIcon &icon)
......@@ -167,16 +168,6 @@ void ItemLibraryEntry::setIcon(const QIcon &icon)
m_data->icon = icon;
}
void ItemLibraryEntry::setMajorVersion(int majorVersion)
{
m_data->majorVersion = majorVersion;
}
void ItemLibraryEntry::setMinorVersion(int minorVersion)
{
m_data->minorVersion = minorVersion;
}
void ItemLibraryEntry::setQml(const QString &qml)
{
m_data->qml = qml;
......@@ -254,66 +245,70 @@ ItemLibraryInfo ItemLibraryInfo::createItemLibraryInfo(const ItemLibraryInfo &pa
return info;
}
QList<ItemLibraryEntry> ItemLibraryInfo::entriesForNodeMetaInfo(const NodeMetaInfo &nodeMetaInfo) const
QList<ItemLibraryEntry> ItemLibraryInfo::entriesForType(const QString &typeName, int majorVersion, int minorVersion) const
{
QList<ItemLibraryEntry> itemLibraryItems;
QList<ItemLibraryEntry> entries;
Internal::ItemLibraryInfoPrivate::WeakPointer pointer(m_data);
while (pointer) {
itemLibraryItems += pointer->itemLibraryInfoHash.values(nodeMetaInfo);
foreach (const ItemLibraryEntry &entry, m_data->nameToEntryHash.values()) {
if (entry.typeName() == typeName
&& entry.majorVersion() == majorVersion
&& entry.minorVersion() == minorVersion)
entries += entry;
}
pointer = pointer->parentData;
}
return itemLibraryItems;
return entries;
}
ItemLibraryEntry ItemLibraryInfo::entry(const QString &name) const
{
Internal::ItemLibraryInfoPrivate::WeakPointer pointer(m_data);
while (pointer) {
if (pointer->itemLibraryInfoHashAll.contains(name))
return pointer->itemLibraryInfoHashAll.value(name);
if (pointer->nameToEntryHash.contains(name))
return pointer->nameToEntryHash.value(name);
pointer = pointer->parentData;
}
return ItemLibraryEntry();
}
QList<ItemLibraryEntry> ItemLibraryInfo::entries() const
{
QList<ItemLibraryEntry> list;
Internal::ItemLibraryInfoPrivate::WeakPointer pointer(m_data);
while (pointer) {
list += pointer->itemLibraryInfoHashAll.values();
list += pointer->nameToEntryHash.values();
pointer = pointer->parentData;
}
return list;
}
ItemLibraryEntry ItemLibraryInfo::addItemLibraryEntry(const NodeMetaInfo &nodeMetaInfo,
const QString &itemLibraryRepresentationName)
void ItemLibraryInfo::addEntry(const ItemLibraryEntry &entry)
{
ItemLibraryEntry itemLibraryType;
itemLibraryType.setName(itemLibraryRepresentationName);
itemLibraryType.setTypeName(nodeMetaInfo.typeName());
itemLibraryType.setMajorVersion(nodeMetaInfo.majorVersion());
itemLibraryType.setMinorVersion(nodeMetaInfo.minorVersion());
m_data->itemLibraryInfoHash.insert(nodeMetaInfo, itemLibraryType);
m_data->itemLibraryInfoHashAll.insert(itemLibraryRepresentationName, itemLibraryType);
return itemLibraryType;
if (m_data->nameToEntryHash.contains(entry.name()))
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
m_data->nameToEntryHash.insert(entry.name(), entry);
}
void ItemLibraryInfo::remove(const NodeMetaInfo &info)
bool ItemLibraryInfo::removeEntry(const QString &name)
{
m_data->itemLibraryInfoHash.remove(info);
m_data->itemLibraryInfoHashAll.remove(info.typeName());
Internal::ItemLibraryInfoPrivate::WeakPointer pointer(m_data);
while (pointer) {
if (pointer->nameToEntryHash.remove(name))
return true;
pointer = pointer->parentData;
}
return false;
}
void ItemLibraryInfo::clear()
void ItemLibraryInfo::clearEntries()
{
m_data->itemLibraryInfoHash.clear();
m_data->itemLibraryInfoHashAll.clear();
m_data->nameToEntryHash.clear();
}
} // namespace QmlDesigner
......@@ -102,7 +102,7 @@ void MetaInfoPrivate::clear()
m_superClassHash.clear();
m_nodeMetaInfoHash.clear();
m_enumeratorMetaInfoHash.clear();
m_itemLibraryInfo.clear();
m_itemLibraryInfo.clearEntries();
m_isInitialized = false;
}
......@@ -608,7 +608,10 @@ void MetaInfo::removeNodeInfo(NodeMetaInfo &info)
m_p->m_superClassHash.remove(info.typeName());
// TODO: Other types might specify type as parent type
m_p->m_itemLibraryInfo.remove(info);
foreach (const ItemLibraryEntry &entry,
m_p->m_itemLibraryInfo.entriesForType(info.typeName(), info.majorVersion(), info.minorVersion())) {
m_p->m_itemLibraryInfo.removeEntry(entry.name());
}
} else if (!isGlobal()) {
global().removeNodeInfo(info);
......
......@@ -198,21 +198,27 @@ void MetaInfoParser::handleNodeItemLibraryEntryElement(QXmlStreamReader &reader,
{
if (reader.isStartElement() && reader.name() == "itemlibraryentry")
{
QString name = reader.attributes().value("name").toString();
ItemLibraryEntry itemLibraryEntry = m_metaInfo.itemLibraryInfo().addItemLibraryEntry(m_metaInfo.nodeMetaInfo(className), name);
const QString name = reader.attributes().value("name").toString();
const NodeMetaInfo typeInfo = m_metaInfo.nodeMetaInfo(className);
ItemLibraryEntry entry;
entry.setType(typeInfo.typeName(), typeInfo.majorVersion(), typeInfo.minorVersion());
entry.setName(name);
QString iconPath = reader.attributes().value("icon").toString();
if (!iconPath.isEmpty())
itemLibraryEntry.setIcon(QIcon(iconPath));
entry.setIcon(QIcon(iconPath));
QString category = reader.attributes().value("category").toString();
if (!category.isEmpty())
itemLibraryEntry.setCategory(category);
entry.setCategory(category);
while (!reader.atEnd() && !(reader.isEndElement() && reader.name() == "itemlibraryentry")) {
reader.readNext();
handleItemLibraryEntryPropertyElement(reader, itemLibraryEntry);
handleItemLibraryEntryPropertyElement(reader, entry);
}
m_metaInfo.itemLibraryInfo().addEntry(entry);
}
}
......
......@@ -303,8 +303,11 @@ void SubComponentManagerPrivate::registerQmlFile(const QFileInfo &fileInfo, cons
nodeInfo.setQmlFile(fileInfo.filePath());
// Add file components to the library
ItemLibraryEntry itemLibType = m_metaInfo.itemLibraryInfo().addItemLibraryEntry(nodeInfo, componentName);
itemLibType.setCategory(tr("QML Components"));
ItemLibraryEntry itemLibraryEntry;
itemLibraryEntry.setType(nodeInfo.typeName(), nodeInfo.majorVersion(), nodeInfo.minorVersion());
itemLibraryEntry.setName(componentName);
itemLibraryEntry.setCategory(tr("QML Components"));
m_metaInfo.itemLibraryInfo().addEntry(itemLibraryEntry);
m_metaInfo.addNodeInfo(nodeInfo, baseType);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment