From 48383c16cb1cf86dda8fa84568715fb00612400e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Fri, 21 May 2021 08:44:13 +0200 Subject: [PATCH] Add context menu to the separate debugger variable view window Added a right click context menu to the tab bar of the separate variable viewer window to being able to change the variable display mode right there (without navigating to the variable tree view in the main window). Fixes: QTCREATORBUG-25762 Change-Id: Ida35f4f6d23f07e5ed45a9f2d51a5af970a95375 Reviewed-by: hjk --- src/plugins/debugger/watchhandler.cpp | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index ab729f22aee..790fd4d8489 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -277,11 +277,15 @@ static void loadSessionData() class SeparatedView : public QTabWidget { + Q_OBJECT public: SeparatedView() : QTabWidget(DebuggerMainWindow::instance()) { setTabsClosable(true); connect(this, &QTabWidget::tabCloseRequested, this, &SeparatedView::closeTab); + connect(tabBar(), &QTabBar::customContextMenuRequested, + this, &SeparatedView::tabBarContextMenuRequested); + tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); setWindowFlags(windowFlags() | Qt::Window); setWindowTitle(WatchHandler::tr("Debugger - %1").arg(Core::Constants::IDE_DISPLAY_NAME)); @@ -327,6 +331,15 @@ public: sanitize(); } + void tabBarContextMenuRequested(const QPoint &point) + { + const QWidget *w = widget(tabBar()->tabAt(point)); + if (!w) + return; + emit tabBarContextMenuRequestedSignal(tabBar()->mapToGlobal(point), + w->property(INameProperty).toString()); + } + void sanitize() { if (count() == 0) @@ -356,6 +369,7 @@ public: if (!t) { t = new T; t->setProperty(KeyProperty, key); + t->setProperty(INameProperty, item->iname); addTab(t, item->name); } setProperty(INameProperty, item->iname); @@ -365,6 +379,9 @@ public: raise(); return t; } + +Q_SIGNALS: + void tabBarContextMenuRequestedSignal(const QPoint &position, const QString &watchiName); }; class TextEdit : public QTextEdit @@ -476,6 +493,9 @@ public: QHash m_valueCache; Location m_location; + +private: + void separatedViewTabBarContextMenuRequested(const QPoint &point, const QString &iname); }; WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine) @@ -525,6 +545,9 @@ WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine) connect(&s.useAnnotationsInMainEditor, &BaseAspect::changed, m_engine, &DebuggerEngine::updateAll); + connect(m_separatedView, &SeparatedView::tabBarContextMenuRequestedSignal, + this, &WatchModel::separatedViewTabBarContextMenuRequested); + connect(SessionManager::instance(), &SessionManager::sessionLoaded, this, &loadSessionData); connect(SessionManager::instance(), &SessionManager::aboutToSaveSession, @@ -1886,6 +1909,12 @@ void WatchModel::addCharsPrintableMenu(QMenu *menu) addBaseChangeAction(tr("Show Unprintable Characters as Hexadecimal"), 16); } +void WatchModel::separatedViewTabBarContextMenuRequested(const QPoint &point, const QString &iname) +{ + auto menu = createFormatMenu(findItem(iname), m_separatedView); + menu->exec(point); +} + QMenu *WatchModel::createFormatMenu(WatchItem *item, QWidget *parent) { auto menu = new QMenu(tr("Change Value Display Format"), parent);