Skip to content

Commit

Permalink
add optional filter for spatial only layers
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Aug 31, 2018
1 parent b224569 commit 9cefd3a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
13 changes: 12 additions & 1 deletion src/app/qgslayercapabilitiesmodel.cpp
Expand Up @@ -174,6 +174,15 @@ QgsMapLayer *QgsLayerCapabilitiesModel::mapLayer( const QModelIndex &idx ) const
return QgsLayerTree::toLayer( node )->layer();
}

void QgsLayerCapabilitiesModel::setShowSpatialLayersOnly( bool only )
{
if ( only == mShowSpatialLayersOnly )
return;

mShowSpatialLayersOnly = only;
invalidateFilter();
}

QModelIndex QgsLayerCapabilitiesModel::index( int row, int column, const QModelIndex &parent ) const
{
QModelIndex newIndex = QSortFilterProxyModel::index( row, LayerColumn, parent );
Expand Down Expand Up @@ -298,6 +307,8 @@ bool QgsLayerCapabilitiesModel::nodeShown( QgsLayerTreeNode *node ) const
else
{
QgsMapLayer *layer = QgsLayerTree::toLayer( node )->layer();
return layer && ( mFilterText.isEmpty() || layer->name().contains( mFilterText, Qt::CaseInsensitive ) );
return layer
&& ( mFilterText.isEmpty() || layer->name().contains( mFilterText, Qt::CaseInsensitive ) )
&& ( !mShowSpatialLayersOnly || layer->isSpatial() );
}
}
2 changes: 2 additions & 0 deletions src/app/qgslayercapabilitiesmodel.h
Expand Up @@ -46,6 +46,7 @@ class APP_EXPORT QgsLayerCapabilitiesModel : public QSortFilterProxyModel
bool readOnly( QgsMapLayer *layer ) const;
bool searchable( QgsMapLayer *layer ) const;
QgsMapLayer *mapLayer( const QModelIndex &idx ) const;
void setShowSpatialLayersOnly( bool only );

int columnCount( const QModelIndex &parent ) const override;
QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
Expand All @@ -67,6 +68,7 @@ class APP_EXPORT QgsLayerCapabilitiesModel : public QSortFilterProxyModel
bool nodeShown( QgsLayerTreeNode *node ) const;

QString mFilterText;
bool mShowSpatialLayersOnly = false;
QStringList mNonIdentifiableLayers;
QHash<QgsMapLayer *, bool> mReadOnlyLayers;
QHash<QgsMapLayer *, bool> mSearchableLayers;
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -387,6 +387,11 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mLayerCapabilitiesTree->repaint();
} );

connect( mShowSpatialLayersCheckBox, &QCheckBox::stateChanged, this, [ = ]( int state )
{
mLayerCapabilitiesModel->setShowSpatialLayersOnly( static_cast<bool>( state ) );
} );

grpOWSServiceCapabilities->setChecked( QgsProject::instance()->readBoolEntry( QStringLiteral( "WMSServiceCapabilities" ), QStringLiteral( "/" ), false ) );
mWMSTitle->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMSServiceTitle" ), QStringLiteral( "/" ) ) );
mWMSName->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMSRootName" ), QStringLiteral( "/" ) ) );
Expand Down
47 changes: 27 additions & 20 deletions src/ui/qgsprojectpropertiesbase.ui
Expand Up @@ -277,7 +277,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<width>563</width>
<height>833</height>
</rect>
</property>
Expand Down Expand Up @@ -875,8 +875,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<height>764</height>
<width>547</width>
<height>152</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -950,8 +950,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<height>764</height>
<width>271</width>
<height>597</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1411,17 +1411,10 @@
<string>Project Layers</string>
</property>
<layout class="QGridLayout" name="gridLayout_20">
<item row="0" column="2">
<widget class="QPushButton" name="mLayerCapabilitiesCheckButton">
<property name="text">
<string>check selection</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QTreeView" name="mLayerCapabilitiesTree"/>
<item row="3" column="3">
<widget class="QgsFilterLineEdit" name="mLayerCapabilitiesTreeFilterLineEdit"/>
</item>
<item row="0" column="0">
<item row="3" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -1434,16 +1427,30 @@
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QgsFilterLineEdit" name="mLayerCapabilitiesTreeFilterLineEdit"/>
</item>
<item row="0" column="1">
<item row="3" column="0">
<widget class="QPushButton" name="mLayerCapabilitiesUncheckButton">
<property name="text">
<string>uncheck selection</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="mLayerCapabilitiesCheckButton">
<property name="text">
<string>check selection</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QCheckBox" name="mShowSpatialLayersCheckBox">
<property name="text">
<string>show spatial layers only</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QTreeView" name="mLayerCapabilitiesTree"/>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -1635,7 +1642,7 @@
<x>0</x>
<y>0</y>
<width>603</width>
<height>2365</height>
<height>2666</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down

0 comments on commit 9cefd3a

Please sign in to comment.