Skip to content

Commit

Permalink
Merge pull request #2417 from elpaso/bugfix-11266
Browse files Browse the repository at this point in the history
Bugfix 11266
  • Loading branch information
elpaso committed Nov 4, 2015
2 parents 8187ad5 + 086525b commit 524febe
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 8 deletions.
6 changes: 6 additions & 0 deletions python/gui/attributetable/qgsfeaturelistview.sip
Expand Up @@ -75,6 +75,12 @@ class QgsFeatureListView : QListView
*/
void setCurrentFeatureEdited( bool state );

/**
* @brief setFeatureSelectionManager
* @param featureSelectionManager We will take ownership
*/
void setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager );

protected:
virtual void mouseMoveEvent( QMouseEvent *event );
virtual void mousePressEvent( QMouseEvent *event );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsrelation.cpp
Expand Up @@ -187,6 +187,7 @@ QgsFeatureRequest QgsRelation::getReferencedFeatureRequest( const QgsAttributes&
{
int referencedIdx = referencedLayer()->fields().indexFromName( fieldPair.referencedField() );
int referencingIdx = referencingLayer()->fields().indexFromName( fieldPair.referencingField() );
Q_UNUSED( referencingIdx );

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

Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -412,7 +412,7 @@ void QgsDualView::setRequest( const QgsFeatureRequest& request )
void QgsDualView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager )
{
mTableView->setFeatureSelectionManager( featureSelectionManager );
// mFeatureList->setFeatureSelectionManager( featureSelectionManager );
mFeatureList->setFeatureSelectionManager( featureSelectionManager );

if ( mFeatureSelectionManager && mFeatureSelectionManager->parent() == this )
delete mFeatureSelectionManager;
Expand Down
21 changes: 19 additions & 2 deletions src/gui/attributetable/qgsfeaturelistview.cpp
Expand Up @@ -38,6 +38,7 @@ QgsFeatureListView::QgsFeatureListView( QWidget *parent )
, mModel( 0 )
, mCurrentEditSelectionModel( 0 )
, mFeatureSelectionModel( 0 )
, mFeatureSelectionManager( NULL )
, mItemDelegate( 0 )
, mEditSelectionDrag( false )
, mRowAnchor( 0 )
Expand All @@ -56,10 +57,15 @@ void QgsFeatureListView::setModel( QgsFeatureListModel* featureListModel )
mModel = featureListModel;

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

mCurrentEditSelectionModel = new QItemSelectionModel( mModel->masterModel(), this );
if ( !mFeatureSelectionManager )
{
mFeatureSelectionManager = new QgsVectorLayerSelectionManager( mModel->layerCache()->layer(), mModel );
}

mFeatureSelectionModel = new QgsFeatureSelectionModel( featureListModel, featureListModel, mFeatureSelectionManager, this );
setSelectionModel( mFeatureSelectionModel );

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

connect( mCurrentEditSelectionModel, SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), SLOT( editSelectionChanged( QItemSelection, QItemSelection ) ) );

}

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

mFeatureSelectionModel->selectFeatures( QItemSelection( tl, br ), command );
}

void QgsFeatureListView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager )
{
delete mFeatureSelectionManager;

mFeatureSelectionManager = featureSelectionManager;

if ( mFeatureSelectionModel )
mFeatureSelectionModel->setFeatureSelectionManager( mFeatureSelectionManager );
}
7 changes: 7 additions & 0 deletions src/gui/attributetable/qgsfeaturelistview.h
Expand Up @@ -25,6 +25,7 @@ class QgsAttributeTableFilterModel;
class QgsFeatureListModel;
class QgsFeatureSelectionModel;
class QgsAttributeTableModel;
class QgsIFeatureSelectionManager;
class QgsVectorLayer;
class QgsVectorLayerCache;
class QgsFeatureListViewDelegate;
Expand Down Expand Up @@ -114,6 +115,11 @@ class GUI_EXPORT QgsFeatureListView : public QListView
*/
void setCurrentFeatureEdited( bool state );

/**
* @brief setFeatureSelectionManager
* @param featureSelectionManager We will take ownership
*/
void setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager );
protected:
virtual void mouseMoveEvent( QMouseEvent *event ) override;
virtual void mousePressEvent( QMouseEvent *event ) override;
Expand Down Expand Up @@ -170,6 +176,7 @@ class GUI_EXPORT QgsFeatureListView : public QListView
QgsFeatureListModel *mModel;
QItemSelectionModel* mCurrentEditSelectionModel;
QgsFeatureSelectionModel* mFeatureSelectionModel;
QgsIFeatureSelectionManager* mFeatureSelectionManager;
QgsFeatureListViewDelegate* mItemDelegate;
bool mEditSelectionDrag; // Is set to true when the user initiated a left button click over an edit button and still keeps pressing /**< TODO */
int mRowAnchor;
Expand Down
4 changes: 3 additions & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -245,8 +245,10 @@ void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
if ( !mReferencedLayer )
return;

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

QgsFeatureRequest request = mRelation.getReferencedFeatureRequest( attrs );

Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidget.h
Expand Up @@ -146,6 +146,7 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
QgsMessageBar* mMessageBar;
QVariant mForeignKey;
QgsFeature mFeature;
// Index of the referenced layer key
int mFkeyFieldIdx;
bool mAllowNull;
QgsHighlight* mHighlight;
Expand Down
7 changes: 5 additions & 2 deletions src/gui/qgsfeatureselectiondlg.cpp
Expand Up @@ -17,8 +17,11 @@

#include "qgsgenericfeatureselectionmanager.h"
#include "qgsdistancearea.h"
#include "qgsfeaturerequest.h"
#include "qgsattributeeditorcontext.h"

QgsFeatureSelectionDlg::QgsFeatureSelectionDlg( QgsVectorLayer* vl, QWidget *parent )

QgsFeatureSelectionDlg::QgsFeatureSelectionDlg( QgsVectorLayer* vl, QgsAttributeEditorContext &context, QWidget *parent )
: QDialog( parent )
, mVectorLayer( vl )
{
Expand All @@ -29,7 +32,7 @@ QgsFeatureSelectionDlg::QgsFeatureSelectionDlg( QgsVectorLayer* vl, QWidget *par
mDualView->setFeatureSelectionManager( mFeatureSelection );

// TODO: Proper QgsDistanceArea, proper mapcanvas
mDualView->init( mVectorLayer, NULL );
mDualView->init( mVectorLayer, NULL, QgsFeatureRequest(), context );
}

const QgsFeatureIds& QgsFeatureSelectionDlg::selectedFeatures()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsfeatureselectiondlg.h
Expand Up @@ -25,7 +25,7 @@ class GUI_EXPORT QgsFeatureSelectionDlg : public QDialog, private Ui::QgsFeature
Q_OBJECT

public:
explicit QgsFeatureSelectionDlg( QgsVectorLayer* vl, QWidget *parent = 0 );
explicit QgsFeatureSelectionDlg( QgsVectorLayer* vl, QgsAttributeEditorContext &context, QWidget *parent = 0 );

const QgsFeatureIds& selectedFeatures();

Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsrelationeditorwidget.cpp
Expand Up @@ -219,7 +219,7 @@ void QgsRelationEditorWidget::addFeature()

void QgsRelationEditorWidget::linkFeature()
{
QgsFeatureSelectionDlg selectionDlg( mRelation.referencingLayer(), this );
QgsFeatureSelectionDlg selectionDlg( mRelation.referencingLayer(), mEditorContext , this );

if ( selectionDlg.exec() )
{
Expand Down

0 comments on commit 524febe

Please sign in to comment.