Skip to content
Permalink
Browse files

Merge pull request #2417 from elpaso/bugfix-11266

Bugfix 11266
  • Loading branch information
elpaso committed Nov 4, 2015
2 parents 8187ad5 + 086525b commit 524febe070832619661757c34f544f77c16ed0c7
@@ -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 );
@@ -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 );

@@ -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;
@@ -38,6 +38,7 @@ QgsFeatureListView::QgsFeatureListView( QWidget *parent )
, mModel( 0 )
, mCurrentEditSelectionModel( 0 )
, mFeatureSelectionModel( 0 )
, mFeatureSelectionManager( NULL )
, mItemDelegate( 0 )
, mEditSelectionDrag( false )
, mRowAnchor( 0 )
@@ -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 )
{
@@ -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 )
@@ -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 );
}
@@ -25,6 +25,7 @@ class QgsAttributeTableFilterModel;
class QgsFeatureListModel;
class QgsFeatureSelectionModel;
class QgsAttributeTableModel;
class QgsIFeatureSelectionManager;
class QgsVectorLayer;
class QgsVectorLayerCache;
class QgsFeatureListViewDelegate;
@@ -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;
@@ -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;
@@ -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 );

@@ -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;
@@ -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 )
{
@@ -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()
@@ -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();

@@ -219,7 +219,7 @@ void QgsRelationEditorWidget::addFeature()

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

if ( selectionDlg.exec() )
{

0 comments on commit 524febe

Please sign in to comment.
You can’t perform that action at this time.