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 <hjk@qt.io>
This commit is contained in:
Miklós Márton
2021-05-21 08:44:13 +02:00
parent 39921ce7bd
commit 48383c16cb

View File

@@ -277,11 +277,15 @@ static void loadSessionData()
class SeparatedView : public QTabWidget class SeparatedView : public QTabWidget
{ {
Q_OBJECT
public: public:
SeparatedView() : QTabWidget(DebuggerMainWindow::instance()) SeparatedView() : QTabWidget(DebuggerMainWindow::instance())
{ {
setTabsClosable(true); setTabsClosable(true);
connect(this, &QTabWidget::tabCloseRequested, this, &SeparatedView::closeTab); connect(this, &QTabWidget::tabCloseRequested, this, &SeparatedView::closeTab);
connect(tabBar(), &QTabBar::customContextMenuRequested,
this, &SeparatedView::tabBarContextMenuRequested);
tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
setWindowFlags(windowFlags() | Qt::Window); setWindowFlags(windowFlags() | Qt::Window);
setWindowTitle(WatchHandler::tr("Debugger - %1").arg(Core::Constants::IDE_DISPLAY_NAME)); setWindowTitle(WatchHandler::tr("Debugger - %1").arg(Core::Constants::IDE_DISPLAY_NAME));
@@ -327,6 +331,15 @@ public:
sanitize(); 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() void sanitize()
{ {
if (count() == 0) if (count() == 0)
@@ -356,6 +369,7 @@ public:
if (!t) { if (!t) {
t = new T; t = new T;
t->setProperty(KeyProperty, key); t->setProperty(KeyProperty, key);
t->setProperty(INameProperty, item->iname);
addTab(t, item->name); addTab(t, item->name);
} }
setProperty(INameProperty, item->iname); setProperty(INameProperty, item->iname);
@@ -365,6 +379,9 @@ public:
raise(); raise();
return t; return t;
} }
Q_SIGNALS:
void tabBarContextMenuRequestedSignal(const QPoint &position, const QString &watchiName);
}; };
class TextEdit : public QTextEdit class TextEdit : public QTextEdit
@@ -476,6 +493,9 @@ public:
QHash<QString, QString> m_valueCache; QHash<QString, QString> m_valueCache;
Location m_location; Location m_location;
private:
void separatedViewTabBarContextMenuRequested(const QPoint &point, const QString &iname);
}; };
WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine) WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine)
@@ -525,6 +545,9 @@ WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine)
connect(&s.useAnnotationsInMainEditor, &BaseAspect::changed, connect(&s.useAnnotationsInMainEditor, &BaseAspect::changed,
m_engine, &DebuggerEngine::updateAll); m_engine, &DebuggerEngine::updateAll);
connect(m_separatedView, &SeparatedView::tabBarContextMenuRequestedSignal,
this, &WatchModel::separatedViewTabBarContextMenuRequested);
connect(SessionManager::instance(), &SessionManager::sessionLoaded, connect(SessionManager::instance(), &SessionManager::sessionLoaded,
this, &loadSessionData); this, &loadSessionData);
connect(SessionManager::instance(), &SessionManager::aboutToSaveSession, connect(SessionManager::instance(), &SessionManager::aboutToSaveSession,
@@ -1886,6 +1909,12 @@ void WatchModel::addCharsPrintableMenu(QMenu *menu)
addBaseChangeAction(tr("Show Unprintable Characters as Hexadecimal"), 16); 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) QMenu *WatchModel::createFormatMenu(WatchItem *item, QWidget *parent)
{ {
auto menu = new QMenu(tr("Change Value Display Format"), parent); auto menu = new QMenu(tr("Change Value Display Format"), parent);