| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses |
| 5 | |
| 6 | #include "declarativebarseries_p.h" |
| 7 | #include <QtCharts/QBarSet> |
| 8 | #include <QtCharts/QVBarModelMapper> |
| 9 | #include <QtCharts/QHBarModelMapper> |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : QBarSet(QString(), parent) |
| 14 | { |
| 15 | connect(sender: this, SIGNAL(valuesAdded(int,int)), receiver: this, SLOT(handleCountChanged(int,int))); |
| 16 | connect(sender: this, SIGNAL(valuesRemoved(int,int)), receiver: this, SLOT(handleCountChanged(int,int))); |
| 17 | connect(sender: this, SIGNAL(brushChanged()), receiver: this, SLOT(handleBrushChanged())); |
| 18 | } |
| 19 | |
| 20 | void DeclarativeBarSet::handleCountChanged(int index, int count) |
| 21 | { |
| 22 | Q_UNUSED(index); |
| 23 | Q_UNUSED(count); |
| 24 | emit countChanged(count: QBarSet::count()); |
| 25 | } |
| 26 | |
| 27 | qreal DeclarativeBarSet::borderWidth() const |
| 28 | { |
| 29 | return pen().widthF(); |
| 30 | } |
| 31 | |
| 32 | void DeclarativeBarSet::setBorderWidth(qreal width) |
| 33 | { |
| 34 | if (width != pen().widthF()) { |
| 35 | QPen p = pen(); |
| 36 | p.setWidthF(width); |
| 37 | setPen(p); |
| 38 | emit borderWidthChanged(width); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | QVariantList DeclarativeBarSet::values() |
| 43 | { |
| 44 | QVariantList values; |
| 45 | for (int i(0); i < count(); i++) |
| 46 | values.append(t: QVariant(QBarSet::at(index: i))); |
| 47 | return values; |
| 48 | } |
| 49 | |
| 50 | void DeclarativeBarSet::setValues(QVariantList values) |
| 51 | { |
| 52 | while (count()) |
| 53 | remove(index: count() - 1); |
| 54 | |
| 55 | if (values.size() > 0 && values.at(i: 0).canConvert<QPoint>()) { |
| 56 | // Create list of values for appending if the first item is Qt.point |
| 57 | int maxValue = 0; |
| 58 | for (int i = 0; i < values.size(); i++) { |
| 59 | if (values.at(i).canConvert<QPoint>() && |
| 60 | values.at(i).toPoint().x() > maxValue) { |
| 61 | maxValue = values.at(i).toPoint().x(); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | QList<qreal> indexValueList; |
| 66 | indexValueList.resize(size: maxValue + 1); |
| 67 | |
| 68 | for (int i = 0; i < values.size(); i++) { |
| 69 | if (values.at(i).canConvert<QPoint>()) { |
| 70 | indexValueList.replace(i: values.at(i).toPoint().x(), t: values.at(i).toPointF().y()); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | for (int i = 0; i < indexValueList.size(); i++) |
| 75 | QBarSet::append(value: indexValueList.at(i)); |
| 76 | |
| 77 | } else { |
| 78 | for (int i(0); i < values.size(); i++) { |
| 79 | if (values.at(i).canConvert<double>()) |
| 80 | QBarSet::append(value: values[i].toDouble()); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | QString DeclarativeBarSet::brushFilename() const |
| 86 | { |
| 87 | return m_brushFilename; |
| 88 | } |
| 89 | |
| 90 | void DeclarativeBarSet::setBrushFilename(const QString &brushFilename) |
| 91 | { |
| 92 | QImage brushImage(brushFilename); |
| 93 | if (QBarSet::brush().textureImage() != brushImage) { |
| 94 | QBrush brush = QBarSet::brush(); |
| 95 | brush.setTextureImage(brushImage); |
| 96 | QBarSet::setBrush(brush); |
| 97 | m_brushFilename = brushFilename; |
| 98 | m_brushImage = brushImage; |
| 99 | emit brushFilenameChanged(brushFilename); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void DeclarativeBarSet::handleBrushChanged() |
| 104 | { |
| 105 | // If the texture image of the brush has changed along the brush |
| 106 | // the brush file name needs to be cleared. |
| 107 | if (!m_brushFilename.isEmpty() && QBarSet::brush().textureImage() != m_brushImage) { |
| 108 | m_brushFilename.clear(); |
| 109 | emit brushFilenameChanged(brushFilename: QString()); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // Declarative bar series ====================================================================================== |
| 114 | DeclarativeBarSeries::DeclarativeBarSeries(QQuickItem *parent) : |
| 115 | QBarSeries(parent), |
| 116 | m_axes(new DeclarativeAxes(this)) |
| 117 | { |
| 118 | connect(sender: m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXChanged(QAbstractAxis*))); |
| 119 | connect(sender: m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYChanged(QAbstractAxis*))); |
| 120 | connect(sender: m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
| 121 | connect(sender: m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
| 122 | } |
| 123 | |
| 124 | void DeclarativeBarSeries::classBegin() |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | void DeclarativeBarSeries::componentComplete() |
| 129 | { |
| 130 | foreach (QObject *child, children()) { |
| 131 | if (qobject_cast<DeclarativeBarSet *>(object: child)) { |
| 132 | QAbstractBarSeries::append(set: qobject_cast<DeclarativeBarSet *>(object: child)); |
| 133 | } else if (qobject_cast<QVBarModelMapper *>(object: child)) { |
| 134 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(object: child); |
| 135 | mapper->setSeries(this); |
| 136 | } else if (qobject_cast<QHBarModelMapper *>(object: child)) { |
| 137 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(object: child); |
| 138 | mapper->setSeries(this); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | QQmlListProperty<QObject> DeclarativeBarSeries::seriesChildren() |
| 144 | { |
| 145 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
| 146 | } |
| 147 | |
| 148 | void DeclarativeBarSeries::appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element) |
| 149 | { |
| 150 | // Empty implementation; the children are parsed in componentComplete instead |
| 151 | Q_UNUSED(list); |
| 152 | Q_UNUSED(element); |
| 153 | } |
| 154 | |
| 155 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) |
| 156 | { |
| 157 | QList<QBarSet *> setList = barSets(); |
| 158 | if (index >= 0 && index < setList.size()) |
| 159 | return qobject_cast<DeclarativeBarSet *>(object: setList[index]); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) |
| 165 | { |
| 166 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
| 167 | barset->setLabel(label); |
| 168 | barset->setValues(values); |
| 169 | if (QBarSeries::insert(index, set: barset)) |
| 170 | return barset; |
| 171 | delete barset; |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | // Declarative stacked bar series ============================================================================== |
| 176 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QQuickItem *parent) : |
| 177 | QStackedBarSeries(parent), |
| 178 | m_axes(0) |
| 179 | { |
| 180 | m_axes = new DeclarativeAxes(this); |
| 181 | connect(sender: m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXChanged(QAbstractAxis*))); |
| 182 | connect(sender: m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYChanged(QAbstractAxis*))); |
| 183 | connect(sender: m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
| 184 | connect(sender: m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
| 185 | } |
| 186 | |
| 187 | void DeclarativeStackedBarSeries::classBegin() |
| 188 | { |
| 189 | } |
| 190 | |
| 191 | void DeclarativeStackedBarSeries::componentComplete() |
| 192 | { |
| 193 | foreach (QObject *child, children()) { |
| 194 | if (qobject_cast<DeclarativeBarSet *>(object: child)) { |
| 195 | QAbstractBarSeries::append(set: qobject_cast<DeclarativeBarSet *>(object: child)); |
| 196 | } else if (qobject_cast<QVBarModelMapper *>(object: child)) { |
| 197 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(object: child); |
| 198 | mapper->setSeries(this); |
| 199 | } else if (qobject_cast<QHBarModelMapper *>(object: child)) { |
| 200 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(object: child); |
| 201 | mapper->setSeries(this); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | |
| 207 | QQmlListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() |
| 208 | { |
| 209 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
| 210 | } |
| 211 | |
| 212 | void DeclarativeStackedBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
| 213 | { |
| 214 | // Empty implementation; the children are parsed in componentComplete instead |
| 215 | Q_UNUSED(list); |
| 216 | Q_UNUSED(element); |
| 217 | } |
| 218 | |
| 219 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) |
| 220 | { |
| 221 | QList<QBarSet *> setList = barSets(); |
| 222 | if (index >= 0 && index < setList.size()) |
| 223 | return qobject_cast<DeclarativeBarSet *>(object: setList[index]); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) |
| 229 | { |
| 230 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
| 231 | barset->setLabel(label); |
| 232 | barset->setValues(values); |
| 233 | if (QStackedBarSeries::insert(index, set: barset)) |
| 234 | return barset; |
| 235 | delete barset; |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | // Declarative percent bar series ============================================================================== |
| 240 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QQuickItem *parent) : |
| 241 | QPercentBarSeries(parent), |
| 242 | m_axes(0) |
| 243 | { |
| 244 | m_axes = new DeclarativeAxes(this); |
| 245 | connect(sender: m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXChanged(QAbstractAxis*))); |
| 246 | connect(sender: m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYChanged(QAbstractAxis*))); |
| 247 | connect(sender: m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
| 248 | connect(sender: m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
| 249 | } |
| 250 | |
| 251 | void DeclarativePercentBarSeries::classBegin() |
| 252 | { |
| 253 | } |
| 254 | |
| 255 | void DeclarativePercentBarSeries::componentComplete() |
| 256 | { |
| 257 | foreach (QObject *child, children()) { |
| 258 | if (qobject_cast<DeclarativeBarSet *>(object: child)) { |
| 259 | QAbstractBarSeries::append(set: qobject_cast<DeclarativeBarSet *>(object: child)); |
| 260 | } else if (qobject_cast<QVBarModelMapper *>(object: child)) { |
| 261 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(object: child); |
| 262 | mapper->setSeries(this); |
| 263 | } else if (qobject_cast<QHBarModelMapper *>(object: child)) { |
| 264 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(object: child); |
| 265 | mapper->setSeries(this); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | QQmlListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() |
| 271 | { |
| 272 | return QQmlListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren ,0,0,0); |
| 273 | } |
| 274 | |
| 275 | void DeclarativePercentBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
| 276 | { |
| 277 | // Empty implementation; the children are parsed in componentComplete instead |
| 278 | Q_UNUSED(list); |
| 279 | Q_UNUSED(element); |
| 280 | } |
| 281 | |
| 282 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) |
| 283 | { |
| 284 | QList<QBarSet *> setList = barSets(); |
| 285 | if (index >= 0 && index < setList.size()) |
| 286 | return qobject_cast<DeclarativeBarSet *>(object: setList[index]); |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) |
| 292 | { |
| 293 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
| 294 | barset->setLabel(label); |
| 295 | barset->setValues(values); |
| 296 | if (QPercentBarSeries::insert(index, set: barset)) |
| 297 | return barset; |
| 298 | delete barset; |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | // Declarative horizontal bar series =========================================================================== |
| 303 | DeclarativeHorizontalBarSeries::DeclarativeHorizontalBarSeries(QQuickItem *parent) : |
| 304 | QHorizontalBarSeries(parent), |
| 305 | m_axes(0) |
| 306 | { |
| 307 | m_axes = new DeclarativeAxes(this); |
| 308 | connect(sender: m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXChanged(QAbstractAxis*))); |
| 309 | connect(sender: m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYChanged(QAbstractAxis*))); |
| 310 | connect(sender: m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
| 311 | connect(sender: m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
| 312 | } |
| 313 | |
| 314 | void DeclarativeHorizontalBarSeries::classBegin() |
| 315 | { |
| 316 | } |
| 317 | |
| 318 | void DeclarativeHorizontalBarSeries::componentComplete() |
| 319 | { |
| 320 | foreach (QObject *child, children()) { |
| 321 | if (qobject_cast<DeclarativeBarSet *>(object: child)) { |
| 322 | QAbstractBarSeries::append(set: qobject_cast<DeclarativeBarSet *>(object: child)); |
| 323 | } else if (qobject_cast<QVBarModelMapper *>(object: child)) { |
| 324 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(object: child); |
| 325 | mapper->setSeries(this); |
| 326 | } else if (qobject_cast<QHBarModelMapper *>(object: child)) { |
| 327 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(object: child); |
| 328 | mapper->setSeries(this); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | QQmlListProperty<QObject> DeclarativeHorizontalBarSeries::seriesChildren() |
| 334 | { |
| 335 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalBarSeries::appendSeriesChildren ,0,0,0); |
| 336 | } |
| 337 | |
| 338 | void DeclarativeHorizontalBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
| 339 | { |
| 340 | // Empty implementation; the children are parsed in componentComplete instead |
| 341 | Q_UNUSED(list); |
| 342 | Q_UNUSED(element); |
| 343 | } |
| 344 | |
| 345 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::at(int index) |
| 346 | { |
| 347 | QList<QBarSet *> setList = barSets(); |
| 348 | if (index >= 0 && index < setList.size()) |
| 349 | return qobject_cast<DeclarativeBarSet *>(object: setList[index]); |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | DeclarativeBarSet *DeclarativeHorizontalBarSeries::insert(int index, QString label, QVariantList values) |
| 355 | { |
| 356 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
| 357 | barset->setLabel(label); |
| 358 | barset->setValues(values); |
| 359 | if (QHorizontalBarSeries::insert(index, set: barset)) |
| 360 | return barset; |
| 361 | delete barset; |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | // Declarative horizontal stacked bar series =================================================================== |
| 366 | DeclarativeHorizontalStackedBarSeries::DeclarativeHorizontalStackedBarSeries(QQuickItem *parent) : |
| 367 | QHorizontalStackedBarSeries(parent), |
| 368 | m_axes(0) |
| 369 | { |
| 370 | m_axes = new DeclarativeAxes(this); |
| 371 | connect(sender: m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXChanged(QAbstractAxis*))); |
| 372 | connect(sender: m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYChanged(QAbstractAxis*))); |
| 373 | connect(sender: m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
| 374 | connect(sender: m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
| 375 | } |
| 376 | |
| 377 | void DeclarativeHorizontalStackedBarSeries::classBegin() |
| 378 | { |
| 379 | } |
| 380 | |
| 381 | void DeclarativeHorizontalStackedBarSeries::componentComplete() |
| 382 | { |
| 383 | foreach (QObject *child, children()) { |
| 384 | if (qobject_cast<DeclarativeBarSet *>(object: child)) { |
| 385 | QAbstractBarSeries::append(set: qobject_cast<DeclarativeBarSet *>(object: child)); |
| 386 | } else if (qobject_cast<QVBarModelMapper *>(object: child)) { |
| 387 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(object: child); |
| 388 | mapper->setSeries(this); |
| 389 | } else if (qobject_cast<QHBarModelMapper *>(object: child)) { |
| 390 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(object: child); |
| 391 | mapper->setSeries(this); |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | QQmlListProperty<QObject> DeclarativeHorizontalStackedBarSeries::seriesChildren() |
| 397 | { |
| 398 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalStackedBarSeries::appendSeriesChildren ,0,0,0); |
| 399 | } |
| 400 | |
| 401 | void DeclarativeHorizontalStackedBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
| 402 | { |
| 403 | // Empty implementation; the children are parsed in componentComplete instead |
| 404 | Q_UNUSED(list); |
| 405 | Q_UNUSED(element); |
| 406 | } |
| 407 | |
| 408 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::at(int index) |
| 409 | { |
| 410 | QList<QBarSet *> setList = barSets(); |
| 411 | if (index >= 0 && index < setList.size()) |
| 412 | return qobject_cast<DeclarativeBarSet *>(object: setList[index]); |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | DeclarativeBarSet *DeclarativeHorizontalStackedBarSeries::insert(int index, QString label, QVariantList values) |
| 418 | { |
| 419 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
| 420 | barset->setLabel(label); |
| 421 | barset->setValues(values); |
| 422 | if (QHorizontalStackedBarSeries::insert(index, set: barset)) |
| 423 | return barset; |
| 424 | delete barset; |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | // Declarative horizontal percent bar series =================================================================== |
| 429 | DeclarativeHorizontalPercentBarSeries::DeclarativeHorizontalPercentBarSeries(QQuickItem *parent) : |
| 430 | QHorizontalPercentBarSeries(parent), |
| 431 | m_axes(0) |
| 432 | { |
| 433 | m_axes = new DeclarativeAxes(this); |
| 434 | connect(sender: m_axes, SIGNAL(axisXChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXChanged(QAbstractAxis*))); |
| 435 | connect(sender: m_axes, SIGNAL(axisYChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYChanged(QAbstractAxis*))); |
| 436 | connect(sender: m_axes, SIGNAL(axisXTopChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisXTopChanged(QAbstractAxis*))); |
| 437 | connect(sender: m_axes, SIGNAL(axisYRightChanged(QAbstractAxis*)), receiver: this, SIGNAL(axisYRightChanged(QAbstractAxis*))); |
| 438 | } |
| 439 | |
| 440 | void DeclarativeHorizontalPercentBarSeries::classBegin() |
| 441 | { |
| 442 | } |
| 443 | |
| 444 | void DeclarativeHorizontalPercentBarSeries::componentComplete() |
| 445 | { |
| 446 | foreach (QObject *child, children()) { |
| 447 | if (qobject_cast<DeclarativeBarSet *>(object: child)) { |
| 448 | QAbstractBarSeries::append(set: qobject_cast<DeclarativeBarSet *>(object: child)); |
| 449 | } else if (qobject_cast<QVBarModelMapper *>(object: child)) { |
| 450 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(object: child); |
| 451 | mapper->setSeries(this); |
| 452 | } else if (qobject_cast<QHBarModelMapper *>(object: child)) { |
| 453 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(object: child); |
| 454 | mapper->setSeries(this); |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | QQmlListProperty<QObject> DeclarativeHorizontalPercentBarSeries::seriesChildren() |
| 460 | { |
| 461 | return QQmlListProperty<QObject>(this, 0, &DeclarativeHorizontalPercentBarSeries::appendSeriesChildren ,0,0,0); |
| 462 | } |
| 463 | |
| 464 | void DeclarativeHorizontalPercentBarSeries::appendSeriesChildren(QQmlListProperty<QObject> * list, QObject *element) |
| 465 | { |
| 466 | // Empty implementation; the children are parsed in componentComplete instead |
| 467 | Q_UNUSED(list); |
| 468 | Q_UNUSED(element); |
| 469 | } |
| 470 | |
| 471 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::at(int index) |
| 472 | { |
| 473 | QList<QBarSet *> setList = barSets(); |
| 474 | if (index >= 0 && index < setList.size()) |
| 475 | return qobject_cast<DeclarativeBarSet *>(object: setList[index]); |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | DeclarativeBarSet *DeclarativeHorizontalPercentBarSeries::insert(int index, QString label, QVariantList values) |
| 481 | { |
| 482 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
| 483 | barset->setLabel(label); |
| 484 | barset->setValues(values); |
| 485 | if (QHorizontalPercentBarSeries::insert(index, set: barset)) |
| 486 | return barset; |
| 487 | delete barset; |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | QT_END_NAMESPACE |
| 492 | |
| 493 | #include "moc_declarativebarseries_p.cpp" |
| 494 | |