diff --git a/src/plugins/debugger/debuggeractions.cpp b/src/plugins/debugger/debuggeractions.cpp index 7a563d37f27c3227c83c6002c0950f5a3d968af1..a70170607551564a1277bf9cb2bcff14b39069d4 100644 --- a/src/plugins/debugger/debuggeractions.cpp +++ b/src/plugins/debugger/debuggeractions.cpp @@ -264,6 +264,11 @@ void QtcSettingsItem::actionTriggered(bool on) } } +void QtcSettingsItem::trigger(const QVariant &data) const +{ + m_action->setData(data); + m_action->trigger(); +} ////////////////////////////////////////////////////////////////////////// // @@ -376,6 +381,9 @@ QtcSettingsPool *theDebuggerSettings() instance->insertItem(WatchExpressionInWindow, item); item->setTextPattern(QObject::tr("Watch expression \"%1\" in separate window")); + item = new QtcSettingsItem(instance); + instance->insertItem(AssignValue, item); + // // Dumpers // diff --git a/src/plugins/debugger/debuggeractions.h b/src/plugins/debugger/debuggeractions.h index 49ae6ed116f471b2880aeb561ed1c00ac45bf1c0..513c683d696b45bfc7ebeea60c6f1425c694fffb 100644 --- a/src/plugins/debugger/debuggeractions.h +++ b/src/plugins/debugger/debuggeractions.h @@ -61,6 +61,7 @@ public: virtual QAction *action(); virtual QAction *updatedAction(const QString &newText); + Q_SLOT virtual void trigger(const QVariant &data) const; // used for persistency virtual QString settingsKey() const; @@ -154,6 +155,7 @@ enum DebuggerSettingsCode UseDumpers, DebugDumpers, UseToolTips, + AssignValue, // Source List ListSourceFiles, diff --git a/src/plugins/debugger/debuggermanager.cpp b/src/plugins/debugger/debuggermanager.cpp index 8369eb33111a7c09e24d25f721adb9d15433744e..35c78d94b6cc5cffb74cae99e2d6b0deef849ba4 100644 --- a/src/plugins/debugger/debuggermanager.cpp +++ b/src/plugins/debugger/debuggermanager.cpp @@ -255,14 +255,10 @@ void DebuggerManager::init() this, SLOT(expandChildren(QModelIndex))); connect(localsView, SIGNAL(requestCollapseChildren(QModelIndex)), this, SLOT(collapseChildren(QModelIndex))); - connect(localsView, SIGNAL(requestAssignValue(QString,QString)), - this, SLOT(assignValueInDebugger(QString,QString))); // Watchers QTreeView *watchersView = qobject_cast<QTreeView *>(m_watchersWindow); watchersView->setModel(m_watchHandler->model()); - connect(watchersView, SIGNAL(requestAssignValue(QString,QString)), - this, SLOT(assignValueInDebugger(QString,QString))); connect(watchersView, SIGNAL(requestExpandChildren(QModelIndex)), this, SLOT(expandChildren(QModelIndex))); connect(watchersView, SIGNAL(requestCollapseChildren(QModelIndex)), @@ -271,6 +267,8 @@ void DebuggerManager::init() this, SIGNAL(sessionValueRequested(QString,QVariant*))); connect(m_watchHandler, SIGNAL(setSessionValueRequested(QString,QVariant)), this, SIGNAL(setSessionValueRequested(QString,QVariant))); + connect(theDebuggerSetting(AssignValue)->action(), SIGNAL(triggered()), + this, SLOT(assignValueInDebugger())); // Tooltip QTreeView *tooltipView = qobject_cast<QTreeView *>(m_tooltipWindow); @@ -965,6 +963,12 @@ void DebuggerManager::exitDebugger() emit debuggingFinished(); } +void DebuggerManager::assignValueInDebugger() +{ + if (QAction *action = qobject_cast<QAction *>(sender())) { + qDebug() << "HANDLING " << action->data().toString(); + } +} void DebuggerManager::assignValueInDebugger(const QString &expr, const QString &value) { QTC_ASSERT(m_engine, return); diff --git a/src/plugins/debugger/debuggermanager.h b/src/plugins/debugger/debuggermanager.h index deeb4375e7e4feb3984ae6bf5745d0fffb533f93..77e629e38e501eedc93fe38613cdc65e6fba08eb 100644 --- a/src/plugins/debugger/debuggermanager.h +++ b/src/plugins/debugger/debuggermanager.h @@ -237,6 +237,7 @@ public slots: void sessionLoaded(); void aboutToSaveSession(); + void assignValueInDebugger(); void assignValueInDebugger(const QString &expr, const QString &value); void executeDebuggerCommand(const QString &command); diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 7c58e2ee7a7633e8c0870a6eb9fb61a01078786a..f0d5a33a1fabc015fe041fd41cce17269345e94d 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -375,23 +375,6 @@ WatchHandler::WatchHandler() SIGNAL(triggered()), this, SLOT(removeWatchExpression())); } -bool WatchHandler::setData(const QModelIndex &idx, - const QVariant &value, int role) -{ -/* - Q_UNUSED(idx); - Q_UNUSED(value); - Q_UNUSED(role); - if (role == VisualRole) { - QString iname = inameFromIndex(index); - setDisplayedIName(iname, value.toBool()); - return true; - } - return true; -*/ - return QAbstractItemModel::setData(idx, value, role); -} - static QString niceType(QString type) { if (type.contains("std::")) { @@ -457,6 +440,9 @@ QVariant WatchHandler::data(const QModelIndex &idx, int role) const const WatchData &data = m_displaySet.at(node); switch (role) { + case Qt::EditRole: + return data.exp; + case Qt::DisplayRole: { switch (idx.column()) { case 0: return data.name; @@ -543,7 +529,7 @@ Qt::ItemFlags WatchHandler::flags(const QModelIndex &idx) const // enabled, editable, selectable, checkable, and can be used both as the // source of a drag and drop operation and as a drop target. - static const ItemFlags DefaultNotEditable = + static const ItemFlags notEditable = ItemIsSelectable | ItemIsDragEnabled | ItemIsDropEnabled @@ -551,12 +537,15 @@ Qt::ItemFlags WatchHandler::flags(const QModelIndex &idx) const // | ItemIsTristate | ItemIsEnabled; - static const ItemFlags DefaultEditable = - DefaultNotEditable | ItemIsEditable; + static const ItemFlags editable = notEditable | ItemIsEditable; const WatchData &data = m_displaySet.at(node); - return idx.column() == 1 && - data.isWatcher() ? DefaultEditable : DefaultNotEditable; + + if (data.isWatcher() && idx.column() == 0) + return editable; // watcher names are + if (idx.column() == 1) + return editable; // values are editable + return notEditable; } QVariant WatchHandler::headerData(int section, Qt::Orientation orientation, diff --git a/src/plugins/debugger/watchhandler.h b/src/plugins/debugger/watchhandler.h index 04bbfa6c3ff93c33e9f570471c9da75a2737f3d7..aed6b37566df0a77c3e61aabec1ad34367a122b3 100644 --- a/src/plugins/debugger/watchhandler.h +++ b/src/plugins/debugger/watchhandler.h @@ -146,7 +146,6 @@ public: // // QAbstractItemModel // - bool setData(const QModelIndex &index, const QVariant &value, int role); QVariant data(const QModelIndex &index, int role) const; QModelIndex index(int, int, const QModelIndex &idx) const; QModelIndex parent(const QModelIndex &idx) const; diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp index e06becfa5d813ea224d0bf71ddd4e637728b4e4b..f93a7fe7ec881e1cae759936ee7d0ca39ae47567 100644 --- a/src/plugins/debugger/watchwindow.cpp +++ b/src/plugins/debugger/watchwindow.cpp @@ -31,12 +31,15 @@ #include "debuggeractions.h" +#include <utils/qtcassert.h> + #include <QtCore/QDebug> #include <QtCore/QTimer> #include <QtGui/QAction> #include <QtGui/QContextMenuEvent> #include <QtGui/QHeaderView> +#include <QtGui/QItemDelegate> #include <QtGui/QLineEdit> #include <QtGui/QMenu> #include <QtGui/QResizeEvent> @@ -44,8 +47,58 @@ using namespace Debugger::Internal; + +///////////////////////////////////////////////////////////////////// +// +// WatchDelegate +// +///////////////////////////////////////////////////////////////////// + enum { INameRole = Qt::UserRole, VisualRole, ExpandedRole }; +class WatchDelegate : public QItemDelegate +{ +public: + WatchDelegate(QObject *parent) : QItemDelegate(parent) {} + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, + const QModelIndex &) const + { + return new QLineEdit(parent); + } + + void setEditorData(QWidget *editor, const QModelIndex &index) const + { + QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor); + QTC_ASSERT(lineEdit, return); + lineEdit->setText(index.model()->data(index, Qt::EditRole).toString()); + } + + void setModelData(QWidget *editor, QAbstractItemModel *, + const QModelIndex &index) const + { + QLineEdit *lineEdit = qobject_cast<QLineEdit*>(editor); + QTC_ASSERT(lineEdit, return); + QString value = lineEdit->text(); + QString exp = index.model()->data(index, Qt::EditRole).toString(); + if (index.column() == 1) { + // the value column + theDebuggerSetting(AssignValue)->trigger(exp + '=' + value); + } else if (index.column() == 0) { + // the watcher name column + theDebuggerSetting(RemoveWatchExpression)->trigger(exp); + theDebuggerSetting(WatchExpression)->trigger(lineEdit->text()); + } + } + + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, + const QModelIndex &) const + { + editor->setGeometry(option.rect); + } +}; + + ///////////////////////////////////////////////////////////////////// // // WatchWindow @@ -53,16 +106,14 @@ enum { INameRole = Qt::UserRole, VisualRole, ExpandedRole }; ///////////////////////////////////////////////////////////////////// WatchWindow::WatchWindow(Type type, QWidget *parent) - : QTreeView(parent) - , m_alwaysResizeColumnsToContents(true), m_type(type) + : QTreeView(parent), m_alwaysResizeColumnsToContents(true), m_type(type) { setWindowTitle(tr("Locals and Watchers")); setAlternatingRowColors(true); setIndentation(indentation() * 9/10); setUniformRowHeights(true); + setItemDelegate(new WatchDelegate(this)); - connect(itemDelegate(), SIGNAL(commitData(QWidget *)), - this, SLOT(handleChangedItem(QWidget *))); connect(this, SIGNAL(expanded(QModelIndex)), this, SLOT(expandNode(QModelIndex))); connect(this, SIGNAL(collapsed(QModelIndex)), @@ -104,6 +155,7 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev) QAction *act2 = new QAction("Always adjust column widths to contents", &menu); act2->setCheckable(true); act2->setChecked(m_alwaysResizeColumnsToContents); + //QAction *act3 = 0; QAction *act4 = 0; menu.addAction(act1); @@ -124,7 +176,10 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev) //act4 = theDebuggerSetting(WatchExpressionInWindow)->action(); //act4->setCheckable(true); //act4->setChecked(visual); - // FIXME: menu.addAction(act4); + //menu.addAction(act4); + + //act3 = new QAction(tr("Add to watch window..."), &menu); + //menu.addAction(act3); menu.addSeparator(); menu.addAction(theDebuggerSetting(RecheckDumpers)->action()); @@ -140,6 +195,8 @@ void WatchWindow::contextMenuEvent(QContextMenuEvent *ev) setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents); else if (act == act4) model()->setData(mi0, !visual, VisualRole); + else if (act == act4) + model()->setData(mi0, !visual, VisualRole); } void WatchWindow::resizeColumnsToContents() @@ -200,10 +257,3 @@ void WatchWindow::resetHelper(const QModelIndex &idx) } } -void WatchWindow::handleChangedItem(QWidget *widget) -{ - QLineEdit *lineEdit = qobject_cast<QLineEdit *>(widget); - if (lineEdit) - requestAssignValue("foo", lineEdit->text()); -} - diff --git a/src/plugins/debugger/watchwindow.h b/src/plugins/debugger/watchwindow.h index 71beffb43f047c7e88661d8f9cdb37b073cb5f7f..bf6995edb4adae1bee3eb4310b771bac9e595cc2 100644 --- a/src/plugins/debugger/watchwindow.h +++ b/src/plugins/debugger/watchwindow.h @@ -58,12 +58,10 @@ public slots: void setModel(QAbstractItemModel *model); signals: - void requestAssignValue(const QString &exp, const QString &value); void requestExpandChildren(const QModelIndex &idx); void requestCollapseChildren(const QModelIndex &idx); private slots: - void handleChangedItem(QWidget *); void expandNode(const QModelIndex &index); void collapseNode(const QModelIndex &index); diff --git a/tests/manual/gdbdebugger/simple/app.cpp b/tests/manual/gdbdebugger/simple/app.cpp index 4115a49a50853b155ed20815b97609922075f05b..50191f91d12cfb52225e01126961544ca2b744a0 100644 --- a/tests/manual/gdbdebugger/simple/app.cpp +++ b/tests/manual/gdbdebugger/simple/app.cpp @@ -702,6 +702,7 @@ void testStdVector() void testQString() { + int i = 0; QString str = "Hello "; str += " big, "; str += " fat ";