Skip to content

Commit

Permalink
Store and retrieve provider name from item custom data
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 9, 2021
1 parent e3106ad commit c0269b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/app/qgshandlebadlayers.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgsapplication.h"
#include "qgsfileutils.h"
#include "qgsprovidermetadata.h"
#include "qgsmaplayerfactory.h"

#include <QDomDocument>
#include <QDomElement>
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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" )
{
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgshandlebadlayers.h
Expand Up @@ -75,6 +75,8 @@ class APP_EXPORT QgsHandleBadLayers
enum class CustomRoles : int
{
Index = Qt::UserRole,
LayerType,
Provider,
ProviderIsFileBased,
DataSourceIsChanged,
LayerId,
Expand Down

0 comments on commit c0269b8

Please sign in to comment.