Skip to content
Permalink
Browse files

Force reset of layer tree view when snapping scale mode is changed. G…

…et rid of the ugly hack forcing the refresh of the rows when the mode was changed. This should fix two bugs with scale combox and min and max column being disabled when they should not. Should fix #35789.
  • Loading branch information
obrix authored and mhugo committed Apr 15, 2020
1 parent 44fec55 commit 5a1d10b1705dfb2c059c370f75c89cd5b0c4e174
Showing with 8 additions and 10 deletions.
  1. +5 −8 src/app/qgssnappinglayertreemodel.cpp
  2. +1 −2 src/app/qgssnappinglayertreemodel.h
  3. +2 −0 src/app/qgssnappingwidget.cpp
@@ -238,7 +238,6 @@ QgsSnappingLayerTreeModel::QgsSnappingLayerTreeModel( QgsProject *project, QgsMa
, mProject( project )
, mCanvas( canvas )
, mIndividualLayerSettings( project->snappingConfig().individualLayerSettings() )
, mEnableMinMaxColumn( project->snappingConfig().scaleDependencyMode() == QgsSnappingConfig::PerLayer )

{
connect( project, &QgsProject::snappingConfigChanged, this, &QgsSnappingLayerTreeModel::onSnappingSettingsChanged );
@@ -281,7 +280,7 @@ Qt::ItemFlags QgsSnappingLayerTreeModel::flags( const QModelIndex &idx ) const
}
else if ( idx.column() == MaxScaleColumn || idx.column() == MinScaleColumn )
{
if ( mEnableMinMaxColumn )
if ( mProject->snappingConfig().scaleDependencyMode() == QgsSnappingConfig::PerLayer )
{
return Qt::ItemIsEnabled | Qt::ItemIsEditable;
}
@@ -345,7 +344,6 @@ void QgsSnappingLayerTreeModel::setFilterText( const QString &filterText )
void QgsSnappingLayerTreeModel::onSnappingSettingsChanged()
{
const QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> oldSettings = mIndividualLayerSettings;
bool wasMinMaxEnabled = mEnableMinMaxColumn;

for ( auto it = oldSettings.constBegin(); it != oldSettings.constEnd(); ++it )
{
@@ -369,18 +367,17 @@ void QgsSnappingLayerTreeModel::onSnappingSettingsChanged()
}
}

mEnableMinMaxColumn = ( mProject->snappingConfig().scaleDependencyMode() == QgsSnappingConfig::PerLayer );
hasRowchanged( mLayerTreeModel->rootGroup(), oldSettings, wasMinMaxEnabled != mEnableMinMaxColumn );
hasRowchanged( mLayerTreeModel->rootGroup(), oldSettings );
}

void QgsSnappingLayerTreeModel::hasRowchanged( QgsLayerTreeNode *node, const QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> &oldSettings, bool forceRefresh )
void QgsSnappingLayerTreeModel::hasRowchanged( QgsLayerTreeNode *node, const QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> &oldSettings )
{
if ( node->nodeType() == QgsLayerTreeNode::NodeGroup )
{
const auto constChildren = node->children();
for ( QgsLayerTreeNode *child : constChildren )
{
hasRowchanged( child, oldSettings, forceRefresh );
hasRowchanged( child, oldSettings );
}
}
else
@@ -391,7 +388,7 @@ void QgsSnappingLayerTreeModel::hasRowchanged( QgsLayerTreeNode *node, const QHa
{
emit dataChanged( QModelIndex(), idx );
}
if ( oldSettings.value( vl ) != mProject->snappingConfig().individualLayerSettings().value( vl ) || forceRefresh )
if ( oldSettings.value( vl ) != mProject->snappingConfig().individualLayerSettings().value( vl ) )
{
mIndividualLayerSettings.insert( vl, mProject->snappingConfig().individualLayerSettings().value( vl ) );
emit dataChanged( idx, index( idx.row(), columnCount( idx ) - 1 ) );
@@ -95,9 +95,8 @@ class APP_EXPORT QgsSnappingLayerTreeModel : public QSortFilterProxyModel
QString mFilterText;
QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> mIndividualLayerSettings;
QgsLayerTreeModel *mLayerTreeModel = nullptr;
bool mEnableMinMaxColumn = true;

void hasRowchanged( QgsLayerTreeNode *node, const QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> &oldSettings, bool forceRefresh );
void hasRowchanged( QgsLayerTreeNode *node, const QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> &oldSettings );
};

#endif // QGSSNAPPINGLAYERTREEVIEW_H
@@ -707,6 +707,8 @@ void QgsSnappingWidget::snappingScaleModeTriggered( QAction *action )
mMaxScaleWidget->setEnabled( mode == QgsSnappingConfig::Global );
mConfig.setScaleDependencyMode( mode );
mProject->setSnappingConfig( mConfig );

mLayerTreeView->reset();
}

void QgsSnappingWidget::updateToleranceDecimals()

0 comments on commit 5a1d10b

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