Skip to content
Permalink
Browse files

fix ownership issues in dualview/attributetable (#34413)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
qgis-bot and github-actions committed Feb 11, 2020
1 parent 34acc14 commit eb1908918460720c6a32865b3d92c63928f448c6
@@ -32,11 +32,11 @@ Constructor for QgsAttributeTableView

virtual void setModel( QgsAttributeTableFilterModel *filterModel );

void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager /Transfer/ );
void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
%Docstring
setFeatureSelectionManager

:param featureSelectionManager: We will take ownership
:param featureSelectionManager:
%End

virtual bool eventFilter( QObject *object, QEvent *event );
@@ -92,11 +92,11 @@ Sets if the currently shown form has received any edit events so far.
:param state: The state
%End

void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager /Transfer/ );
void setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager );
%Docstring
setFeatureSelectionManager

:param featureSelectionManager: We will take ownership
:param featureSelectionManager:
%End

protected:
@@ -148,7 +148,8 @@ void QgsAttributeTableView::setModel( QgsAttributeTableFilterModel *filterModel
{
if ( !mFeatureSelectionManager )
{
mFeatureSelectionManager = new QgsVectorLayerSelectionManager( mFilterModel->layer(), mFilterModel );
mOwnedFeatureSelectionManager = new QgsVectorLayerSelectionManager( mFilterModel->layer(), this );
mFeatureSelectionManager = mOwnedFeatureSelectionManager;
}

mFeatureSelectionModel = new QgsFeatureSelectionModel( mFilterModel, mFilterModel, mFeatureSelectionManager, mFilterModel );
@@ -167,12 +168,17 @@ void QgsAttributeTableView::setModel( QgsAttributeTableFilterModel *filterModel

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

mFeatureSelectionManager = featureSelectionManager;

if ( mFeatureSelectionModel )
mFeatureSelectionModel->setFeatureSelectionManager( mFeatureSelectionManager );

// only delete the owner selection manager and not one created from outside
if ( mOwnedFeatureSelectionManager )
{
mOwnedFeatureSelectionManager->deleteLater();
mOwnedFeatureSelectionManager = nullptr;
}
}

QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
@@ -58,9 +58,9 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView

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

/**
* This event filter is installed on the verticalHeader to intercept mouse press and release
@@ -181,6 +181,7 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView
void selectRow( int row, bool anchor );
QgsAttributeTableFilterModel *mFilterModel = nullptr;
QgsFeatureSelectionModel *mFeatureSelectionModel = nullptr;
QgsIFeatureSelectionManager *mOwnedFeatureSelectionManager = nullptr;
QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
QgsAttributeTableDelegate *mTableDelegate = nullptr;
QMenu *mActionPopup = nullptr;
@@ -54,7 +54,8 @@ void QgsFeatureListView::setModel( QgsFeatureListModel *featureListModel )
mCurrentEditSelectionModel = new QItemSelectionModel( mModel->masterModel(), this );
if ( !mFeatureSelectionManager )
{
mFeatureSelectionManager = new QgsVectorLayerSelectionManager( mModel->layerCache()->layer(), mModel );
mOwnedFeatureSelectionManager = new QgsVectorLayerSelectionManager( mModel->layerCache()->layer(), mModel );
mFeatureSelectionManager = mOwnedFeatureSelectionManager;
}

mFeatureSelectionModel = new QgsFeatureSelectionModel( featureListModel, featureListModel, mFeatureSelectionManager, this );
@@ -461,10 +462,15 @@ void QgsFeatureListView::ensureEditSelection( bool inSelection )

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

mFeatureSelectionManager = featureSelectionManager;

if ( mFeatureSelectionModel )
mFeatureSelectionModel->setFeatureSelectionManager( mFeatureSelectionManager );

// only delete the owner selection manager and not one created from outside
if ( mOwnedFeatureSelectionManager )
{
mOwnedFeatureSelectionManager->deleteLater();
mOwnedFeatureSelectionManager = nullptr;
}
}
@@ -117,9 +117,9 @@ class GUI_EXPORT QgsFeatureListView : public QListView

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

protected:
void mouseMoveEvent( QMouseEvent *event ) override;
@@ -239,6 +239,7 @@ class GUI_EXPORT QgsFeatureListView : public QListView
QgsFeatureListModel *mModel = nullptr;
QItemSelectionModel *mCurrentEditSelectionModel = nullptr;
QgsFeatureSelectionModel *mFeatureSelectionModel = nullptr;
QgsIFeatureSelectionManager *mOwnedFeatureSelectionManager = nullptr;
QgsIFeatureSelectionManager *mFeatureSelectionManager = nullptr;
QgsFeatureListViewDelegate *mItemDelegate = nullptr;
bool mEditSelectionDrag = false; // Is set to true when the user initiated a left button click over an edit button and still keeps pressing //!< TODO
@@ -155,6 +155,9 @@ void QgsFeatureSelectionModel::selectFeatures( const QItemSelection &selection,

void QgsFeatureSelectionModel::setFeatureSelectionManager( QgsIFeatureSelectionManager *featureSelectionManager )
{
if ( mFeatureSelectionManager )
disconnect( mFeatureSelectionManager, &QgsIFeatureSelectionManager::selectionChanged, this, &QgsFeatureSelectionModel::layerSelectionChanged );

mFeatureSelectionManager = featureSelectionManager;

connect( mFeatureSelectionManager, &QgsIFeatureSelectionManager::selectionChanged, this, &QgsFeatureSelectionModel::layerSelectionChanged );

0 comments on commit eb19089

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