diff --git a/src/plugins/analyzerbase/startremotedialog.cpp b/src/plugins/analyzerbase/startremotedialog.cpp index e971e6a7ee2..6f18fa8d0f9 100644 --- a/src/plugins/analyzerbase/startremotedialog.cpp +++ b/src/plugins/analyzerbase/startremotedialog.cpp @@ -46,24 +46,10 @@ using namespace Utils; namespace Analyzer { namespace Internal { -class SshKitChooser : public KitChooser -{ -public: - SshKitChooser(QWidget *parent = 0) : KitChooser(parent) { } - -private: - bool kitMatches(const Kit *kit) const { - if (!KitChooser::kitMatches(kit)) - return false; - const IDevice::ConstPtr device = DeviceKitInformation::device(kit); - return device && !device->sshParameters().host.isEmpty(); - } -}; - class StartRemoteDialogPrivate { public: - SshKitChooser *kitChooser; + KitChooser *kitChooser; QLineEdit *executable; QLineEdit *arguments; QLineEdit *workingDirectory; @@ -79,7 +65,11 @@ StartRemoteDialog::StartRemoteDialog(QWidget *parent) setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowTitle(tr("Start Remote Analysis")); - d->kitChooser = new Internal::SshKitChooser(this); + d->kitChooser = new KitChooser(this); + d->kitChooser->setKitMatcher([](const Kit *kit) { + const IDevice::ConstPtr device = DeviceKitInformation::device(kit); + return kit->isValid() && device && !device->sshParameters().host.isEmpty(); + }); d->executable = new QLineEdit(this); d->arguments = new QLineEdit(this); d->workingDirectory = new QLineEdit(this); diff --git a/src/plugins/debugger/debuggerdialogs.cpp b/src/plugins/debugger/debuggerdialogs.cpp index 9e6417e0ed5..1971367ce4b 100644 --- a/src/plugins/debugger/debuggerdialogs.cpp +++ b/src/plugins/debugger/debuggerdialogs.cpp @@ -110,18 +110,16 @@ DebuggerKitChooser::DebuggerKitChooser(Mode mode, QWidget *parent) , m_hostAbi(Abi::hostAbi()) , m_mode(mode) { -} - -// Match valid debuggers and restrict local debugging to compatible toolchains. -bool DebuggerKitChooser::kitMatches(const Kit *k) const -{ - if (!DebuggerKitInformation::isValidDebugger(k)) - return false; - if (m_mode == LocalDebugging) { - const ToolChain *tc = ToolChainKitInformation::toolChain(k); - return tc && tc->targetAbi().os() == m_hostAbi.os(); - } - return true; + setKitMatcher([this](const Kit *k) { + // Match valid debuggers and restrict local debugging to compatible toolchains. + if (!DebuggerKitInformation::isValidDebugger(k)) + return false; + if (m_mode == LocalDebugging) { + const ToolChain *tc = ToolChainKitInformation::toolChain(k); + return tc && tc->targetAbi().os() == m_hostAbi.os(); + } + return true; + }); } QString DebuggerKitChooser::kitToolTip(Kit *k) const diff --git a/src/plugins/debugger/debuggerdialogs.h b/src/plugins/debugger/debuggerdialogs.h index ac262c962af..2b5c982bd60 100644 --- a/src/plugins/debugger/debuggerdialogs.h +++ b/src/plugins/debugger/debuggerdialogs.h @@ -69,7 +69,6 @@ public: explicit DebuggerKitChooser(Mode mode = AnyDebugging, QWidget *parent = 0); protected: - bool kitMatches(const ProjectExplorer::Kit *k) const; QString kitToolTip(ProjectExplorer::Kit *k) const; private: diff --git a/src/plugins/projectexplorer/devicesupport/devicetypekitchooser.cpp b/src/plugins/projectexplorer/devicesupport/devicetypekitchooser.cpp deleted file mode 100644 index fe7fcbed3b0..00000000000 --- a/src/plugins/projectexplorer/devicesupport/devicetypekitchooser.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company -** Contact: info@kdab.com -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms and -** conditions see http://www.qt.io/terms-conditions. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "devicetypekitchooser.h" - -#include "../kitinformation.h" - -using namespace ProjectExplorer; - -DeviceTypeKitChooser::DeviceTypeKitChooser(Core::Id deviceType, QWidget *parent) - : KitChooser(parent) - , m_deviceType(deviceType) -{ -} - -bool DeviceTypeKitChooser::kitMatches(const Kit *k) const -{ - if (!KitChooser::kitMatches(k)) - return false; - - return DeviceTypeKitInformation::deviceTypeId(k) == m_deviceType; -} diff --git a/src/plugins/projectexplorer/devicesupport/devicetypekitchooser.h b/src/plugins/projectexplorer/devicesupport/devicetypekitchooser.h deleted file mode 100644 index 98a45f9cb8e..00000000000 --- a/src/plugins/projectexplorer/devicesupport/devicetypekitchooser.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company -** Contact: info@kdab.com -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms and -** conditions see http://www.qt.io/terms-conditions. For further information -** use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef PROJECTEXPLORER_DEVICETYPEKITCHOOSER_H -#define PROJECTEXPLORER_DEVICETYPEKITCHOOSER_H - -#include "../kitchooser.h" -#include "../projectexplorer_export.h" - -#include - -namespace ProjectExplorer { - -class PROJECTEXPLORER_EXPORT DeviceTypeKitChooser : public KitChooser -{ - Q_OBJECT -public: - explicit DeviceTypeKitChooser(Core::Id deviceType, QWidget *parent = 0); - -protected: - bool kitMatches(const Kit *k) const; - -private: - Core::Id m_deviceType; -}; - -} // namespace ProjectExplorer - -#endif // PROJECTEXPLORER_DEVICETYPEKITCHOOSER_H diff --git a/src/plugins/projectexplorer/kitchooser.cpp b/src/plugins/projectexplorer/kitchooser.cpp index b0ad5dc62e1..6dfc1eb427c 100644 --- a/src/plugins/projectexplorer/kitchooser.cpp +++ b/src/plugins/projectexplorer/kitchooser.cpp @@ -47,7 +47,10 @@ namespace ProjectExplorer { const char lastKitKey[] = "LastSelectedKit"; KitChooser::KitChooser(QWidget *parent) : - QWidget(parent) + QWidget(parent), + m_kitMatcher([](const Kit *k) { + return k->isValid(); + }) { m_chooser = new QComboBox(this); m_chooser->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); @@ -79,11 +82,6 @@ void KitChooser::onCurrentIndexChanged(int index) emit currentIndexChanged(index); } -bool KitChooser::kitMatches(const Kit *k) const -{ - return k->isValid(); -} - QString KitChooser::kitText(const Kit *k) const { return k->displayName(); @@ -98,7 +96,7 @@ void KitChooser::populate() { m_chooser->clear(); foreach (Kit *kit, KitManager::sortKits(KitManager::kits())) { - if (kitMatches(kit)) { + if (m_kitMatcher(kit)) { m_chooser->addItem(kitText(kit), qVariantFromValue(kit->id())); m_chooser->setItemData(m_chooser->count() - 1, kitToolTip(kit), Qt::ToolTipRole); } @@ -140,6 +138,12 @@ Core::Id KitChooser::currentKitId() const return kit ? kit->id() : Core::Id(); } +void KitChooser::setKitMatcher(const KitChooser::KitMatcher &matcher) +{ + m_kitMatcher = matcher; + populate(); +} + Kit *KitChooser::kitAt(int index) const { Core::Id id = qvariant_cast(m_chooser->itemData(index)); diff --git a/src/plugins/projectexplorer/kitchooser.h b/src/plugins/projectexplorer/kitchooser.h index 571864efb77..c10e29a9a41 100644 --- a/src/plugins/projectexplorer/kitchooser.h +++ b/src/plugins/projectexplorer/kitchooser.h @@ -35,6 +35,8 @@ #include +#include + QT_BEGIN_NAMESPACE class QComboBox; class QPushButton; @@ -57,6 +59,9 @@ public: void setCurrentKitId(Core::Id id); Core::Id currentKitId() const; + typedef std::function KitMatcher; + void setKitMatcher(const KitMatcher &matcher); + Kit *currentKit() const; signals: @@ -71,11 +76,11 @@ private slots: void onManageButtonClicked(); protected: - virtual bool kitMatches(const Kit *k) const; virtual QString kitText(const Kit *k) const; virtual QString kitToolTip(Kit *k) const; private: + KitMatcher m_kitMatcher; Kit *kitAt(int index) const; QComboBox *m_chooser; QPushButton *m_manageButton; diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index 3629c43ff93..d80732f7d5d 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -130,7 +130,6 @@ HEADERS += projectexplorer.h \ devicesupport/devicesettingswidget.h \ devicesupport/devicesettingspage.h \ devicesupport/devicetestdialog.h \ - devicesupport/devicetypekitchooser.h \ devicesupport/deviceusedportsgatherer.h \ devicesupport/deviceapplicationrunner.h \ devicesupport/localprocesslist.h \ @@ -272,7 +271,6 @@ SOURCES += projectexplorer.cpp \ devicesupport/devicesettingswidget.cpp \ devicesupport/devicesettingspage.cpp \ devicesupport/devicetestdialog.cpp \ - devicesupport/devicetypekitchooser.cpp \ devicesupport/deviceusedportsgatherer.cpp \ devicesupport/deviceapplicationrunner.cpp \ devicesupport/localprocesslist.cpp \ diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index f74ffdd9ed1..154a0d7280e 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -213,7 +213,6 @@ QtcPlugin { "devicesettingspage.cpp", "devicesettingspage.h", "devicesettingswidget.cpp", "devicesettingswidget.h", "devicesettingswidget.ui", "devicetestdialog.cpp", "devicetestdialog.h", "devicetestdialog.ui", - "devicetypekitchooser.cpp", "devicetypekitchooser.h", "deviceusedportsgatherer.cpp", "deviceusedportsgatherer.h", "idevice.cpp", "idevice.h", "idevicefactory.cpp", "idevicefactory.h", diff --git a/src/plugins/qnx/qnxattachdebugsupport.cpp b/src/plugins/qnx/qnxattachdebugsupport.cpp index 3bb3f271a98..4c9eb69b744 100644 --- a/src/plugins/qnx/qnxattachdebugsupport.cpp +++ b/src/plugins/qnx/qnxattachdebugsupport.cpp @@ -40,10 +40,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include @@ -74,7 +74,11 @@ QnxAttachDebugSupport::QnxAttachDebugSupport(QObject *parent) void QnxAttachDebugSupport::showProcessesDialog() { - ProjectExplorer::DeviceTypeKitChooser *kitChooser = new ProjectExplorer::DeviceTypeKitChooser(Core::Id(Constants::QNX_QNX_OS_TYPE)); + auto kitChooser = new ProjectExplorer::KitChooser; + kitChooser->setKitMatcher([](const ProjectExplorer::Kit *k){ + return k->isValid() && ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(k) == Core::Id(Constants::QNX_QNX_OS_TYPE); + }); + QnxAttachDebugDialog dlg(kitChooser, 0); dlg.addAcceptButton(ProjectExplorer::DeviceProcessesDialog::tr("&Attach to Process")); dlg.showAllDevices();