From aaf51bfad10e0eac7a8ee64e36aab5f0c1119468 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 2 Apr 2014 12:16:05 +0300 Subject: Enable querying selection label via API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also enable suppressing drawing the label on graph. Selection label formatting was consequently moved from renderers to series. Task-number: QTRD-2896 Change-Id: Ia6a1a40298d8db0f54349de3eb27fb0b683dd302 Reviewed-by: Tomi Korpipää --- .../qmlaxisformatter/customformatter.cpp | 1 + .../qmloscilloscope/datasource.cpp | 23 ---------------- .../datavisualization/qmloscilloscope/datasource.h | 3 --- .../qmloscilloscope/doc/src/qmloscilloscope.qdoc | 15 +++-------- .../qmloscilloscope/qml/qmloscilloscope/main.qml | 31 +++++++++------------- 5 files changed, 17 insertions(+), 56 deletions(-) (limited to 'examples') diff --git a/examples/datavisualization/qmlaxisformatter/customformatter.cpp b/examples/datavisualization/qmlaxisformatter/customformatter.cpp index eeea0451..4a52d273 100644 --- a/examples/datavisualization/qmlaxisformatter/customformatter.cpp +++ b/examples/datavisualization/qmlaxisformatter/customformatter.cpp @@ -142,6 +142,7 @@ void CustomFormatter::setSelectionFormat(const QString &format) { if (m_selectionFormat != format) { m_selectionFormat = format; + markDirty(true); // Necessary to regenerate already visible selection label emit selectionFormatChanged(format); } } diff --git a/examples/datavisualization/qmloscilloscope/datasource.cpp b/examples/datavisualization/qmloscilloscope/datasource.cpp index 01d7e73d..40ebd962 100644 --- a/examples/datavisualization/qmloscilloscope/datasource.cpp +++ b/examples/datavisualization/qmloscilloscope/datasource.cpp @@ -138,29 +138,6 @@ void DataSource::update(QSurface3DSeries *series) } //! [1] -//! [2] -QString DataSource::selectionLabel(QSurface3DSeries *series, QValue3DAxis *axisX, - QValue3DAxis *axisY, QValue3DAxis *axisZ) -{ - QString label; - - if (series && series->selectedPoint() != QSurface3DSeries::invalidSelectionPosition()) { - const QSurfaceDataItem *item = series->dataProxy()->itemAt(series->selectedPoint()); - QString x; - QString y; - QString z; - x.sprintf(axisX->labelFormat().toUtf8().constData(), int(item->x())); - y.sprintf(axisY->labelFormat().toUtf8().constData(), int(item->y())); - z.sprintf(axisZ->labelFormat().toUtf8().constData(), int(item->z())); - label = QStringLiteral("%1, %3: %2").arg(x).arg(y).arg(z); - } else { - label = QStringLiteral("No selection"); - } - - return label; -} -//! [2] - void DataSource::clearData() { for (int i(0); i < m_data.size(); i++) { diff --git a/examples/datavisualization/qmloscilloscope/datasource.h b/examples/datavisualization/qmloscilloscope/datasource.h index 4f210269..76ba7c9c 100644 --- a/examples/datavisualization/qmloscilloscope/datasource.h +++ b/examples/datavisualization/qmloscilloscope/datasource.h @@ -37,9 +37,6 @@ public slots: float xMin, float xMax, float yMin, float yMax, float zMin, float zMax); void update(QSurface3DSeries *series); - - QString selectionLabel(QSurface3DSeries *series, QValue3DAxis *axisX, - QValue3DAxis *axisY, QValue3DAxis *axisZ); //! [0] private: void clearData(); diff --git a/examples/datavisualization/qmloscilloscope/doc/src/qmloscilloscope.qdoc b/examples/datavisualization/qmloscilloscope/doc/src/qmloscilloscope.qdoc index c574950b..93bd5c30 100644 --- a/examples/datavisualization/qmloscilloscope/doc/src/qmloscilloscope.qdoc +++ b/examples/datavisualization/qmloscilloscope/doc/src/qmloscilloscope.qdoc @@ -59,11 +59,6 @@ we still need to call QSurfaceDataProxy::resetArray() after changing the data in it to prompt the graph to render the data. - The final method, \c selectionLabel(), is used to generate a label string we can show on the - QML ui. This method utilizes the axis formats to format the label: - - \snippet qmloscilloscope/datasource.cpp 2 - To be able to access the \c DataSource methods from QML, we need to expose it. We do this by defining a context property in application main: @@ -86,15 +81,11 @@ One interesting detail is that we don't specify a proxy for the Surface3DSeries we attach to the graph. This makes the series to utilize the default QSurfaceDataProxy. - We also specify an empty string for \l{Abstract3DSeries::itemLabelFormat}{itemLabelFormat}, since we want to display - the selected item information in a \c Text element instead of a label above the selection pointer. + We also hide the item label with \l{Abstract3DSeries::itemLabelVisible}{itemLabelFormat}, since + we want to display the selected item information in a \c Text element instead of a floating + label above the selection pointer. This is done because the selection pointer moves around a lot as the data changes, which makes the regular selection label difficult to read. - When selection point changes, we update the label text using a helper function - \c updateSelectionLabel(), which calls one of the methods we defined for our \c DataSource class - to obtain the label: - - \snippet qmloscilloscope/qml/qmloscilloscope/main.qml 1 We initialize the \c DataSource cache when the graph is complete by calling a helper function \c generateData(), which calls the method with the same name on the \c DataSource: diff --git a/examples/datavisualization/qmloscilloscope/qml/qmloscilloscope/main.qml b/examples/datavisualization/qmloscilloscope/qml/qmloscilloscope/main.qml index 81884154..5f5bfe1a 100644 --- a/examples/datavisualization/qmloscilloscope/qml/qmloscilloscope/main.qml +++ b/examples/datavisualization/qmloscilloscope/qml/qmloscilloscope/main.qml @@ -19,7 +19,7 @@ import QtQuick 2.1 import QtQuick.Layouts 1.0 import QtQuick.Controls 1.0 -import QtDataVisualization 1.0 +import QtDataVisualization 1.1 import "." Item { @@ -72,9 +72,8 @@ Item { drawMode: Surface3DSeries.DrawSurface; flatShadingEnabled: false; meshSmooth: true - itemLabelFormat: "" - - onSelectedPointChanged: mainView.updateSelectionLabel() + itemLabelFormat: "@xLabel, @zLabel: @yLabel" + itemLabelVisible: false } //! [0] @@ -90,10 +89,7 @@ Item { interval: 1000 / frequencySlider.value running: true repeat: true - onTriggered: { - dataSource.update(surfaceSeries) - mainView.updateSelectionLabel() - } + onTriggered: dataSource.update(surfaceSeries) } //! [3] @@ -218,10 +214,18 @@ Item { Text { id: selectionText - text: "No selection" anchors.fill: parent verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter + + Binding on text { + when: surfaceSeries.itemLabel.length + value: surfaceSeries.itemLabel + } + Binding on text { + when: !surfaceSeries.itemLabel.length + value: "No selection" + } } } } @@ -285,15 +289,6 @@ Item { } - //! [1] - function updateSelectionLabel() { - selectionText.text = dataSource.selectionLabel(surfaceSeries, - surfaceGraph.axisX, - surfaceGraph.axisY, - surfaceGraph.axisZ) - } - //! [1] - //! [4] function generateData() { dataSource.generateData(mainView.sampleCache, mainView.sampleRows, -- cgit v1.2.3