diff options
Diffstat (limited to 'src/plugins/cmakeprojectmanager/cmakekitinformation.cpp')
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakekitinformation.cpp | 92 |
1 files changed, 32 insertions, 60 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp index def549f580..54add7395f 100644 --- a/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp +++ b/src/plugins/cmakeprojectmanager/cmakekitinformation.cpp @@ -75,22 +75,15 @@ public: m_comboBox->setEnabled(false); m_comboBox->setToolTip(ki->description()); - const QList<CMakeTool *> tools = CMakeToolManager::cmakeTools(); - for (const CMakeTool *tool : tools) - cmakeToolAdded(tool->id()); - - updateComboBox(); refresh(); + connect(m_comboBox, &QComboBox::currentIndexChanged, this, &CMakeKitAspectWidget::currentCMakeToolChanged); CMakeToolManager *cmakeMgr = CMakeToolManager::instance(); - connect(cmakeMgr, &CMakeToolManager::cmakeAdded, - this, &CMakeKitAspectWidget::cmakeToolAdded); - connect(cmakeMgr, &CMakeToolManager::cmakeRemoved, - this, &CMakeKitAspectWidget::cmakeToolRemoved); - connect(cmakeMgr, &CMakeToolManager::cmakeUpdated, - this, &CMakeKitAspectWidget::cmakeToolUpdated); + connect(cmakeMgr, &CMakeToolManager::cmakeAdded, this, &CMakeKitAspectWidget::refresh); + connect(cmakeMgr, &CMakeToolManager::cmakeRemoved, this, &CMakeKitAspectWidget::refresh); + connect(cmakeMgr, &CMakeToolManager::cmakeUpdated, this, &CMakeKitAspectWidget::refresh); } ~CMakeKitAspectWidget() override @@ -112,69 +105,48 @@ private: void refresh() override { - CMakeTool *tool = CMakeKitAspect::cmakeTool(m_kit); - m_comboBox->setCurrentIndex(tool ? indexOf(tool->id()) : -1); - } + const GuardLocker locker(m_ignoreChanges); + m_comboBox->clear(); - int indexOf(Id id) - { - for (int i = 0; i < m_comboBox->count(); ++i) { - if (id == Id::fromSetting(m_comboBox->itemData(i))) - return i; - } - return -1; - } + IDeviceConstPtr device = BuildDeviceKitAspect::device(kit()); + const FilePath rootPath = device->rootPath(); - void updateComboBox() - { - // remove unavailable cmake tool: - int pos = indexOf(Id()); - if (pos >= 0) - m_comboBox->removeItem(pos); + const auto list = CMakeToolManager::cmakeTools(); + + m_comboBox->setEnabled(!list.isEmpty()); - if (m_comboBox->count() == 0) { + if (list.isEmpty()) { m_comboBox->addItem(Tr::tr("<No CMake Tool available>"), Id().toSetting()); - m_comboBox->setEnabled(false); - } else { - m_comboBox->setEnabled(true); + return; } - } - void cmakeToolAdded(Id id) - { - const CMakeTool *tool = CMakeToolManager::findById(id); - QTC_ASSERT(tool, return); + const QList<CMakeTool *> same = Utils::filtered(list, [rootPath](CMakeTool *item) { + return item->cmakeExecutable().isSameDevice(rootPath); + }); + const QList<CMakeTool *> other = Utils::filtered(list, [rootPath](CMakeTool *item) { + return !item->cmakeExecutable().isSameDevice(rootPath); + }); - m_comboBox->addItem(tool->displayName(), tool->id().toSetting()); - updateComboBox(); - refresh(); - } + for (CMakeTool *item : same) + m_comboBox->addItem(item->displayName(), item->id().toSetting()); - void cmakeToolUpdated(Id id) - { - const int pos = indexOf(id); - QTC_ASSERT(pos >= 0, return); + if (!same.isEmpty() && !other.isEmpty()) + m_comboBox->insertSeparator(m_comboBox->count()); - const CMakeTool *tool = CMakeToolManager::findById(id); - QTC_ASSERT(tool, return); + for (CMakeTool *item : other) + m_comboBox->addItem(item->displayName(), item->id().toSetting()); - m_comboBox->setItemText(pos, tool->displayName()); + CMakeTool *tool = CMakeKitAspect::cmakeTool(m_kit); + m_comboBox->setCurrentIndex(tool ? indexOf(tool->id()) : -1); } - void cmakeToolRemoved(Id id) + int indexOf(Id id) { - const int pos = indexOf(id); - QTC_ASSERT(pos >= 0, return); - - { - // do not handle the current index changed signal - const GuardLocker locker(m_ignoreChanges); - m_comboBox->removeItem(pos); + for (int i = 0; i < m_comboBox->count(); ++i) { + if (id == Id::fromSetting(m_comboBox->itemData(i))) + return i; } - - // update the checkbox and set the current index - updateComboBox(); - refresh(); + return -1; } void currentCMakeToolChanged(int index) |