forked from qt-creator/qt-creator
Qml-C++: Find C++ qmlRegisterType calls and populate QML code model.
Reviewed-by: Erik Verbruggen
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <cplusplus/ModelManagerInterface.h>
|
||||
#include <qmljs/qmljsinterpreter.h>
|
||||
#include <qmljs/qmljsbind.h>
|
||||
#include <qmljs/parser/qmldirparser_p.h>
|
||||
@@ -56,6 +57,7 @@
|
||||
#include <qtconcurrent/runextensions.h>
|
||||
#include <QTextStream>
|
||||
#include <QCoreApplication>
|
||||
#include <QTimer>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@@ -72,6 +74,11 @@ ModelManager::ModelManager(QObject *parent):
|
||||
{
|
||||
m_synchronizer.setCancelOnWait(true);
|
||||
|
||||
m_updateCppQmlTypesTimer = new QTimer(this);
|
||||
m_updateCppQmlTypesTimer->setInterval(1000);
|
||||
m_updateCppQmlTypesTimer->setSingleShot(true);
|
||||
connect(m_updateCppQmlTypesTimer, SIGNAL(timeout()), SLOT(updateCppQmlTypes()));
|
||||
|
||||
qRegisterMetaType<QmlJS::Document::Ptr>("QmlJS::Document::Ptr");
|
||||
qRegisterMetaType<QmlJS::LibraryInfo>("QmlJS::LibraryInfo");
|
||||
|
||||
@@ -81,6 +88,16 @@ ModelManager::ModelManager(QObject *parent):
|
||||
updateImportPaths();
|
||||
}
|
||||
|
||||
void ModelManager::delayedInitialization()
|
||||
{
|
||||
CPlusPlus::CppModelManagerInterface *cppModelManager =
|
||||
CPlusPlus::CppModelManagerInterface::instance();
|
||||
if (cppModelManager) {
|
||||
connect(cppModelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
|
||||
m_updateCppQmlTypesTimer, SLOT(start()));
|
||||
}
|
||||
}
|
||||
|
||||
void ModelManager::loadQmlTypeDescriptions()
|
||||
{
|
||||
if (Core::ICore::instance()) {
|
||||
@@ -537,3 +554,16 @@ void ModelManager::loadPluginTypes(const QString &libraryPath, const QString &im
|
||||
{
|
||||
m_pluginDumper->loadPluginTypes(libraryPath, importPath, importUri);
|
||||
}
|
||||
|
||||
void ModelManager::updateCppQmlTypes()
|
||||
{
|
||||
CPlusPlus::CppModelManagerInterface *cppModelManager =
|
||||
CPlusPlus::CppModelManagerInterface::instance();
|
||||
if (!cppModelManager)
|
||||
return;
|
||||
|
||||
QList<const LanguageUtils::FakeMetaObject *> constFMOs;
|
||||
foreach (LanguageUtils::FakeMetaObject *fmo, cppModelManager->exportedQmlObjects())
|
||||
constFMOs.append(fmo);
|
||||
Interpreter::CppQmlTypesLoader::cppObjects = constFMOs;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
#include <QMutex>
|
||||
#include <QProcess>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QTimer)
|
||||
|
||||
namespace Core {
|
||||
class ICore;
|
||||
class MimeType;
|
||||
@@ -61,6 +63,8 @@ class QMLJSTOOLS_EXPORT ModelManager: public QmlJS::ModelManagerInterface
|
||||
public:
|
||||
ModelManager(QObject *parent = 0);
|
||||
|
||||
void delayedInitialization();
|
||||
|
||||
virtual WorkingCopy workingCopy() const;
|
||||
virtual QmlJS::Snapshot snapshot() const;
|
||||
|
||||
@@ -99,6 +103,9 @@ protected:
|
||||
|
||||
void updateImportPaths();
|
||||
|
||||
private slots:
|
||||
void updateCppQmlTypes();
|
||||
|
||||
private:
|
||||
static bool matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType);
|
||||
|
||||
@@ -109,6 +116,7 @@ private:
|
||||
QStringList m_defaultImportPaths;
|
||||
|
||||
QFutureSynchronizer<void> m_synchronizer;
|
||||
QTimer *m_updateCppQmlTypesTimer;
|
||||
|
||||
// project integration
|
||||
QMap<ProjectExplorer::Project *, ProjectInfo> m_projects;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
include($$IDE_SOURCE_TREE/src/libs/languageutils/languageutils.pri)
|
||||
include($$IDE_SOURCE_TREE/src/libs/cplusplus/cplusplus.pri)
|
||||
include($$IDE_SOURCE_TREE/src/libs/qmljs/qmljs.pri)
|
||||
include($$IDE_SOURCE_TREE/src/plugins/projectexplorer/projectexplorer.pri)
|
||||
include($$IDE_SOURCE_TREE/src/plugins/texteditor/texteditor.pri)
|
||||
|
||||
@@ -89,6 +89,7 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
|
||||
void QmlJSToolsPlugin::extensionsInitialized()
|
||||
{
|
||||
m_modelManager->delayedInitialization();
|
||||
}
|
||||
|
||||
ExtensionSystem::IPlugin::ShutdownFlag QmlJSToolsPlugin::aboutToShutdown()
|
||||
|
||||
Reference in New Issue
Block a user