mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-10-31 00:06:02 -04:00 
			
		
		
		
	Merge pull request #10047 from elpaso/bugfix-22071-relation-reference-identify-on-map
Fix identify on map in relation reference widget
This commit is contained in:
		
						commit
						86f35e8beb
					
				| @ -72,7 +72,7 @@ determines if the foreign key is shown in a combox box or a read-only line edit | |||||||
| 
 | 
 | ||||||
|     bool allowMapIdentification(); |     bool allowMapIdentification(); | ||||||
| %Docstring | %Docstring | ||||||
| determines if the widge offers the possibility to select the related feature on the map (using a dedicated map tool) | determines if the widget offers the possibility to select the related feature on the map (using a dedicated map tool) | ||||||
| %End | %End | ||||||
|     void setAllowMapIdentification( bool allowMapIdentification ); |     void setAllowMapIdentification( bool allowMapIdentification ); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -41,7 +41,7 @@ | |||||||
| #include "qgsfeatureiterator.h" | #include "qgsfeatureiterator.h" | ||||||
| #include "qgsfeaturelistcombobox.h" | #include "qgsfeaturelistcombobox.h" | ||||||
| #include "qgsexpressioncontextutils.h" | #include "qgsexpressioncontextutils.h" | ||||||
| 
 | #include "qgsfeaturefiltermodel.h" | ||||||
| 
 | 
 | ||||||
| QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget *parent ) | QgsRelationReferenceWidget::QgsRelationReferenceWidget( QWidget *parent ) | ||||||
|   : QWidget( parent ) |   : QWidget( parent ) | ||||||
| @ -746,7 +746,7 @@ void QgsRelationReferenceWidget::featureIdentified( const QgsFeature &feature ) | |||||||
|   } |   } | ||||||
|   else |   else | ||||||
|   { |   { | ||||||
|     mComboBox->setCurrentIndex( mComboBox->findData( feature.id(), QgsAttributeTableModel::FeatureIdRole ) ); |     mComboBox->setCurrentIndex( mComboBox->findData( feature.attribute( mReferencedFieldIdx ), QgsFeatureFilterModel::Role::IdentifierValueRole ) ); | ||||||
|     mFeature = feature; |     mFeature = feature; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -99,7 +99,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget | |||||||
|     bool readOnlySelector() { return mReadOnlySelector; } |     bool readOnlySelector() { return mReadOnlySelector; } | ||||||
|     void setReadOnlySelector( bool readOnly ); |     void setReadOnlySelector( bool readOnly ); | ||||||
| 
 | 
 | ||||||
|     //! determines if the widge offers the possibility to select the related feature on the map (using a dedicated map tool)
 |     //! determines if the widget offers the possibility to select the related feature on the map (using a dedicated map tool)
 | ||||||
|     bool allowMapIdentification() { return mAllowMapIdentification; } |     bool allowMapIdentification() { return mAllowMapIdentification; } | ||||||
|     void setAllowMapIdentification( bool allowMapIdentification ); |     void setAllowMapIdentification( bool allowMapIdentification ); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -47,6 +47,7 @@ class TestQgsRelationReferenceWidget : public QObject | |||||||
|     void testChainFilterDeleteForeignKey(); |     void testChainFilterDeleteForeignKey(); | ||||||
|     void testInvalidRelation(); |     void testInvalidRelation(); | ||||||
|     void testSetGetForeignKey(); |     void testSetGetForeignKey(); | ||||||
|  |     void testIdentifyOnMap(); | ||||||
| 
 | 
 | ||||||
|   private: |   private: | ||||||
|     std::unique_ptr<QgsVectorLayer> mLayer1; |     std::unique_ptr<QgsVectorLayer> mLayer1; | ||||||
| @ -340,5 +341,38 @@ void TestQgsRelationReferenceWidget::testSetGetForeignKey() | |||||||
|   QCOMPARE( spy.count(), 3 ); |   QCOMPARE( spy.count(), 3 ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | // Test issue https://issues.qgis.org/issues/22071
 | ||||||
|  | // Relation reference widget wrong feature when "on map identification"
 | ||||||
|  | void TestQgsRelationReferenceWidget::testIdentifyOnMap() | ||||||
|  | { | ||||||
|  |   QWidget parentWidget; | ||||||
|  |   QgsRelationReferenceWidget w( &parentWidget ); | ||||||
|  |   QVERIFY( mLayer1->startEditing() ); | ||||||
|  |   w.setRelation( *mRelation, true ); | ||||||
|  |   w.setAllowMapIdentification( true ); | ||||||
|  |   w.init(); | ||||||
|  |   QEventLoop loop; | ||||||
|  |   // Populate model (I tried to listen to signals but the module reload() runs twice
 | ||||||
|  |   // (the first load triggers a second one which does the population of the combo)
 | ||||||
|  |   // and I haven't fin a way to properly wait for it.
 | ||||||
|  |   QTimer::singleShot( 300, [&] { loop.quit(); } ); | ||||||
|  |   loop.exec(); | ||||||
|  |   QgsFeature feature; | ||||||
|  |   mLayer2->getFeatures( QStringLiteral( "pk = %1" ).arg( 11 ) ).nextFeature( feature ); | ||||||
|  |   QVERIFY( feature.isValid() ); | ||||||
|  |   QCOMPARE( feature.attribute( QStringLiteral( "pk" ) ).toInt(), 11 ); | ||||||
|  |   w.featureIdentified( feature ); | ||||||
|  |   QCOMPARE( w.mComboBox->currentData( Qt::DisplayRole ).toInt(), 11 ); | ||||||
|  | 
 | ||||||
|  |   mLayer2->getFeatures( QStringLiteral( "pk = %1" ).arg( 10 ) ).nextFeature( feature ); | ||||||
|  |   QVERIFY( feature.isValid() ); | ||||||
|  |   QCOMPARE( feature.attribute( QStringLiteral( "pk" ) ).toInt(), 10 ); | ||||||
|  |   w.featureIdentified( feature ); | ||||||
|  |   QCOMPARE( w.mComboBox->currentData( Qt::DisplayRole ).toInt(), 10 ); | ||||||
|  | 
 | ||||||
|  |   mLayer1->rollBack(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| QGSTEST_MAIN( TestQgsRelationReferenceWidget ) | QGSTEST_MAIN( TestQgsRelationReferenceWidget ) | ||||||
| #include "testqgsrelationreferencewidget.moc" | #include "testqgsrelationreferencewidget.moc" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user