Skip to content

Commit

Permalink
fix style selection in wms dialog (and a memory leak)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13133 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 21, 2010
1 parent 300ea3c commit 81fa1e2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -2694,6 +2694,7 @@ void QgisApp::addWmsLayer()

QgsWMSSourceSelect *wmss = new QgsWMSSourceSelect( this );
wmss->exec();
delete wmss;
}


Expand Down
87 changes: 47 additions & 40 deletions src/app/qgswmssourceselect.cpp
Expand Up @@ -155,12 +155,19 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget * parent, Qt::WFlags fl )

connect( tableWidgetWMSList, SIGNAL( itemSelectionChanged() ), this, SLOT( wmsSelectionChanged() ) );
connect( lstTilesets, SIGNAL( itemSelectionChanged() ), this, SLOT( updateButtons() ) );

QSettings settings;
QgsDebugMsg( "restoring geometry" );
restoreGeometry( settings.value( "/Windows/WMSSourceSelect/geometry" ).toByteArray() );
}

QgsWMSSourceSelect::~QgsWMSSourceSelect()
{

QSettings settings;
QgsDebugMsg( "saving geometry" );
settings.setValue( "/Windows/WMSSourceSelect/geometry", saveGeometry() );
}

void QgsWMSSourceSelect::populateConnectionList()
{
QSettings settings;
Expand Down Expand Up @@ -574,67 +581,65 @@ void QgsWMSSourceSelect::applySelectionConstraints( QTreeWidgetItem *item )
// layer group =>
// process child layers and style selection first
// then
// if all child layers are selected, deselect them and select the group instead
// if all child layers of a group are selected, deselect them and select the group and collapse it
// if some child layers are selected, deselect the group
// if none child layers are selected, keep the selection state of the group
for ( int i = 0; i < item->childCount(); i++ )
{
applySelectionConstraints( item->child( i ) );
}

// otherwise keep the selection state of the group
int n = 0;
for ( int i = 0; i < item->childCount(); i++ )
{
if ( item->child( i )->isSelected() )
QTreeWidgetItem *child = item->child( i );
applySelectionConstraints( child );
if ( child->isSelected() )
n++;
}

if ( n == item->childCount() )
{
for ( int i = 0; i < item->childCount(); i++ )
item->child( i )->setSelected( false );
item->setSelected( true );
item->setExpanded( false );
}
else if ( n > 0 )
if ( n > 0 )
{
item->setSelected( false );
item->setSelected( n == item->childCount() );
if ( item->isSelected() )
{
for ( int i = 0; i < n; i++ )
item->child( i )->setSelected( false );
item->setExpanded( false );
}
}
}
else if ( styleName.isEmpty() )
{
// named layer =>
// if all styles are selected, deselect all and selected named layer
// else if some styles are selected, deselect all, but the first and deselect the named layer
// else if no style is selected, keep layer selection
int n = 0;
// if styles are selected, deselect the layer and all styles but the first newly selected or the first if there no new,
// else if no styles are selected, keep the layer selection
QTreeWidgetItem *style = 0;
QTreeWidgetItem *firstNewStyle = 0;
for ( int i = 0; i < item->childCount(); i++ )
{
if ( item->child( i )->isSelected() )
QTreeWidgetItem *child = item->child( i );
if ( child->isSelected() )
{
n++;
if ( !firstNewStyle && !mCurrentSelection.contains( child ) )
firstNewStyle = child;

if ( !style )
style = item->child( i );
else
item->child( i )->setSelected( false );
style = child;

child->setSelected( false );
}
}

if ( n > 0 && n == item->childCount() )
if ( firstNewStyle || style )
{
// all styles were selected =>
// deselect all styles and select named layer
if ( style )
style->setSelected( false );
item->setSelected( true );
item->setExpanded( false );
}
else if ( style )
{
// leave first style selected
// and deselect named layer
item->setSelected( false );
// individual style selected => unselect layer and all parent groups
QTreeWidgetItem *parent = item;
while ( parent )
{
parent->setSelected( false );
parent = parent->parent();
}

if ( firstNewStyle )
firstNewStyle->setSelected( true );
else if ( style )
style->setSelected( true );
}
}
}
Expand Down Expand Up @@ -672,8 +677,10 @@ void QgsWMSSourceSelect::on_lstLayers_itemSelectionChanged()
{
applySelectionConstraints( lstLayers->topLevelItem( i ) );
}
mCurrentSelection = lstLayers->selectedItems();
lstLayers->blockSignals( false );


// selected layers with styles
QStringList layers;
QStringList styles;
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgswmssourceselect.h
Expand Up @@ -182,6 +182,8 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
void collectSelectedLayers( QStringList &layers, QStringList &styles );
QString selectedImageEncoding();

QList<QTreeWidgetItem*> mCurrentSelection;

private slots:
void on_btnSearch_clicked();
void on_btnAddWMS_clicked();
Expand Down

0 comments on commit 81fa1e2

Please sign in to comment.