Skip to content

Commit cf0ffef

Browse files
committed
[bugfix] Prevent expansion of WMS connection layers when restoring the browser
This was causing unwanted connections to WMS when QGIS starts.
1 parent d9d6872 commit cf0ffef

8 files changed

+44
-7
lines changed

python/core/qgsdataitem.sip

+2-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ Create new data item.
176176
NoCapabilities,
177177
SetCrs,
178178
Fertile,
179-
Fast
179+
Fast,
180+
Collapse
180181
};
181182
typedef QFlags<QgsDataItem::Capability> Capabilities;
182183

python/gui/qgsbrowsertreeview.sip

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class QgsBrowserTreeView : QTreeView
2525
QgsBrowserTreeView( QWidget *parent /TransferThis/ = 0 );
2626

2727
virtual void setModel( QAbstractItemModel *model );
28+
void setBrowserModel( QgsBrowserModel *model );
29+
QgsBrowserModel *browserModel( );
30+
%Docstring
31+
:rtype: QgsBrowserModel
32+
%End
2833
virtual void showEvent( QShowEvent *e );
2934
virtual void hideEvent( QHideEvent *e );
3035

src/core/qgsdataitem.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ class CORE_EXPORT QgsDataItem : public QObject
169169

170170
enum Capability
171171
{
172-
NoCapabilities = 0,
173-
SetCrs = 1 << 0, //!< Can set CRS on layer or group of layers
174-
Fertile = 1 << 1, //!< Can create children. Even items without this capability may have children, but cannot create them, it means that children are created by item ancestors.
175-
Fast = 1 << 2 //!< CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,wfs,wcs,postgres...) are considered fast because they are reading data only from QgsSettings
172+
NoCapabilities = 0,
173+
SetCrs = 1 << 0, //!< Can set CRS on layer or group of layers
174+
Fertile = 1 << 1, //!< Can create children. Even items without this capability may have children, but cannot create them, it means that children are created by item ancestors.
175+
Fast = 1 << 2, //!< CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,wfs,wcs,postgres...) are considered fast because they are reading data only from QgsSettings
176+
Collapse = 1 << 3 //!< The collapse/expand status for this items children should be ignored in order to avoid undesired network connections (wms etc.)
176177
};
177178
Q_DECLARE_FLAGS( Capabilities, Capability )
178179

src/gui/qgsbrowserdockwidget.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent *e )
118118
mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
119119
mProxyModel->setBrowserModel( mModel );
120120
mBrowserView->setSettingsSection( objectName().toLower() ); // to distinguish 2 instances ow browser
121+
mBrowserView->setBrowserModel( mModel );
121122
mBrowserView->setModel( mProxyModel );
122123
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
123124
mBrowserView->setTextElideMode( Qt::ElideNone );

src/gui/qgsbrowserdockwidget_p.h

+2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
212212
explicit QgsBrowserTreeFilterProxyModel( QObject *parent );
213213
//! Set the browser model
214214
void setBrowserModel( QgsBrowserModel *model );
215+
//! Get the browser model
216+
QgsBrowserModel *browserModel( ) { return mModel; }
215217
//! Set the filter syntax
216218
void setFilterSyntax( const QString &syntax );
217219
//! Set the filter

src/gui/qgsbrowsertreeview.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
QgsBrowserTreeView::QgsBrowserTreeView( QWidget *parent )
2323
: QTreeView( parent )
2424
, mSettingsSection( QStringLiteral( "browser" ) )
25+
, mBrowserModel( nullptr )
2526
{
2627
}
2728

@@ -33,6 +34,11 @@ void QgsBrowserTreeView::setModel( QAbstractItemModel *model )
3334
restoreState();
3435
}
3536

37+
void QgsBrowserTreeView::setBrowserModel( QgsBrowserModel *model )
38+
{
39+
mBrowserModel = model;
40+
}
41+
3642
void QgsBrowserTreeView::showEvent( QShowEvent *e )
3743
{
3844
Q_UNUSED( e );
@@ -72,7 +78,24 @@ void QgsBrowserTreeView::restoreState()
7278
{
7379
QModelIndex expandIndex = QgsBrowserModel::findPath( model(), path, Qt::MatchStartsWith );
7480
if ( expandIndex.isValid() )
75-
expandIndexSet.insert( expandIndex );
81+
{
82+
QModelIndex modelIndex = browserModel()->findPath( path, Qt::MatchExactly );
83+
if ( modelIndex.isValid() )
84+
{
85+
QgsDataItem *ptr = browserModel()->dataItem( modelIndex );
86+
if ( ptr && ( ptr->capabilities2() & QgsDataItem::Capability::Collapse ) )
87+
{
88+
QgsDebugMsgLevel( "do not expand index for path " + path, 4 );
89+
QModelIndex parentIndex = model()->parent( expandIndex );
90+
if ( parentIndex.isValid() )
91+
expandIndexSet.insert( parentIndex );
92+
}
93+
else
94+
{
95+
expandIndexSet.insert( expandIndex );
96+
}
97+
}
98+
}
7699
else
77100
{
78101
QgsDebugMsgLevel( "index for path " + path + " not found", 4 );

src/gui/qgsbrowsertreeview.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "qgis.h"
2121
#include "qgis_gui.h"
2222

23-
//class QgsBrowserModel;
23+
class QgsBrowserModel;
2424

2525
/** \ingroup gui
2626
* The QgsBrowserTreeView class extends QTreeView with save/restore tree state functionality.
@@ -35,6 +35,8 @@ class GUI_EXPORT QgsBrowserTreeView : public QTreeView
3535
QgsBrowserTreeView( QWidget *parent SIP_TRANSFERTHIS = 0 );
3636

3737
virtual void setModel( QAbstractItemModel *model ) override;
38+
void setBrowserModel( QgsBrowserModel *model );
39+
QgsBrowserModel *browserModel( ) { return mBrowserModel; }
3840
virtual void showEvent( QShowEvent *e ) override;
3941
virtual void hideEvent( QHideEvent *e ) override;
4042

@@ -64,6 +66,7 @@ class GUI_EXPORT QgsBrowserTreeView : public QTreeView
6466

6567
// returns true if expanded from root to item
6668
bool treeExpanded( const QModelIndex &index );
69+
QgsBrowserModel *mBrowserModel;
6770
};
6871

6972
#endif // QGSBROWSERTREEVIEW_H

src/providers/wms/qgswmsdataitems.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem *parent, QString name, Q
3535
, mCapabilitiesDownload( nullptr )
3636
{
3737
mIconName = QStringLiteral( "mIconConnect.png" );
38+
mCapabilities |= Collapse;
3839
mCapabilitiesDownload = new QgsWmsCapabilitiesDownload( false );
3940
}
4041

0 commit comments

Comments
 (0)