Skip to content
Permalink
Browse files

Allow filtering WM(T)S list in source dialog (#36166)

  • Loading branch information
3nids committed May 5, 2020
1 parent 0888d37 commit afbb204236a2965144943652c4cc97937bec12ac
Showing with 300 additions and 146 deletions.
  1. +74 −0 src/providers/wms/qgswmssourceselect.cpp
  2. +9 −0 src/providers/wms/qgswmssourceselect.h
  3. +217 −146 src/ui/qgswmssourceselectbase.ui
@@ -75,6 +75,9 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
connect( mLayerDownButton, &QPushButton::clicked, this, &QgsWMSSourceSelect::mLayerDownButton_clicked );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsWMSSourceSelect::showHelp );

connect( mLayersFilterLineEdit, &QgsFilterLineEdit::textChanged, this, &QgsWMSSourceSelect::filterLayers );
connect( mTilesetsFilterLineEdit, &QgsFilterLineEdit::textChanged, this, &QgsWMSSourceSelect::filterTiles );

// Creates and connects standard ok/apply buttons
setupButtons( buttonBox );

@@ -1120,6 +1123,77 @@ void QgsWMSSourceSelect::cmbConnections_activated( int )
QgsWMSConnection::setSelectedConnection( cmbConnections->currentText() );
}

void QgsWMSSourceSelect::filterLayers( const QString &searchText )
{
std::function< void( QTreeWidgetItem *, bool ) > setChildrenVisible;
setChildrenVisible = [&setChildrenVisible]( QTreeWidgetItem * item, bool visible )
{
for ( int i = 0; i < item->childCount(); ++i )
setChildrenVisible( item->child( i ), visible );
item->setHidden( !visible );
};


if ( searchText.isEmpty() )
{
// show everything and reset tree nesting
setChildrenVisible( lstLayers->invisibleRootItem(), true );
for ( QTreeWidgetItem *item : mTreeInitialExpand.keys() )
if ( item )
item->setExpanded( mTreeInitialExpand.value( item ) );
mTreeInitialExpand.clear();
}
else
{
// hide all
setChildrenVisible( lstLayers->invisibleRootItem(), false );
// find and show matching items in name and title columns
QSet<QTreeWidgetItem *> items = lstLayers->findItems( searchText, Qt::MatchContains | Qt::MatchRecursive, 1 ).toSet();
items.unite( lstLayers->findItems( searchText, Qt::MatchContains | Qt::MatchRecursive, 2 ).toSet() );

// if nothing found, search in abstract too
if ( items.isEmpty() )
{
items = lstLayers->findItems( searchText, Qt::MatchContains | Qt::MatchRecursive, 3 ).toSet();
}

mTreeInitialExpand.clear();
for ( QTreeWidgetItem *item : qgis::as_const( items ) )
{
setChildrenVisible( item, true );

QTreeWidgetItem *parent = item;
while ( parent )
{
if ( mTreeInitialExpand.contains( parent ) )
break;
mTreeInitialExpand.insert( parent, parent->isExpanded() );
parent->setExpanded( true );
parent->setHidden( false );
parent = parent->parent();
}
}
}
}

void QgsWMSSourceSelect::filterTiles( const QString &searchText )
{
QList<int> rowsShown;
if ( !searchText.isEmpty() )
{
const QList<QTableWidgetItem *> items = lstTilesets->findItems( searchText, Qt::MatchContains );
for ( const QTableWidgetItem *item : items )
{
rowsShown << item->row();
}
}
for ( int r = 0; r < lstTilesets->rowCount(); r++ )
{
bool visible = rowsShown.isEmpty() || rowsShown.contains( r );
lstTilesets->setRowHidden( r, !visible );
}
}

QString QgsWMSSourceSelect::descriptionForAuthId( const QString &authId )
{
if ( mCrsNames.contains( authId ) )
@@ -93,6 +93,12 @@ class QgsWMSSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsWM
//! Stores the selected datasource whenerver it is changed
void cmbConnections_activated( int );

//! filter the layers
void filterLayers( const QString &searchText );

//! Filters the tiles sets
void filterTiles( const QString &searchText );

private:
//! Populate the connection list combo box
void populateConnectionList();
@@ -184,6 +190,9 @@ class QgsWMSSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsWM
//! Stores all the layers properties from the service capabilities.
QVector<QgsWmsLayerProperty> mLayerProperties;

// save the current status of the layer true
QMap<QTreeWidgetItem *, bool> mTreeInitialExpand = QMap<QTreeWidgetItem *, bool>();

private slots:
void lstTilesets_itemClicked( QTableWidgetItem *item );
void mLayerUpButton_clicked();

0 comments on commit afbb204

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