@@ -25,6 +25,7 m_axis(parent) | |||
|
25 | 25 | setFlags(QGraphicsItem::ItemHasNoContents); |
|
26 | 26 | |
|
27 | 27 | QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
28 | QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); | |
|
28 | 29 | } |
|
29 | 30 | |
|
30 | 31 | AxisItem::~AxisItem() |
@@ -95,21 +96,19 void AxisItem::updateItem() | |||
|
95 | 96 | |
|
96 | 97 | QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) |
|
97 | 98 | { |
|
98 | ||
|
99 | ||
|
100 | 99 | Q_ASSERT(max>=min); |
|
101 | 100 | |
|
102 | 101 | QStringList labels; |
|
103 | 102 | |
|
104 | //int ticks = axis->ticksCount()-1; | |
|
103 | QChartAxisCategories* categories = m_chartAxis->categories(); | |
|
105 | 104 | |
|
106 | 105 | for(int i=0; i<= ticks; i++) { |
|
107 | 106 | qreal value = min + (i * (max - min)/ ticks); |
|
108 | QString label ;//= axis->axisTickLabel(value); | |
|
109 | if(label.isEmpty()) { | |
|
107 | if(categories->count()==0) { | |
|
110 | 108 | labels << QString::number(value); |
|
111 | 109 | } |
|
112 | 110 | else { |
|
111 | QString label = categories->label(value); | |
|
113 | 112 | labels << label; |
|
114 | 113 | } |
|
115 | 114 | } |
@@ -270,7 +269,7 void AxisItem::setLayout(const QVector<qreal>& layout) | |||
|
270 | 269 | QPointF center = labelItem->boundingRect().center(); |
|
271 | 270 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
272 | 271 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
273 | if(i%2){ | |
|
272 | if(i%2 && i+1 < layout.size()){ | |
|
274 | 273 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
275 | 274 | rectItem->setRect(layout[i],m_rect.top(),layout[i+1]-layout[i],m_rect.height()); |
|
276 | 275 | } |
@@ -293,7 +292,7 void AxisItem::setLayout(const QVector<qreal>& layout) | |||
|
293 | 292 | QPointF center = labelItem->boundingRect().center(); |
|
294 | 293 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
295 | 294 | labelItem->setPos(m_rect.left() - labelItem->boundingRect().width() - label_padding , layout[i]-center.y()); |
|
296 | if(i%2){ | |
|
295 | if(i%2 && i+1 < layout.size()){ | |
|
297 | 296 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2)); |
|
298 | 297 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i]-layout[i+1]); |
|
299 | 298 | } |
@@ -312,8 +311,21 void AxisItem::setLayout(const QVector<qreal>& layout) | |||
|
312 | 311 | |
|
313 | 312 | //handlers |
|
314 | 313 | |
|
314 | void AxisItem::handleAxisCategoriesUpdated() | |
|
315 | { | |
|
316 | updateItem(); | |
|
317 | } | |
|
318 | ||
|
315 | 319 | void AxisItem::handleAxisUpdated() |
|
316 | 320 | { |
|
321 | ||
|
322 | int count = m_chartAxis->ticksCount(); | |
|
323 | ||
|
324 | if(m_ticks!=count){ | |
|
325 | m_ticks=count; | |
|
326 | updateItem(); | |
|
327 | } | |
|
328 | ||
|
317 | 329 | if(isEmpty()) return; |
|
318 | 330 | |
|
319 | 331 | if(m_chartAxis->isAxisVisible()) { |
@@ -367,14 +379,6 void AxisItem::handleRangeChanged(qreal min, qreal max) | |||
|
367 | 379 | |
|
368 | 380 | } |
|
369 | 381 | |
|
370 | void AxisItem::handleTicksCountChanged(int ticks) | |
|
371 | { | |
|
372 | m_ticks=ticks; | |
|
373 | ||
|
374 | if(isEmpty()) return; | |
|
375 | updateItem(); | |
|
376 | } | |
|
377 | ||
|
378 | 382 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
379 | 383 | { |
|
380 | 384 | m_rect = rect; |
@@ -51,8 +51,8 public: | |||
|
51 | 51 | |
|
52 | 52 | public slots: |
|
53 | 53 | void handleAxisUpdated();//qchartaxis update calls |
|
54 | void handleAxisCategoriesUpdated();//qchartaxis update calls | |
|
54 | 55 | void handleRangeChanged(qreal min , qreal max); //domain update calls |
|
55 | void handleTicksCountChanged(int ticks); //ticks changed | |
|
56 | 56 | void handleGeometryChanged(const QRectF& size); //geometry update calls |
|
57 | 57 | |
|
58 | 58 | public: |
@@ -66,6 +66,7 private: | |||
|
66 | 66 | void clear(int count); |
|
67 | 67 | void createItems(int count); |
|
68 | 68 | QStringList createLabels(int ticks, qreal min, qreal max); |
|
69 | ||
|
69 | 70 | private: |
|
70 | 71 | QChartAxis* m_chartAxis; |
|
71 | 72 | AxisType m_type; |
@@ -60,7 +60,7 public: | |||
|
60 | 60 | void setTicksCount(int count); |
|
61 | 61 | int ticksCount() const { return m_ticksCount;} |
|
62 | 62 | |
|
63 |
QChartAxisCategories |
|
|
63 | QChartAxisCategories* categories() { return &m_category; } | |
|
64 | 64 | |
|
65 | 65 | signals: |
|
66 | 66 | void minChanged(qreal min); |
@@ -34,6 +34,11 int QChartAxisCategories::count() | |||
|
34 | 34 | emit updated(); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | QString QChartAxisCategories::label(qreal value) const | |
|
38 | { | |
|
39 | return m_map.value(value); | |
|
40 | } | |
|
41 | ||
|
37 | 42 | #include "moc_qchartaxiscategories.cpp" |
|
38 | 43 | |
|
39 | 44 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -14,6 +14,7 public: | |||
|
14 | 14 | |
|
15 | 15 | void insert(qreal value,QString label); |
|
16 | 16 | void remove(qreal value); |
|
17 | QString label(qreal value) const; | |
|
17 | 18 | void clear(); |
|
18 | 19 | int count(); |
|
19 | 20 |
@@ -100,21 +100,21 void BarPresenterBase::initAxisLabels() | |||
|
100 | 100 | if (0 == count) { |
|
101 | 101 | return; |
|
102 | 102 | } |
|
103 | count++; | |
|
103 | 104 | |
|
104 | 105 | mChart->axisX()->setTicksCount(count); |
|
105 | 106 | |
|
106 | 107 | qreal min = 0; |
|
107 |
qreal max = |
|
|
108 | qreal max = count; | |
|
108 | 109 | |
|
109 | 110 | mChart->axisX()->setMin(min); |
|
110 | 111 | mChart->axisX()->setMax(max); |
|
111 | qreal step = (max-min)/count; | |
|
112 |
QChartAxisCategories |
|
|
113 |
categories |
|
|
114 | for (int i=0; i<count; i++) { | |
|
115 |
|
|
|
116 | categories.insert(min,mSeries->categoryName(i)); | |
|
117 | min += step; | |
|
112 | min++; | |
|
113 | QChartAxisCategories* categories = mChart->axisX()->categories(); | |
|
114 | categories->clear(); | |
|
115 | for (int i=0; i<count-1; i++) { | |
|
116 | categories->insert(min,mSeries->categoryName(i)); | |
|
117 | min++; | |
|
118 | 118 | } |
|
119 | 119 | mChart->axisX()->setLabelsVisible(true); |
|
120 | 120 | } |
@@ -109,13 +109,12 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |||
|
109 | 109 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); |
|
110 | 110 | //initialize |
|
111 | 111 | item->handleRangeChanged(domain->minX(),domain->maxX()); |
|
112 | item->handleTicksCountChanged(4); | |
|
113 | 112 | } |
|
114 | 113 | else{ |
|
115 | 114 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); |
|
116 | 115 | //initialize |
|
117 | 116 | item->handleRangeChanged(domain->minY(),domain->maxY()); |
|
118 | item->handleTicksCountChanged(4); | |
|
117 | ||
|
119 | 118 | } |
|
120 | 119 | |
|
121 | 120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
General Comments 0
You need to be logged in to leave comments.
Login now