forked from qt-creator/qt-creator
QmlDesigner: Bind meta info cache to model
A global variable is not helping for multithreading and the cache has anyway a 1:1 relationshit to the model. Change-Id: Ic05f32744b70ef63aa5ae7d475afc0b5b17f2f09 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -579,7 +579,7 @@ void DesignDocument::paste()
|
|||||||
}
|
}
|
||||||
view.setSelectedModelNodes({pastedNode});
|
view.setSelectedModelNodes({pastedNode});
|
||||||
});
|
});
|
||||||
NodeMetaInfo::clearCache();
|
view.model()->clearMetaInfoCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,6 +43,7 @@ namespace QmlDesigner {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
class ModelPrivate;
|
class ModelPrivate;
|
||||||
class WriteLocker;
|
class WriteLocker;
|
||||||
|
class NodeMetaInfoPrivate;
|
||||||
} //Internal
|
} //Internal
|
||||||
|
|
||||||
class AnchorLine;
|
class AnchorLine;
|
||||||
@@ -68,6 +69,7 @@ class QMLDESIGNERCORE_EXPORT Model : public QObject
|
|||||||
friend class QmlDesigner::AbstractView;
|
friend class QmlDesigner::AbstractView;
|
||||||
friend class Internal::ModelPrivate;
|
friend class Internal::ModelPrivate;
|
||||||
friend class Internal::WriteLocker;
|
friend class Internal::WriteLocker;
|
||||||
|
friend class QmlDesigner::Internal::NodeMetaInfoPrivate;
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -118,6 +120,8 @@ public:
|
|||||||
|
|
||||||
QList<ModelNode> selectedNodes(AbstractView *view) const;
|
QList<ModelNode> selectedNodes(AbstractView *view) const;
|
||||||
|
|
||||||
|
void clearMetaInfoCache();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Model();
|
Model();
|
||||||
|
|
||||||
|
@@ -107,8 +107,6 @@ public:
|
|||||||
|
|
||||||
QString importDirectoryPath() const;
|
QString importDirectoryPath() const;
|
||||||
|
|
||||||
static void clearCache();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<Internal::NodeMetaInfoPrivate> m_privateData;
|
QSharedPointer<Internal::NodeMetaInfoPrivate> m_privateData;
|
||||||
};
|
};
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "nodemetainfo.h"
|
#include "nodemetainfo.h"
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
#include "model/model_p.h"
|
||||||
|
|
||||||
#include "metainfo.h"
|
#include "metainfo.h"
|
||||||
#include <enumeration.h>
|
#include <enumeration.h>
|
||||||
@@ -620,8 +621,6 @@ public:
|
|||||||
QSet<QByteArray> &prototypeCachePositives();
|
QSet<QByteArray> &prototypeCachePositives();
|
||||||
QSet<QByteArray> &prototypeCacheNegatives();
|
QSet<QByteArray> &prototypeCacheNegatives();
|
||||||
|
|
||||||
static void clearCache();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NodeMetaInfoPrivate(Model *model, TypeName type, int maj = -1, int min = -1);
|
NodeMetaInfoPrivate(Model *model, TypeName type, int maj = -1, int min = -1);
|
||||||
|
|
||||||
@@ -657,13 +656,10 @@ private:
|
|||||||
const Document *document() const;
|
const Document *document() const;
|
||||||
|
|
||||||
QPointer<Model> m_model;
|
QPointer<Model> m_model;
|
||||||
static QHash<TypeName, Pointer> m_nodeMetaInfoCache;
|
|
||||||
const ObjectValue *m_objectValue = nullptr;
|
const ObjectValue *m_objectValue = nullptr;
|
||||||
bool m_propertiesSetup = false;
|
bool m_propertiesSetup = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
QHash<TypeName, NodeMetaInfoPrivate::Pointer> NodeMetaInfoPrivate::m_nodeMetaInfoCache;
|
|
||||||
|
|
||||||
bool NodeMetaInfoPrivate::isFileComponent() const
|
bool NodeMetaInfoPrivate::isFileComponent() const
|
||||||
{
|
{
|
||||||
return m_isFileComponent;
|
return m_isFileComponent;
|
||||||
@@ -705,11 +701,6 @@ QSet<QByteArray> &NodeMetaInfoPrivate::prototypeCacheNegatives()
|
|||||||
return m_prototypeCacheNegatives;
|
return m_prototypeCacheNegatives;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeMetaInfoPrivate::clearCache()
|
|
||||||
{
|
|
||||||
m_nodeMetaInfoCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyName NodeMetaInfoPrivate::defaultPropertyName() const
|
PropertyName NodeMetaInfoPrivate::defaultPropertyName() const
|
||||||
{
|
{
|
||||||
if (!m_defaultPropertyName.isEmpty())
|
if (!m_defaultPropertyName.isEmpty())
|
||||||
@@ -724,17 +715,12 @@ static inline TypeName stringIdentifier( const TypeName &type, int maj, int min)
|
|||||||
|
|
||||||
NodeMetaInfoPrivate::Pointer NodeMetaInfoPrivate::create(Model *model, const TypeName &type, int major, int minor)
|
NodeMetaInfoPrivate::Pointer NodeMetaInfoPrivate::create(Model *model, const TypeName &type, int major, int minor)
|
||||||
{
|
{
|
||||||
if (m_nodeMetaInfoCache.contains(stringIdentifier(type, major, minor))) {
|
if (model->d->m_nodeMetaInfoCache.contains(stringIdentifier(type, major, minor)))
|
||||||
const Pointer &info = m_nodeMetaInfoCache.value(stringIdentifier(type, major, minor));
|
return model->d->m_nodeMetaInfoCache.value(stringIdentifier(type, major, minor));
|
||||||
if (info->model() == model)
|
|
||||||
return info;
|
|
||||||
else
|
|
||||||
m_nodeMetaInfoCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
Pointer newData(new NodeMetaInfoPrivate(model, type, major, minor));
|
Pointer newData(new NodeMetaInfoPrivate(model, type, major, minor));
|
||||||
if (newData->isValid())
|
if (newData->isValid())
|
||||||
m_nodeMetaInfoCache.insert(stringIdentifier(type, major, minor), newData);
|
model->d->m_nodeMetaInfoCache.insert(stringIdentifier(type, major, minor), newData);
|
||||||
return newData;
|
return newData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1671,11 +1657,6 @@ bool NodeMetaInfo::isQmlItem() const
|
|||||||
|| isSubclassOf("QtQml.QtObject");
|
|| isSubclassOf("QtQml.QtObject");
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeMetaInfo::clearCache()
|
|
||||||
{
|
|
||||||
Internal::NodeMetaInfoPrivate::clearCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NodeMetaInfo::isLayoutable() const
|
bool NodeMetaInfo::isLayoutable() const
|
||||||
{
|
{
|
||||||
if (isSubclassOf("<cpp>.QDeclarativeBasePositioner"))
|
if (isSubclassOf("<cpp>.QDeclarativeBasePositioner"))
|
||||||
|
@@ -161,7 +161,7 @@ void ModelPrivate::notifyImportsChanged(const QList<Import> &addedImports, const
|
|||||||
resetModel = true;
|
resetModel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeMetaInfo::clearCache();
|
m_nodeMetaInfoCache.clear();
|
||||||
|
|
||||||
if (nodeInstanceView())
|
if (nodeInstanceView())
|
||||||
nodeInstanceView()->importsChanged(addedImports, removedImports);
|
nodeInstanceView()->importsChanged(addedImports, removedImports);
|
||||||
@@ -2080,6 +2080,11 @@ QList<ModelNode> Model::selectedNodes(AbstractView *view) const
|
|||||||
return d->toModelNodeList(d->selectedNodes(), view);
|
return d->toModelNodeList(d->selectedNodes(), view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model::clearMetaInfoCache()
|
||||||
|
{
|
||||||
|
d->m_nodeMetaInfoCache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Returns the URL against which relative URLs within the model should be resolved.
|
\brief Returns the URL against which relative URLs within the model should be resolved.
|
||||||
\return The base URL.
|
\return The base URL.
|
||||||
|
@@ -85,6 +85,7 @@ class ModelPrivate : public QObject {
|
|||||||
|
|
||||||
friend class QmlDesigner::Model;
|
friend class QmlDesigner::Model;
|
||||||
friend class QmlDesigner::Internal::WriteLocker;
|
friend class QmlDesigner::Internal::WriteLocker;
|
||||||
|
friend class QmlDesigner::Internal::NodeMetaInfoPrivate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModelPrivate(Model *model);
|
ModelPrivate(Model *model);
|
||||||
@@ -268,6 +269,7 @@ private:
|
|||||||
QPointer<NodeInstanceView> m_nodeInstanceView;
|
QPointer<NodeInstanceView> m_nodeInstanceView;
|
||||||
QPointer<TextModifier> m_textModifier;
|
QPointer<TextModifier> m_textModifier;
|
||||||
QPointer<Model> m_metaInfoProxyModel;
|
QPointer<Model> m_metaInfoProxyModel;
|
||||||
|
QHash<TypeName, QSharedPointer<NodeMetaInfoPrivate>> m_nodeMetaInfoCache;
|
||||||
bool m_writeLock;
|
bool m_writeLock;
|
||||||
qint32 m_internalIdCounter;
|
qint32 m_internalIdCounter;
|
||||||
};
|
};
|
||||||
|
@@ -989,7 +989,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
|
|||||||
m_rewriterView->setIncompleteTypeInformation(false);
|
m_rewriterView->setIncompleteTypeInformation(false);
|
||||||
|
|
||||||
// maybe the project environment (kit, ...) changed, so we need to clean old caches
|
// maybe the project environment (kit, ...) changed, so we need to clean old caches
|
||||||
NodeMetaInfo::clearCache();
|
m_rewriterView->model()->clearMetaInfoCache();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Snapshot snapshot = m_rewriterView->textModifier()->qmljsSnapshot();
|
Snapshot snapshot = m_rewriterView->textModifier()->qmljsSnapshot();
|
||||||
|
Reference in New Issue
Block a user