@@ -51,6 +51,7 @@ class TestQgsRangeWidgetWrapper : public QObject
51
51
void test_setDoubleSmallerRange ();
52
52
void test_setDoubleLimits ();
53
53
void test_nulls ();
54
+ void test_focus ();
54
55
55
56
private:
56
57
std::unique_ptr<QgsRangeWidgetWrapper> widget0; // For field 0
@@ -328,7 +329,64 @@ void TestQgsRangeWidgetWrapper::test_nulls()
328
329
329
330
}
330
331
332
+ void TestQgsRangeWidgetWrapper::test_focus ()
333
+ {
334
+ QgsApplication::setNullRepresentation ( QString ( " nope" ) );
335
+
336
+ QWidget *w = new QWidget (); // required for focus events
337
+ QApplication::setActiveWindow ( w );
338
+
339
+ QVariantMap cfg;
340
+ cfg.insert ( QStringLiteral ( " AllowNull" ), true );
341
+
342
+ widget1->setConfig ( cfg );
343
+ QgsDoubleSpinBox *editor1 = qobject_cast<QgsDoubleSpinBox *>( widget1->createWidget ( w ) );
344
+ QVERIFY ( editor1 );
345
+ widget1->initWidget ( editor1 );
331
346
347
+ widget2->setConfig ( cfg );
348
+ QgsDoubleSpinBox *editor2 = qobject_cast<QgsDoubleSpinBox *>( widget2->createWidget ( w ) );
349
+ QVERIFY ( editor2 );
350
+ widget2->initWidget ( editor2 );
351
+
352
+ editor1->mLineEdit ->setNullValue ( QgsApplication::nullRepresentation () );
353
+ editor2->mLineEdit ->setNullValue ( QgsApplication::nullRepresentation () );
354
+
355
+ QVERIFY ( editor1->mLineEdit ->isNull () );
356
+ QVERIFY ( editor2->mLineEdit ->isNull () );
357
+ QVERIFY ( !editor1->mLineEdit ->hasFocus () );
358
+ QVERIFY ( !editor2->mLineEdit ->hasFocus () );
359
+ QCOMPARE ( editor1->mLineEdit ->text (), QStringLiteral ( " nope" ) );
360
+ QCOMPARE ( editor2->mLineEdit ->text (), QStringLiteral ( " nope" ) );
361
+
362
+ editor1->mLineEdit ->setFocus ();
363
+ QVERIFY ( editor1->mLineEdit ->hasFocus () );
364
+ QVERIFY ( !editor2->mLineEdit ->hasFocus () );
365
+ QCOMPARE ( editor1->mLineEdit ->text (), QStringLiteral ( " " ) );
366
+ QCOMPARE ( editor2->mLineEdit ->text (), QStringLiteral ( " nope" ) );
367
+
368
+ editor2->mLineEdit ->setFocus ();
369
+ QVERIFY ( !editor1->mLineEdit ->hasFocus () );
370
+ QVERIFY ( editor2->mLineEdit ->hasFocus () );
371
+ QCOMPARE ( editor1->mLineEdit ->text (), QStringLiteral ( " nope" ) );
372
+ QCOMPARE ( editor2->mLineEdit ->text (), QStringLiteral ( " " ) );
373
+
374
+ editor1->mLineEdit ->setFocus ();
375
+ editor1->mLineEdit ->setText ( QString ( " 151.000000000" ) );
376
+ QVERIFY ( !editor1->mLineEdit ->isNull () );
377
+ QVERIFY ( editor2->mLineEdit ->isNull () );
378
+ QVERIFY ( editor1->mLineEdit ->hasFocus () );
379
+ QVERIFY ( !editor2->mLineEdit ->hasFocus () );
380
+ QCOMPARE ( editor1->mLineEdit ->text (), QStringLiteral ( " 151.000000000" ) );
381
+ QCOMPARE ( editor2->mLineEdit ->text (), QStringLiteral ( " nope" ) );
382
+
383
+ editor2->mLineEdit ->setFocus ();
384
+ QVERIFY ( !editor1->mLineEdit ->hasFocus () );
385
+ QVERIFY ( editor2->mLineEdit ->hasFocus () );
386
+ QCOMPARE ( editor1->mLineEdit ->text (), QStringLiteral ( " 151.000000000" ) );
387
+ QCOMPARE ( editor2->mLineEdit ->text (), QStringLiteral ( " " ) );
388
+
389
+ }
332
390
333
391
QGSTEST_MAIN ( TestQgsRangeWidgetWrapper )
334
392
#include " testqgsrangewidgetwrapper.moc"
0 commit comments