diff options
Diffstat (limited to 'examples/charts')
18 files changed, 572 insertions, 70 deletions
diff --git a/examples/charts/CMakeLists.txt b/examples/charts/CMakeLists.txt index a2122782..55ec96b7 100644 --- a/examples/charts/CMakeLists.txt +++ b/examples/charts/CMakeLists.txt @@ -1,87 +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) - add_subdirectory(selectedbar) + 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/audio/CMakeLists.txt b/examples/charts/audio/CMakeLists.txt index 6349e31d..3148f9c8 100644 --- a/examples/charts/audio/CMakeLists.txt +++ b/examples/charts/audio/CMakeLists.txt @@ -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/charts.pro b/examples/charts/charts.pro index cd92cfe2..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 \ 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/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/selectedbar/CMakeLists.txt b/examples/charts/selectedbar/CMakeLists.txt index 55542a42..a293d64b 100644 --- a/examples/charts/selectedbar/CMakeLists.txt +++ b/examples/charts/selectedbar/CMakeLists.txt @@ -1,6 +1,6 @@ # Generated from selectedbar.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(selectedbar LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) |