aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-09-09 13:38:02 +0200
committerlonkaars <loek@pipeframe.xyz>2022-09-09 13:38:23 +0200
commitc46903bacbefcb708f028b8869000b2f2e058171 (patch)
tree7a44c4ca6375c934b5f41d9f673cc634fbf3791d
parentbde529a4fb135eef1596ac0a5e6a8fa6a81cf711 (diff)
qt6 client makefile using chartview example
-rw-r--r--.gitignore3
-rw-r--r--client/chart.cpp72
-rw-r--r--client/chart.h59
-rw-r--r--client/chartview.cpp109
-rw-r--r--client/chartview.h58
-rw-r--r--client/client.pro13
-rw-r--r--client/main.cpp72
-rw-r--r--makefile14
-rw-r--r--readme.md7
9 files changed, 407 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 4e4fa75..0e6623a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,6 @@ copyright
stm32f091/main.elf
stm32f091/main.bin
**/compile_commands.json
+client/makefile
+client/client
+.qmake.stash
diff --git a/client/chart.cpp b/client/chart.cpp
new file mode 100644
index 0000000..bf2825e
--- /dev/null
+++ b/client/chart.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 "chart.h"
+#include <QtWidgets/QGesture>
+#include <QtWidgets/QGraphicsScene>
+#include <QtWidgets/QGraphicsView>
+
+Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
+ : QChart(QChart::ChartTypeCartesian, parent, wFlags)
+{
+ // Seems that QGraphicsView (QChartView) does not grab gestures.
+ // They can only be grabbed here in the QGraphicsWidget (QChart).
+ grabGesture(Qt::PanGesture);
+ grabGesture(Qt::PinchGesture);
+}
+
+Chart::~Chart()
+{
+
+}
+
+//![1]
+bool Chart::sceneEvent(QEvent *event)
+{
+ if (event->type() == QEvent::Gesture)
+ return gestureEvent(static_cast<QGestureEvent *>(event));
+ return QChart::event(event);
+}
+
+bool Chart::gestureEvent(QGestureEvent *event)
+{
+ if (QGesture *gesture = event->gesture(Qt::PanGesture)) {
+ QPanGesture *pan = static_cast<QPanGesture *>(gesture);
+ QChart::scroll(-(pan->delta().x()), pan->delta().y());
+ }
+
+ if (QGesture *gesture = event->gesture(Qt::PinchGesture)) {
+ QPinchGesture *pinch = static_cast<QPinchGesture *>(gesture);
+ if (pinch->changeFlags() & QPinchGesture::ScaleFactorChanged)
+ QChart::zoom(pinch->scaleFactor());
+ }
+
+ return true;
+}
+//![1]
diff --git a/client/chart.h b/client/chart.h
new file mode 100644
index 0000000..3ea7593
--- /dev/null
+++ b/client/chart.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 CHART_H
+#define CHART_H
+
+#include <QtCharts/QChart>
+
+QT_BEGIN_NAMESPACE
+class QGestureEvent;
+QT_END_NAMESPACE
+
+QT_CHARTS_USE_NAMESPACE
+
+//![1]
+class Chart : public QChart
+//![1]
+{
+public:
+ explicit Chart(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = {});
+ ~Chart();
+
+protected:
+ bool sceneEvent(QEvent *event);
+
+private:
+ bool gestureEvent(QGestureEvent *event);
+
+private:
+
+};
+
+#endif // CHART_H
diff --git a/client/chartview.cpp b/client/chartview.cpp
new file mode 100644
index 0000000..cb78034
--- /dev/null
+++ b/client/chartview.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 "chartview.h"
+#include <QtGui/QMouseEvent>
+
+ChartView::ChartView(QChart *chart, QWidget *parent) :
+ QChartView(chart, parent),
+ m_isTouching(false)
+{
+ setRubberBand(QChartView::RectangleRubberBand);
+}
+
+bool ChartView::viewportEvent(QEvent *event)
+{
+ if (event->type() == QEvent::TouchBegin) {
+ // By default touch events are converted to mouse events. So
+ // after this event we will get a mouse event also but we want
+ // to handle touch events as gestures only. So we need this safeguard
+ // to block mouse events that are actually generated from touch.
+ m_isTouching = true;
+
+ // Turn off animations when handling gestures they
+ // will only slow us down.
+ chart()->setAnimationOptions(QChart::NoAnimation);
+ }
+ return QChartView::viewportEvent(event);
+}
+
+void ChartView::mousePressEvent(QMouseEvent *event)
+{
+ if (m_isTouching)
+ return;
+ QChartView::mousePressEvent(event);
+}
+
+void ChartView::mouseMoveEvent(QMouseEvent *event)
+{
+ if (m_isTouching)
+ return;
+ QChartView::mouseMoveEvent(event);
+}
+
+void ChartView::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (m_isTouching)
+ m_isTouching = false;
+
+ // Because we disabled animations when touch event was detected
+ // we must put them back on.
+ chart()->setAnimationOptions(QChart::SeriesAnimations);
+
+ QChartView::mouseReleaseEvent(event);
+}
+
+//![1]
+void ChartView::keyPressEvent(QKeyEvent *event)
+{
+ switch (event->key()) {
+ case Qt::Key_Plus:
+ chart()->zoomIn();
+ break;
+ case Qt::Key_Minus:
+ chart()->zoomOut();
+ break;
+//![1]
+ case Qt::Key_Left:
+ chart()->scroll(-10, 0);
+ break;
+ case Qt::Key_Right:
+ chart()->scroll(10, 0);
+ break;
+ case Qt::Key_Up:
+ chart()->scroll(0, 10);
+ break;
+ case Qt::Key_Down:
+ chart()->scroll(0, -10);
+ break;
+ default:
+ QGraphicsView::keyPressEvent(event);
+ break;
+ }
+}
diff --git a/client/chartview.h b/client/chartview.h
new file mode 100644
index 0000000..502b946
--- /dev/null
+++ b/client/chartview.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 CHARTVIEW_H
+#define CHARTVIEW_H
+
+#include <QtCharts/QChartView>
+#include <QtWidgets/QRubberBand>
+
+QT_CHARTS_USE_NAMESPACE
+
+//![1]
+class ChartView : public QChartView
+//![1]
+{
+public:
+ ChartView(QChart *chart, QWidget *parent = 0);
+
+//![2]
+protected:
+ bool viewportEvent(QEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
+ void keyPressEvent(QKeyEvent *event);
+//![2]
+
+private:
+ bool m_isTouching;
+};
+
+#endif
diff --git a/client/client.pro b/client/client.pro
new file mode 100644
index 0000000..a9f38f1
--- /dev/null
+++ b/client/client.pro
@@ -0,0 +1,13 @@
+QT += charts
+
+HEADERS += \
+ chart.h \
+ chartview.h
+
+SOURCES += \
+ main.cpp \
+ chart.cpp \
+ chartview.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/charts/zoomlinechart
+INSTALLS += target
diff --git a/client/main.cpp b/client/main.cpp
new file mode 100644
index 0000000..28a3d91
--- /dev/null
+++ b/client/main.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 "chart.h"
+#include "chartview.h"
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QMainWindow>
+#include <QtCore/QtMath>
+#include <QtCore/QRandomGenerator>
+#include <QtCharts/QLineSeries>
+#include <QtCharts/QValueAxis>
+
+QT_CHARTS_USE_NAMESPACE
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+//![1]
+ QLineSeries *series = new QLineSeries();
+ for (int i = 0; i < 500; i++) {
+ QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100);
+ p.ry() += QRandomGenerator::global()->bounded(20);
+ *series << p;
+ }
+//![1]
+
+ Chart *chart = new Chart();
+ chart->addSeries(series);
+ chart->setTitle("Zoom in/out example");
+ chart->setAnimationOptions(QChart::SeriesAnimations);
+ chart->legend()->hide();
+ chart->createDefaultAxes();
+
+ ChartView *chartView = new ChartView(chart);
+ chartView->setRenderHint(QPainter::Antialiasing);
+
+ QMainWindow window;
+ window.setCentralWidget(chartView);
+ window.resize(400, 300);
+ window.grabGesture(Qt::PanGesture);
+ window.grabGesture(Qt::PinchGesture);
+ window.show();
+
+ return a.exec();
+}
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..0f478fd
--- /dev/null
+++ b/makefile
@@ -0,0 +1,14 @@
+all: client stm32
+
+clean:
+ make -C client clean
+ make -C stm32f091 clean
+
+client_makefile:
+ qmake client/client.pro -o client/makefile
+
+client: client_makefile
+ make -C client
+
+stm32:
+ make -C stm32f091
diff --git a/readme.md b/readme.md
index 063f716..7c9e0ae 100644
--- a/readme.md
+++ b/readme.md
@@ -1,4 +1,11 @@
# avans-whether-station
+## important details
+- the client subfolder uses qmake to generate `client/makefile`, thus only
+ `client/client.pro` should be tracked under version control, not
+ `client/makefile`
+- the stm32 makefile uses git submodules to pull necessary files for
+ compilation. make sure to initialize and sync the git submodules, or re-clone
+ using the `--recursive` flag.