From e7b67edeefcf01a7155c8b6adeffb1304d4d22e4 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Mon, 3 Apr 2023 09:04:48 +0200 Subject: examples: Remove hierarchy example Functionality is also covered in other examples so that hierarchy is no longer needed. In order to keep the use case's code in source, the example was moved to tests/manual. Pick-to: 6.5 Change-Id: I6b3e46d402877b93cfa4dc555328e1e115ec4fc6 Reviewed-by: Volker Hilsheimer --- examples/activeqt/CMakeLists.txt | 1 - examples/activeqt/activeqt.pro | 1 - examples/activeqt/hierarchy/CMakeLists.txt | 34 ---------- .../doc/snippets/hierarchy-demo-snippet.qdoc | 44 ------------- examples/activeqt/hierarchy/doc/src/hierarchy.qdoc | 64 ------------------- examples/activeqt/hierarchy/hierarchy.def | 6 -- examples/activeqt/hierarchy/hierarchy.ico | Bin 766 -> 0 bytes examples/activeqt/hierarchy/hierarchy.inf | 9 --- examples/activeqt/hierarchy/hierarchy.pro | 16 ----- examples/activeqt/hierarchy/hierarchy.rc | 2 - examples/activeqt/hierarchy/main.cpp | 12 ---- examples/activeqt/hierarchy/objects.cpp | 70 --------------------- examples/activeqt/hierarchy/objects.h | 62 ------------------ tests/manual/CMakeLists.txt | 1 + tests/manual/hierarchy/CMakeLists.txt | 24 +++++++ .../doc/snippets/hierarchy-demo-snippet.qdoc | 44 +++++++++++++ tests/manual/hierarchy/doc/src/hierarchy.qdoc | 64 +++++++++++++++++++ tests/manual/hierarchy/hierarchy.def | 6 ++ tests/manual/hierarchy/hierarchy.ico | Bin 0 -> 766 bytes tests/manual/hierarchy/hierarchy.inf | 9 +++ tests/manual/hierarchy/hierarchy.pro | 16 +++++ tests/manual/hierarchy/hierarchy.rc | 2 + tests/manual/hierarchy/main.cpp | 12 ++++ tests/manual/hierarchy/objects.cpp | 70 +++++++++++++++++++++ tests/manual/hierarchy/objects.h | 62 ++++++++++++++++++ 25 files changed, 310 insertions(+), 321 deletions(-) delete mode 100644 examples/activeqt/hierarchy/CMakeLists.txt delete mode 100644 examples/activeqt/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc delete mode 100644 examples/activeqt/hierarchy/doc/src/hierarchy.qdoc delete mode 100644 examples/activeqt/hierarchy/hierarchy.def delete mode 100644 examples/activeqt/hierarchy/hierarchy.ico delete mode 100644 examples/activeqt/hierarchy/hierarchy.inf delete mode 100644 examples/activeqt/hierarchy/hierarchy.pro delete mode 100644 examples/activeqt/hierarchy/hierarchy.rc delete mode 100644 examples/activeqt/hierarchy/main.cpp delete mode 100644 examples/activeqt/hierarchy/objects.cpp delete mode 100644 examples/activeqt/hierarchy/objects.h create mode 100644 tests/manual/hierarchy/CMakeLists.txt create mode 100644 tests/manual/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc create mode 100644 tests/manual/hierarchy/doc/src/hierarchy.qdoc create mode 100644 tests/manual/hierarchy/hierarchy.def create mode 100644 tests/manual/hierarchy/hierarchy.ico create mode 100644 tests/manual/hierarchy/hierarchy.inf create mode 100644 tests/manual/hierarchy/hierarchy.pro create mode 100644 tests/manual/hierarchy/hierarchy.rc create mode 100644 tests/manual/hierarchy/main.cpp create mode 100644 tests/manual/hierarchy/objects.cpp create mode 100644 tests/manual/hierarchy/objects.h diff --git a/examples/activeqt/CMakeLists.txt b/examples/activeqt/CMakeLists.txt index de0a97b..b64c0d0 100644 --- a/examples/activeqt/CMakeLists.txt +++ b/examples/activeqt/CMakeLists.txt @@ -3,7 +3,6 @@ if(MSVC) qt_internal_add_example(comapp) - qt_internal_add_example(hierarchy) qt_internal_add_example(menus) qt_internal_add_example(multiple) qt_internal_add_example(simple) diff --git a/examples/activeqt/activeqt.pro b/examples/activeqt/activeqt.pro index 6f189bc..8dcceff 100644 --- a/examples/activeqt/activeqt.pro +++ b/examples/activeqt/activeqt.pro @@ -1,6 +1,5 @@ TEMPLATE = subdirs SUBDIRS += comapp \ - hierarchy \ menus \ multiple \ simple \ diff --git a/examples/activeqt/hierarchy/CMakeLists.txt b/examples/activeqt/hierarchy/CMakeLists.txt deleted file mode 100644 index 6f3466e..0000000 --- a/examples/activeqt/hierarchy/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(hierarchyax LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/activeqt/hierarchy") - -find_package(Qt6 REQUIRED COMPONENTS AxServer Core Gui Widgets) - -qt6_add_axserver_library(hierarchyax - main.cpp - objects.cpp objects.h - hierarchy.def - hierarchy.rc -) - -target_link_libraries(hierarchyax PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets -) - -install(TARGETS hierarchyax - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/activeqt/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc b/examples/activeqt/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc deleted file mode 100644 index 9b14316..0000000 --- a/examples/activeqt/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -//! [script] - - -

-This widget can have many children! -

- -[Object not available! Did you forget to build and register the server?] -
-
- - - - -
- - -
-//! [script] diff --git a/examples/activeqt/hierarchy/doc/src/hierarchy.qdoc b/examples/activeqt/hierarchy/doc/src/hierarchy.qdoc deleted file mode 100644 index bc1c6e5..0000000 --- a/examples/activeqt/hierarchy/doc/src/hierarchy.qdoc +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \page qaxserver-demo-hierarchy.html - \title Qt Widget Hierarchy - - \input examples/hierarchy-demo.qdocinc -*/ - -/*! - \example activeqt/hierarchy - \title Hierarchy Example (ActiveQt) - - \brief The Hierarchy example is shows how to write an in-process ActiveX - control. The control is a QWidget subclass with child widgets - that are accessible as sub-types. - - \snippet activeqt/hierarchy/objects.h 0 - The \c QParentWidget class provides slots to create a widget - with a name, and to return a pointer to a named widget. The class - declaration uses \c Q_CLASSINFO() to provide the COM identifiers for - this class. - - \snippet activeqt/hierarchy/objects.cpp 0 - The constructor of \c QParentWidget creates a vertical box layout. - New child widgets are automatically added to the layout. - - \snippet activeqt/hierarchy/objects.cpp 1 - The \c createSubWidget slot creates a new \c QSubWidget with - the name provided in the parameter, and sets the label to that - name. The widget is also shown explicitly. - - \snippet activeqt/hierarchy/objects.cpp 2 - The \c subWidget slot uses the \c QObject::findChild() function and - returns the first child of type \c QSubWidget that has the requested - name. - - \snippet activeqt/hierarchy/objects.h 1 - The \c QSubWidget class has a single string-property \c label, - and implements the paintEvent to draw the label. The class uses - again \c Q_CLASSINFO to provide the COM identifiers, and also sets - the \e ToSuperClass attribute to \e QSubWidget, to ensure that only - no slots of any superclasses (i.e. QWidget) are exposed. - - \snippet activeqt/hierarchy/objects.cpp 3 - \snippet activeqt/hierarchy/objects.cpp 4 - The implementation of the \c QSubWidget class is self-explanatory. - - \snippet activeqt/hierarchy/main.cpp 0 - The classes are then exported using a QAxFactory. \c QParentWidget is - exported as a full class (which can be created ), while \c QSubWidget is - only exported as a type, which can only be created indirectly through - APIs of \c QParentWidget. - - To build the example you must first build the QAxServer library. - Then run qmake and your make tool in \c activeqt/hierarchy. - - The \l{qaxserver-demo-hierarchy.html}{demonstration} requires - your WebBrowser to support ActiveX controls, and scripting to be - enabled. - - \snippet activeqt/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc script -*/ diff --git a/examples/activeqt/hierarchy/hierarchy.def b/examples/activeqt/hierarchy/hierarchy.def deleted file mode 100644 index bc82a03..0000000 --- a/examples/activeqt/hierarchy/hierarchy.def +++ /dev/null @@ -1,6 +0,0 @@ -EXPORTS - DllCanUnloadNow PRIVATE - DllGetClassObject PRIVATE - DllRegisterServer PRIVATE - DllUnregisterServer PRIVATE - DumpIDL PRIVATE diff --git a/examples/activeqt/hierarchy/hierarchy.ico b/examples/activeqt/hierarchy/hierarchy.ico deleted file mode 100644 index c80d36a..0000000 Binary files a/examples/activeqt/hierarchy/hierarchy.ico and /dev/null differ diff --git a/examples/activeqt/hierarchy/hierarchy.inf b/examples/activeqt/hierarchy/hierarchy.inf deleted file mode 100644 index cb7e90f..0000000 --- a/examples/activeqt/hierarchy/hierarchy.inf +++ /dev/null @@ -1,9 +0,0 @@ -[version] - signature="$CHICAGO$" - AdvancedINF=2.0 - [Add.Code] - hierarchyax.dll=hierarchyax.dll - [hierarchyax.dll] - file-win32-x86=thiscab - clsid={d574a747-8016-46db-a07c-b2b4854ee75c} - RegisterServer=yes diff --git a/examples/activeqt/hierarchy/hierarchy.pro b/examples/activeqt/hierarchy/hierarchy.pro deleted file mode 100644 index acc108a..0000000 --- a/examples/activeqt/hierarchy/hierarchy.pro +++ /dev/null @@ -1,16 +0,0 @@ -include(../shared.pri) - -TEMPLATE = lib -TARGET = hierarchyax - -CONFIG += warn_off dll -QT += widgets axserver - -SOURCES = objects.cpp main.cpp -HEADERS = objects.h -RC_FILE = hierarchy.rc -DEF_FILE = hierarchy.def - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/hierarchy -INSTALLS += target diff --git a/examples/activeqt/hierarchy/hierarchy.rc b/examples/activeqt/hierarchy/hierarchy.rc deleted file mode 100644 index 70eb503..0000000 --- a/examples/activeqt/hierarchy/hierarchy.rc +++ /dev/null @@ -1,2 +0,0 @@ -1 TYPELIB "hierarchy.rc" -1 ICON "hierarchy.ico" diff --git a/examples/activeqt/hierarchy/main.cpp b/examples/activeqt/hierarchy/main.cpp deleted file mode 100644 index 5ebe6e8..0000000 --- a/examples/activeqt/hierarchy/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2015 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//! [0] -#include "objects.h" -#include - -QAXFACTORY_BEGIN("{9e626211-be62-4d18-9483-9419358fbb03}", "{75c276de-1df5-451f-a004-e4fa1a587df1}") - QAXCLASS(QParentWidget) - QAXTYPE(QSubWidget) -QAXFACTORY_END() -//! [0] diff --git a/examples/activeqt/hierarchy/objects.cpp b/examples/activeqt/hierarchy/objects.cpp deleted file mode 100644 index 6dfda44..0000000 --- a/examples/activeqt/hierarchy/objects.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2015 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "objects.h" -#include -#include - -/* Implementation of QParentWidget */ -//! [0] -QParentWidget::QParentWidget(QWidget *parent) -: QWidget(parent), - m_vbox(new QVBoxLayout(this)) -{ -} - -//! [0] //! [1] -void QParentWidget::createSubWidget(const QString &name) -{ - QSubWidget *sw = new QSubWidget(this, name); - m_vbox->addWidget(sw); - sw->setLabel(name); - sw->show(); -} - -//! [1] //! [2] -QSubWidget *QParentWidget::subWidget(const QString &name) -{ - return findChild(name); -} - -//! [2] -QSize QParentWidget::sizeHint() const -{ - return QWidget::sizeHint().expandedTo(QSize(100, 100)); -} - -/* Implementation of QSubWidget */ -//! [3] -QSubWidget::QSubWidget(QWidget *parent, const QString &name) -: QWidget(parent) -{ - setObjectName(name); -} - -void QSubWidget::setLabel(const QString &text) -{ - m_label = text; - setObjectName(text); - update(); -} - -QString QSubWidget::label() const -{ - return m_label; -} - -QSize QSubWidget::sizeHint() const -{ - QFontMetrics fm(font()); - return QSize(fm.horizontalAdvance(m_label), fm.height()); -} - -void QSubWidget::paintEvent(QPaintEvent *) -{ - QPainter painter(this); - painter.setPen(palette().text().color()); - painter.drawText(rect(), Qt::AlignCenter, m_label); -//! [3] //! [4] -} -//! [4] diff --git a/examples/activeqt/hierarchy/objects.h b/examples/activeqt/hierarchy/objects.h deleted file mode 100644 index 6b8bea6..0000000 --- a/examples/activeqt/hierarchy/objects.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2015 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef OBJECTS_H -#define OBJECTS_H - -#include - -QT_BEGIN_NAMESPACE -class QVBoxLayout; -QT_END_NAMESPACE -class QSubWidget; - -//! [0] -class QParentWidget : public QWidget -{ - Q_OBJECT - Q_CLASSINFO("ClassID", "{d574a747-8016-46db-a07c-b2b4854ee75c}"); - Q_CLASSINFO("InterfaceID", "{4a30719d-d9c2-4659-9d16-67378209f822}"); - Q_CLASSINFO("EventsID", "{4a30719d-d9c2-4659-9d16-67378209f823}"); -public: - explicit QParentWidget(QWidget *parent = nullptr); - - QSize sizeHint() const override; - -public slots: - void createSubWidget(const QString &name); - - QSubWidget *subWidget(const QString &name); - -private: - QVBoxLayout *m_vbox; -}; -//! [0] - -//! [1] -class QSubWidget : public QWidget -{ - Q_OBJECT - Q_PROPERTY(QString label READ label WRITE setLabel) - - Q_CLASSINFO("ClassID", "{850652f4-8f71-4f69-b745-bce241ccdc30}"); - Q_CLASSINFO("InterfaceID", "{2d76cc2f-3488-417a-83d6-debff88b3c3f}"); - Q_CLASSINFO("ToSuperClass", "QSubWidget"); - -public: - QSubWidget(QWidget *parent = nullptr, const QString &name = QString()); - - void setLabel(const QString &text); - QString label() const; - - QSize sizeHint() const override; - -protected: - void paintEvent(QPaintEvent *e) override; - -private: - QString m_label; -}; -//! [1] - -#endif // OBJECTS_H diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt index 2a55b2d..bf36621 100644 --- a/tests/manual/CMakeLists.txt +++ b/tests/manual/CMakeLists.txt @@ -3,4 +3,5 @@ add_subdirectory(axviewer) add_subdirectory(dumpcpp) +add_subdirectory(hierarchy) add_subdirectory(testcontrol) diff --git a/tests/manual/hierarchy/CMakeLists.txt b/tests/manual/hierarchy/CMakeLists.txt new file mode 100644 index 0000000..3db0a0e --- /dev/null +++ b/tests/manual/hierarchy/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## hierarchy Library: +##################################################################### + +set(CMAKE_AUTOMOC ON) + +qt_internal_add_manual_test(tst_hierarchy + GUI + SOURCES + main.cpp + objects.cpp objects.h + hierarchy.def + hierarchy.rc + LIBRARIES + Qt::AxServer + Qt::Gui + Qt::Widgets +) + +qt_disable_warnings(tst_hierarchy) +qt6_target_idl(tst_hierarchy) diff --git a/tests/manual/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc b/tests/manual/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc new file mode 100644 index 0000000..9b14316 --- /dev/null +++ b/tests/manual/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc @@ -0,0 +1,44 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +//! [script] + + +

+This widget can have many children! +

+ +[Object not available! Did you forget to build and register the server?] +
+
+ + + + +
+ + +
+//! [script] diff --git a/tests/manual/hierarchy/doc/src/hierarchy.qdoc b/tests/manual/hierarchy/doc/src/hierarchy.qdoc new file mode 100644 index 0000000..bc1c6e5 --- /dev/null +++ b/tests/manual/hierarchy/doc/src/hierarchy.qdoc @@ -0,0 +1,64 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! + \page qaxserver-demo-hierarchy.html + \title Qt Widget Hierarchy + + \input examples/hierarchy-demo.qdocinc +*/ + +/*! + \example activeqt/hierarchy + \title Hierarchy Example (ActiveQt) + + \brief The Hierarchy example is shows how to write an in-process ActiveX + control. The control is a QWidget subclass with child widgets + that are accessible as sub-types. + + \snippet activeqt/hierarchy/objects.h 0 + The \c QParentWidget class provides slots to create a widget + with a name, and to return a pointer to a named widget. The class + declaration uses \c Q_CLASSINFO() to provide the COM identifiers for + this class. + + \snippet activeqt/hierarchy/objects.cpp 0 + The constructor of \c QParentWidget creates a vertical box layout. + New child widgets are automatically added to the layout. + + \snippet activeqt/hierarchy/objects.cpp 1 + The \c createSubWidget slot creates a new \c QSubWidget with + the name provided in the parameter, and sets the label to that + name. The widget is also shown explicitly. + + \snippet activeqt/hierarchy/objects.cpp 2 + The \c subWidget slot uses the \c QObject::findChild() function and + returns the first child of type \c QSubWidget that has the requested + name. + + \snippet activeqt/hierarchy/objects.h 1 + The \c QSubWidget class has a single string-property \c label, + and implements the paintEvent to draw the label. The class uses + again \c Q_CLASSINFO to provide the COM identifiers, and also sets + the \e ToSuperClass attribute to \e QSubWidget, to ensure that only + no slots of any superclasses (i.e. QWidget) are exposed. + + \snippet activeqt/hierarchy/objects.cpp 3 + \snippet activeqt/hierarchy/objects.cpp 4 + The implementation of the \c QSubWidget class is self-explanatory. + + \snippet activeqt/hierarchy/main.cpp 0 + The classes are then exported using a QAxFactory. \c QParentWidget is + exported as a full class (which can be created ), while \c QSubWidget is + only exported as a type, which can only be created indirectly through + APIs of \c QParentWidget. + + To build the example you must first build the QAxServer library. + Then run qmake and your make tool in \c activeqt/hierarchy. + + The \l{qaxserver-demo-hierarchy.html}{demonstration} requires + your WebBrowser to support ActiveX controls, and scripting to be + enabled. + + \snippet activeqt/hierarchy/doc/snippets/hierarchy-demo-snippet.qdoc script +*/ diff --git a/tests/manual/hierarchy/hierarchy.def b/tests/manual/hierarchy/hierarchy.def new file mode 100644 index 0000000..bc82a03 --- /dev/null +++ b/tests/manual/hierarchy/hierarchy.def @@ -0,0 +1,6 @@ +EXPORTS + DllCanUnloadNow PRIVATE + DllGetClassObject PRIVATE + DllRegisterServer PRIVATE + DllUnregisterServer PRIVATE + DumpIDL PRIVATE diff --git a/tests/manual/hierarchy/hierarchy.ico b/tests/manual/hierarchy/hierarchy.ico new file mode 100644 index 0000000..c80d36a Binary files /dev/null and b/tests/manual/hierarchy/hierarchy.ico differ diff --git a/tests/manual/hierarchy/hierarchy.inf b/tests/manual/hierarchy/hierarchy.inf new file mode 100644 index 0000000..cb7e90f --- /dev/null +++ b/tests/manual/hierarchy/hierarchy.inf @@ -0,0 +1,9 @@ +[version] + signature="$CHICAGO$" + AdvancedINF=2.0 + [Add.Code] + hierarchyax.dll=hierarchyax.dll + [hierarchyax.dll] + file-win32-x86=thiscab + clsid={d574a747-8016-46db-a07c-b2b4854ee75c} + RegisterServer=yes diff --git a/tests/manual/hierarchy/hierarchy.pro b/tests/manual/hierarchy/hierarchy.pro new file mode 100644 index 0000000..acc108a --- /dev/null +++ b/tests/manual/hierarchy/hierarchy.pro @@ -0,0 +1,16 @@ +include(../shared.pri) + +TEMPLATE = lib +TARGET = hierarchyax + +CONFIG += warn_off dll +QT += widgets axserver + +SOURCES = objects.cpp main.cpp +HEADERS = objects.h +RC_FILE = hierarchy.rc +DEF_FILE = hierarchy.def + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/activeqt/hierarchy +INSTALLS += target diff --git a/tests/manual/hierarchy/hierarchy.rc b/tests/manual/hierarchy/hierarchy.rc new file mode 100644 index 0000000..70eb503 --- /dev/null +++ b/tests/manual/hierarchy/hierarchy.rc @@ -0,0 +1,2 @@ +1 TYPELIB "hierarchy.rc" +1 ICON "hierarchy.ico" diff --git a/tests/manual/hierarchy/main.cpp b/tests/manual/hierarchy/main.cpp new file mode 100644 index 0000000..5ebe6e8 --- /dev/null +++ b/tests/manual/hierarchy/main.cpp @@ -0,0 +1,12 @@ +// Copyright (C) 2015 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//! [0] +#include "objects.h" +#include + +QAXFACTORY_BEGIN("{9e626211-be62-4d18-9483-9419358fbb03}", "{75c276de-1df5-451f-a004-e4fa1a587df1}") + QAXCLASS(QParentWidget) + QAXTYPE(QSubWidget) +QAXFACTORY_END() +//! [0] diff --git a/tests/manual/hierarchy/objects.cpp b/tests/manual/hierarchy/objects.cpp new file mode 100644 index 0000000..6dfda44 --- /dev/null +++ b/tests/manual/hierarchy/objects.cpp @@ -0,0 +1,70 @@ +// Copyright (C) 2015 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "objects.h" +#include +#include + +/* Implementation of QParentWidget */ +//! [0] +QParentWidget::QParentWidget(QWidget *parent) +: QWidget(parent), + m_vbox(new QVBoxLayout(this)) +{ +} + +//! [0] //! [1] +void QParentWidget::createSubWidget(const QString &name) +{ + QSubWidget *sw = new QSubWidget(this, name); + m_vbox->addWidget(sw); + sw->setLabel(name); + sw->show(); +} + +//! [1] //! [2] +QSubWidget *QParentWidget::subWidget(const QString &name) +{ + return findChild(name); +} + +//! [2] +QSize QParentWidget::sizeHint() const +{ + return QWidget::sizeHint().expandedTo(QSize(100, 100)); +} + +/* Implementation of QSubWidget */ +//! [3] +QSubWidget::QSubWidget(QWidget *parent, const QString &name) +: QWidget(parent) +{ + setObjectName(name); +} + +void QSubWidget::setLabel(const QString &text) +{ + m_label = text; + setObjectName(text); + update(); +} + +QString QSubWidget::label() const +{ + return m_label; +} + +QSize QSubWidget::sizeHint() const +{ + QFontMetrics fm(font()); + return QSize(fm.horizontalAdvance(m_label), fm.height()); +} + +void QSubWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setPen(palette().text().color()); + painter.drawText(rect(), Qt::AlignCenter, m_label); +//! [3] //! [4] +} +//! [4] diff --git a/tests/manual/hierarchy/objects.h b/tests/manual/hierarchy/objects.h new file mode 100644 index 0000000..6b8bea6 --- /dev/null +++ b/tests/manual/hierarchy/objects.h @@ -0,0 +1,62 @@ +// Copyright (C) 2015 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef OBJECTS_H +#define OBJECTS_H + +#include + +QT_BEGIN_NAMESPACE +class QVBoxLayout; +QT_END_NAMESPACE +class QSubWidget; + +//! [0] +class QParentWidget : public QWidget +{ + Q_OBJECT + Q_CLASSINFO("ClassID", "{d574a747-8016-46db-a07c-b2b4854ee75c}"); + Q_CLASSINFO("InterfaceID", "{4a30719d-d9c2-4659-9d16-67378209f822}"); + Q_CLASSINFO("EventsID", "{4a30719d-d9c2-4659-9d16-67378209f823}"); +public: + explicit QParentWidget(QWidget *parent = nullptr); + + QSize sizeHint() const override; + +public slots: + void createSubWidget(const QString &name); + + QSubWidget *subWidget(const QString &name); + +private: + QVBoxLayout *m_vbox; +}; +//! [0] + +//! [1] +class QSubWidget : public QWidget +{ + Q_OBJECT + Q_PROPERTY(QString label READ label WRITE setLabel) + + Q_CLASSINFO("ClassID", "{850652f4-8f71-4f69-b745-bce241ccdc30}"); + Q_CLASSINFO("InterfaceID", "{2d76cc2f-3488-417a-83d6-debff88b3c3f}"); + Q_CLASSINFO("ToSuperClass", "QSubWidget"); + +public: + QSubWidget(QWidget *parent = nullptr, const QString &name = QString()); + + void setLabel(const QString &text); + QString label() const; + + QSize sizeHint() const override; + +protected: + void paintEvent(QPaintEvent *e) override; + +private: + QString m_label; +}; +//! [1] + +#endif // OBJECTS_H -- cgit v1.2.1