Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix UI and use invalidate rather than reset model
  • Loading branch information
3nids committed Jun 6, 2020
1 parent 558e0b6 commit 09a36c3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 40 deletions.
Expand Up @@ -58,11 +58,6 @@ Rerturns the layer tree model
void setLayerTreeModel( QgsLayerTreeModel *layerTreeModel );
%Docstring
Sets the layer tree model
%End

void resetLayerTreeModel();
%Docstring
This will refresh the model
%End

void setFilters( const QgsMapLayerProxyModel::Filters &filters );
Expand Down
20 changes: 9 additions & 11 deletions src/core/layertree/qgslayertreefilterproxymodel.cpp
Expand Up @@ -22,11 +22,16 @@
QgsLayerTreeFilterProxyModel::QgsLayerTreeFilterProxyModel( QObject *parent )
: QSortFilterProxyModel( parent )
{
connect( QgsProject::instance(), &QgsProject::readProject, this, [ = ] {resetLayerTreeModel();} );
connect( QgsProject::instance(), &QgsProject::readProject, this, [ = ]
{
beginResetModel();
endResetModel();
} );
}

void QgsLayerTreeFilterProxyModel::setCheckedLayers( const QList<QgsMapLayer *> layers )
{
// do not use invalidate() since it's not the filter which changes but the data
beginResetModel();
mCheckedLayers = layers;
endResetModel();
Expand Down Expand Up @@ -101,17 +106,10 @@ void QgsLayerTreeFilterProxyModel::setLayerTreeModel( QgsLayerTreeModel *layerTr
QSortFilterProxyModel::setSourceModel( layerTreeModel );
}

void QgsLayerTreeFilterProxyModel::resetLayerTreeModel()
{
beginResetModel();
endResetModel();
}

void QgsLayerTreeFilterProxyModel::setFilters( const QgsMapLayerProxyModel::Filters &filters )
{
beginResetModel();
mFilters = filters;
endResetModel();
invalidateFilter();
}

bool QgsLayerTreeFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
Expand Down Expand Up @@ -280,9 +278,9 @@ bool QgsLayerTreeFilterProxyModel::setData( const QModelIndex &index, const QVar
return false;
}
if ( value.toInt() == Qt::Checked )
setLayerChecked( layer, true );
setLayerCheckedPrivate( layer, true );
else if ( value.toInt() == Qt::Unchecked )
setLayerChecked( layer, false );
setLayerCheckedPrivate( layer, false );
else
Q_ASSERT( false ); // expected checked or unchecked
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/layertree/qgslayertreefilterproxymodel.h
Expand Up @@ -61,9 +61,6 @@ class CORE_EXPORT QgsLayerTreeFilterProxyModel : public QSortFilterProxyModel
//! Sets the layer tree model
void setLayerTreeModel( QgsLayerTreeModel *layerTreeModel );

//! This will refresh the model
void resetLayerTreeModel();

/**
* Defines the type layers (vector, raster, etc) shown in the tree
* If the list is empty, all types are shown.
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsmaplayerproxymodel.cpp
Expand Up @@ -45,6 +45,9 @@ QgsMapLayerProxyModel *QgsMapLayerProxyModel::setFilters( Filters filters )

bool QgsMapLayerProxyModel::layerMatchesFilters( const QgsMapLayer *layer, const Filters &filters )
{
if ( filters.testFlag( All ) )
return true;

// layer type
if ( ( filters.testFlag( RasterLayer ) && layer->type() == QgsMapLayerType::RasterLayer ) ||
( filters.testFlag( VectorLayer ) && layer->type() == QgsMapLayerType::VectorLayer ) ||
Expand All @@ -61,7 +64,7 @@ bool QgsMapLayerProxyModel::layerMatchesFilters( const QgsMapLayer *layer, const
filters.testFlag( HasGeometry );
if ( detectGeometry && layer->type() == QgsMapLayerType::VectorLayer )
{
if ( QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( layer ) )
if ( const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer ) )
{
if ( filters.testFlag( HasGeometry ) && vl->isSpatial() )
return true;
Expand Down
34 changes: 14 additions & 20 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -363,7 +363,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>18</number>
</property>
<widget class="QWidget" name="mOptsPage_Information">
<layout class="QVBoxLayout" name="verticalLayout_5">
Expand Down Expand Up @@ -439,8 +439,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>679</height>
<width>644</width>
<height>664</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
Expand Down Expand Up @@ -727,8 +727,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>679</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
Expand Down Expand Up @@ -944,8 +944,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>679</height>
<width>199</width>
<height>119</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
Expand Down Expand Up @@ -1339,8 +1339,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>679</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_21">
Expand Down Expand Up @@ -1541,8 +1541,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>673</width>
<height>665</height>
<width>652</width>
<height>368</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_32">
Expand Down Expand Up @@ -1954,7 +1954,7 @@ border-radius: 2px;</string>
</widget>
</item>
<item>
<widget class="QgsLayerTreeView" name="mLayersDependenciesTreeView">
<widget class="QTreeView" name="mLayersDependenciesTreeView">
<property name="enabled">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -2033,8 +2033,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>639</width>
<height>797</height>
<width>644</width>
<height>808</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -2588,12 +2588,6 @@ border-radius: 2px;</string>
<header>qgsfieldexpressionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsLayerTreeView</class>
<extends>QTreeView</extends>
<header>qgslayertreeview.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCodeEditorHTML</class>
<extends>QWidget</extends>
Expand Down

0 comments on commit 09a36c3

Please sign in to comment.