1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
import QtQuick 2.0
import UserMetrics 0.1
/**
To run this example with the qtdeclarative5-usermetrics0.1 package already installed in the system:
qmlscene examples/metrics_declarative.qml
To run it after building te source but without the package installed:
qmlscene -I src/modules examples/metrics_declarative.qml
both from the root of the code repository.
To see the changes generated by clicking on the various rectangles in this example
you either have an libusermetricsoutput client alrady accessing the data somewhere,
or you can use d-feet or a similar dbus inspector application to look at
com.lomiri.UserMetrics /com/lomiri/UserMetrics/DataSet/{N} com.lomiri.UserMetrics.DataSet
and watch how the value of the "data" property varies.
The {N} placeholder is a number that represents the id of your data set. You can examine all the
various data sources by looking at:
com.lomiri.UserMetrics /com/lomiri/UserMetrics/DataSource/{N} com.lomiri.UserMetrics.DataSource
and find the one that has the property "name" equal to "clicks-example", then use the same {N} to
for the DataSet.
**/
Item {
width: 200
height: 200
Metric {
/**
Changing the "name" property will bind the Metric to the DataSource of that name,
as well as set the rest of the properties to the specified values on that DataSource.
If the DataSource doesn't already exist it will be created.
**/
id: clicksMetric
name: "clicks-example"
format: "%1 clicks on red rectangle today"
emptyFormat: "No clicks on red rectangle today yet"
domain: "metrics-declarative-example"
}
Rectangle {
color: "red"
anchors.left: parent.left
anchors.top: parent.top
height: 100
width: 100
Text {
anchors.centerIn: parent
text: "Increment"
}
MouseArea {
anchors.fill: parent
onClicked: clicksMetric.increment();
}
}
Rectangle {
color: "orange"
anchors.right: parent.right
anchors.top: parent.top
height: 100
width: 100
Text {
anchors.centerIn: parent
text: "Add 10.5 :)"
}
MouseArea {
anchors.fill: parent
onClicked: clicksMetric.increment(10.5);
}
}
Rectangle {
color: "yellow"
anchors.left: parent.left
anchors.bottom: parent.bottom
height: 100
width: 200
Text {
anchors.centerIn: parent
text: "Reset to zero"
}
MouseArea {
anchors.fill: parent
onClicked: clicksMetric.update(0);
}
}
}
|