##// END OF EJS Templates
QCategoryAxis renamed some methods names according to review
Marek Rosa -
r1829:df98ed9e54fb
parent child
Show More
@@ -41,7 +41,7 ChartCategoryAxisX::~ChartCategoryAxisX()
41 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
41 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
42 {
42 {
43 QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis);
43 QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis);
44 int tickCount = axis->intervalsLabels().count() + 1;
44 int tickCount = axis->categoriesLabels().count() + 1;
45 QVector<qreal> points;
45 QVector<qreal> points;
46
46
47 if (tickCount < 2)
47 if (tickCount < 2)
@@ -52,10 +52,10 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
52 qreal scale = m_rect.width() / axis->max();
52 qreal scale = m_rect.width() / axis->max();
53 for (int i = 0; i < tickCount; ++i)
53 for (int i = 0; i < tickCount; ++i)
54 if (i < tickCount - 1) {
54 if (i < tickCount - 1) {
55 int x = axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.left();
55 int x = axis->categoryStart(axis->categoriesLabels().at(i)) * scale + m_rect.left();
56 points[i] = x;
56 points[i] = x;
57 } else {
57 } else {
58 int x = axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.left();
58 int x = axis->categoryEnd(axis->categoriesLabels().at(i - 1)) * scale + m_rect.left();
59 points[i] = x;
59 points[i] = x;
60 }
60 }
61
61
@@ -73,7 +73,7 void ChartCategoryAxisX::updateGeometry()
73
73
74 QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis);
74 QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis);
75
75
76 QStringList ticksList = intervalAxis->intervalsLabels();
76 QStringList ticksList = intervalAxis->categoriesLabels();
77
77
78 // createNumberLabels(ticksList,m_min,m_max,layout.size());
78 // createNumberLabels(ticksList,m_min,m_max,layout.size());
79
79
@@ -42,7 +42,7 ChartCategoryAxisY::~ChartCategoryAxisY()
42 QVector<qreal> ChartCategoryAxisY::calculateLayout() const
42 QVector<qreal> ChartCategoryAxisY::calculateLayout() const
43 {
43 {
44 QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis);
44 QCategoryAxis *axis = qobject_cast<QCategoryAxis *>(m_chartAxis);
45 int tickCount = axis->intervalsLabels().count() + 1;
45 int tickCount = axis->categoriesLabels().count() + 1;
46 QVector<qreal> points;
46 QVector<qreal> points;
47
47
48 if (tickCount < 2)
48 if (tickCount < 2)
@@ -53,10 +53,10 QVector<qreal> ChartCategoryAxisY::calculateLayout() const
53 qreal scale = m_rect.height() / axis->max();
53 qreal scale = m_rect.height() / axis->max();
54 for (int i = 0; i < tickCount; ++i)
54 for (int i = 0; i < tickCount; ++i)
55 if (i < tickCount - 1) {
55 if (i < tickCount - 1) {
56 int y = -axis->intervalMin(axis->intervalsLabels().at(i)) * scale + m_rect.bottom();
56 int y = -axis->categoryStart(axis->categoriesLabels().at(i)) * scale + m_rect.bottom();
57 points[i] = y;
57 points[i] = y;
58 } else {
58 } else {
59 int y = -axis->intervalMax(axis->intervalsLabels().at(i - 1)) * scale + m_rect.bottom();
59 int y = -axis->categoryEnd(axis->categoriesLabels().at(i - 1)) * scale + m_rect.bottom();
60 points[i] = y;
60 points[i] = y;
61 }
61 }
62
62
@@ -73,7 +73,7 void ChartCategoryAxisY::updateGeometry()
73
73
74 QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis);
74 QCategoryAxis *intervalAxis = qobject_cast<QCategoryAxis *>(m_chartAxis);
75
75
76 QStringList ticksList = intervalAxis->intervalsLabels();
76 QStringList ticksList = intervalAxis->categoriesLabels();
77
77
78 QList<QGraphicsItem *> lines = m_grid->childItems();
78 QList<QGraphicsItem *> lines = m_grid->childItems();
79 QList<QGraphicsItem *> labels = m_labels->childItems();
79 QList<QGraphicsItem *> labels = m_labels->childItems();
@@ -65,87 +65,87 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis
65 }
65 }
66
66
67 /*!
67 /*!
68 Appends new interval to the axis with an \a intervalLabel.
68 Appends new category to the axis with an \a categoryLabel.
69 Interval label has to be unique.
69 Category label has to be unique.
70 Parameter \a intervalEnd specifies the high end limit of the interval.
70 Parameter \a categoryHighEnd specifies the high end limit of the category.
71 It has to be greater than the high end limit of the previous interval.
71 It has to be greater than the high end limit of the previous category.
72 Otherwise the method returns without adding a new interval.
72 Otherwise the method returns without adding a new category.
73 */
73 */
74 void QCategoryAxis::append(const QString& intervalLabel, qreal intervalEnd)
74 void QCategoryAxis::append(const QString& categoryLabel, qreal categoryHighEnd)
75 {
75 {
76 Q_D(QCategoryAxis);
76 Q_D(QCategoryAxis);
77
77
78 if (!d->m_intervals.contains(intervalLabel))
78 if (!d->m_categories.contains(categoryLabel))
79 {
79 {
80 if(d->m_intervals.isEmpty()){
80 if(d->m_categories.isEmpty()){
81 Range range(d->m_categoryMinimum, intervalEnd);
81 Range range(d->m_categoryMinimum, categoryHighEnd);
82 d->m_intervalsMap.insert(intervalLabel, range);
82 d->m_categoriesMap.insert(categoryLabel, range);
83 d->m_intervals.append(intervalLabel);
83 d->m_categories.append(categoryLabel);
84 }else if (intervalEnd > intervalMax(d->m_intervals.last())){
84 }else if (categoryHighEnd > categoryEnd(d->m_categories.last())){
85 Range range = d->m_intervalsMap.value(d->m_intervals.last());
85 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
86 d->m_intervalsMap.insert(intervalLabel, Range(range.second, intervalEnd));
86 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryHighEnd));
87 d->m_intervals.append(intervalLabel);
87 d->m_categories.append(categoryLabel);
88 }
88 }
89 }
89 }
90 }
90 }
91
91
92 /*!
92 /*!
93 Sets to \a min the low end limit of the first interval on the axis.
93 Sets to \a min the low end limit of the first category on the axis.
94 */
94 */
95 void QCategoryAxis::setFisrtIntervalMinimum(qreal min)
95 void QCategoryAxis::setStartValue(qreal min)
96 {
96 {
97 Q_D(QCategoryAxis);
97 Q_D(QCategoryAxis);
98 if(d->m_intervals.isEmpty()){
98 if(d->m_categories.isEmpty()){
99 d->m_categoryMinimum = min;
99 d->m_categoryMinimum = min;
100 }else{
100 }else{
101 Range range = d->m_intervalsMap.value(d->m_intervals.first());
101 Range range = d->m_categoriesMap.value(d->m_categories.first());
102 d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
102 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
103 }
103 }
104 }
104 }
105
105
106 /*!
106 /*!
107 Returns the low end limit of the interval specified by an \a intervalLabel
107 Returns the low end limit of the category specified by an \a categoryLabel
108 */
108 */
109 qreal QCategoryAxis::intervalMin(const QString& intervalLabel) const
109 qreal QCategoryAxis::categoryStart(const QString& categoryLabel) const
110 {
110 {
111 Q_D(const QCategoryAxis);
111 Q_D(const QCategoryAxis);
112 return d->m_intervalsMap.value(intervalLabel).first;
112 return d->m_categoriesMap.value(categoryLabel).first;
113 }
113 }
114
114
115 /*!
115 /*!
116 Returns the high end limit of the interval specified by an \a intervalLabel
116 Returns the high end limit of the interval specified by an \a categoryLabel
117 */
117 */
118 qreal QCategoryAxis::intervalMax(const QString& intervalLabel) const
118 qreal QCategoryAxis::categoryEnd(const QString& categoryLabel) const
119 {
119 {
120 Q_D(const QCategoryAxis);
120 Q_D(const QCategoryAxis);
121 return d->m_intervalsMap.value(intervalLabel).second;
121 return d->m_categoriesMap.value(categoryLabel).second;
122 }
122 }
123
123
124 /*!
124 /*!
125 Removes an interval specified by the \a intervalLabel from the axis
125 Removes an interval specified by the \a categoryLabel from the axis
126 */
126 */
127 void QCategoryAxis::remove(const QString &intervalLabel)
127 void QCategoryAxis::remove(const QString &categoryLabel)
128 {
128 {
129 Q_D(QCategoryAxis);
129 Q_D(QCategoryAxis);
130 int labelIndex = d->m_intervals.indexOf(intervalLabel);
130 int labelIndex = d->m_categories.indexOf(categoryLabel);
131
131
132 // check if such label exists
132 // check if such label exists
133 if (labelIndex != -1) {
133 if (labelIndex != -1) {
134 d->m_intervals.removeAt(labelIndex);
134 d->m_categories.removeAt(labelIndex);
135 d->m_intervalsMap.remove(intervalLabel);
135 d->m_categoriesMap.remove(categoryLabel);
136
136
137 // the range of the interval that follows (if exists) needs to be updated
137 // the range of the interval that follows (if exists) needs to be updated
138 if (labelIndex < d->m_intervals.count()) {
138 if (labelIndex < d->m_categories.count()) {
139 QString label = d->m_intervals.at(labelIndex);
139 QString label = d->m_categories.at(labelIndex);
140 Range range = d->m_intervalsMap.value(label);
140 Range range = d->m_categoriesMap.value(label);
141
141
142 // set the range
142 // set the range
143 if (labelIndex == 0) {
143 if (labelIndex == 0) {
144 range.first = d->m_categoryMinimum;
144 range.first = d->m_categoryMinimum;
145 d->m_intervalsMap.insert(label, range);
145 d->m_categoriesMap.insert(label, range);
146 } else {
146 } else {
147 range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
147 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
148 d->m_intervalsMap.insert(label, range);
148 d->m_categoriesMap.insert(label, range);
149 }
149 }
150 }
150 }
151 d->emitUpdated();
151 d->emitUpdated();
@@ -153,20 +153,20 void QCategoryAxis::remove(const QString &intervalLabel)
153 }
153 }
154
154
155 /*!
155 /*!
156 Replaces \a oldLabel of an existing interval with a \a newLabel
156 Replaces \a oldLabel of an existing category with a \a newLabel
157 If the old label does not exist the method returns without making any changes.
157 If the old label does not exist the method returns without making any changes.
158 */
158 */
159 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
159 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
160 {
160 {
161 Q_D(QCategoryAxis);
161 Q_D(QCategoryAxis);
162 int labelIndex = d->m_intervals.indexOf(oldLabel);
162 int labelIndex = d->m_categories.indexOf(oldLabel);
163
163
164 // check if such label exists
164 // check if such label exists
165 if (labelIndex != -1) {
165 if (labelIndex != -1) {
166 d->m_intervals.replace(labelIndex, newLabel);
166 d->m_categories.replace(labelIndex, newLabel);
167 Range range = d->m_intervalsMap.value(oldLabel);
167 Range range = d->m_categoriesMap.value(oldLabel);
168 d->m_intervalsMap.remove(oldLabel);
168 d->m_categoriesMap.remove(oldLabel);
169 d->m_intervalsMap.insert(newLabel, range);
169 d->m_categoriesMap.insert(newLabel, range);
170 d->emitUpdated();
170 d->emitUpdated();
171 }
171 }
172
172
@@ -175,10 +175,10 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabe
175 /*!
175 /*!
176 Returns the list of the intervals labels
176 Returns the list of the intervals labels
177 */
177 */
178 QStringList QCategoryAxis::intervalsLabels()
178 QStringList QCategoryAxis::categoriesLabels()
179 {
179 {
180 Q_D(QCategoryAxis);
180 Q_D(QCategoryAxis);
181 return d->m_intervals;
181 return d->m_categories;
182 }
182 }
183
183
184 /*!
184 /*!
@@ -187,7 +187,7 QStringList QCategoryAxis::intervalsLabels()
187 int QCategoryAxis::count() const
187 int QCategoryAxis::count() const
188 {
188 {
189 Q_D(const QCategoryAxis);
189 Q_D(const QCategoryAxis);
190 return d->m_intervals.count();
190 return d->m_categories.count();
191 }
191 }
192
192
193 /*!
193 /*!
@@ -214,7 +214,7 QCategoryAxisPrivate::~QCategoryAxisPrivate()
214
214
215 int QCategoryAxisPrivate::ticksCount() const
215 int QCategoryAxisPrivate::ticksCount() const
216 {
216 {
217 return m_intervals.count() + 1;
217 return m_categories.count() + 1;
218 }
218 }
219
219
220 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
220 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
@@ -42,16 +42,16 protected:
42 public:
42 public:
43 AxisType type() const;
43 AxisType type() const;
44
44
45 void append(const QString& label, qreal intervalEnd);
45 void append(const QString& label, qreal categoryHighEnd);
46 void remove(const QString& label);
46 void remove(const QString& label);
47 void replaceLabel(const QString& oldLabel, const QString& newLabel);
47 void replaceLabel(const QString& oldLabel, const QString& newLabel);
48
48
49 void setFisrtIntervalMinimum(qreal min);
49 void setStartValue(qreal min);
50
50
51 qreal intervalMin(const QString& intervalLabel) const;
51 qreal categoryStart(const QString& categoryLabel) const;
52 qreal intervalMax(const QString& intervalLabel) const;
52 qreal categoryEnd(const QString& categoryLabel) const;
53
53
54 QStringList intervalsLabels();
54 QStringList categoriesLabels();
55 int count() const;
55 int count() const;
56
56
57
57
@@ -57,8 +57,8 public Q_SLOTS:
57 void handleAxisRangeChanged(qreal min, qreal max,int count);
57 void handleAxisRangeChanged(qreal min, qreal max,int count);
58
58
59 private:
59 private:
60 QMap<QString , Range> m_intervalsMap;
60 QMap<QString , Range> m_categoriesMap;
61 QStringList m_intervals;
61 QStringList m_categories;
62 qreal m_categoryMinimum;
62 qreal m_categoryMinimum;
63
63
64 private:
64 private:
@@ -243,7 +243,7 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q):
243 {
243 {
244 m_min = QDateTime::fromMSecsSinceEpoch(0);
244 m_min = QDateTime::fromMSecsSinceEpoch(0);
245 m_max = QDateTime::fromMSecsSinceEpoch(0);
245 m_max = QDateTime::fromMSecsSinceEpoch(0);
246 m_format = "dd-MMM-yy\nh:mm";
246 m_format = "dd-MMM-yyyy\nh:mm";
247 }
247 }
248
248
249 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
249 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
@@ -266,37 +266,37 void tst_QCategoryAxis::interval()
266 {
266 {
267 // append one correct interval
267 // append one correct interval
268 m_intervalsaxis->append("first", (qreal)45);
268 m_intervalsaxis->append("first", (qreal)45);
269 QCOMPARE(m_intervalsaxis->intervalMin("first"), (qreal)0);
269 QCOMPARE(m_intervalsaxis->categoryStart("first"), (qreal)0);
270 QCOMPARE(m_intervalsaxis->intervalMax("first"), (qreal)45);
270 QCOMPARE(m_intervalsaxis->categoryEnd("first"), (qreal)45);
271
271
272 // append one more correct interval
272 // append one more correct interval
273 m_intervalsaxis->append("second", (qreal)75);
273 m_intervalsaxis->append("second", (qreal)75);
274 QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)45);
274 QCOMPARE(m_intervalsaxis->categoryStart("second"), (qreal)45);
275 QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75);
275 QCOMPARE(m_intervalsaxis->categoryEnd("second"), (qreal)75);
276
276
277 // append one incorrect interval
277 // append one incorrect interval
278 m_intervalsaxis->append("third", (qreal)15);
278 m_intervalsaxis->append("third", (qreal)15);
279 QCOMPARE(m_intervalsaxis->count(), 2);
279 QCOMPARE(m_intervalsaxis->count(), 2);
280 QCOMPARE(m_intervalsaxis->intervalMax(m_intervalsaxis->intervalsLabels().last()), (qreal)75);
280 QCOMPARE(m_intervalsaxis->categoryEnd(m_intervalsaxis->categoriesLabels().last()), (qreal)75);
281 // QCOMPARE(intervalMax("first"), (qreal)75);
281 // QCOMPARE(intervalMax("first"), (qreal)75);
282
282
283 // append one more correct interval
283 // append one more correct interval
284 m_intervalsaxis->append("third", (qreal)100);
284 m_intervalsaxis->append("third", (qreal)100);
285 QCOMPARE(m_intervalsaxis->count(), 3);
285 QCOMPARE(m_intervalsaxis->count(), 3);
286 QCOMPARE(m_intervalsaxis->intervalMin("third"), (qreal)75);
286 QCOMPARE(m_intervalsaxis->categoryStart("third"), (qreal)75);
287 QCOMPARE(m_intervalsaxis->intervalMax("third"), (qreal)100);
287 QCOMPARE(m_intervalsaxis->categoryEnd("third"), (qreal)100);
288
288
289 // remove one interval
289 // remove one interval
290 m_intervalsaxis->remove("first");
290 m_intervalsaxis->remove("first");
291 QCOMPARE(m_intervalsaxis->count(), 2);
291 QCOMPARE(m_intervalsaxis->count(), 2);
292 QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)0); // second interval should extend to firstInterval minimum
292 QCOMPARE(m_intervalsaxis->categoryStart("second"), (qreal)0); // second interval should extend to firstInterval minimum
293 QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75);
293 QCOMPARE(m_intervalsaxis->categoryEnd("second"), (qreal)75);
294
294
295 // remove one interval
295 // remove one interval
296 m_intervalsaxis->replaceLabel("second", "replaced");
296 m_intervalsaxis->replaceLabel("second", "replaced");
297 QCOMPARE(m_intervalsaxis->count(), 2);
297 QCOMPARE(m_intervalsaxis->count(), 2);
298 QCOMPARE(m_intervalsaxis->intervalMin("replaced"), (qreal)0); // second interval should extend to firstInterval minimum
298 QCOMPARE(m_intervalsaxis->categoryStart("replaced"), (qreal)0); // second interval should extend to firstInterval minimum
299 QCOMPARE(m_intervalsaxis->intervalMax("replaced"), (qreal)75);
299 QCOMPARE(m_intervalsaxis->categoryEnd("replaced"), (qreal)75);
300 }
300 }
301
301
302 QTEST_MAIN(tst_QCategoryAxis)
302 QTEST_MAIN(tst_QCategoryAxis)
@@ -79,7 +79,7 void tst_QDateTimeAxis::init()
79 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
79 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
80 // tst_QAbstractAxis::init(m_datetimeaxis, m_series);
80 // tst_QAbstractAxis::init(m_datetimeaxis, m_series);
81
81
82 m_view = new QChartView(new QChart());
82 m_view = new QChartView;
83 m_chart = m_view->chart();
83 m_chart = m_view->chart();
84 m_chart->addSeries(m_series);
84 m_chart->addSeries(m_series);
85 m_chart->setAxisY(m_dateTimeAxisY, m_series);
85 m_chart->setAxisY(m_dateTimeAxisY, m_series);
@@ -158,7 +158,7 void tst_QDateTimeAxis::max_data()
158
158
159 void tst_QDateTimeAxis::max()
159 void tst_QDateTimeAxis::max()
160 {
160 {
161 m_chart->setAxisX(m_dateTimeAxisX, m_series);
161 // m_chart->setAxisX(m_dateTimeAxisX, m_series);
162 m_view->show();
162 m_view->show();
163 QTest::qWaitForWindowShown(m_view);
163 QTest::qWaitForWindowShown(m_view);
164 max_raw();
164 max_raw();
@@ -217,7 +217,7 void tst_QDateTimeAxis::min_data()
217
217
218 void tst_QDateTimeAxis::min()
218 void tst_QDateTimeAxis::min()
219 {
219 {
220 m_chart->setAxisX(m_dateTimeAxisX, m_series);
220 // m_chart->setAxisX(m_dateTimeAxisX, m_series);
221 m_view->show();
221 m_view->show();
222 QTest::qWaitForWindowShown(m_view);
222 QTest::qWaitForWindowShown(m_view);
223 min_raw();
223 min_raw();
@@ -291,7 +291,7 void tst_QDateTimeAxis::range_data()
291
291
292 void tst_QDateTimeAxis::range()
292 void tst_QDateTimeAxis::range()
293 {
293 {
294 m_chart->setAxisX(m_dateTimeAxisX, m_series);
294 // m_chart->setAxisX(m_dateTimeAxisX, m_series);
295 m_view->show();
295 m_view->show();
296 QTest::qWaitForWindowShown(m_view);
296 QTest::qWaitForWindowShown(m_view);
297 range_raw();
297 range_raw();
General Comments 0
You need to be logged in to leave comments. Login now