##// END OF EJS Templates
Renames Grid to GridLine
Michal Klocek -
r535:774f7e43278b
parent child
Show More
@@ -1,78 +1,78
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartview.h>
3 #include <qchartview.h>
4 #include <qlineseries.h>
4 #include <qlineseries.h>
5 #include <qchart.h>
5 #include <qchart.h>
6 #include <qchartaxis.h>
6 #include <qchartaxis.h>
7 #include <qchartaxiscategories.h>
7 #include <qchartaxiscategories.h>
8 #include <cmath>
8 #include <cmath>
9
9
10 QTCOMMERCIALCHART_USE_NAMESPACE
10 QTCOMMERCIALCHART_USE_NAMESPACE
11
11
12 #define PI 3.14159265358979
12 #define PI 3.14159265358979
13
13
14 int main(int argc, char *argv[])
14 int main(int argc, char *argv[])
15 {
15 {
16 QApplication a(argc, argv);
16 QApplication a(argc, argv);
17
17
18 QMainWindow window;
18 QMainWindow window;
19
19
20 QLineSeries* series0 = new QLineSeries();
20 QLineSeries* series0 = new QLineSeries();
21 QPen blue(Qt::blue);
21 QPen blue(Qt::blue);
22 blue.setWidth(3);
22 blue.setWidth(3);
23 series0->setPen(blue);
23 series0->setPen(blue);
24 QLineSeries* series1 = new QLineSeries();
24 QLineSeries* series1 = new QLineSeries();
25 QPen red(Qt::red);
25 QPen red(Qt::red);
26 red.setWidth(3);
26 red.setWidth(3);
27 series1->setPen(red);
27 series1->setPen(red);
28
28
29 int numPoints = 100;
29 int numPoints = 100;
30
30
31 for (int x = 0; x <= numPoints; ++x) {
31 for (int x = 0; x <= numPoints; ++x) {
32 series0->add(x, fabs(sin(PI/50*x)*100));
32 series0->add(x, fabs(sin(PI/50*x)*100));
33 series1->add(x, fabs(cos(PI/50*x)*100));
33 series1->add(x, fabs(cos(PI/50*x)*100));
34 }
34 }
35
35
36 QChartView* chartView = new QChartView(&window);
36 QChartView* chartView = new QChartView(&window);
37
37
38 chartView->setRenderHint(QPainter::Antialiasing);
38 chartView->setRenderHint(QPainter::Antialiasing);
39 chartView->setChartTitle("This is custom axis chart example");
39 chartView->setChartTitle("This is custom axis chart example");
40 chartView->addSeries(series0);
40 chartView->addSeries(series0);
41 chartView->addSeries(series1);
41 chartView->addSeries(series1);
42
42
43 QLinearGradient backgroundGradient;
43 QLinearGradient backgroundGradient;
44 backgroundGradient.setColorAt(0.0, Qt::white);
44 backgroundGradient.setColorAt(0.0, Qt::white);
45 backgroundGradient.setColorAt(1.0, QRgb(0xffff80));
45 backgroundGradient.setColorAt(1.0, QRgb(0xffff80));
46 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
46 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
47 chartView->setChartBackgroundBrush(backgroundGradient);
47 chartView->setChartBackgroundBrush(backgroundGradient);
48
48
49 QChartAxis* axisX = chartView->axisX();
49 QChartAxis* axisX = chartView->axisX();
50 axisX->setLabelsAngle(45);
50 axisX->setLabelsAngle(45);
51 axisX->setGridPen(Qt::DashLine);
51 axisX->setGridLinePen(Qt::DashLine);
52
52
53 QChartAxisCategories* categoriesX = axisX->categories();
53 QChartAxisCategories* categoriesX = axisX->categories();
54 categoriesX->insert(0,"low");
54 categoriesX->insert(0,"low");
55 categoriesX->insert(50,"medium");
55 categoriesX->insert(50,"medium");
56 categoriesX->insert(100,"High");
56 categoriesX->insert(100,"High");
57
57
58 axisX->setMin(-10);
58 axisX->setMin(-10);
59 axisX->setMax(2200);
59 axisX->setMax(2200);
60
60
61 QChartAxis* axisY = chartView->axisY();
61 QChartAxis* axisY = chartView->axisY();
62 axisY->setLabelsAngle(45);
62 axisY->setLabelsAngle(45);
63 axisY->setShadesBrush(Qt::yellow);
63 axisY->setShadesBrush(Qt::yellow);
64
64
65 QChartAxisCategories* categoriesY = axisY->categories();
65 QChartAxisCategories* categoriesY = axisY->categories();
66 categoriesY->insert(0,"low");
66 categoriesY->insert(0,"low");
67 categoriesY->insert(50,"medium");
67 categoriesY->insert(50,"medium");
68 categoriesY->insert(100,"High");
68 categoriesY->insert(100,"High");
69
69
70 axisY->setMin(-10);
70 axisY->setMin(-10);
71 axisY->setMax(200);
71 axisY->setMax(200);
72
72
73 window.setCentralWidget(chartView);
73 window.setCentralWidget(chartView);
74 window.resize(400, 300);
74 window.resize(400, 300);
75 window.show();
75 window.show();
76
76
77 return a.exec();
77 return a.exec();
78 }
78 }
@@ -1,81 +1,81
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 tooltip
50 // Enable tooltip
51 series->setToolTipEnabled();
51 series->setToolTipEnabled();
52 series->setSeparatorsVisible(true);
52 series->setSeparatorsVisible(true);
53
53
54 // Connect clicked signal of set to toggle floating values of set.
54 // Connect clicked signal of set to toggle floating values of set.
55 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
55 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
59 QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues()));
59 QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues()));
60 //! [4]
60 //! [4]
61
61
62 //! [5]
62 //! [5]
63 // Create view for chart and add series to it. Apply theme.
63 // Create view for chart and add series to it. Apply theme.
64
64
65 QChartView* chartView = new QChartView(&window);
65 QChartView* chartView = new QChartView(&window);
66 chartView->addSeries(series);
66 chartView->addSeries(series);
67 chartView->setChartTitle("simple barchart");
67 chartView->setChartTitle("simple barchart");
68 chartView->setChartTheme(QChart::ChartThemeIcy);
68 chartView->setChartTheme(QChart::ChartThemeIcy);
69 //! [5]
69 //! [5]
70
70
71 //! [6]
71 //! [6]
72 chartView->axisX()->setGridVisible(false);
72 chartView->axisX()->setGridLineVisible(false);
73 //! [6]
73 //! [6]
74
74
75 window.setCentralWidget(chartView);
75 window.setCentralWidget(chartView);
76 window.resize(400, 300);
76 window.resize(400, 300);
77 window.show();
77 window.show();
78
78
79 return a.exec();
79 return a.exec();
80 }
80 }
81
81
@@ -1,83 +1,83
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 tooltip
50 // Enable tooltip
51 series->setToolTipEnabled();
51 series->setToolTipEnabled();
52
52
53 // Connect clicked signal of set to toggle floating values of set.
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.
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()));
55 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
59 QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues()));
59 QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues()));
60 //! [4]
60 //! [4]
61
61
62 //! [5]
62 //! [5]
63 // Create view for chart and add series to it. Apply theme.
63 // Create view for chart and add series to it. Apply theme.
64
64
65 QChartView* chartView = new QChartView(&window);
65 QChartView* chartView = new QChartView(&window);
66 chartView->addSeries(series);
66 chartView->addSeries(series);
67 chartView->setChartTitle("simple percent barchart");
67 chartView->setChartTitle("simple percent barchart");
68 chartView->setChartTheme(QChart::ChartThemeIcy);
68 chartView->setChartTheme(QChart::ChartThemeIcy);
69 //! [5]
69 //! [5]
70
70
71 //! [6]
71 //! [6]
72 chartView->axisX()->setAxisVisible(false);
72 chartView->axisX()->setAxisVisible(false);
73 chartView->axisX()->setGridVisible(false);
73 chartView->axisX()->setGridLineVisible(false);
74 chartView->axisX()->setLabelsVisible(false);
74 chartView->axisX()->setLabelsVisible(false);
75 //! [6]
75 //! [6]
76
76
77 window.setCentralWidget(chartView);
77 window.setCentralWidget(chartView);
78 window.resize(400, 300);
78 window.resize(400, 300);
79 window.show();
79 window.show();
80
80
81 return a.exec();
81 return a.exec();
82 }
82 }
83
83
@@ -1,79 +1,79
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 tooltip
49 // Enable tooltip
50 series->setToolTipEnabled();
50 series->setToolTipEnabled();
51
51
52 // Connect clicked signal of set to toggle floating values of set.
52 // Connect clicked signal of set to toggle floating values of set.
53 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
53 QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues()));
54 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
54 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
55 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
55 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues()));
58 //! [4]
58 //! [4]
59
59
60 //! [5]
60 //! [5]
61 // Create view for chart and add series to it. Apply theme.
61 // Create view for chart and add series to it. Apply theme.
62
62
63 QChartView* chartView = new QChartView(&window);
63 QChartView* chartView = new QChartView(&window);
64 chartView->addSeries(series);
64 chartView->addSeries(series);
65 chartView->setChartTitle("simple stacked barchart");
65 chartView->setChartTitle("simple stacked barchart");
66 chartView->setChartTheme(QChart::ChartThemeIcy);
66 chartView->setChartTheme(QChart::ChartThemeIcy);
67 //! [5]
67 //! [5]
68
68
69 //! [6]
69 //! [6]
70 chartView->axisX()->setGridVisible(false);
70 chartView->axisX()->setGridLineVisible(false);
71 //! [6]
71 //! [6]
72
72
73 window.setCentralWidget(chartView);
73 window.setCentralWidget(chartView);
74 window.resize(400, 300);
74 window.resize(400, 300);
75 window.show();
75 window.show();
76
76
77 return a.exec();
77 return a.exec();
78 }
78 }
79
79
@@ -1,156 +1,156
1 #include <QtGui/QApplication>
1 #include <QtGui/QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qstackedbarseries.h>
5 #include <qstackedbarseries.h>
6 #include <qbarset.h>
6 #include <qbarset.h>
7 #include <qchartaxis.h>
7 #include <qchartaxis.h>
8 #include <qlegend.h>
8 #include <qlegend.h>
9 #include <QStringList>
9 #include <QStringList>
10 #include <QDebug>
10 #include <QDebug>
11
11
12 QTCOMMERCIALCHART_USE_NAMESPACE
12 QTCOMMERCIALCHART_USE_NAMESPACE
13
13
14 //! [1]
14 //! [1]
15 class DrilldownBarSeries : public QStackedBarSeries
15 class DrilldownBarSeries : public QStackedBarSeries
16 {
16 {
17 Q_OBJECT
17 Q_OBJECT
18 public:
18 public:
19 DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {}
19 DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {}
20
20
21 void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries)
21 void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries)
22 {
22 {
23 mDrilldownSeries[category] = drilldownSeries;
23 mDrilldownSeries[category] = drilldownSeries;
24 }
24 }
25
25
26 DrilldownBarSeries* drilldownSeries(QString category)
26 DrilldownBarSeries* drilldownSeries(QString category)
27 {
27 {
28 return mDrilldownSeries[category];
28 return mDrilldownSeries[category];
29 }
29 }
30
30
31 public Q_SLOTS:
31 public Q_SLOTS:
32
32
33 private:
33 private:
34
34
35 QMap<QString, DrilldownBarSeries*> mDrilldownSeries;
35 QMap<QString, DrilldownBarSeries*> mDrilldownSeries;
36 };
36 };
37 //! [1]
37 //! [1]
38
38
39 //! [2]
39 //! [2]
40 class DrilldownChart : public QChartView
40 class DrilldownChart : public QChartView
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 explicit DrilldownChart(QWidget *parent = 0) : QChartView(parent), m_currentSeries(0) {}
44 explicit DrilldownChart(QWidget *parent = 0) : QChartView(parent), m_currentSeries(0) {}
45
45
46 void changeSeries(QSeries* series)
46 void changeSeries(QSeries* series)
47 {
47 {
48 if (m_currentSeries)
48 if (m_currentSeries)
49 removeSeries(m_currentSeries);
49 removeSeries(m_currentSeries);
50 m_currentSeries = series;
50 m_currentSeries = series;
51 addSeries(series);
51 addSeries(series);
52 setChartTitle(series->title());
52 setChartTitle(series->title());
53 }
53 }
54
54
55 public Q_SLOTS:
55 public Q_SLOTS:
56 void handleRightClick(QBarSet *barset, QString category)
56 void handleRightClick(QBarSet *barset, QString category)
57 {
57 {
58 // qDebug() << "DrilldownChart::handleRightClick" << barset->name() << category;
58 // qDebug() << "DrilldownChart::handleRightClick" << barset->name() << category;
59 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
59 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
60 changeSeries(series->drilldownSeries(category));
60 changeSeries(series->drilldownSeries(category));
61 }
61 }
62
62
63 private:
63 private:
64 QSeries* m_currentSeries;
64 QSeries* m_currentSeries;
65 };
65 };
66 //! [2]
66 //! [2]
67
67
68 int main(int argc, char *argv[])
68 int main(int argc, char *argv[])
69 {
69 {
70 QApplication a(argc, argv);
70 QApplication a(argc, argv);
71 QMainWindow window;
71 QMainWindow window;
72
72
73 DrilldownChart* drilldownChart = new DrilldownChart(&window);
73 DrilldownChart* drilldownChart = new DrilldownChart(&window);
74 drilldownChart->setChartTheme(QChart::ChartThemeIcy);
74 drilldownChart->setChartTheme(QChart::ChartThemeIcy);
75
75
76 //! [3]
76 //! [3]
77 // Define categories
77 // Define categories
78 QStringList months;
78 QStringList months;
79 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
79 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
80 QStringList weeks;
80 QStringList weeks;
81 weeks << "week 1" << "week 2" << "week 3" << "week 4";
81 weeks << "week 1" << "week 2" << "week 3" << "week 4";
82 QStringList plants;
82 QStringList plants;
83 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
83 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
84 //! [3]
84 //! [3]
85
85
86 //! [4]
86 //! [4]
87 // Create drilldown structure
87 // Create drilldown structure
88 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
88 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
89 seasonSeries->setTitle("Crop by month - Season");
89 seasonSeries->setTitle("Crop by month - Season");
90
90
91 // Each month in season series has drilldown series for weekly data
91 // Each month in season series has drilldown series for weekly data
92 foreach (QString month, months) {
92 foreach (QString month, months) {
93
93
94 // Create drilldown series for every week
94 // Create drilldown series for every week
95 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
95 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
96 seasonSeries->mapDrilldownSeries(month, weeklySeries);
96 seasonSeries->mapDrilldownSeries(month, weeklySeries);
97
97
98 // Drilling down from weekly data brings us back to season data.
98 // Drilling down from weekly data brings us back to season data.
99 foreach (QString week, weeks) {
99 foreach (QString week, weeks) {
100 weeklySeries->mapDrilldownSeries(week, seasonSeries);
100 weeklySeries->mapDrilldownSeries(week, seasonSeries);
101 weeklySeries->setTitle(QString("Crop by week - " + month));
101 weeklySeries->setTitle(QString("Crop by week - " + month));
102 }
102 }
103
103
104 // Use right click signal to implement drilldown
104 // Use right click signal to implement drilldown
105 QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
105 QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
106 }
106 }
107
107
108 // Enable drilldown from season series using right click.
108 // Enable drilldown from season series using right click.
109 QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
109 QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
110 //! [4]
110 //! [4]
111
111
112 //! [5]
112 //! [5]
113 // Fill monthly and weekly series with data
113 // Fill monthly and weekly series with data
114 foreach (QString plant, plants) {
114 foreach (QString plant, plants) {
115 QBarSet* monthlyCrop = new QBarSet(plant);
115 QBarSet* monthlyCrop = new QBarSet(plant);
116 foreach (QString month, months) {
116 foreach (QString month, months) {
117 QBarSet* weeklyCrop = new QBarSet(plant);
117 QBarSet* weeklyCrop = new QBarSet(plant);
118 foreach (QString week, weeks ) {
118 foreach (QString week, weeks ) {
119 *weeklyCrop << (qrand() % 20);
119 *weeklyCrop << (qrand() % 20);
120 }
120 }
121 // Get the drilldown series from season series and add crop to it.
121 // Get the drilldown series from season series and add crop to it.
122 seasonSeries->drilldownSeries(month)->addBarSet(weeklyCrop);
122 seasonSeries->drilldownSeries(month)->addBarSet(weeklyCrop);
123 seasonSeries->drilldownSeries(month)->setToolTipEnabled(true);
123 seasonSeries->drilldownSeries(month)->setToolTipEnabled(true);
124 *monthlyCrop << weeklyCrop->total();
124 *monthlyCrop << weeklyCrop->total();
125
125
126 QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues()));
126 QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues()));
127 }
127 }
128 seasonSeries->addBarSet(monthlyCrop);
128 seasonSeries->addBarSet(monthlyCrop);
129 QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues()));
129 QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues()));
130 }
130 }
131 //! [5]
131 //! [5]
132
132
133 seasonSeries->setToolTipEnabled(true);
133 seasonSeries->setToolTipEnabled(true);
134
134
135 //! [6]
135 //! [6]
136 // Show season series in initial view
136 // Show season series in initial view
137 drilldownChart->changeSeries(seasonSeries);
137 drilldownChart->changeSeries(seasonSeries);
138 drilldownChart->setChartTitle(seasonSeries->title());
138 drilldownChart->setChartTitle(seasonSeries->title());
139 //! [6]
139 //! [6]
140
140
141 // Disable axis, since they don't really apply to bar chart
141 // Disable axis, since they don't really apply to bar chart
142 // drilldownChart->axisX()->setAxisVisible(false);
142 // drilldownChart->axisX()->setAxisVisible(false);
143 drilldownChart->axisX()->setGridVisible(false);
143 drilldownChart->axisX()->setGridLineVisible(false);
144 // drilldownChart->axisX()->setLabelsVisible(false);
144 // drilldownChart->axisX()->setLabelsVisible(false);
145
145
146 QLegend* l = drilldownChart->legend();
146 QLegend* l = drilldownChart->legend();
147 l->handleGeometryChanged(QRectF(20,20,100,100));
147 l->handleGeometryChanged(QRectF(20,20,100,100));
148
148
149 window.setCentralWidget(drilldownChart);
149 window.setCentralWidget(drilldownChart);
150 window.resize(400, 300);
150 window.resize(400, 300);
151 window.show();
151 window.show();
152
152
153 return a.exec();
153 return a.exec();
154 }
154 }
155
155
156 #include "main.moc"
156 #include "main.moc"
@@ -1,414 +1,414
1 #include "axisitem_p.h"
1 #include "axisitem_p.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartanimator_p.h"
4 #include "chartanimator_p.h"
5 #include <QPainter>
5 #include <QPainter>
6 #include <QDebug>
6 #include <QDebug>
7
7
8 static int label_padding = 5;
8 static int label_padding = 5;
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 AxisItem::AxisItem(QChartAxis* axis,ChartPresenter* presenter,AxisType type,QGraphicsItem* parent) :
12 AxisItem::AxisItem(QChartAxis* axis,ChartPresenter* presenter,AxisType type,QGraphicsItem* parent) :
13 ChartItem(parent),
13 ChartItem(parent),
14 m_presenter(presenter),
14 m_presenter(presenter),
15 m_chartAxis(axis),
15 m_chartAxis(axis),
16 m_type(type),
16 m_type(type),
17 m_labelsAngle(0),
17 m_labelsAngle(0),
18 m_grid(parent),
18 m_grid(parent),
19 m_shades(parent),
19 m_shades(parent),
20 m_labels(parent),
20 m_labels(parent),
21 m_axis(parent),
21 m_axis(parent),
22 m_min(0),
22 m_min(0),
23 m_max(0),
23 m_max(0),
24 m_ticksCount(0)
24 m_ticksCount(0)
25 {
25 {
26 //initial initialization
26 //initial initialization
27 m_axis.setZValue(ChartPresenter::AxisZValue);
27 m_axis.setZValue(ChartPresenter::AxisZValue);
28 m_shades.setZValue(ChartPresenter::ShadesZValue);
28 m_shades.setZValue(ChartPresenter::ShadesZValue);
29 m_grid.setZValue(ChartPresenter::GridZValue);
29 m_grid.setZValue(ChartPresenter::GridZValue);
30 setFlags(QGraphicsItem::ItemHasNoContents);
30 setFlags(QGraphicsItem::ItemHasNoContents);
31
31
32 QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
32 QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
33 QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
33 QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
34
34
35 handleAxisUpdated();
35 handleAxisUpdated();
36 }
36 }
37
37
38 AxisItem::~AxisItem()
38 AxisItem::~AxisItem()
39 {
39 {
40 }
40 }
41
41
42 QRectF AxisItem::boundingRect() const
42 QRectF AxisItem::boundingRect() const
43 {
43 {
44 return QRectF();
44 return QRectF();
45 }
45 }
46
46
47 void AxisItem::createItems(int count)
47 void AxisItem::createItems(int count)
48 {
48 {
49
49
50 if(m_axis.children().size()==0)
50 if(m_axis.children().size()==0)
51 m_axis.addToGroup(new QGraphicsLineItem());
51 m_axis.addToGroup(new QGraphicsLineItem());
52 for (int i = 0; i < count; ++i) {
52 for (int i = 0; i < count; ++i) {
53 m_grid.addToGroup(new QGraphicsLineItem());
53 m_grid.addToGroup(new QGraphicsLineItem());
54 m_labels.addToGroup(new QGraphicsSimpleTextItem());
54 m_labels.addToGroup(new QGraphicsSimpleTextItem());
55 m_axis.addToGroup(new QGraphicsLineItem());
55 m_axis.addToGroup(new QGraphicsLineItem());
56 if((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem());
56 if((m_grid.childItems().size())%2 && m_grid.childItems().size()>2) m_shades.addToGroup(new QGraphicsRectItem());
57 }
57 }
58 }
58 }
59
59
60 void AxisItem::deleteItems(int count)
60 void AxisItem::deleteItems(int count)
61 {
61 {
62 QList<QGraphicsItem *> lines = m_grid.childItems();
62 QList<QGraphicsItem *> lines = m_grid.childItems();
63 QList<QGraphicsItem *> labels = m_labels.childItems();
63 QList<QGraphicsItem *> labels = m_labels.childItems();
64 QList<QGraphicsItem *> shades = m_shades.childItems();
64 QList<QGraphicsItem *> shades = m_shades.childItems();
65 QList<QGraphicsItem *> axis = m_axis.childItems();
65 QList<QGraphicsItem *> axis = m_axis.childItems();
66
66
67 for (int i = 0; i < count; ++i) {
67 for (int i = 0; i < count; ++i) {
68 if(lines.size()%2 && lines.size()>1) delete(shades.takeLast());
68 if(lines.size()%2 && lines.size()>1) delete(shades.takeLast());
69 delete(lines.takeLast());
69 delete(lines.takeLast());
70 delete(labels.takeLast());
70 delete(labels.takeLast());
71 delete(axis.takeLast());
71 delete(axis.takeLast());
72 }
72 }
73 }
73 }
74
74
75 void AxisItem::updateLayout(QVector<qreal>& layout)
75 void AxisItem::updateLayout(QVector<qreal>& layout)
76 {
76 {
77 if(m_animator){
77 if(m_animator){
78 m_animator->applyLayout(this,layout);
78 m_animator->applyLayout(this,layout);
79 }
79 }
80 else setLayout(layout);
80 else setLayout(layout);
81 }
81 }
82
82
83 QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) const
83 QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) const
84 {
84 {
85 Q_ASSERT(max>=min);
85 Q_ASSERT(max>=min);
86 Q_ASSERT(ticks>0);
86 Q_ASSERT(ticks>0);
87
87
88 QStringList labels;
88 QStringList labels;
89
89
90 QChartAxisCategories* categories = m_chartAxis->categories();
90 QChartAxisCategories* categories = m_chartAxis->categories();
91
91
92 for(int i=0; i< ticks; i++) {
92 for(int i=0; i< ticks; i++) {
93 qreal value = min + (i * (max - min)/ (ticks-1));
93 qreal value = min + (i * (max - min)/ (ticks-1));
94 if(categories->count()==0) {
94 if(categories->count()==0) {
95 labels << QString::number(value);
95 labels << QString::number(value);
96 }
96 }
97 else {
97 else {
98 QString label = categories->label(value);
98 QString label = categories->label(value);
99 labels << label;
99 labels << label;
100 }
100 }
101 }
101 }
102 return labels;
102 return labels;
103 }
103 }
104
104
105 void AxisItem::setAxisOpacity(qreal opacity)
105 void AxisItem::setAxisOpacity(qreal opacity)
106 {
106 {
107 m_axis.setOpacity(opacity);
107 m_axis.setOpacity(opacity);
108 }
108 }
109
109
110 qreal AxisItem::axisOpacity() const
110 qreal AxisItem::axisOpacity() const
111 {
111 {
112 return m_axis.opacity();
112 return m_axis.opacity();
113 }
113 }
114
114
115 void AxisItem::setGridOpacity(qreal opacity)
115 void AxisItem::setGridOpacity(qreal opacity)
116 {
116 {
117 m_grid.setOpacity(opacity);
117 m_grid.setOpacity(opacity);
118 }
118 }
119
119
120 qreal AxisItem::gridOpacity() const
120 qreal AxisItem::gridOpacity() const
121 {
121 {
122 return m_grid.opacity();
122 return m_grid.opacity();
123 }
123 }
124
124
125 void AxisItem::setLabelsOpacity(qreal opacity)
125 void AxisItem::setLabelsOpacity(qreal opacity)
126 {
126 {
127 m_labels.setOpacity(opacity);
127 m_labels.setOpacity(opacity);
128 }
128 }
129
129
130 qreal AxisItem::labelsOpacity() const
130 qreal AxisItem::labelsOpacity() const
131 {
131 {
132 return m_labels.opacity();
132 return m_labels.opacity();
133 }
133 }
134
134
135 void AxisItem::setShadesOpacity(qreal opacity)
135 void AxisItem::setShadesOpacity(qreal opacity)
136 {
136 {
137 m_shades.setOpacity(opacity);
137 m_shades.setOpacity(opacity);
138 }
138 }
139
139
140 qreal AxisItem::shadesOpacity() const
140 qreal AxisItem::shadesOpacity() const
141 {
141 {
142 return m_shades.opacity();
142 return m_shades.opacity();
143 }
143 }
144
144
145 void AxisItem::setLabelsAngle(int angle)
145 void AxisItem::setLabelsAngle(int angle)
146 {
146 {
147 foreach(QGraphicsItem* item , m_labels.childItems()) {
147 foreach(QGraphicsItem* item , m_labels.childItems()) {
148 QPointF center = item->boundingRect().center();
148 QPointF center = item->boundingRect().center();
149 item->setRotation(angle);
149 item->setRotation(angle);
150 }
150 }
151
151
152 m_labelsAngle=angle;
152 m_labelsAngle=angle;
153 }
153 }
154
154
155 void AxisItem::setLabelsPen(const QPen& pen)
155 void AxisItem::setLabelsPen(const QPen& pen)
156 {
156 {
157 foreach(QGraphicsItem* item , m_labels.childItems()) {
157 foreach(QGraphicsItem* item , m_labels.childItems()) {
158 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
158 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
159 }
159 }
160 }
160 }
161
161
162 void AxisItem::setLabelsBrush(const QBrush& brush)
162 void AxisItem::setLabelsBrush(const QBrush& brush)
163 {
163 {
164 foreach(QGraphicsItem* item , m_labels.childItems()) {
164 foreach(QGraphicsItem* item , m_labels.childItems()) {
165 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
165 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
166 }
166 }
167 }
167 }
168
168
169 void AxisItem::setLabelsFont(const QFont& font)
169 void AxisItem::setLabelsFont(const QFont& font)
170 {
170 {
171 foreach(QGraphicsItem* item , m_labels.childItems()) {
171 foreach(QGraphicsItem* item , m_labels.childItems()) {
172 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
172 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
173 }
173 }
174 }
174 }
175
175
176 void AxisItem::setShadesBrush(const QBrush& brush)
176 void AxisItem::setShadesBrush(const QBrush& brush)
177 {
177 {
178 foreach(QGraphicsItem* item , m_shades.childItems()) {
178 foreach(QGraphicsItem* item , m_shades.childItems()) {
179 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
179 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
180 }
180 }
181 }
181 }
182
182
183 void AxisItem::setShadesPen(const QPen& pen)
183 void AxisItem::setShadesPen(const QPen& pen)
184 {
184 {
185 foreach(QGraphicsItem* item , m_shades.childItems()) {
185 foreach(QGraphicsItem* item , m_shades.childItems()) {
186 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
186 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
187 }
187 }
188 }
188 }
189
189
190 void AxisItem::setAxisPen(const QPen& pen)
190 void AxisItem::setAxisPen(const QPen& pen)
191 {
191 {
192 foreach(QGraphicsItem* item , m_axis.childItems()) {
192 foreach(QGraphicsItem* item , m_axis.childItems()) {
193 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
193 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
194 }
194 }
195 }
195 }
196
196
197 void AxisItem::setGridPen(const QPen& pen)
197 void AxisItem::setGridPen(const QPen& pen)
198 {
198 {
199 foreach(QGraphicsItem* item , m_grid.childItems()) {
199 foreach(QGraphicsItem* item , m_grid.childItems()) {
200 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
200 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
201 }
201 }
202 }
202 }
203
203
204 QVector<qreal> AxisItem::calculateLayout() const
204 QVector<qreal> AxisItem::calculateLayout() const
205 {
205 {
206 Q_ASSERT(m_ticksCount>=2);
206 Q_ASSERT(m_ticksCount>=2);
207
207
208 QVector<qreal> points;
208 QVector<qreal> points;
209 points.resize(m_ticksCount);
209 points.resize(m_ticksCount);
210
210
211 switch (m_type)
211 switch (m_type)
212 {
212 {
213 case X_AXIS:
213 case X_AXIS:
214 {
214 {
215 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
215 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
216 for (int i = 0; i < m_ticksCount; ++i) {
216 for (int i = 0; i < m_ticksCount; ++i) {
217 int x = i * deltaX + m_rect.left();
217 int x = i * deltaX + m_rect.left();
218 points[i] = x;
218 points[i] = x;
219 }
219 }
220 }
220 }
221 break;
221 break;
222 case Y_AXIS:
222 case Y_AXIS:
223 {
223 {
224 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
224 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
225 for (int i = 0; i < m_ticksCount; ++i) {
225 for (int i = 0; i < m_ticksCount; ++i) {
226 int y = i * -deltaY + m_rect.bottom();
226 int y = i * -deltaY + m_rect.bottom();
227 points[i] = y;
227 points[i] = y;
228 }
228 }
229 }
229 }
230 break;
230 break;
231 }
231 }
232 return points;
232 return points;
233 }
233 }
234
234
235 void AxisItem::setLayout(QVector<qreal>& layout)
235 void AxisItem::setLayout(QVector<qreal>& layout)
236 {
236 {
237 int diff = m_layoutVector.size() - layout.size();
237 int diff = m_layoutVector.size() - layout.size();
238
238
239 if(diff>0) {
239 if(diff>0) {
240 deleteItems(diff);
240 deleteItems(diff);
241 }
241 }
242 else if(diff<0) {
242 else if(diff<0) {
243 createItems(-diff);
243 createItems(-diff);
244 }
244 }
245
245
246 if(diff!=0) handleAxisUpdated();
246 if(diff!=0) handleAxisUpdated();
247
247
248 QStringList ticksList = createLabels(layout.size(),m_min,m_max);
248 QStringList ticksList = createLabels(layout.size(),m_min,m_max);
249
249
250 QList<QGraphicsItem *> lines = m_grid.childItems();
250 QList<QGraphicsItem *> lines = m_grid.childItems();
251 QList<QGraphicsItem *> labels = m_labels.childItems();
251 QList<QGraphicsItem *> labels = m_labels.childItems();
252 QList<QGraphicsItem *> shades = m_shades.childItems();
252 QList<QGraphicsItem *> shades = m_shades.childItems();
253 QList<QGraphicsItem *> axis = m_axis.childItems();
253 QList<QGraphicsItem *> axis = m_axis.childItems();
254
254
255 Q_ASSERT(labels.size() == ticksList.size());
255 Q_ASSERT(labels.size() == ticksList.size());
256 Q_ASSERT(layout.size() == ticksList.size());
256 Q_ASSERT(layout.size() == ticksList.size());
257 Q_ASSERT(layout.size() == m_ticksCount);
257 Q_ASSERT(layout.size() == m_ticksCount);
258
258
259 switch (m_type)
259 switch (m_type)
260 {
260 {
261 case X_AXIS:
261 case X_AXIS:
262 {
262 {
263 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
263 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
264 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
264 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
265
265
266 for (int i = 0; i < layout.size(); ++i) {
266 for (int i = 0; i < layout.size(); ++i) {
267 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
267 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
268 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
268 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
269 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
269 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
270 labelItem->setText(ticksList.at(i));
270 labelItem->setText(ticksList.at(i));
271 QPointF center = labelItem->boundingRect().center();
271 QPointF center = labelItem->boundingRect().center();
272 labelItem->setTransformOriginPoint(center.x(), center.y());
272 labelItem->setTransformOriginPoint(center.x(), center.y());
273 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
273 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
274 if(i%2 && i+1 < layout.size() && i>1) {
274 if(i%2 && i+1 < layout.size() && i>1) {
275 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
275 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
276 rectItem->setRect(layout[i],m_rect.top(),layout[i+1]-layout[i],m_rect.height());
276 rectItem->setRect(layout[i],m_rect.top(),layout[i+1]-layout[i],m_rect.height());
277 }
277 }
278 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
278 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
279 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
279 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
280 }
280 }
281 }
281 }
282 break;
282 break;
283
283
284 case Y_AXIS:
284 case Y_AXIS:
285 {
285 {
286 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
286 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
287 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
287 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
288
288
289 for (int i = 0; i < layout.size(); ++i) {
289 for (int i = 0; i < layout.size(); ++i) {
290 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
290 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
291 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
291 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
292 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
292 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
293 labelItem->setText(ticksList.at(i));
293 labelItem->setText(ticksList.at(i));
294 QPointF center = labelItem->boundingRect().center();
294 QPointF center = labelItem->boundingRect().center();
295 labelItem->setTransformOriginPoint(center.x(), center.y());
295 labelItem->setTransformOriginPoint(center.x(), center.y());
296 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y());
296 labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y());
297 if(i%2 && i+1 < layout.size() && i>1) {
297 if(i%2 && i+1 < layout.size() && i>1) {
298 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
298 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2));
299 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i]-layout[i+1]);
299 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i]-layout[i+1]);
300 }
300 }
301 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
301 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
302 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
302 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
303 }
303 }
304 }
304 }
305 break;
305 break;
306 default:
306 default:
307 qDebug()<<"Unknown axis type";
307 qDebug()<<"Unknown axis type";
308 break;
308 break;
309 }
309 }
310
310
311 m_layoutVector=layout;
311 m_layoutVector=layout;
312 }
312 }
313
313
314 bool AxisItem::isEmpty()
314 bool AxisItem::isEmpty()
315 {
315 {
316 return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0;
316 return m_rect.isEmpty() || m_min==m_max || m_ticksCount==0;
317 }
317 }
318
318
319 //handlers
319 //handlers
320
320
321 void AxisItem::handleAxisCategoriesUpdated()
321 void AxisItem::handleAxisCategoriesUpdated()
322 {
322 {
323 if(isEmpty()) return;
323 if(isEmpty()) return;
324 updateLayout(m_layoutVector);
324 updateLayout(m_layoutVector);
325 }
325 }
326
326
327 void AxisItem::handleAxisUpdated()
327 void AxisItem::handleAxisUpdated()
328 {
328 {
329
329
330 if(isEmpty()) return;
330 if(isEmpty()) return;
331
331
332 if(m_chartAxis->isAxisVisible()) {
332 if(m_chartAxis->isAxisVisible()) {
333 setAxisOpacity(100);
333 setAxisOpacity(100);
334 }
334 }
335 else {
335 else {
336 setAxisOpacity(0);
336 setAxisOpacity(0);
337 }
337 }
338
338
339 if(m_chartAxis->isGridVisible()) {
339 if(m_chartAxis->isGridLineVisible()) {
340 setGridOpacity(100);
340 setGridOpacity(100);
341 }
341 }
342 else {
342 else {
343 setGridOpacity(0);
343 setGridOpacity(0);
344 }
344 }
345
345
346 if(m_chartAxis->labelsVisible())
346 if(m_chartAxis->labelsVisible())
347 {
347 {
348 setLabelsOpacity(100);
348 setLabelsOpacity(100);
349 }
349 }
350 else {
350 else {
351 setLabelsOpacity(0);
351 setLabelsOpacity(0);
352 }
352 }
353
353
354 if(m_chartAxis->shadesVisible()) {
354 if(m_chartAxis->shadesVisible()) {
355 setShadesOpacity(m_chartAxis->shadesOpacity());
355 setShadesOpacity(m_chartAxis->shadesOpacity());
356 }
356 }
357 else {
357 else {
358 setShadesOpacity(0);
358 setShadesOpacity(0);
359 }
359 }
360
360
361 setLabelsAngle(m_chartAxis->labelsAngle());
361 setLabelsAngle(m_chartAxis->labelsAngle());
362 setAxisPen(m_chartAxis->axisPen());
362 setAxisPen(m_chartAxis->axisPen());
363 setLabelsPen(m_chartAxis->labelsPen());
363 setLabelsPen(m_chartAxis->labelsPen());
364 setLabelsBrush(m_chartAxis->labelsBrush());
364 setLabelsBrush(m_chartAxis->labelsBrush());
365 setLabelsFont(m_chartAxis->labelsFont());
365 setLabelsFont(m_chartAxis->labelsFont());
366 setGridPen(m_chartAxis->gridPen());
366 setGridPen(m_chartAxis->gridLinePen());
367 setShadesPen(m_chartAxis->shadesPen());
367 setShadesPen(m_chartAxis->shadesPen());
368 setShadesBrush(m_chartAxis->shadesBrush());
368 setShadesBrush(m_chartAxis->shadesBrush());
369
369
370 }
370 }
371
371
372 void AxisItem::handleRangeChanged(qreal min, qreal max,int tickCount)
372 void AxisItem::handleRangeChanged(qreal min, qreal max,int tickCount)
373 {
373 {
374 m_min = min;
374 m_min = min;
375 m_max = max;
375 m_max = max;
376 m_ticksCount = tickCount;
376 m_ticksCount = tickCount;
377
377
378 /*= qrand()%10;
378 /*= qrand()%10;
379
379
380 while(m_ticksCount<2){
380 while(m_ticksCount<2){
381 m_ticksCount = qrand()%10;
381 m_ticksCount = qrand()%10;
382 }
382 }
383
383
384 qDebug()<<"Warning : This is testing . Simulating new random ticks "<< m_ticksCount;
384 qDebug()<<"Warning : This is testing . Simulating new random ticks "<< m_ticksCount;
385 //m_chartAxis->setTicksCount(m_ticksCount);
385 //m_chartAxis->setTicksCount(m_ticksCount);
386 */
386 */
387
387
388 if(isEmpty()) return;
388 if(isEmpty()) return;
389 QVector<qreal> layout = calculateLayout();
389 QVector<qreal> layout = calculateLayout();
390 updateLayout(layout);
390 updateLayout(layout);
391
391
392 }
392 }
393
393
394 void AxisItem::handleGeometryChanged(const QRectF& rect)
394 void AxisItem::handleGeometryChanged(const QRectF& rect)
395 {
395 {
396 m_rect = rect;
396 m_rect = rect;
397 if(isEmpty()) return;
397 if(isEmpty()) return;
398 QVector<qreal> layout = calculateLayout();
398 QVector<qreal> layout = calculateLayout();
399 updateLayout(layout);
399 updateLayout(layout);
400 }
400 }
401
401
402 //painter
402 //painter
403
403
404 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
404 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
405 {
405 {
406 Q_UNUSED(painter);
406 Q_UNUSED(painter);
407 Q_UNUSED(option);
407 Q_UNUSED(option);
408 Q_UNUSED(widget);
408 Q_UNUSED(widget);
409 }
409 }
410
410
411 //TODO "nice numbers algorithm"
411 //TODO "nice numbers algorithm"
412 #include "moc_axisitem_p.cpp"
412 #include "moc_axisitem_p.cpp"
413
413
414 QTCOMMERCIALCHART_END_NAMESPACE
414 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,391 +1,391
1 #include "qchartaxis.h"
1 #include "qchartaxis.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
5 /*!
6 \class QChartAxis
6 \class QChartAxis
7 \brief The QChartAxis class is used for manipulating chart's axis
7 \brief The QChartAxis class is used for manipulating chart's axis
8 and for adding optional axes to the chart.
8 and for adding optional axes to the chart.
9 \mainclass
9 \mainclass
10
10
11 There is only one x Axis, however there can be multiple y axes.
11 There is only one x Axis, however there can be multiple y axes.
12 Each chart series can be bound to exactly one Y axis and the share common X axis.
12 Each chart series can be bound to exactly one Y axis and the share common X axis.
13 Axis can be setup to show axis line with ticks, gird lines and shades.
13 Axis can be setup to show axis line with ticks, gird lines and shades.
14
14
15 */
15 */
16
16
17 /*!
17 /*!
18 \fn bool QChartAxis::isAxisVisible() const
18 \fn bool QChartAxis::isAxisVisible() const
19 \brief Returns if axis is visible
19 \brief Returns if axis is visible
20 \sa setAxisVisible()
20 \sa setAxisVisible()
21 */
21 */
22
22
23 /*!
23 /*!
24 \fn QPen QChartAxis::axisPen() const
24 \fn QPen QChartAxis::axisPen() const
25 \brief Returns pen used to draw axis and ticks.
25 \brief Returns pen used to draw axis and ticks.
26 \sa setAxisPen()
26 \sa setAxisPen()
27 */
27 */
28
28
29
29
30 /*!
30 /*!
31 \fn bool QChartAxis::isGridVisible() const
31 \fn bool QChartAxis::isGridLineVisible() const
32 \brief Returns if grid is visible
32 \brief Returns if grid is visible
33 \sa setGridVisible()
33 \sa setGridLineVisible()
34 */
34 */
35
35
36 /*!
36 /*!
37 \fn QPen QChartAxis::gridPen() const
37 \fn QPen QChartAxis::gridPen() const
38 \brief Returns pen used to draw grid.
38 \brief Returns pen used to draw grid.
39 \sa setGridPen()
39 \sa setGridPen()
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn bool QChartAxis::labelsVisible() const
43 \fn bool QChartAxis::labelsVisible() const
44 \brief Returns if grid is visible
44 \brief Returns if grid is visible
45 \sa setLabelsVisible()
45 \sa setLabelsVisible()
46 */
46 */
47
47
48 /*!
48 /*!
49 \fn QPen QChartAxis::labelsPen() const
49 \fn QPen QChartAxis::labelsPen() const
50 \brief Returns the pen used to labels.
50 \brief Returns the pen used to labels.
51 \sa setLabelsPen()
51 \sa setLabelsPen()
52 */
52 */
53
53
54 /*!
54 /*!
55 \fn QBrush QChartAxis::labelsBrush() const
55 \fn QBrush QChartAxis::labelsBrush() const
56 \brief Returns brush used to draw labels.
56 \brief Returns brush used to draw labels.
57 \sa setLabelsBrush()
57 \sa setLabelsBrush()
58 */
58 */
59
59
60 /*!
60 /*!
61 \fn QFont QChartAxis::labelsFont() const
61 \fn QFont QChartAxis::labelsFont() const
62 \brief Returns font used to draw labels.
62 \brief Returns font used to draw labels.
63 \sa setLabelsFont()
63 \sa setLabelsFont()
64 */
64 */
65
65
66 /*!
66 /*!
67 \fn QFont QChartAxis::labelsAngle() const
67 \fn QFont QChartAxis::labelsAngle() const
68 \brief Returns angle used to draw labels.
68 \brief Returns angle used to draw labels.
69 \sa setLabelsAngle()
69 \sa setLabelsAngle()
70 */
70 */
71
71
72 /*!
72 /*!
73 \fn bool QChartAxis::shadesVisible() const
73 \fn bool QChartAxis::shadesVisible() const
74 \brief Returns if shades are visible.
74 \brief Returns if shades are visible.
75 \sa setShadesVisible()
75 \sa setShadesVisible()
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn qreal QChartAxis::shadesOpacity() const
79 \fn qreal QChartAxis::shadesOpacity() const
80 \brief Returns opacity of shades.
80 \brief Returns opacity of shades.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn QPen QChartAxis::shadesPen() const
84 \fn QPen QChartAxis::shadesPen() const
85 \brief Returns pen used to draw shades.
85 \brief Returns pen used to draw shades.
86 \sa setShadesPen()
86 \sa setShadesPen()
87 */
87 */
88
88
89 /*!
89 /*!
90 \fn QBrush QChartAxis::shadesBrush() const
90 \fn QBrush QChartAxis::shadesBrush() const
91 \brief Returns brush used to draw shades.
91 \brief Returns brush used to draw shades.
92 \sa setShadesBrush()
92 \sa setShadesBrush()
93 */
93 */
94
94
95 /*!
95 /*!
96 \fn qreal QChartAxis::min() const
96 \fn qreal QChartAxis::min() const
97 \brief Returns minimum value on the axis.
97 \brief Returns minimum value on the axis.
98 \sa setMin()
98 \sa setMin()
99 */
99 */
100
100
101 /*!
101 /*!
102 \fn qreal QChartAxis::max() const
102 \fn qreal QChartAxis::max() const
103 \brief Returns maximim value on the axis.
103 \brief Returns maximim value on the axis.
104 \sa setMax()
104 \sa setMax()
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QChartAxis::minChanged(qreal min)
108 \fn void QChartAxis::minChanged(qreal min)
109 \brief Axis emits signal when \a min of axis has changed.
109 \brief Axis emits signal when \a min of axis has changed.
110 */
110 */
111
111
112 /*!
112 /*!
113 \fn void QChartAxis::maxChanged(qreal max)
113 \fn void QChartAxis::maxChanged(qreal max)
114 \brief Axis emits signal when \a max of axis has changed.
114 \brief Axis emits signal when \a max of axis has changed.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
118 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
119 \brief Axis emits signal when \a min or \a max of axis has changed.
119 \brief Axis emits signal when \a min or \a max of axis has changed.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn int QChartAxis::ticksCount() const
123 \fn int QChartAxis::ticksCount() const
124 \brief Return number of ticks on the axis
124 \brief Return number of ticks on the axis
125 \sa setTicksCount()
125 \sa setTicksCount()
126 */
126 */
127
127
128 /*!
128 /*!
129 \fn void QChartAxis::updated()
129 \fn void QChartAxis::updated()
130 \brief \internal
130 \brief \internal
131 */
131 */
132
132
133 /*!
133 /*!
134 \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
134 \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
135 \brief \internal \a min \a max
135 \brief \internal \a min \a max
136 */
136 */
137
137
138 /*!
138 /*!
139 Constructs new axis object which is a child of \a parent. Ownership is taken by
139 Constructs new axis object which is a child of \a parent. Ownership is taken by
140 QChatView or QChart when axis added.
140 QChatView or QChart when axis added.
141 */
141 */
142
142
143 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
143 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
144 m_axisVisible(true),
144 m_axisVisible(true),
145 m_gridVisible(true),
145 m_gridLineVisible(true),
146 m_labelsVisible(true),
146 m_labelsVisible(true),
147 m_labelsAngle(0),
147 m_labelsAngle(0),
148 m_shadesVisible(true),
148 m_shadesVisible(true),
149 m_shadesOpacity(1.0),
149 m_shadesOpacity(1.0),
150 m_min(0),
150 m_min(0),
151 m_max(0),
151 m_max(0),
152 m_ticksCount(5)
152 m_ticksCount(5)
153 {
153 {
154
154
155 }
155 }
156
156
157 /*!
157 /*!
158 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
158 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
159 */
159 */
160
160
161 QChartAxis::~QChartAxis()
161 QChartAxis::~QChartAxis()
162 {
162 {
163 }
163 }
164
164
165 /*!
165 /*!
166 Sets \a pen used to draw axis line and ticks.
166 Sets \a pen used to draw axis line and ticks.
167 */
167 */
168 void QChartAxis::setAxisPen(const QPen& pen)
168 void QChartAxis::setAxisPen(const QPen& pen)
169 {
169 {
170 if (pen != m_axisPen) {
170 if (pen != m_axisPen) {
171 m_axisPen=pen;
171 m_axisPen=pen;
172 emit updated();
172 emit updated();
173 }
173 }
174 }
174 }
175
175
176 /*!
176 /*!
177 Sets if axis and ticks are \a visible.
177 Sets if axis and ticks are \a visible.
178 */
178 */
179 void QChartAxis::setAxisVisible(bool visible)
179 void QChartAxis::setAxisVisible(bool visible)
180 {
180 {
181 if (m_axisVisible!=visible) {
181 if (m_axisVisible!=visible) {
182 m_axisVisible=visible;
182 m_axisVisible=visible;
183 emit updated();
183 emit updated();
184 }
184 }
185 }
185 }
186
186
187 /*!
187 /*!
188 Sets if grid is \a visible.
188 Sets if grid line is \a visible.
189 */
189 */
190 void QChartAxis::setGridVisible(bool visible)
190 void QChartAxis::setGridLineVisible(bool visible)
191 {
191 {
192 if (m_gridVisible!=visible) {
192 if (m_gridLineVisible!=visible) {
193 m_gridVisible=visible;
193 m_gridLineVisible=visible;
194 emit updated();
194 emit updated();
195 }
195 }
196 }
196 }
197
197
198 /*!
198 /*!
199 Sets \a pen used to draw grid.
199 Sets \a pen used to draw grid line.
200 */
200 */
201 void QChartAxis::setGridPen(const QPen& pen)
201 void QChartAxis::setGridLinePen(const QPen& pen)
202 {
202 {
203 if (m_gridPen!=pen) {
203 if (m_gridLinePen!=pen) {
204 m_gridPen=pen;
204 m_gridLinePen=pen;
205 emit updated();
205 emit updated();
206 }
206 }
207 }
207 }
208
208
209 /*!
209 /*!
210 Sets if axis' labels are \a visible.
210 Sets if axis' labels are \a visible.
211 */
211 */
212 void QChartAxis::setLabelsVisible(bool visible)
212 void QChartAxis::setLabelsVisible(bool visible)
213 {
213 {
214 if(m_labelsVisible!=visible) {
214 if(m_labelsVisible!=visible) {
215 m_labelsVisible=visible;
215 m_labelsVisible=visible;
216 emit updated();
216 emit updated();
217 }
217 }
218 }
218 }
219
219
220 /*!
220 /*!
221 Sets \a pen used to draw labels.
221 Sets \a pen used to draw labels.
222 */
222 */
223 void QChartAxis::setLabelsPen(const QPen& pen)
223 void QChartAxis::setLabelsPen(const QPen& pen)
224 {
224 {
225 if(m_labelsPen!=pen) {
225 if(m_labelsPen!=pen) {
226 m_labelsPen=pen;
226 m_labelsPen=pen;
227 emit updated();
227 emit updated();
228 }
228 }
229 }
229 }
230
230
231 /*!
231 /*!
232 Sets \a brush used to draw labels.
232 Sets \a brush used to draw labels.
233 */
233 */
234 void QChartAxis::setLabelsBrush(const QBrush& brush)
234 void QChartAxis::setLabelsBrush(const QBrush& brush)
235 {
235 {
236 if(m_labelsBrush!=brush) {
236 if(m_labelsBrush!=brush) {
237 m_labelsBrush=brush;
237 m_labelsBrush=brush;
238 emit updated();
238 emit updated();
239 }
239 }
240 }
240 }
241
241
242 /*!
242 /*!
243 Sets \a font used to draw labels.
243 Sets \a font used to draw labels.
244 */
244 */
245 void QChartAxis::setLabelsFont(const QFont& font)
245 void QChartAxis::setLabelsFont(const QFont& font)
246 {
246 {
247 if(m_labelsFont!=font) {
247 if(m_labelsFont!=font) {
248 m_labelsFont=font;
248 m_labelsFont=font;
249 emit updated();
249 emit updated();
250 }
250 }
251 }
251 }
252
252
253 /*!
253 /*!
254 Sets \a angle for all the labels on given axis.
254 Sets \a angle for all the labels on given axis.
255 */
255 */
256 void QChartAxis::setLabelsAngle(int angle)
256 void QChartAxis::setLabelsAngle(int angle)
257 {
257 {
258 if(m_labelsAngle!=angle) {
258 if(m_labelsAngle!=angle) {
259 m_labelsAngle=angle;
259 m_labelsAngle=angle;
260 emit updated();
260 emit updated();
261 }
261 }
262 }
262 }
263
263
264 /*!
264 /*!
265 Sets if shades are \a visible.
265 Sets if shades are \a visible.
266 */
266 */
267 void QChartAxis::setShadesVisible(bool visible)
267 void QChartAxis::setShadesVisible(bool visible)
268 {
268 {
269 if(m_shadesVisible!=visible) {
269 if(m_shadesVisible!=visible) {
270 m_shadesVisible=visible;
270 m_shadesVisible=visible;
271 emit updated();
271 emit updated();
272 }
272 }
273 }
273 }
274
274
275 /*!
275 /*!
276 Sets \a pen used to draw shades.
276 Sets \a pen used to draw shades.
277 */
277 */
278 void QChartAxis::setShadesPen(const QPen& pen)
278 void QChartAxis::setShadesPen(const QPen& pen)
279 {
279 {
280 if(m_shadesPen!=pen) {
280 if(m_shadesPen!=pen) {
281 m_shadesPen=pen;
281 m_shadesPen=pen;
282 emit updated();
282 emit updated();
283 }
283 }
284 }
284 }
285
285
286 /*!
286 /*!
287 Sets \a brush used to draw shades.
287 Sets \a brush used to draw shades.
288 */
288 */
289 void QChartAxis::setShadesBrush(const QBrush& brush)
289 void QChartAxis::setShadesBrush(const QBrush& brush)
290 {
290 {
291 if(m_shadesBrush!=brush) {
291 if(m_shadesBrush!=brush) {
292 m_shadesBrush=brush;
292 m_shadesBrush=brush;
293 emit updated();
293 emit updated();
294 }
294 }
295 }
295 }
296
296
297 /*!
297 /*!
298 Sets \a opacity of the shades.
298 Sets \a opacity of the shades.
299 */
299 */
300 void QChartAxis::setShadesOpacity(qreal opacity)
300 void QChartAxis::setShadesOpacity(qreal opacity)
301 {
301 {
302 if(m_shadesOpacity!=opacity) {
302 if(m_shadesOpacity!=opacity) {
303 m_shadesOpacity=opacity;
303 m_shadesOpacity=opacity;
304 emit updated();
304 emit updated();
305 }
305 }
306 }
306 }
307
307
308 /*!
308 /*!
309 Sets \a min value on the axis.
309 Sets \a min value on the axis.
310 */
310 */
311 void QChartAxis::setMin(qreal min)
311 void QChartAxis::setMin(qreal min)
312 {
312 {
313 setRange(min,m_max);
313 setRange(min,m_max);
314 }
314 }
315
315
316 /*!
316 /*!
317 Sets \a max value on the axis.
317 Sets \a max value on the axis.
318 */
318 */
319 void QChartAxis::setMax(qreal max)
319 void QChartAxis::setMax(qreal max)
320 {
320 {
321 setRange(m_min,max);
321 setRange(m_min,max);
322 }
322 }
323
323
324 /*!
324 /*!
325 Sets range from \a min to \a max on the axis.
325 Sets range from \a min to \a max on the axis.
326 */
326 */
327 void QChartAxis::setRange(qreal min, qreal max)
327 void QChartAxis::setRange(qreal min, qreal max)
328 {
328 {
329
329
330
330
331 bool changed = false;
331 bool changed = false;
332 if(m_min!=min) {
332 if(m_min!=min) {
333 m_min=min;
333 m_min=min;
334 changed=true;
334 changed=true;
335 emit minChanged(min);
335 emit minChanged(min);
336 }
336 }
337
337
338 if(m_max!=max) {
338 if(m_max!=max) {
339 m_max=max;
339 m_max=max;
340 changed=true;
340 changed=true;
341 emit maxChanged(max);
341 emit maxChanged(max);
342 }
342 }
343
343
344 if(changed) {
344 if(changed) {
345 emit rangeChanged(m_min,m_max,m_ticksCount);
345 emit rangeChanged(m_min,m_max,m_ticksCount);
346 }
346 }
347 }
347 }
348
348
349 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
349 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max)
350 {
350 {
351 setRange(min,max);
351 setRange(min,max);
352 }
352 }
353
353
354 /*!
354 /*!
355 Sets \a count for ticks on the axis.
355 Sets \a count for ticks on the axis.
356 */
356 */
357 void QChartAxis::setTicksCount(int count)
357 void QChartAxis::setTicksCount(int count)
358 {
358 {
359 if(m_ticksCount!=count) {
359 if(m_ticksCount!=count) {
360 m_ticksCount=count;
360 m_ticksCount=count;
361 emit rangeChanged(m_min,m_max,m_ticksCount);
361 emit rangeChanged(m_min,m_max,m_ticksCount);
362 }
362 }
363 }
363 }
364
364
365 /*!
365 /*!
366 Sets axis, shades, labels and grid lines to be visible.
366 Sets axis, shades, labels and grid lines to be visible.
367 */
367 */
368 void QChartAxis::show()
368 void QChartAxis::show()
369 {
369 {
370 m_axisVisible=true;
370 m_axisVisible=true;
371 m_gridVisible=true;
371 m_gridLineVisible=true;
372 m_labelsVisible=true;
372 m_labelsVisible=true;
373 m_shadesVisible=true;
373 m_shadesVisible=true;
374 emit updated();
374 emit updated();
375 }
375 }
376
376
377 /*!
377 /*!
378 Sets axis, shades, labels and grid lines to not be visible.
378 Sets axis, shades, labels and grid lines to not be visible.
379 */
379 */
380 void QChartAxis::hide()
380 void QChartAxis::hide()
381 {
381 {
382 m_axisVisible=false;
382 m_axisVisible=false;
383 m_gridVisible=false;
383 m_gridLineVisible=false;
384 m_labelsVisible=false;
384 m_labelsVisible=false;
385 m_shadesVisible=false;
385 m_shadesVisible=false;
386 emit updated();
386 emit updated();
387 }
387 }
388
388
389 #include "moc_qchartaxis.cpp"
389 #include "moc_qchartaxis.cpp"
390
390
391 QTCOMMERCIALCHART_END_NAMESPACE
391 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,106 +1,106
1 #ifndef QCHARTAXIS_H_
1 #ifndef QCHARTAXIS_H_
2 #define QCHARTAXIS_H_
2 #define QCHARTAXIS_H_
3
3
4 #include <qchartaxiscategories.h>
4 #include <qchartaxiscategories.h>
5 #include <QPen>
5 #include <QPen>
6 #include <QFont>
6 #include <QFont>
7
7
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
11 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
12 {
12 {
13 Q_OBJECT
13 Q_OBJECT
14 public:
14 public:
15 QChartAxis(QObject* parent =0);
15 QChartAxis(QObject* parent =0);
16 ~QChartAxis();
16 ~QChartAxis();
17
17
18 //axis handling
18 //axis handling
19 bool isAxisVisible() const { return m_axisVisible;};
19 bool isAxisVisible() const { return m_axisVisible;};
20 void setAxisVisible(bool visible);
20 void setAxisVisible(bool visible);
21 void setAxisPen(const QPen& pen);
21 void setAxisPen(const QPen& pen);
22 QPen axisPen() const { return m_axisPen;};
22 QPen axisPen() const { return m_axisPen;};
23
23
24 //grid handling
24 //grid handling
25 bool isGridVisible() const { return m_gridVisible;};
25 bool isGridLineVisible() const { return m_gridLineVisible;};
26 void setGridVisible(bool visible);
26 void setGridLineVisible(bool visible);
27 void setGridPen(const QPen& pen);
27 void setGridLinePen(const QPen& pen);
28 QPen gridPen() const {return m_gridPen;}
28 QPen gridLinePen() const {return m_gridLinePen;}
29
29
30 //labels handling
30 //labels handling
31 bool labelsVisible() const { return m_labelsVisible;};
31 bool labelsVisible() const { return m_labelsVisible;};
32 void setLabelsVisible(bool visible);
32 void setLabelsVisible(bool visible);
33 void setLabelsPen(const QPen& pen);
33 void setLabelsPen(const QPen& pen);
34 QPen labelsPen() const { return m_labelsPen;}
34 QPen labelsPen() const { return m_labelsPen;}
35 void setLabelsBrush(const QBrush& brush);
35 void setLabelsBrush(const QBrush& brush);
36 QBrush labelsBrush() const { return m_labelsBrush;}
36 QBrush labelsBrush() const { return m_labelsBrush;}
37 void setLabelsFont(const QFont& font);
37 void setLabelsFont(const QFont& font);
38 QFont labelsFont() const { return m_labelsFont;}
38 QFont labelsFont() const { return m_labelsFont;}
39 void setLabelsAngle(int angle);
39 void setLabelsAngle(int angle);
40 int labelsAngle() const { return m_labelsAngle;};
40 int labelsAngle() const { return m_labelsAngle;};
41
41
42 //shades handling
42 //shades handling
43 bool shadesVisible() const { return m_shadesVisible;};
43 bool shadesVisible() const { return m_shadesVisible;};
44 void setShadesVisible(bool visible);
44 void setShadesVisible(bool visible);
45 void setShadesPen(const QPen& pen);
45 void setShadesPen(const QPen& pen);
46 QPen shadesPen() const { return m_shadesPen;}
46 QPen shadesPen() const { return m_shadesPen;}
47 void setShadesBrush(const QBrush& brush);
47 void setShadesBrush(const QBrush& brush);
48 QBrush shadesBrush() const { return m_shadesBrush;}
48 QBrush shadesBrush() const { return m_shadesBrush;}
49 void setShadesOpacity(qreal opacity);
49 void setShadesOpacity(qreal opacity);
50 qreal shadesOpacity() const { return m_shadesOpacity;}
50 qreal shadesOpacity() const { return m_shadesOpacity;}
51
51
52 //range handling
52 //range handling
53 void setMin(qreal min);
53 void setMin(qreal min);
54 qreal min() const { return m_min;};
54 qreal min() const { return m_min;};
55 void setMax(qreal max);
55 void setMax(qreal max);
56 qreal max() const { return m_max;};
56 qreal max() const { return m_max;};
57 void setRange(qreal min, qreal max);
57 void setRange(qreal min, qreal max);
58
58
59 //ticks handling
59 //ticks handling
60 void setTicksCount(int count);
60 void setTicksCount(int count);
61 int ticksCount() const { return m_ticksCount;}
61 int ticksCount() const { return m_ticksCount;}
62
62
63 QChartAxisCategories* categories() { return &m_category; }
63 QChartAxisCategories* categories() { return &m_category; }
64
64
65 void show();
65 void show();
66 void hide();
66 void hide();
67
67
68 signals:
68 signals:
69 void minChanged(qreal min);
69 void minChanged(qreal min);
70 void maxChanged(qreal max);
70 void maxChanged(qreal max);
71 void rangeChanged(qreal min, qreal max,int ticksCount);
71 void rangeChanged(qreal min, qreal max,int ticksCount);
72
72
73 //interal signal
73 //interal signal
74 void updated();
74 void updated();
75 //internal slot
75 //internal slot
76 public slots:
76 public slots:
77 void handleAxisRangeChanged(qreal min, qreal max);
77 void handleAxisRangeChanged(qreal min, qreal max);
78
78
79 private:
79 private:
80 bool m_axisVisible;
80 bool m_axisVisible;
81 QPen m_axisPen;
81 QPen m_axisPen;
82 QBrush m_axisBrush;
82 QBrush m_axisBrush;
83
83
84 bool m_gridVisible;
84 bool m_gridLineVisible;
85 QPen m_gridPen;
85 QPen m_gridLinePen;
86
86
87 bool m_labelsVisible;
87 bool m_labelsVisible;
88 QPen m_labelsPen;
88 QPen m_labelsPen;
89 QBrush m_labelsBrush;
89 QBrush m_labelsBrush;
90 QFont m_labelsFont;
90 QFont m_labelsFont;
91 int m_labelsAngle;
91 int m_labelsAngle;
92
92
93 bool m_shadesVisible;
93 bool m_shadesVisible;
94 QPen m_shadesPen;
94 QPen m_shadesPen;
95 QBrush m_shadesBrush;
95 QBrush m_shadesBrush;
96 qreal m_shadesOpacity;
96 qreal m_shadesOpacity;
97
97
98 qreal m_min;
98 qreal m_min;
99 qreal m_max;
99 qreal m_max;
100
100
101 int m_ticksCount;
101 int m_ticksCount;
102 QChartAxisCategories m_category;
102 QChartAxisCategories m_category;
103 };
103 };
104
104
105 QTCOMMERCIALCHART_END_NAMESPACE
105 QTCOMMERCIALCHART_END_NAMESPACE
106 #endif /* QCHARTAXIS_H_ */
106 #endif /* QCHARTAXIS_H_ */
General Comments 0
You need to be logged in to leave comments. Login now