IMode: Make main window an (optional) property

Un-virtualize IMode::mainWindow. If the mode widget is a main window
directly, that is handled automatically, otherwise provide a setter. It
is better to have a central point for setting it, in case that it isn't
the mode widget in the first place. Also, using Aggregation::query for
this is actually a misuse of Aggregate, which is supposed to combine
_independent_ objects, not objects that are in the same hierarchy (which
can crash if the child object is deleted first).

Change-Id: I35381e0a05645022aac72501492ea6347953cd55
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2023-11-28 16:10:37 +01:00
parent 8d851fab0b
commit 1f34461088
5 changed files with 30 additions and 19 deletions

View File

@@ -19,6 +19,7 @@ public:
QString m_displayName;
QIcon m_icon;
QMenu *m_menu = nullptr;
Utils::FancyMainWindow *m_mainWindow = nullptr;
int m_priority = -1;
Utils::Id m_id;
bool m_isEnabled = true;
@@ -181,7 +182,14 @@ void IMode::setMenu(QMenu *menu)
Utils::FancyMainWindow *IMode::mainWindow()
{
return Aggregation::query<Utils::FancyMainWindow>(widget());
if (m_d->m_mainWindow)
return m_d->m_mainWindow;
return qobject_cast<Utils::FancyMainWindow *>(widget());
}
void IMode::setMainWindow(Utils::FancyMainWindow *mw)
{
m_d->m_mainWindow = mw;
}
bool IMode::isEnabled() const