ADTF Qt5
Loading...
Searching...
No Matches
sub_window_creator.h
Go to the documentation of this file.
1
7
8/*
9 * This file depends on Qt which is licensed under LGPLv3.
10 * See ADTF_DIR/3rdparty/qt5 and doc/license for detailed information.
11 */
12#pragma once
13#include <adtfjavascriptfiltersdk/qtquick_filter.h>
14#include <adtfbase/error_handling_intf.h>
18#include <adtfstreaming3/graph_element_editors.h>
19
20#include <QGuiApplication>
21#include <QQmlEngine>
22#include <QQmlContext>
23#include <QQuickWidget>
24#include <QPointer>
25#include <QQuickView>
26
27
28#undef GetObjectA
29#undef CreateWindow
30#undef GetObject
31
32// @cond NO_DOC_INTERNAL
33class cQtSubWindow : public adtf::ui::cQtWindow
34{
35public:
36 cQtSubWindow(QString strName)
37 {
38 m_strTitle = strName.toStdString().c_str();
39 }
40
41 ~cQtSubWindow() override
42 {
43 }
44
45 QWidget* CreateView() override
46 {
47 m_pView = new QQuickView();
48 m_pView->setSource(QUrl::fromLocalFile("empty.qml"));
49 m_pView->setResizeMode(QQuickView::SizeRootObjectToView);
50 QWidget* pContainer = QWidget::createWindowContainer(m_pView);
51 pContainer->setObjectName(m_strTitle->GetPtr());
52 return pContainer;
53 }
54
55 void ReleaseView() override
56 {
57 if (m_pView)
58 {
59 m_pView->close();
60 delete m_pView;
61 }
62 }
63
64 adtf::base::property_variable<adtf::util::cString>& GetTitle()
65 {
66 return m_strTitle;
67 }
68
69 QQuickView* m_pView = nullptr;
70};
71
72class cQtSubWindowCreator : public QObject
73{
74 Q_OBJECT
75public:
76 cQtSubWindowCreator()
77 {
78 }
79
80 ~cQtSubWindowCreator() noexcept override
81 {
82 if (IS_OK(_runtime->GetObject(m_pXSystem)))
83 {
84 for (auto& pContainer : m_lstContainers)
85 {
86 m_pXSystem->DestroyWindow(*pContainer);
87 }
88 }
89 }
90
91 Q_INVOKABLE QQuickItem* CreateWindow(QString strName)
92 {
93 if (IS_OK(_runtime->GetObject(m_pXSystem)))
94 {
95 auto pSubWindow = std::make_unique<cQtSubWindow>(strName);
96 m_pXSystem->CreateWindow(*pSubWindow);
97
98 auto pView = pSubWindow->m_pView;
99 m_lstContainers.push_back(std::move(pSubWindow));
100
101 return pView->rootObject();
102 }
103 return nullptr;
104 }
105
106private:
107 std::vector<std::unique_ptr<cQtSubWindow>> m_lstContainers;
108 adtf::ucom::object_ptr<adtf::ui::IQtXSystem> m_pXSystem;
109};
110// @endcond NO_DOC_INTERNAL
virtual QWidget * CreateView()=0
virtual void ReleaseView()=0
Definition xsystem_qtwindow.h:231