Skip to content
Permalink
Browse files

fix UI and use invalidate rather than reset model

  • Loading branch information
3nids committed Jun 6, 2020
1 parent 558e0b6 commit 09a36c3f6d7bf43e9418b3dc371565baf7a858fc
@@ -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 );
@@ -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();
@@ -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
@@ -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
}
@@ -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.
@@ -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 ) ||
@@ -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;
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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">
@@ -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>
@@ -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">
@@ -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>

0 comments on commit 09a36c3

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