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