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