forked from qt-creator/qt-creator
QuickDesigner: Update ItemLibrary when imported directories change
ItemLibraryInfo has now a signal "entriesChanged()", which the ItemLibrary connects to. To allow this, ItemLibraryInfo was moved from a stack-based to a heap-based class. Reviewed-by: Thomas Hartmann
This commit is contained in:
@@ -170,7 +170,7 @@ void ItemCreatorTool::createAtItem(const QRectF &rect)
|
||||
return;
|
||||
if (list.first() == "item") {
|
||||
RewriterTransaction transaction = view()->beginRewriterTransaction();
|
||||
ItemLibraryEntry itemLibraryEntry = view()->model()->metaInfo().itemLibraryInfo().entry(list.at(1));
|
||||
ItemLibraryEntry itemLibraryEntry = view()->model()->metaInfo().itemLibraryInfo()->entry(list.at(1));
|
||||
QmlItemNode newNode = view()->createQmlItemNode(itemLibraryEntry, pos, parentNode);
|
||||
newNode.modelNode().variantProperty("width") = rect.width();
|
||||
newNode.modelNode().variantProperty("height") = rect.height();
|
||||
|
||||
@@ -344,7 +344,7 @@ void DesignDocumentController::loadCurrentModel()
|
||||
m_d->model->setMasterModel(m_d->masterModel.data());
|
||||
|
||||
m_d->model->attachView(m_d->navigator.data());
|
||||
m_d->itemLibrary->setMetaInfo(m_d->model->metaInfo());
|
||||
m_d->itemLibrary->setItemLibraryInfo(m_d->model->metaInfo().itemLibraryInfo());
|
||||
m_d->itemLibrary->setResourcePath(QFileInfo(m_d->fileName).absolutePath());
|
||||
|
||||
if (!m_d->componentAction) {
|
||||
|
||||
@@ -101,6 +101,7 @@ public:
|
||||
Utils::FilterLineEdit *m_lineEdit;
|
||||
QDeclarativeView *m_itemsView;
|
||||
Internal::ItemLibraryTreeView *m_resourcesView;
|
||||
QWeakPointer<ItemLibraryInfo> m_itemLibraryInfo;
|
||||
|
||||
QSize m_itemIconSize, m_resIconSize;
|
||||
MyFileIconProvider m_iconProvider;
|
||||
@@ -233,9 +234,20 @@ ItemLibrary::~ItemLibrary()
|
||||
delete m_d;
|
||||
}
|
||||
|
||||
void ItemLibrary::setMetaInfo(const MetaInfo &metaInfo)
|
||||
void ItemLibrary::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo)
|
||||
{
|
||||
m_d->m_itemLibraryModel->update(metaInfo);
|
||||
if (m_d->m_itemLibraryInfo.data() == itemLibraryInfo)
|
||||
return;
|
||||
|
||||
if (m_d->m_itemLibraryInfo)
|
||||
disconnect(m_d->m_itemLibraryInfo.data(), SIGNAL(entriesChanged()),
|
||||
this, SLOT(updateModel()));
|
||||
m_d->m_itemLibraryInfo = itemLibraryInfo;
|
||||
if (itemLibraryInfo)
|
||||
connect(m_d->m_itemLibraryInfo.data(), SIGNAL(entriesChanged()),
|
||||
this, SLOT(updateModel()));
|
||||
|
||||
updateModel();
|
||||
updateSearch();
|
||||
}
|
||||
|
||||
@@ -262,6 +274,12 @@ void ItemLibrary::setSearchFilter(const QString &searchFilter)
|
||||
}
|
||||
}
|
||||
|
||||
void ItemLibrary::updateModel()
|
||||
{
|
||||
m_d->m_itemLibraryModel->update(m_d->m_itemLibraryInfo.data());
|
||||
updateSearch();
|
||||
}
|
||||
|
||||
void ItemLibrary::updateSearch()
|
||||
{
|
||||
setSearchFilter(m_d->m_lineEdit->text());
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#ifndef ITEMLIBRARY_H
|
||||
#define ITEMLIBRARY_H
|
||||
|
||||
#include "itemlibraryinfo.h"
|
||||
#include <QtGui/QFrame>
|
||||
|
||||
namespace QmlDesigner {
|
||||
@@ -47,10 +48,11 @@ public:
|
||||
ItemLibrary(QWidget *parent = 0);
|
||||
virtual ~ItemLibrary();
|
||||
|
||||
void setMetaInfo(const MetaInfo &metaInfo);
|
||||
void setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setSearchFilter(const QString &searchFilter);
|
||||
void updateModel();
|
||||
void updateSearch();
|
||||
void clearLineEditFocus();
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "itemlibrarymodel.h"
|
||||
#include "metainfo.h"
|
||||
#include "itemlibraryinfo.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QMimeData>
|
||||
@@ -317,7 +317,6 @@ bool ItemLibrarySectionModel::operator<(const ItemLibrarySectionModel &other) co
|
||||
ItemLibraryModel::ItemLibraryModel(QScriptEngine *scriptEngine, QObject *parent)
|
||||
: ItemLibrarySortedModel<ItemLibrarySectionModel>(parent),
|
||||
m_scriptEngine(scriptEngine),
|
||||
m_metaInfo(0),
|
||||
m_searchText(""),
|
||||
m_itemIconSize(64, 64),
|
||||
m_nextLibId(0)
|
||||
@@ -327,8 +326,6 @@ ItemLibraryModel::ItemLibraryModel(QScriptEngine *scriptEngine, QObject *parent)
|
||||
|
||||
ItemLibraryModel::~ItemLibraryModel()
|
||||
{
|
||||
if (m_metaInfo)
|
||||
delete m_metaInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -387,7 +384,7 @@ bool ItemLibraryModel::isItemVisible(int itemLibId)
|
||||
return elementModel(sectionLibId)->isItemVisible(itemLibId);
|
||||
}
|
||||
|
||||
void ItemLibraryModel::update(const MetaInfo &metaInfo)
|
||||
void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo)
|
||||
{
|
||||
QMap<QString, int> sections;
|
||||
|
||||
@@ -396,13 +393,7 @@ void ItemLibraryModel::update(const MetaInfo &metaInfo)
|
||||
m_sections.clear();
|
||||
m_nextLibId = 0;
|
||||
|
||||
if (!m_metaInfo) {
|
||||
m_metaInfo = new MetaInfo(metaInfo);
|
||||
} else {
|
||||
*m_metaInfo = metaInfo;
|
||||
}
|
||||
|
||||
foreach (ItemLibraryEntry entry, metaInfo.itemLibraryInfo().entries()) {
|
||||
foreach (ItemLibraryEntry entry, itemLibraryInfo->entries()) {
|
||||
QString itemSectionName = entry.category();
|
||||
ItemLibrarySectionModel *sectionModel;
|
||||
ItemLibraryItemModel *itemModel;
|
||||
|
||||
@@ -40,7 +40,7 @@ QT_FORWARD_DECLARE_CLASS(QMimeData);
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class MetaInfo;
|
||||
class ItemLibraryInfo;
|
||||
class ItemLibraryEntry;
|
||||
|
||||
namespace Internal {
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
|
||||
QString searchText() const;
|
||||
|
||||
void update(const MetaInfo &metaInfo);
|
||||
void update(ItemLibraryInfo *itemLibraryInfo);
|
||||
|
||||
QString getTypeName(int libId);
|
||||
QMimeData *getMimeData(int libId);
|
||||
@@ -159,7 +159,6 @@ private:
|
||||
QPixmap createDragPixmap(int width, int height);
|
||||
|
||||
QWeakPointer<QScriptEngine> m_scriptEngine;
|
||||
MetaInfo *m_metaInfo;
|
||||
QMap<int, ItemLibraryEntry> m_itemInfos;
|
||||
QMap<int, int> m_sections;
|
||||
|
||||
|
||||
@@ -172,10 +172,10 @@ void IdItemDelegate::paint(QPainter *painter,
|
||||
{
|
||||
// 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.entriesForType(typeInfo.typeName(),
|
||||
typeInfo.majorVersion(),
|
||||
typeInfo.minorVersion());
|
||||
const ItemLibraryInfo *libraryInfo = node.metaInfo().metaInfo().itemLibraryInfo();
|
||||
QList <ItemLibraryEntry> infoList = libraryInfo->entriesForType(typeInfo.typeName(),
|
||||
typeInfo.majorVersion(),
|
||||
typeInfo.minorVersion());
|
||||
foreach (const ItemLibraryEntry &entry, infoList) {
|
||||
if (!icon.isNull()) {
|
||||
icon = entry.icon();
|
||||
|
||||
@@ -87,19 +87,14 @@ private:
|
||||
QExplicitlySharedDataPointer<Internal::ItemLibraryEntryData> m_data;
|
||||
};
|
||||
|
||||
|
||||
class CORESHARED_EXPORT ItemLibraryInfo
|
||||
class CORESHARED_EXPORT ItemLibraryInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ItemLibraryInfo)
|
||||
friend class Internal::MetaInfoPrivate;
|
||||
public:
|
||||
ItemLibraryInfo();
|
||||
ItemLibraryInfo(const ItemLibraryInfo &other);
|
||||
~ItemLibraryInfo();
|
||||
|
||||
ItemLibraryInfo& operator=(const ItemLibraryInfo &other);
|
||||
|
||||
bool isValid();
|
||||
|
||||
QList<ItemLibraryEntry> entries() const;
|
||||
QList<ItemLibraryEntry> entriesForType(const QString &typeName, int majorVersion, int minorVersion) const;
|
||||
ItemLibraryEntry entry(const QString &name) const;
|
||||
@@ -108,9 +103,13 @@ public:
|
||||
bool removeEntry(const QString &name);
|
||||
void clearEntries();
|
||||
|
||||
signals:
|
||||
void entriesChanged();
|
||||
|
||||
private:
|
||||
static ItemLibraryInfo createItemLibraryInfo(const ItemLibraryInfo &parentInfo);
|
||||
QSharedPointer<Internal::ItemLibraryInfoPrivate> m_data;
|
||||
ItemLibraryInfo(QObject *parent = 0);
|
||||
void setBaseInfo(ItemLibraryInfo *baseInfo);
|
||||
QScopedPointer<Internal::ItemLibraryInfoPrivate> m_d;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
bool hasEnumerator(const QString &enumeratorName) const;
|
||||
EnumeratorMetaInfo enumerator(const QString &enumeratorName) const;
|
||||
|
||||
ItemLibraryInfo itemLibraryInfo() const;
|
||||
ItemLibraryInfo *itemLibraryInfo() const;
|
||||
|
||||
QString fromQtTypes(const QString &type) const;
|
||||
|
||||
|
||||
@@ -55,12 +55,9 @@ public:
|
||||
class ItemLibraryInfoPrivate
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<ItemLibraryInfoPrivate> Pointer;
|
||||
typedef QSharedPointer<ItemLibraryInfoPrivate> WeakPointer;
|
||||
|
||||
QHash<QString, ItemLibraryEntry> nameToEntryHash;
|
||||
|
||||
Pointer parentData;
|
||||
QWeakPointer<ItemLibraryInfo> baseInfo;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
@@ -212,13 +209,9 @@ QDataStream& operator>>(QDataStream& stream, ItemLibraryEntry &itemLibraryEntry)
|
||||
// ItemLibraryInfo
|
||||
//
|
||||
|
||||
ItemLibraryInfo::ItemLibraryInfo(const ItemLibraryInfo &other) :
|
||||
m_data(other.m_data)
|
||||
{
|
||||
}
|
||||
|
||||
ItemLibraryInfo::ItemLibraryInfo() :
|
||||
m_data(new Internal::ItemLibraryInfoPrivate())
|
||||
ItemLibraryInfo::ItemLibraryInfo(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_d(new Internal::ItemLibraryInfoPrivate())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -226,89 +219,72 @@ ItemLibraryInfo::~ItemLibraryInfo()
|
||||
{
|
||||
}
|
||||
|
||||
ItemLibraryInfo& ItemLibraryInfo::operator=(const ItemLibraryInfo &other)
|
||||
{
|
||||
m_data = other.m_data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool ItemLibraryInfo::isValid()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
ItemLibraryInfo ItemLibraryInfo::createItemLibraryInfo(const ItemLibraryInfo &parentInfo)
|
||||
{
|
||||
ItemLibraryInfo info;
|
||||
Q_ASSERT(parentInfo.m_data);
|
||||
info.m_data->parentData = parentInfo.m_data;
|
||||
return info;
|
||||
}
|
||||
|
||||
QList<ItemLibraryEntry> ItemLibraryInfo::entriesForType(const QString &typeName, int majorVersion, int minorVersion) const
|
||||
{
|
||||
QList<ItemLibraryEntry> entries;
|
||||
|
||||
Internal::ItemLibraryInfoPrivate::WeakPointer pointer(m_data);
|
||||
while (pointer) {
|
||||
foreach (const ItemLibraryEntry &entry, m_data->nameToEntryHash.values()) {
|
||||
if (entry.typeName() == typeName
|
||||
&& entry.majorVersion() == majorVersion
|
||||
&& entry.minorVersion() == minorVersion)
|
||||
entries += entry;
|
||||
}
|
||||
|
||||
pointer = pointer->parentData;
|
||||
foreach (const ItemLibraryEntry &entry, m_d->nameToEntryHash.values()) {
|
||||
if (entry.typeName() == typeName
|
||||
&& entry.majorVersion() == majorVersion
|
||||
&& entry.minorVersion() == minorVersion)
|
||||
entries += entry;
|
||||
}
|
||||
|
||||
if (m_d->baseInfo)
|
||||
entries += m_d->baseInfo->entriesForType(typeName, majorVersion, minorVersion);
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
ItemLibraryEntry ItemLibraryInfo::entry(const QString &name) const
|
||||
{
|
||||
Internal::ItemLibraryInfoPrivate::WeakPointer pointer(m_data);
|
||||
while (pointer) {
|
||||
if (pointer->nameToEntryHash.contains(name))
|
||||
return pointer->nameToEntryHash.value(name);
|
||||
pointer = pointer->parentData;
|
||||
}
|
||||
if (m_d->nameToEntryHash.contains(name))
|
||||
return m_d->nameToEntryHash.value(name);
|
||||
|
||||
if (m_d->baseInfo)
|
||||
return m_d->baseInfo->entry(name);
|
||||
|
||||
return ItemLibraryEntry();
|
||||
}
|
||||
|
||||
QList<ItemLibraryEntry> ItemLibraryInfo::entries() const
|
||||
{
|
||||
QList<ItemLibraryEntry> list;
|
||||
|
||||
Internal::ItemLibraryInfoPrivate::WeakPointer pointer(m_data);
|
||||
while (pointer) {
|
||||
list += pointer->nameToEntryHash.values();
|
||||
pointer = pointer->parentData;
|
||||
}
|
||||
QList<ItemLibraryEntry> list = m_d->nameToEntryHash.values();
|
||||
if (m_d->baseInfo)
|
||||
list += m_d->baseInfo->entries();
|
||||
return list;
|
||||
}
|
||||
|
||||
void ItemLibraryInfo::addEntry(const ItemLibraryEntry &entry)
|
||||
{
|
||||
if (m_data->nameToEntryHash.contains(entry.name()))
|
||||
if (m_d->nameToEntryHash.contains(entry.name()))
|
||||
throw InvalidMetaInfoException(__LINE__, __FUNCTION__, __FILE__);
|
||||
m_data->nameToEntryHash.insert(entry.name(), entry);
|
||||
m_d->nameToEntryHash.insert(entry.name(), entry);
|
||||
|
||||
emit entriesChanged();
|
||||
}
|
||||
|
||||
bool ItemLibraryInfo::removeEntry(const QString &name)
|
||||
{
|
||||
Internal::ItemLibraryInfoPrivate::WeakPointer pointer(m_data);
|
||||
while (pointer) {
|
||||
if (pointer->nameToEntryHash.remove(name))
|
||||
return true;
|
||||
pointer = pointer->parentData;
|
||||
if (m_d->nameToEntryHash.remove(name)) {
|
||||
emit entriesChanged();
|
||||
return true;
|
||||
}
|
||||
if (m_d->baseInfo)
|
||||
return m_d->baseInfo->removeEntry(name);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ItemLibraryInfo::clearEntries()
|
||||
{
|
||||
m_data->nameToEntryHash.clear();
|
||||
m_d->nameToEntryHash.clear();
|
||||
emit entriesChanged();
|
||||
}
|
||||
|
||||
void ItemLibraryInfo::setBaseInfo(ItemLibraryInfo *baseInfo)
|
||||
{
|
||||
m_d->baseInfo = baseInfo;
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -83,18 +83,19 @@ public:
|
||||
QHash<QString, NodeMetaInfo> m_nodeMetaInfoHash;
|
||||
QHash<QString, EnumeratorMetaInfo> m_enumeratorMetaInfoHash;
|
||||
QHash<QString, QString> m_QtTypesToQmlTypes;
|
||||
ItemLibraryInfo m_itemLibraryInfo;
|
||||
QScopedPointer<ItemLibraryInfo> m_itemLibraryInfo;
|
||||
|
||||
MetaInfo *m_q;
|
||||
bool m_isInitialized;
|
||||
};
|
||||
|
||||
MetaInfoPrivate::MetaInfoPrivate(MetaInfo *q) :
|
||||
m_itemLibraryInfo(new ItemLibraryInfo()),
|
||||
m_q(q),
|
||||
m_isInitialized(false)
|
||||
{
|
||||
if (!m_q->isGlobal())
|
||||
m_itemLibraryInfo = ItemLibraryInfo::createItemLibraryInfo(m_q->global().itemLibraryInfo());
|
||||
m_itemLibraryInfo->setBaseInfo(MetaInfo::global().itemLibraryInfo());
|
||||
}
|
||||
|
||||
void MetaInfoPrivate::clear()
|
||||
@@ -102,7 +103,7 @@ void MetaInfoPrivate::clear()
|
||||
m_superClassHash.clear();
|
||||
m_nodeMetaInfoHash.clear();
|
||||
m_enumeratorMetaInfoHash.clear();
|
||||
m_itemLibraryInfo.clearEntries();
|
||||
m_itemLibraryInfo->clearEntries();
|
||||
m_isInitialized = false;
|
||||
}
|
||||
|
||||
@@ -534,9 +535,9 @@ EnumeratorMetaInfo MetaInfo::enumerator(const QString &enumeratorName) const
|
||||
return EnumeratorMetaInfo();
|
||||
}
|
||||
|
||||
ItemLibraryInfo MetaInfo::itemLibraryInfo() const
|
||||
ItemLibraryInfo *MetaInfo::itemLibraryInfo() const
|
||||
{
|
||||
return m_p->m_itemLibraryInfo;
|
||||
return m_p->m_itemLibraryInfo.data();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -609,8 +610,8 @@ void MetaInfo::removeNodeInfo(NodeMetaInfo &info)
|
||||
m_p->m_superClassHash.remove(info.typeName());
|
||||
// TODO: Other types might specify type as parent type
|
||||
foreach (const ItemLibraryEntry &entry,
|
||||
m_p->m_itemLibraryInfo.entriesForType(info.typeName(), info.majorVersion(), info.minorVersion())) {
|
||||
m_p->m_itemLibraryInfo.removeEntry(entry.name());
|
||||
m_p->m_itemLibraryInfo->entriesForType(info.typeName(), info.majorVersion(), info.minorVersion())) {
|
||||
m_p->m_itemLibraryInfo->removeEntry(entry.name());
|
||||
}
|
||||
|
||||
} else if (!isGlobal()) {
|
||||
|
||||
@@ -218,7 +218,7 @@ void MetaInfoParser::handleNodeItemLibraryEntryElement(QXmlStreamReader &reader,
|
||||
handleItemLibraryEntryPropertyElement(reader, entry);
|
||||
}
|
||||
|
||||
m_metaInfo.itemLibraryInfo().addEntry(entry);
|
||||
m_metaInfo.itemLibraryInfo()->addEntry(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ void SubComponentManagerPrivate::registerQmlFile(const QFileInfo &fileInfo, cons
|
||||
itemLibraryEntry.setType(nodeInfo.typeName(), nodeInfo.majorVersion(), nodeInfo.minorVersion());
|
||||
itemLibraryEntry.setName(componentName);
|
||||
itemLibraryEntry.setCategory(tr("QML Components"));
|
||||
m_metaInfo.itemLibraryInfo().addEntry(itemLibraryEntry);
|
||||
m_metaInfo.itemLibraryInfo()->addEntry(itemLibraryEntry);
|
||||
|
||||
m_metaInfo.addNodeInfo(nodeInfo, baseType);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user