@@ -0,0 +1,15 | |||||
|
1 | !include( ../../common.pri ) { | |||
|
2 | error( "Couldn't find the common.pri file!" ) | |||
|
3 | } | |||
|
4 | ||||
|
5 | !include( ../../integrated.pri ) { | |||
|
6 | error( "Couldn't find the integrated.pri file !") | |||
|
7 | } | |||
|
8 | ||||
|
9 | TARGET = axisChart | |||
|
10 | TEMPLATE = app | |||
|
11 | QT += core gui | |||
|
12 | SOURCES += main.cpp | |||
|
13 | ||||
|
14 | ||||
|
15 |
@@ -0,0 +1,56 | |||||
|
1 | #include <QApplication> | |||
|
2 | #include <QMainWindow> | |||
|
3 | #include <qchartview.h> | |||
|
4 | #include <qlinechartseries.h> | |||
|
5 | #include <qchart.h> | |||
|
6 | #include <qchartaxis.h> | |||
|
7 | #include <cmath> | |||
|
8 | ||||
|
9 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
10 | ||||
|
11 | #define PI 3.14159265358979 | |||
|
12 | ||||
|
13 | int main(int argc, char *argv[]) | |||
|
14 | { | |||
|
15 | QApplication a(argc, argv); | |||
|
16 | ||||
|
17 | QMainWindow window; | |||
|
18 | ||||
|
19 | QLineChartSeries* series0 = new QLineChartSeries(); | |||
|
20 | QPen blue(Qt::blue); | |||
|
21 | blue.setWidth(3); | |||
|
22 | series0->setPen(blue); | |||
|
23 | QLineChartSeries* series1 = new QLineChartSeries(); | |||
|
24 | QPen red(Qt::red); | |||
|
25 | red.setWidth(3); | |||
|
26 | series1->setPen(red); | |||
|
27 | ||||
|
28 | int numPoints = 100; | |||
|
29 | ||||
|
30 | for (int x = 0; x <= numPoints; ++x) { | |||
|
31 | series0->add(x, fabs(sin(PI/50*x)*100)); | |||
|
32 | series1->add(x, fabs(cos(PI/50*x)*100)); | |||
|
33 | } | |||
|
34 | ||||
|
35 | QChartView* chartView = new QChartView(&window); | |||
|
36 | ||||
|
37 | chartView->setRenderHint(QPainter::Antialiasing); | |||
|
38 | chartView->setTitle("Basic line chart example"); | |||
|
39 | chartView->addSeries(series0); | |||
|
40 | chartView->addSeries(series1); | |||
|
41 | chartView->setChartBackgroundBrush(Qt::white); | |||
|
42 | ||||
|
43 | QChartAxis axis = chartView->defaultAxisX(); | |||
|
44 | axis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide); | |||
|
45 | axis.setGridPen(Qt::DashLine); | |||
|
46 | ||||
|
47 | chartView->setDefaultAxisX(axis); | |||
|
48 | //axis.setShadesBrush(Qt::gray); | |||
|
49 | chartView->setDefaultAxisY(axis); | |||
|
50 | ||||
|
51 | window.setCentralWidget(chartView); | |||
|
52 | window.resize(400, 300); | |||
|
53 | window.show(); | |||
|
54 | ||||
|
55 | return a.exec(); | |||
|
56 | } |
@@ -7,4 +7,5 SUBDIRS += linechart \ | |||||
7 | percentbarchart \ |
|
7 | percentbarchart \ | |
8 | scatter \ |
|
8 | scatter \ | |
9 | piechart \ |
|
9 | piechart \ | |
10 | dynamiclinechart |
|
10 | dynamiclinechart \ | |
|
11 | axischart |
@@ -3,18 +3,22 | |||||
3 | #include <QPainter> |
|
3 | #include <QPainter> | |
4 | #include <QDebug> |
|
4 | #include <QDebug> | |
5 |
|
5 | |||
6 | #define LABEL_PADDING 5 |
|
6 | static int label_padding = 5; | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 |
AxisItem::AxisItem( |
|
10 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : | |
11 |
|
|
11 | ChartItem(parent), | |
12 | m_axis(axis), |
|
|||
13 |
|
|
12 | m_ticks(4), | |
14 |
|
|
13 | m_type(type), | |
|
14 | m_labelsAngle(0), | |||
|
15 | m_shadesEnabled(true), | |||
|
16 | m_grid(this), | |||
|
17 | m_shades(this), | |||
|
18 | m_labels(this) | |||
15 | { |
|
19 | { | |
16 | //initial initialization |
|
20 | //initial initialization | |
17 | handleAxisChanged(); |
|
21 | createItems(); | |
18 | } |
|
22 | } | |
19 |
|
23 | |||
20 | AxisItem::~AxisItem() |
|
24 | AxisItem::~AxisItem() | |
@@ -26,63 +30,42 QRectF AxisItem::boundingRect() const | |||||
26 | return m_rect; |
|
30 | return m_rect; | |
27 | } |
|
31 | } | |
28 |
|
32 | |||
29 |
|
33 | void AxisItem::createItems() | ||
30 | /* |
|
|||
31 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) |
|
|||
32 | { |
|
34 | { | |
33 | if (!m_rect.isValid()) |
|
|||
34 | return; |
|
|||
35 |
|
||||
36 | if(m_type==X_AXIS) { |
|
|||
37 |
|
||||
38 | const qreal deltaX = m_rect.width() / m_ticks; |
|
|||
39 |
|
||||
40 |
|
|
35 | for (int i = 0; i <= m_ticks; ++i) { | |
41 |
|
36 | m_grid.addToGroup(new QGraphicsLineItem(this)); | ||
42 | int x = i * deltaX + m_rect.left(); |
|
37 | m_labels.addToGroup(new QGraphicsSimpleTextItem(this)); | |
43 |
|
38 | if(i%2) m_shades.addToGroup(new QGraphicsRectItem(this)); | ||
44 | if(i==0) x--; |
|
|||
45 | if(i==m_ticks) x++; |
|
|||
46 |
|
||||
47 | qreal label = m_plotDomain.m_minX + (i * m_plotDomain.spanX() |
|
|||
48 | / m_ticks); |
|
|||
49 | painter->drawLine(x, m_rect.top()-1, x, m_rect.bottom()+1); |
|
|||
50 | // painter->drawLine(x, m_rect.bottom()-1, x, m_rect.bottom()-1 + 5); |
|
|||
51 |
|
||||
52 | painter->drawText(x - 50, m_rect.bottom() + 5, 100, 20,Qt::AlignHCenter | Qt::AlignTop, QString::number(label)); |
|
|||
53 |
|
|
39 | } | |
54 | } |
|
40 | } | |
55 |
|
41 | |||
56 | if(m_type==Y_AXIS) { |
|
42 | void AxisItem::clear() | |
57 |
|
43 | { | ||
58 | const qreal deltaY = (m_rect.height()) / m_ticks; |
|
44 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |
|
45 | delete item; | |||
|
46 | } | |||
59 |
|
47 | |||
60 | for (int j = 0; j <= m_ticks; ++j) { |
|
48 | foreach(QGraphicsItem* item , m_grid.childItems()) { | |
|
49 | delete item; | |||
|
50 | } | |||
61 |
|
51 | |||
62 | int y = j * -deltaY + m_rect.bottom(); |
|
52 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |
|
53 | delete item; | |||
|
54 | } | |||
63 |
|
55 | |||
64 | if(j==0) y++; |
|
56 | } | |
65 | if(j==m_ticks) y--; |
|
|||
66 |
|
57 | |||
67 | qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY() |
|
58 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
68 | / m_ticks); |
|
59 | { | |
69 |
|
60 | |||
70 | painter->drawLine(m_rect.left()-1, y, m_rect.right()+1, y); |
|
|||
71 | //painter->drawLine(m_rect.left() - 5, y, m_rect.left(), y); |
|
|||
72 | //TODO : margin = 50 ; |
|
|||
73 | painter->drawText(m_rect.left() - 50, y - 10, 50 - 5, 20, |
|
|||
74 | Qt::AlignRight | Qt::AlignVCenter, |
|
|||
75 | QString::number(label)); |
|
|||
76 | } |
|
|||
77 | } |
|
61 | } | |
78 |
|
62 | |||
79 | //painter->drawRect(m_rect.adjusted(0, 0, -1, -1)); |
|
63 | void AxisItem::updateDomain() | |
80 | } |
|
|||
81 | */ |
|
|||
82 | void AxisItem::createItems() |
|
|||
83 | { |
|
64 | { | |
84 |
|
65 | |||
85 | if(!m_rect.isValid()) return; |
|
66 | QList<QGraphicsItem *> lines = m_grid.childItems(); | |
|
67 | QList<QGraphicsItem *> labels = m_labels.childItems(); | |||
|
68 | QList<QGraphicsItem *> shades = m_shades.childItems(); | |||
86 |
|
69 | |||
87 | switch (m_type) |
|
70 | switch (m_type) | |
88 | { |
|
71 | { | |
@@ -96,13 +79,19 void AxisItem::createItems() | |||||
96 |
|
79 | |||
97 | qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks); |
|
80 | qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks); | |
98 |
|
81 | |||
99 | m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this); |
|
82 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
|
83 | lineItem->setLine(x, m_rect.top(), x, m_rect.bottom()); | |||
100 |
|
84 | |||
101 |
QGraphicsSimpleTextItem* |
|
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
102 | QPointF center = text->boundingRect().center(); |
|
86 | labelItem->setText(QString::number(label)); | |
103 | text->setPos(x - center.x(), m_rect.bottom() + LABEL_PADDING); |
|
87 | QPointF center = labelItem->boundingRect().center(); | |
104 | //text->rotate(-45); |
|
88 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
105 | m_labels<<text; |
|
89 | labelItem->setPos(x - center.x(), m_rect.bottom() + label_padding); | |
|
90 | ||||
|
91 | if(i%2){ | |||
|
92 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |||
|
93 | rectItem->setRect(x,m_rect.top(),deltaX,m_rect.height()); | |||
|
94 | } | |||
106 | } |
|
95 | } | |
107 | } |
|
96 | } | |
108 | break; |
|
97 | break; | |
@@ -111,20 +100,26 void AxisItem::createItems() | |||||
111 | { |
|
100 | { | |
112 | const qreal deltaY = m_rect.height()/ m_ticks; |
|
101 | const qreal deltaY = m_rect.height()/ m_ticks; | |
113 |
|
102 | |||
114 |
for (int |
|
103 | for (int i = 0; i <= m_ticks; ++i) { | |
|
104 | ||||
|
105 | int y = i * -deltaY + m_rect.bottom(); | |||
115 |
|
106 | |||
116 | int y = j * -deltaY + m_rect.bottom(); |
|
107 | qreal label = m_domain.m_minY + (i * m_domain.spanY()/ m_ticks); | |
117 |
|
108 | |||
118 | qreal label = m_domain.m_minY + (j * m_domain.spanY() |
|
109 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
119 | / m_ticks); |
|
110 | lineItem->setLine(m_rect.left() , y, m_rect.right(), y); | |
120 |
|
111 | |||
121 | m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this); |
|
112 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
122 | QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this); |
|
113 | labelItem->setText(QString::number(label)); | |
123 |
QPointF center = |
|
114 | QPointF center = labelItem->boundingRect().center(); | |
124 | text->setPos(m_rect.left() - text->boundingRect().width() - LABEL_PADDING , y-center.y()); |
|
115 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
|
116 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , y-center.y()); | |||
125 |
|
117 | |||
126 | m_labels<<text; |
|
|||
127 |
|
118 | |||
|
119 | if(i%2){ | |||
|
120 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); | |||
|
121 | rectItem->setRect(m_rect.left(),y,m_rect.width(),deltaY); | |||
|
122 | } | |||
128 | } |
|
123 | } | |
129 | } |
|
124 | } | |
130 | break; |
|
125 | break; | |
@@ -134,41 +129,159 void AxisItem::createItems() | |||||
134 | } |
|
129 | } | |
135 | } |
|
130 | } | |
136 |
|
131 | |||
137 | void AxisItem::clear() |
|
132 | void AxisItem::handleAxisChanged(const QChartAxis& axis) | |
138 | { |
|
133 | { | |
139 | qDeleteAll(m_shades); |
|
134 | if(axis.isGridVisible()) { | |
140 | m_shades.clear(); |
|
135 | setGridOpacity(100); | |
141 | qDeleteAll(m_grid); |
|
136 | } | |
142 | m_grid.clear(); |
|
137 | else { | |
143 | qDeleteAll(m_labels); |
|
138 | setGridOpacity(0); | |
144 | m_labels.clear(); |
|
|||
145 | } |
|
139 | } | |
146 |
|
140 | |||
147 | void AxisItem::updateDomain() |
|
141 | if(axis.isLabelsVisible()) | |
148 | { |
|
142 | { | |
149 | clear(); |
|
143 | setLabelsOpacity(100); | |
150 | createItems(); |
|
144 | } | |
|
145 | else { | |||
|
146 | setLabelsOpacity(0); | |||
151 | } |
|
147 | } | |
152 |
|
148 | |||
153 | void AxisItem::handleAxisChanged() |
|
149 | if(axis.isShadesVisible()) { | |
|
150 | setShadesOpacity(100); | |||
|
151 | } | |||
|
152 | else { | |||
|
153 | setShadesOpacity(0); | |||
|
154 | } | |||
|
155 | ||||
|
156 | switch(axis.labelsOrientation()) | |||
154 | { |
|
157 | { | |
155 | //m_axis-> |
|
158 | case QChartAxis::LabelsOrientationHorizontal: | |
|
159 | setLabelsAngle(0); | |||
|
160 | break; | |||
|
161 | case QChartAxis::LabelsOrientationVertical: | |||
|
162 | setLabelsAngle(90); | |||
|
163 | break; | |||
|
164 | case QChartAxis::LabelsOrientationSlide: | |||
|
165 | setLabelsAngle(-45); | |||
|
166 | break; | |||
|
167 | default: | |||
|
168 | break; | |||
|
169 | } | |||
|
170 | ||||
|
171 | setLabelsPen(axis.labelsPen()); | |||
|
172 | setLabelsBrush(axis.labelsBrush()); | |||
|
173 | setLabelsFont(axis.labelFont()); | |||
|
174 | setGridPen(axis.gridPen()); | |||
|
175 | setShadesPen(axis.shadesPen()); | |||
|
176 | setShadesBrush(axis.shadesBrush()); | |||
|
177 | ||||
156 | } |
|
178 | } | |
157 |
|
179 | |||
158 | void AxisItem::handleDomainChanged(const Domain& domain) |
|
180 | void AxisItem::handleDomainChanged(const Domain& domain) | |
159 | { |
|
181 | { | |
160 | m_domain = domain; |
|
182 | m_domain = domain; | |
161 | clear(); |
|
183 | updateDomain(); | |
162 |
|
|
184 | update(); | |
163 | } |
|
185 | } | |
164 |
|
186 | |||
165 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
187 | void AxisItem::handleGeometryChanged(const QRectF& rect) | |
166 | { |
|
188 | { | |
167 | Q_ASSERT(rect.isValid()); |
|
|||
168 | m_rect = rect; |
|
189 | m_rect = rect; | |
|
190 | updateDomain(); | |||
|
191 | update(); | |||
|
192 | } | |||
|
193 | ||||
|
194 | void AxisItem::setGridOpacity(qreal opacity) | |||
|
195 | { | |||
|
196 | m_grid.setOpacity(opacity); | |||
|
197 | } | |||
|
198 | ||||
|
199 | ||||
|
200 | qreal AxisItem::gridOpacity() const | |||
|
201 | { | |||
|
202 | return m_grid.opacity(); | |||
|
203 | } | |||
|
204 | ||||
|
205 | void AxisItem::setLabelsOpacity(qreal opacity) | |||
|
206 | { | |||
|
207 | m_labels.setOpacity(opacity); | |||
|
208 | } | |||
|
209 | ||||
|
210 | qreal AxisItem::labelsOpacity() const | |||
|
211 | { | |||
|
212 | return m_labels.opacity(); | |||
|
213 | } | |||
|
214 | ||||
|
215 | void AxisItem::setShadesOpacity(qreal opacity) | |||
|
216 | { | |||
|
217 | m_shades.setOpacity(opacity); | |||
|
218 | } | |||
|
219 | ||||
|
220 | qreal AxisItem::shadesOpacity() const | |||
|
221 | { | |||
|
222 | return m_shades.opacity(); | |||
|
223 | } | |||
|
224 | ||||
|
225 | void AxisItem::setLabelsAngle(int angle) | |||
|
226 | { | |||
|
227 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |||
|
228 | QPointF center = item->boundingRect().center(); | |||
|
229 | item->setRotation(angle); | |||
|
230 | } | |||
|
231 | ||||
|
232 | m_labelsAngle=angle; | |||
|
233 | } | |||
|
234 | ||||
|
235 | void AxisItem::setLabelsPen(const QPen& pen) | |||
|
236 | { | |||
|
237 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |||
|
238 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |||
|
239 | } | |||
|
240 | } | |||
|
241 | ||||
|
242 | void AxisItem::setLabelsBrush(const QBrush& brush) | |||
|
243 | { | |||
|
244 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |||
|
245 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |||
|
246 | } | |||
|
247 | } | |||
|
248 | ||||
|
249 | void AxisItem::setLabelsFont(const QFont& font) | |||
|
250 | { | |||
|
251 | foreach(QGraphicsItem* item , m_labels.childItems()) { | |||
|
252 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |||
|
253 | } | |||
|
254 | } | |||
|
255 | ||||
|
256 | void AxisItem::setShadesBrush(const QBrush& brush) | |||
|
257 | { | |||
|
258 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |||
|
259 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |||
|
260 | } | |||
|
261 | } | |||
|
262 | ||||
|
263 | void AxisItem::setShadesPen(const QPen& pen) | |||
|
264 | { | |||
|
265 | foreach(QGraphicsItem* item , m_shades.childItems()) { | |||
|
266 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |||
|
267 | } | |||
|
268 | } | |||
|
269 | ||||
|
270 | void AxisItem::setGridPen(const QPen& pen) | |||
|
271 | { | |||
|
272 | foreach(QGraphicsItem* item , m_grid.childItems()) { | |||
|
273 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |||
|
274 | } | |||
|
275 | } | |||
|
276 | ||||
|
277 | void AxisItem::setTicks(int count) | |||
|
278 | { | |||
|
279 | if(count!=m_ticks){ | |||
169 | clear(); |
|
280 | clear(); | |
|
281 | m_ticks=count; | |||
170 | createItems(); |
|
282 | createItems(); | |
171 | } |
|
283 | } | |
|
284 | } | |||
172 |
|
285 | |||
173 | //TODO "nice numbers algorithm" |
|
286 | //TODO "nice numbers algorithm" | |
174 | #include "moc_axisitem_p.cpp" |
|
287 | #include "moc_axisitem_p.cpp" |
@@ -15,46 +15,58 class AxisItem : public QObject, public ChartItem | |||||
15 | public: |
|
15 | public: | |
16 | enum AxisType{X_AXIS,Y_AXIS}; |
|
16 | enum AxisType{X_AXIS,Y_AXIS}; | |
17 |
|
17 | |||
18 |
AxisItem( |
|
18 | AxisItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |
19 | ~AxisItem(); |
|
19 | ~AxisItem(); | |
20 |
|
20 | |||
21 | //from QGraphicsItem |
|
21 | //from QGraphicsItem | |
22 | QRectF boundingRect() const; |
|
22 | QRectF boundingRect() const; | |
23 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
24 |
|
24 | |||
25 | protected slots: |
|
25 | AxisType axisType() const {return m_type;}; | |
26 | void handleAxisChanged(); |
|
|||
27 | void handleDomainChanged(const Domain& domain); |
|
|||
28 | void handleGeometryChanged(const QRectF& size); |
|
|||
29 |
|
26 | |||
30 | protected: |
|
27 | void setGridOpacity(qreal opacity); | |
31 | void updateDomain(); |
|
28 | qreal gridOpacity() const; | |
32 |
|
29 | |||
33 | private: |
|
30 | void setLabelsOpacity(qreal opacity); | |
34 | void clear(); |
|
31 | qreal labelsOpacity() const; | |
35 |
|
32 | |||
36 | public: |
|
33 | void setShadesOpacity(qreal opacity); | |
37 | AxisType axisType() const {return m_type;}; |
|
34 | qreal shadesOpacity() const; | |
38 |
|
35 | |||
39 | protected: |
|
36 | void setLabelsAngle(int angle); | |
|
37 | int labelsAngle()const { return m_labelsAngle; } | |||
|
38 | ||||
|
39 | void setTicks(int count); | |||
|
40 | int ticks() const { return m_ticks;} | |||
40 |
|
41 | |||
|
42 | void setShadesBrush(const QBrush& brush); | |||
|
43 | void setShadesPen(const QPen& pen); | |||
41 |
|
44 | |||
|
45 | void setGridPen(const QPen& pen); | |||
|
46 | ||||
|
47 | void setLabelsPen(const QPen& pen); | |||
|
48 | void setLabelsBrush(const QBrush& brush); | |||
|
49 | void setLabelsFont(const QFont& font); | |||
|
50 | ||||
|
51 | public slots: | |||
|
52 | void handleAxisChanged(const QChartAxis& axis); | |||
|
53 | void handleDomainChanged(const Domain& domain); | |||
|
54 | void handleGeometryChanged(const QRectF& size); | |||
|
55 | protected: | |||
|
56 | void updateDomain(); | |||
42 | private: |
|
57 | private: | |
|
58 | void clear(); | |||
43 | void createItems(); |
|
59 | void createItems(); | |
44 | private: |
|
60 | private: | |
45 |
|
||||
46 | QChartAxis* m_axis; |
|
|||
47 | AxisType m_type; |
|
61 | AxisType m_type; | |
48 | int m_ticks; |
|
62 | int m_ticks; | |
49 | Domain m_domain; |
|
63 | Domain m_domain; | |
50 | QRectF m_rect; |
|
64 | QRectF m_rect; | |
51 |
|
65 | int m_labelsAngle; | ||
52 | QPainterPath m_path; |
|
66 | bool m_shadesEnabled; | |
53 |
|
67 | QGraphicsItemGroup m_grid; | ||
54 |
|
68 | QGraphicsItemGroup m_shades; | ||
55 |
|
|
69 | QGraphicsItemGroup m_labels; | |
56 | QList<QGraphicsRectItem*> m_shades; |
|
|||
57 | QList<QGraphicsSimpleTextItem*> m_labels; |
|
|||
58 |
|
70 | |||
59 | }; |
|
71 | }; | |
60 |
|
72 |
@@ -26,15 +26,13 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char | |||||
26 | m_chart(chart), |
|
26 | m_chart(chart), | |
27 | m_dataset(dataset), |
|
27 | m_dataset(dataset), | |
28 | m_chartTheme(0), |
|
28 | m_chartTheme(0), | |
|
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), | |||
|
30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), | |||
29 | m_domainIndex(0), |
|
31 | m_domainIndex(0), | |
30 | m_marginSize(0), |
|
32 | m_marginSize(0), | |
31 | m_axisX(new QChartAxis(this)), |
|
|||
32 | m_axisY(new QChartAxis(this)), |
|
|||
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) | |
34 | { |
|
34 | { | |
35 | setChartTheme(QChart::ChartThemeDefault); |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
36 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); |
|
|||
37 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); |
|
|||
38 | createConnections(); |
|
36 | createConnections(); | |
39 | } |
|
37 | } | |
40 |
|
38 | |||
@@ -46,14 +44,10 void ChartPresenter::createConnections() | |||||
46 | { |
|
44 | { | |
47 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
48 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); | |
49 |
|
47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); | ||
50 | QMapIterator<QChartAxis*,AxisItem*> i(m_axisItems); |
|
48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); | |
51 |
|
49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); | ||
52 | while (i.hasNext()) { |
|
50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); | |
53 | i.next(); |
|
|||
54 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),i.value(),SLOT(handleGeometryChanged(const QRectF&))); |
|
|||
55 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),i.value(),SLOT(handleDomainChanged(const Domain&))); |
|
|||
56 | } |
|
|||
57 | } |
|
51 | } | |
58 |
|
52 | |||
59 | void ChartPresenter::handleGeometryChanged() |
|
53 | void ChartPresenter::handleGeometryChanged() | |
@@ -207,6 +201,10 void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |||||
207 | index++; |
|
201 | index++; | |
208 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
202 | m_chartTheme->decorate(i.value(),i.key(),index); | |
209 |
|
|
203 | } | |
|
204 | ||||
|
205 | m_chartTheme->decorate(m_axisX, m_axisXItem); | |||
|
206 | m_chartTheme->decorate(m_axisY, m_axisYItem); | |||
|
207 | ||||
210 | } |
|
208 | } | |
211 |
|
209 | |||
212 |
|
210 | |||
@@ -215,49 +213,57 QChart::ChartTheme ChartPresenter::chartTheme() | |||||
215 | return m_chartTheme->id(); |
|
213 | return m_chartTheme->id(); | |
216 | } |
|
214 | } | |
217 |
|
215 | |||
218 | QChartAxis* ChartPresenter::axisX() |
|
216 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) | |
219 | { |
|
217 | { | |
220 | return m_axisX; |
|
218 | //if(m_axisX != axis) { | |
|
219 | m_axisX = axis; | |||
|
220 | m_axisXItem->handleAxisChanged(m_axisX); | |||
|
221 | //} | |||
221 | } |
|
222 | } | |
222 |
|
223 | |||
223 | QChartAxis* ChartPresenter::axisY() |
|
224 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) | |
224 | { |
|
225 | { | |
225 | return m_axisY; |
|
226 | // if(m_axisY != axis) { | |
|
227 | m_axisY = axis; | |||
|
228 | m_axisYItem->handleAxisChanged(m_axisY); | |||
|
229 | //} | |||
226 | } |
|
230 | } | |
227 |
|
231 | |||
228 |
QChartAxis |
|
232 | QChartAxis ChartPresenter::defaultAxisX() const | |
229 | { |
|
233 | { | |
230 | //only one axis |
|
|||
231 | if(m_axisX==0){ |
|
|||
232 | m_axisX = new QChartAxis(this); |
|
|||
233 | m_axisItems[m_axisX] = new AxisItem(m_axisX,AxisItem::X_AXIS,m_chart); |
|
|||
234 | } |
|
|||
235 | return m_axisX; |
|
234 | return m_axisX; | |
236 | } |
|
235 | } | |
237 |
|
236 | |||
238 |
QChartAxis |
|
237 | QChartAxis ChartPresenter::defaultAxisY() const | |
239 | { |
|
238 | { | |
240 | if(m_axisY==0){ |
|
|||
241 | m_axisY = new QChartAxis(this); |
|
|||
242 | m_axisItems[m_axisY] = new AxisItem(m_axisY,AxisItem::Y_AXIS,m_chart); |
|
|||
243 |
|
|
239 | return m_axisY; | |
244 | } |
|
240 | } | |
245 |
|
241 | |||
246 | QChartAxis* axis = new QChartAxis(this); |
|
242 | QChartAxis ChartPresenter::axisY(int id) const | |
247 | m_axisItems[axis] = new AxisItem(axis,AxisItem::Y_AXIS,m_chart); |
|
243 | { | |
248 | return axis; |
|
244 | return m_axis.value(id); | |
|
245 | } | |||
|
246 | ||||
|
247 | int ChartPresenter::addAxisY(const QChartAxis& axis) | |||
|
248 | { | |||
|
249 | int key =0 ; | |||
|
250 | ||||
|
251 | while(m_axis.contains(key)){ | |||
|
252 | key++; | |||
|
253 | //TODO overflow | |||
249 | } |
|
254 | } | |
250 |
|
255 | |||
251 | void ChartPresenter::removeAxis(QChartAxis* axis) |
|
256 | m_axis.insert(key,axis); | |
|
257 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); | |||
|
258 | ||||
|
259 | return key; | |||
|
260 | } | |||
|
261 | ||||
|
262 | ||||
|
263 | void ChartPresenter::removeAxisY(int id) | |||
252 | { |
|
264 | { | |
253 | AxisItem* item = m_axisItems.take(axis); |
|
265 | m_axis.remove(id); | |
254 | if(item){ |
|
266 | delete m_axisItems.take(id); | |
255 | delete item; |
|
|||
256 | delete axis; |
|
|||
257 | } |
|
|||
258 | //reset pointers to default ones |
|
|||
259 | if(axis == m_axisX) m_axisX=0; |
|
|||
260 | else if(axis == m_axisY) m_axisY=0; |
|
|||
261 | } |
|
267 | } | |
262 |
|
268 | |||
263 | #include "moc_chartpresenter_p.cpp" |
|
269 | #include "moc_chartpresenter_p.cpp" |
@@ -3,6 +3,7 | |||||
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
5 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
|
6 | #include "qchartaxis.h" | |||
6 | #include <QRectF> |
|
7 | #include <QRectF> | |
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -33,11 +34,13 public: | |||||
33 | void setChartTheme(QChart::ChartTheme theme); |
|
34 | void setChartTheme(QChart::ChartTheme theme); | |
34 | QChart::ChartTheme chartTheme(); |
|
35 | QChart::ChartTheme chartTheme(); | |
35 |
|
36 | |||
36 | QChartAxis* axisX(); |
|
37 | void setDefaultAxisX(const QChartAxis& axis); | |
37 | QChartAxis* axisY(); |
|
38 | void setDefaultAxisY(const QChartAxis& axis); | |
38 |
QChartAxis |
|
39 | QChartAxis defaultAxisX() const; | |
39 |
QChartAxis |
|
40 | QChartAxis defaultAxisY() const; | |
40 | void removeAxis(QChartAxis* axis); |
|
41 | QChartAxis axisY(int id) const; | |
|
42 | int addAxisY(const QChartAxis& axis); | |||
|
43 | void removeAxisY(int id); | |||
41 |
|
44 | |||
42 | private: |
|
45 | private: | |
43 | void createConnections(); |
|
46 | void createConnections(); | |
@@ -48,19 +51,20 public slots: | |||||
48 | void handleSeriesChanged(QChartSeries* series); |
|
51 | void handleSeriesChanged(QChartSeries* series); | |
49 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); |
|
52 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); | |
50 | void handleGeometryChanged(); |
|
53 | void handleGeometryChanged(); | |
51 |
|
||||
52 | signals: |
|
54 | signals: | |
53 | void geometryChanged(const QRectF& rect); |
|
55 | void geometryChanged(const QRectF& rect); | |
54 |
|
||||
55 | private: |
|
56 | private: | |
56 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
57 | QMap<QChartSeries*,ChartItem*> m_chartItems; | |
57 |
QMap< |
|
58 | QMap<int,AxisItem*> m_axisItems; | |
|
59 | QMap<int,QChartAxis> m_axis; | |||
58 | QChart* m_chart; |
|
60 | QChart* m_chart; | |
59 | ChartDataSet* m_dataset; |
|
61 | ChartDataSet* m_dataset; | |
60 | QVector<Domain> m_domains; |
|
62 | QVector<Domain> m_domains; | |
61 | ChartTheme *m_chartTheme; |
|
63 | ChartTheme *m_chartTheme; | |
62 |
QChartAxis |
|
64 | QChartAxis m_axisX; | |
63 |
|
|
65 | AxisItem* m_axisXItem; | |
|
66 | QChartAxis m_axisY; | |||
|
67 | AxisItem* m_axisYItem; | |||
64 | int m_domainIndex; |
|
68 | int m_domainIndex; | |
65 | int m_marginSize; |
|
69 | int m_marginSize; | |
66 | QRectF m_rect; |
|
70 | QRectF m_rect; |
@@ -1,5 +1,6 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
|
3 | #include "qchartaxis.h" | |||
3 |
|
4 | |||
4 |
|
5 | |||
5 | //series |
|
6 | //series | |
@@ -207,4 +208,13 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) | |||||
207 | } |
|
208 | } | |
208 |
|
209 | |||
209 |
|
210 | |||
|
211 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) | |||
|
212 | { | |||
|
213 | //TODO: dummy defults for now | |||
|
214 | ||||
|
215 | axis.setLabelsBrush(Qt::black); | |||
|
216 | axis.setLabelsPen(Qt::NoPen); | |||
|
217 | item->handleAxisChanged(axis); | |||
|
218 | } | |||
|
219 | ||||
210 | QTCOMMERCIALCHART_END_NAMESPACE |
|
220 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -34,6 +34,7 public: | |||||
34 | void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count); |
|
34 | void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count); | |
35 | void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count); |
|
35 | void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count); | |
36 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
36 | void decorate(PiePresenter* item, QPieSeries* series, int count); | |
|
37 | void decorate(QChartAxis& axis,AxisItem* item); | |||
37 |
|
38 | |||
38 | protected: |
|
39 | protected: | |
39 | QChart::ChartTheme m_id; |
|
40 | QChart::ChartTheme m_id; |
@@ -143,29 +143,39 void QChart::zoomReset() | |||||
143 | m_presenter->zoomReset(); |
|
143 | m_presenter->zoomReset(); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | QChartAxis* QChart::axisX() |
|
146 | void QChart::setDefaultAxisX(const QChartAxis& axis) | |
147 | { |
|
147 | { | |
148 |
|
|
148 | m_presenter->setDefaultAxisX(axis); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | QChartAxis* QChart::axisY() |
|
151 | void QChart::setDefaultAxisY(const QChartAxis& axis) | |
152 | { |
|
152 | { | |
153 |
|
|
153 | m_presenter->setDefaultAxisY(axis); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 |
QChartAxis |
|
156 | QChartAxis QChart::defaultAxisX() const | |
157 | { |
|
157 | { | |
158 |
return m_presenter-> |
|
158 | return m_presenter->defaultAxisX(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 |
QChartAxis |
|
161 | QChartAxis QChart::defaultAxisY() const | |
162 | { |
|
162 | { | |
163 |
return m_presenter-> |
|
163 | return m_presenter->defaultAxisY(); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 |
|
|
166 | int QChart::addAxisY(const QChartAxis& axis) | |
167 | { |
|
167 | { | |
168 |
m_presenter-> |
|
168 | return m_presenter->addAxisY(axis); | |
|
169 | } | |||
|
170 | ||||
|
171 | QChartAxis QChart::axisY(int id) const | |||
|
172 | { | |||
|
173 | return m_presenter->axisY(id); | |||
|
174 | } | |||
|
175 | ||||
|
176 | void QChart::removeAxisY(int id) | |||
|
177 | { | |||
|
178 | m_presenter->removeAxisY(id); | |||
169 | } |
|
179 | } | |
170 |
|
180 | |||
171 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
181 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
@@ -67,11 +67,13 public: | |||||
67 | void zoomOut(); |
|
67 | void zoomOut(); | |
68 | void zoomReset(); |
|
68 | void zoomReset(); | |
69 |
|
69 | |||
70 | QChartAxis* axisX(); |
|
70 | void setDefaultAxisX(const QChartAxis& axis); | |
71 | QChartAxis* axisY(); |
|
71 | void setDefaultAxisY(const QChartAxis& axis); | |
72 |
QChartAxis |
|
72 | QChartAxis defaultAxisX() const; | |
73 |
QChartAxis |
|
73 | QChartAxis defaultAxisY() const; | |
74 | void removeAxis(QChartAxis* axis); |
|
74 | QChartAxis axisY(int id) const; | |
|
75 | int addAxisY(const QChartAxis& axis); | |||
|
76 | void removeAxisY(int id); | |||
75 |
|
77 | |||
76 | protected: |
|
78 | protected: | |
77 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
79 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
@@ -1,13 +1,12 | |||||
1 |
|
||||
2 |
|
|
1 | #include "qchartaxis.h" | |
3 |
|
2 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
4 | |||
6 |
QChartAxis::QChartAxis( |
|
5 | QChartAxis::QChartAxis(): | |
7 | m_axisVisible(true), |
|
6 | m_axisVisible(true), | |
8 |
m_g |
|
7 | m_gridVisible(true), | |
9 | m_labelsVisible(true), |
|
8 | m_labelsVisible(true), | |
10 |
m_ |
|
9 | m_shadesVisible(true) | |
11 | { |
|
10 | { | |
12 | // TODO Auto-generated constructor stub |
|
11 | // TODO Auto-generated constructor stub | |
13 |
|
12 | |||
@@ -35,7 +34,12 void QChartAxis::setAxisVisible(bool visible) | |||||
35 |
|
34 | |||
36 | void QChartAxis::setGridVisible(bool visible) |
|
35 | void QChartAxis::setGridVisible(bool visible) | |
37 | { |
|
36 | { | |
38 |
m_g |
|
37 | m_gridVisible=visible; | |
|
38 | } | |||
|
39 | ||||
|
40 | void QChartAxis::setGridPen(const QPen& pen) | |||
|
41 | { | |||
|
42 | m_gridPen=pen; | |||
39 | } |
|
43 | } | |
40 |
|
44 | |||
41 | void QChartAxis::setLabelsVisible(bool visible) |
|
45 | void QChartAxis::setLabelsVisible(bool visible) | |
@@ -43,11 +47,40 void QChartAxis::setLabelsVisible(bool visible) | |||||
43 | m_labelsVisible=visible; |
|
47 | m_labelsVisible=visible; | |
44 | } |
|
48 | } | |
45 |
|
49 | |||
46 | void QChartAxis::setRowShadesVisible(bool visible) |
|
50 | void QChartAxis::setLabelsPen(const QPen& pen) | |
|
51 | { | |||
|
52 | m_labelsPen=pen; | |||
|
53 | } | |||
|
54 | ||||
|
55 | void QChartAxis::setLabelsBrush(const QBrush& brush) | |||
|
56 | { | |||
|
57 | m_labelsBrush=brush; | |||
|
58 | } | |||
|
59 | ||||
|
60 | void QChartAxis::setLabelsFont(const QFont& font) | |||
|
61 | { | |||
|
62 | m_labelsFont=font; | |||
|
63 | } | |||
|
64 | ||||
|
65 | void QChartAxis::setLabelsOrientation(LabelsOrientation orientation) | |||
|
66 | { | |||
|
67 | m_labelsOrientation=orientation; | |||
|
68 | } | |||
|
69 | ||||
|
70 | void QChartAxis::setShadesVisible(bool visible) | |||
|
71 | { | |||
|
72 | m_shadesVisible=visible; | |||
|
73 | } | |||
|
74 | ||||
|
75 | void QChartAxis::setShadesPen(const QPen& pen) | |||
|
76 | { | |||
|
77 | m_shadesPen=pen; | |||
|
78 | } | |||
|
79 | ||||
|
80 | void QChartAxis::setShadesBrush(const QBrush& brush) | |||
47 | { |
|
81 | { | |
48 | m_rowShadesVisible=visible; |
|
82 | m_shadesBrush=brush; | |
49 | } |
|
83 | } | |
50 |
|
84 | |||
51 | #include "moc_qchartaxis.cpp" |
|
|||
52 |
|
85 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -3,62 +3,52 | |||||
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
|
6 | #include <QFont> | |||
6 |
|
7 | |||
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
10 | |||
10 |
class QChartAxis |
|
11 | class QChartAxis | |
11 | { |
|
12 | { | |
12 | Q_OBJECT |
|
|||
13 |
|
||||
14 | Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); |
|
|||
15 | Q_PROPERTY(QPen axisPen READ axisPen WRITE setAxisPen NOTIFY axisPenChanged); |
|
|||
16 | Q_PROPERTY(QBrush axisBrush READ axisBrush WRITE setAxisBrush NOTIFY axisBurshChanged); |
|
|||
17 |
|
||||
18 | // Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY axisVisibilityChanged); |
|
|||
19 | public: |
|
13 | public: | |
20 | enum LabelOrientation{ HORIZONTAL, VERTICAL , SLIDE }; |
|
14 | enum LabelsOrientation{ LabelsOrientationHorizontal, LabelsOrientationVertical , LabelsOrientationSlide }; | |
21 |
|
15 | |||
22 |
QChartAxis( |
|
16 | QChartAxis(); | |
23 | virtual ~QChartAxis(); |
|
17 | virtual ~QChartAxis(); | |
24 |
|
18 | |||
25 | //axis |
|
19 | //axis | |
26 | bool isAxisVisible() const { return m_axisVisible;}; |
|
20 | bool isAxisVisible() const { return m_axisVisible;}; | |
27 | void setAxisVisible(bool visible); |
|
21 | void setAxisVisible(bool visible); | |
28 | void setAxisPen(const QPen& pen); |
|
22 | void setAxisPen(const QPen& pen); | |
29 |
|
|
23 | QPen axisPen() const { return m_axisPen;}; | |
30 | void setAxisBrush(const QBrush& brush); |
|
24 | void setAxisBrush(const QBrush& brush); | |
31 |
|
|
25 | QBrush axisBrush() const { return m_axisBrush;}; | |
32 |
|
26 | |||
33 | //grid |
|
27 | //grid | |
34 |
bool isGridVisible() const { return m_g |
|
28 | bool isGridVisible() const { return m_gridVisible;}; | |
35 | void setGridVisible(bool visible); |
|
29 | void setGridVisible(bool visible); | |
|
30 | void setGridPen(const QPen& pen); | |||
|
31 | QPen gridPen() const {return m_gridPen;} | |||
36 |
|
32 | |||
|
33 | //labels | |||
37 | bool isLabelsVisible() const { return m_labelsVisible;}; |
|
34 | bool isLabelsVisible() const { return m_labelsVisible;}; | |
38 | void setLabelsVisible(bool visible); |
|
35 | void setLabelsVisible(bool visible); | |
39 |
|
36 | void setLabelsPen(const QPen& pen); | ||
40 | bool isRowShadesVisible() const { return m_rowShadesVisible;}; |
|
37 | QPen labelsPen() const { return m_labelsPen;} | |
41 | void setRowShadesVisible(bool visible); |
|
38 | void setLabelsBrush(const QBrush& brush); | |
42 |
|
39 | QBrush labelsBrush() const { return m_labelsBrush;} | ||
43 | /* |
|
40 | void setLabelsFont(const QFont& font); | |
44 | void setLabelFont(const QFont& font); |
|
41 | QFont labelFont() const { return m_labelsFont;} | |
45 | const QFont& labelFont(); |
|
42 | void setLabelsOrientation(LabelsOrientation orientation); | |
46 |
|
43 | LabelsOrientation labelsOrientation() const { return m_labelsOrientation;}; | ||
47 | void setLabelPen(const QPen& pen); |
|
44 | ||
48 | const QPen& labelPen(); |
|
45 | //shades | |
49 |
|
46 | bool isShadesVisible() const { return m_shadesVisible;}; | ||
50 | void setGridPen(const QPen& pen); |
|
47 | void setShadesVisible(bool visible); | |
51 |
const QPen& |
|
48 | void setShadesPen(const QPen& pen); | |
52 |
|
49 | QPen shadesPen() const { return m_shadesPen;} | ||
53 |
void set |
|
50 | void setShadesBrush(const QBrush& brush); | |
54 | const QBrush& gridBrush(); |
|
51 | QBrush shadesBrush() const { return m_shadesBrush;} | |
55 | */ |
|
|||
56 |
|
||||
57 |
|
||||
58 | signals: |
|
|||
59 | void axisVisibilityChanged(); |
|
|||
60 | void axisPenChanged(); |
|
|||
61 | void axisBurshChanged(); |
|
|||
62 |
|
52 | |||
63 |
|
53 | |||
64 | private: |
|
54 | private: | |
@@ -67,9 +57,19 private: | |||||
67 | QPen m_axisPen; |
|
57 | QPen m_axisPen; | |
68 | QBrush m_axisBrush; |
|
58 | QBrush m_axisBrush; | |
69 |
|
59 | |||
70 |
bool m_g |
|
60 | bool m_gridVisible; | |
|
61 | QPen m_gridPen; | |||
|
62 | ||||
71 | bool m_labelsVisible; |
|
63 | bool m_labelsVisible; | |
72 | bool m_rowShadesVisible; |
|
64 | QPen m_labelsPen; | |
|
65 | QBrush m_labelsBrush; | |||
|
66 | QFont m_labelsFont; | |||
|
67 | ||||
|
68 | bool m_shadesVisible; | |||
|
69 | QPen m_shadesPen; | |||
|
70 | QBrush m_shadesBrush; | |||
|
71 | ||||
|
72 | LabelsOrientation m_labelsOrientation; | |||
73 | }; |
|
73 | }; | |
74 |
|
74 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,5 +1,6 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
|
3 | #include "qchartaxis.h" | |||
3 | #include <QGraphicsView> |
|
4 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
5 | #include <QRubberBand> |
|
6 | #include <QRubberBand> | |
@@ -35,7 +36,6 void QChartView::resizeEvent(QResizeEvent *event) | |||||
35 | QWidget::resizeEvent(event); |
|
36 | QWidget::resizeEvent(event); | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 |
|
||||
39 | void QChartView::addSeries(QChartSeries* series) |
|
39 | void QChartView::addSeries(QChartSeries* series) | |
40 | { |
|
40 | { | |
41 | m_chart->addSeries(series); |
|
41 | m_chart->addSeries(series); | |
@@ -81,7 +81,6 void QChartView::setChartBackgroundPen(const QPen& pen) | |||||
81 |
|
|
81 | m_chart->setChartBackgroundPen(pen); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 |
|
||||
85 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
84 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |
86 | { |
|
85 | { | |
87 | switch(policy){ |
|
86 | switch(policy) { | |
@@ -119,7 +118,6 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |||||
119 | return NoRubberBand; |
|
118 | return NoRubberBand; | |
120 | } |
|
119 | } | |
121 |
|
120 | |||
122 |
|
||||
123 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
121 | void QChartView::mousePressEvent(QMouseEvent *event) | |
124 | { |
|
122 | { | |
125 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
123 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
@@ -152,7 +150,8 void QChartView::mouseMoveEvent(QMouseEvent *event) | |||||
152 | width= rect.width(); |
|
150 | width= rect.width(); | |
153 | } |
|
151 | } | |
154 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
152 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |
155 | } else { |
|
153 | } | |
|
154 | else { | |||
156 | QGraphicsView::mouseMoveEvent(event); |
|
155 | QGraphicsView::mouseMoveEvent(event); | |
157 | } |
|
156 | } | |
158 | } |
|
157 | } | |
@@ -169,7 +168,8 void QChartView::mouseReleaseEvent(QMouseEvent *event) | |||||
169 |
|
168 | |||
170 | if(event->button()==Qt::RightButton) |
|
169 | if(event->button()==Qt::RightButton) | |
171 | m_chart->zoomReset(); |
|
170 | m_chart->zoomReset(); | |
172 |
} |
|
171 | } | |
|
172 | else { | |||
173 | QGraphicsView::mouseReleaseEvent(event); |
|
173 | QGraphicsView::mouseReleaseEvent(event); | |
174 | } |
|
174 | } | |
175 | } |
|
175 | } | |
@@ -199,29 +199,38 QChart::ChartTheme QChartView::chartTheme() const | |||||
199 | return m_chart->chartTheme(); |
|
199 | return m_chart->chartTheme(); | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | QChartAxis* QChartView::axisX() |
|
202 | void QChartView::setDefaultAxisX(const QChartAxis& axis) | |
203 | { |
|
203 | { | |
204 |
|
|
204 | m_chart->setDefaultAxisX(axis); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | QChartAxis* QChartView::axisY() |
|
207 | void QChartView::setDefaultAxisY(const QChartAxis& axis) | |
208 | { |
|
208 | { | |
209 |
|
|
209 | m_chart->setDefaultAxisY(axis); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 |
QChartAxis |
|
212 | QChartAxis QChartView::defaultAxisX() const | |
213 | { |
|
213 | { | |
214 |
return m_chart-> |
|
214 | return m_chart->defaultAxisX(); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 |
QChartAxis |
|
217 | QChartAxis QChartView::defaultAxisY() const | |
218 | { |
|
218 | { | |
219 |
return m_chart-> |
|
219 | return m_chart->defaultAxisY(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 |
|
|
222 | int QChartView::addAxisY(const QChartAxis& axis) | |
223 | { |
|
223 | { | |
224 |
m_chart-> |
|
224 | return m_chart->addAxisY(axis); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
|
227 | QChartAxis QChartView::axisY(int id) const | |||
|
228 | { | |||
|
229 | return m_chart->axisY(id); | |||
|
230 | } | |||
|
231 | ||||
|
232 | void QChartView::removeAxisY(int id) | |||
|
233 | { | |||
|
234 | m_chart->removeAxisY(id); | |||
|
235 | } | |||
227 | QTCOMMERCIALCHART_END_NAMESPACE |
|
236 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -45,11 +45,13 public: | |||||
45 | void setChartTheme(QChart::ChartTheme theme); |
|
45 | void setChartTheme(QChart::ChartTheme theme); | |
46 | QChart::ChartTheme chartTheme() const; |
|
46 | QChart::ChartTheme chartTheme() const; | |
47 |
|
47 | |||
48 | QChartAxis* axisX(); |
|
48 | void setDefaultAxisX(const QChartAxis& axis); | |
49 | QChartAxis* axisY(); |
|
49 | void setDefaultAxisY(const QChartAxis& axis); | |
50 |
QChartAxis |
|
50 | QChartAxis defaultAxisX() const; | |
51 |
QChartAxis |
|
51 | QChartAxis defaultAxisY() const; | |
52 | void removeAxis(QChartAxis* axis); |
|
52 | QChartAxis axisY(int id) const; | |
|
53 | int addAxisY(const QChartAxis& axis); | |||
|
54 | void removeAxisY(int id); | |||
53 |
|
55 | |||
54 | protected: |
|
56 | protected: | |
55 | void mousePressEvent(QMouseEvent *event); |
|
57 | void mousePressEvent(QMouseEvent *event); |
General Comments 0
You need to be logged in to leave comments.
Login now