Showing with 101 additions and 74 deletions.
  1. +1 −1 src/app/qgisapp.cpp
  2. +47 −33 src/app/qgsbrowserdockwidget.cpp
  3. +3 −1 src/app/qgsbrowserdockwidget.h
  4. +8 −25 src/core/qgsdataitem.cpp
  5. +21 −7 src/providers/gdal/qgsgdaldataitems.cpp
  6. +21 −7 src/providers/ogr/qgsogrdataitems.cpp
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7968,7 +7968,7 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
else
{
rlp = new QgsRasterLayerProperties( ml, mMapCanvas, this );
connect( rlp, SIGNAL( refreshLegend( QString, QgsLegendItem::Expansion ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, QgsLegendItem::Expansion ) ) );
connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mMapLegend, SLOT( refreshLayerSymbology( QString, bool ) ) );
}

rlp->exec();
Expand Down
80 changes: 47 additions & 33 deletions src/app/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,9 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
{
mModel = new QgsBrowserModel( mBrowserView );

bool useFilter = true;
if ( useFilter ) // enable proxy model
{
// mBrowserView->setModel( mModel );
mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
mProxyModel->setBrowserModel( mModel );
mBrowserView->setModel( mProxyModel );
}
else
{
mBrowserView->setModel( mModel );
}
mProxyModel = new QgsBrowserTreeFilterProxyModel( this );
mProxyModel->setBrowserModel( mModel );
mBrowserView->setModel( mProxyModel );
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
mBrowserView->setTextElideMode( Qt::ElideNone );
mBrowserView->header()->setResizeMode( 0, QHeaderView::ResizeToContents );
Expand All @@ -301,8 +292,8 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )

void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
{
QModelIndex idx = mBrowserView->indexAt( pt );
QgsDataItem* item = dataItem( idx );
QModelIndex index = mProxyModel->mapToSource( mBrowserView->indexAt( pt ) );
QgsDataItem* item = mModel->dataItem( index );
if ( !item )
return;

Expand All @@ -325,6 +316,10 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
menu->addAction( tr( "Remove favourite" ), this, SLOT( removeFavourite() ) );
}
menu->addAction( tr( "Properties" ), this, SLOT( showProperties( ) ) );
QAction *action = menu->addAction( tr( "Fast scan this dir." ), this, SLOT( toggleFastScan( ) ) );
action->setCheckable( true );
action->setChecked( settings.value( "/qgis/scanItemsFastScanUris",
QStringList() ).toStringList().contains( item->path() ) );
}
else if ( item->type() == QgsDataItem::Layer )
{
Expand Down Expand Up @@ -358,7 +353,8 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )

void QgsBrowserDockWidget::addFavourite()
{
QgsDataItem* item = dataItem( mBrowserView->currentIndex() );
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
QgsDataItem* item = mModel->dataItem( index );
if ( !item )
return;

Expand Down Expand Up @@ -390,7 +386,8 @@ void QgsBrowserDockWidget::addFavouriteDirectory( QString favDir )

void QgsBrowserDockWidget::removeFavourite()
{
QgsDataItem* item = dataItem( mBrowserView->currentIndex() );
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
QgsDataItem* item = mModel->dataItem( index );

if ( !item )
return;
Expand Down Expand Up @@ -420,7 +417,7 @@ void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
QgsDebugMsg( "Entered" );
if ( index.isValid() )
{
QgsDataItem *item = dataItem( index );
QgsDataItem *item = mModel->dataItem( index );
if ( item )
{
QgsDebugMsg( "path = " + item->path() );
Expand All @@ -436,7 +433,8 @@ void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
for ( int i = 0 ; i < mModel->rowCount( index ); i++ )
{
QModelIndex idx = mModel->index( i, 0, index );
if ( mBrowserView->isExpanded( idx ) || !mModel->hasChildren( idx ) )
QModelIndex proxyIdx = mProxyModel->mapFromSource( idx );
if ( mBrowserView->isExpanded( proxyIdx ) || !mModel->hasChildren( proxyIdx ) )
{
refreshModel( idx );
}
Expand Down Expand Up @@ -468,7 +466,7 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )

void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index )
{
QgsDataItem *item = dataItem( index );
QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( index ) );

if ( item != NULL && item->type() == QgsDataItem::Layer )
{
Expand Down Expand Up @@ -498,8 +496,7 @@ void QgsBrowserDockWidget::addSelectedLayers()
// add items in reverse order so they are in correct order in the layers dock
for ( int i = list.size() - 1; i >= 0; i-- )
{
QModelIndex index = list[i];
QgsDataItem *item = dataItem( index );
QgsDataItem *item = mModel->dataItem( mProxyModel->mapToSource( list[i] ) );
if ( item && item->type() == QgsDataItem::Layer )
{
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( item );
Expand All @@ -513,9 +510,8 @@ void QgsBrowserDockWidget::addSelectedLayers()

void QgsBrowserDockWidget::showProperties( )
{
QgsDebugMsg( "Entered" );
QModelIndex index = mBrowserView->currentIndex();
QgsDataItem* item = dataItem( index );
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
QgsDataItem* item = mModel->dataItem( index );
if ( ! item )
return;

Expand Down Expand Up @@ -612,6 +608,33 @@ void QgsBrowserDockWidget::showProperties( )
}
}

void QgsBrowserDockWidget::toggleFastScan( )
{
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
QgsDataItem* item = mModel->dataItem( index );
if ( ! item )
return;

if ( item->type() == QgsDataItem::Directory )
{
QSettings settings;
QStringList fastScanDirs = settings.value( "/qgis/scanItemsFastScanUris",
QStringList() ).toStringList();
int idx = fastScanDirs.indexOf( item->path() );
if ( idx != -1 )
{
fastScanDirs.removeAt( idx );
}
else
{
fastScanDirs << item->path();
}
settings.setValue( "/qgis/scanItemsFastScanUris", fastScanDirs );
}
}



void QgsBrowserDockWidget::showFilterWidget( bool visible )
{
mWidgetFilter->setVisible( visible );
Expand All @@ -635,12 +658,3 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action )
return;
mProxyModel->setFilterSyntax(( QRegExp::PatternSyntax ) action->data().toInt() );
}

QgsDataItem* QgsBrowserDockWidget::dataItem( const QModelIndex& index )
{
if ( ! mProxyModel )
return mModel->dataItem( index );
else
return mModel->dataItem( mProxyModel->mapToSource( index ) );
}

4 changes: 3 additions & 1 deletion src/app/qgsbrowserdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrowserDockWidge
void addCurrentLayer();
void addSelectedLayers();
void showProperties();
void toggleFastScan();

protected:
void addFavouriteDirectory( QString favDir );
Expand All @@ -61,7 +62,8 @@ class QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrowserDockWidge

void addLayer( QgsLayerItem *layerItem );

QgsDataItem* dataItem( const QModelIndex& index );
// removed dataItem(), call mModel->dataItem directly (to avoid passing index from the wrong model)

QgsBrowserTreeView* mBrowserView;
QgsBrowserModel* mModel;
QgsBrowserTreeFilterProxyModel* mProxyModel;
Expand Down
33 changes: 8 additions & 25 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,8 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )
QString path = dir.absoluteFilePath( name );
QFileInfo fileInfo( path );

QString vsiPrefix = QgsZipItem::vsiPrefix( path );
// vsizip support was added to GDAL/OGR 1.6 but GDAL_VERSION_NUM not available here
if (( settings.value( "/qgis/scanZipInBrowser2", QVariant( "basic" ) ).toString() != "no" ) &&
( vsiPrefix == "/vsizip/" || vsiPrefix == "/vsitar/" ) )
// so we assume it's available anyway
{
QgsDataItem * item = QgsZipItem::itemFromPath( this, path, name );
if ( item )
Expand Down Expand Up @@ -869,14 +867,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
return children;
}

// if scanZipBrowser == passthru: do not scan zip and allow to open directly with /vsizip/
// if ( scanZipSetting == 1 )
// {
// mPath = "/vsizip/" + path(); // should check for extension
// QgsDebugMsg( "set path to " + path() );
// return children;
// }

// first get list of files
getZipFileList();

Expand Down Expand Up @@ -966,21 +956,15 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QStrin

QgsDebugMsgLevel( QString( "path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path ).arg( name ).arg( scanZipSetting ).arg( vsiPrefix ), 3 );

// if scanZipBrowser == no: don't read the zip file
// don't scan if scanZipBrowser == no
if ( scanZipSetting == "no" )
{
return 0;
}
// if scanZipBrowser == passthru: do not scan zip and allow to open directly with /vsizip/
// else if ( scanZipSetting == 1 )
// {
// vsizipPath = "/vsizip/" + path;
// zipItem = 0;
// }
else
{
zipItem = new QgsZipItem( parent, name, path );
}

// don't scan if this file is not a /vsizip/ or /vsitar/ item
if (( vsiPrefix != "/vsizip/" && vsiPrefix != "/vsitar/" ) )
return 0;

zipItem = new QgsZipItem( parent, name, path );

if ( zipItem )
{
Expand Down Expand Up @@ -1036,7 +1020,6 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QStrin
// try first with normal path (Passthru)
// this is to simplify .qml handling, and without this some tests will fail
// (e.g. testZipItemVectorTransparency(), second test)
// if (( scanZipSetting == 1 ) ||
if (( mProviderNames[i] == "ogr" ) ||
( mProviderNames[i] == "gdal" && zipFileCount == 1 ) )
item = dataItem( path, parent );
Expand Down
28 changes: 21 additions & 7 deletions src/providers/gdal/qgsgdaldataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
bool is_vsigzip = ( vsiPrefix == "/vsigzip/" );
bool is_vsitar = ( vsiPrefix == "/vsitar/" );

// should we check ext. only?
// check if scanItemsInBrowser2 == extension or parent dir in scanItemsFastScanUris
// TODO - do this in dir item, but this requires a way to inform which extensions are supported by provider
// maybe a callback function or in the provider registry?
bool scanExtSetting = false;
if (( settings.value( "/qgis/scanItemsInBrowser2",
"extension" ).toString() == "extension" ) ||
( settings.value( "/qgis/scanItemsFastScanUris",
QStringList() ).toStringList().contains( parentItem->path() ) ) ||
(( is_vsizip || is_vsitar ) && parentItem && parentItem->parent() &&
settings.value( "/qgis/scanItemsFastScanUris",
QStringList() ).toStringList().contains( parentItem->parent()->path() ) ) )
{
scanExtSetting = true;
}

// get suffix, removing .gz if present
QString tmpPath = thePath; //path used for testing, not for layer creation
if ( is_vsigzip )
Expand Down Expand Up @@ -212,13 +228,11 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
}
}

// return a /vsizip/ item without testing if:
// zipfile and scan zip == "Basic scan"
// not zipfile and scan items == "Check extension"
if ((( is_vsizip || is_vsitar ) && scanZipSetting == "basic" ) ||
( !is_vsizip && !is_vsitar &&
( settings.value( "/qgis/scanItemsInBrowser2",
"extension" ).toString() == "extension" ) ) )
// return item without testing if:
// scanExtSetting == true
// or zipfile and scan zip == "Basic scan"
if ( scanExtSetting ||
(( is_vsizip || is_vsitar ) && scanZipSetting == "basic" ) )
{
// if this is a VRT file make sure it is raster VRT to avoid duplicates
if ( suffix == "vrt" )
Expand Down
28 changes: 21 additions & 7 deletions src/providers/ogr/qgsogrdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
bool is_vsigzip = ( vsiPrefix == "/vsigzip/" );
bool is_vsitar = ( vsiPrefix == "/vsitar/" );

// should we check ext. only?
// check if scanItemsInBrowser2 == extension or parent dir in scanItemsFastScanUris
// TODO - do this in dir item, but this requires a way to inform which extensions are supported by provider
// maybe a callback function or in the provider registry?
bool scanExtSetting = false;
if (( settings.value( "/qgis/scanItemsInBrowser2",
"extension" ).toString() == "extension" ) ||
( settings.value( "/qgis/scanItemsFastScanUris",
QStringList() ).toStringList().contains( parentItem->path() ) ) ||
(( is_vsizip || is_vsitar ) && parentItem && parentItem->parent() &&
settings.value( "/qgis/scanItemsFastScanUris",
QStringList() ).toStringList().contains( parentItem->parent()->path() ) ) )
{
scanExtSetting = true;
}

// get suffix, removing .gz if present
QString tmpPath = thePath; //path used for testing, not for layer creation
if ( is_vsigzip )
Expand Down Expand Up @@ -313,13 +329,11 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
}
}

// return a /vsizip/ item without testing if:
// zipfile and scan zip == "Basic scan"
// not zipfile and scan items == "Check extension"
if ((( is_vsizip || is_vsitar ) && scanZipSetting == "basic" ) ||
( !is_vsizip && !is_vsitar &&
( settings.value( "/qgis/scanItemsInBrowser2",
"extension" ).toString() == "extension" ) ) )
// return item without testing if:
// scanExtSetting == true
// or zipfile and scan zip == "Basic scan"
if ( scanExtSetting ||
(( is_vsizip || is_vsitar ) && scanZipSetting == "basic" ) )
{
// if this is a VRT file make sure it is vector VRT to avoid duplicates
if ( suffix == "vrt" )
Expand Down