Commit e88f0d21 authored by Volker Krause's avatar Volker Krause
Browse files

Add QML bindings for PropertyRatioSource

parent c8c40ae3
......@@ -2,6 +2,7 @@ set(provider_qml_srcs
qmlabstractdatasource.cpp
qmldatasources.cpp
qmlplugin.cpp
qmlpropertyratiosource.cpp
qmlproviderextension.cpp
)
......
......@@ -17,6 +17,7 @@
#include "qmlplugin.h"
#include "qmldatasources.h"
#include "qmlpropertyratiosource.h"
#include "qmlproviderextension.h"
#include <Provider>
......@@ -41,6 +42,7 @@ void QmlPlugin::registerTypes(const char* uri)
qmlRegisterType<QmlScreenInfoSource>(uri, 1, 0, "ScreenInfoSource");
qmlRegisterType<QmlStartCountSource>(uri, 1, 0, "StartCountSource");
qmlRegisterType<QmlUsageTimeSource>(uri, 1, 0, "UsageTimeSource");
qmlRegisterType<QmlPropertyRatioSource>(uri, 1, 0, "PropertyRatioSource");
qRegisterMetaType<SurveyInfo>();
}
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library 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 Library 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 <http://www.gnu.org/licenses/>.
*/
#include "qmlpropertyratiosource.h"
#include <PropertyRatioSource>
using namespace UserFeedback;
QmlPropertyRatioSource::QmlPropertyRatioSource(QObject* parent)
: QmlAbstractDataSource(new PropertyRatioSource(nullptr, nullptr, QString()), parent)
{
}
QmlPropertyRatioSource::~QmlPropertyRatioSource()
{
}
PropertyRatioSource* QmlPropertyRatioSource::prSrc() const
{
return static_cast<PropertyRatioSource*>(source());
}
QString QmlPropertyRatioSource::name() const
{
return source()->name();
}
void QmlPropertyRatioSource::setName(const QString& name)
{
if (source()->name() == name)
return;
prSrc()->setName(name);
emit changed();
}
QString QmlPropertyRatioSource::description() const
{
return prSrc()->description();
}
void QmlPropertyRatioSource::setDescription(const QString& desc)
{
if (description() == desc)
return;
prSrc()->setDescription(desc);
emit changed();
}
QObject* QmlPropertyRatioSource::object() const
{
return prSrc()->object();
}
void QmlPropertyRatioSource::setObject(QObject* object)
{
if (prSrc()->object() == object)
return;
prSrc()->setObject(object);
emit changed();
}
QString QmlPropertyRatioSource::propertyName() const
{
return prSrc()->propertyName();
}
void QmlPropertyRatioSource::setPropertyName(const QString& name)
{
if (propertyName() == name)
return;
prSrc()->setPropertyName(name);
emit changed();
}
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library 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 Library 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 <http://www.gnu.org/licenses/>.
*/
#ifndef USERFEEDBACK_QMLPROPERTYRATIOSOURCE_H
#define USERFEEDBACK_QMLPROPERTYRATIOSOURCE_H
#include "qmlabstractdatasource.h"
namespace UserFeedback {
class PropertyRatioSource;
class QmlPropertyRatioSource : public QmlAbstractDataSource
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY changed)
Q_PROPERTY(QObject* object READ object WRITE setObject NOTIFY changed)
Q_PROPERTY(QString propertyName READ propertyName WRITE setPropertyName NOTIFY changed)
public:
explicit QmlPropertyRatioSource(QObject *parent = nullptr);
~QmlPropertyRatioSource();
QString name() const;
void setName(const QString &name);
QString description() const;
void setDescription(const QString &desc);
QObject* object() const;
void setObject(QObject *object);
QString propertyName() const;
void setPropertyName(const QString &name);
Q_SIGNALS:
void changed();
private:
PropertyRatioSource* prSrc() const;
};
}
#endif // USERFEEDBACK_QMLPROPERTYRATIOSOURCE_H
......@@ -18,6 +18,7 @@
import QtQuick 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import Qt.labs.settings 1.0
import org.kde.userfeedback 1.0 as UserFeedback
ApplicationWindow {
......@@ -25,6 +26,16 @@ ApplicationWindow {
width: 480
height: 640
Component.onCompleted: {
Qt.application.name = "qmlorwell";
Qt.application.version = "1984.qml"
Qt.application.organization = "KDE";
Qt.application.domain = "kde.org";
// for Settings to work, we need to have the above setup first
stackView.push(mainView);
}
UserFeedback.Provider {
id: provider
submissionInterval: 1
......@@ -50,13 +61,94 @@ ApplicationWindow {
UserFeedback.ScreenInfoSource { mode: UserFeedback.Provider.DetailedSystemInformation }
UserFeedback.StartCountSource { mode: UserFeedback.Provider.BasicUsageStatistics }
UserFeedback.UsageTimeSource { mode: UserFeedback.Provider.BasicUsageStatistics }
UserFeedback.PropertyRatioSource {
id: dialRatioSource
mode: UserFeedback.Provider.DetailedUsageStatistics
name: "dialRatio"
propertyName: "intValue"
description: qsTr("The dial position.")
}
}
Button {
id: submitButton
text: "Submit!"
anchors.centerIn: parent
onClicked: provider.submit()
StackView {
id: stackView
anchors.fill: parent
}
Component {
id: mainView
Page {
header: ToolBar {
RowLayout {
anchors.fill: parent
Label {
text: "Feedback Demo"
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
}
ToolButton {
id: menuButton
text: ""
onClicked: menu.open()
Menu {
id: menu
y: menuButton.height
MenuItem {
text: "Contribute..."
onTriggered: stackView.push(contributePage)
}
}
}
}
}
ColumnLayout {
anchors.fill: parent
Dial {
property int intValue: Math.round(dial.value)
id: dial
Layout.fillWidth: true
from: 0
to: 10
stepSize: 1
Component.onCompleted: dialRatioSource.object = dial
}
Settings {
property alias sliderValue: dial.value
}
Button {
id: submitButton
Layout.alignment: Qt.AlignHCenter
text: "Submit!"
onClicked: provider.submit()
}
}
}
}
Component {
id: contributePage
Page {
header: ToolBar {
RowLayout {
anchors.fill: parent
ToolButton {
id: menuButton
text: "<"
onClicked: stackView.pop()
}
Label {
text: "Contribution Settings"
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
}
}
}
}
}
Popup {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment