From ef313e402aa2895f2d4d33a0d0d9ec269c84905f Mon Sep 17 00:00:00 2001 From: Znurre Date: Mon, 19 Feb 2018 21:12:19 +0100 Subject: [PATCH 1/5] Add support for Splitter --- src/declarativesplitter.cpp | 88 +++++++++++++++++++ src/declarativesplitter_p.h | 67 ++++++++++++++ src/declarativewidgets_plugin.cpp | 3 + src/splitterwidgetcontainer.cpp | 65 ++++++++++++++ src/splitterwidgetcontainer_p.h | 52 +++++++++++ src/src.pro | 8 +- tests/auto/instantiatetypes/qml.qrc | 1 + .../qml/creatable/widgets/Splitter.qml | 32 +++++++ 8 files changed, 314 insertions(+), 2 deletions(-) create mode 100644 src/declarativesplitter.cpp create mode 100644 src/declarativesplitter_p.h create mode 100644 src/splitterwidgetcontainer.cpp create mode 100644 src/splitterwidgetcontainer_p.h create mode 100644 tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml diff --git a/src/declarativesplitter.cpp b/src/declarativesplitter.cpp new file mode 100644 index 0000000..86905e4 --- /dev/null +++ b/src/declarativesplitter.cpp @@ -0,0 +1,88 @@ +/* + declarativesplitter.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "declarativesplitter_p.h" + +#include +#include +#include + +class DeclarativeSplitterAttached::Private +{ + public: + Private(QWidget *w) + : stretch(0) + , widget(w) + { + } + + int stretch; + + QPointer widget; +}; + +DeclarativeSplitterAttached::DeclarativeSplitterAttached(QWidget *widget, QObject *parent) + : QObject(parent) + , d(new Private(widget)) +{ +} + +DeclarativeSplitterAttached::~DeclarativeSplitterAttached() +{ + delete d; +} + +void DeclarativeSplitterAttached::setStretch(int stretch) +{ + if (stretch == d->stretch) + return; + + d->stretch = stretch; + + emit stretchChanged(stretch); +} + +int DeclarativeSplitterAttached::stretch() const +{ + return d->stretch; +} + +DeclarativeSplitter::DeclarativeSplitter(QWidget *parent) + : QSplitter(parent) +{ +} + +DeclarativeSplitterAttached *DeclarativeSplitter::qmlAttachedProperties(QObject *parent) +{ + QWidget *widget = qobject_cast(parent); + if (widget) + return new DeclarativeSplitterAttached(widget, parent); + + qmlInfo(parent) << "Can only attach Splitter to widgets"; + + return Q_NULLPTR; +} diff --git a/src/declarativesplitter_p.h b/src/declarativesplitter_p.h new file mode 100644 index 0000000..f5ed2aa --- /dev/null +++ b/src/declarativesplitter_p.h @@ -0,0 +1,67 @@ +/* + declarativesplitter_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef DECLARATIVESPLITTER_P_H +#define DECLARATIVESPLITTER_P_H + +#include +#include +#include +#include + +class DeclarativeSplitterAttached : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged) + + public: + DeclarativeSplitterAttached(QWidget *widget, QObject *parent); + ~DeclarativeSplitterAttached(); + + void setStretch(int stretch); + int stretch() const; + + Q_SIGNALS: + void stretchChanged(int stretch); + + private: + class Private; + Private *const d; +}; + +class DeclarativeSplitter : public QSplitter +{ + public: + DeclarativeSplitter(QWidget *parent = Q_NULLPTR); + + static DeclarativeSplitterAttached *qmlAttachedProperties(QObject *parent); +}; + +QML_DECLARE_TYPEINFO(DeclarativeSplitter, QML_HAS_ATTACHED_PROPERTIES) + +#endif // DECLARATIVESPLITTER_P_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index 5c0267c..a57a806 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -70,6 +70,8 @@ #include "scrollareawidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" +#include "splitterwidgetcontainer_p.h" +#include "declarativesplitter_p.h" #include #include @@ -206,4 +208,5 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "WebEngineView"); #endif qmlRegisterExtendedType(uri, 1, 0, "Widget"); + qmlRegisterExtendedType>(uri, 1, 0, "Splitter"); } diff --git a/src/splitterwidgetcontainer.cpp b/src/splitterwidgetcontainer.cpp new file mode 100644 index 0000000..fc2bbac --- /dev/null +++ b/src/splitterwidgetcontainer.cpp @@ -0,0 +1,65 @@ +/* + splitterwidgetcontainer.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "splitterwidgetcontainer_p.h" + +#include "declarativesplitter_p.h" + +#include +#include +#include + +SplitterWidgetContainer::SplitterWidgetContainer(QObject *parent) + : DefaultWidgetContainer(qobject_cast(parent)) +{ + Q_ASSERT(m_widget); +} + +void SplitterWidgetContainer::setLayout(QLayout *layout) +{ + Q_UNUSED(layout); + qmlInfo(m_widget) << "Can not set a Layout to a Splitter"; +} + +void SplitterWidgetContainer::addWidget(QWidget *widget) +{ + QObject *attachedProperties = qmlAttachedPropertiesObject(widget, false); + DeclarativeSplitterAttached *properties = qobject_cast(attachedProperties); + if (properties) { + QSizePolicy policy = widget->sizePolicy(); + policy.setHorizontalStretch(properties->stretch()); + policy.setVerticalStretch(properties->stretch()); + widget->setSizePolicy(policy); + } + + extendedSplitter()->addWidget(widget); +} + +QSplitter *SplitterWidgetContainer::extendedSplitter() const +{ + return static_cast(m_widget); +} diff --git a/src/splitterwidgetcontainer_p.h b/src/splitterwidgetcontainer_p.h new file mode 100644 index 0000000..3c4ff3e --- /dev/null +++ b/src/splitterwidgetcontainer_p.h @@ -0,0 +1,52 @@ +/* + splitterwidgetcontainer_p.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef SPLITTERWIDGETCONTAINER_P_H +#define SPLITTERWIDGETCONTAINER_P_H + +#include + +#include "defaultwidgetcontainer.h" + +QT_BEGIN_NAMESPACE +class QSplitter; +class QObject; +QT_END_NAMESPACE + +class SplitterWidgetContainer : public DefaultWidgetContainer +{ + public: + explicit SplitterWidgetContainer(QObject *parent = Q_NULLPTR); + + void setLayout(QLayout *layout) Q_DECL_OVERRIDE; + void addWidget(QWidget *widget) Q_DECL_OVERRIDE; + + private: + QSplitter *extendedSplitter() const; +}; + +#endif // SPLITTERWIDGETCONTAINER_P_H diff --git a/src/src.pro b/src/src.pro index 6d5919b..d535780 100644 --- a/src/src.pro +++ b/src/src.pro @@ -86,7 +86,9 @@ HEADERS = \ staticdialogmethodattached_p.h \ toolbarwidgetcontainer_p.h \ widgetcontainerinterface_p.h \ - declarativesizepolicy_p.h + declarativesizepolicy_p.h \ + splitterwidgetcontainer_p.h \ + declarativesplitter_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -137,4 +139,6 @@ SOURCES = \ stackedwidgetwidgetcontainer.cpp \ staticdialogmethodattached.cpp \ toolbarwidgetcontainer.cpp \ - declarativesizepolicy.cpp + declarativesizepolicy.cpp \ + splitterwidgetcontainer.cpp \ + declarativesplitter.cpp diff --git a/tests/auto/instantiatetypes/qml.qrc b/tests/auto/instantiatetypes/qml.qrc index 1a8ebb9..192dec0 100644 --- a/tests/auto/instantiatetypes/qml.qrc +++ b/tests/auto/instantiatetypes/qml.qrc @@ -66,5 +66,6 @@ qml/uncreatable/ItemSelectionModel.qml qml/uncreatable/TextDocument.qml qml/creatable/webenginewidgets/WebEngineView.qml + qml/creatable/widgets/Splitter.qml diff --git a/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml b/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml new file mode 100644 index 0000000..2dfca9b --- /dev/null +++ b/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml @@ -0,0 +1,32 @@ +/* + Splitter.qml + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import QtWidgets 1.0 + +Splitter { + +} From 39f80315ed3410aaf3fe3c213d44f5e9c0f63241 Mon Sep 17 00:00:00 2001 From: Znurre Date: Mon, 26 Mar 2018 12:21:21 +0200 Subject: [PATCH 2/5] Changed year in copyright header --- src/declarativesplitter.cpp | 2 +- src/declarativesplitter_p.h | 2 +- src/splitterwidgetcontainer.cpp | 2 +- src/splitterwidgetcontainer_p.h | 2 +- tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/declarativesplitter.cpp b/src/declarativesplitter.cpp index 86905e4..abf0a7b 100644 --- a/src/declarativesplitter.cpp +++ b/src/declarativesplitter.cpp @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/src/declarativesplitter_p.h b/src/declarativesplitter_p.h index f5ed2aa..f0e7730 100644 --- a/src/declarativesplitter_p.h +++ b/src/declarativesplitter_p.h @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/src/splitterwidgetcontainer.cpp b/src/splitterwidgetcontainer.cpp index fc2bbac..b6e6af4 100644 --- a/src/splitterwidgetcontainer.cpp +++ b/src/splitterwidgetcontainer.cpp @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/src/splitterwidgetcontainer_p.h b/src/splitterwidgetcontainer_p.h index 3c4ff3e..9de7b87 100644 --- a/src/splitterwidgetcontainer_p.h +++ b/src/splitterwidgetcontainer_p.h @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2013-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in diff --git a/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml b/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml index 2dfca9b..f0b2483 100644 --- a/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml +++ b/tests/auto/instantiatetypes/qml/creatable/widgets/Splitter.qml @@ -3,7 +3,7 @@ This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Lova Widmark Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in From 86bf0212e46f7348f608fbfe41356f3b62b2f97f Mon Sep 17 00:00:00 2001 From: Znurre Date: Wed, 28 Mar 2018 17:14:10 +0200 Subject: [PATCH 3/5] Added Splitter layout tests --- tests/auto/layouts/layouts.pro | 9 +++-- tests/auto/layouts/qml.qrc | 1 + tests/auto/layouts/qml/SplitterTest.qml | 37 ++++++++++++++++++ tests/auto/layouts/splitter.cpp | 42 ++++++++++++++++++++ tests/auto/layouts/splitter.h | 52 +++++++++++++++++++++++++ tests/auto/layouts/splitter.ui | 18 +++++++++ tests/auto/layouts/tst_layouts.cpp | 23 +++++++++++ 7 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 tests/auto/layouts/qml/SplitterTest.qml create mode 100644 tests/auto/layouts/splitter.cpp create mode 100644 tests/auto/layouts/splitter.h create mode 100644 tests/auto/layouts/splitter.ui diff --git a/tests/auto/layouts/layouts.pro b/tests/auto/layouts/layouts.pro index 82ad540..77eb65e 100644 --- a/tests/auto/layouts/layouts.pro +++ b/tests/auto/layouts/layouts.pro @@ -6,7 +6,8 @@ SOURCES += tst_layouts.cpp \ formlayoutwidget.cpp \ gridlayoutwidget.cpp \ stackedlayoutwidget.cpp \ - stackedwidget.cpp + stackedwidget.cpp \ + splitter.cpp RESOURCES += \ qml.qrc @@ -16,7 +17,8 @@ FORMS += \ vboxlayout.ui \ formlayout.ui \ gridlayout.ui \ - stackedwidget.ui + stackedwidget.ui \ + splitter.ui HEADERS += \ hboxlayoutwidget.h \ @@ -24,4 +26,5 @@ HEADERS += \ formlayoutwidget.h \ gridlayoutwidget.h \ stackedlayoutwidget.h \ - stackedwidget.h + stackedwidget.h \ + splitter.h diff --git a/tests/auto/layouts/qml.qrc b/tests/auto/layouts/qml.qrc index a71de82..c150531 100644 --- a/tests/auto/layouts/qml.qrc +++ b/tests/auto/layouts/qml.qrc @@ -6,5 +6,6 @@ qml/GridLayoutTest.qml qml/StackedLayoutTest.qml qml/StackedWidgetTest.qml + qml/SplitterTest.qml diff --git a/tests/auto/layouts/qml/SplitterTest.qml b/tests/auto/layouts/qml/SplitterTest.qml new file mode 100644 index 0000000..d3b5bbf --- /dev/null +++ b/tests/auto/layouts/qml/SplitterTest.qml @@ -0,0 +1,37 @@ +/* + SplitterTest.qml + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import QtWidgets 1.0 + +Splitter { + Label { + text: "Label 1" + } + Label { + text: "Label 2" + } +} diff --git a/tests/auto/layouts/splitter.cpp b/tests/auto/layouts/splitter.cpp new file mode 100644 index 0000000..ff1b881 --- /dev/null +++ b/tests/auto/layouts/splitter.cpp @@ -0,0 +1,42 @@ +/* + splitter.cpp + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "splitter.h" + +#include "ui_splitter.h" + +Splitter::Splitter(QWidget *parent) + : QSplitter(parent) + , ui(new Ui::Splitter) +{ + ui->setupUi(this); +} + +Splitter::~Splitter() +{ + delete ui; +} diff --git a/tests/auto/layouts/splitter.h b/tests/auto/layouts/splitter.h new file mode 100644 index 0000000..894229a --- /dev/null +++ b/tests/auto/layouts/splitter.h @@ -0,0 +1,52 @@ +/* + splitter.h + + This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. + + Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Lova Widmark + + Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in + accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef SPLITTER_H +#define SPLITTER_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui +{ + class Splitter; +} +QT_END_NAMESPACE + +class Splitter : public QSplitter +{ + Q_OBJECT + + public: + explicit Splitter(QWidget *parent = Q_NULLPTR); + ~Splitter(); + + private: + Ui::Splitter *ui; +}; + +#endif // SPLITTER_H diff --git a/tests/auto/layouts/splitter.ui b/tests/auto/layouts/splitter.ui new file mode 100644 index 0000000..434d5ed --- /dev/null +++ b/tests/auto/layouts/splitter.ui @@ -0,0 +1,18 @@ + + + Splitter + + + + Label 1 + + + + + Label 2 + + + + + + diff --git a/tests/auto/layouts/tst_layouts.cpp b/tests/auto/layouts/tst_layouts.cpp index 8eefa78..b81f1a3 100644 --- a/tests/auto/layouts/tst_layouts.cpp +++ b/tests/auto/layouts/tst_layouts.cpp @@ -31,6 +31,7 @@ #include "vboxlayoutwidget.h" #include "formlayoutwidget.h" #include "gridlayoutwidget.h" +#include "splitter.h" #include "stackedlayoutwidget.h" #include "stackedwidget.h" @@ -65,6 +66,8 @@ private slots: void stackedWidget(); void sizePolicy_data(); void sizePolicy(); + void splitter_data(); + void splitter(); private: QQmlEngine* m_qmlEngine; @@ -214,6 +217,26 @@ void tst_Layouts::stackedWidget() testLayouts(uiWidget, declarativeWidget); } +void tst_Layouts::splitter_data() +{ + QQmlComponent component(m_qmlEngine, QUrl(QStringLiteral("qrc:/qml/SplitterTest.qml"))); + QWidgetPtr declarativeWidget(qobject_cast(component.create())); + QVERIFY(declarativeWidget != nullptr); + + QTest::addColumn("uiWidget"); + QTest::addColumn("declarativeWidget"); + + QTest::newRow("splitterWidget") << QWidgetPtr(new Splitter()) << declarativeWidget; +} + +void tst_Layouts::splitter() +{ + QFETCH(QWidgetPtr, uiWidget); + QFETCH(QWidgetPtr, declarativeWidget); + + testLayouts(uiWidget, declarativeWidget); +} + void tst_Layouts::sizePolicy_data() { // QSizePolicy::ControlType is not registered with the meta-type system. From 85c8f528226fae71785c3bb65ffa53982c2c1c87 Mon Sep 17 00:00:00 2001 From: Znurre Date: Wed, 28 Mar 2018 18:13:21 +0200 Subject: [PATCH 4/5] Dropped the Splitter attached properties --- src/declarativesplitter.cpp | 55 ------------------------------- src/declarativesplitter_p.h | 28 ---------------- src/declarativewidgets_plugin.cpp | 4 +-- src/splitterwidgetcontainer.cpp | 12 +------ 4 files changed, 3 insertions(+), 96 deletions(-) diff --git a/src/declarativesplitter.cpp b/src/declarativesplitter.cpp index abf0a7b..25fccd4 100644 --- a/src/declarativesplitter.cpp +++ b/src/declarativesplitter.cpp @@ -27,62 +27,7 @@ #include "declarativesplitter_p.h" -#include -#include -#include - -class DeclarativeSplitterAttached::Private -{ - public: - Private(QWidget *w) - : stretch(0) - , widget(w) - { - } - - int stretch; - - QPointer widget; -}; - -DeclarativeSplitterAttached::DeclarativeSplitterAttached(QWidget *widget, QObject *parent) - : QObject(parent) - , d(new Private(widget)) -{ -} - -DeclarativeSplitterAttached::~DeclarativeSplitterAttached() -{ - delete d; -} - -void DeclarativeSplitterAttached::setStretch(int stretch) -{ - if (stretch == d->stretch) - return; - - d->stretch = stretch; - - emit stretchChanged(stretch); -} - -int DeclarativeSplitterAttached::stretch() const -{ - return d->stretch; -} - DeclarativeSplitter::DeclarativeSplitter(QWidget *parent) : QSplitter(parent) { } - -DeclarativeSplitterAttached *DeclarativeSplitter::qmlAttachedProperties(QObject *parent) -{ - QWidget *widget = qobject_cast(parent); - if (widget) - return new DeclarativeSplitterAttached(widget, parent); - - qmlInfo(parent) << "Can only attach Splitter to widgets"; - - return Q_NULLPTR; -} diff --git a/src/declarativesplitter_p.h b/src/declarativesplitter_p.h index f0e7730..c5cc58b 100644 --- a/src/declarativesplitter_p.h +++ b/src/declarativesplitter_p.h @@ -28,40 +28,12 @@ #ifndef DECLARATIVESPLITTER_P_H #define DECLARATIVESPLITTER_P_H -#include -#include #include -#include - -class DeclarativeSplitterAttached : public QObject -{ - Q_OBJECT - - Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged) - - public: - DeclarativeSplitterAttached(QWidget *widget, QObject *parent); - ~DeclarativeSplitterAttached(); - - void setStretch(int stretch); - int stretch() const; - - Q_SIGNALS: - void stretchChanged(int stretch); - - private: - class Private; - Private *const d; -}; class DeclarativeSplitter : public QSplitter { public: DeclarativeSplitter(QWidget *parent = Q_NULLPTR); - - static DeclarativeSplitterAttached *qmlAttachedProperties(QObject *parent); }; -QML_DECLARE_TYPEINFO(DeclarativeSplitter, QML_HAS_ATTACHED_PROPERTIES) - #endif // DECLARATIVESPLITTER_P_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index a57a806..4e474e8 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -54,6 +54,7 @@ #include "declarativeseparator_p.h" #include "declarativesizepolicy_p.h" #include "declarativespaceritem_p.h" +#include "declarativesplitter_p.h" #include "declarativestackedlayout_p.h" #include "declarativestatusbar_p.h" #include "declarativestringlistmodelextension_p.h" @@ -68,10 +69,9 @@ #include "menubarwidgetcontainer_p.h" #include "menuwidgetcontainer_p.h" #include "scrollareawidgetcontainer_p.h" +#include "splitterwidgetcontainer_p.h" #include "stackedwidgetwidgetcontainer_p.h" #include "toolbarwidgetcontainer_p.h" -#include "splitterwidgetcontainer_p.h" -#include "declarativesplitter_p.h" #include #include diff --git a/src/splitterwidgetcontainer.cpp b/src/splitterwidgetcontainer.cpp index b6e6af4..8bc1f24 100644 --- a/src/splitterwidgetcontainer.cpp +++ b/src/splitterwidgetcontainer.cpp @@ -29,9 +29,8 @@ #include "declarativesplitter_p.h" -#include #include -#include +#include SplitterWidgetContainer::SplitterWidgetContainer(QObject *parent) : DefaultWidgetContainer(qobject_cast(parent)) @@ -47,15 +46,6 @@ void SplitterWidgetContainer::setLayout(QLayout *layout) void SplitterWidgetContainer::addWidget(QWidget *widget) { - QObject *attachedProperties = qmlAttachedPropertiesObject(widget, false); - DeclarativeSplitterAttached *properties = qobject_cast(attachedProperties); - if (properties) { - QSizePolicy policy = widget->sizePolicy(); - policy.setHorizontalStretch(properties->stretch()); - policy.setVerticalStretch(properties->stretch()); - widget->setSizePolicy(policy); - } - extendedSplitter()->addWidget(widget); } From e6ec70d7aed7a2f4087080e1e7d633251ebe4b04 Mon Sep 17 00:00:00 2001 From: Znurre Date: Thu, 29 Mar 2018 16:59:11 +0200 Subject: [PATCH 5/5] Remove unused class DeclarativeSplitter --- src/declarativesplitter.cpp | 33 -------------------------- src/declarativesplitter_p.h | 39 ------------------------------- src/declarativewidgets_plugin.cpp | 4 ++-- src/splitterwidgetcontainer.cpp | 2 -- src/src.pro | 6 ++--- 5 files changed, 4 insertions(+), 80 deletions(-) delete mode 100644 src/declarativesplitter.cpp delete mode 100644 src/declarativesplitter_p.h diff --git a/src/declarativesplitter.cpp b/src/declarativesplitter.cpp deleted file mode 100644 index 25fccd4..0000000 --- a/src/declarativesplitter.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - declarativesplitter.cpp - - This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - - Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Lova Widmark - - Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in - accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. - - Contact info@kdab.com if any conditions of this licensing are not clear to you. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "declarativesplitter_p.h" - -DeclarativeSplitter::DeclarativeSplitter(QWidget *parent) - : QSplitter(parent) -{ -} diff --git a/src/declarativesplitter_p.h b/src/declarativesplitter_p.h deleted file mode 100644 index c5cc58b..0000000 --- a/src/declarativesplitter_p.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - declarativesplitter_p.h - - This file is part of DeclarativeWidgets, library and tools for creating QtWidget UIs with QML. - - Copyright (C) 2013-2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com - Author: Lova Widmark - - Licensees holding valid commercial KDAB DeclarativeWidgets licenses may use this file in - accordance with DeclarativeWidgets Commercial License Agreement provided with the Software. - - Contact info@kdab.com if any conditions of this licensing are not clear to you. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#ifndef DECLARATIVESPLITTER_P_H -#define DECLARATIVESPLITTER_P_H - -#include - -class DeclarativeSplitter : public QSplitter -{ - public: - DeclarativeSplitter(QWidget *parent = Q_NULLPTR); -}; - -#endif // DECLARATIVESPLITTER_P_H diff --git a/src/declarativewidgets_plugin.cpp b/src/declarativewidgets_plugin.cpp index 4e474e8..47b836b 100644 --- a/src/declarativewidgets_plugin.cpp +++ b/src/declarativewidgets_plugin.cpp @@ -54,7 +54,6 @@ #include "declarativeseparator_p.h" #include "declarativesizepolicy_p.h" #include "declarativespaceritem_p.h" -#include "declarativesplitter_p.h" #include "declarativestackedlayout_p.h" #include "declarativestatusbar_p.h" #include "declarativestringlistmodelextension_p.h" @@ -100,6 +99,7 @@ #include #include #include +#include #include #include #include @@ -208,5 +208,5 @@ void ExtensionpluginPlugin::registerTypes(const char *uri) qmlRegisterExtendedType(uri, 1, 0, "WebEngineView"); #endif qmlRegisterExtendedType(uri, 1, 0, "Widget"); - qmlRegisterExtendedType>(uri, 1, 0, "Splitter"); + qmlRegisterExtendedType>(uri, 1, 0, "Splitter"); } diff --git a/src/splitterwidgetcontainer.cpp b/src/splitterwidgetcontainer.cpp index 8bc1f24..fecc4e7 100644 --- a/src/splitterwidgetcontainer.cpp +++ b/src/splitterwidgetcontainer.cpp @@ -27,8 +27,6 @@ #include "splitterwidgetcontainer_p.h" -#include "declarativesplitter_p.h" - #include #include diff --git a/src/src.pro b/src/src.pro index d535780..81ad2b4 100644 --- a/src/src.pro +++ b/src/src.pro @@ -87,8 +87,7 @@ HEADERS = \ toolbarwidgetcontainer_p.h \ widgetcontainerinterface_p.h \ declarativesizepolicy_p.h \ - splitterwidgetcontainer_p.h \ - declarativesplitter_p.h + splitterwidgetcontainer_p.h SOURCES = \ abstractdeclarativeobject.cpp \ @@ -140,5 +139,4 @@ SOURCES = \ staticdialogmethodattached.cpp \ toolbarwidgetcontainer.cpp \ declarativesizepolicy.cpp \ - splitterwidgetcontainer.cpp \ - declarativesplitter.cpp + splitterwidgetcontainer.cpp