diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2023-05-19 13:58:19 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2023-06-01 16:25:41 +0300 |
commit | 8f4629814f3df83e9ea85aebefb0e0c9929be476 (patch) | |
tree | 064dfae6717954aabf40aa785c4a1a49b030088a | |
parent | e10a36577ef5727784ccf1a909f72175e4fcd58c (diff) |
Revamp examples
Separate gallery example was created for widget and qml examples and
most example code was moved under those two gallery examples.
Examples left outside galleries for various reasons:
- audio: Requires multimedia, which is an optional addon
- openglseries: Requires OpenGL backend
- qmloscilloscope: Complicated hybrid C++/QML example
- qmlweather: Uses optional command line parameter
- zoomlinechart: Uses gestures, which require grabbing main window
Cleaned up the code of the remaining examples to same standard as
galleries.
Examples documentation will be updated in a separate commit.
Task-number: QTBUG-94181
Task-number: QTBUG-111053
Task-number: QTBUG-113655
Change-Id: I6a98a4386364fcb2530e2667aea95760e6ff2983
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
389 files changed, 5647 insertions, 8252 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ce6deae6..a35cf1c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ project(QtCharts set(QT_USE_FIXED_QT_ADD_RESOURCE_BASE TRUE) find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core) # special case -find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Gui Widgets OpenGL OpenGLWidgets Quick Qml QuickTest Test) # special case +find_package(Qt6 ${PROJECT_VERSION} CONFIG OPTIONAL_COMPONENTS Gui Widgets OpenGL OpenGLWidgets MultiMedia Quick Qml QuickTest Test) # special case qt_internal_project_setup() #special case begin diff --git a/examples/charts/CMakeLists.txt b/examples/charts/CMakeLists.txt index f630f3c6..1379f99f 100644 --- a/examples/charts/CMakeLists.txt +++ b/examples/charts/CMakeLists.txt @@ -1,90 +1,48 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -if(QT_FEATURE_charts_area_chart) - qt_internal_add_example(areachart) +if(QT_FEATURE_charts_area_chart + AND QT_FEATURE_charts_line_chart + AND QT_FEATURE_charts_spline_chart + AND QT_FEATURE_charts_bar_chart + AND QT_FEATURE_charts_pie_chart + AND QT_FEATURE_charts_boxplot_chart + AND QT_FEATURE_charts_candlestick_chart + AND QT_FEATURE_charts_scatter_chart + AND QT_FEATURE_charts_datetime_axis) + qt_internal_add_example(gallery) endif() -if(QT_FEATURE_charts_line_chart) - qt_internal_add_example(callout) - qt_internal_add_example(chartinteractions) - qt_internal_add_example(customchart) - qt_internal_add_example(linechart) - qt_internal_add_example(lineandbar) - qt_internal_add_example(legendmarkers) - qt_internal_add_example(logvalueaxis) - qt_internal_add_example(modeldata) - qt_internal_add_example(zoomlinechart) - qt_internal_add_example(pointconfiguration) -endif() -if(QT_FEATURE_charts_spline_chart) - qt_internal_add_example(dynamicspline) - qt_internal_add_example(multiaxis) - qt_internal_add_example(splinechart) - qt_internal_add_example(pointsselectionandmarkers) -endif() -if(QT_FEATURE_charts_area_chart AND QT_FEATURE_charts_spline_chart) - qt_internal_add_example(chartthemes) - qt_internal_add_example(polarchart) -endif() -if(QT_FEATURE_charts_bar_chart) - qt_internal_add_example(barchart) - qt_internal_add_example(barmodelmapper) - qt_internal_add_example(horizontalbarchart) - qt_internal_add_example(horizontalpercentbarchart) - qt_internal_add_example(horizontalstackedbarchart) - qt_internal_add_example(stackedbarchart) - qt_internal_add_example(stackedbarchartdrilldown) - qt_internal_add_example(percentbarchart) - qt_internal_add_example(legend) - qt_internal_add_example(temperaturerecords) - qt_internal_add_example(selectedbar) -endif() -if(QT_FEATURE_charts_pie_chart) - qt_internal_add_example(donutchart) - qt_internal_add_example(donutbreakdown) - qt_internal_add_example(nesteddonuts) - qt_internal_add_example(piechart) - qt_internal_add_example(piechartcustomization) - qt_internal_add_example(piechartdrilldown) -endif() -if(QT_FEATURE_charts_pie_chart AND TARGET Qt::Quick) - qt_internal_add_example(qmlpiechart) -endif() -if(QT_FEATURE_charts_boxplot_chart) - qt_internal_add_example(boxplotchart) -endif() -if(QT_FEATURE_charts_boxplot_chart AND TARGET Qt::Quick) - qt_internal_add_example(qmlboxplot) -endif() -if(QT_FEATURE_charts_candlestick_chart) - qt_internal_add_example(candlestickchart) -endif() -if(QT_FEATURE_charts_candlestick_chart AND TARGET Qt::Quick) - qt_internal_add_example(qmlcandlestick) -endif() -if(QT_FEATURE_charts_scatter_chart) - qt_internal_add_example(scatterchart) - qt_internal_add_example(scatterinteractions) -endif() -if(TARGET Qt::Quick) - qt_internal_add_example(qmlchart) - qt_internal_add_example(qmlcustomizations) - qt_internal_add_example(qmlcustomlegend) - qt_internal_add_example(qmlf1legends) - qt_internal_add_example(qmloscilloscope) - qt_internal_add_example(qmlweather) + +if(QT_FEATURE_charts_area_chart + AND QT_FEATURE_charts_line_chart + AND QT_FEATURE_charts_spline_chart + AND QT_FEATURE_charts_bar_chart + AND QT_FEATURE_charts_pie_chart + AND QT_FEATURE_charts_boxplot_chart + AND QT_FEATURE_charts_candlestick_chart + AND QT_FEATURE_charts_scatter_chart + AND QT_FEATURE_charts_datetime_axis + AND TARGET Qt::Quick) + qt_internal_add_example(qmlgallery) endif() -if(TARGET Qt::Multimedia) - # TODO: this never gets compiled : missing find_pacakge - # qt_internal_add_example(audio) // QTBUG-94181 + +if(QT_FEATURE_charts_line_chart AND TARGET Qt::Multimedia) + qt_internal_add_example(audio) endif() + if(QT_FEATURE_opengl) qt_internal_add_example(openglseries) endif() -if(QT_FEATURE_charts_datetime_axis) - qt_internal_add_example(datetimeaxis) + +if(QT_FEATURE_charts_line_chart) + qt_internal_add_example(zoomlinechart) endif() -if(QT_FEATURE_charts_datetime_axis AND TARGET Qt::Quick) - qt_internal_add_example(qmlaxes) - qt_internal_add_example(qmlpolarchart) + +if(QT_FEATURE_charts_line_chart AND QT_FEATURE_charts_scatter_chart AND TARGET Qt::Quick) + qt_internal_add_example(qmloscilloscope) +endif() + +if(QT_FEATURE_charts_line_chart AND QT_FEATURE_charts_bar_chart AND TARGET Qt::Quick) + qt_internal_add_example(qmlweather) endif() + diff --git a/examples/charts/areachart/CMakeLists.txt b/examples/charts/areachart/CMakeLists.txt deleted file mode 100644 index 0072acac..00000000 --- a/examples/charts/areachart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(areachart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/areachart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(areachart - main.cpp -) - -set_target_properties(areachart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(areachart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS areachart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/areachart/areachart.pro b/examples/charts/areachart/areachart.pro deleted file mode 100644 index 96e138ab..00000000 --- a/examples/charts/areachart/areachart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/areachart -INSTALLS += target diff --git a/examples/charts/audio/CMakeLists.txt b/examples/charts/audio/CMakeLists.txt index d8f11e0d..dd50a1fe 100644 --- a/examples/charts/audio/CMakeLists.txt +++ b/examples/charts/audio/CMakeLists.txt @@ -4,8 +4,6 @@ cmake_minimum_required(VERSION 3.16) project(audio LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/audio") find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Multimedia) +qt_standard_project_setup() + qt_add_executable(audio main.cpp widget.cpp widget.h diff --git a/examples/charts/audio/main.cpp b/examples/charts/audio/main.cpp index 0c56b5e4..15d53c23 100644 --- a/examples/charts/audio/main.cpp +++ b/examples/charts/audio/main.cpp @@ -1,12 +1,12 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "widget.h" -#include <QtMultimedia/QAudioDevice> -#include <QtMultimedia/QMediaDevices> -#include <QtWidgets/QApplication> -#include <QtWidgets/QMessageBox> +#include <QApplication> +#include <QAudioDevice> +#include <QMediaDevices> +#include <QMessageBox> int main(int argc, char *argv[]) { diff --git a/examples/charts/audio/widget.cpp b/examples/charts/audio/widget.cpp index 888604b9..65b9b47c 100644 --- a/examples/charts/audio/widget.cpp +++ b/examples/charts/audio/widget.cpp @@ -1,34 +1,30 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "widget.h" #include "xyseriesiodevice.h" -#include <QtMultimedia/QAudioDevice> -#include <QtMultimedia/QAudioInput> -#include <QtMultimedia/QAudioSource> - -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCharts/QChart> -#include <QtCharts/QValueAxis> - -#include <QtWidgets/QVBoxLayout> - -QT_USE_NAMESPACE - -Widget::Widget(const QAudioDevice &deviceInfo, QWidget *parent) : - QWidget(parent), - m_chart(new QChart), - m_series(new QLineSeries) +#include <QAudioDevice> +#include <QAudioInput> +#include <QAudioSource> +#include <QChart> +#include <QChartView> +#include <QLineSeries> +#include <QValueAxis> +#include <QVBoxLayout> + +Widget::Widget(const QAudioDevice &deviceInfo, QWidget *parent) + : QWidget(parent) + , m_chart(new QChart) + , m_series(new QLineSeries) { - QChartView *chartView = new QChartView(m_chart); + auto chartView = new QChartView(m_chart); m_chart->addSeries(m_series); - QValueAxis *axisX = new QValueAxis; + auto axisX = new QValueAxis; axisX->setRange(0, XYSeriesIODevice::sampleCount); axisX->setLabelFormat("%g"); axisX->setTitleText("Samples"); - QValueAxis *axisY = new QValueAxis; + auto axisY = new QValueAxis; axisY->setRange(-1, 1); axisY->setTitleText("Audio level"); m_chart->addAxis(axisX, Qt::AlignBottom); @@ -38,7 +34,7 @@ Widget::Widget(const QAudioDevice &deviceInfo, QWidget *parent) : m_chart->legend()->hide(); m_chart->setTitle("Data from the microphone (" + deviceInfo.description() + ')'); - QVBoxLayout *mainLayout = new QVBoxLayout(this); + auto mainLayout = new QVBoxLayout(this); mainLayout->addWidget(chartView); m_audioInput = new QAudioInput(deviceInfo, this); diff --git a/examples/charts/audio/widget.h b/examples/charts/audio/widget.h index 0be4534f..ee411f81 100644 --- a/examples/charts/audio/widget.h +++ b/examples/charts/audio/widget.h @@ -1,41 +1,32 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef WIDGET_H #define WIDGET_H -#include <QtWidgets/QWidget> -#include <QtCharts/QChartGlobal> +#include <QWidget> -QT_BEGIN_NAMESPACE -class QLineSeries; -class QChart; -QT_END_NAMESPACE - -QT_USE_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QAudioDevice) +QT_FORWARD_DECLARE_CLASS(QAudioInput) +QT_FORWARD_DECLARE_CLASS(QAudioSource) +QT_FORWARD_DECLARE_CLASS(QChart) +QT_FORWARD_DECLARE_CLASS(QLineSeries) class XYSeriesIODevice; -QT_BEGIN_NAMESPACE -class QAudioInput; -class QAudioDevice; -class QAudioSource; -QT_END_NAMESPACE - class Widget : public QWidget { Q_OBJECT - public: explicit Widget(const QAudioDevice &deviceInfo, QWidget *parent = nullptr); ~Widget(); private: XYSeriesIODevice *m_device = nullptr; - QChart *m_chart; - QLineSeries *m_series ; + QChart *m_chart = nullptr; + QLineSeries *m_series = nullptr; QAudioInput *m_audioInput = nullptr; QAudioSource *m_audioSource = nullptr; }; -#endif // WIDGET_H +#endif diff --git a/examples/charts/audio/xyseriesiodevice.cpp b/examples/charts/audio/xyseriesiodevice.cpp index cbb3b243..f61c6dfd 100644 --- a/examples/charts/audio/xyseriesiodevice.cpp +++ b/examples/charts/audio/xyseriesiodevice.cpp @@ -1,9 +1,9 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "xyseriesiodevice.h" -#include <QtCharts/QXYSeries> +#include <QXYSeries> XYSeriesIODevice::XYSeriesIODevice(QXYSeries *series, QObject *parent) : QIODevice(parent), diff --git a/examples/charts/audio/xyseriesiodevice.h b/examples/charts/audio/xyseriesiodevice.h index 98faf8b4..ef08636e 100644 --- a/examples/charts/audio/xyseriesiodevice.h +++ b/examples/charts/audio/xyseriesiodevice.h @@ -1,19 +1,14 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef XYSERIESIODEVICE_H #define XYSERIESIODEVICE_H -#include <QtCore/QIODevice> -#include <QtCore/QPointF> -#include <QtCore/QList> -#include <QtCharts/QChartGlobal> +#include <QIODevice> +#include <QList> +#include <QPointF> -QT_BEGIN_NAMESPACE -class QXYSeries; -QT_END_NAMESPACE - -QT_USE_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QXYSeries) class XYSeriesIODevice : public QIODevice { @@ -28,7 +23,7 @@ protected: qint64 writeData(const char *data, qint64 maxSize) override; private: - QXYSeries *m_series; + QXYSeries *m_series = nullptr; QList<QPointF> m_buffer; }; diff --git a/examples/charts/barchart/CMakeLists.txt b/examples/charts/barchart/CMakeLists.txt deleted file mode 100644 index 388ca2e0..00000000 --- a/examples/charts/barchart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(barchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/barchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(barchart - main.cpp -) - -set_target_properties(barchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(barchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS barchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/barchart/barchart.pro b/examples/charts/barchart/barchart.pro deleted file mode 100644 index eaa7a037..00000000 --- a/examples/charts/barchart/barchart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/barchart -INSTALLS += target diff --git a/examples/charts/barchart/main.cpp b/examples/charts/barchart/main.cpp deleted file mode 100644 index db79e92e..00000000 --- a/examples/charts/barchart/main.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QValueAxis> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QBarSet *set0 = new QBarSet("Jane"); - QBarSet *set1 = new QBarSet("John"); - QBarSet *set2 = new QBarSet("Axel"); - QBarSet *set3 = new QBarSet("Mary"); - QBarSet *set4 = new QBarSet("Samantha"); - - *set0 << 1 << 2 << 3 << 4 << 5 << 6; - *set1 << 5 << 0 << 0 << 4 << 0 << 7; - *set2 << 3 << 5 << 8 << 13 << 8 << 5; - *set3 << 5 << 6 << 7 << 3 << 4 << 5; - *set4 << 9 << 7 << 5 << 3 << 1 << 2; -//![1] - -//![2] - QBarSeries *series = new QBarSeries(); - series->append(set0); - series->append(set1); - series->append(set2); - series->append(set3); - series->append(set4); - -//![2] - -//![3] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->setTitle("Simple barchart example"); - chart->setAnimationOptions(QChart::SeriesAnimations); -//![3] - -//![4] - QStringList categories; - categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - QBarCategoryAxis *axisX = new QBarCategoryAxis(); - axisX->append(categories); - chart->addAxis(axisX, Qt::AlignBottom); - series->attachAxis(axisX); - - QValueAxis *axisY = new QValueAxis(); - axisY->setRange(0,15); - chart->addAxis(axisY, Qt::AlignLeft); - series->attachAxis(axisY); -//![4] - -//![5] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); -//![5] - -//![6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![6] - -//![7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(420, 300); - window.show(); -//![7] - - return a.exec(); -} diff --git a/examples/charts/barmodelmapper/CMakeLists.txt b/examples/charts/barmodelmapper/CMakeLists.txt deleted file mode 100644 index 21c8cf59..00000000 --- a/examples/charts/barmodelmapper/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(barmodelmapper LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/barmodelmapper") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(barmodelmapper - customtablemodel.cpp customtablemodel.h - main.cpp - tablewidget.cpp tablewidget.h -) - -set_target_properties(barmodelmapper PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(barmodelmapper PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS barmodelmapper - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/barmodelmapper/barmodelmapper.pro b/examples/charts/barmodelmapper/barmodelmapper.pro deleted file mode 100644 index 0ff60561..00000000 --- a/examples/charts/barmodelmapper/barmodelmapper.pro +++ /dev/null @@ -1,14 +0,0 @@ -QT += charts -requires(qtConfig(tableview)) - -HEADERS += \ - customtablemodel.h \ - tablewidget.h - -SOURCES += \ - customtablemodel.cpp \ - main.cpp \ - tablewidget.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/barmodelmapper -INSTALLS += target diff --git a/examples/charts/barmodelmapper/main.cpp b/examples/charts/barmodelmapper/main.cpp deleted file mode 100644 index 92485579..00000000 --- a/examples/charts/barmodelmapper/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include "tablewidget.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - TableWidget w; - w.show(); - return a.exec(); -} diff --git a/examples/charts/barmodelmapper/tablewidget.h b/examples/charts/barmodelmapper/tablewidget.h deleted file mode 100644 index 03fb9db7..00000000 --- a/examples/charts/barmodelmapper/tablewidget.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef TABLEWIDGET_H -#define TABLEWIDGET_H - -#include <QtWidgets/QWidget> -#include "customtablemodel.h" - -class TableWidget : public QWidget -{ - Q_OBJECT - -public: - TableWidget(QWidget *parent = 0); - -private: - CustomTableModel *m_model; -}; - -#endif // TABLEWIDGET_H diff --git a/examples/charts/boxplotchart/CMakeLists.txt b/examples/charts/boxplotchart/CMakeLists.txt deleted file mode 100644 index 208d1ef1..00000000 --- a/examples/charts/boxplotchart/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(boxplotchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/boxplotchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(boxplotchart - boxdatareader.cpp boxdatareader.h - main.cpp -) - -set_target_properties(boxplotchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(boxplotchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -# Resources: -set_source_files_properties("acme_data.txt" - PROPERTIES QT_RESOURCE_ALIAS "acme" -) - -set_source_files_properties("boxwhisk_data.txt" - PROPERTIES QT_RESOURCE_ALIAS "boxwhisk" -) - -set(boxplotdata_resource_files - "acme_data.txt" - "boxwhisk_data.txt" -) - -qt6_add_resources(boxplotchart "boxplotdata" - PREFIX - "/" - FILES - ${boxplotdata_resource_files} -) - -install(TARGETS boxplotchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/boxplotchart/boxdatareader.cpp b/examples/charts/boxplotchart/boxdatareader.cpp deleted file mode 100644 index ec59a38f..00000000 --- a/examples/charts/boxplotchart/boxdatareader.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "boxdatareader.h" - -#include <algorithm> - -BoxDataReader::BoxDataReader(QIODevice *device) : - QTextStream(device) -{ -} - -void BoxDataReader::readFile(QIODevice *device) -{ - QTextStream::setDevice(device); -} - -QBoxSet *BoxDataReader::readBox() -{ - //! [1] - QString line = readLine(); - if (line.startsWith("#")) - return 0; - //! [1] - - //! [2] - QStringList strList = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); - //! [2] - - //! [3] - sortedList.clear(); - for (int i = 1; i < strList.count(); i++) - sortedList.append(strList.at(i).toDouble()); - - std::sort(sortedList.begin(), sortedList.end()); - //! [3] - - int count = sortedList.count(); - - //! [4] - QBoxSet *box = new QBoxSet(strList.first()); - box->setValue(QBoxSet::LowerExtreme, sortedList.first()); - box->setValue(QBoxSet::UpperExtreme, sortedList.last()); - box->setValue(QBoxSet::Median, findMedian(0, count)); - box->setValue(QBoxSet::LowerQuartile, findMedian(0, count / 2)); - box->setValue(QBoxSet::UpperQuartile, findMedian(count / 2 + (count % 2), count)); - //! [4] - - return box; -} - -qreal BoxDataReader::findMedian(int begin, int end) -{ - //! [5] - int count = end - begin; - if (count % 2) { - return sortedList.at(count / 2 + begin); - } else { - qreal right = sortedList.at(count / 2 + begin); - qreal left = sortedList.at(count / 2 - 1 + begin); - return (right + left) / 2.0; - } - //! [5] -} diff --git a/examples/charts/boxplotchart/boxdatareader.h b/examples/charts/boxplotchart/boxdatareader.h deleted file mode 100644 index 30173b9f..00000000 --- a/examples/charts/boxplotchart/boxdatareader.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef BOXDATAREADER_H -#define BOXDATAREADER_H - -#include <QtCore/QTextStream> -#include <QtCharts/QBoxSet> - -QT_USE_NAMESPACE - -class BoxDataReader : public QTextStream -{ -public: - explicit BoxDataReader(QIODevice *device); - QBoxSet *readBox(); - void readFile(QIODevice *device); - -protected: - qreal findMedian(int begin, int end); - -private: - QList<qreal> sortedList; -}; - -#endif // BOXDATAREADER_H diff --git a/examples/charts/boxplotchart/boxplotchart.pro b/examples/charts/boxplotchart/boxplotchart.pro deleted file mode 100644 index 10ed4515..00000000 --- a/examples/charts/boxplotchart/boxplotchart.pro +++ /dev/null @@ -1,14 +0,0 @@ -QT += charts - -HEADERS += \ - boxdatareader.h - -SOURCES += \ - boxdatareader.cpp \ - main.cpp \ - -RESOURCES += \ - boxplotdata.qrc - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/boxplotchart -INSTALLS += target diff --git a/examples/charts/boxplotchart/boxplotdata.qrc b/examples/charts/boxplotchart/boxplotdata.qrc deleted file mode 100644 index fe6d52b5..00000000 --- a/examples/charts/boxplotchart/boxplotdata.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file alias="acme">acme_data.txt</file> - <file alias="boxwhisk">boxwhisk_data.txt</file> - </qresource> -</RCC> diff --git a/examples/charts/boxplotchart/main.cpp b/examples/charts/boxplotchart/main.cpp deleted file mode 100644 index 16cf5d96..00000000 --- a/examples/charts/boxplotchart/main.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QBoxPlotSeries> -#include <QtCharts/QBoxSet> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCore/QFile> - -#include "boxdatareader.h" - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - //! [1] - QBoxPlotSeries *acmeSeries = new QBoxPlotSeries(); - acmeSeries->setName("Acme Ltd"); - - QBoxPlotSeries *boxWhiskSeries = new QBoxPlotSeries(); - boxWhiskSeries->setName("BoxWhisk Inc"); - //! [1] - - //! [2] - QFile acmeData(":acme"); - if (!acmeData.open(QIODevice::ReadOnly | QIODevice::Text)) - return 1; - - BoxDataReader dataReader(&acmeData); - while (!dataReader.atEnd()) { - QBoxSet *set = dataReader.readBox(); - if (set) - acmeSeries->append(set); - } - //! [2] - - //! [3] - QFile boxwhiskData(":boxwhisk"); - if (!boxwhiskData.open(QIODevice::ReadOnly | QIODevice::Text)) - return 1; - - dataReader.readFile(&boxwhiskData); - while (!dataReader.atEnd()) { - QBoxSet *set = dataReader.readBox(); - if (set) - boxWhiskSeries->append(set); - } - //! [3] - - //! [4] - QChart *chart = new QChart(); - chart->addSeries(acmeSeries); - chart->addSeries(boxWhiskSeries); - chart->setTitle("Acme Ltd and BoxWhisk Inc share deviation in 2012"); - chart->setAnimationOptions(QChart::SeriesAnimations); - //! [4] - - //! [5] - chart->createDefaultAxes(); - chart->axes(Qt::Vertical).first()->setMin(15.0); - chart->axes(Qt::Horizontal).first()->setMax(34.0); - //! [5] - - //! [6] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); - //! [6] - - //! [7] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); - //! [7] - - //! [8] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(800, 600); - window.show(); - //! [8] - - return a.exec(); -} - diff --git a/examples/charts/callout/CMakeLists.txt b/examples/charts/callout/CMakeLists.txt deleted file mode 100644 index fc47fbfe..00000000 --- a/examples/charts/callout/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(callout LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/callout") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(callout - callout.cpp callout.h - main.cpp - view.cpp view.h -) - -set_target_properties(callout PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(callout PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS callout - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/callout/callout.h b/examples/charts/callout/callout.h deleted file mode 100644 index 06c55adc..00000000 --- a/examples/charts/callout/callout.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef CALLOUT_H -#define CALLOUT_H - -#include <QtCharts/QChartGlobal> -#include <QtWidgets/QGraphicsItem> -#include <QtGui/QFont> - -QT_BEGIN_NAMESPACE -class QGraphicsSceneMouseEvent; -QT_END_NAMESPACE - -QT_BEGIN_NAMESPACE -class QChart; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class Callout : public QGraphicsItem -{ -public: - Callout(QChart *parent); - - void setText(const QString &text); - void setAnchor(QPointF point); - void updateGeometry(); - - QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - -private: - QString m_text; - QRectF m_textRect; - QRectF m_rect; - QPointF m_anchor; - QFont m_font; - QChart *m_chart; -}; - -#endif // CALLOUT_H diff --git a/examples/charts/callout/callout.pro b/examples/charts/callout/callout.pro deleted file mode 100644 index 688b69e9..00000000 --- a/examples/charts/callout/callout.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts - -HEADERS += \ - callout.h \ - view.h - -SOURCES += \ - callout.cpp \ - main.cpp\ - view.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/callout -INSTALLS += target diff --git a/examples/charts/callout/main.cpp b/examples/charts/callout/main.cpp deleted file mode 100644 index 02115966..00000000 --- a/examples/charts/callout/main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include "view.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - View w; - w.show(); - - return a.exec(); -} diff --git a/examples/charts/callout/view.h b/examples/charts/callout/view.h deleted file mode 100644 index 276d8744..00000000 --- a/examples/charts/callout/view.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef VIEW_H -#define VIEW_H -#include <QtWidgets/QGraphicsView> -#include <QtCharts/QChartGlobal> - -QT_BEGIN_NAMESPACE -class QGraphicsScene; -class QMouseEvent; -class QResizeEvent; -QT_END_NAMESPACE - -QT_BEGIN_NAMESPACE -class QChart; -QT_END_NAMESPACE - -class Callout; - -QT_USE_NAMESPACE - -class View: public QGraphicsView -{ - Q_OBJECT - -public: - View(QWidget *parent = 0); - -protected: - void resizeEvent(QResizeEvent *event); - void mouseMoveEvent(QMouseEvent *event); - -public slots: - void keepCallout(); - void tooltip(QPointF point, bool state); - -private: - QGraphicsSimpleTextItem *m_coordX; - QGraphicsSimpleTextItem *m_coordY; - QChart *m_chart; - Callout *m_tooltip; - QList<Callout *> m_callouts; -}; - -#endif diff --git a/examples/charts/candlestickchart/CMakeLists.txt b/examples/charts/candlestickchart/CMakeLists.txt deleted file mode 100644 index f74163b1..00000000 --- a/examples/charts/candlestickchart/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(candlestickchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/candlestickchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(candlestickchart - candlestickdatareader.cpp candlestickdatareader.h - main.cpp -) - -set_target_properties(candlestickchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(candlestickchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -# Resources: -set_source_files_properties("acme_data.txt" - PROPERTIES QT_RESOURCE_ALIAS "acme" -) - -set(candlestickdata_resource_files - "acme_data.txt" -) - -qt6_add_resources(candlestickchart "candlestickdata" - PREFIX - "/" - FILES - ${candlestickdata_resource_files} -) - -install(TARGETS candlestickchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/candlestickchart/candlestickchart.pro b/examples/charts/candlestickchart/candlestickchart.pro deleted file mode 100644 index f7080e77..00000000 --- a/examples/charts/candlestickchart/candlestickchart.pro +++ /dev/null @@ -1,15 +0,0 @@ -QT += charts - -TARGET = candlestickchart - -SOURCES += main.cpp \ - candlestickdatareader.cpp - -HEADERS += \ - candlestickdatareader.h - -RESOURCES += \ - candlestickdata.qrc - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/candlestickchart -INSTALLS += target diff --git a/examples/charts/candlestickchart/candlestickdata.qrc b/examples/charts/candlestickchart/candlestickdata.qrc deleted file mode 100644 index e311cadb..00000000 --- a/examples/charts/candlestickchart/candlestickdata.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file alias="acme">acme_data.txt</file> - </qresource> -</RCC> diff --git a/examples/charts/candlestickchart/main.cpp b/examples/charts/candlestickchart/main.cpp deleted file mode 100644 index b0f4119d..00000000 --- a/examples/charts/candlestickchart/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QCandlestickSeries> -#include <QtCharts/QChartView> -#include <QtCharts/QValueAxis> -#include <QtCore/QDateTime> -#include <QtCore/QFile> -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> - -#include "candlestickdatareader.h" - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - //! [1] - QCandlestickSeries *acmeSeries = new QCandlestickSeries(); - acmeSeries->setName("Acme Ltd"); - acmeSeries->setIncreasingColor(QColor(Qt::green)); - acmeSeries->setDecreasingColor(QColor(Qt::red)); - //! [1] - - //! [2] - QFile acmeData(":acme"); - if (!acmeData.open(QIODevice::ReadOnly | QIODevice::Text)) - return 1; - - QStringList categories; - - CandlestickDataReader dataReader(&acmeData); - while (!dataReader.atEnd()) { - QCandlestickSet *set = dataReader.readCandlestickSet(); - if (set) { - acmeSeries->append(set); - categories << QDateTime::fromMSecsSinceEpoch(set->timestamp()).toString("dd"); - } - } - //! [2] - - //! [3] - QChart *chart = new QChart(); - chart->addSeries(acmeSeries); - chart->setTitle("Acme Ltd Historical Data (July 2015)"); - chart->setAnimationOptions(QChart::SeriesAnimations); - //! [3] - - //! [4] - chart->createDefaultAxes(); - - QBarCategoryAxis *axisX = qobject_cast<QBarCategoryAxis *>(chart->axes(Qt::Horizontal).at(0)); - axisX->setCategories(categories); - - QValueAxis *axisY = qobject_cast<QValueAxis *>(chart->axes(Qt::Vertical).at(0)); - axisY->setMax(axisY->max() * 1.01); - axisY->setMin(axisY->min() * 0.99); - //! [4] - - //! [5] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); - //! [5] - - //! [6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); - //! [6] - - //! [7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(800, 600); - window.show(); - //! [7] - - return a.exec(); -} diff --git a/examples/charts/chartinteractions/CMakeLists.txt b/examples/charts/chartinteractions/CMakeLists.txt deleted file mode 100644 index 65f1f518..00000000 --- a/examples/charts/chartinteractions/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(chartinteractions LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/chartinteractions") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(chartinteractions - chart.cpp chart.h - chartview.cpp chartview.h - main.cpp -) - -set_target_properties(chartinteractions PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(chartinteractions PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS chartinteractions - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/chartinteractions/chart.h b/examples/charts/chartinteractions/chart.h deleted file mode 100644 index 4b4711d0..00000000 --- a/examples/charts/chartinteractions/chart.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef CHART_H -#define CHART_H - -#include <QtCharts/QChart> -#include <QtCharts/QLineSeries> - -QT_USE_NAMESPACE - -class Chart : public QChart -{ - Q_OBJECT -public: - explicit Chart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {}, QLineSeries *series = nullptr); - ~Chart(); - -public slots: - void clickPoint(const QPointF &point); - -public: - void handlePointMove(const QPoint &point); - void setPointClicked(bool clicked); - -private: - qreal distance(const QPointF &p1, const QPointF &p2); - QLineSeries *m_series; - QPointF m_movingPoint; - - //Boolean value to determine if an actual point in the - //series is clicked. - bool m_clicked; -}; - -#endif // CHART_H diff --git a/examples/charts/chartinteractions/chartinteractions.pro b/examples/charts/chartinteractions/chartinteractions.pro deleted file mode 100644 index 4027eb3c..00000000 --- a/examples/charts/chartinteractions/chartinteractions.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts - -HEADERS += \ - chart.h \ - chartview.h - -SOURCES += \ - chart.cpp \ - chartview.cpp \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/chartinteractions -INSTALLS += target diff --git a/examples/charts/chartinteractions/chartview.h b/examples/charts/chartinteractions/chartview.h deleted file mode 100644 index 4961b76b..00000000 --- a/examples/charts/chartinteractions/chartview.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef CHARTVIEW_H -#define CHARTVIEW_H - -#include <QtCharts/QChartView> - -class Chart; - -QT_USE_NAMESPACE - -class ChartView : public QChartView -{ -public: - ChartView(Chart *chart, QWidget *parent = 0); - -protected: - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - -private: - Chart *m_chart; - QPoint m_mousePos; -}; - -#endif diff --git a/examples/charts/chartinteractions/main.cpp b/examples/charts/chartinteractions/main.cpp deleted file mode 100644 index e78d6007..00000000 --- a/examples/charts/chartinteractions/main.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QLineSeries> - -#include <QtCharts/QValueAxis> - -#include "chart.h" -#include "chartview.h" - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - QLineSeries *series = new QLineSeries(); - - series->append(0, 6); - series->append(1, 3); - series->append(2, 4); - series->append(3, 8); - series->append(7, 13); - series->append(10, 5); - *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); - - Chart *chart = new Chart(0, {}, series); - chart->legend()->hide(); - chart->addSeries(series); - QPen p = series->pen(); - p.setWidth(5); - series->setPen(p); - chart->setTitle("Drag'n drop to move data points"); - - QValueAxis *axisX = new QValueAxis(); - chart->addAxis(axisX, Qt::AlignBottom); - axisX->setRange(0, 20); - series->attachAxis(axisX); - - QValueAxis *axisY = new QValueAxis(); - chart->addAxis(axisY, Qt::AlignLeft); - axisY->setRange(0, 13); - series->attachAxis(axisY); - - QObject::connect(series, &QLineSeries::pressed, chart, &Chart::clickPoint); - - ChartView *chartView = new ChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); - - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); - - return a.exec(); -} diff --git a/examples/charts/charts.pro b/examples/charts/charts.pro index bac912e5..f6cee434 100644 --- a/examples/charts/charts.pro +++ b/examples/charts/charts.pro @@ -2,94 +2,30 @@ include($$OUT_PWD/../../src/charts/qtcharts-config.pri) QT_FOR_CONFIG += charts TEMPLATE = subdirs -qtConfig(charts-area-chart) { - SUBDIRS += areachart -} qtConfig(charts-line-chart) { - SUBDIRS += \ - callout \ - chartinteractions \ - customchart \ - linechart \ - lineandbar \ - legendmarkers \ - logvalueaxis \ - modeldata \ - zoomlinechart -} -qtConfig(charts-spline-chart) { - SUBDIRS += \ - dynamicspline \ - multiaxis \ - splinechart \ - pointsselectionandmarkers - qtConfig(charts-area-chart) { - SUBDIRS += \ - chartthemes \ - polarchart - } -} -qtConfig(charts-bar-chart) { - SUBDIRS += \ - barchart \ - barmodelmapper \ - horizontalbarchart \ - horizontalpercentbarchart \ - horizontalstackedbarchart \ - stackedbarchart \ - stackedbarchartdrilldown \ - percentbarchart \ - legend \ - temperaturerecords \ - selectedbar -} -qtConfig(charts-pie-chart) { - SUBDIRS += \ - donutchart \ - donutbreakdown \ - nesteddonuts \ - piechart \ - piechartcustomization \ - piechartdrilldown - qtHaveModule(quick): SUBDIRS += qmlpiechart -} -qtConfig(charts-boxplot-chart) { - SUBDIRS += boxplotchart - qtHaveModule(quick): SUBDIRS += qmlboxplot -} -qtConfig(charts-candlestick-chart) { - SUBDIRS += candlestickchart - qtHaveModule(quick): SUBDIRS += qmlcandlestick -} -qtConfig(charts-scatter-chart) { - SUBDIRS += \ - scatterchart \ - scatterinteractions + SUBDIRS += zoomlinechart } -qtHaveModule(quick) { - SUBDIRS += \ - qmlchart \ - qmlcustomizations \ - qmlcustomlegend \ - qmlf1legends \ - qmloscilloscope \ - qmlweather +qtHaveModule(quick):qtConfig(charts-line-chart) { + qtConfig(charts-scatter-chart): SUBDIRS += qmloscilloscope + qtConfig(charts-bar-chart): SUBDIRS += qmlweather } qtHaveModule(multimedia) { - # SUBDIRS += audio // QTBUG-94181 + qtConfig(charts-line-chart): SUBDIRS += audio } else { message("QtMultimedia library not available. Some examples are disabled.") } qtConfig(opengl) { - SUBDIRS += openglseries + qtConfig(charts-line-chart): SUBDIRS += openglseries } else { message("OpenGL not available. Some examples are disabled.") } -qtConfig(charts-datetime-axis) { - SUBDIRS += datetimeaxis - qtHaveModule(quick): SUBDIRS += qmlaxes qmlpolarchart +qtConfig(charts-line-chart):qtConfig(charts-spline-chart):qtConfig(charts-bar-chart): + qtConfig(charts-pie-chart):qtConfig(charts-boxplot-chart):qtConfig(charts-candlestick-chart): + qtConfig(charts-scatter-chart):qtConfig(charts-datetime-axis) { + SUBDIRS += gallery + qtHaveModule(quick): SUBDIRS += qmlgallery } diff --git a/examples/charts/chartthemes/CMakeLists.txt b/examples/charts/chartthemes/CMakeLists.txt deleted file mode 100644 index 56b6a542..00000000 --- a/examples/charts/chartthemes/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(chartthemes LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/chartthemes") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(chartthemes - main.cpp - themewidget.cpp themewidget.h themewidget.ui -) - -set_target_properties(chartthemes PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(chartthemes PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS chartthemes - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/chartthemes/chartthemes.pro b/examples/charts/chartthemes/chartthemes.pro deleted file mode 100644 index 5def152f..00000000 --- a/examples/charts/chartthemes/chartthemes.pro +++ /dev/null @@ -1,15 +0,0 @@ -QT += charts -requires(qtConfig(combobox)) - -HEADERS += \ - themewidget.h - -SOURCES += \ - main.cpp \ - themewidget.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/chartthemes -INSTALLS += target - -FORMS += \ - themewidget.ui diff --git a/examples/charts/chartthemes/main.cpp b/examples/charts/chartthemes/main.cpp deleted file mode 100644 index f43522b1..00000000 --- a/examples/charts/chartthemes/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "themewidget.h" -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - QMainWindow window; - ThemeWidget *widget = new ThemeWidget(); - window.setCentralWidget(widget); - window.resize(900, 600); - window.show(); - return a.exec(); -} - diff --git a/examples/charts/customchart/CMakeLists.txt b/examples/charts/customchart/CMakeLists.txt deleted file mode 100644 index bf994270..00000000 --- a/examples/charts/customchart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(customchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/customchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(customchart - main.cpp -) - -set_target_properties(customchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(customchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS customchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/customchart/customchart.pro b/examples/charts/customchart/customchart.pro deleted file mode 100644 index e82b94ae..00000000 --- a/examples/charts/customchart/customchart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/customchart -INSTALLS += target diff --git a/examples/charts/datetimeaxis/CMakeLists.txt b/examples/charts/datetimeaxis/CMakeLists.txt deleted file mode 100644 index a9943119..00000000 --- a/examples/charts/datetimeaxis/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(datetimeaxis LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/datetimeaxis") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(datetimeaxis - main.cpp -) - -set_target_properties(datetimeaxis PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(datetimeaxis PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -# Resources: -set_source_files_properties("sun_spots.txt" - PROPERTIES QT_RESOURCE_ALIAS "sun" -) - -set(sundata_resource_files - "sun_spots.txt" -) - -qt6_add_resources(datetimeaxis "sundata" - PREFIX - "/" - FILES - ${sundata_resource_files} -) - -install(TARGETS datetimeaxis - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/datetimeaxis/datetimeaxis.pro b/examples/charts/datetimeaxis/datetimeaxis.pro deleted file mode 100644 index 09869b05..00000000 --- a/examples/charts/datetimeaxis/datetimeaxis.pro +++ /dev/null @@ -1,10 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -RESOURCES += \ - sundata.qrc - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/datetimeaxis -INSTALLS += target diff --git a/examples/charts/datetimeaxis/sundata.qrc b/examples/charts/datetimeaxis/sundata.qrc deleted file mode 100644 index 318be590..00000000 --- a/examples/charts/datetimeaxis/sundata.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file alias="sun">sun_spots.txt</file> - </qresource> -</RCC> diff --git a/examples/charts/donutbreakdown/CMakeLists.txt b/examples/charts/donutbreakdown/CMakeLists.txt deleted file mode 100644 index 74e616d7..00000000 --- a/examples/charts/donutbreakdown/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(donutbreakdown LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/donutbreakdown") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(donutbreakdown - donutbreakdownchart.cpp donutbreakdownchart.h - main.cpp - mainslice.cpp mainslice.h -) - -set_target_properties(donutbreakdown PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(donutbreakdown PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS donutbreakdown - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/donutbreakdown/donutbreakdown.pro b/examples/charts/donutbreakdown/donutbreakdown.pro deleted file mode 100644 index 85ef9d3a..00000000 --- a/examples/charts/donutbreakdown/donutbreakdown.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts - -HEADERS += \ - donutbreakdownchart.h \ - mainslice.h - -SOURCES += \ - donutbreakdownchart.cpp \ - main.cpp \ - mainslice.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/donutbreakdown -INSTALLS += target diff --git a/examples/charts/donutbreakdown/mainslice.cpp b/examples/charts/donutbreakdown/mainslice.cpp deleted file mode 100644 index 3b602ace..00000000 --- a/examples/charts/donutbreakdown/mainslice.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "mainslice.h" - -QT_USE_NAMESPACE - -//![1] -MainSlice::MainSlice(QPieSeries *breakdownSeries, QObject *parent) - : QPieSlice(parent), - m_breakdownSeries(breakdownSeries) -{ - connect(this, &MainSlice::percentageChanged, this, &MainSlice::updateLabel); -} -//![1] - -QPieSeries *MainSlice::breakdownSeries() const -{ - return m_breakdownSeries; -} - -void MainSlice::setName(QString name) -{ - m_name = name; -} - -QString MainSlice::name() const -{ - return m_name; -} - -//![2] -void MainSlice::updateLabel() -{ - this->setLabel(QString("%1 %2%").arg(m_name).arg(percentage() * 100, 0, 'f', 2)); -} -//![2] - -#include "moc_mainslice.cpp" - diff --git a/examples/charts/donutbreakdown/mainslice.h b/examples/charts/donutbreakdown/mainslice.h deleted file mode 100644 index aef75cca..00000000 --- a/examples/charts/donutbreakdown/mainslice.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef MAINSLICE_H -#define MAINSLICE_H - -#include <QtCharts/QPieSlice> -#include <QtCharts/QPieSeries> - -QT_USE_NAMESPACE - -class MainSlice : public QPieSlice -{ - Q_OBJECT -public: - MainSlice(QPieSeries *breakdownSeries, QObject *parent = 0); - - QPieSeries *breakdownSeries() const; - - void setName(QString name); - QString name() const; - -public Q_SLOTS: - void updateLabel(); - -private: - QPieSeries *m_breakdownSeries; - QString m_name; -}; - -#endif // MAINSLICE_H diff --git a/examples/charts/donutchart/CMakeLists.txt b/examples/charts/donutchart/CMakeLists.txt deleted file mode 100644 index 41aa70f1..00000000 --- a/examples/charts/donutchart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(donutchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/donutchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(donutchart - main.cpp -) - -set_target_properties(donutchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(donutchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS donutchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/donutchart/donutchart.pro b/examples/charts/donutchart/donutchart.pro deleted file mode 100644 index 71017d12..00000000 --- a/examples/charts/donutchart/donutchart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/donutchart -INSTALLS += target diff --git a/examples/charts/donutchart/main.cpp b/examples/charts/donutchart/main.cpp deleted file mode 100644 index e1bfe232..00000000 --- a/examples/charts/donutchart/main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QPieSeries> -#include <QtCharts/QPieSlice> -#include <QtCore/QDebug> -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QPieSeries *series = new QPieSeries(); - series->setHoleSize(0.35); - series->append("Protein 4.2%", 4.2); - QPieSlice *slice = series->append("Fat 15.6%", 15.6); - slice->setExploded(); - slice->setLabelVisible(); - series->append("Other 23.8%", 23.8); - series->append("Carbs 56.4%", 56.4); -//![1] - -//![2] - QChartView *chartView = new QChartView(); - chartView->setRenderHint(QPainter::Antialiasing); - chartView->chart()->setTitle("Donut with a lemon glaze (100g)"); - chartView->chart()->addSeries(series); - chartView->chart()->legend()->setAlignment(Qt::AlignBottom); - chartView->chart()->setTheme(QChart::ChartThemeBlueCerulean); - chartView->chart()->legend()->setFont(QFont("Arial", 7)); -//![2] - -//![3] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); -//![3] - - return a.exec(); -} diff --git a/examples/charts/dynamicspline/CMakeLists.txt b/examples/charts/dynamicspline/CMakeLists.txt deleted file mode 100644 index 19ac27c0..00000000 --- a/examples/charts/dynamicspline/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(dynamicspline LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/dynamicspline") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(dynamicspline - chart.cpp chart.h - main.cpp -) - -set_target_properties(dynamicspline PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(dynamicspline PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS dynamicspline - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/dynamicspline/chart.cpp b/examples/charts/dynamicspline/chart.cpp deleted file mode 100644 index ebd26bb4..00000000 --- a/examples/charts/dynamicspline/chart.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "chart.h" -#include <QtCharts/QAbstractAxis> -#include <QtCharts/QSplineSeries> -#include <QtCharts/QValueAxis> -#include <QtCore/QRandomGenerator> -#include <QtCore/QDebug> - -Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags): - QChart(QChart::ChartTypeCartesian, parent, wFlags), - m_series(0), - m_axisX(new QValueAxis()), - m_axisY(new QValueAxis()), - m_step(0), - m_x(5), - m_y(1) -{ - QObject::connect(&m_timer, &QTimer::timeout, this, &Chart::handleTimeout); - m_timer.setInterval(1000); - - m_series = new QSplineSeries(this); - QPen green(Qt::red); - green.setWidth(3); - m_series->setPen(green); - m_series->append(m_x, m_y); - - addSeries(m_series); - - addAxis(m_axisX,Qt::AlignBottom); - addAxis(m_axisY,Qt::AlignLeft); - m_series->attachAxis(m_axisX); - m_series->attachAxis(m_axisY); - m_axisX->setTickCount(5); - m_axisX->setRange(0, 10); - m_axisY->setRange(-5, 10); - - m_timer.start(); -} - -Chart::~Chart() -{ - -} - -void Chart::handleTimeout() -{ - qreal x = plotArea().width() / m_axisX->tickCount(); - qreal y = (m_axisX->max() - m_axisX->min()) / m_axisX->tickCount(); - m_x += y; - m_y = QRandomGenerator::global()->bounded(5) - 2.5; - m_series->append(m_x, m_y); - scroll(x, 0); - if (m_x == 100) - m_timer.stop(); -} diff --git a/examples/charts/dynamicspline/chart.h b/examples/charts/dynamicspline/chart.h deleted file mode 100644 index e5577dd3..00000000 --- a/examples/charts/dynamicspline/chart.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef CHART_H -#define CHART_H - -#include <QtCharts/QChart> -#include <QtCore/QTimer> - -QT_BEGIN_NAMESPACE -class QSplineSeries; -class QValueAxis; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -//![1] -class Chart: public QChart -{ - Q_OBJECT -public: - Chart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {}); - virtual ~Chart(); - -public slots: - void handleTimeout(); - -private: - QTimer m_timer; - QSplineSeries *m_series; - QStringList m_titles; - QValueAxis *m_axisX; - QValueAxis *m_axisY; - qreal m_step; - qreal m_x; - qreal m_y; -}; -//![1] - -#endif /* CHART_H */ diff --git a/examples/charts/dynamicspline/dynamicspline.pro b/examples/charts/dynamicspline/dynamicspline.pro deleted file mode 100644 index 1aedeca4..00000000 --- a/examples/charts/dynamicspline/dynamicspline.pro +++ /dev/null @@ -1,11 +0,0 @@ -QT += charts - -HEADERS += \ - chart.h - -SOURCES += \ - chart.cpp \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/dynamicspline -INSTALLS += target diff --git a/examples/charts/dynamicspline/main.cpp b/examples/charts/dynamicspline/main.cpp deleted file mode 100644 index 3da9b280..00000000 --- a/examples/charts/dynamicspline/main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "chart.h" -#include <QtCharts/QChartView> -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - QMainWindow window; - Chart *chart = new Chart; - chart->setTitle("Dynamic spline chart"); - chart->legend()->hide(); - chart->setAnimationOptions(QChart::AllAnimations); - QChartView chartView(chart); - chartView.setRenderHint(QPainter::Antialiasing); - window.setCentralWidget(&chartView); - window.resize(400, 300); - window.show(); - return a.exec(); -} diff --git a/examples/charts/gallery/CMakeLists.txt b/examples/charts/gallery/CMakeLists.txt new file mode 100644 index 00000000..69e524d5 --- /dev/null +++ b/examples/charts/gallery/CMakeLists.txt @@ -0,0 +1,135 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(gallery LANGUAGES CXX) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/gallery") + +find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Widgets) + +qt_standard_project_setup() + +qt_add_executable(gallery + areawidget.cpp areawidget.h + barmodelmappermodel.cpp barmodelmappermodel.h + barmodelmapperwidget.cpp barmodelmapperwidget.h + boxplotdatareader.cpp boxplotdatareader.h + boxplotwidget.cpp boxplotwidget.h + barwidget.cpp barwidget.h + barpercentwidget.cpp barpercentwidget.h + barstackedwidget.cpp barstackedwidget.h + callout.cpp callout.h + calloutwidget.cpp calloutwidget.h + calloutview.cpp calloutview.h + candlestickwidget.cpp candlestickwidget.h + candlestickdatareader.cpp candlestickdatareader.h + contentwidget.cpp contentwidget.h + customchartwidget.cpp customchartwidget.h + datetimeaxiswidget.cpp datetimeaxiswidget.h + donutbreakdownchart.cpp donutbreakdownchart.h + donutbreakdownmainslice.cpp donutbreakdownmainslice.h + donutbreakdownwidget.cpp donutbreakdownwidget.h + donutwidget.cpp donutwidget.h + dynamicsplinewidget.cpp dynamicsplinewidget.h + horizontalbarwidget.cpp horizontalbarwidget.h + horizontalpercentbarwidget.cpp horizontalpercentbarwidget.h + horizontalstackedbarwidget.cpp horizontalstackedbarwidget.h + interactionswidget.cpp interactionswidget.h + interactionsview.cpp interactionsview.h + interactionschart.cpp interactionschart.h + legendwidget.cpp legendwidget.h + legendmarkerswidget.cpp legendmarkerswidget.h + lightmarkerswidget.cpp lightmarkerswidget.h + lineandbarwidget.cpp lineandbarwidget.h + linewidget.cpp linewidget.h + logaxiswidget.cpp logaxiswidget.h + modeldatamodel.cpp modeldatamodel.h + modeldatawidget.cpp modeldatawidget.h + multiaxiswidget.cpp multiaxiswidget.h + nesteddonutswidget.cpp nesteddonutswidget.h + main.cpp + mainwidget.cpp mainwidget.h + pccpentool.cpp pccpentool.h + pccbrushtool.cpp pccbrushtool.h + pcccustomslice.cpp pcccustomslice.h + pccwidget.cpp pccwidget.h + piedrilldownchart.cpp piedrilldownchart.h + piedrilldownslice.cpp piedrilldownslice.h + piedrilldownwidget.cpp piedrilldownwidget.h + piewidget.cpp piewidget.h + pointconfigurationwidget.cpp pointconfigurationwidget.h + polarchartview.cpp polarchartview.h + polarchartwidget.cpp polarchartwidget.h + scatterinteractionswidget.cpp scatterinteractionswidget.h + scatterwidget.cpp scatterwidget.h + selectedbarwidget.cpp selectedbarwidget.h + splinewidget.cpp splinewidget.h + stackeddrilldownchart.cpp stackeddrilldownchart.h + stackeddrilldownseries.cpp stackeddrilldownseries.h + stackeddrilldownwidget.cpp stackeddrilldownwidget.h + temperaturerecordswidget.cpp temperaturerecordswidget.h + themewidget.cpp themewidget.h themewidget.ui +) + +set_target_properties(gallery PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(gallery PRIVATE + Qt::Charts + Qt::Core + Qt::Gui + Qt::Widgets +) + +set_source_files_properties("data/boxplot_a.txt" + PROPERTIES QT_RESOURCE_ALIAS "boxplot_a" +) + +set_source_files_properties("data/boxplot_b.txt" + PROPERTIES QT_RESOURCE_ALIAS "boxplot_b" +) + +set_source_files_properties("data/candlestick.txt" + PROPERTIES QT_RESOURCE_ALIAS "candlestick" +) + +set_source_files_properties("data/sun_spots.txt" + PROPERTIES QT_RESOURCE_ALIAS "sun_spots" +) + +set_source_files_properties("data/blue_triangle.png" + PROPERTIES QT_RESOURCE_ALIAS "blue_triangle" +) + +set_source_files_properties("data/green_triangle.png" + PROPERTIES QT_RESOURCE_ALIAS "green_triangle" +) + +set(gallery_resource_files + "data/boxplot_a.txt" + "data/boxplot_b.txt" + "data/candlestick.txt" + "data/sun_spots.txt" + "data/blue_triangle.png" + "data/green_triangle.png" +) + +qt6_add_resources(gallery "gallery" + PREFIX + "/" + FILES + ${gallery_resource_files} +) + +install(TARGETS gallery + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/examples/charts/areachart/main.cpp b/examples/charts/gallery/areawidget.cpp index a99bcfdd..a16ef53d 100644 --- a/examples/charts/areachart/main.cpp +++ b/examples/charts/gallery/areawidget.cpp @@ -1,32 +1,29 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCharts/QAreaSeries> +#include "areawidget.h" -QT_USE_NAMESPACE +#include <QAreaSeries> +#include <QChart> +#include <QLineSeries> -int main(int argc, char *argv[]) +AreaWidget::AreaWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); + //![1] + auto series0 = new QLineSeries; + auto series1 = new QLineSeries; + //![1] -//![1] - QLineSeries *series0 = new QLineSeries(); - QLineSeries *series1 = new QLineSeries(); -//![1] - -//![2] + //![2] *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6) << QPointF(16, 7) << QPointF(18, 5); *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3) << QPointF(16, 4) << QPointF(18, 3); -//![2] + //![2] -//![3] - QAreaSeries *series = new QAreaSeries(series0, series1); + //![3] + auto series = new QAreaSeries(series0, series1); series->setName("Batman"); QPen pen(0x059605); pen.setWidth(3); @@ -37,28 +34,18 @@ int main(int argc, char *argv[]) gradient.setColorAt(1.0, 0x26f626); gradient.setCoordinateMode(QGradient::ObjectBoundingMode); series->setBrush(gradient); -//![3] + //![3] -//![4] - QChart *chart = new QChart(); + //![4] + auto chart = new QChart; chart->addSeries(series); - chart->setTitle("Simple areachart example"); + chart->setTitle("Simple Area Chart"); chart->createDefaultAxes(); chart->axes(Qt::Horizontal).first()->setRange(0, 20); chart->axes(Qt::Vertical).first()->setRange(0, 10); -//![4] - -//![5] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![5] - -//![6] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); -//![6] + //![4] - return a.exec(); + //![5] + createDefaultChartView(chart); + //![5] } diff --git a/examples/charts/gallery/areawidget.h b/examples/charts/gallery/areawidget.h new file mode 100644 index 00000000..201659c9 --- /dev/null +++ b/examples/charts/gallery/areawidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef AREAWIDGET_H +#define AREAWIDGET_H + +#include "contentwidget.h" + +class AreaWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit AreaWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/barmodelmapper/customtablemodel.cpp b/examples/charts/gallery/barmodelmappermodel.cpp index 1114063b..294d85fe 100644 --- a/examples/charts/barmodelmapper/customtablemodel.cpp +++ b/examples/charts/gallery/barmodelmappermodel.cpp @@ -1,22 +1,21 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "customtablemodel.h" -#include <QtCore/QList> -#include <QtCore/QTime> -#include <QtCore/QRect> -#include <QtCore/QRandomGenerator> -#include <QtGui/QColor> +#include "barmodelmappermodel.h" -CustomTableModel::CustomTableModel(QObject *parent) : +#include <QColor> +#include <QList> +#include <QRandomGenerator> +#include <QRect> + +BarModelMapperModel::BarModelMapperModel(QObject *parent) : QAbstractTableModel(parent) { m_columnCount = 6; m_rowCount = 12; - // m_data for (int i = 0; i < m_rowCount; i++) { - QList<qreal> *dataList = new QList<qreal>(m_columnCount); + auto dataList = new QList<qreal>(m_columnCount); for (int k = 0; k < dataList->size(); k++) { if (k % 2 == 0) dataList->replace(k, i * 50 + QRandomGenerator::global()->bounded(20)); @@ -27,24 +26,24 @@ CustomTableModel::CustomTableModel(QObject *parent) : } } -CustomTableModel::~CustomTableModel() +BarModelMapperModel::~BarModelMapperModel() { qDeleteAll(m_data); } -int CustomTableModel::rowCount(const QModelIndex &parent) const +int BarModelMapperModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return m_data.count(); } -int CustomTableModel::columnCount(const QModelIndex &parent) const +int BarModelMapperModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return m_columnCount; } -QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant BarModelMapperModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) return QVariant(); @@ -55,7 +54,7 @@ QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, return QString("%1").arg(section + 1); } -QVariant CustomTableModel::data(const QModelIndex &index, int role) const +QVariant BarModelMapperModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { return m_data[index.row()]->at(index.column()); @@ -73,7 +72,7 @@ QVariant CustomTableModel::data(const QModelIndex &index, int role) const return QVariant(); } -bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role) +bool BarModelMapperModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { m_data[index.row()]->replace(index.column(), value.toDouble()); @@ -83,12 +82,12 @@ bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, return false; } -Qt::ItemFlags CustomTableModel::flags(const QModelIndex &index) const +Qt::ItemFlags BarModelMapperModel::flags(const QModelIndex &index) const { return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } -void CustomTableModel::addMapping(QString color, QRect area) +void BarModelMapperModel::addMapping(QString color, QRect area) { m_mapping.insert(color, area); } diff --git a/examples/charts/modeldata/customtablemodel.h b/examples/charts/gallery/barmodelmappermodel.h index de63bb5a..84d4664e 100644 --- a/examples/charts/modeldata/customtablemodel.h +++ b/examples/charts/gallery/barmodelmappermodel.h @@ -1,18 +1,19 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef CUSTOMTABLEMODEL_H -#define CUSTOMTABLEMODEL_H +#ifndef BARMODELMAPPERMODEL_H +#define BARMODELMAPPERMODEL_H -#include <QtCore/QAbstractTableModel> -#include <QtCore/QMultiHash> -#include <QtCore/QRect> +#include <QAbstractTableModel> +#include <QMultiHash> +#include <QRect> -class CustomTableModel : public QAbstractTableModel +class BarModelMapperModel : public QAbstractTableModel { Q_OBJECT public: - explicit CustomTableModel(QObject *parent = 0); + explicit BarModelMapperModel(QObject *parent = nullptr); + virtual ~BarModelMapperModel(); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -31,4 +32,4 @@ private: int m_rowCount; }; -#endif // CUSTOMTABLEMODEL_H +#endif diff --git a/examples/charts/barmodelmapper/tablewidget.cpp b/examples/charts/gallery/barmodelmapperwidget.cpp index 78006611..1d73fe17 100644 --- a/examples/charts/barmodelmapper/tablewidget.cpp +++ b/examples/charts/gallery/barmodelmapperwidget.cpp @@ -1,59 +1,61 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "tablewidget.h" -#include <QtWidgets/QGridLayout> -#include <QtWidgets/QTableView> -#include <QtCharts/QChart> -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCharts/QVXYModelMapper> -#include <QtCharts/QBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QVBarModelMapper> -#include <QtWidgets/QHeaderView> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QValueAxis> +#include "barmodelmappermodel.h" +#include "barmodelmapperwidget.h" -QT_USE_NAMESPACE +#include <QBarCategoryAxis> +#include <QBarSeries> +#include <QBarSet> +#include <QChart> +#include <QChartView> +#include <QGraphicsLayout> +#include <QGridLayout> +#include <QHeaderView> +#include <QLineSeries> +#include <QTableView> +#include <QValueAxis> +#include <QVBarModelMapper> +#include <QVXYModelMapper> -TableWidget::TableWidget(QWidget *parent) - : QWidget(parent) +BarModelMapperWidget::BarModelMapperWidget(QWidget *parent) + : ContentWidget(parent) { - // create simple model for storing data - // user's table data model + // create simple model for storing user's data //! [1] - m_model = new CustomTableModel; + auto model = new BarModelMapperModel(this); //! [1] //! [2] // create table view and add model to it - QTableView *tableView = new QTableView; - tableView->setModel(m_model); + auto tableView = new QTableView(this); + tableView->setModel(model); tableView->setMinimumWidth(300); tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); - m_model->setParent(tableView); + model->setParent(tableView); //! [2] //! [3] - QChart *chart = new QChart; + auto chart = new QChart; chart->setAnimationOptions(QChart::AllAnimations); //! [3] + chart->layout()->setContentsMargins(0, 0, 0, 0); + // series 1 //! [4] - QBarSeries *series = new QBarSeries; + auto series = new QBarSeries; int first = 3; int count = 5; - QVBarModelMapper *mapper = new QVBarModelMapper(this); + auto mapper = new QVBarModelMapper(this); mapper->setFirstBarSetColumn(1); mapper->setLastBarSetColumn(4); mapper->setFirstRow(first); mapper->setRowCount(count); mapper->setSeries(series); - mapper->setModel(m_model); + mapper->setModel(model); chart->addSeries(series); //! [4] @@ -65,31 +67,30 @@ TableWidget::TableWidget(QWidget *parent) QList<QBarSet *> barsets = series->barSets(); for (int i = 0; i < barsets.count(); i++) { seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); - m_model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); + model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count())); } //! [5] //! [6] - QStringList categories; - categories << "April" << "May" << "June" << "July" << "August"; - QBarCategoryAxis *axisX = new QBarCategoryAxis(); + QStringList categories {"April", "May", "June", "July", "August"}; + auto axisX = new QBarCategoryAxis; axisX->append(categories); chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); - QValueAxis *axisY = new QValueAxis(); + auto axisY = new QValueAxis; chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisY); //! [6] //! [7] - QChartView *chartView = new QChartView(chart); + auto chartView = new QChartView(chart, this); chartView->setRenderHint(QPainter::Antialiasing); - chartView->setMinimumSize(640, 480); //! [7] //! [8] // create main layout - QGridLayout *mainLayout = new QGridLayout; + auto mainLayout = new QGridLayout; + mainLayout->setHorizontalSpacing(10); mainLayout->addWidget(tableView, 1, 0); mainLayout->addWidget(chartView, 1, 1); mainLayout->setColumnStretch(1, 1); diff --git a/examples/charts/gallery/barmodelmapperwidget.h b/examples/charts/gallery/barmodelmapperwidget.h new file mode 100644 index 00000000..17b4eb58 --- /dev/null +++ b/examples/charts/gallery/barmodelmapperwidget.h @@ -0,0 +1,18 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef BARMODELMAPPERWIDGET_H +#define BARMODELMAPPERWIDGET_H + +#include "contentwidget.h" + +QT_FORWARD_DECLARE_CLASS(QChartView) + +class BarModelMapperWidget : public ContentWidget +{ + Q_OBJECT +public: + BarModelMapperWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/barpercentwidget.cpp b/examples/charts/gallery/barpercentwidget.cpp new file mode 100644 index 00000000..d9f2fcb1 --- /dev/null +++ b/examples/charts/gallery/barpercentwidget.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "barpercentwidget.h" + +#include <QBarCategoryAxis> +#include <QBarSet> +#include <QChart> +#include <QLegend> +#include <QPercentBarSeries> +#include <QValueAxis> + +BarPercentWidget::BarPercentWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto set0 = new QBarSet("Jane"); + auto set1 = new QBarSet("John"); + auto set2 = new QBarSet("Axel"); + auto set3 = new QBarSet("Mary"); + auto set4 = new QBarSet("Samantha"); + + *set0 << 1 << 2 << 3 << 4 << 5 << 6; + *set1 << 5 << 0 << 0 << 4 << 0 << 7; + *set2 << 3 << 5 << 8 << 13 << 8 << 5; + *set3 << 5 << 6 << 7 << 3 << 4 << 5; + *set4 << 9 << 7 << 5 << 3 << 1 << 2; + //![1] + + //![2] + auto series = new QPercentBarSeries; + series->append(set0); + series->append(set1); + series->append(set2); + series->append(set3); + series->append(set4); + //![2] + + //![3] + auto chart = new QChart; + chart->addSeries(series); + chart->setTitle("Simple Percent Bar Chart"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //![3] + + //![4] + QStringList categories {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}; + auto axisX = new QBarCategoryAxis; + axisX->append(categories); + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + auto axisY = new QValueAxis; + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisY); + //![4] + + //![5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //![5] + + //![6] + createDefaultChartView(chart); + //![6] +} diff --git a/examples/charts/gallery/barpercentwidget.h b/examples/charts/gallery/barpercentwidget.h new file mode 100644 index 00000000..4372f278 --- /dev/null +++ b/examples/charts/gallery/barpercentwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef BARPERCENTWIDGET_H +#define BARPERCENTWIDGET_H + +#include "contentwidget.h" + +class BarPercentWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit BarPercentWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/barstackedwidget.cpp b/examples/charts/gallery/barstackedwidget.cpp new file mode 100644 index 00000000..6dc377e1 --- /dev/null +++ b/examples/charts/gallery/barstackedwidget.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "barstackedwidget.h" + +#include <QBarCategoryAxis> +#include <QBarSet> +#include <QChart> +#include <QLegend> +#include <QStackedBarSeries> +#include <QValueAxis> + +BarStackedWidget::BarStackedWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto set0 = new QBarSet("Jane"); + auto set1 = new QBarSet("John"); + auto set2 = new QBarSet("Axel"); + auto set3 = new QBarSet("Mary"); + auto set4 = new QBarSet("Samantha"); + + *set0 << 1 << 2 << 3 << 4 << 5 << 6; + *set1 << 5 << 0 << 0 << 4 << 0 << 7; + *set2 << 3 << 5 << 8 << 13 << 8 << 5; + *set3 << 5 << 6 << 7 << 3 << 4 << 5; + *set4 << 9 << 7 << 5 << 3 << 1 << 2; + //![1] + + //![2] + auto series = new QStackedBarSeries; + series->append(set0); + series->append(set1); + series->append(set2); + series->append(set3); + series->append(set4); + //![2] + + //![3] + auto chart = new QChart; + chart->addSeries(series); + chart->setTitle("Simple Stacked Bar Chart"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //![3] + + //![4] + QStringList categories {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}; + auto axisX = new QBarCategoryAxis; + axisX->append(categories); + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + auto axisY = new QValueAxis; + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisY); + //![4] + + //![5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //![5] + + //![6] + createDefaultChartView(chart); + //![6] +} diff --git a/examples/charts/gallery/barstackedwidget.h b/examples/charts/gallery/barstackedwidget.h new file mode 100644 index 00000000..c40941c1 --- /dev/null +++ b/examples/charts/gallery/barstackedwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef BARSTACKEDWIDGET_H +#define BARSTACKEDWIDGET_H + +#include "contentwidget.h" + +class BarStackedWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit BarStackedWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/barwidget.cpp b/examples/charts/gallery/barwidget.cpp new file mode 100644 index 00000000..78430cd1 --- /dev/null +++ b/examples/charts/gallery/barwidget.cpp @@ -0,0 +1,67 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "barwidget.h" + +#include <QBarCategoryAxis> +#include <QBarSeries> +#include <QBarSet> +#include <QChart> +#include <QLegend> +#include <QValueAxis> + +BarWidget::BarWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto set0 = new QBarSet("Jane"); + auto set1 = new QBarSet("John"); + auto set2 = new QBarSet("Axel"); + auto set3 = new QBarSet("Mary"); + auto set4 = new QBarSet("Samantha"); + + *set0 << 1 << 2 << 3 << 4 << 5 << 6; + *set1 << 5 << 0 << 0 << 4 << 0 << 7; + *set2 << 3 << 5 << 8 << 13 << 8 << 5; + *set3 << 5 << 6 << 7 << 3 << 4 << 5; + *set4 << 9 << 7 << 5 << 3 << 1 << 2; + //![1] + + //![2] + QBarSeries *series = new QBarSeries; + series->append(set0); + series->append(set1); + series->append(set2); + series->append(set3); + series->append(set4); + //![2] + + //![3] + auto chart = new QChart; + chart->addSeries(series); + chart->setTitle("Simple Bar Chart"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //![3] + + //![4] + QStringList categories {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}; + auto axisX = new QBarCategoryAxis; + axisX->append(categories); + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + + auto axisY = new QValueAxis; + axisY->setRange(0,15); + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisY); + //![4] + + //![5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //![5] + + //![6] + createDefaultChartView(chart); + //![6] +} diff --git a/examples/charts/gallery/barwidget.h b/examples/charts/gallery/barwidget.h new file mode 100644 index 00000000..0de1785b --- /dev/null +++ b/examples/charts/gallery/barwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef BARWIDGET_H +#define BARWIDGET_H + +#include "contentwidget.h" + +class BarWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit BarWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/boxplotdatareader.cpp b/examples/charts/gallery/boxplotdatareader.cpp new file mode 100644 index 00000000..47172704 --- /dev/null +++ b/examples/charts/gallery/boxplotdatareader.cpp @@ -0,0 +1,71 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "boxplotdatareader.h" + +#include <QBoxSet> + +#include <algorithm> + +BoxPlotDataReader::BoxPlotDataReader(QIODevice *device) + : m_textStream(device) +{ +} + +void BoxPlotDataReader::readFile(QIODevice *device) +{ + m_textStream.setDevice(device); +} + +bool BoxPlotDataReader::atEnd() const +{ + return m_textStream.atEnd(); +} + +QBoxSet *BoxPlotDataReader::readBox() +{ + //! [1] + QString line = m_textStream.readLine(); + if (line.startsWith("#")) + return nullptr; + //! [1] + + //! [2] + QStringList strList = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); + //! [2] + + //! [3] + m_sortedList.clear(); + for (int i = 1; i < strList.count(); i++) + m_sortedList.append(strList.at(i).toDouble()); + + std::sort(m_sortedList.begin(), m_sortedList.end()); + //! [3] + + int count = m_sortedList.count(); + + //! [4] + auto box = new QBoxSet(strList.first()); + box->setValue(QBoxSet::LowerExtreme, m_sortedList.first()); + box->setValue(QBoxSet::UpperExtreme, m_sortedList.last()); + box->setValue(QBoxSet::Median, findMedian(0, count)); + box->setValue(QBoxSet::LowerQuartile, findMedian(0, count / 2)); + box->setValue(QBoxSet::UpperQuartile, findMedian(count / 2 + (count % 2), count)); + //! [4] + + return box; +} + +qreal BoxPlotDataReader::findMedian(int begin, int end) +{ + //! [5] + int count = end - begin; + if (count % 2) { + return m_sortedList.at(count / 2 + begin); + } else { + qreal right = m_sortedList.at(count / 2 + begin); + qreal left = m_sortedList.at(count / 2 - 1 + begin); + return (right + left) / 2.0; + } + //! [5] +} diff --git a/examples/charts/gallery/boxplotdatareader.h b/examples/charts/gallery/boxplotdatareader.h new file mode 100644 index 00000000..253b05ee --- /dev/null +++ b/examples/charts/gallery/boxplotdatareader.h @@ -0,0 +1,29 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef BOXPLOTDATAREADER_H +#define BOXPLOTDATAREADER_H + +#include <QList> +#include <QTextStream> + +QT_FORWARD_DECLARE_CLASS(QBoxSet) + +class BoxPlotDataReader +{ +public: + explicit BoxPlotDataReader(QIODevice *device); + + QBoxSet *readBox(); + void readFile(QIODevice *device); + bool atEnd() const; + +protected: + qreal findMedian(int begin, int end); + +private: + QList<qreal> m_sortedList; + QTextStream m_textStream; +}; + +#endif diff --git a/examples/charts/gallery/boxplotwidget.cpp b/examples/charts/gallery/boxplotwidget.cpp new file mode 100644 index 00000000..c2ca2936 --- /dev/null +++ b/examples/charts/gallery/boxplotwidget.cpp @@ -0,0 +1,84 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "boxplotdatareader.h" +#include "boxplotwidget.h" + +#include <QBarCategoryAxis> +#include <QBoxPlotSeries> +#include <QBoxSet> +#include <QChart> +#include <QFile> +#include <QLegend> + +BoxPlotWidget::BoxPlotWidget(QWidget *parent) + : ContentWidget(parent) +{ +} + +bool BoxPlotWidget::doLoad() +{ + //! [1] + auto acmeSeries = new QBoxPlotSeries; + acmeSeries->setName("Acme Ltd"); + + auto boxWhiskSeries = new QBoxPlotSeries; + boxWhiskSeries->setName("BoxWhisk Inc"); + //! [1] + + //! [2] + QFile acmeData(":boxplot_a"); + const QString errorTemplate = QStringLiteral("Failed to load '%1' file."); + if (!acmeData.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_loadError = errorTemplate.arg(acmeData.fileName()); + return false; + } + + BoxPlotDataReader dataReader(&acmeData); + while (!dataReader.atEnd()) { + QBoxSet *set = dataReader.readBox(); + if (set) + acmeSeries->append(set); + } + //! [2] + + //! [3] + QFile boxwhiskData(":boxplot_b"); + if (!boxwhiskData.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_loadError = errorTemplate.arg(acmeData.fileName()); + return false; + } + + dataReader.readFile(&boxwhiskData); + while (!dataReader.atEnd()) { + QBoxSet *set = dataReader.readBox(); + if (set) + boxWhiskSeries->append(set); + } + //! [3] + + //! [4] + auto chart = new QChart; + chart->addSeries(acmeSeries); + chart->addSeries(boxWhiskSeries); + chart->setTitle("Acme Ltd. and BoxWhisk Inc. share deviation in 2012"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //! [4] + + //! [5] + chart->createDefaultAxes(); + chart->axes(Qt::Vertical).first()->setMin(15.0); + chart->axes(Qt::Horizontal).first()->setMax(34.0); + //! [5] + + //! [6] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //! [6] + + //! [7] + createDefaultChartView(chart); + //! [7] + + return true; +} diff --git a/examples/charts/gallery/boxplotwidget.h b/examples/charts/gallery/boxplotwidget.h new file mode 100644 index 00000000..b498d438 --- /dev/null +++ b/examples/charts/gallery/boxplotwidget.h @@ -0,0 +1,19 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef BOXPLOTWIDGET_H +#define BOXPLOTWIDGET_H + +#include "contentwidget.h" + +class BoxPlotWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit BoxPlotWidget(QWidget *parent = nullptr); + +protected: + bool doLoad() override; +}; + +#endif diff --git a/examples/charts/callout/callout.cpp b/examples/charts/gallery/callout.cpp index 43cc5f11..2169286c 100644 --- a/examples/charts/callout/callout.cpp +++ b/examples/charts/gallery/callout.cpp @@ -1,16 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "callout.h" -#include <QtGui/QPainter> -#include <QtGui/QFontMetrics> -#include <QtWidgets/QGraphicsSceneMouseEvent> -#include <QtGui/QMouseEvent> -#include <QtCharts/QChart> - -Callout::Callout(QChart *chart): - QGraphicsItem(chart), - m_chart(chart) + +#include <QChart> +#include <QFontMetrics> +#include <QGraphicsSceneMouseEvent> +#include <QMouseEvent> +#include <QPainter> + +Callout::Callout(QChart *chart) + : QGraphicsItem(chart) + , m_chart(chart) { } diff --git a/examples/charts/gallery/callout.h b/examples/charts/gallery/callout.h new file mode 100644 index 00000000..27ef57cb --- /dev/null +++ b/examples/charts/gallery/callout.h @@ -0,0 +1,38 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef CALLOUT_H +#define CALLOUT_H + +#include <QFont> +#include <QGraphicsItem> + +QT_FORWARD_DECLARE_CLASS(QChart) +QT_FORWARD_DECLARE_CLASS(QGraphicsSceneMouseEvent) + +class Callout : public QGraphicsItem +{ +public: + Callout(QChart *parent); + + void setText(const QString &text); + void setAnchor(QPointF point); + void updateGeometry(); + + QRectF boundingRect() const override; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event) override; + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; + +private: + QString m_text; + QRectF m_textRect; + QRectF m_rect; + QPointF m_anchor; + QFont m_font; + QChart *m_chart = nullptr; +}; + +#endif diff --git a/examples/charts/callout/view.cpp b/examples/charts/gallery/calloutview.cpp index 53221141..3ea4ef39 100644 --- a/examples/charts/callout/view.cpp +++ b/examples/charts/gallery/calloutview.cpp @@ -1,33 +1,35 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "view.h" -#include <QtGui/QResizeEvent> -#include <QtWidgets/QGraphicsScene> -#include <QtCharts/QChart> -#include <QtCharts/QLineSeries> -#include <QtCharts/QSplineSeries> -#include <QtWidgets/QGraphicsTextItem> #include "callout.h" -#include <QtGui/QMouseEvent> - -View::View(QWidget *parent) - : QGraphicsView(new QGraphicsScene, parent), - m_coordX(0), - m_coordY(0), - m_chart(0), - m_tooltip(0) +#include "calloutview.h" + +#include <QChart> +#include <QGraphicsLayout> +#include <QGraphicsScene> +#include <QGraphicsTextItem> +#include <QGraphicsView> +#include <QLineSeries> +#include <QMouseEvent> +#include <QSplineSeries> +#include <QResizeEvent> + +CalloutView::CalloutView(QWidget *parent) + : QGraphicsView(new QGraphicsScene, parent) { setDragMode(QGraphicsView::NoDrag); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setFrameShape(QFrame::NoFrame); + setBackgroundRole(QPalette::Window); + setRenderHint(QPainter::Antialiasing); + setMouseTracking(true); - // chart m_chart = new QChart; - m_chart->setMinimumSize(640, 480); - m_chart->setTitle("Hover the line to show callout. Click the line to make it stay"); + m_chart->setTitle("Hover the line to show callout. Click the line to make it stay."); m_chart->legend()->hide(); - QLineSeries *series = new QLineSeries; + + auto series = new QLineSeries; series->append(1, 3); series->append(4, 5); series->append(5, 4.5); @@ -35,7 +37,7 @@ View::View(QWidget *parent) series->append(11, 2); m_chart->addSeries(series); - QSplineSeries *series2 = new QSplineSeries; + auto series2 = new QSplineSeries; series2->append(1.6, 1.4); series2->append(2.4, 3.5); series2->append(3.7, 2.5); @@ -46,55 +48,57 @@ View::View(QWidget *parent) m_chart->createDefaultAxes(); m_chart->setAcceptHoverEvents(true); - setRenderHint(QPainter::Antialiasing); scene()->addItem(m_chart); m_coordX = new QGraphicsSimpleTextItem(m_chart); - m_coordX->setPos(m_chart->size().width()/2 - 50, m_chart->size().height()); m_coordX->setText("X: "); m_coordY = new QGraphicsSimpleTextItem(m_chart); - m_coordY->setPos(m_chart->size().width()/2 + 50, m_chart->size().height()); m_coordY->setText("Y: "); - connect(series, &QLineSeries::clicked, this, &View::keepCallout); - connect(series, &QLineSeries::hovered, this, &View::tooltip); + connect(series, &QLineSeries::clicked, this, &CalloutView::keepCallout); + connect(series, &QLineSeries::hovered, this, &CalloutView::tooltip); - connect(series2, &QSplineSeries::clicked, this, &View::keepCallout); - connect(series2, &QSplineSeries::hovered, this, &View::tooltip); + connect(series2, &QSplineSeries::clicked, this, &CalloutView::keepCallout); + connect(series2, &QSplineSeries::hovered, this, &CalloutView::tooltip); +} - this->setMouseTracking(true); +CalloutView::~CalloutView() +{ + delete scene(); } -void View::resizeEvent(QResizeEvent *event) +void CalloutView::resizeEvent(QResizeEvent *event) { if (scene()) { scene()->setSceneRect(QRect(QPoint(0, 0), event->size())); - m_chart->resize(event->size()); - m_coordX->setPos(m_chart->size().width()/2 - 50, m_chart->size().height() - 20); - m_coordY->setPos(m_chart->size().width()/2 + 50, m_chart->size().height() - 20); - const auto callouts = m_callouts; - for (Callout *callout : callouts) - callout->updateGeometry(); + m_chart->resize(event->size()); + m_coordX->setPos(m_chart->size().width() / 2 - 70, m_chart->size().height() - 24); + m_coordY->setPos(m_chart->size().width() / 2 + 30, m_chart->size().height() - 24); + const auto callouts = m_callouts; + for (Callout *callout : callouts) + callout->updateGeometry(); } - QGraphicsView::resizeEvent(event); + + resize(size()); } -void View::mouseMoveEvent(QMouseEvent *event) +void CalloutView::mouseMoveEvent(QMouseEvent *event) { m_coordX->setText(QString("X: %1").arg(m_chart->mapToValue(event->pos()).x())); m_coordY->setText(QString("Y: %1").arg(m_chart->mapToValue(event->pos()).y())); + QGraphicsView::mouseMoveEvent(event); } -void View::keepCallout() +void CalloutView::keepCallout() { m_callouts.append(m_tooltip); m_tooltip = new Callout(m_chart); } -void View::tooltip(QPointF point, bool state) +void CalloutView::tooltip(QPointF point, bool state) { - if (m_tooltip == 0) + if (!m_tooltip) m_tooltip = new Callout(m_chart); if (state) { diff --git a/examples/charts/gallery/calloutview.h b/examples/charts/gallery/calloutview.h new file mode 100644 index 00000000..866846a6 --- /dev/null +++ b/examples/charts/gallery/calloutview.h @@ -0,0 +1,41 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef CALLOUTVIEW_H +#define CALLOUTVIEW_H + +#include <QGraphicsView> + +QT_FORWARD_DECLARE_CLASS(QChart) +QT_FORWARD_DECLARE_CLASS(QGraphicsScene) +QT_FORWARD_DECLARE_CLASS(QGraphicsSimpleTextItem) +QT_FORWARD_DECLARE_CLASS(QGraphicsView) +QT_FORWARD_DECLARE_CLASS(QMouseEvent) +QT_FORWARD_DECLARE_CLASS(QResizeEvent) + +class Callout; + +class CalloutView : public QGraphicsView +{ + Q_OBJECT +public: + CalloutView(QWidget *parent = nullptr); + ~CalloutView(); + +protected: + void resizeEvent(QResizeEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + +public slots: + void keepCallout(); + void tooltip(QPointF point, bool state); + +private: + QGraphicsSimpleTextItem *m_coordX = nullptr; + QGraphicsSimpleTextItem *m_coordY = nullptr; + QChart *m_chart = nullptr; + Callout *m_tooltip = nullptr; + QList<Callout *> m_callouts; +}; + +#endif diff --git a/examples/charts/gallery/calloutwidget.cpp b/examples/charts/gallery/calloutwidget.cpp new file mode 100644 index 00000000..e3571f15 --- /dev/null +++ b/examples/charts/gallery/calloutwidget.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "calloutview.h" +#include "calloutwidget.h" + +CalloutWidget::CalloutWidget(QWidget *parent) + : ContentWidget(parent) +{ + // To make mouse tracking work, we need to subclass the QGraphicsView instead of just having + // it as member of this class + m_view = new CalloutView(this); + m_view->resize(size()); +} + +void CalloutWidget::resizeEvent(QResizeEvent *) +{ + m_view->resize(size()); +} diff --git a/examples/charts/gallery/calloutwidget.h b/examples/charts/gallery/calloutwidget.h new file mode 100644 index 00000000..0040f4eb --- /dev/null +++ b/examples/charts/gallery/calloutwidget.h @@ -0,0 +1,24 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef CALLOUTWIDGET_H +#define CALLOUTWIDGET_H + +#include "contentwidget.h" + +class CalloutView; + +class CalloutWidget : public ContentWidget +{ + Q_OBJECT +public: + CalloutWidget(QWidget *parent = nullptr); + +protected: + void resizeEvent(QResizeEvent *) override; + +private: + CalloutView *m_view; +}; + +#endif diff --git a/examples/charts/candlestickchart/candlestickdatareader.cpp b/examples/charts/gallery/candlestickdatareader.cpp index 7b32cf47..3913e3bd 100644 --- a/examples/charts/candlestickchart/candlestickdatareader.cpp +++ b/examples/charts/gallery/candlestickdatareader.cpp @@ -1,10 +1,12 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "candlestickdatareader.h" +#include <QCandlestickSet> + CandlestickDataReader::CandlestickDataReader(QIODevice *device) - : QTextStream(device) + : m_textStream(device) { } @@ -14,21 +16,21 @@ CandlestickDataReader::~CandlestickDataReader() void CandlestickDataReader::readFile(QIODevice *device) { - QTextStream::setDevice(device); + m_textStream.setDevice(device); } QCandlestickSet *CandlestickDataReader::readCandlestickSet() { //! [1] - QString line = readLine(); + QString line = m_textStream.readLine(); if (line.startsWith("#") || line.isEmpty()) - return 0; + return nullptr; //! [1] //! [2] QStringList strList = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); if (strList.count() != 5) - return 0; + return nullptr; //! [2] //! [3] @@ -40,7 +42,7 @@ QCandlestickSet *CandlestickDataReader::readCandlestickSet() //! [3] //! [4] - QCandlestickSet *candlestickSet = new QCandlestickSet(timestamp); + auto candlestickSet = new QCandlestickSet(timestamp); candlestickSet->setOpen(open); candlestickSet->setHigh(high); candlestickSet->setLow(low); @@ -49,3 +51,8 @@ QCandlestickSet *CandlestickDataReader::readCandlestickSet() return candlestickSet; } + +bool CandlestickDataReader::atEnd() const +{ + return m_textStream.atEnd(); +} diff --git a/examples/charts/candlestickchart/candlestickdatareader.h b/examples/charts/gallery/candlestickdatareader.h index 7a2b50d0..f7ee316d 100644 --- a/examples/charts/candlestickchart/candlestickdatareader.h +++ b/examples/charts/gallery/candlestickdatareader.h @@ -1,15 +1,14 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef CANDLESTICKDATAREADER_H #define CANDLESTICKDATAREADER_H -#include <QtCharts/QCandlestickSet> -#include <QtCore/QTextStream> +#include <QTextStream> -QT_USE_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QCandlestickSet) -class CandlestickDataReader : public QTextStream +class CandlestickDataReader { public: explicit CandlestickDataReader(QIODevice *device); @@ -17,6 +16,10 @@ public: void readFile(QIODevice *device); QCandlestickSet *readCandlestickSet(); + bool atEnd() const; + +private: + QTextStream m_textStream; }; -#endif // CANDLESTICKDATAREADER_H +#endif diff --git a/examples/charts/gallery/candlestickwidget.cpp b/examples/charts/gallery/candlestickwidget.cpp new file mode 100644 index 00000000..f21037c9 --- /dev/null +++ b/examples/charts/gallery/candlestickwidget.cpp @@ -0,0 +1,77 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "candlestickdatareader.h" +#include "candlestickwidget.h" + +#include <QBarCategoryAxis> +#include <QCandlestickSeries> +#include <QCandlestickSet> +#include <QChart> +#include <QDateTime> +#include <QFile> +#include <QLegend> +#include <QValueAxis> + +CandleStickWidget::CandleStickWidget(QWidget *parent) + : ContentWidget(parent) +{ +} + +bool CandleStickWidget::doLoad() +{ + //! [1] + auto acmeSeries = new QCandlestickSeries; + acmeSeries->setName("Acme Ltd"); + acmeSeries->setIncreasingColor(QColor(Qt::green)); + acmeSeries->setDecreasingColor(QColor(Qt::red)); + //! [1] + + //! [2] + QFile acmeData(":candlestick"); + if (!acmeData.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_loadError = QStringLiteral("Failed to load '%1' file.").arg(acmeData.fileName()); + return false; + } + + QStringList categories; + + CandlestickDataReader dataReader(&acmeData); + while (!dataReader.atEnd()) { + QCandlestickSet *set = dataReader.readCandlestickSet(); + if (set) { + acmeSeries->append(set); + categories << QDateTime::fromMSecsSinceEpoch(set->timestamp()).toString("dd"); + } + } + //! [2] + + //! [3] + auto chart = new QChart; + chart->addSeries(acmeSeries); + chart->setTitle("Acme Ltd. Historical Data (July 2015)"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //! [3] + + //! [4] + chart->createDefaultAxes(); + + auto axisX = qobject_cast<QBarCategoryAxis *>(chart->axes(Qt::Horizontal).at(0)); + axisX->setCategories(categories); + + auto axisY = qobject_cast<QValueAxis *>(chart->axes(Qt::Vertical).at(0)); + axisY->setMax(axisY->max() * 1.01); + axisY->setMin(axisY->min() * 0.99); + //! [4] + + //! [5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //! [5] + + //! [6] + createDefaultChartView(chart); + //! [6] + + return true; +} diff --git a/examples/charts/gallery/candlestickwidget.h b/examples/charts/gallery/candlestickwidget.h new file mode 100644 index 00000000..05bfac4e --- /dev/null +++ b/examples/charts/gallery/candlestickwidget.h @@ -0,0 +1,19 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef CANDLESTICKWIDGET_H +#define CANDLESTICKWIDGET_H + +#include "contentwidget.h" + +class CandleStickWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit CandleStickWidget(QWidget *parent = nullptr); + +protected: + bool doLoad() override; +}; + +#endif diff --git a/examples/charts/gallery/contentwidget.cpp b/examples/charts/gallery/contentwidget.cpp new file mode 100644 index 00000000..06ea8314 --- /dev/null +++ b/examples/charts/gallery/contentwidget.cpp @@ -0,0 +1,62 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "contentwidget.h" + +#include <QChart> +#include <QChartView> +#include <QFont> +#include <QLabel> +#include <QVBoxLayout> + +ContentWidget::ContentWidget(QWidget *parent) + : QWidget(parent) +{ +} + +void ContentWidget::load() +{ + if (m_loaded || layout()) + return; + + if (!doLoad()) { + auto errorLabel = new QLabel(this); + auto errorLayout = new QVBoxLayout(this); + errorLabel->setText(tr("Error loading the example:\n%1").arg(m_loadError)); + QFont font = errorLabel->font(); + font.setPointSize(20); + errorLabel->setFont(font); + errorLabel->setAlignment(Qt::AlignCenter); + errorLayout->addWidget(errorLabel); + setLayout(errorLayout); + } + + m_loaded = true; +} + +bool ContentWidget::doLoad() +{ + // Most examples do their initialization in constructor. + // Only those that can fail and show error message need to reimplement this method. + return true; +} + +void ContentWidget::resizeEvent(QResizeEvent *) +{ + if (m_defaultChartView) + m_defaultChartView->resize(size()); +} + +// Most examples are simple and need only basic chart view widget, so provide it in this base class +// to avoid duplicating code +void ContentWidget::createDefaultChartView(QChart *chart) +{ + m_defaultChartView = new QChartView(chart, this); + m_defaultChartView->setRenderHint(QPainter::Antialiasing); +} + +void ContentWidget::setDefaultChartView(QChartView *view) +{ + m_defaultChartView = view; + m_defaultChartView->setRenderHint(QPainter::Antialiasing); +} diff --git a/examples/charts/gallery/contentwidget.h b/examples/charts/gallery/contentwidget.h new file mode 100644 index 00000000..780877a5 --- /dev/null +++ b/examples/charts/gallery/contentwidget.h @@ -0,0 +1,34 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef CONTENTWIDGET_H +#define CONTENTWIDGET_H + +#include <QWidget> + +QT_FORWARD_DECLARE_CLASS(QChart) +QT_FORWARD_DECLARE_CLASS(QChartView) + +class ContentWidget : public QWidget +{ + Q_OBJECT +public: + explicit ContentWidget(QWidget *parent = nullptr); + + void load(); + +protected: + virtual bool doLoad(); + void resizeEvent(QResizeEvent *) override; + void createDefaultChartView(QChart *chart); + QChartView *defaultChartView() const { return m_defaultChartView; } + void setDefaultChartView(QChartView *view); + + QString m_loadError; + +private: + QChartView *m_defaultChartView = nullptr; + bool m_loaded = false; +}; + +#endif diff --git a/examples/charts/customchart/main.cpp b/examples/charts/gallery/customchartwidget.cpp index 6af7b805..dbe4ba6b 100644 --- a/examples/charts/customchart/main.cpp +++ b/examples/charts/gallery/customchartwidget.cpp @@ -1,27 +1,24 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCharts/QCategoryAxis> +#include "customchartwidget.h" -QT_USE_NAMESPACE +#include <QCategoryAxis> +#include <QChart> +#include <QLineSeries> -int main(int argc, char *argv[]) +CustomChartWidget::CustomChartWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); - -//![1] - QLineSeries *series = new QLineSeries(); + //![1] + auto series = new QLineSeries; *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(29, 26); - QChart *chart = new QChart(); + auto chart = new QChart; chart->legend()->hide(); chart->addSeries(series); -//![1] + //![1] -//![2] + //![2] // Customize series QPen pen(QRgb(0xfdb157)); pen.setWidth(5); @@ -32,7 +29,7 @@ int main(int argc, char *argv[]) font.setPixelSize(18); chart->setTitleFont(font); chart->setTitleBrush(QBrush(Qt::white)); - chart->setTitle("Customchart example"); + chart->setTitle("Custom Chart"); // Customize chart background QLinearGradient backgroundGradient; @@ -52,11 +49,11 @@ int main(int argc, char *argv[]) plotAreaGradient.setCoordinateMode(QGradient::ObjectBoundingMode); chart->setPlotAreaBackgroundBrush(plotAreaGradient); chart->setPlotAreaBackgroundVisible(true); -//![2] + //![2] -//![3] - QCategoryAxis *axisX = new QCategoryAxis(); - QCategoryAxis *axisY = new QCategoryAxis(); + //![3] + auto axisX = new QCategoryAxis; + auto axisY = new QCategoryAxis; // Customize axis label font QFont labelsFont; @@ -81,9 +78,9 @@ int main(int argc, char *argv[]) axisY->setShadesPen(Qt::NoPen); axisY->setShadesBrush(QBrush(QColor(0x99, 0xcc, 0xcc, 0x55))); axisY->setShadesVisible(true); -//![3] + //![3] -//![4] + //![4] axisX->append("low", 10); axisX->append("optimal", 20); axisX->append("high", 30); @@ -98,19 +95,9 @@ int main(int argc, char *argv[]) chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisX); series->attachAxis(axisY); -//![4] - -//![5] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![5] - -//![6] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); -//![6] + //![4] - return a.exec(); + //![5] + createDefaultChartView(chart); + //![5] } diff --git a/examples/charts/gallery/customchartwidget.h b/examples/charts/gallery/customchartwidget.h new file mode 100644 index 00000000..dd8db49d --- /dev/null +++ b/examples/charts/gallery/customchartwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef CUSTOMCHARTWIDGET_H +#define CUSTOMCHARTWIDGET_H + +#include "contentwidget.h" + +class CustomChartWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit CustomChartWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/pointsselectionandmarkers/blue_triangle.png b/examples/charts/gallery/data/blue_triangle.png Binary files differindex 7790453c..7790453c 100644 --- a/examples/charts/pointsselectionandmarkers/blue_triangle.png +++ b/examples/charts/gallery/data/blue_triangle.png diff --git a/examples/charts/boxplotchart/acme_data.txt b/examples/charts/gallery/data/boxplot_a.txt index 9511418d..9511418d 100644 --- a/examples/charts/boxplotchart/acme_data.txt +++ b/examples/charts/gallery/data/boxplot_a.txt diff --git a/examples/charts/boxplotchart/boxwhisk_data.txt b/examples/charts/gallery/data/boxplot_b.txt index f1d49cf0..f1d49cf0 100644 --- a/examples/charts/boxplotchart/boxwhisk_data.txt +++ b/examples/charts/gallery/data/boxplot_b.txt diff --git a/examples/charts/candlestickchart/acme_data.txt b/examples/charts/gallery/data/candlestick.txt index eaac318c..eaac318c 100644 --- a/examples/charts/candlestickchart/acme_data.txt +++ b/examples/charts/gallery/data/candlestick.txt diff --git a/examples/charts/pointsselectionandmarkers/green_triangle.png b/examples/charts/gallery/data/green_triangle.png Binary files differindex 29ae043f..29ae043f 100644 --- a/examples/charts/pointsselectionandmarkers/green_triangle.png +++ b/examples/charts/gallery/data/green_triangle.png diff --git a/examples/charts/datetimeaxis/sun_spots.txt b/examples/charts/gallery/data/sun_spots.txt index 91ef5982..91ef5982 100644 --- a/examples/charts/datetimeaxis/sun_spots.txt +++ b/examples/charts/gallery/data/sun_spots.txt diff --git a/examples/charts/datetimeaxis/main.cpp b/examples/charts/gallery/datetimeaxiswidget.cpp index 36ab11a5..c71e7291 100644 --- a/examples/charts/datetimeaxis/main.cpp +++ b/examples/charts/gallery/datetimeaxiswidget.cpp @@ -1,34 +1,35 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCore/QDateTime> -#include <QtCharts/QDateTimeAxis> -#include <QtCore/QFile> -#include <QtCore/QTextStream> -#include <QtCore/QDebug> -#include <QtCharts/QValueAxis> +#include "datetimeaxiswidget.h" -QT_USE_NAMESPACE +#include <QChart> +#include <QDateTime> +#include <QDateTimeAxis> +#include <QFile> +#include <QLineSeries> +#include <QTextStream> +#include <QValueAxis> -int main(int argc, char *argv[]) +DateTimeAxisWidget::DateTimeAxisWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); +} +bool DateTimeAxisWidget::doLoad() +{ //![1] - QLineSeries *series = new QLineSeries(); + auto series = new QLineSeries; //![1] //![2] // data from http://www.swpc.noaa.gov/ftpdir/weekly/RecentIndices.txt // http://www.swpc.noaa.gov/ftpdir/weekly/README // http://www.weather.gov/disclaimer - QFile sunSpots(":sun"); + QFile sunSpots(":sun_spots"); if (!sunSpots.open(QIODevice::ReadOnly | QIODevice::Text)) { - return 1; + m_loadError = QStringLiteral("Failed to load '%1' file.").arg(sunSpots.fileName()); + return false; } QTextStream stream(&sunSpots); @@ -45,21 +46,21 @@ int main(int argc, char *argv[]) //![2] //![3] - QChart *chart = new QChart(); + auto chart = new QChart; chart->addSeries(series); chart->legend()->hide(); chart->setTitle("Sunspots count (by Space Weather Prediction Center)"); //![3] //![4] - QDateTimeAxis *axisX = new QDateTimeAxis; + auto axisX = new QDateTimeAxis; axisX->setTickCount(10); axisX->setFormat("MMM yyyy"); axisX->setTitleText("Date"); chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); - QValueAxis *axisY = new QValueAxis; + auto axisY = new QValueAxis; axisY->setLabelFormat("%i"); axisY->setTitleText("Sunspots count"); chart->addAxis(axisY, Qt::AlignLeft); @@ -67,16 +68,8 @@ int main(int argc, char *argv[]) //![4] //![5] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); + createDefaultChartView(chart); //![5] - //![6] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(820, 600); - window.show(); - //![6] - - return a.exec(); + return true; } diff --git a/examples/charts/gallery/datetimeaxiswidget.h b/examples/charts/gallery/datetimeaxiswidget.h new file mode 100644 index 00000000..1baf6df9 --- /dev/null +++ b/examples/charts/gallery/datetimeaxiswidget.h @@ -0,0 +1,19 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef DATETIMEAXISWIDGET_H +#define DATETIMEAXISWIDGET_H + +#include "contentwidget.h" + +class DateTimeAxisWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit DateTimeAxisWidget(QWidget *parent = nullptr); + +protected: + bool doLoad() override; +}; + +#endif diff --git a/examples/charts/donutbreakdown/donutbreakdownchart.cpp b/examples/charts/gallery/donutbreakdownchart.cpp index 25c5c1ad..7faf09e4 100644 --- a/examples/charts/donutbreakdown/donutbreakdownchart.cpp +++ b/examples/charts/gallery/donutbreakdownchart.cpp @@ -1,9 +1,12 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + #include "donutbreakdownchart.h" -#include "mainslice.h" -#include <QtCharts/QPieSlice> -#include <QtCharts/QPieLegendMarker> +#include "donutbreakdownmainslice.h" + +#include <QPieLegendMarker> +#include <QPieSeries> +#include <QPieSlice> QT_USE_NAMESPACE @@ -12,7 +15,7 @@ DonutBreakdownChart::DonutBreakdownChart(QGraphicsItem *parent, Qt::WindowFlags : QChart(QChart::ChartTypeCartesian, parent, wFlags) { // create the series for main center pie - m_mainSeries = new QPieSeries(); + m_mainSeries = new QPieSeries; m_mainSeries->setPieSize(0.7); QChart::addSeries(m_mainSeries); } @@ -24,7 +27,7 @@ void DonutBreakdownChart::addBreakdownSeries(QPieSeries *breakdownSeries, QColor QFont font("Arial", 8); // add breakdown series as a slice to center pie - MainSlice *mainSlice = new MainSlice(breakdownSeries); + auto mainSlice = new DonutBreakdownMainSlice(breakdownSeries); mainSlice->setName(breakdownSeries->name()); mainSlice->setValue(breakdownSeries->sum()); m_mainSeries->append(mainSlice); @@ -64,7 +67,7 @@ void DonutBreakdownChart::recalculateAngles() qreal angle = 0; const auto slices = m_mainSeries->slices(); for (QPieSlice *slice : slices) { - QPieSeries *breakdownSeries = qobject_cast<MainSlice *>(slice)->breakdownSeries(); + QPieSeries *breakdownSeries = qobject_cast<DonutBreakdownMainSlice *>(slice)->breakdownSeries(); breakdownSeries->setPieStartAngle(angle); angle += slice->percentage() * 360.0; // full pie is 360.0 breakdownSeries->setPieEndAngle(angle); @@ -80,7 +83,7 @@ void DonutBreakdownChart::updateLegendMarkers() for (QAbstractSeries *series : allseries) { const auto markers = legend()->markers(series); for (QLegendMarker *marker : markers) { - QPieLegendMarker *pieMarker = qobject_cast<QPieLegendMarker *>(marker); + auto pieMarker = qobject_cast<QPieLegendMarker *>(marker); if (series == m_mainSeries) { // hide markers from main series pieMarker->setVisible(false); diff --git a/examples/charts/donutbreakdown/donutbreakdownchart.h b/examples/charts/gallery/donutbreakdownchart.h index b5536dc8..5cfc574e 100644 --- a/examples/charts/donutbreakdown/donutbreakdownchart.h +++ b/examples/charts/gallery/donutbreakdownchart.h @@ -1,12 +1,12 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + #ifndef DONUTBREAKDOWNCHART_H #define DONUTBREAKDOWNCHART_H -#include <QtCharts/QChart> -#include <QtCharts/QPieSeries> +#include <QChart> -QT_USE_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QPieSeries) class DonutBreakdownChart : public QChart { @@ -19,7 +19,7 @@ private: void updateLegendMarkers(); private: - QPieSeries *m_mainSeries; + QPieSeries *m_mainSeries = nullptr; }; -#endif // DONUTBREAKDOWNCHART_H +#endif diff --git a/examples/charts/gallery/donutbreakdownmainslice.cpp b/examples/charts/gallery/donutbreakdownmainslice.cpp new file mode 100644 index 00000000..eb0dd4cb --- /dev/null +++ b/examples/charts/gallery/donutbreakdownmainslice.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "donutbreakdownmainslice.h" + +//![1] +DonutBreakdownMainSlice::DonutBreakdownMainSlice(QPieSeries *breakdownSeries, QObject *parent) + : QPieSlice(parent), + m_breakdownSeries(breakdownSeries) +{ + connect(this, &DonutBreakdownMainSlice::percentageChanged, + this, &DonutBreakdownMainSlice::updateLabel); +} +//![1] + +QPieSeries *DonutBreakdownMainSlice::breakdownSeries() const +{ + return m_breakdownSeries; +} + +void DonutBreakdownMainSlice::setName(const QString &name) +{ + m_name = name; +} + +QString DonutBreakdownMainSlice::name() const +{ + return m_name; +} + +//![2] +void DonutBreakdownMainSlice::updateLabel() +{ + setLabel(QString("%1 %2%").arg(m_name).arg(percentage() * 100, 0, 'f', 2)); +} +//![2] diff --git a/examples/charts/gallery/donutbreakdownmainslice.h b/examples/charts/gallery/donutbreakdownmainslice.h new file mode 100644 index 00000000..f0088400 --- /dev/null +++ b/examples/charts/gallery/donutbreakdownmainslice.h @@ -0,0 +1,30 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef DONUTBREAKDOWNMAINSLICE_H +#define DONUTBREAKDOWNMAINSLICE_H + +#include <QPieSlice> + +QT_FORWARD_DECLARE_CLASS(QPieSeries) + +class DonutBreakdownMainSlice : public QPieSlice +{ + Q_OBJECT +public: + DonutBreakdownMainSlice(QPieSeries *breakdownSeries, QObject *parent = nullptr); + + QPieSeries *breakdownSeries() const; + + void setName(const QString &name); + QString name() const; + +public slots: + void updateLabel(); + +private: + QPieSeries *m_breakdownSeries = nullptr; + QString m_name; +}; + +#endif diff --git a/examples/charts/donutbreakdown/main.cpp b/examples/charts/gallery/donutbreakdownwidget.cpp index 5710b2da..63181601 100644 --- a/examples/charts/donutbreakdown/main.cpp +++ b/examples/charts/gallery/donutbreakdownwidget.cpp @@ -1,36 +1,34 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtWidgets/QStatusBar> -#include <QtCharts/QChartView> + #include "donutbreakdownchart.h" +#include "donutbreakdownwidget.h" -QT_USE_NAMESPACE +#include <QChart> +#include <QPieSeries> -int main(int argc, char *argv[]) +DonutBreakdownWidget::DonutBreakdownWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); - //![1] // Graph is based on data of 'Total consumption of energy increased by 10 per cent in 2010' // Statistics Finland, 13 December 2011 // http://www.stat.fi/til/ekul/2010/ekul_2010_2011-12-13_tie_001_en.html - QPieSeries *series1 = new QPieSeries(); + auto series1 = new QPieSeries; series1->setName("Fossil fuels"); series1->append("Oil", 353295); series1->append("Coal", 188500); series1->append("Natural gas", 148680); series1->append("Peat", 94545); - QPieSeries *series2 = new QPieSeries(); + auto series2 = new QPieSeries; series2->setName("Renewables"); series2->append("Wood fuels", 319663); series2->append("Hydro power", 45875); series2->append("Wind power", 1060); - QPieSeries *series3 = new QPieSeries(); + auto series3 = new QPieSeries; series3->setName("Others"); series3->append("Nuclear energy", 238789); series3->append("Import energy", 37802); @@ -38,7 +36,7 @@ int main(int argc, char *argv[]) //![1] //![2] - DonutBreakdownChart *donutBreakdown = new DonutBreakdownChart(); + auto donutBreakdown = new DonutBreakdownChart; donutBreakdown->setAnimationOptions(QChart::AllAnimations); donutBreakdown->setTitle("Total consumption of energy in Finland 2010"); donutBreakdown->legend()->setAlignment(Qt::AlignRight); @@ -48,13 +46,6 @@ int main(int argc, char *argv[]) //![2] //![3] - QMainWindow window; - QChartView *chartView = new QChartView(donutBreakdown); - chartView->setRenderHint(QPainter::Antialiasing); - window.setCentralWidget(chartView); - window.resize(800, 500); - window.show(); + createDefaultChartView(donutBreakdown); //![3] - - return a.exec(); } diff --git a/examples/charts/gallery/donutbreakdownwidget.h b/examples/charts/gallery/donutbreakdownwidget.h new file mode 100644 index 00000000..4b2f9b43 --- /dev/null +++ b/examples/charts/gallery/donutbreakdownwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef DONUTBREAKDOWNWIDGET_H +#define DONUTBREAKDOWNWIDGET_H + +#include "contentwidget.h" + +class DonutBreakdownWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit DonutBreakdownWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/donutwidget.cpp b/examples/charts/gallery/donutwidget.cpp new file mode 100644 index 00000000..2bee9974 --- /dev/null +++ b/examples/charts/gallery/donutwidget.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "donutwidget.h" + +#include <QChart> +#include <QPieSeries> +#include <QPieSlice> + +DonutWidget::DonutWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto series = new QPieSeries; + series->setHoleSize(0.35); + series->append("Protein 4.2%", 4.2); + QPieSlice *slice = series->append("Fat 15.6%", 15.6); + slice->setExploded(); + slice->setLabelVisible(); + series->append("Other 23.8%", 23.8); + series->append("Carbs 56.4%", 56.4); + //![1] + + //![2] + auto chart = new QChart; + chart->setTitle("Donut with a lemon glaze (100g)"); + chart->addSeries(series); + chart->legend()->setAlignment(Qt::AlignBottom); + chart->setTheme(QChart::ChartThemeBlueCerulean); + chart->legend()->setFont(QFont("Arial", 7)); + + createDefaultChartView(chart); + //![2] +} diff --git a/examples/charts/gallery/donutwidget.h b/examples/charts/gallery/donutwidget.h new file mode 100644 index 00000000..cf27c2ae --- /dev/null +++ b/examples/charts/gallery/donutwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef DONUTWIDGET_H +#define DONUTWIDGET_H + +#include "contentwidget.h" + +class DonutWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit DonutWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/dynamicsplinewidget.cpp b/examples/charts/gallery/dynamicsplinewidget.cpp new file mode 100644 index 00000000..fce79d79 --- /dev/null +++ b/examples/charts/gallery/dynamicsplinewidget.cpp @@ -0,0 +1,57 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "dynamicsplinewidget.h" + +#include <QChart> +#include <QChartView> +#include <QRandomGenerator> +#include <QSplineSeries> +#include <QValueAxis> + +DynamicSplineWidget::DynamicSplineWidget(QWidget *parent) + : ContentWidget(parent) +{ + auto chart = new QChart; + chart->setTitle("Dynamic Spline Chart"); + chart->legend()->hide(); + chart->setAnimationOptions(QChart::AllAnimations); + + m_axisX = new QValueAxis; + m_axisY = new QValueAxis; + + QObject::connect(&m_timer, &QTimer::timeout, this, &DynamicSplineWidget::handleTimeout); + m_timer.setInterval(1000); + + m_series = new QSplineSeries; + QPen green(Qt::red); + green.setWidth(3); + m_series->setPen(green); + m_series->append(m_x, m_y); + + chart->addSeries(m_series); + + chart->addAxis(m_axisX,Qt::AlignBottom); + chart->addAxis(m_axisY,Qt::AlignLeft); + m_series->attachAxis(m_axisX); + m_series->attachAxis(m_axisY); + m_axisX->setTickCount(5); + m_axisX->setRange(0, 10); + m_axisY->setRange(-5, 10); + + createDefaultChartView(chart); + + m_timer.start(); +} + +void DynamicSplineWidget::handleTimeout() +{ + qreal x = defaultChartView()->chart()->plotArea().width() / m_axisX->tickCount(); + qreal y = (m_axisX->max() - m_axisX->min()) / m_axisX->tickCount(); + m_x += y; + m_y = QRandomGenerator::global()->bounded(5) - 2.5; + m_series->append(m_x, m_y); + defaultChartView()->chart()->scroll(x, 0); + if (m_x >= 100) + m_timer.stop(); +} diff --git a/examples/charts/gallery/dynamicsplinewidget.h b/examples/charts/gallery/dynamicsplinewidget.h new file mode 100644 index 00000000..1389280b --- /dev/null +++ b/examples/charts/gallery/dynamicsplinewidget.h @@ -0,0 +1,34 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef DYNAMICSPLINEWIDGET_H +#define DYNAMICSPLINEWIDGET_H + +#include "contentwidget.h" + +#include <QTimer> + +QT_FORWARD_DECLARE_CLASS(QSplineSeries) +QT_FORWARD_DECLARE_CLASS(QValueAxis) + +class DynamicSplineWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit DynamicSplineWidget(QWidget *parent = nullptr); + +public slots: + void handleTimeout(); + +private: + QSplineSeries *m_series = nullptr; + QValueAxis *m_axisX = nullptr; + QValueAxis *m_axisY = nullptr; + QTimer m_timer; + QStringList m_titles; + qreal m_step = 0.; + qreal m_x = 5; + qreal m_y = 1; +}; + +#endif diff --git a/examples/charts/gallery/gallery.pro b/examples/charts/gallery/gallery.pro new file mode 100644 index 00000000..ea9adc16 --- /dev/null +++ b/examples/charts/gallery/gallery.pro @@ -0,0 +1,129 @@ +QT += charts + +HEADERS += \ + areawidget.h \ + barmodelmappermodel.h \ + barmodelmapperwidget.h \ + boxplotdatareader.h \ + boxplotwidget.h \ + barwidget.h \ + barpercentwidget.h \ + barstackedwidget.h \ + callout.h \ + calloutwidget.h \ + calloutview.h \ + candlestickwidget.h \ + candlestickdatareader.h \ + contentwidget.h \ + customchartwidget.h \ + datetimeaxiswidget.h \ + donutbreakdownchart.h \ + donutbreakdownmainslice.h \ + donutbreakdownwidget.h \ + donutwidget.h \ + dynamicsplinewidget.h \ + horizontalbarwidget.h \ + horizontalpercentbarwidget.h \ + horizontalstackedbarwidget.h \ + interactionswidget.h \ + interactionsview.h \ + interactionschart.h \ + legendwidget.h \ + legendmarkerswidget.h \ + lightmarkerswidget.h \ + lineandbarwidget.h \ + linewidget.h \ + logaxiswidget.h \ + modeldatamodel.h \ + modeldatawidget.h \ + multiaxiswidget.h \ + nesteddonutswidget.h \ + mainwidget.h \ + pccpentool.h \ + pccbrushtool.h \ + pcccustomslice.h \ + pccwidget.h \ + piedrilldownchart.h \ + piedrilldownslice.h \ + piedrilldownwidget.h \ + piewidget.h \ + pointconfigurationwidget.h \ + polarchartview.h \ + polarchartwidget.h \ + scatterinteractionswidget.h \ + scatterwidget.h \ + selectedbarwidget.h \ + splinewidget.h \ + stackeddrilldownchart.h \ + stackeddrilldownseries.h \ + stackeddrilldownwidget.h \ + temperaturerecordswidget.h \ + themewidget.h + +SOURCES += \ + areawidget.cpp \ + barmodelmappermodel.cpp \ + barmodelmapperwidget.cpp \ + boxplotdatareader.cpp \ + boxplotwidget.cpp \ + barwidget.cpp \ + barpercentwidget.cpp \ + barstackedwidget.cpp \ + callout.cpp \ + calloutwidget.cpp \ + calloutview.cpp \ + candlestickwidget.cpp \ + candlestickdatareader.cpp \ + contentwidget.cpp \ + customchartwidget.cpp \ + datetimeaxiswidget.cpp \ + donutbreakdownchart.cpp \ + donutbreakdownmainslice.cpp \ + donutbreakdownwidget.cpp \ + donutwidget.cpp \ + dynamicsplinewidget.cpp \ + horizontalbarwidget.cpp \ + horizontalpercentbarwidget.cpp \ + horizontalstackedbarwidget.cpp \ + interactionswidget.cpp \ + interactionsview.cpp \ + interactionschart.cpp \ + legendwidget.cpp \ + legendmarkerswidget.cpp \ + lightmarkerswidget.cpp \ + lineandbarwidget.cpp \ + linewidget.cpp \ + logaxiswidget.cpp \ + main.cpp \ + modeldatamodel.cpp \ + modeldatawidget.cpp \ + multiaxiswidget.cpp \ + nesteddonutswidget.cpp \ + mainwidget.cpp \ + pccpentool.cpp \ + pccbrushtool.cpp \ + pcccustomslice.cpp \ + pccwidget.cpp \ + piedrilldownchart.cpp \ + piedrilldownslice.cpp \ + piedrilldownwidget.cpp \ + piewidget.cpp \ + pointconfigurationwidget.cpp \ + polarchartview.cpp \ + polarchartwidget.cpp \ + scatterinteractionswidget.cpp \ + scatterwidget.cpp \ + selectedbarwidget.cpp \ + splinewidget.cpp \ + stackeddrilldownchart.cpp \ + stackeddrilldownseries.cpp \ + stackeddrilldownwidget.cpp \ + temperaturerecordswidget.cpp \ + themewidget.cpp + +RESOURCES += gallery.qrc + +FORMS += themewidget.ui + +target.path = $$[QT_INSTALL_EXAMPLES]/charts/gallery +INSTALLS += target diff --git a/examples/charts/gallery/gallery.qrc b/examples/charts/gallery/gallery.qrc new file mode 100644 index 00000000..016e2241 --- /dev/null +++ b/examples/charts/gallery/gallery.qrc @@ -0,0 +1,10 @@ +<RCC> + <qresource prefix="/"> + <file alias="boxplot_a">data/boxplot_a.txt</file> + <file alias="boxplot_b">data/boxplot_b.txt</file> + <file alias="candlestick">data/candlestick.txt</file> + <file alias="sun_spots">data/sun_spots.txt</file> + <file alias="blue_triangle">data/blue_triangle.png</file> + <file alias="green_triangle">data/green_triangle.png</file> + </qresource> +</RCC> diff --git a/examples/charts/gallery/horizontalbarwidget.cpp b/examples/charts/gallery/horizontalbarwidget.cpp new file mode 100644 index 00000000..5a903335 --- /dev/null +++ b/examples/charts/gallery/horizontalbarwidget.cpp @@ -0,0 +1,67 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "horizontalbarwidget.h" + +#include <QBarCategoryAxis> +#include <QBarSeries> +#include <QBarSet> +#include <QChart> +#include <QHorizontalBarSeries> +#include <QLegend> +#include <QValueAxis> + +HorizontalBarWidget::HorizontalBarWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto set0 = new QBarSet("Jane"); + auto set1 = new QBarSet("John"); + auto set2 = new QBarSet("Axel"); + auto set3 = new QBarSet("Mary"); + auto set4 = new QBarSet("Samantha"); + + *set0 << 1 << 2 << 3 << 4 << 5 << 6; + *set1 << 5 << 0 << 0 << 4 << 0 << 7; + *set2 << 3 << 5 << 8 << 13 << 8 << 5; + *set3 << 5 << 6 << 7 << 3 << 4 << 5; + *set4 << 9 << 7 << 5 << 3 << 1 << 2; + //![1] + + //![2] + auto series = new QHorizontalBarSeries; + series->append(set0); + series->append(set1); + series->append(set2); + series->append(set3); + series->append(set4); + //![2] + + //![3] + auto chart = new QChart; + chart->addSeries(series); + chart->setTitle("Simple Horizontal Bar Chart"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //![3] + + //![4] + QStringList categories {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}; + auto axisY = new QBarCategoryAxis; + axisY->append(categories); + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisY); + auto axisX = new QValueAxis; + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + axisX->applyNiceNumbers(); + //![4] + + //![5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //![5] + + //![6] + createDefaultChartView(chart); + //![6] +} diff --git a/examples/charts/gallery/horizontalbarwidget.h b/examples/charts/gallery/horizontalbarwidget.h new file mode 100644 index 00000000..cd459050 --- /dev/null +++ b/examples/charts/gallery/horizontalbarwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef HORIZONTALBARWIDGET_H +#define HORIZONTALBARWIDGET_H + +#include "contentwidget.h" + +class HorizontalBarWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit HorizontalBarWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/horizontalpercentbarwidget.cpp b/examples/charts/gallery/horizontalpercentbarwidget.cpp new file mode 100644 index 00000000..374b3dd4 --- /dev/null +++ b/examples/charts/gallery/horizontalpercentbarwidget.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "horizontalpercentbarwidget.h" + +#include <QBarCategoryAxis> +#include <QBarSeries> +#include <QBarSet> +#include <QChart> +#include <QHorizontalPercentBarSeries> +#include <QLegend> +#include <QValueAxis> + +HorizontalPercentBarWidget::HorizontalPercentBarWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto set0 = new QBarSet("Jane"); + auto set1 = new QBarSet("John"); + auto set2 = new QBarSet("Axel"); + auto set3 = new QBarSet("Mary"); + auto set4 = new QBarSet("Samantha"); + + *set0 << 1 << 2 << 3 << 4 << 5 << 6; + *set1 << 5 << 0 << 0 << 4 << 0 << 7; + *set2 << 3 << 5 << 8 << 13 << 8 << 5; + *set3 << 5 << 6 << 7 << 3 << 4 << 5; + *set4 << 9 << 7 << 5 << 3 << 1 << 2; + //![1] + + //![2] + auto series = new QHorizontalPercentBarSeries; + series->append(set0); + series->append(set1); + series->append(set2); + series->append(set3); + series->append(set4); + //![2] + + //![3] + auto chart = new QChart; + chart->addSeries(series); + chart->setTitle("Simple Horizontal Percent Bar Chart"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //![3] + + //![4] + QStringList categories {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}; + auto axisY = new QBarCategoryAxis; + axisY->append(categories); + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisY); + auto axisX = new QValueAxis; + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + //![4] + + //![5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //![5] + + //![6] + createDefaultChartView(chart); + //![6] +} diff --git a/examples/charts/gallery/horizontalpercentbarwidget.h b/examples/charts/gallery/horizontalpercentbarwidget.h new file mode 100644 index 00000000..33f7eb8f --- /dev/null +++ b/examples/charts/gallery/horizontalpercentbarwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef HORIZONTALPERCENTBARWIDGET_H +#define HORIZONTALPERCENTBARWIDGET_H + +#include "contentwidget.h" + +class HorizontalPercentBarWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit HorizontalPercentBarWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/horizontalstackedbarwidget.cpp b/examples/charts/gallery/horizontalstackedbarwidget.cpp new file mode 100644 index 00000000..647e0e34 --- /dev/null +++ b/examples/charts/gallery/horizontalstackedbarwidget.cpp @@ -0,0 +1,67 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "horizontalstackedbarwidget.h" + +#include <QBarCategoryAxis> +#include <QBarSeries> +#include <QBarSet> +#include <QChart> +#include <QHorizontalStackedBarSeries> +#include <QLegend> +#include <QValueAxis> + +HorizontalStackedBarWidget::HorizontalStackedBarWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto set0 = new QBarSet("Jane"); + auto set1 = new QBarSet("John"); + auto set2 = new QBarSet("Axel"); + auto set3 = new QBarSet("Mary"); + auto set4 = new QBarSet("Samantha"); + + *set0 << 1 << 2 << 3 << 4 << 5 << 6; + *set1 << 5 << 0 << 0 << 4 << 0 << 7; + *set2 << 3 << 5 << 8 << 13 << 8 << 5; + *set3 << 5 << 6 << 7 << 3 << 4 << 5; + *set4 << 9 << 7 << 5 << 3 << 1 << 2; + //![1] + + //![2] + auto series = new QHorizontalStackedBarSeries; + series->append(set0); + series->append(set1); + series->append(set2); + series->append(set3); + series->append(set4); + + //![2] + + //![3] + auto chart = new QChart; + chart->addSeries(series); + chart->setTitle("Simple Horizontal Stacked Bar Chart"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //![3] + + //![4] + QStringList categories {"Jan", "Feb", "Mar", "Apr", "May", "Jun"}; + auto axisY = new QBarCategoryAxis; + axisY->append(categories); + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisY); + auto axisX = new QValueAxis; + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + //![4] + + //![5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //![5] + + //![6] + createDefaultChartView(chart); + //![6] +} diff --git a/examples/charts/gallery/horizontalstackedbarwidget.h b/examples/charts/gallery/horizontalstackedbarwidget.h new file mode 100644 index 00000000..e36d9687 --- /dev/null +++ b/examples/charts/gallery/horizontalstackedbarwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef HORIZONTALSTACKEDBARWIDGET_H +#define HORIZONTALSTACKEDBARWIDGET_H + +#include "contentwidget.h" + +class HorizontalStackedBarWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit HorizontalStackedBarWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/chartinteractions/chart.cpp b/examples/charts/gallery/interactionschart.cpp index dc0500fb..740c9f64 100644 --- a/examples/charts/chartinteractions/chart.cpp +++ b/examples/charts/gallery/interactionschart.cpp @@ -1,22 +1,18 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "chart.h" -#include <QtCharts/QValueAxis> -#include <QtCharts/QAbstractAxis> -#include <QtCore/QtMath> +#include "interactionschart.h" -Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series) - : QChart(QChart::ChartTypeCartesian, parent, wFlags), m_series(series) -{ - m_clicked = false; -} +#include <QLineSeries> +#include <QtMath> +#include <QValueAxis> -Chart::~Chart() +InteractionsChart::InteractionsChart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series) + : QChart(QChart::ChartTypeCartesian, parent, wFlags), m_series(series) { } -void Chart::clickPoint(const QPointF &point) +void InteractionsChart::clickPoint(const QPointF &point) { // Find the closest data point m_movingPoint = QPoint(); @@ -30,53 +26,49 @@ void Chart::clickPoint(const QPointF &point) } } -qreal Chart::distance(const QPointF &p1, const QPointF &p2) +qreal InteractionsChart::distance(const QPointF &p1, const QPointF &p2) { return qSqrt((p1.x() - p2.x()) * (p1.x() - p2.x()) - + (p1.y() - p2.y()) * (p1.y() - p2.y())); + + (p1.y() - p2.y()) * (p1.y() - p2.y())); } -void Chart::setPointClicked(bool clicked) +void InteractionsChart::setPointClicked(bool clicked) { m_clicked = clicked; } -void Chart::handlePointMove(const QPoint &point) +void InteractionsChart::handlePointMove(const QPoint &point) { if (m_clicked) { - //Map the point clicked from the ChartView - //to the area occupied by the chart. + // Map the point clicked from the ChartView to the area occupied by the chart QPoint mappedPoint = point; mappedPoint.setX(point.x() - this->plotArea().x()); mappedPoint.setY(point.y() - this->plotArea().y()); - //Get the x- and y axis to be able to convert the mapped - //coordinate point to the charts scale. + // Get the x and y axis to be able to convert the mapped coordinate point to the chart scale QAbstractAxis *axisx = axes(Qt::Horizontal).first(); - QValueAxis *haxis = 0; + QValueAxis *haxis = nullptr; if (axisx->type() == QAbstractAxis::AxisTypeValue) haxis = qobject_cast<QValueAxis *>(axisx); QAbstractAxis *axisy = axes(Qt::Vertical).first(); - QValueAxis *vaxis = 0; + QValueAxis *vaxis = nullptr; if (axisy->type() == QAbstractAxis::AxisTypeValue) vaxis = qobject_cast<QValueAxis *>(axisy); if (haxis && vaxis) { - //Calculate the "unit" between points on the x - //y axis. + // Calculate the "unit" between points on the x y axis double xUnit = this->plotArea().width() / haxis->max(); double yUnit = this->plotArea().height() / vaxis->max(); - //Convert the mappedPoint to the actual chart scale. + // Convert the mappedPoint to the actual chart scale double x = mappedPoint.x() / xUnit; double y = vaxis->max() - mappedPoint.y() / yUnit; - //Replace the old point with the new one. + // Replace the old point with the new one m_series->replace(m_movingPoint, QPointF(x, y)); - //Update the m_movingPoint so we are able to - //do the replace also during mousemoveEvent. + // Update the m_movingPoint so we are able to do the replace also during mousemoveEvent m_movingPoint.setX(x); m_movingPoint.setY(y); } diff --git a/examples/charts/gallery/interactionschart.h b/examples/charts/gallery/interactionschart.h new file mode 100644 index 00000000..dd087156 --- /dev/null +++ b/examples/charts/gallery/interactionschart.h @@ -0,0 +1,34 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef INTERACTIONSCHART_H +#define INTERACTIONSCHART_H + +#include <QChart> + +QT_FORWARD_DECLARE_CLASS(QLineSeries) + +class InteractionsChart : public QChart +{ + Q_OBJECT +public: + explicit InteractionsChart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {}, QLineSeries *series = nullptr); + +public slots: + void clickPoint(const QPointF &point); + +public: + void handlePointMove(const QPoint &point); + void setPointClicked(bool clicked); + +private: + qreal distance(const QPointF &p1, const QPointF &p2); + + QLineSeries *m_series = nullptr; + QPointF m_movingPoint; + + // Boolean value to determine if an actual point in the series is clicked + bool m_clicked = false; +}; + +#endif diff --git a/examples/charts/chartinteractions/chartview.cpp b/examples/charts/gallery/interactionsview.cpp index cc9e1f61..0bac0b77 100644 --- a/examples/charts/chartinteractions/chartview.cpp +++ b/examples/charts/gallery/interactionsview.cpp @@ -1,29 +1,30 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "chartview.h" -#include <QtGui/QMouseEvent> -#include "chart.h" +#include "interactionschart.h" +#include "interactionsview.h" -ChartView::ChartView(Chart *chart, QWidget *parent) : +#include <QMouseEvent> + +InteractionsView::InteractionsView(InteractionsChart *chart, QWidget *parent) : QChartView(chart, parent) { m_chart = chart; } -void ChartView::mousePressEvent(QMouseEvent *event) +void InteractionsView::mousePressEvent(QMouseEvent *event) { m_mousePos = event->pos(); QChartView::mousePressEvent(event); } -void ChartView::mouseMoveEvent(QMouseEvent *event) +void InteractionsView::mouseMoveEvent(QMouseEvent *event) { m_chart->handlePointMove(event->pos()); QChartView::mouseMoveEvent(event); } -void ChartView::mouseReleaseEvent(QMouseEvent *event) +void InteractionsView::mouseReleaseEvent(QMouseEvent *event) { if (event->pos() != m_mousePos) { m_chart->handlePointMove(event->pos()); diff --git a/examples/charts/gallery/interactionsview.h b/examples/charts/gallery/interactionsview.h new file mode 100644 index 00000000..04a27b41 --- /dev/null +++ b/examples/charts/gallery/interactionsview.h @@ -0,0 +1,27 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef INTERACTIONSVIEW_H +#define INTERACTIONSVIEW_H + +#include <QChartView> +#include <QPoint> + +class InteractionsChart; + +class InteractionsView : public QChartView +{ +public: + InteractionsView(InteractionsChart *chart, QWidget *parent = nullptr); + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + +private: + InteractionsChart *m_chart = nullptr; + QPoint m_mousePos; +}; + +#endif diff --git a/examples/charts/gallery/interactionswidget.cpp b/examples/charts/gallery/interactionswidget.cpp new file mode 100644 index 00000000..6be473ac --- /dev/null +++ b/examples/charts/gallery/interactionswidget.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "interactionschart.h" +#include "interactionsview.h" +#include "interactionswidget.h" + +#include <QChart> +#include <QLineSeries> +#include <QValueAxis> + +InteractionsWidget::InteractionsWidget(QWidget *parent) + : ContentWidget(parent) +{ + auto series = new QLineSeries; + + series->append(0, 6); + series->append(1, 3); + series->append(2, 4); + series->append(3, 8); + series->append(7, 13); + series->append(10, 5); + *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); + + auto chart = new InteractionsChart(0, {}, series); + chart->legend()->hide(); + chart->addSeries(series); + QPen p = series->pen(); + p.setWidth(5); + series->setPen(p); + chart->setTitle("Drag and drop data points to move them"); + + auto axisX = new QValueAxis; + chart->addAxis(axisX, Qt::AlignBottom); + axisX->setRange(0, 20); + series->attachAxis(axisX); + + auto axisY = new QValueAxis; + chart->addAxis(axisY, Qt::AlignLeft); + axisY->setRange(0, 13); + series->attachAxis(axisY); + + QObject::connect(series, &QLineSeries::pressed, chart, &InteractionsChart::clickPoint); + + auto view = new InteractionsView(chart, this); + setDefaultChartView(view); +} diff --git a/examples/charts/gallery/interactionswidget.h b/examples/charts/gallery/interactionswidget.h new file mode 100644 index 00000000..bc378a10 --- /dev/null +++ b/examples/charts/gallery/interactionswidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef INTERACTIONSWIDGET_H +#define INTERACTIONSWIDGET_H + +#include "contentwidget.h" + +class InteractionsWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit InteractionsWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/legendmarkers/mainwidget.cpp b/examples/charts/gallery/legendmarkerswidget.cpp index 766ffe88..0d739bb1 100644 --- a/examples/charts/legendmarkers/mainwidget.cpp +++ b/examples/charts/gallery/legendmarkerswidget.cpp @@ -1,30 +1,27 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "mainwidget.h" -#include <QtCharts/QChart> -#include <QtCharts/QChartView> -#include <QtWidgets/QPushButton> -#include <QtWidgets/QLabel> -#include <QtCore/QDebug> -#include <QtCharts/QLegend> -#include <QtWidgets/QFormLayout> -#include <QtCharts/QLegendMarker> -#include <QtCharts/QLineSeries> -#include <QtCharts/QXYLegendMarker> -#include <QtCore/QtMath> - -QT_USE_NAMESPACE - -MainWidget::MainWidget(QWidget *parent) : - QWidget(parent) +#include "legendmarkerswidget.h" + +#include <QChart> +#include <QChartView> +#include <QGraphicsLayout> +#include <QGridLayout> +#include <QLegend> +#include <QLegendMarker> +#include <QLineSeries> +#include <QtMath> +#include <QXYLegendMarker> + +LegendMarkersWidget::LegendMarkersWidget(QWidget *parent) + : ContentWidget(parent) { // Create chart view with the chart - m_chart = new QChart(); + m_chart = new QChart; m_chartView = new QChartView(m_chart, this); // Create layout for grid and detached legend - m_mainLayout = new QGridLayout(); + m_mainLayout = new QGridLayout; m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); setLayout(m_mainLayout); @@ -37,16 +34,17 @@ MainWidget::MainWidget(QWidget *parent) : connectMarkers(); // Set the title and show legend - m_chart->setTitle("Legendmarker example (click on legend)"); + m_chart->setTitle("Legend Markers (Click on legend to interact)"); m_chart->legend()->setVisible(true); m_chart->legend()->setAlignment(Qt::AlignBottom); m_chartView->setRenderHint(QPainter::Antialiasing); + m_chart->layout()->setContentsMargins(0, 0, 0, 0); } -void MainWidget::addSeries() +void LegendMarkersWidget::addSeries() { - QLineSeries *series = new QLineSeries(); + auto series = new QLineSeries; m_series.append(series); series->setName(QString("line " + QString::number(m_series.count()))); @@ -66,7 +64,7 @@ void MainWidget::addSeries() m_chart->createDefaultAxes(); } -void MainWidget::removeSeries() +void LegendMarkersWidget::removeSeries() { // Remove last series from chart if (m_series.count() > 0) { @@ -77,7 +75,7 @@ void MainWidget::removeSeries() } } -void MainWidget::connectMarkers() +void LegendMarkersWidget::connectMarkers() { //![1] // Connect all markers to handler @@ -85,27 +83,28 @@ void MainWidget::connectMarkers() for (QLegendMarker *marker : markers) { // Disconnect possible existing connection to avoid multiple connections QObject::disconnect(marker, &QLegendMarker::clicked, - this, &MainWidget::handleMarkerClicked); - QObject::connect(marker, &QLegendMarker::clicked, this, &MainWidget::handleMarkerClicked); + this, &LegendMarkersWidget::handleMarkerClicked); + QObject::connect(marker, &QLegendMarker::clicked, + this, &LegendMarkersWidget::handleMarkerClicked); } //![1] } -void MainWidget::disconnectMarkers() +void LegendMarkersWidget::disconnectMarkers() { //![2] const auto markers = m_chart->legend()->markers(); for (QLegendMarker *marker : markers) { QObject::disconnect(marker, &QLegendMarker::clicked, - this, &MainWidget::handleMarkerClicked); + this, &LegendMarkersWidget::handleMarkerClicked); } //![2] } -void MainWidget::handleMarkerClicked() +void LegendMarkersWidget::handleMarkerClicked() { //![3] - QLegendMarker* marker = qobject_cast<QLegendMarker*> (sender()); + auto marker = qobject_cast<QLegendMarker *>(sender()); Q_ASSERT(marker); //![3] @@ -155,7 +154,7 @@ void MainWidget::handleMarkerClicked() } default: { - qDebug() << "Unknown marker type"; + qDebug("Unknown marker type"); break; } } diff --git a/examples/charts/gallery/legendmarkerswidget.h b/examples/charts/gallery/legendmarkerswidget.h new file mode 100644 index 00000000..78b26623 --- /dev/null +++ b/examples/charts/gallery/legendmarkerswidget.h @@ -0,0 +1,35 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef LEGENDMARKERSWIDGET_H +#define LEGENDMARKERSWIDGET_H + +#include "contentwidget.h" + +QT_FORWARD_DECLARE_CLASS(QChart) +QT_FORWARD_DECLARE_CLASS(QChartView) +QT_FORWARD_DECLARE_CLASS(QGridLayout) +QT_FORWARD_DECLARE_CLASS(QLineSeries) + +class LegendMarkersWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit LegendMarkersWidget(QWidget *parent = nullptr); + +public slots: + void addSeries(); + void removeSeries(); + void connectMarkers(); + void disconnectMarkers(); + void handleMarkerClicked(); + +private: + QChart *m_chart = nullptr; + QChartView *m_chartView = nullptr; + QGridLayout *m_mainLayout = nullptr; + QGridLayout *m_fontLayout = nullptr; + QList<QLineSeries *> m_series; +}; + +#endif diff --git a/examples/charts/legend/mainwidget.cpp b/examples/charts/gallery/legendwidget.cpp index 8506c75a..da5d3587 100644 --- a/examples/charts/legend/mainwidget.cpp +++ b/examples/charts/gallery/legendwidget.cpp @@ -1,149 +1,161 @@ -// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "mainwidget.h" -#include <QtCharts/QChart> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSet> -#include <QtCharts/QBarSeries> -#include <QtCharts/QLegend> -#include <QtWidgets/QGridLayout> -#include <QtWidgets/QFormLayout> -#include <QtWidgets/QGroupBox> -#include <QtWidgets/QCheckBox> -#include <QtWidgets/QPushButton> -#include <QtWidgets/QDoubleSpinBox> - -QT_USE_NAMESPACE - -MainWidget::MainWidget(QWidget *parent) : - QWidget(parent) +#include "legendwidget.h" + +#include <QBarSet> +#include <QBarSeries> +#include <QChart> +#include <QChartView> +#include <QCheckBox> +#include <QDoubleSpinBox> +#include <QFormLayout> +#include <QGraphicsLayout> +#include <QGridLayout> +#include <QGroupBox> +#include <QLegend> +#include <QPushButton> + +LegendWidget::LegendWidget(QWidget *parent) + : ContentWidget(parent) { // Create chart view with the chart - m_chart = new QChart(); + m_chart = new QChart; m_chartView = new QChartView(m_chart, this); - m_chart->setTitle("Legend detach example"); + m_chart->setTitle("Legend Options"); createUi(); - connect(m_toggleAttachedButton, &QPushButton::clicked, this, &MainWidget::toggleAttached); - connect(m_interactiveButton, &QPushButton::clicked, this, &MainWidget::toggleInteractive); - connect(m_boldButton, &QPushButton::clicked, this, &MainWidget::toggleBold); - connect(m_italicButton, &QPushButton::clicked, this, &MainWidget::toggleItalic); - connect(m_addSetButton, &QPushButton::clicked, this, &MainWidget::addBarset); - connect(m_removeSetButton, &QPushButton::clicked, this, &MainWidget::removeBarset); - connect(m_alignmentButton, &QPushButton::clicked, this, &MainWidget::setLegendAlignment); + connect(m_toggleAttachedButton, &QPushButton::clicked, this, &LegendWidget::toggleAttached); + connect(m_interactiveButton, &QPushButton::clicked, this, &LegendWidget::toggleInteractive); + connect(m_boldButton, &QPushButton::clicked, this, &LegendWidget::toggleBold); + connect(m_italicButton, &QPushButton::clicked, this, &LegendWidget::toggleItalic); + connect(m_addSetButton, &QPushButton::clicked, this, &LegendWidget::addBarset); + connect(m_removeSetButton, &QPushButton::clicked, this, &LegendWidget::removeBarset); + connect(m_alignmentButton, &QPushButton::clicked, this, &LegendWidget::setLegendAlignment); connect(m_fontSize, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::fontSizeChanged); + this, &LegendWidget::fontSizeChanged); connect(m_legendPosX, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateLegendLayout); + this, &LegendWidget::updateLegendLayout); connect(m_legendPosY, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateLegendLayout); + this, &LegendWidget::updateLegendLayout); connect(m_legendWidth, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateLegendLayout); + this, &LegendWidget::updateLegendLayout); connect(m_legendHeight, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateLegendLayout); + this, &LegendWidget::updateLegendLayout); QLegend *legend = m_chart->legend(); legend->setShowToolTips(true); legend->setBrush(QBrush(QColor(128, 128, 128, 128))); legend->setPen(QPen(QColor(192, 192, 192, 192))); -//![5] + //![5] legend->setInteractive(true); -//![5] + //![5] -//![4] + //![4] connect(legend, &QLegend::attachedToChartChanged, [legend, this](bool attachedToChart) { m_toggleAttachedButton->setChecked(attachedToChart); legend->setBackgroundVisible(!attachedToChart); m_geometrySettings->setDisabled(attachedToChart); }); -//![4] - connect(legend, &QGraphicsWidget::geometryChanged, this, &MainWidget::updateLegendSpinbox); + //![4] + connect(legend, &QGraphicsWidget::geometryChanged, this, &LegendWidget::updateLegendSpinbox); createSeries(); m_chart->createDefaultAxes(); -//![1] + //![1] m_chart->legend()->setVisible(true); m_chart->legend()->setAlignment(Qt::AlignBottom); -//![1] + //![1] m_chartView->setRenderHint(QPainter::Antialiasing); + m_chart->layout()->setContentsMargins(0, 0, 0, 0); } -void MainWidget::createUi() +void LegendWidget::resizeEvent(QResizeEvent *) +{ + QRectF chartViewRect = m_chartView->rect(); + m_legendPosX->setMaximum(chartViewRect.width()); + m_legendPosY->setMaximum(chartViewRect.height()); + m_legendWidth->setMaximum(chartViewRect.width()); + m_legendHeight->setMaximum(chartViewRect.height()); +} + +void LegendWidget::createUi() { QLegend *legend = m_chart->legend(); // Create buttons for ui - QGridLayout *buttonLayout = new QGridLayout(); - m_toggleAttachedButton = new QCheckBox("Attached"); + auto buttonLayout = new QGridLayout; + m_toggleAttachedButton = new QCheckBox("Attached", this); m_toggleAttachedButton->setChecked(true); buttonLayout->addWidget(m_toggleAttachedButton, 0, 0); - m_interactiveButton = new QCheckBox("Interactive"); + m_interactiveButton = new QCheckBox("Interactive", this); m_interactiveButton->setChecked(true); buttonLayout->addWidget(m_interactiveButton, 1, 0); - m_boldButton = new QCheckBox("Bold"); + m_boldButton = new QCheckBox("Bold", this); buttonLayout->addWidget(m_boldButton, 2, 0); - m_italicButton = new QCheckBox("Italic"); + m_italicButton = new QCheckBox("Italic", this); buttonLayout->addWidget(m_italicButton, 3, 0); - m_addSetButton = new QPushButton("Add Barset"); + m_addSetButton = new QPushButton("Add Barset", this); buttonLayout->addWidget(m_addSetButton, 4, 0); - m_removeSetButton = new QPushButton("Remove Barset"); + m_removeSetButton = new QPushButton("Remove Barset", this); buttonLayout->addWidget(m_removeSetButton, 5, 0); - m_alignmentButton = new QPushButton("Align (Bottom)"); + m_alignmentButton = new QPushButton("Align (Bottom)", this); buttonLayout->addWidget(m_alignmentButton, 6, 0); buttonLayout->setRowStretch(7, 1); - m_legendPosX = new QDoubleSpinBox(); - m_legendPosY = new QDoubleSpinBox(); - m_legendWidth = new QDoubleSpinBox(); - m_legendHeight = new QDoubleSpinBox(); + m_legendPosX = new QDoubleSpinBox(this); + m_legendPosY = new QDoubleSpinBox(this); + m_legendWidth = new QDoubleSpinBox(this); + m_legendHeight = new QDoubleSpinBox(this); - QFormLayout *legendLayout = new QFormLayout(); + auto legendLayout = new QFormLayout; legendLayout->addRow("HPos", m_legendPosX); legendLayout->addRow("VPos", m_legendPosY); legendLayout->addRow("Width", m_legendWidth); legendLayout->addRow("Height", m_legendHeight); - m_geometrySettings = new QGroupBox("Detached legend"); + m_geometrySettings = new QGroupBox("Detached legend", this); m_geometrySettings->setLayout(legendLayout); buttonLayout->addWidget(m_geometrySettings, 8, 0); m_geometrySettings->setDisabled(true); // Create spinbox to modify font size - m_fontSize = new QDoubleSpinBox(); + m_fontSize = new QDoubleSpinBox(this); QFont lfont = legend->font(); lfont.setPointSizeF(12.0); legend->setFont(lfont); m_fontSize->setValue(legend->font().pointSizeF()); + m_fontSize->setMinimum(1.); - QFormLayout *fontLayout = new QFormLayout(); + auto fontLayout = new QFormLayout; fontLayout->addRow("Legend font size", m_fontSize); // Create layout for grid and detached legend - QGridLayout *mainLayout = new QGridLayout(); + auto mainLayout = new QGridLayout; + mainLayout->setHorizontalSpacing(10); mainLayout->addLayout(buttonLayout, 0, 0); mainLayout->addLayout(fontLayout, 1, 0); mainLayout->addWidget(m_chartView, 0, 1, 3, 1); setLayout(mainLayout); } -void MainWidget::createSeries() +void LegendWidget::createSeries() { - m_series = new QBarSeries(); + m_series = new QBarSeries; addBarset(); addBarset(); addBarset(); @@ -152,7 +164,7 @@ void MainWidget::createSeries() m_chart->addSeries(m_series); } -void MainWidget::updateLegendSpinbox() +void LegendWidget::updateLegendSpinbox() { QLegend *legend = m_chart->legend(); double newPosX = legend->x(); @@ -169,7 +181,7 @@ void MainWidget::updateLegendSpinbox() } -void MainWidget::toggleAttached() +void LegendWidget::toggleAttached() { QLegend *legend = m_chart->legend(); if (legend->isAttachedToChart()) { @@ -184,34 +196,34 @@ void MainWidget::toggleAttached() update(); } -void MainWidget::toggleInteractive() +void LegendWidget::toggleInteractive() { m_chart->legend()->setInteractive(!m_chart->legend()->isInteractive()); } -void MainWidget::toggleBold() +void LegendWidget::toggleBold() { QFont font = m_chart->legend()->font(); font.setBold(!font.bold()); m_chart->legend()->setFont(font); } -void MainWidget::toggleItalic() +void LegendWidget::toggleItalic() { QFont font = m_chart->legend()->font(); font.setItalic(!font.italic()); m_chart->legend()->setFont(font); } -void MainWidget::addBarset() +void LegendWidget::addBarset() { - QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count())); + auto barSet = new QBarSet(QString("set ") + QString::number(m_series->count())); qreal delta = m_series->count() * 0.1; *barSet << 1 + delta << 2 + delta << 3 + delta << 4 + delta; m_series->append(barSet); } -void MainWidget::removeBarset() +void LegendWidget::removeBarset() { QList<QBarSet *> sets = m_series->barSets(); if (sets.count() > 0) { @@ -219,9 +231,9 @@ void MainWidget::removeBarset() } } -void MainWidget::setLegendAlignment() +void LegendWidget::setLegendAlignment() { - QPushButton *button = qobject_cast<QPushButton *>(sender()); + auto button = qobject_cast<QPushButton *>(sender()); switch (m_chart->legend()->alignment()) { case Qt::AlignTop: @@ -247,14 +259,14 @@ void MainWidget::setLegendAlignment() } } -void MainWidget::fontSizeChanged() +void LegendWidget::fontSizeChanged() { QFont font = m_chart->legend()->font(); font.setPointSizeF(m_fontSize->value()); m_chart->legend()->setFont(font); } -void MainWidget::updateLegendLayout() +void LegendWidget::updateLegendLayout() { //![6] QRectF geom = m_chart->legend()->geometry(); @@ -271,12 +283,3 @@ void MainWidget::updateLegendLayout() m_chart->legend()->update(); //![6] } - -void MainWidget::resizeEvent(QResizeEvent *) -{ - QRectF chartViewRect = m_chartView->rect(); - m_legendPosX->setMaximum(chartViewRect.width()); - m_legendPosY->setMaximum(chartViewRect.height()); - m_legendWidth->setMaximum(chartViewRect.width()); - m_legendHeight->setMaximum(chartViewRect.height()); -} diff --git a/examples/charts/legend/mainwidget.h b/examples/charts/gallery/legendwidget.h index 84235902..2ca128be 100644 --- a/examples/charts/legend/mainwidget.h +++ b/examples/charts/gallery/legendwidget.h @@ -1,30 +1,29 @@ -// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef MAINWIDGET_H -#define MAINWIDGET_H +#ifndef LEGENDWIDGET_H +#define LEGENDWIDGET_H -#include <QtWidgets/QWidget> -#include <QtCharts/QChart> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSeries> -#include <QtWidgets/QCheckBox> -#include <QtWidgets/QPushButton> -#include <QtWidgets/QDoubleSpinBox> -#include <QtWidgets/QGroupBox> +#include "contentwidget.h" -QT_USE_NAMESPACE +#include <QBarSeries> +#include <QChart> +#include <QChartView> +#include <QCheckBox> +#include <QDoubleSpinBox> +#include <QGroupBox> +#include <QPushButton> -class MainWidget : public QWidget +class LegendWidget : public ContentWidget { Q_OBJECT public: - explicit MainWidget(QWidget *parent = nullptr); + explicit LegendWidget(QWidget *parent = nullptr); void createUi(); void createSeries(); void updateLegendSpinbox(); -public Q_SLOTS: +public slots: void toggleAttached(); void toggleInteractive(); void toggleBold(); @@ -59,4 +58,4 @@ private: QDoubleSpinBox *m_legendHeight; }; -#endif // MAINWIDGET_H +#endif diff --git a/examples/charts/gallery/lightmarkerswidget.cpp b/examples/charts/gallery/lightmarkerswidget.cpp new file mode 100644 index 00000000..ddb9b759 --- /dev/null +++ b/examples/charts/gallery/lightmarkerswidget.cpp @@ -0,0 +1,211 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "lightmarkerswidget.h" + +#include <QBrush> +#include <QChart> +#include <QChartView> +#include <QCheckBox> +#include <QComboBox> +#include <QGraphicsLayout> +#include <QGridLayout> +#include <QHBoxLayout> +#include <QLabel> +#include <QList> +#include <QPainter> +#include <QPainterPath> +#include <QSplineSeries> + +LightMarkersWidget::LightMarkersWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + constexpr qreal marker_size = 20.; + + auto series = new QSplineSeries; + series->append({QPointF(0., 0.), + QPointF(0.5, 2.27), + QPointF(1.5, 2.2), + QPointF(3.3, 1.7), + QPointF(4.23, 3.1), + QPointF(5.3, 2.3), + QPointF(6.47, 4.1) + }); + series->setMarkerSize(marker_size); + series->setLightMarker(rectangle(marker_size, Qt::red)); + series->setSelectedLightMarker(blueTriangle(marker_size)); + + QObject::connect(series, &QXYSeries::clicked, series, [=](const QPointF &point) { + int index = series->points().indexOf(point); + if (index != -1) + series->toggleSelection({index}); + }); + //![1] + + //![2] + auto chart = new QChart; + chart->addSeries(series); + chart->createDefaultAxes(); + chart->legend()->setVisible(false); + chart->layout()->setContentsMargins(0, 0, 0, 0); + chart->setTitle("Select points with mouse click"); + + auto chartView = new QChartView(chart, this); + chartView->setRenderHint(QPainter::Antialiasing); + + auto controlWidget = new QWidget(this); + auto controlLayout = new QGridLayout(controlWidget); + //![2] + + //![3] + auto charPointCombobox = new QComboBox(controlWidget); + auto charPointSelectedCombobox = new QComboBox(controlWidget); + auto lineColorCombobox = new QComboBox(controlWidget); + auto showUnselectedPointsCheckbox = new QCheckBox(controlWidget); + //![3] + + //![4] + auto charPoint = new QLabel(tr("Char point: "), controlWidget); + charPointCombobox->addItems({tr("Red rectangle"), + tr("Green triangle"), + tr("Orange circle") + }); + QObject::connect(charPointCombobox, &QComboBox::currentIndexChanged, series, [=](const int index) { + if (showUnselectedPointsCheckbox->isChecked()) + series->setLightMarker(getPointRepresentation(PointType(index), marker_size)); + }); + //![4] + + //![5] + auto charPointSelected = new QLabel(tr("Char point selected: "), controlWidget); + charPointSelectedCombobox->addItems({tr("Blue triangle"), + tr("Yellow rectangle"), + tr("Lavender circle") + }); + QObject::connect(charPointSelectedCombobox, &QComboBox::currentIndexChanged, series, [=](const int index) { + series->setSelectedLightMarker(getSelectedPointRepresentation(SelectedPointType(index), marker_size)); + }); + + auto lineColorLabel = new QLabel(tr("Line color: "), controlWidget); + lineColorCombobox->addItems({tr("Blue"), + tr("Black"), + tr("Mint") + }); + QObject::connect(lineColorCombobox, &QComboBox::currentIndexChanged, series, [=](const int index) { + series->setColor(makeLineColor(LineColor(index))); + }); + //![5] + + //![6] + auto showUnselectedPointsLabel = new QLabel(tr("Display unselected points: "), controlWidget); + showUnselectedPointsCheckbox->setChecked(true); + QObject::connect(showUnselectedPointsCheckbox, &QCheckBox::stateChanged, series, [=](const int state) { + if (state) + series->setLightMarker(getPointRepresentation(PointType(charPointCombobox->currentIndex()), marker_size)); + else + series->setLightMarker(QImage()); + }); + //![6] + + //![7] + controlLayout->addWidget(charPoint, 0, 0); + controlLayout->addWidget(charPointCombobox, 0, 1); + + controlLayout->addWidget(charPointSelected, 1, 0); + controlLayout->addWidget(charPointSelectedCombobox, 1, 1); + + controlLayout->addWidget(lineColorLabel, 2, 0); + controlLayout->addWidget(lineColorCombobox, 2, 1); + + controlLayout->addWidget(showUnselectedPointsLabel, 3, 0); + controlLayout->addWidget(showUnselectedPointsCheckbox, 3, 1, 1, 2); + + m_mainWidget = new QWidget(this); + auto mainLayout = new QHBoxLayout(m_mainWidget); + mainLayout->addWidget(chartView); + mainLayout->addWidget(controlWidget); + //![7] +} + +void LightMarkersWidget::resizeEvent(QResizeEvent *) +{ + m_mainWidget->resize(size()); +} + +QImage LightMarkersWidget::rectangle(qreal imageSize, const QColor &color) +{ + QImage image(imageSize, imageSize, QImage::Format_RGB32); + QPainter painter; + painter.begin(&image); + painter.fillRect(0, 0, imageSize, imageSize, color); + painter.end(); + return image; +} + +QImage LightMarkersWidget::circle(qreal imageSize, const QColor &color) +{ + QImage image(imageSize, imageSize, QImage::Format_ARGB32); + image.fill(QColor(0, 0, 0, 0)); + QPainter paint; + paint.begin(&image); + paint.setBrush(color); + QPen pen = paint.pen(); + pen.setWidth(0); + paint.setPen(pen); + paint.drawEllipse(0, 0, imageSize * 0.9, imageSize * 0.9); + paint.end(); + return image; +} + +QImage LightMarkersWidget::blueTriangle(qreal imageSize) +{ + return QImage(":/blue_triangle").scaled(imageSize, imageSize); +} + +QImage LightMarkersWidget::greenTriangle(qreal imageSize) +{ + return QImage(":/green_triangle").scaled(imageSize, imageSize); +} + +QImage LightMarkersWidget::getPointRepresentation(PointType pointType, int imageSize) +{ + switch (pointType) { + case PointType::RedRectangle: + return rectangle(imageSize, Qt::red); + case PointType::GreenTriangle: + return greenTriangle(imageSize); + case PointType::OrangeCircle: + return circle(imageSize, QColor(255, 127, 80)); + default: + return rectangle(imageSize, Qt::red); + } +} + +QImage LightMarkersWidget::getSelectedPointRepresentation(SelectedPointType pointType, int imageSize) +{ + switch (pointType) { + case SelectedPointType::BlueTriangle: + return blueTriangle(imageSize); + case SelectedPointType::YellowRectangle: + return rectangle(imageSize, Qt::yellow); + case SelectedPointType::LavenderCircle: + return circle(imageSize, QColor(147, 112, 219)); + default: + return blueTriangle(imageSize); + } +} + +QColor LightMarkersWidget::makeLineColor(LineColor lineColor) +{ + switch (lineColor) { + case LineColor::Blue: + return QColor(65, 105, 225); + case LineColor::Black: + return QColor(0, 0, 0); + case LineColor::Mint: + return QColor(70, 203, 155); + default: + return QColor(0, 0, 0); + } +} diff --git a/examples/charts/pointsselectionandmarkers/utilities.h b/examples/charts/gallery/lightmarkerswidget.h index b0c4eb2f..9add2b77 100644 --- a/examples/charts/pointsselectionandmarkers/utilities.h +++ b/examples/charts/gallery/lightmarkerswidget.h @@ -1,13 +1,26 @@ -// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef UTILITIES_H -#define UTILITIES_H +#ifndef LIGHTMARKERSWIDGET_H +#define LIGHTMARKERSWIDGET_H +#include "contentwidget.h" + +#include <QColor> #include <QImage> -namespace Utilities +QT_FORWARD_DECLARE_CLASS(QChartView) + +class LightMarkersWidget : public ContentWidget { + Q_OBJECT +public: + explicit LightMarkersWidget(QWidget *parent = nullptr); + +protected: + void resizeEvent(QResizeEvent *) override; + +private: enum class PointType { RedRectangle, GreenTriangle, @@ -26,15 +39,15 @@ namespace Utilities Mint }; - QImage redRectangle(qreal imageSize); - QImage yellowRectangle(qreal imageSize); + QImage rectangle(qreal imageSize, const QColor &color); + QImage circle(qreal imageSize, const QColor &color); QImage blueTriangle(qreal imageSize); QImage greenTriangle(qreal imageSize); - QImage orangeCircle(qreal imageSize); - QImage lavenderCircle(qreal imageSize); QImage getPointRepresentation(PointType pointType, int imageSize); QImage getSelectedPointRepresentation(SelectedPointType pointType, int imageSize); QColor makeLineColor(LineColor lineColor); -} -#endif // UTILITIES_H + QWidget *m_mainWidget = nullptr; +}; + +#endif diff --git a/examples/charts/lineandbar/main.cpp b/examples/charts/gallery/lineandbarwidget.cpp index 1e3e35c5..49d1cfa1 100644 --- a/examples/charts/lineandbar/main.cpp +++ b/examples/charts/gallery/lineandbarwidget.cpp @@ -1,47 +1,44 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLineSeries> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QValueAxis> +#include "lineandbarwidget.h" -QT_USE_NAMESPACE +#include <QBarCategoryAxis> +#include <QBarSeries> +#include <QBarSet> +#include <QChart> +#include <QLegend> +#include <QLineSeries> +#include <QValueAxis> -int main(int argc, char *argv[]) +LineAndBarWidget::LineAndBarWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); - -//![1] - QBarSet *set0 = new QBarSet("Jane"); - QBarSet *set1 = new QBarSet("John"); - QBarSet *set2 = new QBarSet("Axel"); - QBarSet *set3 = new QBarSet("Mary"); - QBarSet *set4 = new QBarSet("Sam"); + //![1] + auto set0 = new QBarSet("Jane"); + auto set1 = new QBarSet("John"); + auto set2 = new QBarSet("Axel"); + auto set3 = new QBarSet("Mary"); + auto set4 = new QBarSet("Sam"); *set0 << 1 << 2 << 3 << 4 << 5 << 6; *set1 << 5 << 0 << 0 << 4 << 0 << 7; *set2 << 3 << 5 << 8 << 13 << 8 << 5; *set3 << 5 << 6 << 7 << 3 << 4 << 5; *set4 << 9 << 7 << 5 << 3 << 1 << 2; -//![1] + //![1] -//![2] - QBarSeries *barseries = new QBarSeries(); + //![2] + auto barseries = new QBarSeries; barseries->append(set0); barseries->append(set1); barseries->append(set2); barseries->append(set3); barseries->append(set4); -//![2] + //![2] -//![8] - QLineSeries *lineseries = new QLineSeries(); + //![8] + auto lineseries = new QLineSeries; lineseries->setName("trend"); lineseries->append(QPoint(0, 4)); lineseries->append(QPoint(1, 15)); @@ -49,48 +46,38 @@ int main(int argc, char *argv[]) lineseries->append(QPoint(3, 4)); lineseries->append(QPoint(4, 12)); lineseries->append(QPoint(5, 17)); -//![8] + //![8] -//![3] - QChart *chart = new QChart(); + //![3] + auto chart = new QChart; chart->addSeries(barseries); chart->addSeries(lineseries); - chart->setTitle("Line and barchart example"); -//![3] + chart->setTitle("Line and Bar Chart"); + //![3] -//![4] + //![4] QStringList categories; categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - QBarCategoryAxis *axisX = new QBarCategoryAxis(); + auto axisX = new QBarCategoryAxis; axisX->append(categories); chart->addAxis(axisX, Qt::AlignBottom); lineseries->attachAxis(axisX); barseries->attachAxis(axisX); axisX->setRange(QString("Jan"), QString("Jun")); - QValueAxis *axisY = new QValueAxis(); + auto axisY = new QValueAxis; chart->addAxis(axisY, Qt::AlignLeft); lineseries->attachAxis(axisY); barseries->attachAxis(axisY); axisY->setRange(0, 20); -//![4] + //![4] -//![5] + //![5] chart->legend()->setVisible(true); chart->legend()->setAlignment(Qt::AlignBottom); -//![5] - -//![6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![6] - -//![7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(440, 300); - window.show(); -//![7] + //![5] - return a.exec(); + //![6] + createDefaultChartView(chart); + //![6] } diff --git a/examples/charts/gallery/lineandbarwidget.h b/examples/charts/gallery/lineandbarwidget.h new file mode 100644 index 00000000..53f64bee --- /dev/null +++ b/examples/charts/gallery/lineandbarwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef LINEANDBARWIDGET_H +#define LINEANDBARWIDGET_H + +#include "contentwidget.h" + +class LineAndBarWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit LineAndBarWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/linewidget.cpp b/examples/charts/gallery/linewidget.cpp new file mode 100644 index 00000000..5bbc9304 --- /dev/null +++ b/examples/charts/gallery/linewidget.cpp @@ -0,0 +1,36 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "linewidget.h" + +#include <QChart> +#include <QLineSeries> + +LineWidget::LineWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto series = new QLineSeries; + //![1] + + //![2] + series->append(0, 6); + series->append(2, 4); + series->append(3, 8); + series->append(7, 4); + series->append(10, 5); + *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); + //![2] + + //![3] + auto chart = new QChart; + chart->legend()->hide(); + chart->addSeries(series); + chart->createDefaultAxes(); + chart->setTitle("Simple Line Chart"); + //![3] + + //![4] + createDefaultChartView(chart); + //![4] +} diff --git a/examples/charts/gallery/linewidget.h b/examples/charts/gallery/linewidget.h new file mode 100644 index 00000000..a4022463 --- /dev/null +++ b/examples/charts/gallery/linewidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef LINEWIDGET_H +#define LINEWIDGET_H + +#include "contentwidget.h" + +class LineWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit LineWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/logaxiswidget.cpp b/examples/charts/gallery/logaxiswidget.cpp new file mode 100644 index 00000000..ce72b2ce --- /dev/null +++ b/examples/charts/gallery/logaxiswidget.cpp @@ -0,0 +1,47 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "logaxiswidget.h" + +#include <QChart> +#include <QLineSeries> +#include <QLogValueAxis> +#include <QValueAxis> + +LogAxisWidget::LogAxisWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto series = new QLineSeries; + *series << QPointF(1.0, 1.0) << QPointF(2.0, 73.0) << QPointF(3.0, 268.0) << QPointF(4.0, 17.0) + << QPointF(5.0, 4325.0) << QPointF(6.0, 723.0); + //![1] + + //![2] + auto chart = new QChart; + chart->addSeries(series); + chart->legend()->hide(); + chart->setTitle("Logarithmic Axis"); + //![2] + + //![3] + auto axisX = new QValueAxis; + axisX->setTitleText("Data point"); + axisX->setLabelFormat("%i"); + axisX->setTickCount(series->count()); + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + + auto axisY = new QLogValueAxis; + axisY->setTitleText("Values"); + axisY->setLabelFormat("%g"); + axisY->setBase(8.0); + axisY->setMinorTickCount(-1); + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisY); + //![3] + + //![4] + createDefaultChartView(chart); + //![4] +} diff --git a/examples/charts/gallery/logaxiswidget.h b/examples/charts/gallery/logaxiswidget.h new file mode 100644 index 00000000..860107ee --- /dev/null +++ b/examples/charts/gallery/logaxiswidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef LOGAXISWIDGET_H +#define LOGAXISWIDGET_H + +#include "contentwidget.h" + +class LogAxisWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit LogAxisWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/legendmarkers/main.cpp b/examples/charts/gallery/main.cpp index f4848268..b6f7acae 100644 --- a/examples/charts/legendmarkers/main.cpp +++ b/examples/charts/gallery/main.cpp @@ -1,17 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "mainwidget.h" -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> +#include <QApplication> +#include <QListView> +#include <QStringListModel> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWidget w; - w.resize(720, 480); w.show(); return a.exec(); diff --git a/examples/charts/gallery/mainwidget.cpp b/examples/charts/gallery/mainwidget.cpp new file mode 100644 index 00000000..cb535217 --- /dev/null +++ b/examples/charts/gallery/mainwidget.cpp @@ -0,0 +1,262 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include "areawidget.h" +#include "boxplotwidget.h" +#include "barmodelmapperwidget.h" +#include "barwidget.h" +#include "barpercentwidget.h" +#include "barstackedwidget.h" +#include "calloutwidget.h" +#include "candlestickwidget.h" +#include "contentwidget.h" +#include "customchartwidget.h" +#include "datetimeaxiswidget.h" +#include "donutbreakdownwidget.h" +#include "donutwidget.h" +#include "dynamicsplinewidget.h" +#include "horizontalbarwidget.h" +#include "horizontalpercentbarwidget.h" +#include "horizontalstackedbarwidget.h" +#include "interactionswidget.h" +#include "legendwidget.h" +#include "legendmarkerswidget.h" +#include "lightmarkerswidget.h" +#include "lineandbarwidget.h" +#include "linewidget.h" +#include "logaxiswidget.h" +#include "mainwidget.h" +#include "modeldatawidget.h" +#include "multiaxiswidget.h" +#include "nesteddonutswidget.h" +#include "pccwidget.h" +#include "piewidget.h" +#include "piedrilldownwidget.h" +#include "pointconfigurationwidget.h" +#include "polarchartwidget.h" +#include "scatterwidget.h" +#include "scatterinteractionswidget.h" +#include "selectedbarwidget.h" +#include "splinewidget.h" +#include "stackeddrilldownwidget.h" +#include "temperaturerecordswidget.h" +#include "themewidget.h" + +#include <QApplication> +#include <QHBoxLayout> +#include <QListView> +#include <QModelIndex> +#include <QStringListModel> + +#include <algorithm> + +MainWidget::MainWidget(QWidget *parent) + : QWidget(parent) + , m_listView(new QListView(this)) + , m_listModel(new QStringListModel(this)) + , m_contentArea(new QWidget(this)) +{ + m_exampleMap.insert(tr("Area Chart"), AreaChart); + m_exampleMap.insert(tr("Bar Model Mapper"), BarModelMapper); + m_exampleMap.insert(tr("Bar Chart"), BarChart); + m_exampleMap.insert(tr("Bar Chart Percent"), BarChartPercent); + m_exampleMap.insert(tr("Bar Chart Stacked"), BarChartStacked); + m_exampleMap.insert(tr("Bar Chart Horizontal"), BarChartHorizontal); + m_exampleMap.insert(tr("Bar Chart Percent Horizontal"), BarChartHorizontalPercent); + m_exampleMap.insert(tr("Bar Chart Stacked Horizontal"), BarChartHorizontalStacked); + m_exampleMap.insert(tr("Box Plot Chart"), BoxPlotChart); + m_exampleMap.insert(tr("Callout"), Callout); + m_exampleMap.insert(tr("Candlestick Chart"), CandleStickChart); + m_exampleMap.insert(tr("Chart Interactions"), ChartInteractions); + m_exampleMap.insert(tr("Chart Themes"), ChartThemes); + m_exampleMap.insert(tr("Custom Chart"), CustomChart); + m_exampleMap.insert(tr("Datetime Axis"), DateTimeAxis); + m_exampleMap.insert(tr("Donut"), Donut); + m_exampleMap.insert(tr("Donut Breakdown"), DonutBreakdown); + m_exampleMap.insert(tr("Drilldown Bar Chart"), StackedDrilldown); + m_exampleMap.insert(tr("Drilldown Pie Chart"), PieDrilldown); + m_exampleMap.insert(tr("Dynamic Spline Chart"), DynamicSplineChart); + m_exampleMap.insert(tr("Legend"), Legend); + m_exampleMap.insert(tr("Legend Markers"), LegendMarkers); + m_exampleMap.insert(tr("Light Markers and Point Selection"), LightMarkersPointSelection); + m_exampleMap.insert(tr("Line and Bar Chart"), LineAndBarChart); + m_exampleMap.insert(tr("Line Chart"), LineChart); + m_exampleMap.insert(tr("Log Axis"), LogAxis); + m_exampleMap.insert(tr("Model Data"), ModelData); + m_exampleMap.insert(tr("Multiple Axes"), MultiAxis); + m_exampleMap.insert(tr("Nested Donuts"), NestedDonuts); + m_exampleMap.insert(tr("Pie Chart Customization"), PieChartCustomization); + m_exampleMap.insert(tr("Pie Chart"), PieChart); + m_exampleMap.insert(tr("Point Configuration"), PointConfiguration); + m_exampleMap.insert(tr("Polar Chart"), PolarChart); + m_exampleMap.insert(tr("Scatter Interactions"), ScatterInteractions); + m_exampleMap.insert(tr("Scatter Chart"), ScatterChart); + m_exampleMap.insert(tr("Selected Bar"), SelectedBar); + m_exampleMap.insert(tr("Spline Chart"), SplineChart); + m_exampleMap.insert(tr("Temperature Records"), TemperatureRecords); + + QStringList examples = m_exampleMap.keys(); + std::sort(examples.begin(), examples.end()); + m_listModel->setStringList(examples); + + m_listView->setMaximumWidth(220); + m_listView->setModel(m_listModel); + m_listView->setCurrentIndex(m_listModel->index(0)); + m_listView->setEditTriggers(QAbstractItemView::NoEditTriggers); + + setMinimumSize(800, 400); + resize(1200, 600); + + auto layout = new QHBoxLayout(this); + layout->addWidget(m_listView); + layout->addWidget(m_contentArea); + setLayout(layout); + + connect(m_listView->selectionModel(), &QItemSelectionModel::currentChanged, this, + [this](const QModelIndex &index) { + setActiveExample(m_exampleMap[m_listModel->data(index).toString()]); + }); + + setActiveExample(m_exampleMap[examples[0]]); + + setMouseTracking(true); + + qApp->setApplicationDisplayName(tr("Qt Charts Example Gallery")); +} + +void MainWidget::resizeEvent(QResizeEvent *) +{ + m_activeWidget->resize(m_contentArea->size()); +} + +void MainWidget::setActiveExample(Example example) +{ + // We only keep one example alive at the time to save resources. + // This also allows resetting the example by switching to another example and back. + if (m_activeWidget) { + m_activeWidget->setVisible(false); + m_activeWidget->deleteLater(); + } + + switch (example) { + case AreaChart: + m_activeWidget = new AreaWidget(m_contentArea); + break; + case BarModelMapper: + m_activeWidget = new BarModelMapperWidget(m_contentArea); + break; + case BarChart: + m_activeWidget = new BarWidget(m_contentArea); + break; + case BarChartPercent: + m_activeWidget = new BarPercentWidget(m_contentArea); + break; + case BarChartStacked: + m_activeWidget = new BarStackedWidget(m_contentArea); + break; + case BarChartHorizontal: + m_activeWidget = new HorizontalBarWidget(m_contentArea); + break; + case BarChartHorizontalPercent: + m_activeWidget = new HorizontalPercentBarWidget(m_contentArea); + break; + case BarChartHorizontalStacked: + m_activeWidget = new HorizontalStackedBarWidget(m_contentArea); + break; + case BoxPlotChart: + m_activeWidget = new BoxPlotWidget(m_contentArea); + break; + case Callout: + m_activeWidget = new CalloutWidget(m_contentArea); + break; + case CandleStickChart: + m_activeWidget = new CandleStickWidget(m_contentArea); + break; + case ChartInteractions: + m_activeWidget = new InteractionsWidget(m_contentArea); + break; + case ChartThemes: + m_activeWidget = new ThemeWidget(m_contentArea); + break; + case CustomChart: + m_activeWidget = new CustomChartWidget(m_contentArea); + break; + case DateTimeAxis: + m_activeWidget = new DateTimeAxisWidget(m_contentArea); + break; + case Donut: + m_activeWidget = new DonutWidget(m_contentArea); + break; + case DonutBreakdown: + m_activeWidget = new DonutBreakdownWidget(m_contentArea); + break; + case DynamicSplineChart: + m_activeWidget = new DynamicSplineWidget(m_contentArea); + break; + case Legend: + m_activeWidget = new LegendWidget(m_contentArea); + break; + case LegendMarkers: + m_activeWidget = new LegendMarkersWidget(m_contentArea); + break; + case LightMarkersPointSelection: + m_activeWidget = new LightMarkersWidget(m_contentArea); + break; + case LineAndBarChart: + m_activeWidget = new LineAndBarWidget(m_contentArea); + break; + case LineChart: + m_activeWidget = new LineWidget(m_contentArea); + break; + case LogAxis: + m_activeWidget = new LogAxisWidget(m_contentArea); + break; + case ModelData: + m_activeWidget = new ModelDataWidget(m_contentArea); + break; + case MultiAxis: + m_activeWidget = new MultiAxisWidget(m_contentArea); + break; + case NestedDonuts: + m_activeWidget = new NestedDonutsWidget(m_contentArea); + break; + case PieChartCustomization: + m_activeWidget = new PccWidget(m_contentArea); + break; + case PieDrilldown: + m_activeWidget = new PieDrilldownWidget(m_contentArea); + break; + case PieChart: + m_activeWidget = new PieWidget(m_contentArea); + break; + case PointConfiguration: + m_activeWidget = new PointConfigurationWidget(m_contentArea); + break; + case PolarChart: + m_activeWidget = new PolarChartWidget(m_contentArea); + break; + case ScatterInteractions: + m_activeWidget = new ScatterInteractionsWidget(m_contentArea); + break; + case ScatterChart: + m_activeWidget = new ScatterWidget(m_contentArea); + break; + case SelectedBar: + m_activeWidget = new SelectedBarWidget(m_contentArea); + break; + case SplineChart: + m_activeWidget = new SplineWidget(m_contentArea); + break; + case TemperatureRecords: + m_activeWidget = new TemperatureRecordsWidget(m_contentArea); + break; + case StackedDrilldown: + m_activeWidget = new StackedDrilldownWidget(m_contentArea); + break; + } + + m_activeWidget->load(); + m_activeWidget->resize(m_contentArea->size()); + m_activeWidget->setVisible(true); +} diff --git a/examples/charts/gallery/mainwidget.h b/examples/charts/gallery/mainwidget.h new file mode 100644 index 00000000..8082812c --- /dev/null +++ b/examples/charts/gallery/mainwidget.h @@ -0,0 +1,75 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include <QHash> +#include <QWidget> + +QT_FORWARD_DECLARE_CLASS(QListView) +QT_FORWARD_DECLARE_CLASS(QStringListModel) + +class ContentWidget; + +class MainWidget : public QWidget +{ + Q_OBJECT +public: + explicit MainWidget(QWidget *parent = nullptr); + +protected: + void resizeEvent(QResizeEvent *) override; + +private: + enum Example { + AreaChart, + BarModelMapper, + BarChart, + BarChartPercent, + BarChartStacked, + BarChartHorizontal, + BarChartHorizontalPercent, + BarChartHorizontalStacked, + BoxPlotChart, + Callout, + CandleStickChart, + ChartInteractions, + ChartThemes, + CustomChart, + DateTimeAxis, + Donut, + DonutBreakdown, + DynamicSplineChart, + Legend, + LegendMarkers, + LightMarkersPointSelection, + LineAndBarChart, + LineChart, + LogAxis, + ModelData, + MultiAxis, + NestedDonuts, + PieChartCustomization, + PieDrilldown, + PieChart, + PointConfiguration, + PolarChart, + ScatterChart, + ScatterInteractions, + SelectedBar, + SplineChart, + StackedDrilldown, + TemperatureRecords + }; + + void setActiveExample(Example example); + + QListView *m_listView = nullptr; + QStringListModel *m_listModel = nullptr; + QWidget *m_contentArea = nullptr; + ContentWidget *m_activeWidget = nullptr; + QHash<QString, Example> m_exampleMap; +}; + +#endif diff --git a/examples/charts/modeldata/customtablemodel.cpp b/examples/charts/gallery/modeldatamodel.cpp index 461282ce..af5bc9dd 100644 --- a/examples/charts/modeldata/customtablemodel.cpp +++ b/examples/charts/gallery/modeldatamodel.cpp @@ -1,13 +1,14 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "customtablemodel.h" -#include <QtCore/QList> -#include <QtCore/QRandomGenerator> -#include <QtCore/QRect> -#include <QtGui/QColor> +#include "modeldatamodel.h" -CustomTableModel::CustomTableModel(QObject *parent) : +#include <QColor> +#include <QList> +#include <QRandomGenerator> +#include <QRect> + +ModelDataModel::ModelDataModel(QObject *parent) : QAbstractTableModel(parent) { m_columnCount = 4; @@ -15,7 +16,7 @@ CustomTableModel::CustomTableModel(QObject *parent) : // m_data for (int i = 0; i < m_rowCount; i++) { - QList<qreal> *dataList = new QList<qreal>(m_columnCount); + auto dataList = new QList<qreal>(m_columnCount); for (int k = 0; k < dataList->size(); k++) { if (k % 2 == 0) dataList->replace(k, i * 50 + QRandomGenerator::global()->bounded(20)); @@ -26,19 +27,19 @@ CustomTableModel::CustomTableModel(QObject *parent) : } } -int CustomTableModel::rowCount(const QModelIndex &parent) const +int ModelDataModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return m_data.count(); } -int CustomTableModel::columnCount(const QModelIndex &parent) const +int ModelDataModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); return m_columnCount; } -QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const +QVariant ModelDataModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) return QVariant(); @@ -53,7 +54,7 @@ QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, } } -QVariant CustomTableModel::data(const QModelIndex &index, int role) const +QVariant ModelDataModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { return m_data[index.row()]->at(index.column()); @@ -70,7 +71,7 @@ QVariant CustomTableModel::data(const QModelIndex &index, int role) const return QVariant(); } -bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role) +bool ModelDataModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.isValid() && role == Qt::EditRole) { m_data[index.row()]->replace(index.column(), value.toDouble()); @@ -80,12 +81,12 @@ bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, return false; } -Qt::ItemFlags CustomTableModel::flags(const QModelIndex &index) const +Qt::ItemFlags ModelDataModel::flags(const QModelIndex &index) const { return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; } -void CustomTableModel::addMapping(QString color, QRect area) +void ModelDataModel::addMapping(const QString &color, const QRect &area) { m_mapping.insert(color, area); } diff --git a/examples/charts/barmodelmapper/customtablemodel.h b/examples/charts/gallery/modeldatamodel.h index a4a40171..e8b2e1d1 100644 --- a/examples/charts/barmodelmapper/customtablemodel.h +++ b/examples/charts/gallery/modeldatamodel.h @@ -1,19 +1,18 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef CUSTOMTABLEMODEL_H -#define CUSTOMTABLEMODEL_H +#ifndef MODELDATAMODEL_H +#define MODELDATAMODEL_H -#include <QtCore/QAbstractTableModel> -#include <QtCore/QMultiHash> -#include <QtCore/QRect> +#include <QAbstractTableModel> +#include <QMultiHash> +#include <QRect> -class CustomTableModel : public QAbstractTableModel +class ModelDataModel : public QAbstractTableModel { Q_OBJECT public: - explicit CustomTableModel(QObject *parent = 0); - virtual ~CustomTableModel(); + explicit ModelDataModel(QObject *parent = nullptr); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -22,7 +21,7 @@ public: bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); Qt::ItemFlags flags(const QModelIndex &index) const; - void addMapping(QString color, QRect area); + void addMapping(const QString &color, const QRect &area); void clearMapping() { m_mapping.clear(); } private: @@ -32,4 +31,4 @@ private: int m_rowCount; }; -#endif // CUSTOMTABLEMODEL_H +#endif diff --git a/examples/charts/modeldata/tablewidget.cpp b/examples/charts/gallery/modeldatawidget.cpp index a397083d..20d50aa6 100644 --- a/examples/charts/modeldata/tablewidget.cpp +++ b/examples/charts/gallery/modeldatawidget.cpp @@ -1,45 +1,46 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "tablewidget.h" -#include "customtablemodel.h" -#include <QtWidgets/QGridLayout> -#include <QtWidgets/QTableView> -#include <QtCharts/QChart> -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCharts/QVXYModelMapper> -#include <QtWidgets/QHeaderView> +#include "modeldatawidget.h" +#include "modeldatamodel.h" + +#include <QChart> +#include <QChartView> +#include <QGraphicsLayout> +#include <QGridLayout> +#include <QHeaderView> +#include <QLineSeries> +#include <QTableView> +#include <QVXYModelMapper> QT_USE_NAMESPACE -TableWidget::TableWidget(QWidget *parent) - : QWidget(parent) +ModelDataWidget::ModelDataWidget(QWidget *parent) + : ContentWidget(parent) { - // create simple model for storing data - // user's table data model + // create simple model for storing user's data //! [1] - CustomTableModel *model = new CustomTableModel; + auto *model = new ModelDataModel; //! [1] //! [2] // create table view and add model to it - QTableView *tableView = new QTableView; + auto tableView = new QTableView; tableView->setModel(model); tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); //! [2] //! [3] - QChart *chart = new QChart; + auto chart = new QChart; chart->setAnimationOptions(QChart::AllAnimations); //! [3] // series 1 //! [4] - QLineSeries *series = new QLineSeries; + auto series = new QLineSeries; series->setName("Line 1"); - QVXYModelMapper *mapper = new QVXYModelMapper(this); + auto mapper = new QVXYModelMapper(this); mapper->setXColumn(0); mapper->setYColumn(1); mapper->setSeries(series); @@ -56,7 +57,6 @@ TableWidget::TableWidget(QWidget *parent) model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount())); //! [5] - // series 2 //! [6] series = new QLineSeries; @@ -78,14 +78,14 @@ TableWidget::TableWidget(QWidget *parent) //! [8] chart->createDefaultAxes(); - QChartView *chartView = new QChartView(chart); + chart->layout()->setContentsMargins(0, 0, 0, 0); + auto chartView = new QChartView(chart, this); chartView->setRenderHint(QPainter::Antialiasing); - chartView->setMinimumSize(640, 480); //! [8] //! [9] // create main layout - QGridLayout *mainLayout = new QGridLayout; + auto mainLayout = new QGridLayout; mainLayout->addWidget(tableView, 1, 0); mainLayout->addWidget(chartView, 1, 1); mainLayout->setColumnStretch(1, 1); diff --git a/examples/charts/gallery/modeldatawidget.h b/examples/charts/gallery/modeldatawidget.h new file mode 100644 index 00000000..245e6267 --- /dev/null +++ b/examples/charts/gallery/modeldatawidget.h @@ -0,0 +1,17 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef MODELDATAWIDGET_H +#define MODELDATAWIDGET_H + +#include "contentwidget.h" + +class ModelDataWidget : public ContentWidget +{ + Q_OBJECT + +public: + ModelDataWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/multiaxis/main.cpp b/examples/charts/gallery/multiaxiswidget.cpp index c5b43b55..1979a59e 100644 --- a/examples/charts/multiaxis/main.cpp +++ b/examples/charts/gallery/multiaxiswidget.cpp @@ -1,38 +1,35 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCharts/QSplineSeries> -#include <QtCharts/QValueAxis> -#include <QtCharts/QCategoryAxis> +#include "multiaxiswidget.h" -QT_USE_NAMESPACE +#include <QCategoryAxis> +#include <QChart> +#include <QLineSeries> +#include <QSplineSeries> +#include <QValueAxis> -int main(int argc, char *argv[]) +MultiAxisWidget::MultiAxisWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); - //![1] - QChart *chart = new QChart(); + auto chart = new QChart; chart->legend()->hide(); - chart->setTitle("Multiaxis chart example"); + chart->setTitle("Multiple Vertical Axes in Chart"); //![1] //![2] - QValueAxis *axisX = new QValueAxis; + auto axisX = new QValueAxis; axisX->setTickCount(10); chart->addAxis(axisX, Qt::AlignBottom); //![2] //![3] - QSplineSeries *series = new QSplineSeries; + auto series = new QSplineSeries; *series << QPointF(1, 5) << QPointF(3.5, 18) << QPointF(4.8, 7.5) << QPointF(10, 2.5); chart->addSeries(series); - QValueAxis *axisY = new QValueAxis; + auto axisY = new QValueAxis; axisY->setLinePenColor(series->pen().color()); chart->addAxis(axisY, Qt::AlignLeft); @@ -46,7 +43,7 @@ int main(int argc, char *argv[]) << QPointF(5.2, 3.5) << QPointF(7.4, 16.5) << QPointF(8.3, 7.5) << QPointF(10, 17); chart->addSeries(series); - QCategoryAxis *axisY3 = new QCategoryAxis; + auto axisY3 = new QCategoryAxis; axisY3->append("Low", 5); axisY3->append("Medium", 12); axisY3->append("High", 17); @@ -59,17 +56,6 @@ int main(int argc, char *argv[]) //![4] //![5] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); + createDefaultChartView(chart); //![5] - - //![6] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(800, 600); - window.show(); - //![6] - - return a.exec(); } - diff --git a/examples/charts/gallery/multiaxiswidget.h b/examples/charts/gallery/multiaxiswidget.h new file mode 100644 index 00000000..e61cc368 --- /dev/null +++ b/examples/charts/gallery/multiaxiswidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef MULTIAXISWIDGET_H +#define MULTIAXISWIDGET_H + +#include "contentwidget.h" + +class MultiAxisWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit MultiAxisWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/nesteddonuts/widget.cpp b/examples/charts/gallery/nesteddonutswidget.cpp index 6d6ddffa..25c103c9 100644 --- a/examples/charts/nesteddonuts/widget.cpp +++ b/examples/charts/gallery/nesteddonutswidget.cpp @@ -1,29 +1,29 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "widget.h" -#include <QtCharts/QChartView> -#include <QtCharts/QChart> -#include <QtCharts/QLegend> -#include <QtCharts/QPieSeries> -#include <QtCharts/QPieSlice> -#include <QtCore/QRandomGenerator> -#include <QtWidgets/QGridLayout> -#include <QtCore/QTimer> -QT_USE_NAMESPACE +#include "nesteddonutswidget.h" -Widget::Widget(QWidget *parent) - : QWidget(parent) -{ - setMinimumSize(800, 600); +#include <QChart> +#include <QChartView> +#include <QGraphicsLayout> +#include <QGridLayout> +#include <QLegend> +#include <QPieSeries> +#include <QPieSlice> +#include <QRandomGenerator> +#include <QTimer> +NestedDonutsWidget::NestedDonutsWidget(QWidget *parent) + : ContentWidget(parent) +{ //! [1] - QChartView *chartView = new QChartView; + auto chartView = new QChartView(this); chartView->setRenderHint(QPainter::Antialiasing); QChart *chart = chartView->chart(); chart->legend()->setVisible(false); - chart->setTitle("Nested donuts demo"); + chart->setTitle("Nested Donuts (Hover over segments to explode them)"); chart->setAnimationOptions(QChart::AllAnimations); + chart->layout()->setContentsMargins(0, 0, 0, 0); //! [1] //! [2] @@ -34,15 +34,15 @@ Widget::Widget(QWidget *parent) //! [3] for (int i = 0; i < donutCount; i++) { - QPieSeries *donut = new QPieSeries; + auto donut = new QPieSeries; int sliceCount = 3 + QRandomGenerator::global()->bounded(3); for (int j = 0; j < sliceCount; j++) { qreal value = 100 + QRandomGenerator::global()->bounded(100); - QPieSlice *slice = new QPieSlice(QString("%1").arg(value), value); + auto slice = new QPieSlice(QString("%1").arg(value), value); slice->setLabelVisible(true); slice->setLabelColor(Qt::white); slice->setLabelPosition(QPieSlice::LabelInsideTangential); - connect(slice, &QPieSlice::hovered, this, &Widget::explodeSlice); + connect(slice, &QPieSlice::hovered, this, &NestedDonutsWidget::explodeSlice); donut->append(slice); donut->setHoleSize(minSize + i * (maxSize - minSize) / donutCount); donut->setPieSize(minSize + (i + 1) * (maxSize - minSize) / donutCount); @@ -54,25 +54,20 @@ Widget::Widget(QWidget *parent) // create main layout //! [4] - QGridLayout *mainLayout = new QGridLayout; + auto mainLayout = new QGridLayout; mainLayout->addWidget(chartView, 1, 1); setLayout(mainLayout); //! [4] //! [5] - updateTimer = new QTimer(this); - connect(updateTimer, &QTimer::timeout, this, &Widget::updateRotation); - updateTimer->start(1250); + m_updateTimer = new QTimer(this); + connect(m_updateTimer, &QTimer::timeout, this, &NestedDonutsWidget::updateRotation); + m_updateTimer->start(1250); //! [5] } -Widget::~Widget() -{ - -} - //! [6] -void Widget::updateRotation() +void NestedDonutsWidget::updateRotation() { for (int i = 0; i < m_donuts.count(); i++) { QPieSeries *donut = m_donuts.at(i); @@ -84,11 +79,11 @@ void Widget::updateRotation() //! [6] //! [7] -void Widget::explodeSlice(bool exploded) +void NestedDonutsWidget::explodeSlice(bool exploded) { - QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); + auto slice = qobject_cast<QPieSlice *>(sender()); if (exploded) { - updateTimer->stop(); + m_updateTimer->stop(); qreal sliceStartAngle = slice->startAngle(); qreal sliceEndAngle = slice->startAngle() + slice->angleSpan(); @@ -103,7 +98,7 @@ void Widget::explodeSlice(bool exploded) m_donuts.at(i)->setPieStartAngle(0); m_donuts.at(i)->setPieEndAngle(360); } - updateTimer->start(); + m_updateTimer->start(); } slice->setExploded(exploded); } diff --git a/examples/charts/gallery/nesteddonutswidget.h b/examples/charts/gallery/nesteddonutswidget.h new file mode 100644 index 00000000..7dfc95c1 --- /dev/null +++ b/examples/charts/gallery/nesteddonutswidget.h @@ -0,0 +1,27 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef NESTEDDONUTSWIDGET_H +#define NESTEDDONUTSWIDGET_H + +#include "contentwidget.h" + +QT_FORWARD_DECLARE_CLASS(QTimer) +QT_FORWARD_DECLARE_CLASS(QPieSeries) + +class NestedDonutsWidget : public ContentWidget +{ + Q_OBJECT +public: + NestedDonutsWidget(QWidget *parent = nullptr); + +public slots: + void updateRotation(); + void explodeSlice(bool exploded); + +private: + QList<QPieSeries *> m_donuts; + QTimer *m_updateTimer = nullptr; +}; + +#endif diff --git a/examples/charts/piechartcustomization/brushtool.cpp b/examples/charts/gallery/pccbrushtool.cpp index 7bac155d..63cdf0c3 100644 --- a/examples/charts/piechartcustomization/brushtool.cpp +++ b/examples/charts/gallery/pccbrushtool.cpp @@ -1,12 +1,14 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "brushtool.h" -#include <QtWidgets/QPushButton> -#include <QtWidgets/QFormLayout> -#include <QtWidgets/QComboBox> -#include <QtWidgets/QColorDialog> -BrushTool::BrushTool(QString title, QWidget *parent) +#include "pccbrushtool.h" + +#include <QColorDialog> +#include <QComboBox> +#include <QFormLayout> +#include <QPushButton> + +PccBrushTool::PccBrushTool(const QString &title, QWidget *parent) : QWidget(parent) { setWindowTitle(title); @@ -30,39 +32,38 @@ BrushTool::BrushTool(QString title, QWidget *parent) m_styleCombo->addItem("FDiagPattern", (int) Qt::FDiagPattern); m_styleCombo->addItem("DiagCrossPattern", (int) Qt::DiagCrossPattern); - QFormLayout *layout = new QFormLayout(); + auto layout = new QFormLayout; layout->addRow("Color", m_colorButton); layout->addRow("Style", m_styleCombo); setLayout(layout); - connect(m_colorButton, &QPushButton::clicked, this, &BrushTool::showColorDialog); - connect(m_styleCombo, &QComboBox::currentIndexChanged, - this, &BrushTool::updateStyle); + connect(m_colorButton, &QPushButton::clicked, this, &PccBrushTool::showColorDialog); + connect(m_styleCombo, &QComboBox::currentIndexChanged, this, &PccBrushTool::updateStyle); } -void BrushTool::setBrush(QBrush brush) +void PccBrushTool::setBrush(const QBrush &brush) { m_brush = brush; m_colorButton->setText(m_brush.color().name()); m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum } -QBrush BrushTool::brush() const +QBrush PccBrushTool::brush() const { return m_brush; } -QString BrushTool::name() +QString PccBrushTool::name() const { return name(m_brush); } -QString BrushTool::name(const QBrush &brush) +QString PccBrushTool::name(const QBrush &brush) { return brush.color().name(); } -void BrushTool::showColorDialog() +void PccBrushTool::showColorDialog() { QColorDialog dialog(m_brush.color()); dialog.show(); @@ -72,7 +73,7 @@ void BrushTool::showColorDialog() emit changed(); } -void BrushTool::updateStyle() +void PccBrushTool::updateStyle() { Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt(); if (m_brush.style() != style) { @@ -80,5 +81,3 @@ void BrushTool::updateStyle() emit changed(); } } - -#include "moc_brushtool.cpp" diff --git a/examples/charts/gallery/pccbrushtool.h b/examples/charts/gallery/pccbrushtool.h new file mode 100644 index 00000000..2e392b6a --- /dev/null +++ b/examples/charts/gallery/pccbrushtool.h @@ -0,0 +1,37 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef PCCBRUSHTOOL_H +#define PCCBRUSHTOOL_H + +#include <QBrush> +#include <QWidget> + +QT_FORWARD_DECLARE_CLASS(QComboBox) +QT_FORWARD_DECLARE_CLASS(QPushButton) + +class PccBrushTool : public QWidget +{ + Q_OBJECT + +public: + explicit PccBrushTool(const QString &title, QWidget *parent = nullptr); + void setBrush(const QBrush &brush); + QBrush brush() const; + QString name() const; + static QString name(const QBrush &brush); + +signals: + void changed(); + +public slots: + void showColorDialog(); + void updateStyle(); + +private: + QBrush m_brush; + QPushButton *m_colorButton = nullptr; + QComboBox *m_styleCombo = nullptr; +}; + +#endif diff --git a/examples/charts/piechartcustomization/customslice.cpp b/examples/charts/gallery/pcccustomslice.cpp index 574498ce..6b4857b6 100644 --- a/examples/charts/piechartcustomization/customslice.cpp +++ b/examples/charts/gallery/pcccustomslice.cpp @@ -1,22 +1,20 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "customslice.h" +#include "pcccustomslice.h" -QT_USE_NAMESPACE - -CustomSlice::CustomSlice(QString label, qreal value) +PccCustomSlice::PccCustomSlice(const QString &label, qreal value) : QPieSlice(label, value) { - connect(this, &CustomSlice::hovered, this, &CustomSlice::showHighlight); + connect(this, &PccCustomSlice::hovered, this, &PccCustomSlice::showHighlight); } -QBrush CustomSlice::originalBrush() +QBrush PccCustomSlice::originalBrush() { return m_originalBrush; } -void CustomSlice::showHighlight(bool show) +void PccCustomSlice::showHighlight(bool show) { if (show) { QBrush brush = this->brush(); @@ -27,5 +25,3 @@ void CustomSlice::showHighlight(bool show) setBrush(m_originalBrush); } } - -#include "moc_customslice.cpp" diff --git a/examples/charts/gallery/pcccustomslice.h b/examples/charts/gallery/pcccustomslice.h new file mode 100644 index 00000000..b7ab879e --- /dev/null +++ b/examples/charts/gallery/pcccustomslice.h @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef PCCCUSTOMSLICE_H +#define PCCCUSTOMSLICE_H + +#include <QPieSlice> + +class PccCustomSlice : public QPieSlice +{ + Q_OBJECT +public: + PccCustomSlice(const QString &label, qreal value); + +public: + QBrush originalBrush(); + +public slots: + void showHighlight(bool show); + +private: + QBrush m_originalBrush; +}; + +#endif diff --git a/examples/charts/piechartcustomization/pentool.cpp b/examples/charts/gallery/pccpentool.cpp index 56033b1b..11bb1d76 100644 --- a/examples/charts/piechartcustomization/pentool.cpp +++ b/examples/charts/gallery/pccpentool.cpp @@ -1,24 +1,25 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "pentool.h" -#include <QtWidgets/QPushButton> -#include <QtWidgets/QDoubleSpinBox> -#include <QtWidgets/QComboBox> -#include <QtWidgets/QFormLayout> -#include <QtWidgets/QColorDialog> +#include "pccpentool.h" -PenTool::PenTool(QString title, QWidget *parent) +#include <QColorDialog> +#include <QComboBox> +#include <QDoubleSpinBox> +#include <QFormLayout> +#include <QPushButton> + +PccPenTool::PccPenTool(const QString &title, QWidget *parent) : QWidget(parent) { setWindowTitle(title); setWindowFlags(Qt::Tool); - m_colorButton = new QPushButton(); + m_colorButton = new QPushButton(this); - m_widthSpinBox = new QDoubleSpinBox(); + m_widthSpinBox = new QDoubleSpinBox(this); - m_styleCombo = new QComboBox(); + m_styleCombo = new QComboBox(this); m_styleCombo->addItem("NoPen"); m_styleCombo->addItem("SolidLine"); m_styleCombo->addItem("DashLine"); @@ -26,18 +27,18 @@ PenTool::PenTool(QString title, QWidget *parent) m_styleCombo->addItem("DashDotLine"); m_styleCombo->addItem("DashDotDotLine"); - m_capStyleCombo = new QComboBox(); + m_capStyleCombo = new QComboBox(this); m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); - m_joinStyleCombo = new QComboBox(); + m_joinStyleCombo = new QComboBox(this); m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); - QFormLayout *layout = new QFormLayout(); + auto layout = new QFormLayout; layout->addRow("Color", m_colorButton); layout->addRow("Width", m_widthSpinBox); layout->addRow("Style", m_styleCombo); @@ -46,18 +47,14 @@ PenTool::PenTool(QString title, QWidget *parent) setLayout(layout); // Use old style connect on some signals because the signal is overloaded - connect(m_colorButton, &QPushButton::clicked, this, &PenTool::showColorDialog); - connect(m_widthSpinBox, &QDoubleSpinBox::valueChanged, - this, &PenTool::updateWidth); - connect(m_styleCombo, &QComboBox::currentIndexChanged, - this, &PenTool::updateStyle); - connect(m_capStyleCombo, &QComboBox::currentIndexChanged, - this, &PenTool::updateCapStyle); - connect(m_joinStyleCombo, &QComboBox::currentIndexChanged, - this, &PenTool::updateJoinStyle); + connect(m_colorButton, &QPushButton::clicked, this, &PccPenTool::showColorDialog); + connect(m_widthSpinBox, &QDoubleSpinBox::valueChanged, this, &PccPenTool::updateWidth); + connect(m_styleCombo, &QComboBox::currentIndexChanged, this, &PccPenTool::updateStyle); + connect(m_capStyleCombo, &QComboBox::currentIndexChanged, this, &PccPenTool::updateCapStyle); + connect(m_joinStyleCombo, &QComboBox::currentIndexChanged, this, &PccPenTool::updateJoinStyle); } -void PenTool::setPen(const QPen &pen) +void PccPenTool::setPen(const QPen &pen) { m_pen = pen; m_colorButton->setText(m_pen.color().name()); @@ -67,22 +64,22 @@ void PenTool::setPen(const QPen &pen) m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); } -QPen PenTool::pen() const +QPen PccPenTool::pen() const { return m_pen; } -QString PenTool::name() +QString PccPenTool::name() const { return name(m_pen); } -QString PenTool::name(const QPen &pen) +QString PccPenTool::name(const QPen &pen) { return pen.color().name() + ":" + QString::number(pen.widthF()); } -void PenTool::showColorDialog() +void PccPenTool::showColorDialog() { QColorDialog dialog(m_pen.color()); dialog.show(); @@ -92,7 +89,7 @@ void PenTool::showColorDialog() emit changed(); } -void PenTool::updateWidth(double width) +void PccPenTool::updateWidth(double width) { if (!qFuzzyCompare((qreal) width, m_pen.widthF())) { m_pen.setWidthF(width); @@ -100,7 +97,7 @@ void PenTool::updateWidth(double width) } } -void PenTool::updateStyle(int style) +void PccPenTool::updateStyle(int style) { if (m_pen.style() != style) { m_pen.setStyle((Qt::PenStyle) style); @@ -108,7 +105,7 @@ void PenTool::updateStyle(int style) } } -void PenTool::updateCapStyle(int index) +void PccPenTool::updateCapStyle(int index) { Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); if (m_pen.capStyle() != capStyle) { @@ -117,7 +114,7 @@ void PenTool::updateCapStyle(int index) } } -void PenTool::updateJoinStyle(int index) +void PccPenTool::updateJoinStyle(int index) { Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); if (m_pen.joinStyle() != joinStyle) { @@ -125,5 +122,3 @@ void PenTool::updateJoinStyle(int index) emit changed(); } } - -#include "moc_pentool.cpp" diff --git a/examples/charts/piechartcustomization/pentool.h b/examples/charts/gallery/pccpentool.h index ce8f4189..14a48c89 100644 --- a/examples/charts/piechartcustomization/pentool.h +++ b/examples/charts/gallery/pccpentool.h @@ -1,32 +1,30 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef PENTOOL_H -#define PENTOOL_H -#include <QtWidgets/QWidget> -#include <QtGui/QPen> +#ifndef PCCPENTOOL_H +#define PCCPENTOOL_H -QT_BEGIN_NAMESPACE -class QPushButton; -class QDoubleSpinBox; -class QComboBox; -QT_END_NAMESPACE +#include <QPen> +#include <QWidget> -class PenTool : public QWidget +QT_FORWARD_DECLARE_CLASS(QComboBox); +QT_FORWARD_DECLARE_CLASS(QDoubleSpinBox); +QT_FORWARD_DECLARE_CLASS(QPushButton); + +class PccPenTool : public QWidget { Q_OBJECT - public: - explicit PenTool(QString title, QWidget *parent = 0); + explicit PccPenTool(const QString &title, QWidget *parent = nullptr); void setPen(const QPen &pen); QPen pen() const; - QString name(); + QString name() const; static QString name(const QPen &pen); -Q_SIGNALS: +signals: void changed(); -public Q_SLOTS: +public slots: void showColorDialog(); void updateWidth(double width); void updateStyle(int style); @@ -42,4 +40,4 @@ private: QComboBox *m_joinStyleCombo; }; -#endif // PENTOOL_H +#endif diff --git a/examples/charts/piechartcustomization/mainwidget.cpp b/examples/charts/gallery/pccwidget.cpp index 819f5cf8..2f2e0e02 100644 --- a/examples/charts/piechartcustomization/mainwidget.cpp +++ b/examples/charts/gallery/pccwidget.cpp @@ -1,45 +1,46 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "mainwidget.h" -#include "customslice.h" -#include "pentool.h" -#include "brushtool.h" -#include <QtWidgets/QPushButton> -#include <QtWidgets/QComboBox> -#include <QtWidgets/QCheckBox> -#include <QtWidgets/QLineEdit> -#include <QtWidgets/QGroupBox> -#include <QtWidgets/QDoubleSpinBox> -#include <QtWidgets/QFormLayout> -#include <QtWidgets/QFontDialog> -#include <QtCharts/QChartView> -#include <QtCharts/QPieSeries> - -QT_USE_NAMESPACE - -MainWidget::MainWidget(QWidget *parent) - : QWidget(parent), - m_slice(0) + +#include "pccbrushtool.h" +#include "pcccustomslice.h" +#include "pccwidget.h" +#include "pccpentool.h" + +#include <QChartView> +#include <QCheckBox> +#include <QComboBox> +#include <QDoubleSpinBox> +#include <QFontDialog> +#include <QFormLayout> +#include <QGraphicsLayout> +#include <QGroupBox> +#include <QLineEdit> +#include <QPieSeries> +#include <QPushButton> + +PccWidget::PccWidget(QWidget *parent) + : ContentWidget(parent) { // create chart - QChart *chart = new QChart; - chart->setTitle("Piechart customization"); + auto chart = new QChart; + chart->setTitle("Pie Chart Customization"); chart->setAnimationOptions(QChart::AllAnimations); + chart->layout()->setContentsMargins(0, 0, 0, 0); // create series - m_series = new QPieSeries(); - *m_series << new CustomSlice("Slice 1", 10.0); - *m_series << new CustomSlice("Slice 2", 20.0); - *m_series << new CustomSlice("Slice 3", 30.0); - *m_series << new CustomSlice("Slice 4", 40.0); - *m_series << new CustomSlice("Slice 5", 50.0); + m_series = new QPieSeries; + *m_series << new PccCustomSlice("Slice 1", 10.0); + *m_series << new PccCustomSlice("Slice 2", 20.0); + *m_series << new PccCustomSlice("Slice 3", 30.0); + *m_series << new PccCustomSlice("Slice 4", 40.0); + *m_series << new PccCustomSlice("Slice 5", 50.0); m_series->setLabelsVisible(); chart->addSeries(m_series); - connect(m_series, &QPieSeries::clicked, this, &MainWidget::handleSliceClicked); + connect(m_series, &QPieSeries::clicked, this, &PccWidget::handleSliceClicked); // chart settings - m_themeComboBox = new QComboBox(); + m_themeComboBox = new QComboBox(this); m_themeComboBox->addItem("Light", QChart::ChartThemeLight); m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean); m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); @@ -49,71 +50,70 @@ MainWidget::MainWidget(QWidget *parent) m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); m_themeComboBox->addItem("Qt", QChart::ChartThemeQt); - m_aaCheckBox = new QCheckBox(); - m_animationsCheckBox = new QCheckBox(); + m_aaCheckBox = new QCheckBox(this); + m_animationsCheckBox = new QCheckBox(this); m_animationsCheckBox->setCheckState(Qt::Checked); - m_legendCheckBox = new QCheckBox(); + m_legendCheckBox = new QCheckBox(this); - settingsScrollBar = new QScrollArea(); - QWidget *settingsContentWidget = new QWidget(); + m_settingsScrollBar = new QScrollArea(this); + auto settingsContentWidget = new QWidget(this); - QFormLayout *chartSettingsLayout = new QFormLayout(settingsContentWidget); + auto chartSettingsLayout = new QFormLayout(settingsContentWidget); chartSettingsLayout->addRow("Theme", m_themeComboBox); chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); chartSettingsLayout->addRow("Animations", m_animationsCheckBox); chartSettingsLayout->addRow("Legend", m_legendCheckBox); - QGroupBox *chartSettings = new QGroupBox("Chart"); + auto chartSettings = new QGroupBox("Chart", this); chartSettings->setLayout(chartSettingsLayout); - connect(m_themeComboBox, &QComboBox::currentIndexChanged, - this, &MainWidget::updateChartSettings); - connect(m_aaCheckBox, &QCheckBox::toggled, this, &MainWidget::updateChartSettings); - connect(m_animationsCheckBox, &QCheckBox::toggled, this, &MainWidget::updateChartSettings); - connect(m_legendCheckBox, &QCheckBox::toggled, this, &MainWidget::updateChartSettings); + connect(m_themeComboBox, &QComboBox::currentIndexChanged, this, &PccWidget::updateChartSettings); + connect(m_aaCheckBox, &QCheckBox::toggled, this, &PccWidget::updateChartSettings); + connect(m_animationsCheckBox, &QCheckBox::toggled, this, &PccWidget::updateChartSettings); + connect(m_legendCheckBox, &QCheckBox::toggled, this, &PccWidget::updateChartSettings); // series settings - m_hPosition = new QDoubleSpinBox(); + m_hPosition = new QDoubleSpinBox(this); m_hPosition->setMinimum(0.0); m_hPosition->setMaximum(1.0); m_hPosition->setSingleStep(0.1); m_hPosition->setValue(m_series->horizontalPosition()); - m_vPosition = new QDoubleSpinBox(); + m_vPosition = new QDoubleSpinBox(this); m_vPosition->setMinimum(0.0); m_vPosition->setMaximum(1.0); m_vPosition->setSingleStep(0.1); m_vPosition->setValue(m_series->verticalPosition()); - m_sizeFactor = new QDoubleSpinBox(); + m_sizeFactor = new QDoubleSpinBox(this); m_sizeFactor->setMinimum(0.0); m_sizeFactor->setMaximum(1.0); m_sizeFactor->setSingleStep(0.1); m_sizeFactor->setValue(m_series->pieSize()); - m_startAngle = new QDoubleSpinBox(); + m_startAngle = new QDoubleSpinBox(this); m_startAngle->setMinimum(-720); m_startAngle->setMaximum(720); m_startAngle->setValue(m_series->pieStartAngle()); m_startAngle->setSingleStep(1); - m_endAngle = new QDoubleSpinBox(); + m_endAngle = new QDoubleSpinBox(this); m_endAngle->setMinimum(-720); m_endAngle->setMaximum(720); m_endAngle->setValue(m_series->pieEndAngle()); m_endAngle->setSingleStep(1); - m_holeSize = new QDoubleSpinBox(); + m_holeSize = new QDoubleSpinBox(this); m_holeSize->setMinimum(0.0); m_holeSize->setMaximum(1.0); m_holeSize->setSingleStep(0.1); m_holeSize->setValue(m_series->holeSize()); - QPushButton *appendSlice = new QPushButton("Append slice"); - QPushButton *insertSlice = new QPushButton("Insert slice"); - QPushButton *removeSlice = new QPushButton("Remove selected slice"); + auto appendSlice = new QPushButton("Append slice", this); + auto insertSlice = new QPushButton("Insert slice", this); + auto removeSlice = new QPushButton("Remove selected slice", this); - QFormLayout *seriesSettingsLayout = new QFormLayout(settingsContentWidget); + auto seriesSettingsLayout = new QFormLayout(settingsContentWidget); seriesSettingsLayout->addRow("Horizontal position", m_hPosition); seriesSettingsLayout->addRow("Vertical position", m_vPosition); seriesSettingsLayout->addRow("Size factor", m_sizeFactor); @@ -123,56 +123,56 @@ MainWidget::MainWidget(QWidget *parent) seriesSettingsLayout->addRow(appendSlice); seriesSettingsLayout->addRow(insertSlice); seriesSettingsLayout->addRow(removeSlice); - QGroupBox *seriesSettings = new QGroupBox("Series"); + auto seriesSettings = new QGroupBox("Series", this); seriesSettings->setLayout(seriesSettingsLayout); connect(m_vPosition, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateSerieSettings); + this, &PccWidget::updateSerieSettings); connect(m_hPosition, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateSerieSettings); + this, &PccWidget::updateSerieSettings); connect(m_sizeFactor, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateSerieSettings); + this, &PccWidget::updateSerieSettings); connect(m_startAngle, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateSerieSettings); + this, &PccWidget::updateSerieSettings); connect(m_endAngle, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateSerieSettings); + this, &PccWidget::updateSerieSettings); connect(m_holeSize, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateSerieSettings); - connect(appendSlice, &QPushButton::clicked, this, &MainWidget::appendSlice); - connect(insertSlice, &QPushButton::clicked, this, &MainWidget::insertSlice); - connect(removeSlice, &QPushButton::clicked, this, &MainWidget::removeSlice); + this, &PccWidget::updateSerieSettings); + connect(appendSlice, &QPushButton::clicked, this, &PccWidget::appendSlice); + connect(insertSlice, &QPushButton::clicked, this, &PccWidget::insertSlice); + connect(removeSlice, &QPushButton::clicked, this, &PccWidget::removeSlice); // slice settings - m_sliceName = new QLineEdit("<click a slice>"); + m_sliceName = new QLineEdit("<click a slice>", this); m_sliceName->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); - m_sliceValue = new QDoubleSpinBox(); + m_sliceValue = new QDoubleSpinBox(this); m_sliceValue->setMaximum(1000); - m_sliceLabelVisible = new QCheckBox(); - m_sliceLabelArmFactor = new QDoubleSpinBox(); + m_sliceLabelVisible = new QCheckBox(this); + m_sliceLabelArmFactor = new QDoubleSpinBox(this); m_sliceLabelArmFactor->setSingleStep(0.01); - m_sliceExploded = new QCheckBox(); - m_sliceExplodedFactor = new QDoubleSpinBox(); + m_sliceExploded = new QCheckBox(this); + m_sliceExplodedFactor = new QDoubleSpinBox(this); m_sliceExplodedFactor->setSingleStep(0.01); - m_pen = new QPushButton(); - m_penTool = new PenTool("Slice pen", this); - m_brush = new QPushButton(); - m_brushTool = new BrushTool("Slice brush", this); - m_font = new QPushButton(); - m_labelBrush = new QPushButton(); - m_labelBrushTool = new BrushTool("Label brush", this); + m_pen = new QPushButton(this); + m_penTool = new PccPenTool("Slice pen", this); + m_brush = new QPushButton(this); + m_brushTool = new PccBrushTool("Slice brush", this); + m_font = new QPushButton(this); + m_labelBrush = new QPushButton(this); + m_labelBrushTool = new PccBrushTool("Label brush", this); m_labelPosition = new QComboBox(this); m_labelPosition->addItem("Outside", QPieSlice::LabelOutside); m_labelPosition->addItem("Inside horizontal", QPieSlice::LabelInsideHorizontal); m_labelPosition->addItem("Inside tangential", QPieSlice::LabelInsideTangential); m_labelPosition->addItem("Inside normal", QPieSlice::LabelInsideNormal); - QFormLayout *sliceSettingsLayout = new QFormLayout(settingsContentWidget); + auto sliceSettingsLayout = new QFormLayout(settingsContentWidget); sliceSettingsLayout->addRow("Label", m_sliceName); sliceSettingsLayout->addRow("Value", m_sliceValue); sliceSettingsLayout->addRow("Pen", m_pen); @@ -184,61 +184,60 @@ MainWidget::MainWidget(QWidget *parent) sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); sliceSettingsLayout->addRow("Exploded", m_sliceExploded); sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); - QGroupBox *sliceSettings = new QGroupBox("Selected slice"); + auto sliceSettings = new QGroupBox("Selected slice", this); sliceSettings->setLayout(sliceSettingsLayout); sliceSettings->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); - connect(m_sliceName, &QLineEdit::textChanged, this, &MainWidget::updateSliceSettings); + connect(m_sliceName, &QLineEdit::textChanged, this, &PccWidget::updateSliceSettings); connect(m_sliceValue, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), - this, &MainWidget::updateSliceSettings); - connect(m_pen, &QPushButton::clicked, m_penTool, &PenTool::show); - connect(m_penTool, &PenTool::changed, this, &MainWidget::updateSliceSettings); - connect(m_brush, &QPushButton::clicked, m_brushTool, &BrushTool::show); - connect(m_brushTool, &BrushTool::changed, this, &MainWidget::updateSliceSettings); - connect(m_font, &QPushButton::clicked, this, &MainWidget::showFontDialog); - connect(m_labelBrush, &QPushButton::clicked, m_labelBrushTool, &BrushTool::show); - connect(m_labelBrushTool, &BrushTool::changed, this, &MainWidget::updateSliceSettings); - connect(m_sliceLabelVisible, &QCheckBox::toggled, this, &MainWidget::updateSliceSettings); - connect(m_sliceLabelVisible, &QCheckBox::toggled, this, &MainWidget::updateSliceSettings); + this, &PccWidget::updateSliceSettings); + connect(m_pen, &QPushButton::clicked, m_penTool, &PccPenTool::show); + connect(m_penTool, &PccPenTool::changed, this, &PccWidget::updateSliceSettings); + connect(m_brush, &QPushButton::clicked, m_brushTool, &PccBrushTool::show); + connect(m_brushTool, &PccBrushTool::changed, this, &PccWidget::updateSliceSettings); + connect(m_font, &QPushButton::clicked, this, &PccWidget::showFontDialog); + connect(m_labelBrush, &QPushButton::clicked, m_labelBrushTool, &PccBrushTool::show); + connect(m_labelBrushTool, &PccBrushTool::changed, this, &PccWidget::updateSliceSettings); + connect(m_sliceLabelVisible, &QCheckBox::toggled, this, &PccWidget::updateSliceSettings); + connect(m_sliceLabelVisible, &QCheckBox::toggled, this, &PccWidget::updateSliceSettings); connect(m_sliceLabelArmFactor, &QDoubleSpinBox::valueChanged, - this, &MainWidget::updateSliceSettings); - connect(m_sliceExploded, &QCheckBox::toggled, this, &MainWidget::updateSliceSettings); + this, &PccWidget::updateSliceSettings); + connect(m_sliceExploded, &QCheckBox::toggled, this, &PccWidget::updateSliceSettings); connect(m_sliceExplodedFactor, &QDoubleSpinBox::valueChanged, - this, &MainWidget::updateSliceSettings); + this, &PccWidget::updateSliceSettings); connect(m_labelPosition, &QComboBox::currentIndexChanged, - this, &MainWidget::updateSliceSettings); + this, &PccWidget::updateSliceSettings); // create chart view m_chartView = new QChartView(chart); // create main layout - QVBoxLayout *settingsLayout = new QVBoxLayout(); + auto settingsLayout = new QVBoxLayout; settingsLayout->addWidget(chartSettings); settingsLayout->addWidget(seriesSettings); settingsLayout->addWidget(sliceSettings); settingsContentWidget->setLayout(settingsLayout); - settingsScrollBar->setWidget(settingsContentWidget); - settingsScrollBar->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - settingsScrollBar->setWidgetResizable(true); - settingsScrollBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + m_settingsScrollBar->setWidget(settingsContentWidget); + m_settingsScrollBar->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_settingsScrollBar->setWidgetResizable(true); + m_settingsScrollBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); m_chartView->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); - baseLayout = new QGridLayout(); - baseLayout->addWidget(settingsScrollBar, 0, 0); - baseLayout->addWidget(m_chartView, 1, 0); - setLayout(baseLayout); + m_baseLayout = new QGridLayout; + m_baseLayout->addWidget(m_settingsScrollBar, 0, 0); + m_baseLayout->addWidget(m_chartView, 1, 0); + setLayout(m_baseLayout); updateSerieSettings(); updateChartSettings(); } - -void MainWidget::updateChartSettings() +void PccWidget::updateChartSettings() { - QChart::ChartTheme theme = static_cast<QChart::ChartTheme>(m_themeComboBox->itemData( + auto theme = static_cast<QChart::ChartTheme>(m_themeComboBox->itemData( m_themeComboBox->currentIndex()).toInt()); m_chartView->chart()->setTheme(theme); m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); @@ -254,7 +253,7 @@ void MainWidget::updateChartSettings() m_chartView->chart()->legend()->hide(); } -void MainWidget::updateSerieSettings() +void PccWidget::updateSerieSettings() { m_series->setHorizontalPosition(m_hPosition->value()); m_series->setVerticalPosition(m_vPosition->value()); @@ -265,7 +264,7 @@ void MainWidget::updateSerieSettings() m_series->setHoleSize(m_holeSize->value()); } -void MainWidget::updateSliceSettings() +void PccWidget::updateSliceSettings() { if (!m_slice) return; @@ -287,9 +286,9 @@ void MainWidget::updateSliceSettings() m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); } -void MainWidget::handleSliceClicked(QPieSlice *slice) +void PccWidget::handleSliceClicked(QPieSlice *slice) { - m_slice = static_cast<CustomSlice *>(slice); + m_slice = static_cast<PccCustomSlice *>(slice); // name m_sliceName->blockSignals(true); @@ -302,7 +301,7 @@ void MainWidget::handleSliceClicked(QPieSlice *slice) m_sliceValue->blockSignals(false); // pen - m_pen->setText(PenTool::name(m_slice->pen())); + m_pen->setText(PccPenTool::name(m_slice->pen())); m_penTool->setPen(m_slice->pen()); // brush @@ -310,7 +309,7 @@ void MainWidget::handleSliceClicked(QPieSlice *slice) m_brushTool->setBrush(m_slice->originalBrush()); // label - m_labelBrush->setText(BrushTool::name(m_slice->labelBrush())); + m_labelBrush->setText(PccBrushTool::name(m_slice->labelBrush())); m_labelBrushTool->setBrush(m_slice->labelBrush()); m_font->setText(slice->labelFont().toString()); m_sliceLabelVisible->blockSignals(true); @@ -333,7 +332,7 @@ void MainWidget::handleSliceClicked(QPieSlice *slice) m_sliceExplodedFactor->blockSignals(false); } -void MainWidget::showFontDialog() +void PccWidget::showFontDialog() { if (!m_slice) return; @@ -346,22 +345,22 @@ void MainWidget::showFontDialog() m_font->setText(dialog.currentFont().toString()); } -void MainWidget::appendSlice() +void PccWidget::appendSlice() { - *m_series << new CustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0); + *m_series << new PccCustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0); } -void MainWidget::insertSlice() +void PccWidget::insertSlice() { if (!m_slice) return; int i = m_series->slices().indexOf(m_slice); - m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0)); + m_series->insert(i, new PccCustomSlice("Slice " + QString::number(m_series->count() + 1), 10.0)); } -void MainWidget::removeSlice() +void PccWidget::removeSlice() { if (!m_slice) return; @@ -372,32 +371,28 @@ void MainWidget::removeSlice() m_slice = 0; } -void MainWidget::resizeEvent(QResizeEvent *e) +void PccWidget::resizeEvent(QResizeEvent *) { if (width() == 0 || height() == 0) return; const double aspectRatio = double(width()) / double(height()); - if ((aspectRatio < 1.0) && (oldAspectRatio > 1.0)) { - baseLayout->removeWidget(m_chartView); - baseLayout->removeWidget(settingsScrollBar); + if ((aspectRatio < 1.0) && (m_oldAspectRatio > 1.0)) { + m_baseLayout->removeWidget(m_chartView); + m_baseLayout->removeWidget(m_settingsScrollBar); - baseLayout->addWidget(m_chartView, 0, 0); - baseLayout->addWidget(settingsScrollBar, 1, 0); + m_baseLayout->addWidget(m_chartView, 0, 0); + m_baseLayout->addWidget(m_settingsScrollBar, 1, 0); - oldAspectRatio = aspectRatio; - } - else if ((aspectRatio > 1.0) && (oldAspectRatio < 1.0)) { - baseLayout->removeWidget(m_chartView); - baseLayout->removeWidget(settingsScrollBar); + m_oldAspectRatio = aspectRatio; + } else if ((aspectRatio > 1.0) && (m_oldAspectRatio < 1.0)) { + m_baseLayout->removeWidget(m_chartView); + m_baseLayout->removeWidget(m_settingsScrollBar); - baseLayout->addWidget(m_chartView, 0, 0); - baseLayout->addWidget(settingsScrollBar, 0, 1); + m_baseLayout->addWidget(m_chartView, 0, 0); + m_baseLayout->addWidget(m_settingsScrollBar, 0, 1); - oldAspectRatio = aspectRatio; + m_oldAspectRatio = aspectRatio; } } - - -#include "moc_mainwidget.cpp" diff --git a/examples/charts/gallery/pccwidget.h b/examples/charts/gallery/pccwidget.h new file mode 100644 index 00000000..3b0e617c --- /dev/null +++ b/examples/charts/gallery/pccwidget.h @@ -0,0 +1,80 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef PCCWIDGET_H +#define PCCWIDGET_H + +#include "contentwidget.h" + +#include <QGridLayout> +#include <QScrollArea> + +QT_FORWARD_DECLARE_CLASS(QChartView); +QT_FORWARD_DECLARE_CLASS(QCheckBox); +QT_FORWARD_DECLARE_CLASS(QComboBox); +QT_FORWARD_DECLARE_CLASS(QDoubleSpinBox); +QT_FORWARD_DECLARE_CLASS(QLineEdit); +QT_FORWARD_DECLARE_CLASS(QPushButton); +QT_FORWARD_DECLARE_CLASS(QPieSeries); +QT_FORWARD_DECLARE_CLASS(QPieSlice); + +class PccPenTool; +class PccBrushTool; +class PccCustomSlice; + +class PccWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit PccWidget(QWidget *parent = nullptr); + +public slots: + void updateChartSettings(); + void updateSerieSettings(); + void updateSliceSettings(); + void handleSliceClicked(QPieSlice *slice); + void showFontDialog(); + void appendSlice(); + void insertSlice(); + void removeSlice(); + +private: + void resizeEvent(QResizeEvent *e); + + QComboBox *m_themeComboBox = nullptr; + QCheckBox *m_aaCheckBox = nullptr; + QCheckBox *m_animationsCheckBox = nullptr; + QCheckBox *m_legendCheckBox = nullptr; + + QChartView *m_chartView = nullptr; + QPieSeries *m_series = nullptr; + PccCustomSlice *m_slice = nullptr; + + QDoubleSpinBox *m_hPosition = nullptr; + QDoubleSpinBox *m_vPosition = nullptr; + QDoubleSpinBox *m_sizeFactor = nullptr; + QDoubleSpinBox *m_startAngle = nullptr; + QDoubleSpinBox *m_endAngle = nullptr; + QDoubleSpinBox *m_holeSize = nullptr; + + QLineEdit *m_sliceName = nullptr; + QDoubleSpinBox *m_sliceValue = nullptr; + QCheckBox *m_sliceLabelVisible = nullptr; + QDoubleSpinBox *m_sliceLabelArmFactor = nullptr; + QCheckBox *m_sliceExploded = nullptr; + QDoubleSpinBox *m_sliceExplodedFactor = nullptr; + QPushButton *m_brush = nullptr; + PccBrushTool *m_brushTool = nullptr; + QPushButton *m_pen = nullptr; + PccPenTool *m_penTool = nullptr; + QPushButton *m_font = nullptr; + QPushButton *m_labelBrush = nullptr; + QComboBox *m_labelPosition = nullptr; + PccBrushTool *m_labelBrushTool = nullptr; + QGridLayout *m_baseLayout = nullptr; + QScrollArea *m_settingsScrollBar = nullptr; + + double m_oldAspectRatio = 0.; +}; + +#endif diff --git a/examples/charts/gallery/piedrilldownchart.cpp b/examples/charts/gallery/piedrilldownchart.cpp new file mode 100644 index 00000000..7d60f727 --- /dev/null +++ b/examples/charts/gallery/piedrilldownchart.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "piedrilldownchart.h" +#include "piedrilldownslice.h" + +PieDrilldownChart::PieDrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) + : QChart(QChart::ChartTypeCartesian, parent, wFlags) +{ +} + +void PieDrilldownChart::changeSeries(QAbstractSeries *series) +{ + if (m_currentSeries) + removeSeries(m_currentSeries); + m_currentSeries = series; + addSeries(series); + setTitle(series->name()); +} + +void PieDrilldownChart::handleSliceClicked(QPieSlice *slice) +{ + auto *drilldownSlice = static_cast<PieDrilldownSlice *>(slice); + changeSeries(drilldownSlice->drilldownSeries()); +} diff --git a/examples/charts/gallery/piedrilldownchart.h b/examples/charts/gallery/piedrilldownchart.h new file mode 100644 index 00000000..66c54f9b --- /dev/null +++ b/examples/charts/gallery/piedrilldownchart.h @@ -0,0 +1,26 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef PIEDRILLDOWNCHART_H +#define PIEDRILLDOWNCHART_H + +#include <QChart> + +QT_FORWARD_DECLARE_CLASS(QAbstractSeries); +QT_FORWARD_DECLARE_CLASS(QPieSlice); + +class PieDrilldownChart : public QChart +{ + Q_OBJECT +public: + explicit PieDrilldownChart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {}); + void changeSeries(QAbstractSeries *series); + +public slots: + void handleSliceClicked(QPieSlice *slice); + +private: + QAbstractSeries *m_currentSeries = nullptr; +}; + +#endif diff --git a/examples/charts/gallery/piedrilldownslice.cpp b/examples/charts/gallery/piedrilldownslice.cpp new file mode 100644 index 00000000..a8612cde --- /dev/null +++ b/examples/charts/gallery/piedrilldownslice.cpp @@ -0,0 +1,33 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "piedrilldownslice.h" + +PieDrilldownSlice::PieDrilldownSlice(qreal value, const QString &prefix, QAbstractSeries *drilldownSeries) + : m_drilldownSeries(drilldownSeries), + m_prefix(prefix) +{ + setValue(value); + updateLabel(); + setLabelFont(QFont("Arial", 8)); + connect(this, &PieDrilldownSlice::percentageChanged, this, &PieDrilldownSlice::updateLabel); + connect(this, &PieDrilldownSlice::hovered, this, &PieDrilldownSlice::showHighlight); +} + +QAbstractSeries *PieDrilldownSlice::drilldownSeries() const +{ + return m_drilldownSeries; +} + +void PieDrilldownSlice::updateLabel() +{ + setLabel(QStringLiteral("%1 $%2, %3%").arg(m_prefix, + QString::number(value()), + QString::number(percentage() * 100, 'f', 1))); +} + +void PieDrilldownSlice::showHighlight(bool show) +{ + setLabelVisible(show); + setExploded(show); +} diff --git a/examples/charts/gallery/piedrilldownslice.h b/examples/charts/gallery/piedrilldownslice.h new file mode 100644 index 00000000..9579c42e --- /dev/null +++ b/examples/charts/gallery/piedrilldownslice.h @@ -0,0 +1,27 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef PIEDRILLDOWNSLICE_H +#define PIEDRILLDOWNSLICE_H + +#include <QPieSlice> + +QT_FORWARD_DECLARE_CLASS(QAbstractSeries); + +class PieDrilldownSlice : public QPieSlice +{ + Q_OBJECT +public: + PieDrilldownSlice(qreal value, const QString &prefix, QAbstractSeries *drilldownSeries); + QAbstractSeries *drilldownSeries() const; + +public slots: + void updateLabel(); + void showHighlight(bool show); + +private: + QAbstractSeries *m_drilldownSeries = nullptr; + QString m_prefix; +}; + +#endif diff --git a/examples/charts/gallery/piedrilldownwidget.cpp b/examples/charts/gallery/piedrilldownwidget.cpp new file mode 100644 index 00000000..59555f72 --- /dev/null +++ b/examples/charts/gallery/piedrilldownwidget.cpp @@ -0,0 +1,49 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "piedrilldownchart.h" +#include "piedrilldownslice.h" +#include "piedrilldownwidget.h" + +#include <QChart> +#include <QLegend> +#include <QPieSeries> +#include <QRandomGenerator> + +PieDrilldownWidget::PieDrilldownWidget(QWidget *parent) + : ContentWidget(parent) +{ + auto *chart = new PieDrilldownChart; + chart->setTheme(QChart::ChartThemeLight); + chart->setAnimationOptions(QChart::AllAnimations); + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignRight); + + auto yearSeries = new QPieSeries(this); + yearSeries->setName("Sales by year - All (Click on slice to drill down)"); + + const QStringList months = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + const QStringList names = { + "Jane", "John", "Axel", "Mary", "Susan", "Bob" + }; + + for (const QString &name : names) { + auto series = new QPieSeries(this); + series->setName("Sales by month - " + name); + + for (const QString &month : months) + *series << new PieDrilldownSlice(QRandomGenerator::global()->bounded(1000), month, yearSeries); + + QObject::connect(series, &QPieSeries::clicked, chart, &PieDrilldownChart::handleSliceClicked); + + *yearSeries << new PieDrilldownSlice(series->sum(), name, series); + } + + QObject::connect(yearSeries, &QPieSeries::clicked, chart, &PieDrilldownChart::handleSliceClicked); + + chart->changeSeries(yearSeries); + + createDefaultChartView(chart); +} diff --git a/examples/charts/gallery/piedrilldownwidget.h b/examples/charts/gallery/piedrilldownwidget.h new file mode 100644 index 00000000..cc2b16f1 --- /dev/null +++ b/examples/charts/gallery/piedrilldownwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef PIEDRILLDOWNWIDGET_H +#define PIEDRILLDOWNWIDGET_H + +#include "contentwidget.h" + +class PieDrilldownWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit PieDrilldownWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/piewidget.cpp b/examples/charts/gallery/piewidget.cpp new file mode 100644 index 00000000..feb67afe --- /dev/null +++ b/examples/charts/gallery/piewidget.cpp @@ -0,0 +1,40 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "piewidget.h" + +#include <QChart> +#include <QPieSeries> +#include <QPieSlice> + +PieWidget::PieWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto series = new QPieSeries; + series->append("Jane", 1); + series->append("Joe", 2); + series->append("Andy", 3); + series->append("Barbara", 4); + series->append("Axel", 5); + //![1] + + //![2] + QPieSlice *slice = series->slices().at(1); + slice->setExploded(); + slice->setLabelVisible(); + slice->setPen(QPen(Qt::darkGreen, 2)); + slice->setBrush(Qt::green); + //![2] + + //![3] + auto chart = new QChart; + chart->addSeries(series); + chart->setTitle("Simple Pie Chart"); + chart->legend()->hide(); + //![3] + + //![4] + createDefaultChartView(chart); + //![4] +} diff --git a/examples/charts/gallery/piewidget.h b/examples/charts/gallery/piewidget.h new file mode 100644 index 00000000..c57200e9 --- /dev/null +++ b/examples/charts/gallery/piewidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef PIEWIDGET_H +#define PIEWIDGET_H + +#include "contentwidget.h" + +class PieWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit PieWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/pointconfiguration/chartwindow.cpp b/examples/charts/gallery/pointconfigurationwidget.cpp index a19c4867..5c2970c3 100644 --- a/examples/charts/pointconfiguration/chartwindow.cpp +++ b/examples/charts/gallery/pointconfigurationwidget.cpp @@ -1,42 +1,43 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "chartwindow.h" +#include "pointconfigurationwidget.h" #include <QChart> +#include <QChartView> +#include <QCheckBox> #include <QColor> +#include <QComboBox> +#include <QGraphicsLayout> #include <QGridLayout> #include <QHBoxLayout> #include <QIcon> #include <QLabel> +#include <QLineEdit> #include <QLineSeries> -#include <QMainWindow> //![1] -ChartWindow::ChartWindow(QWidget *parent) - : QMainWindow(parent) +PointConfigurationWidget::PointConfigurationWidget(QWidget *parent) + : ContentWidget(parent) { //![1] //![2] - setWindowTitle(tr("Chart")); - - m_series = new QLineSeries(this); - m_series->setName(tr("Customized series")); + m_series = new QLineSeries; m_series->setPointsVisible(true); m_series->append({QPointF(0, 7), QPointF(2, 4), - QPointF(3, 5), QPointF(7, 4), - QPointF(10, 5), QPointF(11, 1), - QPointF(13, 3), QPointF(17, 6), - QPointF(18, 3), QPointF(20, 2)}); + QPointF(3, 5), QPointF(7, 4), + QPointF(10, 5), QPointF(11, 1), + QPointF(13, 3), QPointF(17, 6), + QPointF(18, 3), QPointF(20, 2)}); //![2] //![3] - QLabel *selectedPointIndexLabel = new QLabel(tr("Selected Point: ")); - m_selectedPointIndexLineEdit = new QLineEdit(); + auto selectedPointIndexLabel = new QLabel(tr("Selected Point: "), this); + m_selectedPointIndexLineEdit = new QLineEdit(this); m_selectedPointIndexLineEdit->setReadOnly(true); - QLabel *colorLabel = new QLabel(tr("Color: ")); - m_colorCombobox = new QComboBox(); + auto colorLabel = new QLabel(tr("Color: "), this); + m_colorCombobox = new QComboBox(this); QStringList colorStrings = {"red", "orange", "yellow", "green", "blue", "indigo", "violet", "black"}; QStringList trColorStrings = {tr("red"), tr("orange"), tr("yellow"), @@ -45,16 +46,16 @@ ChartWindow::ChartWindow(QWidget *parent) for (int i = 0; i < colorStrings.size(); i++) m_colorCombobox->addItem(QIcon(), trColorStrings[i], QColor(colorStrings[i])); - QLabel *sizeLabel = new QLabel(tr("Size: ")); - m_sizeCombobox = new QComboBox(); + auto sizeLabel = new QLabel(tr("Size: "), this); + m_sizeCombobox = new QComboBox(this); for (auto size : { 2, 3, 4, 6, 8, 10, 12, 15 }) m_sizeCombobox->addItem(QIcon(), QString::number(size), size); - QLabel *labelVisibilityLabel = new QLabel(tr("Label Visibility: ")); - m_labelVisibilityCheckbox = new QCheckBox(); + auto labelVisibilityLabel = new QLabel(tr("Label Visibility: "), this); + m_labelVisibilityCheckbox = new QCheckBox(this); - QLabel *customLabelLabel = new QLabel(tr("Custom Label: ")); - m_customLabelLineEdit = new QLineEdit(); + auto customLabelLabel = new QLabel(tr("Custom Label: "), this); + m_customLabelLineEdit = new QLineEdit(this); //![3] //![4] @@ -95,11 +96,11 @@ ChartWindow::ChartWindow(QWidget *parent) //![4] //![5] - QObject::connect(m_colorCombobox, &QComboBox::activated, m_series, [&](const int index) { + QObject::connect(m_colorCombobox, &QComboBox::activated, m_series, [&](const int) { m_selectedPointConfig[QXYSeries::PointConfiguration::Color] = m_colorCombobox->currentData(); m_series->setPointConfiguration(m_selectedPointIndex, m_selectedPointConfig); }); - QObject::connect(m_sizeCombobox, &QComboBox::activated, m_series, [&](const int index) { + QObject::connect(m_sizeCombobox, &QComboBox::activated, m_series, [&](const int) { m_selectedPointConfig[QXYSeries::PointConfiguration::Size] = m_sizeCombobox->currentData(); m_series->setPointConfiguration(m_selectedPointIndex, m_selectedPointConfig); }); @@ -114,21 +115,24 @@ ChartWindow::ChartWindow(QWidget *parent) //![5] //![6] - m_chart = new QChart(); - m_chart->addSeries(m_series); - m_chart->createDefaultAxes(); - - m_selectInitialPointConnection = QObject::connect(m_chart, &QChart::geometryChanged, m_chart, [&]() { + auto chart = new QChart; + chart->addSeries(m_series); + chart->createDefaultAxes(); + chart->setTitle("Select points with mouse click"); + chart->layout()->setContentsMargins(0, 0, 0, 0); + chart->legend()->setVisible(false); + + m_selectInitialPointConnection = QObject::connect(chart, &QChart::geometryChanged, chart, [&]() { m_series->selectPoint(4); m_series->clicked(m_series->at(m_series->selectedPoints()[0])); disconnect(m_selectInitialPointConnection); }); - QChartView *chartView = new QChartView(m_chart); + auto chartView = new QChartView(chart, this); chartView->setRenderHint(QPainter::Antialiasing); - QWidget *controlWidget = new QWidget(this); - QGridLayout *controlLayout = new QGridLayout(controlWidget); + auto controlWidget = new QWidget(this); + auto controlLayout = new QGridLayout(controlWidget); controlLayout->setColumnStretch(1, 1); controlLayout->addWidget(selectedPointIndexLabel, 0, 0); @@ -146,13 +150,10 @@ ChartWindow::ChartWindow(QWidget *parent) controlLayout->addWidget(customLabelLabel, 4, 0); controlLayout->addWidget(m_customLabelLineEdit, 4, 1); - QWidget *mainWidget = new QWidget(this); - QHBoxLayout *mainLayout = new QHBoxLayout(mainWidget); + auto mainLayout = new QHBoxLayout(this); mainLayout->addWidget(chartView); mainLayout->setStretch(0, 1); mainLayout->addWidget(controlWidget); - - setCentralWidget(mainWidget); //![6] //![7] } diff --git a/examples/charts/pointconfiguration/chartwindow.h b/examples/charts/gallery/pointconfigurationwidget.h index 141e17e3..92aba69d 100644 --- a/examples/charts/pointconfiguration/chartwindow.h +++ b/examples/charts/gallery/pointconfigurationwidget.h @@ -1,29 +1,26 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef CHARTWINDOW_H -#define CHARTWINDOW_H +#ifndef POINTCONFIGURATIONWIDGET_H +#define POINTCONFIGURATIONWIDGET_H + +#include "contentwidget.h" -#include <QChartView> -#include <QCheckBox> -#include <QComboBox> -#include <QLineEdit> -#include <QMainWindow> #include <QXYSeries> +QT_FORWARD_DECLARE_CLASS(QLineEdit) +QT_FORWARD_DECLARE_CLASS(QComboBox) +QT_FORWARD_DECLARE_CLASS(QCheckBox) + typedef QHash<QXYSeries::PointConfiguration, QVariant> PointConfigurations; -//![1] -class ChartWindow : public QMainWindow +class PointConfigurationWidget : public ContentWidget { Q_OBJECT - public: - explicit ChartWindow(QWidget *parent = nullptr); - ~ChartWindow() {}; + explicit PointConfigurationWidget(QWidget *parent = nullptr); private: - QChart *m_chart = nullptr; QXYSeries *m_series = nullptr; QMetaObject::Connection m_selectInitialPointConnection; @@ -36,6 +33,5 @@ private: QCheckBox *m_labelVisibilityCheckbox = nullptr; QLineEdit *m_customLabelLineEdit = nullptr; }; -//![1] -#endif // CHARTWINDOW_H +#endif diff --git a/examples/charts/polarchart/chartview.cpp b/examples/charts/gallery/polarchartview.cpp index 999758f6..751ae45f 100644 --- a/examples/charts/polarchart/chartview.cpp +++ b/examples/charts/gallery/polarchartview.cpp @@ -1,21 +1,20 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "chartview.h" -#include <QtGui/QMouseEvent> -#include <QtCore/QDebug> -#include <QtCharts/QAbstractAxis> -#include <QtCharts/QValueAxis> +#include "polarchartview.h" -QT_USE_NAMESPACE +#include <QAbstractAxis> +#include <QMouseEvent> +#include <QPolarChart> +#include <QValueAxis> -ChartView::ChartView(QWidget *parent) +PolarChartView::PolarChartView(QWidget *parent) : QChartView(parent) { } //![1] -void ChartView::keyPressEvent(QKeyEvent *event) +void PolarChartView::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case Qt::Key_Plus: @@ -47,15 +46,15 @@ void ChartView::keyPressEvent(QKeyEvent *event) //![1] //![2] -void ChartView::switchChartType() +void PolarChartView::switchChartType() { QChart *newChart; QChart *oldChart = chart(); if (oldChart->chartType() == QChart::ChartTypeCartesian) - newChart = new QPolarChart(); + newChart = new QPolarChart; else - newChart = new QChart(); + newChart = new QChart; // Move series and axes from old chart to new one const QList<QAbstractSeries *> seriesList = oldChart->series(); @@ -63,7 +62,7 @@ void ChartView::switchChartType() QList<QPair<qreal, qreal> > axisRanges; for (QAbstractAxis *axis : axisList) { - QValueAxis *valueAxis = static_cast<QValueAxis *>(axis); + auto valueAxis = static_cast<QValueAxis *>(axis); axisRanges.append(QPair<qreal, qreal>(valueAxis->min(), valueAxis->max())); } diff --git a/examples/charts/gallery/polarchartview.h b/examples/charts/gallery/polarchartview.h new file mode 100644 index 00000000..ee4e8fb9 --- /dev/null +++ b/examples/charts/gallery/polarchartview.h @@ -0,0 +1,21 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef POLARCHARTVIEW_H +#define POLARCHARTVIEW_H + +#include <QChartView> + +class PolarChartView : public QChartView +{ +public: + PolarChartView(QWidget *parent = nullptr); + +protected: + void keyPressEvent(QKeyEvent *event); + +private: + void switchChartType(); +}; + +#endif diff --git a/examples/charts/polarchart/main.cpp b/examples/charts/gallery/polarchartwidget.cpp index 595719c1..d0550c7c 100644 --- a/examples/charts/polarchart/main.cpp +++ b/examples/charts/gallery/polarchartwidget.cpp @@ -1,75 +1,72 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "chartview.h" -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QScatterSeries> -#include <QtCharts/QLineSeries> -#include <QtCharts/QSplineSeries> -#include <QtCharts/QAreaSeries> -#include <QtCharts/QValueAxis> -#include <QtCharts/QPolarChart> -#include <QtCore/QDebug> +#include "polarchartview.h" +#include "polarchartwidget.h" -QT_USE_NAMESPACE +#include <QAreaSeries> +#include <QChart> +#include <QLineSeries> +#include <QPolarChart> +#include <QScatterSeries> +#include <QSplineSeries> +#include <QValueAxis> -int main(int argc, char *argv[]) +PolarChartWidget::PolarChartWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); - const qreal angularMin = -100; const qreal angularMax = 100; const qreal radialMin = -100; const qreal radialMax = 100; - QScatterSeries *series1 = new QScatterSeries(); + auto series1 = new QScatterSeries; series1->setName("scatter"); for (int i = angularMin; i <= angularMax; i += 10) series1->append(i, (i / radialMax) * radialMax + 8.0); - QSplineSeries *series2 = new QSplineSeries(); + auto series2 = new QSplineSeries; series2->setName("spline"); for (int i = angularMin; i <= angularMax; i += 10) series2->append(i, (i / radialMax) * radialMax); - QLineSeries *series3 = new QLineSeries(); + auto series3 = new QLineSeries; series3->setName("star outer"); qreal ad = (angularMax - angularMin) / 8; qreal rd = (radialMax - radialMin) / 3 * 1.3; series3->append(angularMin, radialMax); - series3->append(angularMin + ad*1, radialMin + rd); - series3->append(angularMin + ad*2, radialMax); - series3->append(angularMin + ad*3, radialMin + rd); - series3->append(angularMin + ad*4, radialMax); - series3->append(angularMin + ad*5, radialMin + rd); - series3->append(angularMin + ad*6, radialMax); - series3->append(angularMin + ad*7, radialMin + rd); - series3->append(angularMin + ad*8, radialMax); - - QLineSeries *series4 = new QLineSeries(); + series3->append(angularMin + ad * 1, radialMin + rd); + series3->append(angularMin + ad * 2, radialMax); + series3->append(angularMin + ad * 3, radialMin + rd); + series3->append(angularMin + ad * 4, radialMax); + series3->append(angularMin + ad * 5, radialMin + rd); + series3->append(angularMin + ad * 6, radialMax); + series3->append(angularMin + ad * 7, radialMin + rd); + series3->append(angularMin + ad * 8, radialMax); + + auto series4 = new QLineSeries; series4->setName("star inner"); ad = (angularMax - angularMin) / 8; rd = (radialMax - radialMin) / 3; series4->append(angularMin, radialMax); - series4->append(angularMin + ad*1, radialMin + rd); - series4->append(angularMin + ad*2, radialMax); - series4->append(angularMin + ad*3, radialMin + rd); - series4->append(angularMin + ad*4, radialMax); - series4->append(angularMin + ad*5, radialMin + rd); - series4->append(angularMin + ad*6, radialMax); - series4->append(angularMin + ad*7, radialMin + rd); - series4->append(angularMin + ad*8, radialMax); - - QAreaSeries *series5 = new QAreaSeries(); + series4->append(angularMin + ad * 1, radialMin + rd); + series4->append(angularMin + ad * 2, radialMax); + series4->append(angularMin + ad * 3, radialMin + rd); + series4->append(angularMin + ad * 4, radialMax); + series4->append(angularMin + ad * 5, radialMin + rd); + series4->append(angularMin + ad * 6, radialMax); + series4->append(angularMin + ad * 7, radialMin + rd); + series4->append(angularMin + ad * 8, radialMax); + + auto series5 = new QAreaSeries; series5->setName("star area"); series5->setUpperSeries(series3); series5->setLowerSeries(series4); series5->setOpacity(0.5); //![1] - QPolarChart *chart = new QPolarChart(); + auto chart = new QPolarChart; //![1] chart->addSeries(series1); chart->addSeries(series2); @@ -80,14 +77,14 @@ int main(int argc, char *argv[]) chart->setTitle("Use arrow keys to scroll, +/- to zoom, and space to switch chart type."); //![2] - QValueAxis *angularAxis = new QValueAxis(); + auto angularAxis = new QValueAxis; angularAxis->setTickCount(9); // First and last ticks are co-located on 0/360 angle. angularAxis->setLabelFormat("%.1f"); angularAxis->setShadesVisible(true); angularAxis->setShadesBrush(QBrush(QColor(249, 249, 255))); chart->addAxis(angularAxis, QPolarChart::PolarOrientationAngular); - QValueAxis *radialAxis = new QValueAxis(); + auto radialAxis = new QValueAxis; radialAxis->setTickCount(9); radialAxis->setLabelFormat("%d"); chart->addAxis(radialAxis, QPolarChart::PolarOrientationRadial); @@ -107,14 +104,7 @@ int main(int argc, char *argv[]) radialAxis->setRange(radialMin, radialMax); angularAxis->setRange(angularMin, angularMax); - ChartView *chartView = new ChartView(); + auto chartView = new PolarChartView(this); chartView->setChart(chart); - chartView->setRenderHint(QPainter::Antialiasing); - - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(800, 600); - window.show(); - - return a.exec(); + setDefaultChartView(chartView); } diff --git a/examples/charts/gallery/polarchartwidget.h b/examples/charts/gallery/polarchartwidget.h new file mode 100644 index 00000000..8d151059 --- /dev/null +++ b/examples/charts/gallery/polarchartwidget.h @@ -0,0 +1,18 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef POLARCHARTWIDGET_H +#define POLARCHARTWIDGET_H + +#include "contentwidget.h" + +class PolarChartView; + +class PolarChartWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit PolarChartWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/scatterinteractions/chartview.cpp b/examples/charts/gallery/scatterinteractionswidget.cpp index 9fabff80..b518c6da 100644 --- a/examples/charts/scatterinteractions/chartview.cpp +++ b/examples/charts/gallery/scatterinteractionswidget.cpp @@ -1,46 +1,42 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "chartview.h" -#include <QtCore/QtMath> -#include <QtCore/QDebug> +#include "scatterinteractionswidget.h" -QT_USE_NAMESPACE +#include <QChart> +#include <QtMath> +#include <QScatterSeries> -ChartView::ChartView(QWidget *parent) - : QChartView(new QChart(), parent), - m_scatter(0), - m_scatter2(0) +ScatterInteractionsWidget::ScatterInteractionsWidget(QWidget *parent) + : ContentWidget(parent) { - setRenderHint(QPainter::Antialiasing); - - chart()->setTitle("Click to interact with scatter points"); - - m_scatter = new QScatterSeries(); + m_scatter = new QScatterSeries; m_scatter->setName("scatter1"); for (qreal x(0.5); x <= 4.0; x += 0.5) { for (qreal y(0.5); y <= 4.0; y += 0.5) *m_scatter << QPointF(x, y); } - m_scatter2 = new QScatterSeries(); + m_scatter2 = new QScatterSeries; m_scatter2->setName("scatter2"); - chart()->addSeries(m_scatter2); - chart()->addSeries(m_scatter); - chart()->createDefaultAxes(); - chart()->axes(Qt::Horizontal).first()->setRange(0, 4.5); - chart()->axes(Qt::Vertical).first()->setRange(0, 4.5); + auto *chart = new QChart; + chart->setTitle("Click to interact with scatter points"); + chart->addSeries(m_scatter2); + chart->addSeries(m_scatter); + chart->createDefaultAxes(); + chart->axes(Qt::Horizontal).first()->setRange(0, 4.5); + chart->axes(Qt::Vertical).first()->setRange(0, 4.5); - connect(m_scatter, &QScatterSeries::clicked, this, &ChartView::handleClickedPoint); -} + connect(m_scatter, &QScatterSeries::clicked, + this, &ScatterInteractionsWidget::handleClickedPoint); -ChartView::~ChartView() -{ + createDefaultChartView(chart); } -void ChartView::handleClickedPoint(const QPointF &point) +void ScatterInteractionsWidget::handleClickedPoint(const QPointF &point) { QPointF clickedPoint = point; + // Find the closest point from series 1 QPointF closest(INT_MAX, INT_MAX); qreal distance(INT_MAX); @@ -56,7 +52,7 @@ void ChartView::handleClickedPoint(const QPointF &point) } } - // Remove the closes point from series 1 and append it to series 2 + // Remove the closest point from series 1 and append it to series 2 m_scatter->remove(closest); m_scatter2->append(closest); } diff --git a/examples/charts/gallery/scatterinteractionswidget.h b/examples/charts/gallery/scatterinteractionswidget.h new file mode 100644 index 00000000..ba757c53 --- /dev/null +++ b/examples/charts/gallery/scatterinteractionswidget.h @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef SCATTERINTERACTIONSWIDGET_H +#define SCATTERINTERACTIONSWIDGET_H + +#include "contentwidget.h" + +QT_FORWARD_DECLARE_CLASS(QScatterSeries) + +class ScatterInteractionsWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit ScatterInteractionsWidget(QWidget *parent = nullptr); + +private slots: + void handleClickedPoint(const QPointF &point); + +private: + QScatterSeries *m_scatter = nullptr; + QScatterSeries *m_scatter2 = nullptr; +}; + +#endif diff --git a/examples/charts/scatterchart/chartview.cpp b/examples/charts/gallery/scatterwidget.cpp index 11fd89c5..413a090b 100644 --- a/examples/charts/scatterchart/chartview.cpp +++ b/examples/charts/gallery/scatterwidget.cpp @@ -1,28 +1,30 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "chartview.h" -#include <QtCharts/QScatterSeries> -#include <QtCharts/QLegendMarker> -#include <QtGui/QImage> -#include <QtGui/QPainter> -#include <QtCore/QtMath> +#include "scatterwidget.h" -ChartView::ChartView(QWidget *parent) : - QChartView(new QChart(), parent) +#include <QChart> +#include <QLegendMarker> +#include <QImage> +#include <QPainter> +#include <QScatterSeries> +#include <QtMath> + +ScatterWidget::ScatterWidget(QWidget *parent) + : ContentWidget(parent) { //![1] - QScatterSeries *series0 = new QScatterSeries(); + auto series0 = new QScatterSeries; series0->setName("scatter1"); series0->setMarkerShape(QScatterSeries::MarkerShapeCircle); series0->setMarkerSize(15.0); - QScatterSeries *series1 = new QScatterSeries(); + auto series1 = new QScatterSeries; series1->setName("scatter2"); series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle); series1->setMarkerSize(20.0); - QScatterSeries *series2 = new QScatterSeries(); + auto series2 = new QScatterSeries; series2->setName("scatter3"); series2->setMarkerShape(QScatterSeries::MarkerShapeRectangle); series2->setMarkerSize(30.0); @@ -62,17 +64,21 @@ ChartView::ChartView(QWidget *parent) : //![3] //![4] - setRenderHint(QPainter::Antialiasing); - chart()->addSeries(series0); - chart()->addSeries(series1); - chart()->addSeries(series2); + auto chart = new QChart; + chart->addSeries(series0); + chart->addSeries(series1); + chart->addSeries(series2); - chart()->setTitle("Simple scatterchart example"); - chart()->createDefaultAxes(); - chart()->setDropShadowEnabled(false); + chart->setTitle("Simple Scatter Chart"); + chart->createDefaultAxes(); + chart->setDropShadowEnabled(false); //![4] //![5] - chart()->legend()->setMarkerShape(QLegend::MarkerShapeFromSeries); + chart->legend()->setMarkerShape(QLegend::MarkerShapeFromSeries); //![5] + + //![6] + createDefaultChartView(chart); + //![6] } diff --git a/examples/charts/gallery/scatterwidget.h b/examples/charts/gallery/scatterwidget.h new file mode 100644 index 00000000..6b836718 --- /dev/null +++ b/examples/charts/gallery/scatterwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef SCATTERWIDGET_H +#define SCATTERWIDGET_H + +#include "contentwidget.h" + +class ScatterWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit ScatterWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/selectedbar/main.cpp b/examples/charts/gallery/selectedbarwidget.cpp index 4d84eec4..d54d2201 100644 --- a/examples/charts/selectedbar/main.cpp +++ b/examples/charts/gallery/selectedbarwidget.cpp @@ -1,62 +1,59 @@ -// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "utilities.h" -#include <QBarSet> -#include <QApplication> +#include "selectedbarwidget.h" + +#include <QBarCategoryAxis> #include <QBarSeries> -#include <QList> +#include <QBarSet> #include <QChart> -#include <QBarCategoryAxis> -#include <QValueAxis> #include <QChartView> -#include <QWindow> +#include <QGraphicsLayout> #include <QHBoxLayout> #include <QLabel> -#include <QMainWindow> +#include <QValueAxis> -int main(int argc, char *argv[]) +SelectedBarWidget::SelectedBarWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); - QMainWindow mainWindow; - mainWindow.setWindowTitle(QCoreApplication::tr("Meat consumption series")); - //![1] - QBarSet *setChicken = Utilities::createChickenSet(); - QBarSet *setPork = Utilities::createPorkSet(); - QBarSet *setTurkey = Utilities::createTurkeySet(); - QBarSet *setHam = Utilities::createHamSet(); + QBarSet *setChicken = createChickenSet(); + QBarSet *setPork = createPorkSet(); + QBarSet *setTurkey = createTurkeySet(); + QBarSet *setHam = createHamSet(); qreal totalSum = setChicken->sum() + setPork->sum() + setTurkey->sum() + setHam->sum(); QList<QBarSet *> setList = QList<QBarSet *>{setChicken, setPork, setTurkey, setHam}; - QBarSeries *series = new QBarSeries(); + auto series = new QBarSeries; series->append(setList); //![1] //![2] - QChart *chart = new QChart(); + auto chart = new QChart; chart->addSeries(series); - chart->setTitle(QCoreApplication::tr("Meat consumption")); + chart->setTitle(tr("Meat Consumption (Click on bars to select them)")); chart->setAnimationOptions(QChart::SeriesAnimations); chart->legend()->setVisible(true); chart->legend()->setAlignment(Qt::AlignBottom); + chart->layout()->setContentsMargins(0, 0, 0, 0); //![2] //![3] - for (QBarSet *barSet : series->barSets()) + const auto barSets = series->barSets(); + for (QBarSet *barSet : barSets) barSet->setSelectedColor(barSet->brush().color().darker()); //![3] //![4] - QStringList categories = Utilities::createYearCategories(); - QBarCategoryAxis *axisX = new QBarCategoryAxis(); + QStringList categories = createYearCategories(); + auto axisX = new QBarCategoryAxis; axisX->setCategories(categories); chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); - QValueAxis *axisY = new QValueAxis(); + auto axisY = new QValueAxis; axisY->setRange(0, 20); - axisY->setTitleText(QCoreApplication::tr("Tons")); + axisY->setTitleText(tr("Tons")); axisY->setLabelsAngle(-90); axisY->setTitleVisible(true); chart->addAxis(axisY, Qt::AlignLeft); @@ -64,23 +61,23 @@ int main(int argc, char *argv[]) //![4] //![5] - QChartView *chartView = new QChartView(chart); + auto chartView = new QChartView(chart, this); chartView->setRenderHint(QPainter::Antialiasing); //![5] //![6] - QWidget *labelWidget = new QWidget(&mainWindow); - QHBoxLayout *labelLayout = new QHBoxLayout(labelWidget); + auto labelWidget = new QWidget(this); + auto labelLayout = new QHBoxLayout(labelWidget); labelLayout->setAlignment(Qt::AlignCenter); - QLabel *totalSumLabel = new QLabel(QCoreApplication::tr("Total sum: %1 T").arg(totalSum)); + auto totalSumLabel = new QLabel(tr("Total sum: %1 T").arg(totalSum), this); labelLayout->addWidget(totalSumLabel); totalSumLabel->setContentsMargins(0, 0, 54, 0); - QLabel *selectedSumLabel = new QLabel(QCoreApplication::tr("Selected sum: 0 T")); + auto selectedSumLabel = new QLabel(tr("Selected sum: 0 T"), this); labelLayout->addWidget(selectedSumLabel); - QLabel *unselectedSumLabel = new QLabel(QCoreApplication::tr("Unselected sum: %1 T").arg(totalSum)); + auto unselectedSumLabel = new QLabel(tr("Unselected sum: %1 T").arg(totalSum), this); labelLayout->addWidget(unselectedSumLabel); unselectedSumLabel->setContentsMargins(54, 0, 0, 0); //![6] @@ -94,27 +91,57 @@ int main(int argc, char *argv[]) for (int k = 0; k < selectedIndices.size(); ++k) selectedSum += setList.at(i)->at(selectedIndices.at(k)); } - selectedSumLabel->setText(QCoreApplication::tr("Selected sum: %1 T").arg(selectedSum)); + selectedSumLabel->setText(tr("Selected sum: %1 T").arg(selectedSum)); // Because of rounding errors, selectedSum can result in being bigger than total sum qreal unselectedSum = totalSum - selectedSum < 0 ? 0. : totalSum - selectedSum; unselectedSumLabel->setText( - QCoreApplication::tr("Unselected sum: %1 T") - .arg(unselectedSum) - ); + tr("Unselected sum: %1 T") + .arg(unselectedSum) + ); }); //![7] //![8] - QWidget *mainWidget = new QWidget(&mainWindow); - QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget); + auto mainLayout = new QVBoxLayout(this); mainLayout->addWidget(chartView); mainLayout->addWidget(labelWidget); + //![8] +} - mainWindow.setCentralWidget(mainWidget); - mainWindow.resize(800, 600); +QBarSet *SelectedBarWidget::createChickenSet() +{ + auto set = new QBarSet(tr("Chicken")); + set->append({15.0, 12.0, 8.0, 11.5, 13.7}); + return set; +} - mainWindow.show(); - return a.exec(); - //![8] +QBarSet *SelectedBarWidget::createPorkSet() +{ + auto set = new QBarSet(tr("Pork")); + set->append({9.0, 11.0, 9.0, 7, 12.2}); + return set; +} + +QBarSet *SelectedBarWidget::createTurkeySet() +{ + auto set = new QBarSet(tr("Turkey")); + set->append({5.0, 7.6, 9.3, 8, 8.1}); + return set; +} + +QBarSet *SelectedBarWidget::createHamSet() +{ + auto set = new QBarSet(tr("Ham")); + set->append({5.4, 7.1, 9.3, 12.3, 11.3}); + return set; +} + +QStringList SelectedBarWidget::createYearCategories() +{ + return QStringList{tr("2017"), + tr("2018"), + tr("2019"), + tr("2020"), + tr("2021")}; } diff --git a/examples/charts/gallery/selectedbarwidget.h b/examples/charts/gallery/selectedbarwidget.h new file mode 100644 index 00000000..2e401dcd --- /dev/null +++ b/examples/charts/gallery/selectedbarwidget.h @@ -0,0 +1,27 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef SELECTEDBARWIDGET_H +#define SELECTEDBARWIDGET_H + +#include "contentwidget.h" + +#include <QStringList> + +QT_FORWARD_DECLARE_CLASS(QBarSet) + +class SelectedBarWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit SelectedBarWidget(QWidget *parent = nullptr); + +private: + QBarSet *createChickenSet(); + QBarSet *createPorkSet(); + QBarSet *createTurkeySet(); + QBarSet *createHamSet(); + QStringList createYearCategories(); +}; + +#endif diff --git a/examples/charts/gallery/splinewidget.cpp b/examples/charts/gallery/splinewidget.cpp new file mode 100644 index 00000000..1bda42f7 --- /dev/null +++ b/examples/charts/gallery/splinewidget.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "splinewidget.h" + +#include <QChart> +#include <QSplineSeries> + +SplineWidget::SplineWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto series = new QSplineSeries; + series->setName("Spline"); + //![1] + + //![2] + series->append(0, 6); + series->append(2, 4); + series->append(3, 8); + series->append(7, 4); + series->append(10, 5); + *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); + //![2] + + //![3] + auto chart = new QChart; + chart->legend()->hide(); + chart->addSeries(series); + chart->setTitle("Simple Spline Chart"); + chart->createDefaultAxes(); + chart->axes(Qt::Vertical).first()->setRange(0, 10); + //![3] + + //![4] + createDefaultChartView(chart); + //![4] +} diff --git a/examples/charts/gallery/splinewidget.h b/examples/charts/gallery/splinewidget.h new file mode 100644 index 00000000..5d9d20cc --- /dev/null +++ b/examples/charts/gallery/splinewidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef SPLINEWIDGET_H +#define SPLINEWIDGET_H + +#include "contentwidget.h" + +class SplineWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit SplineWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/stackeddrilldownchart.cpp b/examples/charts/gallery/stackeddrilldownchart.cpp new file mode 100644 index 00000000..89df4ec0 --- /dev/null +++ b/examples/charts/gallery/stackeddrilldownchart.cpp @@ -0,0 +1,38 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "stackeddrilldownchart.h" + +#include <QBarCategoryAxis> +#include <QValueAxis> + +StackedDrilldownChart::StackedDrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) + : QChart(QChart::ChartTypeCartesian, parent, wFlags), + m_axisX(new QBarCategoryAxis), + m_axisY(new QValueAxis) +{ + addAxis(m_axisY, Qt::AlignLeft); + addAxis(m_axisX, Qt::AlignBottom); +} + +void StackedDrilldownChart::changeSeries(StackedDrilldownSeries *series) +{ + if (m_currentSeries) + removeSeries(m_currentSeries); + + m_currentSeries = series; + + // Reset axis + m_axisX->setCategories(m_currentSeries->categories()); + addSeries(series); + series->attachAxis(m_axisX); + series->attachAxis(m_axisY); + m_axisY->setRange(0,m_currentSeries->maxValue()); + setTitle(series->name()); +} + +void StackedDrilldownChart::handleClicked(int index, QBarSet *) +{ + auto series = static_cast<StackedDrilldownSeries *>(sender()); + changeSeries(series->drilldownSeries(index)); +} diff --git a/examples/charts/gallery/stackeddrilldownchart.h b/examples/charts/gallery/stackeddrilldownchart.h new file mode 100644 index 00000000..85f3a1a0 --- /dev/null +++ b/examples/charts/gallery/stackeddrilldownchart.h @@ -0,0 +1,33 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef STACKEDDRILLDOWNCHART_H +#define STACKEDDRILLDOWNCHART_H + +#include "stackeddrilldownseries.h" + +#include <QChart> + +QT_FORWARD_DECLARE_CLASS(QBarCategoryAxis) +QT_FORWARD_DECLARE_CLASS(QValueAxis) + +//! [1] +class StackedDrilldownChart : public QChart +{ + Q_OBJECT +public: + explicit StackedDrilldownChart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {}); + + void changeSeries(StackedDrilldownSeries *series); + +public slots: + void handleClicked(int index, QBarSet *); + +private: + StackedDrilldownSeries *m_currentSeries = nullptr; + QBarCategoryAxis *m_axisX = nullptr; + QValueAxis *m_axisY = nullptr; +}; +//! [1] + +#endif diff --git a/examples/charts/gallery/stackeddrilldownseries.cpp b/examples/charts/gallery/stackeddrilldownseries.cpp new file mode 100644 index 00000000..39b8ca4d --- /dev/null +++ b/examples/charts/gallery/stackeddrilldownseries.cpp @@ -0,0 +1,33 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "stackeddrilldownseries.h" + +StackedDrilldownSeries::StackedDrilldownSeries(const QStringList &categories, + int maxValue, + QObject *parent) + : QStackedBarSeries(parent) + , m_maxValue(maxValue) +{ + m_categories = categories; +} + +void StackedDrilldownSeries::mapDrilldownSeries(int index, StackedDrilldownSeries *drilldownSeries) +{ + m_drilldownSeries[index] = drilldownSeries; +} + +StackedDrilldownSeries *StackedDrilldownSeries::drilldownSeries(int index) const +{ + return m_drilldownSeries[index]; +} + +QStringList StackedDrilldownSeries::categories() const +{ + return m_categories; +} + +int StackedDrilldownSeries::maxValue() const +{ + return m_maxValue; +} diff --git a/examples/charts/gallery/stackeddrilldownseries.h b/examples/charts/gallery/stackeddrilldownseries.h new file mode 100644 index 00000000..3161811e --- /dev/null +++ b/examples/charts/gallery/stackeddrilldownseries.h @@ -0,0 +1,29 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef STACKEDDRILLDOWNSERIES_H +#define STACKEDDRILLDOWNSERIES_H + +#include <QMap> +#include <QStackedBarSeries> + +//! [1] +class StackedDrilldownSeries : public QStackedBarSeries +{ + Q_OBJECT +public: + StackedDrilldownSeries(const QStringList &categories, int maxValue, QObject *parent = nullptr); + + void mapDrilldownSeries(int index, StackedDrilldownSeries *drilldownSeries); + StackedDrilldownSeries *drilldownSeries(int index) const; + QStringList categories() const; + int maxValue() const; + +private: + QMap<int, StackedDrilldownSeries *> m_drilldownSeries; + QStringList m_categories; + int m_maxValue = 0; +}; +//! [1] + +#endif diff --git a/examples/charts/stackedbarchartdrilldown/main.cpp b/examples/charts/gallery/stackeddrilldownwidget.cpp index c2ad2208..5882c0c7 100644 --- a/examples/charts/stackedbarchartdrilldown/main.cpp +++ b/examples/charts/gallery/stackeddrilldownwidget.cpp @@ -1,28 +1,23 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCore/QRandomGenerator> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSet> -#include <QtCharts/QLegend> -#include "drilldownseries.h" -#include "drilldownchart.h" +#include "stackeddrilldownchart.h" +#include "stackeddrilldownseries.h" +#include "stackeddrilldownwidget.h" -QT_USE_NAMESPACE +#include <QBarSet> +#include <QChart> +#include <QRandomGenerator> -int main(int argc, char *argv[]) +StackedDrilldownWidget::StackedDrilldownWidget(QWidget *parent) + : ContentWidget(parent) { - QApplication a(argc, argv); - QMainWindow window; - -//! [1] - DrilldownChart *drilldownChart = new DrilldownChart(); + //! [1] + auto drilldownChart = new StackedDrilldownChart; drilldownChart->setAnimationOptions(QChart::SeriesAnimations); -//! [1] + //! [1] -//! [2] + //! [2] // Define categories const QStringList months = { "May", "Jun", "Jul", "Aug", "Sep" @@ -33,18 +28,17 @@ int main(int argc, char *argv[]) const QStringList plants = { "Habanero", "Lemon Drop", "Starfish", "Aji Amarillo" }; -//! [2] + //! [2] -//! [3] + //! [3] // Create drilldown structure - DrilldownBarSeries *seasonSeries = new DrilldownBarSeries(months, 320, drilldownChart); - seasonSeries->setName("Crop by month - Season"); + auto seasonSeries = new StackedDrilldownSeries(months, 320, drilldownChart); + seasonSeries->setName("Crop by month - Season (Click on bar to drill down)"); // Each month in season series has drilldown series for weekly data for (int month = 0; month < months.count(); month++) { - // Create drilldown series for every week - DrilldownBarSeries *weeklySeries = new DrilldownBarSeries(weeks, 80, drilldownChart); + auto weeklySeries = new StackedDrilldownSeries(weeks, 80, drilldownChart); seasonSeries->mapDrilldownSeries(month, weeklySeries); // Drilling down from weekly data brings us back to season data. @@ -54,21 +48,21 @@ int main(int argc, char *argv[]) } // Use clicked signal to implement drilldown - QObject::connect(weeklySeries, &DrilldownBarSeries::clicked, - drilldownChart, &DrilldownChart::handleClicked); + QObject::connect(weeklySeries, &StackedDrilldownSeries::clicked, + drilldownChart, &StackedDrilldownChart::handleClicked); } // Enable drilldown from season series using clicked signal - QObject::connect(seasonSeries, &DrilldownBarSeries::clicked, - drilldownChart, &DrilldownChart::handleClicked); -//! [3] + QObject::connect(seasonSeries, &StackedDrilldownSeries::clicked, + drilldownChart, &StackedDrilldownChart::handleClicked); + //! [3] -//! [4] + //! [4] // Fill monthly and weekly series with data for (const QString &plant : plants) { - QBarSet *monthlyCrop = new QBarSet(plant); + auto monthlyCrop = new QBarSet(plant); for (int month = 0; month < months.count(); month++) { - QBarSet *weeklyCrop = new QBarSet(plant); + auto weeklyCrop = new QBarSet(plant); for (int week = 0; week < weeks.count(); week++) *weeklyCrop << QRandomGenerator::global()->bounded(20); // Get the drilldown series from season series and add crop to it. @@ -77,25 +71,21 @@ int main(int argc, char *argv[]) } seasonSeries->append(monthlyCrop); } -//! [4] + //! [4] -//! [5] + //! [5] // Show season series in initial view drilldownChart->changeSeries(seasonSeries); drilldownChart->setTitle(seasonSeries->name()); -//! [5] + //! [5] -//! [6] + //! [6] drilldownChart->axes(Qt::Horizontal).first()->setGridLineVisible(false); drilldownChart->legend()->setVisible(true); drilldownChart->legend()->setAlignment(Qt::AlignBottom); -//! [6] + //! [6] - QChartView *chartView = new QChartView(drilldownChart); - window.setCentralWidget(chartView); - window.resize(480, 300); - window.show(); - - return a.exec(); + //! [7] + createDefaultChartView(drilldownChart); + //! [7] } - diff --git a/examples/charts/gallery/stackeddrilldownwidget.h b/examples/charts/gallery/stackeddrilldownwidget.h new file mode 100644 index 00000000..a8c8acff --- /dev/null +++ b/examples/charts/gallery/stackeddrilldownwidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef STACKEDDRILLDOWNWIDGET_H +#define STACKEDDRILLDOWNWIDGET_H + +#include "contentwidget.h" + +class StackedDrilldownWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit StackedDrilldownWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/gallery/temperaturerecordswidget.cpp b/examples/charts/gallery/temperaturerecordswidget.cpp new file mode 100644 index 00000000..36b748be --- /dev/null +++ b/examples/charts/gallery/temperaturerecordswidget.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "temperaturerecordswidget.h" + +#include <QBarCategoryAxis> +#include <QBarSeries> +#include <QBarSet> +#include <QChart> +#include <QLegend> +#include <QStackedBarSeries> +#include <QValueAxis> + +TemperatureRecordsWidget::TemperatureRecordsWidget(QWidget *parent) + : ContentWidget(parent) +{ + //![1] + auto low = new QBarSet("Min"); + auto high = new QBarSet("Max"); + + *low << -52 << -50 << -45.3 << -37.0 << -25.6 << -8.0 + << -6.0 << -11.8 << -19.7 << -32.8 << -43.0 << -48.0; + *high << 11.9 << 12.8 << 18.5 << 26.5 << 32.0 << 34.8 + << 38.2 << 34.8 << 29.8 << 20.4 << 15.1 << 11.8; + //![1] + + //![2] + auto series = new QStackedBarSeries; + series->append(low); + series->append(high); + //![2] + + //![3] + auto chart = new QChart; + chart->addSeries(series); + chart->setTitle("Temperature records in Celcius"); + chart->setAnimationOptions(QChart::SeriesAnimations); + //![3] + + //![4] + QStringList categories = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + + auto axisX = new QBarCategoryAxis; + axisX->append(categories); + axisX->setTitleText("Month"); + chart->addAxis(axisX, Qt::AlignBottom); + auto axisY = new QValueAxis; + axisY->setRange(-52, 52); + axisY->setTitleText("Temperature [°C]"); + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisX); + series->attachAxis(axisY); + //![4] + + //![5] + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //![5] + + //![6] + createDefaultChartView(chart); + //![6] +} diff --git a/examples/charts/gallery/temperaturerecordswidget.h b/examples/charts/gallery/temperaturerecordswidget.h new file mode 100644 index 00000000..eb43717c --- /dev/null +++ b/examples/charts/gallery/temperaturerecordswidget.h @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef TEMPERATURERECORDSWIDGET_H +#define TEMPERATURERECORDSWIDGET_H + +#include "contentwidget.h" + +class TemperatureRecordsWidget : public ContentWidget +{ + Q_OBJECT +public: + explicit TemperatureRecordsWidget(QWidget *parent = nullptr); +}; + +#endif diff --git a/examples/charts/chartthemes/themewidget.cpp b/examples/charts/gallery/themewidget.cpp index 49d7ee5f..31afc403 100644 --- a/examples/charts/chartthemes/themewidget.cpp +++ b/examples/charts/gallery/themewidget.cpp @@ -1,36 +1,29 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "themewidget.h" #include "ui_themewidget.h" -#include <QtCharts/QChartView> -#include <QtCharts/QPieSeries> -#include <QtCharts/QPieSlice> -#include <QtCharts/QAbstractBarSeries> -#include <QtCharts/QPercentBarSeries> -#include <QtCharts/QStackedBarSeries> -#include <QtCharts/QBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLineSeries> -#include <QtCharts/QSplineSeries> -#include <QtCharts/QScatterSeries> -#include <QtCharts/QAreaSeries> -#include <QtCharts/QLegend> -#include <QtWidgets/QGridLayout> -#include <QtWidgets/QFormLayout> -#include <QtWidgets/QComboBox> -#include <QtWidgets/QSpinBox> -#include <QtWidgets/QCheckBox> -#include <QtWidgets/QGroupBox> -#include <QtWidgets/QLabel> -#include <QtCore/QRandomGenerator> -#include <QtCharts/QBarCategoryAxis> -#include <QtWidgets/QApplication> -#include <QtCharts/QValueAxis> +#include <QAbstractBarSeries> +#include <QAreaSeries> +#include <QBarSet> +#include <QChartView> +#include <QCheckBox> +#include <QComboBox> +#include <QGridLayout> +#include <QLegend> +#include <QLineSeries> +#include <QPercentBarSeries> +#include <QPieSeries> +#include <QPieSlice> +#include <QRandomGenerator> +#include <QScatterSeries> +#include <QSplineSeries> +#include <QStackedBarSeries> +#include <QValueAxis> ThemeWidget::ThemeWidget(QWidget *parent) : - QWidget(parent), + ContentWidget(parent), m_listCount(3), m_valueMax(10), m_valueCount(7), @@ -46,43 +39,37 @@ ThemeWidget::ThemeWidget(QWidget *parent) : QChartView *chartView; - chartView = new QChartView(createAreaChart()); + chartView = new QChartView(createAreaChart(), this); m_ui->gridLayout->addWidget(chartView, 1, 0); m_charts << chartView; - chartView = new QChartView(createPieChart()); + chartView = new QChartView(createPieChart(), this); // Funny things happen if the pie slice labels do not fit the screen, so we ignore size policy chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); m_ui->gridLayout->addWidget(chartView, 1, 1); m_charts << chartView; //![5] - chartView = new QChartView(createLineChart()); + chartView = new QChartView(createLineChart(), this); m_ui->gridLayout->addWidget(chartView, 1, 2); //![5] m_charts << chartView; - chartView = new QChartView(createBarChart(m_valueCount)); + chartView = new QChartView(createBarChart(m_valueCount), this); m_ui->gridLayout->addWidget(chartView, 2, 0); m_charts << chartView; - chartView = new QChartView(createSplineChart()); + chartView = new QChartView(createSplineChart(), this); m_ui->gridLayout->addWidget(chartView, 2, 1); m_charts << chartView; - chartView = new QChartView(createScatterChart()); + chartView = new QChartView(createScatterChart(), this); m_ui->gridLayout->addWidget(chartView, 2, 2); m_charts << chartView; // Set defaults m_ui->antialiasCheckBox->setChecked(true); - // Set the colors from the light theme as default ones - QPalette pal = qApp->palette(); - pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); - pal.setColor(QPalette::WindowText, QRgb(0x404044)); - qApp->setPalette(pal); - updateUI(); } @@ -146,15 +133,15 @@ void ThemeWidget::populateLegendBox() QChart *ThemeWidget::createAreaChart() const { - QChart *chart = new QChart(); - chart->setTitle("Area chart"); + auto chart = new QChart; + chart->setTitle("Area Chart"); // The lower series initialized to zero values - QLineSeries *lowerSeries = 0; + QLineSeries *lowerSeries = nullptr; QString name("Series "); int nameIndex = 0; for (int i(0); i < m_dataTable.count(); i++) { - QLineSeries *upperSeries = new QLineSeries(chart); + auto upperSeries = new QLineSeries(chart); for (int j(0); j < m_dataTable[i].count(); j++) { Data data = m_dataTable[i].at(j); if (lowerSeries) { @@ -164,7 +151,7 @@ QChart *ThemeWidget::createAreaChart() const upperSeries->append(QPointF(j, data.first.y())); } } - QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); + auto area = new QAreaSeries(upperSeries, lowerSeries); area->setName(name + QString::number(nameIndex)); nameIndex++; chart->addSeries(area); @@ -175,7 +162,7 @@ QChart *ThemeWidget::createAreaChart() const chart->axes(Qt::Horizontal).first()->setRange(0, m_valueCount - 1); chart->axes(Qt::Vertical).first()->setRange(0, m_valueMax); // Add space to label to add space between labels and axis - QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first()); + auto axisY = qobject_cast<QValueAxis *>(chart->axes(Qt::Vertical).first()); Q_ASSERT(axisY); axisY->setLabelFormat("%.1f "); @@ -185,12 +172,12 @@ QChart *ThemeWidget::createAreaChart() const QChart *ThemeWidget::createBarChart(int valueCount) const { Q_UNUSED(valueCount); - QChart *chart = new QChart(); - chart->setTitle("Bar chart"); + auto chart = new QChart; + chart->setTitle("Bar Chart"); - QStackedBarSeries *series = new QStackedBarSeries(chart); + auto series = new QStackedBarSeries(chart); for (int i(0); i < m_dataTable.count(); i++) { - QBarSet *set = new QBarSet("Bar set " + QString::number(i)); + auto set = new QBarSet("Bar set " + QString::number(i)); for (const Data &data : m_dataTable[i]) *set << data.first.y(); series->append(set); @@ -200,7 +187,7 @@ QChart *ThemeWidget::createBarChart(int valueCount) const chart->createDefaultAxes(); chart->axes(Qt::Vertical).first()->setRange(0, m_valueMax * 2); // Add space to label to add space between labels and axis - QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first()); + auto axisY = qobject_cast<QValueAxis *>(chart->axes(Qt::Vertical).first()); Q_ASSERT(axisY); axisY->setLabelFormat("%.1f "); @@ -210,15 +197,15 @@ QChart *ThemeWidget::createBarChart(int valueCount) const QChart *ThemeWidget::createLineChart() const { //![1] - QChart *chart = new QChart(); - chart->setTitle("Line chart"); + auto chart = new QChart; + chart->setTitle("Line Chart"); //![1] //![2] QString name("Series "); int nameIndex = 0; for (const DataList &list : m_dataTable) { - QLineSeries *series = new QLineSeries(chart); + auto series = new QLineSeries(chart); for (const Data &data : list) series->append(data.first); series->setName(name + QString::number(nameIndex)); @@ -234,7 +221,7 @@ QChart *ThemeWidget::createLineChart() const //![3] //![4] // Add space to label to add space between labels and axis - QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first()); + auto axisY = qobject_cast<QValueAxis *>(chart->axes(Qt::Vertical).first()); Q_ASSERT(axisY); axisY->setLabelFormat("%.1f "); //![4] @@ -244,10 +231,10 @@ QChart *ThemeWidget::createLineChart() const QChart *ThemeWidget::createPieChart() const { - QChart *chart = new QChart(); - chart->setTitle("Pie chart"); + auto chart = new QChart; + chart->setTitle("Pie Chart"); - QPieSeries *series = new QPieSeries(chart); + auto series = new QPieSeries(chart); for (const Data &data : m_dataTable[0]) { QPieSlice *slice = series->append(data.second, data.first.y()); if (data == m_dataTable[0].first()) { @@ -265,12 +252,12 @@ QChart *ThemeWidget::createPieChart() const QChart *ThemeWidget::createSplineChart() const { - QChart *chart = new QChart(); - chart->setTitle("Spline chart"); + auto chart = new QChart; + chart->setTitle("Spline Chart"); QString name("Series "); int nameIndex = 0; for (const DataList &list : m_dataTable) { - QSplineSeries *series = new QSplineSeries(chart); + auto series = new QSplineSeries(chart); for (const Data &data : list) series->append(data.first); series->setName(name + QString::number(nameIndex)); @@ -283,7 +270,7 @@ QChart *ThemeWidget::createSplineChart() const chart->axes(Qt::Vertical).first()->setRange(0, m_valueCount); // Add space to label to add space between labels and axis - QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first()); + auto axisY = qobject_cast<QValueAxis *>(chart->axes(Qt::Vertical).first()); Q_ASSERT(axisY); axisY->setLabelFormat("%.1f "); return chart; @@ -292,12 +279,12 @@ QChart *ThemeWidget::createSplineChart() const QChart *ThemeWidget::createScatterChart() const { // scatter chart - QChart *chart = new QChart(); - chart->setTitle("Scatter chart"); + auto chart = new QChart; + chart->setTitle("Scatter Chart"); QString name("Series "); int nameIndex = 0; for (const DataList &list : m_dataTable) { - QScatterSeries *series = new QScatterSeries(chart); + auto series = new QScatterSeries(chart); for (const Data &data : list) series->append(data.first); series->setName(name + QString::number(nameIndex)); @@ -309,7 +296,7 @@ QChart *ThemeWidget::createScatterChart() const chart->axes(Qt::Horizontal).first()->setRange(0, m_valueMax); chart->axes(Qt::Vertical).first()->setRange(0, m_valueCount); // Add space to label to add space between labels and axis - QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first()); + auto axisY = qobject_cast<QValueAxis *>(chart->axes(Qt::Vertical).first()); Q_ASSERT(axisY); axisY->setLabelFormat("%.1f "); return chart; @@ -318,7 +305,7 @@ QChart *ThemeWidget::createScatterChart() const void ThemeWidget::updateUI() { //![6] - QChart::ChartTheme theme = static_cast<QChart::ChartTheme>( + auto theme = static_cast<QChart::ChartTheme>( m_ui->themeComboBox->itemData(m_ui->themeComboBox->currentIndex()).toInt()); //![6] const auto charts = m_charts; @@ -328,37 +315,6 @@ void ThemeWidget::updateUI() chartView->chart()->setTheme(theme); //![7] } - - // Set palette colors based on selected theme - //![8] - QPalette pal = window()->palette(); - if (theme == QChart::ChartThemeLight) { - pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); - pal.setColor(QPalette::WindowText, QRgb(0x404044)); - //![8] - } else if (theme == QChart::ChartThemeDark) { - pal.setColor(QPalette::Window, QRgb(0x121218)); - pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); - } else if (theme == QChart::ChartThemeBlueCerulean) { - pal.setColor(QPalette::Window, QRgb(0x40434a)); - pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); - } else if (theme == QChart::ChartThemeBrownSand) { - pal.setColor(QPalette::Window, QRgb(0x9e8965)); - pal.setColor(QPalette::WindowText, QRgb(0x404044)); - } else if (theme == QChart::ChartThemeBlueNcs) { - pal.setColor(QPalette::Window, QRgb(0x018bba)); - pal.setColor(QPalette::WindowText, QRgb(0x404044)); - } else if (theme == QChart::ChartThemeHighContrast) { - pal.setColor(QPalette::Window, QRgb(0xffab03)); - pal.setColor(QPalette::WindowText, QRgb(0x181818)); - } else if (theme == QChart::ChartThemeBlueIcy) { - pal.setColor(QPalette::Window, QRgb(0xcee7f0)); - pal.setColor(QPalette::WindowText, QRgb(0x404044)); - } else { - pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); - pal.setColor(QPalette::WindowText, QRgb(0x404044)); - } - window()->setPalette(pal); } // Update antialiasing diff --git a/examples/charts/chartthemes/themewidget.h b/examples/charts/gallery/themewidget.h index 8c7fb808..e630040c 100644 --- a/examples/charts/chartthemes/themewidget.h +++ b/examples/charts/gallery/themewidget.h @@ -1,37 +1,27 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef THEMEWIDGET_H #define THEMEWIDGET_H -#include <QtWidgets/QWidget> -#include <QtCharts/QChartGlobal> +#include "contentwidget.h" -QT_BEGIN_NAMESPACE -class QComboBox; -class QCheckBox; -class Ui_ThemeWidgetForm; -QT_END_NAMESPACE - -QT_BEGIN_NAMESPACE -class QChartView; -class QChart; -QT_END_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QChart) +QT_FORWARD_DECLARE_CLASS(QChartView) +QT_FORWARD_DECLARE_CLASS(Ui_ThemeWidgetForm); typedef QPair<QPointF, QString> Data; typedef QList<Data> DataList; typedef QList<DataList> DataTable; -QT_USE_NAMESPACE - -class ThemeWidget: public QWidget +class ThemeWidget: public ContentWidget { Q_OBJECT public: - explicit ThemeWidget(QWidget *parent = 0); + explicit ThemeWidget(QWidget *parent = nullptr); ~ThemeWidget(); -private Q_SLOTS: +private slots: void updateUI(); private: @@ -57,4 +47,4 @@ private: Ui_ThemeWidgetForm *m_ui; }; -#endif /* THEMEWIDGET_H */ +#endif diff --git a/examples/charts/chartthemes/themewidget.ui b/examples/charts/gallery/themewidget.ui index 9ea2bb7c..9ea2bb7c 100644 --- a/examples/charts/chartthemes/themewidget.ui +++ b/examples/charts/gallery/themewidget.ui diff --git a/examples/charts/horizontalbarchart/CMakeLists.txt b/examples/charts/horizontalbarchart/CMakeLists.txt deleted file mode 100644 index 9a25f58c..00000000 --- a/examples/charts/horizontalbarchart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(horizontalbarchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/horizontalbarchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(horizontalbarchart - main.cpp -) - -set_target_properties(horizontalbarchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(horizontalbarchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS horizontalbarchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/horizontalbarchart/horizontalbarchart.pro b/examples/charts/horizontalbarchart/horizontalbarchart.pro deleted file mode 100644 index f0acf2bc..00000000 --- a/examples/charts/horizontalbarchart/horizontalbarchart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/horizontalbarchart -INSTALLS += target diff --git a/examples/charts/horizontalbarchart/main.cpp b/examples/charts/horizontalbarchart/main.cpp deleted file mode 100644 index e1de0da8..00000000 --- a/examples/charts/horizontalbarchart/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QValueAxis> -#include <QtCharts/QHorizontalBarSeries> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QBarSet *set0 = new QBarSet("Jane"); - QBarSet *set1 = new QBarSet("John"); - QBarSet *set2 = new QBarSet("Axel"); - QBarSet *set3 = new QBarSet("Mary"); - QBarSet *set4 = new QBarSet("Samantha"); - - *set0 << 1 << 2 << 3 << 4 << 5 << 6; - *set1 << 5 << 0 << 0 << 4 << 0 << 7; - *set2 << 3 << 5 << 8 << 13 << 8 << 5; - *set3 << 5 << 6 << 7 << 3 << 4 << 5; - *set4 << 9 << 7 << 5 << 3 << 1 << 2; -//![1] - -//![2] - QHorizontalBarSeries *series = new QHorizontalBarSeries(); - series->append(set0); - series->append(set1); - series->append(set2); - series->append(set3); - series->append(set4); -//![2] - -//![3] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->setTitle("Simple horizontal barchart example"); - chart->setAnimationOptions(QChart::SeriesAnimations); -//![3] - -//![4] - QStringList categories; - categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - QBarCategoryAxis *axisY = new QBarCategoryAxis(); - axisY->append(categories); - chart->addAxis(axisY, Qt::AlignLeft); - series->attachAxis(axisY); - QValueAxis *axisX = new QValueAxis(); - chart->addAxis(axisX, Qt::AlignBottom); - series->attachAxis(axisX); - axisX->applyNiceNumbers(); -//![4] - -//![5] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); -//![5] - -//![6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![6] - -//![7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(420, 300); - window.show(); -//![7] - - return a.exec(); -} diff --git a/examples/charts/horizontalpercentbarchart/CMakeLists.txt b/examples/charts/horizontalpercentbarchart/CMakeLists.txt deleted file mode 100644 index 3f0063a9..00000000 --- a/examples/charts/horizontalpercentbarchart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(horizontalpercentbarchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/horizontalpercentbarchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(horizontalpercentbarchart - main.cpp -) - -set_target_properties(horizontalpercentbarchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(horizontalpercentbarchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS horizontalpercentbarchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/horizontalpercentbarchart/horizontalpercentbarchart.pro b/examples/charts/horizontalpercentbarchart/horizontalpercentbarchart.pro deleted file mode 100644 index 5bd65774..00000000 --- a/examples/charts/horizontalpercentbarchart/horizontalpercentbarchart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/horizontalpercentbarchart -INSTALLS += target diff --git a/examples/charts/horizontalpercentbarchart/main.cpp b/examples/charts/horizontalpercentbarchart/main.cpp deleted file mode 100644 index 2dff853d..00000000 --- a/examples/charts/horizontalpercentbarchart/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QHorizontalPercentBarSeries> -#include <QtCharts/QValueAxis> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QBarSet *set0 = new QBarSet("Jane"); - QBarSet *set1 = new QBarSet("John"); - QBarSet *set2 = new QBarSet("Axel"); - QBarSet *set3 = new QBarSet("Mary"); - QBarSet *set4 = new QBarSet("Samantha"); - - *set0 << 1 << 2 << 3 << 4 << 5 << 6; - *set1 << 5 << 0 << 0 << 4 << 0 << 7; - *set2 << 3 << 5 << 8 << 13 << 8 << 5; - *set3 << 5 << 6 << 7 << 3 << 4 << 5; - *set4 << 9 << 7 << 5 << 3 << 1 << 2; -//![1] - -//![2] - QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(); - series->append(set0); - series->append(set1); - series->append(set2); - series->append(set3); - series->append(set4); - -//![2] - -//![3] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->setTitle("Simple horizontal percent barchart example"); - chart->setAnimationOptions(QChart::SeriesAnimations); -//![3] - -//![4] - QStringList categories; - categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - QBarCategoryAxis *axisY = new QBarCategoryAxis(); - axisY->append(categories); - chart->addAxis(axisY, Qt::AlignLeft); - series->attachAxis(axisY); - QValueAxis *axisX = new QValueAxis(); - chart->addAxis(axisX, Qt::AlignBottom); - series->attachAxis(axisX); -//![4] - -//![5] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); -//![5] - -//![6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![6] - -//![7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(420, 300); - window.show(); -//![7] - - return a.exec(); -} diff --git a/examples/charts/horizontalstackedbarchart/CMakeLists.txt b/examples/charts/horizontalstackedbarchart/CMakeLists.txt deleted file mode 100644 index 0b51114e..00000000 --- a/examples/charts/horizontalstackedbarchart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(horizontalstackedbarchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/horizontalstackedbarchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(horizontalstackedbarchart - main.cpp -) - -set_target_properties(horizontalstackedbarchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(horizontalstackedbarchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS horizontalstackedbarchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/horizontalstackedbarchart/horizontalstackedbarchart.pro b/examples/charts/horizontalstackedbarchart/horizontalstackedbarchart.pro deleted file mode 100644 index b6ba1612..00000000 --- a/examples/charts/horizontalstackedbarchart/horizontalstackedbarchart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/horizontalstackedbarchart -INSTALLS += target diff --git a/examples/charts/horizontalstackedbarchart/main.cpp b/examples/charts/horizontalstackedbarchart/main.cpp deleted file mode 100644 index cd507f12..00000000 --- a/examples/charts/horizontalstackedbarchart/main.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QHorizontalStackedBarSeries> -#include <QtCharts/QValueAxis> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QBarSet *set0 = new QBarSet("Jane"); - QBarSet *set1 = new QBarSet("John"); - QBarSet *set2 = new QBarSet("Axel"); - QBarSet *set3 = new QBarSet("Mary"); - QBarSet *set4 = new QBarSet("Samantha"); - - *set0 << 1 << 2 << 3 << 4 << 5 << 6; - *set1 << 5 << 0 << 0 << 4 << 0 << 7; - *set2 << 3 << 5 << 8 << 13 << 8 << 5; - *set3 << 5 << 6 << 7 << 3 << 4 << 5; - *set4 << 9 << 7 << 5 << 3 << 1 << 2; -//![1] - -//![2] - QHorizontalStackedBarSeries *series = new QHorizontalStackedBarSeries(); - series->append(set0); - series->append(set1); - series->append(set2); - series->append(set3); - series->append(set4); - -//![2] - -//![3] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->setTitle("Simple horizontal stacked barchart example"); - chart->setAnimationOptions(QChart::SeriesAnimations); -//![3] - -//![4] - QStringList categories; - categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - QBarCategoryAxis *axisY = new QBarCategoryAxis(); - axisY->append(categories); - chart->addAxis(axisY, Qt::AlignLeft); - series->attachAxis(axisY); - QValueAxis *axisX = new QValueAxis(); - chart->addAxis(axisX, Qt::AlignBottom); - series->attachAxis(axisX); -//![4] - -//![5] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); -//![5] - -//![6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![6] - -//![7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(420, 300); - window.show(); -//![7] - - return a.exec(); -} diff --git a/examples/charts/legend/CMakeLists.txt b/examples/charts/legend/CMakeLists.txt deleted file mode 100644 index 3ede108a..00000000 --- a/examples/charts/legend/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(legend LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/legend") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(legend - main.cpp - mainwidget.cpp mainwidget.h -) - -set_target_properties(legend PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(legend PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS legend - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/legend/legend.pro b/examples/charts/legend/legend.pro deleted file mode 100644 index 5e832ed8..00000000 --- a/examples/charts/legend/legend.pro +++ /dev/null @@ -1,11 +0,0 @@ -QT += charts - -HEADERS += \ - mainwidget.h - -SOURCES += \ - main.cpp \ - mainwidget.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/legend -INSTALLS += target diff --git a/examples/charts/legend/main.cpp b/examples/charts/legend/main.cpp deleted file mode 100644 index bed022a8..00000000 --- a/examples/charts/legend/main.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "mainwidget.h" - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - MainWidget w; - w.resize(720, 480); - w.show(); - - return a.exec(); -} diff --git a/examples/charts/legendmarkers/CMakeLists.txt b/examples/charts/legendmarkers/CMakeLists.txt deleted file mode 100644 index 3ccc2f70..00000000 --- a/examples/charts/legendmarkers/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(legendmarkers LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/legendmarkers") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(legendmarkers - main.cpp - mainwidget.cpp mainwidget.h -) - -set_target_properties(legendmarkers PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(legendmarkers PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS legendmarkers - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/legendmarkers/legendmarkers.pro b/examples/charts/legendmarkers/legendmarkers.pro deleted file mode 100644 index 169393e0..00000000 --- a/examples/charts/legendmarkers/legendmarkers.pro +++ /dev/null @@ -1,11 +0,0 @@ -QT += charts - -HEADERS += \ - mainwidget.h - -SOURCES += \ - main.cpp \ - mainwidget.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/legendmarkers -INSTALLS += target diff --git a/examples/charts/legendmarkers/mainwidget.h b/examples/charts/legendmarkers/mainwidget.h deleted file mode 100644 index d0e0405d..00000000 --- a/examples/charts/legendmarkers/mainwidget.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef MAINWIDGET_H -#define MAINWIDGET_H - -#include <QtCharts/QChartGlobal> -#include <QtCharts/QChart> -#include <QtCharts/QChartView> -#include <QtWidgets/QWidget> -#include <QtWidgets/QGraphicsWidget> -#include <QtWidgets/QGridLayout> -#include <QtWidgets/QGraphicsGridLayout> -#include <QtWidgets/QDoubleSpinBox> -#include <QtWidgets/QGroupBox> -#include <QtCharts/QLineSeries> - -QT_USE_NAMESPACE - -class MainWidget : public QWidget -{ - Q_OBJECT -public: - explicit MainWidget(QWidget *parent = 0); - -public slots: - void addSeries(); - void removeSeries(); - void connectMarkers(); - void disconnectMarkers(); - - void handleMarkerClicked(); - -private: - - QChart *m_chart; - QList<QLineSeries *> m_series; - - QChartView *m_chartView; - QGridLayout *m_mainLayout; - QGridLayout *m_fontLayout; - -}; - -#endif // MAINWIDGET_H diff --git a/examples/charts/lineandbar/CMakeLists.txt b/examples/charts/lineandbar/CMakeLists.txt deleted file mode 100644 index 719f698d..00000000 --- a/examples/charts/lineandbar/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(lineandbar LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/lineandbar") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(lineandbar - main.cpp -) - -set_target_properties(lineandbar PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(lineandbar PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS lineandbar - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/lineandbar/lineandbar.pro b/examples/charts/lineandbar/lineandbar.pro deleted file mode 100644 index 073cca49..00000000 --- a/examples/charts/lineandbar/lineandbar.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/lineandbar -INSTALLS += target diff --git a/examples/charts/linechart/CMakeLists.txt b/examples/charts/linechart/CMakeLists.txt deleted file mode 100644 index 5b0d2c8e..00000000 --- a/examples/charts/linechart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(linechart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/linechart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(linechart - main.cpp -) - -set_target_properties(linechart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(linechart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS linechart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/linechart/linechart.pro b/examples/charts/linechart/linechart.pro deleted file mode 100644 index 71f70965..00000000 --- a/examples/charts/linechart/linechart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/linechart -INSTALLS += target diff --git a/examples/charts/linechart/main.cpp b/examples/charts/linechart/main.cpp deleted file mode 100644 index 1ea15d14..00000000 --- a/examples/charts/linechart/main.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QLineSeries *series = new QLineSeries(); -//![1] - -//![2] - series->append(0, 6); - series->append(2, 4); - series->append(3, 8); - series->append(7, 4); - series->append(10, 5); - *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); -//![2] - -//![3] - QChart *chart = new QChart(); - chart->legend()->hide(); - chart->addSeries(series); - chart->createDefaultAxes(); - chart->setTitle("Simple line chart example"); -//![3] - -//![4] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![4] - - -//![5] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); -//![5] - - return a.exec(); -} diff --git a/examples/charts/logvalueaxis/CMakeLists.txt b/examples/charts/logvalueaxis/CMakeLists.txt deleted file mode 100644 index f88d3f3e..00000000 --- a/examples/charts/logvalueaxis/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(logvalueaxis LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/logvalueaxis") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(logvalueaxis - main.cpp -) - -set_target_properties(logvalueaxis PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(logvalueaxis PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS logvalueaxis - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/logvalueaxis/logvalueaxis.pro b/examples/charts/logvalueaxis/logvalueaxis.pro deleted file mode 100644 index 196a062a..00000000 --- a/examples/charts/logvalueaxis/logvalueaxis.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/logvalueaxis -INSTALLS += target diff --git a/examples/charts/logvalueaxis/main.cpp b/examples/charts/logvalueaxis/main.cpp deleted file mode 100644 index ebe8bded..00000000 --- a/examples/charts/logvalueaxis/main.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCharts/QLogValueAxis> -#include <QtCharts/QValueAxis> -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - //![1] - QLineSeries *series = new QLineSeries(); - *series << QPointF(1.0, 1.0) << QPointF(2.0, 73.0) << QPointF(3.0, 268.0) << QPointF(4.0, 17.0) - << QPointF(5.0, 4325.0) << QPointF(6.0, 723.0); - //![1] - - //![2] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->legend()->hide(); - chart->setTitle("Logarithmic axis example"); - //![2] - - //![3] - QValueAxis *axisX = new QValueAxis(); - axisX->setTitleText("Data point"); - axisX->setLabelFormat("%i"); - axisX->setTickCount(series->count()); - chart->addAxis(axisX, Qt::AlignBottom); - series->attachAxis(axisX); - - QLogValueAxis *axisY = new QLogValueAxis(); - axisY->setTitleText("Values"); - axisY->setLabelFormat("%g"); - axisY->setBase(8.0); - axisY->setMinorTickCount(-1); - chart->addAxis(axisY, Qt::AlignLeft); - series->attachAxis(axisY); - //![3] - - //![4] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); - //![4] - - //![5] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(800, 600); - window.show(); - //![5] - - return app.exec(); -} diff --git a/examples/charts/modeldata/CMakeLists.txt b/examples/charts/modeldata/CMakeLists.txt deleted file mode 100644 index 92bfc3ca..00000000 --- a/examples/charts/modeldata/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(modeldata LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/modeldata") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(modeldata - customtablemodel.cpp customtablemodel.h - main.cpp - tablewidget.cpp tablewidget.h -) - -set_target_properties(modeldata PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(modeldata PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS modeldata - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/modeldata/main.cpp b/examples/charts/modeldata/main.cpp deleted file mode 100644 index 92485579..00000000 --- a/examples/charts/modeldata/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include "tablewidget.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - TableWidget w; - w.show(); - return a.exec(); -} diff --git a/examples/charts/modeldata/modeldata.pro b/examples/charts/modeldata/modeldata.pro deleted file mode 100644 index b71a9d66..00000000 --- a/examples/charts/modeldata/modeldata.pro +++ /dev/null @@ -1,14 +0,0 @@ -QT += charts -requires(qtConfig(tableview)) - -HEADERS += \ - customtablemodel.h \ - tablewidget.h - -SOURCES += \ - customtablemodel.cpp \ - main.cpp \ - tablewidget.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/modeldata -INSTALLS += target diff --git a/examples/charts/modeldata/tablewidget.h b/examples/charts/modeldata/tablewidget.h deleted file mode 100644 index 60640e40..00000000 --- a/examples/charts/modeldata/tablewidget.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef TABLEWIDGET_H -#define TABLEWIDGET_H - -#include <QtWidgets/QWidget> - -class TableWidget : public QWidget -{ - Q_OBJECT - -public: - TableWidget(QWidget *parent = 0); -}; - -#endif // TABLEWIDGET_H diff --git a/examples/charts/multiaxis/CMakeLists.txt b/examples/charts/multiaxis/CMakeLists.txt deleted file mode 100644 index d1171918..00000000 --- a/examples/charts/multiaxis/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(multiaxis LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/multiaxis") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(multiaxis - main.cpp -) - -set_target_properties(multiaxis PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(multiaxis PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS multiaxis - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/multiaxis/multiaxis.pro b/examples/charts/multiaxis/multiaxis.pro deleted file mode 100644 index 9edca6ba..00000000 --- a/examples/charts/multiaxis/multiaxis.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/multiaxis -INSTALLS += target diff --git a/examples/charts/nesteddonuts/CMakeLists.txt b/examples/charts/nesteddonuts/CMakeLists.txt deleted file mode 100644 index b48b3ed9..00000000 --- a/examples/charts/nesteddonuts/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(nesteddonuts LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/nesteddonuts") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(nesteddonuts - main.cpp - widget.cpp widget.h -) - -set_target_properties(nesteddonuts PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(nesteddonuts PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS nesteddonuts - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/nesteddonuts/main.cpp b/examples/charts/nesteddonuts/main.cpp deleted file mode 100644 index 41fa002a..00000000 --- a/examples/charts/nesteddonuts/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include "widget.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - Widget w; - w.show(); - return a.exec(); -} diff --git a/examples/charts/nesteddonuts/nesteddonuts.pro b/examples/charts/nesteddonuts/nesteddonuts.pro deleted file mode 100644 index 571f1a06..00000000 --- a/examples/charts/nesteddonuts/nesteddonuts.pro +++ /dev/null @@ -1,11 +0,0 @@ -QT += charts - -HEADERS += \ - widget.h - -SOURCES += \ - main.cpp \ - widget.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/nesteddonuts -INSTALLS += target diff --git a/examples/charts/nesteddonuts/widget.h b/examples/charts/nesteddonuts/widget.h deleted file mode 100644 index 52945911..00000000 --- a/examples/charts/nesteddonuts/widget.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef WIDGET_H -#define WIDGET_H - -#include <QtWidgets/QWidget> -#include <QtCharts/QPieSeries> - -QT_BEGIN_NAMESPACE -class QTimer; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class Widget : public QWidget -{ - Q_OBJECT - -public: - Widget(QWidget *parent = 0); - ~Widget(); - -public slots: - void updateRotation(); - void explodeSlice(bool exploded); - -private: - QList<QPieSeries *> m_donuts; - QTimer *updateTimer; -}; - -#endif // WIDGET_H diff --git a/examples/charts/openglseries/CMakeLists.txt b/examples/charts/openglseries/CMakeLists.txt index 065bd1d9..4e3739fa 100644 --- a/examples/charts/openglseries/CMakeLists.txt +++ b/examples/charts/openglseries/CMakeLists.txt @@ -4,8 +4,6 @@ cmake_minimum_required(VERSION 3.16) project(openglseries LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/openglseries") find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) +qt_standard_project_setup() + qt_add_executable(openglseries datasource.cpp datasource.h main.cpp diff --git a/examples/charts/openglseries/datasource.cpp b/examples/charts/openglseries/datasource.cpp index 8d26338c..960db4d3 100644 --- a/examples/charts/openglseries/datasource.cpp +++ b/examples/charts/openglseries/datasource.cpp @@ -1,15 +1,15 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "datasource.h" -#include <QtCore/QtMath> -#include <QtCore/QRandomGenerator> -QT_USE_NAMESPACE +#include <QLabel> +#include <QRandomGenerator> +#include <QtMath> +#include <QXYSeries> -DataSource::DataSource(QObject *parent) : - QObject(parent), - m_index(-1) +DataSource::DataSource(QObject *parent) + : QObject(parent) { generateData(0, 0, 0); } @@ -17,7 +17,7 @@ DataSource::DataSource(QObject *parent) : void DataSource::update(QAbstractSeries *series, int seriesIndex) { if (series) { - QXYSeries *xySeries = static_cast<QXYSeries *>(series); + auto xySeries = static_cast<QXYSeries *>(series); const QList<QList<QPointF>> &seriesData = m_data.at(seriesIndex); if (seriesIndex == 0) m_index++; diff --git a/examples/charts/openglseries/datasource.h b/examples/charts/openglseries/datasource.h index a3756546..c6f9288a 100644 --- a/examples/charts/openglseries/datasource.h +++ b/examples/charts/openglseries/datasource.h @@ -1,22 +1,23 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef DATASOURCE_H #define DATASOURCE_H -#include <QtCore/QObject> -#include <QtCharts/QXYSeries> -#include <QtWidgets/QLabel> -#include <QtCore/QElapsedTimer> -#include <QtCore/QTimer> +#include <QElapsedTimer> +#include <QObject> +#include <QPointF> +#include <QTimer> -QT_USE_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QAbstractSeries) +QT_FORWARD_DECLARE_CLASS(QLabel) +QT_FORWARD_DECLARE_CLASS(QXYSeries) class DataSource : public QObject { Q_OBJECT public: - explicit DataSource(QObject *parent = 0); + explicit DataSource(QObject *parent = nullptr); void startUpdates(const QList<QXYSeries *> &seriesList, QLabel *fpsLabel); @@ -28,11 +29,11 @@ public slots: private: QList<QList<QList<QPointF>>> m_data; - int m_index; + int m_index = -1; QList<QXYSeries *> m_seriesList; - QLabel *m_fpsLabel; + QLabel *m_fpsLabel = nullptr; QElapsedTimer m_fpsTimer; QTimer m_dataUpdater; }; -#endif // DATASOURCE_H +#endif diff --git a/examples/charts/openglseries/main.cpp b/examples/charts/openglseries/main.cpp index 198294ec..c297b363 100644 --- a/examples/charts/openglseries/main.cpp +++ b/examples/charts/openglseries/main.cpp @@ -1,15 +1,16 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "datasource.h" -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QLineSeries> -#include <QtCharts/QScatterSeries> -#include <QtCharts/QValueAxis> -#include <QtCharts/QLogValueAxis> -#include <QtWidgets/QLabel> + +#include <QApplication> +#include <QChartView> +#include <QLabel> +#include <QLineSeries> +#include <QLogValueAxis> +#include <QMainWindow> +#include <QScatterSeries> +#include <QValueAxis> // Uncomment to use logarithmic axes instead of regular value axes //#define USE_LOG_AXIS @@ -21,23 +22,21 @@ // to verify the series have same visible geometry. //#define ADD_SIMPLE_SERIES -QT_USE_NAMESPACE - int main(int argc, char *argv[]) { QApplication a(argc, argv); QStringList colors; colors << "red" << "blue" << "green" << "black"; - QChart *chart = new QChart(); + auto chart = new QChart; chart->legend()->hide(); #ifdef USE_LOG_AXIS - QLogValueAxis *axisX = new QLogValueAxis; - QLogValueAxis *axisY = new QLogValueAxis; + auto axisX = new QLogValueAxis; + auto axisY = new QLogValueAxis; #else - QValueAxis *axisX = new QValueAxis; - QValueAxis *axisY = new QValueAxis; + auto axisX = new QValueAxis; + auto axisY = new QValueAxis; #endif chart->addAxis(axisX, Qt::AlignBottom); @@ -58,7 +57,7 @@ int main(int argc, char *argv[]) int colorIndex = i % colors.size(); if (i % 2) { series = new QScatterSeries; - QScatterSeries *scatter = static_cast<QScatterSeries *>(series); + auto scatter = static_cast<QScatterSeries *>(series); scatter->setColor(QColor(colors.at(colorIndex))); scatter->setMarkerSize(qreal(colorIndex + 2) / 2.0); // Scatter pen doesn't have affect in OpenGL drawing, but if you disable OpenGL drawing @@ -129,8 +128,8 @@ int main(int argc, char *argv[]) DataSource dataSource; dataSource.generateData(seriesCount, 10, pointCount); - QLabel *fpsLabel = new QLabel(&window); - QLabel *countLabel = new QLabel(&window); + auto fpsLabel = new QLabel(&window); + auto countLabel = new QLabel(&window); QString countText = QStringLiteral("Total point count: %1"); countLabel->setText(countText.arg(pointCount * seriesCount)); countLabel->adjustSize(); diff --git a/examples/charts/percentbarchart/CMakeLists.txt b/examples/charts/percentbarchart/CMakeLists.txt deleted file mode 100644 index 7b03a601..00000000 --- a/examples/charts/percentbarchart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(percentbarchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/percentbarchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(percentbarchart - main.cpp -) - -set_target_properties(percentbarchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(percentbarchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS percentbarchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/percentbarchart/main.cpp b/examples/charts/percentbarchart/main.cpp deleted file mode 100644 index 5d7a9037..00000000 --- a/examples/charts/percentbarchart/main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QPercentBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QValueAxis> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QBarSet *set0 = new QBarSet("Jane"); - QBarSet *set1 = new QBarSet("John"); - QBarSet *set2 = new QBarSet("Axel"); - QBarSet *set3 = new QBarSet("Mary"); - QBarSet *set4 = new QBarSet("Samantha"); - - *set0 << 1 << 2 << 3 << 4 << 5 << 6; - *set1 << 5 << 0 << 0 << 4 << 0 << 7; - *set2 << 3 << 5 << 8 << 13 << 8 << 5; - *set3 << 5 << 6 << 7 << 3 << 4 << 5; - *set4 << 9 << 7 << 5 << 3 << 1 << 2; -//![1] - -//![2] - QPercentBarSeries *series = new QPercentBarSeries(); - series->append(set0); - series->append(set1); - series->append(set2); - series->append(set3); - series->append(set4); -//![2] - -//![3] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->setTitle("Simple percentbarchart example"); - chart->setAnimationOptions(QChart::SeriesAnimations); -//![3] - -//![4] - QStringList categories; - categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - QBarCategoryAxis *axisX = new QBarCategoryAxis(); - axisX->append(categories); - chart->addAxis(axisX, Qt::AlignBottom); - series->attachAxis(axisX); - QValueAxis *axisY = new QValueAxis(); - chart->addAxis(axisY, Qt::AlignLeft); - series->attachAxis(axisY); -//![4] - -//![5] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); -//![5] - -//![6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![6] - -//![7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(420, 300); - window.show(); -//![7] - - return a.exec(); -} - diff --git a/examples/charts/percentbarchart/percentbarchart.pro b/examples/charts/percentbarchart/percentbarchart.pro deleted file mode 100644 index cfb718b0..00000000 --- a/examples/charts/percentbarchart/percentbarchart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/percentbarchart -INSTALLS += target diff --git a/examples/charts/piechart/CMakeLists.txt b/examples/charts/piechart/CMakeLists.txt deleted file mode 100644 index b8fb4f71..00000000 --- a/examples/charts/piechart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(piechart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/piechart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(piechart - main.cpp -) - -set_target_properties(piechart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(piechart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS piechart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/piechart/main.cpp b/examples/charts/piechart/main.cpp deleted file mode 100644 index c370182b..00000000 --- a/examples/charts/piechart/main.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QPieSeries> -#include <QtCharts/QPieSlice> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QPieSeries *series = new QPieSeries(); - series->append("Jane", 1); - series->append("Joe", 2); - series->append("Andy", 3); - series->append("Barbara", 4); - series->append("Axel", 5); -//![1] - -//![2] - QPieSlice *slice = series->slices().at(1); - slice->setExploded(); - slice->setLabelVisible(); - slice->setPen(QPen(Qt::darkGreen, 2)); - slice->setBrush(Qt::green); -//![2] - -//![3] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->setTitle("Simple piechart example"); - chart->legend()->hide(); -//![3] - -//![4] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![4] - -//![5] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); -//![5] - - return a.exec(); -} diff --git a/examples/charts/piechart/piechart.pro b/examples/charts/piechart/piechart.pro deleted file mode 100644 index e3767910..00000000 --- a/examples/charts/piechart/piechart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/piechart -INSTALLS += target diff --git a/examples/charts/piechartcustomization/CMakeLists.txt b/examples/charts/piechartcustomization/CMakeLists.txt deleted file mode 100644 index 1b580da3..00000000 --- a/examples/charts/piechartcustomization/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(piechartcustomization LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/piechartcustomization") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(piechartcustomization - brushtool.cpp brushtool.h - customslice.cpp customslice.h - main.cpp - mainwidget.cpp mainwidget.h - pentool.cpp pentool.h -) - -set_target_properties(piechartcustomization PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(piechartcustomization PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS piechartcustomization - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/piechartcustomization/brushtool.h b/examples/charts/piechartcustomization/brushtool.h deleted file mode 100644 index d58cfe66..00000000 --- a/examples/charts/piechartcustomization/brushtool.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef BRUSHTOOL_H -#define BRUSHTOOL_H - -#include <QtWidgets/QWidget> -#include <QtGui/QBrush> - -QT_BEGIN_NAMESPACE -class QPushButton; -class QComboBox; -QT_END_NAMESPACE - -class BrushTool : public QWidget -{ - Q_OBJECT - -public: - explicit BrushTool(QString title, QWidget *parent = 0); - void setBrush(QBrush brush); - QBrush brush() const; - QString name(); - static QString name(const QBrush &brush); - -Q_SIGNALS: - void changed(); - -public Q_SLOTS: - void showColorDialog(); - void updateStyle(); - -private: - QBrush m_brush; - QPushButton *m_colorButton; - QComboBox *m_styleCombo; -}; - -#endif // BRUSHTOOL_H diff --git a/examples/charts/piechartcustomization/customslice.h b/examples/charts/piechartcustomization/customslice.h deleted file mode 100644 index ec4e0484..00000000 --- a/examples/charts/piechartcustomization/customslice.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef CUSTOMSLICE_H -#define CUSTOMSLICE_H - -#include <QtCharts/QPieSlice> - -QT_USE_NAMESPACE - -class CustomSlice : public QPieSlice -{ - Q_OBJECT - -public: - CustomSlice(QString label, qreal value); - -public: - QBrush originalBrush(); - -public Q_SLOTS: - void showHighlight(bool show); - -private: - QBrush m_originalBrush; -}; - -#endif // CUSTOMSLICE_H diff --git a/examples/charts/piechartcustomization/main.cpp b/examples/charts/piechartcustomization/main.cpp deleted file mode 100644 index 7ec94639..00000000 --- a/examples/charts/piechartcustomization/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "mainwidget.h" -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - QMainWindow window; - MainWidget widget; - window.setCentralWidget(&widget); - window.resize(900, 600); - window.show(); - return a.exec(); -} diff --git a/examples/charts/piechartcustomization/mainwidget.h b/examples/charts/piechartcustomization/mainwidget.h deleted file mode 100644 index 16cf097b..00000000 --- a/examples/charts/piechartcustomization/mainwidget.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef MAINWIDGET_H -#define MAINWIDGET_H - -#include "qgridlayout.h" -#include "qscrollarea.h" -#include <QtWidgets/QWidget> -#include <QtCharts/QChartGlobal> - -QT_BEGIN_NAMESPACE -class QLineEdit; -class QPushButton; -class QCheckBox; -class QComboBox; -class QDoubleSpinBox; -QT_END_NAMESPACE - -class PenTool; -class BrushTool; -class CustomSlice; - -QT_BEGIN_NAMESPACE -class QChartView; -class QPieSeries; -class QPieSlice; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class MainWidget : public QWidget -{ - Q_OBJECT - -public: - explicit MainWidget(QWidget *parent = 0); - -public Q_SLOTS: - void updateChartSettings(); - void updateSerieSettings(); - void updateSliceSettings(); - void handleSliceClicked(QPieSlice *slice); - void showFontDialog(); - void appendSlice(); - void insertSlice(); - void removeSlice(); - -private: - void resizeEvent(QResizeEvent *e); - - QComboBox *m_themeComboBox; - QCheckBox *m_aaCheckBox; - QCheckBox *m_animationsCheckBox; - QCheckBox *m_legendCheckBox; - - QChartView *m_chartView; - QPieSeries *m_series; - CustomSlice *m_slice; - - QDoubleSpinBox *m_hPosition; - QDoubleSpinBox *m_vPosition; - QDoubleSpinBox *m_sizeFactor; - QDoubleSpinBox *m_startAngle; - QDoubleSpinBox *m_endAngle; - QDoubleSpinBox *m_holeSize; - - QLineEdit *m_sliceName; - QDoubleSpinBox *m_sliceValue; - QCheckBox *m_sliceLabelVisible; - QDoubleSpinBox *m_sliceLabelArmFactor; - QCheckBox *m_sliceExploded; - QDoubleSpinBox *m_sliceExplodedFactor; - QPushButton *m_brush; - BrushTool *m_brushTool; - QPushButton *m_pen; - PenTool *m_penTool; - QPushButton *m_font; - QPushButton *m_labelBrush; - QComboBox *m_labelPosition; - BrushTool *m_labelBrushTool; - QGridLayout *baseLayout; - QScrollArea *settingsScrollBar; - - double oldAspectRatio; -}; - -#endif // MAINWIDGET_H diff --git a/examples/charts/piechartcustomization/piechartcustomization.pro b/examples/charts/piechartcustomization/piechartcustomization.pro deleted file mode 100644 index 8c3bf136..00000000 --- a/examples/charts/piechartcustomization/piechartcustomization.pro +++ /dev/null @@ -1,18 +0,0 @@ -QT += charts -requires(qtConfig(combobox)) - -HEADERS += \ - brushtool.h \ - customslice.h \ - mainwidget.h \ - pentool.h - -SOURCES += \ - brushtool.cpp \ - customslice.cpp \ - main.cpp \ - mainwidget.cpp \ - pentool.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/piechartcustomization -INSTALLS += target diff --git a/examples/charts/piechartdrilldown/CMakeLists.txt b/examples/charts/piechartdrilldown/CMakeLists.txt deleted file mode 100644 index d4f65b8e..00000000 --- a/examples/charts/piechartdrilldown/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(piechartdrilldown LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/piechartdrilldown") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(piechartdrilldown - drilldownchart.cpp drilldownchart.h - drilldownslice.cpp drilldownslice.h - main.cpp -) - -set_target_properties(piechartdrilldown PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(piechartdrilldown PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS piechartdrilldown - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/piechartdrilldown/drilldownchart.cpp b/examples/charts/piechartdrilldown/drilldownchart.cpp deleted file mode 100644 index 0cdf3b57..00000000 --- a/examples/charts/piechartdrilldown/drilldownchart.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include "drilldownchart.h" -#include "drilldownslice.h" - -QT_USE_NAMESPACE - -DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) - : QChart(QChart::ChartTypeCartesian, parent, wFlags), - m_currentSeries(0) -{ - -} - -DrilldownChart::~DrilldownChart() -{ - -} - -void DrilldownChart::changeSeries(QAbstractSeries *series) -{ - // NOTE: if the series is owned by the chart it will be deleted - // here the "window" owns the series... - if (m_currentSeries) - removeSeries(m_currentSeries); - m_currentSeries = series; - addSeries(series); - setTitle(series->name()); -} - -void DrilldownChart::handleSliceClicked(QPieSlice *slice) -{ - DrilldownSlice *drilldownSlice = static_cast<DrilldownSlice *>(slice); - changeSeries(drilldownSlice->drilldownSeries()); -} - -#include "moc_drilldownchart.cpp" diff --git a/examples/charts/piechartdrilldown/drilldownchart.h b/examples/charts/piechartdrilldown/drilldownchart.h deleted file mode 100644 index 97cfbdb1..00000000 --- a/examples/charts/piechartdrilldown/drilldownchart.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef DRILLDOWNCHART_H -#define DRILLDOWNCHART_H - -#include <QtCharts/QChart> - -QT_BEGIN_NAMESPACE -class QAbstractSeries; -class QPieSlice; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class DrilldownChart : public QChart -{ - Q_OBJECT -public: - explicit DrilldownChart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {}); - ~DrilldownChart(); - void changeSeries(QAbstractSeries *series); - -public Q_SLOTS: - void handleSliceClicked(QPieSlice *slice); - -private: - QAbstractSeries *m_currentSeries; -}; - -#endif // DRILLDOWNCHART_H diff --git a/examples/charts/piechartdrilldown/drilldownslice.cpp b/examples/charts/piechartdrilldown/drilldownslice.cpp deleted file mode 100644 index 751f0cef..00000000 --- a/examples/charts/piechartdrilldown/drilldownslice.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "drilldownslice.h" - -QT_USE_NAMESPACE - -DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries *drilldownSeries) - : m_drilldownSeries(drilldownSeries), - m_prefix(prefix) -{ - setValue(value); - updateLabel(); - setLabelFont(QFont("Arial", 8)); - connect(this, &DrilldownSlice::percentageChanged, this, &DrilldownSlice::updateLabel); - connect(this, &DrilldownSlice::hovered, this, &DrilldownSlice::showHighlight); -} - -DrilldownSlice::~DrilldownSlice() -{ - -} - -QAbstractSeries *DrilldownSlice::drilldownSeries() const -{ - return m_drilldownSeries; -} - -void DrilldownSlice::updateLabel() -{ - QString label = m_prefix; - label += " $"; - label += QString::number(this->value()); - label += ", "; - label += QString::number(this->percentage() * 100, 'f', 1); - label += "%"; - setLabel(label); -} - -void DrilldownSlice::showHighlight(bool show) -{ - setLabelVisible(show); - setExploded(show); -} - -#include "moc_drilldownslice.cpp" diff --git a/examples/charts/piechartdrilldown/drilldownslice.h b/examples/charts/piechartdrilldown/drilldownslice.h deleted file mode 100644 index d007ffc0..00000000 --- a/examples/charts/piechartdrilldown/drilldownslice.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#ifndef DRILLDOWNSLICE_H -#define DRILLDOWNSLICE_H - -#include <QtCharts/QPieSlice> - -QT_BEGIN_NAMESPACE -class QAbstractSeries; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -class DrilldownSlice : public QPieSlice -{ - Q_OBJECT - -public: - DrilldownSlice(qreal value, QString prefix, QAbstractSeries *drilldownSeries); - virtual ~DrilldownSlice(); - QAbstractSeries *drilldownSeries() const; - -public Q_SLOTS: - void updateLabel(); - void showHighlight(bool show); - -private: - QAbstractSeries *m_drilldownSeries; - QString m_prefix; -}; - -#endif // DRILLDOWNSLICE_H diff --git a/examples/charts/piechartdrilldown/main.cpp b/examples/charts/piechartdrilldown/main.cpp deleted file mode 100644 index 299c477f..00000000 --- a/examples/charts/piechartdrilldown/main.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "drilldownchart.h" -#include "drilldownslice.h" -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCore/QRandomGenerator> -#include <QtCharts/QChartView> -#include <QtCharts/QLegend> -#include <QtCharts/QPieSeries> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - QMainWindow window; - - DrilldownChart *chart = new DrilldownChart(); - chart->setTheme(QChart::ChartThemeLight); - chart->setAnimationOptions(QChart::AllAnimations); - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignRight); - - QPieSeries *yearSeries = new QPieSeries(&window); - yearSeries->setName("Sales by year - All"); - - const QStringList months = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; - const QStringList names = { - "Jane", "John", "Axel", "Mary", "Susan", "Bob" - }; - - for (const QString &name : names) { - QPieSeries *series = new QPieSeries(&window); - series->setName("Sales by month - " + name); - - for (const QString &month : months) - *series << new DrilldownSlice(QRandomGenerator::global()->bounded(1000), month, yearSeries); - - QObject::connect(series, &QPieSeries::clicked, chart, &DrilldownChart::handleSliceClicked); - - *yearSeries << new DrilldownSlice(series->sum(), name, series); - } - - QObject::connect(yearSeries, &QPieSeries::clicked, chart, &DrilldownChart::handleSliceClicked); - - chart->changeSeries(yearSeries); - - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); - window.setCentralWidget(chartView); - window.resize(800, 500); - window.show(); - - return a.exec(); -} diff --git a/examples/charts/piechartdrilldown/piechartdrilldown.pro b/examples/charts/piechartdrilldown/piechartdrilldown.pro deleted file mode 100644 index 60866fc3..00000000 --- a/examples/charts/piechartdrilldown/piechartdrilldown.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts - -HEADERS += \ - drilldownchart.h \ - drilldownslice.h - -SOURCES += \ - drilldownchart.cpp \ - drilldownslice.cpp \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/piechartdrilldown -INSTALLS += target diff --git a/examples/charts/pointconfiguration/CMakeLists.txt b/examples/charts/pointconfiguration/CMakeLists.txt deleted file mode 100644 index 5fc8042f..00000000 --- a/examples/charts/pointconfiguration/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.14) -project(pointconfiguration LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/pointconfiguration") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(pointconfiguration - chartwindow.cpp - chartwindow.h - main.cpp -) - -set_target_properties(pointconfiguration PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(pointconfiguration PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS pointconfiguration - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/pointconfiguration/main.cpp b/examples/charts/pointconfiguration/main.cpp deleted file mode 100644 index 0279d636..00000000 --- a/examples/charts/pointconfiguration/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "chartwindow.h" - -#include <QApplication> - -//![1] -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - ChartWindow mainWindow; - mainWindow.resize(640, 480); - mainWindow.show(); - return a.exec(); -} -//![1] diff --git a/examples/charts/pointconfiguration/pointconfiguration.pro b/examples/charts/pointconfiguration/pointconfiguration.pro deleted file mode 100644 index b10359d1..00000000 --- a/examples/charts/pointconfiguration/pointconfiguration.pro +++ /dev/null @@ -1,12 +0,0 @@ -QT += charts \ - widgets - -SOURCES += \ - chartwindow.cpp - main.cpp - -HEADERS += \ - chartwindow.h - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/pointconfiguration -INSTALLS += target diff --git a/examples/charts/pointsselectionandmarkers/CMakeLists.txt b/examples/charts/pointsselectionandmarkers/CMakeLists.txt deleted file mode 100644 index 6bef7063..00000000 --- a/examples/charts/pointsselectionandmarkers/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.14) -project(pointsselectionandmarkers LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/pointsselectionandmarkers") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(pointsselectionandmarkers - utilities.h utilities.cpp - main.cpp -) - -set_target_properties(pointsselectionandmarkers PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(pointsselectionandmarkers PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -set(pointsselectionandmarkers_resource_files - "blue_triangle.png" - "green_triangle.png" -) - -qt6_add_resources(pointsselectionandmarkers "images" - PREFIX - "/" - FILES - ${pointsselectionandmarkers_resource_files} -) - -install(TARGETS pointsselectionandmarkers - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/pointsselectionandmarkers/main.cpp b/examples/charts/pointsselectionandmarkers/main.cpp deleted file mode 100644 index 7c1af89e..00000000 --- a/examples/charts/pointsselectionandmarkers/main.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "utilities.h" - -#include <QApplication> -#include <QChart> -#include <QChartView> -#include <QCheckBox> -#include <QComboBox> -#include <QGridLayout> -#include <QHBoxLayout> -#include <QLabel> -#include <QMainWindow> -#include <QSplineSeries> - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - QMainWindow mainWindow; - mainWindow.setWindowTitle("Chart"); - - //![1] - constexpr qreal marker_size = 20.; - - QSplineSeries *series = new QSplineSeries(); - series->append({QPointF(0., 0.), - QPointF(0.5, 2.27), - QPointF(1.5, 2.2), - QPointF(3.3, 1.7), - QPointF(4.23, 3.1), - QPointF(5.3, 2.3), - QPointF(6.47, 4.1) - }); - series->setMarkerSize(marker_size); - series->setLightMarker(Utilities::redRectangle(marker_size)); - series->setSelectedLightMarker(Utilities::blueTriangle(marker_size)); - QObject::connect(series, &QXYSeries::clicked, series, [&](const QPointF &point) { - int index = series->points().indexOf(point); - if (index != -1) - series->toggleSelection({index}); - }); - //![1] - - //![2] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->createDefaultAxes(); - chart->legend()->setVisible(false); - - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); - - QWidget *controlWidget = new QWidget(&mainWindow); - QGridLayout *controlLayout = new QGridLayout(controlWidget); - //![2] - - //![3] - QComboBox *charPointCombobox = new QComboBox(); - QComboBox *charPointSelectedCombobox = new QComboBox(); - QComboBox *lineColorCombobox = new QComboBox(); - QCheckBox *showUnselectedPointsCheckbox = new QCheckBox(); - //![3] - - //![4] - QLabel *charPoint = new QLabel(QCoreApplication::tr("Char point: ")); - charPointCombobox->addItems({QCoreApplication::tr("Red rectangle"), - QCoreApplication::tr("Green triangle"), - QCoreApplication::tr("Orange circle") - }); - QObject::connect(charPointCombobox, &QComboBox::currentIndexChanged, series, [&](const int index) { - if (showUnselectedPointsCheckbox->isChecked()) - series->setLightMarker(Utilities::getPointRepresentation(Utilities::PointType(index), marker_size)); - }); - //![4] - - //![5] - QLabel *charPointSelected = new QLabel(QCoreApplication::tr("Char point selected: ")); - charPointSelectedCombobox->addItems({QCoreApplication::tr("Blue triangle"), - QCoreApplication::tr("Yellow rectangle"), - QCoreApplication::tr("Lavender circle") - }); - QObject::connect(charPointSelectedCombobox, &QComboBox::currentIndexChanged, series, [&](const int index) { - series->setSelectedLightMarker(Utilities::getSelectedPointRepresentation(Utilities::SelectedPointType(index), marker_size)); - }); - - QLabel *lineColorLabel = new QLabel(QCoreApplication::tr("Line color: ")); - lineColorCombobox->addItems({QCoreApplication::tr("Blue"), - QCoreApplication::tr("Black"), - QCoreApplication::tr("Mint") - }); - QObject::connect(lineColorCombobox, &QComboBox::currentIndexChanged, series, [&](const int index) { - series->setColor(Utilities::makeLineColor(Utilities::LineColor(index))); - }); - //![5] - - //![6] - QLabel *showUnselectedPointsLabel = new QLabel(QCoreApplication::tr("Display unselected points: ")); - showUnselectedPointsCheckbox->setChecked(true); - QObject::connect(showUnselectedPointsCheckbox, &QCheckBox::stateChanged, series, [&](const int state) { - if (state) { - series->setLightMarker(Utilities::getPointRepresentation(Utilities::PointType(charPointCombobox->currentIndex()), marker_size)); - } else { - series->setLightMarker(QImage()); - } - }); - //![6] - - //![7] - controlLayout->addWidget(charPoint, 0, 0); - controlLayout->addWidget(charPointCombobox, 0, 1); - - controlLayout->addWidget(charPointSelected, 1, 0); - controlLayout->addWidget(charPointSelectedCombobox, 1, 1); - - controlLayout->addWidget(lineColorLabel, 2, 0); - controlLayout->addWidget(lineColorCombobox, 2, 1); - - controlLayout->addWidget(showUnselectedPointsLabel, 3, 0); - controlLayout->addWidget(showUnselectedPointsCheckbox, 3, 1, 1, 2); - - QWidget *mainWidget = new QWidget(&mainWindow); - QHBoxLayout *mainLayout = new QHBoxLayout(mainWidget); - mainLayout->addWidget(chartView); - mainLayout->addWidget(controlWidget); - - mainWindow.setCentralWidget(mainWidget); - mainWindow.resize(1080, 720); - mainWindow.show(); - return a.exec(); - //![7] -} diff --git a/examples/charts/pointsselectionandmarkers/pointsselectionandmarkers.pro b/examples/charts/pointsselectionandmarkers/pointsselectionandmarkers.pro deleted file mode 100644 index ac8adffb..00000000 --- a/examples/charts/pointsselectionandmarkers/pointsselectionandmarkers.pro +++ /dev/null @@ -1,15 +0,0 @@ -QT += charts \ - widgets - -SOURCES += \ - main.cpp \ - utilities.cpp - -HEADERS += \ - utilities.h - -RESOURCES += \ - pointsselectionandmarkers.qrc - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/pointsselectionandmarkers -INSTALLS += target diff --git a/examples/charts/pointsselectionandmarkers/pointsselectionandmarkers.qrc b/examples/charts/pointsselectionandmarkers/pointsselectionandmarkers.qrc deleted file mode 100644 index 920bf0cc..00000000 --- a/examples/charts/pointsselectionandmarkers/pointsselectionandmarkers.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>blue_triangle.png</file> - <file>green_triangle.png</file> - </qresource> -</RCC> diff --git a/examples/charts/pointsselectionandmarkers/utilities.cpp b/examples/charts/pointsselectionandmarkers/utilities.cpp deleted file mode 100644 index 6f96cf9f..00000000 --- a/examples/charts/pointsselectionandmarkers/utilities.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "utilities.h" - -#include <QBrush> -#include <QList> -#include <QPainter> -#include <QPainterPath> - -namespace Utilities -{ - QImage redRectangle(qreal imageSize) - { - QImage image(imageSize, imageSize, QImage::Format_RGB32); - QPainter painter; - painter.begin(&image); - painter.fillRect(0, 0, imageSize, imageSize, Qt::red); - painter.end(); - return image; - } - - QImage yellowRectangle(qreal imageSize) - { - QImage image(imageSize, imageSize, QImage::Format_RGB32); - QPainter painter; - painter.begin(&image); - painter.fillRect(0, 0, imageSize, imageSize, Qt::yellow); - painter.end(); - return image; - } - - QImage blueTriangle(qreal imageSize) - { - return QImage(":/blue_triangle.png").scaled(imageSize, imageSize); - } - - QImage greenTriangle(qreal imageSize) - { - return QImage(":/green_triangle.png").scaled(imageSize, imageSize); - } - - QImage orangeCircle(qreal imageSize) - { - QImage image(imageSize, imageSize, QImage::Format_ARGB32); - image.fill(QColor(0, 0, 0, 0)); - QPainter paint; - paint.begin(&image); - paint.setBrush(QColor(255,127,80)); - QPen pen = paint.pen(); - pen.setWidth(0); - paint.setPen(pen); - paint.drawEllipse(0, 0, imageSize * 0.9, imageSize * 0.9); - paint.end(); - return image; - } - - QImage lavenderCircle(qreal imageSize) - { - QImage image(imageSize, imageSize, QImage::Format_ARGB32); - image.fill(QColor(0, 0, 0, 0)); - QPainter paint; - paint.begin(&image); - paint.setBrush(QColor(147,112,219)); - QPen pen = paint.pen(); - pen.setWidth(0); - paint.setPen(pen); - paint.drawEllipse(0, 0, imageSize * 0.9, imageSize * 0.9); - paint.end(); - return image; - } - - QImage getPointRepresentation(PointType pointType, int imageSize) - { - switch (pointType) { - case Utilities::PointType::RedRectangle: - return redRectangle(imageSize); - case Utilities::PointType::GreenTriangle: - return greenTriangle(imageSize); - case Utilities::PointType::OrangeCircle: - return orangeCircle(imageSize); - default: - return redRectangle(imageSize); - } - } - - QImage getSelectedPointRepresentation(SelectedPointType pointType, int imageSize) - { - switch (pointType) { - case Utilities::SelectedPointType::BlueTriangle: - return blueTriangle(imageSize); - case Utilities::SelectedPointType::YellowRectangle: - return yellowRectangle(imageSize); - case Utilities::SelectedPointType::LavenderCircle: - return lavenderCircle(imageSize); - default: - return blueTriangle(imageSize); - } - } - - QColor makeLineColor(LineColor lineColor) - { - switch (lineColor) { - case Utilities::LineColor::Blue: - return QColor(65, 105, 225); - case Utilities::LineColor::Black: - return QColor(0,0,0); - case Utilities::LineColor::Mint: - return QColor(70, 203, 155); - default: - return QColor(0, 0, 0); - } - } -} diff --git a/examples/charts/polarchart/CMakeLists.txt b/examples/charts/polarchart/CMakeLists.txt deleted file mode 100644 index ae9c12c5..00000000 --- a/examples/charts/polarchart/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(polarchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/polarchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(polarchart - chartview.cpp chartview.h - main.cpp -) - -set_target_properties(polarchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(polarchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS polarchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/polarchart/chartview.h b/examples/charts/polarchart/chartview.h deleted file mode 100644 index 96e7823d..00000000 --- a/examples/charts/polarchart/chartview.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef CHARTVIEW_H -#define CHARTVIEW_H - -#include <QtCharts/QChartView> -#include <QtCharts/QPolarChart> - -QT_USE_NAMESPACE - -class ChartView : public QChartView -{ -public: - ChartView(QWidget *parent = 0); - -protected: - void keyPressEvent(QKeyEvent *event); - -private: - void switchChartType(); -}; - -#endif diff --git a/examples/charts/polarchart/polarchart.pro b/examples/charts/polarchart/polarchart.pro deleted file mode 100644 index a046ca86..00000000 --- a/examples/charts/polarchart/polarchart.pro +++ /dev/null @@ -1,11 +0,0 @@ -QT += charts - -HEADERS += \ - chartview.h - -SOURCES += \ - chartview.cpp \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/polarchart -INSTALLS += target diff --git a/examples/charts/qmlaxes/CMakeLists.txt b/examples/charts/qmlaxes/CMakeLists.txt deleted file mode 100644 index b5086600..00000000 --- a/examples/charts/qmlaxes/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlaxes LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlaxes") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlaxes - main.cpp -) - -set_target_properties(qmlaxes PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlaxes PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlaxes/View1.qml" - "qml/qmlaxes/View2.qml" - "qml/qmlaxes/View3.qml" - "qml/qmlaxes/main.qml" -) - -qt6_add_resources(qmlaxes "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlaxes - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlaxes/main.cpp b/examples/charts/qmlaxes/main.cpp deleted file mode 100644 index bef8d53b..00000000 --- a/examples/charts/qmlaxes/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 <QtWidgets/QApplication> -#include <QtCore/QDir> -#include <QtQuick/QQuickView> -#include <QtQml/QQmlEngine> - -int main(int argc, char *argv[]) -{ - // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. - QApplication 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("QML Axes")); - viewer.setSource(QUrl("qrc:/qml/qmlaxes/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/charts/qmlaxes/qml/qmlaxes/View1.qml b/examples/charts/qmlaxes/qml/qmlaxes/View1.qml deleted file mode 100644 index 4c99bc7f..00000000 --- a/examples/charts/qmlaxes/qml/qmlaxes/View1.qml +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Two Series, Common Axes" - anchors.fill: parent - legend.visible: false - antialiasing: true - - ValueAxis { - id: axisX - min: 0 - max: 10 - tickCount: 5 - } - - ValueAxis { - id: axisY - min: -0.5 - max: 1.5 - } - - LineSeries { - id: series1 - axisX: axisX - axisY: axisY - } - - ScatterSeries { - id: series2 - axisX: axisX - axisY: axisY - } - } - - // Add data dynamically to the series - Component.onCompleted: { - for (var i = 0; i <= 10; i++) { - series1.append(i, Math.random()); - series2.append(i, Math.random()); - } - } - //![1] -} diff --git a/examples/charts/qmlaxes/qml/qmlaxes/View2.qml b/examples/charts/qmlaxes/qml/qmlaxes/View2.qml deleted file mode 100644 index e1105bbb..00000000 --- a/examples/charts/qmlaxes/qml/qmlaxes/View2.qml +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Accurate Historical Data" - anchors.fill: parent - legend.visible: false - antialiasing: true - - LineSeries { - axisX: DateTimeAxis { - format: "yyyy MMM" - tickCount: 5 - } - axisY: ValueAxis { - min: 0 - max: 150 - } - - // Please note that month in JavaScript months are zero based, so 2 means March - XYPoint { x: toMsecsSinceEpoch(new Date(1950, 2, 15)); y: 5 } - XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 } - XYPoint { x: toMsecsSinceEpoch(new Date(1987, 12, 31)); y: 102 } - XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 } - XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 2)); y: 110 } - } - } - - // DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to - // milliseconds since epoch to make them match the DateTimeAxis values - function toMsecsSinceEpoch(date) { - var msecs = date.getTime(); - return msecs; - } - //![1] -} diff --git a/examples/charts/qmlaxes/qml/qmlaxes/View3.qml b/examples/charts/qmlaxes/qml/qmlaxes/View3.qml deleted file mode 100644 index 9a15b16e..00000000 --- a/examples/charts/qmlaxes/qml/qmlaxes/View3.qml +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Numerical Data for Dummies" - anchors.fill: parent - legend.visible: false - antialiasing: true - - LineSeries { - axisY: CategoryAxis { - min: 0 - max: 30 - CategoryRange { - label: "critical" - endValue: 2 - } - CategoryRange { - label: "low" - endValue: 4 - } - CategoryRange { - label: "normal" - endValue: 7 - } - CategoryRange { - label: "high" - endValue: 15 - } - CategoryRange { - label: "extremely high" - endValue: 30 - } - } - - XYPoint { x: 0; y: 4.3 } - XYPoint { x: 1; y: 4.1 } - XYPoint { x: 2; y: 4.7 } - XYPoint { x: 3; y: 3.9 } - XYPoint { x: 4; y: 5.2 } - } - } - //![1] -} diff --git a/examples/charts/qmlaxes/qml/qmlaxes/main.qml b/examples/charts/qmlaxes/qml/qmlaxes/main.qml deleted file mode 100644 index 164a9ce0..00000000 --- a/examples/charts/qmlaxes/qml/qmlaxes/main.qml +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 - -Item { - width: 440 - height: 330 - property bool sourceLoaded: false - - ListView { - id: root - focus: true - anchors.fill: parent - snapMode: ListView.SnapOneItem - highlightRangeMode: ListView.StrictlyEnforceRange - highlightMoveDuration: 250 - orientation: ListView.Horizontal - boundsBehavior: Flickable.StopAtBounds - - onCurrentIndexChanged: { - if (infoText.opacity > 0.0) { - if (sourceLoaded) - infoText.opacity = 0.0; - else if (currentIndex != 0) - currentIndex = 0; - } - } - - model: ListModel { - ListElement {component: "View1.qml"} - ListElement {component: "View2.qml"} - ListElement {component: "View3.qml"} - } - - delegate: Loader { - width: root.width - height: root.height - - source: component - asynchronous: true - - onLoaded: sourceLoaded = true - } - } - - Rectangle { - id: infoText - anchors.centerIn: parent - width: parent.width - height: 40 - color: "black" - Text { - color: "white" - anchors.centerIn: parent - text: "You can navigate between views using swipe or arrow keys" - } - - Behavior on opacity { - NumberAnimation { duration: 400 } - } - } -} diff --git a/examples/charts/qmlaxes/qmlaxes.pro b/examples/charts/qmlaxes/qmlaxes.pro deleted file mode 100644 index 6fb5b4f9..00000000 --- a/examples/charts/qmlaxes/qmlaxes.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts qml quick - -SOURCES += \ - main.cpp - -RESOURCES += \ - resources.qrc - -DISTFILES += \ - qml/qmlaxes/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlaxes -INSTALLS += target diff --git a/examples/charts/qmlaxes/resources.qrc b/examples/charts/qmlaxes/resources.qrc deleted file mode 100644 index c30b2f2c..00000000 --- a/examples/charts/qmlaxes/resources.qrc +++ /dev/null @@ -1,8 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlaxes/main.qml</file> - <file>qml/qmlaxes/View1.qml</file> - <file>qml/qmlaxes/View2.qml</file> - <file>qml/qmlaxes/View3.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlboxplot/CMakeLists.txt b/examples/charts/qmlboxplot/CMakeLists.txt deleted file mode 100644 index 7fda6ade..00000000 --- a/examples/charts/qmlboxplot/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlboxplot LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlboxplot") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlboxplot - main.cpp -) - -set_target_properties(qmlboxplot PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlboxplot PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlboxplot/main.qml" -) - -qt6_add_resources(qmlboxplot "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlboxplot - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlboxplot/qmlboxplot.pro b/examples/charts/qmlboxplot/qmlboxplot.pro deleted file mode 100644 index 3afed6af..00000000 --- a/examples/charts/qmlboxplot/qmlboxplot.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts qml quick - -SOURCES += \ - main.cpp - -RESOURCES += \ - resources.qrc - -DISTFILES += \ - qml/qmlboxplot/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlboxplot -INSTALLS += target diff --git a/examples/charts/qmlboxplot/resources.qrc b/examples/charts/qmlboxplot/resources.qrc deleted file mode 100644 index 49a98f16..00000000 --- a/examples/charts/qmlboxplot/resources.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlboxplot/main.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlcandlestick/CMakeLists.txt b/examples/charts/qmlcandlestick/CMakeLists.txt deleted file mode 100644 index 67138dac..00000000 --- a/examples/charts/qmlcandlestick/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlcandlestick LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlcandlestick") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlcandlestick - main.cpp -) - -set_target_properties(qmlcandlestick PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlcandlestick PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlcandlestick/main.qml" -) - -qt6_add_resources(qmlcandlestick "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlcandlestick - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlcandlestick/main.cpp b/examples/charts/qmlcandlestick/main.cpp deleted file mode 100644 index b4238eee..00000000 --- a/examples/charts/qmlcandlestick/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 <QtCore/QDir> -#include <QtQml/QQmlEngine> -#include <QtQuick/QQuickView> -#include <QtWidgets/QApplication> - -int main(int argc, char *argv[]) -{ - // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. - QApplication 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(QApplication::applicationDirPath(), - QString::fromLatin1("qml"))); - QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); - - viewer.setTitle(QStringLiteral("QML Candlestick")); - viewer.setSource(QUrl("qrc:/qml/qmlcandlestick/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/charts/qmlcandlestick/qmlcandlestick.pro b/examples/charts/qmlcandlestick/qmlcandlestick.pro deleted file mode 100644 index 83f08895..00000000 --- a/examples/charts/qmlcandlestick/qmlcandlestick.pro +++ /dev/null @@ -1,14 +0,0 @@ -QT += charts qml quick - -RESOURCES += resources.qrc - -SOURCES += main.cpp - -OTHER_FILES += \ - qml/qmlcandlestick/main.qml - -DISTFILES += \ - qml/qmlcandlestick/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlcandlestick -INSTALLS += target diff --git a/examples/charts/qmlcandlestick/resources.qrc b/examples/charts/qmlcandlestick/resources.qrc deleted file mode 100644 index ccfab44e..00000000 --- a/examples/charts/qmlcandlestick/resources.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlcandlestick/main.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlchart/CMakeLists.txt b/examples/charts/qmlchart/CMakeLists.txt deleted file mode 100644 index 28b09475..00000000 --- a/examples/charts/qmlchart/CMakeLists.txt +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlchart - main.cpp -) - -set_target_properties(qmlchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlchart/MainForm.ui.qml" - "qml/qmlchart/View1.qml" - "qml/qmlchart/View10.qml" - "qml/qmlchart/View11.qml" - "qml/qmlchart/View12.qml" - "qml/qmlchart/View2.qml" - "qml/qmlchart/View3.qml" - "qml/qmlchart/View4.qml" - "qml/qmlchart/View5.qml" - "qml/qmlchart/View6.qml" - "qml/qmlchart/View7.qml" - "qml/qmlchart/View8.qml" - "qml/qmlchart/View9.qml" - "qml/qmlchart/main.qml" -) - -qt6_add_resources(qmlchart "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlchart/main.cpp b/examples/charts/qmlchart/main.cpp deleted file mode 100644 index d75d43c6..00000000 --- a/examples/charts/qmlchart/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 <QtWidgets/QApplication> -#include <QtQuick/QQuickView> -#include <QtCore/QDir> -#include <QtQml/QQmlEngine> - -int main(int argc, char *argv[]) -{ - // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. - QApplication 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("QML Chart")); - - viewer.setSource(QUrl("qrc:/qml/qmlchart/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/charts/qmlchart/qml/qmlchart/MainForm.ui.qml b/examples/charts/qmlchart/qml/qmlchart/MainForm.ui.qml deleted file mode 100644 index 498b5d58..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/MainForm.ui.qml +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 - -Item { - width: 600 - height: 400 - property bool sourceLoaded: false - property alias currentIndex: root.currentIndex - property alias info: infoText - - ListView { - id: root - focus: true - anchors.fill: parent - snapMode: ListView.SnapOneItem - highlightRangeMode: ListView.StrictlyEnforceRange - highlightMoveDuration: 250 - orientation: ListView.Horizontal - boundsBehavior: Flickable.StopAtBounds - - model: ListModel { - ListElement {component: "View1.qml"} - ListElement {component: "View2.qml"} - ListElement {component: "View3.qml"} - ListElement {component: "View4.qml"} - ListElement {component: "View5.qml"} - ListElement {component: "View6.qml"} - ListElement {component: "View7.qml"} - ListElement {component: "View8.qml"} - ListElement {component: "View9.qml"} - ListElement {component: "View10.qml"} - ListElement {component: "View11.qml"} - ListElement {component: "View12.qml"} - } - - delegate: Loader { - width: root.width - height: root.height - - source: component - asynchronous: true - - onLoaded: sourceLoaded = true - } - } - - Rectangle { - id: infoText - anchors.centerIn: parent - width: parent.width - height: 40 - color: "black" - Text { - color: "white" - anchors.centerIn: parent - text: "You can navigate between views using swipe or arrow keys" - } - } -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View1.qml b/examples/charts/qmlchart/qml/qmlchart/View1.qml deleted file mode 100644 index a09e2720..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View1.qml +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -//![2] -import QtQuick 2.0 -//![2] -import QtCharts 2.0 - -Item { - anchors.fill: parent - property variant othersSlice: 0 - - //![1] - ChartView { - id: chart - title: "Top-5 car brand shares in Finland" - anchors.fill: parent - legend.alignment: Qt.AlignBottom - antialiasing: true - - PieSeries { - id: pieSeries - PieSlice { label: "Volkswagen"; value: 13.5 } - PieSlice { label: "Toyota"; value: 10.9 } - PieSlice { label: "Ford"; value: 8.6 } - PieSlice { label: "Skoda"; value: 8.2 } - PieSlice { label: "Volvo"; value: 6.8 } - } - } - - Component.onCompleted: { - // You can also manipulate slices dynamically, like append a slice or set a slice exploded - othersSlice = pieSeries.append("Others", 52.0); - pieSeries.find("Volkswagen").exploded = true; - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View10.qml b/examples/charts/qmlchart/qml/qmlchart/View10.qml deleted file mode 100644 index f4a183a3..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View10.qml +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Horizontal Stacked Bar series" - anchors.fill: parent - legend.alignment: Qt.AlignBottom - antialiasing: true - - HorizontalStackedBarSeries { - axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } - BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } - BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } - BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } - } - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View11.qml b/examples/charts/qmlchart/qml/qmlchart/View11.qml deleted file mode 100644 index f1a00904..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View11.qml +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Horizontal Percent Bar series" - anchors.fill: parent - legend.alignment: Qt.AlignBottom - antialiasing: true - - HorizontalPercentBarSeries { - axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } - BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } - BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } - BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } - } - } - //![1] -} - diff --git a/examples/charts/qmlchart/qml/qmlchart/View12.qml b/examples/charts/qmlchart/qml/qmlchart/View12.qml deleted file mode 100644 index 51379f37..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View12.qml +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - id: chart - title: "Production costs" - anchors.fill: parent - legend.visible: false - antialiasing: true - - PieSeries { - id: pieOuter - size: 0.96 - holeSize: 0.7 - PieSlice { id: slice; label: "Alpha"; value: 19511; color: "#99CA53" } - PieSlice { label: "Epsilon"; value: 11105; color: "#209FDF" } - PieSlice { label: "Psi"; value: 9352; color: "#F6A625" } - } - - PieSeries { - size: 0.7 - id: pieInner - holeSize: 0.25 - - PieSlice { label: "Materials"; value: 10334; color: "#B9DB8A" } - PieSlice { label: "Employee"; value: 3066; color: "#DCEDC4" } - PieSlice { label: "Logistics"; value: 6111; color: "#F3F9EB" } - - PieSlice { label: "Materials"; value: 7371; color: "#63BCE9" } - PieSlice { label: "Employee"; value: 2443; color: "#A6D9F2" } - PieSlice { label: "Logistics"; value: 1291; color: "#E9F5FC" } - - PieSlice { label: "Materials"; value: 4022; color: "#F9C36C" } - PieSlice { label: "Employee"; value: 3998; color: "#FCE1B6" } - PieSlice { label: "Logistics"; value: 1332; color: "#FEF5E7" } - } - } - - Component.onCompleted: { - // Set the common slice properties dynamically for convenience - for (var i = 0; i < pieOuter.count; i++) { - pieOuter.at(i).labelPosition = PieSlice.LabelOutside; - pieOuter.at(i).labelVisible = true; - pieOuter.at(i).borderWidth = 3; - } - for (var i = 0; i < pieInner.count; i++) { - pieInner.at(i).labelPosition = PieSlice.LabelInsideNormal; - pieInner.at(i).labelVisible = true; - pieInner.at(i).borderWidth = 2; - } - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View2.qml b/examples/charts/qmlchart/qml/qmlchart/View2.qml deleted file mode 100644 index dc97c295..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View2.qml +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Line" - anchors.fill: parent - antialiasing: true - - LineSeries { - name: "LineSeries" - XYPoint { x: 0; y: 0 } - XYPoint { x: 1.1; y: 2.1 } - XYPoint { x: 1.9; y: 3.3 } - XYPoint { x: 2.1; y: 2.1 } - XYPoint { x: 2.9; y: 4.9 } - XYPoint { x: 3.4; y: 3.0 } - XYPoint { x: 4.1; y: 3.3 } - } - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View3.qml b/examples/charts/qmlchart/qml/qmlchart/View3.qml deleted file mode 100644 index 45d7276d..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View3.qml +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Spline" - anchors.fill: parent - antialiasing: true - - SplineSeries { - name: "SplineSeries" - XYPoint { x: 0; y: 0.0 } - XYPoint { x: 1.1; y: 3.2 } - XYPoint { x: 1.9; y: 2.4 } - XYPoint { x: 2.1; y: 2.1 } - XYPoint { x: 2.9; y: 2.6 } - XYPoint { x: 3.4; y: 2.3 } - XYPoint { x: 4.1; y: 3.1 } - } - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View4.qml b/examples/charts/qmlchart/qml/qmlchart/View4.qml deleted file mode 100644 index 5a71868b..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View4.qml +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "NHL All-Star Team Players" - anchors.fill: parent - antialiasing: true - - // Define x-axis to be used with the series instead of default one - ValueAxis { - id: valueAxis - min: 2000 - max: 2011 - tickCount: 12 - labelFormat: "%.0f" - } - - AreaSeries { - name: "Russian" - axisX: valueAxis - upperSeries: LineSeries { - XYPoint { x: 2000; y: 1 } - XYPoint { x: 2001; y: 1 } - XYPoint { x: 2002; y: 1 } - XYPoint { x: 2003; y: 1 } - XYPoint { x: 2004; y: 1 } - XYPoint { x: 2005; y: 0 } - XYPoint { x: 2006; y: 1 } - XYPoint { x: 2007; y: 1 } - XYPoint { x: 2008; y: 4 } - XYPoint { x: 2009; y: 3 } - XYPoint { x: 2010; y: 2 } - XYPoint { x: 2011; y: 1 } - } - } - //![1] - - AreaSeries { - name: "Swedish" - axisX: valueAxis - upperSeries: LineSeries { - XYPoint { x: 2000; y: 1 } - XYPoint { x: 2001; y: 1 } - XYPoint { x: 2002; y: 3 } - XYPoint { x: 2003; y: 3 } - XYPoint { x: 2004; y: 2 } - XYPoint { x: 2005; y: 0 } - XYPoint { x: 2006; y: 2 } - XYPoint { x: 2007; y: 1 } - XYPoint { x: 2008; y: 2 } - XYPoint { x: 2009; y: 1 } - XYPoint { x: 2010; y: 3 } - XYPoint { x: 2011; y: 3 } - } - } - - AreaSeries { - name: "Finnish" - axisX: valueAxis - upperSeries: LineSeries { - XYPoint { x: 2000; y: 0 } - XYPoint { x: 2001; y: 0 } - XYPoint { x: 2002; y: 0 } - XYPoint { x: 2003; y: 0 } - XYPoint { x: 2004; y: 0 } - XYPoint { x: 2005; y: 0 } - XYPoint { x: 2006; y: 1 } - XYPoint { x: 2007; y: 0 } - XYPoint { x: 2008; y: 0 } - XYPoint { x: 2009; y: 0 } - XYPoint { x: 2010; y: 0 } - XYPoint { x: 2011; y: 1 } - } - } - } -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View5.qml b/examples/charts/qmlchart/qml/qmlchart/View5.qml deleted file mode 100644 index bd81bb5f..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View5.qml +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Scatters" - anchors.fill: parent - antialiasing: true - - ScatterSeries { - id: scatter1 - name: "Scatter1" - XYPoint { x: 1.5; y: 1.5 } - XYPoint { x: 1.5; y: 1.6 } - XYPoint { x: 1.57; y: 1.55 } - XYPoint { x: 1.8; y: 1.8 } - XYPoint { x: 1.9; y: 1.6 } - XYPoint { x: 2.1; y: 1.3 } - XYPoint { x: 2.5; y: 2.1 } - } - - ScatterSeries { - name: "Scatter2" - XYPoint { x: 2.0; y: 2.0 } - XYPoint { x: 2.0; y: 2.1 } - XYPoint { x: 2.07; y: 2.05 } - XYPoint { x: 2.2; y: 2.9 } - XYPoint { x: 2.4; y: 2.7 } - XYPoint { x: 2.67; y: 2.65 } - } - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View6.qml b/examples/charts/qmlchart/qml/qmlchart/View6.qml deleted file mode 100644 index b141cfc9..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View6.qml +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Bar series" - anchors.fill: parent - legend.alignment: Qt.AlignBottom - antialiasing: true - - BarSeries { - id: mySeries - axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } - BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } - BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } - BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } - } - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View7.qml b/examples/charts/qmlchart/qml/qmlchart/View7.qml deleted file mode 100644 index b96e896a..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View7.qml +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Stacked Bar series" - anchors.fill: parent - legend.alignment: Qt.AlignBottom - antialiasing: true - - StackedBarSeries { - id: mySeries - axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } - BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } - BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } - BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } - } - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View8.qml b/examples/charts/qmlchart/qml/qmlchart/View8.qml deleted file mode 100644 index fa5efaf3..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View8.qml +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Percent Bar series" - anchors.fill: parent - legend.alignment: Qt.AlignBottom - antialiasing: true - - PercentBarSeries { - axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } - BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } - BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } - BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } - } - } - //![1] -} diff --git a/examples/charts/qmlchart/qml/qmlchart/View9.qml b/examples/charts/qmlchart/qml/qmlchart/View9.qml deleted file mode 100644 index 53e4dfc7..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/View9.qml +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - ChartView { - title: "Horizontal Bar series" - anchors.fill: parent - legend.alignment: Qt.AlignBottom - antialiasing: true - - HorizontalBarSeries { - axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } - BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } - BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } - BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } - } - } - //![1] -} - diff --git a/examples/charts/qmlchart/qml/qmlchart/main.qml b/examples/charts/qmlchart/qml/qmlchart/main.qml deleted file mode 100644 index e0f7c276..00000000 --- a/examples/charts/qmlchart/qml/qmlchart/main.qml +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -//![1] -import QtQuick 2.0 -//![1] - -Item { - width: 600 - height: 400 - - MainForm { - anchors.fill: parent - // Hide the default info text once view changes away from the first view - onCurrentIndexChanged: { - if (info.opacity > 0.0) { - if (sourceLoaded) - info.opacity = 0.0; - else if (currentIndex != 0) - currentIndex = 0; - } - } - - Behavior on info.opacity { - NumberAnimation { duration: 400 } - } - } -} diff --git a/examples/charts/qmlchart/qmlchart.pro b/examples/charts/qmlchart/qmlchart.pro deleted file mode 100644 index f665ee12..00000000 --- a/examples/charts/qmlchart/qmlchart.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts qml quick - -SOURCES += \ - main.cpp - -RESOURCES += \ - resources.qrc - -DISTFILES += \ - qml/qmlchart/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlchart -INSTALLS += target diff --git a/examples/charts/qmlchart/resources.qrc b/examples/charts/qmlchart/resources.qrc deleted file mode 100644 index 28b3a8a4..00000000 --- a/examples/charts/qmlchart/resources.qrc +++ /dev/null @@ -1,18 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlchart/main.qml</file> - <file>qml/qmlchart/View1.qml</file> - <file>qml/qmlchart/View2.qml</file> - <file>qml/qmlchart/View3.qml</file> - <file>qml/qmlchart/View4.qml</file> - <file>qml/qmlchart/View5.qml</file> - <file>qml/qmlchart/View6.qml</file> - <file>qml/qmlchart/View7.qml</file> - <file>qml/qmlchart/View8.qml</file> - <file>qml/qmlchart/View9.qml</file> - <file>qml/qmlchart/View10.qml</file> - <file>qml/qmlchart/View11.qml</file> - <file>qml/qmlchart/View12.qml</file> - <file>qml/qmlchart/MainForm.ui.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlcustomizations/CMakeLists.txt b/examples/charts/qmlcustomizations/CMakeLists.txt deleted file mode 100644 index ca78a4fb..00000000 --- a/examples/charts/qmlcustomizations/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlcustomizations LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlcustomizations") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlcustomizations - main.cpp -) - -set_target_properties(qmlcustomizations PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlcustomizations PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlcustomizations/main.qml" -) - -qt6_add_resources(qmlcustomizations "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlcustomizations - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlcustomizations/main.cpp b/examples/charts/qmlcustomizations/main.cpp deleted file mode 100644 index 0d5bb2a9..00000000 --- a/examples/charts/qmlcustomizations/main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtQuick/QQuickView> -#include <QtCore/QDir> -#include <QtQml/QQmlEngine> - -int main(int argc, char *argv[]) -{ - // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. - QApplication 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("QML Customizations")); - viewer.setSource(QUrl("qrc:/qml/qmlcustomizations/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/charts/qmlcustomizations/qmlcustomizations.pro b/examples/charts/qmlcustomizations/qmlcustomizations.pro deleted file mode 100644 index a2d316d6..00000000 --- a/examples/charts/qmlcustomizations/qmlcustomizations.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts qml quick - -SOURCES += \ - main.cpp - -RESOURCES += \ - resources.qrc - -DISTFILES += \ - qml/qmlcustomizations/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlcustomizations -INSTALLS += target diff --git a/examples/charts/qmlcustomizations/resources.qrc b/examples/charts/qmlcustomizations/resources.qrc deleted file mode 100644 index 35dd1b54..00000000 --- a/examples/charts/qmlcustomizations/resources.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlcustomizations/main.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlcustomlegend/CMakeLists.txt b/examples/charts/qmlcustomlegend/CMakeLists.txt deleted file mode 100644 index 2a6f9d9b..00000000 --- a/examples/charts/qmlcustomlegend/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(qmlcustomlegend LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlcustomlegend") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlcustomlegend - main.cpp -) - -set_target_properties(qmlcustomlegend PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlcustomlegend PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlcustomlegend/AnimatedAreaSeries.qml" - "qml/qmlcustomlegend/ChartViewHighlighted.qml" - "qml/qmlcustomlegend/ChartViewSelector.qml" - "qml/qmlcustomlegend/ChartViewStacked.qml" - "qml/qmlcustomlegend/CustomLegend.qml" - "qml/qmlcustomlegend/main.qml" -) - -qt6_add_resources(qmlcustomlegend "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlcustomlegend - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlcustomlegend/main.cpp b/examples/charts/qmlcustomlegend/main.cpp deleted file mode 100644 index 52d16e63..00000000 --- a/examples/charts/qmlcustomlegend/main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtQuick/QQuickView> -#include <QtCore/QDir> -#include <QtQml/QQmlEngine> - -int main(int argc, char *argv[]) -{ - // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. - QApplication 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("QML Custom Legend")); - viewer.setSource(QUrl("qrc:/qml/qmlcustomlegend/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/charts/qmlcustomlegend/qmlcustomlegend.pro b/examples/charts/qmlcustomlegend/qmlcustomlegend.pro deleted file mode 100644 index 478b68ac..00000000 --- a/examples/charts/qmlcustomlegend/qmlcustomlegend.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts qml quick - -SOURCES += \ - main.cpp - -RESOURCES += \ - resources.qrc - -DISTFILES += \ - qml/qmlcustomlegend/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlcustomlegend -INSTALLS += target diff --git a/examples/charts/qmlcustomlegend/resources.qrc b/examples/charts/qmlcustomlegend/resources.qrc deleted file mode 100644 index bd49690b..00000000 --- a/examples/charts/qmlcustomlegend/resources.qrc +++ /dev/null @@ -1,10 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlcustomlegend/main.qml</file> - <file>qml/qmlcustomlegend/CustomLegend.qml</file> - <file>qml/qmlcustomlegend/ChartViewStacked.qml</file> - <file>qml/qmlcustomlegend/ChartViewHighlighted.qml</file> - <file>qml/qmlcustomlegend/ChartViewSelector.qml</file> - <file>qml/qmlcustomlegend/AnimatedAreaSeries.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlf1legends/CMakeLists.txt b/examples/charts/qmlf1legends/CMakeLists.txt deleted file mode 100644 index 454c86f0..00000000 --- a/examples/charts/qmlf1legends/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlf1legends LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlf1legends") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlf1legends - main.cpp -) - -set_target_properties(qmlf1legends PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlf1legends PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlf1legends/SpeedsList.qml" - "qml/qmlf1legends/main.qml" -) - -qt6_add_resources(qmlf1legends "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlf1legends - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlf1legends/main.cpp b/examples/charts/qmlf1legends/main.cpp deleted file mode 100644 index 56fa12a5..00000000 --- a/examples/charts/qmlf1legends/main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtQuick/QQuickView> -#include <QtCore/QDir> -#include <QtQml/QQmlEngine> - -int main(int argc, char *argv[]) -{ - // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. - QApplication 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("QML F1 Legends")); - viewer.setSource(QUrl("qrc:/qml/qmlf1legends/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/charts/qmlf1legends/qml/qmlf1legends/SpeedsList.qml b/examples/charts/qmlf1legends/qml/qmlf1legends/SpeedsList.qml deleted file mode 100644 index 9714704b..00000000 --- a/examples/charts/qmlf1legends/qml/qmlf1legends/SpeedsList.qml +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQml.Models - -//![1] -ListModel { - // Hard-coded test data - ListElement { speedTrap:0; driver: "Fittipaldi"; speed:104.12 } - ListElement { speedTrap:0; driver:"Stewart"; speed:106.12 } - ListElement { speedTrap:0; driver:"Hunt"; speed:106.12 } -//![1] - ListElement { speedTrap:1; driver:"Fittipaldi"; speed:115.12 } - ListElement { speedTrap:1; driver:"Stewart"; speed:114.12 } - ListElement { speedTrap:1; driver:"Hunt"; speed:115.12 } - ListElement { speedTrap:2; driver:"Hunt"; speed:165.23 } - ListElement { speedTrap:2; driver:"Fittipaldi"; speed:175.23 } - ListElement { speedTrap:2; driver:"Stewart"; speed:168.23 } - ListElement { speedTrap:3; driver:"Hunt"; speed:104.87 } - ListElement { speedTrap:3; driver:"Fittipaldi"; speed:104.43 } - ListElement { speedTrap:3; driver:"Stewart"; speed:94.83 } - ListElement { speedTrap:4; driver:"Hunt"; speed:107.87 } - ListElement { speedTrap:4; driver:"Fittipaldi"; speed:111.84 } - ListElement { speedTrap:4; driver:"Stewart"; speed:106.84 } - ListElement { speedTrap:5; driver:"Hunt"; speed:94.87 } - ListElement { speedTrap:5; driver:"Stewart"; speed:92.37 } - ListElement { speedTrap:5; driver:"Fittipaldi"; speed:99.37 } - ListElement { speedTrap:6; driver:"Hunt"; speed:52.87 } - ListElement { speedTrap:6; driver:"Fittipaldi"; speed:42.87 } - ListElement { speedTrap:6; driver:"Stewart"; speed:55.87 } - ListElement { speedTrap:7; driver:"Hunt"; speed:77.87 } - ListElement { speedTrap:7; driver:"Fittipaldi"; speed:72.87 } - ListElement { speedTrap:7; driver:"Stewart"; speed:87.87 } - ListElement { speedTrap:8; driver:"Hunt"; speed:94.17 } - ListElement { speedTrap:8; driver:"Fittipaldi"; speed:98.17 } - ListElement { speedTrap:8; driver:"Stewart"; speed:84.17 } - ListElement { speedTrap:9; driver:"Hunt"; speed:91.87 } - ListElement { speedTrap:9; driver:"Fittipaldi"; speed:71.87 } - ListElement { speedTrap:9; driver:"Stewart"; speed:81.87 } - ListElement { speedTrap:10; driver:"Hunt"; speed:104.87 } - ListElement { speedTrap:10; driver:"Fittipaldi"; speed:115.87 } - ListElement { speedTrap:10; driver:"Stewart"; speed:119.87 } - ListElement { speedTrap:11; driver:"Hunt"; speed:162.87 } - ListElement { speedTrap:11; driver:"Fittipaldi"; speed:155.84 } - ListElement { speedTrap:11; driver:"Stewart"; speed:152.84 } - ListElement { speedTrap:12; driver:"Hunt"; speed:181.87 } - ListElement { speedTrap:12; driver:"Fittipaldi"; speed:161.85 } - ListElement { speedTrap:12; driver:"Stewart"; speed:167.85 } - ListElement { speedTrap:13; driver:"Hunt"; speed:155.87 } - ListElement { speedTrap:13; driver:"Fittipaldi"; speed:154.87 } - ListElement { speedTrap:13; driver:"Stewart"; speed:164.87 } - ListElement { speedTrap:14; driver:"Hunt"; speed:197.57 } - ListElement { speedTrap:14; driver:"Fittipaldi"; speed:187.54 } - ListElement { speedTrap:14; driver:"Stewart"; speed:180.54 } - ListElement { speedTrap:15; driver:"Fittipaldi"; speed:216.87 } - ListElement { speedTrap:15; driver:"Hunt"; speed:207.87 } - ListElement { speedTrap:15; driver:"Stewart"; speed:197.87 } - ListElement { speedTrap:16; driver:"Hunt"; speed:82.87 } - ListElement { speedTrap:16; driver:"Fittipaldi"; speed:79.37 } - ListElement { speedTrap:16; driver:"Stewart"; speed:85.37 } - ListElement { speedTrap:17; driver:"Hunt"; speed:153.87 } - ListElement { speedTrap:17; driver:"Fittipaldi"; speed:143.87 } - ListElement { speedTrap:17; driver:"Stewart"; speed:133.87 } - ListElement { speedTrap:18; driver:"Hunt"; speed:89.87 } - ListElement { speedTrap:18; driver:"Fittipaldi"; speed:95.85 } - ListElement { speedTrap:18; driver:"Stewart"; speed:98.85 } - ListElement { speedTrap:19; driver:"Hunt"; speed:169.87 } - ListElement { speedTrap:19; driver:"Stewart"; speed:167.87 } - ListElement { speedTrap:19; driver:"Fittipaldi"; speed:154.87 } -} diff --git a/examples/charts/qmlf1legends/qmlf1legends.pro b/examples/charts/qmlf1legends/qmlf1legends.pro deleted file mode 100644 index a3081f15..00000000 --- a/examples/charts/qmlf1legends/qmlf1legends.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts qml quick - -SOURCES += \ - main.cpp - -RESOURCES += \ - resources.qrc - -DISTFILES += \ - qml/qmlf1legends/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlf1legends -INSTALLS += target diff --git a/examples/charts/qmlf1legends/resources.qrc b/examples/charts/qmlf1legends/resources.qrc deleted file mode 100644 index e9c9f29a..00000000 --- a/examples/charts/qmlf1legends/resources.qrc +++ /dev/null @@ -1,6 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlf1legends/main.qml</file> - <file>qml/qmlf1legends/SpeedsList.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlgallery/CMakeLists.txt b/examples/charts/qmlgallery/CMakeLists.txt new file mode 100644 index 00000000..71548990 --- /dev/null +++ b/examples/charts/qmlgallery/CMakeLists.txt @@ -0,0 +1,79 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(qmlgallery LANGUAGES CXX) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlgallery") + +find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) + +qt_standard_project_setup() + +qt_add_executable(qmlgallery + main.cpp +) + +set_target_properties(qmlgallery PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(qmlgallery PUBLIC + Qt::Charts + Qt::Core + Qt::Gui + Qt::Qml + Qt::Quick +) + +# Resources: +set(resources_resource_files + "qml/AreaSeries.qml" + "qml/BarSeries.qml" + "qml/BarSeriesHorizontal.qml" + "qml/BarSeriesPercent.qml" + "qml/BarSeriesPercentHorizontal.qml" + "qml/BarSeriesStacked.qml" + "qml/BarSeriesStackedHorizontal.qml" + "qml/BoxPlotSeries.qml" + "qml/CandlestickSeries.qml" + "qml/CategoryAxis.qml" + "qml/CategoryAxisPolar.qml" + "qml/DateTimeAxis.qml" + "qml/DateTimeAxisPolar.qml" + "qml/Donut.qml" + "qml/LineSeries.qml" + "qml/Main.qml" + "qml/PieChart.qml" + "qml/SplineSeries.qml" + "qml/ScatterSeries.qml" + "qml/TwoSeries.qml" + "qml/TwoSeriesPolar.qml" + "qml/WheelOfFortune.qml" + "qml/customlegend/AnimatedAreaSeries.qml" + "qml/customlegend/ChartViewHighlighted.qml" + "qml/customlegend/ChartViewSelector.qml" + "qml/customlegend/ChartViewStacked.qml" + "qml/customlegend/CustomLegend.qml" + "qml/customlegend/Main.qml" + "qml/f1legends/F1Legends.qml" + "qml/f1legends/SpeedsList.qml" +) + +qt6_add_resources(qmlgallery "qmlgallery" + PREFIX + "/" + FILES + ${resources_resource_files} +) + +install(TARGETS qmlgallery + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/examples/charts/qmlboxplot/main.cpp b/examples/charts/qmlgallery/main.cpp index 521ae91b..f489efbd 100644 --- a/examples/charts/qmlboxplot/main.cpp +++ b/examples/charts/qmlgallery/main.cpp @@ -1,10 +1,10 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtCore/QDir> -#include <QtQuick/QQuickView> -#include <QtQml/QQmlEngine> +#include <QApplication> +#include <QDir> +#include <QQmlEngine> +#include <QQuickView> int main(int argc, char *argv[]) { @@ -12,6 +12,7 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QQuickView viewer; + viewer.setMinimumSize({600, 400}); // The following are needed to make examples run without having to install the module // in desktop environments. @@ -21,11 +22,11 @@ int main(int argc, char *argv[]) QString extraImportPath(QStringLiteral("%1/../../../%2")); #endif viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(), - QString::fromLatin1("qml"))); + QString::fromLatin1("qml"))); QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close); - viewer.setTitle(QStringLiteral("QML Box Plot")); - viewer.setSource(QUrl("qrc:/qml/qmlboxplot/main.qml")); + viewer.setTitle(QStringLiteral("QML Gallery")); + viewer.setSource(QUrl("qrc:/qml/Main.qml")); viewer.setResizeMode(QQuickView::SizeRootObjectToView); viewer.show(); diff --git a/examples/charts/qmlgallery/qml/AreaSeries.qml b/examples/charts/qmlgallery/qml/AreaSeries.qml new file mode 100644 index 00000000..80062616 --- /dev/null +++ b/examples/charts/qmlgallery/qml/AreaSeries.qml @@ -0,0 +1,78 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtCharts + +//![1] +ChartView { + title: "NHL All-Star Team Players" + anchors.fill: parent + antialiasing: true + + // Define x-axis to be used with the series instead of default one + ValueAxis { + id: valueAxis + min: 2000 + max: 2011 + tickCount: 12 + labelFormat: "%.0f" + } + + AreaSeries { + name: "Russian" + axisX: valueAxis + upperSeries: LineSeries { + XYPoint { x: 2000; y: 1 } + XYPoint { x: 2001; y: 1 } + XYPoint { x: 2002; y: 1 } + XYPoint { x: 2003; y: 1 } + XYPoint { x: 2004; y: 1 } + XYPoint { x: 2005; y: 0 } + XYPoint { x: 2006; y: 1 } + XYPoint { x: 2007; y: 1 } + XYPoint { x: 2008; y: 4 } + XYPoint { x: 2009; y: 3 } + XYPoint { x: 2010; y: 2 } + XYPoint { x: 2011; y: 1 } + } + } + //![1] + + AreaSeries { + name: "Swedish" + axisX: valueAxis + upperSeries: LineSeries { + XYPoint { x: 2000; y: 1 } + XYPoint { x: 2001; y: 1 } + XYPoint { x: 2002; y: 3 } + XYPoint { x: 2003; y: 3 } + XYPoint { x: 2004; y: 2 } + XYPoint { x: 2005; y: 0 } + XYPoint { x: 2006; y: 2 } + XYPoint { x: 2007; y: 1 } + XYPoint { x: 2008; y: 2 } + XYPoint { x: 2009; y: 1 } + XYPoint { x: 2010; y: 3 } + XYPoint { x: 2011; y: 3 } + } + } + + AreaSeries { + name: "Finnish" + axisX: valueAxis + upperSeries: LineSeries { + XYPoint { x: 2000; y: 0 } + XYPoint { x: 2001; y: 0 } + XYPoint { x: 2002; y: 0 } + XYPoint { x: 2003; y: 0 } + XYPoint { x: 2004; y: 0 } + XYPoint { x: 2005; y: 0 } + XYPoint { x: 2006; y: 1 } + XYPoint { x: 2007; y: 0 } + XYPoint { x: 2008; y: 0 } + XYPoint { x: 2009; y: 0 } + XYPoint { x: 2010; y: 0 } + XYPoint { x: 2011; y: 1 } + } + } +} diff --git a/examples/charts/qmlgallery/qml/BarSeries.qml b/examples/charts/qmlgallery/qml/BarSeries.qml new file mode 100644 index 00000000..7f6a5639 --- /dev/null +++ b/examples/charts/qmlgallery/qml/BarSeries.qml @@ -0,0 +1,22 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +ChartView { + title: "Bar Chart" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + BarSeries { + id: mySeries + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/BarSeriesHorizontal.qml b/examples/charts/qmlgallery/qml/BarSeriesHorizontal.qml new file mode 100644 index 00000000..bfdd7cec --- /dev/null +++ b/examples/charts/qmlgallery/qml/BarSeriesHorizontal.qml @@ -0,0 +1,21 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +ChartView { + title: "Horizontal Bar Chart" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + HorizontalBarSeries { + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/BarSeriesPercent.qml b/examples/charts/qmlgallery/qml/BarSeriesPercent.qml new file mode 100644 index 00000000..05ebf1cd --- /dev/null +++ b/examples/charts/qmlgallery/qml/BarSeriesPercent.qml @@ -0,0 +1,21 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +ChartView { + title: "Percent Bar Chart" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + PercentBarSeries { + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/BarSeriesPercentHorizontal.qml b/examples/charts/qmlgallery/qml/BarSeriesPercentHorizontal.qml new file mode 100644 index 00000000..28e913a3 --- /dev/null +++ b/examples/charts/qmlgallery/qml/BarSeriesPercentHorizontal.qml @@ -0,0 +1,21 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +ChartView { + title: "Horizontal Percent Bar Chart" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + HorizontalPercentBarSeries { + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/BarSeriesStacked.qml b/examples/charts/qmlgallery/qml/BarSeriesStacked.qml new file mode 100644 index 00000000..839119eb --- /dev/null +++ b/examples/charts/qmlgallery/qml/BarSeriesStacked.qml @@ -0,0 +1,21 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +ChartView { + title: "Stacked Bar Chart" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + StackedBarSeries { + axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/BarSeriesStackedHorizontal.qml b/examples/charts/qmlgallery/qml/BarSeriesStackedHorizontal.qml new file mode 100644 index 00000000..f84fccda --- /dev/null +++ b/examples/charts/qmlgallery/qml/BarSeriesStackedHorizontal.qml @@ -0,0 +1,21 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +ChartView { + title: "Horizontal Stacked Bar Chart" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + HorizontalStackedBarSeries { + axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } + BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] } + BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } + } +} +//![1] diff --git a/examples/charts/qmlboxplot/qml/qmlboxplot/main.qml b/examples/charts/qmlgallery/qml/BoxPlotSeries.qml index 57f9f7c0..09e15ed2 100644 --- a/examples/charts/qmlboxplot/qml/qmlboxplot/main.qml +++ b/examples/charts/qmlgallery/qml/BoxPlotSeries.qml @@ -1,14 +1,11 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +import QtQuick +import QtCharts ChartView { - title: "Box Plot series" - width: 400 - height: 300 - theme: ChartView.ChartThemeBrownSand + title: "Box Plot Chart" legend.alignment: Qt.AlignBottom antialiasing: true diff --git a/examples/charts/qmlcandlestick/qml/qmlcandlestick/main.qml b/examples/charts/qmlgallery/qml/CandlestickSeries.qml index 4be31c24..ad9ed52d 100644 --- a/examples/charts/qmlcandlestick/qml/qmlcandlestick/main.qml +++ b/examples/charts/qmlgallery/qml/CandlestickSeries.qml @@ -1,11 +1,11 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.2 +import QtQuick +import QtCharts ChartView { - title: "Candlestick series" + title: "Candlestick Chart" width: 800 height: 600 theme: ChartView.ChartThemeLight diff --git a/examples/charts/qmlgallery/qml/CategoryAxis.qml b/examples/charts/qmlgallery/qml/CategoryAxis.qml new file mode 100644 index 00000000..21a4f368 --- /dev/null +++ b/examples/charts/qmlgallery/qml/CategoryAxis.qml @@ -0,0 +1,46 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtCharts + +//![1] +ChartView { + title: "Numerical Data for Dummies" + anchors.fill: parent + legend.visible: false + antialiasing: true + + LineSeries { + axisY: CategoryAxis { + min: 0 + max: 30 + CategoryRange { + label: "critical" + endValue: 2 + } + CategoryRange { + label: "low" + endValue: 4 + } + CategoryRange { + label: "normal" + endValue: 7 + } + CategoryRange { + label: "high" + endValue: 15 + } + CategoryRange { + label: "extremely high" + endValue: 30 + } + } + + XYPoint { x: 0; y: 4.3 } + XYPoint { x: 1; y: 4.1 } + XYPoint { x: 2; y: 4.7 } + XYPoint { x: 3; y: 3.9 } + XYPoint { x: 4; y: 5.2 } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/CategoryAxisPolar.qml b/examples/charts/qmlgallery/qml/CategoryAxisPolar.qml new file mode 100644 index 00000000..b74fba2f --- /dev/null +++ b/examples/charts/qmlgallery/qml/CategoryAxisPolar.qml @@ -0,0 +1,55 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtCharts + +//![1] +PolarChartView { + title: "Numerical Data for Dummies" + anchors.fill: parent + legend.visible: false + antialiasing: true + + LineSeries { + axisRadial: CategoryAxis { + min: 0 + max: 30 + CategoryRange { + label: "critical" + endValue: 2 + } + CategoryRange { + label: "low" + endValue: 7 + } + CategoryRange { + label: "normal" + endValue: 12 + } + CategoryRange { + label: "high" + endValue: 18 + } + CategoryRange { + label: "extremely high" + endValue: 30 + } + } + + axisAngular: ValueAxis { + tickCount: 13 + } + + XYPoint { x: 0; y: 4.3 } + XYPoint { x: 1; y: 4.1 } + XYPoint { x: 2; y: 4.7 } + XYPoint { x: 3; y: 3.9 } + XYPoint { x: 4; y: 5.2 } + XYPoint { x: 5; y: 5.3 } + XYPoint { x: 6; y: 6.1 } + XYPoint { x: 7; y: 7.7 } + XYPoint { x: 8; y: 12.9 } + XYPoint { x: 9; y: 19.2 } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/DateTimeAxis.qml b/examples/charts/qmlgallery/qml/DateTimeAxis.qml new file mode 100644 index 00000000..97aa4dd2 --- /dev/null +++ b/examples/charts/qmlgallery/qml/DateTimeAxis.qml @@ -0,0 +1,39 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtCharts + +//![1] +ChartView { + id: root + title: "Accurate Historical Data" + anchors.fill: parent + legend.visible: false + antialiasing: true + + LineSeries { + axisX: DateTimeAxis { + format: "yyyy MMM" + tickCount: 5 + } + axisY: ValueAxis { + min: 0 + max: 150 + } + + // Please note that month in JavaScript months are zero based, so 2 means March + XYPoint { x: root.toMsecsSinceEpoch(new Date(1950, 2, 15)); y: 5 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1987, 12, 31)); y: 102 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(2012, 8, 2)); y: 110 } + } + + // DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to + // milliseconds since epoch to make them match the DateTimeAxis values + function toMsecsSinceEpoch(date) { + var msecs = date.getTime(); + return msecs; + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/DateTimeAxisPolar.qml b/examples/charts/qmlgallery/qml/DateTimeAxisPolar.qml new file mode 100644 index 00000000..87d69c45 --- /dev/null +++ b/examples/charts/qmlgallery/qml/DateTimeAxisPolar.qml @@ -0,0 +1,71 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +PolarChartView { + id: root + title: "Historical Area Chart" + anchors.fill: parent + legend.visible: false + antialiasing: true + + DateTimeAxis { + id: axis1 + format: "yyyy MMM" + tickCount: 13 + } + ValueAxis { + id: axis2 + } + LineSeries { + id: lowerLine + axisAngular: axis1 + axisRadial: axis2 + + // Please note that month in JavaScript months are zero based, so 2 means March + XYPoint { x: root.toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 15 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 35 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 75 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 102 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 132 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 120 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 140 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 150 } + } + LineSeries { + id: upperLine + axisAngular: axis1 + axisRadial: axis2 + + // Please note that month in JavaScript months are zero based, so 2 means March + XYPoint { x: root.toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 30 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 55 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 80 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 105 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 125 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 160 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 140 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 140 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 170 } + XYPoint { x: root.toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 200 } + } + AreaSeries { + axisAngular: axis1 + axisRadial: axis2 + lowerSeries: lowerLine + upperSeries: upperLine + } + + // DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to + // milliseconds since epoch to make them match the DateTimeAxis values + function toMsecsSinceEpoch(date) { + var msecs = date.getTime(); + return msecs; + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/Donut.qml b/examples/charts/qmlgallery/qml/Donut.qml new file mode 100644 index 00000000..dceed779 --- /dev/null +++ b/examples/charts/qmlgallery/qml/Donut.qml @@ -0,0 +1,57 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +ChartView { + id: chart + title: "Production Costs" + anchors.fill: parent + legend.visible: false + antialiasing: true + + PieSeries { + id: pieOuter + size: 0.96 + holeSize: 0.7 + PieSlice { id: slice; label: "Alpha"; value: 19511; color: "#99CA53" } + PieSlice { label: "Epsilon"; value: 11105; color: "#209FDF" } + PieSlice { label: "Psi"; value: 9352; color: "#F6A625" } + } + + PieSeries { + size: 0.7 + id: pieInner + holeSize: 0.25 + + PieSlice { label: "Materials"; value: 10334; color: "#B9DB8A" } + PieSlice { label: "Employee"; value: 3066; color: "#DCEDC4" } + PieSlice { label: "Logistics"; value: 6111; color: "#F3F9EB" } + + PieSlice { label: "Materials"; value: 7371; color: "#63BCE9" } + PieSlice { label: "Employee"; value: 2443; color: "#A6D9F2" } + PieSlice { label: "Logistics"; value: 1291; color: "#E9F5FC" } + + PieSlice { label: "Materials"; value: 4022; color: "#F9C36C" } + PieSlice { label: "Employee"; value: 3998; color: "#FCE1B6" } + PieSlice { label: "Logistics"; value: 1332; color: "#FEF5E7" } + } + + Component.onCompleted: { + // Set the common slice properties dynamically for convenience + for (var i = 0; i < pieOuter.count; i++) { + pieOuter.at(i).labelPosition = PieSlice.LabelOutside; + pieOuter.at(i).labelVisible = true; + pieOuter.at(i).borderWidth = 3; + } + for (var i = 0; i < pieInner.count; i++) { + pieInner.at(i).labelPosition = PieSlice.LabelInsideNormal; + pieInner.at(i).labelVisible = true; + pieInner.at(i).borderWidth = 2; + } + } +} + +//![1] diff --git a/examples/charts/qmlgallery/qml/LineSeries.qml b/examples/charts/qmlgallery/qml/LineSeries.qml new file mode 100644 index 00000000..bc41d2fd --- /dev/null +++ b/examples/charts/qmlgallery/qml/LineSeries.qml @@ -0,0 +1,23 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtCharts + +//![1] +ChartView { + title: "Line Chart" + anchors.fill: parent + antialiasing: true + + LineSeries { + name: "Line" + XYPoint { x: 0; y: 0 } + XYPoint { x: 1.1; y: 2.1 } + XYPoint { x: 1.9; y: 3.3 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 4.9 } + XYPoint { x: 3.4; y: 3.0 } + XYPoint { x: 4.1; y: 3.3 } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/Main.qml b/examples/charts/qmlgallery/qml/Main.qml new file mode 100644 index 00000000..0670b810 --- /dev/null +++ b/examples/charts/qmlgallery/qml/Main.qml @@ -0,0 +1,165 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +Rectangle { + id: root + width: 1200 + height: 600 + + color: "#f0f0f0" + + Row { + id: row + padding: 8 + spacing: 8 + + Rectangle { + width: 200 + height: root.height - row.padding * 2 + border.width: 1 + + ListView { + id: listView + focus: true + anchors.fill: parent + anchors.margins: 1 + highlightMoveDuration: 250 + orientation: ListView.Vertical + boundsBehavior: Flickable.StopAtBounds + currentIndex: 0 + clip: true + + model: ListModel { + ListElement { + name: "Area Chart" + component: "AreaSeries.qml" + } + ListElement { + name: "Bar Chart" + component: "BarSeries.qml" + } + ListElement { + name: "Bar Chart Horizontal" + component: "BarSeriesHorizontal.qml" + } + ListElement { + name: "Bar Chart Percent" + component: "BarSeriesPercent.qml" + } + ListElement { + name: "Bar Chart Percent Horizontal" + component: "BarSeriesPercentHorizontal.qml" + } + ListElement { + name: "Bar Chart Stacked" + component: "BarSeriesStacked.qml" + } + ListElement { + name: "Bar Chart Stacked Horizontal" + component: "BarSeriesStackedHorizontal.qml" + } + ListElement { + name: "Box Plot Chart" + component: "BoxPlotSeries.qml" + } + ListElement { + name: "Candlestick Chart" + component: "CandlestickSeries.qml" + } + ListElement { + name: "Category Axis" + component: "CategoryAxis.qml" + } + ListElement { + name: "Category Axis Polar" + component: "CategoryAxisPolar.qml" + } + ListElement { + name: "Custom Legend" + component: "customlegend/Main.qml" + } + ListElement { + name: "Datetime Axis" + component: "DateTimeAxis.qml" + } + ListElement { + name: "Datetime Axis Polar" + component: "DateTimeAxisPolar.qml" + } + ListElement { + name: "Donut" + component: "Donut.qml" + } + ListElement { + name: "F1 Legends" + component: "f1legends/F1Legends.qml" + } + ListElement { + name: "Line Chart" + component: "LineSeries.qml" + } + ListElement { + name: "Pie Chart" + component: "PieChart.qml" + } + ListElement { + name: "Spline Chart" + component: "SplineSeries.qml" + } + ListElement { + name: "Scatter Chart" + component: "ScatterSeries.qml" + } + ListElement { + name: "Two Series in Chart" + component: "TwoSeries.qml" + } + ListElement { + name: "Two Series in Polar Chart" + component: "TwoSeriesPolar.qml" + } + ListElement { + name: "Wheel of Fortune" + component: "WheelOfFortune.qml" + } + } + + delegate: Text { + property string source: component + text: name + width: listView.width + leftPadding: 4 + + MouseArea { + anchors.fill: parent + onClicked: { + listView.currentIndex = index + } + } + } + + highlight: Rectangle { + color: "lightblue"; + } + } + } + + Rectangle { + height: root.height - row.padding * 2 + width: root.width - listView.width - row.spacing - row.padding * 2 + radius: 5 + clip: true + + Loader { + id: loader + anchors.fill: parent + anchors.margins: 4 + + asynchronous: true + source: listView.currentItem.source + } + } + } +} diff --git a/examples/charts/qmlgallery/qml/PieChart.qml b/examples/charts/qmlgallery/qml/PieChart.qml new file mode 100644 index 00000000..2cd57ca7 --- /dev/null +++ b/examples/charts/qmlgallery/qml/PieChart.qml @@ -0,0 +1,35 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +//![2] +import QtQuick +//![2] +import QtCharts + +//![1] +ChartView { + id: chart + title: "Top-5 car brand shares in Finland" + anchors.fill: parent + legend.alignment: Qt.AlignBottom + antialiasing: true + + property variant othersSlice: 0 + + PieSeries { + id: pieSeries + PieSlice { label: "Volkswagen"; value: 13.5 } + PieSlice { label: "Toyota"; value: 10.9 } + PieSlice { label: "Ford"; value: 8.6 } + PieSlice { label: "Skoda"; value: 8.2 } + PieSlice { label: "Volvo"; value: 6.8 } + } + + Component.onCompleted: { + // You can also manipulate slices dynamically, like append a slice or set a slice exploded + othersSlice = pieSeries.append("Others", 52.0); + pieSeries.find("Volkswagen").exploded = true; + } +} + +//![1] diff --git a/examples/charts/qmlgallery/qml/ScatterSeries.qml b/examples/charts/qmlgallery/qml/ScatterSeries.qml new file mode 100644 index 00000000..2f03bfc6 --- /dev/null +++ b/examples/charts/qmlgallery/qml/ScatterSeries.qml @@ -0,0 +1,34 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtCharts + +//![1] +ChartView { + title: "Scatter Chart" + anchors.fill: parent + antialiasing: true + + ScatterSeries { + id: scatter1 + name: "Scatter A" + XYPoint { x: 1.5; y: 1.5 } + XYPoint { x: 1.5; y: 1.6 } + XYPoint { x: 1.57; y: 1.55 } + XYPoint { x: 1.8; y: 1.8 } + XYPoint { x: 1.9; y: 1.6 } + XYPoint { x: 2.1; y: 1.3 } + XYPoint { x: 2.5; y: 2.1 } + } + + ScatterSeries { + name: "Scatter B" + XYPoint { x: 2.0; y: 2.0 } + XYPoint { x: 2.0; y: 2.1 } + XYPoint { x: 2.07; y: 2.05 } + XYPoint { x: 2.2; y: 2.9 } + XYPoint { x: 2.4; y: 2.7 } + XYPoint { x: 2.67; y: 2.65 } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/SplineSeries.qml b/examples/charts/qmlgallery/qml/SplineSeries.qml new file mode 100644 index 00000000..d9d8c287 --- /dev/null +++ b/examples/charts/qmlgallery/qml/SplineSeries.qml @@ -0,0 +1,23 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtCharts + +//![1] +ChartView { + title: "Spline Chart" + anchors.fill: parent + antialiasing: true + + SplineSeries { + name: "Spline" + XYPoint { x: 0; y: 0.0 } + XYPoint { x: 1.1; y: 3.2 } + XYPoint { x: 1.9; y: 2.4 } + XYPoint { x: 2.1; y: 2.1 } + XYPoint { x: 2.9; y: 2.6 } + XYPoint { x: 3.4; y: 2.3 } + XYPoint { x: 4.1; y: 3.1 } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/TwoSeries.qml b/examples/charts/qmlgallery/qml/TwoSeries.qml new file mode 100644 index 00000000..767e091c --- /dev/null +++ b/examples/charts/qmlgallery/qml/TwoSeries.qml @@ -0,0 +1,47 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +ChartView { + title: "Two Series, Common Axes" + anchors.fill: parent + legend.visible: false + antialiasing: true + + ValueAxis { + id: axisX + min: 0 + max: 10 + tickCount: 5 + } + + ValueAxis { + id: axisY + min: -0.5 + max: 1.5 + } + + LineSeries { + id: series1 + axisX: axisX + axisY: axisY + } + + ScatterSeries { + id: series2 + axisX: axisX + axisY: axisY + } + + // Add data dynamically to the series + Component.onCompleted: { + for (var i = 0; i <= 10; i++) { + series1.append(i, Math.random()); + series2.append(i, Math.random()); + } + } +} +//![1] diff --git a/examples/charts/qmlgallery/qml/TwoSeriesPolar.qml b/examples/charts/qmlgallery/qml/TwoSeriesPolar.qml new file mode 100644 index 00000000..ce5fd9fc --- /dev/null +++ b/examples/charts/qmlgallery/qml/TwoSeriesPolar.qml @@ -0,0 +1,49 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick +import QtCharts + +//![1] +PolarChartView { + title: "Two Series, Common Axes" + anchors.fill: parent + legend.visible: false + antialiasing: true + + ValueAxis { + id: axisAngular + min: 0 + max: 20 + tickCount: 9 + } + + ValueAxis { + id: axisRadial + min: -0.5 + max: 1.5 + } + + SplineSeries { + id: series1 + axisAngular: axisAngular + axisRadial: axisRadial + pointsVisible: true + } + + ScatterSeries { + id: series2 + axisAngular: axisAngular + axisRadial: axisRadial + markerSize: 10 + } + + // Add data dynamically to the series + Component.onCompleted: { + for (var i = 0; i <= 20; i++) { + series1.append(i, Math.random()); + series2.append(i, Math.random()); + } + } +} +//![1] diff --git a/examples/charts/qmlcustomizations/qml/qmlcustomizations/main.qml b/examples/charts/qmlgallery/qml/WheelOfFortune.qml index b9682033..b03d61a3 100644 --- a/examples/charts/qmlcustomizations/qml/qmlcustomizations/main.qml +++ b/examples/charts/qmlgallery/qml/WheelOfFortune.qml @@ -1,12 +1,11 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +import QtQuick +import QtCharts Item { - width: 400 - height: 300 + id: root property int __activeIndex: 1 property real __intervalCoefficient: 0 @@ -14,7 +13,7 @@ Item { ChartView { id: chartView anchors.fill: parent - title: "Wheel of fortune" + title: "Wheel of Fortune" legend.visible: false antialiasing: true @@ -58,18 +57,18 @@ Item { repeat: true interval: 100 onTriggered: { - var index = __activeIndex % wheelOfFortune.count; + var index = root.__activeIndex % wheelOfFortune.count; if (interval < 700) { //![3] wheelOfFortune.at(index).exploded = false; - __activeIndex++; - index = __activeIndex % wheelOfFortune.count; + root.__activeIndex++; + index = root.__activeIndex % wheelOfFortune.count; wheelOfFortune.at(index).exploded = true; //![3] - interval = splineSeries.at(__activeIndex).y; + interval = splineSeries.at(root.__activeIndex).y; //![4] scatterSeries.clear(); - scatterSeries.append(__activeIndex, interval); + scatterSeries.append(root.__activeIndex, interval); scatterSeries.color = Qt.tint(scatterSeries.color, "#05FF0000"); scatterSeries.markerSize += 0.5; //![4] diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/AnimatedAreaSeries.qml b/examples/charts/qmlgallery/qml/customlegend/AnimatedAreaSeries.qml index 2788b2ca..1b768878 100644 --- a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/AnimatedAreaSeries.qml +++ b/examples/charts/qmlgallery/qml/customlegend/AnimatedAreaSeries.qml @@ -1,8 +1,8 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +import QtQuick +import QtCharts AreaSeries { id: series diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewHighlighted.qml b/examples/charts/qmlgallery/qml/customlegend/ChartViewHighlighted.qml index baff581c..f29c944c 100644 --- a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewHighlighted.qml +++ b/examples/charts/qmlgallery/qml/customlegend/ChartViewHighlighted.qml @@ -1,15 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +import QtQuick +import QtCharts //![1] ChartView { id: chartViewHighlighted - title: "" + property variant selectedSeries + signal clicked + legend.visible: false margins.top: 10 margins.bottom: 0 diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewSelector.qml b/examples/charts/qmlgallery/qml/customlegend/ChartViewSelector.qml index e063cdd6..c623af8c 100644 --- a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewSelector.qml +++ b/examples/charts/qmlgallery/qml/customlegend/ChartViewSelector.qml @@ -1,18 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +import QtQuick +import QtCharts Item { id: chartViewSelector - width: parent.width - height: parent.height + signal seriesAdded(string seriesName, color seriesColor) function highlightSeries(seriesName) { - if (seriesName == "") { - if (state != "") + if (seriesName === "") { + if (state !== "") state = ""; for (var i = 0; i < chartViewStacked.count; i++) @@ -20,9 +19,9 @@ Item { } else { var targetOpacity = 0.1; for (var j = 0; j < chartViewStacked.count; j++) { - if (chartViewStacked.series(j).name != seriesName) + if (chartViewStacked.series(j).name !== seriesName) chartViewStacked.series(j).opacity = 0.25; - else if (state == "highlight") + else if (state === "highlight") chartViewSelected.selectedSeries = chartViewStacked.series(j); } } @@ -30,9 +29,9 @@ Item { function selectSeries(seriesName) { for (var i = 0; i < chartViewStacked.count; i++) { - if (chartViewStacked.series(i).name == seriesName) { + if (chartViewStacked.series(i).name === seriesName) { chartViewSelected.selectedSeries = chartViewStacked.series(i); - if (chartViewSelector.state == "") + if (chartViewSelector.state === "") chartViewSelector.state = "highlighted"; else chartViewSelector.state = ""; @@ -46,7 +45,7 @@ Item { anchors.leftMargin: 0 width: parent.width height: parent.height - onSeriesAdded: chartViewSelector.seriesAdded(series.name, series.color); + onSeriesAdded: series => chartViewSelector.seriesAdded(series.name, series.color); } ChartViewHighlighted { diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewStacked.qml b/examples/charts/qmlgallery/qml/customlegend/ChartViewStacked.qml index 336a3a88..063ceef6 100644 --- a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/ChartViewStacked.qml +++ b/examples/charts/qmlgallery/qml/customlegend/ChartViewStacked.qml @@ -1,15 +1,17 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +import QtQuick +import QtCharts ChartView { id: chartView - title: "Government Taxes" - legend.visible: false + signal entered(string seriesName) signal exited(string seriesName) + + title: "Government Taxes" + legend.visible: false margins.top: 10 margins.bottom: 0 antialiasing: true diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml b/examples/charts/qmlgallery/qml/customlegend/CustomLegend.qml index 85191c55..229fb834 100644 --- a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/CustomLegend.qml +++ b/examples/charts/qmlgallery/qml/customlegend/CustomLegend.qml @@ -1,8 +1,8 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 20236 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +pragma ComponentBehavior: Bound +import QtQuick Rectangle { id: legend @@ -11,6 +11,7 @@ Rectangle { property int seriesCount: 0 property variant seriesNames: [] property variant seriesColors: [] + signal entered(string seriesName) signal exited(string seriesName) signal selected(string seriesName) @@ -45,8 +46,9 @@ Rectangle { Rectangle { id: rect //![2] - property string name: seriesNames[index] - property color markerColor: seriesColors[index] + property string name: legend.seriesNames[DelegateModel.itemsIndex] + property color markerColor: legend.seriesColors[DelegateModel.itemsIndex] + gradient: buttonGradient border.color: "#A0A0A0" border.width: 1 @@ -64,7 +66,7 @@ Rectangle { Rectangle { id: marker anchors.verticalCenter: parent.verticalCenter - color: markerColor + color: rect.markerColor opacity: 0.3 radius: 4 width: 12 @@ -74,7 +76,7 @@ Rectangle { id: label anchors.verticalCenter: parent.verticalCenter anchors.verticalCenterOffset: -1 - text: name + text: rect.name } } @@ -111,7 +113,7 @@ Rectangle { Repeater { id: legendRepeater - model: seriesCount + model: legend.seriesCount delegate: legendDelegate } } diff --git a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/main.qml b/examples/charts/qmlgallery/qml/customlegend/Main.qml index 419a5ac9..354e3362 100644 --- a/examples/charts/qmlcustomlegend/qml/qmlcustomlegend/main.qml +++ b/examples/charts/qmlgallery/qml/customlegend/Main.qml @@ -1,13 +1,10 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +import QtQuick Item { id: main - width: 400 - height: 320 Column { id: column @@ -19,7 +16,7 @@ Item { id: chartViewSelector width: parent.width height: parent.height - customLegend.height - anchors.bottomMargin - onSeriesAdded: customLegend.addSeries(seriesName, seriesColor); + onSeriesAdded: (seriesName, seriesColor) => customLegend.addSeries(seriesName, seriesColor); } CustomLegend { @@ -27,9 +24,9 @@ Item { width: parent.width height: 50 anchors.horizontalCenter: parent.horizontalCenter - onEntered: chartViewSelector.highlightSeries(seriesName); + onEntered: seriesName => chartViewSelector.highlightSeries(seriesName); onExited: chartViewSelector.highlightSeries(""); - onSelected: chartViewSelector.selectSeries(seriesName); + onSelected: seriesName => chartViewSelector.selectSeries(seriesName); } } diff --git a/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml b/examples/charts/qmlgallery/qml/f1legends/F1Legends.qml index 8e665aa0..84c5071b 100644 --- a/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml +++ b/examples/charts/qmlgallery/qml/f1legends/F1Legends.qml @@ -1,11 +1,11 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtCharts -import QtQml.Models Item { + id: root width: 400 height: 300 property int currentIndex: -1 @@ -40,14 +40,14 @@ Item { triggeredOnStart: true running: false onTriggered: { - currentIndex++; - if (currentIndex < speedsList.count) { + root.currentIndex++; + if (root.currentIndex < speedsList.count) { // Check if there is a series for the data already // (we are using driver name to identify series) - var lineSeries = chartView.series(speedsList.get(currentIndex).driver); + var lineSeries = chartView.series(speedsList.get(root.currentIndex).driver); if (!lineSeries) { lineSeries = chartView.createSeries(ChartView.SeriesTypeLine, - speedsList.get(currentIndex).driver); + speedsList.get(root.currentIndex).driver); chartView.axisY().min = 0; chartView.axisY().max = 250; chartView.axisY().tickCount = 6; @@ -55,11 +55,11 @@ Item { chartView.axisX().titleText = "speed trap"; chartView.axisX().labelFormat = "%.0f"; } - lineSeries.append(speedsList.get(currentIndex).speedTrap, - speedsList.get(currentIndex).speed); + lineSeries.append(speedsList.get(root.currentIndex).speedTrap, + speedsList.get(root.currentIndex).speed); - if (speedsList.get(currentIndex).speedTrap > 3) { - chartView.axisX().max = Number(speedsList.get(currentIndex).speedTrap) + 1; + if (speedsList.get(root.currentIndex).speedTrap > 3) { + chartView.axisX().max = Number(speedsList.get(root.currentIndex).speedTrap) + 1; chartView.axisX().min = chartView.axisX().max - 5; } else { chartView.axisX().max = 5; @@ -71,7 +71,7 @@ Item { timer.stop(); chartView.animationOptions = ChartView.AllAnimations; chartView.axisX().min = 0; - chartView.axisX().max = speedsList.get(currentIndex - 1).speedTrap; + chartView.axisX().max = speedsList.get(root.currentIndex - 1).speedTrap; } } } diff --git a/examples/charts/qmlgallery/qml/f1legends/SpeedsList.qml b/examples/charts/qmlgallery/qml/f1legends/SpeedsList.qml new file mode 100644 index 00000000..e618ee12 --- /dev/null +++ b/examples/charts/qmlgallery/qml/f1legends/SpeedsList.qml @@ -0,0 +1,70 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQml.Models + +//![1] +ListModel { + // Hard-coded test data + ListElement { speedTrap:0; driver: "Fittipaldi"; speed:104.12 } + ListElement { speedTrap:0; driver:"Stewart"; speed:106.12 } + ListElement { speedTrap:0; driver:"Hunt"; speed:106.12 } +//![1] + ListElement { speedTrap:1; driver:"Fittipaldi"; speed:115.12 } + ListElement { speedTrap:1; driver:"Stewart"; speed:114.12 } + ListElement { speedTrap:1; driver:"Hunt"; speed:115.12 } + ListElement { speedTrap:2; driver:"Hunt"; speed:165.23 } + ListElement { speedTrap:2; driver:"Fittipaldi"; speed:175.23 } + ListElement { speedTrap:2; driver:"Stewart"; speed:168.23 } + ListElement { speedTrap:3; driver:"Hunt"; speed:104.87 } + ListElement { speedTrap:3; driver:"Fittipaldi"; speed:104.43 } + ListElement { speedTrap:3; driver:"Stewart"; speed:94.83 } + ListElement { speedTrap:4; driver:"Hunt"; speed:107.87 } + ListElement { speedTrap:4; driver:"Fittipaldi"; speed:111.84 } + ListElement { speedTrap:4; driver:"Stewart"; speed:106.84 } + ListElement { speedTrap:5; driver:"Hunt"; speed:94.87 } + ListElement { speedTrap:5; driver:"Stewart"; speed:92.37 } + ListElement { speedTrap:5; driver:"Fittipaldi"; speed:99.37 } + ListElement { speedTrap:6; driver:"Hunt"; speed:52.87 } + ListElement { speedTrap:6; driver:"Fittipaldi"; speed:42.87 } + ListElement { speedTrap:6; driver:"Stewart"; speed:55.87 } + ListElement { speedTrap:7; driver:"Hunt"; speed:77.87 } + ListElement { speedTrap:7; driver:"Fittipaldi"; speed:72.87 } + ListElement { speedTrap:7; driver:"Stewart"; speed:87.87 } + ListElement { speedTrap:8; driver:"Hunt"; speed:94.17 } + ListElement { speedTrap:8; driver:"Fittipaldi"; speed:98.17 } + ListElement { speedTrap:8; driver:"Stewart"; speed:84.17 } + ListElement { speedTrap:9; driver:"Hunt"; speed:91.87 } + ListElement { speedTrap:9; driver:"Fittipaldi"; speed:71.87 } + ListElement { speedTrap:9; driver:"Stewart"; speed:81.87 } + ListElement { speedTrap:10; driver:"Hunt"; speed:104.87 } + ListElement { speedTrap:10; driver:"Fittipaldi"; speed:115.87 } + ListElement { speedTrap:10; driver:"Stewart"; speed:119.87 } + ListElement { speedTrap:11; driver:"Hunt"; speed:162.87 } + ListElement { speedTrap:11; driver:"Fittipaldi"; speed:155.84 } + ListElement { speedTrap:11; driver:"Stewart"; speed:152.84 } + ListElement { speedTrap:12; driver:"Hunt"; speed:181.87 } + ListElement { speedTrap:12; driver:"Fittipaldi"; speed:161.85 } + ListElement { speedTrap:12; driver:"Stewart"; speed:167.85 } + ListElement { speedTrap:13; driver:"Hunt"; speed:155.87 } + ListElement { speedTrap:13; driver:"Fittipaldi"; speed:154.87 } + ListElement { speedTrap:13; driver:"Stewart"; speed:164.87 } + ListElement { speedTrap:14; driver:"Hunt"; speed:197.57 } + ListElement { speedTrap:14; driver:"Fittipaldi"; speed:187.54 } + ListElement { speedTrap:14; driver:"Stewart"; speed:180.54 } + ListElement { speedTrap:15; driver:"Fittipaldi"; speed:216.87 } + ListElement { speedTrap:15; driver:"Hunt"; speed:207.87 } + ListElement { speedTrap:15; driver:"Stewart"; speed:197.87 } + ListElement { speedTrap:16; driver:"Hunt"; speed:82.87 } + ListElement { speedTrap:16; driver:"Fittipaldi"; speed:79.37 } + ListElement { speedTrap:16; driver:"Stewart"; speed:85.37 } + ListElement { speedTrap:17; driver:"Hunt"; speed:153.87 } + ListElement { speedTrap:17; driver:"Fittipaldi"; speed:143.87 } + ListElement { speedTrap:17; driver:"Stewart"; speed:133.87 } + ListElement { speedTrap:18; driver:"Hunt"; speed:89.87 } + ListElement { speedTrap:18; driver:"Fittipaldi"; speed:95.85 } + ListElement { speedTrap:18; driver:"Stewart"; speed:98.85 } + ListElement { speedTrap:19; driver:"Hunt"; speed:169.87 } + ListElement { speedTrap:19; driver:"Stewart"; speed:167.87 } + ListElement { speedTrap:19; driver:"Fittipaldi"; speed:154.87 } +} diff --git a/examples/charts/qmlgallery/qmlgallery.pro b/examples/charts/qmlgallery/qmlgallery.pro new file mode 100644 index 00000000..ac53ad6e --- /dev/null +++ b/examples/charts/qmlgallery/qmlgallery.pro @@ -0,0 +1,13 @@ +QT += charts qml quick + +SOURCES += main.cpp + +RESOURCES += qmlgallery.qrc + +DISTFILES += \ + qml/* \ + qml/customlegend/* \ + qml/f1legends/* + +target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlgallery +INSTALLS += target diff --git a/examples/charts/qmlgallery/qmlgallery.qrc b/examples/charts/qmlgallery/qmlgallery.qrc new file mode 100644 index 00000000..f0d63650 --- /dev/null +++ b/examples/charts/qmlgallery/qmlgallery.qrc @@ -0,0 +1,34 @@ +<RCC> + <qresource prefix="/"> + <file>qml/AreaSeries.qml</file> + <file>qml/BarSeries.qml</file> + <file>qml/BarSeriesHorizontal.qml</file> + <file>qml/BarSeriesPercentHorizontal.qml</file> + <file>qml/BarSeriesStackedHorizontal.qml</file> + <file>qml/BarSeriesPercent.qml</file> + <file>qml/BarSeriesStacked.qml</file> + <file>qml/BoxPlotSeries.qml</file> + <file>qml/CandlestickSeries.qml</file> + <file>qml/CategoryAxis.qml</file> + <file>qml/CategoryAxisPolar.qml</file> + <file>qml/DateTimeAxis.qml</file> + <file>qml/DateTimeAxisPolar.qml</file> + <file>qml/Donut.qml</file> + <file>qml/LineSeries.qml</file> + <file>qml/Main.qml</file> + <file>qml/PieChart.qml</file> + <file>qml/SplineSeries.qml</file> + <file>qml/ScatterSeries.qml</file> + <file>qml/TwoSeries.qml</file> + <file>qml/TwoSeriesPolar.qml</file> + <file>qml/WheelOfFortune.qml</file> + <file>qml/customlegend/AnimatedAreaSeries.qml</file> + <file>qml/customlegend/ChartViewHighlighted.qml</file> + <file>qml/customlegend/ChartViewSelector.qml</file> + <file>qml/customlegend/ChartViewStacked.qml</file> + <file>qml/customlegend/CustomLegend.qml</file> + <file>qml/customlegend/Main.qml</file> + <file>qml/f1legends/F1Legends.qml</file> + <file>qml/f1legends/SpeedsList.qml</file> + </qresource> +</RCC> diff --git a/examples/charts/qmloscilloscope/CMakeLists.txt b/examples/charts/qmloscilloscope/CMakeLists.txt index 390f87c9..1ff57dfa 100644 --- a/examples/charts/qmloscilloscope/CMakeLists.txt +++ b/examples/charts/qmloscilloscope/CMakeLists.txt @@ -4,8 +4,6 @@ cmake_minimum_required(VERSION 3.16) project(qmloscilloscope LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmloscilloscope") find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) +qt_standard_project_setup() + qt_add_executable(qmloscilloscope datasource.cpp datasource.h main.cpp diff --git a/examples/charts/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp index 638f9d52..4f13bec0 100644 --- a/examples/charts/qmloscilloscope/datasource.cpp +++ b/examples/charts/qmloscilloscope/datasource.cpp @@ -1,24 +1,21 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "datasource.h" -#include <QtCharts/QXYSeries> -#include <QtCharts/QAreaSeries> -#include <QtQuick/QQuickView> -#include <QtQuick/QQuickItem> -#include <QtCore/QDebug> -#include <QtCore/QRandomGenerator> -#include <QtCore/QtMath> -QT_USE_NAMESPACE +#include <QAreaSeries> +#include <QQuickItem> +#include <QQuickView> +#include <QRandomGenerator> +#include <QtMath> +#include <QXYSeries> Q_DECLARE_METATYPE(QAbstractSeries *) Q_DECLARE_METATYPE(QAbstractAxis *) -DataSource::DataSource(QQuickView *appViewer, QObject *parent) : - QObject(parent), - m_appViewer(appViewer), - m_index(-1) +DataSource::DataSource(QQuickView *appViewer, QObject *parent) + : QObject(parent) + , m_appViewer(appViewer) { qRegisterMetaType<QAbstractSeries*>(); qRegisterMetaType<QAbstractAxis*>(); @@ -29,7 +26,7 @@ DataSource::DataSource(QQuickView *appViewer, QObject *parent) : void DataSource::update(QAbstractSeries *series) { if (series) { - QXYSeries *xySeries = static_cast<QXYSeries *>(series); + auto xySeries = static_cast<QXYSeries *>(series); m_index++; if (m_index > m_data.count() - 1) m_index = 0; diff --git a/examples/charts/qmloscilloscope/datasource.h b/examples/charts/qmloscilloscope/datasource.h index 51999c41..c09982bd 100644 --- a/examples/charts/qmloscilloscope/datasource.h +++ b/examples/charts/qmloscilloscope/datasource.h @@ -1,34 +1,30 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef DATASOURCE_H #define DATASOURCE_H -#include <QtCore/QObject> -#include <QtCharts/QAbstractSeries> +#include <QList> +#include <QObject> +#include <QPointF> -QT_BEGIN_NAMESPACE -class QQuickView; -QT_END_NAMESPACE - -QT_USE_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QAbstractSeries) +QT_FORWARD_DECLARE_CLASS(QQuickView) class DataSource : public QObject { Q_OBJECT public: - explicit DataSource(QQuickView *appViewer, QObject *parent = 0); - -Q_SIGNALS: + explicit DataSource(QQuickView *appViewer, QObject *parent = nullptr); public slots: void generateData(int type, int rowCount, int colCount); void update(QAbstractSeries *series); private: - QQuickView *m_appViewer; + QQuickView *m_appViewer = nullptr; QList<QList<QPointF>> m_data; - int m_index; + int m_index = -1; }; -#endif // DATASOURCE_H +#endif diff --git a/examples/charts/qmloscilloscope/main.cpp b/examples/charts/qmloscilloscope/main.cpp index e908a2bf..a4020a63 100644 --- a/examples/charts/qmloscilloscope/main.cpp +++ b/examples/charts/qmloscilloscope/main.cpp @@ -1,13 +1,14 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QApplication> -#include <QtQml/QQmlContext> -#include <QtQuick/QQuickView> -#include <QtQml/QQmlEngine> -#include <QtCore/QDir> #include "datasource.h" +#include <QApplication> +#include <QDir> +#include <QQmlContext> +#include <QQmlEngine> +#include <QQuickView> + int main(int argc, char *argv[]) { // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. diff --git a/examples/charts/qmloscilloscope/qml/qmloscilloscope/ControlPanel.qml b/examples/charts/qmloscilloscope/qml/qmloscilloscope/ControlPanel.qml index 820cd081..d5c1bc35 100644 --- a/examples/charts/qmloscilloscope/qml/qmloscilloscope/ControlPanel.qml +++ b/examples/charts/qmloscilloscope/qml/qmloscilloscope/ControlPanel.qml @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick @@ -7,8 +7,7 @@ import QtQuick.Layouts ColumnLayout { property alias openGLButton: openGLButton property alias antialiasButton: antialiasButton - spacing: 8 - Layout.fillHeight: true + signal animationsEnabled(bool enabled) signal seriesTypeChanged(string type) signal refreshRateChanged(variant rate); @@ -16,6 +15,9 @@ ColumnLayout { signal antialiasingEnabled(bool enabled) signal openGlChanged(bool enabled) + spacing: 8 + Layout.fillHeight: true + Text { text: "Scope" font.pointSize: 18 diff --git a/examples/charts/qmloscilloscope/qml/qmloscilloscope/MultiButton.qml b/examples/charts/qmloscilloscope/qml/qmloscilloscope/MultiButton.qml index aa67ce92..aba8d10b 100644 --- a/examples/charts/qmloscilloscope/qml/qmloscilloscope/MultiButton.qml +++ b/examples/charts/qmloscilloscope/qml/qmloscilloscope/MultiButton.qml @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick @@ -9,8 +9,8 @@ Item { property string text: "Option: " property variant items: ["first"] property int currentSelection: 0 - signal selectionChanged(variant selection) + signal selectionChanged(variant selection) signal clicked implicitWidth: buttonText.implicitWidth + 5 diff --git a/examples/charts/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml b/examples/charts/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml index b7eee2bd..43d98f29 100644 --- a/examples/charts/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml +++ b/examples/charts/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick @@ -7,9 +7,12 @@ import QtCharts //![1] ChartView { id: chartView + + property bool openGL: openGLSupported + animationOptions: ChartView.NoAnimation theme: ChartView.ChartThemeDark - property bool openGL: openGLSupported + onOpenGLChanged: { if (openGLSupported) { var series1 = series("signal 1") diff --git a/examples/charts/qmloscilloscope/qml/qmloscilloscope/main.qml b/examples/charts/qmloscilloscope/qml/qmloscilloscope/main.qml index 7ff0d333..ce009037 100644 --- a/examples/charts/qmloscilloscope/qml/qmloscilloscope/main.qml +++ b/examples/charts/qmloscilloscope/qml/qmloscilloscope/main.qml @@ -1,4 +1,4 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick diff --git a/examples/charts/qmlpiechart/CMakeLists.txt b/examples/charts/qmlpiechart/CMakeLists.txt deleted file mode 100644 index d9aebafe..00000000 --- a/examples/charts/qmlpiechart/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlpiechart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlpiechart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlpiechart - main.cpp -) - -set_target_properties(qmlpiechart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlpiechart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlpiechart/main.qml" -) - -qt6_add_resources(qmlpiechart "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlpiechart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlpiechart/main.cpp b/examples/charts/qmlpiechart/main.cpp deleted file mode 100644 index 27fad14c..00000000 --- a/examples/charts/qmlpiechart/main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtQuick/QQuickView> -#include <QtCore/QDir> -#include <QtQml/QQmlEngine> - -int main(int argc, char *argv[]) -{ - // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. - QApplication 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("QML Pie Chart")); - viewer.setSource(QUrl("qrc:/qml/qmlpiechart/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/charts/qmlpiechart/qml/qmlpiechart/main.qml b/examples/charts/qmlpiechart/qml/qmlpiechart/main.qml deleted file mode 100644 index 9691f3a4..00000000 --- a/examples/charts/qmlpiechart/qml/qmlpiechart/main.qml +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -//![1] -import QtQuick 2.0 -import QtCharts 2.0 - -ChartView { - width: 400 - height: 300 - theme: ChartView.ChartThemeBrownSand - antialiasing: true - -//![1] -//![2] - PieSeries { - id: pieSeries - PieSlice { label: "eaten"; value: 94.9 } - PieSlice { label: "not yet eaten"; value: 5.1 } - } -//![2] - - Component.onCompleted: { - if (false) { - //![4] - pieSeries.append("don't care", 1.1); - //![4] - - //![5] - pieSeries.at(0).exploded = true; - //![5] - } - } - -//![3] -} -//![3] diff --git a/examples/charts/qmlpiechart/qmlpiechart.pro b/examples/charts/qmlpiechart/qmlpiechart.pro deleted file mode 100644 index 7f87bb1a..00000000 --- a/examples/charts/qmlpiechart/qmlpiechart.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts qml quick - -SOURCES += \ - main.cpp - -RESOURCES += \ - resources.qrc - -DISTFILES += \ - qml/qmlpiechart/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlpiechart -INSTALLS += target diff --git a/examples/charts/qmlpiechart/qmlpiechart.svg b/examples/charts/qmlpiechart/qmlpiechart.svg deleted file mode 100644 index 566acfad..00000000 --- a/examples/charts/qmlpiechart/qmlpiechart.svg +++ /dev/null @@ -1,93 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - height="44px" - version="1.1" - viewBox="0 0 44 44" - width="44px" - x="0px" - y="0px" - id="svg2" - inkscape:version="0.47 r22583" - sodipodi:docname="qt.svg"> - <metadata - id="metadata18"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs16"> - <inkscape:perspective - sodipodi:type="inkscape:persp3d" - inkscape:vp_x="0 : 22 : 1" - inkscape:vp_y="0 : 1000 : 0" - inkscape:vp_z="44 : 22 : 1" - inkscape:persp3d-origin="22 : 14.666667 : 1" - id="perspective2836" /> - </defs> - <sodipodi:namedview - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1" - objecttolerance="10" - gridtolerance="10" - guidetolerance="10" - inkscape:pageopacity="0" - inkscape:pageshadow="2" - inkscape:window-width="1920" - inkscape:window-height="1020" - id="namedview14" - showgrid="false" - inkscape:zoom="21.454545" - inkscape:cx="49.412871" - inkscape:cy="21.894358" - inkscape:window-x="-4" - inkscape:window-y="-4" - inkscape:window-maximized="1" - inkscape:current-layer="g3" /> - <g - transform="matrix(0.18308778,0,0,0.18308778,6.6100946,3.2385199)" - id="g3"> - <path - d="M 43.09,0.3586 C 40.94,0.0036 38.84,-0.0824 36.81,0.0776 31.968136,0.39505671 27.122677,0.73638425 22.28,1.0696 9.62,2.0816 0,12.4996 0,26.8896 l 0,169.7 14.19,13.2 28.87,-209.42 0.03,-0.011 z" - style="fill:#006225" - id="path5" - sodipodi:nodetypes="cccccccc" /> - <path - d="m 174.4,160 c 0,12.5 -7.75,24.07 -17.57,25.77 L 14.23,209.73 V 25.93 C 14.23,9.21 27.57,-2.27 43.12,0.3 l 131.3,21.52 v 138.2 z" - style="fill:#80c342" - id="path7" /> - <path - d="m 154.9,80.96 -12.96,-0.598 0,0.278 6.945,0.32 6.016,0 z" - style="fill:#006225" - id="path11" /> - <path - d="m 144.6,135.6 c 0.66,0.328 1.43,0.476 2.351,0.476 0.161,0 0.329,-0.004 0.497,-0.016 2.55,-0.148 5.32,-0.933 8.343,-2.308 h -6.015 c -1.821,0.832 -3.532,1.457 -5.176,1.848 z" - style="fill:#006225" - id="path13" /> - <path - id="path17" - style="fill:#ffffff" - d="m 91.15,132.4 c 2.351,-6.051 3.511,-17.91 3.511,-35.62 0,-15.89 -1.148,-26.82 -3.484,-32.81 -2.336,-6.027 -5.832,-9.281 -10.52,-9.691 -0.359,-0.031 -0.714,-0.051 -1.058,-0.051 -4.34,0 -7.68,2.535 -10.01,7.625 -2.52,5.543 -3.793,17.04 -3.793,34.44 0,16.82 1.238,28.75 3.734,35.75 2.356,6.672 5.879,9.976 10.5,9.976 0.207,0 0.41,-0.008 0.621,-0.019 4.633,-0.293 8.121,-3.496 10.49,-9.602 m 17.98,3.75 c -4.117,9.707 -10.39,16.06 -18.99,19 0.867,4.449 2.176,7.441 3.922,9.019 1.351,1.211 3.433,1.821 6.222,1.821 0.805,0 1.668,-0.055 2.59,-0.157 v 13.12 l -5.961,0.782 c -1.758,0.23 -3.426,0.343 -5.004,0.343 -5.218,0 -9.445,-1.265 -12.62,-3.824 -4.207,-3.379 -7.308,-9.894 -9.297,-19.54 -9.136,-1.945 -16.26,-7.754 -21.19,-17.5 -5.004,-9.902 -7.551,-24.39 -7.551,-43.34 0,-20.43 3.484,-35.51 10.34,-45.07 5.789,-8.07 13.86,-12.04 24.02,-12.04 1.629,0 3.309,0.102 5.043,0.305 11.95,1.375 20.62,7.016 26.26,16.79 5.535,9.562 8.254,23.27 8.254,41.26 0,16.48 -2,29.45 -6.043,39.02 z M 130.4,45.91 l 11.52,1.238 0,20.21 12.96,0.914 0,12.68 -12.96,-0.598 0,46.33 c 0,4.032 0.445,6.625 1.34,7.789 0.8,1.067 2.046,1.594 3.71,1.594 0.161,0 0.329,-0.004 0.497,-0.016 2.55,-0.148 5.32,-0.933 8.343,-2.308 v 11.65 c -5.136,2.258 -10.18,3.598 -15.12,4.02 -0.718,0.055 -1.41,0.086 -2.078,0.086 -4.48,0 -7.906,-1.301 -10.25,-3.934 -2.73,-3.051 -4.09,-7.949 -4.09,-14.67 V 79.535 L 118.046,79.25 V 65.66 l 7.586,0.547 4.773,-20.3 z" /> - <path - d="m 100.3,166 c 0.809,0 1.672,-0.055 2.59,-0.157 H 98.054 C 98.73,165.949 99.507,166 100.3,166 z" - style="fill:#006225" - id="path19" /> - <path - id="path21" - style="fill:#006225" - d="m 84.85,63.98 c 2.336,5.997 3.484,16.92 3.484,32.81 0,17.7 -1.16,29.57 -3.512,35.62 -1.894,4.879 -4.527,7.902 -7.863,9.07 0.965,0.368 1.992,0.551 3.078,0.551 0.207,0 0.41,-0.008 0.621,-0.019 4.633,-0.293 8.121,-3.496 10.49,-9.602 2.351,-6.051 3.511,-17.91 3.511,-35.62 0,-15.89 -1.148,-26.82 -3.484,-32.81 -2.336,-6.027 -5.832,-9.281 -10.52,-9.691 -0.359,-0.031 -0.714,-0.051 -1.058,-0.051 -1.09,0 -2.117,0.16 -3.082,0.481 h -0.004 c 3.601,1.121 6.379,4.215 8.336,9.261 z m -2.344,114.3 c -0.113,-0.05 -0.227,-0.105 -0.336,-0.16 -0.012,-0.004 -0.023,-0.012 -0.035,-0.015 -0.102,-0.051 -0.207,-0.106 -0.309,-0.157 -0.019,-0.011 -0.039,-0.019 -0.058,-0.031 -0.09,-0.051 -0.184,-0.098 -0.278,-0.148 -0.027,-0.016 -0.054,-0.036 -0.086,-0.051 -0.082,-0.043 -0.164,-0.09 -0.242,-0.137 -0.039,-0.023 -0.078,-0.047 -0.113,-0.07 -0.07,-0.039 -0.145,-0.082 -0.215,-0.125 -0.047,-0.031 -0.094,-0.059 -0.14,-0.09 -0.059,-0.039 -0.118,-0.074 -0.176,-0.113 -0.059,-0.039 -0.114,-0.075 -0.168,-0.114 -0.051,-0.031 -0.102,-0.066 -0.149,-0.097 -0.066,-0.047 -0.132,-0.094 -0.195,-0.137 -0.039,-0.027 -0.078,-0.055 -0.113,-0.082 -0.078,-0.055 -0.153,-0.113 -0.231,-0.172 -0.023,-0.016 -0.05,-0.035 -0.078,-0.055 -0.098,-0.078 -0.199,-0.156 -0.297,-0.234 -4.207,-3.379 -7.308,-9.894 -9.297,-19.54 -9.136,-1.945 -16.26,-7.754 -21.19,-17.5 -5.004,-9.902 -7.551,-24.39 -7.551,-43.34 0,-20.43 3.484,-35.51 10.34,-45.07 5.789,-8.07 13.86,-12.04 24.02,-12.04 h -6.351 c -10.15,0.008 -18.22,3.977 -24,12.04 -6.855,9.563 -10.34,24.64 -10.34,45.07 0,18.95 2.547,33.44 7.551,43.34 4.934,9.75 12.05,15.56 21.19,17.5 1.989,9.641 5.09,16.16 9.297,19.54 3.176,2.559 7.403,3.824 12.62,3.824 0.098,0 0.199,0 0.297,-0.004 h 5.539 c -3.406,-0.05 -6.383,-0.66 -8.906,-1.828 L 82.498,178.28 z M 128.4,145.6 c -2.73,-3.051 -4.09,-7.949 -4.09,-14.67 V 79.57 l -6.226,-0.285 v -13.59 h -6.016 v 3.035 c 0.871,3.273 1.555,6.82 2.063,10.64 l 4.164,0.192 v 51.36 c 0,6.723 1.367,11.62 4.09,14.67 2.343,2.633 5.765,3.934 10.25,3.934 h 6.015 c -4.48,0 -7.906,-1.301 -10.25,-3.934 z m 2.043,-99.66 -6.016,0 -4.668,19.88 5.911,0.422 4.773,-20.3 z" /> - </g> -</svg> diff --git a/examples/charts/qmlpiechart/resources.qrc b/examples/charts/qmlpiechart/resources.qrc deleted file mode 100644 index 2501bcc8..00000000 --- a/examples/charts/qmlpiechart/resources.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlpiechart/main.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlpolarchart/CMakeLists.txt b/examples/charts/qmlpolarchart/CMakeLists.txt deleted file mode 100644 index 80866e66..00000000 --- a/examples/charts/qmlpolarchart/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(qmlpolarchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlpolarchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) - -qt_add_executable(qmlpolarchart - main.cpp -) - -set_target_properties(qmlpolarchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(qmlpolarchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -# Resources: -set(resources_resource_files - "qml/qmlpolarchart/View1.qml" - "qml/qmlpolarchart/View2.qml" - "qml/qmlpolarchart/View3.qml" - "qml/qmlpolarchart/main.qml" -) - -qt6_add_resources(qmlpolarchart "resources" - PREFIX - "/" - FILES - ${resources_resource_files} -) - -install(TARGETS qmlpolarchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/qmlpolarchart/main.cpp b/examples/charts/qmlpolarchart/main.cpp deleted file mode 100644 index c990c44e..00000000 --- a/examples/charts/qmlpolarchart/main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtQuick/QQuickView> -#include <QtCore/QDir> -#include <QtQml/QQmlEngine> - -int main(int argc, char *argv[]) -{ - // Qt Charts uses Qt Graphics View Framework for drawing, therefore QApplication must be used. - QApplication 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("QML Polar Chart")); - viewer.setSource(QUrl("qrc:/qml/qmlpolarchart/main.qml")); - viewer.setResizeMode(QQuickView::SizeRootObjectToView); - viewer.show(); - - return app.exec(); -} diff --git a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View1.qml b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View1.qml deleted file mode 100644 index e4fc3c47..00000000 --- a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View1.qml +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - //![1] - PolarChartView { - title: "Two Series, Common Axes" - anchors.fill: parent - legend.visible: false - antialiasing: true - - ValueAxis { - id: axisAngular - min: 0 - max: 20 - tickCount: 9 - } - - ValueAxis { - id: axisRadial - min: -0.5 - max: 1.5 - } - - SplineSeries { - id: series1 - axisAngular: axisAngular - axisRadial: axisRadial - pointsVisible: true - } - - ScatterSeries { - id: series2 - axisAngular: axisAngular - axisRadial: axisRadial - markerSize: 10 - } - } - - // Add data dynamically to the series - Component.onCompleted: { - for (var i = 0; i <= 20; i++) { - series1.append(i, Math.random()); - series2.append(i, Math.random()); - } - } - //![1] -} diff --git a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View2.qml b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View2.qml deleted file mode 100644 index 1b1e1f0f..00000000 --- a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View2.qml +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - PolarChartView { - title: "Historical Area Series" - anchors.fill: parent - legend.visible: false - antialiasing: true - - DateTimeAxis { - id: axis1 - format: "yyyy MMM" - tickCount: 13 - } - ValueAxis { - id: axis2 - } - LineSeries { - id: lowerLine - axisAngular: axis1 - axisRadial: axis2 - - // Please note that month in JavaScript months are zero based, so 2 means March - XYPoint { x: toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 15 } - XYPoint { x: toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 35 } - XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 } - XYPoint { x: toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 75 } - XYPoint { x: toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 102 } - XYPoint { x: toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 132 } - XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 } - XYPoint { x: toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 120 } - XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 140 } - XYPoint { x: toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 150 } - } - LineSeries { - id: upperLine - axisAngular: axis1 - axisRadial: axis2 - - // Please note that month in JavaScript months are zero based, so 2 means March - XYPoint { x: toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 30 } - XYPoint { x: toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 55 } - XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 80 } - XYPoint { x: toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 105 } - XYPoint { x: toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 125 } - XYPoint { x: toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 160 } - XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 140 } - XYPoint { x: toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 140 } - XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 170 } - XYPoint { x: toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 200 } - } - AreaSeries { - axisAngular: axis1 - axisRadial: axis2 - lowerSeries: lowerLine - upperSeries: upperLine - } - } - // DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to - // milliseconds since epoch to make them match the DateTimeAxis values - function toMsecsSinceEpoch(date) { - var msecs = date.getTime(); - return msecs; - } - //![1] -} diff --git a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View3.qml b/examples/charts/qmlpolarchart/qml/qmlpolarchart/View3.qml deleted file mode 100644 index ee53fc7c..00000000 --- a/examples/charts/qmlpolarchart/qml/qmlpolarchart/View3.qml +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 -import QtCharts 2.0 - -Item { - anchors.fill: parent - - //![1] - PolarChartView { - title: "Numerical Data for Dummies" - anchors.fill: parent - legend.visible: false - antialiasing: true - - LineSeries { - axisRadial: CategoryAxis { - min: 0 - max: 30 - CategoryRange { - label: "critical" - endValue: 2 - } - CategoryRange { - label: "low" - endValue: 7 - } - CategoryRange { - label: "normal" - endValue: 12 - } - CategoryRange { - label: "high" - endValue: 18 - } - CategoryRange { - label: "extremely high" - endValue: 30 - } - } - - axisAngular: ValueAxis { - tickCount: 13 - } - - XYPoint { x: 0; y: 4.3 } - XYPoint { x: 1; y: 4.1 } - XYPoint { x: 2; y: 4.7 } - XYPoint { x: 3; y: 3.9 } - XYPoint { x: 4; y: 5.2 } - XYPoint { x: 5; y: 5.3 } - XYPoint { x: 6; y: 6.1 } - XYPoint { x: 7; y: 7.7 } - XYPoint { x: 8; y: 12.9 } - XYPoint { x: 9; y: 19.2 } - } - } - //![1] -} diff --git a/examples/charts/qmlpolarchart/qml/qmlpolarchart/main.qml b/examples/charts/qmlpolarchart/qml/qmlpolarchart/main.qml deleted file mode 100644 index b03e3b2a..00000000 --- a/examples/charts/qmlpolarchart/qml/qmlpolarchart/main.qml +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -import QtQuick 2.0 - -Item { - width: 800 - height: 600 - property bool sourceLoaded: false - - ListView { - id: root - focus: true - anchors.fill: parent - snapMode: ListView.SnapOneItem - highlightRangeMode: ListView.StrictlyEnforceRange - highlightMoveDuration: 250 - orientation: ListView.Horizontal - boundsBehavior: Flickable.StopAtBounds - - onCurrentIndexChanged: { - if (infoText.opacity > 0.0) { - if (sourceLoaded) - infoText.opacity = 0.0; - else if (currentIndex != 0) - currentIndex = 0; - } - } - - model: ListModel { - ListElement {component: "View1.qml"} - ListElement {component: "View2.qml"} - ListElement {component: "View3.qml"} - } - - delegate: Loader { - width: root.width - height: root.height - - source: component - asynchronous: true - - onLoaded: sourceLoaded = true - } - } - - Rectangle { - id: infoText - anchors.centerIn: parent - width: parent.width - height: 40 - color: "black" - Text { - color: "white" - anchors.centerIn: parent - text: "You can navigate between views using swipe or arrow keys" - } - - Behavior on opacity { - NumberAnimation { duration: 400 } - } - } -} diff --git a/examples/charts/qmlpolarchart/qmlpolarchart.pro b/examples/charts/qmlpolarchart/qmlpolarchart.pro deleted file mode 100644 index 340fbf86..00000000 --- a/examples/charts/qmlpolarchart/qmlpolarchart.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts qml quick - -SOURCES += \ - main.cpp - -RESOURCES += \ - resources.qrc - -DISTFILES += \ - qml/qmlpolarchart/* - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/qmlpolarchart -INSTALLS += target diff --git a/examples/charts/qmlpolarchart/resources.qrc b/examples/charts/qmlpolarchart/resources.qrc deleted file mode 100644 index a4a975ed..00000000 --- a/examples/charts/qmlpolarchart/resources.qrc +++ /dev/null @@ -1,8 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/qmlpolarchart/main.qml</file> - <file>qml/qmlpolarchart/View1.qml</file> - <file>qml/qmlpolarchart/View2.qml</file> - <file>qml/qmlpolarchart/View3.qml</file> - </qresource> -</RCC> diff --git a/examples/charts/qmlweather/CMakeLists.txt b/examples/charts/qmlweather/CMakeLists.txt index d503b0a9..ce17072f 100644 --- a/examples/charts/qmlweather/CMakeLists.txt +++ b/examples/charts/qmlweather/CMakeLists.txt @@ -4,8 +4,6 @@ cmake_minimum_required(VERSION 3.16) project(qmlweather LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/qmlweather") find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick) +qt_standard_project_setup() + qt_add_executable(qmlweather main.cpp ) diff --git a/examples/charts/qmlweather/qml/qmlweather/main.qml b/examples/charts/qmlweather/qml/qmlweather/main.qml index 86690064..9b3a03db 100644 --- a/examples/charts/qmlweather/qml/qmlweather/main.qml +++ b/examples/charts/qmlweather/qml/qmlweather/main.qml @@ -1,8 +1,8 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -import QtQuick 2.0 -import QtCharts 2.0 +import QtQuick +import QtCharts Rectangle { width: 500 diff --git a/examples/charts/scatterchart/CMakeLists.txt b/examples/charts/scatterchart/CMakeLists.txt deleted file mode 100644 index 70e2c5bf..00000000 --- a/examples/charts/scatterchart/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(scatterchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/scatterchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(scatterchart - chartview.cpp chartview.h - main.cpp -) - -set_target_properties(scatterchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(scatterchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS scatterchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/scatterchart/chartview.h b/examples/charts/scatterchart/chartview.h deleted file mode 100644 index 5b5533f8..00000000 --- a/examples/charts/scatterchart/chartview.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef CHARTVIEW_H -#define CHARTVIEW_H - -#include <QtCharts/QChartView> - -QT_USE_NAMESPACE - -class ChartView : public QChartView -{ - Q_OBJECT -public: - explicit ChartView(QWidget *parent = 0); -}; - -#endif // CHARTVIEW_H diff --git a/examples/charts/scatterchart/main.cpp b/examples/charts/scatterchart/main.cpp deleted file mode 100644 index 6ff93771..00000000 --- a/examples/charts/scatterchart/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include "chartview.h" - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![4] - ChartView *chartView = new ChartView(); - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); -//![4] - - return a.exec(); -} diff --git a/examples/charts/scatterchart/scatterchart.pro b/examples/charts/scatterchart/scatterchart.pro deleted file mode 100644 index fdb468d6..00000000 --- a/examples/charts/scatterchart/scatterchart.pro +++ /dev/null @@ -1,11 +0,0 @@ -QT += charts - -HEADERS += \ - chartview.h - -SOURCES += \ - chartview.cpp \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/scatterchart -INSTALLS += target diff --git a/examples/charts/scatterinteractions/CMakeLists.txt b/examples/charts/scatterinteractions/CMakeLists.txt deleted file mode 100644 index e6a94dee..00000000 --- a/examples/charts/scatterinteractions/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(scatterinteractions LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/scatterinteractions") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(scatterinteractions - chartview.cpp chartview.h - main.cpp -) - -set_target_properties(scatterinteractions PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(scatterinteractions PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS scatterinteractions - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/scatterinteractions/chartview.h b/examples/charts/scatterinteractions/chartview.h deleted file mode 100644 index f7c117d9..00000000 --- a/examples/charts/scatterinteractions/chartview.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef CHARTVIEW_H -#define CHARTVIEW_H - -#include <QtCharts/QChartGlobal> -#include <QtCharts/QChartView> -#include <QtCharts/QScatterSeries> - -QT_USE_NAMESPACE - -class ChartView : public QChartView -{ - Q_OBJECT - -public: - ChartView(QWidget *parent = 0); - ~ChartView(); - -private Q_SLOTS: - void handleClickedPoint(const QPointF &point); - -private: - QScatterSeries *m_scatter; - QScatterSeries *m_scatter2; -}; - -#endif // CHARTVIEW_H diff --git a/examples/charts/scatterinteractions/main.cpp b/examples/charts/scatterinteractions/main.cpp deleted file mode 100644 index 10ed1590..00000000 --- a/examples/charts/scatterinteractions/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include "chartview.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - QMainWindow window; - ChartView chartView(&window); - window.setCentralWidget(&chartView); - window.resize(400, 300); - window.show(); - - return a.exec(); -} diff --git a/examples/charts/scatterinteractions/scatterinteractions.pro b/examples/charts/scatterinteractions/scatterinteractions.pro deleted file mode 100644 index e069df7f..00000000 --- a/examples/charts/scatterinteractions/scatterinteractions.pro +++ /dev/null @@ -1,11 +0,0 @@ -QT += charts - -HEADERS += \ - chartview.h - -SOURCES += \ - chartview.cpp \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/scatterinteractions -INSTALLS += target diff --git a/examples/charts/selectedbar/CMakeLists.txt b/examples/charts/selectedbar/CMakeLists.txt deleted file mode 100644 index 3765baaa..00000000 --- a/examples/charts/selectedbar/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(selectedbar LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/selectedbar") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(selectedbar - utilities.h utilities.cpp - main.cpp -) - -set_target_properties(selectedbar PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(selectedbar PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS selectedbar - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/selectedbar/selectedbar.pro b/examples/charts/selectedbar/selectedbar.pro deleted file mode 100644 index 24d0de08..00000000 --- a/examples/charts/selectedbar/selectedbar.pro +++ /dev/null @@ -1,11 +0,0 @@ -QT += charts widgets - -SOURCES += \ - main.cpp \ - utilities.cpp - -HEADERS += \ - utilities.h - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/selectedbar -INSTALLS += target diff --git a/examples/charts/selectedbar/utilities.cpp b/examples/charts/selectedbar/utilities.cpp deleted file mode 100644 index c58301ac..00000000 --- a/examples/charts/selectedbar/utilities.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "utilities.h" -#include <QCoreApplication> - -namespace Utilities -{ - -QBarSet *createChickenSet() -{ - QBarSet *set = new QBarSet(QCoreApplication::tr("Chicken")); - set->append({15.0, 12.0, 8.0, 11.5, 13.7}); - return set; -} - -QBarSet *createPorkSet() -{ - QBarSet *set = new QBarSet(QCoreApplication::tr("Pork")); - set->append({9.0, 11.0, 9.0, 7, 12.2}); - return set; -} - -QBarSet *createTurkeySet() -{ - QBarSet *set = new QBarSet(QCoreApplication::tr("Turkey")); - set->append({5.0, 7.6, 9.3, 8, 8.1}); - return set; -} - -QBarSet *createHamSet() -{ - QBarSet *set = new QBarSet(QCoreApplication::tr("Ham")); - set->append({5.4, 7.1, 9.3, 12.3, 11.3}); - return set; -} - -QStringList createYearCategories() -{ - return QStringList{QCoreApplication::tr("2017"), - QCoreApplication::tr("2018"), - QCoreApplication::tr("2019"), - QCoreApplication::tr("2020"), - QCoreApplication::tr("2021")}; -} - -} diff --git a/examples/charts/selectedbar/utilities.h b/examples/charts/selectedbar/utilities.h deleted file mode 100644 index e928dd8b..00000000 --- a/examples/charts/selectedbar/utilities.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef UTILITIES_H -#define UTILITIES_H - -#include <QList> -#include <QBarSet> - -namespace Utilities -{ - QBarSet *createChickenSet(); - QBarSet *createPorkSet(); - QBarSet *createTurkeySet(); - QBarSet *createHamSet(); - QStringList createYearCategories(); - qreal totalSum(const QList<QBarSet *> &setList); -} - -#endif // UTILITIES_H diff --git a/examples/charts/splinechart/CMakeLists.txt b/examples/charts/splinechart/CMakeLists.txt deleted file mode 100644 index 0b5d68fe..00000000 --- a/examples/charts/splinechart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(splinechart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/splinechart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(splinechart - main.cpp -) - -set_target_properties(splinechart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(splinechart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS splinechart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/splinechart/main.cpp b/examples/charts/splinechart/main.cpp deleted file mode 100644 index 491b1f0e..00000000 --- a/examples/charts/splinechart/main.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QSplineSeries> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - //![1] - QSplineSeries *series = new QSplineSeries(); - series->setName("spline"); - //![1] - - //![2] - series->append(0, 6); - series->append(2, 4); - series->append(3, 8); - series->append(7, 4); - series->append(10, 5); - *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); - //![2] - - //![3] - QChart *chart = new QChart(); - chart->legend()->hide(); - chart->addSeries(series); - chart->setTitle("Simple spline chart example"); - chart->createDefaultAxes(); - chart->axes(Qt::Vertical).first()->setRange(0, 10); - //![3] - - //![4] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); - //![4] - - //![5] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(400, 300); - window.show(); - //![5] - - return a.exec(); -} diff --git a/examples/charts/splinechart/splinechart.pro b/examples/charts/splinechart/splinechart.pro deleted file mode 100644 index e71b7780..00000000 --- a/examples/charts/splinechart/splinechart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/splinechart -INSTALLS += target diff --git a/examples/charts/stackedbarchart/CMakeLists.txt b/examples/charts/stackedbarchart/CMakeLists.txt deleted file mode 100644 index d5f2047b..00000000 --- a/examples/charts/stackedbarchart/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(stackedbarchart LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/stackedbarchart") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(stackedbarchart - main.cpp -) - -set_target_properties(stackedbarchart PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(stackedbarchart PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS stackedbarchart - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/stackedbarchart/main.cpp b/examples/charts/stackedbarchart/main.cpp deleted file mode 100644 index 875290fa..00000000 --- a/examples/charts/stackedbarchart/main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QStackedBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QValueAxis> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QBarSet *set0 = new QBarSet("Jane"); - QBarSet *set1 = new QBarSet("John"); - QBarSet *set2 = new QBarSet("Axel"); - QBarSet *set3 = new QBarSet("Mary"); - QBarSet *set4 = new QBarSet("Samantha"); - - *set0 << 1 << 2 << 3 << 4 << 5 << 6; - *set1 << 5 << 0 << 0 << 4 << 0 << 7; - *set2 << 3 << 5 << 8 << 13 << 8 << 5; - *set3 << 5 << 6 << 7 << 3 << 4 << 5; - *set4 << 9 << 7 << 5 << 3 << 1 << 2; -//![1] - -//![2] - QStackedBarSeries *series = new QStackedBarSeries(); - series->append(set0); - series->append(set1); - series->append(set2); - series->append(set3); - series->append(set4); -//![2] - -//![3] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->setTitle("Simple stackedbarchart example"); - chart->setAnimationOptions(QChart::SeriesAnimations); -//![3] - -//![4] - QStringList categories; - categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; - QBarCategoryAxis *axisX = new QBarCategoryAxis(); - axisX->append(categories); - chart->addAxis(axisX, Qt::AlignBottom); - series->attachAxis(axisX); - QValueAxis *axisY = new QValueAxis(); - chart->addAxis(axisY, Qt::AlignLeft); - series->attachAxis(axisY); -//![4] - -//![5] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); -//![5] - -//![6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![6] - -//![7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(420, 300); - window.show(); -//![7] - - return a.exec(); -} - diff --git a/examples/charts/stackedbarchart/stackedbarchart.pro b/examples/charts/stackedbarchart/stackedbarchart.pro deleted file mode 100644 index 1034c61d..00000000 --- a/examples/charts/stackedbarchart/stackedbarchart.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/stackedbarchart -INSTALLS += target diff --git a/examples/charts/stackedbarchartdrilldown/CMakeLists.txt b/examples/charts/stackedbarchartdrilldown/CMakeLists.txt deleted file mode 100644 index f1404ee1..00000000 --- a/examples/charts/stackedbarchartdrilldown/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(stackedbarchartdrilldown LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/stackedbarchartdrilldown") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(stackedbarchartdrilldown - drilldownchart.cpp drilldownchart.h - drilldownseries.cpp drilldownseries.h - main.cpp -) - -set_target_properties(stackedbarchartdrilldown PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(stackedbarchartdrilldown PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS stackedbarchartdrilldown - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp b/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp deleted file mode 100644 index 81f90d34..00000000 --- a/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "drilldownchart.h" -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QValueAxis> - -QT_USE_NAMESPACE - -DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) - : QChart(QChart::ChartTypeCartesian, parent, wFlags), - m_currentSeries(0), - m_axisX(new QBarCategoryAxis()), - m_axisY(new QValueAxis()) -{ - addAxis(m_axisY, Qt::AlignLeft); - addAxis(m_axisX, Qt::AlignBottom); -} - -void DrilldownChart::changeSeries(DrilldownBarSeries *series) -{ - if (m_currentSeries) - removeSeries(m_currentSeries); - - m_currentSeries = series; - - // Reset axis - m_axisX->setCategories(m_currentSeries->categories()); - addSeries(series); - series->attachAxis(m_axisX); - series->attachAxis(m_axisY); - m_axisY->setRange(0,m_currentSeries->maxValue()); - setTitle(series->name()); -} - -void DrilldownChart::handleClicked(int index, QBarSet *barset) -{ - Q_UNUSED(barset); - DrilldownBarSeries *series = static_cast<DrilldownBarSeries *>(sender()); - changeSeries(series->drilldownSeries(index)); -} - -#include "moc_drilldownchart.cpp" diff --git a/examples/charts/stackedbarchartdrilldown/drilldownchart.h b/examples/charts/stackedbarchartdrilldown/drilldownchart.h deleted file mode 100644 index 88e59a99..00000000 --- a/examples/charts/stackedbarchartdrilldown/drilldownchart.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef DRILLDOWNCHART_H -#define DRILLDOWNCHART_H - -#include <QtCharts/QChart> -#include "drilldownseries.h" - -QT_BEGIN_NAMESPACE -class QBarCategoryAxis; -class QValueAxis; -QT_END_NAMESPACE - -QT_USE_NAMESPACE - -//! [1] -class DrilldownChart : public QChart -{ - Q_OBJECT -public: - explicit DrilldownChart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {}); - - void changeSeries(DrilldownBarSeries *series); - -public Q_SLOTS: - void handleClicked(int index, QBarSet *barset); - -private: - DrilldownBarSeries *m_currentSeries; - QBarCategoryAxis *m_axisX; - QValueAxis *m_axisY; -}; -//! [1] - -#endif // DRILLDOWNCHART_H diff --git a/examples/charts/stackedbarchartdrilldown/drilldownseries.cpp b/examples/charts/stackedbarchartdrilldown/drilldownseries.cpp deleted file mode 100644 index d6012354..00000000 --- a/examples/charts/stackedbarchartdrilldown/drilldownseries.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include "drilldownseries.h" - -QT_USE_NAMESPACE - -DrilldownBarSeries::DrilldownBarSeries(QStringList categories, int maxValue, QObject *parent) - : QStackedBarSeries(parent), - m_maxValue(maxValue) -{ - m_categories = categories; -} - -void DrilldownBarSeries::mapDrilldownSeries(int index, DrilldownBarSeries *drilldownSeries) -{ - m_DrilldownSeries[index] = drilldownSeries; -} - -DrilldownBarSeries *DrilldownBarSeries::drilldownSeries(int index) -{ - return m_DrilldownSeries[index]; -} - -QStringList DrilldownBarSeries::categories() -{ - return m_categories; -} - -int DrilldownBarSeries::maxValue() -{ - return m_maxValue; -} - -#include "moc_drilldownseries.cpp" diff --git a/examples/charts/stackedbarchartdrilldown/drilldownseries.h b/examples/charts/stackedbarchartdrilldown/drilldownseries.h deleted file mode 100644 index 08ecc4dd..00000000 --- a/examples/charts/stackedbarchartdrilldown/drilldownseries.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#ifndef DRILLDOWNSERIES_H -#define DRILLDOWNSERIES_H - -#include <QtCharts/QStackedBarSeries> -#include <QtCore/QMap> - -QT_USE_NAMESPACE - -//! [1] -class DrilldownBarSeries : public QStackedBarSeries -{ - Q_OBJECT -public: - DrilldownBarSeries(QStringList categories, int maxValue, QObject *parent = 0); - - void mapDrilldownSeries(int index, DrilldownBarSeries *drilldownSeries); - - DrilldownBarSeries *drilldownSeries(int index); - - QStringList categories(); - - int maxValue(); - -private: - QMap<int, DrilldownBarSeries *> m_DrilldownSeries; - QStringList m_categories; - int m_maxValue; -}; -//! [1] - -#endif // DRILLDOWNSERIES_H diff --git a/examples/charts/stackedbarchartdrilldown/stackedbarchartdrilldown.pro b/examples/charts/stackedbarchartdrilldown/stackedbarchartdrilldown.pro deleted file mode 100644 index 7cd09466..00000000 --- a/examples/charts/stackedbarchartdrilldown/stackedbarchartdrilldown.pro +++ /dev/null @@ -1,13 +0,0 @@ -QT += charts - -HEADERS += \ - drilldownchart.h \ - drilldownseries.h - -SOURCES += \ - drilldownchart.cpp \ - drilldownseries.cpp \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/stackedbarchartdrilldown -INSTALLS += target diff --git a/examples/charts/temperaturerecords/CMakeLists.txt b/examples/charts/temperaturerecords/CMakeLists.txt deleted file mode 100644 index 5085ce9f..00000000 --- a/examples/charts/temperaturerecords/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(temperaturerecords LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/temperaturerecords") - -find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) - -qt_add_executable(temperaturerecords - main.cpp -) - -set_target_properties(temperaturerecords PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(temperaturerecords PUBLIC - Qt::Charts - Qt::Core - Qt::Gui -) - -install(TARGETS temperaturerecords - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/charts/temperaturerecords/main.cpp b/examples/charts/temperaturerecords/main.cpp deleted file mode 100644 index 24564db9..00000000 --- a/examples/charts/temperaturerecords/main.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only - -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCharts/QChartView> -#include <QtCharts/QBarSeries> -#include <QtCharts/QBarSet> -#include <QtCharts/QLegend> -#include <QtCharts/QBarCategoryAxis> -#include <QtCharts/QStackedBarSeries> -#include <QtCharts/QValueAxis> - -QT_USE_NAMESPACE - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - -//![1] - QBarSet *low = new QBarSet("Min"); - QBarSet *high = new QBarSet("Max"); - - *low << -52 << -50 << -45.3 << -37.0 << -25.6 << -8.0 - << -6.0 << -11.8 << -19.7 << -32.8 << -43.0 << -48.0; - *high << 11.9 << 12.8 << 18.5 << 26.5 << 32.0 << 34.8 - << 38.2 << 34.8 << 29.8 << 20.4 << 15.1 << 11.8; -//![1] - -//![2] - QStackedBarSeries *series = new QStackedBarSeries(); - series->append(low); - series->append(high); -//![2] - -//![3] - QChart *chart = new QChart(); - chart->addSeries(series); - chart->setTitle("Temperature records in celcius"); - chart->setAnimationOptions(QChart::SeriesAnimations); -//![3] - -//![4] - QStringList categories = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; - - QBarCategoryAxis *axisX = new QBarCategoryAxis(); - axisX->append(categories); - axisX->setTitleText("Month"); - chart->addAxis(axisX, Qt::AlignBottom); - QValueAxis *axisY = new QValueAxis(); - axisY->setRange(-52, 52); - axisY->setTitleText("Temperature [°C]"); - chart->addAxis(axisY, Qt::AlignLeft); - series->attachAxis(axisX); - series->attachAxis(axisY); -//![4] - -//![5] - chart->legend()->setVisible(true); - chart->legend()->setAlignment(Qt::AlignBottom); -//![5] - -//![6] - QChartView *chartView = new QChartView(chart); - chartView->setRenderHint(QPainter::Antialiasing); -//![6] - -//![7] - QMainWindow window; - window.setCentralWidget(chartView); - window.resize(600, 300); - window.show(); -//![7] - - return a.exec(); -} diff --git a/examples/charts/temperaturerecords/temperaturerecords.pro b/examples/charts/temperaturerecords/temperaturerecords.pro deleted file mode 100644 index b8f34907..00000000 --- a/examples/charts/temperaturerecords/temperaturerecords.pro +++ /dev/null @@ -1,7 +0,0 @@ -QT += charts - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/charts/temperaturerecords -INSTALLS += target diff --git a/examples/charts/zoomlinechart/CMakeLists.txt b/examples/charts/zoomlinechart/CMakeLists.txt index ed42e109..d2b8ef11 100644 --- a/examples/charts/zoomlinechart/CMakeLists.txt +++ b/examples/charts/zoomlinechart/CMakeLists.txt @@ -4,8 +4,6 @@ cmake_minimum_required(VERSION 3.16) project(zoomlinechart LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() @@ -14,6 +12,8 @@ set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/zoomlinechart") find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui) +qt_standard_project_setup() + qt_add_executable(zoomlinechart chart.cpp chart.h chartview.cpp chartview.h diff --git a/examples/charts/zoomlinechart/chart.cpp b/examples/charts/zoomlinechart/chart.cpp index 773443a3..50fa7cd4 100644 --- a/examples/charts/zoomlinechart/chart.cpp +++ b/examples/charts/zoomlinechart/chart.cpp @@ -1,10 +1,11 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "chart.h" -#include <QtWidgets/QGesture> -#include <QtWidgets/QGraphicsScene> -#include <QtWidgets/QGraphicsView> + +#include <QGesture> +#include <QGraphicsScene> +#include <QGraphicsView> Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QChart(QChart::ChartTypeCartesian, parent, wFlags) @@ -15,11 +16,6 @@ Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) grabGesture(Qt::PinchGesture); } -Chart::~Chart() -{ - -} - //![1] bool Chart::sceneEvent(QEvent *event) { @@ -31,12 +27,12 @@ bool Chart::sceneEvent(QEvent *event) bool Chart::gestureEvent(QGestureEvent *event) { if (QGesture *gesture = event->gesture(Qt::PanGesture)) { - QPanGesture *pan = static_cast<QPanGesture *>(gesture); + auto pan = static_cast<QPanGesture *>(gesture); QChart::scroll(-(pan->delta().x()), pan->delta().y()); } if (QGesture *gesture = event->gesture(Qt::PinchGesture)) { - QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture); + auto pinch = static_cast<QPinchGesture *>(gesture); if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged) QChart::zoom(pinch->scaleFactor()); } diff --git a/examples/charts/zoomlinechart/chart.h b/examples/charts/zoomlinechart/chart.h index 365f8e51..8efed158 100644 --- a/examples/charts/zoomlinechart/chart.h +++ b/examples/charts/zoomlinechart/chart.h @@ -1,16 +1,12 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef CHART_H #define CHART_H -#include <QtCharts/QChart> +#include <QChart> -QT_BEGIN_NAMESPACE -class QGestureEvent; -QT_END_NAMESPACE - -QT_USE_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QGestureEvent) //![1] class Chart : public QChart @@ -18,16 +14,12 @@ class Chart : public QChart { public: explicit Chart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {}); - ~Chart(); protected: bool sceneEvent(QEvent *event); private: bool gestureEvent(QGestureEvent *event); - -private: - }; -#endif // CHART_H +#endif diff --git a/examples/charts/zoomlinechart/chartview.cpp b/examples/charts/zoomlinechart/chartview.cpp index 7edb976a..a8dd9435 100644 --- a/examples/charts/zoomlinechart/chartview.cpp +++ b/examples/charts/zoomlinechart/chartview.cpp @@ -1,12 +1,12 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "chartview.h" -#include <QtGui/QMouseEvent> -ChartView::ChartView(QChart *chart, QWidget *parent) : - QChartView(chart, parent), - m_isTouching(false) +#include <QMouseEvent> + +ChartView::ChartView(QChart *chart, QWidget *parent) + : QChartView(chart, parent) { setRubberBand(QChartView::RectangleRubberBand); } diff --git a/examples/charts/zoomlinechart/chartview.h b/examples/charts/zoomlinechart/chartview.h index 15903df6..9e12f5b0 100644 --- a/examples/charts/zoomlinechart/chartview.h +++ b/examples/charts/zoomlinechart/chartview.h @@ -1,20 +1,18 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef CHARTVIEW_H #define CHARTVIEW_H -#include <QtCharts/QChartView> -#include <QtWidgets/QRubberBand> - -QT_USE_NAMESPACE +#include <QChartView> +#include <QRubberBand> //![1] class ChartView : public QChartView //![1] { public: - ChartView(QChart *chart, QWidget *parent = 0); + ChartView(QChart *chart, QWidget *parent = nullptr); //![2] protected: @@ -26,7 +24,7 @@ protected: //![2] private: - bool m_isTouching; + bool m_isTouching = false; }; #endif diff --git a/examples/charts/zoomlinechart/main.cpp b/examples/charts/zoomlinechart/main.cpp index da68af82..af71641e 100644 --- a/examples/charts/zoomlinechart/main.cpp +++ b/examples/charts/zoomlinechart/main.cpp @@ -1,23 +1,22 @@ -// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "chart.h" #include "chartview.h" -#include <QtWidgets/QApplication> -#include <QtWidgets/QMainWindow> -#include <QtCore/QtMath> -#include <QtCore/QRandomGenerator> -#include <QtCharts/QLineSeries> -#include <QtCharts/QValueAxis> -QT_USE_NAMESPACE +#include <QApplication> +#include <QLineSeries> +#include <QMainWindow> +#include <QRandomGenerator> +#include <QtMath> +#include <QValueAxis> int main(int argc, char *argv[]) { QApplication a(argc, argv); //![1] - QLineSeries *series = new QLineSeries(); + auto series = new QLineSeries; for (int i = 0; i < 500; i++) { QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100); p.ry() += QRandomGenerator::global()->bounded(20); @@ -25,14 +24,14 @@ int main(int argc, char *argv[]) } //![1] - Chart *chart = new Chart(); + auto chart = new Chart; chart->addSeries(series); chart->setTitle("Zoom in/out example"); chart->setAnimationOptions(QChart::SeriesAnimations); chart->legend()->hide(); chart->createDefaultAxes(); - ChartView *chartView = new ChartView(chart); + auto chartView = new ChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); QMainWindow window; |