Skip to content
Permalink
Browse files

GDAL driver selection: show driver extension, flags and long name

  • Loading branch information
etiennesky committed Jul 14, 2012
1 parent dabc492 commit dbce353e9378282b6268136030591b6fbf1a604f
Showing with 158 additions and 18 deletions.
  1. +122 −8 src/app/qgsoptions.cpp
  2. +6 −0 src/app/qgsoptions.h
  3. +30 −10 src/ui/qgsoptionsbase.ui
@@ -45,6 +45,7 @@
#define CPL_SUPRESS_CPLUSPLUS
#include <gdal.h>
#include <geos_c.h>
#include <cpl_conv.h> // for setting gdal options

#include "qgsconfig.h"

@@ -541,10 +542,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
} //default is central point

restoreGeometry( settings.value( "/Windows/Options/geometry" ).toByteArray() );
tabWidget->setCurrentIndex( settings.value( "/Windows/Options/row" ).toInt() );

loadGdalDriverList();
// load gdal driver list only when gdal tab is first opened
mLoadedGdalDriverList = false;

tabWidget->setCurrentIndex( settings.value( "/Windows/Options/row" ).toInt() );
}

//! Destructor
@@ -916,7 +918,8 @@ void QgsOptions::saveOptions()


// Gdal skip driver list
saveGdalDriverList();
if ( mLoadedGdalDriverList )
saveGdalDriverList();
}


@@ -1184,6 +1187,16 @@ void QgsOptions::on_mClearCache_clicked()
#endif
}

void QgsOptions::on_tabWidget_currentChanged( int theTab )
{
// load gdal driver list when gdal tab is first opened
if ( theTab == 1 && ! mLoadedGdalDriverList )
{
loadGdalDriverList();
}
}

#if 0
void QgsOptions::loadGdalDriverList()
{
QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers();
@@ -1228,19 +1241,120 @@ void QgsOptions::loadGdalDriverList()
lstGdalDrivers->addItem( mypItem );
}
}
#endif

void QgsOptions::loadGdalDriverList()
{
QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers();
GDALDriverH myGdalDriver; // current driver
QString myGdalDriverDescription;
QStringList myDrivers;
QMap<QString, QString> myDriversFlags, myDriversExt, myDriversLongName;

// make sure we save list when accept()
mLoadedGdalDriverList = true;

// allow to retrieve metadata from all drivers, they will be skipped again when saving
CPLSetConfigOption( "GDAL_SKIP", "" );
GDALAllRegister();

int myGdalDriverCount = GDALGetDriverCount();
for ( int i = 0; i < myGdalDriverCount; ++i )
{
myGdalDriver = GDALGetDriver( i );

Q_CHECK_PTR( myGdalDriver );

if ( !myGdalDriver )
{
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
continue;
}
myGdalDriverDescription = GDALGetDescription( myGdalDriver );
myDrivers << myGdalDriverDescription;

QgsDebugMsg( QString( "driver #%1 - %2" ).arg( i ).arg( myGdalDriverDescription ) );

// get driver R/W flags, taken from GDALGeneralCmdLineProcessor()
const char *pszRWFlag, *pszVirtualIO;
if ( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_CREATE, NULL ) )
pszRWFlag = "rw+";
else if ( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_CREATECOPY,
NULL ) )
pszRWFlag = "rw";
else
pszRWFlag = "ro";
if ( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_VIRTUALIO, NULL ) )
pszVirtualIO = "v";
else
pszVirtualIO = "";
myDriversFlags[myGdalDriverDescription] = QString( "%1%2" ).arg( pszRWFlag ).arg( pszVirtualIO );

// get driver extensions and long name
// the gdal provider can override/add extensions but there is no interface to query this
// aside from parsing QgsRasterLayer::buildSupportedRasterFileFilter()
myDriversExt[myGdalDriverDescription] = QString( GDALGetMetadataItem( myGdalDriver, "DMD_EXTENSION", "" ) ).toLower();
myDriversLongName[myGdalDriverDescription] = QString( GDALGetMetadataItem( myGdalDriver, "DMD_LONGNAME", "" ) );

}
// restore GDAL_SKIP just in case
CPLSetConfigOption( "GDAL_SKIP", mySkippedDrivers.join( " " ).toUtf8() );

myDrivers.removeDuplicates();
// myDrivers.sort();
// sort list case insensitive - no existing function for this!
QMap<QString, QString> strMap;
foreach( QString str, myDrivers )
{
strMap.insert( str.toLower(), str );
}
myDrivers = strMap.values();

QStringListIterator myIterator( myDrivers );

while ( myIterator.hasNext() )
{
QString myName = myIterator.next();

// QListWidgetItem * mypItem = new QListWidgetItem( myName );
QTreeWidgetItem * mypItem = new QTreeWidgetItem( QStringList( myName ) );
if ( mySkippedDrivers.contains( myName ) )
{
mypItem->setCheckState( 0, Qt::Unchecked );
}
else
{
mypItem->setCheckState( 0, Qt::Checked );
}

// add driver metadata
mypItem->setText( 1, myDriversExt[myName] );
mypItem->setText( 2, myDriversFlags[myName] );
mypItem->setText( 3, myDriversLongName[myName] );

lstGdalDrivers->addTopLevelItem( mypItem );
}
// adjust column width
for ( int i = 0; i < 4; i++ )
{
lstGdalDrivers->resizeColumnToContents( i );
lstGdalDrivers->setColumnWidth( i, lstGdalDrivers->columnWidth( i ) + 5 );
}
}

void QgsOptions::saveGdalDriverList()
{
for ( int i = 0; i < lstGdalDrivers->count(); i++ )
for ( int i = 0; i < lstGdalDrivers->topLevelItemCount(); i++ )
{
QListWidgetItem * mypItem = lstGdalDrivers->item( i );
if ( mypItem->checkState() == Qt::Unchecked )
// QListWidgetItem * mypItem = lstGdalDrivers->item( i );
QTreeWidgetItem * mypItem = lstGdalDrivers->topLevelItem( i );
if ( mypItem->checkState( 0 ) == Qt::Unchecked )
{
QgsApplication::skipGdalDriver( mypItem->text() );
QgsApplication::skipGdalDriver( mypItem->text( 0 ) );
}
else
{
QgsApplication::restoreGdalDriver( mypItem->text() );
QgsApplication::restoreGdalDriver( mypItem->text( 0 ) );
}
}
QSettings mySettings;
@@ -126,6 +126,11 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
void on_mBrowseCacheDirectory_clicked();
void on_mClearCache_clicked();

/** Auto slot executed when the active page in the main widget stack is changed
* @note added in 2.0
*/
void on_tabWidget_currentChanged( int theTab );

/* Load the list of drivers available in GDAL
* @note added in 2.0
*/
@@ -147,6 +152,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
QStringList i18nList();
QgsCoordinateReferenceSystem mDefaultCrs;
QgsCoordinateReferenceSystem mLayerDefaultCrs;
bool mLoadedGdalDriverList;
};

#endif // #ifndef QGSOPTIONS_H
@@ -680,16 +680,6 @@
<string>GDAL Drivers</string>
</property>
<layout class="QGridLayout" name="gridLayout_24">
<item row="1" column="0">
<widget class="QListWidget" name="lstGdalDrivers">
<property name="minimumSize">
<size>
<width>0</width>
<height>141</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
@@ -700,6 +690,36 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="lstGdalDrivers">
<property name="minimumSize">
<size>
<width>0</width>
<height>141</height>
</size>
</property>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>ext</string>
</property>
</column>
<column>
<property name="text">
<string>Flags</string>
</property>
</column>
<column>
<property name="text">
<string>Description</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit dbce353

Please sign in to comment.
You can’t perform that action at this time.