forked from qt-creator/qt-creator
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:
@@ -23,14 +23,17 @@
|
||||
#include <QStackedWidget>
|
||||
#include <QStringList>
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace Core {
|
||||
|
||||
struct DesignEditorInfo
|
||||
{
|
||||
int widgetIndex;
|
||||
int widgetIndex = -1;
|
||||
QStringList mimeTypes;
|
||||
Context context;
|
||||
QWidget *widget;
|
||||
QWidget *widget = nullptr;
|
||||
FancyMainWindow *mainWindow = nullptr;
|
||||
};
|
||||
|
||||
class DesignModePrivate
|
||||
@@ -107,16 +110,17 @@ void DesignMode::setDesignModeIsRequired()
|
||||
*/
|
||||
void DesignMode::registerDesignWidget(QWidget *widget,
|
||||
const QStringList &mimeTypes,
|
||||
const Context &context)
|
||||
const Context &context,
|
||||
Utils::FancyMainWindow *mainWindow)
|
||||
{
|
||||
setDesignModeIsRequired();
|
||||
int index = d->m_stackWidget->addWidget(widget);
|
||||
|
||||
auto info = new DesignEditorInfo;
|
||||
info->mimeTypes = mimeTypes;
|
||||
info->context = context;
|
||||
info->widgetIndex = index;
|
||||
info->widget = widget;
|
||||
info->mainWindow = mainWindow;
|
||||
d->m_editors.append(info);
|
||||
}
|
||||
|
||||
@@ -147,6 +151,7 @@ void DesignMode::currentEditorChanged(IEditor *editor)
|
||||
for (const QString &mime : editorInfo->mimeTypes) {
|
||||
if (mime == mimeType) {
|
||||
d->m_stackWidget->setCurrentIndex(editorInfo->widgetIndex);
|
||||
setMainWindow(editorInfo->mainWindow);
|
||||
setActiveContext(editorInfo->context);
|
||||
mimeEditorAvailable = true;
|
||||
setEnabled(true);
|
||||
@@ -202,11 +207,6 @@ void DesignMode::setActiveContext(const Context &context)
|
||||
d->m_activeContext = context;
|
||||
}
|
||||
|
||||
Utils::FancyMainWindow *DesignMode::mainWindow()
|
||||
{
|
||||
return Aggregation::query<Utils::FancyMainWindow>(d->m_stackWidget->currentWidget());
|
||||
}
|
||||
|
||||
void DesignMode::createModeIfRequired()
|
||||
{
|
||||
if (d) {
|
||||
|
||||
Reference in New Issue
Block a user