@@ -1,4 +1,5 | |||
|
1 | 1 | #include "axisitem_p.h" |
|
2 | #include "qchartaxis.h" | |
|
2 | 3 | #include <QPainter> |
|
3 | 4 | #include <QDebug> |
|
4 | 5 | |
@@ -6,8 +7,9 | |||
|
6 | 7 | |
|
7 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 9 | |
|
9 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : | |
|
10 | AxisItem::AxisItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) : | |
|
10 | 11 | ChartItem(parent), |
|
12 | m_axis(axis), | |
|
11 | 13 | m_ticks(4), |
|
12 | 14 | m_type(type) |
|
13 | 15 | { |
@@ -37,17 +39,6 QRectF AxisItem::boundingRect() const | |||
|
37 | 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 | 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 | 95 | void AxisItem::createItems() |
|
105 | 96 | { |
|
106 | 97 | |
|
107 | //TODO: this is very inefficient handling | |
|
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 | ||
|
98 | if(!m_rect.isValid()) return; | |
|
116 | 99 | |
|
117 | 100 | if(m_type==X_AXIS) { |
|
118 | 101 | |
@@ -122,7 +105,7 void AxisItem::createItems() | |||
|
122 | 105 | |
|
123 | 106 | int x = i * deltaX + m_rect.left(); |
|
124 | 107 | |
|
125 |
qreal label = m_ |
|
|
108 | qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks); | |
|
126 | 109 | |
|
127 | 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 | 126 | int y = j * -deltaY + m_rect.bottom(); |
|
144 | 127 | |
|
145 |
qreal label = m_ |
|
|
128 | qreal label = m_domain.m_minY + (j * m_domain.spanY() | |
|
146 | 129 | / m_ticks); |
|
147 | 130 | |
|
148 | 131 | m_grid<<new QGraphicsLineItem(m_rect.left() , y, m_rect.right(), y,this); |
@@ -159,6 +142,43 void AxisItem::createItems() | |||
|
159 | 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 | 181 | //TODO "nice numbers algorithm" |
|
182 | #include "moc_axisitem_p.cpp" | |
|
163 | 183 | |
|
164 | 184 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,45 +1,71 | |||
|
1 | 1 | #ifndef AXISITEM_H_ |
|
2 | 2 | #define AXISITEM_H_ |
|
3 | 3 | |
|
4 |
#include " |
|
|
4 | #include "domain_p.h" | |
|
5 | 5 | #include "chartitem_p.h" |
|
6 | 6 | #include <QGraphicsItem> |
|
7 | 7 | |
|
8 | 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 | 15 | public: |
|
13 | 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 | 19 | ~AxisItem(); |
|
17 | 20 | |
|
18 | 21 | //from QGraphicsItem |
|
19 | 22 | QRectF boundingRect() const; |
|
20 | 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 | 37 | public: // from ChartItem |
|
23 | void setSize(const QSizeF &size); | |
|
24 | void setPlotDomain(const PlotDomain& data); | |
|
38 | void setSize(const QSizeF &size){}; | |
|
39 | void setPlotDomain(const PlotDomain& data){}; | |
|
25 | 40 | |
|
26 | 41 | public: |
|
27 | 42 | void setLength(int length); |
|
28 | 43 | void setWidth(int width); |
|
29 | 44 | AxisType axisType() const {return m_type;}; |
|
30 | 45 | |
|
46 | protected: | |
|
47 | ||
|
48 | ||
|
31 | 49 | private: |
|
32 | 50 | void createItems(); |
|
33 | 51 | private: |
|
34 | QRectF m_rect; | |
|
52 | ||
|
53 | QChartAxis* m_axis; | |
|
54 | AxisType m_type; | |
|
35 | 55 | int m_ticks; |
|
36 |
|
|
|
56 | Domain m_domain; | |
|
57 | ||
|
58 | ||
|
59 | ||
|
60 | QRectF m_rect; | |
|
61 | ||
|
37 | 62 | QPainterPath m_path; |
|
38 | 63 | |
|
64 | ||
|
39 | 65 | QList<QGraphicsLineItem*> m_grid; |
|
40 | 66 | QList<QGraphicsRectItem*> m_shades; |
|
41 | 67 | QList<QGraphicsSimpleTextItem*> m_labels; |
|
42 | AxisType m_type; | |
|
68 | ||
|
43 | 69 | }; |
|
44 | 70 | |
|
45 | 71 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,4 +1,5 | |||
|
1 | 1 | #include "qchart.h" |
|
2 | #include "qchartaxis.h" | |
|
2 | 3 | #include "chartpresenter_p.h" |
|
3 | 4 | #include "chartdataset_p.h" |
|
4 | 5 | //series |
@@ -7,6 +8,7 | |||
|
7 | 8 | #include "percentbarchartseries.h" |
|
8 | 9 | #include "qxychartseries.h" |
|
9 | 10 | //items |
|
11 | #include "axisitem_p.h" | |
|
10 | 12 | #include "bargroup.h" |
|
11 | 13 | #include "stackedbargroup.h" |
|
12 | 14 | #include "xylinechartitem_p.h" |
@@ -25,14 +27,30 m_domainIndex(0), | |||
|
25 | 27 | m_marginSize(0), |
|
26 | 28 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
27 | 29 | { |
|
28 |
|
|
|
30 | createConnections(); | |
|
31 | createDeafultAxis(); | |
|
29 | 32 | } |
|
30 | 33 | |
|
31 | 34 | ChartPresenter::~ChartPresenter() |
|
32 | 35 | { |
|
33 | 36 | } |
|
34 | 37 | |
|
35 |
void ChartPresenter::cre |
|
|
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 | 55 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
38 | 56 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
@@ -123,15 +141,15 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
123 | 141 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
124 | 142 | m_chartItems.insert(series,item); |
|
125 | 143 | break; |
|
126 |
|
|
|
144 | } | |
|
127 | 145 | /* |
|
128 | 146 | case QChartSeries::SeriesTypeScatter: { |
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
147 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
|
148 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
|
149 | scatterSeries->d->setParentItem(this); | |
|
150 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
|
151 | m_chartItems << scatterSeries->d; | |
|
152 | m_chartTheme->addObserver(scatterSeries->d); | |
|
135 | 153 | |
|
136 | 154 | foreach (qreal x, scatterSeries->d->m_x) { |
|
137 | 155 | domain.m_minX = qMin(domain.m_minX, x); |
@@ -166,7 +184,7 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
166 | 184 | |
|
167 | 185 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
168 | 186 | { |
|
169 | //TODO: | |
|
187 | //TODO: | |
|
170 | 188 | } |
|
171 | 189 | |
|
172 | 190 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
@@ -178,7 +196,6 void ChartPresenter::zoomInToRect(const QRectF& rect) | |||
|
178 | 196 | m_dataset->addDomain(domain); |
|
179 | 197 | } |
|
180 | 198 | |
|
181 | ||
|
182 | 199 | void ChartPresenter::zoomIn() |
|
183 | 200 | { |
|
184 | 201 | if (!m_dataset->nextDomain()) { |
@@ -202,25 +219,25 void ChartPresenter::zoomReset() | |||
|
202 | 219 | } |
|
203 | 220 | |
|
204 | 221 | /* |
|
205 | void ChartPresenter::setAxisX(const QChartAxis& axis) | |
|
206 | { | |
|
207 |
|
|
|
208 | } | |
|
209 | void ChartPresenter::setAxisY(const QChartAxis& axis) | |
|
210 | { | |
|
211 |
|
|
|
212 | } | |
|
213 | ||
|
214 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) | |
|
215 | { | |
|
216 |
|
|
|
217 | } | |
|
218 | ||
|
219 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) | |
|
220 | { | |
|
221 |
|
|
|
222 | } | |
|
223 | */ | |
|
222 | void ChartPresenter::setAxisX(const QChartAxis& axis) | |
|
223 | { | |
|
224 | setAxis(m_axisXItem,axis); | |
|
225 | } | |
|
226 | void ChartPresenter::setAxisY(const QChartAxis& axis) | |
|
227 | { | |
|
228 | setAxis(m_axisYItem.at(0),axis); | |
|
229 | } | |
|
230 | ||
|
231 | void ChartPresenter::setAxisY(const QList<QChartAxis>& axis) | |
|
232 | { | |
|
233 | //TODO not implemented | |
|
234 | } | |
|
235 | ||
|
236 | void ChartPresenter::setAxis(AxisItem *item, const QChartAxis& axis) | |
|
237 | { | |
|
238 | item->setVisible(axis.isAxisVisible()); | |
|
239 | } | |
|
240 | */ | |
|
224 | 241 | #include "moc_chartpresenter_p.cpp" |
|
225 | 242 | |
|
226 | 243 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -11,8 +11,7 class QChartSeries; | |||
|
11 | 11 | class ChartDataSet; |
|
12 | 12 | class QChart; |
|
13 | 13 | class Domain; |
|
14 | class QXYChartSeries; | |
|
15 | class XYLineChartItem; | |
|
14 | class AxisItem; | |
|
16 | 15 | |
|
17 | 16 | class ChartPresenter: public QObject |
|
18 | 17 | { |
@@ -37,7 +36,8 public: | |||
|
37 | 36 | void zoomReset(); |
|
38 | 37 | |
|
39 | 38 | private: |
|
40 | void creteConnections(); | |
|
39 | void createConnections(); | |
|
40 | void createDeafultAxis(); | |
|
41 | 41 | |
|
42 | 42 | public slots: |
|
43 | 43 | void handleSeriesAdded(QChartSeries* series); |
@@ -54,6 +54,7 private: | |||
|
54 | 54 | QChart* m_chart; |
|
55 | 55 | ChartDataSet* m_dataset; |
|
56 | 56 | QVector<Domain> m_domains; |
|
57 | QList<AxisItem*> m_axis; | |
|
57 | 58 | int m_domainIndex; |
|
58 | 59 | int m_marginSize; |
|
59 | 60 | QRectF m_rect; |
@@ -28,7 +28,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
28 | 28 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
29 | 29 | m_backgroundItem(0), |
|
30 | 30 | m_titleItem(0), |
|
31 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), | |
|
31 | m_axisXItem(0), | |
|
32 | 32 | m_plotDataIndex(0), |
|
33 | 33 | m_chartTheme(new ChartTheme(this)), |
|
34 | 34 | //m_dataset(0), |
@@ -42,9 +42,8 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget( | |||
|
42 | 42 | PlotDomain domain; |
|
43 | 43 | m_plotDomainList << domain; |
|
44 | 44 | |
|
45 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); | |
|
46 |
m_chartItems << m_axis |
|
|
47 | m_chartItems << m_axisYItem.at(0); | |
|
45 | //m_chartItems << m_axisXItem; | |
|
46 | //m_chartItems << m_axisYItem.at(0); | |
|
48 | 47 | } |
|
49 | 48 | |
|
50 | 49 | QChart::~QChart(){} |
@@ -3,7 +3,7 | |||
|
3 | 3 | |
|
4 | 4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | 5 | |
|
6 | QChartAxis::QChartAxis(): | |
|
6 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), | |
|
7 | 7 | m_axisVisible(true), |
|
8 | 8 | m_girdVisible(true), |
|
9 | 9 | m_labelsVisible(true), |
@@ -18,6 +18,16 QChartAxis::~QChartAxis() | |||
|
18 | 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 | 31 | void QChartAxis::setAxisVisible(bool visible) |
|
22 | 32 | { |
|
23 | 33 | m_axisVisible=visible; |
@@ -38,6 +48,6 void QChartAxis::setRowShadesVisible(bool visible) | |||
|
38 | 48 | m_rowShadesVisible=visible; |
|
39 | 49 | } |
|
40 | 50 | |
|
41 | ||
|
51 | #include "moc_qchartaxis.cpp" | |
|
42 | 52 | |
|
43 | 53 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -2,26 +2,70 | |||
|
2 | 2 | #define QCHARTAXIS_H_ |
|
3 | 3 | |
|
4 | 4 | #include <qchartglobal.h> |
|
5 | #include <QPen> | |
|
6 | ||
|
5 | 7 | |
|
6 | 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 | 19 | public: |
|
11 | QChartAxis(); | |
|
20 | enum LabelOrientation{ HORIZONTAL, VERTICAL , SLIDE }; | |
|
21 | ||
|
22 | QChartAxis(QObject* parent = 0); | |
|
12 | 23 | virtual ~QChartAxis(); |
|
13 | 24 | |
|
25 | //axis | |
|
14 | 26 | bool isAxisVisible() const { return m_axisVisible;}; |
|
15 | 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 | 34 | bool isGridVisible() const { return m_girdVisible;}; |
|
17 | 35 | void setGridVisible(bool visible); |
|
36 | ||
|
18 | 37 | bool isLabelsVisible() const { return m_labelsVisible;}; |
|
19 | 38 | void setLabelsVisible(bool visible); |
|
39 | ||
|
20 | 40 | bool isRowShadesVisible() const { return m_rowShadesVisible;}; |
|
21 | 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 | 63 | private: |
|
64 | ||
|
24 | 65 | bool m_axisVisible; |
|
66 | QPen m_axisPen; | |
|
67 | QBrush m_axisBrush; | |
|
68 | ||
|
25 | 69 | bool m_girdVisible; |
|
26 | 70 | bool m_labelsVisible; |
|
27 | 71 | bool m_rowShadesVisible; |
General Comments 0
You need to be logged in to leave comments.
Login now