##// END OF EJS Templates
Removed generic chartaxis
Marek Rosa -
r1561:8267a30e4282
parent child
Show More
@@ -1,31 +1,31
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/chartaxis.cpp \
5 $$PWD/chartaxis.cpp \
6 $$PWD/chartaxisx.cpp \
6 # $$PWD/chartaxisx.cpp \
7 $$PWD/chartaxisy.cpp \
7 # $$PWD/chartaxisy.cpp \
8 $$PWD/chartvaluesaxisx.cpp \
8 $$PWD/chartvaluesaxisx.cpp \
9 $$PWD/chartvaluesaxisy.cpp \
9 $$PWD/chartvaluesaxisy.cpp \
10 $$PWD/chartcategoriesaxisx.cpp \
10 $$PWD/chartcategoriesaxisx.cpp \
11 $$PWD/chartcategoriesaxisy.cpp \
11 $$PWD/chartcategoriesaxisy.cpp \
12 $$PWD/qcategoriesaxis.cpp \
12 $$PWD/qcategoriesaxis.cpp \
13 $$PWD/qvaluesaxis.cpp \
13 $$PWD/qvaluesaxis.cpp \
14 $$PWD/qabstractaxis.cpp
14 $$PWD/qabstractaxis.cpp
15
15
16 PRIVATE_HEADERS += \
16 PRIVATE_HEADERS += \
17 $$PWD/chartaxis_p.h \
17 $$PWD/chartaxis_p.h \
18 $$PWD/chartaxisx_p.h \
18 # $$PWD/chartaxisx_p.h \
19 $$PWD/chartaxisy_p.h \
19 # $$PWD/chartaxisy_p.h \
20 $$PWD/chartvaluesaxisx_p.h \
20 $$PWD/chartvaluesaxisx_p.h \
21 $$PWD/chartvaluesaxisy_p.h \
21 $$PWD/chartvaluesaxisy_p.h \
22 $$PWD/chartcategoriesaxisx_p.h \
22 $$PWD/chartcategoriesaxisx_p.h \
23 $$PWD/chartcategoriesaxisy_p.h \
23 $$PWD/chartcategoriesaxisy_p.h \
24 $$PWD/qcategoriesaxis_p.h \
24 $$PWD/qcategoriesaxis_p.h \
25 $$PWD/qvaluesaxis_p.h \
25 $$PWD/qvaluesaxis_p.h \
26 $$PWD/qabstractaxis_p.h
26 $$PWD/qabstractaxis_p.h
27
27
28 PUBLIC_HEADERS += \
28 PUBLIC_HEADERS += \
29 $$PWD/qcategoriesaxis.h \
29 $$PWD/qcategoriesaxis.h \
30 $$PWD/qvaluesaxis.h \
30 $$PWD/qvaluesaxis.h \
31 $$PWD/qabstractaxis.h
31 $$PWD/qabstractaxis.h
@@ -1,122 +1,123
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartcategoriesaxisy_p.h"
21 #include "chartcategoriesaxisy_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28
28
29 static int label_padding = 5;
29 static int label_padding = 5;
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 ChartCategoriesAxisY::ChartCategoriesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
33 ChartCategoriesAxisY::ChartCategoriesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
34 {
34 {
35 }
35 }
36
36
37 ChartCategoriesAxisY::~ChartCategoriesAxisY()
37 ChartCategoriesAxisY::~ChartCategoriesAxisY()
38 {
38 {
39 }
39 }
40
40
41 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
41 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
42 {
42 {
43 Q_ASSERT(m_ticksCount>=2);
43 Q_ASSERT(m_ticksCount>=2);
44
44
45 QVector<qreal> points;
45 QVector<qreal> points;
46 points.resize(m_ticksCount);
46 points.resize(m_ticksCount);
47
47
48 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
48 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
49 for (int i = 0; i < m_ticksCount; ++i) {
49 for (int i = 0; i < m_ticksCount; ++i) {
50 int x = i * deltaX + m_rect.left();
50 int y = i * -deltaY + m_rect.bottom();
51 points[i] = x;
51 points[i] = y;
52 }
52 }
53
53 return points;
54 return points;
54 }
55 }
55
56
56 void ChartCategoriesAxisY::updateGeometry()
57 void ChartCategoriesAxisY::updateGeometry()
57 {
58 {
58 const QVector<qreal>& layout = ChartAxis::layout();
59 const QVector<qreal>& layout = ChartAxis::layout();
59
60
60 m_minWidth = 0;
61 m_minWidth = 0;
61 m_minHeight = 0;
62 m_minHeight = 0;
62
63
63 if(layout.isEmpty()) return;
64 if(layout.isEmpty()) return;
64
65
65 QStringList ticksList;
66 QStringList ticksList;
66
67
67 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
68 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
68
69
69 QList<QGraphicsItem *> lines = m_grid->childItems();
70 QList<QGraphicsItem *> lines = m_grid->childItems();
70 QList<QGraphicsItem *> labels = m_labels->childItems();
71 QList<QGraphicsItem *> labels = m_labels->childItems();
71 QList<QGraphicsItem *> shades = m_shades->childItems();
72 QList<QGraphicsItem *> shades = m_shades->childItems();
72 QList<QGraphicsItem *> axis = m_axis->childItems();
73 QList<QGraphicsItem *> axis = m_axis->childItems();
73
74
74 Q_ASSERT(labels.size() == ticksList.size());
75 Q_ASSERT(labels.size() == ticksList.size());
75 Q_ASSERT(layout.size() == ticksList.size());
76 Q_ASSERT(layout.size() == ticksList.size());
76
77
77 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
78 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
78 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
79 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
79
80
80 qreal width = 0;
81 qreal width = 0;
81 for (int i = 0; i < layout.size(); ++i) {
82 for (int i = 0; i < layout.size(); ++i) {
82 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
84 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
85 if (!categories || i<1) {
86 if (!categories || i<1) {
86 labelItem->setText(ticksList.at(i));
87 labelItem->setText(ticksList.at(i));
87 const QRectF& rect = labelItem->boundingRect();
88 const QRectF& rect = labelItem->boundingRect();
88 QPointF center = rect.center();
89 QPointF center = rect.center();
89 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
91 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
91
92
92 if(labelItem->pos().x()<=width){
93 if(labelItem->pos().x()<=width){
93 labelItem->setVisible(false);
94 labelItem->setVisible(false);
94 lineItem->setVisible(false);
95 lineItem->setVisible(false);
95 }else{
96 }else{
96 labelItem->setVisible(true);
97 labelItem->setVisible(true);
97 lineItem->setVisible(true);
98 lineItem->setVisible(true);
98 width=rect.width()+labelItem->pos().x();
99 width=rect.width()+labelItem->pos().x();
99 }
100 }
100 m_minWidth+=rect.width();
101 m_minWidth+=rect.width();
101 m_minHeight=qMax(rect.height(),m_minHeight);
102 m_minHeight=qMax(rect.height(),m_minHeight);
102 }
103 }
103 else {
104 else {
104 labelItem->setText(ticksList.at(i));
105 labelItem->setText(ticksList.at(i));
105 const QRectF& rect = labelItem->boundingRect();
106 const QRectF& rect = labelItem->boundingRect();
106 QPointF center = rect.center();
107 QPointF center = rect.center();
107 labelItem->setTransformOriginPoint(center.x(), center.y());
108 labelItem->setTransformOriginPoint(center.x(), center.y());
108 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
109 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
109 m_minWidth+=rect.width();
110 m_minWidth+=rect.width();
110 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
111 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
111 }
112 }
112
113
113 if ((i+1)%2 && i>1) {
114 if ((i+1)%2 && i>1) {
114 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
115 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
115 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
116 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
116 }
117 }
117 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
118 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
118 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
119 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
119 }
120 }
120 }
121 }
121
122
122 QTCOMMERCIALCHART_END_NAMESPACE
123 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,122 +1,132
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartvaluesaxisx_p.h"
21 #include "chartvaluesaxisx_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <cmath>
28
29
29 static int label_padding = 5;
30 static int label_padding = 5;
30
31
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
33
33 ChartValuesAxisX::ChartValuesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
34 ChartValuesAxisX::ChartValuesAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
34 {
35 {
35 }
36 }
36
37
37 ChartValuesAxisX::~ChartValuesAxisX()
38 ChartValuesAxisX::~ChartValuesAxisX()
38 {
39 {
39 }
40 }
40
41
41 QVector<qreal> ChartValuesAxisX::calculateLayout() const
42 QVector<qreal> ChartValuesAxisX::calculateLayout() const
42 {
43 {
43 Q_ASSERT(m_ticksCount>=2);
44 Q_ASSERT(m_ticksCount>=2);
44
45
45 QVector<qreal> points;
46 QVector<qreal> points;
46 points.resize(m_ticksCount);
47 points.resize(m_ticksCount);
47
48
48 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
49 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
49 for (int i = 0; i < m_ticksCount; ++i) {
50 for (int i = 0; i < m_ticksCount; ++i) {
50 int x = i * deltaX + m_rect.left();
51 int x = i * deltaX + m_rect.left();
51 points[i] = x;
52 points[i] = x;
52 }
53 }
53 return points;
54 return points;
54 }
55 }
55
56
56 void ChartValuesAxisX::updateGeometry()
57 void ChartValuesAxisX::updateGeometry()
57 {
58 {
58 const QVector<qreal>& layout = ChartAxis::layout();
59 const QVector<qreal>& layout = ChartAxis::layout();
59
60
60 m_minWidth = 0;
61 m_minWidth = 0;
61 m_minHeight = 0;
62 m_minHeight = 0;
62
63
63 if(layout.isEmpty()) return;
64 if(layout.isEmpty()) return;
64
65
65 QStringList ticksList;
66 QStringList ticksList;
66
67
67 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
68 int ticks = layout.size();
69 int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0);
70 n++;
71 for (int i=0; i< ticks; i++) {
72 qreal value = m_min + (i * (m_max - m_min)/ (ticks-1));
73 Q_UNUSED(value);
74 ticksList << QString::number(value,'f',n);
75 }
76
77 bool categories = false; //createLabels(ticksList,m_min,m_max,layout.size());
68
78
69 QList<QGraphicsItem *> lines = m_grid->childItems();
79 QList<QGraphicsItem *> lines = m_grid->childItems();
70 QList<QGraphicsItem *> labels = m_labels->childItems();
80 QList<QGraphicsItem *> labels = m_labels->childItems();
71 QList<QGraphicsItem *> shades = m_shades->childItems();
81 QList<QGraphicsItem *> shades = m_shades->childItems();
72 QList<QGraphicsItem *> axis = m_axis->childItems();
82 QList<QGraphicsItem *> axis = m_axis->childItems();
73
83
74 Q_ASSERT(labels.size() == ticksList.size());
84 Q_ASSERT(labels.size() == ticksList.size());
75 Q_ASSERT(layout.size() == ticksList.size());
85 Q_ASSERT(layout.size() == ticksList.size());
76
86
77 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
87 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
78 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
88 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
79
89
80 qreal width = 0;
90 qreal width = 0;
81 for (int i = 0; i < layout.size(); ++i) {
91 for (int i = 0; i < layout.size(); ++i) {
82 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
92 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
93 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
84 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
94 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
85 if (!categories || i<1) {
95 if (!categories || i<1) {
86 labelItem->setText(ticksList.at(i));
96 labelItem->setText(ticksList.at(i));
87 const QRectF& rect = labelItem->boundingRect();
97 const QRectF& rect = labelItem->boundingRect();
88 QPointF center = rect.center();
98 QPointF center = rect.center();
89 labelItem->setTransformOriginPoint(center.x(), center.y());
99 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
100 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
91
101
92 if(labelItem->pos().x()<=width){
102 if(labelItem->pos().x()<=width){
93 labelItem->setVisible(false);
103 labelItem->setVisible(false);
94 lineItem->setVisible(false);
104 lineItem->setVisible(false);
95 }else{
105 }else{
96 labelItem->setVisible(true);
106 labelItem->setVisible(true);
97 lineItem->setVisible(true);
107 lineItem->setVisible(true);
98 width=rect.width()+labelItem->pos().x();
108 width=rect.width()+labelItem->pos().x();
99 }
109 }
100 m_minWidth+=rect.width();
110 m_minWidth+=rect.width();
101 m_minHeight=qMax(rect.height(),m_minHeight);
111 m_minHeight=qMax(rect.height(),m_minHeight);
102 }
112 }
103 else {
113 // else {
104 labelItem->setText(ticksList.at(i));
114 // labelItem->setText(ticksList.at(i));
105 const QRectF& rect = labelItem->boundingRect();
115 // const QRectF& rect = labelItem->boundingRect();
106 QPointF center = rect.center();
116 // QPointF center = rect.center();
107 labelItem->setTransformOriginPoint(center.x(), center.y());
117 // labelItem->setTransformOriginPoint(center.x(), center.y());
108 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
118 // labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
109 m_minWidth+=rect.width();
119 // m_minWidth+=rect.width();
110 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
120 // m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
111 }
121 // }
112
122
113 if ((i+1)%2 && i>1) {
123 if ((i+1)%2 && i>1) {
114 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
124 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
115 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
125 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
116 }
126 }
117 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
127 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
118 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
128 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
119 }
129 }
120 }
130 }
121
131
122 QTCOMMERCIALCHART_END_NAMESPACE
132 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,122 +1,139
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartvaluesaxisy_p.h"
21 #include "chartvaluesaxisy_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <cmath>
28
29
29 static int label_padding = 5;
30 static int label_padding = 5;
30
31
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
33
33 ChartValuesAxisY::ChartValuesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
34 ChartValuesAxisY::ChartValuesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
34 {
35 {
35 }
36 }
36
37
37 ChartValuesAxisY::~ChartValuesAxisY()
38 ChartValuesAxisY::~ChartValuesAxisY()
38 {
39 {
39 }
40 }
40
41
41 QVector<qreal> ChartValuesAxisY::calculateLayout() const
42 QVector<qreal> ChartValuesAxisY::calculateLayout() const
42 {
43 {
43 Q_ASSERT(m_ticksCount>=2);
44 Q_ASSERT(m_ticksCount>=2);
44
45
45 QVector<qreal> points;
46 QVector<qreal> points;
46 points.resize(m_ticksCount);
47 points.resize(m_ticksCount);
47
48
48 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
49 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
49 for (int i = 0; i < m_ticksCount; ++i) {
50 for (int i = 0; i < m_ticksCount; ++i) {
50 int x = i * deltaX + m_rect.left();
51 int y = i * -deltaY + m_rect.bottom();
51 points[i] = x;
52 points[i] = y;
52 }
53 }
54
53 return points;
55 return points;
54 }
56 }
55
57
56 void ChartValuesAxisY::updateGeometry()
58 void ChartValuesAxisY::updateGeometry()
57 {
59 {
58 const QVector<qreal>& layout = ChartAxis::layout();
60 const QVector<qreal> &layout = ChartAxis::layout();
59
60 m_minWidth = 0;
61 m_minWidth = 0;
61 m_minHeight = 0;
62 m_minHeight = 0;
62
63
63 if(layout.isEmpty()) return;
64 if(layout.isEmpty()) return;
64
65
65 QStringList ticksList;
66 QStringList ticksList;
66
67
67 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
68 int ticks = layout.size();
69 int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0);
70 n++;
71 for (int i=0; i< ticks; i++) {
72 qreal value = m_min + (i * (m_max - m_min)/ (ticks-1));
73 Q_UNUSED(value);
74 ticksList << QString::number(value,'f',n);
75 }
76
77 bool categories = false;
78
79 // bool categories = createLabels(ticksList,m_min,m_max,layout.size());
68
80
69 QList<QGraphicsItem *> lines = m_grid->childItems();
81 QList<QGraphicsItem *> lines = m_grid->childItems();
70 QList<QGraphicsItem *> labels = m_labels->childItems();
82 QList<QGraphicsItem *> labels = m_labels->childItems();
71 QList<QGraphicsItem *> shades = m_shades->childItems();
83 QList<QGraphicsItem *> shades = m_shades->childItems();
72 QList<QGraphicsItem *> axis = m_axis->childItems();
84 QList<QGraphicsItem *> axis = m_axis->childItems();
73
85
74 Q_ASSERT(labels.size() == ticksList.size());
86 Q_ASSERT(labels.size() == ticksList.size());
75 Q_ASSERT(layout.size() == ticksList.size());
87 Q_ASSERT(layout.size() == ticksList.size());
76
88
89 qreal height = 2*m_rect.bottom();
90
77 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
91 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
78 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
92 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
79
93
80 qreal width = 0;
81 for (int i = 0; i < layout.size(); ++i) {
94 for (int i = 0; i < layout.size(); ++i) {
82 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
95 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
96 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
84 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
97 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
98
85 if (!categories || i<1) {
99 if (!categories || i<1) {
86 labelItem->setText(ticksList.at(i));
100 labelItem->setText(ticksList.at(i));
87 const QRectF& rect = labelItem->boundingRect();
101 const QRectF& rect = labelItem->boundingRect();
102
88 QPointF center = rect.center();
103 QPointF center = rect.center();
89 labelItem->setTransformOriginPoint(center.x(), center.y());
104 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
105 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
91
106
92 if(labelItem->pos().x()<=width){
107 if(labelItem->pos().y()+rect.height()>height) {
93 labelItem->setVisible(false);
108 labelItem->setVisible(false);
94 lineItem->setVisible(false);
109 lineItem->setVisible(false);
95 }else{
110 }
111 else {
96 labelItem->setVisible(true);
112 labelItem->setVisible(true);
97 lineItem->setVisible(true);
113 lineItem->setVisible(true);
98 width=rect.width()+labelItem->pos().x();
114 height=labelItem->pos().y();
99 }
115 }
100 m_minWidth+=rect.width();
116
101 m_minHeight=qMax(rect.height(),m_minHeight);
117 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
118 m_minHeight+=rect.height();
102 }
119 }
103 else {
120 else {
104 labelItem->setText(ticksList.at(i));
121 labelItem->setText(ticksList.at(i));
105 const QRectF& rect = labelItem->boundingRect();
122 const QRectF& rect = labelItem->boundingRect();
123 m_minWidth=qMax(rect.width(),m_minWidth);
124 m_minHeight+=rect.height();
106 QPointF center = rect.center();
125 QPointF center = rect.center();
107 labelItem->setTransformOriginPoint(center.x(), center.y());
126 labelItem->setTransformOriginPoint(center.x(), center.y());
108 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
127 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
109 m_minWidth+=rect.width();
110 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
111 }
128 }
112
129
113 if ((i+1)%2 && i>1) {
130 if ((i+1)%2 && i>1) {
114 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
131 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
115 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
132 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
116 }
133 }
117 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
134 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
118 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
135 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
119 }
136 }
120 }
137 }
121
138
122 QTCOMMERCIALCHART_END_NAMESPACE
139 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,222 +1,222
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qcategoriesaxis.h"
21 #include "qcategoriesaxis.h"
22 #include "qcategoriesaxis_p.h"
22 #include "qcategoriesaxis_p.h"
23 #include "chartaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartaxisy_p.h"
24 #include "chartcategoriesaxisy_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 QCategoriesAxis::QCategoriesAxis(QObject *parent):
28 QCategoriesAxis::QCategoriesAxis(QObject *parent):
29 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
29 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
30 {
30 {
31
31
32 }
32 }
33
33
34 QCategoriesAxis::~QCategoriesAxis()
34 QCategoriesAxis::~QCategoriesAxis()
35 {
35 {
36
36
37 }
37 }
38
38
39 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
39 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
40 {
40 {
41
41
42 }
42 }
43
43
44 /*!
44 /*!
45 Appends \a categories to axis
45 Appends \a categories to axis
46 */
46 */
47 void QCategoriesAxis::append(const QStringList &categories)
47 void QCategoriesAxis::append(const QStringList &categories)
48 {
48 {
49 Q_D(QCategoriesAxis);
49 Q_D(QCategoriesAxis);
50 d->m_categories.append(categories);
50 d->m_categories.append(categories);
51 emit categoriesChanged();
51 emit categoriesChanged();
52 }
52 }
53
53
54 /*!
54 /*!
55 Appends \a category to axis
55 Appends \a category to axis
56 */
56 */
57 void QCategoriesAxis::append(const QString &category)
57 void QCategoriesAxis::append(const QString &category)
58 {
58 {
59 Q_D(QCategoriesAxis);
59 Q_D(QCategoriesAxis);
60 d->m_categories.append(category);
60 d->m_categories.append(category);
61 emit categoriesChanged();
61 emit categoriesChanged();
62 }
62 }
63
63
64 /*!
64 /*!
65 Removes \a category from axis
65 Removes \a category from axis
66 */
66 */
67 void QCategoriesAxis::remove(const QString &category)
67 void QCategoriesAxis::remove(const QString &category)
68 {
68 {
69 Q_D(QCategoriesAxis);
69 Q_D(QCategoriesAxis);
70 if (d->m_categories.contains(category)) {
70 if (d->m_categories.contains(category)) {
71 d->m_categories.removeAt(d->m_categories.indexOf(category));
71 d->m_categories.removeAt(d->m_categories.indexOf(category));
72 emit categoriesChanged();
72 emit categoriesChanged();
73 }
73 }
74 }
74 }
75
75
76 /*!
76 /*!
77 Inserts \a category to axis at \a index
77 Inserts \a category to axis at \a index
78 */
78 */
79 void QCategoriesAxis::insert(int index, const QString &category)
79 void QCategoriesAxis::insert(int index, const QString &category)
80 {
80 {
81 Q_D(QCategoriesAxis);
81 Q_D(QCategoriesAxis);
82 d->m_categories.insert(index,category);
82 d->m_categories.insert(index,category);
83 emit categoriesChanged();
83 emit categoriesChanged();
84 }
84 }
85
85
86 /*!
86 /*!
87 Removes all categories.
87 Removes all categories.
88 */
88 */
89 void QCategoriesAxis::clear()
89 void QCategoriesAxis::clear()
90 {
90 {
91 Q_D(QCategoriesAxis);
91 Q_D(QCategoriesAxis);
92 d->m_categories.clear();
92 d->m_categories.clear();
93 emit categoriesChanged();
93 emit categoriesChanged();
94 }
94 }
95
95
96 void QCategoriesAxis::setCategories(const QStringList &categories)
96 void QCategoriesAxis::setCategories(const QStringList &categories)
97 {
97 {
98 Q_D(QCategoriesAxis);
98 Q_D(QCategoriesAxis);
99 d->m_categories = categories;
99 d->m_categories = categories;
100 emit categoriesChanged();
100 emit categoriesChanged();
101 }
101 }
102
102
103 QStringList QCategoriesAxis::categories()
103 QStringList QCategoriesAxis::categories()
104 {
104 {
105 Q_D(QCategoriesAxis);
105 Q_D(QCategoriesAxis);
106 return d->m_categories;
106 return d->m_categories;
107 }
107 }
108
108
109 /*!
109 /*!
110 Returns number of categories.
110 Returns number of categories.
111 */
111 */
112 int QCategoriesAxis::count() const
112 int QCategoriesAxis::count() const
113 {
113 {
114 Q_D(const QCategoriesAxis);
114 Q_D(const QCategoriesAxis);
115 return d->m_categories.count();
115 return d->m_categories.count();
116 }
116 }
117
117
118 /*!
118 /*!
119 Returns category at \a index. Index must be valid.
119 Returns category at \a index. Index must be valid.
120 */
120 */
121 QString QCategoriesAxis::at(int index) const
121 QString QCategoriesAxis::at(int index) const
122 {
122 {
123 Q_D(const QCategoriesAxis);
123 Q_D(const QCategoriesAxis);
124 return d->m_categories.at(index);
124 return d->m_categories.at(index);
125 }
125 }
126
126
127 /*!
127 /*!
128 Sets minimum category to \a minCategory.
128 Sets minimum category to \a minCategory.
129 */
129 */
130 void QCategoriesAxis::setMin(const QString& minCategory)
130 void QCategoriesAxis::setMin(const QString& minCategory)
131 {
131 {
132 Q_D(QCategoriesAxis);
132 Q_D(QCategoriesAxis);
133 int minIndex = d->m_categories.indexOf(minCategory);
133 int minIndex = d->m_categories.indexOf(minCategory);
134 if (minIndex == -1)
134 if (minIndex == -1)
135 return;
135 return;
136 // else
136 // else
137 // QAbstractAxis::setMin(minIndex);
137 // QAbstractAxis::setMin(minIndex);
138 }
138 }
139
139
140 /*!
140 /*!
141 Sets maximum category to \a maxCategory.
141 Sets maximum category to \a maxCategory.
142 */
142 */
143 void QCategoriesAxis::setMax(const QString& maxCategory)
143 void QCategoriesAxis::setMax(const QString& maxCategory)
144 {
144 {
145 Q_D(QCategoriesAxis);
145 Q_D(QCategoriesAxis);
146 int maxIndex = d->m_categories.indexOf(maxCategory);
146 int maxIndex = d->m_categories.indexOf(maxCategory);
147 if (maxIndex == -1)
147 if (maxIndex == -1)
148 return;
148 return;
149 // else
149 // else
150 // QAbstractAxis::setMax(maxIndex);
150 // QAbstractAxis::setMax(maxIndex);
151 }
151 }
152
152
153 /*!
153 /*!
154 Sets range from \a minCategory to \a maxCategory
154 Sets range from \a minCategory to \a maxCategory
155 */
155 */
156 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
156 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
157 {
157 {
158 // TODO: what if maxCategory < minCategory?
158 // TODO: what if maxCategory < minCategory?
159 setMin(minCategory);
159 setMin(minCategory);
160 setMax(maxCategory);
160 setMax(maxCategory);
161 }
161 }
162
162
163 /*!
163 /*!
164 Returns the type of axis.
164 Returns the type of axis.
165 */
165 */
166 QAbstractAxis::AxisType QCategoriesAxis::type() const
166 QAbstractAxis::AxisType QCategoriesAxis::type() const
167 {
167 {
168 return AxisTypeCategories;
168 return AxisTypeCategories;
169 }
169 }
170
170
171 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
172
172
173 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
173 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
174 QAbstractAxisPrivate(q)
174 QAbstractAxisPrivate(q)
175 {
175 {
176
176
177 }
177 }
178
178
179 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
179 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
180 {
180 {
181
181
182 }
182 }
183
183
184
184
185 void QCategoriesAxisPrivate::setMin(const QVariant& min)
185 void QCategoriesAxisPrivate::setMin(const QVariant& min)
186 {
186 {
187 Q_Q(QCategoriesAxis);
187 Q_Q(QCategoriesAxis);
188 q->setMin(min.toString());
188 q->setMin(min.toString());
189 }
189 }
190
190
191 void QCategoriesAxisPrivate::setMax(const QVariant& max)
191 void QCategoriesAxisPrivate::setMax(const QVariant& max)
192 {
192 {
193 Q_Q(QCategoriesAxis);
193 Q_Q(QCategoriesAxis);
194 q->setMax(max.toString());
194 q->setMax(max.toString());
195 }
195 }
196
196
197 void QCategoriesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
197 void QCategoriesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
198 {
198 {
199 Q_Q(QCategoriesAxis);
199 Q_Q(QCategoriesAxis);
200 q->setRange(min.toString(),max.toString());
200 q->setRange(min.toString(),max.toString());
201 }
201 }
202
202
203 int QCategoriesAxisPrivate::ticksCount() const
203 int QCategoriesAxisPrivate::ticksCount() const
204 {
204 {
205 return m_categories.count()+1;
205 return m_categories.count()+1;
206 }
206 }
207
207
208 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
208 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
209 {
209 {
210 Q_Q( QCategoriesAxis);
210 Q_Q( QCategoriesAxis);
211 if(m_orientation == Qt::Vertical){
211 if(m_orientation == Qt::Vertical){
212 return new ChartAxisY(q,presenter);
212 return new ChartCategoriesAxisY(q,presenter);
213 }else{
213 }else{
214 return new ChartAxisX(q,presenter);
214 return new ChartCategoriesAxisX(q,presenter);
215 }
215 }
216
216
217 }
217 }
218
218
219 #include "moc_qcategoriesaxis.cpp"
219 #include "moc_qcategoriesaxis.cpp"
220 #include "moc_qcategoriesaxis_p.cpp"
220 #include "moc_qcategoriesaxis_p.cpp"
221
221
222 QTCOMMERCIALCHART_END_NAMESPACE
222 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,265 +1,265
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvaluesaxis.h"
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
22 #include "qvaluesaxis_p.h"
23 #include "chartaxisx_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartaxisy_p.h"
24 #include "chartvaluesaxisy_p.h"
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 /*!
28 /*!
29 \class QValuesAxis
29 \class QValuesAxis
30 \brief The QValuesAxis class is used for manipulating chart's axis.
30 \brief The QValuesAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass Axis QValuesAxis
37 \qmlclass Axis QValuesAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
41
41
42 To access Axes you can use ChartView API. For example:
42 To access Axes you can use ChartView API. For example:
43 \code
43 \code
44 ChartView {
44 ChartView {
45 axisX.min: 0
45 axisX.min: 0
46 axisX.max: 3
46 axisX.max: 3
47 axisX.ticksCount: 4
47 axisX.ticksCount: 4
48 axisY.min: 0
48 axisY.min: 0
49 axisY.max: 4
49 axisY.max: 4
50 // Add a few series...
50 // Add a few series...
51 }
51 }
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \property QValuesAxis::min
56 \property QValuesAxis::min
57 Defines the minimum value on the axis.
57 Defines the minimum value on the axis.
58 */
58 */
59 /*!
59 /*!
60 \qmlproperty real Axis::min
60 \qmlproperty real Axis::min
61 Defines the minimum value on the axis.
61 Defines the minimum value on the axis.
62 */
62 */
63
63
64 /*!
64 /*!
65 \property QValuesAxis::max
65 \property QValuesAxis::max
66 Defines the maximum value on the axis.
66 Defines the maximum value on the axis.
67 */
67 */
68 /*!
68 /*!
69 \qmlproperty real Axis::max
69 \qmlproperty real Axis::max
70 Defines the maximum value on the axis.
70 Defines the maximum value on the axis.
71 */
71 */
72
72
73 /*!
73 /*!
74 \fn void QValuesAxis::minChanged(qreal min)
74 \fn void QValuesAxis::minChanged(qreal min)
75 Axis emits signal when \a min of axis has changed.
75 Axis emits signal when \a min of axis has changed.
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn void QValuesAxis::maxChanged(qreal max)
79 \fn void QValuesAxis::maxChanged(qreal max)
80 Axis emits signal when \a max of axis has changed.
80 Axis emits signal when \a max of axis has changed.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
85 Axis emits signal when \a min or \a max of axis has changed.
85 Axis emits signal when \a min or \a max of axis has changed.
86 */
86 */
87
87
88 QValuesAxis::QValuesAxis(QObject *parent) :
88 QValuesAxis::QValuesAxis(QObject *parent) :
89 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
89 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
90 {
90 {
91
91
92 }
92 }
93
93
94 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
94 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
95 {
95 {
96
96
97 }
97 }
98
98
99 QValuesAxis::~QValuesAxis()
99 QValuesAxis::~QValuesAxis()
100 {
100 {
101
101
102 }
102 }
103
103
104 void QValuesAxis::setMin(qreal min)
104 void QValuesAxis::setMin(qreal min)
105 {
105 {
106 Q_D(QValuesAxis);
106 Q_D(QValuesAxis);
107 setRange(min,d->m_max);
107 setRange(min,d->m_max);
108 }
108 }
109
109
110 qreal QValuesAxis::min() const
110 qreal QValuesAxis::min() const
111 {
111 {
112 Q_D(const QValuesAxis);
112 Q_D(const QValuesAxis);
113 return d->m_min;
113 return d->m_min;
114 }
114 }
115
115
116 void QValuesAxis::setMax(qreal max)
116 void QValuesAxis::setMax(qreal max)
117 {
117 {
118 Q_D(QValuesAxis);
118 Q_D(QValuesAxis);
119 setRange(d->m_min,max);
119 setRange(d->m_min,max);
120 }
120 }
121
121
122 qreal QValuesAxis::max() const
122 qreal QValuesAxis::max() const
123 {
123 {
124 Q_D(const QValuesAxis);
124 Q_D(const QValuesAxis);
125 return d->m_max;
125 return d->m_max;
126 }
126 }
127
127
128 /*!
128 /*!
129 Sets range from \a min to \a max on the axis.
129 Sets range from \a min to \a max on the axis.
130 */
130 */
131 void QValuesAxis::setRange(qreal min, qreal max)
131 void QValuesAxis::setRange(qreal min, qreal max)
132 {
132 {
133 Q_D(QValuesAxis);
133 Q_D(QValuesAxis);
134 bool changed = false;
134 bool changed = false;
135 if (!qFuzzyIsNull(d->m_min - min)) {
135 if (!qFuzzyIsNull(d->m_min - min)) {
136 d->m_min = min;
136 d->m_min = min;
137 changed = true;
137 changed = true;
138 emit minChanged(min);
138 emit minChanged(min);
139 }
139 }
140
140
141 if (!qFuzzyIsNull(d->m_max - max)) {
141 if (!qFuzzyIsNull(d->m_max - max)) {
142 d->m_max = max;
142 d->m_max = max;
143 changed = true;
143 changed = true;
144 emit maxChanged(max);
144 emit maxChanged(max);
145 }
145 }
146
146
147 if (changed) {
147 if (changed) {
148 emit rangeChanged(d->m_min,d->m_max);
148 emit rangeChanged(d->m_min,d->m_max);
149 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
149 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
150 }
150 }
151 }
151 }
152
152
153 /*!
153 /*!
154 Sets \a count for ticks on the axis.
154 Sets \a count for ticks on the axis.
155 */
155 */
156 void QValuesAxis::setTicksCount(int count)
156 void QValuesAxis::setTicksCount(int count)
157 {
157 {
158 Q_D(QValuesAxis);
158 Q_D(QValuesAxis);
159 if (d->m_ticksCount != count) {
159 if (d->m_ticksCount != count) {
160 d->m_ticksCount = count;
160 d->m_ticksCount = count;
161 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
161 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
162 }
162 }
163 }
163 }
164
164
165 /*!
165 /*!
166 \fn int QAbstractAxis::ticksCount() const
166 \fn int QAbstractAxis::ticksCount() const
167 Return number of ticks on the axis
167 Return number of ticks on the axis
168 */
168 */
169 int QValuesAxis::ticksCount() const
169 int QValuesAxis::ticksCount() const
170 {
170 {
171 Q_D(const QValuesAxis);
171 Q_D(const QValuesAxis);
172 return d->m_ticksCount;
172 return d->m_ticksCount;
173 }
173 }
174
174
175 void QValuesAxis::setNiceNumbersEnabled(bool enable)
175 void QValuesAxis::setNiceNumbersEnabled(bool enable)
176 {
176 {
177 Q_D(QValuesAxis);
177 Q_D(QValuesAxis);
178 if (d->m_niceNumbers != enable){
178 if (d->m_niceNumbers != enable){
179 d->m_niceNumbers = enable;
179 d->m_niceNumbers = enable;
180 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
180 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
181 }
181 }
182 }
182 }
183
183
184 bool QValuesAxis::niceNumbersEnabled() const
184 bool QValuesAxis::niceNumbersEnabled() const
185 {
185 {
186 Q_D(const QValuesAxis);
186 Q_D(const QValuesAxis);
187 return d->m_niceNumbers;
187 return d->m_niceNumbers;
188 }
188 }
189
189
190 QAbstractAxis::AxisType QValuesAxis::type() const
190 QAbstractAxis::AxisType QValuesAxis::type() const
191 {
191 {
192 return AxisTypeValues;
192 return AxisTypeValues;
193 }
193 }
194
194
195 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
195 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
196
196
197 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
197 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
198 QAbstractAxisPrivate(q),
198 QAbstractAxisPrivate(q),
199 m_min(0),
199 m_min(0),
200 m_max(0),
200 m_max(0),
201 m_niceNumbers(false),
201 m_niceNumbers(false),
202 m_ticksCount(5)
202 m_ticksCount(5)
203 {
203 {
204
204
205 }
205 }
206
206
207 QValuesAxisPrivate::~QValuesAxisPrivate()
207 QValuesAxisPrivate::~QValuesAxisPrivate()
208 {
208 {
209
209
210 }
210 }
211
211
212 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
212 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
213 {
213 {
214 Q_Q(QValuesAxis);
214 Q_Q(QValuesAxis);
215 q->setRange(min,max);
215 q->setRange(min,max);
216 q->setTicksCount(count);
216 q->setTicksCount(count);
217 }
217 }
218
218
219
219
220 void QValuesAxisPrivate::setMin(const QVariant& min)
220 void QValuesAxisPrivate::setMin(const QVariant& min)
221 {
221 {
222 Q_Q(QValuesAxis);
222 Q_Q(QValuesAxis);
223 bool ok;
223 bool ok;
224 qreal value = min.toReal(&ok);
224 qreal value = min.toReal(&ok);
225 if(ok) q->setMin(value);
225 if(ok) q->setMin(value);
226 }
226 }
227
227
228 void QValuesAxisPrivate::setMax(const QVariant& max)
228 void QValuesAxisPrivate::setMax(const QVariant& max)
229 {
229 {
230 Q_Q(QValuesAxis);
230 Q_Q(QValuesAxis);
231 bool ok;
231 bool ok;
232 qreal value = max.toReal(&ok);
232 qreal value = max.toReal(&ok);
233 if(ok) q->setMax(value);
233 if(ok) q->setMax(value);
234 }
234 }
235
235
236 void QValuesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
236 void QValuesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
237 {
237 {
238 Q_Q(QValuesAxis);
238 Q_Q(QValuesAxis);
239 bool ok1;
239 bool ok1;
240 bool ok2;
240 bool ok2;
241 qreal value1 = min.toReal(&ok1);
241 qreal value1 = min.toReal(&ok1);
242 qreal value2 = max.toReal(&ok2);
242 qreal value2 = max.toReal(&ok2);
243 if(ok1&&ok2) q->setRange(value1,value2);
243 if(ok1&&ok2) q->setRange(value1,value2);
244 }
244 }
245
245
246 int QValuesAxisPrivate::ticksCount() const
246 int QValuesAxisPrivate::ticksCount() const
247 {
247 {
248 return m_ticksCount;
248 return m_ticksCount;
249 }
249 }
250
250
251 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
251 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
252 {
252 {
253 Q_Q(QValuesAxis);
253 Q_Q(QValuesAxis);
254 if(m_orientation == Qt::Vertical){
254 if(m_orientation == Qt::Vertical){
255 return new ChartAxisY(q,presenter);
255 return new ChartValuesAxisY(q,presenter);
256 }else{
256 }else{
257 return new ChartAxisX(q,presenter);
257 return new ChartValuesAxisX(q,presenter);
258 }
258 }
259
259
260 }
260 }
261
261
262 #include "moc_qvaluesaxis.cpp"
262 #include "moc_qvaluesaxis.cpp"
263 #include "moc_qvaluesaxis_p.cpp"
263 #include "moc_qvaluesaxis_p.cpp"
264
264
265 QTCOMMERCIALCHART_END_NAMESPACE
265 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,420 +1,420
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #include "chartpresenter_p.h"
20 #include "chartpresenter_p.h"
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qabstractaxis.h"
23 #include "qabstractaxis.h"
24 #include "qabstractaxis_p.h"
24 #include "qabstractaxis_p.h"
25 #include "chartdataset_p.h"
25 #include "chartdataset_p.h"
26 #include "charttheme_p.h"
26 #include "charttheme_p.h"
27 #include "chartanimator_p.h"
27 #include "chartanimator_p.h"
28 #include "chartanimation_p.h"
28 #include "chartanimation_p.h"
29 #include "qabstractseries_p.h"
29 #include "qabstractseries_p.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "chartaxis_p.h"
31 #include "chartaxis_p.h"
32 #include "chartaxisx_p.h"
32 //#include "chartaxisx_p.h"
33 #include "chartaxisy_p.h"
33 //#include "chartaxisy_p.h"
34 #include "areachartitem_p.h"
34 #include "areachartitem_p.h"
35 #include "chartbackground_p.h"
35 #include "chartbackground_p.h"
36 #include "chartlayout_p.h"
36 #include "chartlayout_p.h"
37 #include <QTimer>
37 #include <QTimer>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
41 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
42 m_chart(chart),
42 m_chart(chart),
43 m_animator(0),
43 m_animator(0),
44 m_dataset(dataset),
44 m_dataset(dataset),
45 m_chartTheme(0),
45 m_chartTheme(0),
46 m_options(QChart::NoAnimation),
46 m_options(QChart::NoAnimation),
47 m_state(ShowState),
47 m_state(ShowState),
48 m_layout(new ChartLayout(this)),
48 m_layout(new ChartLayout(this)),
49 m_backgroundItem(0),
49 m_backgroundItem(0),
50 m_titleItem(0)
50 m_titleItem(0)
51 {
51 {
52
52
53 }
53 }
54
54
55 ChartPresenter::~ChartPresenter()
55 ChartPresenter::~ChartPresenter()
56 {
56 {
57 delete m_chartTheme;
57 delete m_chartTheme;
58 }
58 }
59
59
60 void ChartPresenter::setGeometry(const QRectF& rect)
60 void ChartPresenter::setGeometry(const QRectF& rect)
61 {
61 {
62
62
63 Q_ASSERT(rect.isValid());
63 Q_ASSERT(rect.isValid());
64
64
65 if(m_rect!=rect) {
65 if(m_rect!=rect) {
66 m_rect=rect;
66 m_rect=rect;
67 emit geometryChanged(m_rect);
67 emit geometryChanged(m_rect);
68 }
68 }
69 }
69 }
70
70
71 void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain)
71 void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain)
72 {
72 {
73 ChartAxis* item = axis->d_ptr->createGraphics(this);
73 ChartAxis* item = axis->d_ptr->createGraphics(this);
74 item->setDomain(domain);
74 item->setDomain(domain);
75
75
76 if(m_options.testFlag(QChart::GridAxisAnimations)){
76 if(m_options.testFlag(QChart::GridAxisAnimations)){
77 item->setAnimator(m_animator);
77 item->setAnimator(m_animator);
78 item->setAnimation(new AxisAnimation(item));
78 item->setAnimation(new AxisAnimation(item));
79 }
79 }
80
80
81 if(item->axisType()==ChartAxis::X_AXIS){
81 if(item->axisType()==ChartAxis::X_AXIS){
82 m_chartTheme->decorate(axis,true);
82 m_chartTheme->decorate(axis,true);
83 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
83 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
84 //initialize
84 //initialize
85 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
85 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
86
86
87 }
87 }
88 else{
88 else{
89 m_chartTheme->decorate(axis,false);
89 m_chartTheme->decorate(axis,false);
90 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
90 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
91 //initialize
91 //initialize
92 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
92 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
93 }
93 }
94
94
95 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
95 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
96 //initialize
96 //initialize
97 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
97 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
98 m_axisItems.insert(axis, item);
98 m_axisItems.insert(axis, item);
99 }
99 }
100
100
101 void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis)
101 void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis)
102 {
102 {
103 ChartAxis* item = m_axisItems.take(axis);
103 ChartAxis* item = m_axisItems.take(axis);
104 Q_ASSERT(item);
104 Q_ASSERT(item);
105 if(m_animator) m_animator->removeAnimation(item);
105 if(m_animator) m_animator->removeAnimation(item);
106 delete item;
106 delete item;
107 }
107 }
108
108
109
109
110 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
110 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
111 {
111 {
112 Chart *item = series->d_ptr->createGraphics(this);
112 Chart *item = series->d_ptr->createGraphics(this);
113 Q_ASSERT(item);
113 Q_ASSERT(item);
114 item->setDomain(domain);
114 item->setDomain(domain);
115
115
116 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
116 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
117 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
117 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
118 //initialize
118 //initialize
119 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
119 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
120 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
120 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
121 m_chartItems.insert(series,item);
121 m_chartItems.insert(series,item);
122 }
122 }
123
123
124 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
124 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
125 {
125 {
126 Chart* item = m_chartItems.take(series);
126 Chart* item = m_chartItems.take(series);
127 Q_ASSERT(item);
127 Q_ASSERT(item);
128 if(m_animator) {
128 if(m_animator) {
129 //small hack to handle area animations
129 //small hack to handle area animations
130 if(series->type() == QAbstractSeries::SeriesTypeArea){
130 if(series->type() == QAbstractSeries::SeriesTypeArea){
131 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
131 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
132 AreaChartItem* area = static_cast<AreaChartItem*>(item);
132 AreaChartItem* area = static_cast<AreaChartItem*>(item);
133 m_animator->removeAnimation(area->upperLineItem());
133 m_animator->removeAnimation(area->upperLineItem());
134 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
134 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
135 }else
135 }else
136 m_animator->removeAnimation(item);
136 m_animator->removeAnimation(item);
137 }
137 }
138 delete item;
138 delete item;
139 }
139 }
140
140
141 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
141 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
142 {
142 {
143 if(m_chartTheme && m_chartTheme->id() == theme) return;
143 if(m_chartTheme && m_chartTheme->id() == theme) return;
144 delete m_chartTheme;
144 delete m_chartTheme;
145 m_chartTheme = ChartTheme::createTheme(theme);
145 m_chartTheme = ChartTheme::createTheme(theme);
146 m_chartTheme->setForced(force);
146 m_chartTheme->setForced(force);
147 m_chartTheme->decorate(m_chart);
147 m_chartTheme->decorate(m_chart);
148 m_chartTheme->decorate(m_chart->legend());
148 m_chartTheme->decorate(m_chart->legend());
149 resetAllElements();
149 resetAllElements();
150
150
151 // We do not want "force" to stay on.
151 // We do not want "force" to stay on.
152 // Bar/pie are calling decorate when adding/removing slices/bars which means
152 // Bar/pie are calling decorate when adding/removing slices/bars which means
153 // that to preserve users colors "force" must not be on.
153 // that to preserve users colors "force" must not be on.
154 m_chartTheme->setForced(false);
154 m_chartTheme->setForced(false);
155 }
155 }
156
156
157 QChart::ChartTheme ChartPresenter::theme()
157 QChart::ChartTheme ChartPresenter::theme()
158 {
158 {
159 return m_chartTheme->id();
159 return m_chartTheme->id();
160 }
160 }
161
161
162 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
162 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
163 {
163 {
164 if(m_options!=options) {
164 if(m_options!=options) {
165
165
166 m_options=options;
166 m_options=options;
167
167
168 if(m_options!=QChart::NoAnimation && !m_animator) {
168 if(m_options!=QChart::NoAnimation && !m_animator) {
169 m_animator= new ChartAnimator(this);
169 m_animator= new ChartAnimator(this);
170 }
170 }
171 resetAllElements();
171 resetAllElements();
172 }
172 }
173
173
174 }
174 }
175
175
176 void ChartPresenter::resetAllElements()
176 void ChartPresenter::resetAllElements()
177 {
177 {
178 QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems);
178 QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems);
179 while (i.hasNext()) {
179 while (i.hasNext()) {
180 i.next();
180 i.next();
181 Domain* domain = i.value()->domain();
181 Domain* domain = i.value()->domain();
182 QAbstractAxis* axis = i.key();
182 QAbstractAxis* axis = i.key();
183 handleAxisRemoved(axis);
183 handleAxisRemoved(axis);
184 handleAxisAdded(axis,domain);
184 handleAxisAdded(axis,domain);
185 }
185 }
186
186
187 QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems);
187 QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems);
188 while (j.hasNext()) {
188 while (j.hasNext()) {
189 j.next();
189 j.next();
190 Domain* domain = j.value()->domain();
190 Domain* domain = j.value()->domain();
191 QAbstractSeries* series = j.key();
191 QAbstractSeries* series = j.key();
192 handleSeriesRemoved(series);
192 handleSeriesRemoved(series);
193 handleSeriesAdded(series,domain);
193 handleSeriesAdded(series,domain);
194 }
194 }
195 }
195 }
196
196
197 void ChartPresenter::zoomIn(qreal factor)
197 void ChartPresenter::zoomIn(qreal factor)
198 {
198 {
199 QRectF rect = geometry();
199 QRectF rect = geometry();
200 rect.setWidth(rect.width()/factor);
200 rect.setWidth(rect.width()/factor);
201 rect.setHeight(rect.height()/factor);
201 rect.setHeight(rect.height()/factor);
202 rect.moveCenter(geometry().center());
202 rect.moveCenter(geometry().center());
203 zoomIn(rect);
203 zoomIn(rect);
204 }
204 }
205
205
206 void ChartPresenter::zoomIn(const QRectF& rect)
206 void ChartPresenter::zoomIn(const QRectF& rect)
207 {
207 {
208 QRectF r = rect.normalized();
208 QRectF r = rect.normalized();
209 r.translate(-geometry().topLeft());
209 r.translate(-geometry().topLeft());
210 if (!r.isValid())
210 if (!r.isValid())
211 return;
211 return;
212
212
213 m_state = ZoomInState;
213 m_state = ZoomInState;
214 m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height());
214 m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height());
215 m_dataset->zoomInDomain(r,geometry().size());
215 m_dataset->zoomInDomain(r,geometry().size());
216 m_state = ShowState;
216 m_state = ShowState;
217 }
217 }
218
218
219 void ChartPresenter::zoomOut(qreal factor)
219 void ChartPresenter::zoomOut(qreal factor)
220 {
220 {
221 m_state = ZoomOutState;
221 m_state = ZoomOutState;
222
222
223 QRectF chartRect;
223 QRectF chartRect;
224 chartRect.setSize(geometry().size());
224 chartRect.setSize(geometry().size());
225
225
226 QRectF rect;
226 QRectF rect;
227 rect.setSize(chartRect.size()/factor);
227 rect.setSize(chartRect.size()/factor);
228 rect.moveCenter(chartRect.center());
228 rect.moveCenter(chartRect.center());
229 if (!rect.isValid())
229 if (!rect.isValid())
230 return;
230 return;
231 m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height());
231 m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height());
232 m_dataset->zoomOutDomain(rect, chartRect.size());
232 m_dataset->zoomOutDomain(rect, chartRect.size());
233 m_state = ShowState;
233 m_state = ShowState;
234 }
234 }
235
235
236 void ChartPresenter::scroll(qreal dx,qreal dy)
236 void ChartPresenter::scroll(qreal dx,qreal dy)
237 {
237 {
238 if(dx<0) m_state=ScrollLeftState;
238 if(dx<0) m_state=ScrollLeftState;
239 if(dx>0) m_state=ScrollRightState;
239 if(dx>0) m_state=ScrollRightState;
240 if(dy<0) m_state=ScrollUpState;
240 if(dy<0) m_state=ScrollUpState;
241 if(dy>0) m_state=ScrollDownState;
241 if(dy>0) m_state=ScrollDownState;
242
242
243 m_dataset->scrollDomain(dx,dy,geometry().size());
243 m_dataset->scrollDomain(dx,dy,geometry().size());
244 m_state = ShowState;
244 m_state = ShowState;
245 }
245 }
246
246
247 QChart::AnimationOptions ChartPresenter::animationOptions() const
247 QChart::AnimationOptions ChartPresenter::animationOptions() const
248 {
248 {
249 return m_options;
249 return m_options;
250 }
250 }
251
251
252 void ChartPresenter::createBackgroundItem()
252 void ChartPresenter::createBackgroundItem()
253 {
253 {
254 if (!m_backgroundItem) {
254 if (!m_backgroundItem) {
255 m_backgroundItem = new ChartBackground(rootItem());
255 m_backgroundItem = new ChartBackground(rootItem());
256 m_backgroundItem->setPen(Qt::NoPen);
256 m_backgroundItem->setPen(Qt::NoPen);
257 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
257 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
258 }
258 }
259 }
259 }
260
260
261 void ChartPresenter::createTitleItem()
261 void ChartPresenter::createTitleItem()
262 {
262 {
263 if (!m_titleItem) {
263 if (!m_titleItem) {
264 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
264 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
265 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
265 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
266 }
266 }
267 }
267 }
268
268
269
269
270 void ChartPresenter::handleAnimationFinished()
270 void ChartPresenter::handleAnimationFinished()
271 {
271 {
272 m_animations.removeAll(qobject_cast<ChartAnimation*>(sender()));
272 m_animations.removeAll(qobject_cast<ChartAnimation*>(sender()));
273 if(m_animations.empty()) emit animationsFinished();
273 if(m_animations.empty()) emit animationsFinished();
274 }
274 }
275
275
276 void ChartPresenter::startAnimation(ChartAnimation* animation)
276 void ChartPresenter::startAnimation(ChartAnimation* animation)
277 {
277 {
278 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
278 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
279 QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection);
279 QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection);
280 if(!m_animations.isEmpty()){
280 if(!m_animations.isEmpty()){
281 m_animations.append(animation);
281 m_animations.append(animation);
282 }
282 }
283 QTimer::singleShot(0, animation, SLOT(start()));
283 QTimer::singleShot(0, animation, SLOT(start()));
284 }
284 }
285
285
286 QGraphicsRectItem* ChartPresenter::backgroundItem()
286 QGraphicsRectItem* ChartPresenter::backgroundItem()
287 {
287 {
288 return m_backgroundItem;
288 return m_backgroundItem;
289 }
289 }
290
290
291 void ChartPresenter::setBackgroundBrush(const QBrush& brush)
291 void ChartPresenter::setBackgroundBrush(const QBrush& brush)
292 {
292 {
293 createBackgroundItem();
293 createBackgroundItem();
294 m_backgroundItem->setBrush(brush);
294 m_backgroundItem->setBrush(brush);
295 m_layout->invalidate();
295 m_layout->invalidate();
296 }
296 }
297
297
298 QBrush ChartPresenter::backgroundBrush() const
298 QBrush ChartPresenter::backgroundBrush() const
299 {
299 {
300 if (!m_backgroundItem) return QBrush();
300 if (!m_backgroundItem) return QBrush();
301 return m_backgroundItem->brush();
301 return m_backgroundItem->brush();
302 }
302 }
303
303
304 void ChartPresenter::setBackgroundPen(const QPen& pen)
304 void ChartPresenter::setBackgroundPen(const QPen& pen)
305 {
305 {
306 createBackgroundItem();
306 createBackgroundItem();
307 m_backgroundItem->setPen(pen);
307 m_backgroundItem->setPen(pen);
308 m_layout->invalidate();
308 m_layout->invalidate();
309 }
309 }
310
310
311 QPen ChartPresenter::backgroundPen() const
311 QPen ChartPresenter::backgroundPen() const
312 {
312 {
313 if (!m_backgroundItem) return QPen();
313 if (!m_backgroundItem) return QPen();
314 return m_backgroundItem->pen();
314 return m_backgroundItem->pen();
315 }
315 }
316
316
317 QGraphicsItem* ChartPresenter::titleItem()
317 QGraphicsItem* ChartPresenter::titleItem()
318 {
318 {
319 return m_titleItem;
319 return m_titleItem;
320 }
320 }
321
321
322 void ChartPresenter::setTitle(const QString& title)
322 void ChartPresenter::setTitle(const QString& title)
323 {
323 {
324 createTitleItem();
324 createTitleItem();
325 m_titleItem->setText(title);
325 m_titleItem->setText(title);
326 m_layout->invalidate();
326 m_layout->invalidate();
327 }
327 }
328
328
329 QString ChartPresenter::title() const
329 QString ChartPresenter::title() const
330 {
330 {
331 if (!m_titleItem) return QString();
331 if (!m_titleItem) return QString();
332 return m_titleItem->text();
332 return m_titleItem->text();
333 }
333 }
334
334
335 void ChartPresenter::setTitleFont(const QFont& font)
335 void ChartPresenter::setTitleFont(const QFont& font)
336 {
336 {
337 createTitleItem();
337 createTitleItem();
338 m_titleItem->setFont(font);
338 m_titleItem->setFont(font);
339 m_layout->invalidate();
339 m_layout->invalidate();
340 }
340 }
341
341
342 QFont ChartPresenter::titleFont() const
342 QFont ChartPresenter::titleFont() const
343 {
343 {
344 if (!m_titleItem) return QFont();
344 if (!m_titleItem) return QFont();
345 return m_titleItem->font();
345 return m_titleItem->font();
346 }
346 }
347
347
348 void ChartPresenter::setTitleBrush(const QBrush &brush)
348 void ChartPresenter::setTitleBrush(const QBrush &brush)
349 {
349 {
350 createTitleItem();
350 createTitleItem();
351 m_titleItem->setBrush(brush);
351 m_titleItem->setBrush(brush);
352 m_layout->invalidate();
352 m_layout->invalidate();
353 }
353 }
354
354
355 QBrush ChartPresenter::titleBrush() const
355 QBrush ChartPresenter::titleBrush() const
356 {
356 {
357 if (!m_titleItem) return QBrush();
357 if (!m_titleItem) return QBrush();
358 return m_titleItem->brush();
358 return m_titleItem->brush();
359 }
359 }
360
360
361 void ChartPresenter::setBackgroundVisible(bool visible)
361 void ChartPresenter::setBackgroundVisible(bool visible)
362 {
362 {
363 createBackgroundItem();
363 createBackgroundItem();
364 m_backgroundItem->setVisible(visible);
364 m_backgroundItem->setVisible(visible);
365 }
365 }
366
366
367
367
368 bool ChartPresenter::isBackgroundVisible() const
368 bool ChartPresenter::isBackgroundVisible() const
369 {
369 {
370 if (!m_backgroundItem) return false;
370 if (!m_backgroundItem) return false;
371 return m_backgroundItem->isVisible();
371 return m_backgroundItem->isVisible();
372 }
372 }
373
373
374 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
374 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
375 {
375 {
376 createBackgroundItem();
376 createBackgroundItem();
377 m_backgroundItem->setDropShadowEnabled(enabled);
377 m_backgroundItem->setDropShadowEnabled(enabled);
378 }
378 }
379
379
380 bool ChartPresenter::isBackgroundDropShadowEnabled() const
380 bool ChartPresenter::isBackgroundDropShadowEnabled() const
381 {
381 {
382 if (!m_backgroundItem) return false;
382 if (!m_backgroundItem) return false;
383 return m_backgroundItem->isDropShadowEnabled();
383 return m_backgroundItem->isDropShadowEnabled();
384 }
384 }
385
385
386
386
387 QGraphicsLayout* ChartPresenter::layout()
387 QGraphicsLayout* ChartPresenter::layout()
388 {
388 {
389 return m_layout;
389 return m_layout;
390 }
390 }
391
391
392 void ChartPresenter::setMarginsMinimum(const QRectF& margins)
392 void ChartPresenter::setMarginsMinimum(const QRectF& margins)
393 {
393 {
394 Q_UNUSED(margins);
394 Q_UNUSED(margins);
395 // m_layout->setMarginsMinimum(margins);
395 // m_layout->setMarginsMinimum(margins);
396 }
396 }
397
397
398 QRectF ChartPresenter::margins() const
398 QRectF ChartPresenter::margins() const
399 {
399 {
400 return QRectF();//m_layout->margins();
400 return QRectF();//m_layout->margins();
401 }
401 }
402
402
403 QLegend* ChartPresenter::legend()
403 QLegend* ChartPresenter::legend()
404 {
404 {
405 return m_chart->legend();
405 return m_chart->legend();
406 }
406 }
407
407
408 QList<ChartAxis*> ChartPresenter::axisItems() const
408 QList<ChartAxis*> ChartPresenter::axisItems() const
409 {
409 {
410 return m_axisItems.values();
410 return m_axisItems.values();
411 }
411 }
412
412
413 void ChartPresenter::setVisible(bool visible)
413 void ChartPresenter::setVisible(bool visible)
414 {
414 {
415 m_chart->setVisible(visible);
415 m_chart->setVisible(visible);
416 }
416 }
417
417
418 #include "moc_chartpresenter_p.cpp"
418 #include "moc_chartpresenter_p.cpp"
419
419
420 QTCOMMERCIALCHART_END_NAMESPACE
420 QTCOMMERCIALCHART_END_NAMESPACE
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now