Skip to content

Commit 5ef70f1

Browse files
authored
Merge pull request #4754 from boundlessgeo/browsertree-collapse-backport
[bugfix] Browsertree collapse network provider items
2 parents c39e4fc + 7d910d5 commit 5ef70f1

19 files changed

Lines changed: 61 additions & 12 deletions

‎python/core/qgsdataitem.sip‎

Lines changed: 2 additions & 1 deletion
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‎

Lines changed: 4 additions & 0 deletions
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‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 2 additions & 1 deletion
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‎

Lines changed: 26 additions & 1 deletion
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‎

Lines changed: 8 additions & 1 deletion
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‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 1 addition & 0 deletions
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‎

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)