##// END OF EJS Templates
Tuned scatterinteractions example
Tero Ahola -
r1026:d9d576bb7abc
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
@@ -4,4 +4,6
4 4 \subtitle
5 5
6 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 */
@@ -18,16 +18,18
18 18 **
19 19 ****************************************************************************/
20 20
21 #include "mainwindow.h"
22 #include <QChartView>
21 #include "chartview.h"
23 22
24 23 QTCOMMERCIALCHART_USE_NAMESPACE
25 24
26 MainWindow::MainWindow(QWidget *parent)
27 : QMainWindow(parent)
25 ChartView::ChartView(QWidget *parent)
26 : QChartView(new QChart(), parent),
27 m_scatter(0),
28 m_scatter2(0)
28 29 {
29 QChart *chart = new QChart();
30 chart->setTitle("Click to remove scatter point");
30 setRenderHint(QPainter::Antialiasing);
31
32 chart()->setTitle("Click to interact with scatter points");
31 33
32 34 m_scatter = new QScatterSeries();
33 35 for(qreal x(0.5); x <= 4.0; x += 0.5) {
@@ -35,23 +37,22 MainWindow::MainWindow(QWidget *parent)
35 37 *m_scatter << QPointF(x, y);
36 38 }
37 39 }
40 m_scatter2 = new QScatterSeries();
38 41
39 chart->addSeries(m_scatter);
40 chart->axisX()->setRange(0, 4.5);
41 chart->axisY()->setRange(0, 4.5);
42 chart()->addSeries(m_scatter2);
43 chart()->addSeries(m_scatter);
44 chart()->axisX()->setRange(0, 4.5);
45 chart()->axisY()->setRange(0, 4.5);
42 46
43 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 56 m_scatter->remove(point);
57 m_scatter2->append(point);
57 58 }
@@ -21,19 +21,19
21 21 #ifndef MAINWINDOW_H
22 22 #define MAINWINDOW_H
23 23
24 #include <QtGui/QMainWindow>
25 #include <qchartglobal.h>
26 #include <qscatterseries.h>
24 #include <QChartGlobal>
25 #include <QChartView>
26 #include <QScatterSeries>
27 27
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 class MainWindow : public QMainWindow
30 class ChartView : public QChartView
31 31 {
32 32 Q_OBJECT
33 33
34 34 public:
35 MainWindow(QWidget *parent = 0);
36 ~MainWindow();
35 ChartView(QWidget *parent = 0);
36 ~ChartView();
37 37
38 38 private Q_SLOTS:
39 39 void handleClickedPoint(const QPointF& point);
@@ -41,7 +41,6 private Q_SLOTS:
41 41 private:
42 42 QScatterSeries *m_scatter;
43 43 QScatterSeries *m_scatter2;
44 QScatterSeries *m_scatter3;
45 44 };
46 45
47 46 #endif // MAINWINDOW_H
@@ -19,14 +19,17
19 19 ****************************************************************************/
20 20
21 21 #include <QtGui/QApplication>
22 #include "mainwindow.h"
22 #include <QMainWindow>
23 #include "chartview.h"
23 24
24 25 int main(int argc, char *argv[])
25 26 {
26 27 QApplication a(argc, argv);
27 MainWindow w;
28 w.resize(400, 300);
29 w.show();
28 QMainWindow window;
29 ChartView chartView(&window);
30 window.setCentralWidget(&chartView);
31 window.resize(400, 300);
32 window.show();
30 33
31 34 return a.exec();
32 35 }
@@ -4,5 +4,6
4 4
5 5 TARGET = scatterinteractions
6 6 SOURCES += main.cpp\
7 mainwindow.cpp
8 HEADERS += mainwindow.h
7 chartview.cpp
8 HEADERS += \
9 chartview.h
General Comments 0
You need to be logged in to leave comments. Login now