##// END OF EJS Templates
Fix setting the axis title...
Titta Heikkala -
r2608:001bc2f70487
parent child
Show More
@@ -1,197 +1,198
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "cartesianchartaxis_p.h"
21 #include "cartesianchartaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "qabstractaxis_p.h"
23 #include "qabstractaxis_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractchartlayout_p.h"
25 #include "abstractchartlayout_p.h"
26 #include "abstractdomain_p.h"
26 #include "abstractdomain_p.h"
27 #include "linearrowitem_p.h"
27 #include "linearrowitem_p.h"
28 #include <QValueAxis>
28 #include <QValueAxis>
29 #include <QLogValueAxis>
29 #include <QLogValueAxis>
30 #include <QGraphicsLayout>
30 #include <QGraphicsLayout>
31 #include <QTextDocument>
31 #include <QTextDocument>
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 CartesianChartAxis::CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item , bool intervalAxis)
35 CartesianChartAxis::CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item , bool intervalAxis)
36 : ChartAxisElement(axis, item, intervalAxis)
36 : ChartAxisElement(axis, item, intervalAxis)
37 {
37 {
38 Q_ASSERT(item);
38 Q_ASSERT(item);
39 }
39 }
40
40
41
41
42 CartesianChartAxis::~CartesianChartAxis()
42 CartesianChartAxis::~CartesianChartAxis()
43 {
43 {
44 }
44 }
45
45
46 void CartesianChartAxis::createItems(int count)
46 void CartesianChartAxis::createItems(int count)
47 {
47 {
48 if (arrowItems().size() == 0) {
48 if (arrowItems().size() == 0) {
49 QGraphicsLineItem *arrow = new LineArrowItem(this, this);
49 QGraphicsLineItem *arrow = new LineArrowItem(this, this);
50 arrow->setPen(axis()->linePen());
50 arrow->setPen(axis()->linePen());
51 arrowGroup()->addToGroup(arrow);
51 arrowGroup()->addToGroup(arrow);
52 }
52 }
53
53
54 if (intervalAxis() && gridItems().size() == 0) {
54 if (intervalAxis() && gridItems().size() == 0) {
55 for (int i = 0 ; i < 2 ; i ++){
55 for (int i = 0 ; i < 2 ; i ++){
56 QGraphicsLineItem *item = new QGraphicsLineItem(this);
56 QGraphicsLineItem *item = new QGraphicsLineItem(this);
57 item->setPen(axis()->gridLinePen());
57 item->setPen(axis()->gridLinePen());
58 gridGroup()->addToGroup(item);
58 gridGroup()->addToGroup(item);
59 }
59 }
60 }
60 }
61
61
62 QGraphicsTextItem *title = titleItem();
63 title->setFont(axis()->titleFont());
64 title->setDefaultTextColor(axis()->titleBrush().color());
65 title->setHtml(axis()->titleText());
66
62 for (int i = 0; i < count; ++i) {
67 for (int i = 0; i < count; ++i) {
63 QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
68 QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
64 QGraphicsLineItem *grid = new QGraphicsLineItem(this);
69 QGraphicsLineItem *grid = new QGraphicsLineItem(this);
65 QGraphicsTextItem *label = new QGraphicsTextItem(this);
70 QGraphicsTextItem *label = new QGraphicsTextItem(this);
66 label->document()->setDocumentMargin(ChartPresenter::textMargin());
71 label->document()->setDocumentMargin(ChartPresenter::textMargin());
67 QGraphicsTextItem *title = titleItem();
68 arrow->setPen(axis()->linePen());
72 arrow->setPen(axis()->linePen());
69 grid->setPen(axis()->gridLinePen());
73 grid->setPen(axis()->gridLinePen());
70 label->setFont(axis()->labelsFont());
74 label->setFont(axis()->labelsFont());
71 label->setDefaultTextColor(axis()->labelsBrush().color());
75 label->setDefaultTextColor(axis()->labelsBrush().color());
72 label->setRotation(axis()->labelsAngle());
76 label->setRotation(axis()->labelsAngle());
73 title->setFont(axis()->titleFont());
74 title->setDefaultTextColor(axis()->titleBrush().color());
75 title->setHtml(axis()->titleText());
76 arrowGroup()->addToGroup(arrow);
77 arrowGroup()->addToGroup(arrow);
77 gridGroup()->addToGroup(grid);
78 gridGroup()->addToGroup(grid);
78 labelGroup()->addToGroup(label);
79 labelGroup()->addToGroup(label);
79
80
80 if ((gridItems().size()) % 2 && gridItems().size() > 2) {
81 if ((gridItems().size()) % 2 && gridItems().size() > 2) {
81 QGraphicsRectItem* shades = new QGraphicsRectItem(this);
82 QGraphicsRectItem* shades = new QGraphicsRectItem(this);
82 shades->setPen(axis()->shadesPen());
83 shades->setPen(axis()->shadesPen());
83 shades->setBrush(axis()->shadesBrush());
84 shades->setBrush(axis()->shadesBrush());
84 shadeGroup()->addToGroup(shades);
85 shadeGroup()->addToGroup(shades);
85 }
86 }
86 }
87 }
87
88
88 }
89 }
89
90
90 void CartesianChartAxis::deleteItems(int count)
91 void CartesianChartAxis::deleteItems(int count)
91 {
92 {
92 QList<QGraphicsItem *> lines = gridItems();
93 QList<QGraphicsItem *> lines = gridItems();
93 QList<QGraphicsItem *> labels = labelItems();
94 QList<QGraphicsItem *> labels = labelItems();
94 QList<QGraphicsItem *> shades = shadeItems();
95 QList<QGraphicsItem *> shades = shadeItems();
95 QList<QGraphicsItem *> axis = arrowItems();
96 QList<QGraphicsItem *> axis = arrowItems();
96
97
97 for (int i = 0; i < count; ++i) {
98 for (int i = 0; i < count; ++i) {
98 if (lines.size() % 2 && lines.size() > 1)
99 if (lines.size() % 2 && lines.size() > 1)
99 delete(shades.takeLast());
100 delete(shades.takeLast());
100 delete(lines.takeLast());
101 delete(lines.takeLast());
101 delete(labels.takeLast());
102 delete(labels.takeLast());
102 delete(axis.takeLast());
103 delete(axis.takeLast());
103 }
104 }
104 }
105 }
105
106
106 void CartesianChartAxis::updateLayout(QVector<qreal> &layout)
107 void CartesianChartAxis::updateLayout(QVector<qreal> &layout)
107 {
108 {
108 int diff = ChartAxisElement::layout().size() - layout.size();
109 int diff = ChartAxisElement::layout().size() - layout.size();
109
110
110 if (diff > 0)
111 if (diff > 0)
111 deleteItems(diff);
112 deleteItems(diff);
112 else if (diff < 0)
113 else if (diff < 0)
113 createItems(-diff);
114 createItems(-diff);
114
115
115 if (animation()) {
116 if (animation()) {
116 switch (presenter()->state()) {
117 switch (presenter()->state()) {
117 case ChartPresenter::ZoomInState:
118 case ChartPresenter::ZoomInState:
118 animation()->setAnimationType(AxisAnimation::ZoomInAnimation);
119 animation()->setAnimationType(AxisAnimation::ZoomInAnimation);
119 animation()->setAnimationPoint(presenter()->statePoint());
120 animation()->setAnimationPoint(presenter()->statePoint());
120 break;
121 break;
121 case ChartPresenter::ZoomOutState:
122 case ChartPresenter::ZoomOutState:
122 animation()->setAnimationType(AxisAnimation::ZoomOutAnimation);
123 animation()->setAnimationType(AxisAnimation::ZoomOutAnimation);
123 animation()->setAnimationPoint(presenter()->statePoint());
124 animation()->setAnimationPoint(presenter()->statePoint());
124 break;
125 break;
125 case ChartPresenter::ScrollUpState:
126 case ChartPresenter::ScrollUpState:
126 case ChartPresenter::ScrollLeftState:
127 case ChartPresenter::ScrollLeftState:
127 animation()->setAnimationType(AxisAnimation::MoveBackwordAnimation);
128 animation()->setAnimationType(AxisAnimation::MoveBackwordAnimation);
128 break;
129 break;
129 case ChartPresenter::ScrollDownState:
130 case ChartPresenter::ScrollDownState:
130 case ChartPresenter::ScrollRightState:
131 case ChartPresenter::ScrollRightState:
131 animation()->setAnimationType(AxisAnimation::MoveForwardAnimation);
132 animation()->setAnimationType(AxisAnimation::MoveForwardAnimation);
132 break;
133 break;
133 case ChartPresenter::ShowState:
134 case ChartPresenter::ShowState:
134 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
135 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
135 break;
136 break;
136 }
137 }
137 animation()->setValues(ChartAxisElement::layout(), layout);
138 animation()->setValues(ChartAxisElement::layout(), layout);
138 presenter()->startAnimation(animation());
139 presenter()->startAnimation(animation());
139 } else {
140 } else {
140 setLayout(layout);
141 setLayout(layout);
141 updateGeometry();
142 updateGeometry();
142 }
143 }
143 }
144 }
144
145
145 bool CartesianChartAxis::isEmpty()
146 bool CartesianChartAxis::isEmpty()
146 {
147 {
147 return axisGeometry().isEmpty()
148 return axisGeometry().isEmpty()
148 || gridGeometry().isEmpty()
149 || gridGeometry().isEmpty()
149 || qFuzzyCompare(min(), max());
150 || qFuzzyCompare(min(), max());
150 }
151 }
151
152
152 void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
153 void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
153 {
154 {
154 m_gridRect = grid;
155 m_gridRect = grid;
155 setAxisGeometry(axis);
156 setAxisGeometry(axis);
156
157
157 if (isEmpty())
158 if (isEmpty())
158 return;
159 return;
159
160
160 QVector<qreal> layout = calculateLayout();
161 QVector<qreal> layout = calculateLayout();
161 updateLayout(layout);
162 updateLayout(layout);
162 }
163 }
163
164
164 QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
165 QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
165 {
166 {
166 Q_UNUSED(which);
167 Q_UNUSED(which);
167 Q_UNUSED(constraint);
168 Q_UNUSED(constraint);
168 return QSizeF();
169 return QSizeF();
169 }
170 }
170
171
171 void CartesianChartAxis::handleArrowPenChanged(const QPen &pen)
172 void CartesianChartAxis::handleArrowPenChanged(const QPen &pen)
172 {
173 {
173 foreach (QGraphicsItem *item, arrowItems())
174 foreach (QGraphicsItem *item, arrowItems())
174 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
175 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
175 }
176 }
176
177
177 void CartesianChartAxis::handleGridPenChanged(const QPen &pen)
178 void CartesianChartAxis::handleGridPenChanged(const QPen &pen)
178 {
179 {
179 foreach (QGraphicsItem *item, gridItems())
180 foreach (QGraphicsItem *item, gridItems())
180 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
181 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
181 }
182 }
182
183
183 void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush)
184 void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush)
184 {
185 {
185 foreach (QGraphicsItem *item, shadeItems())
186 foreach (QGraphicsItem *item, shadeItems())
186 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
187 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
187 }
188 }
188
189
189 void CartesianChartAxis::handleShadesPenChanged(const QPen &pen)
190 void CartesianChartAxis::handleShadesPenChanged(const QPen &pen)
190 {
191 {
191 foreach (QGraphicsItem *item, shadeItems())
192 foreach (QGraphicsItem *item, shadeItems())
192 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
193 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
193 }
194 }
194
195
195 #include "moc_cartesianchartaxis_p.cpp"
196 #include "moc_cartesianchartaxis_p.cpp"
196
197
197 QTCOMMERCIALCHART_END_NAMESPACE
198 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,354 +1,355
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "chartaxiselement_p.h"
21 #include "chartaxiselement_p.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "abstractchartlayout_p.h"
24 #include "abstractchartlayout_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDateTime>
26 #include <QDateTime>
27 #include <QTextDocument>
27 #include <QTextDocument>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])";
31 static const char *labelFormatMatchString = "%[\\-\\+#\\s\\d\\.lhjztL]*([dicuoxfegXFEG])";
32 static QRegExp *labelFormatMatcher = 0;
32 static QRegExp *labelFormatMatcher = 0;
33 class StaticLabelFormatMatcherDeleter
33 class StaticLabelFormatMatcherDeleter
34 {
34 {
35 public:
35 public:
36 StaticLabelFormatMatcherDeleter() {}
36 StaticLabelFormatMatcherDeleter() {}
37 ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; }
37 ~StaticLabelFormatMatcherDeleter() { delete labelFormatMatcher; }
38 };
38 };
39 static StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter;
39 static StaticLabelFormatMatcherDeleter staticLabelFormatMatcherDeleter;
40
40
41 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
41 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
42 : ChartElement(item),
42 : ChartElement(item),
43 m_axis(axis),
43 m_axis(axis),
44 m_animation(0),
44 m_animation(0),
45 m_grid(new QGraphicsItemGroup(item)),
45 m_grid(new QGraphicsItemGroup(item)),
46 m_arrow(new QGraphicsItemGroup(item)),
46 m_arrow(new QGraphicsItemGroup(item)),
47 m_shades(new QGraphicsItemGroup(item)),
47 m_shades(new QGraphicsItemGroup(item)),
48 m_labels(new QGraphicsItemGroup(item)),
48 m_labels(new QGraphicsItemGroup(item)),
49 m_title(new QGraphicsTextItem(item)),
49 m_title(new QGraphicsTextItem(item)),
50 m_intervalAxis(intervalAxis)
50 m_intervalAxis(intervalAxis)
51
51
52 {
52 {
53 //initial initialization
53 //initial initialization
54 m_arrow->setHandlesChildEvents(false);
54 m_arrow->setHandlesChildEvents(false);
55 m_arrow->setZValue(ChartPresenter::AxisZValue);
55 m_arrow->setZValue(ChartPresenter::AxisZValue);
56 m_labels->setZValue(ChartPresenter::AxisZValue);
56 m_labels->setZValue(ChartPresenter::AxisZValue);
57 m_shades->setZValue(ChartPresenter::ShadesZValue);
57 m_shades->setZValue(ChartPresenter::ShadesZValue);
58 m_grid->setZValue(ChartPresenter::GridZValue);
58 m_grid->setZValue(ChartPresenter::GridZValue);
59 m_title->setZValue(ChartPresenter::GridZValue);
59 m_title->setZValue(ChartPresenter::GridZValue);
60 m_title->document()->setDocumentMargin(ChartPresenter::textMargin());
60 m_title->document()->setDocumentMargin(ChartPresenter::textMargin());
61 handleVisibleChanged(axis->isVisible());
61 handleVisibleChanged(axis->isVisible());
62 connectSlots();
62 connectSlots();
63
63
64 setFlag(QGraphicsItem::ItemHasNoContents, true);
64 setFlag(QGraphicsItem::ItemHasNoContents, true);
65 }
65 }
66
66
67 ChartAxisElement::~ChartAxisElement()
67 ChartAxisElement::~ChartAxisElement()
68 {
68 {
69 }
69 }
70
70
71 void ChartAxisElement::connectSlots()
71 void ChartAxisElement::connectSlots()
72 {
72 {
73 QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool)));
73 QObject::connect(axis(), SIGNAL(visibleChanged(bool)), this, SLOT(handleVisibleChanged(bool)));
74 QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool)));
74 QObject::connect(axis(), SIGNAL(lineVisibleChanged(bool)), this, SLOT(handleArrowVisibleChanged(bool)));
75 QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool)));
75 QObject::connect(axis(), SIGNAL(gridVisibleChanged(bool)), this, SLOT(handleGridVisibleChanged(bool)));
76 QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
76 QObject::connect(axis(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
77 QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool)));
77 QObject::connect(axis(), SIGNAL(shadesVisibleChanged(bool)), this, SLOT(handleShadesVisibleChanged(bool)));
78 QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int)));
78 QObject::connect(axis(), SIGNAL(labelsAngleChanged(int)), this, SLOT(handleLabelsAngleChanged(int)));
79 QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&)));
79 QObject::connect(axis(), SIGNAL(linePenChanged(const QPen&)), this, SLOT(handleArrowPenChanged(const QPen&)));
80 QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&)));
80 QObject::connect(axis(), SIGNAL(labelsPenChanged(const QPen&)), this, SLOT(handleLabelsPenChanged(const QPen&)));
81 QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&)));
81 QObject::connect(axis(), SIGNAL(labelsBrushChanged(const QBrush&)), this, SLOT(handleLabelsBrushChanged(const QBrush&)));
82 QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&)));
82 QObject::connect(axis(), SIGNAL(labelsFontChanged(const QFont&)), this, SLOT(handleLabelsFontChanged(const QFont&)));
83 QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&)));
83 QObject::connect(axis(), SIGNAL(gridLinePenChanged(const QPen&)), this, SLOT(handleGridPenChanged(const QPen&)));
84 QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&)));
84 QObject::connect(axis(), SIGNAL(shadesPenChanged(const QPen&)), this, SLOT(handleShadesPenChanged(const QPen&)));
85 QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&)));
85 QObject::connect(axis(), SIGNAL(shadesBrushChanged(const QBrush&)), this, SLOT(handleShadesBrushChanged(const QBrush&)));
86 QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&)));
86 QObject::connect(axis(), SIGNAL(titleTextChanged(const QString&)), this, SLOT(handleTitleTextChanged(const QString&)));
87 QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&)));
87 QObject::connect(axis(), SIGNAL(titleFontChanged(const QFont&)), this, SLOT(handleTitleFontChanged(const QFont&)));
88 QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&)));
88 QObject::connect(axis(), SIGNAL(titlePenChanged(const QPen&)), this, SLOT(handleTitlePenChanged(const QPen&)));
89 QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&)));
89 QObject::connect(axis(), SIGNAL(titleBrushChanged(const QBrush&)), this, SLOT(handleTitleBrushChanged(const QBrush&)));
90 QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool)));
90 QObject::connect(axis(), SIGNAL(titleVisibleChanged(bool)), this, SLOT(handleTitleVisibleChanged(bool)));
91 QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal)));
91 QObject::connect(axis()->d_ptr.data(), SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(handleRangeChanged(qreal, qreal)));
92 }
92 }
93
93
94 void ChartAxisElement::handleArrowVisibleChanged(bool visible)
94 void ChartAxisElement::handleArrowVisibleChanged(bool visible)
95 {
95 {
96 m_arrow->setVisible(visible);
96 m_arrow->setVisible(visible);
97 }
97 }
98
98
99 void ChartAxisElement::handleGridVisibleChanged(bool visible)
99 void ChartAxisElement::handleGridVisibleChanged(bool visible)
100 {
100 {
101 m_grid->setVisible(visible);
101 m_grid->setVisible(visible);
102 }
102 }
103
103
104 void ChartAxisElement::handleLabelsVisibleChanged(bool visible)
104 void ChartAxisElement::handleLabelsVisibleChanged(bool visible)
105 {
105 {
106 QGraphicsLayoutItem::updateGeometry();
106 QGraphicsLayoutItem::updateGeometry();
107 presenter()->layout()->invalidate();
107 presenter()->layout()->invalidate();
108 m_labels->setVisible(visible);
108 m_labels->setVisible(visible);
109 }
109 }
110
110
111 void ChartAxisElement::handleShadesVisibleChanged(bool visible)
111 void ChartAxisElement::handleShadesVisibleChanged(bool visible)
112 {
112 {
113 m_shades->setVisible(visible);
113 m_shades->setVisible(visible);
114 }
114 }
115
115
116 void ChartAxisElement::handleTitleVisibleChanged(bool visible)
116 void ChartAxisElement::handleTitleVisibleChanged(bool visible)
117 {
117 {
118 QGraphicsLayoutItem::updateGeometry();
118 QGraphicsLayoutItem::updateGeometry();
119 presenter()->layout()->invalidate();
119 presenter()->layout()->invalidate();
120 m_title->setVisible(visible);
120 m_title->setVisible(visible);
121 }
121 }
122
122
123 void ChartAxisElement::handleLabelsAngleChanged(int angle)
123 void ChartAxisElement::handleLabelsAngleChanged(int angle)
124 {
124 {
125 foreach (QGraphicsItem *item, m_labels->childItems())
125 foreach (QGraphicsItem *item, m_labels->childItems())
126 item->setRotation(angle);
126 item->setRotation(angle);
127
127
128 QGraphicsLayoutItem::updateGeometry();
128 QGraphicsLayoutItem::updateGeometry();
129 presenter()->layout()->invalidate();
129 presenter()->layout()->invalidate();
130 }
130 }
131
131
132 void ChartAxisElement::handleLabelsPenChanged(const QPen &pen)
132 void ChartAxisElement::handleLabelsPenChanged(const QPen &pen)
133 {
133 {
134 Q_UNUSED(pen)
134 Q_UNUSED(pen)
135 }
135 }
136
136
137 void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush)
137 void ChartAxisElement::handleLabelsBrushChanged(const QBrush &brush)
138 {
138 {
139 foreach (QGraphicsItem *item, m_labels->childItems())
139 foreach (QGraphicsItem *item, m_labels->childItems())
140 static_cast<QGraphicsTextItem *>(item)->setDefaultTextColor(brush.color());
140 static_cast<QGraphicsTextItem *>(item)->setDefaultTextColor(brush.color());
141 }
141 }
142
142
143 void ChartAxisElement::handleLabelsFontChanged(const QFont &font)
143 void ChartAxisElement::handleLabelsFontChanged(const QFont &font)
144 {
144 {
145 foreach (QGraphicsItem *item, m_labels->childItems())
145 foreach (QGraphicsItem *item, m_labels->childItems())
146 static_cast<QGraphicsTextItem *>(item)->setFont(font);
146 static_cast<QGraphicsTextItem *>(item)->setFont(font);
147 QGraphicsLayoutItem::updateGeometry();
147 QGraphicsLayoutItem::updateGeometry();
148 presenter()->layout()->invalidate();
148 presenter()->layout()->invalidate();
149 }
149 }
150
150
151 void ChartAxisElement::handleTitleTextChanged(const QString &title)
151 void ChartAxisElement::handleTitleTextChanged(const QString &title)
152 {
152 {
153 QGraphicsLayoutItem::updateGeometry();
153 QGraphicsLayoutItem::updateGeometry();
154 presenter()->layout()->invalidate();
154 presenter()->layout()->invalidate();
155 m_title->setHtml(title);
155 if (title.isEmpty() || !m_title->isVisible())
156 m_title->setHtml(title);
156 }
157 }
157
158
158 void ChartAxisElement::handleTitlePenChanged(const QPen &pen)
159 void ChartAxisElement::handleTitlePenChanged(const QPen &pen)
159 {
160 {
160 Q_UNUSED(pen)
161 Q_UNUSED(pen)
161 }
162 }
162
163
163 void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush)
164 void ChartAxisElement::handleTitleBrushChanged(const QBrush &brush)
164 {
165 {
165 m_title->setDefaultTextColor(brush.color());
166 m_title->setDefaultTextColor(brush.color());
166 }
167 }
167
168
168 void ChartAxisElement::handleTitleFontChanged(const QFont &font)
169 void ChartAxisElement::handleTitleFontChanged(const QFont &font)
169 {
170 {
170 if (m_title->font() != font) {
171 if (m_title->font() != font) {
171 m_title->setFont(font);
172 m_title->setFont(font);
172 QGraphicsLayoutItem::updateGeometry();
173 QGraphicsLayoutItem::updateGeometry();
173 presenter()->layout()->invalidate();
174 presenter()->layout()->invalidate();
174 }
175 }
175 }
176 }
176
177
177 void ChartAxisElement::handleVisibleChanged(bool visible)
178 void ChartAxisElement::handleVisibleChanged(bool visible)
178 {
179 {
179 setVisible(visible);
180 setVisible(visible);
180 if (!visible) {
181 if (!visible) {
181 m_grid->setVisible(visible);
182 m_grid->setVisible(visible);
182 m_arrow->setVisible(visible);
183 m_arrow->setVisible(visible);
183 m_shades->setVisible(visible);
184 m_shades->setVisible(visible);
184 m_labels->setVisible(visible);
185 m_labels->setVisible(visible);
185 m_title->setVisible(visible);
186 m_title->setVisible(visible);
186 } else {
187 } else {
187 m_grid->setVisible(axis()->isGridLineVisible());
188 m_grid->setVisible(axis()->isGridLineVisible());
188 m_arrow->setVisible(axis()->isLineVisible());
189 m_arrow->setVisible(axis()->isLineVisible());
189 m_shades->setVisible(axis()->shadesVisible());
190 m_shades->setVisible(axis()->shadesVisible());
190 m_labels->setVisible(axis()->labelsVisible());
191 m_labels->setVisible(axis()->labelsVisible());
191 m_title->setVisible(axis()->isTitleVisible());
192 m_title->setVisible(axis()->isTitleVisible());
192 }
193 }
193
194
194 if (presenter()) presenter()->layout()->invalidate();
195 if (presenter()) presenter()->layout()->invalidate();
195 }
196 }
196
197
197 void ChartAxisElement::handleRangeChanged(qreal min, qreal max)
198 void ChartAxisElement::handleRangeChanged(qreal min, qreal max)
198 {
199 {
199 Q_UNUSED(min);
200 Q_UNUSED(min);
200 Q_UNUSED(max);
201 Q_UNUSED(max);
201
202
202 if (!isEmpty()) {
203 if (!isEmpty()) {
203 QVector<qreal> layout = calculateLayout();
204 QVector<qreal> layout = calculateLayout();
204 updateLayout(layout);
205 updateLayout(layout);
205 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
206 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
206 QSizeF after = sizeHint(Qt::PreferredSize);
207 QSizeF after = sizeHint(Qt::PreferredSize);
207
208
208 if (before != after) {
209 if (before != after) {
209 QGraphicsLayoutItem::updateGeometry();
210 QGraphicsLayoutItem::updateGeometry();
210 // We don't want to call invalidate on layout, since it will change minimum size of
211 // We don't want to call invalidate on layout, since it will change minimum size of
211 // component, which we would like to avoid since it causes nasty flips when scrolling
212 // component, which we would like to avoid since it causes nasty flips when scrolling
212 // or zooming, instead recalculate layout and use plotArea for extra space.
213 // or zooming, instead recalculate layout and use plotArea for extra space.
213 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
214 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
214 }
215 }
215 }
216 }
216 }
217 }
217
218
218 bool ChartAxisElement::isEmpty()
219 bool ChartAxisElement::isEmpty()
219 {
220 {
220 return axisGeometry().isEmpty()
221 return axisGeometry().isEmpty()
221 || gridGeometry().isEmpty()
222 || gridGeometry().isEmpty()
222 || qFuzzyCompare(min(), max());
223 || qFuzzyCompare(min(), max());
223 }
224 }
224
225
225 qreal ChartAxisElement::min() const
226 qreal ChartAxisElement::min() const
226 {
227 {
227 return m_axis->d_ptr->min();
228 return m_axis->d_ptr->min();
228 }
229 }
229
230
230 qreal ChartAxisElement::max() const
231 qreal ChartAxisElement::max() const
231 {
232 {
232 return m_axis->d_ptr->max();
233 return m_axis->d_ptr->max();
233 }
234 }
234
235
235 static void appendFormattedLabel(const QString &capStr, const QByteArray &array,
236 static void appendFormattedLabel(const QString &capStr, const QByteArray &array,
236 QStringList &labels, qreal value)
237 QStringList &labels, qreal value)
237 {
238 {
238 if (capStr.isEmpty()) {
239 if (capStr.isEmpty()) {
239 labels << QString();
240 labels << QString();
240 } else if (capStr.at(0) == QLatin1Char('d')
241 } else if (capStr.at(0) == QLatin1Char('d')
241 || capStr.at(0) == QLatin1Char('i')
242 || capStr.at(0) == QLatin1Char('i')
242 || capStr.at(0) == QLatin1Char('c')) {
243 || capStr.at(0) == QLatin1Char('c')) {
243 labels << QString().sprintf(array, (qint64)value);
244 labels << QString().sprintf(array, (qint64)value);
244 } else if (capStr.at(0) == QLatin1Char('u')
245 } else if (capStr.at(0) == QLatin1Char('u')
245 || capStr.at(0) == QLatin1Char('o')
246 || capStr.at(0) == QLatin1Char('o')
246 || capStr.at(0) == QLatin1Char('x')
247 || capStr.at(0) == QLatin1Char('x')
247 || capStr.at(0) == QLatin1Char('X')) {
248 || capStr.at(0) == QLatin1Char('X')) {
248 labels << QString().sprintf(array, (quint64)value);
249 labels << QString().sprintf(array, (quint64)value);
249 } else if (capStr.at(0) == QLatin1Char('f')
250 } else if (capStr.at(0) == QLatin1Char('f')
250 || capStr.at(0) == QLatin1Char('F')
251 || capStr.at(0) == QLatin1Char('F')
251 || capStr.at(0) == QLatin1Char('e')
252 || capStr.at(0) == QLatin1Char('e')
252 || capStr.at(0) == QLatin1Char('E')
253 || capStr.at(0) == QLatin1Char('E')
253 || capStr.at(0) == QLatin1Char('g')
254 || capStr.at(0) == QLatin1Char('g')
254 || capStr.at(0) == QLatin1Char('G')) {
255 || capStr.at(0) == QLatin1Char('G')) {
255 labels << QString().sprintf(array, value);
256 labels << QString().sprintf(array, value);
256 } else {
257 } else {
257 labels << QString();
258 labels << QString();
258 }
259 }
259 }
260 }
260
261
261 QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format)
262 QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, const QString &format)
262 {
263 {
263 QStringList labels;
264 QStringList labels;
264
265
265 if (max <= min || ticks < 1)
266 if (max <= min || ticks < 1)
266 return labels;
267 return labels;
267
268
268 int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
269 int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
269 n++;
270 n++;
270
271
271 if (format.isNull()) {
272 if (format.isNull()) {
272 for (int i = 0; i < ticks; i++) {
273 for (int i = 0; i < ticks; i++) {
273 qreal value = min + (i * (max - min) / (ticks - 1));
274 qreal value = min + (i * (max - min) / (ticks - 1));
274 labels << QString::number(value, 'f', n);
275 labels << QString::number(value, 'f', n);
275 }
276 }
276 } else {
277 } else {
277 QByteArray array = format.toLatin1();
278 QByteArray array = format.toLatin1();
278 QString capStr;
279 QString capStr;
279 if (!labelFormatMatcher)
280 if (!labelFormatMatcher)
280 labelFormatMatcher = new QRegExp(labelFormatMatchString);
281 labelFormatMatcher = new QRegExp(labelFormatMatchString);
281 if (labelFormatMatcher->indexIn(format, 0) != -1)
282 if (labelFormatMatcher->indexIn(format, 0) != -1)
282 capStr = labelFormatMatcher->cap(1);
283 capStr = labelFormatMatcher->cap(1);
283 for (int i = 0; i < ticks; i++) {
284 for (int i = 0; i < ticks; i++) {
284 qreal value = min + (i * (max - min) / (ticks - 1));
285 qreal value = min + (i * (max - min) / (ticks - 1));
285 appendFormattedLabel(capStr, array, labels, value);
286 appendFormattedLabel(capStr, array, labels, value);
286 }
287 }
287 }
288 }
288
289
289 return labels;
290 return labels;
290 }
291 }
291
292
292 QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format)
293 QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format)
293 {
294 {
294 QStringList labels;
295 QStringList labels;
295
296
296 if (max <= min || ticks < 1)
297 if (max <= min || ticks < 1)
297 return labels;
298 return labels;
298
299
299 int n = 0;
300 int n = 0;
300 if (ticks > 1)
301 if (ticks > 1)
301 n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
302 n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
302 n++;
303 n++;
303
304
304 int firstTick;
305 int firstTick;
305 if (base > 1)
306 if (base > 1)
306 firstTick = ceil(log10(min) / log10(base));
307 firstTick = ceil(log10(min) / log10(base));
307 else
308 else
308 firstTick = ceil(log10(max) / log10(base));
309 firstTick = ceil(log10(max) / log10(base));
309
310
310 if (format.isNull()) {
311 if (format.isNull()) {
311 for (int i = firstTick; i < ticks + firstTick; i++) {
312 for (int i = firstTick; i < ticks + firstTick; i++) {
312 qreal value = qPow(base, i);
313 qreal value = qPow(base, i);
313 labels << QString::number(value, 'f', n);
314 labels << QString::number(value, 'f', n);
314 }
315 }
315 } else {
316 } else {
316 QByteArray array = format.toLatin1();
317 QByteArray array = format.toLatin1();
317 QString capStr;
318 QString capStr;
318 if (!labelFormatMatcher)
319 if (!labelFormatMatcher)
319 labelFormatMatcher = new QRegExp(labelFormatMatchString);
320 labelFormatMatcher = new QRegExp(labelFormatMatchString);
320 if (labelFormatMatcher->indexIn(format, 0) != -1)
321 if (labelFormatMatcher->indexIn(format, 0) != -1)
321 capStr = labelFormatMatcher->cap(1);
322 capStr = labelFormatMatcher->cap(1);
322 for (int i = firstTick; i < ticks + firstTick; i++) {
323 for (int i = firstTick; i < ticks + firstTick; i++) {
323 qreal value = qPow(base, i);
324 qreal value = qPow(base, i);
324 appendFormattedLabel(capStr, array, labels, value);
325 appendFormattedLabel(capStr, array, labels, value);
325 }
326 }
326 }
327 }
327
328
328 return labels;
329 return labels;
329 }
330 }
330
331
331 QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks,const QString &format)
332 QStringList ChartAxisElement::createDateTimeLabels(qreal min, qreal max,int ticks,const QString &format)
332 {
333 {
333 QStringList labels;
334 QStringList labels;
334
335
335 if (max <= min || ticks < 1)
336 if (max <= min || ticks < 1)
336 return labels;
337 return labels;
337
338
338 int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0);
339 int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0);
339 n++;
340 n++;
340 for (int i = 0; i < ticks; i++) {
341 for (int i = 0; i < ticks; i++) {
341 qreal value = min + (i * (max - min) / (ticks - 1));
342 qreal value = min + (i * (max - min) / (ticks - 1));
342 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
343 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
343 }
344 }
344 return labels;
345 return labels;
345 }
346 }
346
347
347 void ChartAxisElement::axisSelected()
348 void ChartAxisElement::axisSelected()
348 {
349 {
349 emit clicked();
350 emit clicked();
350 }
351 }
351
352
352 #include "moc_chartaxiselement_p.cpp"
353 #include "moc_chartaxiselement_p.cpp"
353
354
354 QTCOMMERCIALCHART_END_NAMESPACE
355 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,431 +1,432
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "polarchartaxisangular_p.h"
21 #include "polarchartaxisangular_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qabstractaxis_p.h"
25 #include "qabstractaxis_p.h"
26 #include <QDebug>
26 #include <QDebug>
27 #include <qmath.h>
27 #include <qmath.h>
28 #include <QTextDocument>
28 #include <QTextDocument>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 PolarChartAxisAngular::PolarChartAxisAngular(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
32 PolarChartAxisAngular::PolarChartAxisAngular(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
33 : PolarChartAxis(axis, item, intervalAxis)
33 : PolarChartAxis(axis, item, intervalAxis)
34 {
34 {
35 }
35 }
36
36
37 PolarChartAxisAngular::~PolarChartAxisAngular()
37 PolarChartAxisAngular::~PolarChartAxisAngular()
38 {
38 {
39 }
39 }
40
40
41 void PolarChartAxisAngular::updateGeometry()
41 void PolarChartAxisAngular::updateGeometry()
42 {
42 {
43 QGraphicsLayoutItem::updateGeometry();
43 QGraphicsLayoutItem::updateGeometry();
44
44
45 const QVector<qreal> &layout = this->layout();
45 const QVector<qreal> &layout = this->layout();
46 if (layout.isEmpty())
46 if (layout.isEmpty())
47 return;
47 return;
48
48
49 createAxisLabels(layout);
49 createAxisLabels(layout);
50 QStringList labelList = labels();
50 QStringList labelList = labels();
51 QPointF center = axisGeometry().center();
51 QPointF center = axisGeometry().center();
52 QList<QGraphicsItem *> arrowItemList = arrowItems();
52 QList<QGraphicsItem *> arrowItemList = arrowItems();
53 QList<QGraphicsItem *> gridItemList = gridItems();
53 QList<QGraphicsItem *> gridItemList = gridItems();
54 QList<QGraphicsItem *> labelItemList = labelItems();
54 QList<QGraphicsItem *> labelItemList = labelItems();
55 QList<QGraphicsItem *> shadeItemList = shadeItems();
55 QList<QGraphicsItem *> shadeItemList = shadeItems();
56 QGraphicsTextItem *title = titleItem();
56 QGraphicsTextItem *title = titleItem();
57
57
58 QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0));
58 QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0));
59 axisLine->setRect(axisGeometry());
59 axisLine->setRect(axisGeometry());
60
60
61 qreal radius = axisGeometry().height() / 2.0;
61 qreal radius = axisGeometry().height() / 2.0;
62
62
63 QRectF previousLabelRect;
63 QRectF previousLabelRect;
64 QRectF firstLabelRect;
64 QRectF firstLabelRect;
65
65
66 qreal labelHeight = 0;
66 qreal labelHeight = 0;
67
67
68 bool firstShade = true;
68 bool firstShade = true;
69 bool nextTickVisible = false;
69 bool nextTickVisible = false;
70 if (layout.size())
70 if (layout.size())
71 nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > 360.0);
71 nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > 360.0);
72
72
73 for (int i = 0; i < layout.size(); ++i) {
73 for (int i = 0; i < layout.size(); ++i) {
74 qreal angularCoordinate = layout.at(i);
74 qreal angularCoordinate = layout.at(i);
75
75
76 QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i));
76 QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i));
77 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
77 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
78 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i));
78 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i));
79 QGraphicsPathItem *shadeItem = 0;
79 QGraphicsPathItem *shadeItem = 0;
80 if (i == 0)
80 if (i == 0)
81 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
81 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
82 else if (i % 2)
82 else if (i % 2)
83 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1));
83 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1));
84
84
85 // Ignore ticks outside valid range
85 // Ignore ticks outside valid range
86 bool currentTickVisible = nextTickVisible;
86 bool currentTickVisible = nextTickVisible;
87 if ((i == layout.size() - 1)
87 if ((i == layout.size() - 1)
88 || layout.at(i + 1) < 0.0
88 || layout.at(i + 1) < 0.0
89 || layout.at(i + 1) > 360.0) {
89 || layout.at(i + 1) > 360.0) {
90 nextTickVisible = false;
90 nextTickVisible = false;
91 } else {
91 } else {
92 nextTickVisible = true;
92 nextTickVisible = true;
93 }
93 }
94
94
95 qreal labelCoordinate = angularCoordinate;
95 qreal labelCoordinate = angularCoordinate;
96 qreal labelVisible = currentTickVisible;
96 qreal labelVisible = currentTickVisible;
97 if (intervalAxis()) {
97 if (intervalAxis()) {
98 qreal farEdge;
98 qreal farEdge;
99 if (i == (layout.size() - 1))
99 if (i == (layout.size() - 1))
100 farEdge = 360.0;
100 farEdge = 360.0;
101 else
101 else
102 farEdge = qMin(qreal(360.0), layout.at(i + 1));
102 farEdge = qMin(qreal(360.0), layout.at(i + 1));
103
103
104 // Adjust the labelCoordinate to show it if next tick is visible
104 // Adjust the labelCoordinate to show it if next tick is visible
105 if (nextTickVisible)
105 if (nextTickVisible)
106 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
106 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
107
107
108 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
108 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
109 // Don't display label once the category gets too small near the axis
109 // Don't display label once the category gets too small near the axis
110 if (labelCoordinate < 5.0 || labelCoordinate > 355.0)
110 if (labelCoordinate < 5.0 || labelCoordinate > 355.0)
111 labelVisible = false;
111 labelVisible = false;
112 else
112 else
113 labelVisible = true;
113 labelVisible = true;
114 }
114 }
115
115
116 // Need this also in label calculations, so determine it first
116 // Need this also in label calculations, so determine it first
117 QLineF tickLine(QLineF::fromPolar(radius - tickWidth(), 90.0 - angularCoordinate).p2(),
117 QLineF tickLine(QLineF::fromPolar(radius - tickWidth(), 90.0 - angularCoordinate).p2(),
118 QLineF::fromPolar(radius + tickWidth(), 90.0 - angularCoordinate).p2());
118 QLineF::fromPolar(radius + tickWidth(), 90.0 - angularCoordinate).p2());
119 tickLine.translate(center);
119 tickLine.translate(center);
120
120
121 // Angular axis label
121 // Angular axis label
122 if (axis()->labelsVisible() && labelVisible) {
122 if (axis()->labelsVisible() && labelVisible) {
123 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
123 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
124 labelList.at(i),
124 labelList.at(i),
125 axis()->labelsAngle());
125 axis()->labelsAngle());
126 labelItem->setTextWidth(boundingRect.width());
126 labelItem->setTextWidth(boundingRect.width());
127 labelItem->setHtml(labelList.at(i));
127 labelItem->setHtml(labelList.at(i));
128 const QRectF &rect = labelItem->boundingRect();
128 const QRectF &rect = labelItem->boundingRect();
129 QPointF labelCenter = rect.center();
129 QPointF labelCenter = rect.center();
130 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
130 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
131 boundingRect.moveCenter(labelCenter);
131 boundingRect.moveCenter(labelCenter);
132 QPointF positionDiff(rect.topLeft() - boundingRect.topLeft());
132 QPointF positionDiff(rect.topLeft() - boundingRect.topLeft());
133
133
134 QPointF labelPoint;
134 QPointF labelPoint;
135 if (intervalAxis()) {
135 if (intervalAxis()) {
136 QLineF labelLine = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate);
136 QLineF labelLine = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate);
137 labelLine.translate(center);
137 labelLine.translate(center);
138 labelPoint = labelLine.p2();
138 labelPoint = labelLine.p2();
139 } else {
139 } else {
140 labelPoint = tickLine.p2();
140 labelPoint = tickLine.p2();
141 }
141 }
142
142
143 QRectF labelRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
143 QRectF labelRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
144 labelItem->setPos(labelRect.topLeft() + positionDiff);
144 labelItem->setPos(labelRect.topLeft() + positionDiff);
145
145
146 // Store height for title calculations
146 // Store height for title calculations
147 qreal labelClearance = axisGeometry().top() - labelRect.top();
147 qreal labelClearance = axisGeometry().top() - labelRect.top();
148 labelHeight = qMax(labelHeight, labelClearance);
148 labelHeight = qMax(labelHeight, labelClearance);
149
149
150 // Label overlap detection
150 // Label overlap detection
151 if (i && (previousLabelRect.intersects(labelRect) || firstLabelRect.intersects(labelRect))) {
151 if (i && (previousLabelRect.intersects(labelRect) || firstLabelRect.intersects(labelRect))) {
152 labelVisible = false;
152 labelVisible = false;
153 } else {
153 } else {
154 // Store labelRect for future comparison. Some area is deducted to make things look
154 // Store labelRect for future comparison. Some area is deducted to make things look
155 // little nicer, as usually intersection happens at label corner with angular labels.
155 // little nicer, as usually intersection happens at label corner with angular labels.
156 labelRect.adjust(-2.0, -4.0, -2.0, -4.0);
156 labelRect.adjust(-2.0, -4.0, -2.0, -4.0);
157 if (firstLabelRect.isEmpty())
157 if (firstLabelRect.isEmpty())
158 firstLabelRect = labelRect;
158 firstLabelRect = labelRect;
159
159
160 previousLabelRect = labelRect;
160 previousLabelRect = labelRect;
161 labelVisible = true;
161 labelVisible = true;
162 }
162 }
163 }
163 }
164
164
165 labelItem->setVisible(labelVisible);
165 labelItem->setVisible(labelVisible);
166 if (!currentTickVisible) {
166 if (!currentTickVisible) {
167 gridLineItem->setVisible(false);
167 gridLineItem->setVisible(false);
168 tickItem->setVisible(false);
168 tickItem->setVisible(false);
169 if (shadeItem)
169 if (shadeItem)
170 shadeItem->setVisible(false);
170 shadeItem->setVisible(false);
171 continue;
171 continue;
172 }
172 }
173
173
174 // Angular grid line
174 // Angular grid line
175 QLineF gridLine = QLineF::fromPolar(radius, 90.0 - angularCoordinate);
175 QLineF gridLine = QLineF::fromPolar(radius, 90.0 - angularCoordinate);
176 gridLine.translate(center);
176 gridLine.translate(center);
177 gridLineItem->setLine(gridLine);
177 gridLineItem->setLine(gridLine);
178 gridLineItem->setVisible(true);
178 gridLineItem->setVisible(true);
179
179
180 // Tick
180 // Tick
181 tickItem->setLine(tickLine);
181 tickItem->setLine(tickLine);
182 tickItem->setVisible(true);
182 tickItem->setVisible(true);
183
183
184 // Shades
184 // Shades
185 if (i % 2 || (i == 0 && !nextTickVisible)) {
185 if (i % 2 || (i == 0 && !nextTickVisible)) {
186 QPainterPath path;
186 QPainterPath path;
187 path.moveTo(center);
187 path.moveTo(center);
188 if (i == 0) {
188 if (i == 0) {
189 // If first tick is also the last, we need to custom fill the first partial arc
189 // If first tick is also the last, we need to custom fill the first partial arc
190 // or it won't get filled.
190 // or it won't get filled.
191 path.arcTo(axisGeometry(), 90.0 - layout.at(0), layout.at(0));
191 path.arcTo(axisGeometry(), 90.0 - layout.at(0), layout.at(0));
192 path.closeSubpath();
192 path.closeSubpath();
193 } else {
193 } else {
194 qreal nextCoordinate;
194 qreal nextCoordinate;
195 if (!nextTickVisible) // Last visible tick
195 if (!nextTickVisible) // Last visible tick
196 nextCoordinate = 360.0;
196 nextCoordinate = 360.0;
197 else
197 else
198 nextCoordinate = layout.at(i + 1);
198 nextCoordinate = layout.at(i + 1);
199 qreal arcSpan = angularCoordinate - nextCoordinate;
199 qreal arcSpan = angularCoordinate - nextCoordinate;
200 path.arcTo(axisGeometry(), 90.0 - angularCoordinate, arcSpan);
200 path.arcTo(axisGeometry(), 90.0 - angularCoordinate, arcSpan);
201 path.closeSubpath();
201 path.closeSubpath();
202
202
203 // Add additional arc for first shade item if there is a partial arc to be filled
203 // Add additional arc for first shade item if there is a partial arc to be filled
204 if (firstShade) {
204 if (firstShade) {
205 QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
205 QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
206 if (layout.at(i - 1) > 0.0) {
206 if (layout.at(i - 1) > 0.0) {
207 QPainterPath specialPath;
207 QPainterPath specialPath;
208 specialPath.moveTo(center);
208 specialPath.moveTo(center);
209 specialPath.arcTo(axisGeometry(), 90.0 - layout.at(i - 1), layout.at(i - 1));
209 specialPath.arcTo(axisGeometry(), 90.0 - layout.at(i - 1), layout.at(i - 1));
210 specialPath.closeSubpath();
210 specialPath.closeSubpath();
211 specialShadeItem->setPath(specialPath);
211 specialShadeItem->setPath(specialPath);
212 specialShadeItem->setVisible(true);
212 specialShadeItem->setVisible(true);
213 } else {
213 } else {
214 specialShadeItem->setVisible(false);
214 specialShadeItem->setVisible(false);
215 }
215 }
216 }
216 }
217 }
217 }
218 shadeItem->setPath(path);
218 shadeItem->setPath(path);
219 shadeItem->setVisible(true);
219 shadeItem->setVisible(true);
220 firstShade = false;
220 firstShade = false;
221 }
221 }
222 }
222 }
223
223
224 // Title, centered above the chart
224 // Title, centered above the chart
225 QString titleText = axis()->titleText();
225 QString titleText = axis()->titleText();
226 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
226 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
227 QRectF truncatedRect;
227 QRectF truncatedRect;
228 qreal availableTitleHeight = axisGeometry().height() - labelPadding() - titlePadding() * 2.0;
228 qreal availableTitleHeight = axisGeometry().height() - labelPadding() - titlePadding() * 2.0;
229 qreal minimumLabelHeight = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...").height();
229 qreal minimumLabelHeight = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...").height();
230 availableTitleHeight -= minimumLabelHeight;
230 availableTitleHeight -= minimumLabelHeight;
231 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0),
231 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0),
232 axisGeometry().width(), availableTitleHeight,
232 axisGeometry().width(), availableTitleHeight,
233 truncatedRect));
233 truncatedRect));
234 title->setTextWidth(truncatedRect.width());
234 title->setTextWidth(truncatedRect.width());
235
235
236 QRectF titleBoundingRect = title->boundingRect();
236 QRectF titleBoundingRect = title->boundingRect();
237 QPointF titleCenter = center - titleBoundingRect.center();
237 QPointF titleCenter = center - titleBoundingRect.center();
238 title->setPos(titleCenter.x(), axisGeometry().top() - titlePadding() * 2.0 - titleBoundingRect.height() - labelHeight);
238 title->setPos(titleCenter.x(), axisGeometry().top() - titlePadding() * 2.0 - titleBoundingRect.height() - labelHeight);
239 }
239 }
240 }
240 }
241
241
242 Qt::Orientation PolarChartAxisAngular::orientation() const
242 Qt::Orientation PolarChartAxisAngular::orientation() const
243 {
243 {
244 return Qt::Horizontal;
244 return Qt::Horizontal;
245 }
245 }
246
246
247 void PolarChartAxisAngular::createItems(int count)
247 void PolarChartAxisAngular::createItems(int count)
248 {
248 {
249 if (arrowItems().count() == 0) {
249 if (arrowItems().count() == 0) {
250 // angular axis line
250 // angular axis line
251 QGraphicsEllipseItem *arrow = new QGraphicsEllipseItem(presenter()->rootItem());
251 QGraphicsEllipseItem *arrow = new QGraphicsEllipseItem(presenter()->rootItem());
252 arrow->setPen(axis()->linePen());
252 arrow->setPen(axis()->linePen());
253 arrowGroup()->addToGroup(arrow);
253 arrowGroup()->addToGroup(arrow);
254 }
254 }
255
255
256 QGraphicsTextItem *title = titleItem();
257 title->setFont(axis()->titleFont());
258 title->setDefaultTextColor(axis()->titleBrush().color());
259 title->setHtml(axis()->titleText());
260
256 for (int i = 0; i < count; ++i) {
261 for (int i = 0; i < count; ++i) {
257 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
262 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
258 QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem());
263 QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem());
259 QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem());
264 QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem());
260 label->document()->setDocumentMargin(ChartPresenter::textMargin());
265 label->document()->setDocumentMargin(ChartPresenter::textMargin());
261 QGraphicsTextItem *title = titleItem();
262 arrow->setPen(axis()->linePen());
266 arrow->setPen(axis()->linePen());
263 grid->setPen(axis()->gridLinePen());
267 grid->setPen(axis()->gridLinePen());
264 label->setFont(axis()->labelsFont());
268 label->setFont(axis()->labelsFont());
265 label->setDefaultTextColor(axis()->labelsBrush().color());
269 label->setDefaultTextColor(axis()->labelsBrush().color());
266 label->setRotation(axis()->labelsAngle());
270 label->setRotation(axis()->labelsAngle());
267 title->setFont(axis()->titleFont());
268 title->setDefaultTextColor(axis()->titleBrush().color());
269 title->setHtml(axis()->titleText());
270 arrowGroup()->addToGroup(arrow);
271 arrowGroup()->addToGroup(arrow);
271 gridGroup()->addToGroup(grid);
272 gridGroup()->addToGroup(grid);
272 labelGroup()->addToGroup(label);
273 labelGroup()->addToGroup(label);
273 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
274 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
274 QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem());
275 QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem());
275 shade->setPen(axis()->shadesPen());
276 shade->setPen(axis()->shadesPen());
276 shade->setBrush(axis()->shadesBrush());
277 shade->setBrush(axis()->shadesBrush());
277 shadeGroup()->addToGroup(shade);
278 shadeGroup()->addToGroup(shade);
278 }
279 }
279 }
280 }
280 }
281 }
281
282
282 void PolarChartAxisAngular::handleArrowPenChanged(const QPen &pen)
283 void PolarChartAxisAngular::handleArrowPenChanged(const QPen &pen)
283 {
284 {
284 bool first = true;
285 bool first = true;
285 foreach (QGraphicsItem *item, arrowItems()) {
286 foreach (QGraphicsItem *item, arrowItems()) {
286 if (first) {
287 if (first) {
287 first = false;
288 first = false;
288 // First arrow item is the outer circle of axis
289 // First arrow item is the outer circle of axis
289 static_cast<QGraphicsEllipseItem *>(item)->setPen(pen);
290 static_cast<QGraphicsEllipseItem *>(item)->setPen(pen);
290 } else {
291 } else {
291 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
292 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
292 }
293 }
293 }
294 }
294 }
295 }
295
296
296 void PolarChartAxisAngular::handleGridPenChanged(const QPen &pen)
297 void PolarChartAxisAngular::handleGridPenChanged(const QPen &pen)
297 {
298 {
298 foreach (QGraphicsItem *item, gridItems())
299 foreach (QGraphicsItem *item, gridItems())
299 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
300 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
300 }
301 }
301
302
302 QSizeF PolarChartAxisAngular::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
303 QSizeF PolarChartAxisAngular::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
303 {
304 {
304 Q_UNUSED(which);
305 Q_UNUSED(which);
305 Q_UNUSED(constraint);
306 Q_UNUSED(constraint);
306 return QSizeF(-1, -1);
307 return QSizeF(-1, -1);
307 }
308 }
308
309
309 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize)
310 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize)
310 {
311 {
311 qreal radius = maxSize.height() / 2.0;
312 qreal radius = maxSize.height() / 2.0;
312 if (maxSize.width() < maxSize.height())
313 if (maxSize.width() < maxSize.height())
313 radius = maxSize.width() / 2.0;
314 radius = maxSize.width() / 2.0;
314
315
315 if (axis()->labelsVisible()) {
316 if (axis()->labelsVisible()) {
316 QVector<qreal> layout = calculateLayout();
317 QVector<qreal> layout = calculateLayout();
317 if (layout.isEmpty())
318 if (layout.isEmpty())
318 return radius;
319 return radius;
319
320
320 createAxisLabels(layout);
321 createAxisLabels(layout);
321 QStringList labelList = labels();
322 QStringList labelList = labels();
322 QFont font = axis()->labelsFont();
323 QFont font = axis()->labelsFont();
323
324
324 QRectF maxRect;
325 QRectF maxRect;
325 maxRect.setSize(maxSize);
326 maxRect.setSize(maxSize);
326 maxRect.moveCenter(QPointF(0.0, 0.0));
327 maxRect.moveCenter(QPointF(0.0, 0.0));
327
328
328 // This is a horrible way to find out the maximum radius for angular axis and its labels.
329 // This is a horrible way to find out the maximum radius for angular axis and its labels.
329 // It just increments the radius down until everyhing fits the constraint size.
330 // It just increments the radius down until everyhing fits the constraint size.
330 // Proper way would be to actually calculate it but this seems to work reasonably fast as it is.
331 // Proper way would be to actually calculate it but this seems to work reasonably fast as it is.
331 bool nextTickVisible = false;
332 bool nextTickVisible = false;
332 for (int i = 0; i < layout.size(); ) {
333 for (int i = 0; i < layout.size(); ) {
333 if ((i == layout.size() - 1)
334 if ((i == layout.size() - 1)
334 || layout.at(i + 1) < 0.0
335 || layout.at(i + 1) < 0.0
335 || layout.at(i + 1) > 360.0) {
336 || layout.at(i + 1) > 360.0) {
336 nextTickVisible = false;
337 nextTickVisible = false;
337 } else {
338 } else {
338 nextTickVisible = true;
339 nextTickVisible = true;
339 }
340 }
340
341
341 qreal labelCoordinate = layout.at(i);
342 qreal labelCoordinate = layout.at(i);
342 qreal labelVisible;
343 qreal labelVisible;
343
344
344 if (intervalAxis()) {
345 if (intervalAxis()) {
345 qreal farEdge;
346 qreal farEdge;
346 if (i == (layout.size() - 1))
347 if (i == (layout.size() - 1))
347 farEdge = 360.0;
348 farEdge = 360.0;
348 else
349 else
349 farEdge = qMin(qreal(360.0), layout.at(i + 1));
350 farEdge = qMin(qreal(360.0), layout.at(i + 1));
350
351
351 // Adjust the labelCoordinate to show it if next tick is visible
352 // Adjust the labelCoordinate to show it if next tick is visible
352 if (nextTickVisible)
353 if (nextTickVisible)
353 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
354 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
354
355
355 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
356 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
356 }
357 }
357
358
358 if (labelCoordinate < 0.0 || labelCoordinate > 360.0)
359 if (labelCoordinate < 0.0 || labelCoordinate > 360.0)
359 labelVisible = false;
360 labelVisible = false;
360 else
361 else
361 labelVisible = true;
362 labelVisible = true;
362
363
363 if (!labelVisible) {
364 if (!labelVisible) {
364 i++;
365 i++;
365 continue;
366 continue;
366 }
367 }
367
368
368 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
369 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
369 QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2();
370 QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2();
370
371
371 boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
372 boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
372 QRectF intersectRect = maxRect.intersected(boundingRect);
373 QRectF intersectRect = maxRect.intersected(boundingRect);
373 if (boundingRect.isEmpty() || intersectRect == boundingRect) {
374 if (boundingRect.isEmpty() || intersectRect == boundingRect) {
374 i++;
375 i++;
375 } else {
376 } else {
376 qreal reduction(0.0);
377 qreal reduction(0.0);
377 // If there is no intersection, reduce by smallest dimension of label rect to be on the safe side
378 // If there is no intersection, reduce by smallest dimension of label rect to be on the safe side
378 if (intersectRect.isEmpty()) {
379 if (intersectRect.isEmpty()) {
379 reduction = qMin(boundingRect.height(), boundingRect.width());
380 reduction = qMin(boundingRect.height(), boundingRect.width());
380 } else {
381 } else {
381 // Approximate needed radius reduction is the amount label rect exceeds max rect in either dimension.
382 // Approximate needed radius reduction is the amount label rect exceeds max rect in either dimension.
382 // Could be further optimized by figuring out the proper math how to calculate exact needed reduction.
383 // Could be further optimized by figuring out the proper math how to calculate exact needed reduction.
383 reduction = qMax(boundingRect.height() - intersectRect.height(),
384 reduction = qMax(boundingRect.height() - intersectRect.height(),
384 boundingRect.width() - intersectRect.width());
385 boundingRect.width() - intersectRect.width());
385 }
386 }
386 // Typically the approximated reduction is little low, so add one
387 // Typically the approximated reduction is little low, so add one
387 radius -= (reduction + 1.0);
388 radius -= (reduction + 1.0);
388
389
389 if (radius < 1.0) // safeguard
390 if (radius < 1.0) // safeguard
390 return 1.0;
391 return 1.0;
391 }
392 }
392 }
393 }
393 }
394 }
394
395
395 if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) {
396 if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) {
396 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText());
397 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText());
397
398
398 radius -= titlePadding() + (titleRect.height() / 2.0);
399 radius -= titlePadding() + (titleRect.height() / 2.0);
399 if (radius < 1.0) // safeguard
400 if (radius < 1.0) // safeguard
400 return 1.0;
401 return 1.0;
401 }
402 }
402
403
403 return radius;
404 return radius;
404 }
405 }
405
406
406 QRectF PolarChartAxisAngular::moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const
407 QRectF PolarChartAxisAngular::moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const
407 {
408 {
408 if (angularCoordinate == 0.0)
409 if (angularCoordinate == 0.0)
409 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
410 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
410 else if (angularCoordinate < 90.0)
411 else if (angularCoordinate < 90.0)
411 labelRect.moveBottomLeft(labelPoint);
412 labelRect.moveBottomLeft(labelPoint);
412 else if (angularCoordinate == 90.0)
413 else if (angularCoordinate == 90.0)
413 labelRect.moveCenter(labelPoint + QPointF(labelRect.width() / 2.0 + 2.0, 0)); // +2 so that it does not hit the radial axis
414 labelRect.moveCenter(labelPoint + QPointF(labelRect.width() / 2.0 + 2.0, 0)); // +2 so that it does not hit the radial axis
414 else if (angularCoordinate < 180.0)
415 else if (angularCoordinate < 180.0)
415 labelRect.moveTopLeft(labelPoint);
416 labelRect.moveTopLeft(labelPoint);
416 else if (angularCoordinate == 180.0)
417 else if (angularCoordinate == 180.0)
417 labelRect.moveCenter(labelPoint + QPointF(0, labelRect.height() / 2.0));
418 labelRect.moveCenter(labelPoint + QPointF(0, labelRect.height() / 2.0));
418 else if (angularCoordinate < 270.0)
419 else if (angularCoordinate < 270.0)
419 labelRect.moveTopRight(labelPoint);
420 labelRect.moveTopRight(labelPoint);
420 else if (angularCoordinate == 270.0)
421 else if (angularCoordinate == 270.0)
421 labelRect.moveCenter(labelPoint + QPointF(-labelRect.width() / 2.0 - 2.0, 0)); // -2 so that it does not hit the radial axis
422 labelRect.moveCenter(labelPoint + QPointF(-labelRect.width() / 2.0 - 2.0, 0)); // -2 so that it does not hit the radial axis
422 else if (angularCoordinate < 360.0)
423 else if (angularCoordinate < 360.0)
423 labelRect.moveBottomRight(labelPoint);
424 labelRect.moveBottomRight(labelPoint);
424 else
425 else
425 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
426 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
426 return labelRect;
427 return labelRect;
427 }
428 }
428
429
429 #include "moc_polarchartaxisangular_p.cpp"
430 #include "moc_polarchartaxisangular_p.cpp"
430
431
431 QTCOMMERCIALCHART_END_NAMESPACE
432 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,296 +1,297
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "polarchartaxisradial_p.h"
21 #include "polarchartaxisradial_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qabstractaxis_p.h"
24 #include "qabstractaxis_p.h"
25 #include "linearrowitem_p.h"
25 #include "linearrowitem_p.h"
26 #include <QTextDocument>
26 #include <QTextDocument>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 PolarChartAxisRadial::PolarChartAxisRadial(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
30 PolarChartAxisRadial::PolarChartAxisRadial(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
31 : PolarChartAxis(axis, item, intervalAxis)
31 : PolarChartAxis(axis, item, intervalAxis)
32 {
32 {
33 }
33 }
34
34
35 PolarChartAxisRadial::~PolarChartAxisRadial()
35 PolarChartAxisRadial::~PolarChartAxisRadial()
36 {
36 {
37 }
37 }
38
38
39 void PolarChartAxisRadial::updateGeometry()
39 void PolarChartAxisRadial::updateGeometry()
40 {
40 {
41 const QVector<qreal> &layout = this->layout();
41 const QVector<qreal> &layout = this->layout();
42 if (layout.isEmpty())
42 if (layout.isEmpty())
43 return;
43 return;
44
44
45 createAxisLabels(layout);
45 createAxisLabels(layout);
46 QStringList labelList = labels();
46 QStringList labelList = labels();
47 QPointF center = axisGeometry().center();
47 QPointF center = axisGeometry().center();
48 QList<QGraphicsItem *> arrowItemList = arrowItems();
48 QList<QGraphicsItem *> arrowItemList = arrowItems();
49 QList<QGraphicsItem *> gridItemList = gridItems();
49 QList<QGraphicsItem *> gridItemList = gridItems();
50 QList<QGraphicsItem *> labelItemList = labelItems();
50 QList<QGraphicsItem *> labelItemList = labelItems();
51 QList<QGraphicsItem *> shadeItemList = shadeItems();
51 QList<QGraphicsItem *> shadeItemList = shadeItems();
52 QGraphicsTextItem* title = titleItem();
52 QGraphicsTextItem* title = titleItem();
53 qreal radius = axisGeometry().height() / 2.0;
53 qreal radius = axisGeometry().height() / 2.0;
54
54
55 QLineF line(center, center + QPointF(0, -radius));
55 QLineF line(center, center + QPointF(0, -radius));
56 QGraphicsLineItem *axisLine = static_cast<QGraphicsLineItem *>(arrowItemList.at(0));
56 QGraphicsLineItem *axisLine = static_cast<QGraphicsLineItem *>(arrowItemList.at(0));
57 axisLine->setLine(line);
57 axisLine->setLine(line);
58
58
59 QRectF previousLabelRect;
59 QRectF previousLabelRect;
60 bool firstShade = true;
60 bool firstShade = true;
61 bool nextTickVisible = false;
61 bool nextTickVisible = false;
62 if (layout.size())
62 if (layout.size())
63 nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > radius);
63 nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > radius);
64
64
65 for (int i = 0; i < layout.size(); ++i) {
65 for (int i = 0; i < layout.size(); ++i) {
66 qreal radialCoordinate = layout.at(i);
66 qreal radialCoordinate = layout.at(i);
67
67
68 QGraphicsEllipseItem *gridItem = static_cast<QGraphicsEllipseItem *>(gridItemList.at(i));
68 QGraphicsEllipseItem *gridItem = static_cast<QGraphicsEllipseItem *>(gridItemList.at(i));
69 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
69 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
70 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i));
70 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i));
71 QGraphicsPathItem *shadeItem = 0;
71 QGraphicsPathItem *shadeItem = 0;
72 if (i == 0)
72 if (i == 0)
73 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
73 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
74 else if (i % 2)
74 else if (i % 2)
75 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1));
75 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1));
76
76
77 // Ignore ticks outside valid range
77 // Ignore ticks outside valid range
78 bool currentTickVisible = nextTickVisible;
78 bool currentTickVisible = nextTickVisible;
79 if ((i == layout.size() - 1)
79 if ((i == layout.size() - 1)
80 || layout.at(i + 1) < 0.0
80 || layout.at(i + 1) < 0.0
81 || layout.at(i + 1) > radius) {
81 || layout.at(i + 1) > radius) {
82 nextTickVisible = false;
82 nextTickVisible = false;
83 } else {
83 } else {
84 nextTickVisible = true;
84 nextTickVisible = true;
85 }
85 }
86
86
87 qreal labelCoordinate = radialCoordinate;
87 qreal labelCoordinate = radialCoordinate;
88 qreal labelVisible = currentTickVisible;
88 qreal labelVisible = currentTickVisible;
89 qreal labelPad = labelPadding() / 2.0;
89 qreal labelPad = labelPadding() / 2.0;
90 if (intervalAxis()) {
90 if (intervalAxis()) {
91 qreal farEdge;
91 qreal farEdge;
92 if (i == (layout.size() - 1))
92 if (i == (layout.size() - 1))
93 farEdge = radius;
93 farEdge = radius;
94 else
94 else
95 farEdge = qMin(radius, layout.at(i + 1));
95 farEdge = qMin(radius, layout.at(i + 1));
96
96
97 // Adjust the labelCoordinate to show it if next tick is visible
97 // Adjust the labelCoordinate to show it if next tick is visible
98 if (nextTickVisible)
98 if (nextTickVisible)
99 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
99 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
100
100
101 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
101 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
102 if (labelCoordinate > 0.0 && labelCoordinate < radius)
102 if (labelCoordinate > 0.0 && labelCoordinate < radius)
103 labelVisible = true;
103 labelVisible = true;
104 else
104 else
105 labelVisible = false;
105 labelVisible = false;
106 }
106 }
107
107
108 // Radial axis label
108 // Radial axis label
109 if (axis()->labelsVisible() && labelVisible) {
109 if (axis()->labelsVisible() && labelVisible) {
110 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
110 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(),
111 labelList.at(i),
111 labelList.at(i),
112 axis()->labelsAngle());
112 axis()->labelsAngle());
113 labelItem->setTextWidth(boundingRect.width());
113 labelItem->setTextWidth(boundingRect.width());
114 labelItem->setHtml(labelList.at(i));
114 labelItem->setHtml(labelList.at(i));
115 QRectF labelRect = labelItem->boundingRect();
115 QRectF labelRect = labelItem->boundingRect();
116 QPointF labelCenter = labelRect.center();
116 QPointF labelCenter = labelRect.center();
117 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
117 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
118 boundingRect.moveCenter(labelCenter);
118 boundingRect.moveCenter(labelCenter);
119 QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft());
119 QPointF positionDiff(labelRect.topLeft() - boundingRect.topLeft());
120 QPointF labelPoint = center;
120 QPointF labelPoint = center;
121 if (intervalAxis())
121 if (intervalAxis())
122 labelPoint += QPointF(labelPad, -labelCoordinate - (boundingRect.height() / 2.0));
122 labelPoint += QPointF(labelPad, -labelCoordinate - (boundingRect.height() / 2.0));
123 else
123 else
124 labelPoint += QPointF(labelPad, labelPad - labelCoordinate);
124 labelPoint += QPointF(labelPad, labelPad - labelCoordinate);
125 labelRect.moveTopLeft(labelPoint);
125 labelRect.moveTopLeft(labelPoint);
126 labelItem->setPos(labelRect.topLeft() + positionDiff);
126 labelItem->setPos(labelRect.topLeft() + positionDiff);
127
127
128 // Label overlap detection
128 // Label overlap detection
129 labelRect.setSize(boundingRect.size());
129 labelRect.setSize(boundingRect.size());
130 if ((i && previousLabelRect.intersects(labelRect))
130 if ((i && previousLabelRect.intersects(labelRect))
131 || !axisGeometry().contains(labelRect)) {
131 || !axisGeometry().contains(labelRect)) {
132 labelVisible = false;
132 labelVisible = false;
133 } else {
133 } else {
134 previousLabelRect = labelRect;
134 previousLabelRect = labelRect;
135 labelVisible = true;
135 labelVisible = true;
136 }
136 }
137 }
137 }
138
138
139 labelItem->setVisible(labelVisible);
139 labelItem->setVisible(labelVisible);
140 if (!currentTickVisible) {
140 if (!currentTickVisible) {
141 gridItem->setVisible(false);
141 gridItem->setVisible(false);
142 tickItem->setVisible(false);
142 tickItem->setVisible(false);
143 if (shadeItem)
143 if (shadeItem)
144 shadeItem->setVisible(false);
144 shadeItem->setVisible(false);
145 continue;
145 continue;
146 }
146 }
147
147
148 // Radial grid line
148 // Radial grid line
149 QRectF gridRect;
149 QRectF gridRect;
150 gridRect.setWidth(radialCoordinate * 2.0);
150 gridRect.setWidth(radialCoordinate * 2.0);
151 gridRect.setHeight(radialCoordinate * 2.0);
151 gridRect.setHeight(radialCoordinate * 2.0);
152 gridRect.moveCenter(center);
152 gridRect.moveCenter(center);
153
153
154 gridItem->setRect(gridRect);
154 gridItem->setRect(gridRect);
155 gridItem->setVisible(true);
155 gridItem->setVisible(true);
156
156
157 // Tick
157 // Tick
158 QLineF tickLine(-tickWidth(), 0.0, tickWidth(), 0.0);
158 QLineF tickLine(-tickWidth(), 0.0, tickWidth(), 0.0);
159 tickLine.translate(center.rx(), gridRect.top());
159 tickLine.translate(center.rx(), gridRect.top());
160 tickItem->setLine(tickLine);
160 tickItem->setLine(tickLine);
161 tickItem->setVisible(true);
161 tickItem->setVisible(true);
162
162
163 // Shades
163 // Shades
164 if (i % 2 || (i == 0 && !nextTickVisible)) {
164 if (i % 2 || (i == 0 && !nextTickVisible)) {
165 QPainterPath path;
165 QPainterPath path;
166 if (i == 0) {
166 if (i == 0) {
167 // If first tick is also the last, we need to custom fill the inner circle
167 // If first tick is also the last, we need to custom fill the inner circle
168 // or it won't get filled.
168 // or it won't get filled.
169 QRectF innerCircle(0.0, 0.0, layout.at(0) * 2.0, layout.at(0) * 2.0);
169 QRectF innerCircle(0.0, 0.0, layout.at(0) * 2.0, layout.at(0) * 2.0);
170 innerCircle.moveCenter(center);
170 innerCircle.moveCenter(center);
171 path.addEllipse(innerCircle);
171 path.addEllipse(innerCircle);
172 } else {
172 } else {
173 QRectF otherGridRect;
173 QRectF otherGridRect;
174 if (!nextTickVisible) { // Last visible tick
174 if (!nextTickVisible) { // Last visible tick
175 otherGridRect = axisGeometry();
175 otherGridRect = axisGeometry();
176 } else {
176 } else {
177 qreal otherGridRectDimension = layout.at(i + 1) * 2.0;
177 qreal otherGridRectDimension = layout.at(i + 1) * 2.0;
178 otherGridRect.setWidth(otherGridRectDimension);
178 otherGridRect.setWidth(otherGridRectDimension);
179 otherGridRect.setHeight(otherGridRectDimension);
179 otherGridRect.setHeight(otherGridRectDimension);
180 otherGridRect.moveCenter(center);
180 otherGridRect.moveCenter(center);
181 }
181 }
182 path.addEllipse(gridRect);
182 path.addEllipse(gridRect);
183 path.addEllipse(otherGridRect);
183 path.addEllipse(otherGridRect);
184
184
185 // Add additional shading in first visible shade item if there is a partial tick
185 // Add additional shading in first visible shade item if there is a partial tick
186 // to be filled at the center (log & category axes)
186 // to be filled at the center (log & category axes)
187 if (firstShade) {
187 if (firstShade) {
188 QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
188 QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
189 if (layout.at(i - 1) > 0.0) {
189 if (layout.at(i - 1) > 0.0) {
190 QRectF innerCircle(0.0, 0.0, layout.at(i - 1) * 2.0, layout.at(i - 1) * 2.0);
190 QRectF innerCircle(0.0, 0.0, layout.at(i - 1) * 2.0, layout.at(i - 1) * 2.0);
191 innerCircle.moveCenter(center);
191 innerCircle.moveCenter(center);
192 QPainterPath specialPath;
192 QPainterPath specialPath;
193 specialPath.addEllipse(innerCircle);
193 specialPath.addEllipse(innerCircle);
194 specialShadeItem->setPath(specialPath);
194 specialShadeItem->setPath(specialPath);
195 specialShadeItem->setVisible(true);
195 specialShadeItem->setVisible(true);
196 } else {
196 } else {
197 specialShadeItem->setVisible(false);
197 specialShadeItem->setVisible(false);
198 }
198 }
199 }
199 }
200 }
200 }
201 shadeItem->setPath(path);
201 shadeItem->setPath(path);
202 shadeItem->setVisible(true);
202 shadeItem->setVisible(true);
203 firstShade = false;
203 firstShade = false;
204 }
204 }
205 }
205 }
206
206
207 // Title, along the 0 axis
207 // Title, along the 0 axis
208 QString titleText = axis()->titleText();
208 QString titleText = axis()->titleText();
209 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
209 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
210 QRectF truncatedRect;
210 QRectF truncatedRect;
211 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0),
211 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0),
212 radius, radius, truncatedRect));
212 radius, radius, truncatedRect));
213 title->setTextWidth(truncatedRect.width());
213 title->setTextWidth(truncatedRect.width());
214
214
215 QRectF titleBoundingRect = title->boundingRect();
215 QRectF titleBoundingRect = title->boundingRect();
216 QPointF titleCenter = titleBoundingRect.center();
216 QPointF titleCenter = titleBoundingRect.center();
217 QPointF arrowCenter = axisLine->boundingRect().center();
217 QPointF arrowCenter = axisLine->boundingRect().center();
218 QPointF titleCenterDiff = arrowCenter - titleCenter;
218 QPointF titleCenterDiff = arrowCenter - titleCenter;
219 title->setPos(titleCenterDiff.x() - titlePadding() - (titleBoundingRect.height() / 2.0), titleCenterDiff.y());
219 title->setPos(titleCenterDiff.x() - titlePadding() - (titleBoundingRect.height() / 2.0), titleCenterDiff.y());
220 title->setTransformOriginPoint(titleCenter);
220 title->setTransformOriginPoint(titleCenter);
221 title->setRotation(270.0);
221 title->setRotation(270.0);
222 }
222 }
223
223
224 QGraphicsLayoutItem::updateGeometry();
224 QGraphicsLayoutItem::updateGeometry();
225 }
225 }
226
226
227 Qt::Orientation PolarChartAxisRadial::orientation() const
227 Qt::Orientation PolarChartAxisRadial::orientation() const
228 {
228 {
229 return Qt::Vertical;
229 return Qt::Vertical;
230 }
230 }
231
231
232 void PolarChartAxisRadial::createItems(int count)
232 void PolarChartAxisRadial::createItems(int count)
233 {
233 {
234 if (arrowItems().count() == 0) {
234 if (arrowItems().count() == 0) {
235 // radial axis center line
235 // radial axis center line
236 QGraphicsLineItem *arrow = new LineArrowItem(this, presenter()->rootItem());
236 QGraphicsLineItem *arrow = new LineArrowItem(this, presenter()->rootItem());
237 arrow->setPen(axis()->linePen());
237 arrow->setPen(axis()->linePen());
238 arrowGroup()->addToGroup(arrow);
238 arrowGroup()->addToGroup(arrow);
239 }
239 }
240
240
241 QGraphicsTextItem *title = titleItem();
242 title->setFont(axis()->titleFont());
243 title->setDefaultTextColor(axis()->titleBrush().color());
244 title->setHtml(axis()->titleText());
245
241 for (int i = 0; i < count; ++i) {
246 for (int i = 0; i < count; ++i) {
242 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
247 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
243 QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem());
248 QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem());
244 QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem());
249 QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem());
245 label->document()->setDocumentMargin(ChartPresenter::textMargin());
250 label->document()->setDocumentMargin(ChartPresenter::textMargin());
246 QGraphicsTextItem *title = titleItem();
247 arrow->setPen(axis()->linePen());
251 arrow->setPen(axis()->linePen());
248 grid->setPen(axis()->gridLinePen());
252 grid->setPen(axis()->gridLinePen());
249 label->setFont(axis()->labelsFont());
253 label->setFont(axis()->labelsFont());
250 label->setDefaultTextColor(axis()->labelsBrush().color());
254 label->setDefaultTextColor(axis()->labelsBrush().color());
251 label->setRotation(axis()->labelsAngle());
255 label->setRotation(axis()->labelsAngle());
252 title->setFont(axis()->titleFont());
253 title->setDefaultTextColor(axis()->titleBrush().color());
254 title->setHtml(axis()->titleText());
255 arrowGroup()->addToGroup(arrow);
256 arrowGroup()->addToGroup(arrow);
256 gridGroup()->addToGroup(grid);
257 gridGroup()->addToGroup(grid);
257 labelGroup()->addToGroup(label);
258 labelGroup()->addToGroup(label);
258 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
259 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
259 QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem());
260 QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem());
260 shade->setPen(axis()->shadesPen());
261 shade->setPen(axis()->shadesPen());
261 shade->setBrush(axis()->shadesBrush());
262 shade->setBrush(axis()->shadesBrush());
262 shadeGroup()->addToGroup(shade);
263 shadeGroup()->addToGroup(shade);
263 }
264 }
264 }
265 }
265 }
266 }
266
267
267 void PolarChartAxisRadial::handleArrowPenChanged(const QPen &pen)
268 void PolarChartAxisRadial::handleArrowPenChanged(const QPen &pen)
268 {
269 {
269 foreach (QGraphicsItem *item, arrowItems())
270 foreach (QGraphicsItem *item, arrowItems())
270 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
271 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
271 }
272 }
272
273
273 void PolarChartAxisRadial::handleGridPenChanged(const QPen &pen)
274 void PolarChartAxisRadial::handleGridPenChanged(const QPen &pen)
274 {
275 {
275 foreach (QGraphicsItem *item, gridItems())
276 foreach (QGraphicsItem *item, gridItems())
276 static_cast<QGraphicsEllipseItem *>(item)->setPen(pen);
277 static_cast<QGraphicsEllipseItem *>(item)->setPen(pen);
277 }
278 }
278
279
279 QSizeF PolarChartAxisRadial::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
280 QSizeF PolarChartAxisRadial::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
280 {
281 {
281 Q_UNUSED(which);
282 Q_UNUSED(which);
282 Q_UNUSED(constraint);
283 Q_UNUSED(constraint);
283 return QSizeF(-1.0, -1.0);
284 return QSizeF(-1.0, -1.0);
284 }
285 }
285
286
286 qreal PolarChartAxisRadial::preferredAxisRadius(const QSizeF &maxSize)
287 qreal PolarChartAxisRadial::preferredAxisRadius(const QSizeF &maxSize)
287 {
288 {
288 qreal radius = maxSize.height() / 2.0;
289 qreal radius = maxSize.height() / 2.0;
289 if (maxSize.width() < maxSize.height())
290 if (maxSize.width() < maxSize.height())
290 radius = maxSize.width() / 2.0;
291 radius = maxSize.width() / 2.0;
291 return radius;
292 return radius;
292 }
293 }
293
294
294 #include "moc_polarchartaxisradial_p.cpp"
295 #include "moc_polarchartaxisradial_p.cpp"
295
296
296 QTCOMMERCIALCHART_END_NAMESPACE
297 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now