Skip to content

Commit

Permalink
Bad layer dialog improvements (Funded by Sourcepole)
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 9, 2014
1 parent 7a92293 commit 2e943c9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
6 changes: 6 additions & 0 deletions python/core/qgsproviderregistry.sip
Expand Up @@ -39,6 +39,12 @@ class QgsProviderRegistry
QgsDataProvider *provider( const QString & providerKey,
const QString & dataSource );

/** Return the provider capabilities
@param providerKey identificator of the provider
@note Added in 2.6
*/
int getProviderCapabilities( const QString& providerKey ) const;

QWidget *selectWidget( const QString & providerKey,
QWidget * parent = 0, Qt::WindowFlags fl = 0 );

Expand Down
35 changes: 23 additions & 12 deletions src/app/qgshandlebadlayers.cpp
Expand Up @@ -26,8 +26,10 @@

#include <QDomDocument>
#include <QDomElement>
#include <QFileDialog>
#include <QPushButton>
#include <QMessageBox>
#include <QSettings>
#include <QUrl>

QgsHandleBadLayersHandler::QgsHandleBadLayersHandler()
Expand Down Expand Up @@ -71,7 +73,6 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo

connect( mLayerList, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) );
connect( mBrowseButton, SIGNAL( clicked() ), this, SLOT( browseClicked() ) );
connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );

mLayerList->clear();
Expand All @@ -94,12 +95,14 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo
QString name = node.namedItem( "layername" ).toElement().text();
QString type = node.toElement().attribute( "type" );
QString datasource = node.namedItem( "datasource" ).toElement().text();
QString provider = type == "vector" ? node.namedItem( "provider" ).toElement().text() : tr( "none" );
QString provider = node.namedItem( "provider" ).toElement().text();
QString vectorProvider = type == "vector" ? provider : tr( "none" );
bool providerFileBased = ( QgsProviderRegistry::instance()->getProviderCapabilities( provider ) & QgsDataProvider::File ) != 0;

QgsDebugMsg( QString( "name=%1 type=%2 provider=%3 datasource='%4'" )
.arg( name )
.arg( type )
.arg( provider )
.arg( vectorProvider )
.arg( datasource ) );

mLayerList->setRowCount( j + 1 );
Expand All @@ -112,10 +115,11 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo
mLayerList->setItem( j, 0, item );

item = new QTableWidgetItem( type );
item->setData( Qt::UserRole + 0, providerFileBased );
item->setFlags( item->flags() & ~Qt::ItemIsEditable );
mLayerList->setItem( j, 1, item );

item = new QTableWidgetItem( provider );
item = new QTableWidgetItem( vectorProvider );
item->setFlags( item->flags() & ~Qt::ItemIsEditable );
mLayerList->setItem( j, 2, item );

Expand Down Expand Up @@ -143,6 +147,10 @@ void QgsHandleBadLayers::selectionChanged()
if ( item->column() != 0 )
continue;

bool providerFileBased = mLayerList->item( item->row(), 1 )->data( Qt::UserRole + 0 ).toBool();
if ( !providerFileBased )
continue;

mRows << item->row();
}

Expand Down Expand Up @@ -261,31 +269,34 @@ void QgsHandleBadLayers::browseClicked()
}
else if ( mRows.size() > 1 )
{
QStringList selectedFiles;
QString enc;
QString title = tr( "Select new directory of selected files" );

QgisGui::openFilesRememberingFilter( "missingDirectory", tr( "All files (*)" ), selectedFiles, enc, title );
if ( selectedFiles.isEmpty() )
QSettings settings;
QString lastDir = settings.value( "/UI/missingDirectory", "" ).toString();
QString selectedFolder = QFileDialog::getExistingDirectory( this, title, lastDir );
if ( selectedFolder.isEmpty() )
{
return;
}

QFileInfo path( selectedFiles[0] );
if ( !path.exists() )
QDir dir( selectedFolder );
if ( !dir.exists() )
{
return;
}

foreach ( int row, mRows )
{
QString type = mLayerList->item( row, 1 )->text();
bool providerFileBased = mLayerList->item( row, 1 )->data( Qt::UserRole + 0 ).toBool();
if ( !providerFileBased )
continue;

QString fn = filename( row );
if ( fn.isEmpty() )
continue;

QFileInfo fi( fn );
fi.setFile( path.dir(), fi.fileName() );
fi.setFile( dir, fi.fileName() );
if ( !fi.exists() )
continue;

Expand Down
2 changes: 0 additions & 2 deletions src/core/qgsdataitem.h
Expand Up @@ -32,8 +32,6 @@
class QgsDataProvider;
class QgsDataItem;

// TODO: bad place, where to put this? qgsproviderregistry.h?
typedef int dataCapabilities_t();
typedef QgsDataItem * dataItem_t( QString, QgsDataItem* );


Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsdataprovider.h
Expand Up @@ -24,6 +24,8 @@
//#include "qgsdataitem.h"
#include "qgserror.h"

typedef int dataCapabilities_t();

class QgsRectangle;
class QgsCoordinateReferenceSystem;

Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsproviderregistry.cpp
Expand Up @@ -371,6 +371,21 @@ QgsDataProvider *QgsProviderRegistry::provider( QString const & providerKey, QSt
return dataProvider;
} // QgsProviderRegistry::setDataProvider

int QgsProviderRegistry::getProviderCapabilities( const QString &providerKey ) const
{
QLibrary *library = providerLibrary( providerKey );
if ( !library )
{
return QgsDataProvider::NoDataCapabilities;
}
dataCapabilities_t * dataCapabilities = ( dataCapabilities_t * ) cast_to_fptr( library->resolve( "dataCapabilities" ) );
if ( !dataCapabilities )
{
return QgsDataProvider::NoDataCapabilities;
}
return dataCapabilities();
}

// This should be QWidget, not QDialog
typedef QWidget * selectFactoryFunction_t( QWidget * parent, Qt::WindowFlags fl );

Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsproviderregistry.h
Expand Up @@ -68,6 +68,12 @@ class CORE_EXPORT QgsProviderRegistry
QgsDataProvider *provider( const QString & providerKey,
const QString & dataSource );

/** Return the provider capabilities
@param providerKey identificator of the provider
@note Added in 2.6
*/
int getProviderCapabilities( const QString& providerKey ) const;

QWidget *selectWidget( const QString & providerKey,
QWidget * parent = 0, Qt::WindowFlags fl = 0 );

Expand Down

0 comments on commit 2e943c9

Please sign in to comment.