Skip to content
Permalink
Browse files

split the disconnecting and connecting on filtermodel change to metho…

…ds, so the disconnect can be called on qgsdualview before the reload of the layer without doing an invalidate() (called in setFilterMode of the qgsattributetablefiltermodel)
  • Loading branch information
signedav committed May 11, 2020
1 parent 99bbf4a commit c6823d8dd465379daa6602c97d74a57ebc6531cf
@@ -92,6 +92,16 @@ Gets a list of currently filtered feature ids
Set the filter mode the filter will use.

:param filterMode: Sets the current mode of the filter
%End

void disconnectFilterModeConnections();
%Docstring
Disconnect the connections set for the current filterMode
%End

void connectFilterModeConnections( FilterMode filterMode );
%Docstring
Disconnect the connections set for the new ``filterMode``
%End

FilterMode filterMode();
@@ -323,54 +323,58 @@ void QgsAttributeTableFilterModel::setFilterMode( FilterMode filterMode )
{
if ( filterMode != mFilterMode )
{
// cleanup existing connections
switch ( mFilterMode )
{
case ShowVisible:
disconnect( mCanvas, &QgsMapCanvas::extentsChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
disconnect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
disconnect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
disconnect( mTableModel, &QgsAttributeTableModel::finished, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
break;
case ShowAll:
case ShowEdited:
case ShowSelected:
break;
case ShowFilteredList:
disconnect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedFilterFeatures );
disconnect( mTableModel, &QgsAttributeTableModel::finished, this, &QgsAttributeTableFilterModel::startTimedFilterFeatures );
disconnect( layer(), &QgsVectorLayer::attributeValueChanged, this, &QgsAttributeTableFilterModel::onAttributeValueChanged );
disconnect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::onGeometryChanged );
break;
}

// setup new connections
switch ( filterMode )
{
case ShowVisible:
connect( mCanvas, &QgsMapCanvas::extentsChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
connect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
connect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
connect( mTableModel, &QgsAttributeTableModel::finished, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
generateListOfVisibleFeatures();
break;
case ShowAll:
case ShowEdited:
case ShowSelected:
break;
case ShowFilteredList:
connect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedFilterFeatures );
connect( mTableModel, &QgsAttributeTableModel::finished, this, &QgsAttributeTableFilterModel::startTimedFilterFeatures );
connect( layer(), &QgsVectorLayer::attributeValueChanged, this, &QgsAttributeTableFilterModel::onAttributeValueChanged );
connect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::onGeometryChanged );
break;
}

disconnectFilterModeConnections();
connectFilterModeConnections( filterMode );
mFilterMode = filterMode;
invalidateFilter();
}
}

void QgsAttributeTableFilterModel::disconnectFilterModeConnections()
{
// cleanup existing connections
switch ( mFilterMode )
{
case ShowVisible:
disconnect( mCanvas, &QgsMapCanvas::extentsChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
disconnect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
disconnect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
break;
case ShowAll:
case ShowEdited:
case ShowSelected:
break;
case ShowFilteredList:
disconnect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedFilterFeatures );
disconnect( layer(), &QgsVectorLayer::attributeValueChanged, this, &QgsAttributeTableFilterModel::onAttributeValueChanged );
disconnect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::onGeometryChanged );
break;
}
}

void QgsAttributeTableFilterModel::connectFilterModeConnections( QgsAttributeTableFilterModel::FilterMode filterMode )
{
// setup new connections
switch ( filterMode )
{
case ShowVisible:
connect( mCanvas, &QgsMapCanvas::extentsChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
connect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
connect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::startTimedReloadVisible );
generateListOfVisibleFeatures();
break;
case ShowAll:
case ShowEdited:
case ShowSelected:
break;
case ShowFilteredList:
connect( layer(), &QgsVectorLayer::featureAdded, this, &QgsAttributeTableFilterModel::startTimedFilterFeatures );
connect( layer(), &QgsVectorLayer::attributeValueChanged, this, &QgsAttributeTableFilterModel::onAttributeValueChanged );
connect( layer(), &QgsVectorLayer::geometryChanged, this, &QgsAttributeTableFilterModel::onGeometryChanged );
break;
}
}

bool QgsAttributeTableFilterModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
{
Q_UNUSED( sourceParent )
@@ -127,6 +127,16 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
*/
void setFilterMode( FilterMode filterMode );

/**
* Disconnect the connections set for the current filterMode
*/
void disconnectFilterModeConnections();

/**
* Disconnect the connections set for the new \a filterMode
*/
void connectFilterModeConnections( FilterMode filterMode );

/**
* The current filterModel
*/
@@ -293,7 +293,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
case QgsAttributeTableFilterModel::ShowAll:
case QgsAttributeTableFilterModel::ShowEdited:
case QgsAttributeTableFilterModel::ShowFilteredList:
disconnect( mFilterModel, &QgsAttributeTableFilterModel::featuresFiltered, this, &QgsDualView::filterChanged );
connect( mFilterModel, &QgsAttributeTableFilterModel::featuresFiltered, this, &QgsDualView::filterChanged );
break;

case QgsAttributeTableFilterModel::ShowSelected:
@@ -317,16 +317,18 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
break;
}

//update filter model
mFilterModel->setFilterMode( filterMode );

if ( requiresTableReload )
{
//disconnect the connections of the current (old) filtermode before reload
mFilterModel->disconnectFilterModeConnections();

mMasterModel->setRequest( r );
whileBlocking( mLayerCache )->setCacheGeometry( needsGeometry );
mMasterModel->loadLayer();
}

//update filter model
mFilterModel->setFilterMode( filterMode );
emit filterChanged();
}

0 comments on commit c6823d8

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