From fe3c9ec0a9fb734e83eb70bc725c303a9d36cd6d Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 28 Mar 2014 14:51:26 +0200 Subject: Axis formatter customization example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also refactored the formatter api somewhat: - Removed virtual from allowNegatives and allowZero and added a setter function for those. This will make it cleaner if we need to add similar properties to the axis formatter in the future, as no new virtual methods can be added without breaking BC. - Changed the labelValues array to labelStrings list, as it makes more sense to directly format the strings in recalculate. Change-Id: I3ea005afa984bb756845ca356b999762e0807415 Reviewed-by: Tomi Korpipää --- .../qmlaxisformatter/doc/src/qmlaxisformatter.qdoc | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc (limited to 'examples/datavisualization/qmlaxisformatter/doc') diff --git a/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc b/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc new file mode 100644 index 00000000..b990c490 --- /dev/null +++ b/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +/*! + \example qmlaxisformatter + \title Qt Quick 2 Axis Formatter Example + \ingroup qtdatavisualization_examples + \brief Example of a hybrid C++ and QML application demonstrating different axis formatters. + + The Qt Quick axis formatter example shows how to use predefined axis formatters and how to + create a custom one. + + \image qmlaxisformatter-example.png + + The interesting thing about this example is axis formatters, so we'll concentrate on + that and skip explaining the basic functionality - for + more detailed QML example documentation, see \l{Qt Quick 2 Scatter Example}. + + \section1 Custom axis formatter + + Customizing axis formatters requires subclassing the QValue3DAxisFormatter, which cannot be + done in QML code alone. In this example we want an axis that interprets the float values as + a timestamp and shows the date in the axis labels. To achieve this, we introduce a new class + called \c CustomFormatter, which subclasses the QValue3DAxisFormatter: + + \snippet qmlaxisformatter/customformatter.h 2 + \dots 0 + + Since float values of a QScatter3DSeries cannot be directly cast into QDateTime values due to + difference in data width, we need some sort of mapping between the two. We chose to do the + mapping by specifying an origin date for the formatter and interpreting the float values + from the QScatter3DSeries as date offsets to that origin value. The origin date is given as + a property: + + \snippet qmlaxisformatter/customformatter.h 1 + + The mapping from value to QDateTime is done using \c valueToDateTime() method: + + \snippet qmlaxisformatter/customformatter.cpp 0 + + To function as an axis formatter, our \c CustomFormatter needs to reimplement some virtual + methods: + + \snippet qmlaxisformatter/customformatter.h 0 + + The first two are simple, we just create a new instance of \c CustomFormatter and copy the + necessary data over to it. These two methods are used to create and update a cache of formatter for + rendering purposes. It is important to remember to call the superclass implementation + of \c populateCopy(): + + \snippet qmlaxisformatter/customformatter.cpp 1 + + Bulk of the work done by \c CustomFormatter is done in the \c recalculate() method, where + our formatter calculates the grid, subgrid, and label positions, as well as formats the label + strings. + In our custom formatter we ignore the segment count of the axis and draw a grid line always at + midnight. Subsegment count and label positioning is handled normally: + + \snippet qmlaxisformatter/customformatter.cpp 2 + + The axis labels are formatted to show only the date, but for selection label we want little more + resolution for the timestamp, so we specify another property for our custom formatter to allow + user to customize it: + + \snippet qmlaxisformatter/customformatter.h 3 + + This selection format property is used in the reimplemented \c stringToValue method, where we + ignore the submitted format and substitute the custom selection format for it: + + \snippet qmlaxisformatter/customformatter.cpp 3 + + To expose our new custom formatter to the QML, we must declare and register it: + + \snippet qmlaxisformatter/main.cpp 0 + \dots 0 + \snippet qmlaxisformatter/main.cpp 1 + + \section1 QML + + In the QML codes, we define a different axis for each dimension: + + \snippet qmlaxisformatter/qml/qmlaxisformatter/main.qml 3 + + Z-axis is just a regular ValueAxis3D: + + \snippet qmlaxisformatter/qml/qmlaxisformatter/main.qml 0 + + For the Y-axis we define a logarithmic axis. ValueAxis3D can be made to show logarithmic scale + by specifying LogValueAxis3DFormatter for \c formatter property of the axis: + + \snippet qmlaxisformatter/qml/qmlaxisformatter/main.qml 2 + + And finally, for the X-axis we use our new \c CustomFormatter: + + \snippet qmlaxisformatter/qml/qmlaxisformatter/main.qml 1 + + Rest of the application consists of fairly self-explanatory logic for modifying the axes and + showing the graph. +*/ -- cgit v1.2.3 From 1bb92e76313c691104869716a2078adecc38fa72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Thu, 3 Apr 2014 12:34:23 +0300 Subject: Added snapshots to 2 examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iad72ba09bd419d2adf3d17636c298f7d54baff27 Change-Id: Iad72ba09bd419d2adf3d17636c298f7d54baff27 Reviewed-by: Tomi Korpipää --- .../doc/images/qmlaxisformatter-example.png | Bin 0 -> 132952 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/datavisualization/qmlaxisformatter/doc/images/qmlaxisformatter-example.png (limited to 'examples/datavisualization/qmlaxisformatter/doc') diff --git a/examples/datavisualization/qmlaxisformatter/doc/images/qmlaxisformatter-example.png b/examples/datavisualization/qmlaxisformatter/doc/images/qmlaxisformatter-example.png new file mode 100644 index 00000000..fbfbd833 Binary files /dev/null and b/examples/datavisualization/qmlaxisformatter/doc/images/qmlaxisformatter-example.png differ -- cgit v1.2.3 From 4e37f474d69c64cb1f7d605467e47538464ba332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Thu, 22 May 2014 08:38:49 +0300 Subject: Docs for qml axis drag example Task-number: QTRD-3128 Change-Id: I731074040d51dc7dcd7aa2774c5889d5ae588191 Reviewed-by: Miikka Heikkinen --- .../datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/datavisualization/qmlaxisformatter/doc') diff --git a/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc b/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc index b990c490..156135bd 100644 --- a/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc +++ b/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc @@ -21,6 +21,7 @@ \title Qt Quick 2 Axis Formatter Example \ingroup qtdatavisualization_examples \brief Example of a hybrid C++ and QML application demonstrating different axis formatters. + \since Qt Data Visualization 1.1 The Qt Quick axis formatter example shows how to use predefined axis formatters and how to create a custom one. -- cgit v1.2.3 From 3eb656382e43fbd8cec36c801ec5eefd5efdcd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Thu, 5 Jun 2014 07:00:48 +0300 Subject: Doc \since changes Task-number: QTRD-3150 All \since -tags changed to use the same format. Change-Id: I858afd61002cef7ecb3cf56deda0dabc431c4fd5 Change-Id: I858afd61002cef7ecb3cf56deda0dabc431c4fd5 Reviewed-by: Titta Heikkala --- .../datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/datavisualization/qmlaxisformatter/doc') diff --git a/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc b/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc index 156135bd..3568e507 100644 --- a/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc +++ b/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc @@ -21,7 +21,7 @@ \title Qt Quick 2 Axis Formatter Example \ingroup qtdatavisualization_examples \brief Example of a hybrid C++ and QML application demonstrating different axis formatters. - \since Qt Data Visualization 1.1 + \since QtDataVisualization 1.1 The Qt Quick axis formatter example shows how to use predefined axis formatters and how to create a custom one. -- cgit v1.2.3