GenericProject: Pimpl and remove uses of global object pool

Change-Id: I2020ab5a72af9dfce5393fa3f91755f914a9e021
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2018-02-02 14:17:52 +01:00
parent 6cfde4c2ed
commit a2d6dc65ff
2 changed files with 41 additions and 30 deletions

View File

@@ -46,8 +46,6 @@
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <QAction> #include <QAction>
#include <QtPlugin>
#include <QDebug>
using namespace Core; using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -55,43 +53,56 @@ using namespace ProjectExplorer;
namespace GenericProjectManager { namespace GenericProjectManager {
namespace Internal { namespace Internal {
bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage) class GenericProjectPluginPrivate : public QObject
{ {
Q_UNUSED(errorMessage) public:
GenericProjectPluginPrivate();
ProjectFilesFactory projectFilesFactory;
GenericMakeAllStepFactory makeAllStepFactory;
GenericMakeCleanStepFactory makeCleanStepFactory;
GenericBuildConfigurationFactory buildConfigFactory;
QAction editFilesAction{GenericProjectPluginPrivate::tr("Edit Files..."), nullptr};
};
static GenericProjectPluginPrivate *dd = nullptr;
GenericProjectPlugin::~GenericProjectPlugin()
{
delete dd;
}
bool GenericProjectPlugin::initialize(const QStringList &, QString *)
{
dd = new GenericProjectPluginPrivate;
return true;
}
GenericProjectPluginPrivate::GenericProjectPluginPrivate()
{
ProjectManager::registerProjectType<GenericProject>(Constants::GENERICMIMETYPE); ProjectManager::registerProjectType<GenericProject>(Constants::GENERICMIMETYPE);
addAutoReleasedObject(new ProjectFilesFactory); IWizardFactory::registerFactoryCreator([] { return QList<IWizardFactory *>{new GenericProjectWizard}; });
addAutoReleasedObject(new GenericMakeAllStepFactory);
addAutoReleasedObject(new GenericMakeCleanStepFactory);
addAutoReleasedObject(new GenericBuildConfigurationFactory);
IWizardFactory::registerFactoryCreator([]() { return QList<IWizardFactory *>() << new GenericProjectWizard; });
ActionContainer *mproject = ActionContainer *mproject =
ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT); ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
auto editFilesAction = new QAction(tr("Edit Files..."), this); Command *command = ActionManager::registerAction(&editFilesAction,
Command *command = ActionManager::registerAction(editFilesAction,
"GenericProjectManager.EditFiles", Context(Constants::GENERICPROJECT_ID)); "GenericProjectManager.EditFiles", Context(Constants::GENERICPROJECT_ID));
command->setAttribute(Command::CA_Hide); command->setAttribute(Command::CA_Hide);
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES); mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
connect(editFilesAction, &QAction::triggered, this, &GenericProjectPlugin::editFiles); connect(&editFilesAction, &QAction::triggered, this, [this] {
auto genericProject = qobject_cast<GenericProject *>(ProjectTree::currentProject());
return true; if (!genericProject)
} return;
SelectableFilesDialogEditFiles sfd(genericProject->projectDirectory(),
void GenericProjectPlugin::editFiles() genericProject->files(Project::AllFiles),
{ ICore::mainWindow());
auto genericProject = qobject_cast<GenericProject *>(ProjectTree::currentProject()); if (sfd.exec() == QDialog::Accepted)
if (!genericProject) genericProject->setFiles(Utils::transform(sfd.selectedFiles(), &Utils::FileName::toString));
return; });
SelectableFilesDialogEditFiles sfd(genericProject->projectDirectory(),
genericProject->files(Project::AllFiles),
ICore::mainWindow());
if (sfd.exec() == QDialog::Accepted)
genericProject->setFiles(Utils::transform(sfd.selectedFiles(), &Utils::FileName::toString));
} }
} // namespace Internal } // namespace Internal

View File

@@ -36,8 +36,7 @@ class GenericProjectPlugin : public ExtensionSystem::IPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GenericProjectManager.json") Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GenericProjectManager.json")
public: public:
bool initialize(const QStringList &arguments, QString *errorString) override; ~GenericProjectPlugin() override;
void extensionsInitialized() override { }
#ifdef WITH_TESTS #ifdef WITH_TESTS
private slots: private slots:
@@ -47,7 +46,8 @@ private slots:
#endif // WITH_TESTS #endif // WITH_TESTS
private: private:
void editFiles(); bool initialize(const QStringList &arguments, QString *errorString) override;
void extensionsInitialized() override { }
}; };
} // namespace Internal } // namespace Internal