Debugger: Make cancel work in DebuggerOptionsPage

Change-Id: I09735507703e9a2c55aff68a25a4405cf12c9ab4
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Tobias Hunger
2013-10-28 17:47:37 +01:00
committed by hjk
parent b17e8e3061
commit fd8f2c6cdb
6 changed files with 201 additions and 112 deletions

View File

@@ -61,6 +61,13 @@ DebuggerItem::DebuggerItem()
m_isAutoDetected = false; m_isAutoDetected = false;
} }
DebuggerItem::DebuggerItem(const QVariant &id)
{
m_id = id;
m_engineType = NoEngineType;
m_isAutoDetected = false;
}
DebuggerItem::DebuggerItem(const QVariantMap &data) DebuggerItem::DebuggerItem(const QVariantMap &data)
{ {
m_command = FileName::fromUserInput(data.value(QLatin1String(DEBUGGER_INFORMATION_COMMAND)).toString()); m_command = FileName::fromUserInput(data.value(QLatin1String(DEBUGGER_INFORMATION_COMMAND)).toString());
@@ -143,9 +150,9 @@ QStringList DebuggerItem::abiNames() const
bool DebuggerItem::operator==(const DebuggerItem &other) const bool DebuggerItem::operator==(const DebuggerItem &other) const
{ {
return m_id == other.m_id return m_id == other.m_id
&& m_displayName == other.m_displayName
&& m_isAutoDetected == other.m_isAutoDetected && m_isAutoDetected == other.m_isAutoDetected
&& m_command == other.m_command && m_command == other.m_command;
&& m_abis == other.m_abis;
} }
QVariantMap DebuggerItem::toMap() const QVariantMap DebuggerItem::toMap() const
@@ -233,7 +240,7 @@ DebuggerItem::MatchLevel DebuggerItem::matchTarget(const Abi &targetAbi) const
bool Debugger::DebuggerItem::isValid() const bool Debugger::DebuggerItem::isValid() const
{ {
return m_engineType != NoEngineType; return !m_id.isNull();
} }
} // namespace Debugger; } // namespace Debugger;

View File

@@ -42,6 +42,8 @@
namespace Debugger { namespace Debugger {
namespace Internal { class DebuggerItemModel; }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// DebuggerItem // DebuggerItem
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -85,12 +87,16 @@ public:
bool operator==(const DebuggerItem &other) const; bool operator==(const DebuggerItem &other) const;
private: private:
DebuggerItem(const QVariant &id);
QVariant m_id; QVariant m_id;
QString m_displayName; QString m_displayName;
DebuggerEngineType m_engineType; DebuggerEngineType m_engineType;
Utils::FileName m_command; Utils::FileName m_command;
bool m_isAutoDetected; bool m_isAutoDetected;
QList<ProjectExplorer::Abi> m_abis; QList<ProjectExplorer::Abi> m_abis;
friend class Internal::DebuggerItemModel;
}; };
} // namespace Debugger } // namespace Debugger

View File

@@ -90,7 +90,7 @@ static void readDebuggers(const FileName &fileName, bool isSystem)
// SDK debuggers are always considered to be up-to-date, so no need to recheck them. // SDK debuggers are always considered to be up-to-date, so no need to recheck them.
} else { } else {
// User settings. // User settings.
if (item.isAutoDetected() && !item.isValid()) { if (item.isAutoDetected() && (!item.isValid() || item.engineType() == NoEngineType)) {
qWarning() << QString::fromLatin1("DebuggerItem \"%1\" (%2) dropped since it is not valid") qWarning() << QString::fromLatin1("DebuggerItem \"%1\" (%2) dropped since it is not valid")
.arg(item.command().toString()).arg(item.id().toString()); .arg(item.command().toString()).arg(item.id().toString());
continue; continue;
@@ -321,7 +321,7 @@ void DebuggerItemManager::saveDebuggers()
int count = 0; int count = 0;
foreach (const DebuggerItem &item, m_debuggers) { foreach (const DebuggerItem &item, m_debuggers) {
if (item.isValid()) { if (item.isValid() && item.engineType() != NoEngineType) {
QVariantMap tmp = item.toMap(); QVariantMap tmp = item.toMap();
if (tmp.isEmpty()) if (tmp.isEmpty())
continue; continue;

View File

@@ -44,9 +44,12 @@ static QList<QStandardItem *> describeItem(const DebuggerItem &item)
row.append(new QStandardItem(item.command().toUserOutput())); row.append(new QStandardItem(item.command().toUserOutput()));
row.append(new QStandardItem(item.engineTypeName())); row.append(new QStandardItem(item.engineTypeName()));
row.at(0)->setData(item.id()); row.at(0)->setData(item.id());
row.at(0)->setData(item.abiNames(), Qt::UserRole + 2);
row.at(0)->setEditable(false); row.at(0)->setEditable(false);
row.at(1)->setEditable(false); row.at(1)->setEditable(false);
row.at(1)->setData(item.toMap());
row.at(2)->setEditable(false); row.at(2)->setEditable(false);
row.at(2)->setData(static_cast<int>(item.engineType()));
row.at(0)->setSelectable(true); row.at(0)->setSelectable(true);
row.at(1)->setSelectable(true); row.at(1)->setSelectable(true);
row.at(2)->setSelectable(true); row.at(2)->setSelectable(true);
@@ -86,7 +89,7 @@ DebuggerItemModel::DebuggerItemModel(QObject *parent)
appendRow(row); appendRow(row);
foreach (const DebuggerItem &item, DebuggerItemManager::debuggers()) foreach (const DebuggerItem &item, DebuggerItemManager::debuggers())
addDebugger(item); addDebuggerStandardItem(item, false);
QObject *manager = DebuggerItemManager::instance(); QObject *manager = DebuggerItemManager::instance();
connect(manager, SIGNAL(debuggerAdded(QVariant)), connect(manager, SIGNAL(debuggerAdded(QVariant)),
@@ -112,6 +115,87 @@ QVariant DebuggerItemModel::headerData(int section, Qt::Orientation orientation,
return QVariant(); return QVariant();
} }
bool DebuggerItemModel::addDebuggerStandardItem(const DebuggerItem &item, bool changed)
{
if (findStandardItemById(item.id()))
return false;
QList<QStandardItem *> row = describeItem(item);
foreach (QStandardItem *cell, row) {
QFont font = cell->font();
font.setBold(changed);
cell->setFont(font);
}
(item.isAutoDetected() ? m_autoRoot : m_manualRoot)->appendRow(row);
return true;
}
bool DebuggerItemModel::removeDebuggerStandardItem(const QVariant &id)
{
QStandardItem *sitem = findStandardItemById(id);
QTC_ASSERT(sitem, return false);
QStandardItem *parent = sitem->parent();
QTC_ASSERT(parent, return false);
// This will trigger a change of m_currentDebugger via changing the
// view selection.
parent->removeRow(sitem->row());
return true;
}
bool DebuggerItemModel::updateDebuggerStandardItem(const DebuggerItem &item, bool changed)
{
QStandardItem *sitem = findStandardItemById(item.id());
QTC_ASSERT(sitem, return false);
QStandardItem *parent = sitem->parent();
QTC_ASSERT(parent, return false);
int row = sitem->row();
QFont font = sitem->font();
font.setBold(changed);
parent->child(row, 0)->setData(item.displayName(), Qt::DisplayRole);
parent->child(row, 0)->setFont(font);
parent->child(row, 1)->setData(item.command().toUserOutput(), Qt::DisplayRole);
parent->child(row, 1)->setFont(font);
parent->child(row, 2)->setData(item.engineTypeName(), Qt::DisplayRole);
parent->child(row, 2)->setData(static_cast<int>(item.engineType()));
parent->child(row, 2)->setFont(font);
return true;
}
DebuggerItem DebuggerItemModel::debuggerItem(QStandardItem *sitem) const
{
DebuggerItem item = DebuggerItem(QVariant());
if (sitem && sitem->parent()) {
item.setAutoDetected(sitem->parent() == m_autoRoot);
QStandardItem *i = sitem->parent()->child(sitem->row(), 0);
item.m_id = i->data();
item.setDisplayName(i->data(Qt::DisplayRole).toString());
QStringList abis = i->data(Qt::UserRole + 2).toStringList();
QList<ProjectExplorer::Abi> abiList;
foreach (const QString &abi, abis)
abiList << ProjectExplorer::Abi(abi);
item.setAbis(abiList);
i = sitem->parent()->child(sitem->row(), 1);
item.setCommand(Utils::FileName::fromUserInput(i->data(Qt::DisplayRole).toString()));
i = sitem->parent()->child(sitem->row(), 2);
item.setEngineType(static_cast<DebuggerEngineType>(i->data().toInt()));
}
return item;
}
QList<DebuggerItem> DebuggerItemModel::debuggerItems() const
{
QList<DebuggerItem> result;
for (int i = 0, n = m_autoRoot->rowCount(); i != n; ++i)
result << debuggerItem(m_autoRoot->child(i));
for (int i = 0, n = m_manualRoot->rowCount(); i != n; ++i)
result << debuggerItem(m_manualRoot->child(i));
return result;
}
QStandardItem *DebuggerItemModel::currentStandardItem() const QStandardItem *DebuggerItemModel::currentStandardItem() const
{ {
return findStandardItemById(m_currentDebugger); return findStandardItemById(m_currentDebugger);
@@ -145,70 +229,62 @@ QModelIndex DebuggerItemModel::lastIndex() const
return current ? current->index() : QModelIndex(); return current ? current->index() : QModelIndex();
} }
void DebuggerItemModel::markCurrentDirty()
{
QStandardItem *sitem = currentStandardItem();
QTC_ASSERT(sitem, return);
QFont font = sitem->font();
font.setBold(true);
sitem->setFont(font);
}
void DebuggerItemModel::onDebuggerAdded(const QVariant &id) void DebuggerItemModel::onDebuggerAdded(const QVariant &id)
{ {
const DebuggerItem *item = DebuggerItemManager::findById(id); const DebuggerItem *item = DebuggerItemManager::findById(id);
QTC_ASSERT(item, return); QTC_ASSERT(item, return);
addDebugger(*item); if (!addDebuggerStandardItem(*item, false))
updateDebuggerStandardItem(*item, false); // already had it added, so just update it.
} }
void DebuggerItemModel::onDebuggerUpdate(const QVariant &id) void DebuggerItemModel::onDebuggerUpdate(const QVariant &id)
{ {
updateDebugger(id); const DebuggerItem *item = DebuggerItemManager::findById(id);
QTC_ASSERT(item, return);
updateDebuggerStandardItem(*item, false);
} }
void DebuggerItemModel::onDebuggerRemoval(const QVariant &id) void DebuggerItemModel::onDebuggerRemoval(const QVariant &id)
{ {
removeDebugger(id); removeDebuggerStandardItem(id);
} }
void DebuggerItemModel::addDebugger(const DebuggerItem &item) void DebuggerItemModel::addDebugger(const DebuggerItem &item)
{ {
QTC_ASSERT(item.id().isValid(), return); addDebuggerStandardItem(item, true);
QList<QStandardItem *> row = describeItem(item);
(item.isAutoDetected() ? m_autoRoot : m_manualRoot)->appendRow(row);
} }
void DebuggerItemModel::removeDebugger(const QVariant &id) void DebuggerItemModel::removeDebugger(const QVariant &id)
{ {
QStandardItem *sitem = findStandardItemById(id); if (!removeDebuggerStandardItem(id)) // Nothing there!
QTC_ASSERT(sitem, return); return;
QStandardItem *parent = sitem->parent();
QTC_ASSERT(parent, return); if (DebuggerItemManager::findById(id))
// This will trigger a change of m_currentDebugger via changing the m_removedItems.append(id);
// view selection.
parent->removeRow(sitem->row());
} }
void DebuggerItemModel::updateDebugger(const QVariant &id) void DebuggerItemModel::updateDebugger(const DebuggerItem &item)
{ {
QList<DebuggerItem> debuggers = DebuggerItemManager::debuggers(); updateDebuggerStandardItem(item, true);
for (int i = 0, n = debuggers.size(); i != n; ++i) { }
DebuggerItem &item = debuggers[i];
if (item.id() == id) { void DebuggerItemModel::apply()
QStandardItem *sitem = findStandardItemById(id); {
QTC_ASSERT(sitem, return); foreach (const QVariant &id, m_removedItems) {
QStandardItem *parent = sitem->parent(); const DebuggerItem *item = DebuggerItemManager::findById(id);
QTC_ASSERT(parent, return); QTC_CHECK(item);
int row = sitem->row(); DebuggerItemManager::deregisterDebugger(*item);
QFont font = sitem->font(); }
font.setBold(false);
parent->child(row, 0)->setData(item.displayName(), Qt::DisplayRole); foreach (const DebuggerItem &item, debuggerItems()) {
parent->child(row, 0)->setFont(font); const DebuggerItem *managed = DebuggerItemManager::findById(item.id());
parent->child(row, 1)->setData(item.command().toUserOutput(), Qt::DisplayRole); if (managed) {
parent->child(row, 1)->setFont(font); if (*managed == item)
parent->child(row, 2)->setData(item.engineTypeName(), Qt::DisplayRole); continue;
parent->child(row, 2)->setFont(font); else
return; DebuggerItemManager::setItemData(item.id(), item.displayName(), item.command());
} else {
DebuggerItemManager::registerDebugger(item);
} }
} }
} }
@@ -219,5 +295,10 @@ void DebuggerItemModel::setCurrentIndex(const QModelIndex &index)
m_currentDebugger = sit ? sit->data() : QVariant(); m_currentDebugger = sit ? sit->data() : QVariant();
} }
DebuggerItem DebuggerItemModel::currentDebugger() const
{
return debuggerItem(currentStandardItem());
}
} // namespace Internal } // namespace Internal
} // namespace Debugger } // namespace Debugger

View File

@@ -52,13 +52,13 @@ public:
QModelIndex currentIndex() const; QModelIndex currentIndex() const;
QModelIndex lastIndex() const; QModelIndex lastIndex() const;
void setCurrentIndex(const QModelIndex &index); void setCurrentIndex(const QModelIndex &index);
QVariant currentDebugger() const { return m_currentDebugger; } QVariant currentDebuggerId() const { return m_currentDebugger; }
DebuggerItem currentDebugger() const;
void addDebugger(const DebuggerItem &item); void addDebugger(const DebuggerItem &item);
void removeDebugger(const QVariant &id); void removeDebugger(const QVariant &id);
void updateDebugger(const QVariant &id); void updateDebugger(const DebuggerItem &item);
public slots: void apply();
void markCurrentDirty();
private slots: private slots:
void onDebuggerAdded(const QVariant &id); void onDebuggerAdded(const QVariant &id);
@@ -70,11 +70,20 @@ private:
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;
bool addDebuggerStandardItem(const DebuggerItem &item, bool changed);
bool removeDebuggerStandardItem(const QVariant &id);
bool updateDebuggerStandardItem(const DebuggerItem &item, bool changed);
DebuggerItem debuggerItem(QStandardItem *sitem) const;
QList<DebuggerItem> debuggerItems() const;
QVariant m_currentDebugger; QVariant m_currentDebugger;
QStandardItem *m_autoRoot; QStandardItem *m_autoRoot;
QStandardItem *m_manualRoot; QStandardItem *m_manualRoot;
QStringList removed; QStringList removed;
QList<QVariant> m_removedItems;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -64,10 +64,8 @@ class DebuggerItemConfigWidget : public QWidget
public: public:
explicit DebuggerItemConfigWidget(DebuggerItemModel *model); explicit DebuggerItemConfigWidget(DebuggerItemModel *model);
void loadItem(); void setItem(const DebuggerItem &item);
void saveItem(); void apply();
void connectDirty();
void disconnectDirty();
private: private:
QLineEdit *m_displayNameLineEdit; QLineEdit *m_displayNameLineEdit;
@@ -102,43 +100,19 @@ DebuggerItemConfigWidget::DebuggerItemConfigWidget(DebuggerItemModel *model) :
formLayout->addRow(m_cdbLabel); formLayout->addRow(m_cdbLabel);
formLayout->addRow(new QLabel(tr("Path:")), m_binaryChooser); formLayout->addRow(new QLabel(tr("Path:")), m_binaryChooser);
formLayout->addRow(new QLabel(tr("ABIs:")), m_abis); formLayout->addRow(new QLabel(tr("ABIs:")), m_abis);
connectDirty();
} }
void DebuggerItemConfigWidget::connectDirty() void DebuggerItemConfigWidget::setItem(const DebuggerItem &item)
{ {
connect(m_displayNameLineEdit, SIGNAL(textChanged(QString)), m_displayNameLineEdit->setEnabled(!item.isAutoDetected());
m_model, SLOT(markCurrentDirty())); m_displayNameLineEdit->setText(item.displayName());
connect(m_binaryChooser, SIGNAL(changed(QString)),
m_model, SLOT(markCurrentDirty()));
}
void DebuggerItemConfigWidget::disconnectDirty() m_binaryChooser->setEnabled(!item.isAutoDetected());
{ m_binaryChooser->setFileName(item.command());
disconnect(m_displayNameLineEdit, SIGNAL(textChanged(QString)),
m_model, SLOT(markCurrentDirty()));
disconnect(m_binaryChooser, SIGNAL(changed(QString)),
m_model, SLOT(markCurrentDirty()));
}
void DebuggerItemConfigWidget::loadItem()
{
const DebuggerItem *item = DebuggerItemManager::findById(m_model->currentDebugger());
if (!item)
return;
disconnectDirty();
m_displayNameLineEdit->setEnabled(!item->isAutoDetected());
m_displayNameLineEdit->setText(item->displayName());
m_binaryChooser->setEnabled(!item->isAutoDetected());
m_binaryChooser->setFileName(item->command());
connectDirty();
QString text; QString text;
QString versionCommand; QString versionCommand;
if (item->engineType() == CdbEngineType) { if (item.engineType() == CdbEngineType) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
const bool is64bit = winIs64BitSystem(); const bool is64bit = winIs64BitSystem();
#else #else
@@ -159,15 +133,18 @@ void DebuggerItemConfigWidget::loadItem()
m_cdbLabel->setVisible(!text.isEmpty()); m_cdbLabel->setVisible(!text.isEmpty());
m_binaryChooser->setCommandVersionArguments(QStringList(versionCommand)); m_binaryChooser->setCommandVersionArguments(QStringList(versionCommand));
m_abis->setText(item->abiNames().join(QLatin1String(", "))); m_abis->setText(item.abiNames().join(QLatin1String(", ")));
} }
void DebuggerItemConfigWidget::saveItem() void DebuggerItemConfigWidget::apply()
{ {
const DebuggerItem *item = DebuggerItemManager::findById(m_model->currentDebugger()); DebuggerItem item = m_model->currentDebugger();
QTC_ASSERT(item, return); QTC_ASSERT(item.isValid(), return);
DebuggerItemManager::setItemData(item->id(), m_displayNameLineEdit->text(),
m_binaryChooser->fileName()); item.setDisplayName(m_displayNameLineEdit->text());
item.setCommand(m_binaryChooser->fileName());
item.reinitializeFromFile();
m_model->updateDebugger(item);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@@ -253,21 +230,23 @@ QWidget *DebuggerOptionsPage::createPage(QWidget *parent)
void DebuggerOptionsPage::apply() void DebuggerOptionsPage::apply()
{ {
m_itemConfigWidget->saveItem(); m_itemConfigWidget->apply();
debuggerModelChanged(); m_model->apply();
} }
void DebuggerOptionsPage::cloneDebugger() void DebuggerOptionsPage::cloneDebugger()
{ {
const DebuggerItem *item = DebuggerItemManager::findById(m_model->currentDebugger()); DebuggerItem item = m_model->currentDebugger();
QTC_ASSERT(item, return); if (!item.isValid())
return;
DebuggerItem newItem; DebuggerItem newItem;
newItem.setCommand(item->command()); newItem.setCommand(item.command());
newItem.setEngineType(item->engineType()); newItem.setEngineType(item.engineType());
newItem.setAbis(item->abis()); newItem.setAbis(item.abis());
newItem.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("Clone of %1").arg(item->displayName()))); newItem.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("Clone of %1").arg(item.displayName())));
newItem.setAutoDetected(false); newItem.setAutoDetected(false);
DebuggerItemManager::addDebugger(newItem); m_model->addDebugger(newItem);
m_debuggerView->setCurrentIndex(m_model->lastIndex()); m_debuggerView->setCurrentIndex(m_model->lastIndex());
} }
@@ -277,14 +256,14 @@ 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);
DebuggerItemManager::addDebugger(item); m_model->addDebugger(item);
m_debuggerView->setCurrentIndex(m_model->lastIndex()); m_debuggerView->setCurrentIndex(m_model->lastIndex());
} }
void DebuggerOptionsPage::removeDebugger() void DebuggerOptionsPage::removeDebugger()
{ {
QVariant id = m_model->currentDebugger(); QVariant id = m_model->currentDebuggerId();
DebuggerItemManager::removeDebugger(id); m_model->removeDebugger(id);
m_debuggerView->setCurrentIndex(m_model->lastIndex()); m_debuggerView->setCurrentIndex(m_model->lastIndex());
} }
@@ -314,8 +293,10 @@ void DebuggerOptionsPage::debuggerSelectionChanged()
mi = mi.sibling(mi.row(), 0); mi = mi.sibling(mi.row(), 0);
m_model->setCurrentIndex(mi); m_model->setCurrentIndex(mi);
m_itemConfigWidget->loadItem(); DebuggerItem item = m_model->currentDebugger();
m_container->setVisible(m_model->currentDebugger().isValid());
m_itemConfigWidget->setItem(item);
m_container->setVisible(item.isValid());
updateState(); updateState();
} }
@@ -323,8 +304,13 @@ void DebuggerOptionsPage::debuggerModelChanged()
{ {
QTC_ASSERT(m_container, return); QTC_ASSERT(m_container, return);
m_itemConfigWidget->loadItem(); QVariant id = m_model->currentDebuggerId();
m_container->setVisible(m_model->currentDebugger().isValid()); const DebuggerItem *item = DebuggerItemManager::findById(id);
if (!item)
return;
m_itemConfigWidget->setItem(*item);
m_container->setVisible(m_model->currentDebuggerId().isValid());
m_debuggerView->setCurrentIndex(m_model->currentIndex()); m_debuggerView->setCurrentIndex(m_model->currentIndex());
updateState(); updateState();
} }
@@ -337,11 +323,11 @@ void DebuggerOptionsPage::updateState()
bool canCopy = false; bool canCopy = false;
bool canDelete = false; bool canDelete = false;
if (const DebuggerItem *item = DebuggerItemManager::findById(m_model->currentDebugger())) { DebuggerItem item = m_model->currentDebugger();
canCopy = item->isValid() && item->canClone();
canDelete = !item->isAutoDetected(); canCopy = item.isValid() && item.canClone();
canDelete = true; // Do we want to remove auto-detected items? canDelete = !item.isAutoDetected();
}
m_cloneButton->setEnabled(canCopy); m_cloneButton->setEnabled(canCopy);
m_delButton->setEnabled(canDelete); m_delButton->setEnabled(canDelete);
} }