diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2023-01-30 13:10:05 +0200 |
---|---|---|
committer | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2023-02-02 12:05:14 +0200 |
commit | 6ae51a12ccd15575197e5aeff4de3273a615c1a9 (patch) | |
tree | ed52a789b499c02d36d861eb87cc694fd805f23f /examples/datavisualization/qmlaxisformatter | |
parent | b20a41dfb410ef0e99d73bc35dfffade48cf55cb (diff) |
Combine 2 examples into one
Combine qmlaxisdrag and qmlaxisformatter examples into one
Pick-to: 6.5
Fixes: QTBUG-110699
Change-Id: I5043089ad47370165543b7c09409ba08d5f4690d
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'examples/datavisualization/qmlaxisformatter')
10 files changed, 0 insertions, 610 deletions
diff --git a/examples/datavisualization/qmlaxisformatter/CMakeLists.txt b/examples/datavisualization/qmlaxisformatter/CMakeLists.txt deleted file mode 100644 index 6374edf7..00000000 --- a/examples/datavisualization/qmlaxisformatter/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlaxisformatter LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Qml) -find_package(Qt6 COMPONENTS Quick) -find_package(Qt6 COMPONENTS DataVisualization) - -qt_add_executable(qmlaxisformatter - main.cpp -) -set_target_properties(qmlaxisformatter PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(qmlaxisformatter PUBLIC - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick - Qt::DataVisualization -) - -qt6_add_qml_module(qmlaxisformatter - URI CustomFormatter - VERSION 1.0 - NO_RESOURCE_TARGET_PATH - SOURCES - customformatter.cpp customformatter.h - QML_FILES - qml/qmlaxisformatter/Data.qml - qml/qmlaxisformatter/main.qml -) - -install(TARGETS qmlaxisformatter - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/datavisualization/qmlaxisformatter/customformatter.cpp b/examples/datavisualization/qmlaxisformatter/customformatter.cpp deleted file mode 100644 index d628c160..00000000 --- a/examples/datavisualization/qmlaxisformatter/customformatter.cpp +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "customformatter.h" -#include <QtDataVisualization/QValue3DAxis> -#include <QtQml/QQmlExtensionPlugin> -#include <QtCore/QDebug> - -Q_DECLARE_METATYPE(QValue3DAxisFormatter *) - -static const qreal oneDayMs = 60.0 * 60.0 * 24.0 * 1000.0; - -CustomFormatter::CustomFormatter(QObject *parent) : - QValue3DAxisFormatter(parent) -{ - qRegisterMetaType<QValue3DAxisFormatter *>(); -} - -CustomFormatter::~CustomFormatter() -{ -} - -//! [1] -QValue3DAxisFormatter *CustomFormatter::createNewInstance() const -{ - return new CustomFormatter(); -} - -void CustomFormatter::populateCopy(QValue3DAxisFormatter ©) const -{ - QValue3DAxisFormatter::populateCopy(copy); - - CustomFormatter *customFormatter = static_cast<CustomFormatter *>(©); - customFormatter->m_originDate = m_originDate; - customFormatter->m_selectionFormat = m_selectionFormat; -} -//! [1] - -//! [2] -void CustomFormatter::recalculate() -{ - // We want our axis to always have gridlines at date breaks - - // Convert range into QDateTimes - QDateTime minTime = valueToDateTime(qreal(axis()->min())); - QDateTime maxTime = valueToDateTime(qreal(axis()->max())); - - // Find out the grid counts - QTime midnight(0, 0); - QDateTime minFullDate(minTime.date(), midnight); - int gridCount = 0; - if (minFullDate != minTime) - minFullDate = minFullDate.addDays(1); - QDateTime maxFullDate(maxTime.date(), midnight); - - gridCount += minFullDate.daysTo(maxFullDate) + 1; - int subGridCount = axis()->subSegmentCount() - 1; - - // Reserve space for position arrays and label strings - gridPositions().resize(gridCount); - subGridPositions().resize((gridCount + 1) * subGridCount); - labelPositions().resize(gridCount); - labelStrings().reserve(gridCount); - - // Calculate positions and format labels - qint64 startMs = minTime.toMSecsSinceEpoch(); - qint64 endMs = maxTime.toMSecsSinceEpoch(); - qreal dateNormalizer = endMs - startMs; - qreal firstLineOffset = (minFullDate.toMSecsSinceEpoch() - startMs) / dateNormalizer; - qreal segmentStep = oneDayMs / dateNormalizer; - qreal subSegmentStep = 0; - if (subGridCount > 0) - subSegmentStep = segmentStep / qreal(subGridCount + 1); - - for (int i = 0; i < gridCount; i++) { - qreal gridValue = firstLineOffset + (segmentStep * qreal(i)); - gridPositions()[i] = float(gridValue); - labelPositions()[i] = float(gridValue); - labelStrings() << minFullDate.addDays(i).toString(axis()->labelFormat()); - } - - for (int i = 0; i <= gridCount; i++) { - if (subGridPositions().size()) { - for (int j = 0; j < subGridCount; j++) { - float position; - if (i) - position = gridPositions().at(i - 1) + subSegmentStep * (j + 1); - else - position = gridPositions().at(0) - segmentStep + subSegmentStep * (j + 1); - if (position > 1.0f || position < 0.0f) - position = gridPositions().at(0); - subGridPositions()[i * subGridCount + j] = position; - } - } - } -} -//! [2] - -//! [3] -QString CustomFormatter::stringForValue(qreal value, const QString &format) const -{ - Q_UNUSED(format); - - return valueToDateTime(value).toString(m_selectionFormat); -} -//! [3] - -QDate CustomFormatter::originDate() const -{ - return m_originDate; -} - -QString CustomFormatter::selectionFormat() const -{ - return m_selectionFormat; -} - -void CustomFormatter::setOriginDate(const QDate &date) -{ - if (m_originDate != date) { - m_originDate = date; - markDirty(true); - emit originDateChanged(date); - } -} - -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); - } -} - -//! [0] -QDateTime CustomFormatter::valueToDateTime(qreal value) const -{ - return m_originDate.startOfDay().addMSecs(qint64(oneDayMs * value)); -} -//! [0] diff --git a/examples/datavisualization/qmlaxisformatter/customformatter.h b/examples/datavisualization/qmlaxisformatter/customformatter.h deleted file mode 100644 index 995ca3ee..00000000 --- a/examples/datavisualization/qmlaxisformatter/customformatter.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef CUSTOMFORMATTER_H -#define CUSTOMFORMATTER_H - -#include <QtDataVisualization/QValue3DAxisFormatter> -#include <QtCore/QDateTime> -#include <QtQml/qqmlregistration.h> - -//! [2] -class CustomFormatter : public QValue3DAxisFormatter -{ - //! [2] - Q_OBJECT - QML_ELEMENT - - //! [1] - Q_PROPERTY(QDate originDate READ originDate WRITE setOriginDate NOTIFY originDateChanged) - //! [1] - //! [3] - Q_PROPERTY(QString selectionFormat READ selectionFormat WRITE setSelectionFormat NOTIFY selectionFormatChanged) - //! [3] -public: - explicit CustomFormatter(QObject *parent = 0); - virtual ~CustomFormatter(); - - //! [0] - virtual QValue3DAxisFormatter *createNewInstance() const; - virtual void populateCopy(QValue3DAxisFormatter ©) const; - virtual void recalculate(); - virtual QString stringForValue(qreal value, const QString &format) const; - //! [0] - - QDate originDate() const; - QString selectionFormat() const; - -public Q_SLOTS: - void setOriginDate(const QDate &date); - void setSelectionFormat(const QString &format); - -Q_SIGNALS: - void originDateChanged(const QDate &date); - void selectionFormatChanged(const QString &format); - -private: - Q_DISABLE_COPY(CustomFormatter) - - QDateTime valueToDateTime(qreal value) const; - - QDate m_originDate; - QString m_selectionFormat; -}; - -#endif diff --git a/examples/datavisualization/qmlaxisformatter/doc/images/qmlaxisformatter-example.png b/examples/datavisualization/qmlaxisformatter/doc/images/qmlaxisformatter-example.png Binary files differdeleted file mode 100644 index fbfbd833..00000000 --- a/examples/datavisualization/qmlaxisformatter/doc/images/qmlaxisformatter-example.png +++ /dev/null diff --git a/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc b/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc deleted file mode 100644 index 3dd1075f..00000000 --- a/examples/datavisualization/qmlaxisformatter/doc/src/qmlaxisformatter.qdoc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example qmlaxisformatter - \meta tags {DataVisualization, Scatter3D, Custom Axis Formatter, Scatter Graph} - \meta category {Graphics} - \title Axis Formatters - \ingroup qtdatavisualization_qmlexamples - \brief Example of a hybrid C++ and QML application demonstrating different axis formatters. - \since QtDataVisualization 1.1 - - The Qt Quick axis formatters 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{Simple Scatter Graph}. - - \include examples-run.qdocinc - - \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 it and make it a QML module. - Doing this was introduced in the \l{Surface Oscilloscope} so we will skip it here. - - \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. -*/ diff --git a/examples/datavisualization/qmlaxisformatter/main.cpp b/examples/datavisualization/qmlaxisformatter/main.cpp deleted file mode 100644 index 557b77b2..00000000 --- a/examples/datavisualization/qmlaxisformatter/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtGui/QGuiApplication> -#include <QtQuick/QQuickView> -#include <QtQml> - -int main(int argc, char *argv[]) -{ - qputenv("QSG_RHI_BACKEND", "opengl"); - QGuiApplication app(argc, argv); - - QQuickView viewer; - - // The following are needed to make examples run without having to install the module - // in desktop environments. -#ifdef Q_OS_WIN - QString extraImportPath(QStringLiteral("%1/../../../../%2")); -#else - QString extraImportPath(QStringLiteral("%1/../../../%2")); -#endif - viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), - QString::fromLatin1("qml"))); - QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); - - viewer.setTitle(QStringLiteral("Axis formatter example")); - - viewer.setSource(QUrl("qrc:/qml/qmlaxisformatter/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/datavisualization/qmlaxisformatter/qml/qmlaxisformatter/Data.qml b/examples/datavisualization/qmlaxisformatter/qml/qmlaxisformatter/Data.qml deleted file mode 100644 index 689069e2..00000000 --- a/examples/datavisualization/qmlaxisformatter/qml/qmlaxisformatter/Data.qml +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick - -Item { - property alias model: dataModel - - ListModel { - id: dataModel - ListElement{ xPos: 2.456103; yPos: 1.0; zPos: 5.0 } - ListElement{ xPos: 5.687549; yPos: 3.0; zPos: 2.5 } - ListElement{ xPos: 2.357458; yPos: 4.1; zPos: 1.0 } - ListElement{ xPos: 4.567458; yPos: 4.75; zPos: 3.9 } - ListElement{ xPos: 6.885439; yPos: 4.9; zPos: 7.2 } - ListElement{ xPos: 2.366769; yPos: 13.42; zPos: 3.5 } - ListElement{ xPos: 7.546457; yPos: 233.1; zPos: 6.9 } - ListElement{ xPos: 2.475867; yPos: 32.91; zPos: 4.1 } - ListElement{ xPos: 8.456546; yPos: 153.68; zPos: 9.52 } - ListElement{ xPos: 3.456348; yPos: 52.96; zPos: 1.6 } - ListElement{ xPos: 1.536446; yPos: 32.4; zPos: 2.92 } - ListElement{ xPos: 8.456666; yPos: 114.74; zPos: 8.18 } - ListElement{ xPos: 5.468486; yPos: 83.1; zPos: 3.8 } - ListElement{ xPos: 6.546586 ; yPos: 63.66; zPos: 3.58 } - ListElement{ xPos: 8.567516 ; yPos: 1.82; zPos: 4.64 } - ListElement{ xPos: 7.678984 ; yPos: 213.18; zPos: 7.22 } - ListElement{ xPos: 7.457569 ; yPos: 63.06; zPos: 4.3 } - ListElement{ xPos: 8.456755 ; yPos: 122.64; zPos: 6.44 } - ListElement{ xPos: 6.234536 ; yPos: 63.96; zPos: 4.38 } - ListElement{ xPos: 9.456718 ; yPos: 243.32; zPos: 4.04 } - ListElement{ xPos: 10.789889 ; yPos: 43.4; zPos: 2.78 } - ListElement{ xPos: 11.346554 ; yPos: 345.12; zPos: 3.1 } - ListElement{ xPos: 12.023454 ; yPos: 500.0; zPos: 3.68 } - } -} diff --git a/examples/datavisualization/qmlaxisformatter/qml/qmlaxisformatter/main.qml b/examples/datavisualization/qmlaxisformatter/qml/qmlaxisformatter/main.qml deleted file mode 100644 index c77c6e8b..00000000 --- a/examples/datavisualization/qmlaxisformatter/qml/qmlaxisformatter/main.qml +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick -import QtQuick.Layouts -import QtQuick.Controls -import QtDataVisualization -import CustomFormatter - -Item { - id: mainView - width: 1280 - height: 1024 - - Data { - id: seriesData - } - - Theme3D { - id: themeIsabelle - type: Theme3D.ThemePrimaryColors - font.family: "Lucida Handwriting" - font.pointSize: 40 - } - - //! [1] - ValueAxis3D { - id: dateAxis - formatter: CustomFormatter { - originDate: "2014-01-01" - selectionFormat: "yyyy-MM-dd HH:mm:ss" - } - subSegmentCount: 2 - labelFormat: "yyyy-MM-dd" - min: 0 - max: 14 - } - //! [1] - - //! [2] - ValueAxis3D { - id: logAxis - formatter: LogValueAxis3DFormatter { - id: logAxisFormatter - base: 10 - autoSubGrid: true - showEdgeLabels: true - } - labelFormat: "%.2f" - } - //! [2] - - ValueAxis3D { - id: linearAxis - labelFormat: "%.2f" - min: 0 - max: 500 - } - - //! [0] - ValueAxis3D { - id: valueAxis - segmentCount: 5 - subSegmentCount: 2 - labelFormat: "%.2f" - min: 0 - max: 10 - } - //! [0] - - Item { - id: dataView - anchors.bottom: parent.bottom - width: parent.width - height: parent.height - buttonLayout.height - - Scatter3D { - id: scatterGraph - width: dataView.width - height: dataView.height - theme: themeIsabelle - shadowQuality: AbstractGraph3D.ShadowQualitySoftLow - scene.activeCamera.cameraPreset: Camera3D.CameraPresetIsometricRight - //! [3] - axisZ: valueAxis - axisY: logAxis - axisX: dateAxis - //! [3] - - Scatter3DSeries { - id: scatterSeries - itemLabelFormat: "@xLabel - (@yLabel, @zLabel)" - meshSmooth: true - ItemModelScatterDataProxy { - itemModel: seriesData.model - xPosRole: "xPos" - yPosRole: "yPos" - zPosRole: "zPos" - } - } - } - } - - RowLayout { - id: buttonLayout - Layout.minimumHeight: exitButton.height - width: parent.width - anchors.left: parent.left - spacing: 0 - - Button { - id: yAxisBaseChange - Layout.fillHeight: true - Layout.fillWidth: true - state: "enabled" - onClicked: { - if (logAxisFormatter.base === 10) - logAxisFormatter.base = 0 - else if (logAxisFormatter.base === 2) - logAxisFormatter.base = 10 - else - logAxisFormatter.base = 2 - } - states: [ - State { - name: "enabled" - PropertyChanges { - target: yAxisBaseChange - text: "Y-axis log base: " + logAxisFormatter.base - enabled: true - } - }, - State { - name: "disabled" - PropertyChanges { - target: yAxisBaseChange - text: "Y-axis linear" - enabled: false - } - } - ] - } - - Button { - id: yAxisToggle - Layout.fillHeight: true - Layout.fillWidth: true - text: "Toggle Y-axis" - onClicked: { - if (scatterGraph.axisY == linearAxis) { - scatterGraph.axisY = logAxis - yAxisBaseChange.state = "enabled" - } else { - scatterGraph.axisY = linearAxis - yAxisBaseChange.state = "disabled" - } - } - } - - Button { - id: exitButton - Layout.fillHeight: true - Layout.fillWidth: true - text: "Quit" - onClicked: Qt.quit(); - } - } -} diff --git a/examples/datavisualization/qmlaxisformatter/qmlaxisformatter.pro b/examples/datavisualization/qmlaxisformatter/qmlaxisformatter.pro deleted file mode 100644 index 0f3b2f80..00000000 --- a/examples/datavisualization/qmlaxisformatter/qmlaxisformatter.pro +++ /dev/null @@ -1,16 +0,0 @@ -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} - -QT += datavisualization - -# The .cpp file which was generated for your project. Feel free to hack it. -SOURCES += main.cpp \ - customformatter.cpp -HEADERS += customformatter.h - -RESOURCES += qmlaxisformatter.qrc - -OTHER_FILES += doc/src/* \ - doc/images/* \ - qml/qmlaxisformatter/* diff --git a/examples/datavisualization/qmlaxisformatter/qmlaxisformatter.qrc b/examples/datavisualization/qmlaxisformatter/qmlaxisformatter.qrc deleted file mode 100644 index 27c30362..00000000 --- a/examples/datavisualization/qmlaxisformatter/qmlaxisformatter.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlaxisformatter/main.qml</file> - <file>qml/qmlaxisformatter/Data.qml</file> - </qresource> -</RCC> |