@@ -1,115 +1,115 | |||||
1 |
|
1 | |||
2 | LIBRARY_NAME = QtCommercialChart |
|
2 | LIBRARY_NAME = QtCommercialChart | |
3 |
|
3 | |||
4 | ##################### SHADOW CONFIG ################################################# |
|
4 | ##################### SHADOW CONFIG ################################################# | |
5 |
|
5 | |||
6 | !contains($${PWD}, $${OUT_PWD}){ |
|
6 | !contains($${PWD}, $${OUT_PWD}){ | |
7 | search = "$$PWD:::" |
|
7 | search = "$$PWD:::" | |
8 | temp = $$split(search,"/") |
|
8 | temp = $$split(search,"/") | |
9 | temp = $$last(temp) |
|
9 | temp = $$last(temp) | |
10 | path = $$replace(search,$$temp,'') |
|
10 | path = $$replace(search,$$temp,'') | |
11 | temp = $$split(OUT_PWD,$$path) |
|
11 | temp = $$split(OUT_PWD,$$path) | |
12 | temp = $$split(temp,'/') |
|
12 | temp = $$split(temp,'/') | |
13 | temp = $$first(temp) |
|
13 | temp = $$first(temp) | |
14 | path = "$${path}$${temp}" |
|
14 | path = "$${path}$${temp}" | |
15 | SHADOW=$$path |
|
15 | SHADOW=$$path | |
16 | }else{ |
|
16 | }else{ | |
17 | SHADOW=$$PWD |
|
17 | SHADOW=$$PWD | |
18 | CONFIG-=development_build |
|
18 | CONFIG-=development_build | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | ##################### BUILD PATHS ################################################## |
|
21 | ##################### BUILD PATHS ################################################## | |
22 |
|
22 | |||
23 | CHART_BUILD_PUBLIC_HEADER_DIR = $$SHADOW/include |
|
23 | CHART_BUILD_PUBLIC_HEADER_DIR = $$SHADOW/include | |
24 | CHART_BUILD_PRIVATE_HEADER_DIR = $$CHART_BUILD_PUBLIC_HEADER_DIR/private |
|
24 | CHART_BUILD_PRIVATE_HEADER_DIR = $$CHART_BUILD_PUBLIC_HEADER_DIR/private | |
25 | CHART_BUILD_LIB_DIR = $$SHADOW/lib |
|
25 | CHART_BUILD_LIB_DIR = $$SHADOW/lib | |
26 | CHART_BUILD_DIR = $$SHADOW/build |
|
26 | CHART_BUILD_DIR = $$SHADOW/build | |
27 | CHART_BUILD_BIN_DIR = $$SHADOW/bin |
|
27 | CHART_BUILD_BIN_DIR = $$SHADOW/bin | |
28 | CHART_BUILD_PLUGIN_DIR = $$CHART_BUILD_BIN_DIR/QtCommercial/Chart |
|
28 | CHART_BUILD_PLUGIN_DIR = $$CHART_BUILD_BIN_DIR/QtCommercial/Chart | |
29 | CHART_BUILD_DOC_DIR = $$SHADOW/doc |
|
29 | CHART_BUILD_DOC_DIR = $$SHADOW/doc | |
30 |
|
30 | |||
31 | win32:{ |
|
31 | win32:{ | |
32 | CHART_BUILD_PUBLIC_HEADER_DIR = $$replace(CHART_BUILD_PUBLIC_HEADER_DIR, "/","\\") |
|
32 | CHART_BUILD_PUBLIC_HEADER_DIR = $$replace(CHART_BUILD_PUBLIC_HEADER_DIR, "/","\\") | |
33 | CHART_BUILD_PRIVATE_HEADER_DIR = $$replace(CHART_BUILD_PRIVATE_HEADER_DIR, "/","\\") |
|
33 | CHART_BUILD_PRIVATE_HEADER_DIR = $$replace(CHART_BUILD_PRIVATE_HEADER_DIR, "/","\\") | |
34 | CHART_BUILD_BUILD_DIR = $$replace(CHART_BUILD_BUILD_DIR, "/","\\") |
|
34 | CHART_BUILD_BUILD_DIR = $$replace(CHART_BUILD_BUILD_DIR, "/","\\") | |
35 | CHART_BUILD_BIN_DIR = $$replace(CHART_BUILD_BIN_DIR, "/","\\") |
|
35 | CHART_BUILD_BIN_DIR = $$replace(CHART_BUILD_BIN_DIR, "/","\\") | |
36 | CHART_BUILD_PLUGIN_DIR = $$replace(CHART_BUILD_PLUGIN_DIR, "/","\\") |
|
36 | CHART_BUILD_PLUGIN_DIR = $$replace(CHART_BUILD_PLUGIN_DIR, "/","\\") | |
37 | CHART_BUILD_DOC_DIR = $$replace(CHART_BUILD_DOC_DIR, "/","\\") |
|
37 | CHART_BUILD_DOC_DIR = $$replace(CHART_BUILD_DOC_DIR, "/","\\") | |
38 | CHART_BUILD_LIB_DIR = $$CHART_BUILD_BIN_DIR |
|
38 | CHART_BUILD_LIB_DIR = $$CHART_BUILD_BIN_DIR | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | mac: { |
|
41 | mac: { | |
42 | # TODO: The following qmake flags are a work-around to make QtCommercial Charts compile on |
|
42 | # TODO: The following qmake flags are a work-around to make QtCommercial Charts compile on | |
43 | # QtCommercial 4.8. On the other hand Charts builds successfully with Qt open source 4.8 |
|
43 | # QtCommercial 4.8. On the other hand Charts builds successfully with Qt open source 4.8 | |
44 | # without these definitions, so this is probably a configuration issue on QtCommercial 4.8; |
|
44 | # without these definitions, so this is probably a configuration issue on QtCommercial 4.8; | |
45 | # it should probably define the minimum OSX version to be 10.5... |
|
45 | # it should probably define the minimum OSX version to be 10.5... | |
46 | QMAKE_CXXFLAGS *= -mmacosx-version-min=10.5 |
|
46 | QMAKE_CXXFLAGS *= -mmacosx-version-min=10.5 | |
47 | QMAKE_LFLAGS *= -mmacosx-version-min=10.5 |
|
47 | QMAKE_LFLAGS *= -mmacosx-version-min=10.5 | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | ##################### DEVELOPMENT BUILD ################################################### |
|
50 | ##################### DEVELOPMENT BUILD ################################################### | |
51 |
|
51 | |||
52 | development_build: { |
|
52 | development_build: { | |
53 | DEFINES+=DEVELOPMENT_BUILD |
|
53 | DEFINES+=DEVELOPMENT_BUILD | |
54 | CONFIG+=debug_and_release |
|
54 | CONFIG+=debug_and_release | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | ##################### BUILD CONFIG ######################################################## |
|
58 | ##################### BUILD CONFIG ######################################################## | |
59 |
|
59 | |||
60 | !system_build:{ |
|
60 | !system_build:{ | |
61 |
|
61 | |||
62 | INCLUDEPATH += $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
62 | INCLUDEPATH += $$CHART_BUILD_PUBLIC_HEADER_DIR | |
63 |
|
63 | |||
64 | !win32: { |
|
64 | !win32: { | |
65 | LIBS += -L $$CHART_BUILD_LIB_DIR -Wl,-rpath,$$CHART_BUILD_LIB_DIR |
|
65 | LIBS += -L $$CHART_BUILD_LIB_DIR -Wl,-rpath,$$CHART_BUILD_LIB_DIR | |
66 | }else{ |
|
66 | }else{ | |
67 | win32-msvc*: { |
|
67 | win32-msvc*: { | |
68 | # hack fix for error: |
|
68 | # hack fix for error: | |
69 | # "LINK : fatal error LNK1146: no argument specified with option '/LIBPATH:'" |
|
69 | # "LINK : fatal error LNK1146: no argument specified with option '/LIBPATH:'" | |
70 | QMAKE_LIBDIR += $$CHART_BUILD_LIB_DIR |
|
70 | QMAKE_LIBDIR += $$CHART_BUILD_LIB_DIR | |
71 | }else{ |
|
71 | }else{ | |
72 | LIBS += -L $$CHART_BUILD_LIB_DIR |
|
72 | LIBS += -L $$CHART_BUILD_LIB_DIR | |
73 | } |
|
73 | } | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | CONFIG(debug, debug|release) { |
|
76 | CONFIG(debug, debug|release) { | |
77 | mac: LIBRARY_NAME = $$join(LIBRARY_NAME,,,_debug) |
|
77 | mac: LIBRARY_NAME = $$join(LIBRARY_NAME,,,_debug) | |
78 | win32: LIBRARY_NAME = $$join(LIBRARY_NAME,,,d) |
|
78 | win32: LIBRARY_NAME = $$join(LIBRARY_NAME,,,d) | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | LIBS += -l$$LIBRARY_NAME |
|
81 | LIBS += -l$$LIBRARY_NAME | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | mac: { |
|
84 | mac: { | |
85 | # This is a hack to make binaries to use the internal version of the QtCommercial Charts library on OSX |
|
85 | # This is a hack to make binaries to use the internal version of the QtCommercial Charts library on OSX | |
86 | CHARTS_LIB_NAME = libQtCommercialChart.1.dylib |
|
86 | CHARTS_LIB_NAME = libQtCommercialChart.1.dylib | |
87 | CONFIG(debug, debug|release) { |
|
87 | CONFIG(debug, debug|release) { | |
88 | CHARTS_LIB_NAME = libQtCommercialChartd.1.dylib |
|
88 | CHARTS_LIB_NAME = libQtCommercialChartd.1.dylib | |
89 | } |
|
89 | } | |
90 | BIN_TARGET_PATH = "" |
|
90 | BIN_TARGET_PATH = "" | |
91 | exists ($$CHART_BUILD_BIN_DIR"/"$$TARGET".app/Contents/MacOS/"$$TARGET) { |
|
91 | exists ($$CHART_BUILD_BIN_DIR"/"$$TARGET".app/Contents/MacOS/"$$TARGET) { | |
92 | BIN_TARGET_PATH = $$CHART_BUILD_BIN_DIR"/"$$TARGET".app/Contents/MacOS/"$$TARGET |
|
92 | BIN_TARGET_PATH = $$CHART_BUILD_BIN_DIR"/"$$TARGET".app/Contents/MacOS/"$$TARGET | |
93 | } |
|
93 | } | |
94 | exists ($$CHART_BUILD_BIN_DIR"/test/"$$TARGET".app/Contents/MacOS/"$$TARGET) { |
|
94 | exists ($$CHART_BUILD_BIN_DIR"/test/"$$TARGET".app/Contents/MacOS/"$$TARGET) { | |
95 | # Executable in test folder |
|
95 | # Executable in test folder | |
96 | BIN_TARGET_PATH = $$CHART_BUILD_BIN_DIR"/test/"$$TARGET".app/Contents/MacOS/"$$TARGET |
|
96 | BIN_TARGET_PATH = $$CHART_BUILD_BIN_DIR"/test/"$$TARGET".app/Contents/MacOS/"$$TARGET | |
97 | } |
|
97 | } | |
98 | exists ($$CHART_BUILD_BIN_DIR"/test/tst_"$$TARGET".app/Contents/MacOS/tst_"$$TARGET) { |
|
98 | exists ($$CHART_BUILD_BIN_DIR"/test/tst_"$$TARGET".app/Contents/MacOS/tst_"$$TARGET) { | |
99 | # Executable in test folder with custom target "tst_NNN" |
|
99 | # Executable in test folder with custom target "tst_NNN" | |
100 | BIN_TARGET_PATH = $$CHART_BUILD_BIN_DIR"/test/tst_"$$TARGET".app/Contents/MacOS/tst_"$$TARGET |
|
100 | BIN_TARGET_PATH = $$CHART_BUILD_BIN_DIR"/test/tst_"$$TARGET".app/Contents/MacOS/tst_"$$TARGET | |
101 | } |
|
101 | } | |
102 | exists($$CHART_BUILD_PLUGIN_DIR"/lib"$$TARGET".dylib") { |
|
102 | exists($$CHART_BUILD_PLUGIN_DIR"/lib"$$TARGET".dylib") { | |
103 | # Plugin |
|
103 | # Plugin | |
104 | BIN_TARGET_PATH = $$CHART_BUILD_PLUGIN_DIR"/lib"$$TARGET".dylib" |
|
104 | BIN_TARGET_PATH = $$CHART_BUILD_PLUGIN_DIR"/lib"$$TARGET".dylib" | |
105 | } |
|
105 | } | |
106 | !isEmpty (BIN_TARGET_PATH) { |
|
106 | !isEmpty (BIN_TARGET_PATH) { | |
107 | QMAKE_POST_LINK += install_name_tool -change $$CHARTS_LIB_NAME $$CHART_BUILD_LIB_DIR"/"$$CHARTS_LIB_NAME $$BIN_TARGET_PATH |
|
107 | QMAKE_POST_LINK += install_name_tool -change $$CHARTS_LIB_NAME $$CHART_BUILD_LIB_DIR"/"$$CHARTS_LIB_NAME $$BIN_TARGET_PATH | |
108 | } |
|
108 | } | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | }else { |
|
111 | } else { | |
112 |
|
112 | |||
113 | CONFIG += qtcommercialchart |
|
113 | CONFIG += qtcommercialchart | |
114 |
|
114 | |||
115 | } No newline at end of file |
|
115 | } |
@@ -1,121 +1,121 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QLineSeries> |
|
24 | #include <QLineSeries> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | int main(int argc, char *argv[]) |
|
28 | int main(int argc, char *argv[]) | |
29 | { |
|
29 | { | |
30 | QApplication a(argc, argv); |
|
30 | QApplication a(argc, argv); | |
31 |
|
31 | |||
32 | //![1] |
|
32 | //![1] | |
33 | QLineSeries* series = new QLineSeries(); |
|
33 | QLineSeries* series = new QLineSeries(); | |
34 | *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5); |
|
34 | *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5); | |
35 | QChart* chart = new QChart(); |
|
35 | QChart* chart = new QChart(); | |
36 | chart->addSeries(series); |
|
36 | chart->addSeries(series); | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | // Customize series |
|
40 | // Customize series | |
41 | QPen pen(QRgb(0xfdb157)); |
|
41 | QPen pen(QRgb(0xfdb157)); | |
42 | pen.setWidth(5); |
|
42 | pen.setWidth(5); | |
43 | series->setPen(pen); |
|
43 | series->setPen(pen); | |
44 |
|
44 | |||
45 | // Customize chart title |
|
45 | // Customize chart title | |
46 | QFont font; |
|
46 | QFont font; | |
47 | font.setPixelSize(18); |
|
47 | font.setPixelSize(18); | |
48 | chart->setTitleFont(font); |
|
48 | chart->setTitleFont(font); | |
49 | chart->setTitleBrush(QBrush(Qt::white)); |
|
49 | chart->setTitleBrush(QBrush(Qt::white)); | |
50 | chart->setTitle("Customchart example"); |
|
50 | chart->setTitle("Customchart example"); | |
51 |
|
51 | |||
52 | // Customize chart background |
|
52 | // Customize chart background | |
53 | QLinearGradient backgroundGradient; |
|
53 | QLinearGradient backgroundGradient; | |
54 | backgroundGradient.setStart(QPointF(0,0)); |
|
54 | backgroundGradient.setStart(QPointF(0,0)); | |
55 | backgroundGradient.setFinalStop(QPointF(0,1)); |
|
55 | backgroundGradient.setFinalStop(QPointF(0,1)); | |
56 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); |
|
56 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); | |
57 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); |
|
57 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); | |
58 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
58 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
59 | chart->setBackgroundBrush(backgroundGradient); |
|
59 | chart->setBackgroundBrush(backgroundGradient); | |
60 | //![2] |
|
60 | //![2] | |
61 |
|
61 | |||
62 | //![3] |
|
62 | //![3] | |
63 | QAxis* axisX = chart->axisX(); |
|
63 | QAxis* axisX = chart->axisX(); | |
64 | QAxis* axisY = chart->axisY(); |
|
64 | QAxis* axisY = chart->axisY(); | |
65 |
|
65 | |||
66 | // Customize axis label font |
|
66 | // Customize axis label font | |
67 | QFont labelsFont; |
|
67 | QFont labelsFont; | |
68 | labelsFont.setPixelSize(12); |
|
68 | labelsFont.setPixelSize(12); | |
69 | axisX->setLabelsFont(labelsFont); |
|
69 | axisX->setLabelsFont(labelsFont); | |
70 | axisY->setLabelsFont(labelsFont); |
|
70 | axisY->setLabelsFont(labelsFont); | |
71 |
|
71 | |||
72 | // Customize axis colors |
|
72 | // Customize axis colors | |
73 | QPen axisPen(QRgb(0xd18952)); |
|
73 | QPen axisPen(QRgb(0xd18952)); | |
74 | axisPen.setWidth(2); |
|
74 | axisPen.setWidth(2); | |
75 | axisX->setAxisPen(axisPen); |
|
75 | axisX->setAxisPen(axisPen); | |
76 | axisY->setAxisPen(axisPen); |
|
76 | axisY->setAxisPen(axisPen); | |
77 |
|
77 | |||
78 | // Customize axis label colors |
|
78 | // Customize axis label colors | |
79 | QBrush axisBrush(Qt::white); |
|
79 | QBrush axisBrush(Qt::white); | |
80 | axisX->setLabelsBrush(axisBrush); |
|
80 | axisX->setLabelsBrush(axisBrush); | |
81 | axisY->setLabelsBrush(axisBrush); |
|
81 | axisY->setLabelsBrush(axisBrush); | |
82 |
|
82 | |||
83 | // Customize grid lines and shades |
|
83 | // Customize grid lines and shades | |
84 | axisX->setGridLineVisible(false); |
|
84 | axisX->setGridLineVisible(false); | |
85 | axisY->setGridLineVisible(false); |
|
85 | axisY->setGridLineVisible(false); | |
86 | axisY->setShadesPen(Qt::NoPen); |
|
86 | axisY->setShadesPen(Qt::NoPen); | |
87 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); |
|
87 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); | |
88 | axisY->setShadesVisible(true); |
|
88 | axisY->setShadesVisible(true); | |
89 | //![3] |
|
89 | //![3] | |
90 |
|
90 | |||
91 | //![4] |
|
91 | //![4] | |
92 |
Q |
|
92 | QAxisCategories* categoriesX = chart->axisX()->categories(); | |
93 | categoriesX->insert(1,"low"); |
|
93 | categoriesX->insert(1,"low"); | |
94 | categoriesX->insert(5,"optimal"); |
|
94 | categoriesX->insert(5,"optimal"); | |
95 | categoriesX->insert(10,"high"); |
|
95 | categoriesX->insert(10,"high"); | |
96 |
|
96 | |||
97 |
Q |
|
97 | QAxisCategories* categoriesY = chart->axisY()->categories(); | |
98 | categoriesY->insert(1,"slow"); |
|
98 | categoriesY->insert(1,"slow"); | |
99 | categoriesY->insert(5,"med"); |
|
99 | categoriesY->insert(5,"med"); | |
100 | categoriesY->insert(10,"fast"); |
|
100 | categoriesY->insert(10,"fast"); | |
101 |
|
101 | |||
102 | axisX->setRange(0,10); |
|
102 | axisX->setRange(0,10); | |
103 | axisX->setTicksCount(4); |
|
103 | axisX->setTicksCount(4); | |
104 | axisY->setRange(0,10); |
|
104 | axisY->setRange(0,10); | |
105 | axisY->setTicksCount(4); |
|
105 | axisY->setTicksCount(4); | |
106 | //![4] |
|
106 | //![4] | |
107 |
|
107 | |||
108 | //![5] |
|
108 | //![5] | |
109 | QChartView* chartView = new QChartView(chart); |
|
109 | QChartView* chartView = new QChartView(chart); | |
110 | chartView->setRenderHint(QPainter::Antialiasing); |
|
110 | chartView->setRenderHint(QPainter::Antialiasing); | |
111 | //![5] |
|
111 | //![5] | |
112 |
|
112 | |||
113 | //![6] |
|
113 | //![6] | |
114 | QMainWindow window; |
|
114 | QMainWindow window; | |
115 | window.setCentralWidget(chartView); |
|
115 | window.setCentralWidget(chartView); | |
116 | window.resize(400, 300); |
|
116 | window.resize(400, 300); | |
117 | window.show(); |
|
117 | window.show(); | |
118 | //![6] |
|
118 | //![6] | |
119 |
|
119 | |||
120 | return a.exec(); |
|
120 | return a.exec(); | |
121 | } |
|
121 | } |
@@ -1,16 +1,16 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/chartaxis.cpp \ |
|
5 | $$PWD/chartaxis.cpp \ | |
6 | $$PWD/qaxis.cpp \ |
|
6 | $$PWD/qaxis.cpp \ | |
7 |
$$PWD/q |
|
7 | $$PWD/qaxiscategories.cpp | |
8 |
|
8 | |||
9 | PRIVATE_HEADERS += \ |
|
9 | PRIVATE_HEADERS += \ | |
10 | $$PWD/chartaxis_p.h \ |
|
10 | $$PWD/chartaxis_p.h \ | |
11 | $$PWD/qaxis_p.h \ |
|
11 | $$PWD/qaxis_p.h \ | |
12 |
$$PWD/q |
|
12 | $$PWD/qaxiscategories_p.h | |
13 |
|
13 | |||
14 | PUBLIC_HEADERS += \ |
|
14 | PUBLIC_HEADERS += \ | |
15 | $$PWD/qaxis.h \ |
|
15 | $$PWD/qaxis.h \ | |
16 |
$$PWD/q |
|
16 | $$PWD/qaxiscategories.h No newline at end of file |
@@ -1,466 +1,466 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartaxis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 | #include "qaxis.h" |
|
22 | #include "qaxis.h" | |
23 | #include "qaxis_p.h" |
|
23 | #include "qaxis_p.h" | |
24 |
#include "q |
|
24 | #include "qaxiscategories_p.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 | #include <cmath> |
|
29 | #include <cmath> | |
30 |
|
30 | |||
31 | static int label_padding = 5; |
|
31 | static int label_padding = 5; | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | ChartAxis::ChartAxis(QAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter), |
|
35 | ChartAxis::ChartAxis(QAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter), | |
36 | m_chartAxis(axis), |
|
36 | m_chartAxis(axis), | |
37 | m_type(type), |
|
37 | m_type(type), | |
38 | m_labelsAngle(0), |
|
38 | m_labelsAngle(0), | |
39 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
39 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
40 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), |
|
40 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
41 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), |
|
41 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
42 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), |
|
42 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), | |
43 | m_min(0), |
|
43 | m_min(0), | |
44 | m_max(0), |
|
44 | m_max(0), | |
45 | m_ticksCount(0) |
|
45 | m_ticksCount(0) | |
46 | { |
|
46 | { | |
47 | //initial initialization |
|
47 | //initial initialization | |
48 | m_axis->setZValue(ChartPresenter::AxisZValue); |
|
48 | m_axis->setZValue(ChartPresenter::AxisZValue); | |
49 | m_axis->setHandlesChildEvents(false); |
|
49 | m_axis->setHandlesChildEvents(false); | |
50 |
|
50 | |||
51 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
51 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
52 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
52 | m_grid->setZValue(ChartPresenter::GridZValue); | |
53 |
|
53 | |||
54 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
54 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
55 | QObject::connect(m_chartAxis->categories()->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); |
|
55 | QObject::connect(m_chartAxis->categories()->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); | |
56 |
|
56 | |||
57 | handleAxisUpdated(); |
|
57 | handleAxisUpdated(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | ChartAxis::~ChartAxis() |
|
60 | ChartAxis::~ChartAxis() | |
61 | { |
|
61 | { | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void ChartAxis::createItems(int count) |
|
64 | void ChartAxis::createItems(int count) | |
65 | { |
|
65 | { | |
66 |
|
66 | |||
67 | if (m_axis->children().size() == 0) |
|
67 | if (m_axis->children().size() == 0) | |
68 | m_axis->addToGroup(new AxisItem(this)); |
|
68 | m_axis->addToGroup(new AxisItem(this)); | |
69 | for (int i = 0; i < count; ++i) { |
|
69 | for (int i = 0; i < count; ++i) { | |
70 | m_grid->addToGroup(new QGraphicsLineItem()); |
|
70 | m_grid->addToGroup(new QGraphicsLineItem()); | |
71 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); |
|
71 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); | |
72 | m_axis->addToGroup(new QGraphicsLineItem()); |
|
72 | m_axis->addToGroup(new QGraphicsLineItem()); | |
73 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); |
|
73 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); | |
74 | } |
|
74 | } | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void ChartAxis::deleteItems(int count) |
|
77 | void ChartAxis::deleteItems(int count) | |
78 | { |
|
78 | { | |
79 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
79 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
80 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
80 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
81 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
81 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
82 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
82 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
83 |
|
83 | |||
84 | for (int i = 0; i < count; ++i) { |
|
84 | for (int i = 0; i < count; ++i) { | |
85 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); |
|
85 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); | |
86 | delete(lines.takeLast()); |
|
86 | delete(lines.takeLast()); | |
87 | delete(labels.takeLast()); |
|
87 | delete(labels.takeLast()); | |
88 | delete(axis.takeLast()); |
|
88 | delete(axis.takeLast()); | |
89 | } |
|
89 | } | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
92 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
93 | { |
|
93 | { | |
94 | if (animator()) { |
|
94 | if (animator()) { | |
95 | animator()->updateLayout(this,layout); |
|
95 | animator()->updateLayout(this,layout); | |
96 | } else { |
|
96 | } else { | |
97 | setLayout(layout); |
|
97 | setLayout(layout); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | bool ChartAxis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const |
|
101 | bool ChartAxis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const | |
102 | { |
|
102 | { | |
103 | Q_ASSERT(max>=min); |
|
103 | Q_ASSERT(max>=min); | |
104 | Q_ASSERT(ticks>1); |
|
104 | Q_ASSERT(ticks>1); | |
105 |
|
105 | |||
106 |
Q |
|
106 | QAxisCategories* categories = m_chartAxis->categories(); | |
107 |
|
107 | |||
108 | bool category = categories->count()>0; |
|
108 | bool category = categories->count()>0; | |
109 |
|
109 | |||
110 | if (!category) { |
|
110 | if (!category) { | |
111 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); |
|
111 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |
112 | n++; |
|
112 | n++; | |
113 | for (int i=0; i< ticks; i++) { |
|
113 | for (int i=0; i< ticks; i++) { | |
114 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
114 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
115 | labels << QString::number(value,'f',n); |
|
115 | labels << QString::number(value,'f',n); | |
116 | } |
|
116 | } | |
117 | } else { |
|
117 | } else { | |
118 | QList<qreal> values = categories->values(); |
|
118 | QList<qreal> values = categories->values(); | |
119 | for (int i=0; i< ticks; i++) { |
|
119 | for (int i=0; i< ticks; i++) { | |
120 | qreal value = (min + (i * (max - min)/ (ticks-1))); |
|
120 | qreal value = (min + (i * (max - min)/ (ticks-1))); | |
121 | int j=0; |
|
121 | int j=0; | |
122 | for (; j<values.count(); j++) { |
|
122 | for (; j<values.count(); j++) { | |
123 | if (values.at(j) > value) break; |
|
123 | if (values.at(j) > value) break; | |
124 | } |
|
124 | } | |
125 | if (j!=0) value=values.at(j-1); |
|
125 | if (j!=0) value=values.at(j-1); | |
126 |
|
126 | |||
127 | QString label = categories->label(value); |
|
127 | QString label = categories->label(value); | |
128 | labels << label; |
|
128 | labels << label; | |
129 | } |
|
129 | } | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | return category; |
|
132 | return category; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void ChartAxis::setAxisOpacity(qreal opacity) |
|
135 | void ChartAxis::setAxisOpacity(qreal opacity) | |
136 | { |
|
136 | { | |
137 | m_axis->setOpacity(opacity); |
|
137 | m_axis->setOpacity(opacity); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | qreal ChartAxis::axisOpacity() const |
|
140 | qreal ChartAxis::axisOpacity() const | |
141 | { |
|
141 | { | |
142 | return m_axis->opacity(); |
|
142 | return m_axis->opacity(); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void ChartAxis::setGridOpacity(qreal opacity) |
|
145 | void ChartAxis::setGridOpacity(qreal opacity) | |
146 | { |
|
146 | { | |
147 | m_grid->setOpacity(opacity); |
|
147 | m_grid->setOpacity(opacity); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | qreal ChartAxis::gridOpacity() const |
|
150 | qreal ChartAxis::gridOpacity() const | |
151 | { |
|
151 | { | |
152 | return m_grid->opacity(); |
|
152 | return m_grid->opacity(); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void ChartAxis::setLabelsOpacity(qreal opacity) |
|
155 | void ChartAxis::setLabelsOpacity(qreal opacity) | |
156 | { |
|
156 | { | |
157 | m_labels->setOpacity(opacity); |
|
157 | m_labels->setOpacity(opacity); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | qreal ChartAxis::labelsOpacity() const |
|
160 | qreal ChartAxis::labelsOpacity() const | |
161 | { |
|
161 | { | |
162 | return m_labels->opacity(); |
|
162 | return m_labels->opacity(); | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | void ChartAxis::setShadesOpacity(qreal opacity) |
|
165 | void ChartAxis::setShadesOpacity(qreal opacity) | |
166 | { |
|
166 | { | |
167 | m_shades->setOpacity(opacity); |
|
167 | m_shades->setOpacity(opacity); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | qreal ChartAxis::shadesOpacity() const |
|
170 | qreal ChartAxis::shadesOpacity() const | |
171 | { |
|
171 | { | |
172 | return m_shades->opacity(); |
|
172 | return m_shades->opacity(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void ChartAxis::setLabelsAngle(int angle) |
|
175 | void ChartAxis::setLabelsAngle(int angle) | |
176 | { |
|
176 | { | |
177 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
177 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
178 | item->setRotation(angle); |
|
178 | item->setRotation(angle); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | m_labelsAngle=angle; |
|
181 | m_labelsAngle=angle; | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void ChartAxis::setLabelsPen(const QPen &pen) |
|
184 | void ChartAxis::setLabelsPen(const QPen &pen) | |
185 | { |
|
185 | { | |
186 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
186 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
187 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
187 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | void ChartAxis::setLabelsBrush(const QBrush &brush) |
|
191 | void ChartAxis::setLabelsBrush(const QBrush &brush) | |
192 | { |
|
192 | { | |
193 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
193 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
194 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
194 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
195 | } |
|
195 | } | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | void ChartAxis::setLabelsFont(const QFont &font) |
|
198 | void ChartAxis::setLabelsFont(const QFont &font) | |
199 | { |
|
199 | { | |
200 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
200 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
201 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
201 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
202 | } |
|
202 | } | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void ChartAxis::setShadesBrush(const QBrush &brush) |
|
205 | void ChartAxis::setShadesBrush(const QBrush &brush) | |
206 | { |
|
206 | { | |
207 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
207 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
208 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
208 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void ChartAxis::setShadesPen(const QPen &pen) |
|
212 | void ChartAxis::setShadesPen(const QPen &pen) | |
213 | { |
|
213 | { | |
214 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
214 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
215 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
215 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
216 | } |
|
216 | } | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void ChartAxis::setAxisPen(const QPen &pen) |
|
219 | void ChartAxis::setAxisPen(const QPen &pen) | |
220 | { |
|
220 | { | |
221 | foreach(QGraphicsItem* item , m_axis->childItems()) { |
|
221 | foreach(QGraphicsItem* item , m_axis->childItems()) { | |
222 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
222 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
223 | } |
|
223 | } | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void ChartAxis::setGridPen(const QPen &pen) |
|
226 | void ChartAxis::setGridPen(const QPen &pen) | |
227 | { |
|
227 | { | |
228 | foreach(QGraphicsItem* item , m_grid->childItems()) { |
|
228 | foreach(QGraphicsItem* item , m_grid->childItems()) { | |
229 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
229 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | QVector<qreal> ChartAxis::calculateLayout() const |
|
233 | QVector<qreal> ChartAxis::calculateLayout() const | |
234 | { |
|
234 | { | |
235 | Q_ASSERT(m_ticksCount>=2); |
|
235 | Q_ASSERT(m_ticksCount>=2); | |
236 |
|
236 | |||
237 | QVector<qreal> points; |
|
237 | QVector<qreal> points; | |
238 | points.resize(m_ticksCount); |
|
238 | points.resize(m_ticksCount); | |
239 |
|
239 | |||
240 | switch (m_type) |
|
240 | switch (m_type) | |
241 | { |
|
241 | { | |
242 | case X_AXIS: |
|
242 | case X_AXIS: | |
243 | { |
|
243 | { | |
244 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); |
|
244 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
245 | for (int i = 0; i < m_ticksCount; ++i) { |
|
245 | for (int i = 0; i < m_ticksCount; ++i) { | |
246 | int x = i * deltaX + m_rect.left(); |
|
246 | int x = i * deltaX + m_rect.left(); | |
247 | points[i] = x; |
|
247 | points[i] = x; | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 | break; |
|
250 | break; | |
251 | case Y_AXIS: |
|
251 | case Y_AXIS: | |
252 | { |
|
252 | { | |
253 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); |
|
253 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); | |
254 | for (int i = 0; i < m_ticksCount; ++i) { |
|
254 | for (int i = 0; i < m_ticksCount; ++i) { | |
255 | int y = i * -deltaY + m_rect.bottom(); |
|
255 | int y = i * -deltaY + m_rect.bottom(); | |
256 | points[i] = y; |
|
256 | points[i] = y; | |
257 | } |
|
257 | } | |
258 | } |
|
258 | } | |
259 | break; |
|
259 | break; | |
260 | } |
|
260 | } | |
261 | return points; |
|
261 | return points; | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
264 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
265 | { |
|
265 | { | |
266 | int diff = m_layoutVector.size() - layout.size(); |
|
266 | int diff = m_layoutVector.size() - layout.size(); | |
267 |
|
267 | |||
268 | if (diff>0) { |
|
268 | if (diff>0) { | |
269 | deleteItems(diff); |
|
269 | deleteItems(diff); | |
270 | } else if (diff<0) { |
|
270 | } else if (diff<0) { | |
271 | createItems(-diff); |
|
271 | createItems(-diff); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | if( diff!=0) handleAxisUpdated(); |
|
274 | if( diff!=0) handleAxisUpdated(); | |
275 |
|
275 | |||
276 | QStringList ticksList; |
|
276 | QStringList ticksList; | |
277 |
|
277 | |||
278 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); |
|
278 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
279 |
|
279 | |||
280 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
280 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
281 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
281 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
282 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
282 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
283 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
283 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
284 |
|
284 | |||
285 | Q_ASSERT(labels.size() == ticksList.size()); |
|
285 | Q_ASSERT(labels.size() == ticksList.size()); | |
286 | Q_ASSERT(layout.size() == ticksList.size()); |
|
286 | Q_ASSERT(layout.size() == ticksList.size()); | |
287 |
|
287 | |||
288 | qreal minWidth = 0; |
|
288 | qreal minWidth = 0; | |
289 | qreal minHeight = 0; |
|
289 | qreal minHeight = 0; | |
290 |
|
290 | |||
291 | switch (m_type) |
|
291 | switch (m_type) | |
292 | { |
|
292 | { | |
293 | case X_AXIS: |
|
293 | case X_AXIS: | |
294 | { |
|
294 | { | |
295 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
295 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
296 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
296 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
297 |
|
297 | |||
298 | for (int i = 0; i < layout.size(); ++i) { |
|
298 | for (int i = 0; i < layout.size(); ++i) { | |
299 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
299 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
300 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
300 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
301 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
301 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
302 | if (!categories || i<1) { |
|
302 | if (!categories || i<1) { | |
303 | labelItem->setText(ticksList.at(i)); |
|
303 | labelItem->setText(ticksList.at(i)); | |
304 | const QRectF& rect = labelItem->boundingRect(); |
|
304 | const QRectF& rect = labelItem->boundingRect(); | |
305 | minWidth+=rect.width(); |
|
305 | minWidth+=rect.width(); | |
306 | minHeight=qMax(rect.height(),minHeight); |
|
306 | minHeight=qMax(rect.height(),minHeight); | |
307 | QPointF center = rect.center(); |
|
307 | QPointF center = rect.center(); | |
308 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
308 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
309 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
309 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
310 | } else { |
|
310 | } else { | |
311 | labelItem->setText(ticksList.at(i)); |
|
311 | labelItem->setText(ticksList.at(i)); | |
312 | const QRectF& rect = labelItem->boundingRect(); |
|
312 | const QRectF& rect = labelItem->boundingRect(); | |
313 | minWidth+=rect.width(); |
|
313 | minWidth+=rect.width(); | |
314 | minHeight=qMax(rect.height()+label_padding,minHeight); |
|
314 | minHeight=qMax(rect.height()+label_padding,minHeight); | |
315 | QPointF center = rect.center(); |
|
315 | QPointF center = rect.center(); | |
316 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
316 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
317 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); |
|
317 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | if ((i+1)%2 && i>1) { |
|
320 | if ((i+1)%2 && i>1) { | |
321 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
321 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
322 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); |
|
322 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
323 | } |
|
323 | } | |
324 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
324 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
325 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
325 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | } |
|
328 | } | |
329 | break; |
|
329 | break; | |
330 |
|
330 | |||
331 | case Y_AXIS: |
|
331 | case Y_AXIS: | |
332 | { |
|
332 | { | |
333 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
333 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
334 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
334 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
335 |
|
335 | |||
336 | for (int i = 0; i < layout.size(); ++i) { |
|
336 | for (int i = 0; i < layout.size(); ++i) { | |
337 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
337 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
338 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
338 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
339 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
339 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
340 |
|
340 | |||
341 | if (!categories || i<1) { |
|
341 | if (!categories || i<1) { | |
342 | labelItem->setText(ticksList.at(i)); |
|
342 | labelItem->setText(ticksList.at(i)); | |
343 | const QRectF& rect = labelItem->boundingRect(); |
|
343 | const QRectF& rect = labelItem->boundingRect(); | |
344 | minWidth=qMax(rect.width()+label_padding,minWidth); |
|
344 | minWidth=qMax(rect.width()+label_padding,minWidth); | |
345 | minHeight+=rect.height(); |
|
345 | minHeight+=rect.height(); | |
346 | QPointF center = rect.center(); |
|
346 | QPointF center = rect.center(); | |
347 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
347 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
348 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); |
|
348 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
349 | } else { |
|
349 | } else { | |
350 | labelItem->setText(ticksList.at(i)); |
|
350 | labelItem->setText(ticksList.at(i)); | |
351 | const QRectF& rect = labelItem->boundingRect(); |
|
351 | const QRectF& rect = labelItem->boundingRect(); | |
352 | minWidth=qMax(rect.width(),minWidth); |
|
352 | minWidth=qMax(rect.width(),minWidth); | |
353 | minHeight+=rect.height(); |
|
353 | minHeight+=rect.height(); | |
354 | QPointF center = rect.center(); |
|
354 | QPointF center = rect.center(); | |
355 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
355 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
356 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); |
|
356 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | if ((i+1)%2 && i>1) { |
|
359 | if ((i+1)%2 && i>1) { | |
360 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
360 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
361 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
361 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
362 | } |
|
362 | } | |
363 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
363 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
364 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
364 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
365 | } |
|
365 | } | |
366 | } |
|
366 | } | |
367 | break; |
|
367 | break; | |
368 | default: |
|
368 | default: | |
369 | qWarning()<<"Unknown axis type"; |
|
369 | qWarning()<<"Unknown axis type"; | |
370 | break; |
|
370 | break; | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | m_layoutVector=layout; |
|
373 | m_layoutVector=layout; | |
374 |
|
374 | |||
375 | presenter()->setMinimumMarginWidth(this,minWidth); |
|
375 | presenter()->setMinimumMarginWidth(this,minWidth); | |
376 | presenter()->setMinimumMarginHeight(this,minHeight); |
|
376 | presenter()->setMinimumMarginHeight(this,minHeight); | |
377 |
|
377 | |||
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | bool ChartAxis::isEmpty() |
|
380 | bool ChartAxis::isEmpty() | |
381 | { |
|
381 | { | |
382 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; |
|
382 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | //handlers |
|
385 | //handlers | |
386 |
|
386 | |||
387 | void ChartAxis::handleAxisCategoriesUpdated() |
|
387 | void ChartAxis::handleAxisCategoriesUpdated() | |
388 | { |
|
388 | { | |
389 | if (isEmpty()) return; |
|
389 | if (isEmpty()) return; | |
390 | updateLayout(m_layoutVector); |
|
390 | updateLayout(m_layoutVector); | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | void ChartAxis::handleAxisUpdated() |
|
393 | void ChartAxis::handleAxisUpdated() | |
394 | { |
|
394 | { | |
395 |
|
395 | |||
396 | if (isEmpty()) return; |
|
396 | if (isEmpty()) return; | |
397 |
|
397 | |||
398 | if (m_chartAxis->isAxisVisible()) { |
|
398 | if (m_chartAxis->isAxisVisible()) { | |
399 | setAxisOpacity(100); |
|
399 | setAxisOpacity(100); | |
400 | } else { |
|
400 | } else { | |
401 | setAxisOpacity(0); |
|
401 | setAxisOpacity(0); | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | if (m_chartAxis->isGridLineVisible()) { |
|
404 | if (m_chartAxis->isGridLineVisible()) { | |
405 | setGridOpacity(100); |
|
405 | setGridOpacity(100); | |
406 | } else { |
|
406 | } else { | |
407 | setGridOpacity(0); |
|
407 | setGridOpacity(0); | |
408 | } |
|
408 | } | |
409 |
|
409 | |||
410 | if (m_chartAxis->labelsVisible()) { |
|
410 | if (m_chartAxis->labelsVisible()) { | |
411 | setLabelsOpacity(100); |
|
411 | setLabelsOpacity(100); | |
412 | } else { |
|
412 | } else { | |
413 | setLabelsOpacity(0); |
|
413 | setLabelsOpacity(0); | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | if (m_chartAxis->shadesVisible()) { |
|
416 | if (m_chartAxis->shadesVisible()) { | |
417 | setShadesOpacity(m_chartAxis->shadesOpacity()); |
|
417 | setShadesOpacity(m_chartAxis->shadesOpacity()); | |
418 | } else { |
|
418 | } else { | |
419 | setShadesOpacity(0); |
|
419 | setShadesOpacity(0); | |
420 | } |
|
420 | } | |
421 |
|
421 | |||
422 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
422 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
423 | setAxisPen(m_chartAxis->axisPen()); |
|
423 | setAxisPen(m_chartAxis->axisPen()); | |
424 | setLabelsPen(m_chartAxis->labelsPen()); |
|
424 | setLabelsPen(m_chartAxis->labelsPen()); | |
425 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
425 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
426 | setLabelsFont(m_chartAxis->labelsFont()); |
|
426 | setLabelsFont(m_chartAxis->labelsFont()); | |
427 | setGridPen(m_chartAxis->gridLinePen()); |
|
427 | setGridPen(m_chartAxis->gridLinePen()); | |
428 | setShadesPen(m_chartAxis->shadesPen()); |
|
428 | setShadesPen(m_chartAxis->shadesPen()); | |
429 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
429 | setShadesBrush(m_chartAxis->shadesBrush()); | |
430 |
|
430 | |||
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount) |
|
433 | void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount) | |
434 | { |
|
434 | { | |
435 | if (qFuzzyIsNull(min - max) || tickCount < 2) |
|
435 | if (qFuzzyIsNull(min - max) || tickCount < 2) | |
436 | return; |
|
436 | return; | |
437 |
|
437 | |||
438 | m_min = min; |
|
438 | m_min = min; | |
439 | m_max = max; |
|
439 | m_max = max; | |
440 | m_ticksCount= tickCount; |
|
440 | m_ticksCount= tickCount; | |
441 |
|
441 | |||
442 | if (isEmpty()) return; |
|
442 | if (isEmpty()) return; | |
443 | QVector<qreal> layout = calculateLayout(); |
|
443 | QVector<qreal> layout = calculateLayout(); | |
444 | updateLayout(layout); |
|
444 | updateLayout(layout); | |
445 |
|
445 | |||
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | void ChartAxis::handleGeometryChanged(const QRectF &rect) |
|
448 | void ChartAxis::handleGeometryChanged(const QRectF &rect) | |
449 | { |
|
449 | { | |
450 | if(m_rect != rect) |
|
450 | if(m_rect != rect) | |
451 | { |
|
451 | { | |
452 | m_rect = rect; |
|
452 | m_rect = rect; | |
453 | if (isEmpty()) return; |
|
453 | if (isEmpty()) return; | |
454 | QVector<qreal> layout = calculateLayout(); |
|
454 | QVector<qreal> layout = calculateLayout(); | |
455 | updateLayout(layout); |
|
455 | updateLayout(layout); | |
456 | } |
|
456 | } | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | void ChartAxis::axisSelected() |
|
459 | void ChartAxis::axisSelected() | |
460 | { |
|
460 | { | |
461 | qDebug()<<"TODO: axis clicked"; |
|
461 | qDebug()<<"TODO: axis clicked"; | |
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | #include "moc_chartaxis_p.cpp" |
|
464 | #include "moc_chartaxis_p.cpp" | |
465 |
|
465 | |||
466 | QTCOMMERCIALCHART_END_NAMESPACE |
|
466 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,533 +1,533 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qaxis.h" |
|
21 | #include "qaxis.h" | |
22 | #include "qaxis_p.h" |
|
22 | #include "qaxis_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QAxis |
|
27 | \class QAxis | |
28 | \brief The QAxis class is used for manipulating chart's axis |
|
28 | \brief The QAxis class is used for manipulating chart's axis | |
29 | and for adding optional axes to the chart. |
|
29 | and for adding optional axes to the chart. | |
30 | \mainclass |
|
30 | \mainclass | |
31 |
|
31 | |||
32 | There is only one x Axis, however there can be multiple y axes. |
|
32 | There is only one x Axis, however there can be multiple y axes. | |
33 | Each chart series can be bound to exactly one Y axis and the share common X axis. |
|
33 | Each chart series can be bound to exactly one Y axis and the share common X axis. | |
34 | Axis can be setup to show axis line with ticks, gird lines and shades. |
|
34 | Axis can be setup to show axis line with ticks, gird lines and shades. | |
35 |
|
35 | |||
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \fn bool QAxis::isAxisVisible() const |
|
39 | \fn bool QAxis::isAxisVisible() const | |
40 | \brief Returns if axis is visible |
|
40 | \brief Returns if axis is visible | |
41 | \sa setAxisVisible() |
|
41 | \sa setAxisVisible() | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 | /*! |
|
44 | /*! | |
45 | \fn QPen QAxis::axisPen() const |
|
45 | \fn QPen QAxis::axisPen() const | |
46 | \brief Returns pen used to draw axis and ticks. |
|
46 | \brief Returns pen used to draw axis and ticks. | |
47 | \sa setAxisPen() |
|
47 | \sa setAxisPen() | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \fn bool QAxis::isGridLineVisible() const |
|
52 | \fn bool QAxis::isGridLineVisible() const | |
53 | \brief Returns if grid is visible |
|
53 | \brief Returns if grid is visible | |
54 | \sa setGridLineVisible() |
|
54 | \sa setGridLineVisible() | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \fn QPen QAxis::gridLinePen() const |
|
58 | \fn QPen QAxis::gridLinePen() const | |
59 | \brief Returns pen used to draw grid. |
|
59 | \brief Returns pen used to draw grid. | |
60 | \sa setGridLinePen() |
|
60 | \sa setGridLinePen() | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \fn bool QAxis::labelsVisible() const |
|
64 | \fn bool QAxis::labelsVisible() const | |
65 | \brief Returns if grid is visible |
|
65 | \brief Returns if grid is visible | |
66 | \sa setLabelsVisible() |
|
66 | \sa setLabelsVisible() | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \fn QPen QAxis::labelsPen() const |
|
70 | \fn QPen QAxis::labelsPen() const | |
71 | \brief Returns the pen used to labels. |
|
71 | \brief Returns the pen used to labels. | |
72 | \sa setLabelsPen() |
|
72 | \sa setLabelsPen() | |
73 | */ |
|
73 | */ | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | \fn QBrush QAxis::labelsBrush() const |
|
76 | \fn QBrush QAxis::labelsBrush() const | |
77 | \brief Returns brush used to draw labels. |
|
77 | \brief Returns brush used to draw labels. | |
78 | \sa setLabelsBrush() |
|
78 | \sa setLabelsBrush() | |
79 | */ |
|
79 | */ | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | \fn QFont QAxis::labelsFont() const |
|
82 | \fn QFont QAxis::labelsFont() const | |
83 | \brief Returns font used to draw labels. |
|
83 | \brief Returns font used to draw labels. | |
84 | \sa setLabelsFont() |
|
84 | \sa setLabelsFont() | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \fn QFont QAxis::labelsAngle() const |
|
88 | \fn QFont QAxis::labelsAngle() const | |
89 | \brief Returns angle used to draw labels. |
|
89 | \brief Returns angle used to draw labels. | |
90 | \sa setLabelsAngle() |
|
90 | \sa setLabelsAngle() | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \fn bool QAxis::shadesVisible() const |
|
94 | \fn bool QAxis::shadesVisible() const | |
95 | \brief Returns if shades are visible. |
|
95 | \brief Returns if shades are visible. | |
96 | \sa setShadesVisible() |
|
96 | \sa setShadesVisible() | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \fn qreal QAxis::shadesOpacity() const |
|
100 | \fn qreal QAxis::shadesOpacity() const | |
101 | \brief Returns opacity of shades. |
|
101 | \brief Returns opacity of shades. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \fn QPen QAxis::shadesPen() const |
|
105 | \fn QPen QAxis::shadesPen() const | |
106 | \brief Returns pen used to draw shades. |
|
106 | \brief Returns pen used to draw shades. | |
107 | \sa setShadesPen() |
|
107 | \sa setShadesPen() | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \fn QBrush QAxis::shadesBrush() const |
|
111 | \fn QBrush QAxis::shadesBrush() const | |
112 | \brief Returns brush used to draw shades. |
|
112 | \brief Returns brush used to draw shades. | |
113 | \sa setShadesBrush() |
|
113 | \sa setShadesBrush() | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \fn qreal QAxis::min() const |
|
117 | \fn qreal QAxis::min() const | |
118 | \brief Returns minimum value on the axis. |
|
118 | \brief Returns minimum value on the axis. | |
119 | \sa setMin() |
|
119 | \sa setMin() | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn qreal QAxis::max() const |
|
123 | \fn qreal QAxis::max() const | |
124 | \brief Returns maximim value on the axis. |
|
124 | \brief Returns maximim value on the axis. | |
125 | \sa setMax() |
|
125 | \sa setMax() | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \fn void QAxis::minChanged(qreal min) |
|
129 | \fn void QAxis::minChanged(qreal min) | |
130 | \brief Axis emits signal when \a min of axis has changed. |
|
130 | \brief Axis emits signal when \a min of axis has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QAxis::maxChanged(qreal max) |
|
134 | \fn void QAxis::maxChanged(qreal max) | |
135 | \brief Axis emits signal when \a max of axis has changed. |
|
135 | \brief Axis emits signal when \a max of axis has changed. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QAxis::rangeChanged(qreal min, qreal max) |
|
139 | \fn void QAxis::rangeChanged(qreal min, qreal max) | |
140 | \brief Axis emits signal when \a min or \a max of axis has changed. |
|
140 | \brief Axis emits signal when \a min or \a max of axis has changed. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \fn int QAxis::ticksCount() const |
|
144 | \fn int QAxis::ticksCount() const | |
145 | \brief Return number of ticks on the axis |
|
145 | \brief Return number of ticks on the axis | |
146 | \sa setTicksCount() |
|
146 | \sa setTicksCount() | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn QChartAxisCategories* QAxis::categories() |
|
150 | \fn QChartAxisCategories* QAxis::categories() | |
151 | \brief Returns pointer to the list of categories which correspond to the values on the axis. |
|
151 | \brief Returns pointer to the list of categories which correspond to the values on the axis. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QAxis::ticksCountChanged(int count) |
|
155 | \fn void QAxis::ticksCountChanged(int count) | |
156 | \brief Emits the new \a count of ticks on the axis |
|
156 | \brief Emits the new \a count of ticks on the axis | |
157 | Signal is emitted when the number of the ticks on the axis has been changed to a different value. |
|
157 | Signal is emitted when the number of the ticks on the axis has been changed to a different value. | |
158 | Parementer count\a count is the new number of ticks on the axis. |
|
158 | Parementer count\a count is the new number of ticks on the axis. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
162 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
163 | QChart when axis added. |
|
163 | QChart when axis added. | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | QAxis::QAxis(QObject *parent) : QObject(parent), |
|
166 | QAxis::QAxis(QObject *parent) : QObject(parent), | |
167 | d_ptr(new QAxisPrivate(this)) |
|
167 | d_ptr(new QAxisPrivate(this)) | |
168 | { |
|
168 | { | |
169 |
|
169 | |||
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
173 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 | QAxis::~QAxis() |
|
176 | QAxis::~QAxis() | |
177 | { |
|
177 | { | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | Sets \a pen used to draw axis line and ticks. |
|
181 | Sets \a pen used to draw axis line and ticks. | |
182 | */ |
|
182 | */ | |
183 | void QAxis::setAxisPen(const QPen &pen) |
|
183 | void QAxis::setAxisPen(const QPen &pen) | |
184 | { |
|
184 | { | |
185 | if (d_ptr->m_axisPen!=pen) { |
|
185 | if (d_ptr->m_axisPen!=pen) { | |
186 | d_ptr->m_axisPen = pen; |
|
186 | d_ptr->m_axisPen = pen; | |
187 | emit d_ptr->updated(); |
|
187 | emit d_ptr->updated(); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | QPen QAxis::axisPen() const |
|
191 | QPen QAxis::axisPen() const | |
192 | { |
|
192 | { | |
193 | return d_ptr->m_axisPen; |
|
193 | return d_ptr->m_axisPen; | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | /*! |
|
196 | /*! | |
197 | Sets if axis and ticks are \a visible. |
|
197 | Sets if axis and ticks are \a visible. | |
198 | */ |
|
198 | */ | |
199 | void QAxis::setAxisVisible(bool visible) |
|
199 | void QAxis::setAxisVisible(bool visible) | |
200 | { |
|
200 | { | |
201 | if (d_ptr->m_axisVisible != visible) { |
|
201 | if (d_ptr->m_axisVisible != visible) { | |
202 | d_ptr->m_axisVisible = visible; |
|
202 | d_ptr->m_axisVisible = visible; | |
203 | emit d_ptr->updated(); |
|
203 | emit d_ptr->updated(); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | bool QAxis::isAxisVisible() const |
|
207 | bool QAxis::isAxisVisible() const | |
208 | { |
|
208 | { | |
209 | return d_ptr->m_axisVisible; |
|
209 | return d_ptr->m_axisVisible; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Sets if grid line is \a visible. |
|
213 | Sets if grid line is \a visible. | |
214 | */ |
|
214 | */ | |
215 | void QAxis::setGridLineVisible(bool visible) |
|
215 | void QAxis::setGridLineVisible(bool visible) | |
216 | { |
|
216 | { | |
217 | if (d_ptr->m_gridLineVisible != visible) { |
|
217 | if (d_ptr->m_gridLineVisible != visible) { | |
218 | d_ptr->m_gridLineVisible = visible; |
|
218 | d_ptr->m_gridLineVisible = visible; | |
219 | emit d_ptr->updated(); |
|
219 | emit d_ptr->updated(); | |
220 | } |
|
220 | } | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | bool QAxis::isGridLineVisible() const |
|
223 | bool QAxis::isGridLineVisible() const | |
224 | { |
|
224 | { | |
225 | return d_ptr->m_gridLineVisible; |
|
225 | return d_ptr->m_gridLineVisible; | |
226 | } |
|
226 | } | |
227 | /*! |
|
227 | /*! | |
228 | Sets \a pen used to draw grid line. |
|
228 | Sets \a pen used to draw grid line. | |
229 | */ |
|
229 | */ | |
230 | void QAxis::setGridLinePen(const QPen &pen) |
|
230 | void QAxis::setGridLinePen(const QPen &pen) | |
231 | { |
|
231 | { | |
232 | if (d_ptr->m_gridLinePen != pen) { |
|
232 | if (d_ptr->m_gridLinePen != pen) { | |
233 | d_ptr->m_gridLinePen = pen; |
|
233 | d_ptr->m_gridLinePen = pen; | |
234 | emit d_ptr->updated(); |
|
234 | emit d_ptr->updated(); | |
235 | } |
|
235 | } | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | QPen QAxis::gridLinePen() const |
|
238 | QPen QAxis::gridLinePen() const | |
239 | { |
|
239 | { | |
240 | return d_ptr->m_gridLinePen; |
|
240 | return d_ptr->m_gridLinePen; | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Sets if axis' labels are \a visible. |
|
244 | Sets if axis' labels are \a visible. | |
245 | */ |
|
245 | */ | |
246 | void QAxis::setLabelsVisible(bool visible) |
|
246 | void QAxis::setLabelsVisible(bool visible) | |
247 | { |
|
247 | { | |
248 | if (d_ptr->m_labelsVisible != visible) { |
|
248 | if (d_ptr->m_labelsVisible != visible) { | |
249 | d_ptr->m_labelsVisible = visible; |
|
249 | d_ptr->m_labelsVisible = visible; | |
250 | emit d_ptr->updated(); |
|
250 | emit d_ptr->updated(); | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | bool QAxis::labelsVisible() const |
|
254 | bool QAxis::labelsVisible() const | |
255 | { |
|
255 | { | |
256 | return d_ptr->m_labelsVisible; |
|
256 | return d_ptr->m_labelsVisible; | |
257 | } |
|
257 | } | |
258 | /*! |
|
258 | /*! | |
259 | Sets \a pen used to draw labels. |
|
259 | Sets \a pen used to draw labels. | |
260 | */ |
|
260 | */ | |
261 | void QAxis::setLabelsPen(const QPen &pen) |
|
261 | void QAxis::setLabelsPen(const QPen &pen) | |
262 | { |
|
262 | { | |
263 | if (d_ptr->m_labelsPen != pen) { |
|
263 | if (d_ptr->m_labelsPen != pen) { | |
264 | d_ptr->m_labelsPen = pen; |
|
264 | d_ptr->m_labelsPen = pen; | |
265 | emit d_ptr->updated(); |
|
265 | emit d_ptr->updated(); | |
266 | } |
|
266 | } | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | QPen QAxis::labelsPen() const |
|
269 | QPen QAxis::labelsPen() const | |
270 | { |
|
270 | { | |
271 | return d_ptr->m_labelsPen; |
|
271 | return d_ptr->m_labelsPen; | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | /*! |
|
274 | /*! | |
275 | Sets \a brush used to draw labels. |
|
275 | Sets \a brush used to draw labels. | |
276 | */ |
|
276 | */ | |
277 | void QAxis::setLabelsBrush(const QBrush &brush) |
|
277 | void QAxis::setLabelsBrush(const QBrush &brush) | |
278 | { |
|
278 | { | |
279 | if (d_ptr->m_labelsBrush != brush) { |
|
279 | if (d_ptr->m_labelsBrush != brush) { | |
280 | d_ptr->m_labelsBrush = brush; |
|
280 | d_ptr->m_labelsBrush = brush; | |
281 | emit d_ptr->updated(); |
|
281 | emit d_ptr->updated(); | |
282 | } |
|
282 | } | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | QBrush QAxis::labelsBrush() const |
|
285 | QBrush QAxis::labelsBrush() const | |
286 | { |
|
286 | { | |
287 | return d_ptr->m_labelsBrush; |
|
287 | return d_ptr->m_labelsBrush; | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | /*! |
|
290 | /*! | |
291 | Sets \a font used to draw labels. |
|
291 | Sets \a font used to draw labels. | |
292 | */ |
|
292 | */ | |
293 | void QAxis::setLabelsFont(const QFont &font) |
|
293 | void QAxis::setLabelsFont(const QFont &font) | |
294 | { |
|
294 | { | |
295 | if (d_ptr->m_labelsFont != font) { |
|
295 | if (d_ptr->m_labelsFont != font) { | |
296 | d_ptr->m_labelsFont = font; |
|
296 | d_ptr->m_labelsFont = font; | |
297 | emit d_ptr->updated(); |
|
297 | emit d_ptr->updated(); | |
298 | } |
|
298 | } | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | QFont QAxis::labelsFont() const |
|
301 | QFont QAxis::labelsFont() const | |
302 | { |
|
302 | { | |
303 | return d_ptr->m_labelsFont; |
|
303 | return d_ptr->m_labelsFont; | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | /*! |
|
306 | /*! | |
307 | Sets \a angle for all the labels on given axis. |
|
307 | Sets \a angle for all the labels on given axis. | |
308 | */ |
|
308 | */ | |
309 | void QAxis::setLabelsAngle(int angle) |
|
309 | void QAxis::setLabelsAngle(int angle) | |
310 | { |
|
310 | { | |
311 | if (d_ptr->m_labelsAngle != angle) { |
|
311 | if (d_ptr->m_labelsAngle != angle) { | |
312 | d_ptr->m_labelsAngle = angle; |
|
312 | d_ptr->m_labelsAngle = angle; | |
313 | emit d_ptr->updated(); |
|
313 | emit d_ptr->updated(); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | int QAxis::labelsAngle() const |
|
317 | int QAxis::labelsAngle() const | |
318 | { |
|
318 | { | |
319 | return d_ptr->m_labelsAngle; |
|
319 | return d_ptr->m_labelsAngle; | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | /*! |
|
322 | /*! | |
323 | Sets if shades are \a visible. |
|
323 | Sets if shades are \a visible. | |
324 | */ |
|
324 | */ | |
325 | void QAxis::setShadesVisible(bool visible) |
|
325 | void QAxis::setShadesVisible(bool visible) | |
326 | { |
|
326 | { | |
327 | if (d_ptr->m_shadesVisible != visible) { |
|
327 | if (d_ptr->m_shadesVisible != visible) { | |
328 | d_ptr->m_shadesVisible = visible; |
|
328 | d_ptr->m_shadesVisible = visible; | |
329 | emit d_ptr->updated(); |
|
329 | emit d_ptr->updated(); | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | bool QAxis::shadesVisible() const |
|
333 | bool QAxis::shadesVisible() const | |
334 | { |
|
334 | { | |
335 | return d_ptr->m_shadesVisible; |
|
335 | return d_ptr->m_shadesVisible; | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | /*! |
|
338 | /*! | |
339 | Sets \a pen used to draw shades. |
|
339 | Sets \a pen used to draw shades. | |
340 | */ |
|
340 | */ | |
341 | void QAxis::setShadesPen(const QPen &pen) |
|
341 | void QAxis::setShadesPen(const QPen &pen) | |
342 | { |
|
342 | { | |
343 | if (d_ptr->m_shadesPen != pen) { |
|
343 | if (d_ptr->m_shadesPen != pen) { | |
344 | d_ptr->m_shadesPen = pen; |
|
344 | d_ptr->m_shadesPen = pen; | |
345 | emit d_ptr->updated(); |
|
345 | emit d_ptr->updated(); | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | QPen QAxis::shadesPen() const |
|
349 | QPen QAxis::shadesPen() const | |
350 | { |
|
350 | { | |
351 | return d_ptr->m_shadesPen; |
|
351 | return d_ptr->m_shadesPen; | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Sets \a brush used to draw shades. |
|
355 | Sets \a brush used to draw shades. | |
356 | */ |
|
356 | */ | |
357 | void QAxis::setShadesBrush(const QBrush &brush) |
|
357 | void QAxis::setShadesBrush(const QBrush &brush) | |
358 | { |
|
358 | { | |
359 | if (d_ptr->m_shadesBrush != brush) { |
|
359 | if (d_ptr->m_shadesBrush != brush) { | |
360 | d_ptr->m_shadesBrush = brush; |
|
360 | d_ptr->m_shadesBrush = brush; | |
361 | emit d_ptr->updated(); |
|
361 | emit d_ptr->updated(); | |
362 | } |
|
362 | } | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | QBrush QAxis::shadesBrush() const |
|
365 | QBrush QAxis::shadesBrush() const | |
366 | { |
|
366 | { | |
367 | return d_ptr->m_shadesBrush; |
|
367 | return d_ptr->m_shadesBrush; | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | Sets \a opacity of the shades. |
|
371 | Sets \a opacity of the shades. | |
372 | */ |
|
372 | */ | |
373 | void QAxis::setShadesOpacity(qreal opacity) |
|
373 | void QAxis::setShadesOpacity(qreal opacity) | |
374 | { |
|
374 | { | |
375 | if (d_ptr->m_shadesOpacity != opacity) { |
|
375 | if (d_ptr->m_shadesOpacity != opacity) { | |
376 | d_ptr->m_shadesOpacity=opacity; |
|
376 | d_ptr->m_shadesOpacity=opacity; | |
377 | emit d_ptr->updated(); |
|
377 | emit d_ptr->updated(); | |
378 | } |
|
378 | } | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | qreal QAxis::shadesOpacity() const |
|
381 | qreal QAxis::shadesOpacity() const | |
382 | { |
|
382 | { | |
383 | return d_ptr->m_shadesOpacity; |
|
383 | return d_ptr->m_shadesOpacity; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | /*! |
|
386 | /*! | |
387 | Sets \a min value on the axis. |
|
387 | Sets \a min value on the axis. | |
388 | */ |
|
388 | */ | |
389 | void QAxis::setMin(qreal min) |
|
389 | void QAxis::setMin(qreal min) | |
390 | { |
|
390 | { | |
391 | setRange(min,d_ptr->m_max); |
|
391 | setRange(min,d_ptr->m_max); | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | qreal QAxis::min() const |
|
394 | qreal QAxis::min() const | |
395 | { |
|
395 | { | |
396 | return d_ptr->m_min; |
|
396 | return d_ptr->m_min; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | /*! |
|
399 | /*! | |
400 | Sets \a max value on the axis. |
|
400 | Sets \a max value on the axis. | |
401 | */ |
|
401 | */ | |
402 | void QAxis::setMax(qreal max) |
|
402 | void QAxis::setMax(qreal max) | |
403 | { |
|
403 | { | |
404 | setRange(d_ptr->m_min,max); |
|
404 | setRange(d_ptr->m_min,max); | |
405 | } |
|
405 | } | |
406 |
|
406 | |||
407 | qreal QAxis::max() const |
|
407 | qreal QAxis::max() const | |
408 | { |
|
408 | { | |
409 | return d_ptr->m_max; |
|
409 | return d_ptr->m_max; | |
410 | } |
|
410 | } | |
411 |
|
411 | |||
412 | /*! |
|
412 | /*! | |
413 | Sets range from \a min to \a max on the axis. |
|
413 | Sets range from \a min to \a max on the axis. | |
414 | */ |
|
414 | */ | |
415 | void QAxis::setRange(qreal min, qreal max) |
|
415 | void QAxis::setRange(qreal min, qreal max) | |
416 | { |
|
416 | { | |
417 | bool changed = false; |
|
417 | bool changed = false; | |
418 | if (!qFuzzyIsNull(d_ptr->m_min - min)) { |
|
418 | if (!qFuzzyIsNull(d_ptr->m_min - min)) { | |
419 | d_ptr->m_min = min; |
|
419 | d_ptr->m_min = min; | |
420 | changed = true; |
|
420 | changed = true; | |
421 | emit minChanged(min); |
|
421 | emit minChanged(min); | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | if (!qFuzzyIsNull(d_ptr->m_max - max)) { |
|
424 | if (!qFuzzyIsNull(d_ptr->m_max - max)) { | |
425 | d_ptr->m_max = max; |
|
425 | d_ptr->m_max = max; | |
426 | changed = true; |
|
426 | changed = true; | |
427 | emit maxChanged(max); |
|
427 | emit maxChanged(max); | |
428 | } |
|
428 | } | |
429 |
|
429 | |||
430 | if (changed) { |
|
430 | if (changed) { | |
431 | emit rangeChanged(d_ptr->m_min,d_ptr->m_max); |
|
431 | emit rangeChanged(d_ptr->m_min,d_ptr->m_max); | |
432 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
432 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | |
433 | } |
|
433 | } | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | /*! |
|
436 | /*! | |
437 | Sets \a count for ticks on the axis. |
|
437 | Sets \a count for ticks on the axis. | |
438 | */ |
|
438 | */ | |
439 | void QAxis::setTicksCount(int count) |
|
439 | void QAxis::setTicksCount(int count) | |
440 | { |
|
440 | { | |
441 | if (d_ptr->m_ticksCount != count) { |
|
441 | if (d_ptr->m_ticksCount != count) { | |
442 | d_ptr->m_ticksCount = count; |
|
442 | d_ptr->m_ticksCount = count; | |
443 | emit ticksCountChanged(count); |
|
443 | emit ticksCountChanged(count); | |
444 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
444 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | |
445 | } |
|
445 | } | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | int QAxis::ticksCount() const |
|
448 | int QAxis::ticksCount() const | |
449 | { |
|
449 | { | |
450 | return d_ptr->m_ticksCount; |
|
450 | return d_ptr->m_ticksCount; | |
451 | } |
|
451 | } | |
452 |
|
452 | |||
453 | /*! |
|
453 | /*! | |
454 | Sets axis, shades, labels and grid lines to be visible. |
|
454 | Sets axis, shades, labels and grid lines to be visible. | |
455 | */ |
|
455 | */ | |
456 | void QAxis::show() |
|
456 | void QAxis::show() | |
457 | { |
|
457 | { | |
458 | d_ptr->m_axisVisible=true; |
|
458 | d_ptr->m_axisVisible=true; | |
459 | d_ptr->m_gridLineVisible=true; |
|
459 | d_ptr->m_gridLineVisible=true; | |
460 | d_ptr->m_labelsVisible=true; |
|
460 | d_ptr->m_labelsVisible=true; | |
461 | d_ptr->m_shadesVisible=true; |
|
461 | d_ptr->m_shadesVisible=true; | |
462 | emit d_ptr->updated(); |
|
462 | emit d_ptr->updated(); | |
463 | } |
|
463 | } | |
464 |
|
464 | |||
465 | /*! |
|
465 | /*! | |
466 | Sets axis, shades, labels and grid lines to not be visible. |
|
466 | Sets axis, shades, labels and grid lines to not be visible. | |
467 | */ |
|
467 | */ | |
468 | void QAxis::hide() |
|
468 | void QAxis::hide() | |
469 | { |
|
469 | { | |
470 | d_ptr->m_axisVisible = false; |
|
470 | d_ptr->m_axisVisible = false; | |
471 | d_ptr->m_gridLineVisible = false; |
|
471 | d_ptr->m_gridLineVisible = false; | |
472 | d_ptr->m_labelsVisible = false; |
|
472 | d_ptr->m_labelsVisible = false; | |
473 | d_ptr->m_shadesVisible = false; |
|
473 | d_ptr->m_shadesVisible = false; | |
474 | emit d_ptr->updated(); |
|
474 | emit d_ptr->updated(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | /*! |
|
477 | /*! | |
478 | Sets the nice numbers state to \a enable |
|
478 | Sets the nice numbers state to \a enable | |
479 | */ |
|
479 | */ | |
480 | void QAxis::setNiceNumbersEnabled(bool enable) |
|
480 | void QAxis::setNiceNumbersEnabled(bool enable) | |
481 | { |
|
481 | { | |
482 | if (d_ptr->m_niceNumbers != enable){ |
|
482 | if (d_ptr->m_niceNumbers != enable){ | |
483 | d_ptr->m_niceNumbers = enable; |
|
483 | d_ptr->m_niceNumbers = enable; | |
484 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); |
|
484 | emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers); | |
485 | } |
|
485 | } | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | /*! |
|
488 | /*! | |
489 | Returns whether nice numbers are enabled or not. |
|
489 | Returns whether nice numbers are enabled or not. | |
490 | */ |
|
490 | */ | |
491 | bool QAxis::niceNumbersEnabled() const |
|
491 | bool QAxis::niceNumbersEnabled() const | |
492 | { |
|
492 | { | |
493 | return d_ptr->m_niceNumbers; |
|
493 | return d_ptr->m_niceNumbers; | |
494 | } |
|
494 | } | |
495 |
|
495 | |||
496 |
Q |
|
496 | QAxisCategories* QAxis::categories() | |
497 | { |
|
497 | { | |
498 | return &d_ptr->m_category; |
|
498 | return &d_ptr->m_category; | |
499 | } |
|
499 | } | |
500 |
|
500 | |||
501 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
501 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
502 |
|
502 | |||
503 | QAxisPrivate::QAxisPrivate(QAxis* q): |
|
503 | QAxisPrivate::QAxisPrivate(QAxis* q): | |
504 | q_ptr(q), |
|
504 | q_ptr(q), | |
505 | m_axisVisible(true), |
|
505 | m_axisVisible(true), | |
506 | m_gridLineVisible(true), |
|
506 | m_gridLineVisible(true), | |
507 | m_labelsVisible(true), |
|
507 | m_labelsVisible(true), | |
508 | m_labelsAngle(0), |
|
508 | m_labelsAngle(0), | |
509 | m_shadesVisible(false), |
|
509 | m_shadesVisible(false), | |
510 | m_shadesOpacity(1.0), |
|
510 | m_shadesOpacity(1.0), | |
511 | m_min(0), |
|
511 | m_min(0), | |
512 | m_max(0), |
|
512 | m_max(0), | |
513 | m_ticksCount(5), |
|
513 | m_ticksCount(5), | |
514 | m_niceNumbers(false) |
|
514 | m_niceNumbers(false) | |
515 | { |
|
515 | { | |
516 |
|
516 | |||
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | QAxisPrivate::~QAxisPrivate() |
|
519 | QAxisPrivate::~QAxisPrivate() | |
520 | { |
|
520 | { | |
521 |
|
521 | |||
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | void QAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
524 | void QAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
525 | { |
|
525 | { | |
526 | q_ptr->setRange(min,max); |
|
526 | q_ptr->setRange(min,max); | |
527 | q_ptr->setTicksCount(count); |
|
527 | q_ptr->setTicksCount(count); | |
528 | } |
|
528 | } | |
529 |
|
529 | |||
530 | #include "moc_qaxis.cpp" |
|
530 | #include "moc_qaxis.cpp" | |
531 | #include "moc_qaxis_p.cpp" |
|
531 | #include "moc_qaxis_p.cpp" | |
532 |
|
532 | |||
533 | QTCOMMERCIALCHART_END_NAMESPACE |
|
533 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,108 +1,108 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QAXIS_H |
|
21 | #ifndef QAXIS_H | |
22 | #define QAXIS_H |
|
22 | #define QAXIS_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 |
#include <q |
|
25 | #include <qaxiscategories.h> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QFont> |
|
27 | #include <QFont> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QAxisPrivate; |
|
31 | class QAxisPrivate; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QAxis : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QAxis : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | public: |
|
36 | public: | |
37 |
|
37 | |||
38 | QAxis(QObject *parent =0); |
|
38 | QAxis(QObject *parent =0); | |
39 | ~QAxis(); |
|
39 | ~QAxis(); | |
40 |
|
40 | |||
41 | //axis handling |
|
41 | //axis handling | |
42 | bool isAxisVisible() const; |
|
42 | bool isAxisVisible() const; | |
43 | void setAxisVisible(bool visible = true); |
|
43 | void setAxisVisible(bool visible = true); | |
44 | void setAxisPen(const QPen &pen); |
|
44 | void setAxisPen(const QPen &pen); | |
45 | QPen axisPen() const; |
|
45 | QPen axisPen() const; | |
46 |
|
46 | |||
47 | //grid handling |
|
47 | //grid handling | |
48 | bool isGridLineVisible() const; |
|
48 | bool isGridLineVisible() const; | |
49 | void setGridLineVisible(bool visible = true); |
|
49 | void setGridLineVisible(bool visible = true); | |
50 | void setGridLinePen(const QPen &pen); |
|
50 | void setGridLinePen(const QPen &pen); | |
51 | QPen gridLinePen() const; |
|
51 | QPen gridLinePen() const; | |
52 |
|
52 | |||
53 | //labels handling |
|
53 | //labels handling | |
54 | bool labelsVisible() const; |
|
54 | bool labelsVisible() const; | |
55 | void setLabelsVisible(bool visible = true); |
|
55 | void setLabelsVisible(bool visible = true); | |
56 | void setLabelsPen(const QPen &pen); |
|
56 | void setLabelsPen(const QPen &pen); | |
57 | QPen labelsPen() const; |
|
57 | QPen labelsPen() const; | |
58 | void setLabelsBrush(const QBrush &brush); |
|
58 | void setLabelsBrush(const QBrush &brush); | |
59 | QBrush labelsBrush() const; |
|
59 | QBrush labelsBrush() const; | |
60 | void setLabelsFont(const QFont &font); |
|
60 | void setLabelsFont(const QFont &font); | |
61 | QFont labelsFont() const; |
|
61 | QFont labelsFont() const; | |
62 | void setLabelsAngle(int angle); |
|
62 | void setLabelsAngle(int angle); | |
63 | int labelsAngle() const; |
|
63 | int labelsAngle() const; | |
64 |
|
64 | |||
65 | //shades handling |
|
65 | //shades handling | |
66 | bool shadesVisible() const; |
|
66 | bool shadesVisible() const; | |
67 | void setShadesVisible(bool visible = true); |
|
67 | void setShadesVisible(bool visible = true); | |
68 | void setShadesPen(const QPen &pen); |
|
68 | void setShadesPen(const QPen &pen); | |
69 | QPen shadesPen() const; |
|
69 | QPen shadesPen() const; | |
70 | void setShadesBrush(const QBrush &brush); |
|
70 | void setShadesBrush(const QBrush &brush); | |
71 | QBrush shadesBrush() const; |
|
71 | QBrush shadesBrush() const; | |
72 | void setShadesOpacity(qreal opacity); |
|
72 | void setShadesOpacity(qreal opacity); | |
73 | qreal shadesOpacity() const; |
|
73 | qreal shadesOpacity() const; | |
74 |
|
74 | |||
75 | //range handling |
|
75 | //range handling | |
76 | void setMin(qreal min); |
|
76 | void setMin(qreal min); | |
77 | qreal min() const; |
|
77 | qreal min() const; | |
78 | void setMax(qreal max); |
|
78 | void setMax(qreal max); | |
79 | qreal max() const; |
|
79 | qreal max() const; | |
80 | void setRange(qreal min, qreal max); |
|
80 | void setRange(qreal min, qreal max); | |
81 |
|
81 | |||
82 | //ticks handling |
|
82 | //ticks handling | |
83 | void setTicksCount(int count); |
|
83 | void setTicksCount(int count); | |
84 | int ticksCount() const; |
|
84 | int ticksCount() const; | |
85 |
|
85 | |||
86 | void setNiceNumbersEnabled(bool enable = true); |
|
86 | void setNiceNumbersEnabled(bool enable = true); | |
87 | bool niceNumbersEnabled() const; |
|
87 | bool niceNumbersEnabled() const; | |
88 |
|
88 | |||
89 |
Q |
|
89 | QAxisCategories* categories(); | |
90 |
|
90 | |||
91 | void show(); |
|
91 | void show(); | |
92 | void hide(); |
|
92 | void hide(); | |
93 |
|
93 | |||
94 | Q_SIGNALS: |
|
94 | Q_SIGNALS: | |
95 | void minChanged(qreal min); |
|
95 | void minChanged(qreal min); | |
96 | void maxChanged(qreal max); |
|
96 | void maxChanged(qreal max); | |
97 | void rangeChanged(qreal min, qreal max); |
|
97 | void rangeChanged(qreal min, qreal max); | |
98 | void ticksCountChanged(int count); |
|
98 | void ticksCountChanged(int count); | |
99 |
|
99 | |||
100 | private: |
|
100 | private: | |
101 | QScopedPointer<QAxisPrivate> d_ptr; |
|
101 | QScopedPointer<QAxisPrivate> d_ptr; | |
102 | Q_DISABLE_COPY(QAxis); |
|
102 | Q_DISABLE_COPY(QAxis); | |
103 | friend class ChartDataSet; |
|
103 | friend class ChartDataSet; | |
104 | friend class ChartAxis; |
|
104 | friend class ChartAxis; | |
105 | }; |
|
105 | }; | |
106 |
|
106 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 | #endif /* QCHARTAXIS_H_ */ |
|
108 | #endif /* QCHARTAXIS_H_ */ |
@@ -1,85 +1,85 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QAXIS_P_H |
|
30 | #ifndef QAXIS_P_H | |
31 | #define QAXIS_P_H |
|
31 | #define QAXIS_P_H | |
32 |
|
32 | |||
33 | #include "qaxis.h" |
|
33 | #include "qaxis.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAxisPrivate : public QObject |
|
37 | class QAxisPrivate : public QObject | |
38 | { |
|
38 | { | |
39 | Q_OBJECT |
|
39 | Q_OBJECT | |
40 | public: |
|
40 | public: | |
41 | QAxisPrivate(QAxis *q); |
|
41 | QAxisPrivate(QAxis *q); | |
42 | ~QAxisPrivate(); |
|
42 | ~QAxisPrivate(); | |
43 |
|
43 | |||
44 | Q_SIGNALS: |
|
44 | Q_SIGNALS: | |
45 | void updated(); |
|
45 | void updated(); | |
46 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); |
|
46 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); | |
47 |
|
47 | |||
48 | public Q_SLOTS: |
|
48 | public Q_SLOTS: | |
49 | void handleAxisRangeChanged(qreal min, qreal max,int count); |
|
49 | void handleAxisRangeChanged(qreal min, qreal max,int count); | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 | QAxis *q_ptr; |
|
52 | QAxis *q_ptr; | |
53 |
|
53 | |||
54 | bool m_axisVisible; |
|
54 | bool m_axisVisible; | |
55 | QPen m_axisPen; |
|
55 | QPen m_axisPen; | |
56 | QBrush m_axisBrush; |
|
56 | QBrush m_axisBrush; | |
57 |
|
57 | |||
58 | bool m_gridLineVisible; |
|
58 | bool m_gridLineVisible; | |
59 | QPen m_gridLinePen; |
|
59 | QPen m_gridLinePen; | |
60 |
|
60 | |||
61 | bool m_labelsVisible; |
|
61 | bool m_labelsVisible; | |
62 | QPen m_labelsPen; |
|
62 | QPen m_labelsPen; | |
63 | QBrush m_labelsBrush; |
|
63 | QBrush m_labelsBrush; | |
64 | QFont m_labelsFont; |
|
64 | QFont m_labelsFont; | |
65 | int m_labelsAngle; |
|
65 | int m_labelsAngle; | |
66 |
|
66 | |||
67 | bool m_shadesVisible; |
|
67 | bool m_shadesVisible; | |
68 | QPen m_shadesPen; |
|
68 | QPen m_shadesPen; | |
69 | QBrush m_shadesBrush; |
|
69 | QBrush m_shadesBrush; | |
70 | qreal m_shadesOpacity; |
|
70 | qreal m_shadesOpacity; | |
71 |
|
71 | |||
72 | qreal m_min; |
|
72 | qreal m_min; | |
73 | qreal m_max; |
|
73 | qreal m_max; | |
74 |
|
74 | |||
75 | int m_ticksCount; |
|
75 | int m_ticksCount; | |
76 |
Q |
|
76 | QAxisCategories m_category; | |
77 |
|
77 | |||
78 | bool m_niceNumbers; |
|
78 | bool m_niceNumbers; | |
79 |
|
79 | |||
80 | friend class QAxis; |
|
80 | friend class QAxis; | |
81 | }; |
|
81 | }; | |
82 |
|
82 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | QTCOMMERCIALCHART_END_NAMESPACE | |
84 |
|
84 | |||
85 | #endif |
|
85 | #endif |
@@ -1,96 +1,96 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#include "q |
|
21 | #include "qaxiscategories.h" | |
22 |
#include "q |
|
22 | #include "qaxiscategories_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 |
Q |
|
26 | QAxisCategories::QAxisCategories(): | |
27 |
d_ptr(new Q |
|
27 | d_ptr(new QAxisCategoriesPrivate(this)) | |
28 | { |
|
28 | { | |
29 |
|
29 | |||
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 |
Q |
|
32 | QAxisCategories::~QAxisCategories() | |
33 | { |
|
33 | { | |
34 |
|
34 | |||
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 |
void Q |
|
37 | void QAxisCategories::insert(const QBarCategories &categories) | |
38 | { |
|
38 | { | |
39 | int i=1; |
|
39 | int i=1; | |
40 | foreach (const QString& string , categories) { |
|
40 | foreach (const QString& string , categories) { | |
41 | d_ptr->m_map.insert(i,string); |
|
41 | d_ptr->m_map.insert(i,string); | |
42 | i++; |
|
42 | i++; | |
43 | } |
|
43 | } | |
44 | emit d_ptr->updated(); |
|
44 | emit d_ptr->updated(); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 |
void Q |
|
47 | void QAxisCategories::insert(qreal value,QString label) | |
48 | { |
|
48 | { | |
49 | d_ptr->m_map.insert(value,label); |
|
49 | d_ptr->m_map.insert(value,label); | |
50 | emit d_ptr->updated(); |
|
50 | emit d_ptr->updated(); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 |
void Q |
|
53 | void QAxisCategories::remove(qreal value) | |
54 | { |
|
54 | { | |
55 | d_ptr->m_map.remove(value); |
|
55 | d_ptr->m_map.remove(value); | |
56 | emit d_ptr->updated(); |
|
56 | emit d_ptr->updated(); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 |
void Q |
|
59 | void QAxisCategories::clear() | |
60 | { |
|
60 | { | |
61 | d_ptr->m_map.clear(); |
|
61 | d_ptr->m_map.clear(); | |
62 | emit d_ptr->updated(); |
|
62 | emit d_ptr->updated(); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 |
int Q |
|
65 | int QAxisCategories::count() | |
66 | { |
|
66 | { | |
67 | return d_ptr->m_map.count(); |
|
67 | return d_ptr->m_map.count(); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 |
QList<qreal> Q |
|
70 | QList<qreal> QAxisCategories::values() const | |
71 | { |
|
71 | { | |
72 | return d_ptr->m_map.keys(); |
|
72 | return d_ptr->m_map.keys(); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 |
QString Q |
|
75 | QString QAxisCategories::label(qreal value) const | |
76 | { |
|
76 | { | |
77 | return d_ptr->m_map.value(value); |
|
77 | return d_ptr->m_map.value(value); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
81 |
|
81 | |||
82 |
Q |
|
82 | QAxisCategoriesPrivate::QAxisCategoriesPrivate(QAxisCategories *q): | |
83 | q_ptr(q) |
|
83 | q_ptr(q) | |
84 | { |
|
84 | { | |
85 |
|
85 | |||
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 |
Q |
|
88 | QAxisCategoriesPrivate::~QAxisCategoriesPrivate() | |
89 | { |
|
89 | { | |
90 |
|
90 | |||
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 |
#include "moc_q |
|
93 | #include "moc_qaxiscategories.cpp" | |
94 |
#include "moc_q |
|
94 | #include "moc_qaxiscategories_p.cpp" | |
95 |
|
95 | |||
96 | QTCOMMERCIALCHART_END_NAMESPACE |
|
96 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,56 +1,56 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#ifndef Q |
|
21 | #ifndef QAXISCATEGORIES_H | |
22 |
#define Q |
|
22 | #define QAXISCATEGORIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <qbarseries.h> |
|
25 | #include <qbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
class Q |
|
29 | class QAxisCategoriesPrivate; | |
30 |
|
30 | |||
31 |
class QTCOMMERCIALCHART_EXPORT Q |
|
31 | class QTCOMMERCIALCHART_EXPORT QAxisCategories : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | private: |
|
34 | private: | |
35 |
Q |
|
35 | QAxisCategories(); | |
36 | public: |
|
36 | public: | |
37 |
~Q |
|
37 | ~QAxisCategories(); | |
38 |
|
38 | |||
39 | void insert(const QBarCategories &category); |
|
39 | void insert(const QBarCategories &category); | |
40 | void insert(qreal value,QString label); |
|
40 | void insert(qreal value,QString label); | |
41 | void remove(qreal value); |
|
41 | void remove(qreal value); | |
42 | QList<qreal> values() const; |
|
42 | QList<qreal> values() const; | |
43 | QString label(qreal value) const; |
|
43 | QString label(qreal value) const; | |
44 | void clear(); |
|
44 | void clear(); | |
45 | int count(); |
|
45 | int count(); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 |
QScopedPointer<Q |
|
48 | QScopedPointer<QAxisCategoriesPrivate> d_ptr; | |
49 | friend class QAxisPrivate; |
|
49 | friend class QAxisPrivate; | |
50 | friend class ChartAxis; |
|
50 | friend class ChartAxis; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE | |
55 |
|
55 | |||
56 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
|
56 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
@@ -1,57 +1,57 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
#ifndef Q |
|
30 | #ifndef QAXISCATEGORIES_P_H | |
31 |
#define Q |
|
31 | #define QAXISCATEGORIES_P_H | |
32 |
|
32 | |||
33 |
#include "q |
|
33 | #include "qaxiscategories.h" | |
34 | #include <QMap> |
|
34 | #include <QMap> | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
class Q |
|
38 | class QAxisCategoriesPrivate : public QObject | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 |
Q |
|
42 | QAxisCategoriesPrivate(QAxisCategories *q); | |
43 |
~Q |
|
43 | ~QAxisCategoriesPrivate(); | |
44 |
|
44 | |||
45 | Q_SIGNALS: |
|
45 | Q_SIGNALS: | |
46 | void updated(); |
|
46 | void updated(); | |
47 |
|
47 | |||
48 | private: |
|
48 | private: | |
49 |
Q |
|
49 | QAxisCategories *q_ptr; | |
50 | QMap<qreal,QString> m_map; |
|
50 | QMap<qreal,QString> m_map; | |
51 |
friend class Q |
|
51 | friend class QAxisCategories; | |
52 |
|
52 | |||
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
56 | |||
57 | #endif |
|
57 | #endif |
@@ -1,206 +1,204 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "barchartitem_p.h" |
|
21 | #include "barchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "barlabel_p.h" |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qbarset_p.h" |
|
25 | #include "qbarset_p.h" | |
26 | #include "qbarseries.h" |
|
26 | #include "qbarseries.h" | |
27 | #include "qbarseries_p.h" |
|
27 | #include "qbarseries_p.h" | |
28 | #include "qchart.h" |
|
28 | #include "qchart.h" | |
29 | //#include "qchartaxis.h" |
|
|||
30 | #include "qchartaxiscategories.h" |
|
|||
31 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
32 | #include "chartanimator_p.h" |
|
30 | #include "chartanimator_p.h" | |
33 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
34 | #include <QPainter> |
|
32 | #include <QPainter> | |
35 |
|
33 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
35 | |||
38 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
36 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
39 | ChartItem(presenter), |
|
37 | ChartItem(presenter), | |
40 | m_layoutSet(false), |
|
38 | m_layoutSet(false), | |
41 | m_series(series) |
|
39 | m_series(series) | |
42 | { |
|
40 | { | |
43 | setFlag(ItemClipsChildrenToShape); |
|
41 | setFlag(ItemClipsChildrenToShape); | |
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
42 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
45 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); |
|
43 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); | |
46 | setZValue(ChartPresenter::BarSeriesZValue); |
|
44 | setZValue(ChartPresenter::BarSeriesZValue); | |
47 | dataChanged(); |
|
45 | dataChanged(); | |
48 | } |
|
46 | } | |
49 |
|
47 | |||
50 | BarChartItem::~BarChartItem() |
|
48 | BarChartItem::~BarChartItem() | |
51 | { |
|
49 | { | |
52 | } |
|
50 | } | |
53 |
|
51 | |||
54 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
52 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
55 | { |
|
53 | { | |
56 | Q_UNUSED(painter); |
|
54 | Q_UNUSED(painter); | |
57 | Q_UNUSED(option); |
|
55 | Q_UNUSED(option); | |
58 | Q_UNUSED(widget); |
|
56 | Q_UNUSED(widget); | |
59 | } |
|
57 | } | |
60 |
|
58 | |||
61 | QRectF BarChartItem::boundingRect() const |
|
59 | QRectF BarChartItem::boundingRect() const | |
62 | { |
|
60 | { | |
63 | return m_rect; |
|
61 | return m_rect; | |
64 | } |
|
62 | } | |
65 |
|
63 | |||
66 | void BarChartItem::dataChanged() |
|
64 | void BarChartItem::dataChanged() | |
67 | { |
|
65 | { | |
68 | foreach(QGraphicsItem *item, childItems()) { |
|
66 | foreach(QGraphicsItem *item, childItems()) { | |
69 | delete item; |
|
67 | delete item; | |
70 | } |
|
68 | } | |
71 |
|
69 | |||
72 | m_bars.clear(); |
|
70 | m_bars.clear(); | |
73 | m_labels.clear(); |
|
71 | m_labels.clear(); | |
74 | m_layout.clear(); |
|
72 | m_layout.clear(); | |
75 |
|
73 | |||
76 | // Create new graphic items for bars |
|
74 | // Create new graphic items for bars | |
77 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
75 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
78 | QString category = m_series->d_func()->categoryName(c); |
|
76 | QString category = m_series->d_func()->categoryName(c); | |
79 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
77 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
80 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
78 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
81 | Bar *bar = new Bar(set,category,this); |
|
79 | Bar *bar = new Bar(set,category,this); | |
82 | m_bars.append(bar); |
|
80 | m_bars.append(bar); | |
83 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); |
|
81 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); | |
84 | connect(bar, SIGNAL(clicked(QBarSet*,QString)), m_series, SIGNAL(clicked(QBarSet*,QString))); |
|
82 | connect(bar, SIGNAL(clicked(QBarSet*,QString)), m_series, SIGNAL(clicked(QBarSet*,QString))); | |
85 | connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool))); |
|
83 | connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool))); | |
86 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); |
|
84 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); | |
87 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
85 | m_layout.append(QRectF(0, 0, 0, 0)); | |
88 | } |
|
86 | } | |
89 | } |
|
87 | } | |
90 |
|
88 | |||
91 | // Create labels |
|
89 | // Create labels | |
92 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
90 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
93 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
91 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
94 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
92 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
95 | BarLabel *value = new BarLabel(*set, this); |
|
93 | BarLabel *value = new BarLabel(*set, this); | |
96 | m_labels.append(value); |
|
94 | m_labels.append(value); | |
97 | connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); |
|
95 | connect(set->d_ptr.data(),SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); | |
98 | } |
|
96 | } | |
99 | } |
|
97 | } | |
100 | } |
|
98 | } | |
101 |
|
99 | |||
102 | QVector<QRectF> BarChartItem::calculateLayout() |
|
100 | QVector<QRectF> BarChartItem::calculateLayout() | |
103 | { |
|
101 | { | |
104 | QVector<QRectF> layout; |
|
102 | QVector<QRectF> layout; | |
105 |
|
103 | |||
106 | // Use temporary qreals for accurancy |
|
104 | // Use temporary qreals for accurancy | |
107 | qreal categoryCount = m_series->categoryCount(); |
|
105 | qreal categoryCount = m_series->categoryCount(); | |
108 | qreal setCount = m_series->barsetCount(); |
|
106 | qreal setCount = m_series->barsetCount(); | |
109 |
|
107 | |||
110 | // Domain: |
|
108 | // Domain: | |
111 | qreal width = geometry().width(); |
|
109 | qreal width = geometry().width(); | |
112 | qreal height = geometry().height(); |
|
110 | qreal height = geometry().height(); | |
113 | qreal range = m_domainMaxY - m_domainMinY; |
|
111 | qreal range = m_domainMaxY - m_domainMinY; | |
114 | qreal scale = (height / range); |
|
112 | qreal scale = (height / range); | |
115 | qreal categoryWidth = width / categoryCount; |
|
113 | qreal categoryWidth = width / categoryCount; | |
116 | qreal barWidth = categoryWidth / (setCount+1); |
|
114 | qreal barWidth = categoryWidth / (setCount+1); | |
117 |
|
115 | |||
118 | int itemIndex(0); |
|
116 | int itemIndex(0); | |
119 | for (int category = 0; category < categoryCount; category++) { |
|
117 | for (int category = 0; category < categoryCount; category++) { | |
120 | qreal xPos = categoryWidth * category + barWidth / 2 + geometry().topLeft().x(); |
|
118 | qreal xPos = categoryWidth * category + barWidth / 2 + geometry().topLeft().x(); | |
121 | qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y(); |
|
119 | qreal yPos = height + scale * m_domainMinY + geometry().topLeft().y(); | |
122 | for (int set = 0; set < setCount; set++) { |
|
120 | for (int set = 0; set < setCount; set++) { | |
123 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
121 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
124 |
|
122 | |||
125 | qreal barHeight = barSet->at(category) * scale; |
|
123 | qreal barHeight = barSet->at(category) * scale; | |
126 | Bar* bar = m_bars.at(itemIndex); |
|
124 | Bar* bar = m_bars.at(itemIndex); | |
127 |
|
125 | |||
128 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
126 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
129 | layout.append(rect); |
|
127 | layout.append(rect); | |
130 | bar->setPen(barSet->pen()); |
|
128 | bar->setPen(barSet->pen()); | |
131 | bar->setBrush(barSet->brush()); |
|
129 | bar->setBrush(barSet->brush()); | |
132 |
|
130 | |||
133 | BarLabel* label = m_labels.at(itemIndex); |
|
131 | BarLabel* label = m_labels.at(itemIndex); | |
134 |
|
132 | |||
135 | if (!qFuzzyIsNull(barSet->at(category))) { |
|
133 | if (!qFuzzyIsNull(barSet->at(category))) { | |
136 | label->setText(QString::number(barSet->at(category))); |
|
134 | label->setText(QString::number(barSet->at(category))); | |
137 | } else { |
|
135 | } else { | |
138 | label->setText(QString("")); |
|
136 | label->setText(QString("")); | |
139 | } |
|
137 | } | |
140 |
|
138 | |||
141 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
139 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
142 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
140 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
143 | label->setFont(barSet->labelFont()); |
|
141 | label->setFont(barSet->labelFont()); | |
144 |
|
142 | |||
145 | itemIndex++; |
|
143 | itemIndex++; | |
146 | xPos += barWidth; |
|
144 | xPos += barWidth; | |
147 | } |
|
145 | } | |
148 | } |
|
146 | } | |
149 | return layout; |
|
147 | return layout; | |
150 | } |
|
148 | } | |
151 |
|
149 | |||
152 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
150 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
153 | { |
|
151 | { | |
154 | if (animator()) |
|
152 | if (animator()) | |
155 | animator()->updateLayout(this, m_layout, layout); |
|
153 | animator()->updateLayout(this, m_layout, layout); | |
156 | else |
|
154 | else | |
157 | setLayout(layout); |
|
155 | setLayout(layout); | |
158 | } |
|
156 | } | |
159 |
|
157 | |||
160 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
158 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
161 | { |
|
159 | { | |
162 | m_layout = layout; |
|
160 | m_layout = layout; | |
163 |
|
161 | |||
164 | for (int i=0; i < m_bars.count(); i++) |
|
162 | for (int i=0; i < m_bars.count(); i++) | |
165 | m_bars.at(i)->setRect(layout.at(i)); |
|
163 | m_bars.at(i)->setRect(layout.at(i)); | |
166 |
|
164 | |||
167 | update(); |
|
165 | update(); | |
168 | } |
|
166 | } | |
169 | //handlers |
|
167 | //handlers | |
170 |
|
168 | |||
171 | void BarChartItem::handleModelChanged() |
|
169 | void BarChartItem::handleModelChanged() | |
172 | { |
|
170 | { | |
173 | dataChanged(); |
|
171 | dataChanged(); | |
174 | } |
|
172 | } | |
175 |
|
173 | |||
176 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
174 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
177 | { |
|
175 | { | |
178 | m_domainMinX = minX; |
|
176 | m_domainMinX = minX; | |
179 | m_domainMaxX = maxX; |
|
177 | m_domainMaxX = maxX; | |
180 | m_domainMinY = minY; |
|
178 | m_domainMinY = minY; | |
181 | m_domainMaxY = maxY; |
|
179 | m_domainMaxY = maxY; | |
182 | handleLayoutChanged(); |
|
180 | handleLayoutChanged(); | |
183 | } |
|
181 | } | |
184 |
|
182 | |||
185 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
183 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
186 | { |
|
184 | { | |
187 | prepareGeometryChange(); |
|
185 | prepareGeometryChange(); | |
188 | m_rect = rect; |
|
186 | m_rect = rect; | |
189 | handleLayoutChanged(); |
|
187 | handleLayoutChanged(); | |
190 | m_layoutSet = true; |
|
188 | m_layoutSet = true; | |
191 | } |
|
189 | } | |
192 |
|
190 | |||
193 | void BarChartItem::handleLayoutChanged() |
|
191 | void BarChartItem::handleLayoutChanged() | |
194 | { |
|
192 | { | |
195 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
193 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
196 | // rect size zero. |
|
194 | // rect size zero. | |
197 | return; |
|
195 | return; | |
198 | } |
|
196 | } | |
199 | QVector<QRectF> layout = calculateLayout(); |
|
197 | QVector<QRectF> layout = calculateLayout(); | |
200 | applyLayout(layout); |
|
198 | applyLayout(layout); | |
201 | update(); |
|
199 | update(); | |
202 | } |
|
200 | } | |
203 |
|
201 | |||
204 | #include "moc_barchartitem_p.cpp" |
|
202 | #include "moc_barchartitem_p.cpp" | |
205 |
|
203 | |||
206 | QTCOMMERCIALCHART_END_NAMESPACE |
|
204 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,84 +1,84 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARCHARTITEM_H |
|
21 | #ifndef BARCHARTITEM_H | |
22 | #define BARCHARTITEM_H |
|
22 | #define BARCHARTITEM_H | |
23 |
|
23 | |||
24 | #include "chartitem_p.h" |
|
24 | #include "chartitem_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class Bar; |
|
31 | class Bar; | |
32 | class BarLabel; |
|
32 | class BarLabel; | |
33 |
class Q |
|
33 | class QAxisCategories; | |
34 | class QChart; |
|
34 | class QChart; | |
35 |
|
35 | |||
36 | //typedef QVector<QRectF> BarLayout; |
|
36 | //typedef QVector<QRectF> BarLayout; | |
37 |
|
37 | |||
38 | class BarChartItem : public ChartItem |
|
38 | class BarChartItem : public ChartItem | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
42 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
43 | virtual ~BarChartItem(); |
|
43 | virtual ~BarChartItem(); | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | // From QGraphicsItem |
|
46 | // From QGraphicsItem | |
47 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
47 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
48 | QRectF boundingRect() const; |
|
48 | QRectF boundingRect() const; | |
49 |
|
49 | |||
50 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
50 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
51 |
|
51 | |||
52 | virtual QVector<QRectF> calculateLayout(); |
|
52 | virtual QVector<QRectF> calculateLayout(); | |
53 | void applyLayout(const QVector<QRectF> &layout); |
|
53 | void applyLayout(const QVector<QRectF> &layout); | |
54 | void setLayout(const QVector<QRectF> &layout); |
|
54 | void setLayout(const QVector<QRectF> &layout); | |
55 | void updateLayout(const QVector<QRectF> &layout); |
|
55 | void updateLayout(const QVector<QRectF> &layout); | |
56 |
|
56 | |||
57 | QRectF geometry() const { return m_rect;} |
|
57 | QRectF geometry() const { return m_rect;} | |
58 |
|
58 | |||
59 | public Q_SLOTS: |
|
59 | public Q_SLOTS: | |
60 | void handleModelChanged(); |
|
60 | void handleModelChanged(); | |
61 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
61 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
62 | void handleGeometryChanged(const QRectF &size); |
|
62 | void handleGeometryChanged(const QRectF &size); | |
63 | void handleLayoutChanged(); |
|
63 | void handleLayoutChanged(); | |
64 |
|
64 | |||
65 | protected: |
|
65 | protected: | |
66 |
|
66 | |||
67 | qreal m_domainMinX; |
|
67 | qreal m_domainMinX; | |
68 | qreal m_domainMaxX; |
|
68 | qreal m_domainMaxX; | |
69 | qreal m_domainMinY; |
|
69 | qreal m_domainMinY; | |
70 | qreal m_domainMaxY; |
|
70 | qreal m_domainMaxY; | |
71 |
|
71 | |||
72 | QRectF m_rect; |
|
72 | QRectF m_rect; | |
73 | bool m_layoutSet; // True, if component has been laid out. |
|
73 | bool m_layoutSet; // True, if component has been laid out. | |
74 | QVector<QRectF> m_layout; |
|
74 | QVector<QRectF> m_layout; | |
75 |
|
75 | |||
76 | // Not owned. |
|
76 | // Not owned. | |
77 | QBarSeries *m_series; |
|
77 | QBarSeries *m_series; | |
78 | QList<Bar *> m_bars; |
|
78 | QList<Bar *> m_bars; | |
79 | QList<BarLabel *> m_labels; |
|
79 | QList<BarLabel *> m_labels; | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | QTCOMMERCIALCHART_END_NAMESPACE | |
83 |
|
83 | |||
84 | #endif // BARCHARTITEM_H |
|
84 | #endif // BARCHARTITEM_H |
@@ -1,252 +1,252 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qaxis.h" |
|
22 | #include "qaxis.h" | |
23 | #include "qaxis_p.h" |
|
23 | #include "qaxis_p.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qstackedbarseries.h" |
|
26 | #include "qstackedbarseries.h" | |
27 | #include "qpercentbarseries.h" |
|
27 | #include "qpercentbarseries.h" | |
28 | #include "qpieseries.h" |
|
28 | #include "qpieseries.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
32 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
33 | m_axisX(new QAxis(this)), |
|
33 | m_axisX(new QAxis(this)), | |
34 | m_axisY(new QAxis(this)), |
|
34 | m_axisY(new QAxis(this)), | |
35 | m_domainIndex(0), |
|
35 | m_domainIndex(0), | |
36 | m_axisXInitialized(false) |
|
36 | m_axisXInitialized(false) | |
37 | { |
|
37 | { | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | ChartDataSet::~ChartDataSet() |
|
40 | ChartDataSet::~ChartDataSet() | |
41 | { |
|
41 | { | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) |
|
44 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) | |
45 | { |
|
45 | { | |
46 | if(axisY==0) axisY = m_axisY; |
|
46 | if(axisY==0) axisY = m_axisY; | |
47 |
|
47 | |||
48 | QAxis* axis = m_seriesAxisMap.value(series); |
|
48 | QAxis* axis = m_seriesAxisMap.value(series); | |
49 |
|
49 | |||
50 | if(axis) { |
|
50 | if(axis) { | |
51 | qWarning() << "Can not add series. Series already on the chart"; |
|
51 | qWarning() << "Can not add series. Series already on the chart"; | |
52 | return; |
|
52 | return; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | series->setParent(this); // take ownership |
|
55 | series->setParent(this); // take ownership | |
56 | axisY->setParent(this); // take ownership |
|
56 | axisY->setParent(this); // take ownership | |
57 |
|
57 | |||
58 | Domain* domain = m_axisDomainMap.value(axisY); |
|
58 | Domain* domain = m_axisDomainMap.value(axisY); | |
59 |
|
59 | |||
60 | if(!domain) { |
|
60 | if(!domain) { | |
61 | domain = new Domain(axisY); |
|
61 | domain = new Domain(axisY); | |
62 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
62 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
63 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
63 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
64 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
64 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
65 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX()->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
65 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX()->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
66 | //initialize |
|
66 | //initialize | |
67 | m_axisDomainMap.insert(axisY,domain); |
|
67 | m_axisDomainMap.insert(axisY,domain); | |
68 | emit axisAdded(axisY,domain); |
|
68 | emit axisAdded(axisY,domain); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | if(!m_axisXInitialized){ |
|
71 | if(!m_axisXInitialized){ | |
72 | emit axisAdded(axisX(),domain); |
|
72 | emit axisAdded(axisX(),domain); | |
73 | m_axisXInitialized=true; |
|
73 | m_axisXInitialized=true; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | series->d_ptr->scaleDomain(*domain); |
|
76 | series->d_ptr->scaleDomain(*domain); | |
77 |
|
77 | |||
78 | if(series->type() == QAbstractSeries::SeriesTypeBar |
|
78 | if(series->type() == QAbstractSeries::SeriesTypeBar | |
79 | || series->type() == QAbstractSeries::SeriesTypeStackedBar |
|
79 | || series->type() == QAbstractSeries::SeriesTypeStackedBar | |
80 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { |
|
80 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { | |
81 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
81 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
82 | setupCategories(barSeries); |
|
82 | setupCategories(barSeries); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { |
|
85 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { | |
86 | axisX()->hide(); |
|
86 | axisX()->hide(); | |
87 | this->axisY()->hide(); |
|
87 | this->axisY()->hide(); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | m_seriesAxisMap.insert(series,axisY); |
|
90 | m_seriesAxisMap.insert(series,axisY); | |
91 |
|
91 | |||
92 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
92 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
93 |
|
93 | |||
94 | int key=0; |
|
94 | int key=0; | |
95 | while (i.hasNext()) { |
|
95 | while (i.hasNext()) { | |
96 | i.next(); |
|
96 | i.next(); | |
97 | if(i.key()!=key) { |
|
97 | if(i.key()!=key) { | |
98 | break; |
|
98 | break; | |
99 | } |
|
99 | } | |
100 | key++; |
|
100 | key++; | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | m_indexSeriesMap.insert(key,series); |
|
103 | m_indexSeriesMap.insert(key,series); | |
104 |
|
104 | |||
105 | emit seriesAdded(series,domain); |
|
105 | emit seriesAdded(series,domain); | |
106 |
|
106 | |||
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) |
|
109 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) | |
110 | { |
|
110 | { | |
111 | QAxis* axis = m_seriesAxisMap.value(series); |
|
111 | QAxis* axis = m_seriesAxisMap.value(series); | |
112 |
|
112 | |||
113 | if(!axis){ |
|
113 | if(!axis){ | |
114 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
114 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
115 | return 0; |
|
115 | return 0; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | emit seriesRemoved(series); |
|
118 | emit seriesRemoved(series); | |
119 |
|
119 | |||
120 | m_seriesAxisMap.remove(series); |
|
120 | m_seriesAxisMap.remove(series); | |
121 | int key = seriesIndex(series); |
|
121 | int key = seriesIndex(series); | |
122 | Q_ASSERT(key!=-1); |
|
122 | Q_ASSERT(key!=-1); | |
123 |
|
123 | |||
124 | m_indexSeriesMap.remove(key); |
|
124 | m_indexSeriesMap.remove(key); | |
125 | series->setParent(0); |
|
125 | series->setParent(0); | |
126 |
|
126 | |||
127 | QList<QAxis*> axes = m_seriesAxisMap.values(); |
|
127 | QList<QAxis*> axes = m_seriesAxisMap.values(); | |
128 |
|
128 | |||
129 | int i = axes.indexOf(axis); |
|
129 | int i = axes.indexOf(axis); | |
130 |
|
130 | |||
131 | if(i==-1){ |
|
131 | if(i==-1){ | |
132 | Domain* domain = m_axisDomainMap.take(axis); |
|
132 | Domain* domain = m_axisDomainMap.take(axis); | |
133 | emit axisRemoved(axis); |
|
133 | emit axisRemoved(axis); | |
134 | if(axis!=axisY()){ |
|
134 | if(axis!=axisY()){ | |
135 | axis->setParent(0); |
|
135 | axis->setParent(0); | |
136 | } |
|
136 | } | |
137 | delete domain; |
|
137 | delete domain; | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | if(m_seriesAxisMap.values().size()==0) |
|
140 | if(m_seriesAxisMap.values().size()==0) | |
141 | { |
|
141 | { | |
142 | m_axisXInitialized=false; |
|
142 | m_axisXInitialized=false; | |
143 | emit axisRemoved(axisX()); |
|
143 | emit axisRemoved(axisX()); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | return axis; |
|
146 | return axis; | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | void ChartDataSet::removeAllSeries() |
|
149 | void ChartDataSet::removeAllSeries() | |
150 | { |
|
150 | { | |
151 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); |
|
151 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); | |
152 | QList<QAxis*> axes; |
|
152 | QList<QAxis*> axes; | |
153 | foreach(QAbstractSeries *s , series) { |
|
153 | foreach(QAbstractSeries *s , series) { | |
154 | QAxis* axis = removeSeries(s); |
|
154 | QAxis* axis = removeSeries(s); | |
155 | if(axis==axisY()) continue; |
|
155 | if(axis==axisY()) continue; | |
156 | int i = axes.indexOf(axis); |
|
156 | int i = axes.indexOf(axis); | |
157 | if(i==-1){ |
|
157 | if(i==-1){ | |
158 | axes<<axis; |
|
158 | axes<<axis; | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | Q_ASSERT(m_seriesAxisMap.count()==0); |
|
162 | Q_ASSERT(m_seriesAxisMap.count()==0); | |
163 | Q_ASSERT(m_axisDomainMap.count()==0); |
|
163 | Q_ASSERT(m_axisDomainMap.count()==0); | |
164 |
|
164 | |||
165 | qDeleteAll(series); |
|
165 | qDeleteAll(series); | |
166 | qDeleteAll(axes); |
|
166 | qDeleteAll(axes); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | void ChartDataSet::setupCategories(QBarSeries* series) |
|
169 | void ChartDataSet::setupCategories(QBarSeries* series) | |
170 | { |
|
170 | { | |
171 |
Q |
|
171 | QAxisCategories* categories = axisX()->categories(); | |
172 | categories->clear(); |
|
172 | categories->clear(); | |
173 | categories->insert(series->categories()); |
|
173 | categories->insert(series->categories()); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
176 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
177 | { |
|
177 | { | |
178 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); |
|
178 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
179 | while (i.hasNext()) { |
|
179 | while (i.hasNext()) { | |
180 | i.next(); |
|
180 | i.next(); | |
181 | i.value()->zoomIn(rect,size); |
|
181 | i.value()->zoomIn(rect,size); | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
185 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
186 | { |
|
186 | { | |
187 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); |
|
187 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
188 | while (i.hasNext()) { |
|
188 | while (i.hasNext()) { | |
189 | i.next(); |
|
189 | i.next(); | |
190 | i.value()->zoomOut(rect,size); |
|
190 | i.value()->zoomOut(rect,size); | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | int ChartDataSet::seriesCount(QAbstractSeries::QSeriesType type) |
|
194 | int ChartDataSet::seriesCount(QAbstractSeries::QSeriesType type) | |
195 | { |
|
195 | { | |
196 | int count=0; |
|
196 | int count=0; | |
197 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); |
|
197 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); | |
198 | while (i.hasNext()) { |
|
198 | while (i.hasNext()) { | |
199 | i.next(); |
|
199 | i.next(); | |
200 | if(i.key()->type()==type) count++; |
|
200 | if(i.key()->type()==type) count++; | |
201 | } |
|
201 | } | |
202 | return count; |
|
202 | return count; | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
205 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
206 | { |
|
206 | { | |
207 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
207 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
208 | while (i.hasNext()) { |
|
208 | while (i.hasNext()) { | |
209 | i.next(); |
|
209 | i.next(); | |
210 | if (i.value() == series) |
|
210 | if (i.value() == series) | |
211 | return i.key(); |
|
211 | return i.key(); | |
212 | } |
|
212 | } | |
213 | return -1; |
|
213 | return -1; | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
216 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
217 | { |
|
217 | { | |
218 | if(series == 0) return m_axisY; |
|
218 | if(series == 0) return m_axisY; | |
219 | return m_seriesAxisMap.value(series); |
|
219 | return m_seriesAxisMap.value(series); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
222 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
223 | { |
|
223 | { | |
224 | QAxis* axis = m_seriesAxisMap.value(series); |
|
224 | QAxis* axis = m_seriesAxisMap.value(series); | |
225 | if(axis){ |
|
225 | if(axis){ | |
226 | return m_axisDomainMap.value(axis); |
|
226 | return m_axisDomainMap.value(axis); | |
227 | }else |
|
227 | }else | |
228 | return 0; |
|
228 | return 0; | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | Domain* ChartDataSet::domain(QAxis* axis) const |
|
231 | Domain* ChartDataSet::domain(QAxis* axis) const | |
232 | { |
|
232 | { | |
233 | if(!axis || axis==axisX()) { |
|
233 | if(!axis || axis==axisX()) { | |
234 | return m_axisDomainMap.value(axisY()); |
|
234 | return m_axisDomainMap.value(axisY()); | |
235 | } |
|
235 | } | |
236 | else { |
|
236 | else { | |
237 | return m_axisDomainMap.value(axis); |
|
237 | return m_axisDomainMap.value(axis); | |
238 | } |
|
238 | } | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) |
|
241 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) | |
242 | { |
|
242 | { | |
243 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); |
|
243 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); | |
244 | while (i.hasNext()) { |
|
244 | while (i.hasNext()) { | |
245 | i.next(); |
|
245 | i.next(); | |
246 | i.value()->move(dx,dy,size); |
|
246 | i.value()->move(dx,dy,size); | |
247 | } |
|
247 | } | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | #include "moc_chartdataset_p.cpp" |
|
250 | #include "moc_chartdataset_p.cpp" | |
251 |
|
251 | |||
252 | QTCOMMERCIALCHART_END_NAMESPACE |
|
252 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now