##// END OF EJS Templates
Tuned scatterinteractions example
Tero Ahola -
r1026:d9d576bb7abc
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -1,7 +1,9
1 /*!
1 /*!
2 \example examples/scatterinteractions
2 \example examples/scatterinteractions
3 \title ScatterChart Example
3 \title ScatterChart Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to create simple scatter chart and how to interact with the chart.
6 The example shows how to create simple scatter chart and how to interact with the chart.
7
8 \image examples_scatterinteractions.png
7 */
9 */
@@ -1,57 +1,58
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "mainwindow.h"
21 #include "chartview.h"
22 #include <QChartView>
23
22
24 QTCOMMERCIALCHART_USE_NAMESPACE
23 QTCOMMERCIALCHART_USE_NAMESPACE
25
24
26 MainWindow::MainWindow(QWidget *parent)
25 ChartView::ChartView(QWidget *parent)
27 : QMainWindow(parent)
26 : QChartView(new QChart(), parent),
27 m_scatter(0),
28 m_scatter2(0)
28 {
29 {
29 QChart *chart = new QChart();
30 setRenderHint(QPainter::Antialiasing);
30 chart->setTitle("Click to remove scatter point");
31
32 chart()->setTitle("Click to interact with scatter points");
31
33
32 m_scatter = new QScatterSeries();
34 m_scatter = new QScatterSeries();
33 for(qreal x(0.5); x <= 4.0; x += 0.5) {
35 for(qreal x(0.5); x <= 4.0; x += 0.5) {
34 for(qreal y(0.5); y <= 4.0; y += 0.5) {
36 for(qreal y(0.5); y <= 4.0; y += 0.5) {
35 *m_scatter << QPointF(x, y);
37 *m_scatter << QPointF(x, y);
36 }
38 }
37 }
39 }
40 m_scatter2 = new QScatterSeries();
38
41
39 chart->addSeries(m_scatter);
42 chart()->addSeries(m_scatter2);
40 chart->axisX()->setRange(0, 4.5);
43 chart()->addSeries(m_scatter);
41 chart->axisY()->setRange(0, 4.5);
44 chart()->axisX()->setRange(0, 4.5);
45 chart()->axisY()->setRange(0, 4.5);
42
46
43 connect(m_scatter, SIGNAL(clicked(QPointF)), this, SLOT(handleClickedPoint(QPointF)));
47 connect(m_scatter, SIGNAL(clicked(QPointF)), this, SLOT(handleClickedPoint(QPointF)));
44
45 QChartView *chartView = new QChartView(chart);
46 chartView->setRenderHint(QPainter::Antialiasing);
47 setCentralWidget(chartView);
48 }
48 }
49
49
50 MainWindow::~MainWindow()
50 ChartView::~ChartView()
51 {
51 {
52 }
52 }
53
53
54 void MainWindow::handleClickedPoint(const QPointF& point)
54 void ChartView::handleClickedPoint(const QPointF& point)
55 {
55 {
56 m_scatter->remove(point);
56 m_scatter->remove(point);
57 m_scatter2->append(point);
57 }
58 }
@@ -1,47 +1,46
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef MAINWINDOW_H
21 #ifndef MAINWINDOW_H
22 #define MAINWINDOW_H
22 #define MAINWINDOW_H
23
23
24 #include <QtGui/QMainWindow>
24 #include <QChartGlobal>
25 #include <qchartglobal.h>
25 #include <QChartView>
26 #include <qscatterseries.h>
26 #include <QScatterSeries>
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 class MainWindow : public QMainWindow
30 class ChartView : public QChartView
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33
33
34 public:
34 public:
35 MainWindow(QWidget *parent = 0);
35 ChartView(QWidget *parent = 0);
36 ~MainWindow();
36 ~ChartView();
37
37
38 private Q_SLOTS:
38 private Q_SLOTS:
39 void handleClickedPoint(const QPointF& point);
39 void handleClickedPoint(const QPointF& point);
40
40
41 private:
41 private:
42 QScatterSeries *m_scatter;
42 QScatterSeries *m_scatter;
43 QScatterSeries *m_scatter2;
43 QScatterSeries *m_scatter2;
44 QScatterSeries *m_scatter3;
45 };
44 };
46
45
47 #endif // MAINWINDOW_H
46 #endif // MAINWINDOW_H
@@ -1,32 +1,35
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
22 #include "mainwindow.h"
22 #include <QMainWindow>
23 #include "chartview.h"
23
24
24 int main(int argc, char *argv[])
25 int main(int argc, char *argv[])
25 {
26 {
26 QApplication a(argc, argv);
27 QApplication a(argc, argv);
27 MainWindow w;
28 QMainWindow window;
28 w.resize(400, 300);
29 ChartView chartView(&window);
29 w.show();
30 window.setCentralWidget(&chartView);
31 window.resize(400, 300);
32 window.show();
30
33
31 return a.exec();
34 return a.exec();
32 }
35 }
@@ -1,8 +1,9
1 !include( ../examples.pri ) {
1 !include( ../examples.pri ) {
2 error( "Couldn't find the examples.pri file!" )
2 error( "Couldn't find the examples.pri file!" )
3 }
3 }
4
4
5 TARGET = scatterinteractions
5 TARGET = scatterinteractions
6 SOURCES += main.cpp\
6 SOURCES += main.cpp \
7 mainwindow.cpp
7 chartview.cpp
8 HEADERS += mainwindow.h
8 HEADERS += \
9 chartview.h
General Comments 0
You need to be logged in to leave comments. Login now