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