forked from qt-creator/qt-creator
Break IMode's inheritance from IContext
IContext has the purpose of matching the current focus widget hierarchy to active context and context help. We do have actions that are enabled by mode context and we do have some modes that specify context help, and modes do have associated widgets. But the inheritance of IMode from IContext also forces IModes to create their widgets early which is undesirable. We already manually add the active mode's context via updateAdditionalContexts, so we already do not rely on the focus and do not need the IContext for that. Instead add a context property to IMode directly. Also, modes can just create an IContext for their widget if they need it _when_ the widget is created. Change-Id: I1178b73ffa7b6e4c25221dca0419c7def78f7bdc Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -25,6 +25,8 @@ public:
|
||||
Utils::FancyMainWindow *m_mainWindow = nullptr;
|
||||
int m_priority = -1;
|
||||
Utils::Id m_id;
|
||||
Context m_context;
|
||||
QPointer<QWidget> m_widget;
|
||||
bool m_isEnabled = true;
|
||||
BoolAspect m_isVisible;
|
||||
};
|
||||
@@ -123,7 +125,7 @@ public:
|
||||
Registers the mode in \QC.
|
||||
*/
|
||||
IMode::IMode(QObject *parent)
|
||||
: IContext(parent)
|
||||
: QObject(parent)
|
||||
, m_d(new Internal::IModePrivate)
|
||||
{
|
||||
m_d->m_isVisible.setDefaultValue(true);
|
||||
@@ -197,6 +199,16 @@ void IMode::setMenu(QMenu *menu)
|
||||
m_d->m_menu = menu;
|
||||
}
|
||||
|
||||
void IMode::setContext(const Context &context)
|
||||
{
|
||||
m_d->m_context = context;
|
||||
}
|
||||
|
||||
void IMode::setWidget(QWidget *widget)
|
||||
{
|
||||
m_d->m_widget = widget;
|
||||
}
|
||||
|
||||
Utils::FancyMainWindow *IMode::mainWindow()
|
||||
{
|
||||
if (m_d->m_mainWindow)
|
||||
@@ -225,4 +237,14 @@ QMenu *IMode::menu() const
|
||||
return m_d->m_menu;
|
||||
}
|
||||
|
||||
Context IMode::context() const
|
||||
{
|
||||
return m_d->m_context;
|
||||
}
|
||||
|
||||
QWidget *IMode::widget() const
|
||||
{
|
||||
return m_d->m_widget;
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
Reference in New Issue
Block a user