Skip to content

Commit

Permalink
disable browsing auto pan/scale in attribute table when showing visib…
Browse files Browse the repository at this point in the history
…le features only

fixes #34486
  • Loading branch information
3nids committed Feb 17, 2020
1 parent 9e1db2c commit f1842a3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -301,6 +301,21 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
mMasterModel->loadLayer();
}

// disable the browsing auto pan/scale if the list only shows visible items
switch ( filterMode )
{
case QgsAttributeTableFilterModel::ShowVisible:
setBrowsingAutoPanScaleAllowed( false );
break;

case QgsAttributeTableFilterModel::ShowAll:
case QgsAttributeTableFilterModel::ShowEdited:
case QgsAttributeTableFilterModel::ShowFilteredList:
case QgsAttributeTableFilterModel::ShowSelected:
setBrowsingAutoPanScaleAllowed( true );
break;
}

//update filter model
mFilterModel->setFilterMode( filterMode );
emit filterChanged();
Expand Down Expand Up @@ -464,7 +479,7 @@ void QgsDualView::panOrZoomToFeature( const QgsFeatureIds &featureset )
QgsMapCanvas *canvas = mFilterModel->mapCanvas();
if ( canvas && view() == AttributeEditor && featureset != mLastFeatureSet )
{
if ( filterMode() != QgsAttributeTableFilterModel::ShowVisible )
if ( mBrowsingAutoPanScaleAllowed )
{
if ( mAutoPanButton->isChecked() )
QTimer::singleShot( 0, this, [ = ]()
Expand All @@ -486,6 +501,22 @@ void QgsDualView::panOrZoomToFeature( const QgsFeatureIds &featureset )
}
}

void QgsDualView::setBrowsingAutoPanScaleAllowed( bool allowed )
{
if ( mBrowsingAutoPanScaleAllowed == allowed )
return;

mBrowsingAutoPanScaleAllowed = allowed;

mAutoPanButton->setEnabled( allowed );
mAutoZoomButton->setEnabled( allowed );

QString disabledHint = tr( "(disabled when attribute table ony shows features visible in the current map canvas extent)" );

mAutoPanButton->setToolTip( tr( "Automatically pan to the current feature" ) + ( allowed ? QStringLiteral( "" ) : QStringLiteral( " " ) + disabledHint ) );
mAutoZoomButton->setToolTip( tr( "Automatically zoom to the current feature" ) + ( allowed ? QStringLiteral( "" ) : QStringLiteral( " " ) + disabledHint ) );
}

void QgsDualView::panZoomGroupButtonToggled( QAbstractButton *button, bool checked )
{
if ( button == mAutoPanButton && checked )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/attributetable/qgsdualview.h
Expand Up @@ -387,6 +387,8 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
void insertRecentlyUsedDisplayExpression( const QString &expression );
void updateEditSelectionProgress( int progress, int count );
void panOrZoomToFeature( const QgsFeatureIds &featureset );
//! disable/enable the buttons of the browsing toolbar (feature list view)
void setBrowsingAutoPanScaleAllowed( bool allowed );

QgsFieldConditionalFormatWidget *mConditionalFormatWidget = nullptr;
QgsAttributeEditorContext mEditorContext;
Expand All @@ -409,6 +411,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
// we will temporarily save it in here and set it on init
QgsFeature mTempAttributeFormFeature;
QgsFeatureIds mLastFeatureSet;
bool mBrowsingAutoPanScaleAllowed = true;

friend class TestQgsDualView;
friend class TestQgsAttributeTable;
Expand Down

0 comments on commit f1842a3

Please sign in to comment.