diff options
| author | hjk <[email protected]> | 2025-03-18 14:01:42 +0100 |
|---|---|---|
| committer | hjk <[email protected]> | 2025-03-24 06:50:56 +0000 |
| commit | 2bae48eafa3bf089efe721cd5374d653bb584247 (patch) | |
| tree | 6a0ae72273510a2731410a98bcc232c37e0e8bef /src/plugins/debugger/stackhandler.cpp | |
| parent | 19a62f558ce48aacd509cee1252dad3a2688aa97 (diff) | |
Utils: Make helpers for stack view contents more widely available
... and use them in other debugger views.
This also gives a more central place where to put more functionality
which we use to add an action to copy selected items into a new editor.
Task-number: QTCREATORBUG-32626
Change-Id: I2d8b578d1ca377b9bda560f5cf5bdb083f37b451
Reviewed-by: David Schulz <[email protected]>
Diffstat (limited to 'src/plugins/debugger/stackhandler.cpp')
| -rw-r--r-- | src/plugins/debugger/stackhandler.cpp | 69 |
1 files changed, 3 insertions, 66 deletions
diff --git a/src/plugins/debugger/stackhandler.cpp b/src/plugins/debugger/stackhandler.cpp index 080176605dc..1c2d7bfa14d 100644 --- a/src/plugins/debugger/stackhandler.cpp +++ b/src/plugins/debugger/stackhandler.cpp @@ -330,63 +330,6 @@ static StackFrame inputFunctionForDisassembly() return frame; } -template<typename Functor> -void forEachCell(Functor f, QAbstractItemModel *model, const QModelIndex &idx) -{ - f(idx); - for (int i = 0, n = model->rowCount(idx); i < n; ++i) - forEachCell(f, model, model->index(i, 0, idx)); -} - -static QString selectedText(QWidget *widget, bool useAll) -{ - QAbstractItemView *view = qobject_cast<QAbstractItemView *>(widget); - QTC_ASSERT(view, return {}); - QAbstractItemModel *model = view->model(); - QTC_ASSERT(model, return {}); - - const int ncols = model->columnCount(QModelIndex()); - QList<int> largestColumnWidths(ncols, 0); - - QSet<QModelIndex> selected; - if (QItemSelectionModel *selection = view->selectionModel()) { - const QModelIndexList list = selection->selectedIndexes(); - selected = QSet<QModelIndex>(list.begin(), list.end()); - } - if (selected.isEmpty()) - useAll = true; - - // First, find the widths of the largest columns, - // so that we can print them out nicely aligned. - forEachCell([ncols, model, &largestColumnWidths, selected, useAll](const QModelIndex &idx) { - if (useAll || selected.contains(idx)) { - for (int j = 0; j < ncols; ++j) { - const QModelIndex sibling = model->sibling(idx.row(), j, idx); - const int columnWidth = model->data(sibling, Qt::DisplayRole).toString().size(); - if (columnWidth > largestColumnWidths.at(j)) - largestColumnWidths[j] = columnWidth; - } - } - }, model, QModelIndex()); - - QString str; - forEachCell([ncols, model, largestColumnWidths, &str, selected, useAll](const QModelIndex &idx) { - if (useAll || selected.contains(idx)) { - for (int j = 0; j != ncols; ++j) { - const QModelIndex sibling = model->sibling(idx.row(), j, idx); - const QString columnEntry = model->data(sibling, Qt::DisplayRole).toString(); - str += columnEntry; - const int difference = largestColumnWidths.at(j) - columnEntry.size(); - // Add one extra space between columns. - str += QString(qMax(difference, 0) + 1, QChar(' ')); - } - str += '\n'; - } - }, model, QModelIndex()); - - return str.trimmed(); -} - // Write stack frames as task file for displaying it in the build issues pane. void StackHandler::saveTaskFile() { @@ -426,14 +369,6 @@ bool StackHandler::contextMenuEvent(const ItemViewEvent &ev) menu->addAction(settings().expandStack.action()); - addAction(this, menu, Tr::tr("Copy Contents to Clipboard"), true, [ev] { - setClipboardAndSelection(selectedText(ev.view(), true)); - }); - - addAction(this, menu, Tr::tr("Copy Selection to Clipboard"), true, [ev] { - setClipboardAndSelection(selectedText(ev.view(), false)); - }); - addAction(this, menu, Tr::tr("Save as Task File..."), true, [this] { saveTaskFile(); }); if (m_engine->hasCapability(CreateFullBacktraceCapability)) @@ -483,7 +418,9 @@ bool StackHandler::contextMenuEvent(const ItemViewEvent &ev) menu->addSeparator(); menu->addAction(settings().useToolTipsInStackView.action()); - menu->addAction(settings().settingsDialog.action()); + + addStandardActions(qobject_cast<BaseTreeView *>(ev.view()), menu); + connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater); menu->popup(ev.globalPos()); return true; |
