##// END OF EJS Templates
Removed generic chartaxis
Marek Rosa -
r1561:8267a30e4282
parent child
Show More
@@ -3,8 +3,8 DEPENDPATH += $$PWD
3 3
4 4 SOURCES += \
5 5 $$PWD/chartaxis.cpp \
6 $$PWD/chartaxisx.cpp \
7 $$PWD/chartaxisy.cpp \
6 # $$PWD/chartaxisx.cpp \
7 # $$PWD/chartaxisy.cpp \
8 8 $$PWD/chartvaluesaxisx.cpp \
9 9 $$PWD/chartvaluesaxisy.cpp \
10 10 $$PWD/chartcategoriesaxisx.cpp \
@@ -15,8 +15,8 SOURCES += \
15 15
16 16 PRIVATE_HEADERS += \
17 17 $$PWD/chartaxis_p.h \
18 $$PWD/chartaxisx_p.h \
19 $$PWD/chartaxisy_p.h \
18 # $$PWD/chartaxisx_p.h \
19 # $$PWD/chartaxisy_p.h \
20 20 $$PWD/chartvaluesaxisx_p.h \
21 21 $$PWD/chartvaluesaxisy_p.h \
22 22 $$PWD/chartcategoriesaxisx_p.h \
@@ -45,11 +45,12 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
45 45 QVector<qreal> points;
46 46 points.resize(m_ticksCount);
47 47
48 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
48 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
49 49 for (int i = 0; i < m_ticksCount; ++i) {
50 int x = i * deltaX + m_rect.left();
51 points[i] = x;
50 int y = i * -deltaY + m_rect.bottom();
51 points[i] = y;
52 52 }
53
53 54 return points;
54 55 }
55 56
@@ -25,6 +25,7
25 25 #include <QGraphicsLayout>
26 26 #include <QDebug>
27 27 #include <QFontMetrics>
28 #include <cmath>
28 29
29 30 static int label_padding = 5;
30 31
@@ -64,7 +65,16 void ChartValuesAxisX::updateGeometry()
64 65
65 66 QStringList ticksList;
66 67
67 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
68 int ticks = layout.size();
69 int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0);
70 n++;
71 for (int i=0; i< ticks; i++) {
72 qreal value = m_min + (i * (m_max - m_min)/ (ticks-1));
73 Q_UNUSED(value);
74 ticksList << QString::number(value,'f',n);
75 }
76
77 bool categories = false; //createLabels(ticksList,m_min,m_max,layout.size());
68 78
69 79 QList<QGraphicsItem *> lines = m_grid->childItems();
70 80 QList<QGraphicsItem *> labels = m_labels->childItems();
@@ -100,15 +110,15 void ChartValuesAxisX::updateGeometry()
100 110 m_minWidth+=rect.width();
101 111 m_minHeight=qMax(rect.height(),m_minHeight);
102 112 }
103 else {
104 labelItem->setText(ticksList.at(i));
105 const QRectF& rect = labelItem->boundingRect();
106 QPointF center = rect.center();
107 labelItem->setTransformOriginPoint(center.x(), center.y());
108 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
109 m_minWidth+=rect.width();
110 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
111 }
113 // else {
114 // labelItem->setText(ticksList.at(i));
115 // const QRectF& rect = labelItem->boundingRect();
116 // QPointF center = rect.center();
117 // labelItem->setTransformOriginPoint(center.x(), center.y());
118 // labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
119 // m_minWidth+=rect.width();
120 // m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
121 // }
112 122
113 123 if ((i+1)%2 && i>1) {
114 124 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
@@ -25,6 +25,7
25 25 #include <QGraphicsLayout>
26 26 #include <QDebug>
27 27 #include <QFontMetrics>
28 #include <cmath>
28 29
29 30 static int label_padding = 5;
30 31
@@ -45,18 +46,18 QVector<qreal> ChartValuesAxisY::calculateLayout() const
45 46 QVector<qreal> points;
46 47 points.resize(m_ticksCount);
47 48
48 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
49 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
49 50 for (int i = 0; i < m_ticksCount; ++i) {
50 int x = i * deltaX + m_rect.left();
51 points[i] = x;
51 int y = i * -deltaY + m_rect.bottom();
52 points[i] = y;
52 53 }
54
53 55 return points;
54 56 }
55 57
56 58 void ChartValuesAxisY::updateGeometry()
57 59 {
58 const QVector<qreal>& layout = ChartAxis::layout();
59
60 const QVector<qreal> &layout = ChartAxis::layout();
60 61 m_minWidth = 0;
61 62 m_minHeight = 0;
62 63
@@ -64,7 +65,18 void ChartValuesAxisY::updateGeometry()
64 65
65 66 QStringList ticksList;
66 67
67 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
68 int ticks = layout.size();
69 int n = qMax(int(-floor(log10((m_max-m_min)/(ticks-1)))),0);
70 n++;
71 for (int i=0; i< ticks; i++) {
72 qreal value = m_min + (i * (m_max - m_min)/ (ticks-1));
73 Q_UNUSED(value);
74 ticksList << QString::number(value,'f',n);
75 }
76
77 bool categories = false;
78
79 // bool categories = createLabels(ticksList,m_min,m_max,layout.size());
68 80
69 81 QList<QGraphicsItem *> lines = m_grid->childItems();
70 82 QList<QGraphicsItem *> labels = m_labels->childItems();
@@ -74,48 +86,53 void ChartValuesAxisY::updateGeometry()
74 86 Q_ASSERT(labels.size() == ticksList.size());
75 87 Q_ASSERT(layout.size() == ticksList.size());
76 88
89 qreal height = 2*m_rect.bottom();
90
77 91 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
78 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
92 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
79 93
80 qreal width = 0;
81 94 for (int i = 0; i < layout.size(); ++i) {
82 95 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
96 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
84 97 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
98
85 99 if (!categories || i<1) {
86 100 labelItem->setText(ticksList.at(i));
87 101 const QRectF& rect = labelItem->boundingRect();
102
88 103 QPointF center = rect.center();
89 104 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
105 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
91 106
92 if(labelItem->pos().x()<=width){
107 if(labelItem->pos().y()+rect.height()>height) {
93 108 labelItem->setVisible(false);
94 109 lineItem->setVisible(false);
95 }else{
110 }
111 else {
96 112 labelItem->setVisible(true);
97 113 lineItem->setVisible(true);
98 width=rect.width()+labelItem->pos().x();
114 height=labelItem->pos().y();
99 115 }
100 m_minWidth+=rect.width();
101 m_minHeight=qMax(rect.height(),m_minHeight);
116
117 m_minWidth=qMax(rect.width()+label_padding,m_minWidth);
118 m_minHeight+=rect.height();
102 119 }
103 120 else {
104 121 labelItem->setText(ticksList.at(i));
105 122 const QRectF& rect = labelItem->boundingRect();
123 m_minWidth=qMax(rect.width(),m_minWidth);
124 m_minHeight+=rect.height();
106 125 QPointF center = rect.center();
107 126 labelItem->setTransformOriginPoint(center.x(), center.y());
108 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
109 m_minWidth+=rect.width();
110 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
127 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
111 128 }
112 129
113 130 if ((i+1)%2 && i>1) {
114 131 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
115 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
132 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
116 133 }
117 134 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
118 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
135 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
119 136 }
120 137 }
121 138
@@ -20,8 +20,8
20 20
21 21 #include "qcategoriesaxis.h"
22 22 #include "qcategoriesaxis_p.h"
23 #include "chartaxisx_p.h"
24 #include "chartaxisy_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 25
26 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 27
@@ -209,9 +209,9 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
209 209 {
210 210 Q_Q( QCategoriesAxis);
211 211 if(m_orientation == Qt::Vertical){
212 return new ChartAxisY(q,presenter);
212 return new ChartCategoriesAxisY(q,presenter);
213 213 }else{
214 return new ChartAxisX(q,presenter);
214 return new ChartCategoriesAxisX(q,presenter);
215 215 }
216 216
217 217 }
@@ -20,8 +20,8
20 20
21 21 #include "qvaluesaxis.h"
22 22 #include "qvaluesaxis_p.h"
23 #include "chartaxisx_p.h"
24 #include "chartaxisy_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
25 25 #include <QDebug>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -252,9 +252,9 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
252 252 {
253 253 Q_Q(QValuesAxis);
254 254 if(m_orientation == Qt::Vertical){
255 return new ChartAxisY(q,presenter);
255 return new ChartValuesAxisY(q,presenter);
256 256 }else{
257 return new ChartAxisX(q,presenter);
257 return new ChartValuesAxisX(q,presenter);
258 258 }
259 259
260 260 }
@@ -29,8 +29,8
29 29 #include "qabstractseries_p.h"
30 30 #include "qareaseries.h"
31 31 #include "chartaxis_p.h"
32 #include "chartaxisx_p.h"
33 #include "chartaxisy_p.h"
32 //#include "chartaxisx_p.h"
33 //#include "chartaxisy_p.h"
34 34 #include "areachartitem_p.h"
35 35 #include "chartbackground_p.h"
36 36 #include "chartlayout_p.h"
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now