Skip to content

Commit 524febe

Browse files
committed
Merge pull request #2417 from elpaso/bugfix-11266
Bugfix 11266
2 parents 8187ad5 + 086525b commit 524febe

File tree

10 files changed

+45
-8
lines changed

10 files changed

+45
-8
lines changed

python/gui/attributetable/qgsfeaturelistview.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class QgsFeatureListView : QListView
7575
*/
7676
void setCurrentFeatureEdited( bool state );
7777

78+
/**
79+
* @brief setFeatureSelectionManager
80+
* @param featureSelectionManager We will take ownership
81+
*/
82+
void setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager );
83+
7884
protected:
7985
virtual void mouseMoveEvent( QMouseEvent *event );
8086
virtual void mousePressEvent( QMouseEvent *event );

src/core/qgsrelation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ QgsFeatureRequest QgsRelation::getReferencedFeatureRequest( const QgsAttributes&
187187
{
188188
int referencedIdx = referencedLayer()->fields().indexFromName( fieldPair.referencedField() );
189189
int referencingIdx = referencingLayer()->fields().indexFromName( fieldPair.referencingField() );
190+
Q_UNUSED( referencingIdx );
190191

191192
QgsField referencedField = referencedLayer()->fields().at( referencedIdx );
192193

src/gui/attributetable/qgsdualview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void QgsDualView::setRequest( const QgsFeatureRequest& request )
412412
void QgsDualView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager )
413413
{
414414
mTableView->setFeatureSelectionManager( featureSelectionManager );
415-
// mFeatureList->setFeatureSelectionManager( featureSelectionManager );
415+
mFeatureList->setFeatureSelectionManager( featureSelectionManager );
416416

417417
if ( mFeatureSelectionManager && mFeatureSelectionManager->parent() == this )
418418
delete mFeatureSelectionManager;

src/gui/attributetable/qgsfeaturelistview.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ QgsFeatureListView::QgsFeatureListView( QWidget *parent )
3838
, mModel( 0 )
3939
, mCurrentEditSelectionModel( 0 )
4040
, mFeatureSelectionModel( 0 )
41+
, mFeatureSelectionManager( NULL )
4142
, mItemDelegate( 0 )
4243
, mEditSelectionDrag( false )
4344
, mRowAnchor( 0 )
@@ -56,10 +57,15 @@ void QgsFeatureListView::setModel( QgsFeatureListModel* featureListModel )
5657
mModel = featureListModel;
5758

5859
delete mFeatureSelectionModel;
59-
mFeatureSelectionModel = new QgsFeatureSelectionModel( featureListModel, featureListModel, new QgsVectorLayerSelectionManager( featureListModel->layerCache()->layer(), this ), this );
60-
setSelectionModel( mFeatureSelectionModel );
6160

6261
mCurrentEditSelectionModel = new QItemSelectionModel( mModel->masterModel(), this );
62+
if ( !mFeatureSelectionManager )
63+
{
64+
mFeatureSelectionManager = new QgsVectorLayerSelectionManager( mModel->layerCache()->layer(), mModel );
65+
}
66+
67+
mFeatureSelectionModel = new QgsFeatureSelectionModel( featureListModel, featureListModel, mFeatureSelectionManager, this );
68+
setSelectionModel( mFeatureSelectionModel );
6369

6470
if ( mItemDelegate && mItemDelegate->parent() == this )
6571
{
@@ -75,6 +81,7 @@ void QgsFeatureListView::setModel( QgsFeatureListModel* featureListModel )
7581
connect( mFeatureSelectionModel, SIGNAL( requestRepaint() ), this, SLOT( repaintRequested() ) );
7682

7783
connect( mCurrentEditSelectionModel, SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( editSelectionChanged( QItemSelection, QItemSelection ) ) );
84+
7885
}
7986

8087
bool QgsFeatureListView::setDisplayExpression( const QString& expression )
@@ -338,3 +345,13 @@ void QgsFeatureListView::selectRow( const QModelIndex& index, bool anchor )
338345

339346
mFeatureSelectionModel->selectFeatures( QItemSelection( tl, br ), command );
340347
}
348+
349+
void QgsFeatureListView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager )
350+
{
351+
delete mFeatureSelectionManager;
352+
353+
mFeatureSelectionManager = featureSelectionManager;
354+
355+
if ( mFeatureSelectionModel )
356+
mFeatureSelectionModel->setFeatureSelectionManager( mFeatureSelectionManager );
357+
}

src/gui/attributetable/qgsfeaturelistview.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class QgsAttributeTableFilterModel;
2525
class QgsFeatureListModel;
2626
class QgsFeatureSelectionModel;
2727
class QgsAttributeTableModel;
28+
class QgsIFeatureSelectionManager;
2829
class QgsVectorLayer;
2930
class QgsVectorLayerCache;
3031
class QgsFeatureListViewDelegate;
@@ -114,6 +115,11 @@ class GUI_EXPORT QgsFeatureListView : public QListView
114115
*/
115116
void setCurrentFeatureEdited( bool state );
116117

118+
/**
119+
* @brief setFeatureSelectionManager
120+
* @param featureSelectionManager We will take ownership
121+
*/
122+
void setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager );
117123
protected:
118124
virtual void mouseMoveEvent( QMouseEvent *event ) override;
119125
virtual void mousePressEvent( QMouseEvent *event ) override;
@@ -170,6 +176,7 @@ class GUI_EXPORT QgsFeatureListView : public QListView
170176
QgsFeatureListModel *mModel;
171177
QItemSelectionModel* mCurrentEditSelectionModel;
172178
QgsFeatureSelectionModel* mFeatureSelectionModel;
179+
QgsIFeatureSelectionManager* mFeatureSelectionManager;
173180
QgsFeatureListViewDelegate* mItemDelegate;
174181
bool mEditSelectionDrag; // Is set to true when the user initiated a left button click over an edit button and still keeps pressing /**< TODO */
175182
int mRowAnchor;

src/gui/editorwidgets/qgsrelationreferencewidget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
245245
if ( !mReferencedLayer )
246246
return;
247247

248+
// Attributes from the referencing layer
248249
QgsAttributes attrs = QgsAttributes( mReferencingLayer->fields().count() );
249-
attrs[mFkeyFieldIdx] = value;
250+
// Set the value on the foreign key field of the referencing record
251+
attrs[ mReferencingLayer->fieldNameIndex( mRelation.fieldPairs().at( 0 ).first )] = value;
250252

251253
QgsFeatureRequest request = mRelation.getReferencedFeatureRequest( attrs );
252254

src/gui/editorwidgets/qgsrelationreferencewidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
146146
QgsMessageBar* mMessageBar;
147147
QVariant mForeignKey;
148148
QgsFeature mFeature;
149+
// Index of the referenced layer key
149150
int mFkeyFieldIdx;
150151
bool mAllowNull;
151152
QgsHighlight* mHighlight;

src/gui/qgsfeatureselectiondlg.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717

1818
#include "qgsgenericfeatureselectionmanager.h"
1919
#include "qgsdistancearea.h"
20+
#include "qgsfeaturerequest.h"
21+
#include "qgsattributeeditorcontext.h"
2022

21-
QgsFeatureSelectionDlg::QgsFeatureSelectionDlg( QgsVectorLayer* vl, QWidget *parent )
23+
24+
QgsFeatureSelectionDlg::QgsFeatureSelectionDlg( QgsVectorLayer* vl, QgsAttributeEditorContext &context, QWidget *parent )
2225
: QDialog( parent )
2326
, mVectorLayer( vl )
2427
{
@@ -29,7 +32,7 @@ QgsFeatureSelectionDlg::QgsFeatureSelectionDlg( QgsVectorLayer* vl, QWidget *par
2932
mDualView->setFeatureSelectionManager( mFeatureSelection );
3033

3134
// TODO: Proper QgsDistanceArea, proper mapcanvas
32-
mDualView->init( mVectorLayer, NULL );
35+
mDualView->init( mVectorLayer, NULL, QgsFeatureRequest(), context );
3336
}
3437

3538
const QgsFeatureIds& QgsFeatureSelectionDlg::selectedFeatures()

src/gui/qgsfeatureselectiondlg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GUI_EXPORT QgsFeatureSelectionDlg : public QDialog, private Ui::QgsFeature
2525
Q_OBJECT
2626

2727
public:
28-
explicit QgsFeatureSelectionDlg( QgsVectorLayer* vl, QWidget *parent = 0 );
28+
explicit QgsFeatureSelectionDlg( QgsVectorLayer* vl, QgsAttributeEditorContext &context, QWidget *parent = 0 );
2929

3030
const QgsFeatureIds& selectedFeatures();
3131

src/gui/qgsrelationeditorwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void QgsRelationEditorWidget::addFeature()
219219

220220
void QgsRelationEditorWidget::linkFeature()
221221
{
222-
QgsFeatureSelectionDlg selectionDlg( mRelation.referencingLayer(), this );
222+
QgsFeatureSelectionDlg selectionDlg( mRelation.referencingLayer(), mEditorContext , this );
223223

224224
if ( selectionDlg.exec() )
225225
{

0 commit comments

Comments
 (0)