Skip to content

Commit

Permalink
Implemented setFeatureSelectionManager in QgsListView
Browse files Browse the repository at this point in the history
Partially fixes #11266

 * now passing editor context to QgsFeatureSelectionDlg
   (otherwise fails on assert parentContext.vectorLayerTools())
 * still crashes at the provider level after saving
 * unlink still doesn't work
  • Loading branch information
elpaso committed Nov 4, 2015
1 parent 93bd825 commit ba4895d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsrelation.cpp
Expand Up @@ -187,7 +187,7 @@ QgsFeatureRequest QgsRelation::getReferencedFeatureRequest( const QgsAttributes&
{
int referencedIdx = referencedLayer()->fields().indexFromName( fieldPair.referencedField() );
int referencingIdx = referencingLayer()->fields().indexFromName( fieldPair.referencingField() );
Q_UNUSED(referencingIdx);
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
22 changes: 20 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,14 @@ void QgsFeatureListView::selectRow( const QModelIndex& index, bool anchor )

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

void QgsFeatureListView::setFeatureSelectionManager( QgsIFeatureSelectionManager* featureSelectionManager )
{
if ( mFeatureSelectionManager )
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
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 ba4895d

Please sign in to comment.