159 btnRestart->setVisible(visible); |
159 btnRestart->setVisible(visible); |
160 } |
160 } |
161 |
161 |
162 void PageGameStats::renderStats() |
162 void PageGameStats::renderStats() |
163 { |
163 { |
164 graphic->show(); |
|
165 labelGraphTitle-> show(); |
|
166 if(defaultGraphTitle) { |
164 if(defaultGraphTitle) { |
167 labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>"); |
165 labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>"); |
168 } else { |
166 } else { |
169 defaultGraphTitle = true; |
167 defaultGraphTitle = true; |
170 } |
168 } |
175 } else { |
173 } else { |
176 graphic->setScene(Q_NULLPTR); |
174 graphic->setScene(Q_NULLPTR); |
177 m_scene.reset(new QGraphicsScene(this)); |
175 m_scene.reset(new QGraphicsScene(this)); |
178 |
176 |
179 quint32 maxValue = 0; |
177 quint32 maxValue = 0; |
180 int maxSize = 0; |
178 int maxDataPoints = 0; |
181 for(QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); i != healthPoints.constEnd(); ++i) |
179 for(QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); i != healthPoints.constEnd(); ++i) |
182 { |
180 { |
183 maxSize = qMax(maxSize, i.value().size()); |
181 maxDataPoints = qMax(maxDataPoints, i.value().size()); |
184 |
182 } |
185 foreach (quint32 v, i.value()) |
183 |
186 maxValue = qMax(maxValue, v); |
184 /* There must be at least 2 data points for any clan, |
187 } |
185 otherwise there's not much to look at. ;-) */ |
188 |
186 if(maxDataPoints < 2) { |
189 if(maxSize < 2) |
187 labelGraphTitle->hide(); |
190 return; |
188 graphic->hide(); |
|
189 return; |
|
190 } |
191 |
191 |
192 QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); |
192 QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); |
193 while (i != healthPoints.constEnd()) |
193 while (i != healthPoints.constEnd()) |
194 { |
194 { |
195 quint32 c = i.key(); |
195 quint32 c = i.key(); |
196 //QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); |
|
197 const QVector<quint32>& hps = i.value(); |
196 const QVector<quint32>& hps = i.value(); |
198 |
197 |
199 QPainterPath path; |
198 QPainterPath path; |
|
199 |
200 if (hps.size()) |
200 if (hps.size()) |
201 path.moveTo(0, hps[0]); |
201 path.moveTo(0, hps[0]); |
202 |
202 |
203 for(int t = 1; t < hps.size(); ++t) |
203 for(int t = 0; t < hps.size(); ++t) { |
204 path.lineTo(t * maxValue / (maxSize - 1), hps[t]); |
204 path.lineTo(t, hps[t]); |
|
205 maxValue = qMax(maxValue, hps[t]); |
|
206 } |
205 |
207 |
206 QPen pen(c); |
208 QPen pen(c); |
207 pen.setWidth(2); |
209 pen.setWidth(2); |
208 pen.setCosmetic(true); |
210 pen.setCosmetic(true); |
209 |
211 |
210 m_scene->addPath(path, pen); |
212 m_scene->addPath(path, pen); |
211 ++i; |
213 ++i; |
212 } |
214 } |
213 |
215 |
214 graphic->setScene(m_scene.data()); |
216 graphic->setScene(m_scene.data()); |
|
217 graphic->setSceneRect(0, 0, maxDataPoints-1, qMax(maxValue, (quint32) 1)); |
215 graphic->fitInView(graphic->sceneRect()); |
218 graphic->fitInView(graphic->sceneRect()); |
|
219 |
|
220 graphic->show(); |
|
221 labelGraphTitle->show(); |
216 } |
222 } |
217 } |
223 } |
218 |
224 |
219 void PageGameStats::GameStats(char type, const QString & info) |
225 void PageGameStats::GameStats(char type, const QString & info) |
220 { |
226 { |