Skip to content
Permalink
Browse files
wms: use titles in layer name (fixes #4002)
  • Loading branch information
jef-n committed Feb 15, 2014
1 parent edfce68 commit 675746c2d7bdba0b7e3f15a3c96b5a5c2709a41f
@@ -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
@@ -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 );
}
}

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

@@ -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;
}
@@ -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() );

@@ -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" );
}

@@ -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();
@@ -766,6 +772,7 @@ void QgsWMSSourceSelect::on_lstLayers_itemSelectionChanged()
// selected layers with styles
QStringList layers;
QStringList styles;
QStringList titles;

mCRSs.clear();

@@ -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
@@ -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
@@ -840,7 +850,7 @@ void QgsWMSSourceSelect::on_lstLayers_itemSelectionChanged()
labelCoordRefSys->setText( "" );
}

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

@@ -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 );
}

@@ -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 );
}
}
@@ -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 );
}
}

@@ -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()
@@ -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 )
@@ -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 );
}

@@ -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;
@@ -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;
@@ -318,6 +318,11 @@
<string>Style</string>
</property>
</column>
<column>
<property name="text">
<string>Title</string>
</property>
</column>
</widget>
</item>
</layout>

0 comments on commit 675746c

Please sign in to comment.