Skip to content
Permalink
Browse files

Added the possibility to change the order of layers in the WMS dialog

git-svn-id: http://svn.osgeo.org/qgis/trunk@10850 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed May 27, 2009
1 parent f13f45e commit 14ae3b93eec1c04f53fa044ebec872b248e7dbd2
Binary file not shown.
Binary file not shown.
@@ -21,6 +21,7 @@

#include "../providers/wms/qgswmsprovider.h"
#include "qgis.h" // GEO_EPSG_CRS_ID
#include "qgisapp.h" //for getThemeIcon
#include "qgscontexthelp.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsgenericprojectionselector.h"
@@ -55,6 +56,8 @@ QgsServerSourceSelect::QgsServerSourceSelect( QWidget * parent, Qt::WFlags fl )
mWmsProvider( 0 )
{
setupUi( this );
mLayerUpButton->setIcon(QgisApp::getThemeIcon("/mActionArrowUp.png"));
mLayerDownButton->setIcon(QgisApp::getThemeIcon("/mActionArrowDown.png"));
connect( btnCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );

// Qt Designer 4.1 doesn't let us use a QButtonGroup, so it has to
@@ -426,11 +429,11 @@ void QgsServerSourceSelect::on_btnConnect_clicked()

void QgsServerSourceSelect::on_btnAdd_clicked()
{
if ( m_selectedLayers.empty() == TRUE )
if ( selectedLayers().empty() == TRUE )
{
QMessageBox::information( this, tr( "Select Layer" ), tr( "You must select at least one leaf layer first." ) );
}
else if ( mWmsProvider->supportedCrsForLayers( m_selectedLayers ).size() == 0 )
else if ( mWmsProvider->supportedCrsForLayers( selectedLayers() ).size() == 0 )
{
QMessageBox::information( this, tr( "Coordinate Reference System" ), tr( "There are no available coordinate reference system for the set of layers you've selected." ) );
}
@@ -448,7 +451,7 @@ void QgsServerSourceSelect::on_btnChangeSpatialRefSys_clicked()
return;
}

QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers( m_selectedLayers );
QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers( selectedLayers() );

QgsGenericProjectionSelector * mySelector =
new QgsGenericProjectionSelector( this );
@@ -519,6 +522,13 @@ void QgsServerSourceSelect::on_lstLayers_itemSelectionChanged()
{
// Remove old style selection
lstLayers->findItems( m_selectedStyleIdForLayer[layerName], Qt::MatchRecursive ).first()->setSelected( false );
// Remove old layer/style pair also from newSelectedLayers / newSelectedStylesForSelectedLayers
int oldIndex = newSelectedLayers.indexOf(layerName);
if(oldIndex != -1)
{
newSelectedLayers.removeAt(oldIndex);
newSelectedStylesForSelectedLayers.removeAt(oldIndex);
}
}

QgsDebugMsg( QString( "Added %1" ).arg( item->text( 0 ) ) );
@@ -576,9 +586,8 @@ void QgsServerSourceSelect::on_lstLayers_itemSelectionChanged()
btnChangeSpatialRefSys->setEnabled( FALSE );
}

m_selectedLayers = newSelectedLayers;
m_selectedStylesForSelectedLayers = newSelectedStylesForSelectedLayers;
m_selectedStyleIdForLayer = newSelectedStyleIdForLayer;
updateLayerOrderTab(newSelectedLayers, newSelectedStylesForSelectedLayers);
}


@@ -594,12 +603,24 @@ QString QgsServerSourceSelect::connectionInfo()

QStringList QgsServerSourceSelect::selectedLayers()
{
return m_selectedLayers;
//go through list in layer order tab
QStringList selectedLayerList;
for(int i = mLayerOrderTreeWidget->topLevelItemCount() - 1; i >= 0; --i)
{
selectedLayerList << mLayerOrderTreeWidget->topLevelItem(i)->text(0);
}
return selectedLayerList;
}

QStringList QgsServerSourceSelect::selectedStylesForSelectedLayers()
{
return m_selectedStylesForSelectedLayers;
//go through list in layer order tab
QStringList selectedStyleList;
for(int i = mLayerOrderTreeWidget->topLevelItemCount() - 1; i >= 0; --i)
{
selectedStyleList << mLayerOrderTreeWidget->topLevelItem(i)->text(1);
}
return selectedStyleList;
}


@@ -910,7 +931,104 @@ void QgsServerSourceSelect::wmsSelectionChanged()
btnAddWMS->setEnabled( tableWidgetWMSList->currentRow() != -1 );
}

void QgsServerSourceSelect::on_mLayerUpButton_clicked()
{
QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
if(selectionList.size() < 1)
{
return;
}
int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem(selectionList[0]);
if(selectedIndex < 1)
{
return; //item not existing or already on top
}

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

void QgsServerSourceSelect::on_mLayerDownButton_clicked()
{
QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
if(selectionList.size() < 1)
{
return;
}
int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem(selectionList[0]);
if(selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2)
{
return; //item not existing or already at bottom
}

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

void QgsServerSourceSelect::updateLayerOrderTab(const QStringList& newLayerList, const QStringList& newStyleList)
{
//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();

for( ; layerListIt != newLayerList.constEnd(); ++layerListIt, ++styleListIt)
{
bool combinationExists = false;
for(int i = 0; i < mLayerOrderTreeWidget->topLevelItemCount(); ++i)
{
QTreeWidgetItem* currentItem = mLayerOrderTreeWidget->topLevelItem(i);
if(currentItem->text(0) == *layerListIt && currentItem->text(1) == *styleListIt)
{
combinationExists = true;
break;
}
}

if(!combinationExists)
{
QTreeWidgetItem* newItem = new QTreeWidgetItem();
newItem->setText(0, *layerListIt);
newItem->setText(1, *styleListIt);
mLayerOrderTreeWidget->insertTopLevelItem(0, newItem);
}

}

//check, if each layer style combination in the layer order tab is still in newLayerList / newStyleList
//if not: remove it from the tree widget

if(mLayerOrderTreeWidget->topLevelItemCount() > 0)
{
for(int i = mLayerOrderTreeWidget->topLevelItemCount() - 1; i >= 0; --i)
{
QTreeWidgetItem* currentItem = mLayerOrderTreeWidget->topLevelItem(i);
bool combinationExists = false;

QStringList::const_iterator llIt = newLayerList.constBegin();
QStringList::const_iterator slIt = newStyleList.constBegin();
for( ; llIt != newLayerList.constEnd(); ++llIt, ++slIt)
{
if(*llIt == currentItem->text(0) && *slIt == currentItem->text(1))
{
combinationExists = true;
break;
}
}

if(!combinationExists)
{
mLayerOrderTreeWidget->takeTopLevelItem(i);
}
}
}

}

//
//
@@ -148,6 +148,9 @@ class QgsServerSourceSelect : public QDialog, private Ui::QgsServerSourceSelectB
//! Returns a textual description for the EpsgCrsId number
QString descriptionForEpsg( long epsg );

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

//! Name for selected connection
QString m_connName;

@@ -166,8 +169,8 @@ class QgsServerSourceSelect : public QDialog, private Ui::QgsServerSourceSelectB
//! Proxy Pass for selected connection
QString m_connProxyPass;

QStringList m_selectedLayers;
QStringList m_selectedStylesForSelectedLayers;
//QStringList m_selectedLayers;
//QStringList m_selectedStylesForSelectedLayers;
long m_Epsg;

QMap<QString, QString> m_selectedStyleIdForLayer;
@@ -194,6 +197,8 @@ class QgsServerSourceSelect : public QDialog, private Ui::QgsServerSourceSelectB
void on_btnSearch_clicked();
void on_btnAddWMS_clicked();
void wmsSelectionChanged();
void on_mLayerUpButton_clicked();
void on_mLayerDownButton_clicked();
};


@@ -13,7 +13,9 @@
<string>Add Layer(s) from a Server</string>
</property>
<property name="windowIcon" >
<iconset/>
<iconset>
<normaloff/>
</iconset>
</property>
<property name="sizeGripEnabled" >
<bool>true</bool>
@@ -93,7 +95,7 @@
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>131</width>
<height>30</height>
@@ -139,6 +141,61 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabLayerOrder" >
<attribute name="title" >
<string>Layer Order</string>
</attribute>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="QPushButton" name="mLayerUpButton" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QPushButton" name="mLayerDownButton" >
<property name="text" >
<string/>
</property>
</widget>
</item>
<item row="0" column="2" >
<spacer name="horizontalSpacer" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>391</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="3" >
<widget class="QTreeWidget" name="mLayerOrderTreeWidget" >
<property name="columnCount" >
<number>2</number>
</property>
<column>
<property name="text" >
<string>Layer</string>
</property>
</column>
<column>
<property name="text" >
<string>Style</string>
</property>
</column>
</widget>
</item>
</layout>
<zorder>mLayerUpButton</zorder>
<zorder>mLayerDownButton</zorder>
<zorder>horizontalSpacer</zorder>
<zorder>mLayerOrderTreeWidget</zorder>
</widget>
<widget class="QWidget" name="tab_2" >
<attribute name="title" >
<string>Server Search</string>
@@ -236,7 +293,7 @@
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>441</width>
<height>23</height>
@@ -281,7 +338,7 @@
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>284</width>
<height>31</height>

0 comments on commit 14ae3b9

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