forked from qt-creator/qt-creator
Make it easy to set a kit matcher.
Using a function to set a kit matcher is much easier that crating a new
class. It also enables an easy way to reuse classes that are using it.
E.g.
DeviceProcessesDialog processDialog;
processDialog.kitChooser()->setKitMatcher([](const Kit* kit) {
return kit->isValid() && other_checks_with(kit);
});
Change-Id: I4e2fc7c52038902412cec5331504230bb8160ceb
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -110,11 +110,8 @@ DebuggerKitChooser::DebuggerKitChooser(Mode mode, QWidget *parent)
|
||||
, m_hostAbi(Abi::hostAbi())
|
||||
, m_mode(mode)
|
||||
{
|
||||
}
|
||||
|
||||
setKitMatcher([this](const Kit *k) {
|
||||
// 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) {
|
||||
@@ -122,6 +119,7 @@ bool DebuggerKitChooser::kitMatches(const Kit *k) const
|
||||
return tc && tc->targetAbi().os() == m_hostAbi.os();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
QString DebuggerKitChooser::kitToolTip(Kit *k) const
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 <coreplugin/id.h>
|
||||
|
||||
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
|
||||
@@ -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<Core::Id>(m_chooser->itemData(index));
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include <functional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QComboBox;
|
||||
class QPushButton;
|
||||
@@ -57,6 +59,9 @@ public:
|
||||
void setCurrentKitId(Core::Id id);
|
||||
Core::Id currentKitId() const;
|
||||
|
||||
typedef std::function<bool(const Kit *k)> 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;
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -40,10 +40,10 @@
|
||||
#include <debugger/debuggerstartparameters.h>
|
||||
#include <projectexplorer/devicesupport/deviceapplicationrunner.h>
|
||||
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
||||
#include <projectexplorer/devicesupport/devicetypekitchooser.h>
|
||||
#include <projectexplorer/devicesupport/deviceprocessesdialog.h>
|
||||
#include <projectexplorer/devicesupport/deviceprocesslist.h>
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/kitchooser.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user