Skip to content

Commit

Permalink
Merge pull request #4754 from boundlessgeo/browsertree-collapse-backport
Browse files Browse the repository at this point in the history
[bugfix] Browsertree collapse network provider items
  • Loading branch information
elpaso committed Jun 20, 2017
2 parents c39e4fc + 7d910d5 commit 5ef70f1
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 12 deletions.
3 changes: 2 additions & 1 deletion python/core/qgsdataitem.sip
Expand Up @@ -143,7 +143,8 @@ class QgsDataItem : QObject
NoCapabilities,
SetCrs, //!< Can set CRS on layer or group of layers
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.
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
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
Collapse //!< The collapse/expand status for this items children should be ignored in order to avoid undesired network connections (wms etc.)
};
typedef QFlags<QgsDataItem::Capability> Capabilities;

Expand Down
4 changes: 4 additions & 0 deletions python/gui/qgsbrowsertreeview.sip
Expand Up @@ -15,6 +15,10 @@ class QgsBrowserTreeView: QTreeView
~QgsBrowserTreeView();

virtual void setModel( QAbstractItemModel* model );
//! Set the browser model
void setBrowserModel( QgsBrowserModel *model );
//! Return the browser model
QgsBrowserModel *browserModel( );
virtual void showEvent( QShowEvent * e );
virtual void hideEvent( QHideEvent * e );

Expand Down
1 change: 1 addition & 0 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -344,6 +344,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
mProxyModel->setBrowserModel( mModel );
mBrowserView->setSettingsSection( objectName().toLower() ); // to distinguish 2 instances ow browser
mBrowserView->setBrowserModel( mModel );
mBrowserView->setModel( mProxyModel );
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
mBrowserView->setTextElideMode( Qt::ElideNone );
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsdataitem.h
Expand Up @@ -170,7 +170,8 @@ class CORE_EXPORT QgsDataItem : public QObject
NoCapabilities = 0,
SetCrs = 1 << 0, //!< Can set CRS on layer or group of layers
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.
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
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
Collapse = 1 << 3 //!< The collapse/expand status for this items children should be ignored in order to avoid undesired network connections (wms etc.)
};
Q_DECLARE_FLAGS( Capabilities, Capability )

Expand Down
27 changes: 26 additions & 1 deletion src/gui/qgsbrowsertreeview.cpp
Expand Up @@ -24,13 +24,19 @@
QgsBrowserTreeView::QgsBrowserTreeView( QWidget *parent )
: QTreeView( parent )
, mSettingsSection( "browser" )
, mBrowserModel( nullptr )
{
}

QgsBrowserTreeView::~QgsBrowserTreeView()
{
}

void QgsBrowserTreeView::setBrowserModel( QgsBrowserModel *model )
{
mBrowserModel = model;
}

void QgsBrowserTreeView::setModel( QAbstractItemModel* model )
{

Expand Down Expand Up @@ -78,7 +84,26 @@ void QgsBrowserTreeView::restoreState()
{
QModelIndex expandIndex = QgsBrowserModel::findPath( model(), path, Qt::MatchStartsWith );
if ( expandIndex.isValid() )
expandIndexSet.insert( expandIndex );
{
QModelIndex modelIndex = browserModel()->findPath( path, Qt::MatchExactly );
if ( modelIndex.isValid() )
{
QgsDataItem *ptr = browserModel()->dataItem( modelIndex );
if ( ptr && ( ptr->capabilities2() & QgsDataItem::Capability::Collapse ) )
{
QgsDebugMsgLevel( "do not expand index for path " + path, 4 );
QModelIndex parentIndex = model()->parent( expandIndex );
// Still we need to store the parent in order to expand it
if ( parentIndex.isValid() )
expandIndexSet.insert( parentIndex );
}
else
{
expandIndexSet.insert( expandIndex );
}
}

}
else
{
QgsDebugMsg( "index for path " + path + " not found" );
Expand Down
9 changes: 8 additions & 1 deletion src/gui/qgsbrowsertreeview.h
Expand Up @@ -18,7 +18,7 @@

#include <QTreeView>

//class QgsBrowserModel;
class QgsBrowserModel;

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

virtual void setModel( QAbstractItemModel* model ) override;
//! Set the browser model
void setBrowserModel( QgsBrowserModel *model );
//! Return the browser model
QgsBrowserModel *browserModel( ) { return mBrowserModel; }
virtual void showEvent( QShowEvent * e ) override;
virtual void hideEvent( QHideEvent * e ) override;

Expand Down Expand Up @@ -63,6 +67,9 @@ class GUI_EXPORT QgsBrowserTreeView : public QTreeView

// returns true if expanded from root to item
bool treeExpanded( const QModelIndex & index );

// Stores the browser model
QgsBrowserModel *mBrowserModel;
};

#endif // QGSBROWSERTREEVIEW_H
1 change: 1 addition & 0 deletions src/providers/arcgisrest/qgsafsdataitems.cpp
Expand Up @@ -83,6 +83,7 @@ QgsAfsConnectionItem::QgsAfsConnectionItem( QgsDataItem* parent, const QString &
, mUrl( url )
{
mIconName = "mIconConnect.png";
mCapabilities |= Collapse;
}

QVector<QgsDataItem*> QgsAfsConnectionItem::createChildren()
Expand Down
1 change: 1 addition & 0 deletions src/providers/arcgisrest/qgsamsdataitems.cpp
Expand Up @@ -80,6 +80,7 @@ QgsAmsConnectionItem::QgsAmsConnectionItem( QgsDataItem* parent, QString name, Q
, mUrl( url )
{
mIconName = "mIconConnect.png";
mCapabilities |= Collapse;
}

QVector<QgsDataItem*> QgsAmsConnectionItem::createChildren()
Expand Down
1 change: 1 addition & 0 deletions src/providers/db2/qgsdb2dataitems.cpp
Expand Up @@ -36,6 +36,7 @@ QgsDb2ConnectionItem::QgsDb2ConnectionItem( QgsDataItem *parent, const QString n
: QgsDataCollectionItem( parent, name, path )
{
mIconName = "mIconConnect.png";
mCapabilities |= Collapse;
populate();
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqldataitems.cpp
Expand Up @@ -41,7 +41,7 @@ QgsMssqlConnectionItem::QgsMssqlConnectionItem( QgsDataItem* parent, QString nam
, mAllowGeometrylessTables( true )
, mColumnTypeThread( nullptr )
{
mCapabilities |= Fast;
mCapabilities |= Fast | Collapse;
mIconName = "mIconConnect.png";
}

Expand Down
1 change: 1 addition & 0 deletions src/providers/oracle/qgsoracledataitems.cpp
Expand Up @@ -33,6 +33,7 @@ QgsOracleConnectionItem::QgsOracleConnectionItem( QgsDataItem* parent, QString n
, mColumnTypeThread( nullptr )
{
mIconName = "mIconConnect.png";
mCapabilities |= Collapse;
}

QgsOracleConnectionItem::~QgsOracleConnectionItem()
Expand Down
1 change: 1 addition & 0 deletions src/providers/ows/qgsowsdataitems.cpp
Expand Up @@ -29,6 +29,7 @@ QgsOWSConnectionItem::QgsOWSConnectionItem( QgsDataItem* parent, QString name, Q
: QgsDataCollectionItem( parent, name, path )
{
mIconName = "mIconConnect.png";
mCapabilities |= Collapse;
}

QgsOWSConnectionItem::~QgsOWSConnectionItem()
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -38,6 +38,7 @@ QgsPGConnectionItem::QgsPGConnectionItem( QgsDataItem* parent, QString name, QSt
: QgsDataCollectionItem( parent, name, path )
{
mIconName = "mIconConnect.png";
mCapabilities |= Collapse;
}

QgsPGConnectionItem::~QgsPGConnectionItem()
Expand Down
1 change: 1 addition & 0 deletions src/providers/spatialite/qgsspatialitedataitems.cpp
Expand Up @@ -75,6 +75,7 @@ QgsSLConnectionItem::QgsSLConnectionItem( QgsDataItem* parent, QString name, QSt
{
mDbPath = QgsSpatiaLiteConnection::connectionPath( name );
mToolTip = mDbPath;
mCapabilities |= Collapse;
}

QgsSLConnectionItem::~QgsSLConnectionItem()
Expand Down
9 changes: 5 additions & 4 deletions src/providers/wcs/qgswcsdataitems.cpp
Expand Up @@ -30,6 +30,7 @@ QgsWCSConnectionItem::QgsWCSConnectionItem( QgsDataItem* parent, QString name, Q
, mUri( uri )
{
mIconName = "mIconWcs.svg";
mCapabilities |= Collapse;
}

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

mCapabilities.setUri( uri );
mWcsCapabilities.setUri( uri );

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

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

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

children.append( layer );
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wcs/qgswcsdataitems.h
Expand Up @@ -31,7 +31,7 @@ class QgsWCSConnectionItem : public QgsDataCollectionItem

virtual QList<QAction*> actions() override;

QgsWcsCapabilities mCapabilities;
QgsWcsCapabilities mWcsCapabilities;
QVector<QgsWcsCoverageSummary> mLayerProperties;

public slots:
Expand Down
3 changes: 2 additions & 1 deletion src/providers/wfs/qgswfsdataitems.cpp
Expand Up @@ -46,9 +46,10 @@ QgsWFSLayerItem::~QgsWFSLayerItem()
QgsWFSConnectionItem::QgsWFSConnectionItem( QgsDataItem* parent, QString name, QString path, QString uri )
: QgsDataCollectionItem( parent, name, path )
, mUri( uri )
, mCapabilities( nullptr )
, mWfsCapabilities( nullptr )
{
mIconName = "mIconWfs.svg";
mCapabilities |= Collapse;
}

QgsWFSConnectionItem::~QgsWFSConnectionItem()
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsdataitems.h
Expand Up @@ -58,7 +58,7 @@ class QgsWFSConnectionItem : public QgsDataCollectionItem
private:
QString mUri;

QgsWFSCapabilities* mCapabilities;
QgsWFSCapabilities* mWfsCapabilities;
};


Expand Down
1 change: 1 addition & 0 deletions src/providers/wms/qgswmsdataitems.cpp
Expand Up @@ -35,6 +35,7 @@ QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem* parent, QString name, Q
, mCapabilitiesDownload( nullptr )
{
mIconName = "mIconConnect.png";
mCapabilities |= Collapse;
mCapabilitiesDownload = new QgsWmsCapabilitiesDownload( false );
}

Expand Down

0 comments on commit 5ef70f1

Please sign in to comment.