| 132 | } |
| 133 | |
| 134 | void AxisTest::majorTicksAutoNumberEnableDisable() { |
| 135 | Project project; |
| 136 | auto* ws = new Worksheet(QStringLiteral("worksheet")); |
| 137 | QVERIFY(ws != nullptr); |
| 138 | project.addChild(ws); |
| 139 | |
| 140 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 141 | QVERIFY(p != nullptr); |
| 142 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created |
| 143 | ws->addChild(p); |
| 144 | |
| 145 | auto axes = p->children<Axis>(); |
| 146 | QCOMPARE(axes.count(), 2); |
| 147 | QCOMPARE(axes.at(0)->name(), QStringLiteral("x")); |
| 148 | QCOMPARE(axes.at(1)->name(), QStringLiteral("y")); |
| 149 | |
| 150 | AxisDock axisDock(nullptr); |
| 151 | |
| 152 | auto* xAxis = axes.at(0); |
| 153 | QCOMPARE(xAxis->majorTicksNumber(), 6); // Default number created by autonumbering |
| 154 | QCOMPARE(xAxis->majorTicksAutoNumber(), true); |
| 155 | |
| 156 | { |
| 157 | QVector<double> expectedTickValues = {0, 0.2, 0.4, 0.6, 0.8, 1.0}; |
| 158 | CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues); |
| 159 | } |
| 160 | |
| 161 | // To check also if the dock shows the correct values |
| 162 | axisDock.setAxes({xAxis}); |
| 163 | |
| 164 | QCOMPARE(axisDock.ui.cbMajorTicksAutoNumber->isChecked(), true); |
| 165 | QCOMPARE(axisDock.ui.sbMajorTicksNumber->isEnabled(), false); |
| 166 | |
| 167 | // Not possible, because sbMajorTicksNumber is disabled |
| 168 | // test it nevertless |
| 169 | xAxis->setMajorTicksNumber(5); |
| 170 | QCOMPARE(xAxis->majorTicksNumber(), 5); |
| 171 | QCOMPARE(xAxis->majorTicksAutoNumber(), false); |
| 172 | |
| 173 | { |
| 174 | QVector<double> expectedTickValues = {0, 0.25, 0.5, 0.75, 1}; |
| 175 | CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues); |
| 176 | } |
| 177 | |
| 178 | QCOMPARE(axisDock.ui.cbMajorTicksAutoNumber->isChecked(), false); |
| 179 | QCOMPARE(axisDock.ui.sbMajorTicksNumber->isEnabled(), true); |
| 180 | QCOMPARE(axisDock.ui.sbMajorTicksNumber->value(), 5); |
| 181 | |
| 182 | // Check that undo/redo works for setting manual ticknumber |
| 183 | project.undoStack()->undo(); |
| 184 | QCOMPARE(xAxis->majorTicksNumber(), 6); |
| 185 | QCOMPARE(xAxis->majorTicksAutoNumber(), true); |
| 186 | |
| 187 | { |
| 188 | QVector<double> expectedTickValues = {0, 0.2, 0.4, 0.6, 0.8, 1.0}; |
| 189 | CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues); |
| 190 | } |
| 191 |
nothing calls this directly
no test coverage detected