@@ -9,7 +9,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | 9 | |
|
10 | 10 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : |
|
11 | 11 | ChartItem(parent), |
|
12 | m_ticks(4), | |
|
13 | 12 | m_type(type), |
|
14 | 13 | m_labelsAngle(0), |
|
15 | 14 | m_shadesEnabled(true), |
@@ -20,7 +19,6 m_labels(parent) | |||
|
20 | 19 | //initial initialization |
|
21 | 20 | m_shades.setZValue(0); |
|
22 | 21 | m_grid.setZValue(2); |
|
23 | createItems(); | |
|
24 | 22 | } |
|
25 | 23 | |
|
26 | 24 | AxisItem::~AxisItem() |
@@ -32,9 +30,9 QRectF AxisItem::boundingRect() const | |||
|
32 | 30 | return m_rect; |
|
33 | 31 | } |
|
34 | 32 | |
|
35 | void AxisItem::createItems() | |
|
33 | void AxisItem::createItems(int count) | |
|
36 | 34 | { |
|
37 |
for (int i = 0; i < |
|
|
35 | for (int i = 0; i < count; ++i) { | |
|
38 | 36 | m_grid.addToGroup(new QGraphicsLineItem(this)); |
|
39 | 37 | m_labels.addToGroup(new QGraphicsSimpleTextItem(this)); |
|
40 | 38 | if(i%2) m_shades.addToGroup(new QGraphicsRectItem(this)); |
@@ -55,6 +53,8 void AxisItem::clear() | |||
|
55 | 53 | delete item; |
|
56 | 54 | } |
|
57 | 55 | |
|
56 | m_thicksList.clear(); | |
|
57 | ||
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
@@ -62,7 +62,7 void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, | |||
|
62 | 62 | |
|
63 | 63 | } |
|
64 | 64 | |
|
65 |
void AxisItem::update |
|
|
65 | void AxisItem::updateItem(int count) | |
|
66 | 66 | { |
|
67 | 67 | |
|
68 | 68 | QList<QGraphicsItem *> lines = m_grid.childItems(); |
@@ -73,21 +73,16 void AxisItem::updateDomain() | |||
|
73 | 73 | { |
|
74 | 74 | case X_AXIS: |
|
75 | 75 | { |
|
76 |
const qreal deltaX = m_rect.width() / |
|
|
76 | const qreal deltaX = m_rect.width() / (count-1); | |
|
77 | 77 | |
|
78 | 78 | m_axis.setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
79 | 79 | |
|
80 |
for (int i = 0; i < |
|
|
81 | ||
|
80 | for (int i = 0; i < count; ++i) { | |
|
82 | 81 | int x = i * deltaX + m_rect.left(); |
|
83 | ||
|
84 | qreal label = m_domain.m_minX + (i * m_domain.spanX()/ m_ticks); | |
|
85 | ||
|
86 | 82 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
87 | 83 | lineItem->setLine(x, m_rect.top(), x, m_rect.bottom()); |
|
88 | ||
|
89 | 84 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
90 |
labelItem->setText( |
|
|
85 | labelItem->setText(m_thicksList.at(i)); | |
|
91 | 86 | QPointF center = labelItem->boundingRect().center(); |
|
92 | 87 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
93 | 88 | labelItem->setPos(x - center.x(), m_rect.bottom() + label_padding); |
@@ -103,26 +98,19 void AxisItem::updateDomain() | |||
|
103 | 98 | |
|
104 | 99 | case Y_AXIS: |
|
105 | 100 | { |
|
106 |
const qreal deltaY = m_rect.height()/ |
|
|
101 | const qreal deltaY = m_rect.height()/ (count-1); | |
|
107 | 102 | |
|
108 | 103 | m_axis.setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
109 | 104 | |
|
110 |
for (int i = 0; i < |
|
|
111 | ||
|
105 | for (int i = 0; i < count; ++i) { | |
|
112 | 106 | int y = i * -deltaY + m_rect.bottom(); |
|
113 | ||
|
114 | qreal label = m_domain.m_minY + (i * m_domain.spanY()/ m_ticks); | |
|
115 | ||
|
116 | 107 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
117 | 108 | lineItem->setLine(m_rect.left() , y, m_rect.right(), y); |
|
118 | ||
|
119 | 109 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
120 |
labelItem->setText( |
|
|
110 | labelItem->setText(m_thicksList.at(i)); | |
|
121 | 111 | QPointF center = labelItem->boundingRect().center(); |
|
122 | 112 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
123 | 113 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , y-center.y()); |
|
124 | ||
|
125 | ||
|
126 | 114 | if(i%2){ |
|
127 | 115 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
128 | 116 | rectItem->setRect(m_rect.left(),y,m_rect.width(),deltaY); |
@@ -137,23 +125,23 void AxisItem::updateDomain() | |||
|
137 | 125 | } |
|
138 | 126 | } |
|
139 | 127 | |
|
140 |
void AxisItem::handleAxis |
|
|
128 | void AxisItem::handleAxisUpdate(QChartAxis* axis) | |
|
141 | 129 | { |
|
142 |
if(axis |
|
|
130 | if(axis->isAxisVisible()) { | |
|
143 | 131 | setAxisOpacity(100); |
|
144 | 132 | } |
|
145 | 133 | else { |
|
146 | 134 | setAxisOpacity(0); |
|
147 | 135 | } |
|
148 | 136 | |
|
149 |
if(axis |
|
|
137 | if(axis->isGridVisible()) { | |
|
150 | 138 | setGridOpacity(100); |
|
151 | 139 | } |
|
152 | 140 | else { |
|
153 | 141 | setGridOpacity(0); |
|
154 | 142 | } |
|
155 | 143 | |
|
156 |
if(axis |
|
|
144 | if(axis->isLabelsVisible()) | |
|
157 | 145 | { |
|
158 | 146 | setLabelsOpacity(100); |
|
159 | 147 | } |
@@ -161,49 +149,48 void AxisItem::handleAxisChanged(const QChartAxis& axis) | |||
|
161 | 149 | setLabelsOpacity(0); |
|
162 | 150 | } |
|
163 | 151 | |
|
164 |
if(axis |
|
|
165 |
setShadesOpacity(axis |
|
|
152 | if(axis->isShadesVisible()) { | |
|
153 | setShadesOpacity(axis->shadesOpacity()); | |
|
166 | 154 | } |
|
167 | 155 | else { |
|
168 | 156 | setShadesOpacity(0); |
|
169 | 157 | } |
|
170 | 158 | |
|
171 | switch(axis.labelsOrientation()) | |
|
159 | setLabelsAngle(axis->labelsAngle()); | |
|
160 | setAxisPen(axis->axisPen()); | |
|
161 | setLabelsPen(axis->labelsPen()); | |
|
162 | setLabelsBrush(axis->labelsBrush()); | |
|
163 | setLabelsFont(axis->labelFont()); | |
|
164 | setGridPen(axis->gridPen()); | |
|
165 | setShadesPen(axis->shadesPen()); | |
|
166 | setShadesBrush(axis->shadesBrush()); | |
|
167 | } | |
|
168 | ||
|
169 | void AxisItem::handleLabelsChanged(const QStringList& labels) | |
|
172 | 170 | { |
|
173 | case QChartAxis::LabelsOrientationHorizontal: | |
|
174 | setLabelsAngle(0); | |
|
175 | break; | |
|
176 | case QChartAxis::LabelsOrientationVertical: | |
|
177 | setLabelsAngle(90); | |
|
178 | break; | |
|
179 | case QChartAxis::LabelsOrientationSlide: | |
|
180 | setLabelsAngle(-45); | |
|
181 | break; | |
|
182 | default: | |
|
183 | break; | |
|
171 | m_thicksList=labels; | |
|
172 | QList<QGraphicsItem*> items = m_labels.childItems(); | |
|
173 | if(items.size()!=m_thicksList.size()){ | |
|
174 | clear(); | |
|
175 | m_thicksList=labels; | |
|
176 | createItems(m_thicksList.size()); | |
|
177 | items = m_labels.childItems(); | |
|
184 | 178 | } |
|
185 | 179 | |
|
186 | setAxisPen(axis.axisPen()); | |
|
187 | setLabelsPen(axis.labelsPen()); | |
|
188 | setLabelsBrush(axis.labelsBrush()); | |
|
189 | setLabelsFont(axis.labelFont()); | |
|
190 | setGridPen(axis.gridPen()); | |
|
191 | setShadesPen(axis.shadesPen()); | |
|
192 | setShadesBrush(axis.shadesBrush()); | |
|
180 | Q_ASSERT(items.size()==m_thicksList.size()); | |
|
193 | 181 | |
|
182 | int i=0; | |
|
183 | foreach(QGraphicsItem* item, items){ | |
|
184 | static_cast<QGraphicsSimpleTextItem*>(item)->setText(m_thicksList.at(i)); | |
|
185 | i++; | |
|
194 | 186 | } |
|
195 | ||
|
196 | void AxisItem::handleDomainChanged(const Domain& domain) | |
|
197 | { | |
|
198 | m_domain = domain; | |
|
199 | updateDomain(); | |
|
200 | 187 | update(); |
|
201 | 188 | } |
|
202 | 189 | |
|
203 | 190 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
204 | 191 | { |
|
205 | 192 | m_rect = rect; |
|
206 | updateDomain(); | |
|
193 | updateItem(m_thicksList.size()); | |
|
207 | 194 | update(); |
|
208 | 195 | } |
|
209 | 196 | |
@@ -305,14 +292,6 void AxisItem::setGridPen(const QPen& pen) | |||
|
305 | 292 | } |
|
306 | 293 | } |
|
307 | 294 | |
|
308 | void AxisItem::setTicks(int count) | |
|
309 | { | |
|
310 | if(count!=m_ticks){ | |
|
311 | clear(); | |
|
312 | m_ticks=count; | |
|
313 | createItems(); | |
|
314 | } | |
|
315 | } | |
|
316 | 295 | |
|
317 | 296 | //TODO "nice numbers algorithm" |
|
318 | 297 | #include "moc_axisitem_p.cpp" |
@@ -39,9 +39,6 public: | |||
|
39 | 39 | void setLabelsAngle(int angle); |
|
40 | 40 | int labelsAngle()const { return m_labelsAngle; } |
|
41 | 41 | |
|
42 | void setTicks(int count); | |
|
43 | int ticks() const { return m_ticks;} | |
|
44 | ||
|
45 | 42 | void setShadesBrush(const QBrush& brush); |
|
46 | 43 | void setShadesPen(const QPen& pen); |
|
47 | 44 | |
@@ -53,18 +50,16 public: | |||
|
53 | 50 | void setLabelsFont(const QFont& font); |
|
54 | 51 | |
|
55 | 52 | public slots: |
|
56 |
void handleAxis |
|
|
57 |
void handle |
|
|
53 | void handleAxisUpdate(QChartAxis* axis); | |
|
54 | void handleLabelsChanged(const QStringList& labels); | |
|
58 | 55 | void handleGeometryChanged(const QRectF& size); |
|
59 | 56 | protected: |
|
60 |
void update |
|
|
57 | void updateItem(int count); | |
|
61 | 58 | private: |
|
62 | 59 | void clear(); |
|
63 | void createItems(); | |
|
60 | void createItems(int count); | |
|
64 | 61 | private: |
|
65 | 62 | AxisType m_type; |
|
66 | int m_ticks; | |
|
67 | Domain m_domain; | |
|
68 | 63 | QRectF m_rect; |
|
69 | 64 | int m_labelsAngle; |
|
70 | 65 | bool m_shadesEnabled; |
@@ -72,6 +67,7 private: | |||
|
72 | 67 | QGraphicsItemGroup m_shades; |
|
73 | 68 | QGraphicsItemGroup m_labels; |
|
74 | 69 | QGraphicsLineItem m_axis; |
|
70 | QStringList m_thicksList; | |
|
75 | 71 | |
|
76 | 72 | }; |
|
77 | 73 |
@@ -1,4 +1,5 | |||
|
1 | 1 | #include "chartdataset_p.h" |
|
2 | #include "qchartaxis.h" | |
|
2 | 3 | //series |
|
3 | 4 | #include "qlinechartseries.h" |
|
4 | 5 | #include "qbarchartseries.h" |
@@ -9,10 +10,12 | |||
|
9 | 10 | |
|
10 | 11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 12 | |
|
12 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent) | |
|
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
|
14 | m_axisX(new QChartAxis(this)), | |
|
15 | m_axisY(new QChartAxis(this)), | |
|
16 | m_domainIndex(0), | |
|
17 | m_axisXInitialized(false) | |
|
13 | 18 | { |
|
14 | Domain domain; | |
|
15 | m_domains<<domain; | |
|
16 | 19 | } |
|
17 | 20 | |
|
18 | 21 | ChartDataSet::~ChartDataSet() |
@@ -20,20 +23,34 ChartDataSet::~ChartDataSet() | |||
|
20 | 23 | // TODO Auto-generated destructor stub |
|
21 | 24 | } |
|
22 | 25 | |
|
23 |
const Domain |
|
|
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const | |
|
24 | 27 | { |
|
25 | return m_domains[m_domainIndex]; | |
|
28 | int i = m_domainMap.count(axisY); | |
|
29 | if(i == 0){ | |
|
30 | return Domain(); | |
|
31 | } | |
|
32 | i = i - m_domainIndex -1; | |
|
33 | return m_domainMap.values(axisY).at(i); | |
|
26 | 34 | } |
|
27 | 35 | |
|
28 | void ChartDataSet::addSeries(QChartSeries* series) | |
|
36 | void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY) | |
|
29 | 37 | { |
|
30 | 38 | // TODO: we should check the series not already added |
|
31 | m_chartSeries << series; | |
|
32 | 39 | series->setParent(this); // take ownership |
|
33 | m_domainIndex = 0; | |
|
34 | m_domains.resize(1); | |
|
35 | 40 | |
|
36 | Domain& domain = m_domains[m_domainIndex]; | |
|
41 | clearDomains(); | |
|
42 | ||
|
43 | if(axisY==0) axisY = m_axisY; | |
|
44 | ||
|
45 | QList<QChartSeries*> seriesList = m_seriesMap.values(axisY); | |
|
46 | ||
|
47 | QList<Domain> domainList = m_domainMap.values(axisY); | |
|
48 | ||
|
49 | Q_ASSERT(domainList.size()<=1); | |
|
50 | ||
|
51 | Domain domain; | |
|
52 | ||
|
53 | if(domainList.size()>0) domain = domainList.at(0); | |
|
37 | 54 | |
|
38 | 55 | switch(series->type()) |
|
39 | 56 | { |
@@ -113,15 +130,60 void ChartDataSet::addSeries(QChartSeries* series) | |||
|
113 | 130 | |
|
114 | 131 | } |
|
115 | 132 | |
|
133 | if(!m_domainMap.contains(axisY)) | |
|
134 | { | |
|
135 | emit axisAdded(axisY); | |
|
136 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
|
137 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
|
138 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
|
139 | } | |
|
140 | m_domainMap.replace(axisY,domain); | |
|
141 | m_seriesMap.insert(axisY,series); | |
|
142 | ||
|
143 | if(!m_axisXInitialized) | |
|
144 | { | |
|
145 | emit axisAdded(axisX()); | |
|
146 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
|
147 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
|
148 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
|
149 | m_axisXInitialized=true; | |
|
150 | } | |
|
151 | ||
|
152 | ||
|
116 | 153 | emit seriesAdded(series); |
|
117 | emit domainChanged(domain); | |
|
154 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); | |
|
155 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
|
156 | emit axisLabelsChanged(axisY,ylabels); | |
|
157 | emit axisLabelsChanged(axisX(),xlabels); | |
|
158 | emit seriesDomainChanged(series,domain); | |
|
159 | ||
|
160 | } | |
|
161 | ||
|
162 | void ChartDataSet::removeSeries(QChartSeries* series) | |
|
163 | { | |
|
164 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
|
165 | foreach(QChartAxis* axis , keys) { | |
|
166 | if(m_seriesMap.contains(axis,series)){ | |
|
167 | emit seriesRemoved(series); | |
|
168 | m_seriesMap.remove(axis,series); | |
|
169 | //remove axis if no longer there | |
|
170 | if(!m_seriesMap.contains(axis) && axis != m_axisY){ | |
|
171 | emit axisRemoved(axis); | |
|
172 | m_domainMap.remove(axis); | |
|
173 | delete axis; | |
|
174 | } | |
|
175 | break; | |
|
176 | } | |
|
177 | } | |
|
118 | 178 | } |
|
119 | 179 | |
|
120 | 180 | bool ChartDataSet::nextDomain() |
|
121 | 181 | { |
|
122 | if (m_domainIndex < m_domains.count() - 1) { | |
|
182 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; | |
|
183 | ||
|
184 | if (m_domainIndex < limit) { | |
|
123 | 185 | m_domainIndex++; |
|
124 |
|
|
|
186 | setDomain(m_domainIndex); | |
|
125 | 187 | return true; |
|
126 | 188 | } |
|
127 | 189 | else { |
@@ -133,7 +195,7 bool ChartDataSet::previousDomain() | |||
|
133 | 195 | { |
|
134 | 196 | if (m_domainIndex > 0) { |
|
135 | 197 | m_domainIndex--; |
|
136 |
|
|
|
198 | setDomain(m_domainIndex); | |
|
137 | 199 | return true; |
|
138 | 200 | } |
|
139 | 201 | else { |
@@ -141,21 +203,129 bool ChartDataSet::previousDomain() | |||
|
141 | 203 | } |
|
142 | 204 | } |
|
143 | 205 | |
|
144 |
void ChartDataSet:: |
|
|
206 | void ChartDataSet::setDomain(int index) | |
|
145 | 207 | { |
|
146 | if (m_domainIndex > 0) { | |
|
147 | m_domainIndex = 0; | |
|
148 | emit domainChanged(m_domains[m_domainIndex]); | |
|
208 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
|
209 | foreach (QChartAxis* axis , domainList) { | |
|
210 | int i = m_domainMap.count(axis) - index -1; | |
|
211 | Q_ASSERT(i>=0); | |
|
212 | Domain domain = m_domainMap.values(axis).at(i); | |
|
213 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
|
214 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); | |
|
215 | foreach(QChartSeries* series, seriesList) { | |
|
216 | emit seriesDomainChanged(series,domain); | |
|
217 | } | |
|
218 | emit axisLabelsChanged(axis,labels); | |
|
149 | 219 | } |
|
220 | ||
|
221 | Domain domain = m_domainMap.value(axisY()); | |
|
222 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
|
223 | emit axisLabelsChanged(axisX(),labels); | |
|
150 | 224 | } |
|
151 | 225 | |
|
152 |
void ChartDataSet:: |
|
|
226 | void ChartDataSet::clearDomains(int toIndex) | |
|
227 | { | |
|
228 | Q_ASSERT(toIndex>=0); | |
|
229 | ||
|
230 | m_domainIndex = toIndex; | |
|
231 | ||
|
232 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
|
233 | ||
|
234 | foreach (QChartAxis* key , keys) | |
|
153 | 235 | { |
|
154 | m_domains.resize(m_domainIndex + 1); | |
|
155 | m_domains << domain; | |
|
236 | QList<Domain> domains = m_domainMap.values(key); | |
|
237 | m_domainMap.remove(key); | |
|
238 | int i = domains.size() - toIndex - 1; | |
|
239 | while(i--){ | |
|
240 | domains.removeFirst(); | |
|
241 | } | |
|
242 | for(int j=domains.size()-1; j>=0 ;j--) | |
|
243 | m_domainMap.insert(key,domains.at(j)); | |
|
244 | } | |
|
245 | } | |
|
246 | ||
|
247 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
|
248 | { | |
|
249 | Q_ASSERT(rect.isValid()); | |
|
250 | Q_ASSERT(viewport.isValid()); | |
|
251 | ||
|
252 | clearDomains(m_domainIndex); | |
|
253 | ||
|
254 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
|
255 | ||
|
256 | foreach (QChartAxis* axis , domainList){ | |
|
257 | Domain domain(m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height())); | |
|
258 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
|
259 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); | |
|
260 | foreach(QChartSeries* series, seriesList){ | |
|
261 | emit seriesDomainChanged(series,domain); | |
|
262 | } | |
|
263 | emit axisLabelsChanged(axis,labels); | |
|
264 | m_domainMap.insert(axis,domain); | |
|
265 | } | |
|
266 | ||
|
267 | Domain domain = m_domainMap.value(axisY()); | |
|
268 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
|
269 | emit axisLabelsChanged(axisX(),labels); | |
|
270 | ||
|
156 | 271 | m_domainIndex++; |
|
272 | } | |
|
273 | ||
|
274 | QChartAxis* ChartDataSet::axisY(QChartSeries* series) const | |
|
275 | { | |
|
276 | if(series == 0) return m_axisY; | |
|
277 | ||
|
278 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
|
279 | ||
|
280 | foreach(QChartAxis* axis , keys) { | |
|
281 | if(m_seriesMap.contains(axis,series)){ | |
|
282 | return axis; | |
|
283 | } | |
|
284 | } | |
|
285 | return 0; | |
|
286 | } | |
|
287 | ||
|
288 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
|
289 | { | |
|
290 | Q_ASSERT(max>=min); | |
|
157 | 291 | |
|
158 | emit domainChanged(domain); | |
|
292 | QStringList labels; | |
|
293 | ||
|
294 | int ticks = axis->ticksCount(); | |
|
295 | ||
|
296 | for(int i=0; i<= ticks; i++){ | |
|
297 | qreal value = min + (i * (max - min)/ ticks); | |
|
298 | QString label = axis->axisTickLabel(value); | |
|
299 | if(label.isEmpty()){ | |
|
300 | labels << QString::number(value); | |
|
301 | }else{ | |
|
302 | labels << label; | |
|
303 | } | |
|
304 | } | |
|
305 | return labels; | |
|
306 | } | |
|
307 | ||
|
308 | ||
|
309 | void ChartDataSet::handleMinChanged(qreal min) | |
|
310 | { | |
|
311 | ||
|
312 | } | |
|
313 | ||
|
314 | void ChartDataSet::handleMaxChanged(qreal max) | |
|
315 | { | |
|
316 | ||
|
317 | } | |
|
318 | ||
|
319 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
|
320 | { | |
|
321 | Domain domain = m_domainMap.value(axisY()); | |
|
322 | if(axis==axisX()){ | |
|
323 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
|
324 | emit axisLabelsChanged(axis,labels); | |
|
325 | }else{ | |
|
326 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
|
327 | emit axisLabelsChanged(axis,labels); | |
|
328 | } | |
|
159 | 329 | } |
|
160 | 330 | |
|
161 | 331 | #include "moc_chartdataset_p.cpp" |
@@ -1,12 +1,14 | |||
|
1 |
#ifndef CHART |
|
|
2 |
#define CHART |
|
|
1 | #ifndef CHARTDATASET_P_H_ | |
|
2 | #define CHARTDATASET_P_H_ | |
|
3 | 3 | |
|
4 |
#include |
|
|
4 | #include "qchartseries.h" | |
|
5 | 5 | #include "domain_p.h" |
|
6 | 6 | #include <QVector> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | class QChartAxis; | |
|
11 | ||
|
10 | 12 | class ChartDataSet : public QObject |
|
11 | 13 | { |
|
12 | 14 | Q_OBJECT |
@@ -14,21 +16,42 public: | |||
|
14 | 16 |
ChartDataSet(QObject* parent |
|
15 | 17 | virtual ~ChartDataSet(); |
|
16 | 18 | |
|
17 | void addSeries(QChartSeries* series); | |
|
18 | void addDomain(const Domain& domain); | |
|
19 | void addSeries(QChartSeries* series,QChartAxis *axisY = 0); | |
|
20 | void removeSeries(QChartSeries* series); | |
|
21 | void addDomain(const QRectF& rect, const QRectF& viewport); | |
|
19 | 22 | bool nextDomain(); |
|
20 | 23 | bool previousDomain(); |
|
21 | void clearDomains(); | |
|
22 |
const Domain |
|
|
24 | void clearDomains(int toIndex =0); | |
|
25 | const Domain domain(QChartAxis *axisY) const; | |
|
26 | int domainIndex() const {return m_domainIndex;} | |
|
27 | ||
|
28 | QChartAxis* axisX() const { return m_axisX;}; | |
|
29 | QChartAxis* axisY(QChartSeries* series = 0) const; | |
|
23 | 30 | |
|
24 | 31 | signals: |
|
25 | 32 | void seriesAdded(QChartSeries* series); |
|
26 | void domainChanged(const Domain& domain); | |
|
33 | void seriesRemoved(QChartSeries* series); | |
|
34 | void axisAdded(QChartAxis* axis); | |
|
35 | void axisRemoved(QChartAxis* axis); | |
|
36 | void axisLabelsChanged(QChartAxis* axis, const QStringList& labels); | |
|
37 | void seriesDomainChanged(QChartSeries* series,const Domain& domain); | |
|
38 | ||
|
39 | private slots: | |
|
40 | void handleMinChanged(qreal min); | |
|
41 | void handleMaxChanged(qreal max); | |
|
42 | void handleTickChanged(QChartAxis*); | |
|
43 | ||
|
44 | private: | |
|
45 | void setDomain(int index); | |
|
46 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); | |
|
27 | 47 | |
|
28 | 48 | private: |
|
29 | QList<QChartSeries*> m_chartSeries; | |
|
30 | QVector<Domain> m_domains; | |
|
49 | QMultiMap<QChartAxis*, Domain> m_domainMap; | |
|
50 | QMultiMap<QChartAxis*, QChartSeries*> m_seriesMap; | |
|
51 | QChartAxis* m_axisX; | |
|
52 | QChartAxis* m_axisY; | |
|
31 | 53 | int m_domainIndex; |
|
54 | bool m_axisXInitialized; | |
|
32 | 55 | }; |
|
33 | 56 | |
|
34 | 57 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -13,6 +13,9 class ChartItem : public QGraphicsItem | |||
|
13 | 13 | enum ChartItemTypes{ AXIS_ITEM = UserType+1, XYLINE_ITEM}; |
|
14 | 14 | public: |
|
15 | 15 | ChartItem(QGraphicsItem* parent = 0):QGraphicsItem(parent){}; |
|
16 | //TODO make pure | |
|
17 | virtual void handleGeometryChanged(const QRectF&){}; | |
|
18 | virtual void handleDomainChanged(const Domain& domain){}; | |
|
16 | 19 | virtual ~ChartItem(){}; |
|
17 | 20 | }; |
|
18 | 21 |
@@ -26,14 +26,12 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)), | |
|
31 | m_domainIndex(0), | |
|
32 | 29 | m_marginSize(0), |
|
33 | 30 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
34 | 31 | { |
|
35 | setChartTheme(QChart::ChartThemeDefault); | |
|
36 | 32 |
|
|
33 | setChartTheme(QChart::ChartThemeDefault); | |
|
34 | ||
|
37 | 35 | } |
|
38 | 36 | |
|
39 | 37 | ChartPresenter::~ChartPresenter() |
@@ -44,10 +42,17 void ChartPresenter::createConnections() | |||
|
44 | 42 | { |
|
45 | 43 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
46 | 44 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
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( |
|
|
45 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QChartSeries*)),this,SLOT(handleSeriesRemoved(QChartSeries*))); | |
|
46 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); | |
|
47 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
|
48 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QChartSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QChartSeries*,const Domain&))); | |
|
49 | QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&))); | |
|
50 | } | |
|
51 | ||
|
52 | ||
|
53 | QRectF ChartPresenter::geometry() const | |
|
54 | { | |
|
55 | return m_rect; | |
|
51 | 56 | } |
|
52 | 57 | |
|
53 | 58 | void ChartPresenter::handleGeometryChanged() |
@@ -68,9 +73,31 void ChartPresenter::setMargin(int margin) | |||
|
68 | 73 | m_marginSize = margin; |
|
69 | 74 | } |
|
70 | 75 | |
|
76 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) | |
|
77 | { | |
|
78 | AxisItem* item ; | |
|
79 | ||
|
80 | if(axis==m_dataset->axisX()){ | |
|
81 | item = new AxisItem(AxisItem::X_AXIS,m_chart); | |
|
82 | }else{ | |
|
83 | item = new AxisItem(AxisItem::Y_AXIS,m_chart); | |
|
84 | } | |
|
85 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
|
86 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); | |
|
87 | m_chartTheme->decorate(axis,item); | |
|
88 | m_axisItems.insert(axis,item); | |
|
89 | } | |
|
90 | ||
|
91 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
|
92 | { | |
|
93 | AxisItem* item = m_axisItems.take(axis); | |
|
94 | Q_ASSERT(item); | |
|
95 | delete item; | |
|
96 | } | |
|
97 | ||
|
98 | ||
|
71 | 99 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
72 | 100 | { |
|
73 | qDebug() << " ChartPresenter::handleSeriesAdded"; | |
|
74 | 101 | switch(series->type()) |
|
75 | 102 | { |
|
76 | 103 | case QChartSeries::SeriesTypeLine: { |
@@ -78,7 +105,6 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
78 | 105 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
79 | 106 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
80 | 107 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
|
82 | 108 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
83 | 109 | m_chartItems.insert(series,item); |
|
84 | 110 | break; |
@@ -89,7 +115,6 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
89 | 115 | BarPresenter* item = new BarPresenter(barSeries->model(),m_chart); |
|
90 | 116 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
91 | 117 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
|
93 | 118 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
94 | 119 | m_chartItems.insert(series,item); |
|
95 | 120 | // m_axisXItem->setVisible(false); |
@@ -102,7 +127,6 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
102 | 127 | StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries->model(),m_chart); |
|
103 | 128 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
104 | 129 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
|
106 | 130 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
107 | 131 | m_chartItems.insert(series,item); |
|
108 | 132 | break; |
@@ -114,7 +138,6 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
114 | 138 | PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries->model(),m_chart); |
|
115 | 139 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
116 | 140 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); | |
|
118 | 141 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
119 | 142 | m_chartItems.insert(series,item); |
|
120 | 143 | break; |
@@ -124,8 +147,6 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
124 | 147 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
125 | 148 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
126 | 149 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), | |
|
128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); | |
|
129 | 150 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
130 | 151 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
131 | 152 | break; |
@@ -135,7 +156,6 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
135 | 156 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
136 | 157 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
137 | 158 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
138 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); | |
|
139 | 159 | m_chartItems.insert(series, pie); |
|
140 | 160 | break; |
|
141 | 161 | } |
@@ -148,40 +168,25 void ChartPresenter::handleSeriesAdded(QChartSeries* series) | |||
|
148 | 168 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
149 | 169 | } |
|
150 | 170 | |
|
151 |
void ChartPresenter::handleSeries |
|
|
171 | void ChartPresenter::handleSeriesRemoved(QChartSeries* series) | |
|
152 | 172 | { |
|
153 | //TODO: | |
|
173 | ChartItem* item = m_chartItems.take(series); | |
|
174 | delete item; | |
|
154 | 175 | } |
|
155 | 176 | |
|
156 | void ChartPresenter::zoomInToRect(const QRectF& rect) | |
|
157 | { | |
|
158 | if(!rect.isValid()) return; | |
|
159 | QRectF r = rect.normalized(); | |
|
160 | r.translate(-m_marginSize, -m_marginSize); | |
|
161 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); | |
|
162 | m_dataset->addDomain(domain); | |
|
163 | } | |
|
164 | ||
|
165 | void ChartPresenter::zoomIn() | |
|
177 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) | |
|
166 | 178 | { |
|
167 | if (!m_dataset->nextDomain()) { | |
|
168 | QRectF rect = m_rect; | |
|
169 | rect.setWidth(rect.width()/2); | |
|
170 | rect.setHeight(rect.height()/2); | |
|
171 | rect.moveCenter(m_rect.center()); | |
|
172 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); | |
|
173 | m_dataset->addDomain(domain); | |
|
174 | } | |
|
179 | //TODO: | |
|
175 | 180 | } |
|
176 | 181 | |
|
177 | void ChartPresenter::zoomOut() | |
|
182 | void ChartPresenter::handleSeriesDomainChanged(QChartSeries* series, const Domain& domain) | |
|
178 | 183 | { |
|
179 | m_dataset->previousDomain(); | |
|
184 | m_chartItems.value(series)->handleDomainChanged(domain); | |
|
180 | 185 | } |
|
181 | 186 | |
|
182 | void ChartPresenter::zoomReset() | |
|
187 | void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels) | |
|
183 | 188 | { |
|
184 | m_dataset->clearDomains(); | |
|
189 | m_axisItems.value(axis)->handleLabelsChanged(labels); | |
|
185 | 190 | } |
|
186 | 191 | |
|
187 | 192 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
@@ -200,69 +205,18 void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |||
|
200 | 205 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
201 | 206 | } |
|
202 | 207 | |
|
203 | m_chartTheme->decorate(m_axisX, m_axisXItem); | |
|
204 | m_chartTheme->decorate(m_axisY, m_axisYItem); | |
|
205 | ||
|
208 | QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems); | |
|
209 | while (j.hasNext()) { | |
|
210 | j.next(); | |
|
211 | m_chartTheme->decorate(j.key(),j.value()); | |
|
212 | } | |
|
206 | 213 | } |
|
207 | ||
|
208 | 214 | |
|
209 | 215 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
210 | 216 | { |
|
211 | 217 | return m_chartTheme->id(); |
|
212 | 218 | } |
|
213 | 219 | |
|
214 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) | |
|
215 | { | |
|
216 | //if(m_axisX != axis) { | |
|
217 | m_axisX = axis; | |
|
218 | m_axisXItem->handleAxisChanged(m_axisX); | |
|
219 | //} | |
|
220 | } | |
|
221 | ||
|
222 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) | |
|
223 | { | |
|
224 | // if(m_axisY != axis) { | |
|
225 | m_axisY = axis; | |
|
226 | m_axisYItem->handleAxisChanged(m_axisY); | |
|
227 | //} | |
|
228 | } | |
|
229 | ||
|
230 | QChartAxis ChartPresenter::defaultAxisX() const | |
|
231 | { | |
|
232 | return m_axisX; | |
|
233 | } | |
|
234 | ||
|
235 | QChartAxis ChartPresenter::defaultAxisY() const | |
|
236 | { | |
|
237 | return m_axisY; | |
|
238 | } | |
|
239 | ||
|
240 | QChartAxis ChartPresenter::axisY(int id) const | |
|
241 | { | |
|
242 | return m_axis.value(id); | |
|
243 | } | |
|
244 | ||
|
245 | int ChartPresenter::addAxisY(const QChartAxis& axis) | |
|
246 | { | |
|
247 | int key =0 ; | |
|
248 | ||
|
249 | while(m_axis.contains(key)){ | |
|
250 | key++; | |
|
251 | //TODO overflow | |
|
252 | } | |
|
253 | ||
|
254 | m_axis.insert(key,axis); | |
|
255 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); | |
|
256 | ||
|
257 | return key; | |
|
258 | } | |
|
259 | ||
|
260 | ||
|
261 | void ChartPresenter::removeAxisY(int id) | |
|
262 | { | |
|
263 | m_axis.remove(id); | |
|
264 | delete m_axisItems.take(id); | |
|
265 | } | |
|
266 | 220 | |
|
267 | 221 | #include "moc_chartpresenter_p.cpp" |
|
268 | 222 |
@@ -26,46 +26,31 public: | |||
|
26 | 26 | void setMargin(int margin); |
|
27 | 27 | int margin() const; |
|
28 | 28 | |
|
29 | void zoomInToRect(const QRectF& rectangle); | |
|
30 | void zoomIn(); | |
|
31 | void zoomOut(); | |
|
32 | void zoomReset(); | |
|
29 | QRectF geometry() const; | |
|
33 | 30 | |
|
34 | 31 | void setChartTheme(QChart::ChartTheme theme); |
|
35 | 32 | QChart::ChartTheme chartTheme(); |
|
36 | 33 | |
|
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); | |
|
44 | ||
|
45 | 34 | private: |
|
46 | 35 | void createConnections(); |
|
47 | 36 | |
|
48 | 37 | public slots: |
|
49 | 38 | void handleSeriesAdded(QChartSeries* series); |
|
50 |
void handleSeriesRemoved(QChartSeries* series) |
|
|
39 | void handleSeriesRemoved(QChartSeries* series); | |
|
40 | void handleAxisAdded(QChartAxis* axis); | |
|
41 | void handleAxisRemoved(QChartAxis* axis); | |
|
42 | void handleSeriesDomainChanged(QChartSeries* series, const Domain& domain); | |
|
43 | void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); | |
|
51 | 44 | void handleSeriesChanged(QChartSeries* series); |
|
52 | //void handleDomainChanged(Domain oldDomain,Domain newDomain); | |
|
53 | 45 | void handleGeometryChanged(); |
|
54 | 46 | signals: |
|
55 | 47 | void geometryChanged(const QRectF& rect); |
|
56 | 48 | private: |
|
57 | 49 | QMap<QChartSeries*,ChartItem*> m_chartItems; |
|
58 |
QMap< |
|
|
59 | QMap<int,QChartAxis> m_axis; | |
|
50 | QMap<QChartAxis*,AxisItem*> m_axisItems; | |
|
60 | 51 | QChart* m_chart; |
|
61 | 52 | ChartDataSet* m_dataset; |
|
62 | QVector<Domain> m_domains; | |
|
63 | 53 | ChartTheme *m_chartTheme; |
|
64 | QChartAxis m_axisX; | |
|
65 | AxisItem* m_axisXItem; | |
|
66 | QChartAxis m_axisY; | |
|
67 | AxisItem* m_axisYItem; | |
|
68 | int m_domainIndex; | |
|
69 | 54 | int m_marginSize; |
|
70 | 55 | QRectF m_rect; |
|
71 | 56 |
@@ -217,15 +217,13 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) | |||
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | |
|
220 |
void ChartTheme::decorate(QChartAxis |
|
|
220 | void ChartTheme::decorate(QChartAxis* axis,AxisItem* item) | |
|
221 | 221 | { |
|
222 | 222 | //TODO: dummy defults for now |
|
223 | ||
|
224 |
axis |
|
|
225 |
axis |
|
|
226 |
axis |
|
|
227 | axis.setShadesOpacity(0.5); | |
|
228 | item->handleAxisChanged(axis); | |
|
223 | axis->setLabelsBrush(Qt::black); | |
|
224 | axis->setLabelsPen(Qt::NoPen); | |
|
225 | axis->setShadesPen(Qt::NoPen); | |
|
226 | axis->setShadesOpacity(0.5); | |
|
229 | 227 | } |
|
230 | 228 | |
|
231 | 229 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -37,7 +37,7 public: | |||
|
37 | 37 | void decorate(PercentBarPresenter* item, QPercentBarChartSeries* series,int count); |
|
38 | 38 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); |
|
39 | 39 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
40 |
void decorate(QChartAxis |
|
|
40 | void decorate(QChartAxis* axis,AxisItem* item); | |
|
41 | 41 | |
|
42 | 42 | protected: |
|
43 | 43 | QChart::ChartTheme m_id; |
@@ -3,6 +3,7 | |||
|
3 | 3 | #include "chartpresenter_p.h" |
|
4 | 4 | #include "chartdataset_p.h" |
|
5 | 5 | |
|
6 | <<<<<<< HEAD | |
|
6 | 7 | //series |
|
7 | 8 | #include "qbarchartseries.h" |
|
8 | 9 | #include "qstackedbarchartseries.h" |
@@ -11,7 +12,6 | |||
|
11 | 12 | #include "qscatterseries.h" |
|
12 | 13 | //#include "scatterseries_p.h" |
|
13 | 14 | #include "qpieseries.h" |
|
14 | ||
|
15 | 15 | #include <QGraphicsScene> |
|
16 | 16 | #include <QGraphicsSceneResizeEvent> |
|
17 | 17 | #include <QDebug> |
@@ -28,86 +28,55 m_presenter(new ChartPresenter(this,m_dataset)) | |||
|
28 | 28 | |
|
29 | 29 | QChart::~QChart() {} |
|
30 | 30 | |
|
31 | void QChart::addSeries(QChartSeries* series) | |
|
31 | void QChart::addSeries(QChartSeries* series,QChartAxis* axisY) | |
|
32 | 32 | { |
|
33 | m_dataset->addSeries(series); | |
|
33 | m_dataset->addSeries(series,axisY); | |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | //TODO on review, is it really needed ?? | |
|
37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
|
36 | void QChart::removeSeries(QChartSeries* series) | |
|
38 | 37 | { |
|
39 |
|
|
|
40 | ||
|
41 | switch (type) { | |
|
42 | case QChartSeries::SeriesTypeLine: { | |
|
43 | series = new QLineChartSeries(this); | |
|
44 | break; | |
|
45 | } | |
|
46 | case QChartSeries::SeriesTypeBar: { | |
|
47 | //series = new BarChartSeries(this); | |
|
48 | break; | |
|
49 | } | |
|
50 | case QChartSeries::SeriesTypeStackedBar: { | |
|
51 | //series = new StackedBarChartSeries(this); | |
|
52 | break; | |
|
53 | } | |
|
54 | case QChartSeries::SeriesTypePercentBar: { | |
|
55 | //series = new PercentBarChartSeries(this); | |
|
56 | break; | |
|
57 | } | |
|
58 | case QChartSeries::SeriesTypeScatter: { | |
|
59 | series = new QScatterSeries(this); | |
|
60 | break; | |
|
61 | } | |
|
62 | case QChartSeries::SeriesTypePie: { | |
|
63 | series = new QPieSeries(this); | |
|
64 | break; | |
|
65 | } | |
|
66 | default: | |
|
67 | Q_ASSERT(false); | |
|
68 | break; | |
|
69 | } | |
|
70 | ||
|
71 | addSeries(series); | |
|
72 | return series; | |
|
38 | m_dataset->removeSeries(series); | |
|
73 | 39 | } |
|
74 | 40 | |
|
75 | 41 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
76 | 42 | { |
|
77 | ||
|
78 | if(!m_backgroundItem) { | |
|
79 | m_backgroundItem = new QGraphicsRectItem(this); | |
|
80 | m_backgroundItem->setZValue(-1); | |
|
81 | } | |
|
82 | ||
|
43 | createChartBackgroundItem(); | |
|
83 | 44 | m_backgroundItem->setBrush(brush); |
|
84 | 45 | m_backgroundItem->update(); |
|
85 | 46 | } |
|
86 | 47 | |
|
87 | 48 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
88 | 49 | { |
|
89 | ||
|
90 | if(!m_backgroundItem) { | |
|
91 | m_backgroundItem = new QGraphicsRectItem(this); | |
|
92 | m_backgroundItem->setZValue(-1); | |
|
93 | } | |
|
94 | ||
|
50 | createChartBackgroundItem(); | |
|
95 | 51 | m_backgroundItem->setPen(pen); |
|
96 | 52 | m_backgroundItem->update(); |
|
97 | 53 | } |
|
98 | 54 | |
|
99 | 55 | void QChart::setChartTitle(const QString& title) |
|
100 | 56 | { |
|
101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
|
57 | createChartTitleItem(); | |
|
102 | 58 | m_titleItem->setPlainText(title); |
|
103 | 59 | } |
|
104 | 60 | |
|
105 | 61 | void QChart::setChartTitleFont(const QFont& font) |
|
106 | 62 | { |
|
107 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
|
63 | createChartTitleItem(); | |
|
108 | 64 | m_titleItem->setFont(font); |
|
109 | 65 | } |
|
110 | 66 | |
|
67 | void QChart::createChartBackgroundItem() | |
|
68 | { | |
|
69 | if(!m_backgroundItem) { | |
|
70 | m_backgroundItem = new QGraphicsRectItem(this); | |
|
71 | m_backgroundItem->setZValue(-1); | |
|
72 | } | |
|
73 | } | |
|
74 | ||
|
75 | void QChart::createChartTitleItem() | |
|
76 | { | |
|
77 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
|
78 | } | |
|
79 | ||
|
111 | 80 | int QChart::margin() const |
|
112 | 81 | { |
|
113 | 82 | return m_presenter->margin(); |
@@ -128,59 +97,44 QChart::ChartTheme QChart::chartTheme() const | |||
|
128 | 97 | return m_presenter->chartTheme(); |
|
129 | 98 | } |
|
130 | 99 | |
|
131 | void QChart::zoomInToRect(const QRectF& rectangle) | |
|
132 | { | |
|
133 | m_presenter->zoomInToRect(rectangle); | |
|
134 | } | |
|
135 | ||
|
136 | 100 | void QChart::zoomIn() |
|
137 | 101 | { |
|
138 | m_presenter->zoomIn(); | |
|
139 | } | |
|
140 | ||
|
141 | void QChart::zoomOut() | |
|
142 | { | |
|
143 | m_presenter->zoomOut(); | |
|
102 | if (!m_dataset->nextDomain()) { | |
|
103 | QRectF rect = m_presenter->geometry(); | |
|
104 | rect.setWidth(rect.width()/2); | |
|
105 | rect.setHeight(rect.height()/2); | |
|
106 | rect.moveCenter(m_presenter->geometry().center()); | |
|
107 | zoomIn(rect); | |
|
144 | 108 | } |
|
145 | ||
|
146 | void QChart::zoomReset() | |
|
147 | { | |
|
148 | m_presenter->zoomReset(); | |
|
149 | 109 | } |
|
150 | 110 | |
|
151 | void QChart::setDefaultAxisX(const QChartAxis& axis) | |
|
111 | void QChart::zoomIn(const QRectF& rect) | |
|
152 | 112 | { |
|
153 | m_presenter->setDefaultAxisX(axis); | |
|
113 | if(!rect.isValid()) return; | |
|
114 | QRectF r = rect.normalized(); | |
|
115 | int margin = m_presenter->margin(); | |
|
116 | r.translate(-margin, -margin); | |
|
117 | m_dataset->addDomain(r,m_presenter->geometry()); | |
|
154 | 118 | } |
|
155 | 119 | |
|
156 | void QChart::setDefaultAxisY(const QChartAxis& axis) | |
|
157 | { | |
|
158 | m_presenter->setDefaultAxisY(axis); | |
|
159 | } | |
|
160 | ||
|
161 | QChartAxis QChart::defaultAxisX() const | |
|
162 | { | |
|
163 | return m_presenter->defaultAxisX(); | |
|
164 | } | |
|
165 | ||
|
166 | QChartAxis QChart::defaultAxisY() const | |
|
120 | void QChart::zoomOut() | |
|
167 | 121 | { |
|
168 | return m_presenter->defaultAxisY(); | |
|
122 | m_dataset->previousDomain(); | |
|
169 | 123 | } |
|
170 | 124 | |
|
171 | int QChart::addAxisY(const QChartAxis& axis) | |
|
125 | void QChart::zoomReset() | |
|
172 | 126 | { |
|
173 | return m_presenter->addAxisY(axis); | |
|
127 | m_dataset->clearDomains(); | |
|
174 | 128 | } |
|
175 | 129 | |
|
176 |
QChartAxis QChart::axis |
|
|
130 | QChartAxis* QChart::axisX() const | |
|
177 | 131 | { |
|
178 |
return m_ |
|
|
132 | return m_dataset->axisX(); | |
|
179 | 133 | } |
|
180 | 134 | |
|
181 | void QChart::removeAxisY(int id) | |
|
135 | QChartAxis* QChart::axisY() const | |
|
182 | 136 | { |
|
183 | m_presenter->removeAxisY(id); | |
|
137 | return m_dataset->axisY(); | |
|
184 | 138 | } |
|
185 | 139 | |
|
186 | 140 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
@@ -21,11 +21,6 class ChartItem; | |||
|
21 | 21 | class ChartDataSet; |
|
22 | 22 | class ChartPresenter; |
|
23 | 23 | |
|
24 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
|
25 | //class QTCOMMERCIALCHART_EXPORT QChart | |
|
26 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
|
27 | // public: QChartGraphicsItem(QChart &chart); | |
|
28 | ||
|
29 | 24 | /*! |
|
30 | 25 | * TODO: define the responsibilities |
|
31 | 26 | */ |
@@ -47,11 +42,8 public: | |||
|
47 | 42 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
48 | 43 | ~QChart(); |
|
49 | 44 | |
|
50 | void addSeries(QChartSeries* series); | |
|
51 | ||
|
52 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
|
53 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
|
54 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
|
45 | void addSeries(QChartSeries* series,QChartAxis *axisY=0); | |
|
46 | void removeSeries(QChartSeries* series); | |
|
55 | 47 | |
|
56 | 48 | void setMargin(int margin); |
|
57 | 49 | int margin() const; |
@@ -63,23 +55,22 public: | |||
|
63 | 55 | void setChartBackgroundBrush(const QBrush& brush); |
|
64 | 56 | void setChartBackgroundPen(const QPen& pen); |
|
65 | 57 | |
|
66 | void zoomInToRect(const QRectF& rectangle); | |
|
67 | 58 | void zoomIn(); |
|
59 | void zoomIn(const QRectF& rect); | |
|
68 | 60 | void zoomOut(); |
|
69 | 61 | void zoomReset(); |
|
70 | 62 | |
|
71 | void setDefaultAxisX(const QChartAxis& axis); | |
|
72 | void setDefaultAxisY(const QChartAxis& axis); | |
|
73 | QChartAxis defaultAxisX() const; | |
|
74 | QChartAxis defaultAxisY() const; | |
|
75 | QChartAxis axisY(int id) const; | |
|
76 | int addAxisY(const QChartAxis& axis); | |
|
77 | void removeAxisY(int id); | |
|
63 | QChartAxis* axisX() const; | |
|
64 | QChartAxis* axisY() const; | |
|
78 | 65 | |
|
79 | 66 | protected: |
|
80 | 67 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
81 | 68 | |
|
82 | 69 | private: |
|
70 | inline void createChartBackgroundItem(); | |
|
71 | inline void createChartTitleItem(); | |
|
72 | ||
|
73 | private: | |
|
83 | 74 | Q_DISABLE_COPY(QChart) |
|
84 | 75 | QGraphicsRectItem* m_backgroundItem; |
|
85 | 76 | QGraphicsTextItem* m_titleItem; |
@@ -2,85 +2,153 | |||
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | QChartAxis::QChartAxis(): | |
|
5 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), | |
|
6 | 6 | m_axisVisible(true), |
|
7 | 7 | m_gridVisible(true), |
|
8 | 8 | m_labelsVisible(true), |
|
9 | m_labelsAngle(0), | |
|
9 | 10 | m_shadesVisible(true), |
|
10 | m_shadesOpacity(1.0) | |
|
11 | m_shadesOpacity(1.0), | |
|
12 | m_min(0), | |
|
13 | m_max(0), | |
|
14 | m_ticksCount(4) | |
|
11 | 15 | { |
|
12 | // TODO Auto-generated constructor stub | |
|
13 | 16 | |
|
14 | 17 | } |
|
15 | 18 | |
|
16 | 19 | QChartAxis::~QChartAxis() |
|
17 | 20 | { |
|
18 | // TODO Auto-generated destructor stub | |
|
19 | 21 | } |
|
20 | 22 | |
|
21 | 23 | void QChartAxis::setAxisPen(const QPen& pen) |
|
22 | 24 | { |
|
23 | 25 | m_axisPen=pen; |
|
26 | emit update(this); | |
|
24 | 27 | } |
|
25 | 28 | |
|
26 | 29 | void QChartAxis::setAxisVisible(bool visible) |
|
27 | 30 | { |
|
28 | 31 | m_axisVisible=visible; |
|
32 | emit update(this); | |
|
29 | 33 | } |
|
30 | 34 | |
|
31 | 35 | void QChartAxis::setGridVisible(bool visible) |
|
32 | 36 | { |
|
33 | 37 | m_gridVisible=visible; |
|
38 | emit update(this); | |
|
34 | 39 | } |
|
35 | 40 | |
|
36 | 41 | void QChartAxis::setGridPen(const QPen& pen) |
|
37 | 42 | { |
|
38 | 43 | m_gridPen=pen; |
|
44 | emit update(this); | |
|
39 | 45 | } |
|
40 | 46 | |
|
41 | 47 | void QChartAxis::setLabelsVisible(bool visible) |
|
42 | 48 | { |
|
43 | 49 | m_labelsVisible=visible; |
|
50 | emit update(this); | |
|
44 | 51 | } |
|
45 | 52 | |
|
46 | 53 | void QChartAxis::setLabelsPen(const QPen& pen) |
|
47 | 54 | { |
|
48 | 55 | m_labelsPen=pen; |
|
56 | emit update(this); | |
|
49 | 57 | } |
|
50 | 58 | |
|
51 | 59 | void QChartAxis::setLabelsBrush(const QBrush& brush) |
|
52 | 60 | { |
|
53 | 61 | m_labelsBrush=brush; |
|
62 | emit update(this); | |
|
54 | 63 | } |
|
55 | 64 | |
|
56 | 65 | void QChartAxis::setLabelsFont(const QFont& font) |
|
57 | 66 | { |
|
58 | 67 | m_labelsFont=font; |
|
68 | emit update(this); | |
|
59 | 69 | } |
|
60 | 70 | |
|
61 |
void QChartAxis::setLabels |
|
|
71 | void QChartAxis::setLabelsAngle(int angle) | |
|
62 | 72 | { |
|
63 | m_labelsOrientation=orientation; | |
|
73 | m_labelsAngle=angle; | |
|
74 | emit update(this); | |
|
64 | 75 | } |
|
65 | 76 | |
|
66 | 77 | void QChartAxis::setShadesVisible(bool visible) |
|
67 | 78 | { |
|
68 | 79 | m_shadesVisible=visible; |
|
80 | emit update(this); | |
|
69 | 81 | } |
|
70 | 82 | |
|
71 | 83 | void QChartAxis::setShadesPen(const QPen& pen) |
|
72 | 84 | { |
|
73 | 85 | m_shadesPen=pen; |
|
86 | emit update(this); | |
|
74 | 87 | } |
|
75 | 88 | |
|
76 | 89 | void QChartAxis::setShadesBrush(const QBrush& brush) |
|
77 | 90 | { |
|
78 | 91 | m_shadesBrush=brush; |
|
92 | emit update(this); | |
|
79 | 93 | } |
|
80 | 94 | |
|
81 | 95 | void QChartAxis::setShadesOpacity(qreal opacity) |
|
82 | 96 | { |
|
83 | 97 | m_shadesOpacity=opacity; |
|
98 | emit update(this); | |
|
84 | 99 | } |
|
85 | 100 | |
|
101 | void QChartAxis::setMin(qreal min) | |
|
102 | { | |
|
103 | if(m_min!=min){ | |
|
104 | m_min=min; | |
|
105 | emit minChanged(m_min); | |
|
106 | } | |
|
107 | } | |
|
108 | ||
|
109 | void QChartAxis::setMax(qreal max) | |
|
110 | { | |
|
111 | if(m_max!=max){ | |
|
112 | m_max=max; | |
|
113 | emit maxChanged(m_max); | |
|
114 | } | |
|
115 | } | |
|
116 | ||
|
117 | void QChartAxis::setRange(qreal min, qreal max) | |
|
118 | { | |
|
119 | setMin(min); | |
|
120 | setMax(max); | |
|
121 | } | |
|
122 | ||
|
123 | void QChartAxis::setTicksCount(int count) | |
|
124 | { | |
|
125 | m_ticksCount=count; | |
|
126 | emit ticksChanged(this); | |
|
127 | } | |
|
128 | ||
|
129 | void QChartAxis::addAxisTickLabel(qreal value,const QString& label) | |
|
130 | { | |
|
131 | m_ticks.insert(value,label); | |
|
132 | emit ticksChanged(this); | |
|
133 | } | |
|
134 | ||
|
135 | void QChartAxis::removeAxisTickLabel(qreal value) | |
|
136 | { | |
|
137 | m_ticks.remove(value); | |
|
138 | emit ticksChanged(this); | |
|
139 | } | |
|
140 | ||
|
141 | QString QChartAxis::axisTickLabel(qreal value) const | |
|
142 | { | |
|
143 | return m_ticks.value(value); | |
|
144 | } | |
|
145 | ||
|
146 | void QChartAxis::clearAxisTickLabels() | |
|
147 | { | |
|
148 | m_ticks.clear(); | |
|
149 | emit ticksChanged(this); | |
|
150 | } | |
|
151 | ||
|
152 | #include "moc_qchartaxis.cpp" | |
|
153 | ||
|
86 | 154 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -8,15 +8,14 | |||
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | class QTCOMMERCIALCHART_EXPORT QChartAxis | |
|
11 | class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject | |
|
12 | 12 | { |
|
13 | Q_OBJECT | |
|
13 | 14 | public: |
|
14 | enum LabelsOrientation{ LabelsOrientationHorizontal, LabelsOrientationVertical , LabelsOrientationSlide }; | |
|
15 | QChartAxis(QObject* parent =0); | |
|
16 | ~QChartAxis(); | |
|
15 | 17 | |
|
16 | QChartAxis(); | |
|
17 | virtual ~QChartAxis(); | |
|
18 | ||
|
19 | //axis | |
|
18 | //axis handling | |
|
20 | 19 | bool isAxisVisible() const { return m_axisVisible;}; |
|
21 | 20 | void setAxisVisible(bool visible); |
|
22 | 21 | void setAxisPen(const QPen& pen); |
@@ -24,13 +23,13 public: | |||
|
24 | 23 | void setAxisBrush(const QBrush& brush); |
|
25 | 24 | QBrush axisBrush() const { return m_axisBrush;}; |
|
26 | 25 | |
|
27 | //grid | |
|
26 | //grid handling | |
|
28 | 27 | bool isGridVisible() const { return m_gridVisible;}; |
|
29 | 28 | void setGridVisible(bool visible); |
|
30 | 29 | void setGridPen(const QPen& pen); |
|
31 | 30 | QPen gridPen() const {return m_gridPen;} |
|
32 | 31 | |
|
33 | //labels | |
|
32 | //labels handling | |
|
34 | 33 | bool isLabelsVisible() const { return m_labelsVisible;}; |
|
35 | 34 | void setLabelsVisible(bool visible); |
|
36 | 35 | void setLabelsPen(const QPen& pen); |
@@ -39,10 +38,10 public: | |||
|
39 | 38 | QBrush labelsBrush() const { return m_labelsBrush;} |
|
40 | 39 | void setLabelsFont(const QFont& font); |
|
41 | 40 | QFont labelFont() const { return m_labelsFont;} |
|
42 | void setLabelsOrientation(LabelsOrientation orientation); | |
|
43 |
|
|
|
41 | void setLabelsAngle(int angle); | |
|
42 | int labelsAngle() const { return m_labelsAngle;}; | |
|
44 | 43 | |
|
45 | //shades | |
|
44 | //shades handling | |
|
46 | 45 | bool isShadesVisible() const { return m_shadesVisible;}; |
|
47 | 46 | void setShadesVisible(bool visible); |
|
48 | 47 | void setShadesPen(const QPen& pen); |
@@ -52,10 +51,29 public: | |||
|
52 | 51 | void setShadesOpacity(qreal opacity); |
|
53 | 52 | qreal shadesOpacity() const { return m_shadesOpacity;} |
|
54 | 53 | |
|
55 | ||
|
54 | //range handling | |
|
55 | void setMin(qreal min); | |
|
56 | qreal min() const { return m_min;}; | |
|
57 | void setMax(qreal max); | |
|
58 | qreal max() const { return m_max;}; | |
|
59 | void setRange(qreal min, qreal max); | |
|
60 | ||
|
61 | //ticks handling | |
|
62 | void setTicksCount(int count); | |
|
63 | int ticksCount() const { return m_ticksCount;} | |
|
64 | void addAxisTickLabel(qreal value,const QString& label); | |
|
65 | void removeAxisTickLabel(qreal value); | |
|
66 | QString axisTickLabel(qreal value) const ; | |
|
67 | void clearAxisTickLabels(); | |
|
68 | ||
|
69 | signals: | |
|
70 | void minChanged(qreal min); | |
|
71 | void maxChanged(qreal max); | |
|
72 | //private signal | |
|
73 | void update(QChartAxis*); | |
|
74 | void ticksChanged(QChartAxis*); | |
|
56 | 75 | |
|
57 | 76 | private: |
|
58 | ||
|
59 | 77 | bool m_axisVisible; |
|
60 | 78 | QPen m_axisPen; |
|
61 | 79 | QBrush m_axisBrush; |
@@ -67,15 +85,18 private: | |||
|
67 | 85 | QPen m_labelsPen; |
|
68 | 86 | QBrush m_labelsBrush; |
|
69 | 87 | QFont m_labelsFont; |
|
88 | int m_labelsAngle; | |
|
70 | 89 | |
|
71 | 90 | bool m_shadesVisible; |
|
72 | 91 | QPen m_shadesPen; |
|
73 | 92 | QBrush m_shadesBrush; |
|
74 | ||
|
75 | 93 | qreal m_shadesOpacity; |
|
76 | 94 | |
|
95 | qreal m_min; | |
|
96 | qreal m_max; | |
|
77 | 97 | |
|
78 | LabelsOrientation m_labelsOrientation; | |
|
98 | int m_ticksCount; | |
|
99 | QMap<qreal, QString> m_ticks; | |
|
79 | 100 | }; |
|
80 | 101 | |
|
81 | 102 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -36,25 +36,19 void QChartView::resizeEvent(QResizeEvent *event) | |||
|
36 | 36 | QWidget::resizeEvent(event); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | void QChartView::addSeries(QChartSeries* series) | |
|
39 | void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY) | |
|
40 | 40 | { |
|
41 | m_chart->addSeries(series); | |
|
41 | m_chart->addSeries(series,axisY); | |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) | |
|
44 | void QChartView::zoomIn() | |
|
45 | 45 | { |
|
46 | ||
|
47 | return m_chart->createSeries(type); | |
|
46 | m_chart->zoomIn(); | |
|
48 | 47 | } |
|
49 | 48 | |
|
50 |
void QChartView::zoomIn |
|
|
49 | void QChartView::zoomIn(const QRect& rect) | |
|
51 | 50 | { |
|
52 |
m_chart->zoomIn |
|
|
53 | } | |
|
54 | ||
|
55 | void QChartView::zoomIn() | |
|
56 | { | |
|
57 | m_chart->zoomIn(); | |
|
51 | m_chart->zoomIn(rect); | |
|
58 | 52 | } |
|
59 | 53 | |
|
60 | 54 | void QChartView::zoomOut() |
@@ -167,7 +161,7 void QChartView::mouseReleaseEvent(QMouseEvent *event) | |||
|
167 | 161 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
168 | 162 | m_rubberBand->hide(); |
|
169 | 163 | QRect rect = m_rubberBand->geometry(); |
|
170 |
m_chart->zoomIn |
|
|
164 | m_chart->zoomIn(rect); | |
|
171 | 165 | event->accept(); |
|
172 | 166 | } |
|
173 | 167 | |
@@ -204,38 +198,14 QChart::ChartTheme QChartView::chartTheme() const | |||
|
204 | 198 | return m_chart->chartTheme(); |
|
205 | 199 | } |
|
206 | 200 | |
|
207 | void QChartView::setDefaultAxisX(const QChartAxis& axis) | |
|
208 | { | |
|
209 | m_chart->setDefaultAxisX(axis); | |
|
210 | } | |
|
211 | ||
|
212 | void QChartView::setDefaultAxisY(const QChartAxis& axis) | |
|
201 | QChartAxis* QChartView::axisX() const | |
|
213 | 202 | { |
|
214 |
m_chart-> |
|
|
203 | return m_chart->axisX(); | |
|
215 | 204 | } |
|
216 | 205 | |
|
217 |
QChartAxis QChartView:: |
|
|
206 | QChartAxis* QChartView::axisY() const | |
|
218 | 207 | { |
|
219 |
return m_chart-> |
|
|
208 | return m_chart->axisY(); | |
|
220 | 209 | } |
|
221 | 210 | |
|
222 | QChartAxis QChartView::defaultAxisY() const | |
|
223 | { | |
|
224 | return m_chart->defaultAxisY(); | |
|
225 | } | |
|
226 | ||
|
227 | int QChartView::addAxisY(const QChartAxis& axis) | |
|
228 | { | |
|
229 | return m_chart->addAxisY(axis); | |
|
230 | } | |
|
231 | ||
|
232 | QChartAxis QChartView::axisY(int id) const | |
|
233 | { | |
|
234 | return m_chart->axisY(id); | |
|
235 | } | |
|
236 | ||
|
237 | void QChartView::removeAxisY(int id) | |
|
238 | { | |
|
239 | m_chart->removeAxisY(id); | |
|
240 | } | |
|
241 | 211 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -24,10 +24,8 public: | |||
|
24 | 24 | //implement from QWidget |
|
25 | 25 | void resizeEvent(QResizeEvent *event); |
|
26 | 26 | |
|
27 |
void addSeries(QChartSeries* series); |
|
|
28 | ||
|
29 | // Convenience function | |
|
30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
|
27 | void addSeries(QChartSeries* series,QChartAxis* axisY=0) ;// takes ownership | |
|
28 | void removeSeries(QChartSeries* series); | |
|
31 | 29 | |
|
32 | 30 | int margin() const; |
|
33 | 31 | |
@@ -36,8 +34,8 public: | |||
|
36 | 34 | void setChartBackgroundBrush(const QBrush& brush); |
|
37 | 35 | void setChartBackgroundPen(const QPen& pen); |
|
38 | 36 | |
|
39 | void zoomInToRect(const QRect& rectangle); | |
|
40 | 37 | void zoomIn(); |
|
38 | void zoomIn(const QRect& rect); | |
|
41 | 39 | void zoomOut(); |
|
42 | 40 | |
|
43 | 41 | void setRubberBandPolicy(const RubberBandPolicy ); |
@@ -46,13 +44,8 public: | |||
|
46 | 44 | void setChartTheme(QChart::ChartTheme theme); |
|
47 | 45 | QChart::ChartTheme chartTheme() const; |
|
48 | 46 | |
|
49 | void setDefaultAxisX(const QChartAxis& axis); | |
|
50 | void setDefaultAxisY(const QChartAxis& axis); | |
|
51 | QChartAxis defaultAxisX() const; | |
|
52 | QChartAxis defaultAxisY() const; | |
|
53 | QChartAxis axisY(int id) const; | |
|
54 | int addAxisY(const QChartAxis& axis); | |
|
55 | void removeAxisY(int id); | |
|
47 | QChartAxis* axisX() const; | |
|
48 | QChartAxis* axisY() const; | |
|
56 | 49 | |
|
57 | 50 | protected: |
|
58 | 51 | void mousePressEvent(QMouseEvent *event); |
General Comments 0
You need to be logged in to leave comments.
Login now