Skip to content

Commit

Permalink
browser: add Fast Scan option for directories, when activated its ite…
Browse files Browse the repository at this point in the history
…ms will only be checked for extension, not content
  • Loading branch information
etiennesky committed Nov 29, 2012
1 parent 63ebe67 commit 70273b9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 39 deletions.
31 changes: 31 additions & 0 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -316,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 @@ -604,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 Down
1 change: 1 addition & 0 deletions src/app/qgsbrowserdockwidget.h
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 Down
33 changes: 8 additions & 25 deletions src/core/qgsdataitem.cpp
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
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
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

0 comments on commit 70273b9

Please sign in to comment.