Debugger: Rework Tooltips. Again.

Too much layers of complexity. Instead of keeping an eye on
the "live" tree model and switch to a static StandardItemModel
whenever live synchronization is not possible (and do all the
tree view snake oil magic that's needed to make the switch
appear "smooth") keep static copies of relevant parts of the
live model, and update them whenever the the live model changes.

Change-Id: I88a7de67f7703cd2fed041351346b1c7ada0839e
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
hjk
2015-02-09 09:00:21 +01:00
parent d24fab71eb
commit 2fe69b60dd
5 changed files with 417 additions and 567 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -54,6 +54,7 @@ public:
bool isValid() const { return !expression.isEmpty(); } bool isValid() const { return !expression.isEmpty(); }
bool matchesFrame(const StackFrame &frame) const; bool matchesFrame(const StackFrame &frame) const;
bool isSame(const DebuggerToolTipContext &other) const; bool isSame(const DebuggerToolTipContext &other) const;
QString toolTip() const;
QString fileName; QString fileName;
int position; int position;
@@ -89,8 +90,6 @@ public:
virtual bool eventFilter(QObject *, QEvent *); virtual bool eventFilter(QObject *, QEvent *);
static QString treeModelClipboardContents(const QAbstractItemModel *model);
void debugModeEntered(); void debugModeEntered();
void leavingDebugMode(); void leavingDebugMode();
void sessionAboutToChange(); void sessionAboutToChange();
@@ -101,8 +100,6 @@ public:
public slots: public slots:
static void slotUpdateVisibleToolTips(); static void slotUpdateVisibleToolTips();
void slotItemIsExpanded(const QModelIndex &idx);
void slotColumnAdjustmentRequested();
}; };
} // namespace Internal } // namespace Internal

View File

@@ -679,7 +679,7 @@ QString WatchItem::expression() const
QString WatchItem::displayName() const QString WatchItem::displayName() const
{ {
QString result; QString result;
if (!parent()) if (!parentItem())
return result; return result;
if (d.iname.startsWith("return")) if (d.iname.startsWith("return"))
result = WatchModel::tr("returned value"); result = WatchModel::tr("returned value");
@@ -720,6 +720,23 @@ QString WatchItem::displayType() const
return result; return result;
} }
QColor WatchItem::color() const
{
static const QColor red(200, 0, 0);
static const QColor gray(140, 140, 140);
if (watchModel()) {
if (!d.valueEnabled)
return gray;
if (!watchModel()->contentIsValid() && !d.isInspect())
return gray;
if (d.value.isEmpty()) // This might still show 0x...
return gray;
if (d.value != watchModel()->m_valueCache.value(d.iname))
return red;
}
return QColor();
}
QVariant WatchItem::data(int column, int role) const QVariant WatchItem::data(int column, int role) const
{ {
switch (role) { switch (role) {
@@ -763,22 +780,9 @@ QVariant WatchItem::data(int column, int role) const
return boolSetting(UseToolTipsInLocalsView) return boolSetting(UseToolTipsInLocalsView)
? d.toToolTip() : QVariant(); ? d.toToolTip() : QVariant();
case Qt::ForegroundRole: { case Qt::ForegroundRole:
static const QVariant red(QColor(200, 0, 0)); if (column == 1)
static const QVariant gray(QColor(140, 140, 140)); return color();
if (column == 1) {
QTC_ASSERT(model(), break);
if (!d.valueEnabled)
return gray;
if (!watchModel()->contentIsValid() && !d.isInspect())
return gray;
if (d.value.isEmpty()) // This might still show 0x...
return gray;
if (d.value != watchModel()->m_valueCache.value(d.iname))
return red;
}
break;
}
case LocalsExpressionRole: case LocalsExpressionRole:
return QVariant(expression()); return QVariant(expression());
@@ -1109,10 +1113,12 @@ void WatchModel::insertDataItem(const WatchData &data, bool destructive)
newItem->d = data; newItem->d = data;
const int row = findInsertPosition(parent->children(), newItem); const int row = findInsertPosition(parent->children(), newItem);
parent->insertChild(row, newItem); parent->insertChild(row, newItem);
if (m_expandedINames.contains(parent->d.iname)) if (m_expandedINames.contains(parent->d.iname)) {
emit inameIsExpanded(parent->d.iname);
emit itemIsExpanded(indexFromItem(parent)); emit itemIsExpanded(indexFromItem(parent));
} }
} }
}
void WatchModel::insertBulkData(const QList<WatchData> &list) void WatchModel::insertBulkData(const QList<WatchData> &list)
{ {
@@ -1245,6 +1251,7 @@ void WatchModel::reexpandItems()
foreach (const QByteArray &iname, m_expandedINames) { foreach (const QByteArray &iname, m_expandedINames) {
WatchItem *item = findItem(iname); WatchItem *item = findItem(iname);
emit itemIsExpanded(indexFromItem(item)); emit itemIsExpanded(indexFromItem(item));
emit inameIsExpanded(iname);
} }
} }

View File

@@ -72,6 +72,7 @@ public:
QVariant editValue() const; QVariant editValue() const;
int editType() const; int editType() const;
QColor color() const;
void formatRequests(QByteArray *out) const; void formatRequests(QByteArray *out) const;
void showInEditorHelper(QString *contents, int depth) const; void showInEditorHelper(QString *contents, int depth) const;
@@ -173,6 +174,7 @@ public:
signals: signals:
void currentIndexRequested(const QModelIndex &idx); void currentIndexRequested(const QModelIndex &idx);
void itemIsExpanded(const QModelIndex &idx); void itemIsExpanded(const QModelIndex &idx);
void inameIsExpanded(const QByteArray &iname);
void columnAdjustmentRequested(); void columnAdjustmentRequested();
}; };

View File

@@ -46,9 +46,10 @@
#include <coreplugin/messagebox.h> #include <coreplugin/messagebox.h>
#include <utils/fancylineedit.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/savedaction.h> #include <utils/savedaction.h>
#include <utils/fancylineedit.h> #include <utils/treemodel.h>
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
@@ -61,6 +62,7 @@
#include <QMimeData> #include <QMimeData>
#include <QScrollBar> #include <QScrollBar>
#include <QTimer> #include <QTimer>
#include <QTextStream>
// For InputDialog, move to Utils? // For InputDialog, move to Utils?
#include <coreplugin/helpmanager.h> #include <coreplugin/helpmanager.h>
@@ -906,7 +908,17 @@ void WatchTreeView::contextMenuEvent(QContextMenuEvent *ev)
} else if (act == &actRemoveAllWatchExpression) { } else if (act == &actRemoveAllWatchExpression) {
handler->clearWatches(); handler->clearWatches();
} else if (act == &actCopy) { } else if (act == &actCopy) {
copyToClipboard(DebuggerToolTipManager::treeModelClipboardContents(model())); QString text;
QTextStream str(&text);
handler->model()->rootItem()->walkTree([&str](Utils::TreeItem *item) {
str << QString(item->level(), QLatin1Char('\t'))
<< item->data(0, Qt::DisplayRole).toString() << '\t'
<< item->data(1, Qt::DisplayRole).toString() << '\t'
<< item->data(2, Qt::DisplayRole).toString() << '\n';
});
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(text, QClipboard::Selection);
clipboard->setText(text, QClipboard::Clipboard);
} else if (act == &actCopyValue) { } else if (act == &actCopyValue) {
copyToClipboard(mi1.data().toString()); copyToClipboard(mi1.data().toString());
} else if (act == &actShowInEditor) { } else if (act == &actShowInEditor) {