@@ -15,20 +15,20 Chart(presenter), | |||||
15 | m_chartAxis(axis), |
|
15 | m_chartAxis(axis), | |
16 | m_type(type), |
|
16 | m_type(type), | |
17 | m_labelsAngle(0), |
|
17 | m_labelsAngle(0), | |
18 | m_grid(presenter->rootItem()), |
|
18 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
19 | m_shades(presenter->rootItem()), |
|
19 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
20 | m_labels(presenter->rootItem()), |
|
20 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
21 | m_axis(presenter->rootItem()), |
|
21 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), | |
22 | m_min(0), |
|
22 | m_min(0), | |
23 | m_max(0), |
|
23 | m_max(0), | |
24 | m_ticksCount(0) |
|
24 | m_ticksCount(0) | |
25 | { |
|
25 | { | |
26 | //initial initialization |
|
26 | //initial initialization | |
27 |
m_axis |
|
27 | m_axis->setZValue(ChartPresenter::AxisZValue); | |
28 |
m_axis |
|
28 | m_axis->setHandlesChildEvents(false); | |
29 |
|
29 | |||
30 |
m_shades |
|
30 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
31 |
m_grid |
|
31 | m_grid->setZValue(ChartPresenter::GridZValue); | |
32 |
|
32 | |||
33 | QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
33 | QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
34 | QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); |
|
34 | QObject::connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); | |
@@ -43,22 +43,22 Axis::~Axis() | |||||
43 | void Axis::createItems(int count) |
|
43 | void Axis::createItems(int count) | |
44 | { |
|
44 | { | |
45 |
|
45 | |||
46 |
if(m_axis |
|
46 | if(m_axis->children().size()==0) | |
47 |
m_axis |
|
47 | m_axis->addToGroup(new AxisItem(this)); | |
48 | for (int i = 0; i < count; ++i) { |
|
48 | for (int i = 0; i < count; ++i) { | |
49 |
m_grid |
|
49 | m_grid->addToGroup(new QGraphicsLineItem()); | |
50 |
m_labels |
|
50 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); | |
51 |
m_axis |
|
51 | m_axis->addToGroup(new QGraphicsLineItem()); | |
52 |
if((m_grid |
|
52 | if((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); | |
53 | } |
|
53 | } | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void Axis::deleteItems(int count) |
|
56 | void Axis::deleteItems(int count) | |
57 | { |
|
57 | { | |
58 |
QList<QGraphicsItem *> lines = m_grid |
|
58 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
59 |
QList<QGraphicsItem *> labels = m_labels |
|
59 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
60 |
QList<QGraphicsItem *> shades = m_shades |
|
60 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
61 |
QList<QGraphicsItem *> axis = m_axis |
|
61 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
62 |
|
62 | |||
63 | for (int i = 0; i < count; ++i) { |
|
63 | for (int i = 0; i < count; ++i) { | |
64 | if(lines.size()%2 && lines.size()>1) delete(shades.takeLast()); |
|
64 | if(lines.size()%2 && lines.size()>1) delete(shades.takeLast()); | |
@@ -103,47 +103,47 QStringList Axis::createLabels(int ticks, qreal min, qreal max) const | |||||
103 |
|
103 | |||
104 | void Axis::setAxisOpacity(qreal opacity) |
|
104 | void Axis::setAxisOpacity(qreal opacity) | |
105 | { |
|
105 | { | |
106 |
m_axis |
|
106 | m_axis->setOpacity(opacity); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | qreal Axis::axisOpacity() const |
|
109 | qreal Axis::axisOpacity() const | |
110 | { |
|
110 | { | |
111 |
return m_axis |
|
111 | return m_axis->opacity(); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void Axis::setGridOpacity(qreal opacity) |
|
114 | void Axis::setGridOpacity(qreal opacity) | |
115 | { |
|
115 | { | |
116 |
m_grid |
|
116 | m_grid->setOpacity(opacity); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | qreal Axis::gridOpacity() const |
|
119 | qreal Axis::gridOpacity() const | |
120 | { |
|
120 | { | |
121 |
return m_grid |
|
121 | return m_grid->opacity(); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void Axis::setLabelsOpacity(qreal opacity) |
|
124 | void Axis::setLabelsOpacity(qreal opacity) | |
125 | { |
|
125 | { | |
126 |
m_labels |
|
126 | m_labels->setOpacity(opacity); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | qreal Axis::labelsOpacity() const |
|
129 | qreal Axis::labelsOpacity() const | |
130 | { |
|
130 | { | |
131 |
return m_labels |
|
131 | return m_labels->opacity(); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void Axis::setShadesOpacity(qreal opacity) |
|
134 | void Axis::setShadesOpacity(qreal opacity) | |
135 | { |
|
135 | { | |
136 |
m_shades |
|
136 | m_shades->setOpacity(opacity); | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | qreal Axis::shadesOpacity() const |
|
139 | qreal Axis::shadesOpacity() const | |
140 | { |
|
140 | { | |
141 |
return m_shades |
|
141 | return m_shades->opacity(); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void Axis::setLabelsAngle(int angle) |
|
144 | void Axis::setLabelsAngle(int angle) | |
145 | { |
|
145 | { | |
146 |
foreach(QGraphicsItem* item , m_labels |
|
146 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
147 | QPointF center = item->boundingRect().center(); |
|
147 | QPointF center = item->boundingRect().center(); | |
148 | item->setRotation(angle); |
|
148 | item->setRotation(angle); | |
149 | } |
|
149 | } | |
@@ -153,49 +153,49 void Axis::setLabelsAngle(int angle) | |||||
153 |
|
153 | |||
154 | void Axis::setLabelsPen(const QPen& pen) |
|
154 | void Axis::setLabelsPen(const QPen& pen) | |
155 | { |
|
155 | { | |
156 |
foreach(QGraphicsItem* item , m_labels |
|
156 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
157 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
157 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void Axis::setLabelsBrush(const QBrush& brush) |
|
161 | void Axis::setLabelsBrush(const QBrush& brush) | |
162 | { |
|
162 | { | |
163 |
foreach(QGraphicsItem* item , m_labels |
|
163 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
164 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
164 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
165 | } |
|
165 | } | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void Axis::setLabelsFont(const QFont& font) |
|
168 | void Axis::setLabelsFont(const QFont& font) | |
169 | { |
|
169 | { | |
170 |
foreach(QGraphicsItem* item , m_labels |
|
170 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
171 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
171 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
172 | } |
|
172 | } | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void Axis::setShadesBrush(const QBrush& brush) |
|
175 | void Axis::setShadesBrush(const QBrush& brush) | |
176 | { |
|
176 | { | |
177 |
foreach(QGraphicsItem* item , m_shades |
|
177 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
178 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
178 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | void Axis::setShadesPen(const QPen& pen) |
|
182 | void Axis::setShadesPen(const QPen& pen) | |
183 | { |
|
183 | { | |
184 |
foreach(QGraphicsItem* item , m_shades |
|
184 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
185 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
185 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
186 | } |
|
186 | } | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | void Axis::setAxisPen(const QPen& pen) |
|
189 | void Axis::setAxisPen(const QPen& pen) | |
190 | { |
|
190 | { | |
191 |
foreach(QGraphicsItem* item , m_axis |
|
191 | foreach(QGraphicsItem* item , m_axis->childItems()) { | |
192 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
192 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void Axis::setGridPen(const QPen& pen) |
|
196 | void Axis::setGridPen(const QPen& pen) | |
197 | { |
|
197 | { | |
198 |
foreach(QGraphicsItem* item , m_grid |
|
198 | foreach(QGraphicsItem* item , m_grid->childItems()) { | |
199 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
199 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } | |
@@ -246,10 +246,10 void Axis::setLayout(QVector<qreal>& layout) | |||||
246 |
|
246 | |||
247 | QStringList ticksList = createLabels(layout.size(),m_min,m_max); |
|
247 | QStringList ticksList = createLabels(layout.size(),m_min,m_max); | |
248 |
|
248 | |||
249 |
QList<QGraphicsItem *> lines = m_grid |
|
249 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
250 |
QList<QGraphicsItem *> labels = m_labels |
|
250 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
251 |
QList<QGraphicsItem *> shades = m_shades |
|
251 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
252 |
QList<QGraphicsItem *> axis = m_axis |
|
252 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
253 |
|
253 | |||
254 | Q_ASSERT(labels.size() == ticksList.size()); |
|
254 | Q_ASSERT(labels.size() == ticksList.size()); | |
255 | Q_ASSERT(layout.size() == ticksList.size()); |
|
255 | Q_ASSERT(layout.size() == ticksList.size()); |
@@ -73,10 +73,10 private: | |||||
73 | AxisType m_type; |
|
73 | AxisType m_type; | |
74 | QRectF m_rect; |
|
74 | QRectF m_rect; | |
75 | int m_labelsAngle; |
|
75 | int m_labelsAngle; | |
76 | QGraphicsItemGroup m_grid; |
|
76 | QGraphicsItemGroup *m_grid; | |
77 | QGraphicsItemGroup m_shades; |
|
77 | QGraphicsItemGroup *m_shades; | |
78 | QGraphicsItemGroup m_labels; |
|
78 | QGraphicsItemGroup *m_labels; | |
79 | QGraphicsItemGroup m_axis; |
|
79 | QGraphicsItemGroup *m_axis; | |
80 | QVector<qreal> m_layoutVector; |
|
80 | QVector<qreal> m_layoutVector; | |
81 | qreal m_min; |
|
81 | qreal m_min; | |
82 | qreal m_max; |
|
82 | qreal m_max; |
General Comments 0
You need to be logged in to leave comments.
Login now