Commit 2847a02f authored by hjk's avatar hjk
Browse files

BareMetal: Modernize



C++11, Utils::TreeModel.

Change-Id: I0746693436c41fa6b0f02cb61a9cc99d4e6e3e64
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 6368f8f6
......@@ -109,8 +109,6 @@ GdbServerProvider::StartupMode GdbServerProvider::startupMode() const
void GdbServerProvider::setStartupMode(StartupMode m)
{
if (m == m_startupMode)
return;
m_startupMode = m;
}
......@@ -121,8 +119,6 @@ QString GdbServerProvider::initCommands() const
void GdbServerProvider::setInitCommands(const QString &cmds)
{
if (cmds == m_initCommands)
return;
m_initCommands = cmds;
}
......@@ -133,8 +129,6 @@ QString GdbServerProvider::resetCommands() const
void GdbServerProvider::setResetCommands(const QString &cmds)
{
if (cmds == m_resetCommands)
return;
m_resetCommands = cmds;
}
......@@ -160,19 +154,18 @@ bool GdbServerProvider::operator==(const GdbServerProvider &other) const
return thisId == otherId
&& m_startupMode == other.m_startupMode
&& m_initCommands == other.m_initCommands
&& m_resetCommands == other.m_resetCommands
;
&& m_resetCommands == other.m_resetCommands;
}
QVariantMap GdbServerProvider::toMap() const
{
QVariantMap result;
result.insert(QLatin1String(idKeyC), m_id);
result.insert(QLatin1String(displayNameKeyC), m_displayName);
result.insert(QLatin1String(startupModeKeyC), m_startupMode);
result.insert(QLatin1String(initCommandsKeyC), m_initCommands);
result.insert(QLatin1String(resetCommandsKeyC), m_resetCommands);
return result;
return {
{ QLatin1String(idKeyC), m_id },
{ QLatin1String(displayNameKeyC), m_displayName },
{ QLatin1String(startupModeKeyC), m_startupMode },
{ QLatin1String(initCommandsKeyC), m_initCommands },
{ QLatin1String(resetCommandsKeyC), m_resetCommands }
};
}
bool GdbServerProvider::isValid() const
......
......@@ -52,7 +52,6 @@ namespace BareMetal {
namespace Internal {
class GdbServerProviderConfigWidget;
class GdbServerProviderFactory;
class GdbServerProviderManager;
class GdbServerProvider
......
......@@ -59,22 +59,14 @@ static Utils::FileName settingsFileName(const QString &path)
return Utils::FileName::fromString(settingsLocation.absolutePath() + path);
}
static QList<GdbServerProviderFactory *> createFactories()
{
QList<GdbServerProviderFactory *> result;
result << new DefaultGdbServerProviderFactory
<< new OpenOcdGdbServerProviderFactory
<< new StLinkUtilGdbServerProviderFactory
;
return result;
}
GdbServerProviderManager *GdbServerProviderManager::m_instance = 0;
static GdbServerProviderManager *m_instance = 0;
GdbServerProviderManager::GdbServerProviderManager(QObject *parent)
: QObject(parent)
, m_configFile(settingsFileName(QLatin1String(fileNameKeyC)))
, m_factories(createFactories())
, m_factories({ new DefaultGdbServerProviderFactory,
new OpenOcdGdbServerProviderFactory,
new StLinkUtilGdbServerProviderFactory })
{
m_writer = new Utils::PersistentSettingsWriter(
m_configFile, QLatin1String("QtCreatorGdbServerProviders"));
......@@ -82,12 +74,12 @@ GdbServerProviderManager::GdbServerProviderManager(QObject *parent)
connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested,
this, &GdbServerProviderManager::saveProviders);
connect(this, SIGNAL(providerAdded(GdbServerProvider*)),
SIGNAL(providersChanged()));
connect(this, SIGNAL(providerRemoved(GdbServerProvider*)),
SIGNAL(providersChanged()));
connect(this, SIGNAL(providerUpdated(GdbServerProvider*)),
SIGNAL(providersChanged()));
connect(this, &GdbServerProviderManager::providerAdded,
this, &GdbServerProviderManager::providersChanged);
connect(this, &GdbServerProviderManager::providerRemoved,
this, &GdbServerProviderManager::providersChanged);
connect(this, &GdbServerProviderManager::providerUpdated,
this, &GdbServerProviderManager::providersChanged);
}
GdbServerProviderManager::~GdbServerProviderManager()
......
......@@ -59,9 +59,6 @@ public:
bool registerProvider(GdbServerProvider *);
void deregisterProvider(GdbServerProvider *);
public slots:
void saveProviders();
signals:
void providerAdded(GdbServerProvider *);
void providerRemoved(GdbServerProvider *);
......@@ -70,6 +67,7 @@ signals:
void providersLoaded();
private:
void saveProviders();
explicit GdbServerProviderManager(QObject *parent = 0);
void restoreProviders();
......@@ -80,8 +78,6 @@ private:
const Utils::FileName m_configFile;
const QList<GdbServerProviderFactory *> m_factories;
static GdbServerProviderManager *m_instance;
friend class BareMetalPlugin; // for constructor
friend class GdbServerProvider;
};
......
......@@ -33,7 +33,8 @@
#include <coreplugin/dialogs/ioptionspage.h>
#include <QAbstractItemModel>
#include <utils/treemodel.h>
#include <QPointer>
QT_BEGIN_NAMESPACE
......@@ -49,36 +50,20 @@ namespace Internal {
class GdbServerProvider;
class GdbServerProviderConfigWidget;
class GdbServerProviderFactory;
class GdbServerProviderNode;
class GdbServerProvidersSettingsWidget;
class GdbServerProviderModel : public QAbstractItemModel
class GdbServerProviderModel : public Utils::TreeModel
{
Q_OBJECT
public:
explicit GdbServerProviderModel(QObject *parent = 0);
~GdbServerProviderModel();
QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(const QModelIndex &topIdx, const GdbServerProvider *) const;
QModelIndex parent(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
GdbServerProvider *provider(const QModelIndex &) const;
GdbServerProviderConfigWidget *widget(const QModelIndex &) const;
bool isDirty() const;
bool isDirty(GdbServerProvider *) const;
QModelIndex indexForProvider(GdbServerProvider *provider) const;
void apply();
......@@ -88,26 +73,12 @@ public:
signals:
void providerStateChanged();
private slots:
private:
void addProvider(GdbServerProvider *);
void removeProvider(GdbServerProvider *);
void setDirty();
private:
enum ColumnIndex { NameIndex = 0, TypeIndex, ColumnsCount };
QModelIndex index(GdbServerProviderNode *, int column = 0) const;
GdbServerProviderNode *createNode(GdbServerProviderNode *parent,
GdbServerProvider *, bool changed);
GdbServerProviderNode *nodeFromIndex(const QModelIndex &) const;
GdbServerProviderNode *createNode(GdbServerProvider *, bool changed);
static GdbServerProviderNode *findNode(
const QList<GdbServerProviderNode *> &container,
const GdbServerProvider *);
GdbServerProviderNode *m_root;
QList<GdbServerProviderNode *> m_toAddNodes;
QList<GdbServerProviderNode *> m_toRemoveNodes;
};
......@@ -119,28 +90,12 @@ class GdbServerProvidersSettingsPage : public Core::IOptionsPage
public:
explicit GdbServerProvidersSettingsPage(QObject *parent = 0);
private:
QWidget *widget();
void apply();
void finish();
private slots:
void providerSelectionChanged();
void createProvider(QObject *);
void removeProvider();
void updateState();
private:
QModelIndex currentIndex() const;
QPointer<QWidget> m_configWidget;
QPointer<GdbServerProviderModel> m_model;
QPointer<QItemSelectionModel> m_selectionModel;
QPointer<QTreeView> m_providerView;
QPointer<Utils::DetailsWidget> m_container;
QPointer<QPushButton> m_addButton;
QPointer<QPushButton> m_cloneButton;
QPointer<QPushButton> m_delButton;
QPointer<GdbServerProvidersSettingsWidget> m_configWidget;
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment