##// END OF EJS Templates
Adds more axis handling...
Michal Klocek -
r176:6a1519e364a3
parent child
Show More
@@ -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 7 percentbarchart \
8 8 scatter \
9 9 piechart \
10 dynamiclinechart
10 dynamiclinechart \
11 axischart
@@ -3,18 +3,22
3 3 #include <QPainter>
4 4 #include <QDebug>
5 5
6 #define LABEL_PADDING 5
6 static int label_padding = 5;
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 AxisItem::AxisItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) :
10 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) :
11 11 ChartItem(parent),
12 m_axis(axis),
13 12 m_ticks(4),
14 m_type(type)
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 20 //initial initialization
17 handleAxisChanged();
21 createItems();
18 22 }
19 23
20 24 AxisItem::~AxisItem()
@@ -26,63 +30,42 QRectF AxisItem::boundingRect() const
26 30 return m_rect;
27 31 }
28 32
29
30 /*
31 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
33 void AxisItem::createItems()
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
42 int x = i * deltaX + m_rect.left();
43
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));
36 m_grid.addToGroup(new QGraphicsLineItem(this));
37 m_labels.addToGroup(new QGraphicsSimpleTextItem(this));
38 if(i%2) m_shades.addToGroup(new QGraphicsRectItem(this));
53 39 }
54 40 }
55 41
56 if(m_type==Y_AXIS) {
57
58 const qreal deltaY = (m_rect.height()) / m_ticks;
42 void AxisItem::clear()
43 {
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++;
65 if(j==m_ticks) y--;
56 }
66 57
67 qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY()
68 / m_ticks);
58 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
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));
80 }
81 */
82 void AxisItem::createItems()
63 void AxisItem::updateDomain()
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 70 switch (m_type)
88 71 {
@@ -96,13 +79,19 void AxisItem::createItems()
96 79
97 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* text = new QGraphicsSimpleTextItem(QString::number(label),this);
102 QPointF center = text->boundingRect().center();
103 text->setPos(x - center.x(), m_rect.bottom() + LABEL_PADDING);
104 //text->rotate(-45);
105 m_labels<<text;
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
86 labelItem->setText(QString::number(label));
87 QPointF center = labelItem->boundingRect().center();
88 labelItem->setTransformOriginPoint(center.x(), center.y());
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 97 break;
@@ -111,20 +100,26 void AxisItem::createItems()
111 100 {
112 101 const qreal deltaY = m_rect.height()/ m_ticks;
113 102
114 for (int j = 0; j <= m_ticks; ++j) {
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()
119 / m_ticks);
109 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
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);
122 QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(QString::number(label),this);
123 QPointF center = text->boundingRect().center();
124 text->setPos(m_rect.left() - text->boundingRect().width() - LABEL_PADDING , y-center.y());
112 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
113 labelItem->setText(QString::number(label));
114 QPointF center = labelItem->boundingRect().center();
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 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);
140 m_shades.clear();
141 qDeleteAll(m_grid);
142 m_grid.clear();
143 qDeleteAll(m_labels);
144 m_labels.clear();
134 if(axis.isGridVisible()) {
135 setGridOpacity(100);
136 }
137 else {
138 setGridOpacity(0);
145 139 }
146 140
147 void AxisItem::updateDomain()
141 if(axis.isLabelsVisible())
148 142 {
149 clear();
150 createItems();
143 setLabelsOpacity(100);
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 180 void AxisItem::handleDomainChanged(const Domain& domain)
159 181 {
160 182 m_domain = domain;
161 clear();
162 createItems();
183 updateDomain();
184 update();
163 185 }
164 186
165 187 void AxisItem::handleGeometryChanged(const QRectF& rect)
166 188 {
167 Q_ASSERT(rect.isValid());
168 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 280 clear();
281 m_ticks=count;
170 282 createItems();
171 283 }
284 }
172 285
173 286 //TODO "nice numbers algorithm"
174 287 #include "moc_axisitem_p.cpp"
@@ -15,46 +15,58 class AxisItem : public QObject, public ChartItem
15 15 public:
16 16 enum AxisType{X_AXIS,Y_AXIS};
17 17
18 AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0);
18 AxisItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0);
19 19 ~AxisItem();
20 20
21 21 //from QGraphicsItem
22 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:
26 void handleAxisChanged();
27 void handleDomainChanged(const Domain& domain);
28 void handleGeometryChanged(const QRectF& size);
25 AxisType axisType() const {return m_type;};
29 26
30 protected:
31 void updateDomain();
27 void setGridOpacity(qreal opacity);
28 qreal gridOpacity() const;
32 29
33 private:
34 void clear();
30 void setLabelsOpacity(qreal opacity);
31 qreal labelsOpacity() const;
35 32
36 public:
37 AxisType axisType() const {return m_type;};
33 void setShadesOpacity(qreal opacity);
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 57 private:
58 void clear();
43 59 void createItems();
44 60 private:
45
46 QChartAxis* m_axis;
47 61 AxisType m_type;
48 62 int m_ticks;
49 63 Domain m_domain;
50 64 QRectF m_rect;
51
52 QPainterPath m_path;
53
54
55 QList<QGraphicsLineItem*> m_grid;
56 QList<QGraphicsRectItem*> m_shades;
57 QList<QGraphicsSimpleTextItem*> m_labels;
65 int m_labelsAngle;
66 bool m_shadesEnabled;
67 QGraphicsItemGroup m_grid;
68 QGraphicsItemGroup m_shades;
69 QGraphicsItemGroup m_labels;
58 70
59 71 };
60 72
@@ -26,15 +26,13 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char
26 26 m_chart(chart),
27 27 m_dataset(dataset),
28 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 31 m_domainIndex(0),
30 32 m_marginSize(0),
31 m_axisX(new QChartAxis(this)),
32 m_axisY(new QChartAxis(this)),
33 33 m_rect(QRectF(QPoint(0,0),m_chart->size()))
34 34 {
35 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 36 createConnections();
39 37 }
40 38
@@ -46,14 +44,10 void ChartPresenter::createConnections()
46 44 {
47 45 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
48 46 QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
49
50 QMapIterator<QChartAxis*,AxisItem*> i(m_axisItems);
51
52 while (i.hasNext()) {
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 }
47 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&)));
48 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&)));
49 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&)));
50 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&)));
57 51 }
58 52
59 53 void ChartPresenter::handleGeometryChanged()
@@ -207,6 +201,10 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
207 201 index++;
208 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 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* ChartPresenter::addAxisX()
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 234 return m_axisX;
236 235 }
237 236
238 QChartAxis* ChartPresenter::addAxisY()
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);
247 m_axisItems[axis] = new AxisItem(axis,AxisItem::Y_AXIS,m_chart);
248 return axis;
242 QChartAxis ChartPresenter::axisY(int id) const
243 {
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);
254 if(item){
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;
265 m_axis.remove(id);
266 delete m_axisItems.take(id);
261 267 }
262 268
263 269 #include "moc_chartpresenter_p.cpp"
@@ -3,6 +3,7
3 3
4 4 #include "qchartglobal.h"
5 5 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
6 #include "qchartaxis.h"
6 7 #include <QRectF>
7 8
8 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -33,11 +34,13 public:
33 34 void setChartTheme(QChart::ChartTheme theme);
34 35 QChart::ChartTheme chartTheme();
35 36
36 QChartAxis* axisX();
37 QChartAxis* axisY();
38 QChartAxis* addAxisX();
39 QChartAxis* addAxisY();
40 void removeAxis(QChartAxis* axis);
37 void setDefaultAxisX(const QChartAxis& axis);
38 void setDefaultAxisY(const QChartAxis& axis);
39 QChartAxis defaultAxisX() const;
40 QChartAxis defaultAxisY() const;
41 QChartAxis axisY(int id) const;
42 int addAxisY(const QChartAxis& axis);
43 void removeAxisY(int id);
41 44
42 45 private:
43 46 void createConnections();
@@ -48,19 +51,20 public slots:
48 51 void handleSeriesChanged(QChartSeries* series);
49 52 //void handleDomainChanged(Domain oldDomain,Domain newDomain);
50 53 void handleGeometryChanged();
51
52 54 signals:
53 55 void geometryChanged(const QRectF& rect);
54
55 56 private:
56 57 QMap<QChartSeries*,ChartItem*> m_chartItems;
57 QMap<QChartAxis*,AxisItem*> m_axisItems;
58 QMap<int,AxisItem*> m_axisItems;
59 QMap<int,QChartAxis> m_axis;
58 60 QChart* m_chart;
59 61 ChartDataSet* m_dataset;
60 62 QVector<Domain> m_domains;
61 63 ChartTheme *m_chartTheme;
62 QChartAxis* m_axisX;
63 QChartAxis* m_axisY;
64 QChartAxis m_axisX;
65 AxisItem* m_axisXItem;
66 QChartAxis m_axisY;
67 AxisItem* m_axisYItem;
64 68 int m_domainIndex;
65 69 int m_marginSize;
66 70 QRectF m_rect;
@@ -1,5 +1,6
1 1 #include "charttheme_p.h"
2 2 #include "qchart.h"
3 #include "qchartaxis.h"
3 4
4 5
5 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 220 QTCOMMERCIALCHART_END_NAMESPACE
@@ -34,6 +34,7 public:
34 34 void decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count);
35 35 void decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count);
36 36 void decorate(PiePresenter* item, QPieSeries* series, int count);
37 void decorate(QChartAxis& axis,AxisItem* item);
37 38
38 39 protected:
39 40 QChart::ChartTheme m_id;
@@ -143,29 +143,39 void QChart::zoomReset()
143 143 m_presenter->zoomReset();
144 144 }
145 145
146 QChartAxis* QChart::axisX()
146 void QChart::setDefaultAxisX(const QChartAxis& axis)
147 147 {
148 return m_presenter->axisX();
148 m_presenter->setDefaultAxisX(axis);
149 149 }
150 150
151 QChartAxis* QChart::axisY()
151 void QChart::setDefaultAxisY(const QChartAxis& axis)
152 152 {
153 return m_presenter->axisY();
153 m_presenter->setDefaultAxisY(axis);
154 154 }
155 155
156 QChartAxis* QChart::addAxisX()
156 QChartAxis QChart::defaultAxisX() const
157 157 {
158 return m_presenter->addAxisX();
158 return m_presenter->defaultAxisX();
159 159 }
160 160
161 QChartAxis* QChart::addAxisY()
161 QChartAxis QChart::defaultAxisY() const
162 162 {
163 return m_presenter->addAxisY();
163 return m_presenter->defaultAxisY();
164 164 }
165 165
166 void QChart::removeAxis(QChartAxis* axis)
166 int QChart::addAxisY(const QChartAxis& axis)
167 167 {
168 m_presenter->removeAxis(axis);
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 181 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
@@ -67,11 +67,13 public:
67 67 void zoomOut();
68 68 void zoomReset();
69 69
70 QChartAxis* axisX();
71 QChartAxis* axisY();
72 QChartAxis* addAxisX();
73 QChartAxis* addAxisY();
74 void removeAxis(QChartAxis* axis);
70 void setDefaultAxisX(const QChartAxis& axis);
71 void setDefaultAxisY(const QChartAxis& axis);
72 QChartAxis defaultAxisX() const;
73 QChartAxis defaultAxisY() const;
74 QChartAxis axisY(int id) const;
75 int addAxisY(const QChartAxis& axis);
76 void removeAxisY(int id);
75 77
76 78 protected:
77 79 void resizeEvent(QGraphicsSceneResizeEvent *event);
@@ -1,13 +1,12
1
2 1 #include "qchartaxis.h"
3 2
4 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 4
6 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
5 QChartAxis::QChartAxis():
7 6 m_axisVisible(true),
8 m_girdVisible(true),
7 m_gridVisible(true),
9 8 m_labelsVisible(true),
10 m_rowShadesVisible(true)
9 m_shadesVisible(true)
11 10 {
12 11 // TODO Auto-generated constructor stub
13 12
@@ -35,7 +34,12 void QChartAxis::setAxisVisible(bool visible)
35 34
36 35 void QChartAxis::setGridVisible(bool visible)
37 36 {
38 m_girdVisible=visible;
37 m_gridVisible=visible;
38 }
39
40 void QChartAxis::setGridPen(const QPen& pen)
41 {
42 m_gridPen=pen;
39 43 }
40 44
41 45 void QChartAxis::setLabelsVisible(bool visible)
@@ -43,11 +47,40 void QChartAxis::setLabelsVisible(bool visible)
43 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 86 QTCOMMERCIALCHART_END_NAMESPACE
@@ -3,62 +3,52
3 3
4 4 #include <qchartglobal.h>
5 5 #include <QPen>
6 #include <QFont>
6 7
7 8
8 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 10
10 class QChartAxis : public QObject
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 13 public:
20 enum LabelOrientation{ HORIZONTAL, VERTICAL , SLIDE };
14 enum LabelsOrientation{ LabelsOrientationHorizontal, LabelsOrientationVertical , LabelsOrientationSlide };
21 15
22 QChartAxis(QObject* parent = 0);
16 QChartAxis();
23 17 virtual ~QChartAxis();
24 18
25 19 //axis
26 20 bool isAxisVisible() const { return m_axisVisible;};
27 21 void setAxisVisible(bool visible);
28 22 void setAxisPen(const QPen& pen);
29 const QPen& axisPen() const { return m_axisPen;};
23 QPen axisPen() const { return m_axisPen;};
30 24 void setAxisBrush(const QBrush& brush);
31 const QBrush& axisBrush() const { return m_axisBrush;};
25 QBrush axisBrush() const { return m_axisBrush;};
32 26
33 27 //grid
34 bool isGridVisible() const { return m_girdVisible;};
28 bool isGridVisible() const { return m_gridVisible;};
35 29 void setGridVisible(bool visible);
30 void setGridPen(const QPen& pen);
31 QPen gridPen() const {return m_gridPen;}
36 32
33 //labels
37 34 bool isLabelsVisible() const { return m_labelsVisible;};
38 35 void setLabelsVisible(bool visible);
39
40 bool isRowShadesVisible() const { return m_rowShadesVisible;};
41 void setRowShadesVisible(bool visible);
42
43 /*
44 void setLabelFont(const QFont& font);
45 const QFont& labelFont();
46
47 void setLabelPen(const QPen& pen);
48 const QPen& labelPen();
49
50 void setGridPen(const QPen& pen);
51 const QPen& gridPen();
52
53 void setGridBrush(const QBrush& brush);
54 const QBrush& gridBrush();
55 */
56
57
58 signals:
59 void axisVisibilityChanged();
60 void axisPenChanged();
61 void axisBurshChanged();
36 void setLabelsPen(const QPen& pen);
37 QPen labelsPen() const { return m_labelsPen;}
38 void setLabelsBrush(const QBrush& brush);
39 QBrush labelsBrush() const { return m_labelsBrush;}
40 void setLabelsFont(const QFont& font);
41 QFont labelFont() const { return m_labelsFont;}
42 void setLabelsOrientation(LabelsOrientation orientation);
43 LabelsOrientation labelsOrientation() const { return m_labelsOrientation;};
44
45 //shades
46 bool isShadesVisible() const { return m_shadesVisible;};
47 void setShadesVisible(bool visible);
48 void setShadesPen(const QPen& pen);
49 QPen shadesPen() const { return m_shadesPen;}
50 void setShadesBrush(const QBrush& brush);
51 QBrush shadesBrush() const { return m_shadesBrush;}
62 52
63 53
64 54 private:
@@ -67,9 +57,19 private:
67 57 QPen m_axisPen;
68 58 QBrush m_axisBrush;
69 59
70 bool m_girdVisible;
60 bool m_gridVisible;
61 QPen m_gridPen;
62
71 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 75 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,5 +1,6
1 1 #include "qchartview.h"
2 2 #include "qchart.h"
3 #include "qchartaxis.h"
3 4 #include <QGraphicsView>
4 5 #include <QGraphicsScene>
5 6 #include <QRubberBand>
@@ -35,7 +36,6 void QChartView::resizeEvent(QResizeEvent *event)
35 36 QWidget::resizeEvent(event);
36 37 }
37 38
38
39 39 void QChartView::addSeries(QChartSeries* series)
40 40 {
41 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 84 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
86 85 {
87 86 switch(policy){
@@ -119,7 +118,6 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
119 118 return NoRubberBand;
120 119 }
121 120
122
123 121 void QChartView::mousePressEvent(QMouseEvent *event)
124 122 {
125 123 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
@@ -152,7 +150,8 void QChartView::mouseMoveEvent(QMouseEvent *event)
152 150 width= rect.width();
153 151 }
154 152 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
155 } else {
153 }
154 else {
156 155 QGraphicsView::mouseMoveEvent(event);
157 156 }
158 157 }
@@ -169,7 +168,8 void QChartView::mouseReleaseEvent(QMouseEvent *event)
169 168
170 169 if(event->button()==Qt::RightButton)
171 170 m_chart->zoomReset();
172 }else{
171 }
172 else {
173 173 QGraphicsView::mouseReleaseEvent(event);
174 174 }
175 175 }
@@ -199,29 +199,38 QChart::ChartTheme QChartView::chartTheme() const
199 199 return m_chart->chartTheme();
200 200 }
201 201
202 QChartAxis* QChartView::axisX()
202 void QChartView::setDefaultAxisX(const QChartAxis& axis)
203 203 {
204 return m_chart->axisX();
204 m_chart->setDefaultAxisX(axis);
205 205 }
206 206
207 QChartAxis* QChartView::axisY()
207 void QChartView::setDefaultAxisY(const QChartAxis& axis)
208 208 {
209 return m_chart->axisY();
209 m_chart->setDefaultAxisY(axis);
210 210 }
211 211
212 QChartAxis* QChartView::addAxisX()
212 QChartAxis QChartView::defaultAxisX() const
213 213 {
214 return m_chart->addAxisX();
214 return m_chart->defaultAxisX();
215 215 }
216 216
217 QChartAxis* QChartView::addAxisY()
217 QChartAxis QChartView::defaultAxisY() const
218 218 {
219 return m_chart->addAxisY();
219 return m_chart->defaultAxisY();
220 220 }
221 221
222 void QChartView::removeAxis(QChartAxis* axis)
222 int QChartView::addAxisY(const QChartAxis& axis)
223 223 {
224 m_chart->removeAxis(axis);
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 236 QTCOMMERCIALCHART_END_NAMESPACE
@@ -45,11 +45,13 public:
45 45 void setChartTheme(QChart::ChartTheme theme);
46 46 QChart::ChartTheme chartTheme() const;
47 47
48 QChartAxis* axisX();
49 QChartAxis* axisY();
50 QChartAxis* addAxisX();
51 QChartAxis* addAxisY();
52 void removeAxis(QChartAxis* axis);
48 void setDefaultAxisX(const QChartAxis& axis);
49 void setDefaultAxisY(const QChartAxis& axis);
50 QChartAxis defaultAxisX() const;
51 QChartAxis defaultAxisY() const;
52 QChartAxis axisY(int id) const;
53 int addAxisY(const QChartAxis& axis);
54 void removeAxisY(int id);
53 55
54 56 protected:
55 57 void mousePressEvent(QMouseEvent *event);
General Comments 0
You need to be logged in to leave comments. Login now