Add KDDockWidgets::initPlatform()
Instead of using the static variable, which is initialized before having QApplication. Will allow us to remove the QTimer from Platform init
This commit is contained in:
@@ -33,10 +33,11 @@ int main(int argc, char **argv)
|
|||||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
#endif
|
#endif
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
app.setOrganizationName(QStringLiteral("KDAB"));
|
app.setOrganizationName(QStringLiteral("KDAB"));
|
||||||
app.setApplicationName(QStringLiteral("Test app"));
|
app.setApplicationName(QStringLiteral("Test app"));
|
||||||
|
|
||||||
|
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtWidgets);
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("KDDockWidgets example application");
|
parser.setApplicationDescription("KDDockWidgets example application");
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ int main(int argc, char **argv)
|
|||||||
app.setOrganizationName(QStringLiteral("KDAB"));
|
app.setOrganizationName(QStringLiteral("KDAB"));
|
||||||
app.setApplicationName(QStringLiteral("App supporting both docking and a MDI area"));
|
app.setApplicationName(QStringLiteral("App supporting both docking and a MDI area"));
|
||||||
|
|
||||||
|
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtWidgets);
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("KDDockWidgets MDI mixed with normal docking");
|
parser.setApplicationDescription("KDDockWidgets MDI mixed with normal docking");
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ int main(int argc, char **argv)
|
|||||||
app.setOrganizationName(QStringLiteral("KDAB"));
|
app.setOrganizationName(QStringLiteral("KDAB"));
|
||||||
app.setApplicationName(QStringLiteral("Test app"));
|
app.setApplicationName(QStringLiteral("Test app"));
|
||||||
|
|
||||||
|
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtWidgets);
|
||||||
|
|
||||||
// Fusion looks better in general, but feel free to change
|
// Fusion looks better in general, but feel free to change
|
||||||
qApp->setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
|
qApp->setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,11 @@ int main(int argc, char **argv)
|
|||||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
#endif
|
#endif
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
app.setOrganizationName(QStringLiteral("KDAB"));
|
app.setOrganizationName(QStringLiteral("KDAB"));
|
||||||
app.setApplicationName(QStringLiteral("Test app"));
|
app.setApplicationName(QStringLiteral("Test app"));
|
||||||
|
|
||||||
|
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtWidgets);
|
||||||
|
|
||||||
// Fusion looks better in general, but feel free to change
|
// Fusion looks better in general, but feel free to change
|
||||||
qApp->setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
|
qApp->setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ add_definitions(-DQT_NO_SIGNALS_SLOTS_KEYWORDS
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(DOCKSLIBS_SRCS
|
set(DOCKSLIBS_SRCS
|
||||||
|
KDDockWidgets.cpp
|
||||||
Config.cpp
|
Config.cpp
|
||||||
Config.h
|
Config.h
|
||||||
Qt5Qt6Compat_p.h
|
Qt5Qt6Compat_p.h
|
||||||
|
|||||||
33
src/KDDockWidgets.cpp
Normal file
33
src/KDDockWidgets.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
This file is part of KDDockWidgets.
|
||||||
|
|
||||||
|
SPDX-FileCopyrightText: 2019-2022 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
|
||||||
|
Author: Sérgio Martins <sergio.martins@kdab.com>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
|
Contact KDAB at <info@kdab.com> for commercial licensing options.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "KDDockWidgets.h"
|
||||||
|
|
||||||
|
#include "qtwidgets/Platform_qtwidgets.h"
|
||||||
|
#include "qtquick/Platform_qtquick.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
void KDDockWidgets::initFrontend(FrontendType type)
|
||||||
|
{
|
||||||
|
if (Platform::instance())
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case FrontendType::QtWidgets:
|
||||||
|
new Platform_qtwidgets();
|
||||||
|
break;
|
||||||
|
case FrontendType::QtQuick:
|
||||||
|
// new Platform_qtquick(); // TODOv2
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,12 +60,12 @@ enum MainWindowOption {
|
|||||||
Q_DECLARE_FLAGS(MainWindowOptions, MainWindowOption)
|
Q_DECLARE_FLAGS(MainWindowOptions, MainWindowOption)
|
||||||
Q_ENUM_NS(MainWindowOptions)
|
Q_ENUM_NS(MainWindowOptions)
|
||||||
|
|
||||||
enum class FrontEndType
|
enum class FrontendType
|
||||||
{
|
{
|
||||||
QtWidgets = 1,
|
QtWidgets = 1,
|
||||||
QtQuick
|
QtQuick
|
||||||
};
|
};
|
||||||
Q_ENUM_NS(FrontEndType)
|
Q_ENUM_NS(FrontendType)
|
||||||
|
|
||||||
///@internal
|
///@internal
|
||||||
///@brief Describes some sizing strategies for the layouting engine.
|
///@brief Describes some sizing strategies for the layouting engine.
|
||||||
@@ -310,7 +310,11 @@ inline QString locationStr(Location loc)
|
|||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/// @brief Initializes the desired frontend
|
||||||
|
void DOCKS_EXPORT initFrontend(FrontendType);
|
||||||
|
|
||||||
|
} // end namespace
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
///@internal
|
///@internal
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ static Platform *s_platform = nullptr;
|
|||||||
|
|
||||||
Platform::Platform()
|
Platform::Platform()
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(!s_platform);
|
||||||
s_platform = this;
|
s_platform = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "Window_qt.h"
|
#include "Window_qt.h"
|
||||||
|
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
#include <QDebug>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
||||||
using namespace KDDockWidgets;
|
using namespace KDDockWidgets;
|
||||||
@@ -20,6 +21,8 @@ using namespace KDDockWidgets;
|
|||||||
|
|
||||||
Platform_qt::Platform_qt()
|
Platform_qt::Platform_qt()
|
||||||
{
|
{
|
||||||
|
if (!qApp)
|
||||||
|
qWarning() << "Please call KDDockWidgets::initPlatform() after QGuiApplication";
|
||||||
}
|
}
|
||||||
|
|
||||||
Platform_qt::~Platform_qt()
|
Platform_qt::~Platform_qt()
|
||||||
|
|||||||
@@ -22,8 +22,6 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
|
||||||
static KDDockWidgets::Platform_qtquick s_platformQtQuick;
|
|
||||||
|
|
||||||
using namespace KDDockWidgets;
|
using namespace KDDockWidgets;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
|
||||||
static KDDockWidgets::Platform_qtwidgets s_platformQtWidgets;
|
|
||||||
|
|
||||||
using namespace KDDockWidgets;
|
using namespace KDDockWidgets;
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ class TestDocks : public QObject
|
|||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void initTestCase()
|
void initTestCase()
|
||||||
{
|
{
|
||||||
|
// TODOv2
|
||||||
|
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtWidgets);
|
||||||
|
|
||||||
qputenv("KDDOCKWIDGETS_SHOW_DEBUG_WINDOW", "");
|
qputenv("KDDOCKWIDGETS_SHOW_DEBUG_WINDOW", "");
|
||||||
qApp->setOrganizationName("KDAB");
|
qApp->setOrganizationName("KDAB");
|
||||||
qApp->setApplicationName("dockwidgets-unit-tests");
|
qApp->setApplicationName("dockwidgets-unit-tests");
|
||||||
|
|||||||
Reference in New Issue
Block a user