QmlJSPlugin: reorganize setup

Pimpl, remove use of global object pool, cosmetics, ...

Change-Id: I9e1415b07d7ff8e95db0998c87ce7d75ca638a8e
Reviewed-by: Marco Benelli <marco.benelli@qt.io>
This commit is contained in:
hjk
2018-02-08 10:40:29 +01:00
parent 5efd576020
commit 4248c53c79
8 changed files with 53 additions and 87 deletions

View File

@@ -36,8 +36,7 @@ using namespace QmlJSTools::Internal;
using namespace QmlJS;
using namespace QmlJS::AST;
LocatorData::LocatorData(QObject *parent)
: QObject(parent)
LocatorData::LocatorData()
{
ModelManagerInterface *manager = ModelManagerInterface::instance();

View File

@@ -38,7 +38,7 @@ class LocatorData : public QObject
{
Q_OBJECT
public:
explicit LocatorData(QObject *parent = 0);
LocatorData();
~LocatorData();
enum EntryType

View File

@@ -206,8 +206,7 @@ QHash<QString,Dialect> ModelManager::languageForSuffix() const
return res;
}
ModelManager::ModelManager(QObject *parent):
ModelManagerInterface(parent)
ModelManager::ModelManager()
{
qRegisterMetaType<QmlJSTools::SemanticInfo>("QmlJSTools::SemanticInfo");
loadDefaultQmlTypeDescriptions();

View File

@@ -46,7 +46,7 @@ class QMLJSTOOLS_EXPORT ModelManager: public QmlJS::ModelManagerInterface
Q_OBJECT
public:
ModelManager(QObject *parent = 0);
ModelManager();
~ModelManager() override;
void delayedInitialization();

View File

@@ -39,27 +39,34 @@
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <QtPlugin>
#include <QMenu>
using namespace Core;
using namespace QmlJSTools;
using namespace QmlJSTools::Internal;
namespace QmlJSTools {
namespace Internal {
enum { debug = 0 };
QmlJSToolsPlugin *QmlJSToolsPlugin::m_instance = 0;
QmlJSToolsPlugin::QmlJSToolsPlugin()
: m_modelManager(0)
class QmlJSToolsPluginPrivate : public QObject
{
m_instance = this;
}
public:
QmlJSToolsPluginPrivate();
QmlJSToolsSettings settings;
ModelManager modelManager;
QAction resetCodeModelAction{QmlJSToolsPlugin::tr("Reset Code Model"), nullptr};
LocatorData locatorData;
FunctionFilter functionFilter{&locatorData};
QmlJSCodeStyleSettingsPage codeStyleSettingsPage;
BasicBundleProvider basicBundleProvider;
};
QmlJSToolsPlugin::~QmlJSToolsPlugin()
{
m_instance = 0;
m_modelManager = 0; // deleted automatically
delete d;
}
bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
@@ -67,67 +74,53 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
Q_UNUSED(arguments)
Q_UNUSED(error)
m_settings = new QmlJSToolsSettings(this); // force registration of qmljstools settings
d = new QmlJSToolsPluginPrivate;
// Objects
m_modelManager = new ModelManager(this);
return true;
}
QmlJSToolsPluginPrivate::QmlJSToolsPluginPrivate()
{
// Core::VcsManager *vcsManager = Core::VcsManager::instance();
// Core::DocumentManager *documentManager = Core::DocumentManager::instance();
// connect(vcsManager, &Core::VcsManager::repositoryChanged,
// m_modelManager, &ModelManager::updateModifiedSourceFiles);
// &d->modelManager, &ModelManager::updateModifiedSourceFiles);
// connect(documentManager, &DocumentManager::filesChangedInternally,
// m_modelManager, &ModelManager::updateSourceFiles);
LocatorData *locatorData = new LocatorData;
addAutoReleasedObject(locatorData);
addAutoReleasedObject(new FunctionFilter(locatorData));
addAutoReleasedObject(new QmlJSCodeStyleSettingsPage);
addAutoReleasedObject(new BasicBundleProvider);
// &d->modelManager, &ModelManager::updateSourceFiles);
// Menus
ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS);
ActionContainer *mqmljstools = ActionManager::createMenu(Constants::M_TOOLS_QMLJS);
QMenu *menu = mqmljstools->menu();
menu->setTitle(tr("&QML/JS"));
menu->setTitle(QmlJSToolsPlugin::tr("&QML/JS"));
menu->setEnabled(true);
mtools->addMenu(mqmljstools);
// Update context in global context
m_resetCodeModelAction = new QAction(tr("Reset Code Model"), this);
Command *cmd = ActionManager::registerAction(
m_resetCodeModelAction, Constants::RESET_CODEMODEL);
connect(m_resetCodeModelAction, &QAction::triggered,
m_modelManager, &ModelManager::resetCodeModel);
&resetCodeModelAction, Constants::RESET_CODEMODEL);
connect(&resetCodeModelAction, &QAction::triggered,
&modelManager, &ModelManager::resetCodeModel);
mqmljstools->addAction(cmd);
// watch task progress
connect(ProgressManager::instance(), &ProgressManager::taskStarted,
this, &QmlJSToolsPlugin::onTaskStarted);
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
this, &QmlJSToolsPlugin::onAllTasksFinished);
// Watch task progress
connect(ProgressManager::instance(), &ProgressManager::taskStarted, this,
[this](Core::Id type) {
if (type == QmlJS::Constants::TASK_INDEX)
resetCodeModelAction.setEnabled(false);
});
return true;
connect(ProgressManager::instance(), &ProgressManager::allTasksFinished,
[this](Core::Id type) {
if (type == QmlJS::Constants::TASK_INDEX)
resetCodeModelAction.setEnabled(true);
});
}
void QmlJSToolsPlugin::extensionsInitialized()
{
m_modelManager->delayedInitialization();
d->modelManager.delayedInitialization();
}
ExtensionSystem::IPlugin::ShutdownFlag QmlJSToolsPlugin::aboutToShutdown()
{
return SynchronousShutdown;
}
void QmlJSToolsPlugin::onTaskStarted(Id type)
{
if (type == QmlJS::Constants::TASK_INDEX)
m_resetCodeModelAction->setEnabled(false);
}
void QmlJSToolsPlugin::onAllTasksFinished(Id type)
{
if (type == QmlJS::Constants::TASK_INDEX)
m_resetCodeModelAction->setEnabled(true);
}
} // Internal
} // QmlJSTools

View File

@@ -25,48 +25,24 @@
#pragma once
#include <coreplugin/id.h>
#include <extensionsystem/iplugin.h>
QT_BEGIN_NAMESPACE
class QFileInfo;
class QDir;
class QAction;
QT_END_NAMESPACE
namespace QmlJSTools {
class QmlJSToolsSettings;
namespace Internal {
class ModelManager;
class QmlJSToolsPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "QmlJSTools.json")
public:
static QmlJSToolsPlugin *instance() { return m_instance; }
QmlJSToolsPlugin();
~QmlJSToolsPlugin();
bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized();
ShutdownFlag aboutToShutdown();
ModelManager *modelManager() { return m_modelManager; }
~QmlJSToolsPlugin() final;
private:
void onTaskStarted(Core::Id type);
void onAllTasksFinished(Core::Id type);
bool initialize(const QStringList &arguments, QString *errorMessage) final;
void extensionsInitialized() final;
ModelManager *m_modelManager;
QmlJSToolsSettings *m_settings;
QAction *m_resetCodeModelAction;
static QmlJSToolsPlugin *m_instance;
class QmlJSToolsPluginPrivate *d = nullptr;
#ifdef WITH_TESTS
private slots:

View File

@@ -46,8 +46,7 @@ const char idKey[] = "QmlJSGlobal";
static SimpleCodeStylePreferences *m_globalCodeStyle = 0;
QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
: QObject(parent)
QmlJSToolsSettings::QmlJSToolsSettings()
{
QTC_ASSERT(!m_globalCodeStyle, return);

View File

@@ -41,7 +41,7 @@ class QMLJSTOOLS_EXPORT QmlJSToolsSettings : public QObject
Q_OBJECT
public:
explicit QmlJSToolsSettings(QObject *parent);
explicit QmlJSToolsSettings();
~QmlJSToolsSettings();
static TextEditor::SimpleCodeStylePreferences *globalCodeStyle();