@@ -1077,21 +1077,47 void DeclarativeChart::initializeAxes(QAbstractSeries *series) | |||||
1077 |
|
1077 | |||
1078 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) |
|
1078 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) | |
1079 | { |
|
1079 | { | |
|
1080 | qreal min; | |||
|
1081 | qreal max; | |||
1080 | // Initialize axis X |
|
1082 | // Initialize axis X | |
1081 | if (axes->axisX()) |
|
1083 | if (axes->axisX()) { | |
1082 | axes->emitAxisXChanged(); |
|
1084 | axes->emitAxisXChanged(); | |
1083 | else if (axes->axisXTop()) |
|
1085 | } else if (axes->axisXTop()) { | |
1084 | axes->emitAxisXTopChanged(); |
|
1086 | axes->emitAxisXTopChanged(); | |
1085 | else |
|
1087 | } else { | |
1086 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); |
|
1088 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); | |
|
1089 | findMinMaxForSeries(series, Qt::Horizontal, min, max); | |||
|
1090 | axes->axisX()->setRange(min, max); | |||
|
1091 | } | |||
1087 |
|
1092 | |||
1088 | // Initialize axis Y |
|
1093 | // Initialize axis Y | |
1089 | if (axes->axisY()) |
|
1094 | if (axes->axisY()) { | |
1090 | axes->emitAxisYChanged(); |
|
1095 | axes->emitAxisYChanged(); | |
1091 | else if (axes->axisYRight()) |
|
1096 | } else if (axes->axisYRight()) { | |
1092 | axes->emitAxisYRightChanged(); |
|
1097 | axes->emitAxisYRightChanged(); | |
1093 | else |
|
1098 | } else { | |
1094 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); |
|
1099 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); | |
|
1100 | findMinMaxForSeries(series, Qt::Vertical, min, max); | |||
|
1101 | axes->axisY()->setRange(min, max); | |||
|
1102 | } | |||
|
1103 | } | |||
|
1104 | ||||
|
1105 | void DeclarativeChart::findMinMaxForSeries(QAbstractSeries *series, Qt::Orientations orientation, | |||
|
1106 | qreal &min, qreal &max) | |||
|
1107 | { | |||
|
1108 | if (!series) { | |||
|
1109 | min = 0.5; | |||
|
1110 | max = 0.5; | |||
|
1111 | } else { | |||
|
1112 | AbstractDomain *domain = series->d_ptr->domain(); | |||
|
1113 | min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX(); | |||
|
1114 | max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(); | |||
|
1115 | ||||
|
1116 | if (min == max) { | |||
|
1117 | min -= 0.5; | |||
|
1118 | max += 0.5; | |||
|
1119 | } | |||
|
1120 | } | |||
1095 | } |
|
1121 | } | |
1096 |
|
1122 | |||
1097 | QPointF DeclarativeChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
1123 | QPointF DeclarativeChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
@@ -206,6 +206,8 private: | |||||
206 | void initChart(QChart::ChartType type); |
|
206 | void initChart(QChart::ChartType type); | |
207 | void seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis, |
|
207 | void seriesAxisAttachHelper(QAbstractSeries *series, QAbstractAxis *axis, | |
208 | Qt::Orientations orientation, Qt::Alignment alignment); |
|
208 | Qt::Orientations orientation, Qt::Alignment alignment); | |
|
209 | void findMinMaxForSeries(QAbstractSeries *series,Qt::Orientations orientation, | |||
|
210 | qreal &min, qreal &max); | |||
209 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
211 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
210 | // multi inheritance, so we now have a QChart as a member instead |
|
212 | // multi inheritance, so we now have a QChart as a member instead | |
211 | QChart *m_chart; |
|
213 | QChart *m_chart; |
General Comments 0
You need to be logged in to leave comments.
Login now