@@ -375,14 +375,39 void DeclarativeChart::componentComplete() | |||
|
375 | 375 | QQuickItem::componentComplete(); |
|
376 | 376 | } |
|
377 | 377 | |
|
378 | void DeclarativeChart::seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis, | |
|
379 | Qt::Orientations orientation, | |
|
380 | Qt::Alignment alignment) | |
|
381 | { | |
|
382 | if (!series->attachedAxes().contains(axis)) { | |
|
383 | // Remove & delete old axes that are not attached to any other series | |
|
384 | foreach (QAbstractAxis* oldAxis, m_chart->axes(orientation, series)) { | |
|
385 | bool otherAttachments = false; | |
|
386 | if (oldAxis != axis) { | |
|
387 | foreach (QAbstractSeries *oldSeries, m_chart->series()) { | |
|
388 | if (oldSeries != series && oldSeries->attachedAxes().contains(oldAxis)) { | |
|
389 | otherAttachments = true; | |
|
390 | break; | |
|
391 | } | |
|
392 | } | |
|
393 | if (!otherAttachments) { | |
|
394 | m_chart->removeAxis(oldAxis); | |
|
395 | delete oldAxis; | |
|
396 | } | |
|
397 | } | |
|
398 | } | |
|
399 | if (!m_chart->axes(orientation).contains(axis)) | |
|
400 | m_chart->addAxis(axis, alignment); | |
|
401 | ||
|
402 | series->attachAxis(axis); | |
|
403 | } | |
|
404 | } | |
|
405 | ||
|
378 | 406 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
379 | 407 | { |
|
380 | 408 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
381 | 409 | if (axis && s) { |
|
382 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) | |
|
383 | m_chart->setAxisX(axis, s); | |
|
384 | if (!s->attachedAxes().contains(axis)) | |
|
385 | s->attachAxis(axis); | |
|
410 | seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignBottom); | |
|
386 | 411 | } else { |
|
387 | 412 | qWarning() << "Trying to set axisX to null."; |
|
388 | 413 | } |
@@ -392,16 +417,7 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) | |||
|
392 | 417 | { |
|
393 | 418 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
394 | 419 | if (axis && s) { |
|
395 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) { | |
|
396 | QList<QAbstractAxis *> oldAxes = m_chart->axes(Qt::Horizontal, s); | |
|
397 | foreach (QAbstractAxis* a, oldAxes) { | |
|
398 | m_chart->removeAxis(a); | |
|
399 | delete a; | |
|
400 | } | |
|
401 | m_chart->addAxis(axis, Qt::AlignTop); | |
|
402 | } | |
|
403 | if (!s->attachedAxes().contains(axis)) | |
|
404 | s->attachAxis(axis); | |
|
420 | seriesAxisAttachHelper(s, axis, Qt::Horizontal, Qt::AlignTop); | |
|
405 | 421 | } else { |
|
406 | 422 | qWarning() << "Trying to set axisXTop to null."; |
|
407 | 423 | } |
@@ -411,10 +427,7 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) | |||
|
411 | 427 | { |
|
412 | 428 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
413 | 429 | if (axis && s) { |
|
414 | if (!m_chart->axes(Qt::Vertical).contains(axis)) | |
|
415 | m_chart->setAxisY(axis, s); | |
|
416 | if (!s->attachedAxes().contains(axis)) | |
|
417 | s->attachAxis(axis); | |
|
430 | seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignLeft); | |
|
418 | 431 | } else { |
|
419 | 432 | qWarning() << "Trying to set axisY to null."; |
|
420 | 433 | } |
@@ -424,16 +437,7 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) | |||
|
424 | 437 | { |
|
425 | 438 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
426 | 439 | if (axis && s) { |
|
427 | if (!m_chart->axes(Qt::Vertical).contains(axis)) { | |
|
428 | QList<QAbstractAxis *> oldAxes = m_chart->axes((Qt::Vertical), s); | |
|
429 | foreach (QAbstractAxis* a, oldAxes) { | |
|
430 | m_chart->removeAxis(a); | |
|
431 | delete a; | |
|
432 | } | |
|
433 | m_chart->addAxis(axis, Qt::AlignRight); | |
|
434 | } | |
|
435 | if (!s->attachedAxes().contains(axis)) | |
|
436 | s->attachAxis(axis); | |
|
440 | seriesAxisAttachHelper(s, axis, Qt::Vertical, Qt::AlignRight); | |
|
437 | 441 | } else { |
|
438 | 442 | qWarning() << "Trying to set axisYRight to null."; |
|
439 | 443 | } |
@@ -932,13 +936,13 QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstrac | |||
|
932 | 936 | series->setName(name); |
|
933 | 937 | m_chart->addSeries(series); |
|
934 | 938 | |
|
939 | if (!axisX || !axisY) | |
|
940 | initializeAxes(series); | |
|
941 | ||
|
935 | 942 | if (axisX) |
|
936 | 943 | setAxisX(axisX, series); |
|
937 | 944 | if (axisY) |
|
938 | 945 | setAxisY(axisY, series); |
|
939 | ||
|
940 | if (series->attachedAxes().count() < 2) | |
|
941 | initializeAxes(series); | |
|
942 | 946 | } |
|
943 | 947 | |
|
944 | 948 | return series; |
@@ -954,14 +958,14 void DeclarativeChart::removeSeries(QAbstractSeries *series) | |||
|
954 | 958 | |
|
955 | 959 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
956 | 960 | { |
|
957 | if (axis) | |
|
958 | m_chart->setAxisX(axis, series); | |
|
961 | if (axis && series) | |
|
962 | seriesAxisAttachHelper(series, axis, Qt::Horizontal, Qt::AlignBottom); | |
|
959 | 963 | } |
|
960 | 964 | |
|
961 | 965 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
962 | 966 | { |
|
963 | if (axis) | |
|
964 | m_chart->setAxisY(axis, series); | |
|
967 | if (axis && series) | |
|
968 | seriesAxisAttachHelper(series, axis, Qt::Vertical, Qt::AlignLeft); | |
|
965 | 969 | } |
|
966 | 970 | |
|
967 | 971 | void DeclarativeChart::createDefaultAxes() |
@@ -208,6 +208,8 protected: | |||
|
208 | 208 | |
|
209 | 209 | private: |
|
210 | 210 | void initChart(QChart::ChartType type); |
|
211 | void seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis, | |
|
212 | Qt::Orientations orientation, Qt::Alignment alignment); | |
|
211 | 213 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
212 | 214 | // multi inheritance, so we now have a QChart as a member instead |
|
213 | 215 | QChart *m_chart; |
General Comments 0
You need to be logged in to leave comments.
Login now