Skip to content

Commit

Permalink
wms: use titles in layer name (fixes #4002)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 15, 2014
1 parent edfce68 commit 675746c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
45 changes: 31 additions & 14 deletions src/providers/wms/qgswmssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ bool QgsWMSSourceSelect::populateLayerList( QgsWmsProvider *wmsProvider )
lItem->setData( 0, Qt::UserRole + 0, layer->name );
lItem->setData( 0, Qt::UserRole + 1, "" );
lItem->setData( 0, Qt::UserRole + 2, layer->crs );
lItem->setData( 0, Qt::UserRole + 3, layer->title.isEmpty() ? layer->name : layer->title );

// Also insert the styles
// Layer Styles
Expand All @@ -331,6 +332,7 @@ bool QgsWMSSourceSelect::populateLayerList( QgsWmsProvider *wmsProvider )

lItem2->setData( 0, Qt::UserRole + 0, layer->name );
lItem2->setData( 0, Qt::UserRole + 1, layer->style[j].name );
lItem2->setData( 0, Qt::UserRole + 3, layer->style[j].title.isEmpty() ? layer->style[j].name : layer->style[j].title );
}
}

Expand Down Expand Up @@ -479,6 +481,7 @@ void QgsWMSSourceSelect::addClicked()
{
QStringList layers;
QStringList styles;
QStringList titles;
QString format;
QString crs;

Expand All @@ -492,7 +495,7 @@ void QgsWMSSourceSelect::addClicked()

if ( lstTilesets->selectedItems().isEmpty() )
{
collectSelectedLayers( layers, styles );
collectSelectedLayers( layers, styles, titles );
crs = mCRS;
format = mFormats[ mImageFormatGroup->checkedId()].format;
}
Expand All @@ -504,6 +507,7 @@ void QgsWMSSourceSelect::addClicked()
format = item->data( Qt::UserRole + 1 ).toString();
styles = QStringList( item->data( Qt::UserRole + 2 ).toString() );
crs = item->data( Qt::UserRole + 4 ).toString();
titles = QStringList( item->data( Qt::UserRole + 5 ).toString() );

uri.setParam( "tileMatrixSet", item->data( Qt::UserRole + 3 ).toStringList() );

Expand Down Expand Up @@ -561,7 +565,7 @@ void QgsWMSSourceSelect::addClicked()
}

emit addRasterLayer( uri.encodedUri(),
leLayerName->text().isEmpty() ? layers.join( "/" ) : leLayerName->text(),
leLayerName->text().isEmpty() ? titles.join( "/" ) : leLayerName->text(),
"wms" );
}

Expand Down Expand Up @@ -727,21 +731,23 @@ void QgsWMSSourceSelect::applySelectionConstraints( QTreeWidgetItem *item )
}
}

void QgsWMSSourceSelect::collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles )
void QgsWMSSourceSelect::collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles, QStringList &titles )
{
QString layerName = item->data( 0, Qt::UserRole + 0 ).toString();
QString styleName = item->data( 0, Qt::UserRole + 1 ).toString();
QString titleName = item->data( 0, Qt::UserRole + 3 ).toString();
if ( layerName.isEmpty() )
{
// layer group
for ( int i = 0; i < item->childCount(); i++ )
collectNamedLayers( item->child( i ), layers, styles );
collectNamedLayers( item->child( i ), layers, styles, titles );
}
else if ( styleName.isEmpty() )
{
// named layers
layers << layerName;
styles << "";
titles << titleName;

if ( mCRSs.isEmpty() )
mCRSs = item->data( 0, Qt::UserRole + 2 ).toStringList().toSet();
Expand All @@ -766,6 +772,7 @@ void QgsWMSSourceSelect::on_lstLayers_itemSelectionChanged()
// selected layers with styles
QStringList layers;
QStringList styles;
QStringList titles;

mCRSs.clear();

Expand All @@ -774,17 +781,19 @@ void QgsWMSSourceSelect::on_lstLayers_itemSelectionChanged()
{
QString layerName = item->data( 0, Qt::UserRole + 0 ).toString();
QString styleName = item->data( 0, Qt::UserRole + 1 ).toString();
QString titleName = item->data( 0, Qt::UserRole + 3 ).toString();

if ( layerName.isEmpty() )
{
// layers groups: collect named layers of group and add using the default style
collectNamedLayers( item, layers, styles );
collectNamedLayers( item, layers, styles, titles );
}
else if ( styleName.isEmpty() )
{
// named layer: add using default style
layers << layerName;
styles << "";
titles << titleName;
if ( mCRSs.isEmpty() )
mCRSs = item->data( 0, Qt::UserRole + 2 ).toStringList().toSet();
else
Expand All @@ -795,6 +804,7 @@ void QgsWMSSourceSelect::on_lstLayers_itemSelectionChanged()
// style: add named layer with selected style
layers << layerName;
styles << styleName;
titles << titleName;
if ( mCRSs.isEmpty() )
mCRSs = item->parent()->data( 0, Qt::UserRole + 2 ).toStringList().toSet();
else
Expand Down Expand Up @@ -840,7 +850,7 @@ void QgsWMSSourceSelect::on_lstLayers_itemSelectionChanged()
labelCoordRefSys->setText( "" );
}

updateLayerOrderTab( layers, styles );
updateLayerOrderTab( layers, styles, titles );
updateButtons();
}

Expand Down Expand Up @@ -885,7 +895,7 @@ void QgsWMSSourceSelect::updateButtons()
// disable tilesets, when layer are selected or no tilesets available
lstLayers->setEnabled( true );
tabServers->setTabEnabled( tabServers->indexOf( tabLayerOrder ), mLayerOrderTreeWidget->topLevelItemCount() > 0 );
tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ), mLayerOrderTreeWidget->topLevelItemCount() == 0 && lstTilesets->rowCount() > 0 );
tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ), mLayerOrderTreeWidget->topLevelItemCount() == 0 && lstTilesets->rowCount() > 0 );
btnGrpImageEncoding->setEnabled( true );
}

Expand Down Expand Up @@ -951,9 +961,9 @@ void QgsWMSSourceSelect::updateButtons()
}
else
{
QStringList layers, styles;
collectSelectedLayers( layers, styles );
mLastLayerName = layers.join( "/" );
QStringList layers, styles, titles;
collectSelectedLayers( layers, styles, titles );
mLastLayerName = titles.join( "/" );
leLayerName->setText( mLastLayerName );
}
}
Expand All @@ -976,14 +986,15 @@ QString QgsWMSSourceSelect::connectionInfo()
return mConnectionInfo;
}

void QgsWMSSourceSelect::collectSelectedLayers( QStringList &layers, QStringList &styles )
void QgsWMSSourceSelect::collectSelectedLayers( QStringList &layers, QStringList &styles, QStringList &titles )
{
//go through list in layer order tab
QStringList selectedLayerList;
for ( int i = mLayerOrderTreeWidget->topLevelItemCount() - 1; i >= 0; --i )
{
layers << mLayerOrderTreeWidget->topLevelItem( i )->text( 0 );
styles << mLayerOrderTreeWidget->topLevelItem( i )->text( 1 );
titles << mLayerOrderTreeWidget->topLevelItem( i )->text( 2 );
}
}

Expand Down Expand Up @@ -1247,10 +1258,12 @@ void QgsWMSSourceSelect::on_mLayerUpButton_clicked()
return; //item not existing or already on top
}

QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
mLayerOrderTreeWidget->clearSelection();
selectedItem->setSelected( true );

updateButtons();
}

void QgsWMSSourceSelect::on_mLayerDownButton_clicked()
Expand All @@ -1270,17 +1283,20 @@ void QgsWMSSourceSelect::on_mLayerDownButton_clicked()
mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
mLayerOrderTreeWidget->clearSelection();
selectedItem->setSelected( true );

updateButtons();
}

void QgsWMSSourceSelect::updateLayerOrderTab( const QStringList& newLayerList, const QStringList& newStyleList )
void QgsWMSSourceSelect::updateLayerOrderTab( const QStringList& newLayerList, const QStringList& newStyleList, const QStringList &newTitleList )
{
//check, if each layer / style combination is already contained in the layer order tab
//if not, add it to the top of the list

QStringList::const_iterator layerListIt = newLayerList.constBegin();
QStringList::const_iterator styleListIt = newStyleList.constBegin();
QStringList::const_iterator titleListIt = newTitleList.constBegin();

for ( ; layerListIt != newLayerList.constEnd(); ++layerListIt, ++styleListIt )
for ( ; layerListIt != newLayerList.constEnd(); ++layerListIt, ++styleListIt, ++titleListIt )
{
bool combinationExists = false;
for ( int i = 0; i < mLayerOrderTreeWidget->topLevelItemCount(); ++i )
Expand All @@ -1298,6 +1314,7 @@ void QgsWMSSourceSelect::updateLayerOrderTab( const QStringList& newLayerList, c
QTreeWidgetItem* newItem = new QTreeWidgetItem();
newItem->setText( 0, *layerListIt );
newItem->setText( 1, *styleListIt );
newItem->setText( 2, *titleListIt );
mLayerOrderTreeWidget->addTopLevelItem( newItem );
}

Expand Down
6 changes: 3 additions & 3 deletions src/providers/wms/qgswmssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
QString descriptionForAuthId( QString authId );

//! Keeps the layer order list up-to-date with changed layers and styles
void updateLayerOrderTab( const QStringList& newLayerList, const QStringList& newStyleList );
void updateLayerOrderTab( const QStringList& newLayerList, const QStringList& newStyleList, const QStringList &newTitleList );

//! Name for selected connection
QString mConnName;
Expand All @@ -196,10 +196,10 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
void addWMSListItem( const QDomElement& el, int row, int column );

void applySelectionConstraints( QTreeWidgetItem *item );
void collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles );
void collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles, QStringList &titles );
void enableLayersForCrs( QTreeWidgetItem *item );

void collectSelectedLayers( QStringList &layers, QStringList &styles );
void collectSelectedLayers( QStringList &layers, QStringList &styles, QStringList &titles );
QString selectedImageEncoding();

QList<QTreeWidgetItem*> mCurrentSelection;
Expand Down
5 changes: 5 additions & 0 deletions src/ui/qgswmssourceselectbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@
<string>Style</string>
</property>
</column>
<column>
<property name="text">
<string>Title</string>
</property>
</column>
</widget>
</item>
</layout>
Expand Down

0 comments on commit 675746c

Please sign in to comment.