diff options
Diffstat (limited to 'examples')
71 files changed, 939 insertions, 119 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7613c97b..4eb2527b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from examples.pro. -qt_examples_build_begin() +qt_examples_build_begin(EXTERNAL_BUILD) add_subdirectory(charts) diff --git a/examples/charts/CMakeLists.txt b/examples/charts/CMakeLists.txt index 8cd0211f..55ec96b7 100644 --- a/examples/charts/CMakeLists.txt +++ b/examples/charts/CMakeLists.txt @@ -1,86 +1,88 @@ # Generated from charts.pro. if(QT_FEATURE_charts_area_chart) - add_subdirectory(areachart) + qt_internal_add_example(areachart) endif() if(QT_FEATURE_charts_line_chart) - add_subdirectory(callout) - add_subdirectory(chartinteractions) - add_subdirectory(customchart) - add_subdirectory(linechart) - add_subdirectory(lineandbar) - add_subdirectory(legendmarkers) - add_subdirectory(logvalueaxis) - add_subdirectory(modeldata) - add_subdirectory(zoomlinechart) + 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) endif() if(QT_FEATURE_charts_spline_chart) - add_subdirectory(dynamicspline) - add_subdirectory(multiaxis) - add_subdirectory(splinechart) + 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) - add_subdirectory(chartthemes) - add_subdirectory(polarchart) + qt_internal_add_example(chartthemes) + qt_internal_add_example(polarchart) endif() if(QT_FEATURE_charts_bar_chart) - add_subdirectory(barchart) - add_subdirectory(barmodelmapper) - add_subdirectory(horizontalbarchart) - add_subdirectory(horizontalpercentbarchart) - add_subdirectory(horizontalstackedbarchart) - add_subdirectory(stackedbarchart) - add_subdirectory(stackedbarchartdrilldown) - add_subdirectory(percentbarchart) - add_subdirectory(legend) - add_subdirectory(temperaturerecords) + 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) - add_subdirectory(donutchart) - add_subdirectory(donutbreakdown) - add_subdirectory(nesteddonuts) - add_subdirectory(piechart) - add_subdirectory(piechartcustomization) - add_subdirectory(piechartdrilldown) + 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) - add_subdirectory(qmlpiechart) + qt_internal_add_example(qmlpiechart) endif() if(QT_FEATURE_charts_boxplot_chart) - add_subdirectory(boxplotchart) + qt_internal_add_example(boxplotchart) endif() if(QT_FEATURE_charts_boxplot_chart AND TARGET Qt::Quick) - add_subdirectory(qmlboxplot) + qt_internal_add_example(qmlboxplot) endif() if(QT_FEATURE_charts_candlestick_chart) - add_subdirectory(candlestickchart) + qt_internal_add_example(candlestickchart) endif() if(QT_FEATURE_charts_candlestick_chart AND TARGET Qt::Quick) - add_subdirectory(qmlcandlestick) + qt_internal_add_example(qmlcandlestick) endif() if(QT_FEATURE_charts_scatter_chart) - add_subdirectory(scatterchart) - add_subdirectory(scatterinteractions) + qt_internal_add_example(scatterchart) + qt_internal_add_example(scatterinteractions) endif() if(TARGET Qt::Quick) - add_subdirectory(qmlchart) - add_subdirectory(qmlcustomizations) - add_subdirectory(qmlcustomlegend) - add_subdirectory(qmlf1legends) - add_subdirectory(qmloscilloscope) - add_subdirectory(qmlweather) + 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) endif() if(TARGET Qt::Multimedia) # TODO: this never gets compiled : missing find_pacakge - # add_subdirectory(audio) // QTBUG-94181 + # qt_internal_add_example(audio) // QTBUG-94181 endif() if(QT_FEATURE_opengl) - add_subdirectory(openglseries) + qt_internal_add_example(openglseries) endif() if(QT_FEATURE_charts_datetime_axis) - add_subdirectory(datetimeaxis) + qt_internal_add_example(datetimeaxis) endif() if(QT_FEATURE_charts_datetime_axis AND TARGET Qt::Quick) - add_subdirectory(qmlaxes) - add_subdirectory(qmlpolarchart) + qt_internal_add_example(qmlaxes) + qt_internal_add_example(qmlpolarchart) endif() diff --git a/examples/charts/areachart/CMakeLists.txt b/examples/charts/areachart/CMakeLists.txt index f55320ed..bc80affe 100644 --- a/examples/charts/areachart/CMakeLists.txt +++ b/examples/charts/areachart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from areachart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(areachart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/audio/CMakeLists.txt b/examples/charts/audio/CMakeLists.txt index ab7ee791..3148f9c8 100644 --- a/examples/charts/audio/CMakeLists.txt +++ b/examples/charts/audio/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from audio.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(audio LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -28,6 +28,7 @@ qt_add_executable(audio set_target_properties(audio PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/apple/Info.plist.in" ) target_link_libraries(audio PUBLIC Qt::Charts diff --git a/examples/charts/audio/apple/Info.plist.in b/examples/charts/audio/apple/Info.plist.in new file mode 100644 index 00000000..9e6cc252 --- /dev/null +++ b/examples/charts/audio/apple/Info.plist.in @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + + <key>NSMicrophoneUsageDescription</key> + <string>Qt Charts Example</string> +</dict> +</plist> diff --git a/examples/charts/audio/main.cpp b/examples/charts/audio/main.cpp index 8c4eca66..712a7c14 100644 --- a/examples/charts/audio/main.cpp +++ b/examples/charts/audio/main.cpp @@ -29,7 +29,8 @@ #include "widget.h" -#include <QtMultimedia/QAudioDeviceInfo> +#include <QtMultimedia/QAudioDevice> +#include <QtMultimedia/QMediaDevices> #include <QtWidgets/QApplication> #include <QtWidgets/QMessageBox> @@ -37,7 +38,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - const QAudioDeviceInfo inputDevice = QAudioDeviceInfo::defaultInputDevice(); + const QAudioDevice inputDevice = QMediaDevices::defaultAudioInput(); if (inputDevice.isNull()) { QMessageBox::warning(nullptr, "audio", "There is no audio input device available."); diff --git a/examples/charts/audio/widget.cpp b/examples/charts/audio/widget.cpp index c4945067..1a63150b 100644 --- a/examples/charts/audio/widget.cpp +++ b/examples/charts/audio/widget.cpp @@ -30,8 +30,9 @@ #include "widget.h" #include "xyseriesiodevice.h" -#include <QtMultimedia/QAudioDeviceInfo> +#include <QtMultimedia/QAudioDevice> #include <QtMultimedia/QAudioInput> +#include <QtMultimedia/QAudioSource> #include <QtCharts/QChartView> #include <QtCharts/QLineSeries> @@ -42,7 +43,7 @@ QT_USE_NAMESPACE -Widget::Widget(const QAudioDeviceInfo &deviceInfo, QWidget *parent) : +Widget::Widget(const QAudioDevice &deviceInfo, QWidget *parent) : QWidget(parent), m_chart(new QChart), m_series(new QLineSeries) @@ -62,29 +63,31 @@ Widget::Widget(const QAudioDeviceInfo &deviceInfo, QWidget *parent) : m_chart->addAxis(axisY, Qt::AlignLeft); m_series->attachAxis(axisY); m_chart->legend()->hide(); - m_chart->setTitle("Data from the microphone (" + deviceInfo.deviceName() + ')'); + m_chart->setTitle("Data from the microphone (" + deviceInfo.description() + ')'); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(chartView); + m_audioInput = new QAudioInput(deviceInfo, this); + QAudioFormat formatAudio; formatAudio.setSampleRate(8000); formatAudio.setChannelCount(1); - formatAudio.setSampleSize(8); - formatAudio.setCodec("audio/pcm"); - formatAudio.setByteOrder(QAudioFormat::LittleEndian); - formatAudio.setSampleType(QAudioFormat::UnSignedInt); + formatAudio.setSampleFormat(QAudioFormat::UInt8); - m_audioInput = new QAudioInput(deviceInfo, formatAudio, this); + m_audioSource = new QAudioSource(deviceInfo, formatAudio); + m_audioSource->setBufferSize(200); m_device = new XYSeriesIODevice(m_series, this); m_device->open(QIODevice::WriteOnly); - m_audioInput->start(m_device); + m_audioSource->start(m_device); } Widget::~Widget() { - m_audioInput->stop(); + m_audioSource->stop(); m_device->close(); + delete m_audioInput; + delete m_device; } diff --git a/examples/charts/audio/widget.h b/examples/charts/audio/widget.h index f4c3f049..64a130a2 100644 --- a/examples/charts/audio/widget.h +++ b/examples/charts/audio/widget.h @@ -44,7 +44,8 @@ class XYSeriesIODevice; QT_BEGIN_NAMESPACE class QAudioInput; -class QAudioDeviceInfo; +class QAudioDevice; +class QAudioSource; QT_END_NAMESPACE class Widget : public QWidget @@ -52,7 +53,7 @@ class Widget : public QWidget Q_OBJECT public: - explicit Widget(const QAudioDeviceInfo &deviceInfo, QWidget *parent = nullptr); + explicit Widget(const QAudioDevice &deviceInfo, QWidget *parent = nullptr); ~Widget(); private: @@ -60,6 +61,7 @@ private: QChart *m_chart; QLineSeries *m_series ; QAudioInput *m_audioInput = nullptr; + QAudioSource *m_audioSource = nullptr; }; #endif // WIDGET_H diff --git a/examples/charts/barchart/CMakeLists.txt b/examples/charts/barchart/CMakeLists.txt index 3f713b72..52e0af31 100644 --- a/examples/charts/barchart/CMakeLists.txt +++ b/examples/charts/barchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from barchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(barchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/barmodelmapper/CMakeLists.txt b/examples/charts/barmodelmapper/CMakeLists.txt index d1f66c96..72af0a79 100644 --- a/examples/charts/barmodelmapper/CMakeLists.txt +++ b/examples/charts/barmodelmapper/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from barmodelmapper.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(barmodelmapper LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/boxplotchart/CMakeLists.txt b/examples/charts/boxplotchart/CMakeLists.txt index ff1ee5a4..4007dced 100644 --- a/examples/charts/boxplotchart/CMakeLists.txt +++ b/examples/charts/boxplotchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from boxplotchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(boxplotchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/callout/CMakeLists.txt b/examples/charts/callout/CMakeLists.txt index 82b1d790..ec98349d 100644 --- a/examples/charts/callout/CMakeLists.txt +++ b/examples/charts/callout/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from callout.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(callout LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/candlestickchart/CMakeLists.txt b/examples/charts/candlestickchart/CMakeLists.txt index 94accdd6..7db565af 100644 --- a/examples/charts/candlestickchart/CMakeLists.txt +++ b/examples/charts/candlestickchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from candlestickchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(candlestickchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/chartinteractions/CMakeLists.txt b/examples/charts/chartinteractions/CMakeLists.txt index 1dccc30b..95f911c5 100644 --- a/examples/charts/chartinteractions/CMakeLists.txt +++ b/examples/charts/chartinteractions/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from chartinteractions.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(chartinteractions LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/charts.pro b/examples/charts/charts.pro index 1e60be5a..bac912e5 100644 --- a/examples/charts/charts.pro +++ b/examples/charts/charts.pro @@ -21,7 +21,8 @@ qtConfig(charts-spline-chart) { SUBDIRS += \ dynamicspline \ multiaxis \ - splinechart + splinechart \ + pointsselectionandmarkers qtConfig(charts-area-chart) { SUBDIRS += \ chartthemes \ @@ -39,7 +40,8 @@ qtConfig(charts-bar-chart) { stackedbarchartdrilldown \ percentbarchart \ legend \ - temperaturerecords + temperaturerecords \ + selectedbar } qtConfig(charts-pie-chart) { SUBDIRS += \ diff --git a/examples/charts/chartthemes/CMakeLists.txt b/examples/charts/chartthemes/CMakeLists.txt index 8caf3c79..3d6f9639 100644 --- a/examples/charts/chartthemes/CMakeLists.txt +++ b/examples/charts/chartthemes/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from chartthemes.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(chartthemes LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/customchart/CMakeLists.txt b/examples/charts/customchart/CMakeLists.txt index 164d55f4..70b3f14c 100644 --- a/examples/charts/customchart/CMakeLists.txt +++ b/examples/charts/customchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from customchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(customchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/datetimeaxis/CMakeLists.txt b/examples/charts/datetimeaxis/CMakeLists.txt index 128aa126..d34f4746 100644 --- a/examples/charts/datetimeaxis/CMakeLists.txt +++ b/examples/charts/datetimeaxis/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from datetimeaxis.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(datetimeaxis LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/donutbreakdown/CMakeLists.txt b/examples/charts/donutbreakdown/CMakeLists.txt index 63ba5b5f..eceaa86c 100644 --- a/examples/charts/donutbreakdown/CMakeLists.txt +++ b/examples/charts/donutbreakdown/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from donutbreakdown.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(donutbreakdown LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/donutchart/CMakeLists.txt b/examples/charts/donutchart/CMakeLists.txt index 40316cab..a19232dd 100644 --- a/examples/charts/donutchart/CMakeLists.txt +++ b/examples/charts/donutchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from donutchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(donutchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/dynamicspline/CMakeLists.txt b/examples/charts/dynamicspline/CMakeLists.txt index 8d65964b..734fddc7 100644 --- a/examples/charts/dynamicspline/CMakeLists.txt +++ b/examples/charts/dynamicspline/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from dynamicspline.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(dynamicspline LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/horizontalbarchart/CMakeLists.txt b/examples/charts/horizontalbarchart/CMakeLists.txt index 2ba0d249..541b7134 100644 --- a/examples/charts/horizontalbarchart/CMakeLists.txt +++ b/examples/charts/horizontalbarchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from horizontalbarchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(horizontalbarchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/horizontalpercentbarchart/CMakeLists.txt b/examples/charts/horizontalpercentbarchart/CMakeLists.txt index 005e2ba5..4740e4da 100644 --- a/examples/charts/horizontalpercentbarchart/CMakeLists.txt +++ b/examples/charts/horizontalpercentbarchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from horizontalpercentbarchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(horizontalpercentbarchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/horizontalstackedbarchart/CMakeLists.txt b/examples/charts/horizontalstackedbarchart/CMakeLists.txt index 17be4111..3a83038d 100644 --- a/examples/charts/horizontalstackedbarchart/CMakeLists.txt +++ b/examples/charts/horizontalstackedbarchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from horizontalstackedbarchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(horizontalstackedbarchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/legend/CMakeLists.txt b/examples/charts/legend/CMakeLists.txt index 434909d5..837a0eff 100644 --- a/examples/charts/legend/CMakeLists.txt +++ b/examples/charts/legend/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from legend.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(legend LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/legendmarkers/CMakeLists.txt b/examples/charts/legendmarkers/CMakeLists.txt index 9a06c081..ebd4a8c3 100644 --- a/examples/charts/legendmarkers/CMakeLists.txt +++ b/examples/charts/legendmarkers/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from legendmarkers.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(legendmarkers LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/lineandbar/CMakeLists.txt b/examples/charts/lineandbar/CMakeLists.txt index ca6d9054..7488c42c 100644 --- a/examples/charts/lineandbar/CMakeLists.txt +++ b/examples/charts/lineandbar/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from lineandbar.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(lineandbar LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/linechart/CMakeLists.txt b/examples/charts/linechart/CMakeLists.txt index 74076d20..6b18cbdd 100644 --- a/examples/charts/linechart/CMakeLists.txt +++ b/examples/charts/linechart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from linechart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(linechart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/logvalueaxis/CMakeLists.txt b/examples/charts/logvalueaxis/CMakeLists.txt index f2841b88..600c42fd 100644 --- a/examples/charts/logvalueaxis/CMakeLists.txt +++ b/examples/charts/logvalueaxis/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from logvalueaxis.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(logvalueaxis LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/modeldata/CMakeLists.txt b/examples/charts/modeldata/CMakeLists.txt index 65478668..650f236b 100644 --- a/examples/charts/modeldata/CMakeLists.txt +++ b/examples/charts/modeldata/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from modeldata.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(modeldata LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/multiaxis/CMakeLists.txt b/examples/charts/multiaxis/CMakeLists.txt index d333f519..e5396390 100644 --- a/examples/charts/multiaxis/CMakeLists.txt +++ b/examples/charts/multiaxis/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from multiaxis.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(multiaxis LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/nesteddonuts/CMakeLists.txt b/examples/charts/nesteddonuts/CMakeLists.txt index 4e55b578..47a62951 100644 --- a/examples/charts/nesteddonuts/CMakeLists.txt +++ b/examples/charts/nesteddonuts/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from nesteddonuts.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(nesteddonuts LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/openglseries/CMakeLists.txt b/examples/charts/openglseries/CMakeLists.txt index 26be0522..de21d0d3 100644 --- a/examples/charts/openglseries/CMakeLists.txt +++ b/examples/charts/openglseries/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from openglseries.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(openglseries LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/percentbarchart/CMakeLists.txt b/examples/charts/percentbarchart/CMakeLists.txt index c3243045..2b2e51d2 100644 --- a/examples/charts/percentbarchart/CMakeLists.txt +++ b/examples/charts/percentbarchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from percentbarchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(percentbarchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/piechart/CMakeLists.txt b/examples/charts/piechart/CMakeLists.txt index e37c2a6d..9450dce1 100644 --- a/examples/charts/piechart/CMakeLists.txt +++ b/examples/charts/piechart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from piechart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(piechart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/piechartcustomization/CMakeLists.txt b/examples/charts/piechartcustomization/CMakeLists.txt index 3bf78144..94a02914 100644 --- a/examples/charts/piechartcustomization/CMakeLists.txt +++ b/examples/charts/piechartcustomization/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from piechartcustomization.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(piechartcustomization LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/piechartcustomization/mainwidget.cpp b/examples/charts/piechartcustomization/mainwidget.cpp index 5d2ac832..8c2d9b71 100644 --- a/examples/charts/piechartcustomization/mainwidget.cpp +++ b/examples/charts/piechartcustomization/mainwidget.cpp @@ -81,7 +81,7 @@ MainWidget::MainWidget(QWidget *parent) m_legendCheckBox = new QCheckBox(); - QScrollArea *settingsScrollBar = new QScrollArea(); + settingsScrollBar = new QScrollArea(); QWidget *settingsContentWidget = new QWidget(); QFormLayout *chartSettingsLayout = new QFormLayout(settingsContentWidget); @@ -212,6 +212,7 @@ MainWidget::MainWidget(QWidget *parent) sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); QGroupBox *sliceSettings = new QGroupBox("Selected slice"); sliceSettings->setLayout(sliceSettingsLayout); + sliceSettings->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); connect(m_sliceName, &QLineEdit::textChanged, this, &MainWidget::updateSliceSettings); connect(m_sliceValue, @@ -244,12 +245,16 @@ MainWidget::MainWidget(QWidget *parent) settingsLayout->addWidget(sliceSettings); settingsContentWidget->setLayout(settingsLayout); + settingsScrollBar->setWidget(settingsContentWidget); - settingsScrollBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + settingsScrollBar->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + settingsScrollBar->setWidgetResizable(true); + settingsScrollBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + m_chartView->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); - QGridLayout *baseLayout = new QGridLayout(); + baseLayout = new QGridLayout(); baseLayout->addWidget(settingsScrollBar, 0, 0); - baseLayout->addWidget(m_chartView, 0, 1); + baseLayout->addWidget(m_chartView, 1, 0); setLayout(baseLayout); updateSerieSettings(); @@ -393,4 +398,32 @@ void MainWidget::removeSlice() m_slice = 0; } +void MainWidget::resizeEvent(QResizeEvent *e) +{ + 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); + + baseLayout->addWidget(m_chartView, 0, 0); + baseLayout->addWidget(settingsScrollBar, 1, 0); + + oldAspectRatio = aspectRatio; + } + else if ((aspectRatio > 1.0) && (oldAspectRatio < 1.0)) { + baseLayout->removeWidget(m_chartView); + baseLayout->removeWidget(settingsScrollBar); + + baseLayout->addWidget(m_chartView, 0, 0); + baseLayout->addWidget(settingsScrollBar, 0, 1); + + oldAspectRatio = aspectRatio; + } +} + + #include "moc_mainwidget.cpp" diff --git a/examples/charts/piechartcustomization/mainwidget.h b/examples/charts/piechartcustomization/mainwidget.h index d3c1e724..ba6c3670 100644 --- a/examples/charts/piechartcustomization/mainwidget.h +++ b/examples/charts/piechartcustomization/mainwidget.h @@ -29,6 +29,8 @@ #ifndef MAINWIDGET_H #define MAINWIDGET_H +#include "qgridlayout.h" +#include "qscrollarea.h" #include <QtWidgets/QWidget> #include <QtCharts/QChartGlobal> @@ -70,6 +72,8 @@ public Q_SLOTS: void removeSlice(); private: + void resizeEvent(QResizeEvent *e); + QComboBox *m_themeComboBox; QCheckBox *m_aaCheckBox; QCheckBox *m_animationsCheckBox; @@ -100,6 +104,10 @@ private: QPushButton *m_labelBrush; QComboBox *m_labelPosition; BrushTool *m_labelBrushTool; + QGridLayout *baseLayout; + QScrollArea *settingsScrollBar; + + double oldAspectRatio; }; #endif // MAINWIDGET_H diff --git a/examples/charts/piechartdrilldown/CMakeLists.txt b/examples/charts/piechartdrilldown/CMakeLists.txt index 923803cd..567f5c2a 100644 --- a/examples/charts/piechartdrilldown/CMakeLists.txt +++ b/examples/charts/piechartdrilldown/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from piechartdrilldown.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(piechartdrilldown LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/pointsselectionandmarkers/CMakeLists.txt b/examples/charts/pointsselectionandmarkers/CMakeLists.txt new file mode 100644 index 00000000..c2e68bd3 --- /dev/null +++ b/examples/charts/pointsselectionandmarkers/CMakeLists.txt @@ -0,0 +1,54 @@ +# Generated from pointsselectionandmarkers.pro. + +cmake_minimum_required(VERSION 3.14) +project(pointsselectionandmarkers LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/pointsselectionandmarkers") + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Gui) +find_package(Qt6 COMPONENTS Charts) + +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/blue_triangle.png b/examples/charts/pointsselectionandmarkers/blue_triangle.png Binary files differnew file mode 100644 index 00000000..7790453c --- /dev/null +++ b/examples/charts/pointsselectionandmarkers/blue_triangle.png diff --git a/examples/charts/pointsselectionandmarkers/green_triangle.png b/examples/charts/pointsselectionandmarkers/green_triangle.png Binary files differnew file mode 100644 index 00000000..29ae043f --- /dev/null +++ b/examples/charts/pointsselectionandmarkers/green_triangle.png diff --git a/examples/charts/pointsselectionandmarkers/main.cpp b/examples/charts/pointsselectionandmarkers/main.cpp new file mode 100644 index 00000000..376d49f9 --- /dev/null +++ b/examples/charts/pointsselectionandmarkers/main.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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 new file mode 100644 index 00000000..ac8adffb --- /dev/null +++ b/examples/charts/pointsselectionandmarkers/pointsselectionandmarkers.pro @@ -0,0 +1,15 @@ +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 new file mode 100644 index 00000000..920bf0cc --- /dev/null +++ b/examples/charts/pointsselectionandmarkers/pointsselectionandmarkers.qrc @@ -0,0 +1,6 @@ +<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 new file mode 100644 index 00000000..7b3ef7f4 --- /dev/null +++ b/examples/charts/pointsselectionandmarkers/utilities.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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/pointsselectionandmarkers/utilities.h b/examples/charts/pointsselectionandmarkers/utilities.h new file mode 100644 index 00000000..79a6a0c6 --- /dev/null +++ b/examples/charts/pointsselectionandmarkers/utilities.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef UTILITIES_H +#define UTILITIES_H + +#include <QImage> + +namespace Utilities +{ + enum class PointType { + RedRectangle, + GreenTriangle, + OrangeCircle + }; + + enum class SelectedPointType { + BlueTriangle, + YellowRectangle, + LavenderCircle + }; + + enum class LineColor { + Blue, + Black, + Mint + }; + + QImage redRectangle(qreal imageSize); + QImage yellowRectangle(qreal imageSize); + 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 diff --git a/examples/charts/polarchart/CMakeLists.txt b/examples/charts/polarchart/CMakeLists.txt index 7047de38..7c94a7eb 100644 --- a/examples/charts/polarchart/CMakeLists.txt +++ b/examples/charts/polarchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from polarchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(polarchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlaxes/CMakeLists.txt b/examples/charts/qmlaxes/CMakeLists.txt index bb061691..738ff295 100644 --- a/examples/charts/qmlaxes/CMakeLists.txt +++ b/examples/charts/qmlaxes/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlaxes.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlaxes LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlboxplot/CMakeLists.txt b/examples/charts/qmlboxplot/CMakeLists.txt index e60aa879..ce55be21 100644 --- a/examples/charts/qmlboxplot/CMakeLists.txt +++ b/examples/charts/qmlboxplot/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlboxplot.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlboxplot LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlcandlestick/CMakeLists.txt b/examples/charts/qmlcandlestick/CMakeLists.txt index c78b7950..df2a7015 100644 --- a/examples/charts/qmlcandlestick/CMakeLists.txt +++ b/examples/charts/qmlcandlestick/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlcandlestick.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlcandlestick LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlchart/CMakeLists.txt b/examples/charts/qmlchart/CMakeLists.txt index 6496ca8b..fd2aa325 100644 --- a/examples/charts/qmlchart/CMakeLists.txt +++ b/examples/charts/qmlchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlcustomizations/CMakeLists.txt b/examples/charts/qmlcustomizations/CMakeLists.txt index 00f59f59..7af83332 100644 --- a/examples/charts/qmlcustomizations/CMakeLists.txt +++ b/examples/charts/qmlcustomizations/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlcustomizations.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlcustomizations LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlcustomlegend/CMakeLists.txt b/examples/charts/qmlcustomlegend/CMakeLists.txt index e51e7f67..1c3aef8a 100644 --- a/examples/charts/qmlcustomlegend/CMakeLists.txt +++ b/examples/charts/qmlcustomlegend/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlcustomlegend.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlcustomlegend LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlf1legends/CMakeLists.txt b/examples/charts/qmlf1legends/CMakeLists.txt index 69b418e9..f5438a22 100644 --- a/examples/charts/qmlf1legends/CMakeLists.txt +++ b/examples/charts/qmlf1legends/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlf1legends.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlf1legends LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmloscilloscope/CMakeLists.txt b/examples/charts/qmloscilloscope/CMakeLists.txt index 5db06367..6d8bf8f9 100644 --- a/examples/charts/qmloscilloscope/CMakeLists.txt +++ b/examples/charts/qmloscilloscope/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmloscilloscope.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmloscilloscope LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlpiechart/CMakeLists.txt b/examples/charts/qmlpiechart/CMakeLists.txt index 787e5235..35a880fc 100644 --- a/examples/charts/qmlpiechart/CMakeLists.txt +++ b/examples/charts/qmlpiechart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlpiechart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlpiechart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlpolarchart/CMakeLists.txt b/examples/charts/qmlpolarchart/CMakeLists.txt index b1c927f9..39685151 100644 --- a/examples/charts/qmlpolarchart/CMakeLists.txt +++ b/examples/charts/qmlpolarchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlpolarchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlpolarchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/qmlweather/CMakeLists.txt b/examples/charts/qmlweather/CMakeLists.txt index 314ece1b..8142fb8c 100644 --- a/examples/charts/qmlweather/CMakeLists.txt +++ b/examples/charts/qmlweather/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from qmlweather.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(qmlweather LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/scatterchart/CMakeLists.txt b/examples/charts/scatterchart/CMakeLists.txt index fa498df7..facd2538 100644 --- a/examples/charts/scatterchart/CMakeLists.txt +++ b/examples/charts/scatterchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from scatterchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(scatterchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/scatterinteractions/CMakeLists.txt b/examples/charts/scatterinteractions/CMakeLists.txt index 51eb2bea..6d1cada9 100644 --- a/examples/charts/scatterinteractions/CMakeLists.txt +++ b/examples/charts/scatterinteractions/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from scatterinteractions.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(scatterinteractions LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/selectedbar/CMakeLists.txt b/examples/charts/selectedbar/CMakeLists.txt new file mode 100644 index 00000000..a293d64b --- /dev/null +++ b/examples/charts/selectedbar/CMakeLists.txt @@ -0,0 +1,40 @@ +# Generated from selectedbar.pro. + +cmake_minimum_required(VERSION 3.16) +project(selectedbar LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/charts/selectedbar") + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Gui) +find_package(Qt6 COMPONENTS Charts) + +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/main.cpp b/examples/charts/selectedbar/main.cpp new file mode 100644 index 00000000..9ed62441 --- /dev/null +++ b/examples/charts/selectedbar/main.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "utilities.h" +#include <QBarSet> +#include <QApplication> +#include <QBarSeries> +#include <QList> +#include <QChart> +#include <QBarCategoryAxis> +#include <QValueAxis> +#include <QChartView> +#include <QWindow> +#include <QHBoxLayout> +#include <QLabel> +#include <QMainWindow> + +int main(int argc, char *argv[]) +{ + 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(); + qreal totalSum = setChicken->sum() + setPork->sum() + setTurkey->sum() + setHam->sum(); + QList<QBarSet *> setList = QList<QBarSet *>{setChicken, setPork, setTurkey, setHam}; + + QBarSeries *series = new QBarSeries(); + series->append(setList); + //![1] + + //![2] + QChart *chart = new QChart(); + chart->addSeries(series); + chart->setTitle(QCoreApplication::tr("Meat consumption")); + chart->setAnimationOptions(QChart::SeriesAnimations); + chart->legend()->setVisible(true); + chart->legend()->setAlignment(Qt::AlignBottom); + //![2] + + //![3] + for (QBarSet *barSet : series->barSets()) + barSet->setSelectedColor(barSet->brush().color().darker()); + //![3] + + //![4] + QStringList categories = Utilities::createYearCategories(); + QBarCategoryAxis *axisX = new QBarCategoryAxis(); + axisX->setCategories(categories); + chart->addAxis(axisX, Qt::AlignBottom); + series->attachAxis(axisX); + + QValueAxis *axisY = new QValueAxis(); + axisY->setRange(0, 20); + axisY->setTitleText(QCoreApplication::tr("Tons")); + axisY->setLabelsAngle(-90); + axisY->setTitleVisible(true); + chart->addAxis(axisY, Qt::AlignLeft); + series->attachAxis(axisY); + //![4] + + //![5] + QChartView *chartView = new QChartView(chart); + chartView->setRenderHint(QPainter::Antialiasing); + //![5] + + //![6] + QWidget *labelWidget = new QWidget(&mainWindow); + QHBoxLayout *labelLayout = new QHBoxLayout(labelWidget); + labelLayout->setAlignment(Qt::AlignCenter); + + QLabel *totalSumLabel = new QLabel(QCoreApplication::tr("Total sum: %1 T").arg(totalSum)); + labelLayout->addWidget(totalSumLabel); + totalSumLabel->setContentsMargins(0, 0, 54, 0); + + QLabel *selectedSumLabel = new QLabel(QCoreApplication::tr("Selected sum: 0 T")); + labelLayout->addWidget(selectedSumLabel); + + QLabel *unselectedSumLabel = new QLabel(QCoreApplication::tr("Unselected sum: %1 T").arg(totalSum)); + labelLayout->addWidget(unselectedSumLabel); + unselectedSumLabel->setContentsMargins(54, 0, 0, 0); + //![6] + + //![7] + QObject::connect(series, &QAbstractBarSeries::clicked, series, [=](int index, QBarSet *set) { + set->toggleSelection({index}); + qreal selectedSum = 0.; + for (int i = 0; i < setList.size(); ++i) { + auto selectedIndices = setList.at(i)->selectedBars(); + 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)); + // 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) + ); + }); + //![7] + + //![8] + QWidget *mainWidget = new QWidget(&mainWindow); + QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget); + + mainLayout->addWidget(chartView); + mainLayout->addWidget(labelWidget); + + mainWindow.setCentralWidget(mainWidget); + mainWindow.resize(800, 600); + + mainWindow.show(); + return a.exec(); + //![8] +} diff --git a/examples/charts/selectedbar/selectedbar.pro b/examples/charts/selectedbar/selectedbar.pro new file mode 100644 index 00000000..24d0de08 --- /dev/null +++ b/examples/charts/selectedbar/selectedbar.pro @@ -0,0 +1,11 @@ +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 new file mode 100644 index 00000000..4bbf2c74 --- /dev/null +++ b/examples/charts/selectedbar/utilities.cpp @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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 new file mode 100644 index 00000000..41fe9610 --- /dev/null +++ b/examples/charts/selectedbar/utilities.h @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Charts module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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 index 62e369d0..1e8c0092 100644 --- a/examples/charts/splinechart/CMakeLists.txt +++ b/examples/charts/splinechart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from splinechart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(splinechart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/stackedbarchart/CMakeLists.txt b/examples/charts/stackedbarchart/CMakeLists.txt index 782258bf..c96be256 100644 --- a/examples/charts/stackedbarchart/CMakeLists.txt +++ b/examples/charts/stackedbarchart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from stackedbarchart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(stackedbarchart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/stackedbarchartdrilldown/CMakeLists.txt b/examples/charts/stackedbarchartdrilldown/CMakeLists.txt index f8374cf9..576960bc 100644 --- a/examples/charts/stackedbarchartdrilldown/CMakeLists.txt +++ b/examples/charts/stackedbarchartdrilldown/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from stackedbarchartdrilldown.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(stackedbarchartdrilldown LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/temperaturerecords/CMakeLists.txt b/examples/charts/temperaturerecords/CMakeLists.txt index c6bd04d5..b1a0588b 100644 --- a/examples/charts/temperaturerecords/CMakeLists.txt +++ b/examples/charts/temperaturerecords/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from temperaturerecords.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(temperaturerecords LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/examples/charts/zoomlinechart/CMakeLists.txt b/examples/charts/zoomlinechart/CMakeLists.txt index 5c0f299d..6c6b8222 100644 --- a/examples/charts/zoomlinechart/CMakeLists.txt +++ b/examples/charts/zoomlinechart/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from zoomlinechart.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(zoomlinechart LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) |