##// END OF EJS Templates
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
sauimone -
r425:85842e6c8dba
parent child
Show More
@@ -0,0 +1,6
1 #include "chartwidget.h"
2
3 ChartWidget::ChartWidget(QWidget *parent) :
4 QChartView(parent)
5 {
6 }
@@ -0,0 +1,21
1 #ifndef CHARTWIDGET_H
2 #define CHARTWIDGET_H
3
4 #include <qchartview.h>
5
6 QTCOMMERCIALCHART_USE_NAMESPACE
7
8
9 class ChartWidget : public QChartView
10 {
11 Q_OBJECT
12 public:
13 explicit ChartWidget(QWidget *parent = 0);
14
15 signals:
16
17 public slots:
18
19 };
20
21 #endif // CHARTWIDGET_H
@@ -0,0 +1,83
1 #include <QApplication>
2 #include <QMainWindow>
3 #include <qchartview.h>
4 #include <qstackedbarseries.h>
5 #include <qbarset.h>
6 #include <qchartaxis.h>
7 #include <QStringList>
8
9 QTCOMMERCIALCHART_USE_NAMESPACE
10
11 int main(int argc, char *argv[])
12 {
13 QApplication a(argc, argv);
14 QMainWindow window;
15
16 // TODO:
17 /*
18 //! [1]
19 // Define categories
20 QStringList categories;
21 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
22 //! [1]
23
24 //! [2]
25 // Create some test sets for chat
26 QBarSet *set0 = new QBarSet("Bub");
27 QBarSet *set1 = new QBarSet("Bob");
28 QBarSet *set2 = new QBarSet("Guybrush");
29 QBarSet *set3 = new QBarSet("Larry");
30 QBarSet *set4 = new QBarSet("Zak");
31
32 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
33 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
34 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
35 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
36 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
37 //! [2]
38
39 //! [3]
40 // Create series and add sets to it
41 QStackedBarSeries* series = new QStackedBarSeries(categories);
42
43 series->addBarSet(set0);
44 series->addBarSet(set1);
45 series->addBarSet(set2);
46 series->addBarSet(set3);
47 series->addBarSet(set4);
48 //! [3]
49
50 //! [4]
51 // Enable tooltip
52 series->setToolTipEnabled();
53
54 // Connect clicked signal of set to toggle floating values of set.
55 // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values.
56 QObject::connect(set0,SIGNAL(clicked(QBarSet*,QString)),set0,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set1,SIGNAL(clicked(QBarSet*,QString)),set1,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set2,SIGNAL(clicked(QBarSet*,QString)),set2,SIGNAL(toggleFloatingValues()));
59 QObject::connect(set3,SIGNAL(clicked(QBarSet*,QString)),set3,SIGNAL(toggleFloatingValues()));
60 //! [4]
61
62 //! [5]
63 // Create view for chart and add series to it. Apply theme.
64
65 QChartView* chartView = new QChartView(&window);
66 chartView->addSeries(series);
67 chartView->setChartTitle("simple stacked barchart");
68 chartView->setChartTheme(QChart::ChartThemeIcy);
69 //! [5]
70
71 //! [6]
72 chartView->axisX()->setAxisVisible(false);
73 chartView->axisX()->setGridVisible(false);
74 chartView->axisX()->setLabelsVisible(false);
75 //! [6]
76
77 window.setCentralWidget(chartView);
78 window.resize(400, 300);
79 window.show();
80 */
81 return a.exec();
82 }
83
@@ -0,0 +1,9
1 !include( ../example.pri ) {
2 error( "Couldn't find the example.pri file!" )
3 }
4 TARGET = stackedbarchartdrilldown
5 SOURCES += main.cpp \
6 chartwidget.cpp
7 HEADERS += \
8 chartwidget.h
9
@@ -1,76 +1,82
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qbarseries.h>
4 #include <qbarseries.h>
5 #include <qbarset.h>
5 #include <qbarset.h>
6 #include <qchartaxis.h>
6 #include <qchartaxis.h>
7 #include <QStringList>
7 #include <QStringList>
8
8
9 QTCOMMERCIALCHART_USE_NAMESPACE
9 QTCOMMERCIALCHART_USE_NAMESPACE
10
10
11 int main(int argc, char *argv[])
11 int main(int argc, char *argv[])
12 {
12 {
13 QApplication a(argc, argv);
13 QApplication a(argc, argv);
14 QMainWindow window;
14 QMainWindow window;
15
15
16 //! [1]
16 //! [1]
17 // Define categories
17 // Define categories
18 QStringList categories;
18 QStringList categories;
19 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
19 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
20 //! [1]
20 //! [1]
21
21
22 //! [2]
22 //! [2]
23 // Create some test sets for chat
23 // Create some test sets for chat
24
24
25 QBarSet *set0 = new QBarSet("Bub");
25 QBarSet *set0 = new QBarSet("Bub");
26 QBarSet *set1 = new QBarSet("Bob");
26 QBarSet *set1 = new QBarSet("Bob");
27 QBarSet *set2 = new QBarSet("Guybrush");
27 QBarSet *set2 = new QBarSet("Guybrush");
28 QBarSet *set3 = new QBarSet("Larry");
28 QBarSet *set3 = new QBarSet("Larry");
29 QBarSet *set4 = new QBarSet("Zak");
29 QBarSet *set4 = new QBarSet("Zak");
30
30
31 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
31 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
32 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
32 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
33 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
33 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
34 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
34 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
35 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
35 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
36 //! [2]
36 //! [2]
37
37
38 //! [3]
38 //! [3]
39 // Create series and add sets to it
39 // Create series and add sets to it
40 QBarSeries* series= new QBarSeries(categories);
40 QBarSeries* series= new QBarSeries(categories);
41
41
42 series->addBarSet(set0);
42 series->addBarSet(set0);
43 series->addBarSet(set1);
43 series->addBarSet(set1);
44 series->addBarSet(set2);
44 series->addBarSet(set2);
45 series->addBarSet(set3);
45 series->addBarSet(set3);
46 series->addBarSet(set4);
46 series->addBarSet(set4);
47 //! [3]
47 //! [3]
48
48
49 //! [4]
49 //! [4]
50 // Enable some features
50 // Enable tooltip
51 series->setToolTipEnabled();
51 series->setToolTipEnabled();
52 series->setFloatingValuesEnabled();
52
53 // Connect clicked signal of set to toggle floating values of set.
54 // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values.
55 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
53 //! [4]
59 //! [4]
54
60
55 //! [5]
61 //! [5]
56 // Create view for chart and add series to it. Apply theme.
62 // Create view for chart and add series to it. Apply theme.
57
63
58 QChartView* chartView = new QChartView(&window);
64 QChartView* chartView = new QChartView(&window);
59 chartView->addSeries(series);
65 chartView->addSeries(series);
60 chartView->setChartTitle("simple barchart");
66 chartView->setChartTitle("simple barchart");
61 chartView->setChartTheme(QChart::ChartThemeIcy);
67 chartView->setChartTheme(QChart::ChartThemeIcy);
62 //! [5]
68 //! [5]
63
69
64 //! [6]
70 //! [6]
65 chartView->axisX()->setAxisVisible(false);
71 chartView->axisX()->setAxisVisible(false);
66 chartView->axisX()->setGridVisible(false);
72 chartView->axisX()->setGridVisible(false);
67 chartView->axisX()->setLabelsVisible(false);
73 chartView->axisX()->setLabelsVisible(false);
68 //! [6]
74 //! [6]
69
75
70 window.setCentralWidget(chartView);
76 window.setCentralWidget(chartView);
71 window.resize(400, 300);
77 window.resize(400, 300);
72 window.show();
78 window.show();
73
79
74 return a.exec();
80 return a.exec();
75 }
81 }
76
82
@@ -1,18 +1,19
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 SUBDIRS += linechart \
2 SUBDIRS += linechart \
3 zoomlinechart \
3 zoomlinechart \
4 colorlinechart \
4 colorlinechart \
5 barchart \
5 barchart \
6 stackedbarchart \
6 stackedbarchart \
7 percentbarchart \
7 percentbarchart \
8 scatter \
8 scatter \
9 piechart \
9 piechart \
10 piechartdrilldown \
10 piechartdrilldown \
11 dynamiclinechart \
11 dynamiclinechart \
12 axischart \
12 axischart \
13 multichart \
13 multichart \
14 gdpbarchart \
14 gdpbarchart \
15 presenterchart \
15 presenterchart \
16 chartview \
16 chartview \
17 scatterinteractions \
17 scatterinteractions \
18 areachart
18 areachart \
19 stackedbarchartdrilldown
@@ -1,76 +1,82
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <QStandardItemModel>
3 #include <QStandardItemModel>
4 #include <qpercentbarseries.h>
4 #include <qpercentbarseries.h>
5 #include <qchartview.h>
5 #include <qchartview.h>
6 #include <qbarset.h>
6 #include <qbarset.h>
7 #include <qchartaxis.h>
7 #include <qchartaxis.h>
8 #include <QStringList>
8 #include <QStringList>
9
9
10 QTCOMMERCIALCHART_USE_NAMESPACE
10 QTCOMMERCIALCHART_USE_NAMESPACE
11
11
12 int main(int argc, char *argv[])
12 int main(int argc, char *argv[])
13 {
13 {
14 QApplication a(argc, argv);
14 QApplication a(argc, argv);
15 QMainWindow window;
15 QMainWindow window;
16
16
17 //! [1]
17 //! [1]
18 // Define categories
18 // Define categories
19 QStringList categories;
19 QStringList categories;
20 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
20 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
21 //! [1]
21 //! [1]
22
22
23 //! [2]
23 //! [2]
24 // Create some test sets for chat
24 // Create some test sets for chat
25 QBarSet *set0 = new QBarSet("Bub");
25 QBarSet *set0 = new QBarSet("Bub");
26 QBarSet *set1 = new QBarSet("Bob");
26 QBarSet *set1 = new QBarSet("Bob");
27 QBarSet *set2 = new QBarSet("Guybrush");
27 QBarSet *set2 = new QBarSet("Guybrush");
28 QBarSet *set3 = new QBarSet("Larry");
28 QBarSet *set3 = new QBarSet("Larry");
29 QBarSet *set4 = new QBarSet("Zak");
29 QBarSet *set4 = new QBarSet("Zak");
30
30
31 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
31 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
32 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
32 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
33 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
33 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
34 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
34 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
35 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
35 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
36 //! [2]
36 //! [2]
37
37
38 //! [3]
38 //! [3]
39 // Create series and add sets to it
39 // Create series and add sets to it
40 QPercentBarSeries* series = new QPercentBarSeries(categories);
40 QPercentBarSeries* series = new QPercentBarSeries(categories);
41
41
42 series->addBarSet(set0);
42 series->addBarSet(set0);
43 series->addBarSet(set1);
43 series->addBarSet(set1);
44 series->addBarSet(set2);
44 series->addBarSet(set2);
45 series->addBarSet(set3);
45 series->addBarSet(set3);
46 series->addBarSet(set4);
46 series->addBarSet(set4);
47 //! [3]
47 //! [3]
48
48
49 //! [4]
49 //! [4]
50 // Enable features
50 // Enable tooltip
51 series->setToolTipEnabled();
51 series->setToolTipEnabled();
52 series->setFloatingValuesEnabled();
52
53 // Connect clicked signal of set to toggle floating values of set.
54 // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values.
55 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
53 //! [4]
59 //! [4]
54
60
55 //! [5]
61 //! [5]
56 // Create view for chart and add series to it. Apply theme.
62 // Create view for chart and add series to it. Apply theme.
57
63
58 QChartView* chartView = new QChartView(&window);
64 QChartView* chartView = new QChartView(&window);
59 chartView->addSeries(series);
65 chartView->addSeries(series);
60 chartView->setChartTitle("simple percent barchart");
66 chartView->setChartTitle("simple percent barchart");
61 chartView->setChartTheme(QChart::ChartThemeIcy);
67 chartView->setChartTheme(QChart::ChartThemeIcy);
62 //! [5]
68 //! [5]
63
69
64 //! [6]
70 //! [6]
65 chartView->axisX()->setAxisVisible(false);
71 chartView->axisX()->setAxisVisible(false);
66 chartView->axisX()->setGridVisible(false);
72 chartView->axisX()->setGridVisible(false);
67 chartView->axisX()->setLabelsVisible(false);
73 chartView->axisX()->setLabelsVisible(false);
68 //! [6]
74 //! [6]
69
75
70 window.setCentralWidget(chartView);
76 window.setCentralWidget(chartView);
71 window.resize(400, 300);
77 window.resize(400, 300);
72 window.show();
78 window.show();
73
79
74 return a.exec();
80 return a.exec();
75 }
81 }
76
82
@@ -1,75 +1,81
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qstackedbarseries.h>
4 #include <qstackedbarseries.h>
5 #include <qbarset.h>
5 #include <qbarset.h>
6 #include <qchartaxis.h>
6 #include <qchartaxis.h>
7 #include <QStringList>
7 #include <QStringList>
8
8
9 QTCOMMERCIALCHART_USE_NAMESPACE
9 QTCOMMERCIALCHART_USE_NAMESPACE
10
10
11 int main(int argc, char *argv[])
11 int main(int argc, char *argv[])
12 {
12 {
13 QApplication a(argc, argv);
13 QApplication a(argc, argv);
14 QMainWindow window;
14 QMainWindow window;
15
15
16 //! [1]
16 //! [1]
17 // Define categories
17 // Define categories
18 QStringList categories;
18 QStringList categories;
19 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
19 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
20 //! [1]
20 //! [1]
21
21
22 //! [2]
22 //! [2]
23 // Create some test sets for chat
23 // Create some test sets for chat
24 QBarSet *set0 = new QBarSet("Bub");
24 QBarSet *set0 = new QBarSet("Bub");
25 QBarSet *set1 = new QBarSet("Bob");
25 QBarSet *set1 = new QBarSet("Bob");
26 QBarSet *set2 = new QBarSet("Guybrush");
26 QBarSet *set2 = new QBarSet("Guybrush");
27 QBarSet *set3 = new QBarSet("Larry");
27 QBarSet *set3 = new QBarSet("Larry");
28 QBarSet *set4 = new QBarSet("Zak");
28 QBarSet *set4 = new QBarSet("Zak");
29
29
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
30 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
31 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
31 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
32 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
32 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
33 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
33 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
34 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
34 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
35 //! [2]
35 //! [2]
36
36
37 //! [3]
37 //! [3]
38 // Create series and add sets to it
38 // Create series and add sets to it
39 QStackedBarSeries* series = new QStackedBarSeries(categories);
39 QStackedBarSeries* series = new QStackedBarSeries(categories);
40
40
41 series->addBarSet(set0);
41 series->addBarSet(set0);
42 series->addBarSet(set1);
42 series->addBarSet(set1);
43 series->addBarSet(set2);
43 series->addBarSet(set2);
44 series->addBarSet(set3);
44 series->addBarSet(set3);
45 series->addBarSet(set4);
45 series->addBarSet(set4);
46 //! [3]
46 //! [3]
47
47
48 //! [4]
48 //! [4]
49 // Enable features
49 // Enable tooltip
50 series->setToolTipEnabled();
50 series->setToolTipEnabled();
51 series->setFloatingValuesEnabled();
51
52 // Connect clicked signal of set to toggle floating values of set.
53 // Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values.
54 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
55 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
52 //! [4]
58 //! [4]
53
59
54 //! [5]
60 //! [5]
55 // Create view for chart and add series to it. Apply theme.
61 // Create view for chart and add series to it. Apply theme.
56
62
57 QChartView* chartView = new QChartView(&window);
63 QChartView* chartView = new QChartView(&window);
58 chartView->addSeries(series);
64 chartView->addSeries(series);
59 chartView->setChartTitle("simple stacked barchart");
65 chartView->setChartTitle("simple stacked barchart");
60 chartView->setChartTheme(QChart::ChartThemeIcy);
66 chartView->setChartTheme(QChart::ChartThemeIcy);
61 //! [5]
67 //! [5]
62
68
63 //! [6]
69 //! [6]
64 chartView->axisX()->setAxisVisible(false);
70 chartView->axisX()->setAxisVisible(false);
65 chartView->axisX()->setGridVisible(false);
71 chartView->axisX()->setGridVisible(false);
66 chartView->axisX()->setLabelsVisible(false);
72 chartView->axisX()->setLabelsVisible(false);
67 //! [6]
73 //! [6]
68
74
69 window.setCentralWidget(chartView);
75 window.setCentralWidget(chartView);
70 window.resize(400, 300);
76 window.resize(400, 300);
71 window.show();
77 window.show();
72
78
73 return a.exec();
79 return a.exec();
74 }
80 }
75
81
@@ -1,88 +1,89
1 #include "bar_p.h"
1 #include "bar_p.h"
2 #include <QDebug>
2 #include <QDebug>
3 #include <QPainter>
3 #include <QPainter>
4 #include <QGraphicsSceneEvent>
4 #include <QGraphicsSceneEvent>
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 Bar::Bar(QGraphicsItem *parent)
8 Bar::Bar(QString category, QGraphicsItem *parent)
9 : QGraphicsObject(parent)
9 : QGraphicsObject(parent)
10 ,mCategory(category)
10 {
11 {
11 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
12 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
12 setAcceptHoverEvents(true);
13 setAcceptHoverEvents(true);
13 }
14 }
14
15
15 void Bar::setSize(const QSizeF& size)
16 void Bar::setSize(const QSizeF& size)
16 {
17 {
17 mWidth = size.width();
18 mWidth = size.width();
18 mHeight = size.height();
19 mHeight = size.height();
19 }
20 }
20
21
21
22
22 void Bar::resize( qreal w, qreal h )
23 void Bar::resize( qreal w, qreal h )
23 {
24 {
24 mWidth = w;
25 mWidth = w;
25 mHeight = h;
26 mHeight = h;
26 }
27 }
27
28
28 void Bar::setPos(qreal x, qreal y)
29 void Bar::setPos(qreal x, qreal y)
29 {
30 {
30 mXpos = x;
31 mXpos = x;
31 mYpos = y;
32 mYpos = y;
32 }
33 }
33
34
34 void Bar::setPen(QPen pen)
35 void Bar::setPen(QPen pen)
35 {
36 {
36 mPen = pen;
37 mPen = pen;
37 }
38 }
38
39
39 void Bar::setBrush(QBrush brush)
40 void Bar::setBrush(QBrush brush)
40 {
41 {
41 mBrush = brush;
42 mBrush = brush;
42 }
43 }
43
44
44 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
45 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
45 {
46 {
46 if (0 == mHeight) {
47 if (0 == mHeight) {
47 return;
48 return;
48 }
49 }
49 painter->setBrush(mBrush);
50 painter->setBrush(mBrush);
50
51
51 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
52 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
52 int x0 = mXpos;
53 int x0 = mXpos;
53 int x1 = (mXpos + mWidth);
54 int x1 = (mXpos + mWidth);
54 int w = x1-x0;
55 int w = x1-x0;
55 int y0 = mYpos;
56 int y0 = mYpos;
56 int y1 = (mYpos + mHeight);
57 int y1 = (mYpos + mHeight);
57 int h = y1-y0;
58 int h = y1-y0;
58 painter->drawRect(x0, y0 ,w ,h);
59 painter->drawRect(x0, y0 ,w ,h);
59 }
60 }
60
61
61 QRectF Bar::boundingRect() const
62 QRectF Bar::boundingRect() const
62 {
63 {
63 QRectF r(mXpos, mYpos, mWidth, mHeight);
64 QRectF r(mXpos, mYpos, mWidth, mHeight);
64 return r;
65 return r;
65 }
66 }
66
67
67 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event)
68 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* event)
68 {
69 {
69 if (event->button() == Qt::LeftButton) {
70 if (event->button() == Qt::LeftButton) {
70 emit clicked();
71 emit clicked(mCategory);
71 } else if (event->button() == Qt::RightButton) {
72 } else if (event->button() == Qt::RightButton) {
72 emit rightClicked();
73 emit rightClicked(mCategory);
73 }
74 }
74 }
75 }
75
76
76 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
77 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
77 {
78 {
78 emit hoverEntered(event->lastScreenPos());
79 emit hoverEntered(event->lastScreenPos());
79 }
80 }
80
81
81 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
82 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
82 {
83 {
83 emit hoverLeaved();
84 emit hoverLeaved();
84 }
85 }
85
86
86 #include "moc_bar_p.cpp"
87 #include "moc_bar_p.cpp"
87
88
88 QTCOMMERCIALCHART_END_NAMESPACE
89 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,55 +1,56
1 #ifndef BAR_H
1 #ifndef BAR_H
2 #define BAR_H
2 #define BAR_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QGraphicsObject>
5 #include <QGraphicsObject>
6 #include <QPen>
6 #include <QPen>
7 #include <QBrush>
7 #include <QBrush>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 // Single visual bar item of chart
11 // Single visual bar item of chart
12 class Bar : public QGraphicsObject
12 class Bar : public QGraphicsObject
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 Bar(QGraphicsItem *parent=0);
16 Bar(QString category, QGraphicsItem *parent=0);
17
17
18 public: // from ChartItem
18 public: // from ChartItem
19 void setSize(const QSizeF &size);
19 void setSize(const QSizeF &size);
20
20
21 // Layout Stuff
21 // Layout Stuff
22 void resize(qreal w, qreal h);
22 void resize(qreal w, qreal h);
23 void setPos(qreal x, qreal y);
23 void setPos(qreal x, qreal y);
24 void setPen(QPen pen);
24 void setPen(QPen pen);
25 void setBrush(QBrush brush);
25 void setBrush(QBrush brush);
26
26
27 public:
27 public:
28 // From QGraphicsItem
28 // From QGraphicsItem
29 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
29 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
30 QRectF boundingRect() const;
30 QRectF boundingRect() const;
31 void mousePressEvent(QGraphicsSceneMouseEvent *event);
31 void mousePressEvent(QGraphicsSceneMouseEvent *event);
32 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
32 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
33 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
33 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
34
34
35 Q_SIGNALS:
35 Q_SIGNALS:
36 void clicked();
36 void clicked(QString category);
37 void rightClicked();
37 void rightClicked(QString category);
38 void hoverEntered(QPoint pos);
38 void hoverEntered(QPoint pos);
39 void hoverLeaved();
39 void hoverLeaved();
40
40
41 private:
41 private:
42
42
43 qreal mHeight;
43 qreal mHeight;
44 qreal mWidth;
44 qreal mWidth;
45 qreal mXpos;
45 qreal mXpos;
46 qreal mYpos;
46 qreal mYpos;
47
47
48 QBrush mBrush;
48 QBrush mBrush;
49 QPen mPen;
49 QPen mPen;
50
50
51 QString mCategory;
51 };
52 };
52
53
53 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
54
55
55 #endif // BAR_H
56 #endif // BAR_H
@@ -1,37 +1,35
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/bar.cpp \
5 $$PWD/bar.cpp \
6 $$PWD/barchartmodel.cpp \
6 $$PWD/barchartmodel.cpp \
7 $$PWD/barlabel.cpp \
7 $$PWD/barlabel.cpp \
8 $$PWD/barpresenter.cpp \
8 $$PWD/barpresenter.cpp \
9 $$PWD/barpresenterbase.cpp \
9 $$PWD/barpresenterbase.cpp \
10 $$PWD/percentbarpresenter.cpp \
10 $$PWD/percentbarpresenter.cpp \
11 $$PWD/qbarseries.cpp \
11 $$PWD/qbarseries.cpp \
12 $$PWD/qbarset.cpp \
12 $$PWD/qbarset.cpp \
13 $$PWD/qpercentbarseries.cpp \
13 $$PWD/qpercentbarseries.cpp \
14 $$PWD/qstackedbarseries.cpp \
14 $$PWD/qstackedbarseries.cpp \
15 $$PWD/separator.cpp \
15 $$PWD/separator.cpp \
16 $$PWD/stackedbarpresenter.cpp \
16 $$PWD/stackedbarpresenter.cpp \
17 $$PWD/barvalue.cpp \
17 $$PWD/barvalue.cpp
18 $$PWD/barcategory.cpp
19
18
20 PRIVATE_HEADERS += \
19 PRIVATE_HEADERS += \
21 $$PWD/bar_p.h \
20 $$PWD/bar_p.h \
22 $$PWD/barchartmodel_p.h \
21 $$PWD/barchartmodel_p.h \
23 $$PWD/barlabel_p.h \
22 $$PWD/barlabel_p.h \
24 $$PWD/barpresenter_p.h \
23 $$PWD/barpresenter_p.h \
25 $$PWD/barpresenterbase_p.h \
24 $$PWD/barpresenterbase_p.h \
26 $$PWD/percentbarpresenter_p.h \
25 $$PWD/percentbarpresenter_p.h \
27 $$PWD/separator_p.h \
26 $$PWD/separator_p.h \
28 $$PWD/stackedbarpresenter_p.h \
27 $$PWD/stackedbarpresenter_p.h \
29 $$PWD/barvalue_p.h \
28 $$PWD/barvalue_p.h
30 $$PWD/barcategory_p.h
31
29
32 PUBLIC_HEADERS += \
30 PUBLIC_HEADERS += \
33 $$PWD/qbarseries.h \
31 $$PWD/qbarseries.h \
34 $$PWD/qbarset.h \
32 $$PWD/qbarset.h \
35 $$PWD/qpercentbarseries.h \
33 $$PWD/qpercentbarseries.h \
36 $$PWD/qstackedbarseries.h
34 $$PWD/qstackedbarseries.h
37
35
@@ -1,182 +1,172
1 #include <limits.h>
1 #include <limits.h>
2 #include <QVector>
2 #include <QVector>
3 #include <QDebug>
3 #include <QDebug>
4 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
5 #include "barcategory_p.h"
6 #include "qbarset.h"
5 #include "qbarset.h"
7
6
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
8
10 BarChartModel::BarChartModel(QStringList categories, QObject *parent) :
9 BarChartModel::BarChartModel(QStringList categories, QObject *parent) :
11 QObject(parent)
10 QObject(parent)
12 ,mCategory(categories)
11 ,mCategory(categories)
13 {
12 {
14 for (int i=0; i<mCategory.count(); i++) {
15 BarCategory* cat = new BarCategory(mCategory.at(i), this);
16 mCategoryObjects.append(cat);
17 }
18 }
13 }
19
14
20 QStringList BarChartModel::category()
15 QStringList BarChartModel::category()
21 {
16 {
22 return mCategory;
17 return mCategory;
23 }
18 }
24
19
25 void BarChartModel::addBarSet(QBarSet *set)
20 void BarChartModel::addBarSet(QBarSet *set)
26 {
21 {
27 mDataModel.append(set);
22 mDataModel.append(set);
28 }
23 }
29
24
30 void BarChartModel::removeBarSet(QBarSet *set)
25 void BarChartModel::removeBarSet(QBarSet *set)
31 {
26 {
32 if (mDataModel.contains(set)) {
27 if (mDataModel.contains(set)) {
33 mDataModel.removeOne(set);
28 mDataModel.removeOne(set);
34 }
29 }
35 }
30 }
36
31
37 QBarSet* BarChartModel::setAt(int index)
32 QBarSet* BarChartModel::setAt(int index)
38 {
33 {
39 return mDataModel.at(index);
34 return mDataModel.at(index);
40 }
35 }
41
36
42 QList<QBarSet*> BarChartModel::barSets()
37 QList<QBarSet*> BarChartModel::barSets()
43 {
38 {
44 return mDataModel;
39 return mDataModel;
45 }
40 }
46
41
47 QList<QSeries::Legend> BarChartModel::legend()
42 QList<QSeries::Legend> BarChartModel::legend()
48 {
43 {
49 QList<QSeries::Legend> legend;
44 QList<QSeries::Legend> legend;
50
45
51 for (int i=0; i<mDataModel.count(); i++) {
46 for (int i=0; i<mDataModel.count(); i++) {
52 QSeries::Legend l;
47 QSeries::Legend l;
53 l.mName = mDataModel.at(i)->name();
48 l.mName = mDataModel.at(i)->name();
54 l.mPen = mDataModel.at(i)->pen();
49 l.mPen = mDataModel.at(i)->pen();
55 legend.append(l);
50 legend.append(l);
56 }
51 }
57 return legend;
52 return legend;
58 }
53 }
59
54
60 int BarChartModel::barsetCount()
55 int BarChartModel::barsetCount()
61 {
56 {
62 return mDataModel.count();
57 return mDataModel.count();
63 }
58 }
64
59
65 int BarChartModel::categoryCount()
60 int BarChartModel::categoryCount()
66 {
61 {
67 return mCategory.count();
62 return mCategory.count();
68 }
63 }
69
64
70 qreal BarChartModel::min()
65 qreal BarChartModel::min()
71 {
66 {
72 Q_ASSERT(mDataModel.count() > 0);
67 Q_ASSERT(mDataModel.count() > 0);
73 // TODO: make min and max members and update them when data changes.
68 // TODO: make min and max members and update them when data changes.
74 // This is slower since they are checked every time, even if data is same since previous call.
69 // This is slower since they are checked every time, even if data is same since previous call.
75 qreal min = INT_MAX;
70 qreal min = INT_MAX;
76
71
77 for (int i=0; i <mDataModel.count(); i++) {
72 for (int i=0; i <mDataModel.count(); i++) {
78 int itemCount = mDataModel.at(i)->count();
73 int itemCount = mDataModel.at(i)->count();
79 for (int j=0; j<itemCount; j++) {
74 for (int j=0; j<itemCount; j++) {
80 qreal temp = mDataModel.at(i)->valueAt(j);
75 qreal temp = mDataModel.at(i)->valueAt(j);
81 if (temp < min) {
76 if (temp < min) {
82 min = temp;
77 min = temp;
83 }
78 }
84 }
79 }
85 }
80 }
86 return min;
81 return min;
87 }
82 }
88
83
89 qreal BarChartModel::max()
84 qreal BarChartModel::max()
90 {
85 {
91 Q_ASSERT(mDataModel.count() > 0);
86 Q_ASSERT(mDataModel.count() > 0);
92
87
93 // TODO: make min and max members and update them when data changes.
88 // TODO: make min and max members and update them when data changes.
94 // This is slower since they are checked every time, even if data is same since previous call.
89 // This is slower since they are checked every time, even if data is same since previous call.
95 qreal max = INT_MIN;
90 qreal max = INT_MIN;
96
91
97 for (int i=0; i <mDataModel.count(); i++) {
92 for (int i=0; i <mDataModel.count(); i++) {
98 int itemCount = mDataModel.at(i)->count();
93 int itemCount = mDataModel.at(i)->count();
99 for (int j=0; j<itemCount; j++) {
94 for (int j=0; j<itemCount; j++) {
100 qreal temp = mDataModel.at(i)->valueAt(j);
95 qreal temp = mDataModel.at(i)->valueAt(j);
101 if (temp > max) {
96 if (temp > max) {
102 max = temp;
97 max = temp;
103 }
98 }
104 }
99 }
105 }
100 }
106
101
107 return max;
102 return max;
108 }
103 }
109
104
110 qreal BarChartModel::valueAt(int set, int category)
105 qreal BarChartModel::valueAt(int set, int category)
111 {
106 {
112 if ((set < 0) || (set >= mDataModel.count())) {
107 if ((set < 0) || (set >= mDataModel.count())) {
113 // No set, no value.
108 // No set, no value.
114 return 0;
109 return 0;
115 } else if ((category < 0) || (category >= mDataModel.at(set)->count())) {
110 } else if ((category < 0) || (category >= mDataModel.at(set)->count())) {
116 // No category, no value.
111 // No category, no value.
117 return 0;
112 return 0;
118 }
113 }
119
114
120 return mDataModel.at(set)->valueAt(category);
115 return mDataModel.at(set)->valueAt(category);
121 }
116 }
122
117
123 qreal BarChartModel::percentageAt(int set, int category)
118 qreal BarChartModel::percentageAt(int set, int category)
124 {
119 {
125 if ((set < 0) || (set >= mDataModel.count())) {
120 if ((set < 0) || (set >= mDataModel.count())) {
126 // No set, no value.
121 // No set, no value.
127 return 0;
122 return 0;
128 } else if ((category < 0) || (category >= mDataModel.at(set)->count())) {
123 } else if ((category < 0) || (category >= mDataModel.at(set)->count())) {
129 // No category, no value.
124 // No category, no value.
130 return 0;
125 return 0;
131 }
126 }
132
127
133 qreal value = mDataModel.at(set)->valueAt(category);
128 qreal value = mDataModel.at(set)->valueAt(category);
134 qreal total = categorySum(category);
129 qreal total = categorySum(category);
135 if (0 == total) {
130 if (0 == total) {
136 return 100.0;
131 return 100.0;
137 }
132 }
138
133
139 return value / total;
134 return value / total;
140 }
135 }
141
136
142
137
143 qreal BarChartModel::categorySum(int category)
138 qreal BarChartModel::categorySum(int category)
144 {
139 {
145 qreal sum(0);
140 qreal sum(0);
146 int count = mDataModel.count(); // Count sets
141 int count = mDataModel.count(); // Count sets
147
142
148 for (int set = 0; set < count; set++) {
143 for (int set = 0; set < count; set++) {
149 if (category < mDataModel.at(set)->count()) {
144 if (category < mDataModel.at(set)->count()) {
150 sum += mDataModel.at(set)->valueAt(category);
145 sum += mDataModel.at(set)->valueAt(category);
151 }
146 }
152 }
147 }
153 return sum;
148 return sum;
154 }
149 }
155
150
156 qreal BarChartModel::maxCategorySum()
151 qreal BarChartModel::maxCategorySum()
157 {
152 {
158 qreal max = INT_MIN;
153 qreal max = INT_MIN;
159 int count = categoryCount();
154 int count = categoryCount();
160
155
161 for (int col=0; col<count; col++) {
156 for (int col=0; col<count; col++) {
162 qreal sum = categorySum(col);
157 qreal sum = categorySum(col);
163 if (sum > max) {
158 if (sum > max) {
164 max = sum;
159 max = sum;
165 }
160 }
166 }
161 }
167 return max;
162 return max;
168 }
163 }
169
164
170 QString BarChartModel::categoryName(int category)
165 QString BarChartModel::categoryName(int category)
171 {
166 {
172 return mCategory.at(category);
167 return mCategory.at(category);
173 }
168 }
174
169
175 BarCategory* BarChartModel::categoryObject(int category)
176 {
177 return mCategoryObjects.at(category);
178 }
179
180 #include "moc_barchartmodel_p.cpp"
170 #include "moc_barchartmodel_p.cpp"
181
171
182 QTCOMMERCIALCHART_END_NAMESPACE
172 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,62 +1,59
1 #ifndef BARCHARTMODEL_H
1 #ifndef BARCHARTMODEL_H
2 #define BARCHARTMODEL_H
2 #define BARCHARTMODEL_H
3
3
4 #include <QObject>
4 #include <QObject>
5 #include <QStringList>
5 #include <QStringList>
6 #include "qchartglobal.h"
6 #include "qchartglobal.h"
7 #include <qseries.h>
7 #include <qseries.h>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 // Model for bar chart. Internal class.
11 // Model for bar chart. Internal class.
12 // TODO: Implement as QAbstractItemModel?
12 // TODO: Implement as QAbstractItemModel?
13
13
14 class QBarSet;
14 class QBarSet;
15 class BarCategory;
16
15
17 class BarChartModel : public QObject //, public QAbstractItemModel
16 class BarChartModel : public QObject //, public QAbstractItemModel
18 {
17 {
19 Q_OBJECT
18 Q_OBJECT
20 public:
19 public:
21 explicit BarChartModel(QStringList categories, QObject *parent = 0);
20 explicit BarChartModel(QStringList categories, QObject *parent = 0);
22
21
23 QStringList category();
22 QStringList category();
24 void addBarSet(QBarSet *set);
23 void addBarSet(QBarSet *set);
25 void removeBarSet(QBarSet *set);
24 void removeBarSet(QBarSet *set);
26 QBarSet *setAt(int index);
25 QBarSet *setAt(int index);
27 QList<QBarSet*> barSets();
26 QList<QBarSet*> barSets();
28
27
29 QList<QSeries::Legend> legend();
28 QList<QSeries::Legend> legend();
30
29
31 int barsetCount(); // Number of sets in model
30 int barsetCount(); // Number of sets in model
32 int categoryCount(); // Number of categories
31 int categoryCount(); // Number of categories
33
32
34 qreal max(); // Maximum value of all sets
33 qreal max(); // Maximum value of all sets
35 qreal min(); // Minimum value of all sets
34 qreal min(); // Minimum value of all sets
36 qreal valueAt(int set, int category);
35 qreal valueAt(int set, int category);
37 qreal percentageAt(int set, int category);
36 qreal percentageAt(int set, int category);
38
37
39 qreal categorySum(int category);
38 qreal categorySum(int category);
40 qreal maxCategorySum(); // returns maximum sum of sets in all categories.
39 qreal maxCategorySum(); // returns maximum sum of sets in all categories.
41
40
42 QString categoryName(int category);
41 QString categoryName(int category);
43 BarCategory* categoryObject(int category);
44
42
45 signals:
43 signals:
46 void modelUpdated();
44 void modelUpdated();
47
45
48 public slots:
46 public slots:
49
47
50 private:
48 private:
51
49
52 QList<QBarSet*> mDataModel;
50 QList<QBarSet*> mDataModel;
53 QStringList mCategory;
51 QStringList mCategory;
54 QList<BarCategory*> mCategoryObjects;
55
52
56 int mCurrentSet;
53 int mCurrentSet;
57
54
58 };
55 };
59
56
60 QTCOMMERCIALCHART_END_NAMESPACE
57 QTCOMMERCIALCHART_END_NAMESPACE
61
58
62 #endif // BARCHARTMODEL_H
59 #endif // BARCHARTMODEL_H
@@ -1,161 +1,160
1 #include "barpresenterbase_p.h"
1 #include "barpresenterbase_p.h"
2 #include "bar_p.h"
2 #include "bar_p.h"
3 #include "barvalue_p.h"
3 #include "barvalue_p.h"
4 #include "barlabel_p.h"
4 #include "barlabel_p.h"
5 #include "separator_p.h"
5 #include "separator_p.h"
6 #include "barcategory_p.h"
7 #include "qbarset.h"
6 #include "qbarset.h"
8 #include "qbarseries.h"
7 #include "qbarseries.h"
9 #include <QDebug>
8 #include <QDebug>
10 #include <QToolTip>
9 #include <QToolTip>
11
10
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
12
14 BarPresenterBase::BarPresenterBase(QBarSeries *series, QGraphicsItem *parent)
13 BarPresenterBase::BarPresenterBase(QBarSeries *series, QGraphicsItem *parent)
15 : ChartItem(parent)
14 : ChartItem(parent)
16 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
15 ,mBarDefaultWidth(20) // TODO: remove hard coding, when we have layout code ready
17 ,mLayoutSet(false)
16 ,mLayoutSet(false)
18 ,mLayoutDirty(true)
17 ,mLayoutDirty(true)
19 ,mSeparatorsEnabled(false)
18 ,mSeparatorsEnabled(false)
20 ,mSeries(series)
19 ,mSeries(series)
21 {
20 {
22 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
21 connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString)));
23 connect(series,SIGNAL(separatorsEnabled(bool)),this,SLOT(enableSeparators(bool)));
22 // connect(series,SIGNAL(separatorsEnabled(bool)),this,SLOT(enableSeparators(bool)));
24 dataChanged();
23 dataChanged();
25 }
24 }
26
25
27 BarPresenterBase::~BarPresenterBase()
26 BarPresenterBase::~BarPresenterBase()
28 {
27 {
29 disconnect(this,SLOT(showToolTip(QPoint,QString)));
28 disconnect(this,SLOT(showToolTip(QPoint,QString)));
30 delete mSeries;
29 delete mSeries;
31 }
30 }
32
31
33 void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
32 void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
34 {
33 {
35 if (!mLayoutSet) {
34 if (!mLayoutSet) {
36 qDebug() << "BarPresenterBase::paint called without layout set. Aborting.";
35 qDebug() << "BarPresenterBase::paint called without layout set. Aborting.";
37 return;
36 return;
38 }
37 }
39 // if (mLayoutDirty) {
38 // if (mLayoutDirty) {
40 // Layout or data has changed. Need to redraw.
39 // Layout or data has changed. Need to redraw.
41 foreach(QGraphicsItem* i, childItems()) {
40 foreach(QGraphicsItem* i, childItems()) {
42 i->paint(painter,option,widget);
41 i->paint(painter,option,widget);
43 }
42 }
44 // }
43 // }
45 }
44 }
46
45
47 QRectF BarPresenterBase::boundingRect() const
46 QRectF BarPresenterBase::boundingRect() const
48 {
47 {
49 return QRectF(0,0,mWidth,mHeight);
48 return QRectF(0,0,mWidth,mHeight);
50 }
49 }
51
50
52 void BarPresenterBase::setBarWidth( int w )
51 void BarPresenterBase::setBarWidth( int w )
53 {
52 {
54 mBarDefaultWidth = w;
53 mBarDefaultWidth = w;
55 }
54 }
56
55
57 void BarPresenterBase::dataChanged()
56 void BarPresenterBase::dataChanged()
58 {
57 {
59 // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
58 // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them?
60 // qDebug() << "datachanged";
59 // qDebug() << "datachanged";
61 // Delete old bars
60 // Delete old bars
62 foreach (QGraphicsItem* item, childItems()) {
61 foreach (QGraphicsItem* item, childItems()) {
63 delete item;
62 delete item;
64 }
63 }
65
64
66 mBars.clear();
65 mBars.clear();
67 mLabels.clear();
66 mLabels.clear();
68 mSeparators.clear();
67 mSeparators.clear();
69 mFloatingValues.clear();
68 mFloatingValues.clear();
70
69
71 // Create new graphic items for bars
70 // Create new graphic items for bars
72 for (int c=0; c<mSeries->categoryCount(); c++) {
71 for (int c=0; c<mSeries->categoryCount(); c++) {
73 BarCategory *category = mSeries->categoryObject(c);
72 QString category = mSeries->categoryName(c);
74 for (int s=0; s<mSeries->barsetCount(); s++) {
73 for (int s=0; s<mSeries->barsetCount(); s++) {
75 QBarSet *set = mSeries->barsetAt(s);
74 QBarSet *set = mSeries->barsetAt(s);
76 Bar *bar = new Bar(this);
75 Bar *bar = new Bar(category,this);
77 childItems().append(bar);
76 childItems().append(bar);
78 mBars.append(bar);
77 mBars.append(bar);
79 connect(bar,SIGNAL(clicked()),set,SLOT(barClickedEvent()));
78 connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString)));
80 connect(bar,SIGNAL(rightClicked()),category,SLOT(barRightClickEvent()));
79 connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString)));
81 connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint)));
80 connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint)));
82 connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent()));
81 connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent()));
83 }
82 }
84 }
83 }
85
84
86 // Create labels
85 // Create labels
87 int count = mSeries->categoryCount();
86 int count = mSeries->categoryCount();
88 for (int i=0; i<count; i++) {
87 for (int i=0; i<count; i++) {
89 BarLabel* label = new BarLabel(this);
88 BarLabel* label = new BarLabel(this);
90 label->set(mSeries->categoryName(i));
89 label->set(mSeries->categoryName(i));
91 childItems().append(label);
90 childItems().append(label);
92 mLabels.append(label);
91 mLabels.append(label);
93 }
92 }
94
93
95 // Create separators
94 // Create separators
96 count = mSeries->categoryCount() - 1; // There is one less separator than columns
95 count = mSeries->categoryCount() - 1; // There is one less separator than columns
97 for (int i=0; i<count; i++) {
96 for (int i=0; i<count; i++) {
98 Separator* sep = new Separator(this);
97 Separator* sep = new Separator(this);
99 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
98 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
100 sep->setVisible(mSeparatorsEnabled);
99 sep->setVisible(mSeparatorsEnabled);
101 childItems().append(sep);
100 childItems().append(sep);
102 mSeparators.append(sep);
101 mSeparators.append(sep);
103 }
102 }
104
103
105 // Create floating values
104 // Create floating values
106 for (int category=0; category<mSeries->categoryCount(); category++) {
105 for (int category=0; category<mSeries->categoryCount(); category++) {
107 for (int s=0; s<mSeries->barsetCount(); s++) {
106 for (int s=0; s<mSeries->barsetCount(); s++) {
108 QBarSet *set = mSeries->barsetAt(s);
107 QBarSet *set = mSeries->barsetAt(s);
109 BarValue *value = new BarValue(*set, this);
108 BarValue *value = new BarValue(*set, this);
110 childItems().append(value);
109 childItems().append(value);
111 mFloatingValues.append(value);
110 mFloatingValues.append(value);
112 connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible()));
111 connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible()));
113 }
112 }
114 }
113 }
115
114
116 // TODO: if (autolayout) { layoutChanged() } or something
115 // TODO: if (autolayout) { layoutChanged() } or something
117 mLayoutDirty = true;
116 mLayoutDirty = true;
118 }
117 }
119
118
120 //handlers
119 //handlers
121
120
122 void BarPresenterBase::handleModelChanged(int index)
121 void BarPresenterBase::handleModelChanged(int index)
123 {
122 {
124 // qDebug() << "BarPresenterBase::handleModelChanged" << index;
123 // qDebug() << "BarPresenterBase::handleModelChanged" << index;
125 dataChanged();
124 dataChanged();
126 }
125 }
127
126
128 void BarPresenterBase::handleDomainChanged(const Domain& domain)
127 void BarPresenterBase::handleDomainChanged(const Domain& domain)
129 {
128 {
130 // qDebug() << "BarPresenterBase::handleDomainChanged";
129 // qDebug() << "BarPresenterBase::handleDomainChanged";
131 // TODO: Figure out the use case for this.
130 // TODO: Figure out the use case for this.
132 // Affects the size of visible item, so layout is changed.
131 // Affects the size of visible item, so layout is changed.
133 // layoutChanged();
132 // layoutChanged();
134 }
133 }
135
134
136 void BarPresenterBase::handleGeometryChanged(const QRectF& rect)
135 void BarPresenterBase::handleGeometryChanged(const QRectF& rect)
137 {
136 {
138 mWidth = rect.width();
137 mWidth = rect.width();
139 mHeight = rect.height();
138 mHeight = rect.height();
140 layoutChanged();
139 layoutChanged();
141 mLayoutSet = true;
140 mLayoutSet = true;
142 setPos(rect.topLeft());
141 setPos(rect.topLeft());
143 }
142 }
144
143
145 void BarPresenterBase::showToolTip(QPoint pos, QString tip)
144 void BarPresenterBase::showToolTip(QPoint pos, QString tip)
146 {
145 {
147 // TODO: cool tooltip instead of default
146 // TODO: cool tooltip instead of default
148 QToolTip::showText(pos,tip);
147 QToolTip::showText(pos,tip);
149 }
148 }
150
149
151 void BarPresenterBase::enableSeparators(bool enabled)
150 void BarPresenterBase::enableSeparators(bool enabled)
152 {
151 {
153 for (int i=0; i<mSeparators.count(); i++) {
152 for (int i=0; i<mSeparators.count(); i++) {
154 mSeparators.at(i)->setVisible(enabled);
153 mSeparators.at(i)->setVisible(enabled);
155 }
154 }
156 mSeparatorsEnabled = enabled;
155 mSeparatorsEnabled = enabled;
157 }
156 }
158
157
159 #include "moc_barpresenterbase_p.cpp"
158 #include "moc_barpresenterbase_p.cpp"
160
159
161 QTCOMMERCIALCHART_END_NAMESPACE
160 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,73 +1,66
1 #include "barvalue_p.h"
1 #include "barvalue_p.h"
2 #include <QPainter>
2 #include <QPainter>
3 #include <QPen>
3 #include <QPen>
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent)
7 BarValue::BarValue(QBarSet &set, QGraphicsItem *parent)
8 : QGraphicsObject(parent)
8 : QGraphicsObject(parent)
9 ,mBarSet(set)
9 ,mBarSet(set)
10 {
10 {
11 setVisible(false);
11 setVisible(false);
12 }
12 }
13
13
14 void BarValue::setValueString(QString str)
14 void BarValue::setValueString(QString str)
15 {
15 {
16 mValueString = str;
16 mValueString = str;
17 }
17 }
18
18
19 QString BarValue::valueString()
19 QString BarValue::valueString()
20 {
20 {
21 return mValueString;
21 return mValueString;
22 }
22 }
23
23
24 void BarValue::setPen(const QPen& pen)
24 void BarValue::setPen(const QPen& pen)
25 {
25 {
26 mPen = pen;
26 mPen = pen;
27 }
27 }
28
28
29 const QPen& BarValue::pen()
29 const QPen& BarValue::pen()
30 {
30 {
31 return mPen;
31 return mPen;
32 }
32 }
33
33
34 void BarValue::resize(qreal w, qreal h)
34 void BarValue::resize(qreal w, qreal h)
35 {
35 {
36 mWidth = w;
36 mWidth = w;
37 mHeight = h;
37 mHeight = h;
38 }
38 }
39
39
40 void BarValue::setPos(qreal x, qreal y)
40 void BarValue::setPos(qreal x, qreal y)
41 {
41 {
42 mXpos = x;
42 mXpos = x;
43 mYpos = y;
43 mYpos = y;
44 }
44 }
45
45
46 /*
47 bool BarValue::belongsToSet(QBarSet *set)
48 {
49 return (&mBarSet == set);
50 }
51 */
52
53 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
46 void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
54 {
47 {
55 if (isVisible()) {
48 if (isVisible()) {
56 painter->setPen(mPen);
49 painter->setPen(mPen);
57 painter->drawText(boundingRect(),mValueString);
50 painter->drawText(boundingRect(),mValueString);
58 }
51 }
59 }
52 }
60
53
61 QRectF BarValue::boundingRect() const
54 QRectF BarValue::boundingRect() const
62 {
55 {
63 QRectF r(mXpos, mYpos, mWidth, mHeight);
56 QRectF r(mXpos, mYpos, mWidth, mHeight);
64 return r;
57 return r;
65 }
58 }
66
59
67 void BarValue::toggleVisible()
60 void BarValue::toggleVisible()
68 {
61 {
69 setVisible(!isVisible());
62 setVisible(!isVisible());
70 }
63 }
71
64
72 #include "moc_barvalue_p.cpp"
65 #include "moc_barvalue_p.cpp"
73 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,54 +1,50
1 #ifndef BARVALUE_P_H
1 #ifndef BARVALUE_P_H
2 #define BARVALUE_P_H
2 #define BARVALUE_P_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QGraphicsObject>
5 #include <QGraphicsObject>
6 #include <QPen>
6 #include <QPen>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QBarSet;
10 class QBarSet;
11
11
12 // Visual class for floating bar values
12 // Visual class for floating bar values
13 // TODO: fonts, colors etc.
14 // By default these are not visible.
13 // By default these are not visible.
15 class BarValue : public QGraphicsObject
14 class BarValue : public QGraphicsObject
16 {
15 {
17 Q_OBJECT
16 Q_OBJECT
18 public:
17 public:
19 BarValue(QBarSet &set, QGraphicsItem *parent = 0);
18 BarValue(QBarSet &set, QGraphicsItem *parent = 0);
20
19
21 void setValueString(QString str);
20 void setValueString(QString str);
22 QString valueString();
21 QString valueString();
23
22
24 void setPen(const QPen& pen);
23 void setPen(const QPen& pen);
25 const QPen& pen();
24 const QPen& pen();
26
25
27 void resize(qreal w, qreal h);
26 void resize(qreal w, qreal h);
28 void setPos(qreal x, qreal y);
27 void setPos(qreal x, qreal y);
29
28
30 // Propably not needed.
31 // bool belongsToSet(QBarSet *set);
32
33 // From QGraphicsItem
29 // From QGraphicsItem
34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
30 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
35 QRectF boundingRect() const;
31 QRectF boundingRect() const;
36
32
37 public Q_SLOTS:
33 public Q_SLOTS:
38 void toggleVisible();
34 void toggleVisible();
39
35
40 private:
36 private:
41
37
42 QBarSet& mBarSet;
38 QBarSet& mBarSet;
43 QPen mPen;
39 QPen mPen;
44 QString mValueString;
40 QString mValueString;
45
41
46 qreal mXpos;
42 qreal mXpos;
47 qreal mYpos;
43 qreal mYpos;
48 qreal mWidth;
44 qreal mWidth;
49 qreal mHeight;
45 qreal mHeight;
50 };
46 };
51
47
52 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
53
49
54 #endif // BARVALUE_P_H
50 #endif // BARVALUE_P_H
@@ -1,240 +1,221
1 #include <QDebug>
1 #include <QDebug>
2 #include "qbarseries.h"
2 #include "qbarseries.h"
3 #include "qbarset.h"
3 #include "qbarset.h"
4 #include "barchartmodel_p.h"
4 #include "barchartmodel_p.h"
5 #include "barcategory_p.h"
6
5
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
7
9 /*!
8 /*!
10 \class QBarSeries
9 \class QBarSeries
11 \brief part of QtCommercial chart API.
10 \brief part of QtCommercial chart API.
12
11
13 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
12 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible
14 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
13 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
15 by QStringList.
14 by QStringList.
16
15
17 \mainclass
16 \mainclass
18
17
19 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
18 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
20 */
19 */
21
20
22 /*!
21 /*!
23 \fn virtual QSeriesType QBarSeries::type() const
22 \fn virtual QSeriesType QBarSeries::type() const
24 \brief Returns type of series.
23 \brief Returns type of series.
25 \sa QSeries, QSeriesType
24 \sa QSeries, QSeriesType
26 */
25 */
27 /*!
26
28 \fn void QBarSeries::changed(int index)
29 \brief \internal \a index
30 */
31 /*!
32 \fn void QBarSeries::floatingValuesEnabled(bool enabled)
33 \brief \internal \a enabled
34 */
35 /*!
36 \fn void QBarSeries::toolTipEnabled(bool enabled)
37 \brief \internal \a enabled
38 */
39 /*!
40 \fn void QBarSeries::separatorsEnabled(bool enabled)
41 \brief \internal \a enabled
42 */
43 /*!
27 /*!
44 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
28 \fn void QBarSeries::showToolTip(QPoint pos, QString tip)
45 \brief \internal \a pos \a tip
29 \brief \internal \a pos \a tip
46 */
30 */
47
31
48 /*!
32 /*!
49 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
33 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
50 QBarSeries is QObject which is a child of a \a parent.
34 QBarSeries is QObject which is a child of a \a parent.
51 */
35 */
52 QBarSeries::QBarSeries(QStringList categories, QObject *parent)
36 QBarSeries::QBarSeries(QStringList categories, QObject *parent)
53 : QSeries(parent)
37 : QSeries(parent)
54 ,mModel(new BarChartModel(categories, this))
38 ,mModel(new BarChartModel(categories, this))
55 {
39 {
56 for (int i=0; i<mModel->categoryCount(); i++) {
57 BarCategory *categoryObject = mModel->categoryObject(i);
58 connect(categoryObject, SIGNAL(rightClicked(QString)), this, SIGNAL(categoryRightClicked(QString)));
59 }
60 }
40 }
61
41
62 /*!
42 /*!
63 Adds a set of bars to series. Takes ownership of \a set
43 Adds a set of bars to series. Takes ownership of \a set.
44 Connects the clicked(QString) and rightClicked(QString) signals
45 of \a set to this series
64 */
46 */
65 void QBarSeries::addBarSet(QBarSet *set)
47 void QBarSeries::addBarSet(QBarSet *set)
66 {
48 {
67 mModel->addBarSet(set);
49 mModel->addBarSet(set);
50 connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
51 connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
68 }
52 }
69
53
70 /*!
54 /*!
71 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
55 Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set.
56 Disconnects the clicked(QString) and rightClicked(QString) signals
57 of \a set from this series
72 */
58 */
73 void QBarSeries::removeBarSet(QBarSet *set)
59 void QBarSeries::removeBarSet(QBarSet *set)
74 {
60 {
61 disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString)));
62 disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString)));
75 mModel->removeBarSet(set);
63 mModel->removeBarSet(set);
76 }
64 }
77
65
78 /*!
66 /*!
79 Returns number of sets in series.
67 Returns number of sets in series.
80 */
68 */
81 int QBarSeries::barsetCount()
69 int QBarSeries::barsetCount()
82 {
70 {
83 return mModel->barsetCount();
71 return mModel->barsetCount();
84 }
72 }
85
73
86 /*!
74 /*!
87 Returns number of categories in series
75 Returns number of categories in series
88 */
76 */
89 int QBarSeries::categoryCount()
77 int QBarSeries::categoryCount()
90 {
78 {
91 return mModel->categoryCount();
79 return mModel->categoryCount();
92 }
80 }
93
81
94 /*!
82 /*!
95 Returns a list of sets in series. Keeps ownership of sets.
83 Returns a list of sets in series. Keeps ownership of sets.
96 */
84 */
97 QList<QBarSet*> QBarSeries::barSets()
85 QList<QBarSet*> QBarSeries::barSets()
98 {
86 {
99 return mModel->barSets();
87 return mModel->barSets();
100 }
88 }
101
89
102 /*!
90 /*!
103 \internal \a index
91 \internal \a index
104 */
92 */
105 QBarSet* QBarSeries::barsetAt(int index)
93 QBarSet* QBarSeries::barsetAt(int index)
106 {
94 {
107 return mModel->setAt(index);
95 return mModel->setAt(index);
108 }
96 }
109
97
110 /*!
98 /*!
111 Returns legend of series.
99 Returns legend of series.
112 */
100 */
113 QList<QSeries::Legend> QBarSeries::legend()
101 QList<QSeries::Legend> QBarSeries::legend()
114 {
102 {
115 return mModel->legend();
103 return mModel->legend();
116 }
104 }
117
105
118 /*!
106 /*!
119 \internal \a category
107 \internal \a category
120 */
108 */
121 QString QBarSeries::categoryName(int category)
109 QString QBarSeries::categoryName(int category)
122 {
110 {
123 return mModel->categoryName(category);
111 return mModel->categoryName(category);
124 }
112 }
125
113
126 /*!
114 /*!
127 Enables or disables floating values depending on parameter \a enabled.
128 Floating values are bar values, that are displayed on top of each bar.
129 Calling without parameter \a enabled, enables the floating values
130 */
131 void QBarSeries::setFloatingValuesEnabled(bool enabled)
132 {
133 if (enabled) {
134 for (int i=0; i<mModel->barsetCount(); i++) {
135 QBarSet *set = mModel->setAt(i);
136 connect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
137 }
138 } else {
139 for (int i=0; i<mModel->barsetCount(); i++) {
140 QBarSet *set = mModel->setAt(i);
141 disconnect(set,SIGNAL(clicked()),set,SIGNAL(toggleFloatingValues()));
142 }
143 }
144 }
145
146 /*!
147 Enables or disables tooltip depending on parameter \a enabled.
115 Enables or disables tooltip depending on parameter \a enabled.
148 Tooltip shows the name of set, when mouse is hovering on top of bar.
116 Tooltip shows the name of set, when mouse is hovering on top of bar.
149 Calling without parameter \a enabled, enables the tooltip
117 Calling without parameter \a enabled, enables the tooltip
150 */
118 */
151 void QBarSeries::setToolTipEnabled(bool enabled)
119 void QBarSeries::setToolTipEnabled(bool enabled)
152 {
120 {
153 if (enabled) {
121 if (enabled) {
154 for (int i=0; i<mModel->barsetCount(); i++) {
122 for (int i=0; i<mModel->barsetCount(); i++) {
155 QBarSet *set = mModel->setAt(i);
123 QBarSet *set = mModel->setAt(i);
156 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
124 connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
157 }
125 }
158 } else {
126 } else {
159 for (int i=0; i<mModel->barsetCount(); i++) {
127 for (int i=0; i<mModel->barsetCount(); i++) {
160 QBarSet *set = mModel->setAt(i);
128 QBarSet *set = mModel->setAt(i);
161 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
129 disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString)));
162 }
130 }
163 }
131 }
164 }
132 }
165
133
166 /*!
134 /*!
167 Enables or disables separators depending on parameter \a enabled.
135 Enables or disables separators depending on parameter \a enabled.
168 Separators are visual elements that are drawn between categories.
136 Separators are visual elements that are drawn between categories.
169 Calling without parameter \a enabled, enables the separators
137 Calling without parameter \a enabled, enables the separators
170 */
138 */
171 void QBarSeries::setSeparatorsEnabled(bool enabled)
139 void QBarSeries::setSeparatorsEnabled(bool enabled)
172 {
140 {
173 emit separatorsEnabled(enabled);
141 // TODO: toggle
142 // emit separatorsEnabled(enabled);
174 }
143 }
175
144
145
146 /*!
147 \internal \a category
148 */
149 void QBarSeries::barsetClicked(QString category)
150 {
151 emit clicked(qobject_cast<QBarSet*>(sender()), category);
152 }
153
154 /*!
155 \internal \a category
156 */
157 void QBarSeries::barsetRightClicked(QString category)
158 {
159 emit rightClicked(qobject_cast<QBarSet*>(sender()), category);
160 }
161
162
176 /*!
163 /*!
177 \internal
164 \internal
178 */
165 */
179 qreal QBarSeries::min()
166 qreal QBarSeries::min()
180 {
167 {
181 return mModel->min();
168 return mModel->min();
182 }
169 }
183
170
184 /*!
171 /*!
185 \internal
172 \internal
186 */
173 */
187 qreal QBarSeries::max()
174 qreal QBarSeries::max()
188 {
175 {
189 return mModel->max();
176 return mModel->max();
190 }
177 }
191
178
192 /*!
179 /*!
193 \internal \a set \a category
180 \internal \a set \a category
194 */
181 */
195 qreal QBarSeries::valueAt(int set, int category)
182 qreal QBarSeries::valueAt(int set, int category)
196 {
183 {
197 return mModel->valueAt(set,category);
184 return mModel->valueAt(set,category);
198 }
185 }
199
186
200 /*!
187 /*!
201 \internal \a set \a category
188 \internal \a set \a category
202 */
189 */
203 qreal QBarSeries::percentageAt(int set, int category)
190 qreal QBarSeries::percentageAt(int set, int category)
204 {
191 {
205 return mModel->percentageAt(set,category);
192 return mModel->percentageAt(set,category);
206 }
193 }
207
194
208 /*!
195 /*!
209 \internal \a category
196 \internal \a category
210 */
197 */
211 qreal QBarSeries::categorySum(int category)
198 qreal QBarSeries::categorySum(int category)
212 {
199 {
213 return mModel->categorySum(category);
200 return mModel->categorySum(category);
214 }
201 }
215
202
216 /*!
203 /*!
217 \internal
204 \internal
218 */
205 */
219 qreal QBarSeries::maxCategorySum()
206 qreal QBarSeries::maxCategorySum()
220 {
207 {
221 return mModel->maxCategorySum();
208 return mModel->maxCategorySum();
222 }
209 }
223
210
224 /*!
211 /*!
225 \internal
212 \internal
226 */
213 */
227 BarChartModel& QBarSeries::model()
214 BarChartModel& QBarSeries::model()
228 {
215 {
229 return *mModel;
216 return *mModel;
230 }
217 }
231
218
232 BarCategory* QBarSeries::categoryObject(int category)
233 {
234 return mModel->categoryObject(category);
235 }
236
237
238 #include "moc_qbarseries.cpp"
219 #include "moc_qbarseries.cpp"
239
220
240 QTCOMMERCIALCHART_END_NAMESPACE
221 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,68 +1,69
1 #ifndef BARSERIES_H
1 #ifndef BARSERIES_H
2 #define BARSERIES_H
2 #define BARSERIES_H
3
3
4 #include "qseries.h"
4 #include "qseries.h"
5 #include <QStringList>
5 #include <QStringList>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QBarSet;
9 class QBarSet;
10 class BarChartModel;
10 class BarChartModel;
11 class BarCategory;
11 class BarCategory;
12
12
13 // Container for series
13 // Container for series
14 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
14 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries
15 {
15 {
16 Q_OBJECT
16 Q_OBJECT
17 public:
17 public:
18 QBarSeries(QStringList categories, QObject* parent=0);
18 QBarSeries(QStringList categories, QObject* parent=0);
19
19
20 virtual QSeriesType type() const { return QSeries::SeriesTypeBar; }
20 virtual QSeriesType type() const { return QSeries::SeriesTypeBar; }
21
21
22 void addBarSet(QBarSet *set); // Takes ownership of set
22 void addBarSet(QBarSet *set); // Takes ownership of set
23 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
23 void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set
24 int barsetCount();
24 int barsetCount();
25 int categoryCount();
25 int categoryCount();
26 QList<QBarSet*> barSets();
26 QList<QBarSet*> barSets();
27 QList<QSeries::Legend> legend();
27 QList<QSeries::Legend> legend();
28
28
29 public:
29 public:
30 // TODO: Functions below this are not part of api and will be moved
30 // TODO: Functions below this are not part of api and will be moved
31 // to private implementation, when we start using it
31 // to private implementation, when we start using it
32 // TODO: TO PIMPL --->
32 // TODO: TO PIMPL --->
33 QBarSet* barsetAt(int index);
33 QBarSet* barsetAt(int index);
34 QString categoryName(int category);
34 QString categoryName(int category);
35 qreal min();
35 qreal min();
36 qreal max();
36 qreal max();
37 qreal valueAt(int set, int category);
37 qreal valueAt(int set, int category);
38 qreal percentageAt(int set, int category);
38 qreal percentageAt(int set, int category);
39 qreal categorySum(int category);
39 qreal categorySum(int category);
40 qreal maxCategorySum();
40 qreal maxCategorySum();
41 BarChartModel& model();
41 BarChartModel& model();
42 BarCategory* categoryObject(int category);
43 // <--- TO PIMPL
42 // <--- TO PIMPL
44
43
45 signals:
44 signals:
46 void changed(int index);
45 //void changed(int index);
47 void categoryRightClicked(QString category);
46 void clicked(QBarSet* barset, QString category); // Up to user of api, what to do with these signals
47 void rightClicked(QBarSet* barset, QString category);
48
48
49 // TODO: internal signals, these to private implementation.
49 // TODO: internal signals, these to private implementation.
50 // TODO: TO PIMPL --->
50 // TODO: TO PIMPL --->
51 void floatingValuesEnabled(bool enabled);
52 void toolTipEnabled(bool enabled);
53 void separatorsEnabled(bool enabled);
54 void showToolTip(QPoint pos, QString tip);
51 void showToolTip(QPoint pos, QString tip);
55 // <--- TO PIMPL
52 // <--- TO PIMPL
56
53
57 public Q_SLOTS:
54 public Q_SLOTS:
58 void setFloatingValuesEnabled(bool enabled=true); // enables floating values on top of bars
59 void setToolTipEnabled(bool enabled=true); // enables tooltips
55 void setToolTipEnabled(bool enabled=true); // enables tooltips
60 void setSeparatorsEnabled(bool enabled=true); // enables separators between categories
56 void setSeparatorsEnabled(bool enabled=true); // enables separators between categories
61
57
58 // TODO: TO PIMPL --->
59 void barsetClicked(QString category);
60 void barsetRightClicked(QString category);
61 // <--- TO PIMPL
62
62 protected:
63 protected:
63 BarChartModel* mModel;
64 BarChartModel* mModel;
64 };
65 };
65
66
66 QTCOMMERCIALCHART_END_NAMESPACE
67 QTCOMMERCIALCHART_END_NAMESPACE
67
68
68 #endif // BARSERIES_H
69 #endif // BARSERIES_H
@@ -1,162 +1,177
1 #include "qbarset.h"
1 #include "qbarset.h"
2 #include <QDebug>
2 #include <QDebug>
3 #include <QToolTip>
3 #include <QToolTip>
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 /*!
7 /*!
8 \class QBarSet
8 \class QBarSet
9 \brief part of QtCommercial chart API.
9 \brief part of QtCommercial chart API.
10
10
11 QBarSet represents one set of bars. Set of bars contains one data value for each category.
11 QBarSet represents one set of bars. Set of bars contains one data value for each category.
12 First value of set is assumed to belong to first category, second to second category and so on.
12 First value of set is assumed to belong to first category, second to second category and so on.
13 If set has fewer values than there are categories, then the missing values are assumed to be
13 If set has fewer values than there are categories, then the missing values are assumed to be
14 at the end of set. For missing values in middle of a set, numerical value of zero is used.
14 at the end of set. For missing values in middle of a set, numerical value of zero is used.
15
15
16 \mainclass
16 \mainclass
17
17
18 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
18 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
19 */
19 */
20
20
21 /*!
21 /*!
22 \fn void QBarSet::clicked()
22 \fn void QBarSet::clicked(QString category)
23 \brief signals that set has been clicked
23 \brief signals that set has been clicked
24 Parameter \a category describes on which category was clicked
24 */
25 */
26
27 /*!
28 \fn void QBarSet::rightClicked(QString category)
29 \brief signals that set has been clicked with right mouse button
30 Parameter \a category describes on which category was clicked
31 */
32
25 /*!
33 /*!
26 \fn void QBarSet::hoverEnter(QPoint pos)
34 \fn void QBarSet::hoverEnter(QPoint pos)
27 \brief signals that mouse has entered over the set at position \a pos.
35 \brief signals that mouse has entered over the set at position \a pos.
28 */
36 */
37
29 /*!
38 /*!
30 \fn void QBarSet::hoverLeave()
39 \fn void QBarSet::hoverLeave()
31 \brief signals that mouse has left from the set.
40 \brief signals that mouse has left from the set.
32 */
41 */
42
33 /*!
43 /*!
34 \fn void QBarSet::toggleFloatingValues()
44 \fn void QBarSet::toggleFloatingValues()
35 \brief \internal
45 \brief \internal
36 */
46 */
47
37 /*!
48 /*!
38 \fn void QBarSet::showToolTip(QPoint pos, QString tip)
49 \fn void QBarSet::showToolTip(QPoint pos, QString tip)
39 \brief \internal \a pos \a tip
50 \brief \internal \a pos \a tip
40 */
51 */
41
52
42
53
43 /*!
54 /*!
44 Constructs QBarSet with a name of \a name and with parent of \a parent
55 Constructs QBarSet with a name of \a name and with parent of \a parent
45 */
56 */
46 QBarSet::QBarSet(QString name, QObject *parent)
57 QBarSet::QBarSet(QString name, QObject *parent)
47 : QObject(parent)
58 : QObject(parent)
48 ,mName(name)
59 ,mName(name)
49 {
60 {
50 }
61 }
51
62
52 /*!
63 /*!
53 Sets new \a name for set.
64 Sets new \a name for set.
54 */
65 */
55 void QBarSet::setName(QString name)
66 void QBarSet::setName(QString name)
56 {
67 {
57 mName = name;
68 mName = name;
58 }
69 }
59
70
60 /*!
71 /*!
61 Returns name of the set.
72 Returns name of the set.
62 */
73 */
63 QString QBarSet::name()
74 QString QBarSet::name()
64 {
75 {
65 return mName;
76 return mName;
66 }
77 }
67
78
68 /*!
79 /*!
69 Appends new value \a value to the end of set.
80 Appends new value \a value to the end of set.
70 */
81 */
71 QBarSet& QBarSet::operator << (const qreal &value)
82 QBarSet& QBarSet::operator << (const qreal &value)
72 {
83 {
73 mValues.append(value);
84 mValues.append(value);
74 return *this;
85 return *this;
75 }
86 }
76
87
77 /*!
88 /*!
78 Returns count of values in set.
89 Returns count of values in set.
79 */
90 */
80 int QBarSet::count()
91 int QBarSet::count()
81 {
92 {
82 return mValues.count();
93 return mValues.count();
83 }
94 }
84
95
85 /*!
96 /*!
86 Returns value of set indexed by \a index
97 Returns value of set indexed by \a index
87 */
98 */
88 qreal QBarSet::valueAt(int index)
99 qreal QBarSet::valueAt(int index)
89 {
100 {
90 return mValues.at(index);
101 return mValues.at(index);
91 }
102 }
92
103
93 /*!
104 /*!
94 Sets a new value \a value to set, indexed by \a index
105 Sets a new value \a value to set, indexed by \a index
95 */
106 */
96 void QBarSet::setValue(int index, qreal value)
107 void QBarSet::setValue(int index, qreal value)
97 {
108 {
98 mValues.replace(index,value);
109 mValues.replace(index,value);
99 }
110 }
100
111
101 /*!
112 /*!
102 Sets pen for set. Bars of this set are drawn using \a pen
113 Sets pen for set. Bars of this set are drawn using \a pen
103 */
114 */
104 void QBarSet::setPen(QPen pen)
115 void QBarSet::setPen(QPen pen)
105 {
116 {
106 mPen = pen;
117 mPen = pen;
107 }
118 }
108
119
109 /*!
120 /*!
110 Returns pen of the set.
121 Returns pen of the set.
111 */
122 */
112 QPen QBarSet::pen()
123 QPen QBarSet::pen()
113 {
124 {
114 return mPen;
125 return mPen;
115 }
126 }
116
127
117 /*!
128 /*!
118 Sets brush for the set. Bars of this set are drawn using \a brush
129 Sets brush for the set. Bars of this set are drawn using \a brush
119 */
130 */
120 void QBarSet::setBrush(QBrush brush)
131 void QBarSet::setBrush(QBrush brush)
121 {
132 {
122 mBrush = brush;
133 mBrush = brush;
123 }
134 }
124
135
125 /*!
136 /*!
126 Returns brush of the set.
137 Returns brush of the set.
127 */
138 */
128 QBrush QBarSet::brush()
139 QBrush QBarSet::brush()
129 {
140 {
130 return mBrush;
141 return mBrush;
131 }
142 }
132
143
133 /*!
144 /*
134 \internal
145 void QBarSet::barClickedEvent(QString category)
135 */
136 void QBarSet::barClickedEvent()
137 {
146 {
138 // Some bar of this set has been clicked
147 // Some bar of this set has been clicked
139 // TODO: What happens then?
148 // TODO: What happens then?
140 emit clicked(); // Notify that set has been clicked
149 emit clicked(category); // Notify that set has been clicked
141 }
150 }
142
151
152 void QBarSet::barRightClickedEvent(QString category)
153 {
154 emit rightClicked(category);
155 }
156 */
157
143 /*!
158 /*!
144 \internal \a pos
159 \internal \a pos
145 */
160 */
146 void QBarSet::barHoverEnterEvent(QPoint pos)
161 void QBarSet::barHoverEnterEvent(QPoint pos)
147 {
162 {
148 emit showToolTip(pos, mName);
163 emit showToolTip(pos, mName);
149 emit hoverEnter(pos);
164 emit hoverEnter(pos);
150 }
165 }
151
166
152 /*!
167 /*!
153 \internal
168 \internal
154 */
169 */
155 void QBarSet::barHoverLeaveEvent()
170 void QBarSet::barHoverLeaveEvent()
156 {
171 {
157 // Emit signal to user of charts
172 // Emit signal to user of charts
158 emit hoverLeave();
173 emit hoverLeave();
159 }
174 }
160
175
161 #include "moc_qbarset.cpp"
176 #include "moc_qbarset.cpp"
162 QTCOMMERCIALCHART_END_NAMESPACE
177 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,60 +1,62
1 #ifndef QBARSET_H
1 #ifndef QBARSET_H
2 #define QBARSET_H
2 #define QBARSET_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <QPen>
5 #include <QPen>
6 #include <QBrush>
6 #include <QBrush>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
10 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 public:
13 public:
14 QBarSet(QString name, QObject *parent = 0);
14 QBarSet(QString name, QObject *parent = 0);
15
15
16 void setName(QString name);
16 void setName(QString name);
17 QString name();
17 QString name();
18 QBarSet& operator << (const qreal &value); // appends new value to set
18 QBarSet& operator << (const qreal &value); // appends new value to set
19
19
20 int count(); // count of values in set
20 int count(); // count of values in set
21 qreal valueAt(int index); // for modifying individual values
21 qreal valueAt(int index); // for modifying individual values
22 void setValue(int index, qreal value); // setter for individual value
22 void setValue(int index, qreal value); // setter for individual value
23
23
24 void setPen(QPen pen);
24 void setPen(QPen pen);
25 QPen pen();
25 QPen pen();
26
26
27 void setBrush(QBrush brush);
27 void setBrush(QBrush brush);
28 QBrush brush();
28 QBrush brush();
29
29
30 Q_SIGNALS:
30 Q_SIGNALS:
31 void clicked(); // Clicked and hover signals exposed to user
31 void clicked(QString category); // Clicked and hover signals exposed to user
32 void hoverEnter(QPoint pos);
32 void rightClicked(QString category);
33 void hoverLeave();
33 void toggleFloatingValues();
34
34
35 // TODO: Expose this to user or not?
35 // TODO: Expose this to user or not?
36 // TODO: TO PIMPL --->
36 // TODO: TO PIMPL --->
37 void toggleFloatingValues();
37 void hoverEnter(QPoint pos);
38 void hoverLeave();
38 void showToolTip(QPoint pos, QString tip); // Private signal
39 void showToolTip(QPoint pos, QString tip); // Private signal
39 // <--- TO PIMPL
40 // <--- TO PIMPL
40
41
41 public Q_SLOTS:
42 public Q_SLOTS:
42 // These are for internal communication
43 // These are for internal communication
43 // TODO: TO PIMPL --->
44 // TODO: TO PIMPL --->
44 void barClickedEvent();
45 // void barClickedEvent(QString category);
46 // void barRightClickedEvent(QString category);
45 void barHoverEnterEvent(QPoint pos);
47 void barHoverEnterEvent(QPoint pos);
46 void barHoverLeaveEvent();
48 void barHoverLeaveEvent();
47 // <--- TO PIMPL
49 // <--- TO PIMPL
48
50
49 private:
51 private:
50
52
51 QString mName;
53 QString mName;
52 QList<qreal> mValues;
54 QList<qreal> mValues;
53 QPen mPen;
55 QPen mPen;
54 QBrush mBrush;
56 QBrush mBrush;
55
57
56 };
58 };
57
59
58 QTCOMMERCIALCHART_END_NAMESPACE
60 QTCOMMERCIALCHART_END_NAMESPACE
59
61
60 #endif // QBARSET_H
62 #endif // QBARSET_H
@@ -1,300 +1,300
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include "charttheme_p.h"
5 #include "charttheme_p.h"
6 //series
6 //series
7 #include "qbarseries.h"
7 #include "qbarseries.h"
8 #include "qstackedbarseries.h"
8 #include "qstackedbarseries.h"
9 #include "qpercentbarseries.h"
9 #include "qpercentbarseries.h"
10 #include "qlineseries.h"
10 #include "qlineseries.h"
11 #include "qareaseries.h"
11 #include "qareaseries.h"
12 #include "qpieseries.h"
12 #include "qpieseries.h"
13 #include "qscatterseries.h"
13 #include "qscatterseries.h"
14 //items
14 //items
15 #include "axisitem_p.h"
15 #include "axisitem_p.h"
16 #include "axisanimationitem_p.h"
16 #include "axisanimationitem_p.h"
17 #include "areachartitem_p.h"
17 #include "areachartitem_p.h"
18 #include "barpresenter_p.h"
18 #include "barpresenter_p.h"
19 #include "stackedbarpresenter_p.h"
19 #include "stackedbarpresenter_p.h"
20 #include "percentbarpresenter_p.h"
20 #include "percentbarpresenter_p.h"
21 #include "linechartitem_p.h"
21 #include "linechartitem_p.h"
22 #include "linechartanimationitem_p.h"
22 #include "linechartanimationitem_p.h"
23 #include "piepresenter_p.h"
23 #include "piepresenter_p.h"
24 #include "scatterpresenter_p.h"
24 #include "scatterpresenter_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
28 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
29 m_chart(chart),
29 m_chart(chart),
30 m_dataset(dataset),
30 m_dataset(dataset),
31 m_chartTheme(0),
31 m_chartTheme(0),
32 m_marginSize(0),
32 m_marginSize(0),
33 m_rect(QRectF(QPoint(0,0),m_chart->size())),
33 m_rect(QRectF(QPoint(0,0),m_chart->size())),
34 m_options(0)
34 m_options(0)
35 {
35 {
36 createConnections();
36 createConnections();
37 setChartTheme(QChart::ChartThemeDefault);
37 setChartTheme(QChart::ChartThemeDefault);
38
38
39 }
39 }
40
40
41 ChartPresenter::~ChartPresenter()
41 ChartPresenter::~ChartPresenter()
42 {
42 {
43 }
43 }
44
44
45 void ChartPresenter::createConnections()
45 void ChartPresenter::createConnections()
46 {
46 {
47 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
47 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
48 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*)));
48 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*)));
49 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
49 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
50 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
50 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
51 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
51 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
52 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&)));
52 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&)));
53 QObject::connect(m_dataset,SIGNAL(axisRangeChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisRangeChanged(QChartAxis*,const QStringList&)));
53 QObject::connect(m_dataset,SIGNAL(axisRangeChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisRangeChanged(QChartAxis*,const QStringList&)));
54 }
54 }
55
55
56
56
57 QRectF ChartPresenter::geometry() const
57 QRectF ChartPresenter::geometry() const
58 {
58 {
59 return m_rect;
59 return m_rect;
60 }
60 }
61
61
62 void ChartPresenter::handleGeometryChanged()
62 void ChartPresenter::handleGeometryChanged()
63 {
63 {
64 m_rect = QRectF(QPoint(0,0),m_chart->size());
64 m_rect = QRectF(QPoint(0,0),m_chart->size());
65 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
65 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
66 Q_ASSERT(m_rect.isValid());
66 Q_ASSERT(m_rect.isValid());
67 emit geometryChanged(m_rect);
67 emit geometryChanged(m_rect);
68 }
68 }
69
69
70 int ChartPresenter::margin() const
70 int ChartPresenter::margin() const
71 {
71 {
72 return m_marginSize;
72 return m_marginSize;
73 }
73 }
74
74
75 void ChartPresenter::setMargin(int margin)
75 void ChartPresenter::setMargin(int margin)
76 {
76 {
77 m_marginSize = margin;
77 m_marginSize = margin;
78 }
78 }
79
79
80 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
80 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
81 {
81 {
82
82
83 AxisItem* item ;
83 AxisItem* item ;
84
84
85 if(!m_options.testFlag(QChart::GridAxisAnimations))
85 if(!m_options.testFlag(QChart::GridAxisAnimations))
86 {
86 {
87 item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
87 item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
88 }else{
88 }else{
89 item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
89 item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
90 }
90 }
91
91
92 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
92 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
93 QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
93 QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
94
94
95 item->handleAxisUpdate(axis);
95 item->handleAxisUpdate(axis);
96 item->handleGeometryChanged(m_rect);
96 item->handleGeometryChanged(m_rect);
97 m_chartTheme->decorate(axis,item);
97 m_chartTheme->decorate(axis,item);
98 m_axisItems.insert(axis,item);
98 m_axisItems.insert(axis,item);
99 }
99 }
100
100
101 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
101 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
102 {
102 {
103 AxisItem* item = m_axisItems.take(axis);
103 AxisItem* item = m_axisItems.take(axis);
104 Q_ASSERT(item);
104 Q_ASSERT(item);
105 delete item;
105 delete item;
106 }
106 }
107
107
108
108
109 void ChartPresenter::handleSeriesAdded(QSeries* series)
109 void ChartPresenter::handleSeriesAdded(QSeries* series)
110 {
110 {
111 switch(series->type())
111 switch(series->type())
112 {
112 {
113 case QSeries::SeriesTypeLine: {
113 case QSeries::SeriesTypeLine: {
114
114
115 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
115 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
116 LineChartItem* item;
116 LineChartItem* item;
117 if(m_options.testFlag(QChart::SeriesAnimations)){
117 if(m_options.testFlag(QChart::SeriesAnimations)){
118 item = new LineChartAnimationItem(this,lineSeries,m_chart);
118 item = new LineChartAnimationItem(this,lineSeries,m_chart);
119 }else{
119 }else{
120 item = new LineChartItem(this,lineSeries,m_chart);
120 item = new LineChartItem(this,lineSeries,m_chart);
121 }
121 }
122 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
122 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
123 m_chartItems.insert(series,item);
123 m_chartItems.insert(series,item);
124 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
124 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
125 break;
125 break;
126 }
126 }
127
127
128 case QSeries::SeriesTypeArea: {
128 case QSeries::SeriesTypeArea: {
129
129
130 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
130 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
131 AreaChartItem* item;
131 AreaChartItem* item;
132 if(m_options.testFlag(QChart::SeriesAnimations)) {
132 if(m_options.testFlag(QChart::SeriesAnimations)) {
133 item = new AreaChartItem(this,areaSeries,m_chart);
133 item = new AreaChartItem(this,areaSeries,m_chart);
134 }
134 }
135 else {
135 else {
136 item = new AreaChartItem(this,areaSeries,m_chart);
136 item = new AreaChartItem(this,areaSeries,m_chart);
137 }
137 }
138 m_chartTheme->decorate(item,areaSeries,m_chartItems.count());
138 m_chartTheme->decorate(item,areaSeries,m_chartItems.count());
139 m_chartItems.insert(series,item);
139 m_chartItems.insert(series,item);
140 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
140 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
141 break;
141 break;
142 }
142 }
143
143
144 case QSeries::SeriesTypeBar: {
144 case QSeries::SeriesTypeBar: {
145 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
145 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
146 BarPresenter* item = new BarPresenter(barSeries,m_chart);
146 BarPresenter* item = new BarPresenter(barSeries,m_chart);
147 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
147 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
148 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
148 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
149 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
149 // QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
150 m_chartItems.insert(series,item);
150 m_chartItems.insert(series,item);
151 // m_axisXItem->setVisible(false);
151 // m_axisXItem->setVisible(false);
152 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
152 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
153 break;
153 break;
154 }
154 }
155
155
156 case QSeries::SeriesTypeStackedBar: {
156 case QSeries::SeriesTypeStackedBar: {
157
157
158 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
158 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
159 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
159 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
160 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
160 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
161 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
161 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
162 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
162 // QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
163 m_chartItems.insert(series,item);
163 m_chartItems.insert(series,item);
164 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
164 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
165 break;
165 break;
166 }
166 }
167
167
168 case QSeries::SeriesTypePercentBar: {
168 case QSeries::SeriesTypePercentBar: {
169
169
170 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
170 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
171 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
171 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
172 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
172 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
173 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
173 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
174 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
174 // QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
175 m_chartItems.insert(series,item);
175 m_chartItems.insert(series,item);
176 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
176 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
177 break;
177 break;
178 }
178 }
179 case QSeries::SeriesTypeScatter: {
179 case QSeries::SeriesTypeScatter: {
180 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
180 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
181 ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
181 ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
182 QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)),
182 QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)),
183 scatterSeries, SIGNAL(clicked(QPointF)));
183 scatterSeries, SIGNAL(clicked(QPointF)));
184 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
184 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
185 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
185 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
186 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
186 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
187 m_chartItems.insert(scatterSeries, scatterPresenter);
187 m_chartItems.insert(scatterSeries, scatterPresenter);
188 if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect);
188 if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect);
189 break;
189 break;
190 }
190 }
191 case QSeries::SeriesTypePie: {
191 case QSeries::SeriesTypePie: {
192 QPieSeries *s = qobject_cast<QPieSeries *>(series);
192 QPieSeries *s = qobject_cast<QPieSeries *>(series);
193 PiePresenter* pie = new PiePresenter(m_chart, s);
193 PiePresenter* pie = new PiePresenter(m_chart, s);
194 m_chartTheme->decorate(pie, s, m_chartItems.count());
194 m_chartTheme->decorate(pie, s, m_chartItems.count());
195 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
195 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
196
196
197 // Hide all from background when there is only piechart
197 // Hide all from background when there is only piechart
198 // TODO: refactor this ugly code... should be one setting for this
198 // TODO: refactor this ugly code... should be one setting for this
199 if (m_chartItems.count() == 0) {
199 if (m_chartItems.count() == 0) {
200 m_chart->axisX()->setAxisVisible(false);
200 m_chart->axisX()->setAxisVisible(false);
201 m_chart->axisY()->setAxisVisible(false);
201 m_chart->axisY()->setAxisVisible(false);
202 m_chart->axisX()->setGridVisible(false);
202 m_chart->axisX()->setGridVisible(false);
203 m_chart->axisY()->setGridVisible(false);
203 m_chart->axisY()->setGridVisible(false);
204 m_chart->axisX()->setLabelsVisible(false);
204 m_chart->axisX()->setLabelsVisible(false);
205 m_chart->axisY()->setLabelsVisible(false);
205 m_chart->axisY()->setLabelsVisible(false);
206 m_chart->axisX()->setShadesVisible(false);
206 m_chart->axisX()->setShadesVisible(false);
207 m_chart->axisY()->setShadesVisible(false);
207 m_chart->axisY()->setShadesVisible(false);
208 m_chart->setChartBackgroundBrush(Qt::transparent);
208 m_chart->setChartBackgroundBrush(Qt::transparent);
209 }
209 }
210
210
211 m_chartItems.insert(series, pie);
211 m_chartItems.insert(series, pie);
212 pie->handleGeometryChanged(m_rect);
212 pie->handleGeometryChanged(m_rect);
213 break;
213 break;
214 }
214 }
215 default: {
215 default: {
216 qDebug()<< "Series type" << series->type() << "not implemented.";
216 qDebug()<< "Series type" << series->type() << "not implemented.";
217 break;
217 break;
218 }
218 }
219 }
219 }
220 }
220 }
221
221
222 void ChartPresenter::handleSeriesRemoved(QSeries* series)
222 void ChartPresenter::handleSeriesRemoved(QSeries* series)
223 {
223 {
224 ChartItem* item = m_chartItems.take(series);
224 ChartItem* item = m_chartItems.take(series);
225 delete item;
225 delete item;
226 }
226 }
227
227
228 void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain)
228 void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain)
229 {
229 {
230 m_chartItems.value(series)->handleDomainChanged(domain);
230 m_chartItems.value(series)->handleDomainChanged(domain);
231 }
231 }
232
232
233 void ChartPresenter::handleAxisRangeChanged(QChartAxis* axis,const QStringList& labels)
233 void ChartPresenter::handleAxisRangeChanged(QChartAxis* axis,const QStringList& labels)
234 {
234 {
235 m_axisItems.value(axis)->handleRangeChanged(axis,labels);
235 m_axisItems.value(axis)->handleRangeChanged(axis,labels);
236 }
236 }
237
237
238 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
238 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
239 {
239 {
240 delete m_chartTheme;
240 delete m_chartTheme;
241
241
242 m_chartTheme = ChartTheme::createTheme(theme);
242 m_chartTheme = ChartTheme::createTheme(theme);
243
243
244 m_chartTheme->decorate(m_chart);
244 m_chartTheme->decorate(m_chart);
245 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
245 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
246
246
247 int index=0;
247 int index=0;
248 while (i.hasNext()) {
248 while (i.hasNext()) {
249 i.next();
249 i.next();
250 m_chartTheme->decorate(i.value(),i.key(),index);
250 m_chartTheme->decorate(i.value(),i.key(),index);
251 index++;
251 index++;
252 }
252 }
253
253
254 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
254 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
255 while (j.hasNext()) {
255 while (j.hasNext()) {
256 j.next();
256 j.next();
257 m_chartTheme->decorate(j.key(),j.value());
257 m_chartTheme->decorate(j.key(),j.value());
258 }
258 }
259 }
259 }
260
260
261 QChart::ChartTheme ChartPresenter::chartTheme()
261 QChart::ChartTheme ChartPresenter::chartTheme()
262 {
262 {
263 return m_chartTheme->id();
263 return m_chartTheme->id();
264 }
264 }
265
265
266 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
266 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
267 {
267 {
268 if(m_options!=options) {
268 if(m_options!=options) {
269
269
270 m_options=options;
270 m_options=options;
271
271
272 //recreate elements
272 //recreate elements
273
273
274 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
274 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
275 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
275 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
276
276
277 foreach(QChartAxis* axis, axisList) {
277 foreach(QChartAxis* axis, axisList) {
278 handleAxisRemoved(axis);
278 handleAxisRemoved(axis);
279 handleAxisAdded(axis);
279 handleAxisAdded(axis);
280 }
280 }
281 foreach(QSeries* series, seriesList) {
281 foreach(QSeries* series, seriesList) {
282 handleSeriesRemoved(series);
282 handleSeriesRemoved(series);
283 handleSeriesAdded(series);
283 handleSeriesAdded(series);
284 }
284 }
285
285
286 //now reintialize view data
286 //now reintialize view data
287 //TODO: make it more nice
287 //TODO: make it more nice
288 m_dataset->setDomain(m_dataset->domainIndex());
288 m_dataset->setDomain(m_dataset->domainIndex());
289 }
289 }
290 }
290 }
291
291
292 QChart::AnimationOptions ChartPresenter::animationOptions() const
292 QChart::AnimationOptions ChartPresenter::animationOptions() const
293 {
293 {
294 return m_options;
294 return m_options;
295 }
295 }
296
296
297
297
298 #include "moc_chartpresenter_p.cpp"
298 #include "moc_chartpresenter_p.cpp"
299
299
300 QTCOMMERCIALCHART_END_NAMESPACE
300 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,391 +1,392
1 #include "mainwidget.h"
1 #include "mainwidget.h"
2 #include "dataseriedialog.h"
2 #include "dataseriedialog.h"
3 #include "qpieseries.h"
3 #include "qpieseries.h"
4 #include "qscatterseries.h"
4 #include "qscatterseries.h"
5 #include <qlineseries.h>
5 #include <qlineseries.h>
6 #include <qbarset.h>
6 #include <qbarset.h>
7 #include <qbarseries.h>
7 #include <qbarseries.h>
8 #include <qstackedbarseries.h>
8 #include <qstackedbarseries.h>
9 #include <qpercentbarseries.h>
9 #include <qpercentbarseries.h>
10 #include <QPushButton>
10 #include <QPushButton>
11 #include <QComboBox>
11 #include <QComboBox>
12 #include <QSpinBox>
12 #include <QSpinBox>
13 #include <QCheckBox>
13 #include <QCheckBox>
14 #include <QGridLayout>
14 #include <QGridLayout>
15 #include <QHBoxLayout>
15 #include <QHBoxLayout>
16 #include <QLabel>
16 #include <QLabel>
17 #include <QSpacerItem>
17 #include <QSpacerItem>
18 #include <QMessageBox>
18 #include <QMessageBox>
19 #include <cmath>
19 #include <cmath>
20 #include <QDebug>
20 #include <QDebug>
21 #include <QStandardItemModel>
21 #include <QStandardItemModel>
22
22
23
23
24 QTCOMMERCIALCHART_USE_NAMESPACE
24 QTCOMMERCIALCHART_USE_NAMESPACE
25
25
26 MainWidget::MainWidget(QWidget *parent) :
26 MainWidget::MainWidget(QWidget *parent) :
27 QWidget(parent),
27 QWidget(parent),
28 m_addSerieDialog(0),
28 m_addSerieDialog(0),
29 m_chartView(0)
29 m_chartView(0)
30 {
30 {
31 m_chartView = new QChartView(this);
31 m_chartView = new QChartView(this);
32 m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand);
32 m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand);
33
33
34 // Grid layout for the controls for configuring the chart widget
34 // Grid layout for the controls for configuring the chart widget
35 QGridLayout *grid = new QGridLayout();
35 QGridLayout *grid = new QGridLayout();
36 QPushButton *addSeriesButton = new QPushButton("Add series");
36 QPushButton *addSeriesButton = new QPushButton("Add series");
37 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
37 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
38 grid->addWidget(addSeriesButton, 0, 1);
38 grid->addWidget(addSeriesButton, 0, 1);
39 initBackroundCombo(grid);
39 initBackroundCombo(grid);
40 initScaleControls(grid);
40 initScaleControls(grid);
41 initThemeCombo(grid);
41 initThemeCombo(grid);
42 initCheckboxes(grid);
42 initCheckboxes(grid);
43
43
44 // add row with empty label to make all the other rows static
44 // add row with empty label to make all the other rows static
45 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
45 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
46 grid->setRowStretch(grid->rowCount() - 1, 1);
46 grid->setRowStretch(grid->rowCount() - 1, 1);
47
47
48 // Another grid layout as a main layout
48 // Another grid layout as a main layout
49 QGridLayout *mainLayout = new QGridLayout();
49 QGridLayout *mainLayout = new QGridLayout();
50 mainLayout->addLayout(grid, 0, 0);
50 mainLayout->addLayout(grid, 0, 0);
51
51
52 // Init series type specific controls
52 // Init series type specific controls
53 initPieControls();
53 initPieControls();
54 mainLayout->addLayout(m_pieLayout, 2, 0);
54 mainLayout->addLayout(m_pieLayout, 2, 0);
55 // Scatter series specific settings
55 // Scatter series specific settings
56 // m_scatterLayout = new QGridLayout();
56 // m_scatterLayout = new QGridLayout();
57 // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
57 // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
58 // m_scatterLayout->setEnabled(false);
58 // m_scatterLayout->setEnabled(false);
59 // mainLayout->addLayout(m_scatterLayout, 1, 0);
59 // mainLayout->addLayout(m_scatterLayout, 1, 0);
60
60
61 // Add layouts and the chart widget to the main layout
61 // Add layouts and the chart widget to the main layout
62 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
62 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
63 setLayout(mainLayout);
63 setLayout(mainLayout);
64 }
64 }
65
65
66 // Combo box for selecting the chart's background
66 // Combo box for selecting the chart's background
67 void MainWidget::initBackroundCombo(QGridLayout *grid)
67 void MainWidget::initBackroundCombo(QGridLayout *grid)
68 {
68 {
69 QComboBox *backgroundCombo = new QComboBox(this);
69 QComboBox *backgroundCombo = new QComboBox(this);
70 backgroundCombo->addItem("Color");
70 backgroundCombo->addItem("Color");
71 backgroundCombo->addItem("Gradient");
71 backgroundCombo->addItem("Gradient");
72 backgroundCombo->addItem("Image");
72 backgroundCombo->addItem("Image");
73 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
73 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
74 this, SLOT(backgroundChanged(int)));
74 this, SLOT(backgroundChanged(int)));
75
75
76 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
76 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
77 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
77 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
78 }
78 }
79
79
80 // Scale related controls (auto-scale vs. manual min-max values)
80 // Scale related controls (auto-scale vs. manual min-max values)
81 void MainWidget::initScaleControls(QGridLayout *grid)
81 void MainWidget::initScaleControls(QGridLayout *grid)
82 {
82 {
83 m_autoScaleCheck = new QCheckBox("Automatic scaling");
83 m_autoScaleCheck = new QCheckBox("Automatic scaling");
84 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
84 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
85 // Allow setting also non-sense values (like -2147483648 and 2147483647)
85 // Allow setting also non-sense values (like -2147483648 and 2147483647)
86 m_xMinSpin = new QSpinBox();
86 m_xMinSpin = new QSpinBox();
87 m_xMinSpin->setMinimum(INT_MIN);
87 m_xMinSpin->setMinimum(INT_MIN);
88 m_xMinSpin->setMaximum(INT_MAX);
88 m_xMinSpin->setMaximum(INT_MAX);
89 m_xMinSpin->setValue(0);
89 m_xMinSpin->setValue(0);
90 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
90 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
91 m_xMaxSpin = new QSpinBox();
91 m_xMaxSpin = new QSpinBox();
92 m_xMaxSpin->setMinimum(INT_MIN);
92 m_xMaxSpin->setMinimum(INT_MIN);
93 m_xMaxSpin->setMaximum(INT_MAX);
93 m_xMaxSpin->setMaximum(INT_MAX);
94 m_xMaxSpin->setValue(10);
94 m_xMaxSpin->setValue(10);
95 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
95 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
96 m_yMinSpin = new QSpinBox();
96 m_yMinSpin = new QSpinBox();
97 m_yMinSpin->setMinimum(INT_MIN);
97 m_yMinSpin->setMinimum(INT_MIN);
98 m_yMinSpin->setMaximum(INT_MAX);
98 m_yMinSpin->setMaximum(INT_MAX);
99 m_yMinSpin->setValue(0);
99 m_yMinSpin->setValue(0);
100 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
100 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
101 m_yMaxSpin = new QSpinBox();
101 m_yMaxSpin = new QSpinBox();
102 m_yMaxSpin->setMinimum(INT_MIN);
102 m_yMaxSpin->setMinimum(INT_MIN);
103 m_yMaxSpin->setMaximum(INT_MAX);
103 m_yMaxSpin->setMaximum(INT_MAX);
104 m_yMaxSpin->setValue(10);
104 m_yMaxSpin->setValue(10);
105 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
105 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
106
106
107 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
107 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
108 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
108 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
109 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
109 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
110 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
110 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
111 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
111 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
112 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
112 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
113 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
113 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
114 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
114 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
115 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
115 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
116
116
117 m_autoScaleCheck->setChecked(true);
117 m_autoScaleCheck->setChecked(true);
118 }
118 }
119
119
120 // Combo box for selecting theme
120 // Combo box for selecting theme
121 void MainWidget::initThemeCombo(QGridLayout *grid)
121 void MainWidget::initThemeCombo(QGridLayout *grid)
122 {
122 {
123 QComboBox *chartTheme = new QComboBox();
123 QComboBox *chartTheme = new QComboBox();
124 chartTheme->addItem("Default");
124 chartTheme->addItem("Default");
125 chartTheme->addItem("Vanilla");
125 chartTheme->addItem("Vanilla");
126 chartTheme->addItem("Icy");
126 chartTheme->addItem("Icy");
127 chartTheme->addItem("Grayscale");
127 chartTheme->addItem("Grayscale");
128 chartTheme->addItem("Scientific");
128 chartTheme->addItem("Scientific");
129 chartTheme->addItem("Unnamed1");
129 chartTheme->addItem("Unnamed1");
130 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
130 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
131 this, SLOT(changeChartTheme(int)));
131 this, SLOT(changeChartTheme(int)));
132 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
132 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
133 grid->addWidget(chartTheme, 8, 1);
133 grid->addWidget(chartTheme, 8, 1);
134 }
134 }
135
135
136 // Different check boxes for customizing chart
136 // Different check boxes for customizing chart
137 void MainWidget::initCheckboxes(QGridLayout *grid)
137 void MainWidget::initCheckboxes(QGridLayout *grid)
138 {
138 {
139 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
139 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
140 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
140 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
141 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
141 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
142 zoomCheckBox->setChecked(true);
142 zoomCheckBox->setChecked(true);
143 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
143 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
144
144
145 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
145 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
146 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
146 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
147 aliasCheckBox->setChecked(false);
147 aliasCheckBox->setChecked(false);
148 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
148 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
149 }
149 }
150
150
151 void MainWidget::antiAliasToggled(bool enabled)
151 void MainWidget::antiAliasToggled(bool enabled)
152 {
152 {
153 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
153 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
154 }
154 }
155
155
156 void MainWidget::initPieControls()
156 void MainWidget::initPieControls()
157 {
157 {
158 // Pie series specific settings
158 // Pie series specific settings
159 // Pie size factory
159 // Pie size factory
160 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
160 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
161 pieSizeSpin->setMinimum(LONG_MIN);
161 pieSizeSpin->setMinimum(LONG_MIN);
162 pieSizeSpin->setMaximum(LONG_MAX);
162 pieSizeSpin->setMaximum(LONG_MAX);
163 pieSizeSpin->setValue(1.0);
163 pieSizeSpin->setValue(1.0);
164 pieSizeSpin->setSingleStep(0.1);
164 pieSizeSpin->setSingleStep(0.1);
165 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
165 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
166 // Pie position
166 // Pie position
167 QComboBox *piePosCombo = new QComboBox(this);
167 QComboBox *piePosCombo = new QComboBox(this);
168 piePosCombo->addItem("Maximized");
168 piePosCombo->addItem("Maximized");
169 piePosCombo->addItem("Top left");
169 piePosCombo->addItem("Top left");
170 piePosCombo->addItem("Top right");
170 piePosCombo->addItem("Top right");
171 piePosCombo->addItem("Bottom left");
171 piePosCombo->addItem("Bottom left");
172 piePosCombo->addItem("Bottom right");
172 piePosCombo->addItem("Bottom right");
173 connect(piePosCombo, SIGNAL(currentIndexChanged(int)),
173 connect(piePosCombo, SIGNAL(currentIndexChanged(int)),
174 this, SLOT(setPiePosition(int)));
174 this, SLOT(setPiePosition(int)));
175 m_pieLayout = new QGridLayout();
175 m_pieLayout = new QGridLayout();
176 m_pieLayout->setEnabled(false);
176 m_pieLayout->setEnabled(false);
177 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
177 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
178 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
178 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
179 m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0);
179 m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0);
180 m_pieLayout->addWidget(piePosCombo, 1, 1);
180 m_pieLayout->addWidget(piePosCombo, 1, 1);
181 }
181 }
182
182
183 void MainWidget::addSeries()
183 void MainWidget::addSeries()
184 {
184 {
185 if (!m_addSerieDialog) {
185 if (!m_addSerieDialog) {
186 m_addSerieDialog = new DataSerieDialog(this);
186 m_addSerieDialog = new DataSerieDialog(this);
187 connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
187 connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
188 this, SLOT(addSeries(QString, int, int, QString, bool)));
188 this, SLOT(addSeries(QString, int, int, QString, bool)));
189 }
189 }
190 m_addSerieDialog->exec();
190 m_addSerieDialog->exec();
191 }
191 }
192
192
193 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
193 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
194 {
194 {
195 // TODO: dataCharacteristics
195 // TODO: dataCharacteristics
196 QList<RealList> testData;
196 QList<RealList> testData;
197 for (int j(0); j < columnCount; j++) {
197 for (int j(0); j < columnCount; j++) {
198 QList <qreal> newColumn;
198 QList <qreal> newColumn;
199 for (int i(0); i < rowCount; i++) {
199 for (int i(0); i < rowCount; i++) {
200 if (dataCharacteristics == "Sin") {
200 if (dataCharacteristics == "Sin") {
201 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
201 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
202 } else if (dataCharacteristics == "Sin + random") {
202 } else if (dataCharacteristics == "Sin + random") {
203 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
203 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
204 } else if (dataCharacteristics == "Random") {
204 } else if (dataCharacteristics == "Random") {
205 newColumn.append(rand() % 5);
205 newColumn.append(rand() % 5);
206 } else if (dataCharacteristics == "Linear") {
206 } else if (dataCharacteristics == "Linear") {
207 //newColumn.append(i * (j + 1.0));
207 //newColumn.append(i * (j + 1.0));
208 // TODO: temporary hack to make pie work; prevent zero values:
208 // TODO: temporary hack to make pie work; prevent zero values:
209 newColumn.append(i * (j + 1.0) + 0.1);
209 newColumn.append(i * (j + 1.0) + 0.1);
210 } else { // "constant"
210 } else { // "constant"
211 newColumn.append((j + 1.0));
211 newColumn.append((j + 1.0));
212 }
212 }
213 }
213 }
214 testData.append(newColumn);
214 testData.append(newColumn);
215 }
215 }
216 return testData;
216 return testData;
217 }
217 }
218
218
219 QStringList MainWidget::generateLabels(int count)
219 QStringList MainWidget::generateLabels(int count)
220 {
220 {
221 QStringList result;
221 QStringList result;
222 for (int i(0); i < count; i++)
222 for (int i(0); i < count; i++)
223 result.append("label" + QString::number(i));
223 result.append("label" + QString::number(i));
224 return result;
224 return result;
225 }
225 }
226
226
227 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
227 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
228 {
228 {
229 qDebug() << "addSeries: " << seriesName
229 qDebug() << "addSeries: " << seriesName
230 << " columnCount: " << columnCount
230 << " columnCount: " << columnCount
231 << " rowCount: " << rowCount
231 << " rowCount: " << rowCount
232 << " dataCharacteristics: " << dataCharacteristics
232 << " dataCharacteristics: " << dataCharacteristics
233 << " labels enabled: " << labelsEnabled;
233 << " labels enabled: " << labelsEnabled;
234 m_defaultSeriesName = seriesName;
234 m_defaultSeriesName = seriesName;
235
235
236 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
236 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
237
237
238 // Line series and scatter series use similar data
238 // Line series and scatter series use similar data
239 if (seriesName.contains("line", Qt::CaseInsensitive)) {
239 if (seriesName.contains("line", Qt::CaseInsensitive)) {
240 for (int j(0); j < data.count(); j ++) {
240 for (int j(0); j < data.count(); j ++) {
241 QList<qreal> column = data.at(j);
241 QList<qreal> column = data.at(j);
242 QLineSeries *series = new QLineSeries();
242 QLineSeries *series = new QLineSeries();
243 for (int i(0); i < column.count(); i++) {
243 for (int i(0); i < column.count(); i++) {
244 series->add(i, column.at(i));
244 series->add(i, column.at(i));
245 }
245 }
246 m_chartView->addSeries(series);
246 m_chartView->addSeries(series);
247 setCurrentSeries(series);
247 setCurrentSeries(series);
248 }
248 }
249 } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) {
249 } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) {
250 for (int j(0); j < data.count(); j++) {
250 for (int j(0); j < data.count(); j++) {
251 QList<qreal> column = data.at(j);
251 QList<qreal> column = data.at(j);
252 QScatterSeries *series = new QScatterSeries();
252 QScatterSeries *series = new QScatterSeries();
253 for (int i(0); i < column.count(); i++) {
253 for (int i(0); i < column.count(); i++) {
254 (*series) << QPointF(i, column.at(i));
254 (*series) << QPointF(i, column.at(i));
255 }
255 }
256 m_chartView->addSeries(series);
256 m_chartView->addSeries(series);
257 setCurrentSeries(series);
257 setCurrentSeries(series);
258 }
258 }
259 } else if (seriesName.contains("pie", Qt::CaseInsensitive)) {
259 } else if (seriesName.contains("pie", Qt::CaseInsensitive)) {
260 QStringList labels = generateLabels(rowCount);
260 QStringList labels = generateLabels(rowCount);
261 for (int j(0); j < data.count(); j++) {
261 for (int j(0); j < data.count(); j++) {
262 QPieSeries *series = new QPieSeries();
262 QPieSeries *series = new QPieSeries();
263 QList<qreal> column = data.at(j);
263 QList<qreal> column = data.at(j);
264 for (int i(0); i < column.count(); i++) {
264 for (int i(0); i < column.count(); i++) {
265 series->add(column.at(i), labels.at(i));
265 series->add(column.at(i), labels.at(i));
266 }
266 }
267 m_chartView->addSeries(series);
267 m_chartView->addSeries(series);
268 setCurrentSeries(series);
268 setCurrentSeries(series);
269 }
269 }
270 } else if (seriesName == "Bar"
270 } else if (seriesName == "Bar"
271 || seriesName == "Stacked bar"
271 || seriesName == "Stacked bar"
272 || seriesName == "Percent bar") {
272 || seriesName == "Percent bar") {
273 QStringList category;
273 QStringList category;
274 QStringList labels = generateLabels(rowCount);
274 QStringList labels = generateLabels(rowCount);
275 foreach(QString label, labels)
275 foreach(QString label, labels)
276 category << label;
276 category << label;
277 QBarSeries* series = 0;
277 QBarSeries* series = 0;
278 if (seriesName == "Bar")
278 if (seriesName == "Bar")
279 series = new QBarSeries(category, this);
279 series = new QBarSeries(category, this);
280 else if (seriesName == "Stacked bar")
280 else if (seriesName == "Stacked bar")
281 series = new QStackedBarSeries(category, this);
281 series = new QStackedBarSeries(category, this);
282 else
282 else
283 series = new QPercentBarSeries(category, this);
283 series = new QPercentBarSeries(category, this);
284
284
285 for (int j(0); j < data.count(); j++) {
285 for (int j(0); j < data.count(); j++) {
286 QList<qreal> column = data.at(j);
286 QList<qreal> column = data.at(j);
287 QBarSet *set = new QBarSet("set" + QString::number(j));
287 QBarSet *set = new QBarSet("set" + QString::number(j));
288 for (int i(0); i < column.count(); i++) {
288 for (int i(0); i < column.count(); i++) {
289 *set << column.at(i);
289 *set << column.at(i);
290 }
290 }
291 series->addBarSet(set);
291 series->addBarSet(set);
292 }
292 }
293 series->setFloatingValuesEnabled(true);
293 // TODO: new implementation of setFloatingValuesEnabled with signals
294 //series->setFloatingValuesEnabled(true);
294 series->setToolTipEnabled(true);
295 series->setToolTipEnabled(true);
295 series->setSeparatorsEnabled(false);
296 series->setSeparatorsEnabled(false);
296 m_chartView->addSeries(series);
297 m_chartView->addSeries(series);
297 setCurrentSeries(series);
298 setCurrentSeries(series);
298 }
299 }
299
300
300 // TODO: spline and area
301 // TODO: spline and area
301 }
302 }
302
303
303 void MainWidget::setCurrentSeries(QSeries *series)
304 void MainWidget::setCurrentSeries(QSeries *series)
304 {
305 {
305 if (series) {
306 if (series) {
306 m_currentSeries = series;
307 m_currentSeries = series;
307 switch (m_currentSeries->type()) {
308 switch (m_currentSeries->type()) {
308 case QSeries::SeriesTypeLine:
309 case QSeries::SeriesTypeLine:
309 break;
310 break;
310 case QSeries::SeriesTypeScatter:
311 case QSeries::SeriesTypeScatter:
311 break;
312 break;
312 case QSeries::SeriesTypePie:
313 case QSeries::SeriesTypePie:
313 break;
314 break;
314 case QSeries::SeriesTypeBar:
315 case QSeries::SeriesTypeBar:
315 qDebug() << "setCurrentSeries (bar)";
316 qDebug() << "setCurrentSeries (bar)";
316 break;
317 break;
317 case QSeries::SeriesTypeStackedBar:
318 case QSeries::SeriesTypeStackedBar:
318 qDebug() << "setCurrentSeries (Stackedbar)";
319 qDebug() << "setCurrentSeries (Stackedbar)";
319 break;
320 break;
320 case QSeries::SeriesTypePercentBar:
321 case QSeries::SeriesTypePercentBar:
321 qDebug() << "setCurrentSeries (Percentbar)";
322 qDebug() << "setCurrentSeries (Percentbar)";
322 break;
323 break;
323 default:
324 default:
324 Q_ASSERT(false);
325 Q_ASSERT(false);
325 break;
326 break;
326 }
327 }
327 }
328 }
328 }
329 }
329
330
330 void MainWidget::backgroundChanged(int itemIndex)
331 void MainWidget::backgroundChanged(int itemIndex)
331 {
332 {
332 qDebug() << "backgroundChanged: " << itemIndex;
333 qDebug() << "backgroundChanged: " << itemIndex;
333 }
334 }
334
335
335 void MainWidget::autoScaleChanged(int value)
336 void MainWidget::autoScaleChanged(int value)
336 {
337 {
337 if (value) {
338 if (value) {
338 // TODO: enable auto scaling
339 // TODO: enable auto scaling
339 } else {
340 } else {
340 // TODO: set scaling manually (and disable auto scaling)
341 // TODO: set scaling manually (and disable auto scaling)
341 }
342 }
342
343
343 m_xMinSpin->setEnabled(!value);
344 m_xMinSpin->setEnabled(!value);
344 m_xMaxSpin->setEnabled(!value);
345 m_xMaxSpin->setEnabled(!value);
345 m_yMinSpin->setEnabled(!value);
346 m_yMinSpin->setEnabled(!value);
346 m_yMaxSpin->setEnabled(!value);
347 m_yMaxSpin->setEnabled(!value);
347 }
348 }
348
349
349 void MainWidget::xMinChanged(int value)
350 void MainWidget::xMinChanged(int value)
350 {
351 {
351 qDebug() << "xMinChanged: " << value;
352 qDebug() << "xMinChanged: " << value;
352 }
353 }
353
354
354 void MainWidget::xMaxChanged(int value)
355 void MainWidget::xMaxChanged(int value)
355 {
356 {
356 qDebug() << "xMaxChanged: " << value;
357 qDebug() << "xMaxChanged: " << value;
357 }
358 }
358
359
359 void MainWidget::yMinChanged(int value)
360 void MainWidget::yMinChanged(int value)
360 {
361 {
361 qDebug() << "yMinChanged: " << value;
362 qDebug() << "yMinChanged: " << value;
362 }
363 }
363
364
364 void MainWidget::yMaxChanged(int value)
365 void MainWidget::yMaxChanged(int value)
365 {
366 {
366 qDebug() << "yMaxChanged: " << value;
367 qDebug() << "yMaxChanged: " << value;
367 }
368 }
368
369
369 void MainWidget::changeChartTheme(int themeIndex)
370 void MainWidget::changeChartTheme(int themeIndex)
370 {
371 {
371 qDebug() << "changeChartTheme: " << themeIndex;
372 qDebug() << "changeChartTheme: " << themeIndex;
372 m_chartView->setChartTheme((QChart::ChartTheme) themeIndex);
373 m_chartView->setChartTheme((QChart::ChartTheme) themeIndex);
373 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
374 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
374 QSize s = size();
375 QSize s = size();
375 s.setWidth(s.width()+1);
376 s.setWidth(s.width()+1);
376 resize(s);
377 resize(s);
377 }
378 }
378
379
379 void MainWidget::setPieSizeFactor(double size)
380 void MainWidget::setPieSizeFactor(double size)
380 {
381 {
381 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
382 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
382 if (pie)
383 if (pie)
383 pie->setSizeFactor(qreal(size));
384 pie->setSizeFactor(qreal(size));
384 }
385 }
385
386
386 void MainWidget::setPiePosition(int position)
387 void MainWidget::setPiePosition(int position)
387 {
388 {
388 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
389 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
389 if (pie)
390 if (pie)
390 pie->setPosition((QPieSeries::PiePosition) position);
391 pie->setPosition((QPieSeries::PiePosition) position);
391 }
392 }
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now