Skip to content

Commit

Permalink
qtquick: Fix qmllint warnings about unknown properties
Browse files Browse the repository at this point in the history
By using the actual type instead of just QtObject
  • Loading branch information
iamsergio committed Jan 26, 2025
1 parent d4c5dba commit 9c93ae5
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,13 @@ set(KDDW_FRONTEND_QTQUICK_SRCS
qtquick/views/DropArea.cpp
qtquick/views/DockWidget.cpp
qtquick/views/FloatingWindow.cpp
qtquick/views/Group.cpp
qtquick/views/MainWindow.cpp
qtquick/views/MainWindowMDI.cpp
qtquick/views/MDILayout.cpp
qtquick/views/RubberBand.cpp
qtquick/views/Separator.cpp
qtquick/views/Stack.cpp
qtquick/views/TabBar.cpp
qtquick/views/TitleBar.cpp
qtquick/views/View.cpp
qtquick/views/ViewWrapper.cpp
qtquick/views/ClassicIndicatorsWindow.cpp
Expand Down Expand Up @@ -541,6 +539,10 @@ if(KDDW_FRONTEND_QTQUICK)
qtquick/DockWidgetInstantiator.h
qtquick/MainWindowMDIInstantiator.cpp
qtquick/MainWindowMDIInstantiator.h
qtquick/views/Group.cpp
qtquick/views/Group.h
qtquick/views/TitleBar.cpp
qtquick/views/TitleBar.h
)

if(NOT KDDockWidgets_QML_MODULE)
Expand Down
7 changes: 7 additions & 0 deletions src/qtquick/MainWindowInstantiator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
#include "kddockwidgets/docks_export.h"
#include "kddockwidgets/KDDockWidgets.h"

// workaround QTBUG-101146, the QML_ELEMENTS Inside views/ aren't being included automatically
#include "views/Group.h"
#include "views/TitleBar.h"
#include "views/TabBar.h"
#include "views/DropArea.h"
#include "views/FloatingWindow.h"

#include <QQuickItem>
#include <QQmlEngine>

Expand Down
24 changes: 24 additions & 0 deletions src/qtquick/QmlTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
#include "MainWindowMDIInstantiator.h"
#include "LayoutSaverInstantiator.h"

#include "views/Group.h"
#include "views/TitleBar.h"
#include "views/TabBar.h"
#include "views/DropArea.h"
#include "views/FloatingWindow.h"

#include <QQmlEngine>
#include <QDebug>

Expand All @@ -26,4 +32,22 @@ void KDDockWidgets::registerQmlTypes()
qmlRegisterType<LayoutSaverInstantiator>("com.kdab.dockwidgets", 2, 0, "LayoutSaver");
qmlRegisterUncreatableMetaObject(KDDockWidgets::staticMetaObject, "com.kdab.dockwidgets", 2, 0,
"KDDockWidgets", QStringLiteral("Enum access only"));

qmlRegisterUncreatableType<QtQuick::Group>("com.kdab.dockwidgets", 2, 0,
"GroupView", QStringLiteral("Internal usage only"));

qmlRegisterUncreatableType<QtQuick::TitleBar>("com.kdab.dockwidgets", 2, 0,
"TitleBarView", QStringLiteral("Internal usage only"));

qmlRegisterUncreatableType<QtQuick::TabBar>("com.kdab.dockwidgets", 2, 0,
"TabBarView", QStringLiteral("Internal usage only"));

qmlRegisterUncreatableType<QtQuick::DropArea>("com.kdab.dockwidgets", 2, 0,
"DropAreaView", QStringLiteral("Internal usage only"));

qmlRegisterUncreatableType<QtQuick::FloatingWindow>("com.kdab.dockwidgets", 2, 0,
"FloatingWindowView", QStringLiteral("Internal usage only"));

qmlRegisterUncreatableType<QtQuick::DockWidgetModel>("com.kdab.dockwidgets", 2, 0,
"DockWidgetModel", QStringLiteral("Internal usage only"));
}
2 changes: 2 additions & 0 deletions src/qtquick/views/DropArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class DOCKS_EXPORT DropArea : public QtQuick::View
{
Q_OBJECT
public:
QML_NAMED_ELEMENT(DropAreaView)
QML_UNCREATABLE("Created by the framework only.")
explicit DropArea(Core::DropArea *, Core::View *parent);
~DropArea();

Expand Down
3 changes: 3 additions & 0 deletions src/qtquick/views/FloatingWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ using QuickWindowCreationCallback = std::function<void(QQuickView *window, QtQui
class DOCKS_EXPORT FloatingWindow : public QtQuick::View
{
Q_OBJECT
QML_NAMED_ELEMENT(FloatingWindowView)
QML_UNCREATABLE("Created by the framework only.")

Q_PROPERTY(QObject *titleBar READ titleBar CONSTANT)
Q_PROPERTY(QObject *dropArea READ dropArea CONSTANT)
public:
Expand Down
2 changes: 1 addition & 1 deletion src/qtquick/views/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ QSize Group::maxSizeHint() const
return View::maxSizeHint();
}

QObject *Group::tabBarObj() const
QtQuick::TabBar *Group::tabBarObj() const
{
return tabBarView();
}
Expand Down
6 changes: 4 additions & 2 deletions src/qtquick/views/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class Stack;
class DOCKS_EXPORT Group : public QtQuick::View, public Core::GroupViewInterface
{
Q_OBJECT
Q_PROPERTY(QObject *tabBar READ tabBarObj CONSTANT)
QML_NAMED_ELEMENT(GroupView)
QML_UNCREATABLE("Created by the framework only.")
Q_PROPERTY(KDDockWidgets::QtQuick::TabBar *tabBar READ tabBarObj CONSTANT)
Q_PROPERTY(KDDockWidgets::QtQuick::TitleBar *titleBar READ titleBar CONSTANT)
Q_PROPERTY(int userType READ userType CONSTANT)
Q_PROPERTY(KDDockWidgets::QtQuick::TitleBar *actualTitleBar READ actualTitleBar NOTIFY
Expand Down Expand Up @@ -66,7 +68,7 @@ class DOCKS_EXPORT Group : public QtQuick::View, public Core::GroupViewInterface
KDDockWidgets::QtQuick::TitleBar *titleBar() const;
KDDockWidgets::QtQuick::TitleBar *actualTitleBar() const;
int userType() const;
QObject *tabBarObj() const;
QtQuick::TabBar *tabBarObj() const;

/// Sets the size of this group in the MDI layout
Q_INVOKABLE void setMDISize(QSize);
Expand Down
4 changes: 4 additions & 0 deletions src/qtquick/views/TabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class DockWidgetModel;
class DOCKS_EXPORT TabBar : public QtQuick::View, public Core::TabBarViewInterface
{
Q_OBJECT
QML_NAMED_ELEMENT(TabBarView)
QML_UNCREATABLE("Created by the framework only.")
Q_PROPERTY(QQuickItem *tabBarQmlItem READ tabBarQmlItem WRITE setTabBarQmlItem NOTIFY
tabBarQmlItemChanged)
Q_PROPERTY(bool tabBarAutoHide READ tabBarAutoHide NOTIFY tabBarAutoHideChanged)
Expand Down Expand Up @@ -114,6 +116,8 @@ class DOCKS_EXPORT TabBar : public QtQuick::View, public Core::TabBarViewInterfa
class DockWidgetModel : public QAbstractListModel
{
Q_OBJECT
QML_NAMED_ELEMENT(DockWidgetModel)
QML_UNCREATABLE("Created by the framework only.")
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
enum Role {
Expand Down
3 changes: 3 additions & 0 deletions src/qtquick/views/TitleBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace QtQuick {
class DOCKS_EXPORT TitleBar : public QtQuick::View, public Core::TitleBarViewInterface
{
Q_OBJECT
QML_NAMED_ELEMENT(TitleBarView)
QML_UNCREATABLE("Created by the framework only.")

// These properties is just for the unit-tests
Q_PROPERTY(QQuickItem *titleBarQmlItem READ titleBarQmlItem WRITE setTitleBarQmlItem NOTIFY
titleBarQmlItemChanged)
Expand Down
30 changes: 16 additions & 14 deletions src/qtquick/views/qml/FloatingWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
*/

import QtQuick 2.9

import com.kdab.dockwidgets 2.0
import "." as KDDW

Rectangle {
id: root
readonly property QtObject floatingWindowCpp: parent
readonly property QtObject titleBarCpp: floatingWindowCpp ? floatingWindowCpp.titleBar : null
readonly property QtObject dropAreaCpp: floatingWindowCpp ? floatingWindowCpp.dropArea : null
readonly property FloatingWindowView floatingWindowCpp: parent
readonly property TitleBarView titleBarCpp: floatingWindowCpp ? floatingWindowCpp.titleBar : null
readonly property DropAreaView dropAreaCpp: floatingWindowCpp ? floatingWindowCpp.dropArea : null
readonly property int titleBarHeight: titleBar.heightWhenVisible
property int margins: 4

Expand All @@ -35,12 +37,12 @@ Rectangle {

Loader {
id: titleBar
readonly property QtObject titleBarCpp: root.titleBarCpp
readonly property TitleBarView titleBarCpp: root.titleBarCpp
readonly property int heightWhenVisible: item.heightWhenVisible
source: _kddw_widgetFactory.titleBarFilename()

anchors {
top: parent ? parent.top : undefined
top: parent ? parent.top : undefined
left: parent ? parent.left : undefined
right: parent ? parent.right : undefined
margins: root.margins
Expand All @@ -61,9 +63,9 @@ Rectangle {
bottomMargin: root.margins
}

onHeightChanged: {
// console.log("FloatingWindow.qml.dropArea height changed to " + height + " ; root.height= " + root.height)
}
onHeightChanged:
// console.log("FloatingWindow.qml.dropArea height changed to " + height + " ; root.height= " + root.height)
{}
}

onDropAreaCppChanged: {
Expand All @@ -76,11 +78,11 @@ Rectangle {
}
}

onHeightChanged: {
// console.log("FloatingWindow.qml.root height changed to " + height)
}
onHeightChanged:
// console.log("FloatingWindow.qml.root height changed to " + height)
{}

onWidthChanged: {
// console.log("FloatingWindow.qml.root width changed to " + width)
}
onWidthChanged:
// console.log("FloatingWindow.qml.root width changed to " + width)
{}
}
2 changes: 1 addition & 1 deletion src/qtquick/views/qml/Group.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.kdab.dockwidgets 2.0
Rectangle {
id: root

property QtObject groupCpp
property GroupView groupCpp
readonly property QtObject titleBarCpp: groupCpp ? groupCpp.titleBar : null
readonly property int nonContentsHeight: (titleBar.item ? titleBar.item.heightWhenVisible : 0) + tabbar.implicitHeight + (2 * contentsMargin) + titleBarContentsMargin
property int contentsMargin: isMDI ? 2 : 1
Expand Down
2 changes: 1 addition & 1 deletion src/qtquick/views/qml/MDIResizeHandlerHelper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MouseArea {
id: root
required property int resizeMargin
required property bool resizeAllowed
required property QtObject groupCpp
required property GroupView groupCpp
required property int cursorPosition

enabled: resizeAllowed
Expand Down
6 changes: 4 additions & 2 deletions src/qtquick/views/qml/TabBarBase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@

import QtQuick 2.9

import com.kdab.dockwidgets 2.0

Item {
id: root

readonly property bool hasCustomMouseEventRedirector: parent.hasCustomMouseEventRedirector

/// This is our C++ Group.cpp view
readonly property QtObject groupCpp: parent.groupCpp
readonly property GroupView groupCpp: parent.groupCpp

/// This is our C++ TabBar.cpp view
readonly property QtObject tabBarCpp: groupCpp ? groupCpp.tabBar : null
readonly property TabBarView tabBarCpp: groupCpp ? groupCpp.tabBar : null

/// The number of tabs
readonly property int count: tabBarCpp ? tabBarCpp.dockWidgetModel.count : 0
Expand Down
13 changes: 7 additions & 6 deletions src/qtquick/views/qml/TitleBarBase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

import QtQuick 2.9
import com.kdab.dockwidgets 2.0

/**
* @brief Base component for title bars.
Expand All @@ -24,7 +25,7 @@ import QtQuick 2.9
Rectangle {
id: root

readonly property QtObject titleBarCpp: parent.titleBarCpp // It's set in the loader
readonly property TitleBarView titleBarCpp: parent.titleBarCpp // It's set in the loader
readonly property string title: titleBarCpp ? titleBarCpp.title : ""
readonly property bool floatButtonVisible: titleBarCpp && titleBarCpp.floatButtonVisible
readonly property bool maximizeButtonVisible: titleBarCpp && titleBarCpp.maximizeButtonVisible
Expand All @@ -44,16 +45,16 @@ Rectangle {
property bool hasCustomMouseEventRedirector: false

/// @brief Signal emitted by a TitleBar.qml component when the close button is clicked
signal closeButtonClicked();
signal closeButtonClicked

/// @brief Signal emitted by a TitleBar.qml component when the float button is clicked
signal floatButtonClicked();
signal floatButtonClicked

/// @brief Signal emitted by a TitleBar.qml component when the maximize button is clicked
signal maximizeButtonClicked();
signal maximizeButtonClicked

/// @brief Signal emitted by a TitleBar.qml component when the minimize button is clicked
signal minimizeButtonClicked();
signal minimizeButtonClicked

visible: titleBarCpp && titleBarCpp.visible
height: visible ? heightWhenVisible : 0
Expand All @@ -72,7 +73,7 @@ Rectangle {
onTitleBarCppChanged: {
if (titleBarCpp) {
if (!root.hasCustomMouseEventRedirector)
titleBarCpp.redirectMouseEvents(titleBarDragMouseArea)
titleBarCpp.redirectMouseEvents(titleBarDragMouseArea);

// Setting just so the unit-tests can access the buttons
titleBarCpp.titleBarQmlItem = this;
Expand Down

0 comments on commit 9c93ae5

Please sign in to comment.