Qmake: Modernize code

Change-Id: I4ebedb69ae91843fd096af6f4cf225ec0c76a0b2
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2016-03-10 12:21:30 +01:00
parent 5996ff0ab8
commit cdf6e499c5
4 changed files with 45 additions and 43 deletions

View File

@@ -123,17 +123,17 @@ void QmakeManager::setContextFile(ProjectExplorer::FileNode *file)
void QmakeManager::addLibrary() void QmakeManager::addLibrary()
{ {
if (auto editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor())) if (auto editor = qobject_cast<BaseTextEditor *>(Core::EditorManager::currentEditor()))
addLibrary(editor->document()->filePath().toString(), editor); addLibraryImpl(editor->document()->filePath().toString(), editor);
} }
void QmakeManager::addLibraryContextMenu() void QmakeManager::addLibraryContextMenu()
{ {
Node *node = ProjectTree::currentNode(); Node *node = ProjectTree::currentNode();
if (dynamic_cast<QmakeProFileNode *>(node)) if (dynamic_cast<QmakeProFileNode *>(node))
addLibrary(node->filePath().toString()); addLibraryImpl(node->filePath().toString(), nullptr);
} }
void QmakeManager::addLibrary(const QString &fileName, BaseTextEditor *editor) void QmakeManager::addLibraryImpl(const QString &fileName, BaseTextEditor *editor)
{ {
Internal::AddLibraryWizard wizard(fileName, Core::ICore::dialogParent()); Internal::AddLibraryWizard wizard(fileName, Core::ICore::dialogParent());
if (wizard.exec() != QDialog::Accepted) if (wizard.exec() != QDialog::Accepted)
@@ -161,15 +161,15 @@ void QmakeManager::addLibrary(const QString &fileName, BaseTextEditor *editor)
void QmakeManager::runQMake() void QmakeManager::runQMake()
{ {
runQMake(SessionManager::startupProject(), 0); runQMakeImpl(SessionManager::startupProject(), nullptr);
} }
void QmakeManager::runQMakeContextMenu() void QmakeManager::runQMakeContextMenu()
{ {
runQMake(m_contextProject, m_contextNode); runQMakeImpl(m_contextProject, m_contextNode);
} }
void QmakeManager::runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node) void QmakeManager::runQMakeImpl(ProjectExplorer::Project *p, ProjectExplorer::Node *node)
{ {
if (!ProjectExplorerPlugin::saveModifiedFiles()) if (!ProjectExplorerPlugin::saveModifiedFiles())
return; return;

View File

@@ -23,8 +23,7 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef QMAKEPROJECTMANAGER_H #pragma once
#define QMAKEPROJECTMANAGER_H
#include "qmakeprojectmanager_global.h" #include "qmakeprojectmanager_global.h"
@@ -68,7 +67,6 @@ public:
enum Action { BUILD, REBUILD, CLEAN }; enum Action { BUILD, REBUILD, CLEAN };
public slots:
void addLibrary(); void addLibrary();
void addLibraryContextMenu(); void addLibraryContextMenu();
void runQMake(); void runQMake();
@@ -86,8 +84,8 @@ private:
ProjectExplorer::Project *contextProject, ProjectExplorer::Project *contextProject,
ProjectExplorer::Node *contextNode, ProjectExplorer::Node *contextNode,
ProjectExplorer::FileNode *contextFile); ProjectExplorer::FileNode *contextFile);
void addLibrary(const QString &fileName, TextEditor::BaseTextEditor *editor = 0); void addLibraryImpl(const QString &fileName, TextEditor::BaseTextEditor *editor);
void runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node); void runQMakeImpl(ProjectExplorer::Project *p, ProjectExplorer::Node *node);
ProjectExplorer::Node *m_contextNode = nullptr; ProjectExplorer::Node *m_contextNode = nullptr;
ProjectExplorer::Project *m_contextProject = nullptr; ProjectExplorer::Project *m_contextProject = nullptr;
@@ -95,5 +93,3 @@ private:
}; };
} // namespace QmakeProjectManager } // namespace QmakeProjectManager
#endif // QMAKEPROJECTMANAGER_H

View File

@@ -135,14 +135,15 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setAttribute(Command::CA_UpdateText); command->setAttribute(Command::CA_UpdateText);
command->setDescription(m_buildSubProjectContextMenu->text()); command->setDescription(m_buildSubProjectContextMenu->text());
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD); msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(m_buildSubProjectContextMenu, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(buildSubDirContextMenu())); connect(m_buildSubProjectContextMenu, &QAction::triggered, m_qmakeProjectManager, &QmakeManager::buildSubDirContextMenu);
m_runQMakeActionContextMenu = new QAction(tr("Run qmake"), this); m_runQMakeActionContextMenu = new QAction(tr("Run qmake"), this);
command = ActionManager::registerAction(m_runQMakeActionContextMenu, Constants::RUNQMAKECONTEXTMENU, projectContext); command = ActionManager::registerAction(m_runQMakeActionContextMenu, Constants::RUNQMAKECONTEXTMENU, projectContext);
command->setAttribute(Command::CA_Hide); command->setAttribute(Command::CA_Hide);
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD); mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD); msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(m_runQMakeActionContextMenu, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(runQMakeContextMenu())); connect(m_runQMakeActionContextMenu, &QAction::triggered,
m_qmakeProjectManager, &QmakeManager::runQMakeContextMenu);
command = msubproject->addSeparator(projectContext, ProjectExplorer::Constants::G_PROJECT_BUILD, command = msubproject->addSeparator(projectContext, ProjectExplorer::Constants::G_PROJECT_BUILD,
&m_subProjectRebuildSeparator); &m_subProjectRebuildSeparator);
@@ -153,20 +154,23 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
m_rebuildSubProjectContextMenu, Constants::REBUILDSUBDIRCONTEXTMENU, projectContext); m_rebuildSubProjectContextMenu, Constants::REBUILDSUBDIRCONTEXTMENU, projectContext);
command->setAttribute(Command::CA_Hide); command->setAttribute(Command::CA_Hide);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD); msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(m_rebuildSubProjectContextMenu, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(rebuildSubDirContextMenu())); connect(m_rebuildSubProjectContextMenu, &QAction::triggered,
m_qmakeProjectManager, &QmakeManager::rebuildSubDirContextMenu);
m_cleanSubProjectContextMenu = new QAction(tr("Clean"), this); m_cleanSubProjectContextMenu = new QAction(tr("Clean"), this);
command = ActionManager::registerAction( command = ActionManager::registerAction(
m_cleanSubProjectContextMenu, Constants::CLEANSUBDIRCONTEXTMENU, projectContext); m_cleanSubProjectContextMenu, Constants::CLEANSUBDIRCONTEXTMENU, projectContext);
command->setAttribute(Command::CA_Hide); command->setAttribute(Command::CA_Hide);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD); msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
connect(m_cleanSubProjectContextMenu, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(cleanSubDirContextMenu())); connect(m_cleanSubProjectContextMenu, &QAction::triggered,
m_qmakeProjectManager, &QmakeManager::cleanSubDirContextMenu);
m_buildFileContextMenu = new QAction(tr("Build"), this); m_buildFileContextMenu = new QAction(tr("Build"), this);
command = ActionManager::registerAction(m_buildFileContextMenu, Constants::BUILDFILECONTEXTMENU, projectContext); command = ActionManager::registerAction(m_buildFileContextMenu, Constants::BUILDFILECONTEXTMENU, projectContext);
command->setAttribute(Command::CA_Hide); command->setAttribute(Command::CA_Hide);
mfile->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER); mfile->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER);
connect(m_buildFileContextMenu, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(buildFileContextMenu())); connect(m_buildFileContextMenu, &QAction::triggered,
m_qmakeProjectManager, &QmakeManager::buildFileContextMenu);
m_buildSubProjectAction = new Utils::ParameterAction(tr("Build Subproject"), tr("Build Subproject \"%1\""), m_buildSubProjectAction = new Utils::ParameterAction(tr("Build Subproject"), tr("Build Subproject \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this); Utils::ParameterAction::AlwaysEnabled, this);
@@ -175,13 +179,14 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setAttribute(Command::CA_UpdateText); command->setAttribute(Command::CA_UpdateText);
command->setDescription(m_buildSubProjectAction->text()); command->setDescription(m_buildSubProjectAction->text());
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(m_buildSubProjectAction, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(buildSubDirContextMenu())); connect(m_buildSubProjectAction, &QAction::triggered,
m_qmakeProjectManager, &QmakeManager::buildSubDirContextMenu);
m_runQMakeAction = new QAction(tr("Run qmake"), this); m_runQMakeAction = new QAction(tr("Run qmake"), this);
const Context globalcontext(Core::Constants::C_GLOBAL); const Context globalcontext(Core::Constants::C_GLOBAL);
command = ActionManager::registerAction(m_runQMakeAction, Constants::RUNQMAKE, globalcontext); command = ActionManager::registerAction(m_runQMakeAction, Constants::RUNQMAKE, globalcontext);
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(m_runQMakeAction, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(runQMake())); connect(m_runQMakeAction, &QAction::triggered, m_qmakeProjectManager, &QmakeManager::runQMake);
m_rebuildSubProjectAction = new Utils::ParameterAction(tr("Rebuild Subproject"), tr("Rebuild Subproject \"%1\""), m_rebuildSubProjectAction = new Utils::ParameterAction(tr("Rebuild Subproject"), tr("Rebuild Subproject \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this); Utils::ParameterAction::AlwaysEnabled, this);
@@ -190,7 +195,8 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setAttribute(Command::CA_UpdateText); command->setAttribute(Command::CA_UpdateText);
command->setDescription(m_rebuildSubProjectAction->text()); command->setDescription(m_rebuildSubProjectAction->text());
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_REBUILD); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_REBUILD);
connect(m_rebuildSubProjectAction, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(rebuildSubDirContextMenu())); connect(m_rebuildSubProjectAction, &QAction::triggered,
m_qmakeProjectManager, &QmakeManager::rebuildSubDirContextMenu);
m_cleanSubProjectAction = new Utils::ParameterAction(tr("Clean Subproject"), tr("Clean Subproject \"%1\""), m_cleanSubProjectAction = new Utils::ParameterAction(tr("Clean Subproject"), tr("Clean Subproject \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this); Utils::ParameterAction::AlwaysEnabled, this);
@@ -199,7 +205,8 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setAttribute(Command::CA_UpdateText); command->setAttribute(Command::CA_UpdateText);
command->setDescription(m_cleanSubProjectAction->text()); command->setDescription(m_cleanSubProjectAction->text());
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_CLEAN); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_CLEAN);
connect(m_cleanSubProjectAction, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(cleanSubDirContextMenu())); connect(m_cleanSubProjectAction, &QAction::triggered,
m_qmakeProjectManager, &QmakeManager::cleanSubDirContextMenu);
m_buildFileAction = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""), m_buildFileAction = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this); Utils::ParameterAction::AlwaysEnabled, this);
@@ -209,10 +216,10 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
command->setDescription(m_buildFileAction->text()); command->setDescription(m_buildFileAction->text());
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+B"))); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+B")));
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
connect(m_buildFileAction, SIGNAL(triggered()), m_qmakeProjectManager, SLOT(buildFile())); connect(m_buildFileAction, &QAction::triggered, m_qmakeProjectManager, &QmakeManager::buildFile);
connect(BuildManager::instance(), SIGNAL(buildStateChanged(ProjectExplorer::Project*)), connect(BuildManager::instance(), &BuildManager::buildStateChanged,
this, SLOT(buildStateChanged(ProjectExplorer::Project*))); this, &QmakeProjectManagerPlugin::buildStateChanged);
connect(SessionManager::instance(), &SessionManager::startupProjectChanged, connect(SessionManager::instance(), &SessionManager::startupProjectChanged,
this, &QmakeProjectManagerPlugin::projectChanged); this, &QmakeProjectManagerPlugin::projectChanged);
connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged, connect(ProjectTree::instance(), &ProjectTree::currentProjectChanged,
@@ -231,15 +238,14 @@ bool QmakeProjectManagerPlugin::initialize(const QStringList &arguments, QString
m_addLibraryAction = new QAction(tr("Add Library..."), this); m_addLibraryAction = new QAction(tr("Add Library..."), this);
command = ActionManager::registerAction(m_addLibraryAction, command = ActionManager::registerAction(m_addLibraryAction,
Constants::ADDLIBRARY, proFileEditorContext); Constants::ADDLIBRARY, proFileEditorContext);
connect(m_addLibraryAction, SIGNAL(triggered()), connect(m_addLibraryAction, &QAction::triggered, m_qmakeProjectManager, &QmakeManager::addLibrary);
m_qmakeProjectManager, SLOT(addLibrary()));
contextMenu->addAction(command); contextMenu->addAction(command);
m_addLibraryActionContextMenu = new QAction(tr("Add Library..."), this); m_addLibraryActionContextMenu = new QAction(tr("Add Library..."), this);
command = ActionManager::registerAction(m_addLibraryActionContextMenu, command = ActionManager::registerAction(m_addLibraryActionContextMenu,
Constants::ADDLIBRARY, projecTreeContext); Constants::ADDLIBRARY, projecTreeContext);
connect(m_addLibraryActionContextMenu, SIGNAL(triggered()), connect(m_addLibraryActionContextMenu, &QAction::triggered,
m_qmakeProjectManager, SLOT(addLibraryContextMenu())); m_qmakeProjectManager, &QmakeManager::addLibraryContextMenu);
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES); mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES); msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
@@ -260,8 +266,8 @@ void QmakeProjectManagerPlugin::extensionsInitialized()
void QmakeProjectManagerPlugin::projectChanged() void QmakeProjectManagerPlugin::projectChanged()
{ {
if (m_previousStartupProject) if (m_previousStartupProject)
disconnect(m_previousStartupProject, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)), disconnect(m_previousStartupProject, &Project::activeTargetChanged,
this, SLOT(activeTargetChanged())); this, &QmakeProjectManagerPlugin::activeTargetChanged);
if (ProjectTree::currentProject()) if (ProjectTree::currentProject())
m_previousStartupProject = qobject_cast<QmakeProject *>(ProjectTree::currentProject()); m_previousStartupProject = qobject_cast<QmakeProject *>(ProjectTree::currentProject());
@@ -269,8 +275,8 @@ void QmakeProjectManagerPlugin::projectChanged()
m_previousStartupProject = qobject_cast<QmakeProject *>(SessionManager::startupProject()); m_previousStartupProject = qobject_cast<QmakeProject *>(SessionManager::startupProject());
if (m_previousStartupProject) if (m_previousStartupProject)
connect(m_previousStartupProject, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)), connect(m_previousStartupProject, &Project::activeTargetChanged,
this, SLOT(activeTargetChanged())); this, &QmakeProjectManagerPlugin::activeTargetChanged);
activeTargetChanged(); activeTargetChanged();
} }
@@ -278,14 +284,14 @@ void QmakeProjectManagerPlugin::projectChanged()
void QmakeProjectManagerPlugin::activeTargetChanged() void QmakeProjectManagerPlugin::activeTargetChanged()
{ {
if (m_previousTarget) if (m_previousTarget)
disconnect(m_previousTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)), disconnect(m_previousTarget, &Target::activeBuildConfigurationChanged,
this, SLOT(updateRunQMakeAction())); this, &QmakeProjectManagerPlugin::updateRunQMakeAction);
m_previousTarget = m_previousStartupProject ? m_previousStartupProject->activeTarget() : 0; m_previousTarget = m_previousStartupProject ? m_previousStartupProject->activeTarget() : 0;
if (m_previousTarget) if (m_previousTarget)
connect(m_previousTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)), connect(m_previousTarget, &Target::activeBuildConfigurationChanged,
this, SLOT(updateRunQMakeAction())); this, &QmakeProjectManagerPlugin::updateRunQMakeAction);
updateRunQMakeAction(); updateRunQMakeAction();
} }

View File

@@ -58,7 +58,13 @@ public:
bool initialize(const QStringList &arguments, QString *errorMessage); bool initialize(const QStringList &arguments, QString *errorMessage);
void extensionsInitialized(); void extensionsInitialized();
#ifdef WITH_TESTS
private slots: private slots:
void testQmakeOutputParsers_data();
void testQmakeOutputParsers();
#endif
private:
void projectChanged(); void projectChanged();
void activeTargetChanged(); void activeTargetChanged();
void updateRunQMakeAction(); void updateRunQMakeAction();
@@ -66,12 +72,6 @@ private slots:
void buildStateChanged(ProjectExplorer::Project *pro); void buildStateChanged(ProjectExplorer::Project *pro);
void updateBuildFileAction(); void updateBuildFileAction();
#ifdef WITH_TESTS
void testQmakeOutputParsers_data();
void testQmakeOutputParsers();
#endif
private:
QmakeManager *m_qmakeProjectManager = nullptr; QmakeManager *m_qmakeProjectManager = nullptr;
QmakeProject *m_previousStartupProject = nullptr; QmakeProject *m_previousStartupProject = nullptr;
ProjectExplorer::Target *m_previousTarget = nullptr; ProjectExplorer::Target *m_previousTarget = nullptr;