Added Platform::createMainWindow()

Called by tests and layout linter to create a main window.

Simplifies creation of the main window, we can now remove one of the ctors.
Before we supported both the controller creating the view and vice-versa,
while this is convenient it's complex to support, due to order or initializations.

Now, you a create a view, and it creates the controller behind the scenes.
MainWindow is special in this sense, as it's created by the end user, it's
not something internal we want in the ViewFactory.
This commit is contained in:
Sergio Martins
2022-05-27 10:23:05 +01:00
parent e20a8ba396
commit 03f1a6930c
17 changed files with 64 additions and 40 deletions

View File

@@ -18,6 +18,8 @@
#include "views/View_qtwidgets.h"
#include "ViewFactory_qtwidgets.h"
#include "controllers/MainWindow.h"
#include "qtwidgets/views/MainWindow_qtwidgets.h"
#include <QScreen>
@@ -124,3 +126,13 @@ View *Platform_qtwidgets::createView(View *parent) const
{
return new Views::View_qtwidgets<QWidget>(nullptr, Type::None, Views::View_qtwidgets<QWidget>::asQWidget(parent));
}
Controllers::MainWindow *Platform_qtwidgets::createMainWindow(const QString &uniqueName, MainWindowOptions options,
View *parent, Qt::WindowFlags flags) const
{
auto view = new Views::MainWindow_qtwidgets(uniqueName, options,
parent ? static_cast<Views::View_qtwidgets<QMainWindow> *>(parent) : nullptr,
flags);
return view->mainWindow();
}