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});
|
||||
});
|
||||
NodeMetaInfo::clearCache();
|
||||
view.model()->clearMetaInfoCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -43,6 +43,7 @@ namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
class ModelPrivate;
|
||||
class WriteLocker;
|
||||
class NodeMetaInfoPrivate;
|
||||
} //Internal
|
||||
|
||||
class AnchorLine;
|
||||
@@ -68,6 +69,7 @@ class QMLDESIGNERCORE_EXPORT Model : public QObject
|
||||
friend class QmlDesigner::AbstractView;
|
||||
friend class Internal::ModelPrivate;
|
||||
friend class Internal::WriteLocker;
|
||||
friend class QmlDesigner::Internal::NodeMetaInfoPrivate;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
@@ -118,6 +120,8 @@ public:
|
||||
|
||||
QList<ModelNode> selectedNodes(AbstractView *view) const;
|
||||
|
||||
void clearMetaInfoCache();
|
||||
|
||||
protected:
|
||||
Model();
|
||||
|
||||
|
@@ -107,8 +107,6 @@ public:
|
||||
|
||||
QString importDirectoryPath() const;
|
||||
|
||||
static void clearCache();
|
||||
|
||||
private:
|
||||
QSharedPointer<Internal::NodeMetaInfoPrivate> m_privateData;
|
||||
};
|
||||
|
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "nodemetainfo.h"
|
||||
#include "model.h"
|
||||
#include "model/model_p.h"
|
||||
|
||||
#include "metainfo.h"
|
||||
#include <enumeration.h>
|
||||
@@ -620,8 +621,6 @@ public:
|
||||
QSet<QByteArray> &prototypeCachePositives();
|
||||
QSet<QByteArray> &prototypeCacheNegatives();
|
||||
|
||||
static void clearCache();
|
||||
|
||||
private:
|
||||
NodeMetaInfoPrivate(Model *model, TypeName type, int maj = -1, int min = -1);
|
||||
|
||||
@@ -657,13 +656,10 @@ private:
|
||||
const Document *document() const;
|
||||
|
||||
QPointer<Model> m_model;
|
||||
static QHash<TypeName, Pointer> m_nodeMetaInfoCache;
|
||||
const ObjectValue *m_objectValue = nullptr;
|
||||
bool m_propertiesSetup = false;
|
||||
};
|
||||
|
||||
QHash<TypeName, NodeMetaInfoPrivate::Pointer> NodeMetaInfoPrivate::m_nodeMetaInfoCache;
|
||||
|
||||
bool NodeMetaInfoPrivate::isFileComponent() const
|
||||
{
|
||||
return m_isFileComponent;
|
||||
@@ -705,11 +701,6 @@ QSet<QByteArray> &NodeMetaInfoPrivate::prototypeCacheNegatives()
|
||||
return m_prototypeCacheNegatives;
|
||||
}
|
||||
|
||||
void NodeMetaInfoPrivate::clearCache()
|
||||
{
|
||||
m_nodeMetaInfoCache.clear();
|
||||
}
|
||||
|
||||
PropertyName NodeMetaInfoPrivate::defaultPropertyName() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (m_nodeMetaInfoCache.contains(stringIdentifier(type, major, minor))) {
|
||||
const Pointer &info = m_nodeMetaInfoCache.value(stringIdentifier(type, major, minor));
|
||||
if (info->model() == model)
|
||||
return info;
|
||||
else
|
||||
m_nodeMetaInfoCache.clear();
|
||||
}
|
||||
if (model->d->m_nodeMetaInfoCache.contains(stringIdentifier(type, major, minor)))
|
||||
return model->d->m_nodeMetaInfoCache.value(stringIdentifier(type, major, minor));
|
||||
|
||||
Pointer newData(new NodeMetaInfoPrivate(model, type, major, minor));
|
||||
if (newData->isValid())
|
||||
m_nodeMetaInfoCache.insert(stringIdentifier(type, major, minor), newData);
|
||||
model->d->m_nodeMetaInfoCache.insert(stringIdentifier(type, major, minor), newData);
|
||||
return newData;
|
||||
}
|
||||
|
||||
@@ -1671,11 +1657,6 @@ bool NodeMetaInfo::isQmlItem() const
|
||||
|| isSubclassOf("QtQml.QtObject");
|
||||
}
|
||||
|
||||
void NodeMetaInfo::clearCache()
|
||||
{
|
||||
Internal::NodeMetaInfoPrivate::clearCache();
|
||||
}
|
||||
|
||||
bool NodeMetaInfo::isLayoutable() const
|
||||
{
|
||||
if (isSubclassOf("<cpp>.QDeclarativeBasePositioner"))
|
||||
|
@@ -161,7 +161,7 @@ void ModelPrivate::notifyImportsChanged(const QList<Import> &addedImports, const
|
||||
resetModel = true;
|
||||
}
|
||||
|
||||
NodeMetaInfo::clearCache();
|
||||
m_nodeMetaInfoCache.clear();
|
||||
|
||||
if (nodeInstanceView())
|
||||
nodeInstanceView()->importsChanged(addedImports, removedImports);
|
||||
@@ -2080,6 +2080,11 @@ QList<ModelNode> Model::selectedNodes(AbstractView *view) const
|
||||
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.
|
||||
\return The base URL.
|
||||
|
@@ -85,6 +85,7 @@ class ModelPrivate : public QObject {
|
||||
|
||||
friend class QmlDesigner::Model;
|
||||
friend class QmlDesigner::Internal::WriteLocker;
|
||||
friend class QmlDesigner::Internal::NodeMetaInfoPrivate;
|
||||
|
||||
public:
|
||||
ModelPrivate(Model *model);
|
||||
@@ -268,6 +269,7 @@ private:
|
||||
QPointer<NodeInstanceView> m_nodeInstanceView;
|
||||
QPointer<TextModifier> m_textModifier;
|
||||
QPointer<Model> m_metaInfoProxyModel;
|
||||
QHash<TypeName, QSharedPointer<NodeMetaInfoPrivate>> m_nodeMetaInfoCache;
|
||||
bool m_writeLock;
|
||||
qint32 m_internalIdCounter;
|
||||
};
|
||||
|
@@ -989,7 +989,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
|
||||
m_rewriterView->setIncompleteTypeInformation(false);
|
||||
|
||||
// maybe the project environment (kit, ...) changed, so we need to clean old caches
|
||||
NodeMetaInfo::clearCache();
|
||||
m_rewriterView->model()->clearMetaInfoCache();
|
||||
|
||||
try {
|
||||
Snapshot snapshot = m_rewriterView->textModifier()->qmljsSnapshot();
|
||||
|
Reference in New Issue
Block a user