Skip to content

Commit 7d910d5

Browse files
committed
[bugfix] Browsertree collapse network provider items
Backport of #4742 Prevent expansion of WMS connection layers when restoring the browser. This was causing unwanted connections to WMS and other providers when QGIS starts.
1 parent c39e4fc commit 7d910d5

19 files changed

+61
-12
lines changed

python/core/qgsdataitem.sip

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ class QgsDataItem : QObject
143143
NoCapabilities,
144144
SetCrs, //!< Can set CRS on layer or group of layers
145145
Fertile, //!< Can create children. Even items without this capability may have children, but cannot create them, it means that children are created by item ancestors.
146-
Fast //!< 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 QSettings
146+
Fast, //!< 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 QSettings
147+
Collapse //!< The collapse/expand status for this items children should be ignored in order to avoid undesired network connections (wms etc.)
147148
};
148149
typedef QFlags<QgsDataItem::Capability> Capabilities;
149150

python/gui/qgsbrowsertreeview.sip

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class QgsBrowserTreeView: QTreeView
1515
~QgsBrowserTreeView();
1616

1717
virtual void setModel( QAbstractItemModel* model );
18+
//! Set the browser model
19+
void setBrowserModel( QgsBrowserModel *model );
20+
//! Return the browser model
21+
QgsBrowserModel *browserModel( );
1822
virtual void showEvent( QShowEvent * e );
1923
virtual void hideEvent( QHideEvent * e );
2024

src/app/qgsbrowserdockwidget.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
344344
mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
345345
mProxyModel->setBrowserModel( mModel );
346346
mBrowserView->setSettingsSection( objectName().toLower() ); // to distinguish 2 instances ow browser
347+
mBrowserView->setBrowserModel( mModel );
347348
mBrowserView->setModel( mProxyModel );
348349
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
349350
mBrowserView->setTextElideMode( Qt::ElideNone );

src/core/qgsdataitem.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ class CORE_EXPORT QgsDataItem : public QObject
170170
NoCapabilities = 0,
171171
SetCrs = 1 << 0, //!< Can set CRS on layer or group of layers
172172
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.
173-
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 QSettings
173+
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 QSettings
174+
Collapse = 1 << 3 //!< The collapse/expand status for this items children should be ignored in order to avoid undesired network connections (wms etc.)
174175
};
175176
Q_DECLARE_FLAGS( Capabilities, Capability )
176177

src/gui/qgsbrowsertreeview.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@
2424
QgsBrowserTreeView::QgsBrowserTreeView( QWidget *parent )
2525
: QTreeView( parent )
2626
, mSettingsSection( "browser" )
27+
, mBrowserModel( nullptr )
2728
{
2829
}
2930

3031
QgsBrowserTreeView::~QgsBrowserTreeView()
3132
{
3233
}
3334

35+
void QgsBrowserTreeView::setBrowserModel( QgsBrowserModel *model )
36+
{
37+
mBrowserModel = model;
38+
}
39+
3440
void QgsBrowserTreeView::setModel( QAbstractItemModel* model )
3541
{
3642

@@ -78,7 +84,26 @@ void QgsBrowserTreeView::restoreState()
7884
{
7985
QModelIndex expandIndex = QgsBrowserModel::findPath( model(), path, Qt::MatchStartsWith );
8086
if ( expandIndex.isValid() )
81-
expandIndexSet.insert( expandIndex );
87+
{
88+
QModelIndex modelIndex = browserModel()->findPath( path, Qt::MatchExactly );
89+
if ( modelIndex.isValid() )
90+
{
91+
QgsDataItem *ptr = browserModel()->dataItem( modelIndex );
92+
if ( ptr && ( ptr->capabilities2() & QgsDataItem::Capability::Collapse ) )
93+
{
94+
QgsDebugMsgLevel( "do not expand index for path " + path, 4 );
95+
QModelIndex parentIndex = model()->parent( expandIndex );
96+
// Still we need to store the parent in order to expand it
97+
if ( parentIndex.isValid() )
98+
expandIndexSet.insert( parentIndex );
99+
}
100+
else
101+
{
102+
expandIndexSet.insert( expandIndex );
103+
}
104+
}
105+
106+
}
82107
else
83108
{
84109
QgsDebugMsg( "index for path " + path + " not found" );

src/gui/qgsbrowsertreeview.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include <QTreeView>
2020

21-
//class QgsBrowserModel;
21+
class QgsBrowserModel;
2222

2323
/** \ingroup gui
2424
* The QgsBrowserTreeView class extends QTreeView with save/restore tree state functionality.
@@ -34,6 +34,10 @@ class GUI_EXPORT QgsBrowserTreeView : public QTreeView
3434
~QgsBrowserTreeView();
3535

3636
virtual void setModel( QAbstractItemModel* model ) override;
37+
//! Set the browser model
38+
void setBrowserModel( QgsBrowserModel *model );
39+
//! Return the browser model
40+
QgsBrowserModel *browserModel( ) { return mBrowserModel; }
3741
virtual void showEvent( QShowEvent * e ) override;
3842
virtual void hideEvent( QHideEvent * e ) override;
3943

@@ -63,6 +67,9 @@ class GUI_EXPORT QgsBrowserTreeView : public QTreeView
6367

6468
// returns true if expanded from root to item
6569
bool treeExpanded( const QModelIndex & index );
70+
71+
// Stores the browser model
72+
QgsBrowserModel *mBrowserModel;
6673
};
6774

6875
#endif // QGSBROWSERTREEVIEW_H

src/providers/arcgisrest/qgsafsdataitems.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ QgsAfsConnectionItem::QgsAfsConnectionItem( QgsDataItem* parent, const QString &
8383
, mUrl( url )
8484
{
8585
mIconName = "mIconConnect.png";
86+
mCapabilities |= Collapse;
8687
}
8788

8889
QVector<QgsDataItem*> QgsAfsConnectionItem::createChildren()

src/providers/arcgisrest/qgsamsdataitems.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ QgsAmsConnectionItem::QgsAmsConnectionItem( QgsDataItem* parent, QString name, Q
8080
, mUrl( url )
8181
{
8282
mIconName = "mIconConnect.png";
83+
mCapabilities |= Collapse;
8384
}
8485

8586
QVector<QgsDataItem*> QgsAmsConnectionItem::createChildren()

src/providers/db2/qgsdb2dataitems.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ QgsDb2ConnectionItem::QgsDb2ConnectionItem( QgsDataItem *parent, const QString n
3636
: QgsDataCollectionItem( parent, name, path )
3737
{
3838
mIconName = "mIconConnect.png";
39+
mCapabilities |= Collapse;
3940
populate();
4041
}
4142

src/providers/mssql/qgsmssqldataitems.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ QgsMssqlConnectionItem::QgsMssqlConnectionItem( QgsDataItem* parent, QString nam
4141
, mAllowGeometrylessTables( true )
4242
, mColumnTypeThread( nullptr )
4343
{
44-
mCapabilities |= Fast;
44+
mCapabilities |= Fast | Collapse;
4545
mIconName = "mIconConnect.png";
4646
}
4747

src/providers/oracle/qgsoracledataitems.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ QgsOracleConnectionItem::QgsOracleConnectionItem( QgsDataItem* parent, QString n
3333
, mColumnTypeThread( nullptr )
3434
{
3535
mIconName = "mIconConnect.png";
36+
mCapabilities |= Collapse;
3637
}
3738

3839
QgsOracleConnectionItem::~QgsOracleConnectionItem()

src/providers/ows/qgsowsdataitems.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ QgsOWSConnectionItem::QgsOWSConnectionItem( QgsDataItem* parent, QString name, Q
2929
: QgsDataCollectionItem( parent, name, path )
3030
{
3131
mIconName = "mIconConnect.png";
32+
mCapabilities |= Collapse;
3233
}
3334

3435
QgsOWSConnectionItem::~QgsOWSConnectionItem()

src/providers/postgres/qgspostgresdataitems.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ QgsPGConnectionItem::QgsPGConnectionItem( QgsDataItem* parent, QString name, QSt
3838
: QgsDataCollectionItem( parent, name, path )
3939
{
4040
mIconName = "mIconConnect.png";
41+
mCapabilities |= Collapse;
4142
}
4243

4344
QgsPGConnectionItem::~QgsPGConnectionItem()

src/providers/spatialite/qgsspatialitedataitems.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ QgsSLConnectionItem::QgsSLConnectionItem( QgsDataItem* parent, QString name, QSt
7575
{
7676
mDbPath = QgsSpatiaLiteConnection::connectionPath( name );
7777
mToolTip = mDbPath;
78+
mCapabilities |= Collapse;
7879
}
7980

8081
QgsSLConnectionItem::~QgsSLConnectionItem()

src/providers/wcs/qgswcsdataitems.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ QgsWCSConnectionItem::QgsWCSConnectionItem( QgsDataItem* parent, QString name, Q
3030
, mUri( uri )
3131
{
3232
mIconName = "mIconWcs.svg";
33+
mCapabilities |= Collapse;
3334
}
3435

3536
QgsWCSConnectionItem::~QgsWCSConnectionItem()
@@ -44,23 +45,23 @@ QVector<QgsDataItem*> QgsWCSConnectionItem::createChildren()
4445
uri.setEncodedUri( mUri );
4546
QgsDebugMsg( "mUri = " + mUri );
4647

47-
mCapabilities.setUri( uri );
48+
mWcsCapabilities.setUri( uri );
4849

4950
// Attention: supportedLayers() gives tree leafes, not top level
50-
if ( !mCapabilities.lastError().isEmpty() )
51+
if ( !mWcsCapabilities.lastError().isEmpty() )
5152
{
5253
//children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
5354
// TODO: show the error without adding child
5455
return children;
5556
}
5657

57-
Q_FOREACH ( const QgsWcsCoverageSummary& coverageSummary, mCapabilities.capabilities().contents.coverageSummary )
58+
Q_FOREACH ( const QgsWcsCoverageSummary& coverageSummary, mWcsCapabilities.capabilities().contents.coverageSummary )
5859
{
5960
// Attention, the name may be empty
6061
QgsDebugMsg( QString::number( coverageSummary.orderId ) + ' ' + coverageSummary.identifier + ' ' + coverageSummary.title );
6162
QString pathName = coverageSummary.identifier.isEmpty() ? QString::number( coverageSummary.orderId ) : coverageSummary.identifier;
6263

63-
QgsWCSLayerItem * layer = new QgsWCSLayerItem( this, coverageSummary.title, mPath + '/' + pathName, mCapabilities.capabilities(), uri, coverageSummary );
64+
QgsWCSLayerItem * layer = new QgsWCSLayerItem( this, coverageSummary.title, mPath + '/' + pathName, mWcsCapabilities.capabilities(), uri, coverageSummary );
6465

6566
children.append( layer );
6667
}

src/providers/wcs/qgswcsdataitems.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class QgsWCSConnectionItem : public QgsDataCollectionItem
3131

3232
virtual QList<QAction*> actions() override;
3333

34-
QgsWcsCapabilities mCapabilities;
34+
QgsWcsCapabilities mWcsCapabilities;
3535
QVector<QgsWcsCoverageSummary> mLayerProperties;
3636

3737
public slots:

src/providers/wfs/qgswfsdataitems.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ QgsWFSLayerItem::~QgsWFSLayerItem()
4646
QgsWFSConnectionItem::QgsWFSConnectionItem( QgsDataItem* parent, QString name, QString path, QString uri )
4747
: QgsDataCollectionItem( parent, name, path )
4848
, mUri( uri )
49-
, mCapabilities( nullptr )
49+
, mWfsCapabilities( nullptr )
5050
{
5151
mIconName = "mIconWfs.svg";
52+
mCapabilities |= Collapse;
5253
}
5354

5455
QgsWFSConnectionItem::~QgsWFSConnectionItem()

src/providers/wfs/qgswfsdataitems.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class QgsWFSConnectionItem : public QgsDataCollectionItem
5858
private:
5959
QString mUri;
6060

61-
QgsWFSCapabilities* mCapabilities;
61+
QgsWFSCapabilities* mWfsCapabilities;
6262
};
6363

6464

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 = "mIconConnect.png";
38+
mCapabilities |= Collapse;
3839
mCapabilitiesDownload = new QgsWmsCapabilitiesDownload( false );
3940
}
4041

0 commit comments

Comments
 (0)