##// END OF EJS Templates
Add Polar chart support...
Miikka Heikkinen -
r2483:f494279b6366
parent child
Show More
@@ -0,0 +1,36
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include <QApplication>
22 #include <QtDeclarative/QDeclarativeEngine>
23 #include "qmlapplicationviewer.h"
24
25 Q_DECL_EXPORT int main(int argc, char *argv[])
26 {
27 QScopedPointer<QApplication> app(createApplication(argc, argv));
28 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
29
30 // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
31 viewer->setSource(QUrl("qrc:/qml/qmlpolarchart/loader.qml"));
32 viewer->setRenderHint(QPainter::Antialiasing, true);
33 viewer->showExpanded();
34
35 return app->exec();
36 }
@@ -0,0 +1,68
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.3
23
24 Rectangle {
25 anchors.fill: parent
26 //![1]
27 PolarChartView {
28 title: "Two Series, Common Axes"
29 anchors.fill: parent
30 legend.visible: false
31
32 ValueAxis {
33 id: axisAngular
34 min: 0
35 max: 20
36 tickCount: 9
37 }
38
39 ValueAxis {
40 id: axisRadial
41 min: -0.5
42 max: 1.5
43 }
44
45 SplineSeries {
46 id: series1
47 axisAngular: axisAngular
48 axisRadial: axisRadial
49 pointsVisible: true
50 }
51
52 ScatterSeries {
53 id: series2
54 axisAngular: axisAngular
55 axisRadial: axisRadial
56 markerSize: 10
57 }
58 }
59
60 // Add data dynamically to the series
61 Component.onCompleted: {
62 for (var i = 0; i <= 20; i++) {
63 series1.append(i, Math.random());
64 series2.append(i, Math.random());
65 }
66 }
67 //![1]
68 }
@@ -0,0 +1,89
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.3
23
24 Rectangle {
25 anchors.fill: parent
26
27 //![1]
28 PolarChartView {
29 title: "Historical Area Series"
30 anchors.fill: parent
31 legend.visible: false
32
33 DateTimeAxis {
34 id: axis1
35 format: "yyyy MMM"
36 tickCount: 13
37 }
38 ValueAxis {
39 id: axis2
40 }
41 LineSeries {
42 id: lowerLine
43 axisAngular: axis1
44 axisRadial: axis2
45
46 // Please note that month in JavaScript months are zero based, so 2 means March
47 XYPoint { x: toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 15 }
48 XYPoint { x: toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 35 }
49 XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 }
50 XYPoint { x: toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 75 }
51 XYPoint { x: toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 102 }
52 XYPoint { x: toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 132 }
53 XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 }
54 XYPoint { x: toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 120 }
55 XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 140 }
56 XYPoint { x: toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 150 }
57 }
58 LineSeries {
59 id: upperLine
60 axisAngular: axis1
61 axisRadial: axis2
62
63 // Please note that month in JavaScript months are zero based, so 2 means March
64 XYPoint { x: toMsecsSinceEpoch(new Date(1950, 0, 1)); y: 30 }
65 XYPoint { x: toMsecsSinceEpoch(new Date(1962, 4, 1)); y: 55 }
66 XYPoint { x: toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 80 }
67 XYPoint { x: toMsecsSinceEpoch(new Date(1978, 2, 1)); y: 105 }
68 XYPoint { x: toMsecsSinceEpoch(new Date(1987, 11, 1)); y: 125 }
69 XYPoint { x: toMsecsSinceEpoch(new Date(1992, 1, 1)); y: 160 }
70 XYPoint { x: toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 140 }
71 XYPoint { x: toMsecsSinceEpoch(new Date(2002, 4, 1)); y: 140 }
72 XYPoint { x: toMsecsSinceEpoch(new Date(2012, 8, 1)); y: 170 }
73 XYPoint { x: toMsecsSinceEpoch(new Date(2013, 5, 1)); y: 200 }
74 }
75 AreaSeries {
76 axisAngular: axis1
77 axisRadial: axis2
78 lowerSeries: lowerLine
79 upperSeries: upperLine
80 }
81 }
82 // DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to
83 // milliseconds since epoch to make them match the DateTimeAxis values
84 function toMsecsSinceEpoch(date) {
85 var msecs = date.getTime();
86 return msecs;
87 }
88 //![1]
89 }
@@ -0,0 +1,76
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.3
23
24 Rectangle {
25 anchors.fill: parent
26
27 //![1]
28 PolarChartView {
29 title: "Numerical Data for Dummies"
30 anchors.fill: parent
31 legend.visible: false
32
33 LineSeries {
34 axisRadial: CategoryAxis {
35 min: 0
36 max: 30
37 CategoryRange {
38 label: "critical"
39 endValue: 2
40 }
41 CategoryRange {
42 label: "low"
43 endValue: 4
44 }
45 CategoryRange {
46 label: "normal"
47 endValue: 7
48 }
49 CategoryRange {
50 label: "high"
51 endValue: 15
52 }
53 CategoryRange {
54 label: "extremely high"
55 endValue: 30
56 }
57 }
58
59 axisAngular: ValueAxis {
60 tickCount: 13
61 }
62
63 XYPoint { x: 0; y: 4.3 }
64 XYPoint { x: 1; y: 4.1 }
65 XYPoint { x: 2; y: 4.7 }
66 XYPoint { x: 3; y: 3.9 }
67 XYPoint { x: 4; y: 5.2 }
68 XYPoint { x: 5; y: 5.3 }
69 XYPoint { x: 6; y: 6.1 }
70 XYPoint { x: 7; y: 7.7 }
71 XYPoint { x: 8; y: 12.9 }
72 XYPoint { x: 9; y: 19.2 }
73 }
74 }
75 //![1]
76 }
@@ -0,0 +1,37
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22
23 Item {
24 id: container
25 width: 400
26 height: 300
27 Component.onCompleted: {
28 var co = Qt.createComponent("main.qml")
29 if (co.status == Component.Ready) {
30 var o = co.createObject(container)
31 } else {
32 console.log(co.errorString())
33 console.log("QtCommercial.Chart 1.3 not available")
34 console.log("Please use correct QML_IMPORT_PATH export")
35 }
36 }
37 }
@@ -0,0 +1,90
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22
23 Rectangle {
24 width: parent.width
25 height: parent.height
26 property int viewNumber: 1
27 property int viewCount: 3
28
29 Loader {
30 id: loader
31 anchors.fill: parent
32 source: "View" + viewNumber + ".qml";
33 }
34
35 Rectangle {
36 id: infoText
37 anchors.centerIn: parent
38 width: parent.width
39 height: 40
40 color: "black"
41 Text {
42 color: "white"
43 anchors.centerIn: parent
44 text: "Use left and right arrow keys to navigate"
45 }
46
47 Behavior on opacity {
48 NumberAnimation { duration: 400 }
49 }
50 }
51
52 MouseArea {
53 focus: true
54 anchors.fill: parent
55 onClicked: {
56 if (infoText.opacity > 0) {
57 infoText.opacity = 0.0;
58 } else {
59 nextView();
60 }
61 }
62 Keys.onPressed: {
63 if (infoText.opacity > 0) {
64 infoText.opacity = 0.0;
65 } else {
66 if (event.key == Qt.Key_Left) {
67 previousView();
68 } else {
69 nextView();
70 }
71 }
72 }
73 }
74
75 function nextView() {
76 var i = viewNumber + 1;
77 if (i > viewCount)
78 viewNumber = 1;
79 else
80 viewNumber = i;
81 }
82
83 function previousView() {
84 var i = viewNumber - 1;
85 if (i <= 0)
86 viewNumber = viewCount;
87 else
88 viewNumber = i;
89 }
90 }
@@ -0,0 +1,177
1 // checksum 0xbd34 version 0x80016
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #include "qmlapplicationviewer.h"
12
13 #include <QDir>
14 #include <QFileInfo>
15 #include <QApplication>
16 #include <QDeclarativeComponent>
17 #include <QDeclarativeEngine>
18 #include <QDeclarativeContext>
19
20 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
21
22 #ifdef HARMATTAN_BOOSTER
23 #include <MDeclarativeCache>
24 #endif
25
26 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
27
28 #include <qt_private/qdeclarativedebughelper_p.h>
29
30 #if !defined(NO_JSDEBUGGER)
31 #include <jsdebuggeragent.h>
32 #endif
33 #if !defined(NO_QMLOBSERVER)
34 #include <qdeclarativeviewobserver.h>
35 #endif
36
37 // Enable debugging before any QDeclarativeEngine is created
38 struct QmlJsDebuggingEnabler
39 {
40 QmlJsDebuggingEnabler()
41 {
42 QDeclarativeDebugHelper::enableDebugging();
43 }
44 };
45
46 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 static QmlJsDebuggingEnabler enableDebuggingHelper;
48
49 #endif // QMLJSDEBUGGER
50
51 class QmlApplicationViewerPrivate
52 {
53 QString mainQmlFile;
54 friend class QmlApplicationViewer;
55 static QString adjustPath(const QString &path);
56 };
57
58 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
59 {
60 #ifdef Q_OS_MAC
61 if (!QDir::isAbsolutePath(path))
62 return QString::fromLatin1("%1/../Resources/%2")
63 .arg(QCoreApplication::applicationDirPath(), path);
64 #elif defined(Q_OS_QNX)
65 if (!QDir::isAbsolutePath(path))
66 return QString::fromLatin1("app/native/%1").arg(path);
67 #elif !defined(Q_OS_ANDROID)
68 QString pathInInstallDir =
69 QString::fromLatin1("%1/../%2").arg(QCoreApplication::applicationDirPath(), path);
70 if (QFileInfo(pathInInstallDir).exists())
71 return pathInInstallDir;
72 pathInInstallDir =
73 QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), path);
74 if (QFileInfo(pathInInstallDir).exists())
75 return pathInInstallDir;
76 #endif
77 return path;
78 }
79
80 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
81 : QDeclarativeView(parent)
82 , d(new QmlApplicationViewerPrivate())
83 {
84 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86
87 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
88 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
89 #if !defined(NO_JSDEBUGGER)
90 new QmlJSDebugger::JSDebuggerAgent(engine());
91 #endif
92 #if !defined(NO_QMLOBSERVER)
93 new QmlJSDebugger::QDeclarativeViewObserver(this, this);
94 #endif
95 #endif
96 }
97
98 QmlApplicationViewer::~QmlApplicationViewer()
99 {
100 delete d;
101 }
102
103 QmlApplicationViewer *QmlApplicationViewer::create()
104 {
105 return new QmlApplicationViewer();
106 }
107
108 void QmlApplicationViewer::setMainQmlFile(const QString &file)
109 {
110 d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
111 #ifdef Q_OS_ANDROID
112 setSource(QUrl(QLatin1String("assets:/")+d->mainQmlFile));
113 #else
114 setSource(QUrl::fromLocalFile(d->mainQmlFile));
115 #endif
116 }
117
118 void QmlApplicationViewer::addImportPath(const QString &path)
119 {
120 engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
121 }
122
123 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
124 {
125 #if QT_VERSION < 0x050000
126 Qt::WidgetAttribute attribute;
127 switch (orientation) {
128 #if QT_VERSION < 0x040702
129 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
130 case ScreenOrientationLockPortrait:
131 attribute = static_cast<Qt::WidgetAttribute>(128);
132 break;
133 case ScreenOrientationLockLandscape:
134 attribute = static_cast<Qt::WidgetAttribute>(129);
135 break;
136 default:
137 case ScreenOrientationAuto:
138 attribute = static_cast<Qt::WidgetAttribute>(130);
139 break;
140 #else // QT_VERSION < 0x040702
141 case ScreenOrientationLockPortrait:
142 attribute = Qt::WA_LockPortraitOrientation;
143 break;
144 case ScreenOrientationLockLandscape:
145 attribute = Qt::WA_LockLandscapeOrientation;
146 break;
147 default:
148 case ScreenOrientationAuto:
149 attribute = Qt::WA_AutoOrientation;
150 break;
151 #endif // QT_VERSION < 0x040702
152 };
153 setAttribute(attribute, true);
154 #else // QT_VERSION < 0x050000
155 Q_UNUSED(orientation)
156 #endif // QT_VERSION < 0x050000
157 }
158
159 void QmlApplicationViewer::showExpanded()
160 {
161 #if defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
162 showFullScreen();
163 #elif defined(Q_WS_MAEMO_5) || defined(Q_OS_QNX)
164 showMaximized();
165 #else
166 show();
167 #endif
168 }
169
170 QApplication *createApplication(int &argc, char **argv)
171 {
172 #ifdef HARMATTAN_BOOSTER
173 return MDeclarativeCache::qApplication(argc, argv);
174 #else
175 return new QApplication(argc, argv);
176 #endif
177 }
@@ -0,0 +1,46
1 // checksum 0xc67a version 0x80016
2 /*
3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 QmlApplicationViewer is a convenience class containing mobile device specific
5 code such as screen orientation handling. Also QML paths and debugging are
6 handled here.
7 It is recommended not to modify this file, since newer versions of Qt Creator
8 may offer an updated version of it.
9 */
10
11 #ifndef QMLAPPLICATIONVIEWER_H
12 #define QMLAPPLICATIONVIEWER_H
13
14 #include <QDeclarativeView>
15
16 class QmlApplicationViewer : public QDeclarativeView
17 {
18 Q_OBJECT
19
20 public:
21 enum ScreenOrientation {
22 ScreenOrientationLockPortrait,
23 ScreenOrientationLockLandscape,
24 ScreenOrientationAuto
25 };
26
27 explicit QmlApplicationViewer(QWidget *parent = 0);
28 virtual ~QmlApplicationViewer();
29
30 static QmlApplicationViewer *create();
31
32 void setMainQmlFile(const QString &file);
33 void addImportPath(const QString &path);
34
35 // Note that this will only have an effect on Fremantle.
36 void setOrientation(ScreenOrientation orientation);
37
38 void showExpanded();
39
40 private:
41 class QmlApplicationViewerPrivate *d;
42 };
43
44 QApplication *createApplication(int &argc, char **argv);
45
46 #endif // QMLAPPLICATIONVIEWER_H
@@ -0,0 +1,13
1 QT += declarative
2
3 SOURCES += $$PWD/qmlapplicationviewer.cpp
4 HEADERS += $$PWD/qmlapplicationviewer.h
5 INCLUDEPATH += $$PWD
6
7 # Include JS debugger library if QMLJSDEBUGGER_PATH is set
8 !isEmpty(QMLJSDEBUGGER_PATH) {
9 include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri)
10 } else {
11 DEFINES -= QMLJSDEBUGGER
12 }
13
@@ -0,0 +1,9
1 !include( ../demos.pri ) {
2 error( "Couldn't find the demos.pri file!" )
3 }
4
5 RESOURCES += resources.qrc
6 SOURCES += main.cpp
7 OTHER_FILES += qml/qmlpolarchart/*
8
9 include(qmlapplicationviewer/qmlapplicationviewer.pri)
@@ -0,0 +1,9
1 <RCC>
2 <qresource prefix="/">
3 <file>qml/qmlpolarchart/loader.qml</file>
4 <file>qml/qmlpolarchart/main.qml</file>
5 <file>qml/qmlpolarchart/View1.qml</file>
6 <file>qml/qmlpolarchart/View2.qml</file>
7 <file>qml/qmlpolarchart/View3.qml</file>
8 </qresource>
9 </RCC>
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,33
1 /*!
2 \example demos/qmlpolarchart
3 \title Qml Polar Chart
4 \subtitle
5
6 This is a demonstration of how to use polar chart in your QML application.
7
8 \table
9 \row
10 \o \br
11 We begin with a chart that has a spline series and a scatter series with random
12 data. Both series use the same axes.
13 \br
14 \br
15 \snippet ../demos/qmlpolarchart/qml/qmlpolarchart/View1.qml 1
16 \o \inlineimage demos_qmlpolarchart1.png
17 \row
18 \o \br
19 The next example shows a chart with some accurate historical data that makes us to use a DateTimeAxis
20 and AreaSeries.
21 \br
22 \br
23 \snippet ../demos/qmlpolarchart/qml/qmlpolarchart/View2.qml 1
24 \o \inlineimage demos_qmlpolarchart2.png
25 \row
26 \o \br
27 And the final example with a chart that uses a CategoryAxis to make the data easier to understand.
28 \br
29 \br
30 \snippet ../demos/qmlpolarchart/qml/qmlpolarchart/View3.qml 1
31 \o \inlineimage demos_qmlpolarchart3.png
32 \endtable
33 */
@@ -0,0 +1,33
1 /*!
2 \example examples/polarchart
3 \title Polar chart example
4 \subtitle
5
6 The example shows how to create simple polar chart with multiple different series.
7 It also shows how to implement scrolling and zooming of the polar chart as well as
8 visually demonstrate how polar chart and cartesian chart relate to each other.
9
10 \image examples_polarchart.png
11
12 Creating polar chart is done via QPolarChart instance instead of QChart.
13
14 \snippet ../examples/polarchart/main.cpp 1
15
16 Axes are created similarly to cartesian charts, but when axes are added to the chart,
17 you can use polar orientations instead of alignments.
18
19 \snippet ../examples/polarchart/main.cpp 2
20
21 Zooming and scrolling of the polar chart is logically nearly identical to zooming and scrolling of cartesian chart.
22 The main difference is that when scrolling along X-axis (angular axis), angle is used instead of number of pixels.
23 Another difference is that zooming to a rectangle cannot be done.
24
25 \snippet ../examples/polarchart/chartview.cpp 1
26
27 Same axes and series can be used in both cartesian and polar charts, though not simultaneously.
28 To switch between chart types, you need to first remove series and axes from the old chart and then add
29 them to the new chart. If you want to preserve axis ranges, those need to be copied, too.
30
31 \snippet ../examples/polarchart/chartview.cpp 2
32
33 */
@@ -0,0 +1,111
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "chartview.h"
22 #include <QMouseEvent>
23 #include <QDebug>
24 #include <QAbstractAxis>
25 #include <QValueAxis>
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
29 ChartView::ChartView(QWidget *parent)
30 : QChartView(parent)
31 {
32 }
33
34 //![1]
35 void ChartView::keyPressEvent(QKeyEvent *event)
36 {
37 switch (event->key()) {
38 case Qt::Key_Plus:
39 chart()->zoomIn();
40 break;
41 case Qt::Key_Minus:
42 chart()->zoomOut();
43 break;
44 case Qt::Key_Left:
45 chart()->scroll(-1.0, 0);
46 break;
47 case Qt::Key_Right:
48 chart()->scroll(1.0, 0);
49 break;
50 case Qt::Key_Up:
51 chart()->scroll(0, 1.0);
52 break;
53 case Qt::Key_Down:
54 chart()->scroll(0, -1.0);
55 break;
56 case Qt::Key_Space:
57 switchChartType();
58 break;
59 default:
60 QGraphicsView::keyPressEvent(event);
61 break;
62 }
63 }
64 //![1]
65
66 //![2]
67 void ChartView::switchChartType()
68 {
69 QChart *newChart;
70 QChart *oldChart = chart();
71
72 if (oldChart->chartType() == QChart::ChartTypeCartesian)
73 newChart = new QPolarChart();
74 else
75 newChart = new QChart();
76
77 // Move series and axes from old chart to new one
78 QList<QAbstractSeries *> seriesList = oldChart->series();
79 QList<QAbstractAxis *> axisList = oldChart->axes();
80 QList<QPair<qreal, qreal>> axisRanges;
81
82 foreach (QAbstractAxis *axis, axisList) {
83 QValueAxis *valueAxis = static_cast<QValueAxis *>(axis);
84 axisRanges.append(QPair<qreal, qreal>(valueAxis->min(), valueAxis->max()));
85 }
86
87 foreach (QAbstractSeries *series, seriesList)
88 oldChart->removeSeries(series);
89
90 foreach (QAbstractAxis *axis, axisList) {
91 oldChart->removeAxis(axis);
92 newChart->addAxis(axis, axis->alignment());
93 }
94
95 foreach (QAbstractSeries *series, seriesList) {
96 newChart->addSeries(series);
97 foreach (QAbstractAxis *axis, axisList)
98 series->attachAxis(axis);
99 }
100
101 int count = 0;
102 foreach (QAbstractAxis *axis, axisList) {
103 axis->setRange(axisRanges[count].first, axisRanges[count].second);
104 count++;
105 }
106
107 newChart->setTitle(oldChart->title());
108 setChart(newChart);
109 delete oldChart;
110 }
111 //![2]
@@ -0,0 +1,41
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef CHARTVIEW_H
22 #define CHARTVIEW_H
23
24 #include <QChartView>
25 #include <QPolarChart>
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
29 class ChartView : public QChartView
30 {
31 public:
32 ChartView(QWidget *parent = 0);
33
34 protected:
35 void keyPressEvent(QKeyEvent *event);
36
37 private:
38 void switchChartType();
39 };
40
41 #endif
@@ -0,0 +1,137
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "chartview.h"
22 #include <QApplication>
23 #include <QMainWindow>
24 #include <QScatterSeries>
25 #include <QLineSeries>
26 #include <QSplineSeries>
27 #include <QAreaSeries>
28 #include <QValueAxis>
29 #include <QPolarChart>
30 #include <QDebug>
31
32 QTCOMMERCIALCHART_USE_NAMESPACE
33
34 int main(int argc, char *argv[])
35 {
36 QApplication a(argc, argv);
37
38 const qreal angularMin = -100;
39 const qreal angularMax = 100;
40
41 const qreal radialMin = -100;
42 const qreal radialMax = 100;
43
44 QScatterSeries *series1 = new QScatterSeries();
45 series1->setName("scatter");
46 for (int i = angularMin; i <= angularMax; i += 10)
47 series1->append(i, (i / radialMax) * radialMax + 8.0);
48
49 QSplineSeries *series2 = new QSplineSeries();
50 series2->setName("spline");
51 for (int i = angularMin; i <= angularMax; i += 10)
52 series2->append(i, (i / radialMax) * radialMax);
53
54 QLineSeries *series3 = new QLineSeries();
55 series3->setName("star outer");
56 qreal ad = (angularMax - angularMin) / 8;
57 qreal rd = (radialMax - radialMin) / 3 * 1.3;
58 series3->append(angularMin, radialMax);
59 series3->append(angularMin + ad*1, radialMin + rd);
60 series3->append(angularMin + ad*2, radialMax);
61 series3->append(angularMin + ad*3, radialMin + rd);
62 series3->append(angularMin + ad*4, radialMax);
63 series3->append(angularMin + ad*5, radialMin + rd);
64 series3->append(angularMin + ad*6, radialMax);
65 series3->append(angularMin + ad*7, radialMin + rd);
66 series3->append(angularMin + ad*8, radialMax);
67
68 QLineSeries *series4 = new QLineSeries();
69 series4->setName("star inner");
70 ad = (angularMax - angularMin) / 8;
71 rd = (radialMax - radialMin) / 3;
72 series4->append(angularMin, radialMax);
73 series4->append(angularMin + ad*1, radialMin + rd);
74 series4->append(angularMin + ad*2, radialMax);
75 series4->append(angularMin + ad*3, radialMin + rd);
76 series4->append(angularMin + ad*4, radialMax);
77 series4->append(angularMin + ad*5, radialMin + rd);
78 series4->append(angularMin + ad*6, radialMax);
79 series4->append(angularMin + ad*7, radialMin + rd);
80 series4->append(angularMin + ad*8, radialMax);
81
82 QAreaSeries *series5 = new QAreaSeries();
83 series5->setName("star area");
84 series5->setUpperSeries(series3);
85 series5->setLowerSeries(series4);
86 series5->setOpacity(0.5);
87
88 //![1]
89 QPolarChart *chart = new QPolarChart();
90 //![1]
91 chart->addSeries(series1);
92 chart->addSeries(series2);
93 chart->addSeries(series3);
94 chart->addSeries(series4);
95 chart->addSeries(series5);
96
97 chart->setTitle("Use arrow keys to scroll, +/- to zoom, and space to switch chart type.");
98
99 //![2]
100 QValueAxis *angularAxis = new QValueAxis();
101 angularAxis->setTickCount(9); // First and last ticks are co-located on 0/360 angle.
102 angularAxis->setLabelFormat("%.1f");
103 angularAxis->setShadesVisible(true);
104 angularAxis->setShadesBrush(QBrush(QColor(249, 249, 255)));
105 chart->addAxis(angularAxis, QPolarChart::PolarOrientationAngular);
106
107 QValueAxis *radialAxis = new QValueAxis();
108 radialAxis->setTickCount(9);
109 radialAxis->setLabelFormat("%d");
110 chart->addAxis(radialAxis, QPolarChart::PolarOrientationRadial);
111 //![2]
112
113 series1->attachAxis(radialAxis);
114 series1->attachAxis(angularAxis);
115 series2->attachAxis(radialAxis);
116 series2->attachAxis(angularAxis);
117 series3->attachAxis(radialAxis);
118 series3->attachAxis(angularAxis);
119 series4->attachAxis(radialAxis);
120 series4->attachAxis(angularAxis);
121 series5->attachAxis(radialAxis);
122 series5->attachAxis(angularAxis);
123
124 radialAxis->setRange(radialMin, radialMax);
125 angularAxis->setRange(angularMin, angularMax);
126
127 ChartView *chartView = new ChartView();
128 chartView->setChart(chart);
129 chartView->setRenderHint(QPainter::Antialiasing);
130
131 QMainWindow window;
132 window.setCentralWidget(chartView);
133 window.resize(800, 600);
134 window.show();
135
136 return a.exec();
137 }
@@ -0,0 +1,6
1 !include( ../examples.pri ) {
2 error( "Couldn't find the examples.pri file!" )
3 }
4 TARGET = polarchart
5 SOURCES += main.cpp chartview.cpp
6 HEADERS += chartview.h
@@ -0,0 +1,64
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "declarativepolarchart.h"
22 #include "qchart.h"
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
26 /*!
27 \qmlclass PolarChartView DeclarativePolarChart
28
29 PolarChartView element is the parent that is responsible for showing different chart series types
30 in a polar chart.
31
32 Polar charts support line, spline, area, and scatter series, and all axis types
33 supported by those series.
34
35 \note When setting ticks to an angular ValueAxis, keep in mind that the first and last tick
36 are co-located at 0/360 degree angle.
37
38 \note If the angular distance between two consecutive points in a series is more than 180 degrees,
39 any line connecting the two points becomes meaningless, so choose the axis ranges accordingly
40 when displaying line, spline, or area series.
41
42 \note Polar charts do not support multiple axes of same orientation.
43
44 The following QML shows how to create a polar chart with two series:
45 \snippet ../demos/qmlpolarchart/qml/qmlpolarchart/view1.qml 1
46
47 \beginfloatleft
48 \image demos_qmlpolarchart1.png
49 \endfloat
50 \clearfloat
51 */
52
53 DeclarativePolarChart::DeclarativePolarChart(QDeclarativeItem *parent)
54 : DeclarativeChart(QChart::ChartTypePolar, parent)
55 {
56 }
57
58 DeclarativePolarChart::~DeclarativePolarChart()
59 {
60 }
61
62 #include "moc_declarativepolarchart.cpp"
63
64 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,40
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef DECLARATIVEPOLARCHART_H
22 #define DECLARATIVEPOLARCHART_H
23
24 #include <QtCore/QtGlobal>
25 #include <QtDeclarative/QDeclarativeItem>
26 #include "declarativechart.h"
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 class DeclarativePolarChart : public DeclarativeChart
31 {
32 Q_OBJECT
33 public:
34 DeclarativePolarChart(QDeclarativeItem *parent = 0);
35 ~DeclarativePolarChart();
36 };
37
38 QTCOMMERCIALCHART_END_NAMESPACE
39
40 #endif // DECLARATIVEPOLARCHART_H
@@ -0,0 +1,197
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "cartesianchartaxis_p.h"
22 #include "qabstractaxis.h"
23 #include "qabstractaxis_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractchartlayout_p.h"
26 #include "abstractdomain_p.h"
27 #include "linearrowitem_p.h"
28 #include <QValueAxis>
29 #include <QLogValueAxis>
30 #include <QGraphicsLayout>
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
34 CartesianChartAxis::CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item , bool intervalAxis)
35 : ChartAxisElement(axis, item, intervalAxis)
36 {
37 Q_ASSERT(item);
38 }
39
40
41 CartesianChartAxis::~CartesianChartAxis()
42 {
43 }
44
45 void CartesianChartAxis::createItems(int count)
46 {
47 if (arrowItems().size() == 0) {
48 QGraphicsLineItem *arrow = new LineArrowItem(this, this);
49 arrow->setPen(axis()->linePen());
50 arrowGroup()->addToGroup(arrow);
51 }
52
53 if (intervalAxis() && gridItems().size() == 0) {
54 for (int i = 0 ; i < 2 ; i ++){
55 QGraphicsLineItem *item = new QGraphicsLineItem(this);
56 item->setPen(axis()->gridLinePen());
57 gridGroup()->addToGroup(item);
58 }
59 }
60
61 for (int i = 0; i < count; ++i) {
62 QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
63 QGraphicsLineItem *grid = new QGraphicsLineItem(this);
64 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
65 QGraphicsSimpleTextItem *title = titleItem();
66 arrow->setPen(axis()->linePen());
67 grid->setPen(axis()->gridLinePen());
68 label->setFont(axis()->labelsFont());
69 label->setPen(axis()->labelsPen());
70 label->setBrush(axis()->labelsBrush());
71 label->setRotation(axis()->labelsAngle());
72 title->setFont(axis()->titleFont());
73 title->setPen(axis()->titlePen());
74 title->setBrush(axis()->titleBrush());
75 title->setText(axis()->titleText());
76 arrowGroup()->addToGroup(arrow);
77 gridGroup()->addToGroup(grid);
78 labelGroup()->addToGroup(label);
79
80 if ((gridItems().size()) % 2 && gridItems().size() > 2) {
81 QGraphicsRectItem* shades = new QGraphicsRectItem(this);
82 shades->setPen(axis()->shadesPen());
83 shades->setBrush(axis()->shadesBrush());
84 shadeGroup()->addToGroup(shades);
85 }
86 }
87
88 }
89
90 void CartesianChartAxis::deleteItems(int count)
91 {
92 QList<QGraphicsItem *> lines = gridItems();
93 QList<QGraphicsItem *> labels = labelItems();
94 QList<QGraphicsItem *> shades = shadeItems();
95 QList<QGraphicsItem *> axis = arrowItems();
96
97 for (int i = 0; i < count; ++i) {
98 if (lines.size() % 2 && lines.size() > 1)
99 delete(shades.takeLast());
100 delete(lines.takeLast());
101 delete(labels.takeLast());
102 delete(axis.takeLast());
103 }
104 }
105
106 void CartesianChartAxis::updateLayout(QVector<qreal> &layout)
107 {
108 int diff = ChartAxisElement::layout().size() - layout.size();
109
110 if (diff > 0)
111 deleteItems(diff);
112 else if (diff < 0)
113 createItems(-diff);
114
115 if (animation()) {
116 switch (presenter()->state()) {
117 case ChartPresenter::ZoomInState:
118 animation()->setAnimationType(AxisAnimation::ZoomInAnimation);
119 animation()->setAnimationPoint(presenter()->statePoint());
120 break;
121 case ChartPresenter::ZoomOutState:
122 animation()->setAnimationType(AxisAnimation::ZoomOutAnimation);
123 animation()->setAnimationPoint(presenter()->statePoint());
124 break;
125 case ChartPresenter::ScrollUpState:
126 case ChartPresenter::ScrollLeftState:
127 animation()->setAnimationType(AxisAnimation::MoveBackwordAnimation);
128 break;
129 case ChartPresenter::ScrollDownState:
130 case ChartPresenter::ScrollRightState:
131 animation()->setAnimationType(AxisAnimation::MoveForwardAnimation);
132 break;
133 case ChartPresenter::ShowState:
134 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
135 break;
136 }
137 animation()->setValues(ChartAxisElement::layout(), layout);
138 presenter()->startAnimation(animation());
139 } else {
140 setLayout(layout);
141 updateGeometry();
142 }
143 }
144
145 bool CartesianChartAxis::isEmpty()
146 {
147 return axisGeometry().isEmpty()
148 || gridGeometry().isEmpty()
149 || qFuzzyCompare(min(), max());
150 }
151
152 void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
153 {
154 m_gridRect = grid;
155 setAxisGeometry(axis);
156
157 if (isEmpty())
158 return;
159
160 QVector<qreal> layout = calculateLayout();
161 updateLayout(layout);
162 }
163
164 QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
165 {
166 Q_UNUSED(which);
167 Q_UNUSED(constraint);
168 return QSizeF();
169 }
170
171 void CartesianChartAxis::handleArrowPenChanged(const QPen &pen)
172 {
173 foreach (QGraphicsItem *item, arrowItems())
174 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
175 }
176
177 void CartesianChartAxis::handleGridPenChanged(const QPen &pen)
178 {
179 foreach (QGraphicsItem *item, gridItems())
180 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
181 }
182
183 void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush)
184 {
185 foreach (QGraphicsItem *item, shadeItems())
186 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
187 }
188
189 void CartesianChartAxis::handleShadesPenChanged(const QPen &pen)
190 {
191 foreach (QGraphicsItem *item, shadeItems())
192 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
193 }
194
195 #include "moc_cartesianchartaxis_p.cpp"
196
197 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,79
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef CARTESIANCHARTAXIS_H
31 #define CARTESIANCHARTAXIS_H
32
33 #include "qchartglobal.h"
34 #include "chartaxiselement_p.h"
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class QAbstractAxis;
39
40 class CartesianChartAxis : public ChartAxisElement
41 {
42 Q_OBJECT
43 Q_INTERFACES(QGraphicsLayoutItem)
44 public:
45
46 CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item = 0, bool intervalAxis = false);
47 ~CartesianChartAxis();
48
49 void setGeometry(const QRectF &axis, const QRectF &grid);
50 QRectF gridGeometry() const { return m_gridRect; }
51 bool isEmpty();
52
53 virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
54
55 protected:
56 void setGeometry(const QRectF &size) { Q_UNUSED(size);}
57 virtual void updateGeometry() = 0;
58 void updateLayout(QVector<qreal> &layout);
59
60 public Q_SLOTS:
61 virtual void handleArrowPenChanged(const QPen &pen);
62 virtual void handleGridPenChanged(const QPen &pen);
63 virtual void handleShadesBrushChanged(const QBrush &brush);
64 virtual void handleShadesPenChanged(const QPen &pen);
65
66 private:
67 void createItems(int count);
68 void deleteItems(int count);
69
70 private:
71 QRectF m_gridRect;
72
73 friend class AxisAnimation;
74 friend class LineArrowItem;
75 };
76
77 QTCOMMERCIALCHART_END_NAMESPACE
78
79 #endif /* CARTESIANCHARTAXIS_H */
@@ -0,0 +1,80
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartcategoryaxisangular_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qcategoryaxis.h"
25 #include <QDebug>
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 PolarChartCategoryAxisAngular::PolarChartCategoryAxisAngular(QCategoryAxis *axis, QGraphicsItem *item)
30 : PolarChartAxisAngular(axis, item, true)
31 {
32 QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged()));
33 }
34
35 PolarChartCategoryAxisAngular::~PolarChartCategoryAxisAngular()
36 {
37 }
38
39 QVector<qreal> PolarChartCategoryAxisAngular::calculateLayout() const
40 {
41 QCategoryAxis *catAxis = static_cast<QCategoryAxis *>(axis());
42 int tickCount = catAxis->categoriesLabels().count() + 1;
43 QVector<qreal> points;
44
45 if (tickCount < 2)
46 return points;
47
48 qreal range = max() - min();
49 if (range > 0) {
50 points.resize(tickCount);
51 qreal scale = 360.0 / range;
52 qreal angle;
53 for (int i = 0; i < tickCount; ++i) {
54 if (i < tickCount - 1)
55 angle = (catAxis->startValue(catAxis->categoriesLabels().at(i)) - min()) * scale;
56 else
57 angle = (catAxis->endValue(catAxis->categoriesLabels().at(i - 1)) - min()) * scale;
58 points[i] = angle;
59 }
60 }
61
62 return points;
63 }
64
65 void PolarChartCategoryAxisAngular::createAxisLabels(const QVector<qreal> &layout)
66 {
67 Q_UNUSED(layout);
68 setLabels(static_cast<QCategoryAxis *>(axis())->categoriesLabels() << "");
69 }
70
71 void PolarChartCategoryAxisAngular::handleCategoriesChanged()
72 {
73 QGraphicsLayoutItem::updateGeometry();
74 presenter()->layout()->invalidate();
75 }
76
77
78 #include "moc_polarchartcategoryaxisangular_p.cpp"
79
80 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,56
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTCATEGORYAXISANGULAR_P_H
31 #define POLARCHARTCATEGORYAXISANGULAR_P_H
32
33 #include "polarchartaxisangular_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QCategoryAxis;
38
39 class PolarChartCategoryAxisAngular : public PolarChartAxisAngular
40 {
41 Q_OBJECT
42
43 public:
44 PolarChartCategoryAxisAngular(QCategoryAxis *axis, QGraphicsItem *item);
45 ~PolarChartCategoryAxisAngular();
46
47 virtual QVector<qreal> calculateLayout() const;
48 virtual void createAxisLabels(const QVector<qreal> &layout);
49
50 public Q_SLOTS:
51 void handleCategoriesChanged();
52 };
53
54 QTCOMMERCIALCHART_END_NAMESPACE
55
56 #endif // POLARCHARTCATEGORYAXISANGULAR_P_H
@@ -0,0 +1,79
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartcategoryaxisradial_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qcategoryaxis.h"
25 #include <QDebug>
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 PolarChartCategoryAxisRadial::PolarChartCategoryAxisRadial(QCategoryAxis *axis, QGraphicsItem *item)
30 : PolarChartAxisRadial(axis, item, true)
31 {
32 QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged()));
33 }
34
35 PolarChartCategoryAxisRadial::~PolarChartCategoryAxisRadial()
36 {
37 }
38
39 QVector<qreal> PolarChartCategoryAxisRadial::calculateLayout() const
40 {
41 QCategoryAxis *catAxis = static_cast<QCategoryAxis *>(axis());
42 int tickCount = catAxis->categoriesLabels().count() + 1;
43 QVector<qreal> points;
44
45 if (tickCount < 2)
46 return points;
47
48 qreal range = max() - min();
49 if (range > 0) {
50 points.resize(tickCount);
51 qreal scale = (axisGeometry().width() / 2) / range;
52 qreal angle;
53 for (int i = 0; i < tickCount; ++i) {
54 if (i < tickCount - 1)
55 angle = (catAxis->startValue(catAxis->categoriesLabels().at(i)) - min()) * scale;
56 else
57 angle = (catAxis->endValue(catAxis->categoriesLabels().at(i - 1)) - min()) * scale;
58 points[i] = angle;
59 }
60 }
61
62 return points;
63 }
64
65 void PolarChartCategoryAxisRadial::createAxisLabels(const QVector<qreal> &layout)
66 {
67 Q_UNUSED(layout);
68 setLabels(static_cast<QCategoryAxis *>(axis())->categoriesLabels() << "");
69 }
70
71 void PolarChartCategoryAxisRadial::handleCategoriesChanged()
72 {
73 QGraphicsLayoutItem::updateGeometry();
74 presenter()->layout()->invalidate();
75 }
76
77 #include "moc_polarchartcategoryaxisradial_p.cpp"
78
79 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,56
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTCATEGORYAXISRADIAL_P_H
31 #define POLARCHARTCATEGORYAXISRADIAL_P_H
32
33 #include "polarchartaxisradial_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QCategoryAxis;
38
39 class PolarChartCategoryAxisRadial : public PolarChartAxisRadial
40 {
41 Q_OBJECT
42
43 public:
44 PolarChartCategoryAxisRadial(QCategoryAxis *axis, QGraphicsItem *item);
45 ~PolarChartCategoryAxisRadial();
46
47 virtual QVector<qreal> calculateLayout() const;
48 virtual void createAxisLabels(const QVector<qreal> &layout);
49
50 public Q_SLOTS:
51 void handleCategoriesChanged();
52 };
53
54 QTCOMMERCIALCHART_END_NAMESPACE
55
56 #endif // POLARCHARTCATEGORYAXISRADIAL_P_H
@@ -0,0 +1,349
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "chartaxiselement_p.h"
22 #include "qabstractaxis_p.h"
23 #include "chartpresenter_p.h"
24 #include "abstractchartlayout_p.h"
25 #include <qmath.h>
26 #include <QDateTime>
27 #include <QFontMetrics>
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
32 : ChartElement(item),
33 m_axis(axis),
34 m_animation(0),
35 m_grid(new QGraphicsItemGroup(item)),
36 m_arrow(new QGraphicsItemGroup(item)),
37 m_shades(new QGraphicsItemGroup(item)),
38 m_labels(new QGraphicsItemGroup(item)),
39 m_title(new QGraphicsSimpleTextItem(item)),
40 m_intervalAxis(intervalAxis)
41
42 {
43 //initial initialization
44 m_arrow->setHandlesChildEvents(false);
45 m_arrow->setZValue(ChartPresenter::AxisZValue);
46 m_labels->setZValue(ChartPresenter::AxisZValue);
47 m_shades->setZValue(ChartPresenter::ShadesZValue);
48 m_grid->setZValue(ChartPresenter::GridZValue);
49 m_title->setZValue(ChartPresenter::GridZValue);
50 handleVisibleChanged(axis->isVisible());
51 connectSlots();
52
53 setFlag(QGraphicsItem::ItemHasNoContents, true);
54 }
55
56 ChartAxisElement::~ChartAxisElement()
57 {
58 }
59
60 void ChartAxisElement::connectSlots()
61 {
62 QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool)));
63 QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool)));
64 QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool)));
65 QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
66 QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool)));
67 QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int)));
68 QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&)));
69 QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&)));
70 QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&)));
71 QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&)));
72 QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&)));
73 QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&)));
74 QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&)));
75 QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&)));
76 QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&)));
77 QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&)));
78 QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&)));
79 QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool)));
80 QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal)));
81 }
82
83 void ChartAxisElement::handleArrowVisibleChanged(bool visible)
84 {
85 m_arrow->setVisible(visible);
86 }
87
88 void ChartAxisElement::handleGridVisibleChanged(bool visible)
89 {
90 m_grid->setVisible(visible);
91 }
92
93 void ChartAxisElement::handleLabelsVisibleChanged(bool visible)
94 {
95 QGraphicsLayoutItem::updateGeometry();
96 presenter()->layout()->invalidate();
97 m_labels->setVisible(visible);
98 }
99
100 void ChartAxisElement::handleShadesVisibleChanged(bool visible)
101 {
102 m_shades->setVisible(visible);
103 }
104
105 void ChartAxisElement::handleTitleVisibleChanged(bool visible)
106 {
107 QGraphicsLayoutItem::updateGeometry();
108 presenter()->layout()->invalidate();
109 m_title->setVisible(visible);
110 }
111
112 void ChartAxisElement::handleLabelsAngleChanged(int angle)
113 {
114 foreach (QGraphicsItem *item, m_labels->childItems())
115 item->setRotation(angle);
116
117 QGraphicsLayoutItem::updateGeometry();
118 presenter()->layout()->invalidate();
119 }
120
121 void ChartAxisElement::handleLabelsPenChanged(const QPen &pen)
122 {
123 foreach (QGraphicsItem *item, m_labels->childItems())
124 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
125 }
126
127 void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush)
128 {
129 foreach (QGraphicsItem *item, m_labels->childItems())
130 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
131 }
132
133 void ChartAxisElement::handleLabelsFontChanged(const QFont &font)
134 {
135 foreach (QGraphicsItem *item, m_labels->childItems())
136 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
137 QGraphicsLayoutItem::updateGeometry();
138 presenter()->layout()->invalidate();
139 }
140
141 void ChartAxisElement::handleTitleTextChanged(const QString &title)
142 {
143 QGraphicsLayoutItem::updateGeometry();
144 presenter()->layout()->invalidate();
145 m_title->setText(title);
146 }
147
148 void ChartAxisElement::handleTitlePenChanged(const QPen &pen)
149 {
150 m_title->setPen(pen);
151 }
152
153 void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush)
154 {
155 m_title->setBrush(brush);
156 }
157
158 void ChartAxisElement::handleTitleFontChanged(const QFont &font)
159 {
160 if (m_title->font() != font) {
161 m_title->setFont(font);
162 QGraphicsLayoutItem::updateGeometry();
163 presenter()->layout()->invalidate();
164 }
165 }
166
167 void ChartAxisElement::handleVisibleChanged(bool visible)
168 {
169 setVisible(visible);
170 if (!visible) {
171 m_grid->setVisible(visible);
172 m_arrow->setVisible(visible);
173 m_shades->setVisible(visible);
174 m_labels->setVisible(visible);
175 m_title->setVisible(visible);
176 } else {
177 m_grid->setVisible(axis()->isGridLineVisible());
178 m_arrow->setVisible(axis()->isLineVisible());
179 m_shades->setVisible(axis()->shadesVisible());
180 m_labels->setVisible(axis()->labelsVisible());
181 m_title->setVisible(axis()->isTitleVisible());
182 }
183
184 if (presenter()) presenter()->layout()->invalidate();
185 }
186
187 QRect ChartAxisElement::labelBoundingRect(const QFontMetrics &fn, const QString &label) const
188 {
189 QRect boundingRect = fn.boundingRect(label);
190 // Take label rotation into account
191 if (axis()->labelsAngle()) {
192 QTransform transform;
193 transform.rotate(axis()->labelsAngle());
194 boundingRect = transform.mapRect(boundingRect);
195 }
196
197 return boundingRect;
198 }
199
200 void ChartAxisElement::handleRangeChanged(qreal min, qreal max)
201 {
202 Q_UNUSED(min);
203 Q_UNUSED(max);
204
205 if (!isEmpty()) {
206 QVector<qreal> layout = calculateLayout();
207 updateLayout(layout);
208 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
209 QSizeF after = sizeHint(Qt::PreferredSize);
210
211 if (before != after) {
212 QGraphicsLayoutItem::updateGeometry();
213 // We don't want to call invalidate on layout, since it will change minimum size of
214 // component, which we would like to avoid since it causes nasty flips when scrolling
215 // or zooming, instead recalculate layout and use plotArea for extra space.
216 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
217 }
218 }
219 }
220
221 bool ChartAxisElement::isEmpty()
222 {
223 return axisGeometry().isEmpty()
224 || gridGeometry().isEmpty()
225 || qFuzzyCompare(min(), max());
226 }
227
228 qreal ChartAxisElement::min() const
229 {
230 return m_axis->d_ptr->min();
231 }
232
233 qreal ChartAxisElement::max() const
234 {
235 return m_axis->d_ptr->max();
236 }
237
238 QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format)
239 {
240 QStringList labels;
241
242 if (max <= min || ticks < 1)
243 return labels;
244
245 int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
246 n++;
247
248 if (format.isNull()) {
249 for (int i = 0; i < ticks; i++) {
250 qreal value = min + (i * (max - min) / (ticks - 1));
251 labels << QString::number(value, 'f', n);
252 }
253 } else {
254 QByteArray array = format.toLatin1();
255 for (int i = 0; i < ticks; i++) {
256 qreal value = min + (i * (max - min) / (ticks - 1));
257 if (format.contains("d")
258 || format.contains("i")
259 || format.contains("c")) {
260 labels << QString().sprintf(array, (qint64)value);
261 } else if (format.contains("u")
262 || format.contains("o")
263 || format.contains("x", Qt::CaseInsensitive)) {
264 labels << QString().sprintf(array, (quint64)value);
265 } else if (format.contains("f", Qt::CaseInsensitive)
266 || format.contains("e", Qt::CaseInsensitive)
267 || format.contains("g", Qt::CaseInsensitive)) {
268 labels << QString().sprintf(array, value);
269 } else {
270 labels << QString();
271 }
272 }
273 }
274
275 return labels;
276 }
277
278 QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format)
279 {
280 QStringList labels;
281
282 if (max <= min || ticks < 1)
283 return labels;
284
285 int n = 0;
286 if (ticks > 1)
287 n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
288 n++;
289
290 int firstTick;
291 if (base > 1)
292 firstTick = ceil(log10(min) / log10(base));
293 else
294 firstTick = ceil(log10(max) / log10(base));
295
296 if (format.isNull()) {
297 for (int i = firstTick; i < ticks + firstTick; i++) {
298 qreal value = qPow(base, i);
299 labels << QString::number(value, 'f', n);
300 }
301 } else {
302 QByteArray array = format.toLatin1();
303 for (int i = firstTick; i < ticks + firstTick; i++) {
304 qreal value = qPow(base, i);
305 if (format.contains("d")
306 || format.contains("i")
307 || format.contains("c")) {
308 labels << QString().sprintf(array, (qint64)value);
309 } else if (format.contains("u")
310 || format.contains("o")
311 || format.contains("x", Qt::CaseInsensitive)) {
312 labels << QString().sprintf(array, (quint64)value);
313 } else if (format.contains("f", Qt::CaseInsensitive)
314 || format.contains("e", Qt::CaseInsensitive)
315 || format.contains("g", Qt::CaseInsensitive)) {
316 labels << QString().sprintf(array, value);
317 } else {
318 labels << QString();
319 }
320 }
321 }
322
323 return labels;
324 }
325
326 QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks,const QString &format)
327 {
328 QStringList labels;
329
330 if (max <= min || ticks < 1)
331 return labels;
332
333 int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0);
334 n++;
335 for (int i = 0; i < ticks; i++) {
336 qreal value = min + (i * (max - min) / (ticks - 1));
337 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
338 }
339 return labels;
340 }
341
342 void ChartAxisElement::axisSelected()
343 {
344 emit clicked();
345 }
346
347 #include "moc_chartaxiselement_p.cpp"
348
349 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,80
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartdatetimeaxisangular_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qdatetimeaxis.h"
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 PolarChartDateTimeAxisAngular::PolarChartDateTimeAxisAngular(QDateTimeAxis *axis, QGraphicsItem *item)
29 : PolarChartAxisAngular(axis, item)
30 {
31 QObject::connect(axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int)));
32 QObject::connect(axis, SIGNAL(formatChanged(QString)), this, SLOT(handleFormatChanged(QString)));
33 }
34
35 PolarChartDateTimeAxisAngular::~PolarChartDateTimeAxisAngular()
36 {
37 }
38
39 QVector<qreal> PolarChartDateTimeAxisAngular::calculateLayout() const
40 {
41 int tickCount = static_cast<QDateTimeAxis *>(axis())->tickCount();
42 Q_ASSERT(tickCount >= 2);
43
44 QVector<qreal> points;
45 points.resize(tickCount);
46
47 const qreal d = 360.0 / qreal(tickCount - 1);
48
49 for (int i = 0; i < tickCount; ++i) {
50 qreal angularCoordinate = qreal(i) * d;
51 points[i] = angularCoordinate;
52 }
53
54 return points;
55 }
56 void PolarChartDateTimeAxisAngular::createAxisLabels(const QVector<qreal> &layout)
57 {
58 QStringList labelList = createDateTimeLabels(min(), max(), layout.size(), static_cast<QDateTimeAxis *>(axis())->format());
59 setLabels(labelList);
60 }
61
62 void PolarChartDateTimeAxisAngular::handleTickCountChanged(int tick)
63 {
64 Q_UNUSED(tick);
65 QGraphicsLayoutItem::updateGeometry();
66 if (presenter())
67 presenter()->layout()->invalidate();
68 }
69
70 void PolarChartDateTimeAxisAngular::handleFormatChanged(const QString &format)
71 {
72 Q_UNUSED(format);
73 QGraphicsLayoutItem::updateGeometry();
74 if (presenter())
75 presenter()->layout()->invalidate();
76 }
77
78 #include "moc_polarchartdatetimeaxisangular_p.cpp"
79
80 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,56
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTDATETIMEAXISANGULAR_P_H
31 #define POLARCHARTDATETIMEAXISANGULAR_P_H
32
33 #include "polarchartaxisangular_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QDateTimeAxis;
38
39 class PolarChartDateTimeAxisAngular : public PolarChartAxisAngular
40 {
41 Q_OBJECT
42 public:
43 PolarChartDateTimeAxisAngular(QDateTimeAxis *axis, QGraphicsItem *item);
44 ~PolarChartDateTimeAxisAngular();
45
46 virtual QVector<qreal> calculateLayout() const;
47 virtual void createAxisLabels(const QVector<qreal> &layout);
48
49 private Q_SLOTS:
50 void handleTickCountChanged(int tick);
51 void handleFormatChanged(const QString &format);
52 };
53
54 QTCOMMERCIALCHART_END_NAMESPACE
55
56 #endif // POLARCHARTDATETIMEAXISANGULAR_P_H
@@ -0,0 +1,79
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartdatetimeaxisradial_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qdatetimeaxis.h"
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 PolarChartDateTimeAxisRadial::PolarChartDateTimeAxisRadial(QDateTimeAxis *axis, QGraphicsItem *item)
29 : PolarChartAxisRadial(axis, item)
30 {
31 QObject::connect(axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int)));
32 QObject::connect(axis, SIGNAL(formatChanged(QString)), this, SLOT(handleFormatChanged(QString)));
33 }
34
35 PolarChartDateTimeAxisRadial::~PolarChartDateTimeAxisRadial()
36 {
37 }
38
39 QVector<qreal> PolarChartDateTimeAxisRadial::calculateLayout() const
40 {
41 int tickCount = static_cast<QDateTimeAxis *>(axis())->tickCount();
42 Q_ASSERT(tickCount >= 2);
43
44 QVector<qreal> points;
45 points.resize(tickCount);
46
47 const qreal d = (axisGeometry().width() / 2) / qreal(tickCount - 1);
48
49 for (int i = 0; i < tickCount; ++i) {
50 qreal radialCoordinate = qreal(i) * d;
51 points[i] = radialCoordinate;
52 }
53
54 return points;
55 }
56 void PolarChartDateTimeAxisRadial::createAxisLabels(const QVector<qreal> &layout)
57 {
58 setLabels(createDateTimeLabels(min(), max(), layout.size(), static_cast<QDateTimeAxis *>(axis())->format()));
59 }
60
61 void PolarChartDateTimeAxisRadial::handleTickCountChanged(int tick)
62 {
63 Q_UNUSED(tick);
64 QGraphicsLayoutItem::updateGeometry();
65 if (presenter())
66 presenter()->layout()->invalidate();
67 }
68
69 void PolarChartDateTimeAxisRadial::handleFormatChanged(const QString &format)
70 {
71 Q_UNUSED(format);
72 QGraphicsLayoutItem::updateGeometry();
73 if (presenter())
74 presenter()->layout()->invalidate();
75 }
76
77 #include "moc_polarchartdatetimeaxisradial_p.cpp"
78
79 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,56
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTDATETIMEAXISRADIAL_P_H
31 #define POLARCHARTDATETIMEAXISRADIAL_P_H
32
33 #include "polarchartaxisradial_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QDateTimeAxis;
38
39 class PolarChartDateTimeAxisRadial : public PolarChartAxisRadial
40 {
41 Q_OBJECT
42 public:
43 PolarChartDateTimeAxisRadial(QDateTimeAxis *axis, QGraphicsItem *item);
44 ~PolarChartDateTimeAxisRadial();
45
46 virtual QVector<qreal> calculateLayout() const;
47 virtual void createAxisLabels(const QVector<qreal> &layout);
48
49 private Q_SLOTS:
50 void handleTickCountChanged(int tick);
51 void handleFormatChanged(const QString &format);
52 };
53
54 QTCOMMERCIALCHART_END_NAMESPACE
55
56 #endif // POLARCHARTDATETIMEAXISRADIAL_P_H
@@ -0,0 +1,76
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef LINEARROWITEM_P_H
31 #define LINEARROWITEM_P_H
32
33 #include "chartaxiselement_p.h"
34 #include "qabstractaxis_p.h"
35 #include <QGraphicsLineItem>
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
39 class LineArrowItem: public QGraphicsLineItem
40 {
41 public:
42 explicit LineArrowItem(ChartAxisElement *axis, QGraphicsItem *parent = 0)
43 : QGraphicsLineItem(parent),
44 m_axis(axis),
45 m_axisOrientation(axis->axis()->orientation())
46 {
47 }
48
49 protected:
50 void mousePressEvent(QGraphicsSceneMouseEvent *event)
51 {
52 Q_UNUSED(event)
53 m_axis->axisSelected();
54 }
55
56 QRectF boundingRect() const
57 {
58 return shape().boundingRect();
59 }
60
61 QPainterPath shape() const
62 {
63 QPainterPath path = QGraphicsLineItem::shape();
64 QRectF rect = path.boundingRect();
65 path.addRect(rect.adjusted(0, 0, m_axisOrientation != Qt::Horizontal ? 8 : 0, m_axisOrientation != Qt::Vertical ? 8 : 0));
66 return path;
67 }
68
69 private:
70 ChartAxisElement *m_axis;
71 Qt::Orientation m_axisOrientation;
72 };
73
74 QTCOMMERCIALCHART_END_NAMESPACE
75
76 #endif /* LINEARROWITEM_P_H */
@@ -0,0 +1,90
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartlogvalueaxisangular_p.h"
22 #include "abstractchartlayout_p.h"
23 #include "chartpresenter_p.h"
24 #include "qlogvalueaxis.h"
25 #include <qmath.h>
26 #include <QDebug>
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 PolarChartLogValueAxisAngular::PolarChartLogValueAxisAngular(QLogValueAxis *axis, QGraphicsItem *item)
31 : PolarChartAxisAngular(axis, item)
32 {
33 QObject::connect(axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal)));
34 QObject::connect(axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
35 }
36
37 PolarChartLogValueAxisAngular::~PolarChartLogValueAxisAngular()
38 {
39 }
40
41 QVector<qreal> PolarChartLogValueAxisAngular::calculateLayout() const
42 {
43 QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
44 const qreal logMax = log10(logValueAxis->max()) / log10(logValueAxis->base());
45 const qreal logMin = log10(logValueAxis->min()) / log10(logValueAxis->base());
46 const qreal startEdge = logMin < logMax ? logMin : logMax;
47 const qreal delta = 360.0 / qAbs(logMax - logMin);
48 const qreal initialSpan = (ceil(startEdge) - startEdge) * delta;
49 int tickCount = qAbs(ceil(logMax) - ceil(logMin));
50
51 QVector<qreal> points;
52 points.resize(tickCount);
53
54 for (int i = 0; i < tickCount; ++i) {
55 qreal angularCoordinate = initialSpan + (delta * qreal(i));
56 points[i] = angularCoordinate;
57 }
58
59 return points;
60 }
61
62 void PolarChartLogValueAxisAngular::createAxisLabels(const QVector<qreal> &layout)
63 {
64 QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
65 setLabels(createLogValueLabels(logValueAxis->min(),
66 logValueAxis->max(),
67 logValueAxis->base(),
68 layout.size(),
69 logValueAxis->labelFormat()));
70 }
71
72 void PolarChartLogValueAxisAngular::handleBaseChanged(qreal base)
73 {
74 Q_UNUSED(base);
75 QGraphicsLayoutItem::updateGeometry();
76 if (presenter())
77 presenter()->layout()->invalidate();
78 }
79
80 void PolarChartLogValueAxisAngular::handleLabelFormatChanged(const QString &format)
81 {
82 Q_UNUSED(format);
83 QGraphicsLayoutItem::updateGeometry();
84 if (presenter())
85 presenter()->layout()->invalidate();
86 }
87
88 #include "moc_polarchartlogvalueaxisangular_p.cpp"
89
90 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,57
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTLOGVALUEAXISANGULAR_P_H
31 #define POLARCHARTLOGVALUEAXISANGULAR_P_H
32
33 #include "polarchartaxisangular_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QLogValueAxis;
38
39 class PolarChartLogValueAxisAngular : public PolarChartAxisAngular
40 {
41 Q_OBJECT
42 public:
43 PolarChartLogValueAxisAngular(QLogValueAxis *axis, QGraphicsItem *item);
44 ~PolarChartLogValueAxisAngular();
45
46 protected:
47 virtual QVector<qreal> calculateLayout() const;
48 virtual void createAxisLabels(const QVector<qreal> &layout);
49
50 private Q_SLOTS:
51 void handleBaseChanged(qreal base);
52 void handleLabelFormatChanged(const QString &format);
53 };
54
55 QTCOMMERCIALCHART_END_NAMESPACE
56
57 #endif // POLARCHARTLOGVALUEAXISANGULAR_P_H
@@ -0,0 +1,95
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartlogvalueaxisradial_p.h"
22 #include "abstractchartlayout_p.h"
23 #include "chartpresenter_p.h"
24 #include "qlogvalueaxis.h"
25 #include <qmath.h>
26 #include <QDebug>
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 PolarChartLogValueAxisRadial::PolarChartLogValueAxisRadial(QLogValueAxis *axis, QGraphicsItem *item)
31 : PolarChartAxisRadial(axis, item)
32 {
33 QObject::connect(axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal)));
34 QObject::connect(axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
35 }
36
37 PolarChartLogValueAxisRadial::~PolarChartLogValueAxisRadial()
38 {
39 }
40
41 QVector<qreal> PolarChartLogValueAxisRadial::calculateLayout() const
42 {
43 QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
44 const qreal logMax = log10(logValueAxis->max()) / log10(logValueAxis->base());
45 const qreal logMin = log10(logValueAxis->min()) / log10(logValueAxis->base());
46 const qreal innerEdge = logMin < logMax ? logMin : logMax;
47 const qreal outerEdge = logMin > logMax ? logMin : logMax;
48 const qreal delta = (axisGeometry().width() / 2.0) / qAbs(logMax - logMin);
49 const qreal initialSpan = (ceil(innerEdge) - innerEdge) * delta;
50 int tickCount = qAbs(ceil(logMax) - ceil(logMin));
51
52 // Extra tick if outer edge is exactly at the tick
53 if (outerEdge == ceil(outerEdge))
54 tickCount++;
55
56 QVector<qreal> points;
57 points.resize(tickCount);
58
59 for (int i = 0; i < tickCount; ++i) {
60 qreal radialCoordinate = initialSpan + (delta * qreal(i));
61 points[i] = radialCoordinate;
62 }
63
64 return points;
65 }
66
67 void PolarChartLogValueAxisRadial::createAxisLabels(const QVector<qreal> &layout)
68 {
69 QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
70 setLabels(createLogValueLabels(logValueAxis->min(),
71 logValueAxis->max(),
72 logValueAxis->base(),
73 layout.size(),
74 logValueAxis->labelFormat()));
75 }
76
77 void PolarChartLogValueAxisRadial::handleBaseChanged(qreal base)
78 {
79 Q_UNUSED(base);
80 QGraphicsLayoutItem::updateGeometry();
81 if (presenter())
82 presenter()->layout()->invalidate();
83 }
84
85 void PolarChartLogValueAxisRadial::handleLabelFormatChanged(const QString &format)
86 {
87 Q_UNUSED(format);
88 QGraphicsLayoutItem::updateGeometry();
89 if (presenter())
90 presenter()->layout()->invalidate();
91 }
92
93 #include "moc_polarchartlogvalueaxisradial_p.cpp"
94
95 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,57
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTLOGVALUEAXISRADIAL_P_H
31 #define POLARCHARTLOGVALUEAXISRADIAL_P_H
32
33 #include "polarchartaxisradial_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QLogValueAxis;
38
39 class PolarChartLogValueAxisRadial : public PolarChartAxisRadial
40 {
41 Q_OBJECT
42 public:
43 PolarChartLogValueAxisRadial(QLogValueAxis *axis, QGraphicsItem *item);
44 ~PolarChartLogValueAxisRadial();
45
46 protected:
47 virtual QVector<qreal> calculateLayout() const;
48 virtual void createAxisLabels(const QVector<qreal> &layout);
49
50 private Q_SLOTS:
51 void handleBaseChanged(qreal base);
52 void handleLabelFormatChanged(const QString &format);
53 };
54
55 QTCOMMERCIALCHART_END_NAMESPACE
56
57 #endif // POLARCHARTLOGVALUEAXISRADIAL_P_H
@@ -0,0 +1,120
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartaxis_p.h"
22 #include "qabstractaxis_p.h"
23 #include "chartpresenter_p.h"
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 PolarChartAxis::PolarChartAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
28 : ChartAxisElement(axis, item, intervalAxis)
29 {
30 }
31
32 PolarChartAxis::~PolarChartAxis()
33 {
34
35 }
36
37 void PolarChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
38 {
39 Q_UNUSED(grid);
40 setAxisGeometry(axis);
41
42 if (isEmpty())
43 return;
44
45 QVector<qreal> layout = calculateLayout();
46 updateLayout(layout);
47 }
48
49 QRectF PolarChartAxis::gridGeometry() const
50 {
51 return QRectF();
52 }
53
54 void PolarChartAxis::updateLayout(QVector<qreal> &layout)
55 {
56 int diff = ChartAxisElement::layout().size() - layout.size();
57
58 if (animation()) {
59 switch (presenter()->state()) {
60 case ChartPresenter::ShowState:
61 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
62 break;
63 }
64 // Update to "old" geometry before starting animation to avoid incorrectly sized
65 // axes lingering in wrong position compared to series plot before animation can kick in.
66 // Note that the position mismatch still exists even with this update, but it will be
67 // far less ugly.
68 updateGeometry();
69 }
70
71 if (diff > 0)
72 deleteItems(diff);
73 else if (diff < 0)
74 createItems(-diff);
75
76 if (animation()) {
77 animation()->setValues(ChartAxisElement::layout(), layout);
78 presenter()->startAnimation(animation());
79 } else {
80 setLayout(layout);
81 updateGeometry();
82 }
83 }
84
85 bool PolarChartAxis::isEmpty()
86 {
87 return !axisGeometry().isValid() || qFuzzyIsNull(min() - max());
88 }
89
90 void PolarChartAxis::deleteItems(int count)
91 {
92 QList<QGraphicsItem *> gridLines = gridItems();
93 QList<QGraphicsItem *> labels = labelItems();
94 QList<QGraphicsItem *> shades = shadeItems();
95 QList<QGraphicsItem *> axis = arrowItems();
96
97 for (int i = 0; i < count; ++i) {
98 if (gridItems().size() == 1 || (((gridLines.size() + 1) % 2) && gridLines.size() > 0))
99 delete(shades.takeLast());
100 delete(gridLines.takeLast());
101 delete(labels.takeLast());
102 delete(axis.takeLast());
103 }
104 }
105
106 void PolarChartAxis::handleShadesBrushChanged(const QBrush &brush)
107 {
108 foreach (QGraphicsItem *item, shadeItems())
109 static_cast<QGraphicsPathItem *>(item)->setBrush(brush);
110 }
111
112 void PolarChartAxis::handleShadesPenChanged(const QPen &pen)
113 {
114 foreach (QGraphicsItem *item, shadeItems())
115 static_cast<QGraphicsPathItem *>(item)->setPen(pen);
116 }
117
118 #include "moc_polarchartaxis_p.cpp"
119
120 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,70
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTAXIS_P_H
31 #define POLARCHARTAXIS_P_H
32
33 #include "chartaxiselement_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class PolarChartAxis : public ChartAxisElement
38 {
39 Q_OBJECT
40 Q_INTERFACES(QGraphicsLayoutItem)
41 public:
42 PolarChartAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false);
43 ~PolarChartAxis();
44
45 void setGeometry(const QRectF &axis, const QRectF &grid);
46 virtual qreal preferredAxisRadius(const QSizeF &maxSize) = 0;
47 int tickWidth() { return 3; }
48
49 public: // from ChartAxisElement
50 QRectF gridGeometry() const;
51 bool isEmpty();
52
53 protected:
54 void updateLayout(QVector<qreal> &layout);
55
56 protected: // virtual functions
57 virtual void createItems(int count) = 0;
58 virtual void createAxisLabels(const QVector<qreal> &layout) = 0;
59
60 public Q_SLOTS:
61 virtual void handleShadesBrushChanged(const QBrush &brush);
62 virtual void handleShadesPenChanged(const QPen &pen);
63
64 private:
65 void deleteItems(int count);
66 };
67
68 QTCOMMERCIALCHART_END_NAMESPACE
69
70 #endif // POLARCHARTAXIS_P_H
@@ -0,0 +1,428
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartaxisangular_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qabstractaxis.h"
25 #include "qabstractaxis_p.h"
26 #include <QFontMetrics>
27 #include <QDebug>
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31 PolarChartAxisAngular::PolarChartAxisAngular(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
32 : PolarChartAxis(axis, item, intervalAxis)
33 {
34 }
35
36 PolarChartAxisAngular::~PolarChartAxisAngular()
37 {
38 }
39
40 void PolarChartAxisAngular::updateGeometry()
41 {
42 QGraphicsLayoutItem::updateGeometry();
43
44 const QVector<qreal> &layout = this->layout();
45 if (layout.isEmpty())
46 return;
47
48 createAxisLabels(layout);
49 QStringList labelList = labels();
50 QPointF center = axisGeometry().center();
51 QList<QGraphicsItem *> arrowItemList = arrowItems();
52 QList<QGraphicsItem *> gridItemList = gridItems();
53 QList<QGraphicsItem *> labelItemList = labelItems();
54 QList<QGraphicsItem *> shadeItemList = shadeItems();
55 QGraphicsSimpleTextItem *title = titleItem();
56
57 QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0));
58 axisLine->setRect(axisGeometry());
59
60 qreal radius = axisGeometry().height() / 2.0;
61
62 QFontMetrics fn(axis()->labelsFont());
63 QRectF previousLabelRect;
64 QRectF firstLabelRect;
65
66 qreal labelHeight = 0;
67
68 bool firstShade = true;
69 bool nextTickVisible = false;
70 if (layout.size())
71 nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > 360.0);
72
73 for (int i = 0; i < layout.size(); ++i) {
74 qreal angularCoordinate = layout.at(i);
75
76 QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i));
77 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
78 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labelItemList.at(i));
79 QGraphicsPathItem *shadeItem = 0;
80 if (i == 0)
81 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
82 else if (i % 2)
83 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1));
84
85 // Ignore ticks outside valid range
86 bool currentTickVisible = nextTickVisible;
87 if ((i == layout.size() - 1)
88 || layout.at(i + 1) < 0.0
89 || layout.at(i + 1) > 360.0) {
90 nextTickVisible = false;
91 } else {
92 nextTickVisible = true;
93 }
94
95 qreal labelCoordinate = angularCoordinate;
96 qreal labelVisible = currentTickVisible;
97 if (intervalAxis()) {
98 qreal farEdge;
99 if (i == (layout.size() - 1))
100 farEdge = 360.0;
101 else
102 farEdge = qMin(360.0, layout.at(i + 1));
103
104 // Adjust the labelCoordinate to show it if next tick is visible
105 if (nextTickVisible)
106 labelCoordinate = qMax(0.0, labelCoordinate);
107
108 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
109 // Don't display label once the category gets too small near the axis
110 if (labelCoordinate < 5.0 || labelCoordinate > 355.0)
111 labelVisible = false;
112 else
113 labelVisible = true;
114 }
115
116 // Need this also in label calculations, so determine it first
117 QLineF tickLine(QLineF::fromPolar(radius - tickWidth(), 90.0 - angularCoordinate).p2(),
118 QLineF::fromPolar(radius + tickWidth(), 90.0 - angularCoordinate).p2());
119 tickLine.translate(center);
120
121 // Angular axis label
122 if (axis()->labelsVisible() && labelVisible) {
123 labelItem->setText(labelList.at(i));
124 const QRectF &rect = labelItem->boundingRect();
125 QPointF labelCenter = rect.center();
126 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
127 QRectF boundingRect = labelBoundingRect(fn, labelList.at(i));
128 boundingRect.moveCenter(labelCenter);
129 QPointF positionDiff(rect.topLeft() - boundingRect.topLeft());
130
131 QPointF labelPoint;
132 if (intervalAxis()) {
133 QLineF labelLine = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate);
134 labelLine.translate(center);
135 labelPoint = labelLine.p2();
136 } else {
137 labelPoint = tickLine.p2();
138 }
139
140 QRectF labelRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
141 labelItem->setPos(labelRect.topLeft() + positionDiff);
142
143 // Store height for title calculations
144 qreal labelClearance = axisGeometry().top() - labelRect.top();
145 labelHeight = qMax(labelHeight, labelClearance);
146
147 // Label overlap detection
148 if (i && (previousLabelRect.intersects(labelRect) || firstLabelRect.intersects(labelRect))) {
149 labelVisible = false;
150 } else {
151 // Store labelRect for future comparison. Some area is deducted to make things look
152 // little nicer, as usually intersection happens at label corner with angular labels.
153 labelRect.adjust(-2.0, -4.0, -2.0, -4.0);
154 if (firstLabelRect.isEmpty())
155 firstLabelRect = labelRect;
156
157 previousLabelRect = labelRect;
158 labelVisible = true;
159 }
160 }
161
162 labelItem->setVisible(labelVisible);
163 if (!currentTickVisible) {
164 gridLineItem->setVisible(false);
165 tickItem->setVisible(false);
166 if (shadeItem)
167 shadeItem->setVisible(false);
168 continue;
169 }
170
171 // Angular grid line
172 QLineF gridLine = QLineF::fromPolar(radius, 90.0 - angularCoordinate);
173 gridLine.translate(center);
174 gridLineItem->setLine(gridLine);
175 gridLineItem->setVisible(true);
176
177 // Tick
178 tickItem->setLine(tickLine);
179 tickItem->setVisible(true);
180
181 // Shades
182 if (i % 2 || (i == 0 && !nextTickVisible)) {
183 QPainterPath path;
184 path.moveTo(center);
185 if (i == 0) {
186 // If first tick is also the last, we need to custom fill the first partial arc
187 // or it won't get filled.
188 path.arcTo(axisGeometry(), 90.0 - layout.at(0), layout.at(0));
189 path.closeSubpath();
190 } else {
191 qreal nextCoordinate;
192 if (!nextTickVisible) // Last visible tick
193 nextCoordinate = 360.0;
194 else
195 nextCoordinate = layout.at(i + 1);
196 qreal arcSpan = angularCoordinate - nextCoordinate;
197 path.arcTo(axisGeometry(), 90.0 - angularCoordinate, arcSpan);
198 path.closeSubpath();
199
200 // Add additional arc for first shade item if there is a partial arc to be filled
201 if (firstShade) {
202 QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
203 if (layout.at(i - 1) > 0.0) {
204 QPainterPath specialPath;
205 specialPath.moveTo(center);
206 specialPath.arcTo(axisGeometry(), 90.0 - layout.at(i - 1), layout.at(i - 1));
207 specialPath.closeSubpath();
208 specialShadeItem->setPath(specialPath);
209 specialShadeItem->setVisible(true);
210 } else {
211 specialShadeItem->setVisible(false);
212 }
213 }
214 }
215 shadeItem->setPath(path);
216 shadeItem->setVisible(true);
217 firstShade = false;
218 }
219 }
220
221 // Title, centered above the chart
222 QString titleText = axis()->titleText();
223 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
224 int size(0);
225 size = axisGeometry().width();
226
227 QFontMetrics titleMetrics(axis()->titleFont());
228 if (titleMetrics.boundingRect(titleText).width() > size) {
229 QString string = titleText + "...";
230 while (titleMetrics.boundingRect(string).width() > size && string.length() > 3)
231 string.remove(string.length() - 4, 1);
232 title->setText(string);
233 } else {
234 title->setText(titleText);
235 }
236
237 QRectF titleBoundingRect;
238 titleBoundingRect = title->boundingRect();
239 QPointF titleCenter = center - titleBoundingRect.center();
240 title->setPos(titleCenter.x(), axisGeometry().top() - qreal(titlePadding()) * 2.0 - titleBoundingRect.height() - labelHeight);
241 }
242 }
243
244 Qt::Orientation PolarChartAxisAngular::orientation() const
245 {
246 return Qt::Horizontal;
247 }
248
249 void PolarChartAxisAngular::createItems(int count)
250 {
251 if (arrowItems().count() == 0) {
252 // angular axis line
253 // TODO: need class similar to LineArrowItem for click handling?
254 QGraphicsEllipseItem *arrow = new QGraphicsEllipseItem(presenter()->rootItem());
255 arrow->setPen(axis()->linePen());
256 arrowGroup()->addToGroup(arrow);
257 }
258
259 for (int i = 0; i < count; ++i) {
260 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
261 QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem());
262 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
263 QGraphicsSimpleTextItem *title = titleItem();
264 arrow->setPen(axis()->linePen());
265 grid->setPen(axis()->gridLinePen());
266 label->setFont(axis()->labelsFont());
267 label->setPen(axis()->labelsPen());
268 label->setBrush(axis()->labelsBrush());
269 label->setRotation(axis()->labelsAngle());
270 title->setFont(axis()->titleFont());
271 title->setPen(axis()->titlePen());
272 title->setBrush(axis()->titleBrush());
273 title->setText(axis()->titleText());
274 arrowGroup()->addToGroup(arrow);
275 gridGroup()->addToGroup(grid);
276 labelGroup()->addToGroup(label);
277 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
278 QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem());
279 shade->setPen(axis()->shadesPen());
280 shade->setBrush(axis()->shadesBrush());
281 shadeGroup()->addToGroup(shade);
282 }
283 }
284 }
285
286 void PolarChartAxisAngular::handleArrowPenChanged(const QPen &pen)
287 {
288 bool first = true;
289 foreach (QGraphicsItem *item, arrowItems()) {
290 if (first) {
291 first = false;
292 // First arrow item is the outer circle of axis
293 static_cast<QGraphicsEllipseItem *>(item)->setPen(pen);
294 } else {
295 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
296 }
297 }
298 }
299
300 void PolarChartAxisAngular::handleGridPenChanged(const QPen &pen)
301 {
302 foreach (QGraphicsItem *item, gridItems())
303 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
304 }
305
306 QSizeF PolarChartAxisAngular::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
307 {
308 Q_UNUSED(which);
309 Q_UNUSED(constraint);
310 return QSizeF(-1, -1);
311 }
312
313 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize)
314 {
315 qreal radius = maxSize.height() / 2.0;
316 if (maxSize.width() < maxSize.height())
317 radius = maxSize.width() / 2.0;
318
319 int labelHeight = 0;
320
321 if (axis()->labelsVisible()) {
322 QVector<qreal> layout = calculateLayout();
323 if (layout.isEmpty())
324 return radius;
325
326 createAxisLabels(layout);
327 QStringList labelList = labels();
328 QFont font = axis()->labelsFont();
329
330 QRectF maxRect;
331 maxRect.setSize(maxSize);
332 maxRect.moveCenter(QPointF(0.0, 0.0));
333
334 // This is a horrible way to find out the maximum radius for angular axis and its labels.
335 // It just increments the radius down until everyhing fits the constraint size.
336 // Proper way would be to actually calculate it but this seems to work reasonably fast as it is.
337 QFontMetrics fm(font);
338 bool nextTickVisible = false;
339 for (int i = 0; i < layout.size(); ) {
340 if ((i == layout.size() - 1)
341 || layout.at(i + 1) < 0.0
342 || layout.at(i + 1) > 360.0) {
343 nextTickVisible = false;
344 } else {
345 nextTickVisible = true;
346 }
347
348 qreal labelCoordinate = layout.at(i);
349 qreal labelVisible;
350
351 if (intervalAxis()) {
352 qreal farEdge;
353 if (i == (layout.size() - 1))
354 farEdge = 360.0;
355 else
356 farEdge = qMin(360.0, layout.at(i + 1));
357
358 // Adjust the labelCoordinate to show it if next tick is visible
359 if (nextTickVisible)
360 labelCoordinate = qMax(0.0, labelCoordinate);
361
362 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
363 }
364
365 if (labelCoordinate < 0.0 || labelCoordinate > 360.0)
366 labelVisible = false;
367 else
368 labelVisible = true;
369
370 if (!labelVisible) {
371 i++;
372 continue;
373 }
374
375 QRectF boundingRect = labelBoundingRect(fm, labelList.at(i));
376 labelHeight = boundingRect.height();
377 QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2();
378
379 boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
380 if (boundingRect.isEmpty() || maxRect.intersected(boundingRect) == boundingRect) {
381 i++;
382 } else {
383 radius -= 1.0;
384 if (radius < 1.0) // safeguard
385 return 1.0;
386 }
387 }
388 }
389
390 if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) {
391 QFontMetrics titleMetrics(axis()->titleFont());
392 int titleHeight = titleMetrics.boundingRect(axis()->titleText()).height();
393 radius -= titlePadding() + (titleHeight / 2);
394 if (radius < 1.0) // safeguard
395 return 1.0;
396 }
397
398 return radius;
399 }
400
401 QRectF PolarChartAxisAngular::moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const
402 {
403 // TODO use fuzzy compare for "==" cases?
404 // TODO Adjust the rect position near 0, 90, 180, and 270 angles for smoother animation?
405 if (angularCoordinate == 0.0)
406 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
407 else if (angularCoordinate < 90.0)
408 labelRect.moveBottomLeft(labelPoint);
409 else if (angularCoordinate == 90.0)
410 labelRect.moveCenter(labelPoint + QPointF(labelRect.width() / 2.0 + 2.0, 0)); // +2 so that it does not hit the radial axis
411 else if (angularCoordinate < 180.0)
412 labelRect.moveTopLeft(labelPoint);
413 else if (angularCoordinate == 180.0)
414 labelRect.moveCenter(labelPoint + QPointF(0, labelRect.height() / 2.0));
415 else if (angularCoordinate < 270.0)
416 labelRect.moveTopRight(labelPoint);
417 else if (angularCoordinate == 270.0)
418 labelRect.moveCenter(labelPoint + QPointF(-labelRect.width() / 2.0 - 2.0, 0)); // -2 so that it does not hit the radial axis
419 else if (angularCoordinate < 360.0)
420 labelRect.moveBottomRight(labelPoint);
421 else
422 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
423 return labelRect;
424 }
425
426 #include "moc_polarchartaxisangular_p.cpp"
427
428 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,63
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTAXISANGULAR_P_H
31 #define POLARCHARTAXISANGULAR_P_H
32
33 #include "polarchartaxis_p.h"
34 #include "qvalueaxis.h"
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class PolarChartAxisAngular : public PolarChartAxis
39 {
40 Q_OBJECT
41 public:
42 PolarChartAxisAngular(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false);
43 ~PolarChartAxisAngular();
44
45 Qt::Orientation orientation() const;
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
47
48 virtual void updateGeometry();
49 virtual void createItems(int count);
50
51 qreal preferredAxisRadius(const QSizeF &maxSize);
52
53 public Q_SLOTS:
54 virtual void handleArrowPenChanged(const QPen &pen);
55 virtual void handleGridPenChanged(const QPen &pen);
56
57 private:
58 QRectF moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const;
59 };
60
61 QTCOMMERCIALCHART_END_NAMESPACE
62
63 #endif // POLARCHARTAXISANGULAR_P_H
@@ -0,0 +1,301
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartaxisradial_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qabstractaxis_p.h"
25 #include "linearrowitem_p.h"
26 #include <QFontMetrics>
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 PolarChartAxisRadial::PolarChartAxisRadial(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
31 : PolarChartAxis(axis, item, intervalAxis)
32 {
33 }
34
35 PolarChartAxisRadial::~PolarChartAxisRadial()
36 {
37 }
38
39 void PolarChartAxisRadial::updateGeometry()
40 {
41 const QVector<qreal> &layout = this->layout();
42 if (layout.isEmpty())
43 return;
44
45 createAxisLabels(layout);
46 QStringList labelList = labels();
47 QPointF center = axisGeometry().center();
48 QList<QGraphicsItem *> arrowItemList = arrowItems();
49 QList<QGraphicsItem *> gridItemList = gridItems();
50 QList<QGraphicsItem *> labelItemList = labelItems();
51 QList<QGraphicsItem *> shadeItemList = shadeItems();
52 QGraphicsSimpleTextItem* title = titleItem();
53 qreal radius = axisGeometry().height() / 2.0;
54
55 QLineF line(center, center + QPointF(0, -radius));
56 QGraphicsLineItem *axisLine = static_cast<QGraphicsLineItem *>(arrowItemList.at(0));
57 axisLine->setLine(line);
58
59 QFontMetrics fn(axis()->labelsFont());
60 QRectF previousLabelRect;
61 bool firstShade = true;
62 bool nextTickVisible = false;
63 if (layout.size())
64 nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > radius);
65
66 for (int i = 0; i < layout.size(); ++i) {
67 qreal radialCoordinate = layout.at(i);
68
69 QGraphicsEllipseItem *gridItem = static_cast<QGraphicsEllipseItem *>(gridItemList.at(i));
70 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
71 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labelItemList.at(i));
72 QGraphicsPathItem *shadeItem = 0;
73 if (i == 0)
74 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
75 else if (i % 2)
76 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1));
77
78 // Ignore ticks outside valid range
79 bool currentTickVisible = nextTickVisible;
80 if ((i == layout.size() - 1)
81 || layout.at(i + 1) < 0.0
82 || layout.at(i + 1) > radius) {
83 nextTickVisible = false;
84 } else {
85 nextTickVisible = true;
86 }
87
88 qreal labelCoordinate = radialCoordinate;
89 qreal labelVisible = currentTickVisible;
90 qreal labelPad = labelPadding() / 2.0;
91 if (intervalAxis()) {
92 qreal farEdge;
93 if (i == (layout.size() - 1))
94 farEdge = radius;
95 else
96 farEdge = qMin(radius, layout.at(i + 1));
97
98 // Adjust the labelCoordinate to show it if next tick is visible
99 if (nextTickVisible)
100 labelCoordinate = qMax(0.0, labelCoordinate);
101
102 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
103 if (labelCoordinate > 0.0 && labelCoordinate < radius)
104 labelVisible = true;
105 else
106 labelVisible = false;
107 }
108
109 // Radial axis label
110 if (axis()->labelsVisible() && labelVisible) {
111 labelItem->setText(labelList.at(i));
112 QRectF labelRect = labelItem->boundingRect();
113 QPointF labelCenter = labelRect.center();
114 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
115 QRectF boundingRect = labelBoundingRect(fn, labelList.at(i));
116 boundingRect.moveCenter(labelCenter);
117 QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft());
118 QPointF labelPoint = center;
119 if (intervalAxis())
120 labelPoint += QPointF(labelPad, -labelCoordinate - (boundingRect.height() / 2.0));
121 else
122 labelPoint += QPointF(labelPad, labelPad - labelCoordinate);
123 labelRect.moveTopLeft(labelPoint);
124 labelItem->setPos(labelRect.topLeft() + positionDiff);
125
126 // Label overlap detection
127 labelRect.setSize(boundingRect.size());
128 if ((i && previousLabelRect.intersects(labelRect))
129 || !axisGeometry().contains(labelRect)) {
130 labelVisible = false;
131 } else {
132 previousLabelRect = labelRect;
133 labelVisible = true;
134 }
135 }
136
137 labelItem->setVisible(labelVisible);
138 if (!currentTickVisible) {
139 gridItem->setVisible(false);
140 tickItem->setVisible(false);
141 if (shadeItem)
142 shadeItem->setVisible(false);
143 continue;
144 }
145
146 // Radial grid line
147 QRectF gridRect;
148 gridRect.setWidth(radialCoordinate * 2.0);
149 gridRect.setHeight(radialCoordinate * 2.0);
150 gridRect.moveCenter(center);
151
152 gridItem->setRect(gridRect);
153 gridItem->setVisible(true);
154
155 // Tick
156 QLineF tickLine(-tickWidth(), 0.0, tickWidth(), 0.0);
157 tickLine.translate(center.rx(), gridRect.top());
158 tickItem->setLine(tickLine);
159 tickItem->setVisible(true);
160
161 // Shades
162 if (i % 2 || (i == 0 && !nextTickVisible)) {
163 QPainterPath path;
164 if (i == 0) {
165 // If first tick is also the last, we need to custom fill the inner circle
166 // or it won't get filled.
167 QRectF innerCircle(0.0, 0.0, layout.at(0) * 2.0, layout.at(0) * 2.0);
168 innerCircle.moveCenter(center);
169 path.addEllipse(innerCircle);
170 } else {
171 QRectF otherGridRect;
172 if (!nextTickVisible) { // Last visible tick
173 otherGridRect = axisGeometry();
174 } else {
175 qreal otherGridRectDimension = layout.at(i + 1) * 2.0;
176 otherGridRect.setWidth(otherGridRectDimension);
177 otherGridRect.setHeight(otherGridRectDimension);
178 otherGridRect.moveCenter(center);
179 }
180 path.addEllipse(gridRect);
181 path.addEllipse(otherGridRect);
182
183 // Add additional shading in first visible shade item if there is a partial tick
184 // to be filled at the center (log & category axes)
185 if (firstShade) {
186 QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
187 if (layout.at(i - 1) > 0.0) {
188 QRectF innerCircle(0.0, 0.0, layout.at(i - 1) * 2.0, layout.at(i - 1) * 2.0);
189 innerCircle.moveCenter(center);
190 QPainterPath specialPath;
191 specialPath.addEllipse(innerCircle);
192 specialShadeItem->setPath(specialPath);
193 specialShadeItem->setVisible(true);
194 } else {
195 specialShadeItem->setVisible(false);
196 }
197 }
198 }
199 shadeItem->setPath(path);
200 shadeItem->setVisible(true);
201 firstShade = false;
202 }
203 }
204
205 // Title, along the 0 axis
206 QString titleText = axis()->titleText();
207 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
208 QFontMetrics titleMetrics(axis()->titleFont());
209 if (titleMetrics.boundingRect(titleText).width() > radius) {
210 QString string = titleText + "...";
211 while (titleMetrics.boundingRect(string).width() > radius && string.length() > 3)
212 string.remove(string.length() - 4, 1);
213 title->setText(string);
214 } else {
215 title->setText(titleText);
216 }
217
218 QRectF titleBoundingRect;
219 titleBoundingRect = title->boundingRect();
220 QPointF titleCenter = titleBoundingRect.center();
221 QPointF arrowCenter = axisLine->boundingRect().center();
222 QPointF titleCenterDiff = arrowCenter - titleCenter;
223 title->setPos(titleCenterDiff.x() - qreal(titlePadding()) - (titleBoundingRect.height() / 2.0), titleCenterDiff.y());
224 title->setTransformOriginPoint(titleCenter);
225 title->setRotation(270.0);
226 }
227
228 QGraphicsLayoutItem::updateGeometry();
229 }
230
231 Qt::Orientation PolarChartAxisRadial::orientation() const
232 {
233 return Qt::Vertical;
234 }
235
236 void PolarChartAxisRadial::createItems(int count)
237 {
238 if (arrowItems().count() == 0) {
239 // radial axis center line
240 QGraphicsLineItem *arrow = new LineArrowItem(this, presenter()->rootItem());
241 arrow->setPen(axis()->linePen());
242 arrowGroup()->addToGroup(arrow);
243 }
244
245 for (int i = 0; i < count; ++i) {
246 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
247 QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem());
248 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
249 QGraphicsSimpleTextItem *title = titleItem();
250 arrow->setPen(axis()->linePen());
251 grid->setPen(axis()->gridLinePen());
252 label->setFont(axis()->labelsFont());
253 label->setPen(axis()->labelsPen());
254 label->setBrush(axis()->labelsBrush());
255 label->setRotation(axis()->labelsAngle());
256 title->setFont(axis()->titleFont());
257 title->setPen(axis()->titlePen());
258 title->setBrush(axis()->titleBrush());
259 title->setText(axis()->titleText());
260 arrowGroup()->addToGroup(arrow);
261 gridGroup()->addToGroup(grid);
262 labelGroup()->addToGroup(label);
263 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
264 QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem());
265 shade->setPen(axis()->shadesPen());
266 shade->setBrush(axis()->shadesBrush());
267 shadeGroup()->addToGroup(shade);
268 }
269 }
270 }
271
272 void PolarChartAxisRadial::handleArrowPenChanged(const QPen &pen)
273 {
274 foreach (QGraphicsItem *item, arrowItems())
275 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
276 }
277
278 void PolarChartAxisRadial::handleGridPenChanged(const QPen &pen)
279 {
280 foreach (QGraphicsItem *item, gridItems())
281 static_cast<QGraphicsEllipseItem *>(item)->setPen(pen);
282 }
283
284 QSizeF PolarChartAxisRadial::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
285 {
286 Q_UNUSED(which);
287 Q_UNUSED(constraint);
288 return QSizeF(-1.0, -1.0);
289 }
290
291 qreal PolarChartAxisRadial::preferredAxisRadius(const QSizeF &maxSize)
292 {
293 qreal radius = maxSize.height() / 2.0;
294 if (maxSize.width() < maxSize.height())
295 radius = maxSize.width() / 2.0;
296 return radius;
297 }
298
299 #include "moc_polarchartaxisradial_p.cpp"
300
301 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,60
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTAXISRADIAL_P_H
31 #define POLARCHARTAXISRADIAL_P_H
32
33 #include "polarchartaxis_p.h"
34 #include "qvalueaxis.h"
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class PolarChartAxisRadial : public PolarChartAxis
39 {
40 Q_OBJECT
41 public:
42 PolarChartAxisRadial(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false);
43 ~PolarChartAxisRadial();
44
45 Qt::Orientation orientation() const;
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
47
48 virtual void updateGeometry();
49 virtual void createItems(int count);
50
51 qreal preferredAxisRadius(const QSizeF &maxSize);
52
53 public Q_SLOTS:
54 virtual void handleArrowPenChanged(const QPen &pen);
55 virtual void handleGridPenChanged(const QPen &pen);
56 };
57
58 QTCOMMERCIALCHART_END_NAMESPACE
59
60 #endif // POLARCHARTAXISRADIAL_P_H
@@ -0,0 +1,80
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartvalueaxisangular_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 PolarChartValueAxisAngular::PolarChartValueAxisAngular(QValueAxis *axis, QGraphicsItem *item)
28 : PolarChartAxisAngular(axis, item)
29 {
30 QObject::connect(axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int)));
31 QObject::connect(axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
32 }
33
34 PolarChartValueAxisAngular::~PolarChartValueAxisAngular()
35 {
36 }
37
38 QVector<qreal> PolarChartValueAxisAngular::calculateLayout() const
39 {
40 int tickCount = static_cast<QValueAxis *>(axis())->tickCount();
41 Q_ASSERT(tickCount >= 2);
42
43 QVector<qreal> points;
44 points.resize(tickCount);
45
46 const qreal d = 360.0 / qreal(tickCount - 1);
47
48 for (int i = 0; i < tickCount; ++i) {
49 qreal angularCoordinate = qreal(i) * d;
50 points[i] = angularCoordinate;
51 }
52
53 return points;
54 }
55
56 void PolarChartValueAxisAngular::createAxisLabels(const QVector<qreal> &layout)
57 {
58 QStringList labelList = createValueLabels(min(), max(), layout.size(), static_cast<QValueAxis *>(axis())->labelFormat());
59 setLabels(labelList);
60 }
61
62 void PolarChartValueAxisAngular::handleTickCountChanged(int tick)
63 {
64 Q_UNUSED(tick);
65 QGraphicsLayoutItem::updateGeometry();
66 if (presenter())
67 presenter()->layout()->invalidate();
68 }
69
70 void PolarChartValueAxisAngular::handleLabelFormatChanged(const QString &format)
71 {
72 Q_UNUSED(format);
73 QGraphicsLayoutItem::updateGeometry();
74 if (presenter())
75 presenter()->layout()->invalidate();
76 }
77
78 #include "moc_polarchartvalueaxisangular_p.cpp"
79
80 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,56
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTVALUEAXISANGULAR_P_H
31 #define POLARCHARTVALUEAXISANGULAR_P_H
32
33 #include "polarchartaxisangular_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QValueAxis;
38
39 class PolarChartValueAxisAngular : public PolarChartAxisAngular
40 {
41 Q_OBJECT
42 public:
43 PolarChartValueAxisAngular(QValueAxis *axis, QGraphicsItem *item);
44 ~PolarChartValueAxisAngular();
45
46 virtual QVector<qreal> calculateLayout() const;
47 virtual void createAxisLabels(const QVector<qreal> &layout);
48
49 private Q_SLOTS:
50 void handleTickCountChanged(int tick);
51 void handleLabelFormatChanged(const QString &format);
52 };
53
54 QTCOMMERCIALCHART_END_NAMESPACE
55
56 #endif // POLARCHARTVALUEAXISANGULAR_P_H
@@ -0,0 +1,79
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartvalueaxisradial_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 PolarChartValueAxisRadial::PolarChartValueAxisRadial(QValueAxis *axis, QGraphicsItem *item)
28 : PolarChartAxisRadial(axis, item)
29 {
30 QObject::connect(axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int)));
31 QObject::connect(axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
32 }
33
34 PolarChartValueAxisRadial::~PolarChartValueAxisRadial()
35 {
36 }
37
38 QVector<qreal> PolarChartValueAxisRadial::calculateLayout() const
39 {
40 int tickCount = static_cast<QValueAxis *>(axis())->tickCount();
41 Q_ASSERT(tickCount >= 2);
42
43 QVector<qreal> points;
44 points.resize(tickCount);
45
46 const qreal d = (axisGeometry().width() / 2) / qreal(tickCount - 1);
47
48 for (int i = 0; i < tickCount; ++i) {
49 qreal radialCoordinate = qreal(i) * d;
50 points[i] = radialCoordinate;
51 }
52
53 return points;
54 }
55
56 void PolarChartValueAxisRadial::createAxisLabels(const QVector<qreal> &layout)
57 {
58 setLabels(createValueLabels(min(), max(), layout.size(), static_cast<QValueAxis *>(axis())->labelFormat()));
59 }
60
61 void PolarChartValueAxisRadial::handleTickCountChanged(int tick)
62 {
63 Q_UNUSED(tick);
64 QGraphicsLayoutItem::updateGeometry();
65 if (presenter())
66 presenter()->layout()->invalidate();
67 }
68
69 void PolarChartValueAxisRadial::handleLabelFormatChanged(const QString &format)
70 {
71 Q_UNUSED(format);
72 QGraphicsLayoutItem::updateGeometry();
73 if (presenter())
74 presenter()->layout()->invalidate();
75 }
76
77 #include "moc_polarchartvalueaxisradial_p.cpp"
78
79 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,56
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTVALUEAXISRADIAL_P_H
31 #define POLARCHARTVALUEAXISRADIAL_P_H
32
33 #include "polarchartaxisradial_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QValueAxis;
38
39 class PolarChartValueAxisRadial : public PolarChartAxisRadial
40 {
41 Q_OBJECT
42 public:
43 PolarChartValueAxisRadial(QValueAxis *axis, QGraphicsItem *item);
44 ~PolarChartValueAxisRadial();
45
46 virtual QVector<qreal> calculateLayout() const;
47 virtual void createAxisLabels(const QVector<qreal> &layout);
48
49 private Q_SLOTS:
50 void handleTickCountChanged(int tick);
51 void handleLabelFormatChanged(const QString &format);
52 };
53
54 QTCOMMERCIALCHART_END_NAMESPACE
55
56 #endif // POLARCHARTVALUEAXISRADIAL_P_H
@@ -0,0 +1,267
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "logxlogypolardomain_p.h"
22 #include "qabstractaxis_p.h"
23 #include "qlogvalueaxis.h"
24 #include <qmath.h>
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 LogXLogYPolarDomain::LogXLogYPolarDomain(QObject *parent)
29 : PolarDomain(parent),
30 m_logLeftX(0),
31 m_logRightX(1),
32 m_logBaseX(10),
33 m_logInnerY(0),
34 m_logOuterY(1),
35 m_logBaseY(10)
36 {
37 }
38
39 LogXLogYPolarDomain::~LogXLogYPolarDomain()
40 {
41 }
42
43 void LogXLogYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
44 {
45 bool axisXChanged = false;
46 bool axisYChanged = false;
47
48 adjustLogDomainRanges(minX, maxX);
49 adjustLogDomainRanges(minY, maxY);
50
51 if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) {
52 m_minX = minX;
53 m_maxX = maxX;
54 axisXChanged = true;
55 qreal logMinX = log10(m_minX) / log10(m_logBaseX);
56 qreal logMaxX = log10(m_maxX) / log10(m_logBaseX);
57 m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX;
58 m_logRightX = logMinX > logMaxX ? logMinX : logMaxX;
59 if (!m_signalsBlocked)
60 emit rangeHorizontalChanged(m_minX, m_maxX);
61 }
62
63 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
64 m_minY = minY;
65 m_maxY = maxY;
66 axisYChanged = true;
67 qreal logMinY = log10(m_minY) / log10(m_logBaseY);
68 qreal logMaxY = log10(m_maxY) / log10(m_logBaseY);
69 m_logInnerY = logMinY < logMaxY ? logMinY : logMaxY;
70 m_logOuterY = logMinY > logMaxY ? logMinY : logMaxY;
71 if (!m_signalsBlocked)
72 emit rangeVerticalChanged(m_minY, m_maxY);
73 }
74
75 if (axisXChanged || axisYChanged)
76 emit updated();
77 }
78
79 void LogXLogYPolarDomain::zoomIn(const QRectF &rect)
80 {
81 qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX;
82 qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX;
83 qreal leftX = qPow(m_logBaseX, logLeftX);
84 qreal rightX = qPow(m_logBaseX, logRightX);
85 qreal minX = leftX < rightX ? leftX : rightX;
86 qreal maxX = leftX > rightX ? leftX : rightX;
87
88 qreal logLeftY = m_logOuterY - rect.bottom() * (m_logOuterY - m_logInnerY) / m_size.height();
89 qreal logRightY = m_logOuterY - rect.top() * (m_logOuterY - m_logInnerY) / m_size.height();
90 qreal leftY = qPow(m_logBaseY, logLeftY);
91 qreal rightY = qPow(m_logBaseY, logRightY);
92 qreal minY = leftY < rightY ? leftY : rightY;
93 qreal maxY = leftY > rightY ? leftY : rightY;
94
95 setRange(minX, maxX, minY, maxY);
96 }
97
98 void LogXLogYPolarDomain::zoomOut(const QRectF &rect)
99 {
100 const qreal factorX = m_size.width() / rect.width();
101
102 qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 - factorX);
103 qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 + factorX);
104 qreal leftX = qPow(m_logBaseX, logLeftX);
105 qreal rightX = qPow(m_logBaseX, logRIghtX);
106 qreal minX = leftX < rightX ? leftX : rightX;
107 qreal maxX = leftX > rightX ? leftX : rightX;
108
109 const qreal factorY = m_size.height() / rect.height();
110 qreal newLogMinY = m_logInnerY + (m_logOuterY - m_logInnerY) / 2.0 * (1.0 - factorY);
111 qreal newLogMaxY = m_logInnerY + (m_logOuterY - m_logInnerY) / 2.0 * (1.0 + factorY);
112 qreal leftY = qPow(m_logBaseY, newLogMinY);
113 qreal rightY = qPow(m_logBaseY, newLogMaxY);
114 qreal minY = leftY < rightY ? leftY : rightY;
115 qreal maxY = leftY > rightY ? leftY : rightY;
116
117 setRange(minX, maxX, minY, maxY);
118 }
119
120 void LogXLogYPolarDomain::move(qreal dx, qreal dy)
121 {
122 qreal stepX = dx * (m_logRightX - m_logLeftX) / m_size.width();
123 qreal leftX = qPow(m_logBaseX, m_logLeftX + stepX);
124 qreal rightX = qPow(m_logBaseX, m_logRightX + stepX);
125 qreal minX = leftX < rightX ? leftX : rightX;
126 qreal maxX = leftX > rightX ? leftX : rightX;
127
128 qreal stepY = dy * (m_logOuterY - m_logInnerY) / m_radius;
129 qreal leftY = qPow(m_logBaseY, m_logInnerY + stepY);
130 qreal rightY = qPow(m_logBaseY, m_logOuterY + stepY);
131 qreal minY = leftY < rightY ? leftY : rightY;
132 qreal maxY = leftY > rightY ? leftY : rightY;
133
134 setRange(minX, maxX, minY, maxY);
135 }
136
137 qreal LogXLogYPolarDomain::toAngularCoordinate(qreal value, bool &ok) const
138 {
139 qreal retVal;
140 if (value <= 0) {
141 ok = false;
142 retVal = 0.0;
143 } else {
144 ok = true;
145 const qreal tickSpan = 360.0 / qAbs(m_logRightX - m_logLeftX);
146 const qreal logValue = log10(value) / log10(m_logBaseX);
147 const qreal valueDelta = logValue - m_logLeftX;
148
149 retVal = valueDelta * tickSpan;
150 }
151 return retVal;
152 }
153
154 qreal LogXLogYPolarDomain::toRadialCoordinate(qreal value, bool &ok) const
155 {
156 qreal retVal;
157 if (value <= 0) {
158 ok = false;
159 retVal = 0.0;
160 } else {
161 ok = true;
162 const qreal tickSpan = m_radius / qAbs(m_logOuterY - m_logInnerY);
163 const qreal logValue = log10(value) / log10(m_logBaseY);
164 const qreal valueDelta = logValue - m_logInnerY;
165
166 retVal = valueDelta * tickSpan;
167
168 if (retVal < 0.0)
169 retVal = 0.0;
170 }
171 return retVal;
172 }
173
174 QPointF LogXLogYPolarDomain::calculateDomainPoint(const QPointF &point) const
175 {
176 if (point == m_center)
177 return QPointF(0.0, m_minY);
178
179 QLineF line(m_center, point);
180 qreal a = 90.0 - line.angle();
181 if (a < 0.0)
182 a += 360.0;
183
184 const qreal deltaX = 360.0 / qAbs(m_logRightX - m_logLeftX);
185 a = qPow(m_logBaseX, m_logLeftX + (a / deltaX));
186
187 const qreal deltaY = m_radius / qAbs(m_logOuterY - m_logInnerY);
188 qreal r = qPow(m_logBaseY, m_logInnerY + (line.length() / deltaY));
189
190 return QPointF(a, r);
191 }
192
193 bool LogXLogYPolarDomain::attachAxis(QAbstractAxis *axis)
194 {
195 AbstractDomain::attachAxis(axis);
196 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
197
198 if (logAxis && logAxis->orientation() == Qt::Horizontal) {
199 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
200 handleHorizontalAxisBaseChanged(logAxis->base());
201 } else if (logAxis && logAxis->orientation() == Qt::Vertical){
202 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
203 handleVerticalAxisBaseChanged(logAxis->base());
204 }
205
206 return true;
207 }
208
209 bool LogXLogYPolarDomain::detachAxis(QAbstractAxis *axis)
210 {
211 AbstractDomain::detachAxis(axis);
212 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
213
214 if (logAxis && logAxis->orientation() == Qt::Horizontal)
215 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
216 else if (logAxis && logAxis->orientation() == Qt::Vertical)
217 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
218
219 return true;
220 }
221
222 void LogXLogYPolarDomain::handleHorizontalAxisBaseChanged(qreal baseX)
223 {
224 m_logBaseX = baseX;
225 qreal logMinX = log10(m_minX) / log10(m_logBaseX);
226 qreal logMaxX = log10(m_maxX) / log10(m_logBaseX);
227 m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX;
228 m_logRightX = logMinX > logMaxX ? logMinX : logMaxX;
229 emit updated();
230 }
231
232 void LogXLogYPolarDomain::handleVerticalAxisBaseChanged(qreal baseY)
233 {
234 m_logBaseY = baseY;
235 qreal logMinY = log10(m_minY) / log10(m_logBaseY);
236 qreal logMaxY = log10(m_maxY) / log10(m_logBaseY);
237 m_logInnerY = logMinY < logMaxY ? logMinY : logMaxY;
238 m_logOuterY = logMinY > logMaxY ? logMinY : logMaxY;
239 emit updated();
240 }
241
242 // operators
243
244 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYPolarDomain &domain1, const LogXLogYPolarDomain &domain2)
245 {
246 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX)
247 && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY)
248 && qFuzzyIsNull(domain1.m_minX - domain2.m_minX)
249 && qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
250 }
251
252
253 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXLogYPolarDomain &domain1, const LogXLogYPolarDomain &domain2)
254 {
255 return !(domain1 == domain2);
256 }
257
258
259 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYPolarDomain &domain)
260 {
261 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
262 return dbg.maybeSpace();
263 }
264
265 #include "moc_logxlogypolardomain_p.cpp"
266
267 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,81
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef LOGXLOGYPOLARDOMAIN_H
31 #define LOGXLOGYPOLARDOMAIN_H
32 #include "polardomain_p.h"
33 #include <QRectF>
34 #include <QSizeF>
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT LogXLogYPolarDomain: public PolarDomain
39 {
40 Q_OBJECT
41 public:
42 explicit LogXLogYPolarDomain(QObject *object = 0);
43 virtual ~LogXLogYPolarDomain();
44
45 DomainType type() { return AbstractDomain::LogXLogYPolarDomain; }
46
47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
48
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYPolarDomain &domain1, const LogXLogYPolarDomain &domain2);
50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXLogYPolarDomain &domain1, const LogXLogYPolarDomain &domain2);
51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYPolarDomain &domain);
52
53 void zoomIn(const QRectF &rect);
54 void zoomOut(const QRectF &rect);
55 void move(qreal dx, qreal dy);
56
57 QPointF calculateDomainPoint(const QPointF &point) const;
58
59 bool attachAxis(QAbstractAxis *axis);
60 bool detachAxis(QAbstractAxis *axis);
61
62 public Q_SLOTS:
63 void handleVerticalAxisBaseChanged(qreal baseY);
64 void handleHorizontalAxisBaseChanged(qreal baseX);
65
66 protected:
67 qreal toAngularCoordinate(qreal value, bool &ok) const;
68 qreal toRadialCoordinate(qreal value, bool &ok) const;
69
70 private:
71 qreal m_logLeftX;
72 qreal m_logRightX;
73 qreal m_logBaseX;
74 qreal m_logInnerY;
75 qreal m_logOuterY;
76 qreal m_logBaseY;
77 };
78
79 QTCOMMERCIALCHART_END_NAMESPACE
80
81 #endif // LOGXLOGYPOLARDOMAIN_H
@@ -0,0 +1,236
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "logxypolardomain_p.h"
22 #include "qabstractaxis_p.h"
23 #include "qlogvalueaxis.h"
24 #include <qmath.h>
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 LogXYPolarDomain::LogXYPolarDomain(QObject *parent)
29 : PolarDomain(parent),
30 m_logLeftX(0),
31 m_logRightX(1),
32 m_logBaseX(10)
33 {
34 }
35
36 LogXYPolarDomain::~LogXYPolarDomain()
37 {
38 }
39
40 void LogXYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
41 {
42 bool axisXChanged = false;
43 bool axisYChanged = false;
44
45 adjustLogDomainRanges(minX, maxX);
46
47 if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) {
48 m_minX = minX;
49 m_maxX = maxX;
50 axisXChanged = true;
51 qreal logMinX = log10(m_minX) / log10(m_logBaseX);
52 qreal logMaxX = log10(m_maxX) / log10(m_logBaseX);
53 m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX;
54 m_logRightX = logMinX > logMaxX ? logMinX : logMaxX;
55 if (!m_signalsBlocked)
56 emit rangeHorizontalChanged(m_minX, m_maxX);
57 }
58
59 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
60 m_minY = minY;
61 m_maxY = maxY;
62 axisYChanged = true;
63 if (!m_signalsBlocked)
64 emit rangeVerticalChanged(m_minY, m_maxY);
65 }
66
67 if (axisXChanged || axisYChanged)
68 emit updated();
69 }
70
71 void LogXYPolarDomain::zoomIn(const QRectF &rect)
72 {
73 qreal logLeftX = rect.left() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX;
74 qreal logRightX = rect.right() * (m_logRightX - m_logLeftX) / m_size.width() + m_logLeftX;
75 qreal leftX = qPow(m_logBaseX, logLeftX);
76 qreal rightX = qPow(m_logBaseX, logRightX);
77 qreal minX = leftX < rightX ? leftX : rightX;
78 qreal maxX = leftX > rightX ? leftX : rightX;
79
80 qreal dy = spanY() / m_size.height();
81 qreal minY = m_minY;
82 qreal maxY = m_maxY;
83
84 minY = maxY - dy * rect.bottom();
85 maxY = maxY - dy * rect.top();
86
87 setRange(minX, maxX, minY, maxY);
88 }
89
90 void LogXYPolarDomain::zoomOut(const QRectF &rect)
91 {
92 const qreal factorX = m_size.width() / rect.width();
93
94 qreal logLeftX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 - factorX);
95 qreal logRIghtX = m_logLeftX + (m_logRightX - m_logLeftX) / 2.0 * (1.0 + factorX);
96 qreal leftX = qPow(m_logBaseX, logLeftX);
97 qreal rightX = qPow(m_logBaseX, logRIghtX);
98 qreal minX = leftX < rightX ? leftX : rightX;
99 qreal maxX = leftX > rightX ? leftX : rightX;
100
101 qreal dy = spanY() / rect.height();
102 qreal minY = m_minY;
103 qreal maxY = m_maxY;
104
105 maxY = minY + dy * rect.bottom();
106 minY = maxY - dy * m_size.height();
107
108 setRange(minX, maxX, minY, maxY);
109 }
110
111 void LogXYPolarDomain::move(qreal dx, qreal dy)
112 {
113 qreal stepX = dx * (m_logRightX - m_logLeftX) / m_size.width();
114 qreal leftX = qPow(m_logBaseX, m_logLeftX + stepX);
115 qreal rightX = qPow(m_logBaseX, m_logRightX + stepX);
116 qreal minX = leftX < rightX ? leftX : rightX;
117 qreal maxX = leftX > rightX ? leftX : rightX;
118
119 qreal y = spanY() / m_radius;
120 qreal minY = m_minY;
121 qreal maxY = m_maxY;
122
123 if (dy != 0) {
124 minY = minY + y * dy;
125 maxY = maxY + y * dy;
126 }
127 setRange(minX, maxX, minY, maxY);
128 }
129
130 qreal LogXYPolarDomain::toAngularCoordinate(qreal value, bool &ok) const
131 {
132 qreal retVal;
133 if (value <= 0) {
134 ok = false;
135 retVal = 0.0;
136 } else {
137 ok = true;
138 const qreal tickSpan = 360.0 / qAbs(m_logRightX - m_logLeftX);
139 const qreal logValue = log10(value) / log10(m_logBaseX);
140 const qreal valueDelta = logValue - m_logLeftX;
141
142 retVal = valueDelta * tickSpan;
143 }
144 return retVal;
145 }
146
147 qreal LogXYPolarDomain::toRadialCoordinate(qreal value, bool &ok) const
148 {
149 ok = true;
150 if (value < m_minY)
151 value = m_minY;
152
153 // Dont limit the max. The drawing should clip the stuff that goes out of the grid
154 qreal f = (value - m_minY) / (m_maxY - m_minY);
155
156 return f * m_radius;
157 }
158
159 QPointF LogXYPolarDomain::calculateDomainPoint(const QPointF &point) const
160 {
161 if (point == m_center)
162 return QPointF(0.0, m_minY);
163
164 QLineF line(m_center, point);
165 qreal a = 90.0 - line.angle();
166 if (a < 0.0)
167 a += 360.0;
168
169 const qreal deltaX = 360.0 / qAbs(m_logRightX - m_logLeftX);
170 a = qPow(m_logBaseX, m_logLeftX + (a / deltaX));
171
172 qreal r = m_minY + ((m_maxY - m_minY) * (line.length() / m_radius));
173
174 return QPointF(a, r);
175 }
176
177 bool LogXYPolarDomain::attachAxis(QAbstractAxis *axis)
178 {
179 AbstractDomain::attachAxis(axis);
180 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
181
182 if (logAxis && logAxis->orientation() == Qt::Horizontal) {
183 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
184 handleHorizontalAxisBaseChanged(logAxis->base());
185 }
186
187 return true;
188 }
189
190 bool LogXYPolarDomain::detachAxis(QAbstractAxis *axis)
191 {
192 AbstractDomain::detachAxis(axis);
193 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
194
195 if (logAxis && logAxis->orientation() == Qt::Horizontal)
196 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
197
198 return true;
199 }
200
201 void LogXYPolarDomain::handleHorizontalAxisBaseChanged(qreal baseX)
202 {
203 m_logBaseX = baseX;
204 qreal logMinX = log10(m_minX) / log10(m_logBaseX);
205 qreal logMaxX = log10(m_maxX) / log10(m_logBaseX);
206 m_logLeftX = logMinX < logMaxX ? logMinX : logMaxX;
207 m_logRightX = logMinX > logMaxX ? logMinX : logMaxX;
208 emit updated();
209 }
210
211 // operators
212
213 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXYPolarDomain &domain1, const LogXYPolarDomain &domain2)
214 {
215 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX)
216 && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY)
217 && qFuzzyIsNull(domain1.m_minX - domain2.m_minX)
218 && qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
219 }
220
221
222 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXYPolarDomain &domain1, const LogXYPolarDomain &domain2)
223 {
224 return !(domain1 == domain2);
225 }
226
227
228 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYPolarDomain &domain)
229 {
230 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
231 return dbg.maybeSpace();
232 }
233
234 #include "moc_logxypolardomain_p.cpp"
235
236 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,77
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef LOGXYPOLARDOMAIN_H
31 #define LOGXYPOLARDOMAIN_H
32 #include "polardomain_p.h"
33 #include <QRectF>
34 #include <QSizeF>
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT LogXYPolarDomain: public PolarDomain
39 {
40 Q_OBJECT
41 public:
42 explicit LogXYPolarDomain(QObject *object = 0);
43 virtual ~LogXYPolarDomain();
44
45 DomainType type() { return AbstractDomain::LogXYPolarDomain; }
46
47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
48
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXYPolarDomain &domain1, const LogXYPolarDomain &domain2);
50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXYPolarDomain &domain1, const LogXYPolarDomain &domain2);
51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYPolarDomain &domain);
52
53 void zoomIn(const QRectF &rect);
54 void zoomOut(const QRectF &rect);
55 void move(qreal dx, qreal dy);
56
57 QPointF calculateDomainPoint(const QPointF &point) const;
58
59 bool attachAxis(QAbstractAxis *axis);
60 bool detachAxis(QAbstractAxis *axis);
61
62 public Q_SLOTS:
63 void handleHorizontalAxisBaseChanged(qreal baseX);
64
65 protected:
66 qreal toAngularCoordinate(qreal value, bool &ok) const;
67 qreal toRadialCoordinate(qreal value, bool &ok) const;
68
69 private:
70 qreal m_logLeftX;
71 qreal m_logRightX;
72 qreal m_logBaseX;
73 };
74
75 QTCOMMERCIALCHART_END_NAMESPACE
76
77 #endif // LOGXYPOLARDOMAIN_H
@@ -0,0 +1,91
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polardomain_p.h"
22 #include "qabstractaxis_p.h"
23 #include <qmath.h>
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 PolarDomain::PolarDomain(QObject *parent)
28 : AbstractDomain(parent)
29 {
30 }
31
32 PolarDomain::~PolarDomain()
33 {
34 }
35
36 void PolarDomain::setSize(const QSizeF &size)
37 {
38 Q_ASSERT(size.width() == size.height());
39 m_radius = size.height() / 2;
40 m_center = QPointF(m_radius, m_radius);
41 AbstractDomain::setSize(size);
42 }
43
44 QPointF PolarDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const
45 {
46 qreal r;
47 qreal a = toAngularCoordinate(point.x(), ok);
48 if (ok)
49 r = toRadialCoordinate(point.y(), ok);
50 if (ok) {
51 return m_center + polarCoordinateToPoint(a, r);
52 } else {
53 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
54 return QPointF();
55 }
56 }
57
58 QVector<QPointF> PolarDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
59 {
60 QVector<QPointF> result;
61 result.resize(vector.count());
62 bool ok;
63 qreal r;
64 qreal a;
65
66 for (int i = 0; i < vector.count(); ++i) {
67 a = toAngularCoordinate(vector[i].x(), ok);
68 if (ok)
69 r = toRadialCoordinate(vector[i].y(), ok);
70 if (ok) {
71 result[i] = m_center + polarCoordinateToPoint(a, r);
72 } else {
73 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
74 return QVector<QPointF>();
75 }
76 }
77
78 return result;
79 }
80
81 QPointF PolarDomain::polarCoordinateToPoint(qreal angularCoordinate, qreal radialCoordinate) const
82 {
83 qreal dx = qSin(angularCoordinate * (M_PI / 180)) * radialCoordinate;
84 qreal dy = qCos(angularCoordinate * (M_PI / 180)) * radialCoordinate;
85
86 return QPointF(dx, -dy);
87 }
88
89 #include "moc_polardomain_p.cpp"
90
91 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,62
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARDOMAIN_H
31 #define POLARDOMAIN_H
32 #include "abstractdomain_p.h"
33 #include <QRectF>
34 #include <QSizeF>
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT PolarDomain: public AbstractDomain
39 {
40 Q_OBJECT
41 public:
42 explicit PolarDomain(QObject *object = 0);
43 virtual ~PolarDomain();
44
45 void setSize(const QSizeF &size);
46
47 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
48 QVector<QPointF> calculateGeometryPoints(const QList<QPointF> &vector) const;
49
50 virtual qreal toAngularCoordinate(qreal value, bool &ok) const = 0;
51 virtual qreal toRadialCoordinate(qreal value, bool &ok) const = 0;
52
53 protected:
54 QPointF polarCoordinateToPoint(qreal angularCoordinate, qreal radialCoordinate) const;
55
56 QPointF m_center;
57 qreal m_radius;
58 };
59
60 QTCOMMERCIALCHART_END_NAMESPACE
61
62 #endif // POLARDOMAIN_H
@@ -0,0 +1,231
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "xlogypolardomain_p.h"
22 #include "qabstractaxis_p.h"
23 #include "qlogvalueaxis.h"
24 #include <qmath.h>
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 XLogYPolarDomain::XLogYPolarDomain(QObject *parent)
29 : PolarDomain(parent),
30 m_logInnerY(0),
31 m_logOuterY(1),
32 m_logBaseY(10)
33 {
34 }
35
36 XLogYPolarDomain::~XLogYPolarDomain()
37 {
38 }
39
40 void XLogYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
41 {
42 bool axisXChanged = false;
43 bool axisYChanged = false;
44
45 adjustLogDomainRanges(minY, maxY);
46
47 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
48 m_minX = minX;
49 m_maxX = maxX;
50 axisXChanged = true;
51 if (!m_signalsBlocked)
52 emit rangeHorizontalChanged(m_minX, m_maxX);
53 }
54
55 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
56 m_minY = minY;
57 m_maxY = maxY;
58 axisYChanged = true;
59 qreal logMinY = log10(m_minY) / log10(m_logBaseY);
60 qreal logMaxY = log10(m_maxY) / log10(m_logBaseY);
61 m_logInnerY = logMinY < logMaxY ? logMinY : logMaxY;
62 m_logOuterY = logMinY > logMaxY ? logMinY : logMaxY;
63 if (!m_signalsBlocked)
64 emit rangeVerticalChanged(m_minY, m_maxY);
65 }
66
67 if (axisXChanged || axisYChanged)
68 emit updated();
69 }
70
71 void XLogYPolarDomain::zoomIn(const QRectF &rect)
72 {
73 qreal dx = spanX() / m_size.width();
74 qreal maxX = m_maxX;
75 qreal minX = m_minX;
76
77 maxX = minX + dx * rect.right();
78 minX = minX + dx * rect.left();
79
80 qreal logLeftY = m_logOuterY - rect.bottom() * (m_logOuterY - m_logInnerY) / m_size.height();
81 qreal logRightY = m_logOuterY - rect.top() * (m_logOuterY - m_logInnerY) / m_size.height();
82 qreal leftY = qPow(m_logBaseY, logLeftY);
83 qreal rightY = qPow(m_logBaseY, logRightY);
84 qreal minY = leftY < rightY ? leftY : rightY;
85 qreal maxY = leftY > rightY ? leftY : rightY;
86
87 setRange(minX, maxX, minY, maxY);
88 }
89
90 void XLogYPolarDomain::zoomOut(const QRectF &rect)
91 {
92 qreal dx = spanX() / rect.width();
93 qreal maxX = m_maxX;
94 qreal minX = m_minX;
95
96 minX = maxX - dx * rect.right();
97 maxX = minX + dx * m_size.width();
98
99 const qreal factorY = m_size.height() / rect.height();
100 qreal newLogMinY = m_logInnerY + (m_logOuterY - m_logInnerY) / 2.0 * (1.0 - factorY);
101 qreal newLogMaxY = m_logInnerY + (m_logOuterY - m_logInnerY) / 2.0 * (1.0 + factorY);
102 qreal leftY = qPow(m_logBaseY, newLogMinY);
103 qreal rightY = qPow(m_logBaseY, newLogMaxY);
104 qreal minY = leftY < rightY ? leftY : rightY;
105 qreal maxY = leftY > rightY ? leftY : rightY;
106
107 setRange(minX, maxX, minY, maxY);
108 }
109
110 void XLogYPolarDomain::move(qreal dx, qreal dy)
111 {
112 qreal x = spanX() / 360.0;
113
114 qreal maxX = m_maxX;
115 qreal minX = m_minX;
116
117 if (dx != 0) {
118 minX = minX + x * dx;
119 maxX = maxX + x * dx;
120 }
121
122 qreal stepY = dy * (m_logOuterY - m_logInnerY) / m_radius;
123 qreal leftY = qPow(m_logBaseY, m_logInnerY + stepY);
124 qreal rightY = qPow(m_logBaseY, m_logOuterY + stepY);
125 qreal minY = leftY < rightY ? leftY : rightY;
126 qreal maxY = leftY > rightY ? leftY : rightY;
127
128 setRange(minX, maxX, minY, maxY);
129 }
130
131 qreal XLogYPolarDomain::toAngularCoordinate(qreal value, bool &ok) const
132 {
133 ok = true;
134 qreal f = (value - m_minX) / (m_maxX - m_minX);
135 return f * 360.0;
136 }
137
138 qreal XLogYPolarDomain::toRadialCoordinate(qreal value, bool &ok) const
139 {
140 qreal retVal;
141 if (value <= 0) {
142 ok = false;
143 retVal = 0.0;
144 } else {
145 ok = true;
146 const qreal tickSpan = m_radius / qAbs(m_logOuterY - m_logInnerY);
147 const qreal logValue = log10(value) / log10(m_logBaseY);
148 const qreal valueDelta = logValue - m_logInnerY;
149
150 retVal = valueDelta * tickSpan;
151
152 if (retVal < 0.0)
153 retVal = 0.0;
154 }
155 return retVal;
156 }
157
158 QPointF XLogYPolarDomain::calculateDomainPoint(const QPointF &point) const
159 {
160 if (point == m_center)
161 return QPointF(0.0, m_minY);
162
163 QLineF line(m_center, point);
164 qreal a = 90.0 - line.angle();
165 if (a < 0.0)
166 a += 360.0;
167 a = ((a / 360.0) * (m_maxX - m_minX)) + m_minX;
168
169 const qreal deltaY = m_radius / qAbs(m_logOuterY - m_logInnerY);
170 qreal r = qPow(m_logBaseY, m_logInnerY + (line.length() / deltaY));
171
172 return QPointF(a, r);
173 }
174
175 bool XLogYPolarDomain::attachAxis(QAbstractAxis *axis)
176 {
177 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
178
179 if (logAxis && logAxis->orientation() == Qt::Vertical) {
180 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
181 handleVerticalAxisBaseChanged(logAxis->base());
182 }
183 return AbstractDomain::attachAxis(axis);
184 }
185
186 bool XLogYPolarDomain::detachAxis(QAbstractAxis *axis)
187 {
188 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
189
190 if (logAxis && logAxis->orientation() == Qt::Vertical)
191 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
192
193 return AbstractDomain::detachAxis(axis);
194 }
195
196 void XLogYPolarDomain::handleVerticalAxisBaseChanged(qreal baseY)
197 {
198 m_logBaseY = baseY;
199 qreal logMinY = log10(m_minY) / log10(m_logBaseY);
200 qreal logMaxY = log10(m_maxY) / log10(m_logBaseY);
201 m_logInnerY = logMinY < logMaxY ? logMinY : logMaxY;
202 m_logOuterY = logMinY > logMaxY ? logMinY : logMaxY;
203 emit updated();
204 }
205
206 // operators
207
208 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYPolarDomain &domain1, const XLogYPolarDomain &domain2)
209 {
210 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX)
211 && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY)
212 && qFuzzyIsNull(domain1.m_minX - domain2.m_minX)
213 && qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
214 }
215
216
217 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYPolarDomain &domain1, const XLogYPolarDomain &domain2)
218 {
219 return !(domain1 == domain2);
220 }
221
222
223 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYPolarDomain &domain)
224 {
225 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
226 return dbg.maybeSpace();
227 }
228
229 #include "moc_xlogypolardomain_p.cpp"
230
231 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,77
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef XLOGYPOLARDOMAIN_H
31 #define XLOGYPOLARDOMAIN_H
32 #include "polardomain_p.h"
33 #include <QRectF>
34 #include <QSizeF>
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT XLogYPolarDomain: public PolarDomain
39 {
40 Q_OBJECT
41 public:
42 explicit XLogYPolarDomain(QObject *object = 0);
43 virtual ~XLogYPolarDomain();
44
45 DomainType type() { return AbstractDomain::XLogYPolarDomain; }
46
47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
48
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYPolarDomain &domain1, const XLogYPolarDomain &domain2);
50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYPolarDomain &domain1, const XLogYPolarDomain &domain2);
51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYPolarDomain &domain);
52
53 void zoomIn(const QRectF &rect);
54 void zoomOut(const QRectF &rect);
55 void move(qreal dx, qreal dy);
56
57 QPointF calculateDomainPoint(const QPointF &point) const;
58
59 bool attachAxis(QAbstractAxis *axis);
60 bool detachAxis(QAbstractAxis *axis);
61
62 public Q_SLOTS:
63 void handleVerticalAxisBaseChanged(qreal baseY);
64
65 protected:
66 qreal toAngularCoordinate(qreal value, bool &ok) const;
67 qreal toRadialCoordinate(qreal value, bool &ok) const;
68
69 private:
70 qreal m_logInnerY;
71 qreal m_logOuterY;
72 qreal m_logBaseY;
73 };
74
75 QTCOMMERCIALCHART_END_NAMESPACE
76
77 #endif // XLOGYPOLARDOMAIN_H
@@ -0,0 +1,178
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "xypolardomain_p.h"
22 #include "qabstractaxis_p.h"
23 #include <qmath.h>
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 XYPolarDomain::XYPolarDomain(QObject *parent)
28 : PolarDomain(parent)
29 {
30 }
31
32 XYPolarDomain::~XYPolarDomain()
33 {
34 }
35
36 void XYPolarDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
37 {
38 bool axisXChanged = false;
39 bool axisYChanged = false;
40
41 if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) {
42 m_minX = minX;
43 m_maxX = maxX;
44 axisXChanged = true;
45 if (!m_signalsBlocked)
46 emit rangeHorizontalChanged(m_minX, m_maxX);
47 }
48
49 if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) {
50 m_minY = minY;
51 m_maxY = maxY;
52 axisYChanged = true;
53 if (!m_signalsBlocked)
54 emit rangeVerticalChanged(m_minY, m_maxY);
55 }
56
57 if (axisXChanged || axisYChanged)
58 emit updated();
59 }
60
61
62 void XYPolarDomain::zoomIn(const QRectF &rect)
63 {
64 qreal dx = spanX() / m_size.width();
65 qreal dy = spanY() / m_size.height();
66
67 qreal maxX = m_maxX;
68 qreal minX = m_minX;
69 qreal minY = m_minY;
70 qreal maxY = m_maxY;
71
72 maxX = minX + dx * rect.right();
73 minX = minX + dx * rect.left();
74 minY = maxY - dy * rect.bottom();
75 maxY = maxY - dy * rect.top();
76
77 setRange(minX, maxX, minY, maxY);
78 }
79
80 void XYPolarDomain::zoomOut(const QRectF &rect)
81 {
82 qreal dx = spanX() / rect.width();
83 qreal dy = spanY() / rect.height();
84
85 qreal maxX = m_maxX;
86 qreal minX = m_minX;
87 qreal minY = m_minY;
88 qreal maxY = m_maxY;
89
90 minX = maxX - dx * rect.right();
91 maxX = minX + dx * m_size.width();
92 maxY = minY + dy * rect.bottom();
93 minY = maxY - dy * m_size.height();
94
95 setRange(minX, maxX, minY, maxY);
96 }
97
98 void XYPolarDomain::move(qreal dx, qreal dy)
99 {
100 // One unit scrolls one degree angular and one pixel radial
101 qreal x = spanX() / 360.0;
102 qreal y = spanY() / m_radius;
103
104 qreal maxX = m_maxX;
105 qreal minX = m_minX;
106 qreal minY = m_minY;
107 qreal maxY = m_maxY;
108
109 if (dx != 0) {
110 minX = minX + x * dx;
111 maxX = maxX + x * dx;
112 }
113 if (dy != 0) {
114 minY = minY + y * dy;
115 maxY = maxY + y * dy;
116 }
117 setRange(minX, maxX, minY, maxY);
118 }
119
120 QPointF XYPolarDomain::calculateDomainPoint(const QPointF &point) const
121 {
122 if (point == m_center)
123 return QPointF(0.0, m_minX);
124
125 QLineF line(m_center, point);
126 qreal a = 90.0 - line.angle();
127 if (a < 0.0)
128 a += 360.0;
129 a = ((a / 360.0) * (m_maxX - m_minX)) + m_minX;
130 qreal r = m_minY + ((m_maxY - m_minY) * (line.length() / m_radius));
131 return QPointF(a, r);
132 }
133
134 qreal XYPolarDomain::toAngularCoordinate(qreal value, bool &ok) const
135 {
136 ok = true;
137 qreal f = (value - m_minX) / (m_maxX - m_minX);
138 return f * 360.0;
139 }
140
141 qreal XYPolarDomain::toRadialCoordinate(qreal value, bool &ok) const
142 {
143 ok = true;
144 if (value < m_minY)
145 value = m_minY;
146
147 // Dont limit the max. The drawing should clip the stuff that goes out of the grid
148 qreal f = (value - m_minY) / (m_maxY - m_minY);
149
150 return f * m_radius;
151 }
152
153 // operators
154
155 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYPolarDomain &domain1, const XYPolarDomain &domain2)
156 {
157 return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX)
158 && qFuzzyCompare(domain1.m_maxY, domain2.m_maxY)
159 && qFuzzyCompare(domain1.m_minX, domain2.m_minX)
160 && qFuzzyCompare(domain1.m_minY, domain2.m_minY));
161 }
162
163
164 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XYPolarDomain &domain1, const XYPolarDomain &domain2)
165 {
166 return !(domain1 == domain2);
167 }
168
169
170 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYPolarDomain &domain)
171 {
172 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
173 return dbg.maybeSpace();
174 }
175
176 #include "moc_xypolardomain_p.cpp"
177
178 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,65
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef XYPOLARDOMAIN_H
31 #define XYPOLARDOMAIN_H
32 #include "polardomain_p.h"
33 #include <QRectF>
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QTCOMMERCIALCHART_AUTOTEST_EXPORT XYPolarDomain: public PolarDomain
38 {
39 Q_OBJECT
40 public:
41 explicit XYPolarDomain(QObject *object = 0);
42 virtual ~XYPolarDomain();
43
44 DomainType type(){ return AbstractDomain::XYPolarDomain;}
45
46 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
47
48 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYPolarDomain &Domain1, const XYPolarDomain &Domain2);
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XYPolarDomain &Domain1, const XYPolarDomain &Domain2);
50 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XYPolarDomain &AbstractDomain);
51
52 void zoomIn(const QRectF &rect);
53 void zoomOut(const QRectF &rect);
54 void move(qreal dx, qreal dy);
55
56 QPointF calculateDomainPoint(const QPointF &point) const;
57
58 protected:
59 qreal toAngularCoordinate(qreal value, bool &ok) const;
60 qreal toRadialCoordinate(qreal value, bool &ok) const;
61 };
62
63 QTCOMMERCIALCHART_END_NAMESPACE
64
65 #endif // XYPOLARDOMAIN_H
@@ -0,0 +1,197
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "abstractchartlayout_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlegend_p.h"
24 #include "chartaxiselement_p.h"
25 #include "charttitle_p.h"
26 #include "chartbackground_p.h"
27 #include <QDebug>
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31 static const qreal golden_ratio = 0.4;
32
33 AbstractChartLayout::AbstractChartLayout(ChartPresenter *presenter)
34 : m_presenter(presenter),
35 m_margins(20, 20, 20, 20),
36 m_minChartRect(0, 0, 200, 200)
37 {
38 }
39
40 AbstractChartLayout::~AbstractChartLayout()
41 {
42 }
43
44 void AbstractChartLayout::setGeometry(const QRectF &rect)
45 {
46 if (!rect.isValid())
47 return;
48
49 QList<ChartAxisElement *> axes = m_presenter->axisItems();
50 ChartTitle *title = m_presenter->titleElement();
51 QLegend *legend = m_presenter->legend();
52 ChartBackground *background = m_presenter->backgroundElement();
53
54 QRectF contentGeometry = calculateBackgroundGeometry(rect, background);
55
56 contentGeometry = calculateContentGeometry(contentGeometry);
57
58 if (title && title->isVisible())
59 contentGeometry = calculateTitleGeometry(contentGeometry, title);
60
61 if (legend->isAttachedToChart() && legend->isVisible())
62 contentGeometry = calculateLegendGeometry(contentGeometry, legend);
63
64 contentGeometry = calculateAxisGeometry(contentGeometry, axes);
65
66 m_presenter->setGeometry(contentGeometry);
67
68 QGraphicsLayout::setGeometry(rect);
69 }
70
71 QRectF AbstractChartLayout::calculateContentGeometry(const QRectF &geometry) const
72 {
73 return geometry.adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom());
74 }
75
76 QRectF AbstractChartLayout::calculateContentMinimum(const QRectF &minimum) const
77 {
78 return minimum.adjusted(0, 0, m_margins.left() + m_margins.right(), m_margins.top() + m_margins.bottom());
79 }
80
81
82 QRectF AbstractChartLayout::calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const
83 {
84 qreal left;
85 qreal top;
86 qreal right;
87 qreal bottom;
88 getContentsMargins(&left, &top, &right, &bottom);
89 QRectF backgroundGeometry = geometry.adjusted(left, top, -right, -bottom);
90 if (background)
91 background->setRect(backgroundGeometry);
92 return backgroundGeometry;
93 }
94
95 QRectF AbstractChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const
96 {
97 qreal left;
98 qreal top;
99 qreal right;
100 qreal bottom;
101 getContentsMargins(&left, &top, &right, &bottom);
102 return minimum.adjusted(0, 0, left + right, top + bottom);
103 }
104
105 QRectF AbstractChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const
106 {
107 QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1));
108 QRectF legendRect;
109 QRectF result;
110
111 switch (legend->alignment()) {
112 case Qt::AlignTop: {
113 legendRect = QRectF(geometry.topLeft(), QSizeF(geometry.width(), size.height()));
114 result = geometry.adjusted(0, legendRect.height(), 0, 0);
115 break;
116 }
117 case Qt::AlignBottom: {
118 legendRect = QRectF(QPointF(geometry.left(), geometry.bottom() - size.height()), QSizeF(geometry.width(), size.height()));
119 result = geometry.adjusted(0, 0, 0, -legendRect.height());
120 break;
121 }
122 case Qt::AlignLeft: {
123 qreal width = qMin(size.width(), geometry.width() * golden_ratio);
124 legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height()));
125 result = geometry.adjusted(width, 0, 0, 0);
126 break;
127 }
128 case Qt::AlignRight: {
129 qreal width = qMin(size.width(), geometry.width() * golden_ratio);
130 legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height()));
131 result = geometry.adjusted(0, 0, -width, 0);
132 break;
133 }
134 default: {
135 legendRect = QRectF(0, 0, 0, 0);
136 result = geometry;
137 break;
138 }
139 }
140
141 legend->setGeometry(legendRect);
142
143 return result;
144 }
145
146 QRectF AbstractChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const
147 {
148 QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1));
149 return geometry.adjusted(0, 0, minSize.width(), minSize.height());
150 }
151
152 QRectF AbstractChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const
153 {
154 title->setGeometry(geometry);
155 QPointF center = geometry.center() - title->boundingRect().center();
156 title->setPos(center.x(), title->pos().y());
157 return geometry.adjusted(0, title->boundingRect().height()+1, 0, 0);
158 }
159
160 QRectF AbstractChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const
161 {
162 QSizeF min = title->sizeHint(Qt::MinimumSize);
163 return minimum.adjusted(0, 0, min.width(), min.height());
164 }
165
166 QSizeF AbstractChartLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
167 {
168 Q_UNUSED(constraint);
169 if (which == Qt::MinimumSize) {
170 QList<ChartAxisElement *> axes = m_presenter->axisItems();
171 ChartTitle *title = m_presenter->titleElement();
172 QLegend *legend = m_presenter->legend();
173 QRectF minimumRect(0, 0, 0, 0);
174 minimumRect = calculateBackgroundMinimum(minimumRect);
175 minimumRect = calculateContentMinimum(minimumRect);
176 minimumRect = calculateTitleMinimum(minimumRect, title);
177 minimumRect = calculateLegendMinimum(minimumRect, legend);
178 minimumRect = calculateAxisMinimum(minimumRect, axes);
179 return minimumRect.united(m_minChartRect).size().toSize();
180 }
181 return QSize(-1, -1);
182 }
183
184 void AbstractChartLayout::setMargins(const QMargins &margins)
185 {
186 if (m_margins != margins) {
187 m_margins = margins;
188 updateGeometry();
189 }
190 }
191
192 QMargins AbstractChartLayout::margins() const
193 {
194 return m_margins;
195 }
196
197 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,50
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef CARTESIANCHARTLAYOUT_H
31 #define CARTESIANCHARTLAYOUT_H
32
33 #include "abstractchartlayout_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class CartesianChartLayout : public AbstractChartLayout
38 {
39 public:
40 CartesianChartLayout(ChartPresenter *presenter);
41 virtual ~CartesianChartLayout();
42
43 // from AbstractChartLayout
44 QRectF calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const;
45 QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxisElement *> &axes) const;
46 };
47
48 QTCOMMERCIALCHART_END_NAMESPACE
49
50 #endif // CARTESIANCHARTLAYOUT_H
@@ -0,0 +1,12
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
3
4 SOURCES += \
5 $$PWD/abstractchartlayout.cpp \
6 $$PWD/cartesianchartlayout.cpp \
7 $$PWD/polarchartlayout.cpp
8
9 PRIVATE_HEADERS += \
10 $$PWD/abstractchartlayout_p.h \
11 $$PWD/cartesianchartlayout_p.h \
12 $$PWD/polarchartlayout_p.h
@@ -0,0 +1,83
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "polarchartlayout_p.h"
22 #include "chartpresenter_p.h"
23 #include "polarchartaxis_p.h"
24 #include <QDebug>
25 #include <QFontMetrics>
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29 static const qreal golden_ratio = 0.4;
30
31 PolarChartLayout::PolarChartLayout(ChartPresenter *presenter)
32 : AbstractChartLayout(presenter)
33 {
34 }
35
36 PolarChartLayout::~PolarChartLayout()
37 {
38 }
39
40 QRectF PolarChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxisElement *> &axes) const
41 {
42 // How to handle multiple angular/radial axes?
43 qreal axisRadius = geometry.height() / 2.0;
44 if (geometry.width() < geometry.height())
45 axisRadius = geometry.width() / 2.0;
46
47 int titleHeight = 0;
48 foreach (ChartAxisElement *chartAxis, axes) {
49 if (!chartAxis->isVisible())
50 continue;
51
52 PolarChartAxis *polarChartAxis = static_cast<PolarChartAxis *>(chartAxis);
53 qreal radius = polarChartAxis->preferredAxisRadius(geometry.size());
54 if (radius < axisRadius)
55 axisRadius = radius;
56
57 if (chartAxis->axis()->orientation() == Qt::Horizontal
58 && chartAxis->axis()->isTitleVisible()
59 && !chartAxis->axis()->titleText().isEmpty()) {
60 // If axis has angular title, adjust geometry down by the space title takes
61 QFontMetrics titleMetrics(chartAxis->axis()->titleFont());
62 titleHeight = (titleMetrics.boundingRect(chartAxis->axis()->titleText()).height() / 2) + chartAxis->titlePadding();
63 }
64 }
65
66 QRectF axisRect;
67 axisRect.setSize(QSizeF(axisRadius * 2.0, axisRadius * 2.0));
68 axisRect.moveCenter(geometry.center());
69 axisRect.adjust(0, titleHeight, 0, titleHeight);
70
71 foreach (ChartAxisElement *chartAxis, axes)
72 chartAxis->setGeometry(axisRect, QRectF());
73
74 return axisRect;
75 }
76
77 QRectF PolarChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const
78 {
79 Q_UNUSED(axes);
80 return minimum;
81 }
82
83 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,50
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef POLARCHARTLAYOUT_H
31 #define POLARCHARTLAYOUT_H
32
33 #include "abstractchartlayout_p.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class PolarChartLayout : public AbstractChartLayout
38 {
39 public:
40 PolarChartLayout(ChartPresenter *presenter);
41 virtual ~PolarChartLayout();
42
43 // from AbstractChartLayout
44 QRectF calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const;
45 QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxisElement *> &axes) const;
46 };
47
48 QTCOMMERCIALCHART_END_NAMESPACE
49
50 #endif // POLARCHARTLAYOUT_H
@@ -0,0 +1,126
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "qpolarchart.h"
22 #include "qabstractaxis.h"
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
26 /*!
27 \enum QPolarChart::PolarOrientation
28
29 This type is used to signify the polar orientation of an axis.
30
31 \value PolarOrientationRadial
32 \value PolarOrientationAngular
33 */
34
35 /*!
36 \class QPolarChart
37 \brief QtCommercial chart API.
38
39 QPolarChart is a specialization of QChart to show a polar chart.
40
41 Polar charts support line, spline, area, and scatter series, and all axis types
42 supported by those series.
43
44 \note When setting ticks to an angular QValueAxis, keep in mind that the first and last tick
45 are co-located at 0/360 degree angle.
46
47 \note If the angular distance between two consecutive points in a series is more than 180 degrees,
48 any line connecting the two points becomes meaningless, so choose the axis ranges accordingly
49 when displaying line, spline, or area series.
50
51 \note Polar charts do not support multiple axes of same orientation.
52
53 \sa QChart
54 */
55
56 /*!
57 Constructs a polar chart as a child of a \a parent.
58 Parameter \a wFlags is passed to the QChart constructor.
59 */
60 QPolarChart::QPolarChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
61 : QChart(QChart::ChartTypePolar, parent, wFlags)
62 {
63 }
64
65 /*!
66 Destroys the object and it's children, like series and axis objects added to it.
67 */
68 QPolarChart::~QPolarChart()
69 {
70 }
71
72 /*!
73 Returns the axes added for the \a series with \a polarOrientation. If no series is provided, then any axis with the
74 specified polar orientation is returned.
75 \sa addAxis()
76 */
77 QList<QAbstractAxis *> QPolarChart::axes(PolarOrientations polarOrientation, QAbstractSeries *series) const
78 {
79 Qt::Orientations orientation(0);
80 if (polarOrientation.testFlag(PolarOrientationAngular))
81 orientation |= Qt::Horizontal;
82 if (polarOrientation.testFlag(PolarOrientationRadial))
83 orientation |= Qt::Vertical;
84
85 return QChart::axes(orientation, series);
86 }
87
88 /*!
89 This convenience method adds \a axis to the polar chart with \a polarOrientation.
90 The chart takes the ownership of the axis.
91
92 \note Axes can be added to a polar chart also with QChart::addAxis() instead of this method.
93 The specified alignment determines the polar orientation: horizontal alignments indicate angular
94 axis and vertical alignments indicate radial axis.
95 \sa QChart::removeAxis(), QChart::createDefaultAxes(), QAbstractSeries::attachAxis(), QChart::addAxis()
96 */
97 void QPolarChart::addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation)
98 {
99 if (!axis || axis->type() == QAbstractAxis::AxisTypeBarCategory) {
100 qWarning("QAbstractAxis::AxisTypeBarCategory is not a supported axis type for polar charts.");
101 } else {
102 Qt::Alignment alignment = Qt::AlignLeft;
103 if (polarOrientation == PolarOrientationAngular)
104 alignment = Qt::AlignBottom;
105 QChart::addAxis(axis, alignment);
106 }
107 }
108
109 /*!
110 Angular axes of a polar chart report horizontal orientation and radial axes report
111 vertical orientation.
112 This function is a convenience function for converting the orientation of an \a axis to
113 corresponding polar orientation. If the \a axis is NULL or not added to a polar chart,
114 the return value is meaningless.
115 */
116 QPolarChart::PolarOrientation QPolarChart::axisPolarOrientation(QAbstractAxis *axis)
117 {
118 if (axis && axis->orientation() == Qt::Horizontal)
119 return PolarOrientationAngular;
120 else
121 return PolarOrientationRadial;
122 }
123
124 #include "moc_qpolarchart.cpp"
125
126 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,60
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef QPOLARCHART_H
22 #define QPOLARCHART_H
23
24 #include "qchart.h"
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 class QAbstractSeries;
29 class QAbstractAxis;
30
31 class QTCOMMERCIALCHART_EXPORT QPolarChart : public QChart
32 {
33 Q_OBJECT
34 Q_ENUMS(PolarOrientation)
35 Q_FLAGS(PolarOrientations)
36
37 public:
38 enum PolarOrientation {
39 PolarOrientationRadial = 0x1,
40 PolarOrientationAngular = 0x2
41 };
42 Q_DECLARE_FLAGS(PolarOrientations, PolarOrientation)
43
44 public:
45 explicit QPolarChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
46 ~QPolarChart();
47
48 void addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation);
49
50 QList<QAbstractAxis*> axes(PolarOrientations polarOrientation = PolarOrientations(PolarOrientationRadial | PolarOrientationAngular), QAbstractSeries *series = 0) const;
51
52 static PolarOrientation axisPolarOrientation(QAbstractAxis *axis);
53
54 protected:
55 Q_DISABLE_COPY(QPolarChart)
56 };
57
58 QTCOMMERCIALCHART_END_NAMESPACE
59
60 #endif // QCHART_H
@@ -0,0 +1,9
1 Testing polar chart:
2
3 Since the tests typically initialize the chart once for the whole test case,
4 it is difficult to test the components against polar chart unless all tests
5 are duplicated or massively refactored. Neither option is desirable, so instead
6 we check environment variable TEST_POLAR_CHART. If it is not empty, we run
7 the tests that are relevant for polar chart against polar chart. Unfortunately
8 This means two runs of the tests with different environment are required for
9 full coverage.
@@ -0,0 +1,58
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "chartview.h"
22 #include <QMouseEvent>
23 #include <QDebug>
24 #include <QAbstractAxis>
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
28 ChartView::ChartView(QWidget *parent) :
29 QChartView(parent)
30 {
31 }
32
33 void ChartView::keyPressEvent(QKeyEvent *event)
34 {
35 switch (event->key()) {
36 case Qt::Key_Plus:
37 chart()->zoomIn();
38 break;
39 case Qt::Key_Minus:
40 chart()->zoomOut();
41 break;
42 case Qt::Key_Left:
43 chart()->scroll(-1.0, 0);
44 break;
45 case Qt::Key_Right:
46 chart()->scroll(1.0, 0);
47 break;
48 case Qt::Key_Up:
49 chart()->scroll(0, 1.0);
50 break;
51 case Qt::Key_Down:
52 chart()->scroll(0, -1.0);
53 break;
54 default:
55 QGraphicsView::keyPressEvent(event);
56 break;
57 }
58 }
@@ -0,0 +1,38
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef CHARTVIEW_H
22 #define CHARTVIEW_H
23
24 #include <QChartView>
25 #include <QPolarChart>
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
29 class ChartView : public QChartView
30 {
31 public:
32 ChartView(QWidget *parent = 0);
33
34 protected:
35 void keyPressEvent(QKeyEvent *event);
36 };
37
38 #endif
@@ -0,0 +1,31
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "mainwindow.h"
22 #include <QApplication>
23
24 int main(int argc, char *argv[])
25 {
26 QApplication a(argc, argv);
27 MainWindow w;
28 w.show();
29
30 return a.exec();
31 }
This diff has been collapsed as it changes many lines, (1136 lines changed) Show them Hide them
@@ -0,0 +1,1136
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "mainwindow.h"
22 #include "chartview.h"
23 #include <QScatterSeries>
24 #include <QLineSeries>
25 #include <QSplineSeries>
26 #include <QAreaSeries>
27 #include <QBarSeries>
28 #include <QBarSet>
29 #include <QValueAxis>
30 #include <QLogValueAxis>
31 #include <QDateTimeAxis>
32 #include <QCategoryAxis>
33 #include <QPolarChart>
34 #include <QDebug>
35 #include <qmath.h>
36 #include <QDateTime>
37
38 QTCOMMERCIALCHART_USE_NAMESPACE
39 #include "ui_mainwindow.h"
40
41 MainWindow::MainWindow(QWidget *parent) :
42 QMainWindow(parent),
43 ui(new Ui::MainWindow),
44 m_angularTickCount(9),
45 m_radialTickCount(11),
46 m_labelsAngle(0),
47 m_angularMin(0.0),
48 m_angularMax(40000.0),
49 m_radialMin(0.0),
50 m_radialMax(30000.0),
51 m_angularShadesVisible(false),
52 m_radialShadesVisible(false),
53 m_labelsVisible(true),
54 m_titleVisible(true),
55 m_gridVisible(true),
56 m_arrowVisible(true),
57 m_angularShadesBrush(new QBrush(Qt::NoBrush)),
58 m_radialShadesBrush(new QBrush(Qt::NoBrush)),
59 m_labelBrush(new QBrush(Qt::black)),
60 m_titleBrush(new QBrush(Qt::black)),
61 m_angularShadesPen(new QPen(Qt::NoPen)),
62 m_radialShadesPen(new QPen(Qt::NoPen)),
63 m_labelPen(new QPen(Qt::NoPen)),
64 m_titlePen(new QPen(Qt::NoPen)),
65 m_gridPen(new QPen(QRgb(0x010101))), // Note: Pure black is default color, so it gets overridden by
66 m_arrowPen(new QPen(QRgb(0x010101))), // default theme if set to that initially. This is an example of workaround.
67 m_labelFormat(QString("%.2f")),
68 m_animationOptions(QChart::NoAnimation),
69 m_angularTitle(QString("Angular Title")),
70 m_radialTitle(QString("Radial Title")),
71 m_base(2.0),
72 m_chart(0),
73 m_angularAxis(0),
74 m_radialAxis(0),
75 m_angularAxisMode(AxisModeNone),
76 m_radialAxisMode(AxisModeNone),
77 m_series1(0),
78 m_series2(0),
79 m_series3(0),
80 m_series4(0),
81 m_series5(0),
82 m_series6(0),
83 m_series7(0),
84 m_dateFormat(QString("mm-ss-zzz")),
85 m_moreCategories(false)
86 {
87 ui->setupUi(this);
88
89 ui->angularTicksSpin->setValue(m_angularTickCount);
90 ui->radialTicksSpin->setValue(m_radialTickCount);
91 ui->anglesSpin->setValue(m_labelsAngle);
92 ui->radialMinSpin->setValue(m_radialMin);
93 ui->radialMaxSpin->setValue(m_radialMax);
94 ui->angularMinSpin->setValue(m_angularMin);
95 ui->angularMaxSpin->setValue(m_angularMax);
96 ui->angularShadesComboBox->setCurrentIndex(0);
97 ui->radialShadesComboBox->setCurrentIndex(0);
98 ui->labelFormatEdit->setText(m_labelFormat);
99 ui->dateFormatEdit->setText(m_dateFormat);
100 ui->moreCategoriesCheckBox->setChecked(m_moreCategories);
101
102 ui->series1checkBox->setChecked(true);
103 ui->series2checkBox->setChecked(true);
104 ui->series3checkBox->setChecked(true);
105 ui->series4checkBox->setChecked(true);
106 ui->series5checkBox->setChecked(true);
107 ui->series6checkBox->setChecked(true);
108 ui->series7checkBox->setChecked(true);
109
110 m_currentLabelFont.setFamily(ui->labelFontComboBox->currentFont().family());
111 m_currentLabelFont.setPixelSize(15);
112 m_currentTitleFont.setFamily(ui->titleFontComboBox->currentFont().family());
113 m_currentTitleFont.setPixelSize(30);
114
115 ui->labelFontSizeSpin->setValue(m_currentLabelFont.pixelSize());
116 ui->titleFontSizeSpin->setValue(m_currentTitleFont.pixelSize());
117
118 ui->logBaseSpin->setValue(m_base);
119
120 initXYValueChart();
121 setAngularAxis(AxisModeValue);
122 setRadialAxis(AxisModeValue);
123
124 ui->angularAxisComboBox->setCurrentIndex(int(m_angularAxisMode));
125 ui->radialAxisComboBox->setCurrentIndex(int(m_radialAxisMode));
126
127 connect(ui->angularTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(angularTicksChanged(int)));
128 connect(ui->radialTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(radialTicksChanged(int)));
129 connect(ui->anglesSpin, SIGNAL(valueChanged(int)), this, SLOT(anglesChanged(int)));
130 connect(ui->radialMinSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMinChanged(double)));
131 connect(ui->radialMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMaxChanged(double)));
132 connect(ui->angularMinSpin, SIGNAL(valueChanged(double)), this, SLOT(angularMinChanged(double)));
133 connect(ui->angularMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(angularMaxChanged(double)));
134 connect(ui->angularShadesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularShadesIndexChanged(int)));
135 connect(ui->radialShadesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(radialShadesIndexChanged(int)));
136 connect(ui->animationsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(animationIndexChanged(int)));
137 connect(ui->labelFormatEdit, SIGNAL(textEdited(QString)), this, SLOT(labelFormatEdited(QString)));
138 connect(ui->labelFontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(labelFontChanged(QFont)));
139 connect(ui->labelFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(labelFontSizeChanged(int)));
140 connect(ui->labelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(labelsIndexChanged(int)));
141 connect(ui->titleFontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(titleFontChanged(QFont)));
142 connect(ui->titleFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(titleFontSizeChanged(int)));
143 connect(ui->titleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(titleIndexChanged(int)));
144 connect(ui->gridComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(gridIndexChanged(int)));
145 connect(ui->arrowComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(arrowIndexChanged(int)));
146 connect(ui->logBaseSpin, SIGNAL(valueChanged(double)), this, SLOT(logBaseChanged(double)));
147 connect(ui->angularAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularAxisIndexChanged(int)));
148 connect(ui->radialAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(radialAxisIndexChanged(int)));
149 connect(ui->niceNumbersCheckBox, SIGNAL(clicked()), this, SLOT(niceNumbersChecked()));
150 connect(ui->dateFormatEdit, SIGNAL(textEdited(QString)), this, SLOT(dateFormatEdited(QString)));
151 connect(ui->moreCategoriesCheckBox, SIGNAL(clicked()), this, SLOT(moreCategoriesChecked()));
152 connect(ui->series1checkBox, SIGNAL(clicked()), this, SLOT(series1CheckBoxChecked()));
153 connect(ui->series2checkBox, SIGNAL(clicked()), this, SLOT(series2CheckBoxChecked()));
154 connect(ui->series3checkBox, SIGNAL(clicked()), this, SLOT(series3CheckBoxChecked()));
155 connect(ui->series4checkBox, SIGNAL(clicked()), this, SLOT(series4CheckBoxChecked()));
156 connect(ui->series5checkBox, SIGNAL(clicked()), this, SLOT(series5CheckBoxChecked()));
157 connect(ui->series6checkBox, SIGNAL(clicked()), this, SLOT(series6CheckBoxChecked()));
158 connect(ui->series7checkBox, SIGNAL(clicked()), this, SLOT(series7CheckBoxChecked()));
159 connect(ui->themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(themeIndexChanged(int)));
160
161 ui->chartView->setChart(m_chart);
162 ui->chartView->setRenderHint(QPainter::Antialiasing);
163 }
164
165 MainWindow::~MainWindow()
166 {
167 delete ui;
168 delete m_angularShadesBrush;
169 delete m_radialShadesBrush;
170 delete m_angularShadesPen;
171 delete m_radialShadesPen;
172 }
173
174 void MainWindow::initXYValueChart()
175 {
176 qreal seriesAngularMin = 1;
177 qreal seriesAngularMax = 46000;
178 qreal seriesRadialMin = 1;
179 qreal seriesRadialMax = 23500;
180 qreal radialDimension = seriesRadialMax - seriesRadialMin;
181 qreal angularDimension = seriesAngularMax - seriesAngularMin;
182
183 // Scatter series, points outside min-max ranges should not be drawn
184 m_series1 = new QScatterSeries();
185 m_series1->setName("scatter");
186 qreal scatterCount = 10;
187 qreal scatterAngularStep = angularDimension / scatterCount;
188 qreal scatterRadialStep = radialDimension / scatterCount;
189 for (qreal i = 0.0; i < scatterCount; i++) {
190 m_series1->append((i * scatterAngularStep) + seriesAngularMin, (i * scatterRadialStep) + seriesRadialMin);
191 //qDebug() << m_series1->points().last();
192 }
193 m_series1->setMarkerSize(10);
194 *m_series1 << QPointF(50, 50) << QPointF(150, 150) << QPointF(250, 250) << QPointF(350, 350) << QPointF(450, 450);
195 *m_series1 << QPointF(1050, 0.50) << QPointF(1150, 0.25) << QPointF(1250, 0.12) << QPointF(1350, 0.075) << QPointF(1450, 0.036);
196 *m_series1 << QPointF(0.50, 2000) << QPointF(0.25, 3500) << QPointF(0.12, 5000) << QPointF(0.075, 6500) << QPointF(0.036, 8000);
197
198 // Line series, points outside min-max ranges should not be drawn,
199 // but lines should be properly interpolated at chart edges
200 m_series2 = new QLineSeries();
201 m_series2->setName("line 1");
202 qreal lineCount = 100;
203 qreal lineAngularStep = angularDimension / lineCount;
204 qreal lineRadialStep = radialDimension / lineCount;
205 for (qreal i = 0.0; i < lineCount; i++) {
206 m_series2->append((i * lineAngularStep) + seriesAngularMin, (i * lineRadialStep) + seriesRadialMin);
207 //qDebug() << m_series2->points().last();
208 }
209 QPen series2Pen = QPen(Qt::blue, 10);
210 //series2Pen.setStyle(Qt::DashDotDotLine);
211 m_series2->setPen(series2Pen);
212
213 m_series3 = new QLineSeries();
214 m_series3->setName("Area upper");
215 lineCount = 87;
216 lineAngularStep = angularDimension / lineCount;
217 lineRadialStep = radialDimension / lineCount;
218 for (qreal i = 1.0; i <= lineCount; i++) {
219 m_series3->append((i * lineAngularStep) + seriesAngularMin, (i * lineRadialStep) + seriesRadialMin + 200.0);
220 //qDebug() << m_series3->points().last();
221 }
222
223 m_series4 = new QLineSeries();
224 m_series4->setName("Area lower");
225 lineCount = 89;
226 lineAngularStep = angularDimension / lineCount;
227 lineRadialStep = radialDimension / lineCount;
228 for (qreal i = 1.0; i <= lineCount; i++) {
229 m_series4->append((i * lineAngularStep) + seriesAngularMin + 100.0, (i * lineRadialStep) + seriesRadialMin + i * 300.0);
230 //qDebug() << m_series4->points().last();
231 }
232
233 m_series5 = new QAreaSeries();
234 m_series5->setName("area");
235 m_series5->setUpperSeries(m_series3);
236 m_series5->setLowerSeries(m_series4);
237 m_series5->setOpacity(0.5);
238
239 m_series6 = new QSplineSeries();
240 m_series6->setName("spline");
241 qreal ad = angularDimension / 20;
242 qreal rd = radialDimension / 10;
243 m_series6->append(seriesAngularMin, seriesRadialMin + rd * 2);
244 m_series6->append(seriesAngularMin + ad, seriesRadialMin + rd * 5);
245 m_series6->append(seriesAngularMin + ad * 2, seriesRadialMin + rd * 4);
246 m_series6->append(seriesAngularMin + ad * 3, seriesRadialMin + rd * 9);
247 m_series6->append(seriesAngularMin + ad * 4, seriesRadialMin + rd * 11);
248 m_series6->append(seriesAngularMin + ad * 5, seriesRadialMin + rd * 12);
249 m_series6->append(seriesAngularMin + ad * 6, seriesRadialMin + rd * 9);
250 m_series6->append(seriesAngularMin + ad * 7, seriesRadialMin + rd * 11);
251 m_series6->append(seriesAngularMin + ad * 8, seriesRadialMin + rd * 12);
252 m_series6->append(seriesAngularMin + ad * 9, seriesRadialMin + rd * 6);
253 m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 4);
254 m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 8);
255 m_series6->append(seriesAngularMin + ad * 11, seriesRadialMin + rd * 9);
256 m_series6->append(seriesAngularMin + ad * 12, seriesRadialMin + rd * 11);
257 m_series6->append(seriesAngularMin + ad * 13, seriesRadialMin + rd * 12);
258 m_series6->append(seriesAngularMin + ad * 14, seriesRadialMin + rd * 6);
259 m_series6->append(seriesAngularMin + ad * 15, seriesRadialMin + rd * 3);
260 m_series6->append(seriesAngularMin + ad * 16, seriesRadialMin + rd * 2);
261 m_series6->append(seriesAngularMin + ad * 17, seriesRadialMin + rd * 6);
262 m_series6->append(seriesAngularMin + ad * 18, seriesRadialMin + rd * 6);
263 m_series6->append(seriesAngularMin + ad * 19, seriesRadialMin + rd * 6);
264 m_series6->append(seriesAngularMin + ad * 20, seriesRadialMin + rd * 6);
265 m_series6->append(seriesAngularMin + ad * 19, seriesRadialMin + rd * 2);
266 m_series6->append(seriesAngularMin + ad * 18, seriesRadialMin + rd * 9);
267 m_series6->append(seriesAngularMin + ad * 17, seriesRadialMin + rd * 7);
268 m_series6->append(seriesAngularMin + ad * 16, seriesRadialMin + rd * 3);
269 m_series6->append(seriesAngularMin + ad * 15, seriesRadialMin + rd * 1);
270 m_series6->append(seriesAngularMin + ad * 14, seriesRadialMin + rd * 7);
271 m_series6->append(seriesAngularMin + ad * 13, seriesRadialMin + rd * 5);
272 m_series6->append(seriesAngularMin + ad * 12, seriesRadialMin + rd * 9);
273 m_series6->append(seriesAngularMin + ad * 11, seriesRadialMin + rd * 1);
274 m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 4);
275 m_series6->append(seriesAngularMin + ad * 9, seriesRadialMin + rd * 1);
276 m_series6->append(seriesAngularMin + ad * 8, seriesRadialMin + rd * 2);
277 m_series6->append(seriesAngularMin + ad * 7, seriesRadialMin + rd * 4);
278 m_series6->append(seriesAngularMin + ad * 6, seriesRadialMin + rd * 8);
279 m_series6->append(seriesAngularMin + ad * 5, seriesRadialMin + rd * 12);
280 m_series6->append(seriesAngularMin + ad * 4, seriesRadialMin + rd * 9);
281 m_series6->append(seriesAngularMin + ad * 3, seriesRadialMin + rd * 8);
282 m_series6->append(seriesAngularMin + ad * 2, seriesRadialMin + rd * 7);
283 m_series6->append(seriesAngularMin + ad, seriesRadialMin + rd * 4);
284 m_series6->append(seriesAngularMin, seriesRadialMin + rd * 10);
285
286 m_series6->setPointsVisible(true);
287 QPen series6Pen = QPen(Qt::red, 10);
288 //series6Pen.setStyle(Qt::DashDotDotLine);
289 m_series6->setPen(series6Pen);
290
291 // m_series7 shows points at category intersections
292 m_series7 = new QScatterSeries();
293 m_series7->setName("Category check");
294 m_series7->setMarkerSize(7);
295 m_series7->setBrush(QColor(Qt::red));
296 m_series7->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
297 *m_series7 << QPointF(1000, 1000)
298 << QPointF(1000, 2000)
299 << QPointF(1000, 4000)
300 << QPointF(1000, 9000)
301 << QPointF(1000, 14000)
302 << QPointF(1000, 16500)
303 << QPointF(1000, 19000)
304
305 << QPointF(4000, 1000)
306 << QPointF(4000, 2000)
307 << QPointF(4000, 4000)
308 << QPointF(4000, 9000)
309 << QPointF(4000, 14000)
310 << QPointF(4000, 16500)
311 << QPointF(4000, 19000)
312
313 << QPointF(7000, 1000)
314 << QPointF(7000, 2000)
315 << QPointF(7000, 4000)
316 << QPointF(7000, 9000)
317 << QPointF(7000, 14000)
318 << QPointF(7000, 16500)
319 << QPointF(7000, 19000)
320
321 << QPointF(12000, 1000)
322 << QPointF(12000, 2000)
323 << QPointF(12000, 4000)
324 << QPointF(12000, 9000)
325 << QPointF(12000, 14000)
326 << QPointF(12000, 16500)
327 << QPointF(12000, 19000)
328
329 << QPointF(17000, 1000)
330 << QPointF(17000, 2000)
331 << QPointF(17000, 4000)
332 << QPointF(17000, 9000)
333 << QPointF(17000, 14000)
334 << QPointF(17000, 16500)
335 << QPointF(17000, 19000)
336
337 << QPointF(22000, 1000)
338 << QPointF(22000, 2000)
339 << QPointF(22000, 4000)
340 << QPointF(22000, 9000)
341 << QPointF(22000, 14000)
342 << QPointF(22000, 16500)
343 << QPointF(22000, 19000)
344
345 << QPointF(28000, 1000)
346 << QPointF(28000, 2000)
347 << QPointF(28000, 4000)
348 << QPointF(28000, 9000)
349 << QPointF(28000, 14000)
350 << QPointF(28000, 16500)
351 << QPointF(28000, 19000);
352
353 m_chart = new QPolarChart();
354
355 m_chart->addSeries(m_series1);
356 m_chart->addSeries(m_series2);
357 m_chart->addSeries(m_series3);
358 m_chart->addSeries(m_series4);
359 m_chart->addSeries(m_series5);
360 m_chart->addSeries(m_series6);
361 m_chart->addSeries(m_series7);
362
363 connect(m_series1, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF)));
364 connect(m_series2, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF)));
365 connect(m_series3, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF)));
366 connect(m_series4, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF)));
367 connect(m_series5, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF)));
368 connect(m_series6, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF)));
369 connect(m_series7, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF)));
370 connect(m_series1, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool)));
371 connect(m_series2, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool)));
372 connect(m_series3, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool)));
373 connect(m_series4, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool)));
374 connect(m_series5, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool)));
375 connect(m_series6, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool)));
376 connect(m_series7, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool)));
377
378 m_chart->setTitle("Use arrow keys to scroll and +/- to zoom");
379 m_chart->setAnimationOptions(m_animationOptions);
380 //m_chart->legend()->setVisible(false);
381 m_chart->setAcceptHoverEvents(true);
382 }
383
384 void MainWindow::setAngularAxis(MainWindow::AxisMode mode)
385 {
386 if (m_angularAxis) {
387 m_chart->removeAxis(m_angularAxis);
388 delete m_angularAxis;
389 m_angularAxis = 0;
390 }
391
392 m_angularAxisMode = mode;
393
394 switch (m_angularAxisMode) {
395 case AxisModeNone:
396 return;
397 case AxisModeValue:
398 m_angularAxis = new QValueAxis();
399 static_cast<QValueAxis *>(m_angularAxis)->setTickCount(m_angularTickCount);
400 static_cast<QValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat);
401 break;
402 case AxisModeLogValue:
403 m_angularAxis = new QLogValueAxis();
404 static_cast<QLogValueAxis *>(m_angularAxis)->setBase(m_base);
405 static_cast<QLogValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat);
406 break;
407 case AxisModeDateTime:
408 m_angularAxis = new QDateTimeAxis();
409 static_cast<QDateTimeAxis *>(m_angularAxis)->setTickCount(m_angularTickCount);
410 static_cast<QDateTimeAxis *>(m_angularAxis)->setFormat(m_dateFormat);
411 break;
412 case AxisModeCategory:
413 m_angularAxis = new QCategoryAxis();
414 applyCategories();
415 break;
416 default:
417 qWarning() << "Unsupported AxisMode";
418 break;
419 }
420
421 m_angularAxis->setLabelsAngle(m_labelsAngle);
422 m_angularAxis->setLabelsFont(m_currentLabelFont);
423 m_angularAxis->setLabelsBrush(*m_labelBrush);
424 m_angularAxis->setLabelsPen(*m_labelPen);
425 m_angularAxis->setLabelsVisible(m_labelsVisible);
426 m_angularAxis->setShadesBrush(*m_angularShadesBrush);
427 m_angularAxis->setShadesPen(*m_angularShadesPen);
428 m_angularAxis->setShadesVisible(m_angularShadesVisible);
429 m_angularAxis->setTitleFont(m_currentTitleFont);
430 m_angularAxis->setTitleBrush(*m_titleBrush);
431 m_angularAxis->setTitlePen(*m_titlePen);
432 m_angularAxis->setTitleVisible(m_titleVisible);
433 m_angularAxis->setTitleText(m_angularTitle);
434 m_angularAxis->setGridLinePen(*m_gridPen);
435 m_angularAxis->setGridLineVisible(m_gridVisible);
436 m_angularAxis->setLinePen(*m_arrowPen);
437 m_angularAxis->setLineVisible(m_arrowVisible);
438
439 m_chart->addAxis(m_angularAxis, QPolarChart::PolarOrientationAngular);
440
441 m_series1->attachAxis(m_angularAxis);
442 m_series2->attachAxis(m_angularAxis);
443 m_series3->attachAxis(m_angularAxis);
444 m_series4->attachAxis(m_angularAxis);
445 m_series5->attachAxis(m_angularAxis);
446 m_series6->attachAxis(m_angularAxis);
447 m_series7->attachAxis(m_angularAxis);
448
449 applyRanges();
450
451 //connect(m_angularAxis, SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(angularRangeChanged(qreal, qreal)));
452 }
453
454 void MainWindow::setRadialAxis(MainWindow::AxisMode mode)
455 {
456 if (m_radialAxis) {
457 m_chart->removeAxis(m_radialAxis);
458 delete m_radialAxis;
459 m_radialAxis = 0;
460 }
461
462 m_radialAxisMode = mode;
463
464 switch (m_radialAxisMode) {
465 case AxisModeNone:
466 return;
467 case AxisModeValue:
468 m_radialAxis = new QValueAxis();
469 static_cast<QValueAxis *>(m_radialAxis)->setTickCount(m_radialTickCount);
470 static_cast<QValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat);
471 break;
472 case AxisModeLogValue:
473 m_radialAxis = new QLogValueAxis();
474 static_cast<QLogValueAxis *>(m_radialAxis)->setBase(m_base);
475 static_cast<QLogValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat);
476 break;
477 case AxisModeDateTime:
478 m_radialAxis = new QDateTimeAxis();
479 static_cast<QDateTimeAxis *>(m_radialAxis)->setTickCount(m_radialTickCount);
480 static_cast<QDateTimeAxis *>(m_radialAxis)->setFormat(m_dateFormat);
481 break;
482 case AxisModeCategory:
483 m_radialAxis = new QCategoryAxis();
484 applyCategories();
485 break;
486 default:
487 qWarning() << "Unsupported AxisMode";
488 break;
489 }
490
491 m_radialAxis->setLabelsAngle(m_labelsAngle);
492 m_radialAxis->setLabelsFont(m_currentLabelFont);
493 m_radialAxis->setLabelsBrush(*m_labelBrush);
494 m_radialAxis->setLabelsPen(*m_labelPen);
495 m_radialAxis->setLabelsVisible(m_labelsVisible);
496 m_radialAxis->setShadesBrush(*m_radialShadesBrush);
497 m_radialAxis->setShadesPen(*m_radialShadesPen);
498 m_radialAxis->setShadesVisible(m_radialShadesVisible);
499 m_radialAxis->setTitleFont(m_currentTitleFont);
500 m_radialAxis->setTitleBrush(*m_titleBrush);
501 m_radialAxis->setTitlePen(*m_titlePen);
502 m_radialAxis->setTitleVisible(m_titleVisible);
503 m_radialAxis->setTitleText(m_radialTitle);
504 m_radialAxis->setGridLinePen(*m_gridPen);
505 m_radialAxis->setGridLineVisible(m_gridVisible);
506 m_radialAxis->setLinePen(*m_arrowPen);
507 m_radialAxis->setLineVisible(m_arrowVisible);
508
509 m_chart->addAxis(m_radialAxis, QPolarChart::PolarOrientationRadial);
510
511 m_series1->attachAxis(m_radialAxis);
512 m_series2->attachAxis(m_radialAxis);
513 m_series3->attachAxis(m_radialAxis);
514 m_series4->attachAxis(m_radialAxis);
515 m_series5->attachAxis(m_radialAxis);
516 m_series6->attachAxis(m_radialAxis);
517 m_series7->attachAxis(m_radialAxis);
518
519 applyRanges();
520
521 series1CheckBoxChecked();
522 series2CheckBoxChecked();
523 series3CheckBoxChecked();
524 series4CheckBoxChecked();
525 series5CheckBoxChecked();
526 series6CheckBoxChecked();
527 series7CheckBoxChecked();
528
529 //connect(m_radialAxis, SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(radialRangeChanged(qreal, qreal)));
530 }
531
532 void MainWindow::applyRanges()
533 {
534 if (ui->niceNumbersCheckBox->isChecked()) {
535 if (m_angularAxisMode == AxisModeValue) {
536 static_cast<QValueAxis *>(m_angularAxis)->applyNiceNumbers();
537 m_angularMin = static_cast<QValueAxis *>(m_angularAxis)->min();
538 m_angularMax = static_cast<QValueAxis *>(m_angularAxis)->max();
539 m_angularTickCount = static_cast<QValueAxis *>(m_angularAxis)->tickCount();
540 }
541 if (m_radialAxisMode == AxisModeValue) {
542 static_cast<QValueAxis *>(m_radialAxis)->applyNiceNumbers();
543 m_radialMin = static_cast<QValueAxis *>(m_radialAxis)->min();
544 m_radialMax = static_cast<QValueAxis *>(m_radialAxis)->max();
545 m_radialTickCount = static_cast<QValueAxis *>(m_radialAxis)->tickCount();
546 }
547 }
548
549 if (m_angularAxis)
550 m_angularAxis->setRange(m_angularMin, m_angularMax);
551 if (m_radialAxis)
552 m_radialAxis->setRange(m_radialMin, m_radialMax);
553 }
554
555 void MainWindow::angularTicksChanged(int value)
556 {
557 m_angularTickCount = value;
558 if (m_angularAxisMode == AxisModeValue)
559 static_cast<QValueAxis *>(m_angularAxis)->setTickCount(m_angularTickCount);
560 else if (m_angularAxisMode == AxisModeDateTime)
561 static_cast<QDateTimeAxis *>(m_angularAxis)->setTickCount(m_angularTickCount);
562 }
563
564 void MainWindow::radialTicksChanged(int value)
565 {
566 m_radialTickCount = value;
567 if (m_radialAxisMode == AxisModeValue)
568 static_cast<QValueAxis *>(m_radialAxis)->setTickCount(m_radialTickCount);
569 else if (m_radialAxisMode == AxisModeDateTime)
570 static_cast<QDateTimeAxis *>(m_radialAxis)->setTickCount(m_radialTickCount);
571 }
572
573 void MainWindow::anglesChanged(int value)
574 {
575 m_labelsAngle = value;
576 m_radialAxis->setLabelsAngle(m_labelsAngle);
577 m_angularAxis->setLabelsAngle(m_labelsAngle);
578 }
579
580 void MainWindow::angularMinChanged(double value)
581 {
582 m_angularMin = value;
583 if (m_angularAxisMode != AxisModeDateTime) {
584 m_angularAxis->setMin(m_angularMin);
585 } else {
586 QDateTime dateTime;
587 dateTime.setMSecsSinceEpoch(qint64(m_angularMin));
588 m_angularAxis->setMin(dateTime);
589 }
590 }
591
592 void MainWindow::angularMaxChanged(double value)
593 {
594 m_angularMax = value;
595 if (m_angularAxisMode != AxisModeDateTime) {
596 m_angularAxis->setMax(m_angularMax);
597 } else {
598 QDateTime dateTime;
599 dateTime.setMSecsSinceEpoch(qint64(m_angularMax));
600 m_angularAxis->setMax(dateTime);
601 }
602 }
603
604 void MainWindow::radialMinChanged(double value)
605 {
606 m_radialMin = value;
607 if (m_radialAxisMode != AxisModeDateTime) {
608 m_radialAxis->setMin(m_radialMin);
609 } else {
610 QDateTime dateTime;
611 dateTime.setMSecsSinceEpoch(qint64(m_radialMin));
612 m_radialAxis->setMin(dateTime);
613 }
614 }
615
616 void MainWindow::radialMaxChanged(double value)
617 {
618 m_radialMax = value;
619 if (m_radialAxisMode != AxisModeDateTime) {
620 m_radialAxis->setMax(m_radialMax);
621 } else {
622 QDateTime dateTime;
623 dateTime.setMSecsSinceEpoch(qint64(m_radialMax));
624 m_radialAxis->setMax(dateTime);
625 }
626 }
627
628 void MainWindow::angularShadesIndexChanged(int index)
629 {
630 delete m_angularShadesBrush;
631 delete m_angularShadesPen;
632
633 switch (index) {
634 case 0:
635 m_angularShadesBrush = new QBrush(Qt::NoBrush);
636 m_angularShadesPen = new QPen(Qt::NoPen);
637 m_angularShadesVisible = false;
638 break;
639 case 1:
640 m_angularShadesBrush = new QBrush(Qt::lightGray);
641 m_angularShadesPen = new QPen(Qt::NoPen);
642 m_angularShadesVisible = true;
643 break;
644 case 2:
645 m_angularShadesBrush = new QBrush(Qt::yellow);
646 m_angularShadesPen = new QPen(Qt::DotLine);
647 m_angularShadesPen->setWidth(2);
648 m_angularShadesVisible = true;
649 break;
650 default:
651 break;
652 }
653
654 m_angularAxis->setShadesBrush(*m_angularShadesBrush);
655 m_angularAxis->setShadesPen(*m_angularShadesPen);
656 m_angularAxis->setShadesVisible(m_angularShadesVisible);
657 }
658
659 void MainWindow::radialShadesIndexChanged(int index)
660 {
661 delete m_radialShadesBrush;
662 delete m_radialShadesPen;
663
664 switch (index) {
665 case 0:
666 m_radialShadesBrush = new QBrush(Qt::NoBrush);
667 m_radialShadesPen = new QPen(Qt::NoPen);
668 m_radialShadesVisible = false;
669 break;
670 case 1:
671 m_radialShadesBrush = new QBrush(Qt::green);
672 m_radialShadesPen = new QPen(Qt::NoPen);
673 m_radialShadesVisible = true;
674 break;
675 case 2:
676 m_radialShadesBrush = new QBrush(Qt::blue);
677 m_radialShadesPen = new QPen(Qt::DotLine);
678 m_radialShadesPen->setWidth(2);
679 m_radialShadesVisible = true;
680 break;
681 default:
682 break;
683 }
684
685 m_radialAxis->setShadesBrush(*m_radialShadesBrush);
686 m_radialAxis->setShadesPen(*m_radialShadesPen);
687 m_radialAxis->setShadesVisible(m_radialShadesVisible);
688 }
689
690 void MainWindow::labelFormatEdited(const QString &text)
691 {
692 m_labelFormat = text;
693 if (m_angularAxisMode == AxisModeValue)
694 static_cast<QValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat);
695 else if (m_angularAxisMode == AxisModeLogValue)
696 static_cast<QLogValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat);
697
698 if (m_radialAxisMode == AxisModeValue)
699 static_cast<QValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat);
700 else if (m_radialAxisMode == AxisModeLogValue)
701 static_cast<QLogValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat);
702 }
703
704 void MainWindow::labelFontChanged(const QFont &font)
705 {
706 m_currentLabelFont = font;
707 m_currentLabelFont.setPixelSize(ui->labelFontSizeSpin->value());
708 m_angularAxis->setLabelsFont(m_currentLabelFont);
709 m_radialAxis->setLabelsFont(m_currentLabelFont);
710 }
711
712 void MainWindow::labelFontSizeChanged(int value)
713 {
714 m_currentLabelFont = ui->labelFontComboBox->currentFont();
715 m_currentLabelFont.setPixelSize(value);
716 m_angularAxis->setLabelsFont(m_currentLabelFont);
717 m_radialAxis->setLabelsFont(m_currentLabelFont);
718 }
719
720 void MainWindow::animationIndexChanged(int index)
721 {
722 switch (index) {
723 case 0:
724 m_animationOptions = QChart::NoAnimation;
725 break;
726 case 1:
727 m_animationOptions = QChart::SeriesAnimations;
728 break;
729 case 2:
730 m_animationOptions = QChart::GridAxisAnimations;
731 break;
732 case 3:
733 m_animationOptions = QChart::AllAnimations;
734 break;
735 default:
736 break;
737 }
738
739 m_chart->setAnimationOptions(m_animationOptions);
740 }
741
742 void MainWindow::labelsIndexChanged(int index)
743 {
744 delete m_labelBrush;
745 delete m_labelPen;
746
747 switch (index) {
748 case 0:
749 m_labelBrush = new QBrush(Qt::NoBrush);
750 m_labelPen = new QPen(Qt::NoPen);
751 m_labelsVisible = false;
752 break;
753 case 1:
754 m_labelBrush = new QBrush(Qt::black);
755 m_labelPen = new QPen(Qt::NoPen);
756 m_labelsVisible = true;
757 break;
758 case 2:
759 m_labelBrush = new QBrush(Qt::white);
760 m_labelPen = new QPen(Qt::blue);
761 m_labelsVisible = true;
762 break;
763 default:
764 break;
765 }
766
767 m_radialAxis->setLabelsBrush(*m_labelBrush);
768 m_radialAxis->setLabelsPen(*m_labelPen);
769 m_radialAxis->setLabelsVisible(m_labelsVisible);
770 m_angularAxis->setLabelsBrush(*m_labelBrush);
771 m_angularAxis->setLabelsPen(*m_labelPen);
772 m_angularAxis->setLabelsVisible(m_labelsVisible);
773 }
774
775 void MainWindow::titleIndexChanged(int index)
776 {
777 delete m_titleBrush;
778 delete m_titlePen;
779
780 switch (index) {
781 case 0:
782 m_titleBrush = new QBrush(Qt::NoBrush);
783 m_titlePen = new QPen(Qt::NoPen);
784 m_titleVisible = false;
785 m_angularTitle = QString();
786 m_radialTitle = QString();
787 break;
788 case 1:
789 m_titleBrush = new QBrush(Qt::NoBrush);
790 m_titlePen = new QPen(Qt::NoPen);
791 m_titleVisible = true;
792 m_angularTitle = QString();
793 m_radialTitle = QString();
794 break;
795 case 2:
796 m_titleBrush = new QBrush(Qt::NoBrush);
797 m_titlePen = new QPen(Qt::NoPen);
798 m_titleVisible = false;
799 m_angularTitle = QString("Invisible Ang. Title!");
800 m_radialTitle = QString("Invisible Rad. Title!");
801 break;
802 case 3:
803 m_titleBrush = new QBrush(Qt::black);
804 m_titlePen = new QPen(Qt::NoPen);
805 m_titleVisible = true;
806 m_angularTitle = QString("Angular Title");
807 m_radialTitle = QString("Radial Title");
808 break;
809 case 4:
810 m_titleBrush = new QBrush(Qt::white);
811 m_titlePen = new QPen(Qt::blue);
812 m_titleVisible = true;
813 m_angularTitle = QString("Angular Blue Title");
814 m_radialTitle = QString("Radial Blue Title");
815 break;
816 default:
817 break;
818 }
819
820 m_radialAxis->setTitleBrush(*m_titleBrush);
821 m_radialAxis->setTitlePen(*m_titlePen);
822 m_radialAxis->setTitleVisible(m_titleVisible);
823 m_radialAxis->setTitleText(m_radialTitle);
824 m_angularAxis->setTitleBrush(*m_titleBrush);
825 m_angularAxis->setTitlePen(*m_titlePen);
826 m_angularAxis->setTitleVisible(m_titleVisible);
827 m_angularAxis->setTitleText(m_angularTitle);
828 }
829
830 void MainWindow::titleFontChanged(const QFont &font)
831 {
832 m_currentTitleFont = font;
833 m_currentTitleFont.setPixelSize(ui->titleFontSizeSpin->value());
834 m_angularAxis->setTitleFont(m_currentTitleFont);
835 m_radialAxis->setTitleFont(m_currentTitleFont);
836 }
837
838 void MainWindow::titleFontSizeChanged(int value)
839 {
840 m_currentTitleFont = ui->titleFontComboBox->currentFont();
841 m_currentTitleFont.setPixelSize(value);
842 m_angularAxis->setTitleFont(m_currentTitleFont);
843 m_radialAxis->setTitleFont(m_currentTitleFont);
844 }
845
846 void MainWindow::gridIndexChanged(int index)
847 {
848 delete m_gridPen;
849
850 switch (index) {
851 case 0:
852 m_gridPen = new QPen(Qt::NoPen);
853 m_gridVisible = false;
854 break;
855 case 1:
856 m_gridPen = new QPen(Qt::black);
857 m_gridVisible = true;
858 break;
859 case 2:
860 m_gridPen = new QPen(Qt::red);
861 m_gridPen->setStyle(Qt::DashDotLine);
862 m_gridPen->setWidth(3);
863 m_gridVisible = true;
864 break;
865 default:
866 break;
867 }
868
869 m_angularAxis->setGridLinePen(*m_gridPen);
870 m_angularAxis->setGridLineVisible(m_gridVisible);
871 m_radialAxis->setGridLinePen(*m_gridPen);
872 m_radialAxis->setGridLineVisible(m_gridVisible);
873 }
874
875 void MainWindow::arrowIndexChanged(int index)
876 {
877 delete m_arrowPen;
878
879 switch (index) {
880 case 0:
881 m_arrowPen = new QPen(Qt::NoPen);
882 m_arrowVisible = false;
883 break;
884 case 1:
885 m_arrowPen = new QPen(Qt::black);
886 m_arrowVisible = true;
887 break;
888 case 2:
889 m_arrowPen = new QPen(Qt::red);
890 m_arrowPen->setStyle(Qt::DashDotLine);
891 m_arrowPen->setWidth(3);
892 m_arrowVisible = true;
893 break;
894 default:
895 break;
896 }
897
898 m_angularAxis->setLinePen(*m_arrowPen);
899 m_angularAxis->setLineVisible(m_arrowVisible);
900 m_radialAxis->setLinePen(*m_arrowPen);
901 m_radialAxis->setLineVisible(m_arrowVisible);
902 }
903
904 void MainWindow::angularRangeChanged(qreal min, qreal max)
905 {
906 if (!qFuzzyCompare(ui->angularMinSpin->value(), min))
907 ui->angularMinSpin->setValue(min);
908 if (!qFuzzyCompare(ui->angularMaxSpin->value(), max))
909 ui->angularMaxSpin->setValue(max);
910 }
911
912 void MainWindow::radialRangeChanged(qreal min, qreal max)
913 {
914 if (!qFuzzyCompare(ui->radialMinSpin->value(), min))
915 ui->radialMinSpin->setValue(min);
916 if (!qFuzzyCompare(ui->radialMaxSpin->value(), max))
917 ui->radialMaxSpin->setValue(max);
918 }
919
920 void MainWindow::angularAxisIndexChanged(int index)
921 {
922 switch (index) {
923 case 0:
924 setAngularAxis(AxisModeNone);
925 break;
926 case 1:
927 setAngularAxis(AxisModeValue);
928 break;
929 case 2:
930 setAngularAxis(AxisModeLogValue);
931 break;
932 case 3:
933 setAngularAxis(AxisModeDateTime);
934 break;
935 case 4:
936 setAngularAxis(AxisModeCategory);
937 break;
938 default:
939 qWarning("Invalid Index!");
940 }
941 }
942
943 void MainWindow::radialAxisIndexChanged(int index)
944 {
945 switch (index) {
946 case 0:
947 setRadialAxis(AxisModeNone);
948 break;
949 case 1:
950 setRadialAxis(AxisModeValue);
951 break;
952 case 2:
953 setRadialAxis(AxisModeLogValue);
954 break;
955 case 3:
956 setRadialAxis(AxisModeDateTime);
957 break;
958 case 4:
959 setRadialAxis(AxisModeCategory);
960 break;
961 default:
962 qWarning("Invalid Index!");
963 }
964 }
965
966 void MainWindow::logBaseChanged(double value)
967 {
968 m_base = value;
969 if (m_angularAxisMode == AxisModeLogValue)
970 static_cast<QLogValueAxis *>(m_angularAxis)->setBase(m_base);
971 if (m_radialAxisMode == AxisModeLogValue)
972 static_cast<QLogValueAxis *>(m_radialAxis)->setBase(m_base);
973 }
974
975 void MainWindow::niceNumbersChecked()
976 {
977 if (ui->niceNumbersCheckBox->isChecked())
978 applyRanges();
979 }
980
981 void MainWindow::dateFormatEdited(const QString &text)
982 {
983 m_dateFormat = text;
984 if (m_angularAxisMode == AxisModeDateTime)
985 static_cast<QDateTimeAxis *>(m_angularAxis)->setFormat(m_dateFormat);
986 if (m_radialAxisMode == AxisModeDateTime)
987 static_cast<QDateTimeAxis *>(m_radialAxis)->setFormat(m_dateFormat);
988 }
989
990 void MainWindow::moreCategoriesChecked()
991 {
992 applyCategories();
993 m_moreCategories = ui->moreCategoriesCheckBox->isChecked();
994 }
995
996 void MainWindow::series1CheckBoxChecked()
997 {
998 if (ui->series1checkBox->isChecked())
999 m_series1->setVisible(true);
1000 else
1001 m_series1->setVisible(false);
1002 }
1003
1004 void MainWindow::series2CheckBoxChecked()
1005 {
1006 if (ui->series2checkBox->isChecked())
1007 m_series2->setVisible(true);
1008 else
1009 m_series2->setVisible(false);
1010 }
1011
1012 void MainWindow::series3CheckBoxChecked()
1013 {
1014 if (ui->series3checkBox->isChecked())
1015 m_series3->setVisible(true);
1016 else
1017 m_series3->setVisible(false);
1018 }
1019
1020 void MainWindow::series4CheckBoxChecked()
1021 {
1022 if (ui->series4checkBox->isChecked())
1023 m_series4->setVisible(true);
1024 else
1025 m_series4->setVisible(false);
1026 }
1027
1028 void MainWindow::series5CheckBoxChecked()
1029 {
1030 if (ui->series5checkBox->isChecked())
1031 m_series5->setVisible(true);
1032 else
1033 m_series5->setVisible(false);
1034 }
1035
1036 void MainWindow::series6CheckBoxChecked()
1037 {
1038 if (ui->series6checkBox->isChecked())
1039 m_series6->setVisible(true);
1040 else
1041 m_series6->setVisible(false);
1042 }
1043
1044 void MainWindow::series7CheckBoxChecked()
1045 {
1046 if (ui->series7checkBox->isChecked())
1047 m_series7->setVisible(true);
1048 else
1049 m_series7->setVisible(false);
1050 }
1051
1052 void MainWindow::themeIndexChanged(int index)
1053 {
1054 m_chart->setTheme(QChart::ChartTheme(index));
1055 }
1056
1057 void MainWindow::seriesHovered(QPointF point, bool state)
1058 {
1059 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender());
1060 if (series) {
1061 if (state) {
1062 QString str("'%3' - %1 x %2");
1063 ui->hoverLabel->setText(str.arg(point.x()).arg(point.y()).arg(series->name()));
1064 } else {
1065 ui->hoverLabel->setText("No hover");
1066 }
1067 } else {
1068 qDebug() << "seriesHovered - invalid sender!";
1069 }
1070 }
1071
1072 void MainWindow::seriesClicked(const QPointF &point)
1073 {
1074 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender());
1075 if (series) {
1076 QString str("'%3' clicked at: %1 x %2");
1077 m_angularTitle = str.arg(point.x()).arg(point.y()).arg(series->name());
1078 m_angularAxis->setTitleText(m_angularTitle);
1079 } else {
1080 qDebug() << "seriesClicked - invalid sender!";
1081 }
1082 }
1083
1084 void MainWindow::applyCategories()
1085 {
1086 // Basic layout is three categories, extended has five
1087 if (m_angularAxisMode == AxisModeCategory) {
1088 QCategoryAxis *angCatAxis = static_cast<QCategoryAxis *>(m_angularAxis);
1089 if (angCatAxis->count() == 0) {
1090 angCatAxis->setStartValue(4000);
1091 angCatAxis->append("Category A", 7000);
1092 angCatAxis->append("Category B", 12000);
1093 angCatAxis->append("Category C", 17000);
1094 }
1095 if (angCatAxis->count() == 3 && ui->moreCategoriesCheckBox->isChecked()) {
1096 angCatAxis->setStartValue(1000);
1097 angCatAxis->replaceLabel("Category A", "Cat A");
1098 angCatAxis->replaceLabel("Category B", "Cat B");
1099 angCatAxis->replaceLabel("Category C", "Cat C");
1100 angCatAxis->append("Cat D", 22000);
1101 angCatAxis->append("Cat E", 28000);
1102 } else if (angCatAxis->count() == 5 && !ui->moreCategoriesCheckBox->isChecked()) {
1103 angCatAxis->setStartValue(4000);
1104 angCatAxis->replaceLabel("Cat A", "Category A");
1105 angCatAxis->replaceLabel("Cat B", "Category B");
1106 angCatAxis->replaceLabel("Cat C", "Category C");
1107 angCatAxis->remove("Cat D");
1108 angCatAxis->remove("Cat E");
1109 }
1110 }
1111
1112 if (m_radialAxisMode == AxisModeCategory) {
1113 QCategoryAxis *radCatAxis = static_cast<QCategoryAxis *>(m_radialAxis);
1114 if (radCatAxis->count() == 0) {
1115 radCatAxis->setStartValue(2000);
1116 radCatAxis->append("Category 1", 4000);
1117 radCatAxis->append("Category 2", 9000);
1118 radCatAxis->append("Category 3", 14000);
1119 }
1120 if (radCatAxis->count() == 3 && ui->moreCategoriesCheckBox->isChecked()) {
1121 radCatAxis->setStartValue(1000);
1122 radCatAxis->replaceLabel("Category 1", "Cat 1");
1123 radCatAxis->replaceLabel("Category 2", "Cat 2");
1124 radCatAxis->replaceLabel("Category 3", "Cat 3");
1125 radCatAxis->append("Cat 4", 16500);
1126 radCatAxis->append("Cat 5", 19000);
1127 } else if (radCatAxis->count() == 5 && !ui->moreCategoriesCheckBox->isChecked()) {
1128 radCatAxis->setStartValue(2000);
1129 radCatAxis->replaceLabel("Cat 1", "Category 1");
1130 radCatAxis->replaceLabel("Cat 2", "Category 2");
1131 radCatAxis->replaceLabel("Cat 3", "Category 3");
1132 radCatAxis->remove("Cat 4");
1133 radCatAxis->remove("Cat 5");
1134 }
1135 }
1136 }
@@ -0,0 +1,155
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef MAINWINDOW_H
22 #define MAINWINDOW_H
23
24 #include <QPolarChart>
25 #include <QMainWindow>
26 #include <QFont>
27 #include <QChart>
28 #include <QScatterSeries>
29 #include <QLineSeries>
30 #include <QSplineSeries>
31 #include <QAreaSeries>
32
33 namespace Ui {
34 class MainWindow;
35 }
36
37 QTCOMMERCIALCHART_USE_NAMESPACE
38
39 class QBrush;
40 class QPen;
41
42 class MainWindow : public QMainWindow
43 {
44 Q_OBJECT
45
46 public:
47 explicit MainWindow(QWidget *parent = 0);
48 ~MainWindow();
49
50 public slots:
51 void angularTicksChanged(int value);
52 void radialTicksChanged(int value);
53 void anglesChanged(int value);
54 void angularMinChanged(double value);
55 void angularMaxChanged(double value);
56 void radialMinChanged(double value);
57 void radialMaxChanged(double value);
58 void angularShadesIndexChanged(int index);
59 void radialShadesIndexChanged(int index);
60 void labelFormatEdited(const QString &text);
61 void labelFontChanged(const QFont &font);
62 void labelFontSizeChanged(int value);
63 void animationIndexChanged(int index);
64 void labelsIndexChanged(int index);
65 void titleIndexChanged(int index);
66 void titleFontChanged(const QFont &font);
67 void titleFontSizeChanged(int value);
68 void gridIndexChanged(int index);
69 void arrowIndexChanged(int index);
70 void angularRangeChanged(qreal min, qreal max);
71 void radialRangeChanged(qreal min, qreal max);
72 void angularAxisIndexChanged(int index);
73 void radialAxisIndexChanged(int index);
74 void logBaseChanged(double value);
75 void niceNumbersChecked();
76 void dateFormatEdited(const QString &text);
77 void moreCategoriesChecked();
78 void series1CheckBoxChecked();
79 void series2CheckBoxChecked();
80 void series3CheckBoxChecked();
81 void series4CheckBoxChecked();
82 void series5CheckBoxChecked();
83 void series6CheckBoxChecked();
84 void series7CheckBoxChecked();
85 void themeIndexChanged(int index);
86 void seriesHovered(QPointF point, bool state);
87 void seriesClicked(const QPointF &point);
88
89 private:
90 enum AxisMode {
91 AxisModeNone,
92 AxisModeValue,
93 AxisModeLogValue,
94 AxisModeDateTime,
95 AxisModeCategory
96 };
97
98 void initXYValueChart();
99 void setAngularAxis(AxisMode mode);
100 void setRadialAxis(AxisMode mode);
101
102 void applyRanges();
103 void applyCategories();
104
105 Ui::MainWindow *ui;
106
107 int m_angularTickCount;
108 int m_radialTickCount;
109 qreal m_labelsAngle;
110 qreal m_angularMin;
111 qreal m_angularMax;
112 qreal m_radialMin;
113 qreal m_radialMax;
114 bool m_angularShadesVisible;
115 bool m_radialShadesVisible;
116 bool m_labelsVisible;
117 bool m_titleVisible;
118 bool m_gridVisible;
119 bool m_arrowVisible;
120 QBrush *m_angularShadesBrush;
121 QBrush *m_radialShadesBrush;
122 QBrush *m_labelBrush;
123 QBrush *m_titleBrush;
124 QPen *m_angularShadesPen;
125 QPen *m_radialShadesPen;
126 QPen *m_labelPen;
127 QPen *m_titlePen;
128 QPen *m_gridPen;
129 QPen *m_arrowPen;
130 QString m_labelFormat;
131 QFont m_currentLabelFont;
132 QFont m_currentTitleFont;
133 QChart::AnimationOptions m_animationOptions;
134 QString m_angularTitle;
135 QString m_radialTitle;
136 qreal m_base;
137 QString m_dateFormat;
138
139 QPolarChart *m_chart;
140 QAbstractAxis *m_angularAxis;
141 QAbstractAxis *m_radialAxis;
142 AxisMode m_angularAxisMode;
143 AxisMode m_radialAxisMode;
144 bool m_moreCategories;
145
146 QScatterSeries *m_series1;
147 QLineSeries *m_series2;
148 QLineSeries *m_series3;
149 QLineSeries *m_series4;
150 QAreaSeries *m_series5;
151 QSplineSeries *m_series6;
152 QScatterSeries *m_series7;
153 };
154
155 #endif // MAINWINDOW_H
This diff has been collapsed as it changes many lines, (929 lines changed) Show them Hide them
@@ -0,0 +1,929
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>MainWindow</class>
4 <widget class="QMainWindow" name="MainWindow">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>1207</width>
10 <height>905</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>MainWindow</string>
15 </property>
16 <widget class="QWidget" name="centralWidget">
17 <layout class="QHBoxLayout" name="horizontalLayout">
18 <item>
19 <widget class="ChartView" name="chartView"/>
20 </item>
21 <item>
22 <widget class="QGroupBox" name="settingsBox">
23 <property name="sizePolicy">
24 <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
25 <horstretch>0</horstretch>
26 <verstretch>0</verstretch>
27 </sizepolicy>
28 </property>
29 <property name="minimumSize">
30 <size>
31 <width>200</width>
32 <height>0</height>
33 </size>
34 </property>
35 <property name="title">
36 <string>Settings</string>
37 </property>
38 <widget class="QSpinBox" name="radialTicksSpin">
39 <property name="geometry">
40 <rect>
41 <x>110</x>
42 <y>90</y>
43 <width>71</width>
44 <height>22</height>
45 </rect>
46 </property>
47 </widget>
48 <widget class="QLabel" name="label">
49 <property name="geometry">
50 <rect>
51 <x>10</x>
52 <y>90</y>
53 <width>101</width>
54 <height>16</height>
55 </rect>
56 </property>
57 <property name="text">
58 <string>Radial Tick count</string>
59 </property>
60 </widget>
61 <widget class="QLabel" name="label_2">
62 <property name="geometry">
63 <rect>
64 <x>10</x>
65 <y>120</y>
66 <width>101</width>
67 <height>16</height>
68 </rect>
69 </property>
70 <property name="text">
71 <string>Angular Tick count</string>
72 </property>
73 </widget>
74 <widget class="QSpinBox" name="angularTicksSpin">
75 <property name="geometry">
76 <rect>
77 <x>110</x>
78 <y>120</y>
79 <width>71</width>
80 <height>22</height>
81 </rect>
82 </property>
83 </widget>
84 <widget class="QSpinBox" name="anglesSpin">
85 <property name="geometry">
86 <rect>
87 <x>110</x>
88 <y>150</y>
89 <width>71</width>
90 <height>22</height>
91 </rect>
92 </property>
93 <property name="minimum">
94 <number>-9999</number>
95 </property>
96 <property name="maximum">
97 <number>9999</number>
98 </property>
99 <property name="singleStep">
100 <number>5</number>
101 </property>
102 </widget>
103 <widget class="QLabel" name="label_3">
104 <property name="geometry">
105 <rect>
106 <x>10</x>
107 <y>150</y>
108 <width>101</width>
109 <height>16</height>
110 </rect>
111 </property>
112 <property name="text">
113 <string>Label angles</string>
114 </property>
115 </widget>
116 <widget class="QLabel" name="label_4">
117 <property name="geometry">
118 <rect>
119 <x>10</x>
120 <y>180</y>
121 <width>101</width>
122 <height>16</height>
123 </rect>
124 </property>
125 <property name="text">
126 <string>Angular min</string>
127 </property>
128 </widget>
129 <widget class="QLabel" name="label_5">
130 <property name="geometry">
131 <rect>
132 <x>10</x>
133 <y>210</y>
134 <width>101</width>
135 <height>16</height>
136 </rect>
137 </property>
138 <property name="text">
139 <string>Angular max</string>
140 </property>
141 </widget>
142 <widget class="QDoubleSpinBox" name="angularMinSpin">
143 <property name="geometry">
144 <rect>
145 <x>90</x>
146 <y>180</y>
147 <width>91</width>
148 <height>22</height>
149 </rect>
150 </property>
151 <property name="decimals">
152 <number>5</number>
153 </property>
154 <property name="minimum">
155 <double>-999999999.000000000000000</double>
156 </property>
157 <property name="maximum">
158 <double>999999999.000000000000000</double>
159 </property>
160 <property name="singleStep">
161 <double>10.000000000000000</double>
162 </property>
163 </widget>
164 <widget class="QDoubleSpinBox" name="angularMaxSpin">
165 <property name="geometry">
166 <rect>
167 <x>90</x>
168 <y>210</y>
169 <width>91</width>
170 <height>22</height>
171 </rect>
172 </property>
173 <property name="decimals">
174 <number>5</number>
175 </property>
176 <property name="minimum">
177 <double>-999999999.000000000000000</double>
178 </property>
179 <property name="maximum">
180 <double>999999999.000000000000000</double>
181 </property>
182 <property name="singleStep">
183 <double>10.000000000000000</double>
184 </property>
185 </widget>
186 <widget class="QDoubleSpinBox" name="radialMaxSpin">
187 <property name="geometry">
188 <rect>
189 <x>90</x>
190 <y>270</y>
191 <width>91</width>
192 <height>22</height>
193 </rect>
194 </property>
195 <property name="decimals">
196 <number>5</number>
197 </property>
198 <property name="minimum">
199 <double>-999999999.000000000000000</double>
200 </property>
201 <property name="maximum">
202 <double>999999999.000000000000000</double>
203 </property>
204 <property name="singleStep">
205 <double>10.000000000000000</double>
206 </property>
207 </widget>
208 <widget class="QDoubleSpinBox" name="radialMinSpin">
209 <property name="geometry">
210 <rect>
211 <x>90</x>
212 <y>240</y>
213 <width>91</width>
214 <height>22</height>
215 </rect>
216 </property>
217 <property name="decimals">
218 <number>5</number>
219 </property>
220 <property name="minimum">
221 <double>-999999999.000000000000000</double>
222 </property>
223 <property name="maximum">
224 <double>999999999.000000000000000</double>
225 </property>
226 <property name="singleStep">
227 <double>10.000000000000000</double>
228 </property>
229 </widget>
230 <widget class="QLabel" name="label_11">
231 <property name="geometry">
232 <rect>
233 <x>10</x>
234 <y>270</y>
235 <width>101</width>
236 <height>16</height>
237 </rect>
238 </property>
239 <property name="text">
240 <string>Radial max</string>
241 </property>
242 </widget>
243 <widget class="QLabel" name="label_12">
244 <property name="geometry">
245 <rect>
246 <x>10</x>
247 <y>240</y>
248 <width>101</width>
249 <height>16</height>
250 </rect>
251 </property>
252 <property name="text">
253 <string>Radial min</string>
254 </property>
255 </widget>
256 <widget class="QComboBox" name="angularShadesComboBox">
257 <property name="geometry">
258 <rect>
259 <x>10</x>
260 <y>300</y>
261 <width>171</width>
262 <height>22</height>
263 </rect>
264 </property>
265 <item>
266 <property name="text">
267 <string>No angular shades</string>
268 </property>
269 </item>
270 <item>
271 <property name="text">
272 <string>Gray angular shades</string>
273 </property>
274 </item>
275 <item>
276 <property name="text">
277 <string>Yellow ang. shades + custom pen</string>
278 </property>
279 </item>
280 </widget>
281 <widget class="QComboBox" name="radialShadesComboBox">
282 <property name="geometry">
283 <rect>
284 <x>10</x>
285 <y>330</y>
286 <width>171</width>
287 <height>22</height>
288 </rect>
289 </property>
290 <item>
291 <property name="text">
292 <string>No radial shades</string>
293 </property>
294 </item>
295 <item>
296 <property name="text">
297 <string>Green radial shades</string>
298 </property>
299 </item>
300 <item>
301 <property name="text">
302 <string>Blue rad. shades + custom pen</string>
303 </property>
304 </item>
305 </widget>
306 <widget class="QLabel" name="label_13">
307 <property name="geometry">
308 <rect>
309 <x>10</x>
310 <y>360</y>
311 <width>101</width>
312 <height>16</height>
313 </rect>
314 </property>
315 <property name="text">
316 <string>Label format</string>
317 </property>
318 </widget>
319 <widget class="QLineEdit" name="labelFormatEdit">
320 <property name="geometry">
321 <rect>
322 <x>100</x>
323 <y>360</y>
324 <width>81</width>
325 <height>20</height>
326 </rect>
327 </property>
328 </widget>
329 <widget class="QLabel" name="label_14">
330 <property name="geometry">
331 <rect>
332 <x>10</x>
333 <y>390</y>
334 <width>101</width>
335 <height>16</height>
336 </rect>
337 </property>
338 <property name="text">
339 <string>Label font size</string>
340 </property>
341 </widget>
342 <widget class="QFontComboBox" name="labelFontComboBox">
343 <property name="geometry">
344 <rect>
345 <x>10</x>
346 <y>420</y>
347 <width>171</width>
348 <height>22</height>
349 </rect>
350 </property>
351 </widget>
352 <widget class="QSpinBox" name="labelFontSizeSpin">
353 <property name="geometry">
354 <rect>
355 <x>100</x>
356 <y>390</y>
357 <width>81</width>
358 <height>22</height>
359 </rect>
360 </property>
361 <property name="minimum">
362 <number>-100000</number>
363 </property>
364 <property name="maximum">
365 <number>100000</number>
366 </property>
367 </widget>
368 <widget class="QComboBox" name="animationsComboBox">
369 <property name="geometry">
370 <rect>
371 <x>10</x>
372 <y>480</y>
373 <width>171</width>
374 <height>22</height>
375 </rect>
376 </property>
377 <item>
378 <property name="text">
379 <string>No animations</string>
380 </property>
381 </item>
382 <item>
383 <property name="text">
384 <string>Series animation</string>
385 </property>
386 </item>
387 <item>
388 <property name="text">
389 <string>Grid animation</string>
390 </property>
391 </item>
392 <item>
393 <property name="text">
394 <string>All animations</string>
395 </property>
396 </item>
397 </widget>
398 <widget class="QComboBox" name="labelComboBox">
399 <property name="geometry">
400 <rect>
401 <x>10</x>
402 <y>450</y>
403 <width>171</width>
404 <height>22</height>
405 </rect>
406 </property>
407 <property name="currentIndex">
408 <number>1</number>
409 </property>
410 <item>
411 <property name="text">
412 <string>No labels</string>
413 </property>
414 </item>
415 <item>
416 <property name="text">
417 <string>Black label</string>
418 </property>
419 </item>
420 <item>
421 <property name="text">
422 <string>White label + blue pen</string>
423 </property>
424 </item>
425 </widget>
426 <widget class="QSpinBox" name="titleFontSizeSpin">
427 <property name="geometry">
428 <rect>
429 <x>100</x>
430 <y>510</y>
431 <width>81</width>
432 <height>22</height>
433 </rect>
434 </property>
435 <property name="minimum">
436 <number>-100000</number>
437 </property>
438 <property name="maximum">
439 <number>100000</number>
440 </property>
441 </widget>
442 <widget class="QComboBox" name="titleComboBox">
443 <property name="geometry">
444 <rect>
445 <x>10</x>
446 <y>570</y>
447 <width>171</width>
448 <height>22</height>
449 </rect>
450 </property>
451 <property name="sizePolicy">
452 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
453 <horstretch>0</horstretch>
454 <verstretch>0</verstretch>
455 </sizepolicy>
456 </property>
457 <property name="currentIndex">
458 <number>3</number>
459 </property>
460 <item>
461 <property name="text">
462 <string>Invisible empty title</string>
463 </property>
464 </item>
465 <item>
466 <property name="text">
467 <string>Visible empty title</string>
468 </property>
469 </item>
470 <item>
471 <property name="text">
472 <string>Invisible title</string>
473 </property>
474 </item>
475 <item>
476 <property name="text">
477 <string>Black title</string>
478 </property>
479 </item>
480 <item>
481 <property name="text">
482 <string>White title + blue pen</string>
483 </property>
484 </item>
485 </widget>
486 <widget class="QFontComboBox" name="titleFontComboBox">
487 <property name="geometry">
488 <rect>
489 <x>10</x>
490 <y>540</y>
491 <width>171</width>
492 <height>22</height>
493 </rect>
494 </property>
495 </widget>
496 <widget class="QLabel" name="label_15">
497 <property name="geometry">
498 <rect>
499 <x>10</x>
500 <y>510</y>
501 <width>101</width>
502 <height>16</height>
503 </rect>
504 </property>
505 <property name="text">
506 <string>Title font size</string>
507 </property>
508 </widget>
509 <widget class="QComboBox" name="gridComboBox">
510 <property name="geometry">
511 <rect>
512 <x>10</x>
513 <y>600</y>
514 <width>171</width>
515 <height>22</height>
516 </rect>
517 </property>
518 <property name="sizePolicy">
519 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
520 <horstretch>0</horstretch>
521 <verstretch>0</verstretch>
522 </sizepolicy>
523 </property>
524 <property name="currentIndex">
525 <number>1</number>
526 </property>
527 <item>
528 <property name="text">
529 <string>Invisible grid</string>
530 </property>
531 </item>
532 <item>
533 <property name="text">
534 <string>Black grid</string>
535 </property>
536 </item>
537 <item>
538 <property name="text">
539 <string>Custom grid pen</string>
540 </property>
541 </item>
542 </widget>
543 <widget class="QComboBox" name="arrowComboBox">
544 <property name="geometry">
545 <rect>
546 <x>10</x>
547 <y>630</y>
548 <width>171</width>
549 <height>22</height>
550 </rect>
551 </property>
552 <property name="sizePolicy">
553 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
554 <horstretch>0</horstretch>
555 <verstretch>0</verstretch>
556 </sizepolicy>
557 </property>
558 <property name="currentIndex">
559 <number>1</number>
560 </property>
561 <item>
562 <property name="text">
563 <string>Invisible arrow</string>
564 </property>
565 </item>
566 <item>
567 <property name="text">
568 <string>Black arrow</string>
569 </property>
570 </item>
571 <item>
572 <property name="text">
573 <string>Custom arrow pen</string>
574 </property>
575 </item>
576 </widget>
577 <widget class="QComboBox" name="angularAxisComboBox">
578 <property name="geometry">
579 <rect>
580 <x>10</x>
581 <y>20</y>
582 <width>171</width>
583 <height>22</height>
584 </rect>
585 </property>
586 <property name="currentIndex">
587 <number>1</number>
588 </property>
589 <item>
590 <property name="text">
591 <string>No Angular Axis</string>
592 </property>
593 </item>
594 <item>
595 <property name="text">
596 <string>Angular Value Axis</string>
597 </property>
598 </item>
599 <item>
600 <property name="text">
601 <string>Angular Log Axis</string>
602 </property>
603 </item>
604 <item>
605 <property name="text">
606 <string>Angular DateTime Axis</string>
607 </property>
608 </item>
609 <item>
610 <property name="text">
611 <string>Angular Category Axis</string>
612 </property>
613 </item>
614 </widget>
615 <widget class="QComboBox" name="radialAxisComboBox">
616 <property name="geometry">
617 <rect>
618 <x>10</x>
619 <y>50</y>
620 <width>171</width>
621 <height>22</height>
622 </rect>
623 </property>
624 <property name="currentIndex">
625 <number>1</number>
626 </property>
627 <item>
628 <property name="text">
629 <string>No Radial Axis</string>
630 </property>
631 </item>
632 <item>
633 <property name="text">
634 <string>Radial Value Axis</string>
635 </property>
636 </item>
637 <item>
638 <property name="text">
639 <string>Radial Log Axis</string>
640 </property>
641 </item>
642 <item>
643 <property name="text">
644 <string>Radial DateTime Axis</string>
645 </property>
646 </item>
647 <item>
648 <property name="text">
649 <string>Radial Category Axis</string>
650 </property>
651 </item>
652 </widget>
653 <widget class="QLabel" name="label_16">
654 <property name="geometry">
655 <rect>
656 <x>10</x>
657 <y>660</y>
658 <width>101</width>
659 <height>16</height>
660 </rect>
661 </property>
662 <property name="text">
663 <string>Log Base</string>
664 </property>
665 </widget>
666 <widget class="QDoubleSpinBox" name="logBaseSpin">
667 <property name="geometry">
668 <rect>
669 <x>90</x>
670 <y>660</y>
671 <width>91</width>
672 <height>22</height>
673 </rect>
674 </property>
675 <property name="decimals">
676 <number>5</number>
677 </property>
678 <property name="minimum">
679 <double>-999999999.000000000000000</double>
680 </property>
681 <property name="maximum">
682 <double>999999999.000000000000000</double>
683 </property>
684 <property name="value">
685 <double>8.000000000000000</double>
686 </property>
687 </widget>
688 <widget class="QCheckBox" name="niceNumbersCheckBox">
689 <property name="geometry">
690 <rect>
691 <x>10</x>
692 <y>690</y>
693 <width>91</width>
694 <height>16</height>
695 </rect>
696 </property>
697 <property name="text">
698 <string>Nice Numbers</string>
699 </property>
700 </widget>
701 <widget class="QLineEdit" name="dateFormatEdit">
702 <property name="geometry">
703 <rect>
704 <x>100</x>
705 <y>710</y>
706 <width>81</width>
707 <height>20</height>
708 </rect>
709 </property>
710 </widget>
711 <widget class="QLabel" name="label_17">
712 <property name="geometry">
713 <rect>
714 <x>10</x>
715 <y>710</y>
716 <width>101</width>
717 <height>16</height>
718 </rect>
719 </property>
720 <property name="text">
721 <string>DateTime format</string>
722 </property>
723 </widget>
724 <widget class="QCheckBox" name="moreCategoriesCheckBox">
725 <property name="geometry">
726 <rect>
727 <x>100</x>
728 <y>690</y>
729 <width>141</width>
730 <height>16</height>
731 </rect>
732 </property>
733 <property name="text">
734 <string>More Categories</string>
735 </property>
736 </widget>
737 <widget class="QCheckBox" name="series1checkBox">
738 <property name="geometry">
739 <rect>
740 <x>10</x>
741 <y>730</y>
742 <width>31</width>
743 <height>16</height>
744 </rect>
745 </property>
746 <property name="text">
747 <string>1</string>
748 </property>
749 </widget>
750 <widget class="QCheckBox" name="series2checkBox">
751 <property name="geometry">
752 <rect>
753 <x>40</x>
754 <y>730</y>
755 <width>31</width>
756 <height>16</height>
757 </rect>
758 </property>
759 <property name="text">
760 <string>2</string>
761 </property>
762 </widget>
763 <widget class="QCheckBox" name="series3checkBox">
764 <property name="geometry">
765 <rect>
766 <x>70</x>
767 <y>730</y>
768 <width>31</width>
769 <height>16</height>
770 </rect>
771 </property>
772 <property name="text">
773 <string>3</string>
774 </property>
775 </widget>
776 <widget class="QCheckBox" name="series4checkBox">
777 <property name="geometry">
778 <rect>
779 <x>10</x>
780 <y>750</y>
781 <width>31</width>
782 <height>16</height>
783 </rect>
784 </property>
785 <property name="text">
786 <string>4</string>
787 </property>
788 </widget>
789 <widget class="QCheckBox" name="series5checkBox">
790 <property name="geometry">
791 <rect>
792 <x>40</x>
793 <y>750</y>
794 <width>31</width>
795 <height>16</height>
796 </rect>
797 </property>
798 <property name="text">
799 <string>5</string>
800 </property>
801 </widget>
802 <widget class="QCheckBox" name="series6checkBox">
803 <property name="geometry">
804 <rect>
805 <x>70</x>
806 <y>750</y>
807 <width>31</width>
808 <height>16</height>
809 </rect>
810 </property>
811 <property name="text">
812 <string>6</string>
813 </property>
814 </widget>
815 <widget class="QCheckBox" name="series7checkBox">
816 <property name="geometry">
817 <rect>
818 <x>100</x>
819 <y>740</y>
820 <width>31</width>
821 <height>16</height>
822 </rect>
823 </property>
824 <property name="text">
825 <string>7</string>
826 </property>
827 </widget>
828 <widget class="QComboBox" name="themeComboBox">
829 <property name="geometry">
830 <rect>
831 <x>10</x>
832 <y>770</y>
833 <width>171</width>
834 <height>22</height>
835 </rect>
836 </property>
837 <property name="sizePolicy">
838 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
839 <horstretch>0</horstretch>
840 <verstretch>0</verstretch>
841 </sizepolicy>
842 </property>
843 <property name="currentIndex">
844 <number>0</number>
845 </property>
846 <item>
847 <property name="text">
848 <string>Theme: Light</string>
849 </property>
850 </item>
851 <item>
852 <property name="text">
853 <string>Theme: Blue Cerulean</string>
854 </property>
855 </item>
856 <item>
857 <property name="text">
858 <string>Theme: Dark</string>
859 </property>
860 </item>
861 <item>
862 <property name="text">
863 <string>Theme: Brown Sand</string>
864 </property>
865 </item>
866 <item>
867 <property name="text">
868 <string>Theme: Blue Ncs</string>
869 </property>
870 </item>
871 <item>
872 <property name="text">
873 <string>Theme: High Contrast</string>
874 </property>
875 </item>
876 <item>
877 <property name="text">
878 <string>Theme: Blue Icy</string>
879 </property>
880 </item>
881 </widget>
882 <widget class="QLabel" name="hoverLabel">
883 <property name="geometry">
884 <rect>
885 <x>10</x>
886 <y>800</y>
887 <width>171</width>
888 <height>16</height>
889 </rect>
890 </property>
891 <property name="text">
892 <string>Hover coordinates here!</string>
893 </property>
894 </widget>
895 </widget>
896 </item>
897 </layout>
898 </widget>
899 <widget class="QMenuBar" name="menuBar">
900 <property name="geometry">
901 <rect>
902 <x>0</x>
903 <y>0</y>
904 <width>1207</width>
905 <height>21</height>
906 </rect>
907 </property>
908 </widget>
909 <widget class="QToolBar" name="mainToolBar">
910 <attribute name="toolBarArea">
911 <enum>TopToolBarArea</enum>
912 </attribute>
913 <attribute name="toolBarBreak">
914 <bool>false</bool>
915 </attribute>
916 </widget>
917 <widget class="QStatusBar" name="statusBar"/>
918 </widget>
919 <layoutdefault spacing="6" margin="11"/>
920 <customwidgets>
921 <customwidget>
922 <class>ChartView</class>
923 <extends>QGraphicsView</extends>
924 <header>chartview.h</header>
925 </customwidget>
926 </customwidgets>
927 <resources/>
928 <connections/>
929 </ui>
@@ -0,0 +1,20
1 !include( ../tests.pri ) {
2 error( "Couldn't find the test.pri file!" )
3 }
4
5 QT += core gui
6
7 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
8
9 TARGET = polarcharttest
10 TEMPLATE = app
11
12
13 SOURCES += main.cpp \
14 mainwindow.cpp \
15 chartview.cpp
16
17 HEADERS += mainwindow.h \
18 chartview.h
19
20 FORMS += mainwindow.ui
@@ -24,7 +24,7
24 #include <cmath>
24 #include <cmath>
25
25
26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series)
26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags, QLineSeries *series)
27 : QChart(parent, wFlags), m_series(series)
27 : QChart(QChart::ChartTypeCartesian, parent, wFlags), m_series(series)
28 {
28 {
29 m_clicked = false;
29 m_clicked = false;
30 }
30 }
@@ -15,7 +15,8 SUBDIRS += piechartcustomization \
15 chartinteractions \
15 chartinteractions \
16 qmlaxes \
16 qmlaxes \
17 qmlcustomlegend \
17 qmlcustomlegend \
18 callout
18 callout \
19 qmlpolarchart
19
20
20 contains(QT_CONFIG, opengl) {
21 contains(QT_CONFIG, opengl) {
21 SUBDIRS += chartthemes \
22 SUBDIRS += chartthemes \
@@ -26,7 +26,7
26 #include <QDebug>
26 #include <QDebug>
27
27
28 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
28 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
29 QChart(parent, wFlags),
29 QChart(QChart::ChartTypeCartesian, parent, wFlags),
30 m_series(0),
30 m_series(0),
31 m_axis(new QValueAxis),
31 m_axis(new QValueAxis),
32 m_step(0),
32 m_step(0),
@@ -30,6 +30,7
30 <td valign="top">
30 <td valign="top">
31 <ul>
31 <ul>
32 <li><a href="qchart.html">QChart</a></li>
32 <li><a href="qchart.html">QChart</a></li>
33 <li><a href="qpolarchart.html">QPolarChart</a></li>
33 <li><a href="qchartview.html">QChartView</a></li>
34 <li><a href="qchartview.html">QChartView</a></li>
34 <li><a href="qabstractaxis.html">QAbstractAxis</a></li>
35 <li><a href="qabstractaxis.html">QAbstractAxis</a></li>
35 <li><a href="qvalueaxis.html">QValueAxis</a></li>
36 <li><a href="qvalueaxis.html">QValueAxis</a></li>
@@ -8,6 +8,14
8
8
9 <table>
9 <table>
10 <tr>
10 <tr>
11 <td><a href="demos-audio.html">Audio</a></td>
12 <td><a href="demos-callout.html">Callout</a></td>
13 </tr>
14 <tr>
15 <td><a href="demos-audio.html"><img src="images/demos_audio.png" width="300" alt="Audio" /></a></td>
16 <td><a href="demos-callout.html"><img src="images/demos_callout.png" width="300" alt="Callout" /></a></td>
17 </tr>
18 <tr>
11 <td><a href="demos-chartthemes.html">Chart Themes</a></td>
19 <td><a href="demos-chartthemes.html">Chart Themes</a></td>
12 <td><a href="demos-dynamicspline.html">Dynamic Spline Chart</a></td>
20 <td><a href="demos-dynamicspline.html">Dynamic Spline Chart</a></td>
13 </tr>
21 </tr>
@@ -15,7 +23,6
15 <td><a href="demos-chartthemes.html"><img src="images/demo_chartthemes_blue_cerulean.png" width="300" alt="Chart Themes" /></a></td>
23 <td><a href="demos-chartthemes.html"><img src="images/demo_chartthemes_blue_cerulean.png" width="300" alt="Chart Themes" /></a></td>
16 <td><a href="demos-dynamicspline.html"><img src="images/demos_dynamicspline2.png" width="300" alt="Dynamic Spline" /></a></td>
24 <td><a href="demos-dynamicspline.html"><img src="images/demos_dynamicspline2.png" width="300" alt="Dynamic Spline" /></a></td>
17 </tr>
25 </tr>
18
19 <tr>
26 <tr>
20 <td><a href="demos-nesteddonuts.html">Nested Donuts Chart</a></td>
27 <td><a href="demos-nesteddonuts.html">Nested Donuts Chart</a></td>
21 <td><a href="demos-piechartcustomization.html">Pie Chart Customization</a></td>
28 <td><a href="demos-piechartcustomization.html">Pie Chart Customization</a></td>
@@ -24,7 +31,6
24 <td><a href="demos-nesteddonuts.html"><img src="images/demos_nesteddonuts.png" width="300" alt="Nested Donuts Chart" /></a></td>
31 <td><a href="demos-nesteddonuts.html"><img src="images/demos_nesteddonuts.png" width="300" alt="Nested Donuts Chart" /></a></td>
25 <td><a href="demos-piechartcustomization.html"><img src="images/piechart_customization.png" width="300" alt="Pie Chart Customization" /></a></td>
32 <td><a href="demos-piechartcustomization.html"><img src="images/piechart_customization.png" width="300" alt="Pie Chart Customization" /></a></td>
26 </tr>
33 </tr>
27
28 <tr>
34 <tr>
29 <td><a href="demos-qmlchart.html">Qml Basic Charts</a></td>
35 <td><a href="demos-qmlchart.html">Qml Basic Charts</a></td>
30 <td><a href="demos-qmlaxes.html">Qml Axes</a></td>
36 <td><a href="demos-qmlaxes.html">Qml Axes</a></td>
@@ -33,7 +39,6
33 <td><a href="demos-qmlchart.html"><img src="images/demos_qmlchart1.png" width="300" alt="Qml Basic Charts" /></a></td>
39 <td><a href="demos-qmlchart.html"><img src="images/demos_qmlchart1.png" width="300" alt="Qml Basic Charts" /></a></td>
34 <td><a href="demos-qmlaxes.html"><img src="images/demos_qmlaxes1.png" width="300" alt="Qml Axes" /></a></td>
40 <td><a href="demos-qmlaxes.html"><img src="images/demos_qmlaxes1.png" width="300" alt="Qml Axes" /></a></td>
35 </tr>
41 </tr>
36
37 <tr>
42 <tr>
38 <td><a href="demos-qmlcustomizations.html">Qml Customizations</a></td>
43 <td><a href="demos-qmlcustomizations.html">Qml Customizations</a></td>
39 <td><a href="demos-qmlcustommodel.html">Qml Custom Model</a></td>
44 <td><a href="demos-qmlcustommodel.html">Qml Custom Model</a></td>
@@ -42,7 +47,6
42 <td><a href="demos-qmlcustomizations.html"><img src="images/demos_qmlcustomizations.png" width="300" alt="Qml Customizations" /></a></td>
47 <td><a href="demos-qmlcustomizations.html"><img src="images/demos_qmlcustomizations.png" width="300" alt="Qml Customizations" /></a></td>
43 <td><a href="demos-qmlcustommodel.html"><img src="images/demos_qmlcustommodel.png" width="300" alt="Qml Custom Model" /></a></td>
48 <td><a href="demos-qmlcustommodel.html"><img src="images/demos_qmlcustommodel.png" width="300" alt="Qml Custom Model" /></a></td>
44 </tr>
49 </tr>
45
46 <tr>
50 <tr>
47 <td><a href="demos-qmlf1legends.html">Qml F1 Legends</a></td>
51 <td><a href="demos-qmlf1legends.html">Qml F1 Legends</a></td>
48 <td><a href="demos-qmloscilloscope.html">Qml Oscilloscope</a></td>
52 <td><a href="demos-qmloscilloscope.html">Qml Oscilloscope</a></td>
@@ -51,7 +55,6
51 <td><a href="demos-qmlf1legends.html"><img src="images/demos_qmlf1legends.png" width="300" alt="Qml F1 Legends" /></a></td>
55 <td><a href="demos-qmlf1legends.html"><img src="images/demos_qmlf1legends.png" width="300" alt="Qml F1 Legends" /></a></td>
52 <td><a href="demos-qmloscilloscope.html"><img src="images/demos_qmloscilloscope.png" width="300" alt="Qml Oscilloscope" /></a></td>
56 <td><a href="demos-qmloscilloscope.html"><img src="images/demos_qmloscilloscope.png" width="300" alt="Qml Oscilloscope" /></a></td>
53 </tr>
57 </tr>
54
55 <tr>
58 <tr>
56 <td><a href="demos-qmlweather.html">Qml Weather</a></td>
59 <td><a href="demos-qmlweather.html">Qml Weather</a></td>
57 <td><a href="demos-qmlcustomlegend.html">Qml Custom Legend</a></td>
60 <td><a href="demos-qmlcustomlegend.html">Qml Custom Legend</a></td>
@@ -61,14 +64,11
61 <td><a href="demos-qmlcustomlegend.html"><img src="images/demos-qmlcustomlegend1.png" width="300" alt="Qml Custom Legend" /></a></td>
64 <td><a href="demos-qmlcustomlegend.html"><img src="images/demos-qmlcustomlegend1.png" width="300" alt="Qml Custom Legend" /></a></td>
62 </tr>
65 </tr>
63 <tr>
66 <tr>
64 <td><a href="demos-callout.html">Callout</a></td>
67 <td><a href="demos-qmlpolarchart.html">Qml Polar Chart</a></td>
65 <td><a href="demos-audio.html">Audio</a></td>
66 </tr>
68 </tr>
67 <tr>
69 <tr>
68 <td><a href="demos-callout.html"><img src="images/demos_callout.png" width="300" alt="Callout" /></a></td>
70 <td><a href="demos-qmlpolarchart.html"><img src="images/demos_qmlpolarchart1.png" width="300" alt="Qml Polar Chart" /></a></td>
69 <td><a href="demos-audio.html"><img src="images/demos_audio.png" width="300" alt="Audio" /></a></td>
70 </tr>
71 </tr>
71
72 </table>
72 </table>
73 </div>
73 </div>
74 \endraw
74 \endraw
@@ -98,36 +98,38
98 </tr>
98 </tr>
99
99
100 <tr>
100 <tr>
101 <td><a href="examples-polarchart.html">Polar chart</a></td>
101 <td><a href="examples-scatterchart.html">Scatter chart</a></td>
102 <td><a href="examples-scatterchart.html">Scatter chart</a></td>
102 <td><a href="examples-scatterinteractions.html">Scatter Interactions</a></td>
103 </tr>
103 </tr>
104 <tr>
104 <tr>
105 <td><a href="examples-polarchart.html"><img src="images/examples_polarchart.png" width="300" alt="Polar chart" /></a></td>
105 <td><a href="examples-scatterchart.html"><img src="images/examples_scatterchart.png" width="300" alt="Scatter chart" /></a></td>
106 <td><a href="examples-scatterchart.html"><img src="images/examples_scatterchart.png" width="300" alt="Scatter chart" /></a></td>
106 <td><a href="examples-scatterinteractions.html"><img src="images/examples_scatterinteractions.png" width="300" alt="Scatter Interactions" /></a></td>
107 </tr>
107 </tr>
108
108
109 <tr>
109 <tr>
110 <td><a href="examples-scatterinteractions.html">Scatter Interactions</a></td>
110 <td><a href="examples-splinechart.html">Spline Chart</a></td>
111 <td><a href="examples-splinechart.html">Spline Chart</a></td>
111 <td><a href="examples-stackedbarchart.html">Stacked Bar Chart</a></td>
112 </tr>
112 </tr>
113 <tr>
113 <tr>
114 <td><a href="examples-scatterinteractions.html"><img src="images/examples_scatterinteractions.png" width="300" alt="Scatter Interactions" /></a></td>
114 <td><a href="examples-splinechart.html"><img src="images/examples_splinechart.png" width="300" alt="Spline Chart" /></a></td>
115 <td><a href="examples-splinechart.html"><img src="images/examples_splinechart.png" width="300" alt="Spline Chart" /></a></td>
115 <td><a href="examples-stackedbarchart.html"><img src="images/examples_stackedbarchart.png" width="300" alt="Stacked Bar Chart" /></a></td>
116 </tr>
116 </tr>
117
117
118 <tr>
118 <tr>
119 <td><a href="examples-stackedbarchart.html">Stacked Bar Chart</a></td>
119 <td><a href="examples-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown</a></td>
120 <td><a href="examples-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown</a></td>
120 <td><a href="examples-temperaturerecords.html">Temperature Records</a></td>
121 </tr>
121 </tr>
122 <tr>
122 <tr>
123 <td><a href="examples-stackedbarchart.html"><img src="images/examples_stackedbarchart.png" width="300" alt="Stacked Bar Chart" /></a></td>
123 <td><a href="examples-stackedbarchartdrilldown.html"><img src="images/examples_stackedbarchartdrilldown1.png" width="300" alt="Stacked Bar Chart Drilldown" /></a></td>
124 <td><a href="examples-stackedbarchartdrilldown.html"><img src="images/examples_stackedbarchartdrilldown1.png" width="300" alt="Stacked Bar Chart Drilldown" /></a></td>
124 <td><a href="examples-temperaturerecords.html"><img src="images/examples_temperaturerecords.png" width="300" alt="Temperature Records" /></a></td>
125 </tr>
125 </tr>
126
126
127 <tr>
127 <tr>
128 <td><a href="examples-temperaturerecords.html">Temperature Records</a></td>
128 <td><a href="examples-zoomlinechart.html">Zoom Line</a></td>
129 <td><a href="examples-zoomlinechart.html">Zoom Line</a></td>
129 </tr>
130 </tr>
130 <tr>
131 <tr>
132 <td><a href="examples-temperaturerecords.html"><img src="images/examples_temperaturerecords.png" width="300" alt="Temperature Records" /></a></td>
131 <td><a href="examples-zoomlinechart.html"><img src="images/examples_zoomlinechart1.png" width="300" alt="Zoom Line" /></a></td>
133 <td><a href="examples-zoomlinechart.html"><img src="images/examples_zoomlinechart1.png" width="300" alt="Zoom Line" /></a></td>
132 </tr>
134 </tr>
133
135
@@ -27,6 +27,7
27 <td valign="top">
27 <td valign="top">
28 <ul>
28 <ul>
29 <li><a href="qml-chartview.html">ChartView</a></li>
29 <li><a href="qml-chartview.html">ChartView</a></li>
30 <li><a href="qml-polarchartview.html">PolarChartView</a></li>
30 <li><a href="qml-abstractaxis.html">AbstractAxis</a></li>
31 <li><a href="qml-abstractaxis.html">AbstractAxis</a></li>
31 <li><a href="qml-valueaxis.html">ValueAxis</a></li>
32 <li><a href="qml-valueaxis.html">ValueAxis</a></li>
32 <li><a href="qml-categoryaxis.html">CategoryAxis</a></li>
33 <li><a href="qml-categoryaxis.html">CategoryAxis</a></li>
@@ -26,7 +26,7 QTCOMMERCIALCHART_USE_NAMESPACE
26
26
27 //![1]
27 //![1]
28 DonutBreakdownChart::DonutBreakdownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
28 DonutBreakdownChart::DonutBreakdownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
29 : QChart(parent, wFlags)
29 : QChart(QChart::ChartTypeCartesian, parent, wFlags)
30 {
30 {
31 // create the series for main center pie
31 // create the series for main center pie
32 m_mainSeries = new QPieSeries();
32 m_mainSeries = new QPieSeries();
@@ -31,7 +31,8 SUBDIRS += \
31 donutchart \
31 donutchart \
32 multiaxis \
32 multiaxis \
33 legendmarkers \
33 legendmarkers \
34 logvalueaxis
34 logvalueaxis \
35 polarchart
35
36
36 !linux-arm*: {
37 !linux-arm*: {
37 SUBDIRS += \
38 SUBDIRS += \
@@ -23,7 +23,7
23 QTCOMMERCIALCHART_USE_NAMESPACE
23 QTCOMMERCIALCHART_USE_NAMESPACE
24
24
25 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
25 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
26 : QChart(parent, wFlags),
26 : QChart(QChart::ChartTypeCartesian, parent, wFlags),
27 m_currentSeries(0)
27 m_currentSeries(0)
28 {
28 {
29
29
@@ -24,7 +24,7
24 QTCOMMERCIALCHART_USE_NAMESPACE
24 QTCOMMERCIALCHART_USE_NAMESPACE
25
25
26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 : QChart(parent, wFlags),
27 : QChart(QChart::ChartTypeCartesian, parent, wFlags),
28 m_currentSeries(0)
28 m_currentSeries(0)
29 {
29 {
30 }
30 }
@@ -24,7 +24,7
24 #include <QGraphicsView>
24 #include <QGraphicsView>
25
25
26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 : QChart(parent, wFlags)
27 : QChart(QChart::ChartTypeCartesian, parent, wFlags)
28 {
28 {
29 // Seems that QGraphicsView (QChartView) does not grab gestures.
29 // Seems that QGraphicsView (QChartView) does not grab gestures.
30 // They can only be grabbed here in the QGraphicsWidget (QChart).
30 // They can only be grabbed here in the QGraphicsWidget (QChart).
@@ -25,7 +25,8 SOURCES += \
25 declarativebarseries.cpp \
25 declarativebarseries.cpp \
26 declarativecategoryaxis.cpp \
26 declarativecategoryaxis.cpp \
27 declarativemargins.cpp \
27 declarativemargins.cpp \
28 declarativeaxes.cpp
28 declarativeaxes.cpp \
29 declarativepolarchart.cpp
29
30
30 HEADERS += \
31 HEADERS += \
31 declarativechart.h \
32 declarativechart.h \
@@ -39,7 +40,8 HEADERS += \
39 declarativebarseries.h \
40 declarativebarseries.h \
40 declarativecategoryaxis.h \
41 declarativecategoryaxis.h \
41 declarativemargins.h \
42 declarativemargins.h \
42 declarativeaxes.h
43 declarativeaxes.h \
44 declarativepolarchart.h
43
45
44 TARGETPATH = QtCommercial/Chart
46 TARGETPATH = QtCommercial/Chart
45 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
47 target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
@@ -31,6 +31,8 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) :
31 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
31 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
32 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
32 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
33 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
33 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
34 connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisAngularChanged(QAbstractAxis*)));
35 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*)));
34 }
36 }
35
37
36 void DeclarativeAreaSeries::setUpperSeries(DeclarativeLineSeries *series)
38 void DeclarativeAreaSeries::setUpperSeries(DeclarativeLineSeries *series)
@@ -36,6 +36,8 class DeclarativeAreaSeries : public QAreaSeries
36 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
36 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
37 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
37 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
38 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
38 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
39 Q_PROPERTY(QAbstractAxis *axisAngular READ axisAngular WRITE setAxisAngular NOTIFY axisAngularChanged REVISION 3)
40 Q_PROPERTY(QAbstractAxis *axisRadial READ axisRadial WRITE setAxisRadial NOTIFY axisRadialChanged REVISION 3)
39 Q_PROPERTY(qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged REVISION 1)
41 Q_PROPERTY(qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged REVISION 1)
40
42
41 public:
43 public:
@@ -52,6 +54,10 public:
52 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
54 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
53 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
55 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
54 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
56 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
57 Q_REVISION(3) QAbstractAxis *axisAngular() { return m_axes->axisX(); }
58 Q_REVISION(3) void setAxisAngular(QAbstractAxis *axis) { m_axes->setAxisX(axis); }
59 Q_REVISION(3) QAbstractAxis *axisRadial() { return m_axes->axisY(); }
60 Q_REVISION(3) void setAxisRadial(QAbstractAxis *axis) { m_axes->setAxisY(axis); }
55 qreal borderWidth() const;
61 qreal borderWidth() const;
56 void setBorderWidth(qreal borderWidth);
62 void setBorderWidth(qreal borderWidth);
57
63
@@ -61,6 +67,8 Q_SIGNALS:
61 Q_REVISION(1) void borderWidthChanged(qreal width);
67 Q_REVISION(1) void borderWidthChanged(qreal width);
62 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
68 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
63 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
69 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
70 Q_REVISION(3) void axisAngularChanged(QAbstractAxis *axis);
71 Q_REVISION(3) void axisRadialChanged(QAbstractAxis *axis);
64
72
65 public:
73 public:
66 DeclarativeAxes *m_axes;
74 DeclarativeAxes *m_axes;
@@ -35,6 +35,7
35 #include "chartdataset_p.h"
35 #include "chartdataset_p.h"
36 #include "declarativeaxes.h"
36 #include "declarativeaxes.h"
37 #include "qchart_p.h"
37 #include "qchart_p.h"
38 #include "qpolarchart.h"
38
39
39 #ifndef QT_ON_ARM
40 #ifndef QT_ON_ARM
40 #include "qdatetimeaxis.h"
41 #include "qdatetimeaxis.h"
@@ -235,9 +236,24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
235 */
236 */
236
237
237 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
238 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
238 : QDeclarativeItem(parent),
239 : QDeclarativeItem(parent)
239 m_chart(new QChart(this))
240 {
240 {
241 initChart(QChart::ChartTypeCartesian);
242 }
243
244 DeclarativeChart::DeclarativeChart(QChart::ChartType type, QDeclarativeItem *parent)
245 : QDeclarativeItem(parent)
246 {
247 initChart(type);
248 }
249
250 void DeclarativeChart::initChart(QChart::ChartType type)
251 {
252 if (type == QChart::ChartTypePolar)
253 m_chart = new QPolarChart(this);
254 else
255 m_chart = new QChart(this);
256
241 setFlag(QGraphicsItem::ItemHasNoContents, false);
257 setFlag(QGraphicsItem::ItemHasNoContents, false);
242 m_margins = new DeclarativeMargins(this);
258 m_margins = new DeclarativeMargins(this);
243 m_margins->setTop(m_chart->margins().top());
259 m_margins->setTop(m_chart->margins().top());
@@ -170,7 +170,11 private Q_SLOTS:
170 void handleAxisYRightSet(QAbstractAxis *axis);
170 void handleAxisYRightSet(QAbstractAxis *axis);
171 void handleSeriesAdded(QAbstractSeries *series);
171 void handleSeriesAdded(QAbstractSeries *series);
172
172
173 protected:
174 explicit DeclarativeChart(QChart::ChartType type, QDeclarativeItem *parent);
175
173 private:
176 private:
177 void initChart(QChart::ChartType type);
174 // Extending QChart with DeclarativeChart is not possible because QObject does not support
178 // Extending QChart with DeclarativeChart is not possible because QObject does not support
175 // multi inheritance, so we now have a QChart as a member instead
179 // multi inheritance, so we now have a QChart as a member instead
176 QChart *m_chart;
180 QChart *m_chart;
@@ -30,6 +30,8 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
30 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
30 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
31 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
31 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
32 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
32 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
33 connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisAngularChanged(QAbstractAxis*)));
34 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*)));
33 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
35 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
34 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
36 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
35 }
37 }
@@ -38,6 +38,8 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, pu
38 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
38 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
39 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
39 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
40 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
40 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
41 Q_PROPERTY(QAbstractAxis *axisAngular READ axisAngular WRITE setAxisAngular NOTIFY axisAngularChanged REVISION 3)
42 Q_PROPERTY(QAbstractAxis *axisRadial READ axisRadial WRITE setAxisRadial NOTIFY axisRadialChanged REVISION 3)
41 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged REVISION 1)
43 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged REVISION 1)
42 Q_PROPERTY(Qt::PenStyle style READ style WRITE setStyle NOTIFY styleChanged REVISION 1)
44 Q_PROPERTY(Qt::PenStyle style READ style WRITE setStyle NOTIFY styleChanged REVISION 1)
43 Q_PROPERTY(Qt::PenCapStyle capStyle READ capStyle WRITE setCapStyle NOTIFY capStyleChanged REVISION 1)
45 Q_PROPERTY(Qt::PenCapStyle capStyle READ capStyle WRITE setCapStyle NOTIFY capStyleChanged REVISION 1)
@@ -55,6 +57,10 public:
55 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
57 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
56 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
58 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
57 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
59 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
60 Q_REVISION(3) QAbstractAxis *axisAngular() { return m_axes->axisX(); }
61 Q_REVISION(3) void setAxisAngular(QAbstractAxis *axis) { m_axes->setAxisX(axis); }
62 Q_REVISION(3) QAbstractAxis *axisRadial() { return m_axes->axisY(); }
63 Q_REVISION(3) void setAxisRadial(QAbstractAxis *axis) { m_axes->setAxisY(axis); }
58 qreal width() const;
64 qreal width() const;
59 void setWidth(qreal width);
65 void setWidth(qreal width);
60 Qt::PenStyle style() const;
66 Qt::PenStyle style() const;
@@ -81,6 +87,8 Q_SIGNALS:
81 Q_REVISION(1) void axisYChanged(QAbstractAxis *axis);
87 Q_REVISION(1) void axisYChanged(QAbstractAxis *axis);
82 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
88 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
83 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
89 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
90 Q_REVISION(3) void axisAngularChanged(QAbstractAxis *axis);
91 Q_REVISION(3) void axisRadialChanged(QAbstractAxis *axis);
84 Q_REVISION(1) void widthChanged(qreal width);
92 Q_REVISION(1) void widthChanged(qreal width);
85 Q_REVISION(1) void styleChanged(Qt::PenStyle style);
93 Q_REVISION(1) void styleChanged(Qt::PenStyle style);
86 Q_REVISION(1) void capStyleChanged(Qt::PenCapStyle capStyle);
94 Q_REVISION(1) void capStyleChanged(Qt::PenCapStyle capStyle);
@@ -30,6 +30,8 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
30 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
30 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
31 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
31 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
32 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
32 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
33 connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisAngularChanged(QAbstractAxis*)));
34 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*)));
33 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
35 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
34 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
36 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
35 }
37 }
@@ -38,6 +38,8 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeri
38 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
38 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
39 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
39 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
40 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
40 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
41 Q_PROPERTY(QAbstractAxis *axisAngular READ axisAngular WRITE setAxisAngular NOTIFY axisAngularChanged REVISION 3)
42 Q_PROPERTY(QAbstractAxis *axisRadial READ axisRadial WRITE setAxisRadial NOTIFY axisRadialChanged REVISION 3)
41 Q_PROPERTY(qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged REVISION 1)
43 Q_PROPERTY(qreal borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged REVISION 1)
42 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
44 Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren)
43 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
45 Q_CLASSINFO("DefaultProperty", "declarativeChildren")
@@ -53,6 +55,10 public:
53 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
55 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
54 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
56 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
55 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
57 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
58 Q_REVISION(3) QAbstractAxis *axisAngular() { return m_axes->axisX(); }
59 Q_REVISION(3) void setAxisAngular(QAbstractAxis *axis) { m_axes->setAxisX(axis); }
60 Q_REVISION(3) QAbstractAxis *axisRadial() { return m_axes->axisY(); }
61 Q_REVISION(3) void setAxisRadial(QAbstractAxis *axis) { m_axes->setAxisY(axis); }
56 qreal borderWidth() const;
62 qreal borderWidth() const;
57 void setBorderWidth(qreal borderWidth);
63 void setBorderWidth(qreal borderWidth);
58 QDeclarativeListProperty<QObject> declarativeChildren();
64 QDeclarativeListProperty<QObject> declarativeChildren();
@@ -76,6 +82,8 Q_SIGNALS:
76 Q_REVISION(1) void borderWidthChanged(qreal width);
82 Q_REVISION(1) void borderWidthChanged(qreal width);
77 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
83 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
78 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
84 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
85 Q_REVISION(3) void axisAngularChanged(QAbstractAxis *axis);
86 Q_REVISION(3) void axisRadialChanged(QAbstractAxis *axis);
79
87
80 public Q_SLOTS:
88 public Q_SLOTS:
81 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
89 static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
@@ -30,6 +30,8 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
30 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
30 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisYChanged(QAbstractAxis*)));
31 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
31 connect(m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SIGNAL(axisXTopChanged(QAbstractAxis*)));
32 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
32 connect(m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SIGNAL(axisYRightChanged(QAbstractAxis*)));
33 connect(m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), this, SIGNAL(axisAngularChanged(QAbstractAxis*)));
34 connect(m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), this, SIGNAL(axisRadialChanged(QAbstractAxis*)));
33 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
35 connect(this, SIGNAL(pointAdded(int)), this, SLOT(handleCountChanged(int)));
34 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
36 connect(this, SIGNAL(pointRemoved(int)), this, SLOT(handleCountChanged(int)));
35 }
37 }
@@ -38,6 +38,8 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
38 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
38 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged REVISION 1)
39 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
39 Q_PROPERTY(QAbstractAxis *axisXTop READ axisXTop WRITE setAxisXTop NOTIFY axisXTopChanged REVISION 2)
40 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
40 Q_PROPERTY(QAbstractAxis *axisYRight READ axisYRight WRITE setAxisYRight NOTIFY axisYRightChanged REVISION 2)
41 Q_PROPERTY(QAbstractAxis *axisAngular READ axisAngular WRITE setAxisAngular NOTIFY axisAngularChanged REVISION 3)
42 Q_PROPERTY(QAbstractAxis *axisRadial READ axisRadial WRITE setAxisRadial NOTIFY axisRadialChanged REVISION 3)
41 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged REVISION 1)
43 Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged REVISION 1)
42 Q_PROPERTY(Qt::PenStyle style READ style WRITE setStyle NOTIFY styleChanged REVISION 1)
44 Q_PROPERTY(Qt::PenStyle style READ style WRITE setStyle NOTIFY styleChanged REVISION 1)
43 Q_PROPERTY(Qt::PenCapStyle capStyle READ capStyle WRITE setCapStyle NOTIFY capStyleChanged REVISION 1)
45 Q_PROPERTY(Qt::PenCapStyle capStyle READ capStyle WRITE setCapStyle NOTIFY capStyleChanged REVISION 1)
@@ -55,6 +57,10 public:
55 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
57 Q_REVISION(2) void setAxisXTop(QAbstractAxis *axis) { m_axes->setAxisXTop(axis); }
56 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
58 Q_REVISION(2) QAbstractAxis *axisYRight() { return m_axes->axisYRight(); }
57 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
59 Q_REVISION(2) void setAxisYRight(QAbstractAxis *axis) { m_axes->setAxisYRight(axis); }
60 Q_REVISION(3) QAbstractAxis *axisAngular() { return m_axes->axisX(); }
61 Q_REVISION(3) void setAxisAngular(QAbstractAxis *axis) { m_axes->setAxisX(axis); }
62 Q_REVISION(3) QAbstractAxis *axisRadial() { return m_axes->axisY(); }
63 Q_REVISION(3) void setAxisRadial(QAbstractAxis *axis) { m_axes->setAxisY(axis); }
58 qreal width() const;
64 qreal width() const;
59 void setWidth(qreal width);
65 void setWidth(qreal width);
60 Qt::PenStyle style() const;
66 Qt::PenStyle style() const;
@@ -81,6 +87,8 Q_SIGNALS:
81 Q_REVISION(1) void axisYChanged(QAbstractAxis *axis);
87 Q_REVISION(1) void axisYChanged(QAbstractAxis *axis);
82 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
88 Q_REVISION(2) void axisXTopChanged(QAbstractAxis *axis);
83 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
89 Q_REVISION(2) void axisYRightChanged(QAbstractAxis *axis);
90 Q_REVISION(3) void axisAngularChanged(QAbstractAxis *axis);
91 Q_REVISION(3) void axisRadialChanged(QAbstractAxis *axis);
84 Q_REVISION(1) void widthChanged(qreal width);
92 Q_REVISION(1) void widthChanged(qreal width);
85 Q_REVISION(1) void styleChanged(Qt::PenStyle style);
93 Q_REVISION(1) void styleChanged(Qt::PenStyle style);
86 Q_REVISION(1) void capStyleChanged(Qt::PenCapStyle capStyle);
94 Q_REVISION(1) void capStyleChanged(Qt::PenCapStyle capStyle);
@@ -24,6 +24,7
24 #include "declarativecategoryaxis.h"
24 #include "declarativecategoryaxis.h"
25 #include "qbarcategoryaxis.h"
25 #include "qbarcategoryaxis.h"
26 #include "declarativechart.h"
26 #include "declarativechart.h"
27 #include "declarativepolarchart.h"
27 #include "declarativexypoint.h"
28 #include "declarativexypoint.h"
28 #include "declarativelineseries.h"
29 #include "declarativelineseries.h"
29 #include "declarativesplineseries.h"
30 #include "declarativesplineseries.h"
@@ -62,6 +63,7 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
62 // These should not be needed or at least they are not needed in Qt4.
63 // These should not be needed or at least they are not needed in Qt4.
63
64
64 Q_DECLARE_METATYPE(DeclarativeChart *)
65 Q_DECLARE_METATYPE(DeclarativeChart *)
66 Q_DECLARE_METATYPE(DeclarativePolarChart *)
65 Q_DECLARE_METATYPE(DeclarativeMargins *)
67 Q_DECLARE_METATYPE(DeclarativeMargins *)
66 Q_DECLARE_METATYPE(DeclarativeAreaSeries *)
68 Q_DECLARE_METATYPE(DeclarativeAreaSeries *)
67 Q_DECLARE_METATYPE(DeclarativeBarSeries *)
69 Q_DECLARE_METATYPE(DeclarativeBarSeries *)
@@ -213,6 +215,13 public:
213 qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries");
215 qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries");
214 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries");
216 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries");
215 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries");
217 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries");
218
219 // QtCommercial.Chart 1.3
220 qmlRegisterType<DeclarativePolarChart, 1>(uri, 1, 3, "PolarChartView");
221 qmlRegisterType<DeclarativeSplineSeries, 3>(uri, 1, 3, "SplineSeries");
222 qmlRegisterType<DeclarativeScatterSeries, 3>(uri, 1, 3, "ScatterSeries");
223 qmlRegisterType<DeclarativeLineSeries, 3>(uri, 1, 3, "LineSeries");
224 qmlRegisterType<DeclarativeAreaSeries, 3>(uri, 1, 3, "AreaSeries");
216 }
225 }
217 };
226 };
218
227
@@ -19,14 +19,15
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "axisanimation_p.h"
21 #include "axisanimation_p.h"
22 #include "chartaxis_p.h"
22 #include "chartaxiselement_p.h"
23 #include "qabstractaxis_p.h"
23
24
24 Q_DECLARE_METATYPE(QVector<qreal>)
25 Q_DECLARE_METATYPE(QVector<qreal>)
25
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
28
29
29 AxisAnimation::AxisAnimation(ChartAxis *axis)
30 AxisAnimation::AxisAnimation(ChartAxisElement *axis)
30 : ChartAnimation(axis),
31 : ChartAnimation(axis),
31 m_axis(axis),
32 m_axis(axis),
32 m_type(DefaultAnimation)
33 m_type(DefaultAnimation)
@@ -68,13 +69,13 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayo
68 oldLayout.resize(newLayout.count());
69 oldLayout.resize(newLayout.count());
69
70
70 for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
71 for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
71 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.bottom();
72 oldLayout[i] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.left() : rect.bottom();
72 oldLayout[j] = m_axis->orientation() == Qt::Horizontal ? rect.right() : rect.top();
73 oldLayout[j] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.right() : rect.top();
73 }
74 }
74 }
75 }
75 break;
76 break;
76 case ZoomInAnimation: {
77 case ZoomInAnimation: {
77 int index = qMin(oldLayout.count() * (m_axis->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0);
78 int index = qMin(oldLayout.count() * (m_axis->axis()->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0);
78 oldLayout.resize(newLayout.count());
79 oldLayout.resize(newLayout.count());
79
80
80 for (int i = 0; i < oldLayout.count(); i++)
81 for (int i = 0; i < oldLayout.count(); i++)
@@ -99,7 +100,7 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayo
99 oldLayout.resize(newLayout.count());
100 oldLayout.resize(newLayout.count());
100 QRectF rect = m_axis->gridGeometry();
101 QRectF rect = m_axis->gridGeometry();
101 for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
102 for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
102 oldLayout[i] = m_axis->orientation() == Qt::Horizontal ? rect.left() : rect.top();
103 oldLayout[i] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.left() : rect.top();
103 }
104 }
104 break;
105 break;
105 }
106 }
@@ -35,13 +35,13
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class ChartAxis;
38 class ChartAxisElement;
39
39
40 class AxisAnimation: public ChartAnimation
40 class AxisAnimation: public ChartAnimation
41 {
41 {
42 public:
42 public:
43 enum Animation { DefaultAnimation, ZoomOutAnimation, ZoomInAnimation, MoveForwardAnimation, MoveBackwordAnimation};
43 enum Animation { DefaultAnimation, ZoomOutAnimation, ZoomInAnimation, MoveForwardAnimation, MoveBackwordAnimation};
44 AxisAnimation(ChartAxis *axis);
44 AxisAnimation(ChartAxisElement *axis);
45 ~AxisAnimation();
45 ~AxisAnimation();
46 void setAnimationType(Animation type);
46 void setAnimationType(Animation type);
47 void setAnimationPoint(const QPointF &point);
47 void setAnimationPoint(const QPointF &point);
@@ -50,7 +50,7 protected:
50 QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
50 QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) const;
51 void updateCurrentValue(const QVariant &value);
51 void updateCurrentValue(const QVariant &value);
52 private:
52 private:
53 ChartAxis *m_axis;
53 ChartAxisElement *m_axis;
54 Animation m_type;
54 Animation m_type;
55 QPointF m_point;
55 QPointF m_point;
56 };
56 };
@@ -88,12 +88,26 void AreaChartItem::updatePath()
88 path = m_upper->path();
88 path = m_upper->path();
89
89
90 if (m_lower) {
90 if (m_lower) {
91 // Note: Polarcharts always draw area correctly only when both series have equal width or are
92 // fully displayed. If one series is partally off-chart, the connecting line between
93 // the series does not attach to the end of the partially hidden series but to the point
94 // where it intersects the axis line. The problem is especially noticeable when one of the series
95 // is entirely off-chart, in which case the connecting line connects two ends of the
96 // visible series.
97 // This happens because we get the paths from linechart, which omits off-chart segments.
98 // To properly fix, linechart would need to provide true full path, in right, left, and the rest
99 // portions to enable proper clipping. However, combining those to single visually unified area
100 // would be a nightmare, since they would have to be painted separately.
91 path.connectPath(m_lower->path().toReversed());
101 path.connectPath(m_lower->path().toReversed());
92 } else {
102 } else {
93 QPointF first = path.pointAtPercent(0);
103 QPointF first = path.pointAtPercent(0);
94 QPointF last = path.pointAtPercent(1);
104 QPointF last = path.pointAtPercent(1);
95 path.lineTo(last.x(), rect.bottom());
105 if (presenter()->chartType() == QChart::ChartTypeCartesian) {
96 path.lineTo(first.x(), rect.bottom());
106 path.lineTo(last.x(), rect.bottom());
107 path.lineTo(first.x(), rect.bottom());
108 } else { // polar
109 path.lineTo(rect.center());
110 }
97 }
111 }
98 path.closeSubpath();
112 path.closeSubpath();
99 prepareGeometryChange();
113 prepareGeometryChange();
@@ -137,7 +151,11 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
137 painter->save();
151 painter->save();
138 painter->setPen(m_linePen);
152 painter->setPen(m_linePen);
139 painter->setBrush(m_brush);
153 painter->setBrush(m_brush);
140 painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
154 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
155 if (presenter()->chartType() == QChart::ChartTypePolar)
156 painter->setClipRegion(QRegion(clipRect.toRect(), QRegion::Ellipse));
157 else
158 painter->setClipRect(clipRect);
141 painter->drawPath(m_path);
159 painter->drawPath(m_path);
142 if (m_pointsVisible) {
160 if (m_pointsVisible) {
143 painter->setPen(m_pointPen);
161 painter->setPen(m_pointPen);
@@ -32,11 +32,11
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "linechartitem_p.h"
34 #include "linechartitem_p.h"
35 #include "qareaseries.h"
35 #include <QPen>
36 #include <QPen>
36
37
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
39
39 class QAreaSeries;
40 class AreaChartItem;
40 class AreaChartItem;
41
41
42 class AreaChartItem : public ChartItem
42 class AreaChartItem : public ChartItem
@@ -57,6 +57,8 public:
57 void updatePath();
57 void updatePath();
58
58
59 void setPresenter(ChartPresenter *presenter);
59 void setPresenter(ChartPresenter *presenter);
60 QAreaSeries *series() const { return m_series; }
61
60 protected:
62 protected:
61 void mousePressEvent(QGraphicsSceneMouseEvent *event);
63 void mousePressEvent(QGraphicsSceneMouseEvent *event);
62 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
64 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
@@ -89,6 +91,9 public:
89 AreaBoundItem(AreaChartItem *area, QLineSeries *lineSeries,QGraphicsItem* item = 0)
91 AreaBoundItem(AreaChartItem *area, QLineSeries *lineSeries,QGraphicsItem* item = 0)
90 : LineChartItem(lineSeries, item), m_item(area)
92 : LineChartItem(lineSeries, item), m_item(area)
91 {
93 {
94 // We do not actually want to draw anything from LineChartItem.
95 // Drawing is done in AreaChartItem only.
96 setVisible(false);
92 }
97 }
93 ~AreaBoundItem() {}
98 ~AreaBoundItem() {}
94
99
@@ -97,6 +102,9 public:
97 // Turn off points drawing from component line chart item, as that
102 // Turn off points drawing from component line chart item, as that
98 // messes up the fill for area series.
103 // messes up the fill for area series.
99 suppressPoints();
104 suppressPoints();
105 // Component lineseries are not necessarily themselves on the chart,
106 // so get the chart type for them from area chart.
107 forceChartType(m_item->series()->chart()->chartType());
100 LineChartItem::updateGeometry();
108 LineChartItem::updateGeometry();
101 m_item->updatePath();
109 m_item->updatePath();
102 }
110 }
@@ -13,7 +13,8 DEPENDPATH += $$PWD \
13 $$PWD/logvalueaxis
13 $$PWD/logvalueaxis
14
14
15 SOURCES += \
15 SOURCES += \
16 $$PWD/chartaxis.cpp \
16 $$PWD/chartaxiselement.cpp \
17 $$PWD/cartesianchartaxis.cpp \
17 $$PWD/qabstractaxis.cpp \
18 $$PWD/qabstractaxis.cpp \
18 $$PWD/verticalaxis.cpp \
19 $$PWD/verticalaxis.cpp \
19 $$PWD/horizontalaxis.cpp \
20 $$PWD/horizontalaxis.cpp \
@@ -31,10 +32,12 SOURCES += \
31 $$PWD/logvalueaxis/qlogvalueaxis.cpp
32 $$PWD/logvalueaxis/qlogvalueaxis.cpp
32
33
33 PRIVATE_HEADERS += \
34 PRIVATE_HEADERS += \
34 $$PWD/chartaxis_p.h \
35 $$PWD/chartaxiselement_p.h \
36 $$PWD/cartesianchartaxis_p.h \
35 $$PWD/qabstractaxis_p.h \
37 $$PWD/qabstractaxis_p.h \
36 $$PWD/verticalaxis_p.h \
38 $$PWD/verticalaxis_p.h \
37 $$PWD/horizontalaxis_p.h \
39 $$PWD/horizontalaxis_p.h \
40 $$PWD/linearrowitem_p.h \
38 $$PWD/valueaxis/chartvalueaxisx_p.h \
41 $$PWD/valueaxis/chartvalueaxisx_p.h \
39 $$PWD/valueaxis/chartvalueaxisy_p.h \
42 $$PWD/valueaxis/chartvalueaxisy_p.h \
40 $$PWD/valueaxis/qvalueaxis_p.h \
43 $$PWD/valueaxis/qvalueaxis_p.h \
@@ -55,6 +58,29 PUBLIC_HEADERS += \
55 $$PWD/categoryaxis/qcategoryaxis.h \
58 $$PWD/categoryaxis/qcategoryaxis.h \
56 $$PWD/logvalueaxis/qlogvalueaxis.h \
59 $$PWD/logvalueaxis/qlogvalueaxis.h \
57
60
61 # polar
62 SOURCES += \
63 $$PWD/polarchartaxis.cpp \
64 $$PWD/polarchartaxisangular.cpp \
65 $$PWD/polarchartaxisradial.cpp \
66 $$PWD/valueaxis/polarchartvalueaxisangular.cpp \
67 $$PWD/valueaxis/polarchartvalueaxisradial.cpp \
68 $$PWD/logvalueaxis/polarchartlogvalueaxisangular.cpp \
69 $$PWD/logvalueaxis/polarchartlogvalueaxisradial.cpp \
70 $$PWD/categoryaxis/polarchartcategoryaxisangular.cpp \
71 $$PWD/categoryaxis/polarchartcategoryaxisradial.cpp
72
73 PRIVATE_HEADERS += \
74 $$PWD/polarchartaxis_p.h \
75 $$PWD/polarchartaxisangular_p.h \
76 $$PWD/polarchartaxisradial_p.h \
77 $$PWD/valueaxis/polarchartvalueaxisangular_p.h \
78 $$PWD/valueaxis/polarchartvalueaxisradial_p.h \
79 $$PWD/logvalueaxis/polarchartlogvalueaxisangular_p.h \
80 $$PWD/logvalueaxis/polarchartlogvalueaxisradial_p.h \
81 $$PWD/categoryaxis/polarchartcategoryaxisangular_p.h \
82 $$PWD/categoryaxis/polarchartcategoryaxisradial_p.h
83
58 !linux-arm*: {
84 !linux-arm*: {
59 INCLUDEPATH += \
85 INCLUDEPATH += \
60 $$PWD/datetimeaxis
86 $$PWD/datetimeaxis
@@ -65,12 +91,16 DEPENDPATH += \
65 SOURCES += \
91 SOURCES += \
66 $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \
92 $$PWD/datetimeaxis/chartdatetimeaxisx.cpp \
67 $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \
93 $$PWD/datetimeaxis/chartdatetimeaxisy.cpp \
68 $$PWD/datetimeaxis/qdatetimeaxis.cpp
94 $$PWD/datetimeaxis/qdatetimeaxis.cpp \
95 $$PWD/datetimeaxis/polarchartdatetimeaxisangular.cpp \
96 $$PWD/datetimeaxis/polarchartdatetimeaxisradial.cpp
69
97
70 PRIVATE_HEADERS += \
98 PRIVATE_HEADERS += \
71 $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \
99 $$PWD/datetimeaxis/chartdatetimeaxisx_p.h \
72 $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \
100 $$PWD/datetimeaxis/chartdatetimeaxisy_p.h \
73 $$PWD/datetimeaxis/qdatetimeaxis_p.h
101 $$PWD/datetimeaxis/qdatetimeaxis_p.h \
102 $$PWD/datetimeaxis/polarchartdatetimeaxisangular_p.h \
103 $$PWD/datetimeaxis/polarchartdatetimeaxisradial_p.h
74
104
75 PUBLIC_HEADERS += \
105 PUBLIC_HEADERS += \
76 $$PWD/datetimeaxis/qdatetimeaxis.h
106 $$PWD/datetimeaxis/qdatetimeaxis.h
@@ -21,7 +21,7
21 #include "chartbarcategoryaxisx_p.h"
21 #include "chartbarcategoryaxisx_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qbarcategoryaxis_p.h"
23 #include "qbarcategoryaxis_p.h"
24 #include "chartlayout_p.h"
24 #include "abstractchartlayout_p.h"
25 #include <QFontMetrics>
25 #include <QFontMetrics>
26 #include <QDebug>
26 #include <QDebug>
27 #include <qmath.h>
27 #include <qmath.h>
@@ -87,7 +87,7 QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& la
87
87
88 void ChartBarCategoryAxisX::updateGeometry()
88 void ChartBarCategoryAxisX::updateGeometry()
89 {
89 {
90 const QVector<qreal>& layout = ChartAxis::layout();
90 const QVector<qreal>& layout = ChartAxisElement::layout();
91 if (layout.isEmpty())
91 if (layout.isEmpty())
92 return;
92 return;
93 setLabels(createCategoryLabels(layout));
93 setLabels(createCategoryLabels(layout));
@@ -104,7 +104,7 QSizeF ChartBarCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constra
104 {
104 {
105 Q_UNUSED(constraint)
105 Q_UNUSED(constraint)
106
106
107 QFontMetrics fn(font());
107 QFontMetrics fn(axis()->labelsFont());
108 QSizeF sh;
108 QSizeF sh;
109 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
109 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
110 QStringList ticksList = m_categoriesAxis->categories();
110 QStringList ticksList = m_categoriesAxis->categories();
@@ -21,7 +21,7
21 #include "chartbarcategoryaxisy_p.h"
21 #include "chartbarcategoryaxisy_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qbarcategoryaxis_p.h"
23 #include "qbarcategoryaxis_p.h"
24 #include "chartlayout_p.h"
24 #include "abstractchartlayout_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <QDebug>
27 #include <QDebug>
@@ -86,7 +86,7 QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& la
86
86
87 void ChartBarCategoryAxisY::updateGeometry()
87 void ChartBarCategoryAxisY::updateGeometry()
88 {
88 {
89 const QVector<qreal>& layout = ChartAxis::layout();
89 const QVector<qreal>& layout = ChartAxisElement::layout();
90 if (layout.isEmpty())
90 if (layout.isEmpty())
91 return;
91 return;
92 setLabels(createCategoryLabels(layout));
92 setLabels(createCategoryLabels(layout));
@@ -103,7 +103,7 QSizeF ChartBarCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constra
103 {
103 {
104 Q_UNUSED(constraint)
104 Q_UNUSED(constraint)
105
105
106 QFontMetrics fn(font());
106 QFontMetrics fn(axis()->labelsFont());
107 QSizeF sh;
107 QSizeF sh;
108 QSizeF base = VerticalAxis::sizeHint(which, constraint);
108 QSizeF base = VerticalAxis::sizeHint(which, constraint);
109 QStringList ticksList = m_categoriesAxis->categories();
109 QStringList ticksList = m_categoriesAxis->categories();
@@ -111,7 +111,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
111
111
112 /*!
112 /*!
113 \fn void QBarCategoryAxis::categoriesChanged()
113 \fn void QBarCategoryAxis::categoriesChanged()
114 Axis emits signal when the categories of the axis has changed.
114 Axis emits signal when the categories of the axis have changed.
115 */
115 */
116
116
117 /*!
117 /*!
@@ -550,7 +550,7 void QBarCategoryAxisPrivate::setRange(const QString &minCategory, const QStrin
550 void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent)
550 void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent)
551 {
551 {
552 Q_Q(QBarCategoryAxis);
552 Q_Q(QBarCategoryAxis);
553 ChartAxis* axis(0);
553 ChartAxisElement* axis(0);
554 if (orientation() == Qt::Vertical)
554 if (orientation() == Qt::Vertical)
555 axis = new ChartBarCategoryAxisY(q,parent);
555 axis = new ChartBarCategoryAxisY(q,parent);
556 if (orientation() == Qt::Horizontal)
556 if (orientation() == Qt::Horizontal)
@@ -22,6 +22,7
22 #include "qcategoryaxis.h"
22 #include "qcategoryaxis.h"
23 #include "qabstractaxis.h"
23 #include "qabstractaxis.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractchartlayout_p.h"
25 #include <QGraphicsLayout>
26 #include <QGraphicsLayout>
26 #include <QFontMetrics>
27 #include <QFontMetrics>
27 #include <qmath.h>
28 #include <qmath.h>
@@ -32,6 +33,7 ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item)
32 : HorizontalAxis(axis, item, true),
33 : HorizontalAxis(axis, item, true),
33 m_axis(axis)
34 m_axis(axis)
34 {
35 {
36 QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged()));
35 }
37 }
36
38
37 ChartCategoryAxisX::~ChartCategoryAxisX()
39 ChartCategoryAxisX::~ChartCategoryAxisX()
@@ -72,16 +74,11 void ChartCategoryAxisX::updateGeometry()
72 HorizontalAxis::updateGeometry();
74 HorizontalAxis::updateGeometry();
73 }
75 }
74
76
75 void ChartCategoryAxisX::handleAxisUpdated()
76 {
77 updateGeometry();
78 }
79
80 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
77 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
81 {
78 {
82 Q_UNUSED(constraint)
79 Q_UNUSED(constraint)
83
80
84 QFontMetrics fn(font());
81 QFontMetrics fn(axis()->labelsFont());
85 QSizeF sh;
82 QSizeF sh;
86 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
83 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
87 QStringList ticksList = m_axis->categoriesLabels();
84 QStringList ticksList = m_axis->categoriesLabels();
@@ -114,4 +111,12 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
114 return sh;
111 return sh;
115 }
112 }
116
113
114 void ChartCategoryAxisX::handleCategoriesChanged()
115 {
116 QGraphicsLayoutItem::updateGeometry();
117 presenter()->layout()->invalidate();
118 }
119
120 #include "moc_chartcategoryaxisx_p.cpp"
121
117 QTCOMMERCIALCHART_END_NAMESPACE
122 QTCOMMERCIALCHART_END_NAMESPACE
@@ -35,23 +35,23
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QCategoryAxis;
37 class QCategoryAxis;
38 class ChartPresenter;
39
38
40 class ChartCategoryAxisX : public HorizontalAxis
39 class ChartCategoryAxisX : public HorizontalAxis
41 {
40 {
41 Q_OBJECT
42 public:
42 public:
43 ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item = 0);
43 ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item = 0);
44 ~ChartCategoryAxisX();
44 ~ChartCategoryAxisX();
45
45
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
47
47
48 public Q_SLOTS:
49 void handleCategoriesChanged();
50
48 protected:
51 protected:
49 QVector<qreal> calculateLayout() const;
52 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
53 void updateGeometry();
51
54
52 public Q_SLOTS:
53 void handleAxisUpdated();
54
55 private:
55 private:
56 QCategoryAxis *m_axis;
56 QCategoryAxis *m_axis;
57 };
57 };
@@ -22,6 +22,7
22 #include "qcategoryaxis.h"
22 #include "qcategoryaxis.h"
23 #include "qabstractaxis.h"
23 #include "qabstractaxis.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractchartlayout_p.h"
25 #include <QGraphicsLayout>
26 #include <QGraphicsLayout>
26 #include <QFontMetrics>
27 #include <QFontMetrics>
27 #include <qmath.h>
28 #include <qmath.h>
@@ -33,6 +34,7 ChartCategoryAxisY::ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item)
33 : VerticalAxis(axis, item, true),
34 : VerticalAxis(axis, item, true),
34 m_axis(axis)
35 m_axis(axis)
35 {
36 {
37 QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged()));
36 }
38 }
37
39
38 ChartCategoryAxisY::~ChartCategoryAxisY()
40 ChartCategoryAxisY::~ChartCategoryAxisY()
@@ -72,16 +74,11 void ChartCategoryAxisY::updateGeometry()
72 VerticalAxis::updateGeometry();
74 VerticalAxis::updateGeometry();
73 }
75 }
74
76
75 void ChartCategoryAxisY::handleAxisUpdated()
76 {
77 updateGeometry();
78 }
79
80 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
77 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
81 {
78 {
82 Q_UNUSED(constraint)
79 Q_UNUSED(constraint)
83
80
84 QFontMetrics fn(font());
81 QFontMetrics fn(axis()->labelsFont());
85 QSizeF sh;
82 QSizeF sh;
86 QSizeF base = VerticalAxis::sizeHint(which, constraint);
83 QSizeF base = VerticalAxis::sizeHint(which, constraint);
87 QStringList ticksList = m_axis->categoriesLabels();
84 QStringList ticksList = m_axis->categoriesLabels();
@@ -113,4 +110,12 QSizeF ChartCategoryAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
113 return sh;
110 return sh;
114 }
111 }
115
112
113 void ChartCategoryAxisY::handleCategoriesChanged()
114 {
115 QGraphicsLayoutItem::updateGeometry();
116 presenter()->layout()->invalidate();
117 }
118
119 #include "moc_chartcategoryaxisy_p.cpp"
120
116 QTCOMMERCIALCHART_END_NAMESPACE
121 QTCOMMERCIALCHART_END_NAMESPACE
@@ -35,23 +35,23
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QCategoryAxis;
37 class QCategoryAxis;
38 class ChartPresenter;
39
38
40 class ChartCategoryAxisY : public VerticalAxis
39 class ChartCategoryAxisY : public VerticalAxis
41 {
40 {
41 Q_OBJECT
42 public:
42 public:
43 ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item = 0);
43 ChartCategoryAxisY(QCategoryAxis *axis, QGraphicsItem* item = 0);
44 ~ChartCategoryAxisY();
44 ~ChartCategoryAxisY();
45
45
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
47
47
48 public Q_SLOTS:
49 void handleCategoriesChanged();
50
48 protected:
51 protected:
49 QVector<qreal> calculateLayout() const;
52 QVector<qreal> calculateLayout() const;
50 void updateGeometry();
53 void updateGeometry();
51
54
52 public Q_SLOTS:
53 void handleAxisUpdated();
54
55 private:
55 private:
56 QCategoryAxis *m_axis;
56 QCategoryAxis *m_axis;
57 };
57 };
@@ -22,6 +22,8
22 #include "qcategoryaxis_p.h"
22 #include "qcategoryaxis_p.h"
23 #include "chartcategoryaxisx_p.h"
23 #include "chartcategoryaxisx_p.h"
24 #include "chartcategoryaxisy_p.h"
24 #include "chartcategoryaxisy_p.h"
25 #include "polarchartcategoryaxisangular_p.h"
26 #include "polarchartcategoryaxisradial_p.h"
25 #include "qchart.h"
27 #include "qchart.h"
26 #include <qmath.h>
28 #include <qmath.h>
27 #include <QDebug>
29 #include <QDebug>
@@ -103,6 +105,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
103 */
105 */
104
106
105 /*!
107 /*!
108 \fn void QCategoryAxis::categoriesChanged()
109 Axis emits signal when the categories of the axis have changed.
110 */
111
112
113 /*!
106 Constructs an axis object which is a child of \a parent.
114 Constructs an axis object which is a child of \a parent.
107 */
115 */
108 QCategoryAxis::QCategoryAxis(QObject *parent):
116 QCategoryAxis::QCategoryAxis(QObject *parent):
@@ -151,10 +159,12 void QCategoryAxis::append(const QString &categoryLabel, qreal categoryEndValue)
151 Range range(d->m_categoryMinimum, categoryEndValue);
159 Range range(d->m_categoryMinimum, categoryEndValue);
152 d->m_categoriesMap.insert(categoryLabel, range);
160 d->m_categoriesMap.insert(categoryLabel, range);
153 d->m_categories.append(categoryLabel);
161 d->m_categories.append(categoryLabel);
162 emit categoriesChanged();
154 } else if (categoryEndValue > endValue(d->m_categories.last())) {
163 } else if (categoryEndValue > endValue(d->m_categories.last())) {
155 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
164 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
156 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
165 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
157 d->m_categories.append(categoryLabel);
166 d->m_categories.append(categoryLabel);
167 emit categoriesChanged();
158 }
168 }
159 }
169 }
160 }
170 }
@@ -169,10 +179,13 void QCategoryAxis::setStartValue(qreal min)
169 Q_D(QCategoryAxis);
179 Q_D(QCategoryAxis);
170 if (d->m_categories.isEmpty()) {
180 if (d->m_categories.isEmpty()) {
171 d->m_categoryMinimum = min;
181 d->m_categoryMinimum = min;
182 emit categoriesChanged();
172 } else {
183 } else {
173 Range range = d->m_categoriesMap.value(d->m_categories.first());
184 Range range = d->m_categoriesMap.value(d->m_categories.first());
174 if (min < range.second)
185 if (min < range.second) {
175 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
186 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
187 emit categoriesChanged();
188 }
176 }
189 }
177 }
190 }
178
191
@@ -227,7 +240,7 void QCategoryAxis::remove(const QString &categoryLabel)
227 d->m_categoriesMap.insert(label, range);
240 d->m_categoriesMap.insert(label, range);
228 }
241 }
229 }
242 }
230 //TODO:: d->emitUpdated();
243 emit categoriesChanged();
231 }
244 }
232 }
245 }
233
246
@@ -251,7 +264,7 void QCategoryAxis::replaceLabel(const QString &oldLabel, const QString &newLabe
251 Range range = d->m_categoriesMap.value(oldLabel);
264 Range range = d->m_categoriesMap.value(oldLabel);
252 d->m_categoriesMap.remove(oldLabel);
265 d->m_categoriesMap.remove(oldLabel);
253 d->m_categoriesMap.insert(newLabel, range);
266 d->m_categoriesMap.insert(newLabel, range);
254 //TODO:: d->emitUpdated();
267 emit categoriesChanged();
255 }
268 }
256 }
269 }
257
270
@@ -300,14 +313,23 int QCategoryAxisPrivate::ticksCount() const
300 return m_categories.count() + 1;
313 return m_categories.count() + 1;
301 }
314 }
302
315
303 void QCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent)
316 void QCategoryAxisPrivate::initializeGraphics(QGraphicsItem *parent)
304 {
317 {
305 Q_Q(QCategoryAxis);
318 Q_Q(QCategoryAxis);
306 ChartAxis* axis(0);
319 ChartAxisElement *axis(0);
307 if (orientation() == Qt::Vertical)
320 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
308 axis = new ChartCategoryAxisY(q,parent);
321 if (orientation() == Qt::Vertical)
309 else if(orientation() == Qt::Horizontal)
322 axis = new ChartCategoryAxisY(q,parent);
310 axis = new ChartCategoryAxisX(q,parent);
323 else if (orientation() == Qt::Horizontal)
324 axis = new ChartCategoryAxisX(q,parent);
325 }
326
327 if (m_chart->chartType() == QChart::ChartTypePolar) {
328 if (orientation() == Qt::Vertical)
329 axis = new PolarChartCategoryAxisRadial(q, parent);
330 if (orientation() == Qt::Horizontal)
331 axis = new PolarChartCategoryAxisAngular(q, parent);
332 }
311
333
312 m_item.reset(axis);
334 m_item.reset(axis);
313 QAbstractAxisPrivate::initializeGraphics(parent);
335 QAbstractAxisPrivate::initializeGraphics(parent);
@@ -57,6 +57,9 public:
57 QStringList categoriesLabels();
57 QStringList categoriesLabels();
58 int count() const;
58 int count() const;
59
59
60 Q_SIGNALS:
61 void categoriesChanged();
62
60 private:
63 private:
61 Q_DECLARE_PRIVATE(QCategoryAxis)
64 Q_DECLARE_PRIVATE(QCategoryAxis)
62 Q_DISABLE_COPY(QCategoryAxis)
65 Q_DISABLE_COPY(QCategoryAxis)
@@ -48,9 +48,6 public:
48 void initializeGraphics(QGraphicsItem* parent);
48 void initializeGraphics(QGraphicsItem* parent);
49 int ticksCount() const;
49 int ticksCount() const;
50
50
51 Q_SIGNALS:
52 void changed(qreal min, qreal max, int tickCount, bool niceNumbers);
53
54 private:
51 private:
55 QMap<QString , Range> m_categoriesMap;
52 QMap<QString , Range> m_categoriesMap;
56 QStringList m_categories;
53 QStringList m_categories;
@@ -27,8 +27,8
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTAXIS_H
30 #ifndef CHARTAXISELEMENT_H
31 #define CHARTAXIS_H
31 #define CHARTAXISELEMENT_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "chartelement_p.h"
34 #include "chartelement_p.h"
@@ -39,163 +39,113
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 class QAbstractAxis;
43 class ChartPresenter;
42 class ChartPresenter;
43 class QAbstractAxis;
44
44
45 class ChartAxis : public ChartElement, public QGraphicsLayoutItem
45 class ChartAxisElement : public ChartElement, public QGraphicsLayoutItem
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 Q_INTERFACES(QGraphicsLayoutItem)
49 public:
48 public:
49 ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false);
50 ~ChartAxisElement();
51
52 virtual QRectF gridGeometry() const = 0;
53 virtual void setGeometry(const QRectF &axis, const QRectF &grid) = 0;
54 virtual bool isEmpty() = 0;
55
56 void setAnimation(AxisAnimation *animation) { m_animation = animation; }
57 AxisAnimation *animation() const { return m_animation; }
58
59 QAbstractAxis *axis() const { return m_axis; }
60 void setLayout(QVector<qreal> &layout) { m_layout = layout; }
61 QVector<qreal> &layout() { return m_layout; } // Modifiable reference
62 int labelPadding() const { return 5; }
63 int titlePadding() const { return 3; }
64 void setLabels(const QStringList &labels) { m_labelsList = labels; }
65 QStringList labels() const { return m_labelsList; }
50
66
51 ChartAxis(QAbstractAxis *axis, QGraphicsItem* item = 0, bool intervalAxis = false);
67 qreal min() const;
52 ~ChartAxis();
68 qreal max() const;
53
54 QAbstractAxis* axis() const { return m_axis; }
55
56 void setLabelPadding(int padding);
57 int labelPadding() const { return m_labelPadding;};
58
59 void setTitlePadding(int padding);
60 int titlePadding() const { return m_titlePadding;};
61
62 QFont titleFont() const;
63 QString titleText() const;
64
65 void setLayout(QVector<qreal> &layout);
66 QVector<qreal> layout() const { return m_layoutVector; }
67
68 void setAnimation(AxisAnimation *animation);
69 ChartAnimation *animation() const { return m_animation; };
70
71 Qt::Orientation orientation() const;
72 Qt::Alignment alignment() const;
73
69
74 void setGeometry(const QRectF &axis, const QRectF &grid);
75 QRectF axisGeometry() const { return m_axisRect; }
70 QRectF axisGeometry() const { return m_axisRect; }
76 QRectF gridGeometry() const { return m_gridRect; }
71 void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; }
77
72
78 void setLabels(const QStringList &labels);
73 QRect labelBoundingRect(const QFontMetrics &fn, const QString &label) const;
79 QStringList labels() const { return m_labelsList; }
74
75 void axisSelected();
80
76
81 //this flag indicates that axis is used to show intervals it means labels are in between ticks
77 //this flag indicates that axis is used to show intervals it means labels are in between ticks
82 bool intervalAxis() const { return m_intervalAxis; }
78 bool intervalAxis() const { return m_intervalAxis; }
83
79
84 virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
80 static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format);
85
81 static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format);
82 static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format);
86
83
87 QRectF boundingRect() const{
84 // from QGraphicsLayoutItem
85 QRectF boundingRect() const
86 {
88 return QRectF();
87 return QRectF();
89 }
88 }
90
89
90 // from QGraphicsLayoutItem
91 void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
91 void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
92 {
92 {
93
94 }
93 }
95
94
96 //helpers
97 static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format);
98 static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format);
99 static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format);
100
101 protected:
95 protected:
102 void setGeometry(const QRectF &size) { Q_UNUSED(size);};
103 virtual void updateGeometry() = 0;
104 virtual QVector<qreal> calculateLayout() const = 0;
96 virtual QVector<qreal> calculateLayout() const = 0;
97 virtual void updateLayout(QVector<qreal> &layout) = 0;
98
99 QList<QGraphicsItem *> gridItems() { return m_grid->childItems(); }
100 QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); }
101 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); }
102 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); }
103 QGraphicsSimpleTextItem *titleItem() const { return m_title.data(); }
104 QGraphicsItemGroup *gridGroup() { return m_grid.data(); }
105 QGraphicsItemGroup *labelGroup() { return m_labels.data(); }
106 QGraphicsItemGroup *shadeGroup() { return m_shades.data(); }
107 QGraphicsItemGroup *arrowGroup() { return m_arrow.data(); }
105
108
106 QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); };
107 QList<QGraphicsItem *> labelItems() { return m_labels->childItems();};
108 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();};
109 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();};
110 QGraphicsSimpleTextItem* titleItem() const { return m_title.data();}
111
112 QFont font() const;
113 qreal min() const;
114 qreal max() const;
115 QRect labelBoundingRect(const QFontMetrics &fn, const QString &label) const;
116
117 //handlers
118 public Q_SLOTS:
109 public Q_SLOTS:
119 void handleVisibleChanged(bool visible);
110 void handleVisibleChanged(bool visible);
120 void handleArrowVisibleChanged(bool visible);
111 void handleArrowVisibleChanged(bool visible);
121 void handleGridVisibleChanged(bool visible);
112 void handleGridVisibleChanged(bool visible);
122 void handleLabelsVisibleChanged(bool visible);
113 void handleLabelsVisibleChanged(bool visible);
123 void handleShadesVisibleChanged(bool visible);
114 void handleShadesVisibleChanged(bool visible);
124 void handleLabelsAngleChanged(int angle);
115 void handleLabelsAngleChanged(int angle);
125 void handleShadesBrushChanged(const QBrush &brush);
116 virtual void handleShadesBrushChanged(const QBrush &brush) = 0;
126 void handleShadesPenChanged(const QPen &pen);
117 virtual void handleShadesPenChanged(const QPen &pen) = 0;
127 void handleArrowPenChanged(const QPen &pen);
118 virtual void handleArrowPenChanged(const QPen &pen) = 0;
128 void handleGridPenChanged(const QPen &pen);
119 virtual void handleGridPenChanged(const QPen &pen) = 0;
129 void handleLabelsPenChanged(const QPen &pen);
120 void handleLabelsPenChanged(const QPen &pen);
130 void handleLabelsBrushChanged(const QBrush &brush);
121 void handleLabelsBrushChanged(const QBrush &brush);
131 void handleLabelsFontChanged(const QFont &font);
122 void handleLabelsFontChanged(const QFont &font);
132 void handleTitlePenChanged(const QPen &pen);
123 void handleTitlePenChanged(const QPen &pen);
133 void handleTitleBrushChanged(const QBrush &brush);
124 void handleTitleBrushChanged(const QBrush &brush);
134 void handleTitleFontChanged(const QFont &font);
125 void handleTitleFontChanged(const QFont &font);
135 void handleTitleTextChanged(const QString &title);
126 void handleTitleTextChanged(const QString &title);
136 void handleTitleVisibleChanged(bool visible);
127 void handleTitleVisibleChanged(bool visible);
137 void handleRangeChanged(qreal min , qreal max);
128 void handleRangeChanged(qreal min, qreal max);
138
129
139 Q_SIGNALS:
130 Q_SIGNALS:
140 void clicked();
131 void clicked();
141
132
142 private:
133 private:
143 inline bool isEmpty();
144 void createItems(int count);
145 void deleteItems(int count);
146 void updateLayout(QVector<qreal> &layout);
147 void axisSelected();
148 void connectSlots();
134 void connectSlots();
149
135
150 private:
151 QAbstractAxis *m_axis;
136 QAbstractAxis *m_axis;
152 int m_labelsAngle;
137 AxisAnimation *m_animation;
138 QVector<qreal> m_layout;
139 QStringList m_labelsList;
153 QRectF m_axisRect;
140 QRectF m_axisRect;
154 QRectF m_gridRect;
155 QScopedPointer<QGraphicsItemGroup> m_grid;
141 QScopedPointer<QGraphicsItemGroup> m_grid;
156 QScopedPointer<QGraphicsItemGroup> m_arrow;
142 QScopedPointer<QGraphicsItemGroup> m_arrow;
157 QScopedPointer<QGraphicsItemGroup> m_shades;
143 QScopedPointer<QGraphicsItemGroup> m_shades;
158 QScopedPointer<QGraphicsItemGroup> m_labels;
144 QScopedPointer<QGraphicsItemGroup> m_labels;
159 QScopedPointer<QGraphicsSimpleTextItem> m_title;
145 QScopedPointer<QGraphicsSimpleTextItem> m_title;
160 QVector<qreal> m_layoutVector;
161 AxisAnimation *m_animation;
162 int m_labelPadding;
163 QStringList m_labelsList;
164 bool m_intervalAxis;
146 bool m_intervalAxis;
165 int m_titlePadding;
166
167 friend class AxisAnimation;
168 friend class ArrowItem;
169
170 };
171
172 class ArrowItem: public QGraphicsLineItem
173 {
174
175 public:
176 explicit ArrowItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
177
178 protected:
179 void mousePressEvent(QGraphicsSceneMouseEvent *event) {
180 Q_UNUSED(event)
181 m_axis->axisSelected();
182 }
183
184 QRectF boundingRect() const {
185 return shape().boundingRect();
186 }
187
188 QPainterPath shape() const {
189 QPainterPath path = QGraphicsLineItem::shape();
190 QRectF rect = path.boundingRect();
191 path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0));
192 return path;
193 }
194
195 private:
196 ChartAxis *m_axis;
197 };
147 };
198
148
199 QTCOMMERCIALCHART_END_NAMESPACE
149 QTCOMMERCIALCHART_END_NAMESPACE
200
150
201 #endif /* CHARTAXI_H */
151 #endif /* CHARTAXISELEMENT_H */
@@ -21,7 +21,7
21 #include "chartdatetimeaxisx_p.h"
21 #include "chartdatetimeaxisx_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qdatetimeaxis.h"
23 #include "qdatetimeaxis.h"
24 #include "chartlayout_p.h"
24 #include "abstractchartlayout_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDateTime>
26 #include <QDateTime>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
@@ -29,12 +29,12
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, QGraphicsItem* item)
32 ChartDateTimeAxisX::ChartDateTimeAxisX(QDateTimeAxis *axis, QGraphicsItem *item)
33 : HorizontalAxis(axis, item),
33 : HorizontalAxis(axis, item),
34 m_axis(axis)
34 m_axis(axis)
35 {
35 {
36 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
36 QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int)));
37 QObject::connect(m_axis,SIGNAL(formatChanged(QString)),this, SLOT(handleFormatChanged(QString)));
37 QObject::connect(m_axis, SIGNAL(formatChanged(QString)), this, SLOT(handleFormatChanged(QString)));
38 }
38 }
39
39
40 ChartDateTimeAxisX::~ChartDateTimeAxisX()
40 ChartDateTimeAxisX::~ChartDateTimeAxisX()
@@ -58,10 +58,10 QVector<qreal> ChartDateTimeAxisX::calculateLayout() const
58
58
59 void ChartDateTimeAxisX::updateGeometry()
59 void ChartDateTimeAxisX::updateGeometry()
60 {
60 {
61 const QVector<qreal>& layout = ChartAxis::layout();
61 const QVector<qreal>& layout = ChartAxisElement::layout();
62 if (layout.isEmpty())
62 if (layout.isEmpty())
63 return;
63 return;
64 setLabels(createDateTimeLabels(min(),max(), layout.size(),m_axis->format()));
64 setLabels(createDateTimeLabels(min(), max(), layout.size(), m_axis->format()));
65 HorizontalAxis::updateGeometry();
65 HorizontalAxis::updateGeometry();
66 }
66 }
67
67
@@ -69,25 +69,27 void ChartDateTimeAxisX::handleTickCountChanged(int tick)
69 {
69 {
70 Q_UNUSED(tick)
70 Q_UNUSED(tick)
71 QGraphicsLayoutItem::updateGeometry();
71 QGraphicsLayoutItem::updateGeometry();
72 if(presenter()) presenter()->layout()->invalidate();
72 if (presenter())
73 presenter()->layout()->invalidate();
73 }
74 }
74
75
75 void ChartDateTimeAxisX::handleFormatChanged(const QString &format)
76 void ChartDateTimeAxisX::handleFormatChanged(const QString &format)
76 {
77 {
77 Q_UNUSED(format);
78 Q_UNUSED(format);
78 QGraphicsLayoutItem::updateGeometry();
79 QGraphicsLayoutItem::updateGeometry();
79 if(presenter()) presenter()->layout()->invalidate();
80 if (presenter())
81 presenter()->layout()->invalidate();
80 }
82 }
81
83
82 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
84 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
83 {
85 {
84 Q_UNUSED(constraint)
86 Q_UNUSED(constraint)
85
87
86 QFontMetrics fn(font());
88 QFontMetrics fn(axis()->labelsFont());
87 QSizeF sh;
89 QSizeF sh;
88
90
89 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
91 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
90 QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format());
92 QStringList ticksList = createDateTimeLabels(min(), max(), m_axis->tickCount(), m_axis->format());
91 // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past
93 // Width of horizontal axis sizeHint indicates the maximum distance labels can extend past
92 // first and last ticks. Base width is irrelevant.
94 // first and last ticks. Base width is irrelevant.
93 qreal width = 0;
95 qreal width = 0;
@@ -97,7 +99,7 QSizeF ChartDateTimeAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
97 return sh;
99 return sh;
98
100
99 switch (which) {
101 switch (which) {
100 case Qt::MinimumSize:{
102 case Qt::MinimumSize: {
101 QRectF boundingRect = labelBoundingRect(fn, "...");
103 QRectF boundingRect = labelBoundingRect(fn, "...");
102 width = boundingRect.width() / 2.0;
104 width = boundingRect.width() / 2.0;
103 height = boundingRect.height() + labelPadding();
105 height = boundingRect.height() + labelPadding();
@@ -35,7 +35,6
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QDateTimeAxis;
37 class QDateTimeAxis;
38 class ChartPresenter;
39
38
40 class ChartDateTimeAxisX : public HorizontalAxis
39 class ChartDateTimeAxisX : public HorizontalAxis
41 {
40 {
@@ -21,7 +21,7
21 #include "chartdatetimeaxisy_p.h"
21 #include "chartdatetimeaxisy_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qdatetimeaxis.h"
23 #include "qdatetimeaxis.h"
24 #include "chartlayout_p.h"
24 #include "abstractchartlayout_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <QDateTime>
27 #include <QDateTime>
@@ -29,12 +29,12
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, QGraphicsItem* item)
32 ChartDateTimeAxisY::ChartDateTimeAxisY(QDateTimeAxis *axis, QGraphicsItem *item)
33 : VerticalAxis(axis, item),
33 : VerticalAxis(axis, item),
34 m_axis(axis)
34 m_axis(axis)
35 {
35 {
36 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
36 QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int)));
37 QObject::connect(m_axis,SIGNAL(formatChanged(QString)),this, SLOT(handleFormatChanged(QString)));
37 QObject::connect(m_axis, SIGNAL(formatChanged(QString)), this, SLOT(handleFormatChanged(QString)));
38 }
38 }
39
39
40 ChartDateTimeAxisY::~ChartDateTimeAxisY()
40 ChartDateTimeAxisY::~ChartDateTimeAxisY()
@@ -59,10 +59,10 QVector<qreal> ChartDateTimeAxisY::calculateLayout() const
59
59
60 void ChartDateTimeAxisY::updateGeometry()
60 void ChartDateTimeAxisY::updateGeometry()
61 {
61 {
62 const QVector<qreal> &layout = ChartAxis::layout();
62 const QVector<qreal> &layout = ChartAxisElement::layout();
63 if (layout.isEmpty())
63 if (layout.isEmpty())
64 return;
64 return;
65 setLabels(createDateTimeLabels(min(),max(), layout.size(),m_axis->format()));
65 setLabels(createDateTimeLabels(min(), max(), layout.size(), m_axis->format()));
66 VerticalAxis::updateGeometry();
66 VerticalAxis::updateGeometry();
67 }
67 }
68
68
@@ -70,25 +70,27 void ChartDateTimeAxisY::handleTickCountChanged(int tick)
70 {
70 {
71 Q_UNUSED(tick)
71 Q_UNUSED(tick)
72 QGraphicsLayoutItem::updateGeometry();
72 QGraphicsLayoutItem::updateGeometry();
73 if(presenter()) presenter()->layout()->invalidate();
73 if (presenter())
74 presenter()->layout()->invalidate();
74 }
75 }
75
76
76 void ChartDateTimeAxisY::handleFormatChanged(const QString &format)
77 void ChartDateTimeAxisY::handleFormatChanged(const QString &format)
77 {
78 {
78 Q_UNUSED(format);
79 Q_UNUSED(format);
79 QGraphicsLayoutItem::updateGeometry();
80 QGraphicsLayoutItem::updateGeometry();
80 if(presenter()) presenter()->layout()->invalidate();
81 if (presenter())
82 presenter()->layout()->invalidate();
81 }
83 }
82
84
83 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
85 QSizeF ChartDateTimeAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
84 {
86 {
85 Q_UNUSED(constraint)
87 Q_UNUSED(constraint)
86
88
87 QFontMetrics fn(font());
89 QFontMetrics fn(axis()->labelsFont());
88 QSizeF sh;
90 QSizeF sh;
89
91
90 QSizeF base = VerticalAxis::sizeHint(which, constraint);
92 QSizeF base = VerticalAxis::sizeHint(which, constraint);
91 QStringList ticksList = createDateTimeLabels(min(),max(),m_axis->tickCount(),m_axis->format());
93 QStringList ticksList = createDateTimeLabels(min(), max(), m_axis->tickCount(), m_axis->format());
92 qreal width = 0;
94 qreal width = 0;
93 // Height of vertical axis sizeHint indicates the maximum distance labels can extend past
95 // Height of vertical axis sizeHint indicates the maximum distance labels can extend past
94 // first and last ticks. Base height is irrelevant.
96 // first and last ticks. Base height is irrelevant.
@@ -35,7 +35,6
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QDateTimeAxis;
37 class QDateTimeAxis;
38 class ChartPresenter;
39
38
40 class ChartDateTimeAxisY : public VerticalAxis
39 class ChartDateTimeAxisY : public VerticalAxis
41 {
40 {
@@ -22,6 +22,8
22 #include "qdatetimeaxis_p.h"
22 #include "qdatetimeaxis_p.h"
23 #include "chartdatetimeaxisx_p.h"
23 #include "chartdatetimeaxisx_p.h"
24 #include "chartdatetimeaxisy_p.h"
24 #include "chartdatetimeaxisy_p.h"
25 #include "polarchartdatetimeaxisangular_p.h"
26 #include "polarchartdatetimeaxisradial_p.h"
25 #include "abstractdomain_p.h"
27 #include "abstractdomain_p.h"
26 #include "qchart.h"
28 #include "qchart.h"
27 #include <float.h>
29 #include <float.h>
@@ -342,11 +344,20 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
342 void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent)
344 void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent)
343 {
345 {
344 Q_Q(QDateTimeAxis);
346 Q_Q(QDateTimeAxis);
345 ChartAxis* axis(0);
347 ChartAxisElement *axis(0);
346 if (orientation() == Qt::Vertical)
348 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
347 axis = new ChartDateTimeAxisY(q,parent);
349 if (orientation() == Qt::Vertical)
348 if (orientation() == Qt::Horizontal)
350 axis = new ChartDateTimeAxisY(q,parent);
349 axis = new ChartDateTimeAxisX(q,parent);
351 if (orientation() == Qt::Horizontal)
352 axis = new ChartDateTimeAxisX(q,parent);
353 }
354
355 if (m_chart->chartType() == QChart::ChartTypePolar) {
356 if (orientation() == Qt::Vertical)
357 axis = new PolarChartDateTimeAxisRadial(q, parent);
358 if (orientation() == Qt::Horizontal)
359 axis = new PolarChartDateTimeAxisAngular(q, parent);
360 }
350
361
351 m_item.reset(axis);
362 m_item.reset(axis);
352 QAbstractAxisPrivate::initializeGraphics(parent);
363 QAbstractAxisPrivate::initializeGraphics(parent);
@@ -19,15 +19,15
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "horizontalaxis_p.h"
21 #include "horizontalaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
23 #include <QFontMetrics>
23 #include <QFontMetrics>
24 #include <qmath.h>
24 #include <qmath.h>
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis)
29 HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
30 : ChartAxis(axis, item, intervalAxis)
30 : CartesianChartAxis(axis, item, intervalAxis)
31 {
31 {
32 }
32 }
33
33
@@ -37,18 +37,18 HorizontalAxis::~HorizontalAxis()
37
37
38 void HorizontalAxis::updateGeometry()
38 void HorizontalAxis::updateGeometry()
39 {
39 {
40 const QVector<qreal>& layout = ChartAxis::layout();
40 const QVector<qreal> &layout = ChartAxisElement::layout();
41
41
42 if (layout.isEmpty())
42 if (layout.isEmpty())
43 return;
43 return;
44
44
45 QStringList labelList = labels();
45 QStringList labelList = labels();
46
46
47 QList<QGraphicsItem *> lines = lineItems();
47 QList<QGraphicsItem *> lines = gridItems();
48 QList<QGraphicsItem *> labels = labelItems();
48 QList<QGraphicsItem *> labels = labelItems();
49 QList<QGraphicsItem *> shades = shadeItems();
49 QList<QGraphicsItem *> shades = shadeItems();
50 QList<QGraphicsItem *> axis = arrowItems();
50 QList<QGraphicsItem *> arrow = arrowItems();
51 QGraphicsSimpleTextItem* title = titleItem();
51 QGraphicsSimpleTextItem *title = titleItem();
52
52
53 Q_ASSERT(labels.size() == labelList.size());
53 Q_ASSERT(labels.size() == labelList.size());
54 Q_ASSERT(layout.size() == labelList.size());
54 Q_ASSERT(layout.size() == labelList.size());
@@ -57,24 +57,24 void HorizontalAxis::updateGeometry()
57 const QRectF &gridRect = gridGeometry();
57 const QRectF &gridRect = gridGeometry();
58
58
59 //arrow
59 //arrow
60 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(axis.at(0));
60 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(arrow.at(0));
61
61
62 if (alignment() == Qt::AlignTop)
62 if (axis()->alignment() == Qt::AlignTop)
63 arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom());
63 arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom());
64 else if (alignment() == Qt::AlignBottom)
64 else if (axis()->alignment() == Qt::AlignBottom)
65 arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top());
65 arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top());
66
66
67 qreal width = 0;
67 qreal width = 0;
68 QFontMetrics fn(font());
68 QFontMetrics fn(axis()->labelsFont());
69
69
70 //title
70 //title
71 int titlePad = 0;
71 int titlePad = 0;
72 QRectF titleBoundingRect;
72 QRectF titleBoundingRect;
73 if (!titleText().isEmpty() && titleItem()->isVisible()) {
73 QString titleText = axis()->titleText();
74 if (!titleText.isEmpty() && titleItem()->isVisible()) {
74 QFontMetrics fn(title->font());
75 QFontMetrics fn(title->font());
75 int size(0);
76 int size(0);
76 size = gridRect.width();
77 size = gridRect.width();
77 QString titleText = this->titleText();
78
78
79 if (fn.boundingRect(titleText).width() > size) {
79 if (fn.boundingRect(titleText).width() > size) {
80 QString string = titleText + "...";
80 QString string = titleText + "...";
@@ -89,9 +89,9 void HorizontalAxis::updateGeometry()
89 titleBoundingRect = title->boundingRect();
89 titleBoundingRect = title->boundingRect();
90
90
91 QPointF center = gridRect.center() - titleBoundingRect.center();
91 QPointF center = gridRect.center() - titleBoundingRect.center();
92 if (alignment() == Qt::AlignTop) {
92 if (axis()->alignment() == Qt::AlignTop) {
93 title->setPos(center.x(), axisRect.top() + titlePad);
93 title->setPos(center.x(), axisRect.top() + titlePad);
94 } else if (alignment() == Qt::AlignBottom) {
94 } else if (axis()->alignment() == Qt::AlignBottom) {
95 title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePad);
95 title->setPos(center.x(), axisRect.bottom() - titleBoundingRect.height() - titlePad);
96 }
96 }
97 }
97 }
@@ -100,7 +100,7 void HorizontalAxis::updateGeometry()
100
100
101 //items
101 //items
102 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i));
102 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i));
103 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(axis.at(i + 1));
103 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(arrow.at(i + 1));
104 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
104 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
105
105
106 //grid line
106 //grid line
@@ -128,10 +128,10 void HorizontalAxis::updateGeometry()
128 int heightDiff = rect.height() - boundingRect.height();
128 int heightDiff = rect.height() - boundingRect.height();
129
129
130 //ticks and label position
130 //ticks and label position
131 if (alignment() == Qt::AlignTop) {
131 if (axis()->alignment() == Qt::AlignTop) {
132 labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() + (heightDiff / 2) - labelPadding());
132 labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() + (heightDiff / 2) - labelPadding());
133 tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding());
133 tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding());
134 } else if (alignment() == Qt::AlignBottom) {
134 } else if (axis()->alignment() == Qt::AlignBottom) {
135 labelItem->setPos(layout[i] - center.x(), axisRect.top() - (heightDiff / 2) + labelPadding());
135 labelItem->setPos(layout[i] - center.x(), axisRect.top() - (heightDiff / 2) + labelPadding());
136 tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding());
136 tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding());
137 }
137 }
@@ -178,7 +178,7 void HorizontalAxis::updateGeometry()
178 if (x < gridRect.left() || x > gridRect.right()) {
178 if (x < gridRect.left() || x > gridRect.right()) {
179 gridItem->setVisible(false);
179 gridItem->setVisible(false);
180 tickItem->setVisible(false);
180 tickItem->setVisible(false);
181 }else{
181 } else {
182 gridItem->setVisible(true);
182 gridItem->setVisible(true);
183 tickItem->setVisible(true);
183 tickItem->setVisible(true);
184 }
184 }
@@ -200,10 +200,10 void HorizontalAxis::updateGeometry()
200 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
200 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
201 {
201 {
202 Q_UNUSED(constraint);
202 Q_UNUSED(constraint);
203 QFontMetrics fn(titleFont());
203 QFontMetrics fn(axis()->titleFont());
204 QSizeF sh(0,0);
204 QSizeF sh(0,0);
205
205
206 if (titleText().isEmpty() || !titleItem()->isVisible())
206 if (axis()->titleText().isEmpty() || !titleItem()->isVisible())
207 return sh;
207 return sh;
208
208
209 switch (which) {
209 switch (which) {
@@ -30,14 +30,14
30 #ifndef HORIZONTALAXIS_P_H_
30 #ifndef HORIZONTALAXIS_P_H_
31 #define HORIZONTALAXIS_P_H_
31 #define HORIZONTALAXIS_P_H_
32
32
33 #include "chartaxis_p.h"
33 #include "cartesianchartaxis_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class HorizontalAxis : public ChartAxis
37 class HorizontalAxis : public CartesianChartAxis
38 {
38 {
39 public:
39 public:
40 HorizontalAxis(QAbstractAxis *axis, QGraphicsItem* item = 0, bool intervalAxis = false);
40 HorizontalAxis(QAbstractAxis *axis, QGraphicsItem *item = 0, bool intervalAxis = false);
41 ~HorizontalAxis();
41 ~HorizontalAxis();
42 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
42 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
43 protected:
43 protected:
@@ -21,7 +21,7
21 #include "chartlogvalueaxisx_p.h"
21 #include "chartlogvalueaxisx_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlogvalueaxis.h"
23 #include "qlogvalueaxis.h"
24 #include "chartlayout_p.h"
24 #include "abstractchartlayout_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <qmath.h>
27 #include <qmath.h>
@@ -29,12 +29,12
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item)
32 ChartLogValueAxisX::ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem *item)
33 : HorizontalAxis(axis, item),
33 : HorizontalAxis(axis, item),
34 m_axis(axis)
34 m_axis(axis)
35 {
35 {
36 QObject::connect(m_axis,SIGNAL(baseChanged(qreal)),this, SLOT(handleBaseChanged(qreal)));
36 QObject::connect(m_axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal)));
37 QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString)));
37 QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
38 }
38 }
39
39
40 ChartLogValueAxisX::~ChartLogValueAxisX()
40 ChartLogValueAxisX::~ChartLogValueAxisX()
@@ -55,14 +55,14 QVector<qreal> ChartLogValueAxisX::calculateLayout() const
55 const QRectF &gridRect = gridGeometry();
55 const QRectF &gridRect = gridGeometry();
56 const qreal deltaX = gridRect.width() / qAbs(logMax - logMin);
56 const qreal deltaX = gridRect.width() / qAbs(logMax - logMin);
57 for (int i = 0; i < tickCount; ++i)
57 for (int i = 0; i < tickCount; ++i)
58 points[i] = (ceilEdge + i) * deltaX - leftEdge * deltaX + gridRect.left();
58 points[i] = (ceilEdge + qreal(i)) * deltaX - leftEdge * deltaX + gridRect.left();
59
59
60 return points;
60 return points;
61 }
61 }
62
62
63 void ChartLogValueAxisX::updateGeometry()
63 void ChartLogValueAxisX::updateGeometry()
64 {
64 {
65 const QVector<qreal>& layout = ChartAxis::layout();
65 const QVector<qreal>& layout = ChartAxisElement::layout();
66 if (layout.isEmpty())
66 if (layout.isEmpty())
67 return;
67 return;
68 setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat()));
68 setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat()));
@@ -87,7 +87,7 QSizeF ChartLogValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint
87 {
87 {
88 Q_UNUSED(constraint)
88 Q_UNUSED(constraint)
89
89
90 QFontMetrics fn(font());
90 QFontMetrics fn(axis()->labelsFont());
91 QSizeF sh;
91 QSizeF sh;
92
92
93 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
93 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
@@ -35,20 +35,18
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QLogValueAxis;
37 class QLogValueAxis;
38 class ChartPresenter;
39
38
40 class ChartLogValueAxisX : public HorizontalAxis
39 class ChartLogValueAxisX : public HorizontalAxis
41 {
40 {
42 Q_OBJECT
41 Q_OBJECT
43
42
44 public:
43 public:
45 ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem* item);
44 ChartLogValueAxisX(QLogValueAxis *axis, QGraphicsItem *item);
46 ~ChartLogValueAxisX();
45 ~ChartLogValueAxisX();
47
46
48 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
47 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
49
48
50 protected:
49 protected:
51 void handleAxisUpdated();
52 QVector<qreal> calculateLayout() const;
50 QVector<qreal> calculateLayout() const;
53 void updateGeometry();
51 void updateGeometry();
54
52
@@ -21,7 +21,7
21 #include "chartlogvalueaxisy_p.h"
21 #include "chartlogvalueaxisy_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlogvalueaxis.h"
23 #include "qlogvalueaxis.h"
24 #include "chartlayout_p.h"
24 #include "abstractchartlayout_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QFontMetrics>
26 #include <QFontMetrics>
27 #include <qmath.h>
27 #include <qmath.h>
@@ -29,12 +29,12
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item)
32 ChartLogValueAxisY::ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem *item)
33 : VerticalAxis(axis, item),
33 : VerticalAxis(axis, item),
34 m_axis(axis)
34 m_axis(axis)
35 {
35 {
36 QObject::connect(m_axis, SIGNAL(baseChanged(qreal)),this, SLOT(handleBaseChanged(qreal)));
36 QObject::connect(m_axis, SIGNAL(baseChanged(qreal)), this, SLOT(handleBaseChanged(qreal)));
37 QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString)));
37 QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
38 }
38 }
39
39
40 ChartLogValueAxisY::~ChartLogValueAxisY()
40 ChartLogValueAxisY::~ChartLogValueAxisY()
@@ -54,7 +54,7 QVector<qreal> ChartLogValueAxisY::calculateLayout() const
54 const QRectF &gridRect = gridGeometry();
54 const QRectF &gridRect = gridGeometry();
55 const qreal deltaY = gridRect.height() / qAbs(logMax - logMin);
55 const qreal deltaY = gridRect.height() / qAbs(logMax - logMin);
56 for (int i = 0; i < tickCount; ++i)
56 for (int i = 0; i < tickCount; ++i)
57 points[i] = (ceilEdge + i) * -deltaY - leftEdge * -deltaY + gridRect.bottom();
57 points[i] = (ceilEdge + qreal(i)) * -deltaY - leftEdge * -deltaY + gridRect.bottom();
58
58
59 return points;
59 return points;
60 }
60 }
@@ -62,7 +62,7 QVector<qreal> ChartLogValueAxisY::calculateLayout() const
62
62
63 void ChartLogValueAxisY::updateGeometry()
63 void ChartLogValueAxisY::updateGeometry()
64 {
64 {
65 const QVector<qreal> &layout = ChartAxis::layout();
65 const QVector<qreal> &layout = ChartAxisElement::layout();
66 if (layout.isEmpty())
66 if (layout.isEmpty())
67 return;
67 return;
68 setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat()));
68 setLabels(createLogValueLabels(m_axis->min(), m_axis->max(), m_axis->base(), layout.size(), m_axis->labelFormat()));
@@ -87,7 +87,7 QSizeF ChartLogValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint
87 {
87 {
88 Q_UNUSED(constraint)
88 Q_UNUSED(constraint)
89
89
90 QFontMetrics fn(font());
90 QFontMetrics fn(axis()->labelsFont());
91 QSizeF sh;
91 QSizeF sh;
92
92
93 QSizeF base = VerticalAxis::sizeHint(which, constraint);
93 QSizeF base = VerticalAxis::sizeHint(which, constraint);
@@ -35,20 +35,18
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QLogValueAxis;
37 class QLogValueAxis;
38 class ChartPresenter;
39
38
40 class ChartLogValueAxisY : public VerticalAxis
39 class ChartLogValueAxisY : public VerticalAxis
41 {
40 {
42 Q_OBJECT
41 Q_OBJECT
43
42
44 public:
43 public:
45 ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem* item);
44 ChartLogValueAxisY(QLogValueAxis *axis, QGraphicsItem *item);
46 ~ChartLogValueAxisY();
45 ~ChartLogValueAxisY();
47
46
48 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
47 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
49
48
50 protected:
49 protected:
51 void handleAxisUpdated();
52 QVector<qreal> calculateLayout() const;
50 QVector<qreal> calculateLayout() const;
53 void updateGeometry();
51 void updateGeometry();
54
52
@@ -22,6 +22,8
22 #include "qlogvalueaxis_p.h"
22 #include "qlogvalueaxis_p.h"
23 #include "chartlogvalueaxisx_p.h"
23 #include "chartlogvalueaxisx_p.h"
24 #include "chartlogvalueaxisy_p.h"
24 #include "chartlogvalueaxisy_p.h"
25 #include "polarchartlogvalueaxisangular_p.h"
26 #include "polarchartlogvalueaxisradial_p.h"
25 #include "abstractdomain_p.h"
27 #include "abstractdomain_p.h"
26 #include <float.h>
28 #include <float.h>
27 #include <cmath>
29 #include <cmath>
@@ -287,14 +289,24 void QLogValueAxisPrivate::setRange(qreal min, qreal max)
287 }
289 }
288 }
290 }
289
291
290 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
292 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
291 {
293 {
292 Q_Q(QLogValueAxis);
294 Q_Q(QLogValueAxis);
293 ChartAxis* axis(0);
295 ChartAxisElement *axis(0);
294 if (orientation() == Qt::Vertical)
296
295 axis = new ChartLogValueAxisY(q,parent);
297 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
296 if (orientation() == Qt::Horizontal)
298 if (orientation() == Qt::Vertical)
297 axis = new ChartLogValueAxisX(q,parent);
299 axis = new ChartLogValueAxisY(q,parent);
300 if (orientation() == Qt::Horizontal)
301 axis = new ChartLogValueAxisX(q,parent);
302 }
303
304 if (m_chart->chartType() == QChart::ChartTypePolar) {
305 if (orientation() == Qt::Vertical)
306 axis = new PolarChartLogValueAxisRadial(q, parent);
307 if (orientation() == Qt::Horizontal)
308 axis = new PolarChartLogValueAxisAngular(q, parent);
309 }
298
310
299 m_item.reset(axis);
311 m_item.reset(axis);
300 QAbstractAxisPrivate::initializeGraphics(parent);
312 QAbstractAxisPrivate::initializeGraphics(parent);
@@ -304,7 +316,7 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
304 void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
316 void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
305 {
317 {
306 if (orientation() == Qt::Vertical) {
318 if (orientation() == Qt::Vertical) {
307 if(!qFuzzyCompare(m_max, m_min)) {
319 if (!qFuzzyCompare(m_max, m_min)) {
308 domain->setRangeY(m_min, m_max);
320 domain->setRangeY(m_min, m_max);
309 } else if ( domain->minY() > 0) {
321 } else if ( domain->minY() > 0) {
310 setRange(domain->minY(), domain->maxY());
322 setRange(domain->minY(), domain->maxY());
@@ -315,7 +327,7 void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
315 }
327 }
316 }
328 }
317 if (orientation() == Qt::Horizontal) {
329 if (orientation() == Qt::Horizontal) {
318 if(!qFuzzyCompare(m_max, m_min)) {
330 if (!qFuzzyCompare(m_max, m_min)) {
319 domain->setRangeX(m_min, m_max);
331 domain->setRangeX(m_min, m_max);
320 } else if (domain->minX() > 0){
332 } else if (domain->minX() > 0){
321 setRange(domain->minX(), domain->maxX());
333 setRange(domain->minX(), domain->maxX());
@@ -254,11 +254,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
254
254
255 /*!
255 /*!
256 \property QAbstractAxis::alignment
256 \property QAbstractAxis::alignment
257 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
257 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
258 */
258 */
259 /*!
259 /*!
260 \qmlproperty alignment AbstractAxis::alignment
260 \qmlproperty alignment AbstractAxis::alignment
261 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
261 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
262 */
262 */
263
263
264 /*!
264 /*!
@@ -990,11 +990,11 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
990
990
991 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
991 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
992 {
992 {
993 ChartAxis* axis = m_item.data();
993 ChartAxisElement *axis = m_item.data();
994 Q_ASSERT(axis);
994 Q_ASSERT(axis);
995 if(options.testFlag(QChart::GridAxisAnimations)) {
995 if (options.testFlag(QChart::GridAxisAnimations)) {
996 axis->setAnimation(new AxisAnimation(axis));
996 axis->setAnimation(new AxisAnimation(axis));
997 }else{
997 } else {
998 axis->setAnimation(0);
998 axis->setAnimation(0);
999 }
999 }
1000 }
1000 }
@@ -155,36 +155,37 public:
155
155
156 Q_SIGNALS:
156 Q_SIGNALS:
157 void visibleChanged(bool visible);
157 void visibleChanged(bool visible);
158 void linePenChanged(const QPen& pen);
158 void linePenChanged(const QPen &pen);
159 void lineVisibleChanged(bool visible);
159 void lineVisibleChanged(bool visible);
160 void labelsVisibleChanged(bool visible);
160 void labelsVisibleChanged(bool visible);
161 void labelsPenChanged(const QPen& pen);
161 void labelsPenChanged(const QPen &pen);
162 void labelsBrushChanged(const QBrush& brush);
162 void labelsBrushChanged(const QBrush &brush);
163 void labelsFontChanged(const QFont& pen);
163 void labelsFontChanged(const QFont &pen);
164 void labelsAngleChanged(int angle);
164 void labelsAngleChanged(int angle);
165 void gridLinePenChanged(const QPen& pen);
165 void gridLinePenChanged(const QPen &pen);
166 void gridVisibleChanged(bool visible);
166 void gridVisibleChanged(bool visible);
167 void colorChanged(QColor color);
167 void colorChanged(QColor color);
168 void labelsColorChanged(QColor color);
168 void labelsColorChanged(QColor color);
169 void titleTextChanged(const QString& title);
169 void titleTextChanged(const QString &title);
170 void titlePenChanged(const QPen& pen);
170 void titlePenChanged(const QPen &pen);
171 void titleBrushChanged(const QBrush& brush);
171 void titleBrushChanged(const QBrush &brush);
172 void titleVisibleChanged(bool visible);
172 void titleVisibleChanged(bool visible);
173 void titleFontChanged(const QFont& font);
173 void titleFontChanged(const QFont &font);
174 void shadesVisibleChanged(bool visible);
174 void shadesVisibleChanged(bool visible);
175 void shadesColorChanged(QColor color);
175 void shadesColorChanged(QColor color);
176 void shadesBorderColorChanged(QColor color);
176 void shadesBorderColorChanged(QColor color);
177 void shadesPenChanged(const QPen& pen);
177 void shadesPenChanged(const QPen &pen);
178 void shadesBrushChanged(const QBrush& brush);
178 void shadesBrushChanged(const QBrush &brush);
179
179
180 protected:
180 protected:
181 QScopedPointer<QAbstractAxisPrivate> d_ptr;
181 QScopedPointer<QAbstractAxisPrivate> d_ptr;
182 Q_DISABLE_COPY(QAbstractAxis)
182 Q_DISABLE_COPY(QAbstractAxis)
183 friend class ChartDataSet;
183 friend class ChartDataSet;
184 friend class ChartAxis;
185 friend class ChartPresenter;
184 friend class ChartPresenter;
186 friend class ChartThemeManager;
185 friend class ChartThemeManager;
187 friend class AbstractDomain;
186 friend class AbstractDomain;
187 friend class ChartAxisElement;
188 friend class XYChart;
188 };
189 };
189
190
190 QTCOMMERCIALCHART_END_NAMESPACE
191 QTCOMMERCIALCHART_END_NAMESPACE
@@ -31,7 +31,7
31 #define QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
32
32
33 #include "qabstractaxis.h"
33 #include "qabstractaxis.h"
34 #include "chartaxis_p.h"
34 #include "chartaxiselement_p.h"
35 #include "qchart.h"
35 #include "qchart.h"
36 #include <QDebug>
36 #include <QDebug>
37
37
@@ -59,7 +59,7 public:
59 void setAlignment( Qt::Alignment alignment);
59 void setAlignment( Qt::Alignment alignment);
60
60
61 virtual void initializeDomain(AbstractDomain *domain) = 0;
61 virtual void initializeDomain(AbstractDomain *domain) = 0;
62 virtual void initializeGraphics(QGraphicsItem* parent) = 0;
62 virtual void initializeGraphics(QGraphicsItem *parent) = 0;
63 virtual void initializeTheme(ChartTheme* theme, bool forced = false);
63 virtual void initializeTheme(ChartTheme* theme, bool forced = false);
64 virtual void initializeAnimations(QChart::AnimationOptions options);
64 virtual void initializeAnimations(QChart::AnimationOptions options);
65
65
@@ -73,7 +73,7 public:
73 virtual qreal min() = 0;
73 virtual qreal min() = 0;
74 virtual qreal max() = 0;
74 virtual qreal max() = 0;
75
75
76 ChartAxis* axisItem() { return m_item.data(); }
76 ChartAxisElement *axisItem() { return m_item.data(); }
77
77
78 public Q_SLOTS:
78 public Q_SLOTS:
79 void handleRangeChanged(qreal min, qreal max);
79 void handleRangeChanged(qreal min, qreal max);
@@ -84,7 +84,7 Q_SIGNALS:
84 protected:
84 protected:
85 QAbstractAxis *q_ptr;
85 QAbstractAxis *q_ptr;
86 QChart *m_chart;
86 QChart *m_chart;
87 QScopedPointer<ChartAxis> m_item;
87 QScopedPointer<ChartAxisElement> m_item;
88 private:
88 private:
89 QList<QAbstractSeries*> m_series;
89 QList<QAbstractSeries*> m_series;
90
90
@@ -22,7 +22,7
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "qvalueaxis.h"
24 #include "qvalueaxis.h"
25 #include "chartlayout_p.h"
25 #include "abstractchartlayout_p.h"
26 #include <QGraphicsLayout>
26 #include <QGraphicsLayout>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <qmath.h>
28 #include <qmath.h>
@@ -31,12 +31,12
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem* item )
34 ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem *item )
35 : HorizontalAxis(axis, item),
35 : HorizontalAxis(axis, item),
36 m_axis(axis)
36 m_axis(axis)
37 {
37 {
38 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
38 QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int)));
39 QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString)));
39 QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
40 }
40 }
41
41
42 ChartValueAxisX::~ChartValueAxisX()
42 ChartValueAxisX::~ChartValueAxisX()
@@ -61,10 +61,10 QVector<qreal> ChartValueAxisX::calculateLayout() const
61
61
62 void ChartValueAxisX::updateGeometry()
62 void ChartValueAxisX::updateGeometry()
63 {
63 {
64 const QVector<qreal>& layout = ChartAxis::layout();
64 const QVector<qreal>& layout = ChartAxisElement::layout();
65 if (layout.isEmpty())
65 if (layout.isEmpty())
66 return;
66 return;
67 setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat()));
67 setLabels(createValueLabels(min(), max(), layout.size(), m_axis->labelFormat()));
68 HorizontalAxis::updateGeometry();
68 HorizontalAxis::updateGeometry();
69 }
69 }
70
70
@@ -86,7 +86,7 QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
86 {
86 {
87 Q_UNUSED(constraint)
87 Q_UNUSED(constraint)
88
88
89 QFontMetrics fn(font());
89 QFontMetrics fn(axis()->labelsFont());
90 QSizeF sh;
90 QSizeF sh;
91
91
92 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
92 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
@@ -35,13 +35,12
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QValueAxis;
37 class QValueAxis;
38 class ChartPresenter;
39
38
40 class ChartValueAxisX : public HorizontalAxis
39 class ChartValueAxisX : public HorizontalAxis
41 {
40 {
42 Q_OBJECT
41 Q_OBJECT
43 public:
42 public:
44 ChartValueAxisX(QValueAxis *axis, QGraphicsItem* item = 0);
43 ChartValueAxisX(QValueAxis *axis, QGraphicsItem *item = 0);
45 ~ChartValueAxisX();
44 ~ChartValueAxisX();
46
45
47 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
@@ -22,7 +22,7
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "qvalueaxis.h"
24 #include "qvalueaxis.h"
25 #include "chartlayout_p.h"
25 #include "abstractchartlayout_p.h"
26 #include <QGraphicsLayout>
26 #include <QGraphicsLayout>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <qmath.h>
28 #include <qmath.h>
@@ -30,12 +30,12
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem* item)
33 ChartValueAxisY::ChartValueAxisY(QValueAxis *axis, QGraphicsItem *item)
34 : VerticalAxis(axis, item),
34 : VerticalAxis(axis, item),
35 m_axis(axis)
35 m_axis(axis)
36 {
36 {
37 QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
37 QObject::connect(m_axis, SIGNAL(tickCountChanged(int)), this, SLOT(handleTickCountChanged(int)));
38 QObject::connect(m_axis,SIGNAL(labelFormatChanged(QString)),this, SLOT(handleLabelFormatChanged(QString)));
38 QObject::connect(m_axis, SIGNAL(labelFormatChanged(QString)), this, SLOT(handleLabelFormatChanged(QString)));
39 }
39 }
40
40
41 ChartValueAxisY::~ChartValueAxisY()
41 ChartValueAxisY::~ChartValueAxisY()
@@ -62,7 +62,7 QVector<qreal> ChartValueAxisY::calculateLayout() const
62
62
63 void ChartValueAxisY::updateGeometry()
63 void ChartValueAxisY::updateGeometry()
64 {
64 {
65 const QVector<qreal> &layout = ChartAxis::layout();
65 const QVector<qreal> &layout = ChartAxisElement::layout();
66 if (layout.isEmpty())
66 if (layout.isEmpty())
67 return;
67 return;
68 setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat()));
68 setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat()));
@@ -87,7 +87,7 QSizeF ChartValueAxisY::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
87 {
87 {
88 Q_UNUSED(constraint)
88 Q_UNUSED(constraint)
89
89
90 QFontMetrics fn(font());
90 QFontMetrics fn(axis()->labelsFont());
91 QSizeF sh;
91 QSizeF sh;
92 QSizeF base = VerticalAxis::sizeHint(which, constraint);
92 QSizeF base = VerticalAxis::sizeHint(which, constraint);
93 QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat());
93 QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat());
@@ -35,13 +35,12
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QValueAxis;
37 class QValueAxis;
38 class ChartPresenter;
39
38
40 class ChartValueAxisY : public VerticalAxis
39 class ChartValueAxisY : public VerticalAxis
41 {
40 {
42 Q_OBJECT
41 Q_OBJECT
43 public:
42 public:
44 ChartValueAxisY(QValueAxis *axis, QGraphicsItem* item = 0);
43 ChartValueAxisY(QValueAxis *axis, QGraphicsItem *item = 0);
45 ~ChartValueAxisY();
44 ~ChartValueAxisY();
46
45
47 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
46 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
@@ -23,6 +23,8
23 #include "chartvalueaxisx_p.h"
23 #include "chartvalueaxisx_p.h"
24 #include "chartvalueaxisy_p.h"
24 #include "chartvalueaxisy_p.h"
25 #include "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "polarchartvalueaxisangular_p.h"
27 #include "polarchartvalueaxisradial_p.h"
26 #include "chartdataset_p.h"
28 #include "chartdataset_p.h"
27 #include "chartpresenter_p.h"
29 #include "chartpresenter_p.h"
28 #include "charttheme_p.h"
30 #include "charttheme_p.h"
@@ -387,14 +389,24 void QValueAxisPrivate::setRange(qreal min, qreal max)
387 }
389 }
388 }
390 }
389
391
390 void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
392 void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
391 {
393 {
392 Q_Q(QValueAxis);
394 Q_Q(QValueAxis);
393 ChartAxis* axis(0);
395 ChartAxisElement *axis(0);
394 if (orientation() == Qt::Vertical)
396
395 axis = new ChartValueAxisY(q,parent);
397 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
396 if (orientation() == Qt::Horizontal)
398 if (orientation() == Qt::Vertical)
397 axis = new ChartValueAxisX(q,parent);
399 axis = new ChartValueAxisY(q,parent);
400 if (orientation() == Qt::Horizontal)
401 axis = new ChartValueAxisX(q,parent);
402 }
403
404 if (m_chart->chartType() == QChart::ChartTypePolar) {
405 if (orientation() == Qt::Vertical)
406 axis = new PolarChartValueAxisRadial(q, parent);
407 if (orientation() == Qt::Horizontal)
408 axis = new PolarChartValueAxisAngular(q, parent);
409 }
398
410
399 m_item.reset(axis);
411 m_item.reset(axis);
400 QAbstractAxisPrivate::initializeGraphics(parent);
412 QAbstractAxisPrivate::initializeGraphics(parent);
@@ -404,20 +416,16 void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent)
404 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
416 void QValueAxisPrivate::initializeDomain(AbstractDomain *domain)
405 {
417 {
406 if (orientation() == Qt::Vertical) {
418 if (orientation() == Qt::Vertical) {
407 if(!qFuzzyIsNull(m_max - m_min)) {
419 if (!qFuzzyIsNull(m_max - m_min))
408 domain->setRangeY(m_min, m_max);
420 domain->setRangeY(m_min, m_max);
409 }
421 else
410 else {
411 setRange(domain->minY(), domain->maxY());
422 setRange(domain->minY(), domain->maxY());
412 }
413 }
423 }
414 if (orientation() == Qt::Horizontal) {
424 if (orientation() == Qt::Horizontal) {
415 if(!qFuzzyIsNull(m_max - m_min)) {
425 if (!qFuzzyIsNull(m_max - m_min))
416 domain->setRangeX(m_min, m_max);
426 domain->setRangeX(m_min, m_max);
417 }
427 else
418 else {
419 setRange(domain->minX(), domain->maxX());
428 setRange(domain->minX(), domain->maxX());
420 }
421 }
429 }
422 }
430 }
423
431
@@ -25,31 +25,29
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 VerticalAxis::VerticalAxis(QAbstractAxis *axis, QGraphicsItem* item, bool intervalAxis)
28 VerticalAxis::VerticalAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
29 : ChartAxis(axis, item, intervalAxis)
29 : CartesianChartAxis(axis, item, intervalAxis)
30 {
30 {
31
32 }
31 }
33
32
34 VerticalAxis::~VerticalAxis()
33 VerticalAxis::~VerticalAxis()
35 {
34 {
36
37 }
35 }
38
36
39 void VerticalAxis::updateGeometry()
37 void VerticalAxis::updateGeometry()
40 {
38 {
41 const QVector<qreal> &layout = ChartAxis::layout();
39 const QVector<qreal> &layout = ChartAxisElement::layout();
42
40
43 if (layout.isEmpty())
41 if (layout.isEmpty())
44 return;
42 return;
45
43
46 QStringList labelList = labels();
44 QStringList labelList = labels();
47
45
48 QList<QGraphicsItem *> lines = lineItems();
46 QList<QGraphicsItem *> lines = gridItems();
49 QList<QGraphicsItem *> labels = labelItems();
47 QList<QGraphicsItem *> labels = labelItems();
50 QList<QGraphicsItem *> shades = shadeItems();
48 QList<QGraphicsItem *> shades = shadeItems();
51 QList<QGraphicsItem *> axis = arrowItems();
49 QList<QGraphicsItem *> arrow = arrowItems();
52 QGraphicsSimpleTextItem* title = titleItem();
50 QGraphicsSimpleTextItem *title = titleItem();
53
51
54 Q_ASSERT(labels.size() == labelList.size());
52 Q_ASSERT(labels.size() == labelList.size());
55 Q_ASSERT(layout.size() == labelList.size());
53 Q_ASSERT(layout.size() == labelList.size());
@@ -61,32 +59,31 void VerticalAxis::updateGeometry()
61
59
62
60
63 //arrow
61 //arrow
64 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(axis.at(0));
62 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(arrow.at(0));
65
63
66 //arrow position
64 //arrow position
67 if (alignment()==Qt::AlignLeft)
65 if (axis()->alignment() == Qt::AlignLeft)
68 arrowItem->setLine( axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom());
66 arrowItem->setLine(axisRect.right(), gridRect.top(), axisRect.right(), gridRect.bottom());
69 else if(alignment()==Qt::AlignRight)
67 else if (axis()->alignment() == Qt::AlignRight)
70 arrowItem->setLine( axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom());
68 arrowItem->setLine(axisRect.left(), gridRect.top(), axisRect.left(), gridRect.bottom());
71
69
72 QFontMetrics fn(font());
70 QFontMetrics fn(axis()->labelsFont());
73
71
74 //title
72 //title
75 int titlePad = 0;
73 int titlePad = 0;
76 QRectF titleBoundingRect;
74 QRectF titleBoundingRect;
77 if (!titleText().isEmpty() && titleItem()->isVisible()) {
75 QString titleText = axis()->titleText();
76 if (!titleText.isEmpty() && titleItem()->isVisible()) {
78 QFontMetrics fn(title->font());
77 QFontMetrics fn(title->font());
79 int size(0);
78 int size(0);
80 size = gridRect.height();
79 size = gridRect.height();
81 QString titleText = this->titleText();
82
80
83 if (fn.boundingRect(titleText).width() > size) {
81 if (fn.boundingRect(titleText).width() > size) {
84 QString string = titleText + "...";
82 QString string = titleText + "...";
85 while (fn.boundingRect(string).width() > size && string.length() > 3)
83 while (fn.boundingRect(string).width() > size && string.length() > 3)
86 string.remove(string.length() - 4, 1);
84 string.remove(string.length() - 4, 1);
87 title->setText(string);
85 title->setText(string);
88 }
86 } else {
89 else {
90 title->setText(titleText);
87 title->setText(titleText);
91 }
88 }
92
89
@@ -94,10 +91,10 void VerticalAxis::updateGeometry()
94 titleBoundingRect = title->boundingRect();
91 titleBoundingRect = title->boundingRect();
95
92
96 QPointF center = gridRect.center() - titleBoundingRect.center();
93 QPointF center = gridRect.center() - titleBoundingRect.center();
97 if (alignment() == Qt::AlignLeft) {
94 if (axis()->alignment() == Qt::AlignLeft) {
98 title->setPos(axisRect.left() - titleBoundingRect.width() / 2 + titleBoundingRect.height() / 2 + titlePad, center.y());
95 title->setPos(axisRect.left() - titleBoundingRect.width() / 2 + titleBoundingRect.height() / 2 + titlePad, center.y());
99 }
96 }
100 else if (alignment() == Qt::AlignRight) {
97 else if (axis()->alignment() == Qt::AlignRight) {
101 title->setPos(axisRect.right() - titleBoundingRect.width() / 2 - titleBoundingRect.height() / 2 - titlePad, center.y());
98 title->setPos(axisRect.right() - titleBoundingRect.width() / 2 - titleBoundingRect.height() / 2 - titlePad, center.y());
102 }
99 }
103 title->setTransformOriginPoint(titleBoundingRect.center());
100 title->setTransformOriginPoint(titleBoundingRect.center());
@@ -105,14 +102,13 void VerticalAxis::updateGeometry()
105 }
102 }
106
103
107 for (int i = 0; i < layout.size(); ++i) {
104 for (int i = 0; i < layout.size(); ++i) {
108
109 //items
105 //items
110 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
106 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
111 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(axis.at(i + 1));
107 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrow.at(i + 1));
112 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
108 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
113
109
114 //grid line
110 //grid line
115 gridItem->setLine(gridRect.left() , layout[i], gridRect.right(), layout[i]);
111 gridItem->setLine(gridRect.left(), layout[i], gridRect.right(), layout[i]);
116
112
117 //label text wrapping
113 //label text wrapping
118 QString text = labelList.at(i);
114 QString text = labelList.at(i);
@@ -138,10 +134,10 void VerticalAxis::updateGeometry()
138 int widthDiff = rect.width() - boundingRect.width();
134 int widthDiff = rect.width() - boundingRect.width();
139
135
140 //ticks and label position
136 //ticks and label position
141 if (alignment() == Qt::AlignLeft) {
137 if (axis()->alignment() == Qt::AlignLeft) {
142 labelItem->setPos(axisRect.right() - rect.width() + (widthDiff / 2) - labelPadding(), layout[i] - center.y());
138 labelItem->setPos(axisRect.right() - rect.width() + (widthDiff / 2) - labelPadding(), layout[i] - center.y());
143 tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]);
139 tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]);
144 } else if (alignment() == Qt::AlignRight) {
140 } else if (axis()->alignment() == Qt::AlignRight) {
145 labelItem->setPos(axisRect.left() + labelPadding() - (widthDiff / 2), layout[i] - center.y());
141 labelItem->setPos(axisRect.left() + labelPadding() - (widthDiff / 2), layout[i] - center.y());
146 tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]);
142 tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]);
147 }
143 }
@@ -202,7 +198,7 void VerticalAxis::updateGeometry()
202 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
198 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
203 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top());
199 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top());
204 gridLine->setVisible(true);
200 gridLine->setVisible(true);
205 gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1));
201 gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size() + 1));
206 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
202 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
207 gridLine->setVisible(true);
203 gridLine->setVisible(true);
208 }
204 }
@@ -212,10 +208,10 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
212 {
208 {
213
209
214 Q_UNUSED(constraint);
210 Q_UNUSED(constraint);
215 QFontMetrics fn(titleFont());
211 QFontMetrics fn(axis()->titleFont());
216 QSizeF sh(0,0);
212 QSizeF sh(0, 0);
217
213
218 if (titleText().isEmpty() || !titleItem()->isVisible())
214 if (axis()->titleText().isEmpty() || !titleItem()->isVisible())
219 return sh;
215 return sh;
220
216
221 switch (which) {
217 switch (which) {
@@ -30,14 +30,14
30 #ifndef VERTICALAXIS_P_H_
30 #ifndef VERTICALAXIS_P_H_
31 #define VERTICALAXIS_P_H_
31 #define VERTICALAXIS_P_H_
32
32
33 #include "chartaxis_p.h"
33 #include "cartesianchartaxis_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class VerticalAxis : public ChartAxis
37 class VerticalAxis : public CartesianChartAxis
38 {
38 {
39 public:
39 public:
40 VerticalAxis(QAbstractAxis *axis, QGraphicsItem* item = 0, bool intervalAxis = false);
40 VerticalAxis(QAbstractAxis *axis, QGraphicsItem *item = 0, bool intervalAxis = false);
41 ~VerticalAxis();
41 ~VerticalAxis();
42 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
42 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
43 protected:
43 protected:
@@ -33,9 +33,13
33 #include "qpieseries.h"
33 #include "qpieseries.h"
34 #include "chartitem_p.h"
34 #include "chartitem_p.h"
35 #include "xydomain_p.h"
35 #include "xydomain_p.h"
36 #include "xypolardomain_p.h"
36 #include "xlogydomain_p.h"
37 #include "xlogydomain_p.h"
37 #include "logxydomain_p.h"
38 #include "logxydomain_p.h"
38 #include "logxlogydomain_p.h"
39 #include "logxlogydomain_p.h"
40 #include "xlogypolardomain_p.h"
41 #include "logxypolardomain_p.h"
42 #include "logxlogypolardomain_p.h"
39
43
40 #ifndef QT_ON_ARM
44 #ifndef QT_ON_ARM
41 #include "qdatetimeaxis.h"
45 #include "qdatetimeaxis.h"
@@ -66,6 +70,20 void ChartDataSet::addSeries(QAbstractSeries *series)
66 return;
70 return;
67 }
71 }
68
72
73 // Ignore unsupported series added to polar chart
74 if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) {
75 if (!(series->type() == QAbstractSeries::SeriesTypeArea
76 || series->type() == QAbstractSeries::SeriesTypeLine
77 || series->type() == QAbstractSeries::SeriesTypeScatter
78 || series->type() == QAbstractSeries::SeriesTypeSpline)) {
79 qWarning() << QObject::tr("Can not add series. Series type is not supported by a polar chart.");
80 return;
81 }
82 series->d_ptr->setDomain(new XYPolarDomain());
83 } else {
84 series->d_ptr->setDomain(new XYDomain());
85 }
86
69 series->d_ptr->initializeDomain();
87 series->d_ptr->initializeDomain();
70 m_seriesList.append(series);
88 m_seriesList.append(series);
71
89
@@ -78,7 +96,7 void ChartDataSet::addSeries(QAbstractSeries *series)
78 /*
96 /*
79 * This method adds axis to chartdataset, axis ownership is taken from caller.
97 * This method adds axis to chartdataset, axis ownership is taken from caller.
80 */
98 */
81 void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
99 void ChartDataSet::addAxis(QAbstractAxis *axis, Qt::Alignment aligment)
82 {
100 {
83 if (m_axisList.contains(axis)) {
101 if (m_axisList.contains(axis)) {
84 qWarning() << QObject::tr("Can not add axis. Axis already on the chart.");
102 qWarning() << QObject::tr("Can not add axis. Axis already on the chart.");
@@ -87,12 +105,25 void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
87
105
88 axis->d_ptr->setAlignment(aligment);
106 axis->d_ptr->setAlignment(aligment);
89
107
90 if(!axis->alignment()) {
108 if (!axis->alignment()) {
91 qWarning()<< QObject::tr("No alignment specified !");
109 qWarning() << QObject::tr("No alignment specified !");
92 return;
110 return;
93 };
111 };
94
112
95 QSharedPointer<AbstractDomain> domain(new XYDomain());
113 AbstractDomain *newDomain;
114 if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) {
115 foreach (QAbstractAxis *existingAxis, axes()) {
116 if (existingAxis->orientation() == axis->orientation()) {
117 qWarning() << QObject::tr("Cannot add multiple axes of same orientation to a polar chart!");
118 return;
119 }
120 }
121 newDomain = new XYPolarDomain();
122 } else {
123 newDomain = new XYDomain();
124 }
125
126 QSharedPointer<AbstractDomain> domain(newDomain);
96 axis->d_ptr->initializeDomain(domain.data());
127 axis->d_ptr->initializeDomain(domain.data());
97
128
98 axis->setParent(this);
129 axis->setParent(this);
@@ -122,6 +153,8 void ChartDataSet::removeSeries(QAbstractSeries *series)
122 emit seriesRemoved(series);
153 emit seriesRemoved(series);
123 m_seriesList.removeAll(series);
154 m_seriesList.removeAll(series);
124
155
156 // Reset domain to default
157 series->d_ptr->setDomain(new XYDomain());
125 series->setParent(0);
158 series->setParent(0);
126 series->d_ptr->m_chart = 0;
159 series->d_ptr->m_chart = 0;
127 }
160 }
@@ -152,13 +185,13 void ChartDataSet::removeAxis(QAbstractAxis *axis)
152 /*
185 /*
153 * This method attaches axis to series, return true if success.
186 * This method attaches axis to series, return true if success.
154 */
187 */
155 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis)
188 bool ChartDataSet::attachAxis(QAbstractSeries *series,QAbstractAxis *axis)
156 {
189 {
157 Q_ASSERT(series);
190 Q_ASSERT(series);
158 Q_ASSERT(axis);
191 Q_ASSERT(axis);
159
192
160 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
193 QList<QAbstractSeries *> attachedSeriesList = axis->d_ptr->m_series;
161 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
194 QList<QAbstractAxis *> attachedAxisList = series->d_ptr->m_axes;
162
195
163 if (!m_seriesList.contains(series)) {
196 if (!m_seriesList.contains(series)) {
164 qWarning() << QObject::tr("Can not find series on the chart.");
197 qWarning() << QObject::tr("Can not find series on the chart.");
@@ -180,25 +213,42 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis)
180 return false;
213 return false;
181 }
214 }
182
215
183 AbstractDomain* domain = series->d_ptr->domain();
216 AbstractDomain *domain = series->d_ptr->domain();
184 AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis);
217 AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis);
185
218
186 if(type == AbstractDomain::UndefinedDomain) return false;
219 if (type == AbstractDomain::UndefinedDomain) return false;
187
220
188 if(domain->type()!=type){
221 if (domain->type() != type) {
189 AbstractDomain *old = domain;
222 AbstractDomain *old = domain;
190 domain = createDomain(type);
223 domain = createDomain(type);
191 domain->setRange(old->minX(), old->maxX(), old->minY(), old->maxY());
224 domain->setRange(old->minX(), old->maxX(), old->minY(), old->maxY());
225 // Initialize domain size to old domain size, as it won't get updated
226 // unless geometry changes.
227 domain->setSize(old->size());
192 }
228 }
193
229
194 if(!domain) return false;
230 if (!domain)
231 return false;
232
233 if (!domain->attachAxis(axis))
234 return false;
195
235
196 if(!domain->attachAxis(axis)) return false;
236 QList<AbstractDomain *> blockedDomains;
237 domain->blockRangeSignals(true);
238 blockedDomains << domain;
197
239
198 if(domain!=series->d_ptr->domain()){
240 if (domain != series->d_ptr->domain()) {
199 foreach(QAbstractAxis* axis,series->d_ptr->m_axes){
241 foreach (QAbstractAxis *axis, series->d_ptr->m_axes) {
200 series->d_ptr->domain()->detachAxis(axis);
242 series->d_ptr->domain()->detachAxis(axis);
201 domain->attachAxis(axis);
243 domain->attachAxis(axis);
244 foreach (QAbstractSeries *otherSeries, axis->d_ptr->m_series) {
245 if (otherSeries != series && otherSeries->d_ptr->domain()) {
246 if (!otherSeries->d_ptr->domain()->rangeSignalsBlocked()) {
247 otherSeries->d_ptr->domain()->blockRangeSignals(true);
248 blockedDomains << otherSeries->d_ptr->domain();
249 }
250 }
251 }
202 }
252 }
203 series->d_ptr->setDomain(domain);
253 series->d_ptr->setDomain(domain);
204 series->d_ptr->initializeDomain();
254 series->d_ptr->initializeDomain();
@@ -210,6 +260,9 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis)
210 series->d_ptr->initializeAxes();
260 series->d_ptr->initializeAxes();
211 axis->d_ptr->initializeDomain(domain);
261 axis->d_ptr->initializeDomain(domain);
212
262
263 foreach (AbstractDomain *blockedDomain, blockedDomains)
264 blockedDomain->blockRangeSignals(false);
265
213 return true;
266 return true;
214 }
267 }
215
268
@@ -327,12 +380,12 void ChartDataSet::findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orien
327 {
380 {
328 Q_ASSERT(!series.isEmpty());
381 Q_ASSERT(!series.isEmpty());
329
382
330 AbstractDomain* domain = series.first()->d_ptr->domain();
383 AbstractDomain *domain = series.first()->d_ptr->domain();
331 min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX();
384 min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX();
332 max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX();
385 max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX();
333
386
334 for(int i = 1; i< series.size(); i++) {
387 for (int i = 1; i< series.size(); i++) {
335 AbstractDomain* domain = series[i]->d_ptr->domain();
388 AbstractDomain *domain = series[i]->d_ptr->domain();
336 min = qMin((orientation == Qt::Vertical) ? domain->minY() : domain->minX(), min);
389 min = qMin((orientation == Qt::Vertical) ? domain->minY() : domain->minX(), min);
337 max = qMax((orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(), max);
390 max = qMax((orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(), max);
338 }
391 }
@@ -437,7 +490,7 QPointF ChartDataSet::mapToPosition(const QPointF &value, QAbstractSeries *serie
437 return point;
490 return point;
438 }
491 }
439
492
440 QList<QAbstractAxis*> ChartDataSet::axes() const
493 QList<QAbstractAxis *> ChartDataSet::axes() const
441 {
494 {
442 return m_axisList;
495 return m_axisList;
443 }
496 }
@@ -447,7 +500,7 QList<QAbstractSeries *> ChartDataSet::series() const
447 return m_seriesList;
500 return m_seriesList;
448 }
501 }
449
502
450 AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes)
503 AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis *> axes)
451 {
504 {
452 enum Type {
505 enum Type {
453 Undefined = 0,
506 Undefined = 0,
@@ -458,75 +511,95 AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes
458 int horizontal(Undefined);
511 int horizontal(Undefined);
459 int vertical(Undefined);
512 int vertical(Undefined);
460
513
461 foreach(QAbstractAxis* axis, axes)
514 // Assume cartesian chart type, unless chart is set
462 {
515 QChart::ChartType chartType(QChart::ChartTypeCartesian);
463 switch(axis->type()) {
516 if (m_chart)
464 case QAbstractAxis::AxisTypeLogValue:
517 chartType = m_chart->chartType();
465
466 if(axis->orientation()==Qt::Horizontal) {
467 horizontal|=LogType;
468 }
469 if(axis->orientation()==Qt::Vertical) {
470 vertical|=LogType;
471 }
472
518
519 foreach (QAbstractAxis *axis, axes)
520 {
521 switch (axis->type()) {
522 case QAbstractAxis::AxisTypeLogValue:
523 if (axis->orientation() == Qt::Horizontal)
524 horizontal |= LogType;
525 if (axis->orientation() == Qt::Vertical)
526 vertical |= LogType;
473 break;
527 break;
474 case QAbstractAxis::AxisTypeValue:
528 case QAbstractAxis::AxisTypeValue:
475 case QAbstractAxis::AxisTypeBarCategory:
529 case QAbstractAxis::AxisTypeBarCategory:
476 case QAbstractAxis::AxisTypeCategory:
530 case QAbstractAxis::AxisTypeCategory:
477 case QAbstractAxis::AxisTypeDateTime:
531 case QAbstractAxis::AxisTypeDateTime:
478 if(axis->orientation()==Qt::Horizontal) {
532 if (axis->orientation() == Qt::Horizontal)
479 horizontal|=ValueType;
533 horizontal |= ValueType;
480 }
534 if (axis->orientation() == Qt::Vertical)
481 if(axis->orientation()==Qt::Vertical) {
535 vertical |= ValueType;
482 vertical|=ValueType;
483 }
484 break;
536 break;
485 default:
537 default:
486 qWarning()<<"Undefined type";
538 qWarning() << "Undefined type";
487 break;
539 break;
488 }
540 }
489 }
541 }
490
542
491 if(vertical==Undefined) vertical=ValueType;
543 if (vertical == Undefined)
492 if(horizontal==Undefined) horizontal=ValueType;
544 vertical = ValueType;
545 if (horizontal == Undefined)
546 horizontal = ValueType;
493
547
494 if(vertical==ValueType && horizontal== ValueType) {
548 if (vertical == ValueType && horizontal == ValueType) {
495 return AbstractDomain::XYDomain;
549 if (chartType == QChart::ChartTypeCartesian)
550 return AbstractDomain::XYDomain;
551 else if (chartType == QChart::ChartTypePolar)
552 return AbstractDomain::XYPolarDomain;
496 }
553 }
497
554
498 if(vertical==LogType && horizontal== ValueType) {
555 if (vertical == LogType && horizontal == ValueType) {
499 return AbstractDomain::XLogYDomain;
556 if (chartType == QChart::ChartTypeCartesian)
557 return AbstractDomain::XLogYDomain;
558 if (chartType == QChart::ChartTypePolar)
559 return AbstractDomain::XLogYPolarDomain;
500 }
560 }
501
561
502 if(vertical==ValueType && horizontal== LogType) {
562 if (vertical == ValueType && horizontal == LogType) {
503 return AbstractDomain::LogXYDomain;
563 if (chartType == QChart::ChartTypeCartesian)
564 return AbstractDomain::LogXYDomain;
565 else if (chartType == QChart::ChartTypePolar)
566 return AbstractDomain::LogXYPolarDomain;
504 }
567 }
505
568
506 if(vertical==LogType && horizontal== LogType) {
569 if (vertical == LogType && horizontal == LogType) {
507 return AbstractDomain::LogXLogYDomain;
570 if (chartType == QChart::ChartTypeCartesian)
571 return AbstractDomain::LogXLogYDomain;
572 else if (chartType == QChart::ChartTypePolar)
573 return AbstractDomain::LogXLogYPolarDomain;
508 }
574 }
509
575
510 return AbstractDomain::UndefinedDomain;
576 return AbstractDomain::UndefinedDomain;
511 }
577 }
512
578
513
514 //refactor create factory
579 //refactor create factory
515 AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type)
580 AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type)
516 {
581 {
517 switch(type)
582 switch (type)
518 {
583 {
519 case AbstractDomain::LogXLogYDomain:
584 case AbstractDomain::LogXLogYDomain:
520 return new LogXLogYDomain();
585 return new LogXLogYDomain();
521 case AbstractDomain::XYDomain:
586 case AbstractDomain::XYDomain:
522 return new XYDomain();
587 return new XYDomain();
523 case AbstractDomain::XLogYDomain:
588 case AbstractDomain::XLogYDomain:
524 return new XLogYDomain();
589 return new XLogYDomain();
525 case AbstractDomain::LogXYDomain:
590 case AbstractDomain::LogXYDomain:
526 return new LogXYDomain();
591 return new LogXYDomain();
527 default:
592 case AbstractDomain::XYPolarDomain:
528 return 0;
593 return new XYPolarDomain();
529 }
594 case AbstractDomain::XLogYPolarDomain:
595 return new XLogYPolarDomain();
596 case AbstractDomain::LogXYPolarDomain:
597 return new LogXYPolarDomain();
598 case AbstractDomain::LogXLogYPolarDomain:
599 return new LogXLogYPolarDomain();
600 default:
601 return 0;
602 }
530 }
603 }
531
604
532 #include "moc_chartdataset_p.cpp"
605 #include "moc_chartdataset_p.cpp"
@@ -27,24 +27,28
27 #include "chartanimation_p.h"
27 #include "chartanimation_p.h"
28 #include "qabstractseries_p.h"
28 #include "qabstractseries_p.h"
29 #include "qareaseries.h"
29 #include "qareaseries.h"
30 #include "chartaxis_p.h"
30 #include "chartaxiselement_p.h"
31 #include "chartbackground_p.h"
31 #include "chartbackground_p.h"
32 #include "chartlayout_p.h"
32 #include "cartesianchartlayout_p.h"
33 #include "polarchartlayout_p.h"
33 #include "charttitle_p.h"
34 #include "charttitle_p.h"
34 #include <QTimer>
35 #include <QTimer>
35
36
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38
38 ChartPresenter::ChartPresenter(QChart *chart)
39 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
39 : QObject(chart),
40 : QObject(chart),
40 m_chart(chart),
41 m_chart(chart),
41 m_options(QChart::NoAnimation),
42 m_options(QChart::NoAnimation),
42 m_state(ShowState),
43 m_state(ShowState),
43 m_layout(new ChartLayout(this)),
44 m_background(0),
44 m_background(0),
45 m_title(0)
45 m_title(0)
46 {
46 {
47
47 if (type == QChart::ChartTypeCartesian)
48 m_layout = new CartesianChartLayout(this);
49 else if (type == QChart::ChartTypePolar)
50 m_layout = new PolarChartLayout(this);
51 Q_ASSERT(m_layout);
48 }
52 }
49
53
50 ChartPresenter::~ChartPresenter()
54 ChartPresenter::~ChartPresenter()
@@ -54,25 +58,25 ChartPresenter::~ChartPresenter()
54
58
55 void ChartPresenter::setGeometry(const QRectF rect)
59 void ChartPresenter::setGeometry(const QRectF rect)
56 {
60 {
57 if(m_rect != rect) {
61 if (m_rect != rect) {
58 m_rect=rect;
62 m_rect = rect;
59 foreach (ChartItem *chart, m_chartItems){
63 foreach (ChartItem *chart, m_chartItems) {
60 chart->domain()->setSize(rect.size());
64 chart->domain()->setSize(rect.size());
61 chart->setPos(rect.topLeft());
65 chart->setPos(rect.topLeft());
62 }
66 }
63 }
67 }
64 }
68 }
65
69
66 QRectF ChartPresenter::geometry() const
70 QRectF ChartPresenter::geometry() const
67 {
71 {
68 return m_rect;
72 return m_rect;
69 }
73 }
70
74
71 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
75 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
72 {
76 {
73 axis->d_ptr->initializeGraphics(rootItem());
77 axis->d_ptr->initializeGraphics(rootItem());
74 axis->d_ptr->initializeAnimations(m_options);
78 axis->d_ptr->initializeAnimations(m_options);
75 ChartAxis *item = axis->d_ptr->axisItem();
79 ChartAxisElement *item = axis->d_ptr->axisItem();
76 item->setPresenter(this);
80 item->setPresenter(this);
77 item->setThemeManager(m_chart->d_ptr->m_themeManager);
81 item->setThemeManager(m_chart->d_ptr->m_themeManager);
78 m_axisItems<<item;
82 m_axisItems<<item;
@@ -82,7 +86,7 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
82
86
83 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
87 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
84 {
88 {
85 ChartAxis *item = axis->d_ptr->m_item.take();
89 ChartAxisElement *item = axis->d_ptr->m_item.take();
86 item->hide();
90 item->hide();
87 item->disconnect();
91 item->disconnect();
88 item->deleteLater();
92 item->deleteLater();
@@ -275,7 +279,7 bool ChartPresenter::isBackgroundDropShadowEnabled() const
275 }
279 }
276
280
277
281
278 ChartLayout *ChartPresenter::layout()
282 AbstractChartLayout *ChartPresenter::layout()
279 {
283 {
280 return m_layout;
284 return m_layout;
281 }
285 }
@@ -295,7 +299,7 ChartBackground *ChartPresenter::backgroundElement()
295 return m_background;
299 return m_background;
296 }
300 }
297
301
298 QList<ChartAxis *> ChartPresenter::axisItems() const
302 QList<ChartAxisElement *> ChartPresenter::axisItems() const
299 {
303 {
300 return m_axisItems;
304 return m_axisItems;
301 }
305 }
@@ -42,12 +42,12 class AxisItem;
42 class QAbstractSeries;
42 class QAbstractSeries;
43 class ChartDataSet;
43 class ChartDataSet;
44 class AbstractDomain;
44 class AbstractDomain;
45 class ChartAxis;
45 class ChartAxisElement;
46 class ChartAnimator;
46 class ChartAnimator;
47 class ChartBackground;
47 class ChartBackground;
48 class ChartTitle;
48 class ChartTitle;
49 class ChartAnimation;
49 class ChartAnimation;
50 class ChartLayout;
50 class AbstractChartLayout;
51
51
52 class ChartPresenter: public QObject
52 class ChartPresenter: public QObject
53 {
53 {
@@ -78,7 +78,7 public:
78 ZoomOutState
78 ZoomOutState
79 };
79 };
80
80
81 ChartPresenter(QChart *chart);
81 ChartPresenter(QChart *chart, QChart::ChartType type);
82 virtual ~ChartPresenter();
82 virtual ~ChartPresenter();
83
83
84
84
@@ -88,12 +88,9 public:
88 QGraphicsItem *rootItem(){ return m_chart; }
88 QGraphicsItem *rootItem(){ return m_chart; }
89 ChartBackground *backgroundElement();
89 ChartBackground *backgroundElement();
90 ChartTitle *titleElement();
90 ChartTitle *titleElement();
91 QList<ChartAxis *> axisItems() const;
91 QList<ChartAxisElement *> axisItems() const;
92 QList<ChartItem *> chartItems() const;
92 QList<ChartItem *> chartItems() const;
93
93
94 ChartItem* chartElement(QAbstractSeries* series) const;
95 ChartAxis* chartElement(QAbstractAxis* axis) const;
96
97 QLegend *legend();
94 QLegend *legend();
98
95
99 void setBackgroundBrush(const QBrush &brush);
96 void setBackgroundBrush(const QBrush &brush);
@@ -128,7 +125,9 public:
128 void setState(State state,QPointF point);
125 void setState(State state,QPointF point);
129 State state() const { return m_state; }
126 State state() const { return m_state; }
130 QPointF statePoint() const { return m_statePoint; }
127 QPointF statePoint() const { return m_statePoint; }
131 ChartLayout *layout();
128 AbstractChartLayout *layout();
129
130 QChart::ChartType chartType() const { return m_chart->chartType(); }
132
131
133 private:
132 private:
134 void createBackgroundItem();
133 void createBackgroundItem();
@@ -149,14 +148,14 Q_SIGNALS:
149 private:
148 private:
150 QChart *m_chart;
149 QChart *m_chart;
151 QList<ChartItem *> m_chartItems;
150 QList<ChartItem *> m_chartItems;
152 QList<ChartAxis *> m_axisItems;
151 QList<ChartAxisElement *> m_axisItems;
153 QList<QAbstractSeries *> m_series;
152 QList<QAbstractSeries *> m_series;
154 QList<QAbstractAxis *> m_axes;
153 QList<QAbstractAxis *> m_axes;
155 QChart::AnimationOptions m_options;
154 QChart::AnimationOptions m_options;
156 State m_state;
155 State m_state;
157 QPointF m_statePoint;
156 QPointF m_statePoint;
158 QList<ChartAnimation *> m_animations;
157 QList<ChartAnimation *> m_animations;
159 ChartLayout *m_layout;
158 AbstractChartLayout *m_layout;
160 ChartBackground *m_background;
159 ChartBackground *m_background;
161 ChartTitle *m_title;
160 ChartTitle *m_title;
162 QRectF m_rect;
161 QRectF m_rect;
@@ -38,7 +38,7 AbstractDomain::~AbstractDomain()
38 {
38 {
39 }
39 }
40
40
41 void AbstractDomain::setSize(const QSizeF& size)
41 void AbstractDomain::setSize(const QSizeF &size)
42 {
42 {
43 if(m_size!=size)
43 if(m_size!=size)
44 {
44 {
@@ -122,9 +122,9 void AbstractDomain::handleHorizontalAxisRangeChanged(qreal min, qreal max)
122
122
123 void AbstractDomain::blockRangeSignals(bool block)
123 void AbstractDomain::blockRangeSignals(bool block)
124 {
124 {
125 if(m_signalsBlocked!=block){
125 if (m_signalsBlocked!=block) {
126 m_signalsBlocked=block;
126 m_signalsBlocked=block;
127 if(!block) {
127 if (!block) {
128 emit rangeHorizontalChanged(m_minX,m_maxX);
128 emit rangeHorizontalChanged(m_minX,m_maxX);
129 emit rangeVerticalChanged(m_minY,m_maxY);
129 emit rangeVerticalChanged(m_minY,m_maxY);
130 }
130 }
@@ -165,14 +165,14 qreal AbstractDomain::niceNumber(qreal x, bool ceiling)
165 return q * z;
165 return q * z;
166 }
166 }
167
167
168 bool AbstractDomain::attachAxis(QAbstractAxis* axis)
168 bool AbstractDomain::attachAxis(QAbstractAxis *axis)
169 {
169 {
170 if(axis->orientation()==Qt::Vertical) {
170 if (axis->orientation() == Qt::Vertical) {
171 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
171 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
172 QObject::connect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
172 QObject::connect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
173 }
173 }
174
174
175 if(axis->orientation()==Qt::Horizontal) {
175 if (axis->orientation() == Qt::Horizontal) {
176 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
176 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
177 QObject::connect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
177 QObject::connect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
178 }
178 }
@@ -180,14 +180,14 bool AbstractDomain::attachAxis(QAbstractAxis* axis)
180 return true;
180 return true;
181 }
181 }
182
182
183 bool AbstractDomain::detachAxis(QAbstractAxis* axis)
183 bool AbstractDomain::detachAxis(QAbstractAxis *axis)
184 {
184 {
185 if(axis->orientation()==Qt::Vertical) {
185 if (axis->orientation() == Qt::Vertical) {
186 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
186 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
187 QObject::disconnect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
187 QObject::disconnect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
188 }
188 }
189
189
190 if(axis->orientation()==Qt::Horizontal) {
190 if (axis->orientation() == Qt::Horizontal) {
191 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
191 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
192 QObject::disconnect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
192 QObject::disconnect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
193 }
193 }
@@ -199,10 +199,10 bool AbstractDomain::detachAxis(QAbstractAxis* axis)
199
199
200 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2)
200 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2)
201 {
201 {
202 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
202 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX)
203 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
203 && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY)
204 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
204 && qFuzzyIsNull(domain1.m_minX - domain2.m_minX)
205 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
205 && qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
206 }
206 }
207
207
208
208
@@ -218,6 +218,17 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDo
218 return dbg.maybeSpace();
218 return dbg.maybeSpace();
219 }
219 }
220
220
221 // This function adjusts min/max ranges to failsafe values if negative/zero values are attempted.
222 void AbstractDomain::adjustLogDomainRanges(qreal &min, qreal &max)
223 {
224 if (min <= 0) {
225 min = 1.0;
226 if (max <= min)
227 max = min + 1.0;
228 }
229 }
230
231
221 #include "moc_abstractdomain_p.cpp"
232 #include "moc_abstractdomain_p.cpp"
222
233
223 QTCOMMERCIALCHART_END_NAMESPACE
234 QTCOMMERCIALCHART_END_NAMESPACE
@@ -42,12 +42,20 class QTCOMMERCIALCHART_AUTOTEST_EXPORT AbstractDomain: public QObject
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44 public:
44 public:
45 enum DomainType { UndefinedDomain, XYDomain, XLogYDomain, LogXYDomain, LogXLogYDomain };
45 enum DomainType { UndefinedDomain,
46 XYDomain,
47 XLogYDomain,
48 LogXYDomain,
49 LogXLogYDomain,
50 XYPolarDomain,
51 XLogYPolarDomain,
52 LogXYPolarDomain,
53 LogXLogYPolarDomain };
46 public:
54 public:
47 explicit AbstractDomain(QObject *object = 0);
55 explicit AbstractDomain(QObject *object = 0);
48 virtual ~AbstractDomain();
56 virtual ~AbstractDomain();
49
57
50 void setSize(const QSizeF& size);
58 virtual void setSize(const QSizeF &size);
51 QSizeF size() const;
59 QSizeF size() const;
52
60
53 virtual DomainType type() = 0;
61 virtual DomainType type() = 0;
@@ -82,10 +90,10 public:
82
90
83 virtual QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const = 0;
91 virtual QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const = 0;
84 virtual QPointF calculateDomainPoint(const QPointF &point) const = 0;
92 virtual QPointF calculateDomainPoint(const QPointF &point) const = 0;
85 virtual QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const = 0;
93 virtual QVector<QPointF> calculateGeometryPoints(const QList<QPointF> &vector) const = 0;
86
94
87 virtual bool attachAxis(QAbstractAxis* axis);
95 virtual bool attachAxis(QAbstractAxis *axis);
88 virtual bool detachAxis(QAbstractAxis* axis);
96 virtual bool detachAxis(QAbstractAxis *axis);
89
97
90 static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount);
98 static void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount);
91 static qreal niceNumber(qreal x, bool ceiling);
99 static qreal niceNumber(qreal x, bool ceiling);
@@ -100,6 +108,8 public Q_SLOTS:
100 void handleHorizontalAxisRangeChanged(qreal min,qreal max);
108 void handleHorizontalAxisRangeChanged(qreal min,qreal max);
101
109
102 protected:
110 protected:
111 void adjustLogDomainRanges(qreal &min, qreal &max);
112
103 qreal m_minX;
113 qreal m_minX;
104 qreal m_maxX;
114 qreal m_maxX;
105 qreal m_minY;
115 qreal m_minY;
@@ -5,14 +5,24 DEPENDPATH += $$PWD
5
5
6 SOURCES += \
6 SOURCES += \
7 $$PWD/abstractdomain.cpp \
7 $$PWD/abstractdomain.cpp \
8 $$PWD/polardomain.cpp \
8 $$PWD/xydomain.cpp \
9 $$PWD/xydomain.cpp \
10 $$PWD/xypolardomain.cpp \
9 $$PWD/xlogydomain.cpp \
11 $$PWD/xlogydomain.cpp \
12 $$PWD/xlogypolardomain.cpp \
10 $$PWD/logxydomain.cpp \
13 $$PWD/logxydomain.cpp \
11 $$PWD/logxlogydomain.cpp
14 $$PWD/logxypolardomain.cpp \
15 $$PWD/logxlogydomain.cpp \
16 $$PWD/logxlogypolardomain.cpp
12
17
13 PRIVATE_HEADERS += \
18 PRIVATE_HEADERS += \
14 $$PWD/abstractdomain_p.h \
19 $$PWD/abstractdomain_p.h \
20 $$PWD/polardomain_p.h \
15 $$PWD/xydomain_p.h \
21 $$PWD/xydomain_p.h \
22 $$PWD/xypolardomain_p.h \
16 $$PWD/xlogydomain_p.h \
23 $$PWD/xlogydomain_p.h \
24 $$PWD/xlogypolardomain_p.h \
17 $$PWD/logxydomain_p.h \
25 $$PWD/logxydomain_p.h \
18 $$PWD/logxlogydomain_p.h
26 $$PWD/logxypolardomain_p.h \
27 $$PWD/logxlogydomain_p.h \
28 $$PWD/logxlogypolardomain_p.h
@@ -45,6 +45,9 void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
45 bool axisXChanged = false;
45 bool axisXChanged = false;
46 bool axisYChanged = false;
46 bool axisYChanged = false;
47
47
48 adjustLogDomainRanges(minX, maxX);
49 adjustLogDomainRanges(minY, maxY);
50
48 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
51 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
49 m_minX = minX;
52 m_minX = minX;
50 m_maxX = maxX;
53 m_maxX = maxX;
@@ -65,7 +68,7 void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
65 qreal logMaxY = log10(m_maxY) / log10(m_logBaseY);
68 qreal logMaxY = log10(m_maxY) / log10(m_logBaseY);
66 m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY;
69 m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY;
67 m_logRightY = logMinY > logMaxY ? logMinY : logMaxY;
70 m_logRightY = logMinY > logMaxY ? logMinY : logMaxY;
68 if(!m_signalsBlocked)
71 if (!m_signalsBlocked)
69 emit rangeVerticalChanged(m_minY, m_maxY);
72 emit rangeVerticalChanged(m_minY, m_maxY);
70 }
73 }
71
74
@@ -141,13 +144,13 QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) c
141 ok = true;
144 ok = true;
142 return QPointF(x, y);
145 return QPointF(x, y);
143 } else {
146 } else {
144 qWarning() << "Logarithm of negative value is undefined. Empty layout returned";
147 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
145 ok = false;
148 ok = false;
146 return QPointF();
149 return QPointF();
147 }
150 }
148 }
151 }
149
152
150 QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const
153 QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
151 {
154 {
152 const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX);
155 const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX);
153 const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
156 const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
@@ -162,7 +165,7 QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF>& v
162 result[i].setX(x);
165 result[i].setX(x);
163 result[i].setY(y);
166 result[i].setY(y);
164 } else {
167 } else {
165 qWarning() << "Logarithm of negative value is undefined. Empty layout returned";
168 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
166 return QVector<QPointF>();
169 return QVector<QPointF>();
167 }
170 }
168 }
171 }
@@ -178,17 +181,17 QPointF LogXLogYDomain::calculateDomainPoint(const QPointF &point) const
178 return QPointF(x, y);
181 return QPointF(x, y);
179 }
182 }
180
183
181 bool LogXLogYDomain::attachAxis(QAbstractAxis* axis)
184 bool LogXLogYDomain::attachAxis(QAbstractAxis *axis)
182 {
185 {
183 AbstractDomain::attachAxis(axis);
186 AbstractDomain::attachAxis(axis);
184 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
187 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
185
188
186 if(logAxis && logAxis->orientation()==Qt::Vertical) {
189 if (logAxis && logAxis->orientation() == Qt::Vertical) {
187 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
190 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
188 handleVerticalAxisBaseChanged(logAxis->base());
191 handleVerticalAxisBaseChanged(logAxis->base());
189 }
192 }
190
193
191 if(logAxis && logAxis->orientation()==Qt::Horizontal) {
194 if (logAxis && logAxis->orientation() == Qt::Horizontal) {
192 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
195 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
193 handleHorizontalAxisBaseChanged(logAxis->base());
196 handleHorizontalAxisBaseChanged(logAxis->base());
194 }
197 }
@@ -196,15 +199,15 bool LogXLogYDomain::attachAxis(QAbstractAxis* axis)
196 return true;
199 return true;
197 }
200 }
198
201
199 bool LogXLogYDomain::detachAxis(QAbstractAxis* axis)
202 bool LogXLogYDomain::detachAxis(QAbstractAxis *axis)
200 {
203 {
201 AbstractDomain::detachAxis(axis);
204 AbstractDomain::detachAxis(axis);
202 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
205 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
203
206
204 if(logAxis && logAxis->orientation()==Qt::Vertical)
207 if (logAxis && logAxis->orientation() == Qt::Vertical)
205 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
208 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
206
209
207 if(logAxis && logAxis->orientation()==Qt::Horizontal)
210 if (logAxis && logAxis->orientation() == Qt::Horizontal)
208 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
211 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
209
212
210 return true;
213 return true;
@@ -234,10 +237,10 void LogXLogYDomain::handleHorizontalAxisBaseChanged(qreal baseX)
234
237
235 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2)
238 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2)
236 {
239 {
237 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
240 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX)
238 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
241 && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY)
239 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
242 && qFuzzyIsNull(domain1.m_minX - domain2.m_minX)
240 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
243 && qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
241 }
244 }
242
245
243
246
@@ -56,10 +56,10 public:
56
56
57 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
57 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF> &vector) const;
60
60
61 bool attachAxis(QAbstractAxis* axis);
61 bool attachAxis(QAbstractAxis *axis);
62 bool detachAxis(QAbstractAxis* axis);
62 bool detachAxis(QAbstractAxis *axis);
63
63
64 public Q_SLOTS:
64 public Q_SLOTS:
65 void handleVerticalAxisBaseChanged(qreal baseY);
65 void handleVerticalAxisBaseChanged(qreal baseY);
@@ -42,6 +42,8 void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
42 bool axisXChanged = false;
42 bool axisXChanged = false;
43 bool axisYChanged = false;
43 bool axisYChanged = false;
44
44
45 adjustLogDomainRanges(minX, maxX);
46
45 if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) {
47 if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) {
46 m_minX = minX;
48 m_minX = minX;
47 m_maxX = maxX;
49 m_maxX = maxX;
@@ -58,7 +60,7 void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
58 m_minY = minY;
60 m_minY = minY;
59 m_maxY = maxY;
61 m_maxY = maxY;
60 axisYChanged = true;
62 axisYChanged = true;
61 if(!m_signalsBlocked)
63 if (!m_signalsBlocked)
62 emit rangeVerticalChanged(m_minY, m_maxY);
64 emit rangeVerticalChanged(m_minY, m_maxY);
63 }
65 }
64
66
@@ -137,13 +139,13 QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) cons
137 ok = true;
139 ok = true;
138 return QPointF(x, y);
140 return QPointF(x, y);
139 } else {
141 } else {
140 qWarning() << "Logarithm of negative value is undefined. Empty layout returned";
142 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
141 ok = false;
143 ok = false;
142 return QPointF();
144 return QPointF();
143 }
145 }
144 }
146 }
145
147
146 QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const
148 QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
147 {
149 {
148 const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX);
150 const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX);
149 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
151 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
@@ -158,7 +160,7 QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF>& vect
158 result[i].setX(x);
160 result[i].setX(x);
159 result[i].setY(y);
161 result[i].setY(y);
160 } else {
162 } else {
161 qWarning() << "Logarithm of negative value is undefined. Empty layout returned";
163 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
162 return QVector<QPointF>();
164 return QVector<QPointF>();
163 }
165 }
164 }
166 }
@@ -174,12 +176,12 QPointF LogXYDomain::calculateDomainPoint(const QPointF &point) const
174 return QPointF(x, y);
176 return QPointF(x, y);
175 }
177 }
176
178
177 bool LogXYDomain::attachAxis(QAbstractAxis* axis)
179 bool LogXYDomain::attachAxis(QAbstractAxis *axis)
178 {
180 {
179 AbstractDomain::attachAxis(axis);
181 AbstractDomain::attachAxis(axis);
180 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
182 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
181
183
182 if(logAxis && logAxis->orientation()==Qt::Horizontal) {
184 if (logAxis && logAxis->orientation() == Qt::Horizontal) {
183 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
185 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
184 handleHorizontalAxisBaseChanged(logAxis->base());
186 handleHorizontalAxisBaseChanged(logAxis->base());
185 }
187 }
@@ -187,12 +189,12 bool LogXYDomain::attachAxis(QAbstractAxis* axis)
187 return true;
189 return true;
188 }
190 }
189
191
190 bool LogXYDomain::detachAxis(QAbstractAxis* axis)
192 bool LogXYDomain::detachAxis(QAbstractAxis *axis)
191 {
193 {
192 AbstractDomain::detachAxis(axis);
194 AbstractDomain::detachAxis(axis);
193 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
195 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
194
196
195 if(logAxis && logAxis->orientation()==Qt::Horizontal)
197 if (logAxis && logAxis->orientation() == Qt::Horizontal)
196 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
198 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleHorizontalAxisBaseChanged(qreal)));
197
199
198 return true;
200 return true;
@@ -212,10 +214,10 void LogXYDomain::handleHorizontalAxisBaseChanged(qreal baseX)
212
214
213 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXYDomain &domain1, const LogXYDomain &domain2)
215 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXYDomain &domain1, const LogXYDomain &domain2)
214 {
216 {
215 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
217 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX)
216 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
218 && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY)
217 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
219 && qFuzzyIsNull(domain1.m_minX - domain2.m_minX)
218 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
220 && qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
219 }
221 }
220
222
221
223
@@ -56,10 +56,10 public:
56
56
57 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
57 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF> &vector) const;
60
60
61 bool attachAxis(QAbstractAxis* axis);
61 bool attachAxis(QAbstractAxis *axis);
62 bool detachAxis(QAbstractAxis* axis);
62 bool detachAxis(QAbstractAxis *axis);
63
63
64 public Q_SLOTS:
64 public Q_SLOTS:
65 void handleHorizontalAxisBaseChanged(qreal baseX);
65 void handleHorizontalAxisBaseChanged(qreal baseX);
@@ -42,6 +42,8 void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
42 bool axisXChanged = false;
42 bool axisXChanged = false;
43 bool axisYChanged = false;
43 bool axisYChanged = false;
44
44
45 adjustLogDomainRanges(minY, maxY);
46
45 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
47 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
46 m_minX = minX;
48 m_minX = minX;
47 m_maxX = maxX;
49 m_maxX = maxX;
@@ -58,7 +60,7 void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
58 qreal logMaxY = log10(m_maxY) / log10(m_logBaseY);
60 qreal logMaxY = log10(m_maxY) / log10(m_logBaseY);
59 m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY;
61 m_logLeftY = logMinY < logMaxY ? logMinY : logMaxY;
60 m_logRightY = logMinY > logMaxY ? logMinY : logMaxY;
62 m_logRightY = logMinY > logMaxY ? logMinY : logMaxY;
61 if(!m_signalsBlocked)
63 if (!m_signalsBlocked)
62 emit rangeVerticalChanged(m_minY, m_maxY);
64 emit rangeVerticalChanged(m_minY, m_maxY);
63 }
65 }
64
66
@@ -136,13 +138,13 QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) cons
136 ok = true;
138 ok = true;
137 return QPointF(x, y);
139 return QPointF(x, y);
138 } else {
140 } else {
139 qWarning() << "Logarithm of negative value is undefined. Empty layout returned";
141 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
140 ok = false;
142 ok = false;
141 return QPointF();
143 return QPointF();
142 }
144 }
143 }
145 }
144
146
145 QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const
147 QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
146 {
148 {
147 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
149 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
148 const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
150 const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
@@ -157,7 +159,7 QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vect
157 result[i].setX(x);
159 result[i].setX(x);
158 result[i].setY(y);
160 result[i].setY(y);
159 } else {
161 } else {
160 qWarning() << "Logarithm of negative value is undefined. Empty layout returned";
162 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
161 return QVector<QPointF>();
163 return QVector<QPointF>();
162 }
164 }
163 }
165 }
@@ -173,22 +175,22 QPointF XLogYDomain::calculateDomainPoint(const QPointF &point) const
173 return QPointF(x, y);
175 return QPointF(x, y);
174 }
176 }
175
177
176 bool XLogYDomain::attachAxis(QAbstractAxis* axis)
178 bool XLogYDomain::attachAxis(QAbstractAxis *axis)
177 {
179 {
178 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
180 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
179
181
180 if(logAxis && logAxis->orientation()==Qt::Vertical){
182 if (logAxis && logAxis->orientation() == Qt::Vertical) {
181 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
183 QObject::connect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
182 handleVerticalAxisBaseChanged(logAxis->base());
184 handleVerticalAxisBaseChanged(logAxis->base());
183 }
185 }
184 return AbstractDomain::attachAxis(axis);
186 return AbstractDomain::attachAxis(axis);
185 }
187 }
186
188
187 bool XLogYDomain::detachAxis(QAbstractAxis* axis)
189 bool XLogYDomain::detachAxis(QAbstractAxis *axis)
188 {
190 {
189 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
191 QLogValueAxis *logAxis = qobject_cast<QLogValueAxis *>(axis);
190
192
191 if(logAxis && logAxis->orientation()==Qt::Vertical)
193 if (logAxis && logAxis->orientation() == Qt::Vertical)
192 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
194 QObject::disconnect(logAxis, SIGNAL(baseChanged(qreal)), this, SLOT(handleVerticalAxisBaseChanged(qreal)));
193
195
194 return AbstractDomain::detachAxis(axis);
196 return AbstractDomain::detachAxis(axis);
@@ -208,10 +210,10 void XLogYDomain::handleVerticalAxisBaseChanged(qreal baseY)
208
210
209 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2)
211 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2)
210 {
212 {
211 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
213 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX)
212 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
214 && qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY)
213 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
215 && qFuzzyIsNull(domain1.m_minX - domain2.m_minX)
214 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
216 && qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
215 }
217 }
216
218
217
219
@@ -56,10 +56,10 public:
56
56
57 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
57 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF> &vector) const;
60
60
61 bool attachAxis(QAbstractAxis* axis);
61 bool attachAxis(QAbstractAxis *axis);
62 bool detachAxis(QAbstractAxis* axis);
62 bool detachAxis(QAbstractAxis *axis);
63
63
64 public Q_SLOTS:
64 public Q_SLOTS:
65 void handleVerticalAxisBaseChanged(qreal baseY);
65 void handleVerticalAxisBaseChanged(qreal baseY);
@@ -126,7 +126,7 QPointF XYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const
126 return QPointF(x, y);
126 return QPointF(x, y);
127 }
127 }
128
128
129 QVector<QPointF> XYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const
129 QVector<QPointF> XYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
130 {
130 {
131 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
131 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
132 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
132 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
@@ -156,10 +156,10 QPointF XYDomain::calculateDomainPoint(const QPointF &point) const
156
156
157 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYDomain &domain1, const XYDomain &domain2)
157 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XYDomain &domain1, const XYDomain &domain2)
158 {
158 {
159 return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) &&
159 return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX)
160 qFuzzyCompare(domain1.m_maxY, domain2.m_maxY) &&
160 && qFuzzyCompare(domain1.m_maxY, domain2.m_maxY)
161 qFuzzyCompare(domain1.m_minX, domain2.m_minX) &&
161 && qFuzzyCompare(domain1.m_minX, domain2.m_minX)
162 qFuzzyCompare(domain1.m_minY, domain2.m_minY));
162 && qFuzzyCompare(domain1.m_minY, domain2.m_minY));
163 }
163 }
164
164
165
165
@@ -56,7 +56,7 public:
56
56
57 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
57 QPointF calculateGeometryPoint(const QPointF &point, bool &ok) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF> &vector) const;
60 };
60 };
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
@@ -27,51 +27,50
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTLAYOUT_H
30 #ifndef ABSTRACTCHARTLAYOUT_H
31 #define CHARTLAYOUT_H
31 #define ABSTRACTCHARTLAYOUT_H
32
32 #include <QGraphicsLayout>
33 #include <QGraphicsLayout>
33 #include <QMargins>
34 #include <QMargins>
34 #include "qchartglobal.h"
35 #include "qchartglobal.h"
35
36
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38
38 class ChartPresenter;
39 class ChartTitle;
39 class ChartTitle;
40 class ChartAxisElement;
41 class ChartPresenter;
40 class QLegend;
42 class QLegend;
41 class ChartAxis;
42 class ChartBackground;
43 class ChartBackground;
43
44
44 class ChartLayout : public QGraphicsLayout
45 class AbstractChartLayout : public QGraphicsLayout
45 {
46 {
46 public:
47 public:
48 AbstractChartLayout(ChartPresenter *presenter);
49 virtual ~AbstractChartLayout();
47
50
48 ChartLayout(ChartPresenter *presenter);
51 virtual void setMargins(const QMargins &margins);
49 virtual ~ChartLayout();
52 virtual QMargins margins() const;
53 virtual void setGeometry(const QRectF &rect);
50
54
51 void setMargins(const QMargins &margins);
55 protected:
52 QMargins margins() const;
56 virtual QRectF calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const;
57 virtual QRectF calculateBackgroundMinimum(const QRectF &minimum) const;
58 virtual QRectF calculateContentGeometry(const QRectF &geometry) const;
59 virtual QRectF calculateContentMinimum(const QRectF &minimum) const;
60 virtual QRectF calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const;
61 virtual QRectF calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const;
62 virtual QRectF calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const;
63 virtual QRectF calculateLegendMinimum(const QRectF &minimum, QLegend *legend) const;
53
64
54 void setGeometry(const QRectF &rect);
65 virtual QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxisElement *>& axes) const = 0;
66 virtual QRectF calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *>& axes) const = 0;
55
67
56 protected:
68 // from QGraphicsLayout
57 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
69 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
58 int count() const { return 0; }
70 int count() const { return 0; }
59 QGraphicsLayoutItem *itemAt(int) const { return 0; };
71 QGraphicsLayoutItem *itemAt(int) const { return 0; };
60 void removeAt(int) {};
72 void removeAt(int) {};
61
73
62 private:
63 QRectF calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const;
64 QRectF calculateContentGeometry(const QRectF &geometry) const;
65 QRectF calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const;
66 QRectF calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const;
67 QRectF calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const;
68 QRectF calculateBackgroundMinimum(const QRectF &minimum) const;
69 QRectF calculateContentMinimum(const QRectF &minimum) const;
70 QRectF calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const;
71 QRectF calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const;
72 QRectF calculateLegendMinimum(const QRectF &minimum, QLegend *legend) const;
73
74 private:
75 ChartPresenter *m_presenter;
74 ChartPresenter *m_presenter;
76 QMargins m_margins;
75 QMargins m_margins;
77 QRectF m_minChartRect;
76 QRectF m_minChartRect;
@@ -80,4 +79,4 private:
80
79
81 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
82
81
83 #endif
82 #endif // ABSTRACTCHARTLAYOUT_H
@@ -18,88 +18,25
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartlayout_p.h"
21 #include "cartesianchartlayout_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlegend_p.h"
23 #include "chartaxiselement_p.h"
24 #include "chartaxis_p.h"
25 #include "charttitle_p.h"
26 #include "chartbackground_p.h"
27 #include <QDebug>
24 #include <QDebug>
28
25
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
27
31 static const qreal maxAxisPortion = 0.4;
28 static const qreal maxAxisPortion = 0.4;
32
29
33 ChartLayout::ChartLayout(ChartPresenter *presenter)
30 CartesianChartLayout::CartesianChartLayout(ChartPresenter *presenter)
34 : m_presenter(presenter),
31 : AbstractChartLayout(presenter)
35 m_margins(20, 20, 20, 20),
36 m_minChartRect(0, 0, 200, 200)
37 {
32 {
38
39 }
40
41 ChartLayout::~ChartLayout()
42 {
43
44 }
45
46 void ChartLayout::setGeometry(const QRectF &rect)
47 {
48 if (!rect.isValid())
49 return;
50
51 QList<ChartAxis *> axes = m_presenter->axisItems();
52 ChartTitle *title = m_presenter->titleElement();
53 QLegend *legend = m_presenter->legend();
54 ChartBackground *background = m_presenter->backgroundElement();
55
56 QRectF contentGeometry = calculateBackgroundGeometry(rect, background);
57
58 contentGeometry = calculateContentGeometry(contentGeometry);
59
60 if (title && title->isVisible())
61 contentGeometry = calculateTitleGeometry(contentGeometry, title);
62
63 if (legend->isAttachedToChart() && legend->isVisible())
64 contentGeometry = calculateLegendGeometry(contentGeometry, legend);
65
66 contentGeometry = calculateAxisGeometry(contentGeometry, axes);
67
68 m_presenter->setGeometry(contentGeometry);
69
70 QGraphicsLayout::setGeometry(rect);
71 }
33 }
72
34
73 QRectF ChartLayout::calculateContentGeometry(const QRectF &geometry) const
35 CartesianChartLayout::~CartesianChartLayout()
74 {
36 {
75 return geometry.adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom());
76 }
37 }
77
38
78 QRectF ChartLayout::calculateContentMinimum(const QRectF &minimum) const
39 QRectF CartesianChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxisElement *> &axes) const
79 {
80 return minimum.adjusted(0, 0, m_margins.left() + m_margins.right(), m_margins.top() + m_margins.bottom());
81 }
82
83
84 QRectF ChartLayout::calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const
85 {
86 qreal left, top, right, bottom;
87 getContentsMargins(&left, &top, &right, &bottom);
88 QRectF backgroundGeometry = geometry.adjusted(left, top, -right, -bottom);
89 if (background)
90 background->setRect(backgroundGeometry);
91 return backgroundGeometry;
92 }
93
94 QRectF ChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const
95 {
96 qreal left, top, right, bottom;
97 getContentsMargins(&left, &top, &right, &bottom);
98 return minimum.adjusted(0, 0, left + right, top + bottom);
99 }
100
101
102 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<ChartAxis *>& axes) const
103 {
40 {
104 QSizeF left(0,0);
41 QSizeF left(0,0);
105 QSizeF minLeft(0,0);
42 QSizeF minLeft(0,0);
@@ -115,16 +52,17 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
115 int topCount = 0;
52 int topCount = 0;
116 int bottomCount = 0;
53 int bottomCount = 0;
117
54
118 foreach (ChartAxis *axis , axes) {
55 foreach (ChartAxisElement *axis , axes) {
119
56
120 if (!axis->isVisible())
57 if (!axis->isVisible())
121 continue;
58 continue;
122
59
60
123 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
61 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
124 //this is used to get single thick font size
62 //this is used to get single thick font size
125 QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize);
63 QSizeF minSize = axis->effectiveSizeHint(Qt::MinimumSize);
126
64
127 switch (axis->alignment()) {
65 switch (axis->axis()->alignment()) {
128 case Qt::AlignLeft:
66 case Qt::AlignLeft:
129 left.setWidth(left.width()+size.width());
67 left.setWidth(left.width()+size.width());
130 left.setHeight(qMax(left.height(),size.height()));
68 left.setHeight(qMax(left.height(),size.height()));
@@ -163,7 +101,7 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
163 }
101 }
164 }
102 }
165
103
166 int totalVerticalAxes = leftCount + rightCount;
104 qreal totalVerticalAxes = leftCount + rightCount;
167 qreal leftSqueezeRatio = 1.0;
105 qreal leftSqueezeRatio = 1.0;
168 qreal rightSqueezeRatio = 1.0;
106 qreal rightSqueezeRatio = 1.0;
169 qreal vratio = 0;
107 qreal vratio = 0;
@@ -186,7 +124,7 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
186 }
124 }
187 }
125 }
188
126
189 int totalHorizontalAxes = topCount + bottomCount;
127 qreal totalHorizontalAxes = topCount + bottomCount;
190 qreal topSqueezeRatio = 1.0;
128 qreal topSqueezeRatio = 1.0;
191 qreal bottomSqueezeRatio = 1.0;
129 qreal bottomSqueezeRatio = 1.0;
192 qreal hratio = 0;
130 qreal hratio = 0;
@@ -225,15 +163,14 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
225 qreal topOffset = 0;
163 qreal topOffset = 0;
226 qreal bottomOffset = 0;
164 qreal bottomOffset = 0;
227
165
228 foreach(ChartElement *axisElement , axes) {
166 foreach (ChartAxisElement *axis , axes) {
229 ChartAxis* axis = qobject_cast<ChartAxis*>(axisElement);
230
167
231 if (!axis->isVisible())
168 if (!axis->isVisible())
232 continue;
169 continue;
233
170
234 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
171 QSizeF size = axis->effectiveSizeHint(Qt::PreferredSize);
235
172
236 switch(axis->alignment()){
173 switch (axis->axis()->alignment()){
237 case Qt::AlignLeft:{
174 case Qt::AlignLeft:{
238 qreal width = size.width();
175 qreal width = size.width();
239 if (leftSqueezeRatio < 1.0)
176 if (leftSqueezeRatio < 1.0)
@@ -271,21 +208,20 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
271 return chartRect;
208 return chartRect;
272 }
209 }
273
210
274 QRectF ChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxis *>& axes) const
211 QRectF CartesianChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<ChartAxisElement *> &axes) const
275 {
212 {
276 QSizeF left;
213 QSizeF left;
277 QSizeF right;
214 QSizeF right;
278 QSizeF bottom;
215 QSizeF bottom;
279 QSizeF top;
216 QSizeF top;
280
217
281 foreach (ChartAxis *axis, axes) {
218 foreach (ChartAxisElement *axis, axes) {
282
283 QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize);
219 QSizeF size = axis->effectiveSizeHint(Qt::MinimumSize);
284
220
285 if (!axis->isVisible())
221 if (!axis->isVisible())
286 continue;
222 continue;
287
223
288 switch (axis->alignment()) {
224 switch (axis->axis()->alignment()) {
289 case Qt::AlignLeft:
225 case Qt::AlignLeft:
290 left.setWidth(left.width() + size.width());
226 left.setWidth(left.width() + size.width());
291 left.setHeight(qMax(left.height() * 2, size.height()));
227 left.setHeight(qMax(left.height() * 2, size.height()));
@@ -307,96 +243,4 QRectF ChartLayout::calculateAxisMinimum(const QRectF &minimum, const QList<Char
307 return minimum.adjusted(0, 0, left.width() + right.width() + qMax(top.width(), bottom.width()), top.height() + bottom.height() + qMax(left.height(), right.height()));
243 return minimum.adjusted(0, 0, left.width() + right.width() + qMax(top.width(), bottom.width()), top.height() + bottom.height() + qMax(left.height(), right.height()));
308 }
244 }
309
245
310 QRectF ChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const
311 {
312 QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1));
313 QRectF legendRect;
314 QRectF result;
315
316 switch (legend->alignment()) {
317 case Qt::AlignTop: {
318 legendRect = QRectF(geometry.topLeft(), QSizeF(geometry.width(), size.height()));
319 result = geometry.adjusted(0, legendRect.height(), 0, 0);
320 break;
321 }
322 case Qt::AlignBottom: {
323 legendRect = QRectF(QPointF(geometry.left(), geometry.bottom() - size.height()), QSizeF(geometry.width(), size.height()));
324 result = geometry.adjusted(0, 0, 0, -legendRect.height());
325 break;
326 }
327 case Qt::AlignLeft: {
328 qreal width = qMin(size.width(), geometry.width() * maxAxisPortion);
329 legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height()));
330 result = geometry.adjusted(width, 0, 0, 0);
331 break;
332 }
333 case Qt::AlignRight: {
334 qreal width = qMin(size.width(), geometry.width() * maxAxisPortion);
335 legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height()));
336 result = geometry.adjusted(0, 0, -width, 0);
337 break;
338 }
339 default: {
340 legendRect = QRectF(0, 0, 0, 0);
341 result = geometry;
342 break;
343 }
344 }
345
346 legend->setGeometry(legendRect);
347
348 return result;
349 }
350
351 QRectF ChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const
352 {
353 QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1));
354 return geometry.adjusted(0, 0, minSize.width(), minSize.height());
355 }
356
357 QRectF ChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const
358 {
359 title->setGeometry(geometry);
360 QPointF center = geometry.center() - title->boundingRect().center();
361 title->setPos(center.x(),title->pos().y());
362 return geometry.adjusted(0,title->boundingRect().height()+1,0,0);
363 }
364
365 QRectF ChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const
366 {
367 QSizeF min = title->sizeHint(Qt::MinimumSize);
368 return minimum.adjusted(0, 0, min.width(), min.height());
369 }
370
371 QSizeF ChartLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
372 {
373 Q_UNUSED(constraint);
374 if (which == Qt::MinimumSize) {
375 QList<ChartAxis *> axes = m_presenter->axisItems();
376 ChartTitle *title = m_presenter->titleElement();
377 QLegend *legend = m_presenter->legend();
378 QRectF minimumRect(0, 0, 0, 0);
379 minimumRect = calculateBackgroundMinimum(minimumRect);
380 minimumRect = calculateContentMinimum(minimumRect);
381 minimumRect = calculateTitleMinimum(minimumRect, title);
382 minimumRect = calculateLegendMinimum(minimumRect, legend);
383 minimumRect = calculateAxisMinimum(minimumRect, axes);
384 return minimumRect.united(m_minChartRect).size().toSize();
385 }
386 return QSize(-1, -1);
387 }
388
389 void ChartLayout::setMargins(const QMargins &margins)
390 {
391 if (m_margins != margins) {
392 m_margins = margins;
393 updateGeometry();
394 }
395 }
396
397 QMargins ChartLayout::margins() const
398 {
399 return m_margins;
400 }
401
402 QTCOMMERCIALCHART_END_NAMESPACE
246 QTCOMMERCIALCHART_END_NAMESPACE
@@ -21,7 +21,7
21 #include "legendlayout_p.h"
21 #include "legendlayout_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlegend_p.h"
23 #include "qlegend_p.h"
24 #include "chartlayout_p.h"
24 #include "abstractchartlayout_p.h"
25
25
26 #include "qlegendmarker_p.h"
26 #include "qlegendmarker_p.h"
27 #include "legendmarkeritem_p.h"
27 #include "legendmarkeritem_p.h"
@@ -25,7 +25,7
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include "chartpresenter_p.h"
27 #include "chartpresenter_p.h"
28 #include "chartlayout_p.h"
28 #include "abstractchartlayout_p.h"
29 #include "qlegendmarker.h"
29 #include "qlegendmarker.h"
30 #include "qlegendmarker_p.h"
30 #include "qlegendmarker_p.h"
31 #include "legendmarkeritem_p.h"
31 #include "legendmarkeritem_p.h"
@@ -22,7 +22,7
22 #include "qlineseries.h"
22 #include "qlineseries.h"
23 #include "qlineseries_p.h"
23 #include "qlineseries_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractdomain_p.h"
25 #include "polardomain_p.h"
26 #include <QPainter>
26 #include <QPainter>
27 #include <QGraphicsSceneMouseEvent>
27 #include <QGraphicsSceneMouseEvent>
28
28
@@ -30,10 +30,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 const qreal mouseEventMinWidth(12);
31 const qreal mouseEventMinWidth(12);
32
32
33 LineChartItem::LineChartItem(QLineSeries *series,QGraphicsItem* item)
33 LineChartItem::LineChartItem(QLineSeries *series, QGraphicsItem *item)
34 : XYChart(series,item),
34 : XYChart(series,item),
35 m_series(series),
35 m_series(series),
36 m_pointsVisible(false)
36 m_pointsVisible(false),
37 m_chartType(QChart::ChartTypeUndefined)
37 {
38 {
38 setAcceptHoverEvents(true);
39 setAcceptHoverEvents(true);
39 setZValue(ChartPresenter::LineChartZValue);
40 setZValue(ChartPresenter::LineChartZValue);
@@ -50,54 +51,235 QRectF LineChartItem::boundingRect() const
50
51
51 QPainterPath LineChartItem::shape() const
52 QPainterPath LineChartItem::shape() const
52 {
53 {
53 return m_path;
54 return m_shapePath;
54 }
55 }
55
56
56 void LineChartItem::updateGeometry()
57 void LineChartItem::updateGeometry()
57 {
58 {
58 m_points = geometryPoints();
59 m_points = geometryPoints();
60 const QVector<QPointF> &points = m_points;
59
61
60 if (m_points.size() == 0) {
62 if (points.size() == 0) {
61 prepareGeometryChange();
63 prepareGeometryChange();
62 m_path = QPainterPath();
64 m_fullPath = QPainterPath();
63 m_linePath = QPainterPath();
65 m_linePath = QPainterPath();
64 m_rect = QRect();
66 m_rect = QRect();
65 return;
67 return;
66 }
68 }
67
69
68 QPainterPath linePath(m_points.at(0));
70 QPainterPath linePath;
71 QPainterPath fullPath;
72 // Use worst case scenario to determine required margin.
73 qreal margin = m_linePen.width() * 1.42;
69
74
70 if (m_pointsVisible) {
75 // Area series use component line series that aren't necessarily added to the chart themselves,
76 // so check if chart type is forced before trying to obtain it from the chart.
77 QChart::ChartType chartType = m_chartType;
78 if (chartType == QChart::ChartTypeUndefined)
79 chartType = m_series->chart()->chartType();
71
80
81 // For polar charts, we need special handling for angular (horizontal)
82 // points that are off-grid.
83 if (chartType == QChart::ChartTypePolar) {
84 QPainterPath linePathLeft;
85 QPainterPath linePathRight;
86 QPainterPath *currentSegmentPath = 0;
87 QPainterPath *previousSegmentPath = 0;
88 qreal minX = domain()->minX();
89 qreal maxX = domain()->maxX();
90 qreal minY = domain()->minY();
91 QPointF currentSeriesPoint = m_series->pointAt(0);
92 QPointF currentGeometryPoint = points.at(0);
93 QPointF previousGeometryPoint = points.at(0);
72 int size = m_linePen.width();
94 int size = m_linePen.width();
73 linePath.addEllipse(m_points.at(0), size, size);
95 bool pointOffGrid = false;
74 linePath.moveTo(m_points.at(0));
96 bool previousPointWasOffGrid = (currentSeriesPoint.x() < minX || currentSeriesPoint.x() > maxX);
75 for (int i = 1; i < m_points.size(); i++) {
97
76 linePath.lineTo(m_points.at(i));
98 qreal domainRadius = domain()->size().height() / 2.0;
77 linePath.addEllipse(m_points.at(i), size, size);
99 const QPointF centerPoint(domainRadius, domainRadius);
78 linePath.moveTo(m_points.at(i));
100
101 if (!previousPointWasOffGrid) {
102 fullPath.moveTo(points.at(0));
103 if (m_pointsVisible && currentSeriesPoint.y() >= minY) {
104 // Do not draw ellipses for points below minimum Y.
105 linePath.addEllipse(points.at(0), size, size);
106 fullPath.addEllipse(points.at(0), size, size);
107 linePath.moveTo(points.at(0));
108 fullPath.moveTo(points.at(0));
109 }
79 }
110 }
80
111
81 } else {
112 qreal leftMarginLine = centerPoint.x() - margin;
82 for (int i = 1; i < m_points.size(); i++)
113 qreal rightMarginLine = centerPoint.x() + margin;
83 linePath.lineTo(m_points.at(i));
114 qreal horizontal = centerPoint.y();
84 }
85
115
86 m_linePath = linePath;
116 for (int i = 1; i < points.size(); i++) {
117 // Interpolating line fragments would be ugly when thick pen is used,
118 // so we work around it by utilizing three separate
119 // paths for line segments and clip those with custom regions at paint time.
120 // "Right" path contains segments that cross the axis line with visible point on the
121 // right side of the axis line, as well as segments that have one point within the margin
122 // on the right side of the axis line and another point on the right side of the chart.
123 // "Left" path contains points with similarly on the left side.
124 // "Full" path contains rest of the points.
125 // This doesn't yield perfect results always. E.g. when segment covers more than 90
126 // degrees and both of the points are within the margin, one in the top half and one in the
127 // bottom half of the chart, the bottom one gets clipped incorrectly.
128 // However, this should be rare occurrence in any sensible chart.
129 currentSeriesPoint = m_series->pointAt(i);
130 currentGeometryPoint = points.at(i);
131 pointOffGrid = (currentSeriesPoint.x() < minX || currentSeriesPoint.x() > maxX);
132
133 // Draw something unless both off-grid
134 if (!pointOffGrid || !previousPointWasOffGrid) {
135 QPointF intersectionPoint;
136 qreal y;
137 if (pointOffGrid != previousPointWasOffGrid) {
138 if (currentGeometryPoint.x() == previousGeometryPoint.x()) {
139 y = currentGeometryPoint.y() + (currentGeometryPoint.y() - previousGeometryPoint.y()) / 2.0;
140 } else {
141 qreal ratio = (centerPoint.x() - currentGeometryPoint.x()) / (currentGeometryPoint.x() - previousGeometryPoint.x());
142 y = currentGeometryPoint.y() + (currentGeometryPoint.y() - previousGeometryPoint.y()) * ratio;
143 }
144 intersectionPoint = QPointF(centerPoint.x(), y);
145 }
146
147 bool dummyOk; // We know points are ok, but this is needed
148 qreal currentAngle = static_cast<PolarDomain *>(domain())->toAngularCoordinate(currentSeriesPoint.x(), dummyOk);
149 qreal previousAngle = static_cast<PolarDomain *>(domain())->toAngularCoordinate(m_series->pointAt(i - 1).x(), dummyOk);
150
151 if ((qAbs(currentAngle - previousAngle) > 180.0)) {
152 // If the angle between two points is over 180 degrees (half X range),
153 // any direct segment between them becomes meaningless.
154 // In this case two line segments are drawn instead, from previous
155 // point to the center and from center to current point.
156 if ((previousAngle < 0.0 || (previousAngle <= 180.0 && previousGeometryPoint.x() < rightMarginLine))
157 && previousGeometryPoint.y() < horizontal) {
158 currentSegmentPath = &linePathRight;
159 } else if ((previousAngle > 360.0 || (previousAngle > 180.0 && previousGeometryPoint.x() > leftMarginLine))
160 && previousGeometryPoint.y() < horizontal) {
161 currentSegmentPath = &linePathLeft;
162 } else if (previousAngle > 0.0 && previousAngle < 360.0) {
163 currentSegmentPath = &linePath;
164 } else {
165 currentSegmentPath = 0;
166 }
167
168 if (currentSegmentPath) {
169 if (previousSegmentPath != currentSegmentPath)
170 currentSegmentPath->moveTo(previousGeometryPoint);
171 if (previousPointWasOffGrid)
172 fullPath.moveTo(intersectionPoint);
173
174 currentSegmentPath->lineTo(centerPoint);
175 fullPath.lineTo(centerPoint);
176 }
177
178 previousSegmentPath = currentSegmentPath;
179
180 if ((currentAngle < 0.0 || (currentAngle <= 180.0 && currentGeometryPoint.x() < rightMarginLine))
181 && currentGeometryPoint.y() < horizontal) {
182 currentSegmentPath = &linePathRight;
183 } else if ((currentAngle > 360.0 || (currentAngle > 180.0 &&currentGeometryPoint.x() > leftMarginLine))
184 && currentGeometryPoint.y() < horizontal) {
185 currentSegmentPath = &linePathLeft;
186 } else if (currentAngle > 0.0 && currentAngle < 360.0) {
187 currentSegmentPath = &linePath;
188 } else {
189 currentSegmentPath = 0;
190 }
191
192 if (currentSegmentPath) {
193 if (previousSegmentPath != currentSegmentPath)
194 currentSegmentPath->moveTo(centerPoint);
195 if (!previousSegmentPath)
196 fullPath.moveTo(centerPoint);
197
198 currentSegmentPath->lineTo(currentGeometryPoint);
199 if (pointOffGrid)
200 fullPath.lineTo(intersectionPoint);
201 else
202 fullPath.lineTo(currentGeometryPoint);
203 }
204 } else {
205 if (previousAngle < 0.0 || currentAngle < 0.0
206 || ((previousAngle <= 180.0 && currentAngle <= 180.0)
207 && ((previousGeometryPoint.x() < rightMarginLine && previousGeometryPoint.y() < horizontal)
208 || (currentGeometryPoint.x() < rightMarginLine && currentGeometryPoint.y() < horizontal)))) {
209 currentSegmentPath = &linePathRight;
210 } else if (previousAngle > 360.0 || currentAngle > 360.0
211 || ((previousAngle > 180.0 && currentAngle > 180.0)
212 && ((previousGeometryPoint.x() > leftMarginLine && previousGeometryPoint.y() < horizontal)
213 || (currentGeometryPoint.x() > leftMarginLine && currentGeometryPoint.y() < horizontal)))) {
214 currentSegmentPath = &linePathLeft;
215 } else {
216 currentSegmentPath = &linePath;
217 }
218
219 if (currentSegmentPath != previousSegmentPath)
220 currentSegmentPath->moveTo(previousGeometryPoint);
221 if (previousPointWasOffGrid)
222 fullPath.moveTo(intersectionPoint);
223
224 if (pointOffGrid)
225 fullPath.lineTo(intersectionPoint);
226 else
227 fullPath.lineTo(currentGeometryPoint);
228 currentSegmentPath->lineTo(currentGeometryPoint);
229 }
230 } else {
231 currentSegmentPath = 0;
232 }
233
234 previousPointWasOffGrid = pointOffGrid;
235 if (m_pointsVisible && !pointOffGrid && currentSeriesPoint.y() >= minY) {
236 linePath.addEllipse(points.at(i), size, size);
237 fullPath.addEllipse(points.at(i), size, size);
238 linePath.moveTo(points.at(i));
239 fullPath.moveTo(points.at(i));
240 }
241 previousSegmentPath = currentSegmentPath;
242 previousGeometryPoint = currentGeometryPoint;
243 }
244 m_linePathPolarRight = linePathRight;
245 m_linePathPolarLeft = linePathLeft;
246 // Note: This construction of m_fullpath is not perfect. The partial segments that are
247 // outside left/right clip regions at axis boundary still generate hover/click events,
248 // because shape doesn't get clipped. It doesn't seem possible to do sensibly.
249 } else { // not polar
250 linePath.moveTo(points.at(0));
251 if (m_pointsVisible) {
252 int size = m_linePen.width();
253 linePath.addEllipse(points.at(0), size, size);
254 linePath.moveTo(points.at(0));
255 for (int i = 1; i < points.size(); i++) {
256 linePath.lineTo(points.at(i));
257 linePath.addEllipse(points.at(i), size, size);
258 linePath.moveTo(points.at(i));
259 }
260 } else {
261 for (int i = 1; i < points.size(); i++)
262 linePath.lineTo(points.at(i));
263 }
264 fullPath = linePath;
265 }
87
266
88 QPainterPathStroker stroker;
267 QPainterPathStroker stroker;
89 // QPainter::drawLine does not respect join styles, for example BevelJoin becomes MiterJoin.
268 // QPainter::drawLine does not respect join styles, for example BevelJoin becomes MiterJoin.
90 // This is why we are prepared for the "worst case" scenario, i.e. use always MiterJoin and
269 // This is why we are prepared for the "worst case" scenario, i.e. use always MiterJoin and
91 // multiply line width with square root of two when defining shape and bounding rectangle.
270 // multiply line width with square root of two when defining shape and bounding rectangle.
92 stroker.setWidth(m_linePen.width() * 1.42);
271 stroker.setWidth(margin);
93 stroker.setJoinStyle(Qt::MiterJoin);
272 stroker.setJoinStyle(Qt::MiterJoin);
94 stroker.setCapStyle(Qt::SquareCap);
273 stroker.setCapStyle(Qt::SquareCap);
95 stroker.setMiterLimit(m_linePen.miterLimit());
274 stroker.setMiterLimit(m_linePen.miterLimit());
96
275
97 prepareGeometryChange();
276 prepareGeometryChange();
98
277
99 m_path = stroker.createStroke(linePath);
278 m_linePath = linePath;
100 m_rect = m_path.boundingRect();
279 m_fullPath = fullPath;
280 m_shapePath = stroker.createStroke(fullPath);
281
282 m_rect = m_shapePath.boundingRect();
101 }
283 }
102
284
103 void LineChartItem::handleUpdated()
285 void LineChartItem::handleUpdated()
@@ -121,16 +303,35 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
121 Q_UNUSED(widget)
303 Q_UNUSED(widget)
122 Q_UNUSED(option)
304 Q_UNUSED(option)
123
305
306 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
307
124 painter->save();
308 painter->save();
125 painter->setPen(m_linePen);
309 painter->setPen(m_linePen);
126 painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
310 bool alwaysUsePath = false;
311
312 if (m_series->chart()->chartType() == QChart::ChartTypePolar) {
313 qreal halfWidth = domain()->size().width() / 2.0;
314 QRectF clipRectLeft = QRectF(0, 0, halfWidth, domain()->size().height());
315 QRectF clipRectRight = QRectF(halfWidth, 0, halfWidth, domain()->size().height());
316 QRegion fullPolarClipRegion(clipRect.toRect(), QRegion::Ellipse);
317 QRegion clipRegionLeft(fullPolarClipRegion.intersected(clipRectLeft.toRect()));
318 QRegion clipRegionRight(fullPolarClipRegion.intersected(clipRectRight.toRect()));
319 painter->setClipRegion(clipRegionLeft);
320 painter->drawPath(m_linePathPolarLeft);
321 painter->setClipRegion(clipRegionRight);
322 painter->drawPath(m_linePathPolarRight);
323 painter->setClipRegion(fullPolarClipRegion);
324 alwaysUsePath = true; // required for proper clipping
325 } else {
326 painter->setClipRect(clipRect);
327 }
127
328
128 if (m_pointsVisible) {
329 if (m_pointsVisible) {
129 painter->setBrush(m_linePen.color());
330 painter->setBrush(m_linePen.color());
130 painter->drawPath(m_linePath);
331 painter->drawPath(m_linePath);
131 } else {
332 } else {
132 painter->setBrush(QBrush(Qt::NoBrush));
333 painter->setBrush(QBrush(Qt::NoBrush));
133 if (m_linePen.style() != Qt::SolidLine) {
334 if (m_linePen.style() != Qt::SolidLine || alwaysUsePath) {
134 // If pen style is not solid line, always fall back to path painting
335 // If pen style is not solid line, always fall back to path painting
135 // to ensure proper continuity of the pattern
336 // to ensure proper continuity of the pattern
136 painter->drawPath(m_linePath);
337 painter->drawPath(m_linePath);
@@ -32,6 +32,7
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "xychart_p.h"
34 #include "xychart_p.h"
35 #include "qchart.h"
35 #include <QPen>
36 #include <QPen>
36
37
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -44,7 +45,7 class LineChartItem : public XYChart
44 Q_OBJECT
45 Q_OBJECT
45 Q_INTERFACES(QGraphicsItem)
46 Q_INTERFACES(QGraphicsItem)
46 public:
47 public:
47 explicit LineChartItem(QLineSeries *series, QGraphicsItem* item = 0);
48 explicit LineChartItem(QLineSeries *series, QGraphicsItem *item = 0);
48 ~LineChartItem() {}
49 ~LineChartItem() {}
49
50
50 //from QGraphicsItem
51 //from QGraphicsItem
@@ -52,7 +53,7 public:
52 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
53 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
53 QPainterPath shape() const;
54 QPainterPath shape() const;
54
55
55 QPainterPath path() const { return m_linePath; }
56 QPainterPath path() const { return m_fullPath; }
56
57
57 public Q_SLOTS:
58 public Q_SLOTS:
58 void handleUpdated();
59 void handleUpdated();
@@ -63,15 +64,21 protected:
63 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
64 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
64 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
65 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
65 void suppressPoints() { m_pointsVisible = false; }
66 void suppressPoints() { m_pointsVisible = false; }
67 void forceChartType(QChart::ChartType chartType) { m_chartType = chartType; }
66
68
67 private:
69 private:
68 QLineSeries *m_series;
70 QLineSeries *m_series;
69 QPainterPath m_path;
70 QPainterPath m_linePath;
71 QPainterPath m_linePath;
72 QPainterPath m_linePathPolarRight;
73 QPainterPath m_linePathPolarLeft;
74 QPainterPath m_fullPath;
75 QPainterPath m_shapePath;
76
71 QVector<QPointF> m_points;
77 QVector<QPointF> m_points;
72 QRectF m_rect;
78 QRectF m_rect;
73 QPen m_linePen;
79 QPen m_linePen;
74 bool m_pointsVisible;
80 bool m_pointsVisible;
81 QChart::ChartType m_chartType;
75 };
82 };
76
83
77 QTCOMMERCIALCHART_END_NAMESPACE
84 QTCOMMERCIALCHART_END_NAMESPACE
@@ -24,7 +24,7
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include "chartlayout_p.h"
27 #include "abstractchartlayout_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartpresenter_p.h"
29 #include "chartpresenter_p.h"
30 #include "chartdataset_p.h"
30 #include "chartdataset_p.h"
@@ -59,6 +59,16 QTCOMMERCIALCHART_BEGIN_NAMESPACE
59 */
59 */
60
60
61 /*!
61 /*!
62 \enum QChart::ChartType
63
64 This enum describes the chart type.
65
66 \value ChartTypeUndefined
67 \value ChartTypeCartesian
68 \value ChartTypePolar
69 */
70
71 /*!
62 \class QChart
72 \class QChart
63 \brief QtCommercial chart API.
73 \brief QtCommercial chart API.
64
74
@@ -110,15 +120,34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
110 */
120 */
111
121
112 /*!
122 /*!
113 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
123 \property QChart::chartType
124 Chart type indicates if the chart is a cartesian chart or a polar chart.
125 This property is set internally and is read only.
126 \sa QPolarChart
127 */
128
129 /*!
130 \internal
131 Constructs a chart object of \a type which is a child of a \a parent.
132 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
133 This constructor is called only by subclasses.
134 */
135 QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags)
136 : QGraphicsWidget(parent, wFlags),
137 d_ptr(new QChartPrivate(this, type))
138 {
139 d_ptr->init();
140 }
141
142 /*!
143 Constructs a chart object which is a child of a \a parent.
144 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
114 */
145 */
115 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
146 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
116 : QGraphicsWidget(parent, wFlags),
147 : QGraphicsWidget(parent, wFlags),
117 d_ptr(new QChartPrivate(this))
148 d_ptr(new QChartPrivate(this, ChartTypeCartesian))
118 {
149 {
119 d_ptr->m_legend = new LegendScroller(this);
150 d_ptr->init();
120 setTheme(QChart::ChartThemeLight);
121 setLayout(d_ptr->m_presenter->layout());
122 }
151 }
123
152
124 /*!
153 /*!
@@ -269,9 +298,12 void QChart::zoomIn()
269
298
270 /*!
299 /*!
271 Zooms in the view to a maximum level at which \a rect is still fully visible.
300 Zooms in the view to a maximum level at which \a rect is still fully visible.
301 \note This is not supported for polar charts.
272 */
302 */
273 void QChart::zoomIn(const QRectF &rect)
303 void QChart::zoomIn(const QRectF &rect)
274 {
304 {
305 if (d_ptr->m_type == QChart::ChartTypePolar)
306 return;
275 d_ptr->zoomIn(rect);
307 d_ptr->zoomIn(rect);
276 }
308 }
277
309
@@ -306,8 +338,8 void QChart::zoom(qreal factor)
306 }
338 }
307
339
308 /*!
340 /*!
309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
341 Returns the pointer to the x axis object of the chart associated with the specified \a series.
310 If no series is provided then pointer to currently visible axis is provided
342 If no series is provided then pointer to currently visible axis is provided.
311 */
343 */
312 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
344 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
313 {
345 {
@@ -318,8 +350,8 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
318 }
350 }
319
351
320 /*!
352 /*!
321 Returns the pointer to the y axis object of the chart asociated with the specified \a series
353 Returns the pointer to the y axis object of the chart associated with the specified \a series.
322 If no series is provided then pointer to currently visible axis is provided
354 If no series is provided then pointer to currently visible axis is provided.
323 */
355 */
324 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
356 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
325 {
357 {
@@ -438,6 +470,11 QMargins QChart::margins() const
438 return d_ptr->m_presenter->layout()->margins();
470 return d_ptr->m_presenter->layout()->margins();
439 }
471 }
440
472
473 QChart::ChartType QChart::chartType() const
474 {
475 return d_ptr->m_type;
476 }
477
441 /*!
478 /*!
442 Returns the the rect within which the drawing of the chart is done.
479 Returns the the rect within which the drawing of the chart is done.
443 It does not include the area defines by margins.
480 It does not include the area defines by margins.
@@ -471,6 +508,8 QChart::AnimationOptions QChart::animationOptions() const
471
508
472 /*!
509 /*!
473 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
510 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
511
512 For polar charts, \a dx indicates the angle along angular axis instead of distance.
474 */
513 */
475 void QChart::scroll(qreal dx, qreal dy)
514 void QChart::scroll(qreal dx, qreal dy)
476 {
515 {
@@ -581,11 +620,12 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
581
620
582 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
621 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
583
622
584 QChartPrivate::QChartPrivate(QChart *q):
623 QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type):
585 q_ptr(q),
624 q_ptr(q),
625 m_type(type),
586 m_legend(0),
626 m_legend(0),
587 m_dataset(new ChartDataSet(q)),
627 m_dataset(new ChartDataSet(q)),
588 m_presenter(new ChartPresenter(q)),
628 m_presenter(new ChartPresenter(q, type)),
589 m_themeManager(new ChartThemeManager(q))
629 m_themeManager(new ChartThemeManager(q))
590 {
630 {
591 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
631 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
@@ -603,6 +643,13 QChartPrivate::~QChartPrivate()
603
643
604 }
644 }
605
645
646 void QChartPrivate::init()
647 {
648 m_legend = new LegendScroller(q_ptr);
649 q_ptr->setTheme(QChart::ChartThemeLight);
650 q_ptr->setLayout(m_presenter->layout());
651 }
652
606 void QChartPrivate::zoomIn(qreal factor)
653 void QChartPrivate::zoomIn(qreal factor)
607 {
654 {
608 QRectF rect = m_presenter->geometry();
655 QRectF rect = m_presenter->geometry();
@@ -45,10 +45,18 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
45 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
45 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
46 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
46 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
47 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
47 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
48 Q_PROPERTY(QChart::ChartType chartType READ chartType)
48 Q_ENUMS(ChartTheme)
49 Q_ENUMS(ChartTheme)
49 Q_ENUMS(AnimationOption)
50 Q_ENUMS(AnimationOption)
51 Q_ENUMS(ChartType)
50
52
51 public:
53 public:
54 enum ChartType {
55 ChartTypeUndefined = 0,
56 ChartTypeCartesian,
57 ChartTypePolar
58 };
59
52 enum ChartTheme {
60 enum ChartTheme {
53 ChartThemeLight = 0,
61 ChartThemeLight = 0,
54 ChartThemeBlueCerulean,
62 ChartThemeBlueCerulean,
@@ -84,7 +92,7 public:
84 QAbstractAxis *axisY(QAbstractSeries *series = 0) const;
92 QAbstractAxis *axisY(QAbstractSeries *series = 0) const;
85 // ******************
93 // ******************
86
94
87 void addAxis(QAbstractAxis *axis,Qt::Alignment alignment);
95 void addAxis(QAbstractAxis *axis, Qt::Alignment alignment);
88 void removeAxis(QAbstractAxis *axis);
96 void removeAxis(QAbstractAxis *axis);
89 QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const;
97 QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const;
90
98
@@ -133,7 +141,10 public:
133 QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0);
141 QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0);
134 QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0);
142 QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0);
135
143
144 ChartType chartType() const;
145
136 protected:
146 protected:
147 explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags);
137 QScopedPointer<QChartPrivate> d_ptr;
148 QScopedPointer<QChartPrivate> d_ptr;
138 friend class QLegend;
149 friend class QLegend;
139 friend class DeclarativeChart;
150 friend class DeclarativeChart;
@@ -31,10 +31,10
31 #define QCHART_P_H
31 #define QCHART_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h"
34
35
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37
37 class QChart;
38 class ChartThemeManager;
38 class ChartThemeManager;
39 class ChartPresenter;
39 class ChartPresenter;
40 class QLegend;
40 class QLegend;
@@ -44,14 +44,16 class QChartPrivate
44 {
44 {
45
45
46 public:
46 public:
47 QChartPrivate(QChart *q);
47 QChartPrivate(QChart *q, QChart::ChartType type);
48 ~QChartPrivate();
48 ~QChartPrivate();
49 QChart *q_ptr;
49 QChart *q_ptr;
50 QLegend *m_legend;
50 QLegend *m_legend;
51 ChartDataSet *m_dataset;
51 ChartDataSet *m_dataset;
52 ChartPresenter *m_presenter;
52 ChartPresenter *m_presenter;
53 ChartThemeManager *m_themeManager;
53 ChartThemeManager *m_themeManager;
54 QChart::ChartType m_type;
54
55
56 void init();
55 void zoomIn(qreal factor);
57 void zoomIn(qreal factor);
56 void zoomOut(qreal factor);
58 void zoomOut(qreal factor);
57 void zoomIn(const QRectF &rect);
59 void zoomIn(const QRectF &rect);
@@ -23,6 +23,7
23 #include "qscatterseries_p.h"
23 #include "qscatterseries_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "qchart.h"
26 #include <QPainter>
27 #include <QPainter>
27 #include <QGraphicsScene>
28 #include <QGraphicsScene>
28 #include <QDebug>
29 #include <QDebug>
@@ -30,7 +31,7
30
31
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
33
33 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem* item)
34 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
34 : XYChart(series,item),
35 : XYChart(series,item),
35 m_series(series),
36 m_series(series),
36 m_items(this),
37 m_items(this),
@@ -93,12 +94,12 void ScatterChartItem::deletePoints(int count)
93
94
94 void ScatterChartItem::markerSelected(QGraphicsItem *marker)
95 void ScatterChartItem::markerSelected(QGraphicsItem *marker)
95 {
96 {
96 emit XYChart::clicked(domain()->calculateDomainPoint(m_markerMap[marker]));
97 emit XYChart::clicked(m_markerMap[marker]);
97 }
98 }
98
99
99 void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state)
100 void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state)
100 {
101 {
101 emit XYChart::hovered(domain()->calculateDomainPoint(m_markerMap[marker]), state);
102 emit XYChart::hovered(m_markerMap[marker], state);
102 }
103 }
103
104
104 void ScatterChartItem::updateGeometry()
105 void ScatterChartItem::updateGeometry()
@@ -125,13 +126,16 void ScatterChartItem::updateGeometry()
125
126
126 QRectF clipRect(QPointF(0,0),domain()->size());
127 QRectF clipRect(QPointF(0,0),domain()->size());
127
128
129 QVector<bool> offGridStatus = offGridStatusVector();
130
128 for (int i = 0; i < points.size(); i++) {
131 for (int i = 0; i < points.size(); i++) {
129 QGraphicsItem *item = items.at(i);
132 QGraphicsItem *item = items.at(i);
130 const QPointF &point = points.at(i);
133 const QPointF &point = points.at(i);
131 const QRectF &rect = item->boundingRect();
134 const QRectF &rect = item->boundingRect();
132 m_markerMap[item] = point;
135 m_markerMap[item] = m_series->pointAt(i);
133 item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2);
136 item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2);
134 if (!m_visible || !clipRect.contains(point))
137
138 if (!m_visible || offGridStatus.at(i))
135 item->setVisible(false);
139 item->setVisible(false);
136 else
140 else
137 item->setVisible(true);
141 item->setVisible(true);
@@ -44,7 +44,7 class ScatterChartItem : public XYChart
44 Q_OBJECT
44 Q_OBJECT
45 Q_INTERFACES(QGraphicsItem)
45 Q_INTERFACES(QGraphicsItem)
46 public:
46 public:
47 explicit ScatterChartItem(QScatterSeries *series, QGraphicsItem* item = 0);
47 explicit ScatterChartItem(QScatterSeries *series, QGraphicsItem *item = 0);
48
48
49 public:
49 public:
50 //from QGraphicsItem
50 //from QGraphicsItem
@@ -22,13 +22,13
22 #include "qsplineseries_p.h"
22 #include "qsplineseries_p.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "splineanimation_p.h"
24 #include "splineanimation_p.h"
25 #include "abstractdomain_p.h"
25 #include "polardomain_p.h"
26 #include <QPainter>
26 #include <QPainter>
27 #include <QGraphicsSceneMouseEvent>
27 #include <QGraphicsSceneMouseEvent>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem* item)
31 SplineChartItem::SplineChartItem(QSplineSeries *series, QGraphicsItem *item)
32 : XYChart(series,item),
32 : XYChart(series,item),
33 m_series(series),
33 m_series(series),
34 m_pointsVisible(false),
34 m_pointsVisible(false),
@@ -49,8 +49,7 QRectF SplineChartItem::boundingRect() const
49
49
50 QPainterPath SplineChartItem::shape() const
50 QPainterPath SplineChartItem::shape() const
51 {
51 {
52 QPainterPathStroker stroker;
52 return m_fullPath;
53 return stroker.createStroke(m_path);
54 }
53 }
55
54
56 void SplineChartItem::setAnimation(SplineAnimation *animation)
55 void SplineChartItem::setAnimation(SplineAnimation *animation)
@@ -107,20 +106,179 void SplineChartItem::updateGeometry()
107
106
108 Q_ASSERT(points.count() * 2 - 2 == controlPoints.count());
107 Q_ASSERT(points.count() * 2 - 2 == controlPoints.count());
109
108
110 QPainterPath splinePath(points.at(0));
109 QPainterPath splinePath;
110 QPainterPath fullPath;
111 // Use worst case scenario to determine required margin.
112 qreal margin = m_linePen.width() * 1.42;
113
114 if (m_series->chart()->chartType() == QChart::ChartTypePolar) {
115 QPainterPath splinePathLeft;
116 QPainterPath splinePathRight;
117 QPainterPath *currentSegmentPath = 0;
118 QPainterPath *previousSegmentPath = 0;
119 qreal minX = domain()->minX();
120 qreal maxX = domain()->maxX();
121 qreal minY = domain()->minY();
122 QPointF currentSeriesPoint = m_series->pointAt(0);
123 QPointF currentGeometryPoint = points.at(0);
124 QPointF previousGeometryPoint = points.at(0);
125 bool pointOffGrid = false;
126 bool previousPointWasOffGrid = (currentSeriesPoint.x() < minX || currentSeriesPoint.x() > maxX);
127 m_visiblePoints.clear();
128 m_visiblePoints.reserve(points.size());
129
130 qreal domainRadius = domain()->size().height() / 2.0;
131 const QPointF centerPoint(domainRadius, domainRadius);
132
133 if (!previousPointWasOffGrid) {
134 fullPath.moveTo(points.at(0));
135 // Do not draw points for points below minimum Y.
136 if (m_pointsVisible && currentSeriesPoint.y() >= minY)
137 m_visiblePoints.append(currentGeometryPoint);
138 }
139
140 qreal leftMarginLine = centerPoint.x() - margin;
141 qreal rightMarginLine = centerPoint.x() + margin;
142 qreal horizontal = centerPoint.y();
143
144 for (int i = 1; i < points.size(); i++) {
145 // Interpolating spline fragments accurately is not trivial, and would anyway be ugly
146 // when thick pen is used, so we work around it by utilizing three separate
147 // paths for spline segments and clip those with custom regions at paint time.
148 // "Right" path contains segments that cross the axis line with visible point on the
149 // right side of the axis line, as well as segments that have one point within the margin
150 // on the right side of the axis line and another point on the right side of the chart.
151 // "Left" path contains points with similarly on the left side.
152 // "Full" path contains rest of the points.
153 // This doesn't yield perfect results always. E.g. when segment covers more than 90
154 // degrees and both of the points are within the margin, one in the top half and one in the
155 // bottom half of the chart, the bottom one gets clipped incorrectly.
156 // However, this should be rare occurrence in any sensible chart.
157 currentSeriesPoint = m_series->pointAt(i);
158 currentGeometryPoint = points.at(i);
159 pointOffGrid = (currentSeriesPoint.x() < minX || currentSeriesPoint.x() > maxX);
160
161 // Draw something unless both off-grid
162 if (!pointOffGrid || !previousPointWasOffGrid) {
163 bool dummyOk; // We know points are ok, but this is needed
164 qreal currentAngle = static_cast<PolarDomain *>(domain())->toAngularCoordinate(currentSeriesPoint.x(), dummyOk);
165 qreal previousAngle = static_cast<PolarDomain *>(domain())->toAngularCoordinate(m_series->pointAt(i - 1).x(), dummyOk);
166
167 if ((qAbs(currentAngle - previousAngle) > 180.0)) {
168 // If the angle between two points is over 180 degrees (half X range),
169 // any direct segment between them becomes meaningless.
170 // In this case two line segments are drawn instead, from previous
171 // point to the center and from center to current point.
172 if ((previousAngle < 0.0 || (previousAngle <= 180.0 && previousGeometryPoint.x() < rightMarginLine))
173 && previousGeometryPoint.y() < horizontal) {
174 currentSegmentPath = &splinePathRight;
175 } else if ((previousAngle > 360.0 || (previousAngle > 180.0 && previousGeometryPoint.x() > leftMarginLine))
176 && previousGeometryPoint.y() < horizontal) {
177 currentSegmentPath = &splinePathLeft;
178 } else if (previousAngle > 0.0 && previousAngle < 360.0) {
179 currentSegmentPath = &splinePath;
180 } else {
181 currentSegmentPath = 0;
182 }
183
184 if (currentSegmentPath) {
185 if (previousSegmentPath != currentSegmentPath)
186 currentSegmentPath->moveTo(previousGeometryPoint);
187 if (!previousSegmentPath)
188 fullPath.moveTo(previousGeometryPoint);
189
190 currentSegmentPath->lineTo(centerPoint);
191 fullPath.lineTo(centerPoint);
192 }
193
194 previousSegmentPath = currentSegmentPath;
195
196 if ((currentAngle < 0.0 || (currentAngle <= 180.0 && currentGeometryPoint.x() < rightMarginLine))
197 && currentGeometryPoint.y() < horizontal) {
198 currentSegmentPath = &splinePathRight;
199 } else if ((currentAngle > 360.0 || (currentAngle > 180.0 &&currentGeometryPoint.x() > leftMarginLine))
200 && currentGeometryPoint.y() < horizontal) {
201 currentSegmentPath = &splinePathLeft;
202 } else if (currentAngle > 0.0 && currentAngle < 360.0) {
203 currentSegmentPath = &splinePath;
204 } else {
205 currentSegmentPath = 0;
206 }
207
208 if (currentSegmentPath) {
209 if (previousSegmentPath != currentSegmentPath)
210 currentSegmentPath->moveTo(centerPoint);
211 if (!previousSegmentPath)
212 fullPath.moveTo(centerPoint);
213
214 currentSegmentPath->lineTo(currentGeometryPoint);
215 fullPath.lineTo(currentGeometryPoint);
216 }
217 } else {
218 QPointF cp1 = controlPoints[2 * (i - 1)];
219 QPointF cp2 = controlPoints[(2 * i) - 1];
220
221 if (previousAngle < 0.0 || currentAngle < 0.0
222 || ((previousAngle <= 180.0 && currentAngle <= 180.0)
223 && ((previousGeometryPoint.x() < rightMarginLine && previousGeometryPoint.y() < horizontal)
224 || (currentGeometryPoint.x() < rightMarginLine && currentGeometryPoint.y() < horizontal)))) {
225 currentSegmentPath = &splinePathRight;
226 } else if (previousAngle > 360.0 || currentAngle > 360.0
227 || ((previousAngle > 180.0 && currentAngle > 180.0)
228 && ((previousGeometryPoint.x() > leftMarginLine && previousGeometryPoint.y() < horizontal)
229 || (currentGeometryPoint.x() > leftMarginLine && currentGeometryPoint.y() < horizontal)))) {
230 currentSegmentPath = &splinePathLeft;
231 } else {
232 currentSegmentPath = &splinePath;
233 }
234
235 if (currentSegmentPath != previousSegmentPath)
236 currentSegmentPath->moveTo(previousGeometryPoint);
237 if (!previousSegmentPath)
238 fullPath.moveTo(previousGeometryPoint);
239
240 fullPath.cubicTo(cp1, cp2, currentGeometryPoint);
241 currentSegmentPath->cubicTo(cp1, cp2, currentGeometryPoint);
242 }
243 } else {
244 currentSegmentPath = 0;
245 }
246
247 previousPointWasOffGrid = pointOffGrid;
248 if (!pointOffGrid && m_pointsVisible && currentSeriesPoint.y() >= minY)
249 m_visiblePoints.append(currentGeometryPoint);
250 previousSegmentPath = currentSegmentPath;
251 previousGeometryPoint = currentGeometryPoint;
252 }
111
253
112 for (int i = 0; i < points.size() - 1; i++) {
254 m_pathPolarRight = splinePathRight;
113 const QPointF &point = points.at(i + 1);
255 m_pathPolarLeft = splinePathLeft;
114 splinePath.cubicTo(controlPoints[2 * i], controlPoints[2 * i + 1], point);
256 // Note: This construction of m_fullpath is not perfect. The partial segments that are
257 // outside left/right clip regions at axis boundary still generate hover/click events,
258 // because shape doesn't get clipped. It doesn't seem possible to do sensibly.
259 } else { // not polar
260 splinePath.moveTo(points.at(0));
261 for (int i = 0; i < points.size() - 1; i++) {
262 const QPointF &point = points.at(i + 1);
263 splinePath.cubicTo(controlPoints[2 * i], controlPoints[2 * i + 1], point);
264 }
265 fullPath = splinePath;
115 }
266 }
267 m_path = splinePath;
268
269 QPainterPathStroker stroker;
270 // The full path is comprised of three separate paths.
271 // This is why we are prepared for the "worst case" scenario, i.e. use always MiterJoin and
272 // multiply line width with square root of two when defining shape and bounding rectangle.
273 stroker.setWidth(margin);
274 stroker.setJoinStyle(Qt::MiterJoin);
275 stroker.setCapStyle(Qt::SquareCap);
276 stroker.setMiterLimit(m_linePen.miterLimit());
116
277
117 prepareGeometryChange();
278 prepareGeometryChange();
118 // QPainterPathStroker stroker;
119 // stroker.setWidth(m_linePen.width() / 2.0);
120 // m_path = stroker.createStroke(splinePath);
121 m_path = splinePath;
122 m_rect = splinePath.boundingRect();
123
279
280 m_fullPath = stroker.createStroke(fullPath);
281 m_rect = m_fullPath.boundingRect();
124 }
282 }
125
283
126 /*!
284 /*!
@@ -240,16 +398,38 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
240 Q_UNUSED(widget)
398 Q_UNUSED(widget)
241 Q_UNUSED(option)
399 Q_UNUSED(option)
242
400
401 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
402
243 painter->save();
403 painter->save();
244 painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
245 painter->setPen(m_linePen);
404 painter->setPen(m_linePen);
246 // painter->setBrush(m_linePen.color());
405 painter->setBrush(Qt::NoBrush);
406
407 if (m_series->chart()->chartType() == QChart::ChartTypePolar) {
408 qreal halfWidth = domain()->size().width() / 2.0;
409 QRectF clipRectLeft = QRectF(0, 0, halfWidth, domain()->size().height());
410 QRectF clipRectRight = QRectF(halfWidth, 0, halfWidth, domain()->size().height());
411 QRegion fullPolarClipRegion(clipRect.toRect(), QRegion::Ellipse);
412 QRegion clipRegionLeft(fullPolarClipRegion.intersected(clipRectLeft.toRect()));
413 QRegion clipRegionRight(fullPolarClipRegion.intersected(clipRectRight.toRect()));
414 painter->setClipRegion(clipRegionLeft);
415 painter->drawPath(m_pathPolarLeft);
416 painter->setClipRegion(clipRegionRight);
417 painter->drawPath(m_pathPolarRight);
418 painter->setClipRegion(fullPolarClipRegion);
419 } else {
420 painter->setClipRect(clipRect);
421 }
247
422
248 painter->drawPath(m_path);
423 painter->drawPath(m_path);
424
249 if (m_pointsVisible) {
425 if (m_pointsVisible) {
250 painter->setPen(m_pointPen);
426 painter->setPen(m_pointPen);
251 painter->drawPoints(geometryPoints());
427 if (m_series->chart()->chartType() == QChart::ChartTypePolar)
428 painter->drawPoints(m_visiblePoints);
429 else
430 painter->drawPoints(geometryPoints());
252 }
431 }
432
253 painter->restore();
433 painter->restore();
254 }
434 }
255
435
@@ -42,7 +42,7 class SplineChartItem : public XYChart
42 Q_OBJECT
42 Q_OBJECT
43 Q_INTERFACES(QGraphicsItem)
43 Q_INTERFACES(QGraphicsItem)
44 public:
44 public:
45 SplineChartItem(QSplineSeries *series, QGraphicsItem* item = 0);
45 SplineChartItem(QSplineSeries *series, QGraphicsItem *item = 0);
46
46
47 //from QGraphicsItem
47 //from QGraphicsItem
48 QRectF boundingRect() const;
48 QRectF boundingRect() const;
@@ -70,11 +70,15 protected:
70 private:
70 private:
71 QSplineSeries *m_series;
71 QSplineSeries *m_series;
72 QPainterPath m_path;
72 QPainterPath m_path;
73 QPainterPath m_pathPolarRight;
74 QPainterPath m_pathPolarLeft;
75 QPainterPath m_fullPath;
73 QRectF m_rect;
76 QRectF m_rect;
74 QPen m_linePen;
77 QPen m_linePen;
75 QPen m_pointPen;
78 QPen m_pointPen;
76 bool m_pointsVisible;
79 bool m_pointsVisible;
77 QVector<QPointF> m_controlPoints;
80 QVector<QPointF> m_controlPoints;
81 QVector<QPointF> m_visiblePoints;
78 SplineAnimation *m_animation;
82 SplineAnimation *m_animation;
79
83
80 friend class SplineAnimation;
84 friend class SplineAnimation;
@@ -39,8 +39,8 SOURCES += \
39 $$PWD/chartelement.cpp \
39 $$PWD/chartelement.cpp \
40 $$PWD/chartitem.cpp \
40 $$PWD/chartitem.cpp \
41 $$PWD/scroller.cpp \
41 $$PWD/scroller.cpp \
42 $$PWD/chartlayout.cpp \
42 $$PWD/charttitle.cpp \
43 $$PWD/charttitle.cpp
43 $$PWD/qpolarchart.cpp
44 PRIVATE_HEADERS += \
44 PRIVATE_HEADERS += \
45 $$PWD/chartdataset_p.h \
45 $$PWD/chartdataset_p.h \
46 $$PWD/chartitem_p.h \
46 $$PWD/chartitem_p.h \
@@ -53,7 +53,6 PRIVATE_HEADERS += \
53 $$PWD/qchartview_p.h \
53 $$PWD/qchartview_p.h \
54 $$PWD/scroller_p.h \
54 $$PWD/scroller_p.h \
55 $$PWD/qabstractseries_p.h \
55 $$PWD/qabstractseries_p.h \
56 $$PWD/chartlayout_p.h \
57 $$PWD/charttitle_p.h \
56 $$PWD/charttitle_p.h \
58 $$PWD/charthelpers_p.h
57 $$PWD/charthelpers_p.h
59 PUBLIC_HEADERS += \
58 PUBLIC_HEADERS += \
@@ -61,7 +60,8 PUBLIC_HEADERS += \
61 $$PWD/qchartglobal.h \
60 $$PWD/qchartglobal.h \
62 $$PWD/qabstractseries.h \
61 $$PWD/qabstractseries.h \
63 $$PWD/qchartview.h \
62 $$PWD/qchartview.h \
64 $$PWD/chartsnamespace.h
63 $$PWD/chartsnamespace.h \
64 $$PWD/qpolarchart.h
65
65
66 include(animations/animations.pri)
66 include(animations/animations.pri)
67 include(areachart/areachart.pri)
67 include(areachart/areachart.pri)
@@ -75,6 +75,7 include(scatterchart/scatter.pri)
75 include(splinechart/splinechart.pri)
75 include(splinechart/splinechart.pri)
76 include(themes/themes.pri)
76 include(themes/themes.pri)
77 include(xychart/xychart.pri)
77 include(xychart/xychart.pri)
78 include(layout/layout.pri)
78
79
79 HEADERS += $$PUBLIC_HEADERS
80 HEADERS += $$PUBLIC_HEADERS
80 HEADERS += $$PRIVATE_HEADERS
81 HEADERS += $$PRIVATE_HEADERS
@@ -69,6 +69,18 QTCOMMERCIALCHART_BEGIN_NAMESPACE
69 */
69 */
70
70
71 /*!
71 /*!
72 \qmlproperty AbstractAxis XYSeries::axisAngular
73 The angular axis used for the series, drawn around the polar chart view.
74 \sa axisX
75 */
76
77 /*!
78 \qmlproperty AbstractAxis XYSeries::axisRadial
79 The radial axis used for the series, drawn inside the polar chart view.
80 \sa axisY
81 */
82
83 /*!
72 \property QXYSeries::pointsVisible
84 \property QXYSeries::pointsVisible
73 Controls if the data points are visible and should be drawn.
85 Controls if the data points are visible and should be drawn.
74 */
86 */
@@ -354,6 +366,15 QList<QPointF> QXYSeries::points() const
354 }
366 }
355
367
356 /*!
368 /*!
369 Returns point at \a index in internal points vector.
370 */
371 const QPointF &QXYSeries::pointAt(int index) const
372 {
373 Q_D(const QXYSeries);
374 return d->m_points.at(index);
375 }
376
377 /*!
357 Returns number of data points within series.
378 Returns number of data points within series.
358 */
379 */
359 int QXYSeries::count() const
380 int QXYSeries::count() const
@@ -56,6 +56,7 public:
56
56
57 int count() const;
57 int count() const;
58 QList<QPointF> points() const;
58 QList<QPointF> points() const;
59 const QPointF &pointAt(int index) const;
59
60
60 QXYSeries &operator << (const QPointF &point);
61 QXYSeries &operator << (const QPointF &point);
61 QXYSeries &operator << (const QList<QPointF> &points);
62 QXYSeries &operator << (const QList<QPointF> &points);
@@ -24,6 +24,7
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "qxymodelmapper.h"
26 #include "qxymodelmapper.h"
27 #include "qabstractaxis_p.h"
27 #include <QPainter>
28 #include <QPainter>
28 #include <QAbstractItemModel>
29 #include <QAbstractItemModel>
29
30
@@ -32,7 +33,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
33
33 //TODO: optimize : remove points which are not visible
34 //TODO: optimize : remove points which are not visible
34
35
35 XYChart::XYChart(QXYSeries *series,QGraphicsItem* item):
36 XYChart::XYChart(QXYSeries *series, QGraphicsItem *item):
36 ChartItem(series->d_func(),item),
37 ChartItem(series->d_func(),item),
37 m_series(series),
38 m_series(series),
38 m_animation(0),
39 m_animation(0),
@@ -46,7 +47,7 XYChart::XYChart(QXYSeries *series,QGraphicsItem* item):
46 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool)));
47 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool)));
47 }
48 }
48
49
49 void XYChart::setGeometryPoints(const QVector<QPointF>& points)
50 void XYChart::setGeometryPoints(const QVector<QPointF> &points)
50 {
51 {
51 m_points = points;
52 m_points = points;
52 }
53 }
@@ -61,6 +62,32 void XYChart::setDirty(bool dirty)
61 m_dirty = dirty;
62 m_dirty = dirty;
62 }
63 }
63
64
65 // Returns a vector with same size as geometryPoints vector, indicating
66 // the off grid status of points.
67 QVector<bool> XYChart::offGridStatusVector()
68 {
69 qreal minX = domain()->minX();
70 qreal maxX = domain()->maxX();
71 qreal minY = domain()->minY();
72 qreal maxY = domain()->maxY();
73
74 QVector<bool> returnVector;
75 returnVector.resize(m_points.size());
76
77 for (int i = 0; i < m_points.size(); i++) {
78 const QPointF &seriesPoint = m_series->pointAt(i);
79 if (seriesPoint.x() < minX
80 || seriesPoint.x() > maxX
81 || seriesPoint.y() < minY
82 || seriesPoint.y() > maxY) {
83 returnVector[i] = true;
84 } else {
85 returnVector[i] = false;
86 }
87 }
88 return returnVector;
89 }
90
64 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
91 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
65 {
92 {
66
93
@@ -45,10 +45,10 class XYChart : public ChartItem
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48 explicit XYChart(QXYSeries *series,QGraphicsItem* item = 0);
48 explicit XYChart(QXYSeries *series,QGraphicsItem *item = 0);
49 ~XYChart() {}
49 ~XYChart() {}
50
50
51 void setGeometryPoints(const QVector<QPointF>& points);
51 void setGeometryPoints(const QVector<QPointF> &points);
52 QVector<QPointF> geometryPoints() const { return m_points; }
52 QVector<QPointF> geometryPoints() const { return m_points; }
53
53
54 void setAnimation(XYAnimation *animation);
54 void setAnimation(XYAnimation *animation);
@@ -58,6 +58,9 public:
58 bool isDirty() const { return m_dirty; }
58 bool isDirty() const { return m_dirty; }
59 void setDirty(bool dirty);
59 void setDirty(bool dirty);
60
60
61 void getSeriesRanges(qreal &minX, qreal &maxX, qreal &minY, qreal &maxY);
62 QVector<bool> offGridStatusVector();
63
61 public Q_SLOTS:
64 public Q_SLOTS:
62 void handlePointAdded(int index);
65 void handlePointAdded(int index);
63 void handlePointRemoved(int index);
66 void handlePointRemoved(int index);
@@ -21,6 +21,7
21 #ifndef TST_DEFINITIONS_H
21 #ifndef TST_DEFINITIONS_H
22 #define TST_DEFINITIONS_H
22 #define TST_DEFINITIONS_H
23
23
24 #include "qpolarchart.h"
24 #include <QtTest/QtTest>
25 #include <QtTest/QtTest>
25 #include <QPushButton>
26 #include <QPushButton>
26
27
@@ -63,6 +64,16 namespace QTest
63 QSKIP("Cannot test mouse events in this environment"); \
64 QSKIP("Cannot test mouse events in this environment"); \
64 } while (0); \
65 } while (0); \
65 }
66 }
67
68 #define SKIP_ON_POLAR() { \
69 if (isPolarTest()) \
70 QSKIP("Test not supported by polar chart"); \
71 }
72
73 #define SKIP_ON_CARTESIAN() { \
74 if (!isPolarTest()) \
75 QSKIP("Test not supported by cartesian chart"); \
76 }
66 #else
77 #else
67 #define SKIP_IF_CANNOT_TEST_MOUSE_EVENTS() { \
78 #define SKIP_IF_CANNOT_TEST_MOUSE_EVENTS() { \
68 do { \
79 do { \
@@ -76,6 +87,39 namespace QTest
76 QSKIP("Cannot test mouse events in this environment", SkipAll); \
87 QSKIP("Cannot test mouse events in this environment", SkipAll); \
77 } while (0); \
88 } while (0); \
78 }
89 }
90
91 #define SKIP_ON_POLAR() { \
92 if (isPolarTest()) \
93 QSKIP("Test not supported by polar chart", SkipAll); \
94 }
95
96 #define SKIP_ON_CARTESIAN() { \
97 if (!isPolarTest()) \
98 QSKIP("Test not supported by cartesian chart", SkipAll); \
99 }
79 #endif
100 #endif
80
101
102 static inline bool isPolarTest()
103 {
104 static bool isPolar = false;
105 static bool polarEnvChecked = false;
106 if (!polarEnvChecked) {
107 isPolar = !(qgetenv("TEST_POLAR_CHART").isEmpty());
108 polarEnvChecked = true;
109 if (isPolar)
110 qDebug() << "TEST_POLAR_CHART found -> Testing polar chart!";
111 }
112 return isPolar;
113 }
114
115 static inline QtCommercialChart::QChart *newQChartOrQPolarChart()
116 {
117 if (isPolarTest())
118 return new QtCommercialChart::QPolarChart();
119 else
120 return new QtCommercialChart::QChart();
121 }
122
123
124
81 #endif // TST_DEFINITIONS_H
125 #endif // TST_DEFINITIONS_H
@@ -35,7 +35,7 void tst_QAbstractAxis::init(QAbstractAxis* axis, QAbstractSeries* series)
35 {
35 {
36 m_axis = axis;
36 m_axis = axis;
37 m_series = series;
37 m_series = series;
38 m_view = new QChartView(new QChart());
38 m_view = new QChartView(newQChartOrQPolarChart());
39 m_chart = m_view->chart();
39 m_chart = m_view->chart();
40 }
40 }
41
41
@@ -101,6 +101,7 private slots:
101 void zoomOut();
101 void zoomOut();
102 void createDefaultAxesForLineSeries_data();
102 void createDefaultAxesForLineSeries_data();
103 void createDefaultAxesForLineSeries();
103 void createDefaultAxesForLineSeries();
104 void axisPolarOrientation();
104 private:
105 private:
105 void createTestData();
106 void createTestData();
106
107
@@ -121,7 +122,7 void tst_QChart::cleanupTestCase()
121
122
122 void tst_QChart::init()
123 void tst_QChart::init()
123 {
124 {
124 m_view = new QChartView(new QChart());
125 m_view = new QChartView(newQChartOrQPolarChart());
125 m_chart = m_view->chart();
126 m_chart = m_view->chart();
126 }
127 }
127
128
@@ -191,20 +192,22 void tst_QChart::addSeries_data()
191 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
192 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
192 QAbstractSeries* scatter = new QScatterSeries(this);
193 QAbstractSeries* scatter = new QScatterSeries(this);
193 QAbstractSeries* spline = new QSplineSeries(this);
194 QAbstractSeries* spline = new QSplineSeries(this);
194 QAbstractSeries* pie = new QPieSeries(this);
195 QAbstractSeries* bar = new QBarSeries(this);
196 QAbstractSeries* percent = new QPercentBarSeries(this);
197 QAbstractSeries* stacked = new QStackedBarSeries(this);
198
195
199 QTest::newRow("lineSeries") << line;
196 QTest::newRow("lineSeries") << line;
200 QTest::newRow("areaSeries") << area;
197 QTest::newRow("areaSeries") << area;
201 QTest::newRow("scatterSeries") << scatter;
198 QTest::newRow("scatterSeries") << scatter;
202 QTest::newRow("splineSeries") << spline;
199 QTest::newRow("splineSeries") << spline;
203 QTest::newRow("pieSeries") << pie;
204 QTest::newRow("barSeries") << bar;
205 QTest::newRow("percentBarSeries") << percent;
206 QTest::newRow("stackedBarSeries") << stacked;
207
200
201 if (!isPolarTest()) {
202 QAbstractSeries* pie = new QPieSeries(this);
203 QAbstractSeries* bar = new QBarSeries(this);
204 QAbstractSeries* percent = new QPercentBarSeries(this);
205 QAbstractSeries* stacked = new QStackedBarSeries(this);
206 QTest::newRow("pieSeries") << pie;
207 QTest::newRow("barSeries") << bar;
208 QTest::newRow("percentBarSeries") << percent;
209 QTest::newRow("stackedBarSeries") << stacked;
210 }
208 }
211 }
209
212
210 void tst_QChart::addSeries()
213 void tst_QChart::addSeries()
@@ -258,20 +261,23 void tst_QChart::axisX_data()
258 QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
261 QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
259 QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this);
262 QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this);
260 QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this);
263 QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this);
261 QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this);
264 if (!isPolarTest()) {
262 QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this);
265 QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this);
263 QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
266 QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this);
264 QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
267 QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
268 QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
269 }
265
270
266 QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this);
271 QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this);
267 QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
272 QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
268 QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this);
273 QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this);
269 QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this);
274 QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this);
270 QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this);
275 if (!isPolarTest()) {
271 QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this);
276 QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this);
272 QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
277 QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this);
273 QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
278 QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
274
279 QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
280 }
275 }
281 }
276
282
277 void tst_QChart::axisX()
283 void tst_QChart::axisX()
@@ -850,14 +856,14 void tst_QChart::createDefaultAxesForLineSeries()
850 series2->append(series2minX, series2minY);
856 series2->append(series2minX, series2minY);
851 series2->append(series2midX, series2midY);
857 series2->append(series2midX, series2midY);
852 series2->append(series2maxX, series2maxY);
858 series2->append(series2maxX, series2maxY);
853 QChart chart;
859 QChart *chart = newQChartOrQPolarChart();
854 chart.addSeries(series1);
860 chart->addSeries(series1);
855 chart.addSeries(series2);
861 chart->addSeries(series2);
856 chart.createDefaultAxes();
862 chart->createDefaultAxes();
857 QValueAxis *xAxis = (QValueAxis *)chart.axisX();
863 QValueAxis *xAxis = (QValueAxis *)chart->axisX();
858 QCOMPARE(xAxis->min(), overallminX);
864 QCOMPARE(xAxis->min(), overallminX);
859 QCOMPARE(xAxis->max(), overallmaxX);
865 QCOMPARE(xAxis->max(), overallmaxX);
860 QValueAxis *yAxis = (QValueAxis *)chart.axisY();
866 QValueAxis *yAxis = (QValueAxis *)chart->axisY();
861 QCOMPARE(yAxis->min(), overallminY);
867 QCOMPARE(yAxis->min(), overallminY);
862 QCOMPARE(yAxis->max(), overallmaxY);
868 QCOMPARE(yAxis->max(), overallmaxY);
863 QLineSeries *series3 = new QLineSeries(this);
869 QLineSeries *series3 = new QLineSeries(this);
@@ -865,12 +871,37 void tst_QChart::createDefaultAxesForLineSeries()
865 series3->append(0, 0);
871 series3->append(0, 0);
866 series3->append(100, 100);
872 series3->append(100, 100);
867 // Adding a new series should not change the axes as they have not been told to update
873 // Adding a new series should not change the axes as they have not been told to update
868 chart.addSeries(series3);
874 chart->addSeries(series3);
869 QCOMPARE(xAxis->min(), overallminX);
875 QCOMPARE(xAxis->min(), overallminX);
870 QCOMPARE(xAxis->max(), overallmaxX);
876 QCOMPARE(xAxis->max(), overallmaxX);
871 QCOMPARE(yAxis->min(), overallminY);
877 QCOMPARE(yAxis->min(), overallminY);
872 QCOMPARE(yAxis->max(), overallmaxY);
878 QCOMPARE(yAxis->max(), overallmaxY);
879 }
880
881 void tst_QChart::axisPolarOrientation()
882 {
883 QLineSeries* series1 = new QLineSeries(this);
884 series1->append(1, 2);
885 series1->append(2, 4);
886 series1->append(3, 8);
887 QPolarChart chart;
888 chart.addSeries(series1);
889
890 QValueAxis *xAxis = new QValueAxis();
891 QValueAxis *yAxis = new QValueAxis();
892 chart.addAxis(xAxis, QPolarChart::PolarOrientationAngular);
893 chart.addAxis(yAxis, QPolarChart::PolarOrientationRadial);
894
895 QList<QAbstractAxis *> xAxes = chart.axes(QPolarChart::PolarOrientationAngular);
896 QList<QAbstractAxis *> yAxes = chart.axes(QPolarChart::PolarOrientationRadial);
897
898 QCOMPARE(xAxes.size(), 1);
899 QCOMPARE(yAxes.size(), 1);
900 QCOMPARE(xAxes[0], xAxis);
901 QCOMPARE(yAxes[0], yAxis);
873
902
903 QCOMPARE(chart.axisPolarOrientation(xAxes[0]), QPolarChart::PolarOrientationAngular);
904 QCOMPARE(chart.axisPolarOrientation(yAxes[0]), QPolarChart::PolarOrientationRadial);
874 }
905 }
875
906
876 QTEST_MAIN(tst_QChart)
907 QTEST_MAIN(tst_QChart)
@@ -67,7 +67,7 void tst_QChartView::cleanupTestCase()
67
67
68 void tst_QChartView::init()
68 void tst_QChartView::init()
69 {
69 {
70 m_view = new QChartView(new QChart());
70 m_view = new QChartView(newQChartOrQPolarChart());
71 m_view->chart()->legend()->setVisible(false);
71 m_view->chart()->legend()->setVisible(false);
72 }
72 }
73
73
@@ -120,9 +120,15 void tst_QChartView::rubberBand_data()
120 QTest::addColumn<QPoint>("min");
120 QTest::addColumn<QPoint>("min");
121 QTest::addColumn<QPoint>("max");
121 QTest::addColumn<QPoint>("max");
122
122
123 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << QPoint(5,5) << QPoint(5,5);
123 if (isPolarTest()) {
124 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << QPoint(5,5) << QPoint(5,5);
124 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 0 << QPoint(5,5) << QPoint(5,5);
125 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 << QPoint(5,5) << QPoint(5,5);
125 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 0 << 0 << QPoint(5,5) << QPoint(5,5);
126 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 0 << 0 << QPoint(5,5) << QPoint(5,5);
127 } else {
128 QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << QPoint(5,5) << QPoint(5,5);
129 QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << QPoint(5,5) << QPoint(5,5);
130 QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 << QPoint(5,5) << QPoint(5,5);
131 }
126 }
132 }
127
133
128 void tst_QChartView::rubberBand()
134 void tst_QChartView::rubberBand()
@@ -194,7 +200,8 void tst_QChartView::setChart()
194 series1->append(1,1);
200 series1->append(1,1);
195 oldChart->addSeries(series1);
201 oldChart->addSeries(series1);
196
202
197 QPointer<QChart> newChart = new QChart();
203 QPointer<QChart> newChart = newQChartOrQPolarChart();
204
198 QLineSeries *series2 = new QLineSeries();
205 QLineSeries *series2 = new QLineSeries();
199 series2->append(0,1);
206 series2->append(0,1);
200 series2->append(1,0);
207 series2->append(1,0);
@@ -63,7 +63,6 private slots:
63 private:
63 private:
64
64
65 QChart *m_chart;
65 QChart *m_chart;
66
67 };
66 };
68
67
69 void tst_QLegend::initTestCase()
68 void tst_QLegend::initTestCase()
@@ -76,7 +75,7 void tst_QLegend::cleanupTestCase()
76
75
77 void tst_QLegend::init()
76 void tst_QLegend::init()
78 {
77 {
79 m_chart = new QChart();
78 m_chart = newQChartOrQPolarChart();
80 }
79 }
81
80
82 void tst_QLegend::cleanup()
81 void tst_QLegend::cleanup()
@@ -98,6 +97,8 void tst_QLegend::qlegend()
98
97
99 void tst_QLegend::qpieLegendMarker()
98 void tst_QLegend::qpieLegendMarker()
100 {
99 {
100 SKIP_ON_POLAR();
101
101 QVERIFY(m_chart);
102 QVERIFY(m_chart);
102 QLegend *legend = m_chart->legend();
103 QLegend *legend = m_chart->legend();
103
104
@@ -190,6 +191,8 void tst_QLegend::qxyLegendMarker()
190
191
191 void tst_QLegend::qbarLegendMarker()
192 void tst_QLegend::qbarLegendMarker()
192 {
193 {
194 SKIP_ON_POLAR();
195
193 QVERIFY(m_chart);
196 QVERIFY(m_chart);
194 QLegend *legend = m_chart->legend();
197 QLegend *legend = m_chart->legend();
195
198
@@ -230,6 +233,8 void tst_QLegend::qbarLegendMarker()
230
233
231 void tst_QLegend::markers()
234 void tst_QLegend::markers()
232 {
235 {
236 SKIP_ON_POLAR();
237
233 QVERIFY(m_chart);
238 QVERIFY(m_chart);
234 QLegend *legend = m_chart->legend();
239 QLegend *legend = m_chart->legend();
235
240
@@ -270,6 +275,8 void tst_QLegend::markers()
270
275
271 void tst_QLegend::addAndRemoveSeries()
276 void tst_QLegend::addAndRemoveSeries()
272 {
277 {
278 SKIP_ON_POLAR();
279
273 QVERIFY(m_chart);
280 QVERIFY(m_chart);
274 QLegend *legend = m_chart->legend();
281 QLegend *legend = m_chart->legend();
275
282
@@ -291,6 +298,8 void tst_QLegend::addAndRemoveSeries()
291
298
292 void tst_QLegend::pieMarkerProperties()
299 void tst_QLegend::pieMarkerProperties()
293 {
300 {
301 SKIP_ON_POLAR();
302
294 QVERIFY(m_chart);
303 QVERIFY(m_chart);
295 QLegend *legend = m_chart->legend();
304 QLegend *legend = m_chart->legend();
296
305
@@ -327,6 +336,8 void tst_QLegend::pieMarkerProperties()
327
336
328 void tst_QLegend::barMarkerProperties()
337 void tst_QLegend::barMarkerProperties()
329 {
338 {
339 SKIP_ON_POLAR();
340
330 QVERIFY(m_chart);
341 QVERIFY(m_chart);
331 QLegend *legend = m_chart->legend();
342 QLegend *legend = m_chart->legend();
332
343
@@ -482,8 +493,10 void tst_QLegend::xyMarkerPropertiesScatter()
482
493
483 void tst_QLegend::markerSignals()
494 void tst_QLegend::markerSignals()
484 {
495 {
496 SKIP_ON_POLAR();
497
485 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
498 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
486 QChart *chart = new QChart();
499 QChart *chart = newQChartOrQPolarChart();
487 QLegend *legend = chart->legend();
500 QLegend *legend = chart->legend();
488
501
489 QBarSeries *bar = new QBarSeries();
502 QBarSeries *bar = new QBarSeries();
@@ -36,7 +36,8 private slots:
36 void checkPlugin();
36 void checkPlugin();
37 private:
37 private:
38 QString componentErrors(const QDeclarativeComponent* component) const;
38 QString componentErrors(const QDeclarativeComponent* component) const;
39 QString imports();
39 QString imports_1_1();
40 QString imports_1_3();
40
41
41 };
42 };
42
43
@@ -53,12 +54,18 QString tst_QML::componentErrors(const QDeclarativeComponent* component) const
53 return errors.join("\n");
54 return errors.join("\n");
54 }
55 }
55
56
56 QString tst_QML::imports()
57 QString tst_QML::imports_1_1()
57 {
58 {
58 return "import QtQuick 1.0 \n"
59 return "import QtQuick 1.0 \n"
59 "import QtCommercial.Chart 1.1 \n";
60 "import QtCommercial.Chart 1.1 \n";
60 }
61 }
61
62
63 QString tst_QML::imports_1_3()
64 {
65 return "import QtQuick 1.0 \n"
66 "import QtCommercial.Chart 1.3 \n";
67 }
68
62
69
63 void tst_QML::initTestCase()
70 void tst_QML::initTestCase()
64 {
71 {
@@ -82,34 +89,37 void tst_QML::checkPlugin_data()
82 {
89 {
83 QTest::addColumn<QString>("source");
90 QTest::addColumn<QString>("source");
84
91
85 QTest::newRow("createChartView") << imports() + "ChartView{}";
92 QTest::newRow("createChartView") << imports_1_1() + "ChartView{}";
86 QTest::newRow("XYPoint") << imports() + "XYPoint{}";
93 QTest::newRow("XYPoint") << imports_1_1() + "XYPoint{}";
87 QTest::newRow("scatterSeries") << imports() + "ScatterSeries{}";
94 QTest::newRow("scatterSeries") << imports_1_1() + "ScatterSeries{}";
88 QTest::newRow("lineSeries") << imports() + "LineSeries{}";
95 QTest::newRow("lineSeries") << imports_1_1() + "LineSeries{}";
89 QTest::newRow("splineSeries") << imports() + "SplineSeries{}";
96 QTest::newRow("splineSeries") << imports_1_1() + "SplineSeries{}";
90 QTest::newRow("areaSeries") << imports() + "AreaSeries{}";
97 QTest::newRow("areaSeries") << imports_1_1() + "AreaSeries{}";
91 QTest::newRow("barSeries") << imports() + "BarSeries{}";
98 QTest::newRow("barSeries") << imports_1_1() + "BarSeries{}";
92 QTest::newRow("stackedBarSeries") << imports() + "StackedBarSeries{}";
99 QTest::newRow("stackedBarSeries") << imports_1_1() + "StackedBarSeries{}";
93 QTest::newRow("precentBarSeries") << imports() + "PercentBarSeries{}";
100 QTest::newRow("precentBarSeries") << imports_1_1() + "PercentBarSeries{}";
94 QTest::newRow("horizonatlBarSeries") << imports() + "HorizontalBarSeries{}";
101 QTest::newRow("horizonatlBarSeries") << imports_1_1() + "HorizontalBarSeries{}";
95 QTest::newRow("horizonatlStackedBarSeries") << imports() + "HorizontalStackedBarSeries{}";
102 QTest::newRow("horizonatlStackedBarSeries") << imports_1_1() + "HorizontalStackedBarSeries{}";
96 QTest::newRow("horizonatlstackedBarSeries") << imports() + "HorizontalPercentBarSeries{}";
103 QTest::newRow("horizonatlstackedBarSeries") << imports_1_1() + "HorizontalPercentBarSeries{}";
97 QTest::newRow("pieSeries") << imports() + "PieSeries{}";
104 QTest::newRow("pieSeries") << imports_1_1() + "PieSeries{}";
98 QTest::newRow("PieSlice") << imports() + "PieSlice{}";
105 QTest::newRow("PieSlice") << imports_1_1() + "PieSlice{}";
99 QTest::newRow("BarSet") << imports() + "BarSet{}";
106 QTest::newRow("BarSet") << imports_1_1() + "BarSet{}";
100 QTest::newRow("HXYModelMapper") << imports() + "HXYModelMapper{}";
107 QTest::newRow("HXYModelMapper") << imports_1_1() + "HXYModelMapper{}";
101 QTest::newRow("VXYModelMapper") << imports() + "VXYModelMapper{}";
108 QTest::newRow("VXYModelMapper") << imports_1_1() + "VXYModelMapper{}";
102 QTest::newRow("HPieModelMapper") << imports() + "HPieModelMapper{}";
109 QTest::newRow("HPieModelMapper") << imports_1_1() + "HPieModelMapper{}";
103 QTest::newRow("HPieModelMapper") << imports() + "HPieModelMapper{}";
110 QTest::newRow("HPieModelMapper") << imports_1_1() + "HPieModelMapper{}";
104 QTest::newRow("HBarModelMapper") << imports() + "HBarModelMapper{}";
111 QTest::newRow("HBarModelMapper") << imports_1_1() + "HBarModelMapper{}";
105 QTest::newRow("VBarModelMapper") << imports() + "VBarModelMapper{}";
112 QTest::newRow("VBarModelMapper") << imports_1_1() + "VBarModelMapper{}";
106 QTest::newRow("ValueAxis") << imports() + "ValueAxis{}";
113 QTest::newRow("ValueAxis") << imports_1_1() + "ValueAxis{}";
107 #ifndef QT_ON_ARM
114 #ifndef QT_ON_ARM
108 QTest::newRow("DateTimeAxis") << imports() + "DateTimeAxis{}";
115 QTest::newRow("DateTimeAxis") << imports_1_1() + "DateTimeAxis{}";
109 #endif
116 #endif
110 QTest::newRow("CategoryAxis") << imports() + "CategoryAxis{}";
117 QTest::newRow("CategoryAxis") << imports_1_1() + "CategoryAxis{}";
111 QTest::newRow("CategoryRange") << imports() + "CategoryRange{}";
118 QTest::newRow("CategoryRange") << imports_1_1() + "CategoryRange{}";
112 QTest::newRow("BarCategoryAxis") << imports() + "BarCategoryAxis{}";
119 QTest::newRow("BarCategoryAxis") << imports_1_1() + "BarCategoryAxis{}";
120
121 QTest::newRow("createPolarChartView") << imports_1_3() + "PolarChartView{}";
122 //QTest::newRow("LogValueAxis") << imports_1_3() + "LogValueAxis{}";
113 }
123 }
114
124
115 void tst_QML::checkPlugin()
125 void tst_QML::checkPlugin()
@@ -28,6 +28,7
28 #include <qvxymodelmapper.h>
28 #include <qvxymodelmapper.h>
29 #include <qhxymodelmapper.h>
29 #include <qhxymodelmapper.h>
30 #include <QStandardItemModel>
30 #include <QStandardItemModel>
31 #include "tst_definitions.h"
31
32
32 QTCOMMERCIALCHART_USE_NAMESPACE
33 QTCOMMERCIALCHART_USE_NAMESPACE
33
34
@@ -145,7 +146,7 void tst_qxymodelmapper::cleanup()
145
146
146 void tst_qxymodelmapper::initTestCase()
147 void tst_qxymodelmapper::initTestCase()
147 {
148 {
148 m_chart = new QChart;
149 m_chart = newQChartOrQPolarChart();
149 QChartView *chartView = new QChartView(m_chart);
150 QChartView *chartView = new QChartView(m_chart);
150 chartView->show();
151 chartView->show();
151 }
152 }
@@ -32,7 +32,7 void tst_QXYSeries::cleanupTestCase()
32
32
33 void tst_QXYSeries::init()
33 void tst_QXYSeries::init()
34 {
34 {
35 m_view = new QChartView(new QChart());
35 m_view = new QChartView(newQChartOrQPolarChart());
36 m_chart = m_view->chart();
36 m_chart = m_view->chart();
37 }
37 }
38
38
@@ -7,7 +7,8 SUBDIRS += \
7 auto \
7 auto \
8 qmlchartproperties \
8 qmlchartproperties \
9 qmlchartaxis \
9 qmlchartaxis \
10 presenterchart
10 presenterchart \
11 polarcharttest
11
12
12 contains(QT_CONFIG, opengl) {
13 contains(QT_CONFIG, opengl) {
13 SUBDIRS += chartwidgettest \
14 SUBDIRS += chartwidgettest \
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (547 lines changed) Show them Hide them
General Comments 0
You need to be logged in to leave comments. Login now