@@ -33,6 +33,9 @@ class TestQgsValueRelationWidgetWrapper : public QObject
3333 public:
3434 TestQgsValueRelationWidgetWrapper () = default ;
3535
36+ private:
37+ QTemporaryDir tempDir;
38+
3639 private slots:
3740 void initTestCase (); // will be called before the first testfunction is executed.
3841 void cleanupTestCase (); // will be called after the last testfunction was executed.
@@ -45,6 +48,7 @@ class TestQgsValueRelationWidgetWrapper : public QObject
4548 // ! Checks that a related value of 0 is not interpreted as a NULL
4649 void testZeroIndexInRelatedTable ();
4750 void testWithJsonInPostgres ();
51+ void testWithJsonInGPKG ();
4852};
4953
5054void TestQgsValueRelationWidgetWrapper::initTestCase ()
@@ -389,7 +393,7 @@ void TestQgsValueRelationWidgetWrapper::testWithJsonInPostgres()
389393
390394 QCOMPARE ( vl_json->fields ().at ( 1 ).type (), QVariant::Map );
391395
392- // build a value relation widget wrapper for bikes
396+ // build a value relation widget wrapper
393397 QgsValueRelationWidgetWrapper w_favoriteauthors ( vl_json, vl_json->fields ().indexOf ( QStringLiteral ( " jvalue" ) ), nullptr , nullptr );
394398 QVariantMap cfg_favoriteautors;
395399 cfg_favoriteautors.insert ( QStringLiteral ( " Layer" ), vl_authors->id () );
@@ -450,5 +454,98 @@ void TestQgsValueRelationWidgetWrapper::testWithJsonInPostgres()
450454 QCOMPARE ( w_favoriteauthors.mTableWidget ->item ( 5 , 0 )->checkState (), Qt::Checked );
451455}
452456
457+
458+ void TestQgsValueRelationWidgetWrapper::testWithJsonInGPKG ()
459+ {
460+ /* prepared - functionality needs to be integrated first
461+
462+ // create ogr gpkg layers
463+ QString myFileName( TEST_DATA_DIR ); //defined in CmakeLists.txt
464+ QString myTempDirName = tempDir.path();
465+ QFile::copy( myFileName + "/provider/test_json.gpkg", myTempDirName + "/test_json.gpkg" );
466+ QString myTempFileName = myTempDirName + "/test_json.gpkg";
467+ QFileInfo myMapFileInfo( myTempFileName );
468+ QgsVectorLayer *vl_json = new QgsVectorLayer( myMapFileInfo.filePath()+"|layername=reader", "test", QStringLiteral( "ogr" ) );
469+ QgsVectorLayer *vl_authors = new QgsVectorLayer( myMapFileInfo.filePath()+"|layername=author", "test", QStringLiteral( "ogr" ) );
470+ QVERIFY( vl_json->isValid() );
471+ QVERIFY( vl_authors->isValid() );
472+
473+ QgsProject::instance()->addMapLayer( vl_json, false, false );
474+ QgsProject::instance()->addMapLayer( vl_authors, false, false );
475+
476+ // build a value relation widget wrapper for bikes
477+ QgsValueRelationWidgetWrapper w_favoriteauthors( vl_json, vl_json->fields().indexOf( QStringLiteral( "json_content" ) ), nullptr, nullptr );
478+ QVariantMap cfg_favoriteautors;
479+ cfg_favoriteautors.insert( QStringLiteral( "Layer" ), vl_authors->id() );
480+ cfg_favoriteautors.insert( QStringLiteral( "Key" ), QStringLiteral( "fid" ) );
481+ cfg_favoriteautors.insert( QStringLiteral( "Value" ), QStringLiteral( "NAME" ) );
482+ cfg_favoriteautors.insert( QStringLiteral( "AllowMulti" ), true );
483+ cfg_favoriteautors.insert( QStringLiteral( "NofColumns" ), 1 );
484+ cfg_favoriteautors.insert( QStringLiteral( "AllowNull" ), false );
485+ cfg_favoriteautors.insert( QStringLiteral( "OrderByValue" ), false );
486+ cfg_favoriteautors.insert( QStringLiteral( "UseCompleter" ), false );
487+ w_favoriteauthors.setConfig( cfg_favoriteautors );
488+ w_favoriteauthors.widget();
489+ w_favoriteauthors.setEnabled( true );
490+
491+ //check if set up nice
492+ QCOMPARE( w_favoriteauthors.mTableWidget->rowCount(), 6 );
493+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->text(), QStringLiteral( "Erich Gamma" ) );
494+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "1" ) );
495+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->text(), QStringLiteral( "Richard Helm" ) );
496+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "2" ) );
497+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->text(), QStringLiteral( "Ralph Johnson" ) );
498+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "3" ) );
499+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->text(), QStringLiteral( "John Vlissides" ) );
500+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "4" ) );
501+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->text(), QStringLiteral( "Douglas Adams" ) );
502+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "5" ) );
503+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->text(), QStringLiteral( "Ken Follett" ) );
504+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->data( Qt::UserRole ).toString(), QStringLiteral( "6" ) );
505+
506+ //check if first feature checked correctly [4]
507+ w_favoriteauthors.setFeature( vl_json->getFeature( 1 ) );
508+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->text(), QStringLiteral( "Erich Gamma" ) );
509+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->checkState(), Qt::Unchecked );
510+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->text(), QStringLiteral( "Richard Helm" ) );
511+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->checkState(), Qt::Unchecked );
512+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->text(), QStringLiteral( "Ralph Johnson" ) );
513+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->checkState(), Qt::Unchecked );
514+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->text(), QStringLiteral( "John Vlissides" ) );
515+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->checkState(), Qt::Unchecked );
516+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->text(), QStringLiteral( "Douglas Adams" ) );
517+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->checkState(), Qt::Checked );
518+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->text(), QStringLiteral( "Ken Follett" ) );
519+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->checkState(), Qt::Unchecked );
520+
521+ //check other authors
522+ w_favoriteauthors.mTableWidget->item( 0, 0 )->setCheckState( Qt::Checked);
523+ w_favoriteauthors.mTableWidget->item( 2, 0 )->setCheckState( Qt::Checked);
524+ w_favoriteauthors.mTableWidget->item( 5, 0 )->setCheckState( Qt::Checked);
525+
526+ //check if first feature checked correctly 0, 2, 4, 5
527+ w_favoriteauthors.setFeature( vl_json->getFeature( 1 ) );
528+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->text(), QStringLiteral( "Erich Gamma" ) );
529+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 0, 0 )->checkState(), Qt::Checked );
530+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->text(), QStringLiteral( "Richard Helm" ) );
531+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 1, 0 )->checkState(), Qt::Unchecked );
532+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->text(), QStringLiteral( "Ralph Johnson" ) );
533+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 2, 0 )->checkState(), Qt::Checked );
534+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->text(), QStringLiteral( "John Vlissides" ) );
535+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 3, 0 )->checkState(), Qt::Unchecked );
536+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->text(), QStringLiteral( "Douglas Adams" ) );
537+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 4, 0 )->checkState(), Qt::Checked );
538+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->text(), QStringLiteral( "Ken Follett" ) );
539+ QCOMPARE( w_favoriteauthors.mTableWidget->item( 5, 0 )->checkState(), Qt::Checked );
540+
541+ // check if stored correctly
542+ vl_json->commitChanges();
543+ QVariantList expected_vl;
544+ expected_vl << 0 << 2 << 4 << 5;
545+ QCOMPARE( vl_json->getFeature( 1 ).attribute( QStringLiteral( "json_content" ) ), expected_vl );
546+ */
547+ }
548+
549+
453550QGSTEST_MAIN ( TestQgsValueRelationWidgetWrapper )
454551#include " testqgsvaluerelationwidgetwrapper.moc"
0 commit comments