mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Implemented setFeatureSelectionManager in QgsListView
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
This commit is contained in:
parent
93bd825e1e
commit
ba4895defd
@ -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 );
|
||||
|
||||
|
@ -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,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 );
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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() )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user