hellogl2 example: Decouple mainwindow from window
The circular dependency cannot be ported to the corresponding Python example. Task-number: PYSIDE-2206 Change-Id: I031b3fffdd7bd677d2fc55e132975a65f66ad128 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io> (cherry picked from commit 62eaaeb4f58388dc56cb1b23beae892e2fd6df89) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 6c9ecf98e1624c3eb359e76563c92429ea9c6aa1)
This commit is contained in:
parent
b74b101a06
commit
c9c585b067
@ -23,7 +23,7 @@ MainWindow::MainWindow()
|
|||||||
void MainWindow::onAddNew()
|
void MainWindow::onAddNew()
|
||||||
{
|
{
|
||||||
if (!centralWidget())
|
if (!centralWidget())
|
||||||
setCentralWidget(new Window(this));
|
setCentralWidget(new Window);
|
||||||
else
|
else
|
||||||
QMessageBox::information(this, tr("Cannot Add New Window"),
|
QMessageBox::information(this, tr("Cannot Add New Window"),
|
||||||
tr("Already occupied. Undock first."));
|
tr("Already occupied. Undock first."));
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||||
|
|
||||||
#include "glwidget.h"
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "mainwindow.h"
|
#include "glwidget.h"
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
@ -11,9 +10,18 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QMainWindow>
|
||||||
|
|
||||||
Window::Window(MainWindow *mw)
|
static QMainWindow *findMainWindow()
|
||||||
: mainWindow(mw)
|
{
|
||||||
|
for (auto *w : QApplication::topLevelWidgets()) {
|
||||||
|
if (auto *mw = qobject_cast<QMainWindow *>(w))
|
||||||
|
return mw;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::Window()
|
||||||
{
|
{
|
||||||
glWidget = new GLWidget;
|
glWidget = new GLWidget;
|
||||||
|
|
||||||
@ -77,7 +85,8 @@ void Window::dockUndock()
|
|||||||
|
|
||||||
void Window::dock()
|
void Window::dock()
|
||||||
{
|
{
|
||||||
if (!mainWindow->isVisible()) {
|
auto *mainWindow = findMainWindow();
|
||||||
|
if (mainWindow == nullptr || !mainWindow->isVisible()) {
|
||||||
QMessageBox::information(this, tr("Cannot Dock"),
|
QMessageBox::information(this, tr("Cannot Dock"),
|
||||||
tr("Main window already closed"));
|
tr("Main window already closed"));
|
||||||
return;
|
return;
|
||||||
|
@ -10,14 +10,13 @@ QT_FORWARD_DECLARE_CLASS(QSlider)
|
|||||||
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
||||||
|
|
||||||
class GLWidget;
|
class GLWidget;
|
||||||
class MainWindow;
|
|
||||||
|
|
||||||
class Window : public QWidget
|
class Window : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Window(MainWindow *mw);
|
Window();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
@ -35,7 +34,6 @@ private:
|
|||||||
QSlider *ySlider;
|
QSlider *ySlider;
|
||||||
QSlider *zSlider;
|
QSlider *zSlider;
|
||||||
QPushButton *dockBtn;
|
QPushButton *dockBtn;
|
||||||
MainWindow *mainWindow;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user