Skip to content
Permalink
Browse files

Store and retrieve provider name from item custom data

  • Loading branch information
nyalldawson committed Mar 9, 2021
1 parent e3106ad commit c0269b8df34d89cf67cba6254cacfc04e9cc8d29
Showing with 11 additions and 7 deletions.
  1. +9 −7 src/app/qgshandlebadlayers.cpp
  2. +2 −0 src/app/qgshandlebadlayers.h
@@ -30,6 +30,7 @@
#include "qgsapplication.h"
#include "qgsfileutils.h"
#include "qgsprovidermetadata.h"
#include "qgsmaplayerfactory.h"

#include <QDomDocument>
#include <QDomElement>
@@ -146,10 +147,13 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers )

QTableWidgetItem *item = nullptr;

bool ok = false;
item = new QTableWidgetItem( name );
item->setData( static_cast< int >( CustomRoles::Index ), i );
item->setData( static_cast< int >( CustomRoles::Provider ), provider );
item->setData( static_cast< int >( CustomRoles::ProviderIsFileBased ), providerFileBased );
item->setData( static_cast< int >( CustomRoles::LayerId ), layerId );
item->setData( static_cast< int >( CustomRoles::LayerType ), static_cast< int >( QgsMapLayerFactory::typeFromString( type, ok ) ) );
item->setFlags( item->flags() & ~Qt::ItemIsEditable );
mLayerList->setItem( j, 0, item );

@@ -374,9 +378,7 @@ void QgsHandleBadLayers::editAuthCfg()
if ( row == -1 )
return;

QString provider = mLayerList->item( row, 2 )->text();
if ( provider == QLatin1String( "none" ) )
provider.clear();
const QString provider = mLayerList->item( row, 0 )->data( static_cast< int >( CustomRoles::Provider ) ).toString();

QString prevuri = mLayerList->item( row, 4 )->text();

@@ -406,12 +408,12 @@ void QgsHandleBadLayers::apply()
QTableWidgetItem *item = mLayerList->item( i, 4 );
QString datasource = item->text();
QString fileName;
const QString layerId { node.namedItem( QStringLiteral( "id" ) ).toElement().text() };
const QString layerId = mLayerList->item( i, 0 )->data( static_cast< int >( CustomRoles::LayerId ) ).toString();
const QString name { mLayerList->item( i, 0 )->text() };
const QFileInfo dataInfo = QFileInfo( datasource );
const QString basepath = dataInfo.absoluteDir().path();
const QString longName = dataInfo.fileName();
QString provider = node.namedItem( QStringLiteral( "provider" ) ).toElement().text();
QString provider = mLayerList->item( i, 0 )->data( static_cast< int >( CustomRoles::Provider ) ).toString();
const QString fileType = mLayerList->item( i, 2 )->text();
if ( provider.toLower().toStdString() == "none" )
{
@@ -579,12 +581,12 @@ void QgsHandleBadLayers::autoFind()
QTableWidgetItem *item = mLayerList->item( i, 4 );
QString datasource = item->text();
QString fileName;
const QString layerId { node.namedItem( QStringLiteral( "id" ) ).toElement().text() };
const QString layerId = mLayerList->item( i, 0 )->data( static_cast< int >( CustomRoles::LayerId ) ).toString();
const QString name { mLayerList->item( i, 0 )->text() };
const QFileInfo dataInfo = QFileInfo( datasource );
const QString basepath = dataInfo.absoluteDir().path();
const QString longName = dataInfo.fileName();
QString provider = node.namedItem( QStringLiteral( "provider" ) ).toElement().text();
QString provider = mLayerList->item( i, 0 )->data( static_cast< int >( CustomRoles::Provider ) ).toString();
const QString fileType = mLayerList->item( i, 2 )->text();

progressDialog.setValue( i );
@@ -75,6 +75,8 @@ class APP_EXPORT QgsHandleBadLayers
enum class CustomRoles : int
{
Index = Qt::UserRole,
LayerType,
Provider,
ProviderIsFileBased,
DataSourceIsChanged,
LayerId,

0 comments on commit c0269b8

Please sign in to comment.