forked from qt-creator/qt-creator
CMake: Polish CMakeKitInformation
Change-Id: Ifc22c5ad41449ce6597b604746f25cab86662425 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -38,20 +38,22 @@
|
|||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
// CMakeKitInformation:
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
static Core::Id defaultCMakeToolId()
|
static Core::Id defaultCMakeToolId()
|
||||||
{
|
{
|
||||||
CMakeTool *defaultTool = CMakeToolManager::defaultCMakeTool();
|
CMakeTool *defaultTool = CMakeToolManager::defaultCMakeTool();
|
||||||
if (defaultTool)
|
return defaultTool ? defaultTool->id() : Core::Id();
|
||||||
return defaultTool->id();
|
|
||||||
|
|
||||||
return Core::Id();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char TOOL_ID[] = "CMakeProjectManager.CMakeKitInformation";
|
||||||
|
|
||||||
CMakeKitInformation::CMakeKitInformation()
|
CMakeKitInformation::CMakeKitInformation()
|
||||||
{
|
{
|
||||||
setObjectName(QLatin1String("CMakeKitInformation"));
|
setObjectName(QLatin1String("CMakeKitInformation"));
|
||||||
setId(CMakeKitInformation::id());
|
setId(TOOL_ID);
|
||||||
setPriority(20000);
|
setPriority(20000);
|
||||||
|
|
||||||
//make sure the default value is set if a selected CMake is removed
|
//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); });
|
[this]() { foreach (Kit *k, KitManager::kits()) fix(k); });
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Id CMakeKitInformation::id()
|
|
||||||
{
|
|
||||||
return "CMakeProjectManager.CMakeKitInformation";
|
|
||||||
}
|
|
||||||
|
|
||||||
CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k)
|
CMakeTool *CMakeKitInformation::cmakeTool(const Kit *k)
|
||||||
{
|
{
|
||||||
if (!k)
|
if (!k)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const QVariant id = k->value(CMakeKitInformation::id());
|
const QVariant id = k->value(TOOL_ID);
|
||||||
return CMakeToolManager::findById(Core::Id::fromSetting(id));
|
return CMakeToolManager::findById(Core::Id::fromSetting(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeKitInformation::setCMakeTool(Kit *k, const Core::Id id)
|
void CMakeKitInformation::setCMakeTool(Kit *k, const Core::Id id)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(k, return);
|
const Core::Id toSet = id.isValid() ? id : defaultCMakeToolId();
|
||||||
|
QTC_ASSERT(!id.isValid() || CMakeToolManager::findById(toSet), return);
|
||||||
if (id.isValid()) {
|
if (k)
|
||||||
// Only set cmake tools that are known to the manager
|
k->setValue(TOOL_ID, toSet.toSetting());
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CMakeKitInformation::defaultValue(const Kit *k) const
|
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();
|
return id.toSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,22 +97,19 @@ QList<Task> CMakeKitInformation::validate(const Kit *k) const
|
|||||||
void CMakeKitInformation::setup(Kit *k)
|
void CMakeKitInformation::setup(Kit *k)
|
||||||
{
|
{
|
||||||
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
||||||
if (tool)
|
if (!tool)
|
||||||
return;
|
setCMakeTool(k, defaultCMakeToolId());
|
||||||
|
|
||||||
setCMakeTool(k, defaultCMakeToolId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeKitInformation::fix(Kit *k)
|
void CMakeKitInformation::fix(Kit *k)
|
||||||
{
|
{
|
||||||
CMakeTool *tool = CMakeKitInformation::cmakeTool(k);
|
if (!CMakeKitInformation::cmakeTool(k))
|
||||||
if (!tool)
|
|
||||||
setup(k);
|
setup(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
KitInformation::ItemList CMakeKitInformation::toUserOutput(const Kit *k) const
|
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());
|
return ItemList() << qMakePair(tr("CMake"), tool == 0 ? tr("Unconfigured") : tool->displayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ class CMAKE_EXPORT CMakeKitInformation : public ProjectExplorer::KitInformation
|
|||||||
public:
|
public:
|
||||||
CMakeKitInformation();
|
CMakeKitInformation();
|
||||||
|
|
||||||
static Core::Id id();
|
|
||||||
|
|
||||||
static CMakeTool *cmakeTool(const ProjectExplorer::Kit *k);
|
static CMakeTool *cmakeTool(const ProjectExplorer::Kit *k);
|
||||||
static void setCMakeTool(ProjectExplorer::Kit *k, const Core::Id id);
|
static void setCMakeTool(ProjectExplorer::Kit *k, const Core::Id id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user