From 9c1cb774a155c72e8f8d08663d67120fa7b2c57b Mon Sep 17 00:00:00 2001 From: Christian Kamm <christian.d.kamm@nokia.com> Date: Tue, 30 Aug 2011 09:19:56 +0200 Subject: [PATCH] QmlJS: Improve ModelManagerInterface API, add docs. Change-Id: Ic65d767cbad85de89dffaac66d9e80d8d467f04a Reviewed-on: http://codereview.qt.nokia.com/3851 Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com> --- src/libs/qmljs/qmljsmodelmanagerinterface.cpp | 18 ++++++++++++++++++ src/libs/qmljs/qmljsmodelmanagerinterface.h | 4 +++- src/plugins/qmljseditor/qmltaskmanager.cpp | 2 +- src/plugins/qmljstools/qmljsmodelmanager.cpp | 12 +++++++----- src/plugins/qmljstools/qmljsmodelmanager.h | 3 ++- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index fb43abc65a9..96aac5619d1 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -34,6 +34,24 @@ using namespace QmlJS; +/*! + \class QmlJS::ModelManagerInterface + \brief Interface to the global state of the QmlJS code model. + \sa QmlJS::Document QmlJS::Snapshot QmlJSTools::Internal::ModelManager + + The ModelManagerInterface is an interface for global state and actions in + the QmlJS code model. It is implemented by \l{QmlJSTools::Internal::ModelManager} + and the instance can be accessed through ModelManagerInterface::instance(). + + One of its primary concerns is to keep the Snapshots it + maintains up to date by parsing documents and finding QML modules. + + It has a Snapshot that contains only valid Documents, + accessible through ModelManagerInterface::snapshot() and a Snapshot with + potentially more recent, but invalid documents that is exposed through + ModelManagerInterface::newestSnapshot(). +*/ + static ModelManagerInterface *g_instance = 0; ModelManagerInterface::ModelManagerInterface(QObject *parent) diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.h b/src/libs/qmljs/qmljsmodelmanagerinterface.h index 17530e43593..c021341e5d6 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.h +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.h @@ -119,7 +119,9 @@ public: static ModelManagerInterface *instance(); virtual WorkingCopy workingCopy() const = 0; - virtual QmlJS::Snapshot snapshot(bool preferValid = true) const = 0; + + virtual QmlJS::Snapshot snapshot() const = 0; + virtual QmlJS::Snapshot newestSnapshot() const = 0; virtual void updateSourceFiles(const QStringList &files, bool emitDocumentOnDiskChanged) = 0; diff --git a/src/plugins/qmljseditor/qmltaskmanager.cpp b/src/plugins/qmljseditor/qmltaskmanager.cpp index 93e17201cfd..2a59adc8f6f 100644 --- a/src/plugins/qmljseditor/qmltaskmanager.cpp +++ b/src/plugins/qmljseditor/qmltaskmanager.cpp @@ -153,7 +153,7 @@ void QmlTaskManager::updateMessagesNow(bool updateSemantic) // process them QFuture<FileErrorMessages> future = QtConcurrent::run<FileErrorMessages>( - &collectMessages, modelManager->snapshot(false), modelManager->projectInfos(), + &collectMessages, modelManager->newestSnapshot(), modelManager->projectInfos(), modelManager->importPaths(), updateSemantic); m_messageCollector.setFuture(future); } diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp index 545761ad7e1..bc4c1cfc94d 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.cpp +++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp @@ -170,14 +170,16 @@ ModelManagerInterface::WorkingCopy ModelManager::workingCopy() const return workingCopy; } -Snapshot ModelManager::snapshot(bool preferValid) const +Snapshot ModelManager::snapshot() const { QMutexLocker locker(&m_mutex); + return _validSnapshot; +} - if (preferValid) - return _validSnapshot; - else - return _newestSnapshot; +Snapshot ModelManager::newestSnapshot() const +{ + QMutexLocker locker(&m_mutex); + return _newestSnapshot; } void ModelManager::updateSourceFiles(const QStringList &files, diff --git a/src/plugins/qmljstools/qmljsmodelmanager.h b/src/plugins/qmljstools/qmljsmodelmanager.h index 0a8c26fdbd1..a6803a008ff 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.h +++ b/src/plugins/qmljstools/qmljsmodelmanager.h @@ -69,7 +69,8 @@ public: void delayedInitialization(); virtual WorkingCopy workingCopy() const; - virtual QmlJS::Snapshot snapshot(bool preferValid = true) const; + virtual QmlJS::Snapshot snapshot() const; + virtual QmlJS::Snapshot newestSnapshot() const; virtual void updateSourceFiles(const QStringList &files, bool emitDocumentOnDiskChanged); -- GitLab