summaryrefslogtreecommitdiff
path: root/src/plugins/baremetal/debugserverproviderchooser.cpp
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2019-11-04 00:51:58 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2019-11-04 10:55:46 +0000
commit4828aa724414295ea59ef0a319ec634324c633c5 (patch)
treeba2841639283cc99d659c7c7e013ed08b024c870 /src/plugins/baremetal/debugserverproviderchooser.cpp
parent04bd6e39c8991fcb89ab15728f622a5a3ae8f0b2 (diff)
downloadqt-creator-4828aa724414295ea59ef0a319ec634324c633c5.tar.gz
BareMetal: Minimize dependency from GDB engine
The problem is that this plugin was originally developed only for working with the GDB debugging engine. This hard dependency penetrates to all plugin logic, that excludes an easy addition of other types of a debugger engines. This patch tries to minimize the GDB dependency and improves code a bit in the following way: * A code that belongs to the GDB engine moved to the separate debugservers/gdb directory. * A classes having a common functionality are renamed with 'Debug' suffixes instead of 'Gdb' suffixes. * Introduced a new interface IDebugServerProvider{Factory|ConfigWidget} whih are used as a base for all derived debug servers providers (e.g. for the OpenOCD, STLink and etc). * The IDebugServerProvider interface has a new virtual engineType() method to show a supported debugger engine by a specific debugger server provider. This method is used in BareMetalDebugSupport class to detect a provider engine for an additional initialization (which depends on an used debugger engine). * The IDebugServerProvider interface has a new virtual hasProcess() method. E.g. this is required for a future debug server providers which has not a remote processes. In this case the BareMetalDevice::canCreateProcess() will report about that in a right way. Thus, this approach allowed us to preserve a previous behavior of an already implemented GDB providers. Also it makes possible to add a new providers in a future with a minimized costs. Change-Id: I1be84b9178d4aa78c3ef5108a9e6b381e245f36f Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/baremetal/debugserverproviderchooser.cpp')
-rw-r--r--src/plugins/baremetal/debugserverproviderchooser.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/plugins/baremetal/debugserverproviderchooser.cpp b/src/plugins/baremetal/debugserverproviderchooser.cpp
new file mode 100644
index 0000000000..de1f5c845d
--- /dev/null
+++ b/src/plugins/baremetal/debugserverproviderchooser.cpp
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "baremetalconstants.h"
+
+#include "debugserverproviderchooser.h"
+#include "debugserverprovidermanager.h"
+#include "idebugserverprovider.h"
+
+#include <coreplugin/icore.h>
+
+#include <QComboBox>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QSettings>
+
+namespace BareMetal {
+namespace Internal {
+
+// DebugServerProviderChooser
+
+DebugServerProviderChooser::DebugServerProviderChooser(
+ bool useManageButton, QWidget *parent)
+ : QWidget(parent)
+{
+ m_chooser = new QComboBox(this);
+ m_chooser->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
+ m_manageButton = new QPushButton(tr("Manage..."), this);
+ m_manageButton->setEnabled(useManageButton);
+ m_manageButton->setVisible(useManageButton);
+
+ const auto layout = new QHBoxLayout(this);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addWidget(m_chooser);
+ layout->addWidget(m_manageButton);
+ setFocusProxy(m_manageButton);
+
+ connect(m_chooser, QOverload<int>::of(&QComboBox::currentIndexChanged),
+ this, &DebugServerProviderChooser::currentIndexChanged);
+ connect(m_manageButton, &QAbstractButton::clicked,
+ this, &DebugServerProviderChooser::manageButtonClicked);
+ connect(DebugServerProviderManager::instance(), &DebugServerProviderManager::providersChanged,
+ this, &DebugServerProviderChooser::populate);
+}
+
+QString DebugServerProviderChooser::currentProviderId() const
+{
+ const int idx = m_chooser->currentIndex();
+ return qvariant_cast<QString>(m_chooser->itemData(idx));
+}
+
+void DebugServerProviderChooser::setCurrentProviderId(const QString &id)
+{
+ for (int i = 0; i < m_chooser->count(); ++i) {
+ if (id != qvariant_cast<QString>(m_chooser->itemData(i)))
+ continue;
+ m_chooser->setCurrentIndex(i);
+ }
+}
+
+void DebugServerProviderChooser::manageButtonClicked()
+{
+ Core::ICore::showOptionsDialog(Constants::GDB_PROVIDERS_SETTINGS_ID, this);
+}
+
+void DebugServerProviderChooser::currentIndexChanged(int index)
+{
+ Q_UNUSED(index)
+ emit providerChanged();
+}
+
+bool DebugServerProviderChooser::providerMatches(const IDebugServerProvider *provider) const
+{
+ return provider->isValid();
+}
+
+QString DebugServerProviderChooser::providerText(const IDebugServerProvider *provider) const
+{
+ return provider->displayName();
+}
+
+void DebugServerProviderChooser::populate()
+{
+ const QSignalBlocker blocker(m_chooser);
+ m_chooser->clear();
+ m_chooser->addItem(tr("None"));
+
+ for (const IDebugServerProvider *p : DebugServerProviderManager::providers()) {
+ if (!providerMatches(p))
+ continue;
+ m_chooser->addItem(providerText(p), QVariant::fromValue(p->id()));
+ }
+}
+
+} // namespace Internal
+} // namespace BareMetal