summaryrefslogtreecommitdiff
path: root/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@theqtcompany.com>2016-02-04 18:09:31 +0100
committerTobias Hunger <tobias.hunger@theqtcompany.com>2016-02-05 11:47:37 +0000
commit999a8d0516df80ce4f130fb496b3582b58e54b65 (patch)
treebe90fce3b6c5c116eb64c018c6739056cdf2d04d /src/plugins/cmakeprojectmanager/cmakekitinformation.cpp
parent5404f9c48077c8ba9edbcc81daec4ac75c86ba7d (diff)
downloadqt-creator-999a8d0516df80ce4f130fb496b3582b58e54b65.tar.gz
CMake: Polish CMakeKitInformation
Change-Id: Ifc22c5ad41449ce6597b604746f25cab86662425 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
Diffstat (limited to 'src/plugins/cmakeprojectmanager/cmakekitinformation.cpp')
-rw-r--r--src/plugins/cmakeprojectmanager/cmakekitinformation.cpp46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp
index 7fe23e7fbf..c3126d83be 100644
--- a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp
@@ -38,20 +38,22 @@
using namespace ProjectExplorer;
namespace CMakeProjectManager {
+// --------------------------------------------------------------------
+// CMakeKitInformation:
+// --------------------------------------------------------------------
static Core::Id defaultCMakeToolId()
{
CMakeTool *defaultTool = CMakeToolManager::defaultCMakeTool();
- if (defaultTool)
- return defaultTool->id();
-
- return Core::Id();
+ return defaultTool ? defaultTool->id() : Core::Id();
}
+static const char TOOL_ID[] = "CMakeProjectManager.CMakeKitInformation";
+
CMakeKitInformation::CMakeKitInformation()
{
setObjectName(QLatin1String("CMakeKitInformation"));
- setId(CMakeKitInformation::id());
+ setId(TOOL_ID);
setPriority(20000);
//make sure the default value is set if a selected CMake is removed
@@ -63,37 +65,26 @@ CMakeKitInformation::CMakeKitInformation()
[this]() { foreach (Kit *k, KitManager::kits()) fix(k); });
}
-Core::Id CMakeKitInformation::id()
-{
- return "CMakeProjectManager.CMakeKitInformation";
-}
-
CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k)
{
if (!k)
return 0;
- const QVariant id = k->value(CMakeKitInformation::id());
+ const QVariant id = k->value(TOOL_ID);
return CMakeToolManager::findById(Core::Id::fromSetting(id));
}
void CMakeKitInformation::setCMakeTool(Kit *k, const Core::Id id)
{
- QTC_ASSERT(k, return);
-
- if (id.isValid()) {
- // Only set cmake tools that are known to the manager
- QTC_ASSERT(CMakeToolManager::findById(id), return);
- k->setValue(CMakeKitInformation::id(), id.toSetting());
- } else {
- //setting a empty Core::Id will reset to the default value
- k->setValue(CMakeKitInformation::id(), defaultCMakeToolId().toSetting());
- }
+ const Core::Id toSet = id.isValid() ? id : defaultCMakeToolId();
+ QTC_ASSERT(!id.isValid() || CMakeToolManager::findById(toSet), return);
+ if (k)
+ k->setValue(TOOL_ID, toSet.toSetting());
}
QVariant CMakeKitInformation::defaultValue(const Kit *k) const
{
- Core::Id id = k ? defaultCMakeToolId() : Core::Id();
+ const Core::Id id = k ? defaultCMakeToolId() : Core::Id();
return id.toSetting();
}
@@ -106,22 +97,19 @@ QList<Task> CMakeKitInformation::validate(const Kit *k) const
void CMakeKitInformation::setup(Kit *k)
{
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
- if (tool)
- return;
-
- setCMakeTool(k, defaultCMakeToolId());
+ if (!tool)
+ setCMakeTool(k, defaultCMakeToolId());
}
void CMakeKitInformation::fix(Kit *k)
{
- CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
- if (!tool)
+ if (!CMakeKitInformation::cmakeTool(k))
setup(k);
}
KitInformation::ItemList CMakeKitInformation::toUserOutput(const Kit *k) const
{
- CMakeTool *tool = cmakeTool(k);
+ const CMakeTool *const tool = cmakeTool(k);
return ItemList() << qMakePair(tr("CMake"), tool == 0 ? tr("Unconfigured") : tool->displayName());
}