File indexing completed on 2024-04-21 03:48:03
0001 #ifndef HELPERMACROS_H 0002 #define HELPERMACROS_H 0003 0004 #include <QUndoStack> 0005 0006 #define SETUP_PROJECT \ 0007 Project project; \ 0008 auto* ws = new Worksheet(QStringLiteral("worksheet")); \ 0009 QVERIFY(ws != nullptr); \ 0010 project.addChild(ws); \ 0011 \ 0012 auto* p = new CartesianPlot(QStringLiteral("plot")); \ 0013 p->setType(CartesianPlot::Type::TwoAxes); /* Otherwise no axis are created */ \ 0014 QVERIFY(p != nullptr); \ 0015 ws->addChild(p); \ 0016 \ 0017 p->setHorizontalPadding(0); \ 0018 p->setVerticalPadding(0); \ 0019 p->setRightPadding(0); \ 0020 p->setBottomPadding(0); \ 0021 p->setRect(QRectF(0, 0, 100, 100)); \ 0022 \ 0023 QCOMPARE(p->rangeCount(Dimension::X), 1); \ 0024 QCOMPARE(p->range(Dimension::X, 0).start(), 0.); \ 0025 QCOMPARE(p->range(Dimension::X, 0).end(), 1.); \ 0026 QCOMPARE(p->rangeCount(Dimension::Y), 1); \ 0027 QCOMPARE(p->range(Dimension::Y, 0).start(), 0.); \ 0028 QCOMPARE(p->range(Dimension::Y, 0).end(), 1.); \ 0029 \ 0030 /* For simplicity use even numbers */ \ 0031 QCOMPARE(p->dataRect().x(), -50.); \ 0032 QCOMPARE(p->dataRect().y(), -50.); \ 0033 QCOMPARE(p->dataRect().width(), 100.); \ 0034 QCOMPARE(p->dataRect().height(), 100.); 0035 0036 #define WORKSHEETELEMENT_TEST_DEFINITION(WorksheetElementType, MACRO_NAME) void WorksheetElementType##MACRO_NAME() 0037 0038 #define WORKSHEETELEMENT_TEST(WorksheetElementType, MACRO_NAME, DockType, dockSetElementsMethodName) \ 0039 void WorksheetElementTest::WorksheetElementType##MACRO_NAME() { \ 0040 SETUP_PROJECT \ 0041 \ 0042 auto* element = new WorksheetElementType(p, QStringLiteral("element")); \ 0043 p->addChild(element); \ 0044 auto* dock = new DockType(nullptr); \ 0045 Q_UNUSED(dock); \ 0046 MACRO_NAME(element, dockSetElementsMethodName); \ 0047 } 0048 0049 // Without Cartesian Plot as argument to the constructor 0050 // Because of that the logical positions are not available before calling at least 0051 // once updatePosition(). Because of this retransform() will be done in this version 0052 #define WORKSHEETELEMENT_TEST2(WorksheetElementType, MACRO_NAME, DockType, dockSetElementsMethodName) \ 0053 void WorksheetElementTest::WorksheetElementType##MACRO_NAME() { \ 0054 SETUP_PROJECT \ 0055 \ 0056 auto* element = new WorksheetElementType(QStringLiteral("element")); \ 0057 p->addChild(element); \ 0058 VALUES_EQUAL(element->position().point.x(), 0.); \ 0059 VALUES_EQUAL(element->position().point.y(), 0.); \ 0060 element->retransform(); /* Needed because otherwise logical position is not set */ \ 0061 auto* dock = new DockType(nullptr); \ 0062 Q_UNUSED(dock); \ 0063 MACRO_NAME(element, dockSetElementsMethodName); \ 0064 } 0065 0066 // Test Macros 0067 // Testing if logical points are set correctly 0068 #define WORKSHEETELEMENT_SETPOSITIONLOGICAL(element, dockSetElementsMethodName) \ 0069 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0070 auto pp = element->position(); \ 0071 pp.point = QPointF(0, 0); \ 0072 element->setPosition(pp); \ 0073 element->setCoordinateBindingEnabled(true); \ 0074 \ 0075 QCOMPARE(element->positionLogical().x(), 0.5); \ 0076 QCOMPARE(element->positionLogical().y(), 0.5); \ 0077 \ 0078 element->setPositionLogical(QPointF(1, 1)); \ 0079 QCOMPARE(element->positionLogical().x(), 1.); \ 0080 QCOMPARE(element->positionLogical().y(), 1.); \ 0081 QCOMPARE(element->position().point.x(), 50.); \ 0082 QCOMPARE(element->position().point.y(), 50.); 0083 0084 #define WORKSHEETELEMENT_MOUSE_MOVE(element, dockSetElementsMethodName) \ 0085 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0086 auto pp = element->position(); \ 0087 pp.point = QPointF(0, 0); \ 0088 element->setPosition(pp); \ 0089 element->setCoordinateBindingEnabled(true); \ 0090 \ 0091 QCOMPARE(element->positionLogical().x(), 0.5); \ 0092 QCOMPARE(element->positionLogical().y(), 0.5); \ 0093 \ 0094 /* Simulate mouse move */ \ 0095 element->d_ptr->setPos(QPointF(25, -10)); /* item change will be called (negative value is up) */ \ 0096 QCOMPARE(element->positionLogical().x(), 0.75); /* 25/50 * 0.5 + 0.5 */ \ 0097 QCOMPARE(element->positionLogical().y(), 0.6); \ 0098 \ 0099 element->setPositionLogical(QPointF(0.3, 0.1)); \ 0100 QCOMPARE(element->positionLogical().x(), 0.3); \ 0101 QCOMPARE(element->positionLogical().y(), 0.1); \ 0102 QCOMPARE(element->position().point.x(), -20.); \ 0103 QCOMPARE(element->position().point.y(), -40.); 0104 0105 #define WORKSHEETELEMENT_KEYPRESS_NO_COORD_BINDING(element, dockSetElementsMethodName, KeyType, xScene, yScene, xLogical, yLogical) \ 0106 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0107 auto pp = element->position(); \ 0108 pp.point = QPointF(0, 0); \ 0109 element->setPosition(pp); \ 0110 element->setCoordinateBindingEnabled(false); \ 0111 \ 0112 dock->dockSetElementsMethodName({element}); \ 0113 QCOMPARE(dock->ui.chbBindLogicalPos->isChecked(), false); \ 0114 QCOMPARE(dock->ui.sbPositionX->value(), Worksheet::convertFromSceneUnits(element->position().point.x(), Worksheet::Unit::Centimeter)); \ 0115 QCOMPARE(dock->ui.sbPositionY->value(), Worksheet::convertFromSceneUnits(element->position().point.y(), Worksheet::Unit::Centimeter)); \ 0116 QCOMPARE(dock->ui.sbPositionXLogical->value(), element->positionLogical().x()); \ 0117 QCOMPARE(dock->ui.sbPositionYLogical->value(), element->positionLogical().y()); \ 0118 \ 0119 QKeyEvent event(QKeyEvent::Type::KeyPress, KeyType, Qt::KeyboardModifier::NoModifier); \ 0120 element->d_ptr->keyPressEvent(&event); \ 0121 \ 0122 VALUES_EQUAL(element->position().point.x(), xScene); \ 0123 VALUES_EQUAL(element->position().point.y(), yScene); \ 0124 VALUES_EQUAL(element->positionLogical().x(), xLogical); \ 0125 VALUES_EQUAL(element->positionLogical().y(), yLogical); \ 0126 \ 0127 QCOMPARE(dock->ui.sbPositionX->value(), Worksheet::convertFromSceneUnits(element->position().point.x(), Worksheet::Unit::Centimeter)); \ 0128 QCOMPARE(dock->ui.sbPositionY->value(), Worksheet::convertFromSceneUnits(element->position().point.y(), Worksheet::Unit::Centimeter)); \ 0129 QCOMPARE(dock->ui.sbPositionXLogical->value(), element->positionLogical().x()); \ 0130 QCOMPARE(dock->ui.sbPositionYLogical->value(), element->positionLogical().y()); 0131 0132 #define WORKSHEETELEMENT_KEYPRESS_RIGHT_NO_COORD_BINDING(element, dockSetElementsMethodName) \ 0133 WORKSHEETELEMENT_KEYPRESS_NO_COORD_BINDING(element, dockSetElementsMethodName, Qt::Key_Right, 5., 0., 0.55, 0.5) 0134 0135 #define WORKSHEETELEMENT_KEYPRESS_DOWN_NO_COORD_BINDING(element, dockSetElementsMethodName) \ 0136 WORKSHEETELEMENT_KEYPRESS_NO_COORD_BINDING(element, dockSetElementsMethodName, Qt::Key_Down, 0., -5., 0.5, 0.45) 0137 0138 #define WORKSHEETELEMENT_KEYPRESS(element, dockSetElementsMethodName, KeyType, xScene, yScene, xLogical, yLogical) \ 0139 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0140 auto pp = element->position(); \ 0141 pp.point = QPointF(0, 0); \ 0142 element->setPosition(pp); \ 0143 element->setCoordinateBindingEnabled(true); \ 0144 \ 0145 dock->dockSetElementsMethodName({element}); \ 0146 QCOMPARE(dock->ui.chbBindLogicalPos->isChecked(), true); \ 0147 QCOMPARE(dock->ui.sbPositionX->value(), Worksheet::convertFromSceneUnits(element->position().point.x(), Worksheet::Unit::Centimeter)); \ 0148 QCOMPARE(dock->ui.sbPositionY->value(), Worksheet::convertFromSceneUnits(element->position().point.y(), Worksheet::Unit::Centimeter)); \ 0149 QCOMPARE(dock->ui.sbPositionXLogical->value(), element->positionLogical().x()); \ 0150 QCOMPARE(dock->ui.sbPositionYLogical->value(), element->positionLogical().y()); \ 0151 \ 0152 QKeyEvent event(QKeyEvent::Type::KeyPress, KeyType, Qt::KeyboardModifier::NoModifier); \ 0153 element->d_ptr->keyPressEvent(&event); \ 0154 \ 0155 VALUES_EQUAL(element->position().point.x(), xScene); \ 0156 VALUES_EQUAL(element->position().point.y(), yScene); \ 0157 VALUES_EQUAL(element->positionLogical().x(), xLogical); \ 0158 VALUES_EQUAL(element->positionLogical().y(), yLogical); \ 0159 \ 0160 QCOMPARE(dock->ui.sbPositionX->value(), Worksheet::convertFromSceneUnits(element->position().point.x(), Worksheet::Unit::Centimeter)); \ 0161 QCOMPARE(dock->ui.sbPositionY->value(), Worksheet::convertFromSceneUnits(element->position().point.y(), Worksheet::Unit::Centimeter)); \ 0162 QCOMPARE(dock->ui.sbPositionXLogical->value(), element->positionLogical().x()); \ 0163 QCOMPARE(dock->ui.sbPositionYLogical->value(), element->positionLogical().y()); 0164 0165 #define WORKSHEETELEMENT_KEYPRESS_RIGHT(element, dockSetElementsMethodName) \ 0166 WORKSHEETELEMENT_KEYPRESS(element, dockSetElementsMethodName, Qt::Key_Right, 5., 0., 0.55, 0.5) 0167 0168 #define WORKSHEETELEMENT_KEY_PRESSLEFT(element, dockSetElementsMethodName) \ 0169 WORKSHEETELEMENT_KEYPRESS(element, dockSetElementsMethodName, Qt::Key_Left, -5., 0., 0.45, 0.5) 0170 0171 #define WORKSHEETELEMENT_KEYPRESS_UP(element, dockSetElementsMethodName) \ 0172 WORKSHEETELEMENT_KEYPRESS(element, dockSetElementsMethodName, Qt::Key_Up, 0., 5., 0.5, 0.55) 0173 0174 #define WORKSHEETELEMENT_KEYPRESS_DOWN(element, dockSetElementsMethodName) \ 0175 WORKSHEETELEMENT_KEYPRESS(element, dockSetElementsMethodName, Qt::Key_Down, 0., -5., 0.5, 0.45) 0176 0177 #define WORKSHEETELEMENT_KEYPRESS_UNDO(element, dockSetElementsMethodName, KeyType, xScene, yScene, xLogical, yLogical) \ 0178 WORKSHEETELEMENT_KEYPRESS(element, dockSetElementsMethodName, KeyType, xScene, yScene, xLogical, yLogical) \ 0179 element->undoStack()->undo(); \ 0180 VALUES_EQUAL(element->position().point.x(), 0.); \ 0181 VALUES_EQUAL(element->position().point.y(), 0.); \ 0182 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0183 VALUES_EQUAL(element->positionLogical().y(), 0.5); 0184 0185 #define WORKSHEETELEMENT_KEYPRESS_RIGHT_UNDO(element, dockSetElementsMethodName) \ 0186 WORKSHEETELEMENT_KEYPRESS_UNDO(element, dockSetElementsMethodName, Qt::Key_Right, 5., 0., 0.55, 0.5) 0187 0188 #define WORKSHEETELEMENT_KEYPRESS_UP_UNDO(element, dockSetElementsMethodName) \ 0189 WORKSHEETELEMENT_KEYPRESS_UNDO(element, dockSetElementsMethodName, Qt::Key_Up, 0., 5., 0.5, 0.55) 0190 0191 // Switching between setCoordinateBindingEnabled true and false should not move the point 0192 #define WORKSHEETELEMENT_ENABLE_DISABLE_COORDBINDING(element, dockSetElementsMethodName) \ 0193 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0194 auto pp = element->position(); \ 0195 pp.point = QPointF(0, 0); \ 0196 element->setPosition(pp); \ 0197 \ 0198 VALUES_EQUAL(element->position().point.x(), 0.); \ 0199 VALUES_EQUAL(element->position().point.y(), 0.); \ 0200 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0201 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0202 \ 0203 element->setCoordinateBindingEnabled(true); \ 0204 \ 0205 VALUES_EQUAL(element->position().point.x(), 0.); \ 0206 VALUES_EQUAL(element->position().point.y(), 0.); \ 0207 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0208 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0209 \ 0210 /* Set position to another than the origin */ \ 0211 element->setPositionLogical(QPointF(0.85, 0.7)); \ 0212 \ 0213 VALUES_EQUAL(element->position().point.x(), 35.); \ 0214 VALUES_EQUAL(element->position().point.y(), 20.); \ 0215 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0216 VALUES_EQUAL(element->positionLogical().y(), 0.7); \ 0217 \ 0218 element->setCoordinateBindingEnabled(false); \ 0219 \ 0220 VALUES_EQUAL(element->position().point.x(), 35.); \ 0221 VALUES_EQUAL(element->position().point.y(), 20.); \ 0222 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0223 VALUES_EQUAL(element->positionLogical().y(), 0.7); \ 0224 \ 0225 element->setCoordinateBindingEnabled(true); \ 0226 \ 0227 VALUES_EQUAL(element->position().point.x(), 35.); \ 0228 VALUES_EQUAL(element->position().point.y(), 20.); \ 0229 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0230 VALUES_EQUAL(element->positionLogical().y(), 0.7); 0231 0232 #define WORKSHEETELEMENT_SHIFTX_COORDBINDING(element, dockSetElementsMethodName) \ 0233 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0234 auto pp = element->position(); \ 0235 pp.point = QPointF(0, 0); \ 0236 element->setPosition(pp); \ 0237 \ 0238 VALUES_EQUAL(element->position().point.x(), 0.); \ 0239 VALUES_EQUAL(element->position().point.y(), 0.); \ 0240 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0241 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0242 \ 0243 element->setCoordinateBindingEnabled(true); \ 0244 \ 0245 VALUES_EQUAL(element->position().point.x(), 0.); \ 0246 VALUES_EQUAL(element->position().point.y(), 0.); \ 0247 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0248 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0249 \ 0250 /* Set position to another than the origin */ \ 0251 element->setPositionLogical(QPointF(0.85, 0.7)); \ 0252 \ 0253 VALUES_EQUAL(element->position().point.x(), 35.); \ 0254 VALUES_EQUAL(element->position().point.y(), 20.); \ 0255 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0256 VALUES_EQUAL(element->positionLogical().y(), 0.7); \ 0257 \ 0258 p->shiftLeftX(); \ 0259 \ 0260 VALUES_EQUAL(element->position().point.x(), 25.); /* shift factor is 0.1 -> 1(current range)*0.1 = 0.1 = -10 in scene coords */ \ 0261 VALUES_EQUAL(element->position().point.y(), 20.); \ 0262 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0263 VALUES_EQUAL(element->positionLogical().y(), 0.7); 0264 0265 #define WORKSHEETELEMENT_SHIFTY_COORDBINDING(element, dockSetElementsMethodName) \ 0266 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0267 auto pp = element->position(); \ 0268 pp.point = QPointF(0, 0); \ 0269 element->setPosition(pp); \ 0270 \ 0271 VALUES_EQUAL(element->position().point.x(), 0.); \ 0272 VALUES_EQUAL(element->position().point.y(), 0.); \ 0273 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0274 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0275 \ 0276 element->setCoordinateBindingEnabled(true); \ 0277 \ 0278 VALUES_EQUAL(element->position().point.x(), 0.); \ 0279 VALUES_EQUAL(element->position().point.y(), 0.); \ 0280 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0281 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0282 \ 0283 /* Set position to another than the origin */ \ 0284 element->setPositionLogical(QPointF(0.85, 0.7)); \ 0285 \ 0286 VALUES_EQUAL(element->position().point.x(), 35.); \ 0287 VALUES_EQUAL(element->position().point.y(), 20.); \ 0288 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0289 VALUES_EQUAL(element->positionLogical().y(), 0.7); \ 0290 \ 0291 p->shiftUpY(); \ 0292 \ 0293 VALUES_EQUAL(element->position().point.x(), 35.); \ 0294 VALUES_EQUAL(element->position().point.y(), 30.); /* shift factor is 0.1 -> 1(current range)*0.1 = 0.1 = +10 in scene coords (for UP) */ \ 0295 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0296 VALUES_EQUAL(element->positionLogical().y(), 0.7); 0297 0298 #define WORKSHEETELEMENT_SHIFTX_NO_COORDBINDING(element, dockSetElementsMethodName) \ 0299 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0300 auto pp = element->position(); \ 0301 pp.point = QPointF(0, 0); \ 0302 element->setPosition(pp); \ 0303 \ 0304 VALUES_EQUAL(element->position().point.x(), 0.); \ 0305 VALUES_EQUAL(element->position().point.y(), 0.); \ 0306 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0307 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0308 \ 0309 element->setCoordinateBindingEnabled(true); \ 0310 \ 0311 VALUES_EQUAL(element->position().point.x(), 0.); \ 0312 VALUES_EQUAL(element->position().point.y(), 0.); \ 0313 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0314 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0315 \ 0316 /* Set position to another than the origin */ \ 0317 element->setPositionLogical(QPointF(0.85, 0.7)); \ 0318 element->setCoordinateBindingEnabled(false); \ 0319 \ 0320 VALUES_EQUAL(element->position().point.x(), 35.); \ 0321 VALUES_EQUAL(element->position().point.y(), 20.); \ 0322 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0323 VALUES_EQUAL(element->positionLogical().y(), 0.7); \ 0324 \ 0325 p->shiftLeftX(); \ 0326 \ 0327 VALUES_EQUAL(element->position().point.x(), 35.); \ 0328 VALUES_EQUAL(element->position().point.y(), 20.); \ 0329 VALUES_EQUAL(element->positionLogical().x(), 0.95); /* shift factor is 0.1 -> 1(current range)*0.1 = 0.1 */ \ 0330 VALUES_EQUAL(element->positionLogical().y(), 0.7); 0331 0332 #define WORKSHEETELEMENT_SHIFTY_NO_COORDBINDING(element, dockSetElementsMethodName) \ 0333 element->setCoordinateSystemIndex(p->defaultCoordinateSystemIndex()); \ 0334 auto pp = element->position(); \ 0335 pp.point = QPointF(0, 0); \ 0336 element->setPosition(pp); \ 0337 \ 0338 VALUES_EQUAL(element->position().point.x(), 0.); \ 0339 VALUES_EQUAL(element->position().point.y(), 0.); \ 0340 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0341 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0342 \ 0343 element->setCoordinateBindingEnabled(true); \ 0344 \ 0345 VALUES_EQUAL(element->position().point.x(), 0.); \ 0346 VALUES_EQUAL(element->position().point.y(), 0.); \ 0347 VALUES_EQUAL(element->positionLogical().x(), 0.5); \ 0348 VALUES_EQUAL(element->positionLogical().y(), 0.5); \ 0349 \ 0350 /* Set position to another than the origin */ \ 0351 element->setPositionLogical(QPointF(0.85, 0.7)); \ 0352 element->setCoordinateBindingEnabled(false); \ 0353 \ 0354 VALUES_EQUAL(element->position().point.x(), 35.); \ 0355 VALUES_EQUAL(element->position().point.y(), 20.); \ 0356 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0357 VALUES_EQUAL(element->positionLogical().y(), 0.7); \ 0358 \ 0359 p->shiftUpY(); \ 0360 \ 0361 VALUES_EQUAL(element->position().point.x(), 35.); \ 0362 VALUES_EQUAL(element->position().point.y(), 20.); \ 0363 VALUES_EQUAL(element->positionLogical().x(), 0.85); \ 0364 VALUES_EQUAL(element->positionLogical().y(), 0.6); /* shift factor is 0.1 -> 1(current range)*0.1 = 0.1 */ 0365 0366 /* 0367 * Check that when moving the element, the datetime is changed correctly and aligned with the datetime of the range 0368 * No Timezone problems 0369 * Using a datetime before 1970 because then toMSecsSinceEpoch() will be negative. To test if it works also there 0370 */ 0371 #define MOUSE_MOVE_DATETIME(element, dockSetElementsMethodName) \ 0372 auto start = QDateTime::fromString(QLatin1String("1800-12-01 00:00:00:000Z"), QStringLiteral("yyyy-MM-dd hh:mm:ss:zzzt")); \ 0373 auto end = QDateTime::fromString(QLatin1String("1800-12-02 00:00:00:000Z"), QStringLiteral("yyyy-MM-dd hh:mm:ss:zzzt")); \ 0374 QVERIFY(start.isValid()); \ 0375 QVERIFY(end.isValid()); \ 0376 Range<double> dt(start.toMSecsSinceEpoch(), end.toMSecsSinceEpoch(), RangeT::Format::DateTime); \ 0377 element->setCoordinateBindingEnabled(false); /* Disable binding to be sure that the point is still in the center of the plot when changing the range */ \ 0378 p->setRange(Dimension::X, 0, dt); \ 0379 \ 0380 dock->dockSetElementsMethodName({element}); \ 0381 \ 0382 QCOMPARE(element->position().point.x(), 0.); \ 0383 element->setCoordinateBindingEnabled(true); \ 0384 QCOMPARE(element->d_ptr->pos().x(), 0); \ 0385 QCOMPARE(dock->ui.dtePositionXLogical->dateTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss:zzz")), QLatin1String("1800-12-01 12:00:00:000")); \ 0386 \ 0387 /* 75% on between start and end -> so 3/4 * 24h = 18h */ \ 0388 element->d_ptr->setPos(QPointF(25, -10)); /* item change will be called (negative value is up) */ \ 0389 \ 0390 QCOMPARE(element->positionLogical().x(), \ 0391 QDateTime::fromString(QLatin1String("1800-12-01 18:00:00:000Z"), QStringLiteral("yyyy-MM-dd hh:mm:ss:zzzt")).toMSecsSinceEpoch()); \ 0392 QCOMPARE(dock->ui.dtePositionXLogical->dateTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss:zzz")), QLatin1String("1800-12-01 18:00:00:000")); 0393 0394 #define DOCK_CHANGE_DATETIME(element, dockSetElementsMethodName) \ 0395 auto start = QDateTime::fromString(QLatin1String("1800-12-01 00:00:00:000Z"), QStringLiteral("yyyy-MM-dd hh:mm:ss:zzzt")); \ 0396 auto end = QDateTime::fromString(QLatin1String("1800-12-02 00:00:00:000Z"), QStringLiteral("yyyy-MM-dd hh:mm:ss:zzzt")); \ 0397 QVERIFY(start.isValid()); \ 0398 QVERIFY(end.isValid()); \ 0399 Range<double> dt(start.toMSecsSinceEpoch(), end.toMSecsSinceEpoch(), RangeT::Format::DateTime); \ 0400 element->setCoordinateBindingEnabled(false); /* Disable binding to be sure that the point is still in the center of the plot when changing the range */ \ 0401 p->setRange(Dimension::X, 0, dt); \ 0402 \ 0403 dock->dockSetElementsMethodName({element}); \ 0404 \ 0405 QCOMPARE(element->position().point.x(), 0.); \ 0406 element->setCoordinateBindingEnabled(true); \ 0407 QCOMPARE(element->d_ptr->pos().x(), 0); \ 0408 QCOMPARE(dock->ui.dtePositionXLogical->dateTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss:zzz")), QLatin1String("1800-12-01 12:00:00:000")); \ 0409 \ 0410 /* Change hour by 1 */ \ 0411 dock->ui.dtePositionXLogical->lineEdit()->setCursorPosition(13); /* behind the second hour digit */ \ 0412 QKeyEvent event(QKeyEvent::Type::KeyPress, Qt::Key_Up, Qt::KeyboardModifier::NoModifier); \ 0413 dock->ui.dtePositionXLogical->keyPressEvent(&event); \ 0414 \ 0415 QCOMPARE(element->positionLogical().x(), \ 0416 QDateTime::fromString(QLatin1String("1800-12-01 13:00:00:000Z"), QStringLiteral("yyyy-MM-dd hh:mm:ss:zzzt")).toMSecsSinceEpoch()); \ 0417 QCOMPARE(dock->ui.dtePositionXLogical->dateTime().toString(QLatin1String("yyyy-MM-dd hh:mm:ss:zzz")), QLatin1String("1800-12-01 13:00:00:000")); 0418 0419 #endif // HELPERMACROS_H