summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-11-29 09:41:16 +0100
committerAndy Shaw <andy.shaw@qt.io>2017-12-01 09:18:39 +0000
commit6cde98b2254e6197a285a83617c952fd1d14cb3d (patch)
treec47bbac09fa33a207b0fa4b700d67b92bfad8e2f
parent5d2cb8a429a7ed6244e80973cfcf94740859e174 (diff)
When passing empty QStrings as label format should revert to the default
This ensures that the QML and widgets side both behave in the same way as the QML side handled an empty string as reverting back to the default. Whereas the widget side did not, now it will ensure that it is consistent. Change-Id: Ibc3f149f1761586e5fa04420e3b78bed169304d1 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/charts/axis/chartaxiselement.cpp4
-rw-r--r--tests/auto/qvalueaxis/tst_qvalueaxis.cpp36
2 files changed, 38 insertions, 2 deletions
diff --git a/src/charts/axis/chartaxiselement.cpp b/src/charts/axis/chartaxiselement.cpp
index c5a1ab91..5282ee36 100644
--- a/src/charts/axis/chartaxiselement.cpp
+++ b/src/charts/axis/chartaxiselement.cpp
@@ -343,7 +343,7 @@ QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks,
if (max <= min || ticks < 1)
return labels;
- if (format.isNull()) {
+ if (format.isEmpty()) {
int n = qMax(int(-qFloor(std::log10((max - min) / (ticks - 1)))), 0) + 1;
for (int i = 0; i < ticks; i++) {
qreal value = min + (i * (max - min) / (ticks - 1));
@@ -395,7 +395,7 @@ QStringList ChartAxisElement::createLogValueLabels(qreal min, qreal max, qreal b
else
firstTick = qCeil(std::log10(max) / std::log10(base));
- if (format.isNull()) {
+ if (format.isEmpty()) {
int n = 0;
if (ticks > 1)
n = qMax(int(-qFloor(std::log10((max - min) / (ticks - 1)))), 0);
diff --git a/tests/auto/qvalueaxis/tst_qvalueaxis.cpp b/tests/auto/qvalueaxis/tst_qvalueaxis.cpp
index 4de89cb1..1527cb2b 100644
--- a/tests/auto/qvalueaxis/tst_qvalueaxis.cpp
+++ b/tests/auto/qvalueaxis/tst_qvalueaxis.cpp
@@ -71,6 +71,7 @@ private slots:
void autoscale_data();
void autoscale();
void reverse();
+ void labels();
private:
QValueAxis* m_valuesaxis;
@@ -437,6 +438,41 @@ void tst_QValueAxis::reverse()
QCOMPARE(m_valuesaxis->isReverse(), true);
}
+void tst_QValueAxis::labels()
+{
+ m_chart->setAxisX(m_valuesaxis, m_series);
+ m_view->resize(300, 300);
+ m_view->show();
+ QTest::qWaitForWindowShown(m_view);
+
+ QList<QGraphicsItem *> childItems = m_chart->scene()->items();
+ QList<QGraphicsTextItem *> textItems;
+ QStringList originalStrings;
+ for (QGraphicsItem *i : childItems) {
+ if (QGraphicsTextItem *text = qgraphicsitem_cast<QGraphicsTextItem *>(i)) {
+ if (text->parentItem() != m_chart) {
+ textItems << text;
+ originalStrings << text->toPlainText();
+ }
+ }
+ }
+ m_valuesaxis->setLabelFormat("%.0f");
+ // Wait for the format to have updated
+ QTest::qWait(100);
+ QStringList updatedStrings;
+ for (QGraphicsTextItem *i : textItems)
+ updatedStrings << i->toPlainText();
+ // The order will be the same as we kept the order of the items
+ QVERIFY(originalStrings != updatedStrings);
+ updatedStrings.clear();
+ // The labels should be back to the original defaults
+ m_valuesaxis->setLabelFormat("");
+ QTest::qWait(100);
+ for (QGraphicsTextItem *i : textItems)
+ updatedStrings << i->toPlainText();
+ QCOMPARE(originalStrings, updatedStrings);
+}
+
QTEST_MAIN(tst_QValueAxis)
#include "tst_qvalueaxis.moc"