ProjectExplorer: Simplify AppOutput context menu creation code path

Change-Id: I7ce938e87b7b714bcfad60ef8e0932544d3cb15e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2024-07-31 15:21:04 +02:00
parent 3cb03be0fd
commit 3c78954d5a
2 changed files with 6 additions and 18 deletions

View File

@@ -79,15 +79,11 @@ static QString msgAttachDebuggerTooltip(const QString &handleDescription = QStri
class TabWidget : public QTabWidget class TabWidget : public QTabWidget
{ {
Q_OBJECT
public: public:
TabWidget(QWidget *parent = nullptr); TabWidget(QWidget *parent = nullptr);
signals:
void contextMenuRequested(const QPoint &pos, int index);
protected:
bool eventFilter(QObject *object, QEvent *event) override;
private: private:
void slotContextMenuRequested(const QPoint &pos); bool eventFilter(QObject *object, QEvent *event) override;
int m_tabIndexForMiddleClick = -1; int m_tabIndexForMiddleClick = -1;
}; };
@@ -96,8 +92,6 @@ TabWidget::TabWidget(QWidget *parent)
{ {
tabBar()->installEventFilter(this); tabBar()->installEventFilter(this);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QWidget::customContextMenuRequested,
this, &TabWidget::slotContextMenuRequested);
} }
bool TabWidget::eventFilter(QObject *object, QEvent *event) bool TabWidget::eventFilter(QObject *object, QEvent *event)
@@ -125,11 +119,6 @@ bool TabWidget::eventFilter(QObject *object, QEvent *event)
return QTabWidget::eventFilter(object, event); return QTabWidget::eventFilter(object, event);
} }
void TabWidget::slotContextMenuRequested(const QPoint &pos)
{
emit contextMenuRequested(pos, tabBar()->tabAt(pos));
}
AppOutputPane::RunControlTab::RunControlTab(RunControl *runControl, Core::OutputWindow *w) : AppOutputPane::RunControlTab::RunControlTab(RunControl *runControl, Core::OutputWindow *w) :
runControl(runControl), window(w) runControl(runControl), window(w)
{ {
@@ -216,7 +205,7 @@ AppOutputPane::AppOutputPane() :
connect(m_tabWidget, &QTabWidget::currentChanged, connect(m_tabWidget, &QTabWidget::currentChanged,
this, &AppOutputPane::tabChanged); this, &AppOutputPane::tabChanged);
connect(m_tabWidget, &TabWidget::contextMenuRequested, connect(m_tabWidget, &QWidget::customContextMenuRequested,
this, &AppOutputPane::contextMenuRequested); this, &AppOutputPane::contextMenuRequested);
connect(SessionManager::instance(), &SessionManager::aboutToUnloadSession, connect(SessionManager::instance(), &SessionManager::aboutToUnloadSession,
@@ -774,8 +763,9 @@ void AppOutputPane::tabChanged(int i)
} }
} }
void AppOutputPane::contextMenuRequested(const QPoint &pos, int index) void AppOutputPane::contextMenuRequested(const QPoint &pos)
{ {
const int index = m_tabWidget->tabBar()->tabAt(pos);
const QList<QAction *> actions = {m_closeCurrentTabAction, m_closeAllTabsAction, m_closeOtherTabsAction}; const QList<QAction *> actions = {m_closeCurrentTabAction, m_closeAllTabsAction, m_closeOtherTabsAction};
QAction *action = QMenu::exec(actions, m_tabWidget->mapToGlobal(pos), nullptr, m_tabWidget); QAction *action = QMenu::exec(actions, m_tabWidget->mapToGlobal(pos), nullptr, m_tabWidget);
if (action == m_closeAllTabsAction) { if (action == m_closeAllTabsAction) {
@@ -951,5 +941,3 @@ void destroyAppOutputPane()
} // namespace Internal } // namespace Internal
} // namespace ProjectExplorer } // namespace ProjectExplorer
#include "appoutputpane.moc"

View File

@@ -79,7 +79,7 @@ private:
void stopRunControl(); void stopRunControl();
void attachToRunControl(); void attachToRunControl();
void tabChanged(int); void tabChanged(int);
void contextMenuRequested(const QPoint &pos, int index); void contextMenuRequested(const QPoint &pos);
void runControlFinished(RunControl *runControl); void runControlFinished(RunControl *runControl);
void aboutToUnloadSession(); void aboutToUnloadSession();