Commit c2436190 authored by hjk's avatar hjk

Debugger: Fix cloning of DebuggerItems

Change-Id: I1e16b09361bb7d3eab2bfc7b77da388c60d23f01
Reviewed-by: default avatarMehdi Fekari <mfekari@blackberry.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 2f7625ac
...@@ -576,10 +576,10 @@ void DebuggerItemManager::addDebugger(const DebuggerItem& item0) ...@@ -576,10 +576,10 @@ void DebuggerItemManager::addDebugger(const DebuggerItem& item0)
if (item.id().isNull()) if (item.id().isNull())
item.setId(QUuid::createUuid().toString()); item.setId(QUuid::createUuid().toString());
m_debuggers.append(item); m_debuggers.append(item);
emit m_instance->debuggerAdded(item); m_model->addDebugger(item);
} }
void DebuggerItemManager::removeDebugger(const QVariant& id) void DebuggerItemManager::removeDebugger(const QVariant &id)
{ {
bool ok = false; bool ok = false;
for (int i = 0, n = m_debuggers.size(); i != n; ++i) { for (int i = 0, n = m_debuggers.size(); i != n; ++i) {
...@@ -591,7 +591,7 @@ void DebuggerItemManager::removeDebugger(const QVariant& id) ...@@ -591,7 +591,7 @@ void DebuggerItemManager::removeDebugger(const QVariant& id)
} }
QTC_ASSERT(ok, return); QTC_ASSERT(ok, return);
emit m_instance->debuggerRemoved(id); m_model->removeDebugger(id);
} }
QString DebuggerItemManager::uniqueDisplayName(const QString &base) QString DebuggerItemManager::uniqueDisplayName(const QString &base)
...@@ -611,7 +611,7 @@ void DebuggerItemManager::setItemData(const QVariant &id, const QString &display ...@@ -611,7 +611,7 @@ void DebuggerItemManager::setItemData(const QVariant &id, const QString &display
item.setDisplayName(displayName); item.setDisplayName(displayName);
item.setCommand(fileName); item.setCommand(fileName);
item.reinitializeFromFile(); item.reinitializeFromFile();
emit m_instance->debuggerUpdated(item.id()); emit m_model->updateDebugger(item.id());
break; break;
} }
} }
...@@ -734,13 +734,6 @@ DebuggerItemModel::DebuggerItemModel(QObject *parent) ...@@ -734,13 +734,6 @@ DebuggerItemModel::DebuggerItemModel(QObject *parent)
row = createRow(tr("Manual")); row = createRow(tr("Manual"));
m_manualRoot = row.at(0); m_manualRoot = row.at(0);
appendRow(row); appendRow(row);
foreach (const DebuggerItem& item, DebuggerItemManager::debuggers())
addDebugger(item);
connect(DebuggerItemManager::instance(), SIGNAL(debuggerAdded(DebuggerItem)), this, SLOT(onDebuggerAdded(DebuggerItem)));
connect(DebuggerItemManager::instance(), SIGNAL(debuggerRemoved(QVariant)), this, SLOT(onDebuggerRemoved(QVariant)));
connect(DebuggerItemManager::instance(), SIGNAL(debuggerUpdated(QVariant)), this, SLOT(onDebuggerUpdated(QVariant)));
} }
QVariant DebuggerItemModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant DebuggerItemModel::headerData(int section, Qt::Orientation orientation, int role) const
...@@ -784,15 +777,11 @@ QModelIndex DebuggerItemModel::currentIndex() const ...@@ -784,15 +777,11 @@ QModelIndex DebuggerItemModel::currentIndex() const
return current ? current->index() : QModelIndex(); return current ? current->index() : QModelIndex();
} }
void DebuggerItemModel::addDebugger(const DebuggerItem &item) QModelIndex DebuggerItemModel::lastIndex() const
{ {
DebuggerItemManager::addDebugger(item); int n = m_manualRoot->rowCount();
} QStandardItem *current = m_manualRoot->child(n - 1);
return current ? current->index() : QModelIndex();
void DebuggerItemModel::removeCurrentDebugger()
{
QTC_ASSERT(m_currentDebugger.isValid(), return);
DebuggerItemManager::removeDebugger(m_currentDebugger);
} }
void DebuggerItemModel::markCurrentDirty() void DebuggerItemModel::markCurrentDirty()
...@@ -804,17 +793,7 @@ void DebuggerItemModel::markCurrentDirty() ...@@ -804,17 +793,7 @@ void DebuggerItemModel::markCurrentDirty()
sitem->setFont(font); sitem->setFont(font);
} }
void DebuggerItemModel::cloneDebugger() void DebuggerItemModel::addDebugger(const DebuggerItem &item0)
{
const DebuggerItem *item = DebuggerItemManager::findById(m_currentDebugger);
QTC_ASSERT(item, return);
DebuggerItem newItem = *item;
newItem.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("Clone of %1").arg(item->displayName())));
newItem.setAutoDetected(false);
DebuggerItemManager::addDebugger(newItem);
}
void DebuggerItemModel::onDebuggerAdded(const DebuggerItem &item0)
{ {
DebuggerItem item = item0; DebuggerItem item = item0;
if (item.id().isNull()) if (item.id().isNull())
...@@ -824,7 +803,7 @@ void DebuggerItemModel::onDebuggerAdded(const DebuggerItem &item0) ...@@ -824,7 +803,7 @@ void DebuggerItemModel::onDebuggerAdded(const DebuggerItem &item0)
emit debuggerAdded(item.id(), item.displayName()); emit debuggerAdded(item.id(), item.displayName());
} }
void DebuggerItemModel::onDebuggerRemoved(const QVariant &id) void DebuggerItemModel::removeDebugger(const QVariant &id)
{ {
QStandardItem *sitem = findStandardItemById(id); QStandardItem *sitem = findStandardItemById(id);
QTC_ASSERT(sitem, return); QTC_ASSERT(sitem, return);
...@@ -836,7 +815,7 @@ void DebuggerItemModel::onDebuggerRemoved(const QVariant &id) ...@@ -836,7 +815,7 @@ void DebuggerItemModel::onDebuggerRemoved(const QVariant &id)
emit debuggerRemoved(id); emit debuggerRemoved(id);
} }
void DebuggerItemModel::onDebuggerUpdated(const QVariant &id) void DebuggerItemModel::updateDebugger(const QVariant &id)
{ {
QList<DebuggerItem> debuggers = DebuggerItemManager::debuggers(); QList<DebuggerItem> debuggers = DebuggerItemManager::debuggers();
for (int i = 0, n = debuggers.size(); i != n; ++i) { for (int i = 0, n = debuggers.size(); i != n; ++i) {
...@@ -1202,8 +1181,16 @@ void DebuggerOptionsPage::apply() ...@@ -1202,8 +1181,16 @@ void DebuggerOptionsPage::apply()
void DebuggerOptionsPage::cloneDebugger() void DebuggerOptionsPage::cloneDebugger()
{ {
m_model->cloneDebugger(); const DebuggerItem *item = DebuggerItemManager::findById(m_model->currentDebugger());
debuggerModelChanged(); QTC_ASSERT(item, return);
DebuggerItem newItem;
newItem.setCommand(item->command());
newItem.setEngineType(item->engineType());
newItem.setAbis(item->abis());
newItem.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("Clone of %1").arg(item->displayName())));
newItem.setAutoDetected(false);
DebuggerItemManager::addDebugger(newItem);
m_debuggerView->setCurrentIndex(m_model->lastIndex());
} }
void DebuggerOptionsPage::addDebugger() void DebuggerOptionsPage::addDebugger()
...@@ -1212,14 +1199,15 @@ void DebuggerOptionsPage::addDebugger() ...@@ -1212,14 +1199,15 @@ void DebuggerOptionsPage::addDebugger()
item.setEngineType(NoEngineType); item.setEngineType(NoEngineType);
item.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("New Debugger"))); item.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("New Debugger")));
item.setAutoDetected(false); item.setAutoDetected(false);
m_model->addDebugger(item); DebuggerItemManager::addDebugger(item);
debuggerModelChanged(); m_debuggerView->setCurrentIndex(m_model->lastIndex());
} }
void DebuggerOptionsPage::removeDebugger() void DebuggerOptionsPage::removeDebugger()
{ {
m_model->removeCurrentDebugger(); QVariant id = m_model->currentDebugger();
debuggerModelChanged(); DebuggerItemManager::removeDebugger(id);
m_debuggerView->setCurrentIndex(m_model->lastIndex());
} }
void DebuggerOptionsPage::finish() void DebuggerOptionsPage::finish()
......
...@@ -66,17 +66,15 @@ public: ...@@ -66,17 +66,15 @@ public:
DebuggerItemModel(QObject *parent); DebuggerItemModel(QObject *parent);
QModelIndex currentIndex() const; QModelIndex currentIndex() const;
QModelIndex lastIndex() const;
void setCurrentIndex(const QModelIndex &index); void setCurrentIndex(const QModelIndex &index);
QVariant currentDebugger() const { return m_currentDebugger; }
void addDebugger(const DebuggerItem &item);
void removeDebugger(const QVariant &id);
void updateDebugger(const QVariant &id);
public slots: public slots:
void removeCurrentDebugger();
void markCurrentDirty(); void markCurrentDirty();
void cloneDebugger();
private slots:
void onDebuggerAdded(const DebuggerItem &item);
void onDebuggerRemoved(const QVariant &id);
void onDebuggerUpdated(const QVariant &id);
signals: signals:
void debuggerAdded(const QVariant &id, const QString &display); void debuggerAdded(const QVariant &id, const QString &display);
...@@ -89,8 +87,6 @@ private: ...@@ -89,8 +87,6 @@ private:
friend class DebuggerItemConfigWidget; friend class DebuggerItemConfigWidget;
friend class DebuggerOptionsPage; friend class DebuggerOptionsPage;
void addDebugger(const DebuggerItem &item);
void removeDebugger(const QVariant &id);
QStandardItem *currentStandardItem() const; QStandardItem *currentStandardItem() const;
QStandardItem *findStandardItemById(const QVariant &id) const; QStandardItem *findStandardItemById(const QVariant &id) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;
......
...@@ -118,21 +118,17 @@ public: ...@@ -118,21 +118,17 @@ public:
static QString uniqueDisplayName(const QString &base); static QString uniqueDisplayName(const QString &base);
static void setItemData(const QVariant &id, const QString& displayName, const Utils::FileName &fileName); static void setItemData(const QVariant &id, const QString& displayName, const Utils::FileName &fileName);
static void removeDebugger(const QVariant &id);
static void addDebugger(const DebuggerItem &item);
public slots: public slots:
void saveDebuggers(); void saveDebuggers();
signals:
void debuggerAdded(const DebuggerItem &item);
void debuggerRemoved(const QVariant &id);
void debuggerUpdated(const QVariant &id);
private: private:
explicit DebuggerItemManager(QObject *parent = 0); explicit DebuggerItemManager(QObject *parent = 0);
static void autoDetectDebuggers(); static void autoDetectDebuggers();
static void autoDetectCdbDebugger(); static void autoDetectCdbDebugger();
static void readLegacyDebuggers(); static void readLegacyDebuggers();
static void addDebugger(const DebuggerItem &item);
static void removeDebugger(const QVariant &id);
static Utils::PersistentSettingsWriter *m_writer; static Utils::PersistentSettingsWriter *m_writer;
static QList<DebuggerItem> m_debuggers; static QList<DebuggerItem> m_debuggers;
......
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