From 5f1101702cd0fb82f8dd461f409670c0461e0bfc Mon Sep 17 00:00:00 2001 From: Tobias Junghans Date: Fri, 4 Oct 2019 13:08:26 +0200 Subject: [PATCH 1/2] PropertySelector: allow usage with any QML objects There's no reason to restrict the usage of PropertySelector to QQuickItem objects. Instead it can be made usable with any kind of QML objects easily. --- qt/qml/PropertySelector/PropertySelector.cpp | 2 +- qt/qml/PropertySelector/PropertySelector.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/qt/qml/PropertySelector/PropertySelector.cpp b/qt/qml/PropertySelector/PropertySelector.cpp index 7ad988b..47b0298 100644 --- a/qt/qml/PropertySelector/PropertySelector.cpp +++ b/qt/qml/PropertySelector/PropertySelector.cpp @@ -110,7 +110,7 @@ using namespace cpp::qmltypes; ///@brief constructor ///@param parent the parent item -PropertySelector::PropertySelector(QQuickItem *parent) +PropertySelector::PropertySelector(QObject *parent) :QObject(parent) { } diff --git a/qt/qml/PropertySelector/PropertySelector.h b/qt/qml/PropertySelector/PropertySelector.h index 55c3311..d4d8ba1 100644 --- a/qt/qml/PropertySelector/PropertySelector.h +++ b/qt/qml/PropertySelector/PropertySelector.h @@ -30,7 +30,6 @@ #ifndef PROPERTYSWITCH_H #define PROPERTYSWITCH_H -#include #include #include #include @@ -51,7 +50,7 @@ class PropertySelector : public QObject, public QQmlParserStatus ///@brief the maximum number of conditions supported static const int MaxConditionCount = 32; - PropertySelector(QQuickItem *parent = nullptr); + PropertySelector(QObject *parent = nullptr); QObject *target() const; Q_SLOT void setTarget(QObject *target); From ccdaafe51350a7fa4912a7e475b4983e47dd7338 Mon Sep 17 00:00:00 2001 From: Tobias Junghans Date: Fri, 4 Oct 2019 13:12:29 +0200 Subject: [PATCH 2/2] PropertySelector: use stream operator for message GCC complains about the format string not being a string literal and not containing format arguments (-Wformat-security). This can be fixed easily by using the stream operator with qWarning(). --- qt/qml/PropertySelector/PropertySelector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qt/qml/PropertySelector/PropertySelector.cpp b/qt/qml/PropertySelector/PropertySelector.cpp index 47b0298..55e04a2 100644 --- a/qt/qml/PropertySelector/PropertySelector.cpp +++ b/qt/qml/PropertySelector/PropertySelector.cpp @@ -286,9 +286,9 @@ void PropertySelector::prepareRules() auto context = QQmlEngine::contextForObject(target()); const QString objectName = context->objectName().isEmpty() ? QStringLiteral("unnamed") : context->objectName(); //FIXME: broken auto switchContext = QQmlEngine::contextForObject(this); - qWarning(QString("PropertySelector target %1 (%2) does not have a property '%3' requested from %4, line %5:%6") + qWarning() << QString("PropertySelector target %1 (%2) does not have a property '%3' requested from %4, line %5:%6") .arg(target()->metaObject()->className(), objectName, start->property, - switchContext->baseUrl().toString(), QString::number(start->location.line), QString::number(start->location.column)).toLatin1() ); + switchContext->baseUrl().toString(), QString::number(start->location.line), QString::number(start->location.column)).toLatin1(); } else { PropertyRules rules {prop, start, end, end, nullptr}; m_properties.append(rules);