Skip to content
Permalink
Browse files

add optional filter for spatial only layers

  • Loading branch information
3nids committed Aug 31, 2018
1 parent b224569 commit 9cefd3a565005fd4be63e9d3402bade7df544fff
@@ -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 );
@@ -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() );
}
}
@@ -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;
@@ -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;
@@ -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( "/" ) ) );
@@ -277,7 +277,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<width>563</width>
<height>833</height>
</rect>
</property>
@@ -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">
@@ -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">
@@ -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>
@@ -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>
@@ -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">

0 comments on commit 9cefd3a

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