##// END OF EJS Templates
Adds refactored axis to presenter
Michal Klocek -
r140:683f8b9c197b
parent child
Show More
@@ -1,4 +1,5
1 #include "axisitem_p.h"
1 #include "axisitem_p.h"
2 #include "qchartaxis.h"
2 #include <QPainter>
3 #include <QPainter>
3 #include <QDebug>
4 #include <QDebug>
4
5
@@ -6,8 +7,9
6
7
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
9
9 AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) :
10 AxisItem::AxisItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) :
10 ChartItem(parent),
11 ChartItem(parent),
12 m_axis(axis),
11 m_ticks(4),
13 m_ticks(4),
12 m_type(type)
14 m_type(type)
13 {
15 {
@@ -37,17 +39,6 QRectF AxisItem::boundingRect() const
37 return m_rect;
39 return m_rect;
38 }
40 }
39
41
40 void AxisItem::setPlotDomain(const PlotDomain& plotDomain)
41 {
42 m_plotDomain = plotDomain;
43 createItems();
44 }
45
46 void AxisItem::setSize(const QSizeF &size)
47 {
48 m_rect = QRectF(QPoint(0,0),size);
49 createItems();
50 }
51
42
52 /*
43 /*
53 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
44 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
@@ -104,15 +95,7 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,Q
104 void AxisItem::createItems()
95 void AxisItem::createItems()
105 {
96 {
106
97
107 //TODO: this is very inefficient handling
98 if(!m_rect.isValid()) return;
108
109 qDeleteAll(m_shades);
110 m_shades.clear();
111 qDeleteAll(m_grid);
112 m_grid.clear();
113 qDeleteAll(m_labels);
114 m_labels.clear();
115
116
99
117 if(m_type==X_AXIS) {
100 if(m_type==X_AXIS) {
118
101
@@ -122,7 +105,7 void AxisItem::createItems()
122
105
123 int x = i * deltaX + m_rect.left();
106 int x = i * deltaX + m_rect.left();
124
107
125 qreal label = m_plotDomain.m_minX + (i * m_plotDomain.spanX()/ m_ticks);
108 qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks);
126
109
127 m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this);
110 m_grid<<new QGraphicsLineItem(x, m_rect.top(), x, m_rect.bottom(),this);
128
111
@@ -142,7 +125,7 void AxisItem::createItems()
142
125
143 int y = j * -deltaY + m_rect.bottom();
126 int y = j * -deltaY + m_rect.bottom();
144
127
145 qreal label = m_plotDomain.m_minY + (j * m_plotDomain.spanY()
128 qreal label = m_domain.m_minY + (j * m_domain.spanY()
146 / m_ticks);
129 / m_ticks);
147
130
148 m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this);
131 m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this);
@@ -159,6 +142,43 void AxisItem::createItems()
159 //painter->drawRect(m_rect.adjusted(0, 0, -1, -1));
142 //painter->drawRect(m_rect.adjusted(0, 0, -1, -1));
160 }
143 }
161
144
145 void AxisItem::clear()
146 {
147 qDeleteAll(m_shades);
148 m_shades.clear();
149 qDeleteAll(m_grid);
150 m_grid.clear();
151 qDeleteAll(m_labels);
152 m_labels.clear();
153 }
154
155 void AxisItem::updateDomain()
156 {
157 clear();
158 createItems();
159 }
160
161 void AxisItem::handleAxisChanged()
162 {
163 //m_axis->
164 }
165
166 void AxisItem::handleDomainChanged(const Domain& domain)
167 {
168 m_domain = domain;
169 clear();
170 createItems();
171 }
172
173 void AxisItem::handleGeometryChanged(const QRectF& rect)
174 {
175 Q_ASSERT(rect.isValid());
176 m_rect = rect;
177 clear();
178 createItems();
179 }
180
162 //TODO "nice numbers algorithm"
181 //TODO "nice numbers algorithm"
182 #include "moc_axisitem_p.cpp"
163
183
164 QTCOMMERCIALCHART_END_NAMESPACE
184 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,45 +1,71
1 #ifndef AXISITEM_H_
1 #ifndef AXISITEM_H_
2 #define AXISITEM_H_
2 #define AXISITEM_H_
3
3
4 #include "plotdomain_p.h"
4 #include "domain_p.h"
5 #include "chartitem_p.h"
5 #include "chartitem_p.h"
6 #include <QGraphicsItem>
6 #include <QGraphicsItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class AxisItem : public ChartItem
10 class QChartAxis;
11
12 class AxisItem : public QObject, public ChartItem
11 {
13 {
14 Q_OBJECT
12 public:
15 public:
13 enum AxisType{X_AXIS,Y_AXIS};
16 enum AxisType{X_AXIS,Y_AXIS};
14
17
15 AxisItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0);
18 AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0);
16 ~AxisItem();
19 ~AxisItem();
17
20
18 //from QGraphicsItem
21 //from QGraphicsItem
19 QRectF boundingRect() const;
22 QRectF boundingRect() const;
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
21
24
25 protected slots:
26 void handleAxisChanged();
27 void handleDomainChanged(const Domain& domain);
28 void handleGeometryChanged(const QRectF& size);
29
30 protected:
31 void updateDomain();
32
33 private:
34 void clear();
35
36
22 public: // from ChartItem
37 public: // from ChartItem
23 void setSize(const QSizeF &size);
38 void setSize(const QSizeF &size){};
24 void setPlotDomain(const PlotDomain& data);
39 void setPlotDomain(const PlotDomain& data){};
25
40
26 public:
41 public:
27 void setLength(int length);
42 void setLength(int length);
28 void setWidth(int width);
43 void setWidth(int width);
29 AxisType axisType() const {return m_type;};
44 AxisType axisType() const {return m_type;};
30
45
46 protected:
47
48
31 private:
49 private:
32 void createItems();
50 void createItems();
33 private:
51 private:
34 QRectF m_rect;
52
53 QChartAxis* m_axis;
54 AxisType m_type;
35 int m_ticks;
55 int m_ticks;
36 PlotDomain m_plotDomain;
56 Domain m_domain;
57
58
59
60 QRectF m_rect;
61
37 QPainterPath m_path;
62 QPainterPath m_path;
38
63
64
39 QList<QGraphicsLineItem*> m_grid;
65 QList<QGraphicsLineItem*> m_grid;
40 QList<QGraphicsRectItem*> m_shades;
66 QList<QGraphicsRectItem*> m_shades;
41 QList<QGraphicsSimpleTextItem*> m_labels;
67 QList<QGraphicsSimpleTextItem*> m_labels;
42 AxisType m_type;
68
43 };
69 };
44
70
45 QTCOMMERCIALCHART_END_NAMESPACE
71 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,4 +1,5
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
3 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
4 //series
5 //series
@@ -7,6 +8,7
7 #include "percentbarchartseries.h"
8 #include "percentbarchartseries.h"
8 #include "qxychartseries.h"
9 #include "qxychartseries.h"
9 //items
10 //items
11 #include "axisitem_p.h"
10 #include "bargroup.h"
12 #include "bargroup.h"
11 #include "stackedbargroup.h"
13 #include "stackedbargroup.h"
12 #include "xylinechartitem_p.h"
14 #include "xylinechartitem_p.h"
@@ -25,14 +27,30 m_domainIndex(0),
25 m_marginSize(0),
27 m_marginSize(0),
26 m_rect(QRectF(QPoint(0,0),m_chart->size()))
28 m_rect(QRectF(QPoint(0,0),m_chart->size()))
27 {
29 {
28 creteConnections();
30 createConnections();
31 createDeafultAxis();
29 }
32 }
30
33
31 ChartPresenter::~ChartPresenter()
34 ChartPresenter::~ChartPresenter()
32 {
35 {
33 }
36 }
34
37
35 void ChartPresenter::creteConnections()
38 void ChartPresenter::createDeafultAxis()
39 {
40 //default axis
41 QChartAxis* axisX = new QChartAxis(this);
42 QChartAxis* axisY = new QChartAxis(this);
43
44 m_axis << new AxisItem(axisX,AxisItem::X_AXIS,m_chart);
45 m_axis << new AxisItem(axisY,AxisItem::Y_AXIS,m_chart);
46
47 foreach(AxisItem* item, m_axis) {
48 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
49 QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&)));
50 }
51 }
52
53 void ChartPresenter::createConnections()
36 {
54 {
37 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
55 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
38 QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
56 QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
@@ -178,7 +196,6 void ChartPresenter::zoomInToRect(const QRectF& rect)
178 m_dataset->addDomain(domain);
196 m_dataset->addDomain(domain);
179 }
197 }
180
198
181
182 void ChartPresenter::zoomIn()
199 void ChartPresenter::zoomIn()
183 {
200 {
184 if (!m_dataset->nextDomain()) {
201 if (!m_dataset->nextDomain()) {
@@ -11,8 +11,7 class QChartSeries;
11 class ChartDataSet;
11 class ChartDataSet;
12 class QChart;
12 class QChart;
13 class Domain;
13 class Domain;
14 class QXYChartSeries;
14 class AxisItem;
15 class XYLineChartItem;
16
15
17 class ChartPresenter: public QObject
16 class ChartPresenter: public QObject
18 {
17 {
@@ -37,7 +36,8 public:
37 void zoomReset();
36 void zoomReset();
38
37
39 private:
38 private:
40 void creteConnections();
39 void createConnections();
40 void createDeafultAxis();
41
41
42 public slots:
42 public slots:
43 void handleSeriesAdded(QChartSeries* series);
43 void handleSeriesAdded(QChartSeries* series);
@@ -54,6 +54,7 private:
54 QChart* m_chart;
54 QChart* m_chart;
55 ChartDataSet* m_dataset;
55 ChartDataSet* m_dataset;
56 QVector<Domain> m_domains;
56 QVector<Domain> m_domains;
57 QList<AxisItem*> m_axis;
57 int m_domainIndex;
58 int m_domainIndex;
58 int m_marginSize;
59 int m_marginSize;
59 QRectF m_rect;
60 QRectF m_rect;
@@ -28,7 +28,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
28 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
29 m_backgroundItem(0),
29 m_backgroundItem(0),
30 m_titleItem(0),
30 m_titleItem(0),
31 m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)),
31 m_axisXItem(0),
32 m_plotDataIndex(0),
32 m_plotDataIndex(0),
33 m_chartTheme(new ChartTheme(this)),
33 m_chartTheme(new ChartTheme(this)),
34 //m_dataset(0),
34 //m_dataset(0),
@@ -42,9 +42,8 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(
42 PlotDomain domain;
42 PlotDomain domain;
43 m_plotDomainList << domain;
43 m_plotDomainList << domain;
44
44
45 m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this);
45 //m_chartItems << m_axisXItem;
46 m_chartItems << m_axisXItem;
46 //m_chartItems << m_axisYItem.at(0);
47 m_chartItems << m_axisYItem.at(0);
48 }
47 }
49
48
50 QChart::~QChart(){}
49 QChart::~QChart(){}
@@ -3,7 +3,7
3
3
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
5
6 QChartAxis::QChartAxis():
6 QChartAxis::QChartAxis(QObject* parent):QObject(parent),
7 m_axisVisible(true),
7 m_axisVisible(true),
8 m_girdVisible(true),
8 m_girdVisible(true),
9 m_labelsVisible(true),
9 m_labelsVisible(true),
@@ -18,6 +18,16 QChartAxis::~QChartAxis()
18 // TODO Auto-generated destructor stub
18 // TODO Auto-generated destructor stub
19 }
19 }
20
20
21 void QChartAxis::setAxisPen(const QPen& pen)
22 {
23 m_axisPen = pen;
24 }
25
26 void QChartAxis::setAxisBrush(const QBrush& brush)
27 {
28 m_axisBrush = brush;
29 }
30
21 void QChartAxis::setAxisVisible(bool visible)
31 void QChartAxis::setAxisVisible(bool visible)
22 {
32 {
23 m_axisVisible=visible;
33 m_axisVisible=visible;
@@ -38,6 +48,6 void QChartAxis::setRowShadesVisible(bool visible)
38 m_rowShadesVisible=visible;
48 m_rowShadesVisible=visible;
39 }
49 }
40
50
41
51 #include "moc_qchartaxis.cpp"
42
52
43 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
@@ -2,26 +2,70
2 #define QCHARTAXIS_H_
2 #define QCHARTAXIS_H_
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <QPen>
6
5
7
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
9
8 class QChartAxis
10 class QChartAxis : public QObject
9 {
11 {
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);
10 public:
19 public:
11 QChartAxis();
20 enum LabelOrientation{ HORIZONTAL, VERTICAL , SLIDE };
21
22 QChartAxis(QObject* parent = 0);
12 virtual ~QChartAxis();
23 virtual ~QChartAxis();
13
24
25 //axis
14 bool isAxisVisible() const { return m_axisVisible;};
26 bool isAxisVisible() const { return m_axisVisible;};
15 void setAxisVisible(bool visible);
27 void setAxisVisible(bool visible);
28 void setAxisPen(const QPen& pen);
29 const QPen& axisPen() const { return m_axisPen;};
30 void setAxisBrush(const QBrush& brush);
31 const QBrush& axisBrush() const { return m_axisBrush;};
32
33 //grid
16 bool isGridVisible() const { return m_girdVisible;};
34 bool isGridVisible() const { return m_girdVisible;};
17 void setGridVisible(bool visible);
35 void setGridVisible(bool visible);
36
18 bool isLabelsVisible() const { return m_labelsVisible;};
37 bool isLabelsVisible() const { return m_labelsVisible;};
19 void setLabelsVisible(bool visible);
38 void setLabelsVisible(bool visible);
39
20 bool isRowShadesVisible() const { return m_rowShadesVisible;};
40 bool isRowShadesVisible() const { return m_rowShadesVisible;};
21 void setRowShadesVisible(bool visible);
41 void setRowShadesVisible(bool visible);
22
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 signals:
58 void axisVisibilityChanged();
59 void axisPenChanged();
60 void axisBurshChanged();
61
62
23 private:
63 private:
64
24 bool m_axisVisible;
65 bool m_axisVisible;
66 QPen m_axisPen;
67 QBrush m_axisBrush;
68
25 bool m_girdVisible;
69 bool m_girdVisible;
26 bool m_labelsVisible;
70 bool m_labelsVisible;
27 bool m_rowShadesVisible;
71 bool m_rowShadesVisible;
General Comments 0
You need to be logged in to leave comments. Login now