|
32 | 32 | #include "qgsgui.h"
|
33 | 33 | #include "qgseditorwidgetregistry.h"
|
34 | 34 |
|
| 35 | +#include <QSignalSpy> |
| 36 | + |
35 | 37 | /**
|
36 | 38 | * \ingroup UnitTests
|
37 | 39 | * This is a unit test for the attribute table dialog
|
@@ -66,6 +68,7 @@ class TestQgsAttributeTable : public QObject
|
66 | 68 | void testStartMultiEditNoChanges();
|
67 | 69 | void testMultiEditMakeUncommittedChanges();
|
68 | 70 | void testInvalidView();
|
| 71 | + void testEnsureEditSelection(); |
69 | 72 |
|
70 | 73 | private:
|
71 | 74 | QgisApp *mQgisApp = nullptr;
|
@@ -830,5 +833,68 @@ void TestQgsAttributeTable::testInvalidView()
|
830 | 833 | QCOMPARE( dlg->mMainView->filteredFeatures(), QgsFeatureIds() << 1 << 3 );
|
831 | 834 | }
|
832 | 835 |
|
| 836 | +void TestQgsAttributeTable::testEnsureEditSelection() |
| 837 | +{ |
| 838 | + std::unique_ptr< QgsVectorLayer > layer = std::make_unique< QgsVectorLayer >( QStringLiteral( "Point?field=col0:integer&field=col1:integer" ), QStringLiteral( "test" ), QStringLiteral( "memory" ) ); |
| 839 | + QVERIFY( layer->isValid() ); |
| 840 | + |
| 841 | + QgsFeature ft1( layer->dataProvider()->fields(), 1 ); |
| 842 | + ft1.setAttributes( QgsAttributes() << 1 << 2 ); |
| 843 | + layer->dataProvider()->addFeature( ft1 ); |
| 844 | + QgsFeature ft2( layer->dataProvider()->fields(), 2 ); |
| 845 | + ft2.setAttributes( QgsAttributes() << 3 << 4 ); |
| 846 | + layer->dataProvider()->addFeature( ft2 ); |
| 847 | + QgsFeature ft3( layer->dataProvider()->fields(), 3 ); |
| 848 | + ft3.setAttributes( QgsAttributes() << 5 << 6 ); |
| 849 | + layer->dataProvider()->addFeature( ft3 ); |
| 850 | + QgsFeature ft4( layer->dataProvider()->fields(), 4 ); |
| 851 | + ft4.setAttributes( QgsAttributes() << 7 << 8 ); |
| 852 | + layer->dataProvider()->addFeature( ft4 ); |
| 853 | + |
| 854 | + layer->removeSelection(); |
| 855 | + |
| 856 | + std::unique_ptr< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( layer.get() ) ); |
| 857 | + |
| 858 | + //since the update is done by timer, we have to wait (at least one millisecond) or until the current edit selection changed |
| 859 | + qRegisterMetaType<QgsFeature>( "QgsFeature&" ); |
| 860 | + QSignalSpy spy( dlg->mMainView->mFeatureListView, &QgsFeatureListView::currentEditSelectionChanged ); |
| 861 | + |
| 862 | + // we set the index to ft3 |
| 863 | + dlg->mMainView->setCurrentEditSelection( {ft3.id()} ); |
| 864 | + // ... and the currentEditSelection is on ft3 |
| 865 | + QVERIFY( dlg->mMainView->mFeatureListView->currentEditSelection().contains( 3 ) ); |
| 866 | + |
| 867 | + // we make a featureselection on ft1, ft2 and ft3 |
| 868 | + layer->selectByIds( QgsFeatureIds() << 1 << 2 << 3 ); |
| 869 | + spy.wait( 1 ); |
| 870 | + // ... and the currentEditSelection stays on ft3 (since it's in the featureselection) |
| 871 | + QVERIFY( dlg->mMainView->mFeatureListView->currentEditSelection().contains( 3 ) ); |
| 872 | + |
| 873 | + // we release the featureselection |
| 874 | + layer->removeSelection(); |
| 875 | + spy.wait( 1 ); |
| 876 | + // ... and the currentEditSelection persists on 3 (since it does not make an update) |
| 877 | + QVERIFY( dlg->mMainView->mFeatureListView->currentEditSelection().contains( 3 ) ); |
| 878 | + |
| 879 | + // we make afeatureselection on ft4 |
| 880 | + layer->selectByIds( QgsFeatureIds() << 4 ); |
| 881 | + spy.wait( 1 ); |
| 882 | + // ... and the currentEditSelection goes to ft4 |
| 883 | + QVERIFY( dlg->mMainView->mFeatureListView->currentEditSelection().contains( 4 ) ); |
| 884 | + |
| 885 | + // we make afeatureselection on ft2 and ft3 |
| 886 | + layer->selectByIds( QgsFeatureIds() << 2 << 3 ); |
| 887 | + spy.wait( 1 ); |
| 888 | + // ... and the currentEditSelection goes to the first one of the featureselection (means ft2) |
| 889 | + QVERIFY( dlg->mMainView->mFeatureListView->currentEditSelection().contains( 2 ) ); |
| 890 | + |
| 891 | + // we reload the layer |
| 892 | + layer->reload(); |
| 893 | + spy.wait( 1 ); |
| 894 | + // ... and the currentEditSelection jumps to the first one (instead of staying at 2, since it's NOT persistend) |
| 895 | + QVERIFY( dlg->mMainView->mFeatureListView->currentEditSelection().contains( 1 ) ); |
| 896 | + |
| 897 | +} |
| 898 | + |
833 | 899 | QGSTEST_MAIN( TestQgsAttributeTable )
|
834 | 900 | #include "testqgsattributetable.moc"
|
1 commit comments
jef-n commentedon Mar 3, 2023
Hey, don't merge when the release is ongoing. Esp. when there are quotes in the release name…