Skip to content
Permalink
Browse files
Fix clazy warnings in QgsGrassProviderModule
  • Loading branch information
nyalldawson committed Jun 1, 2021
1 parent 8f8c908 commit f1aab15816c3e809842c2db4b727641bf83385ae
Showing with 79 additions and 64 deletions.
  1. +57 −55 src/providers/grass/qgsgrassprovidermodule.cpp
  2. +22 −9 src/providers/grass/qgsgrassprovidermodule.h
@@ -27,7 +27,6 @@
#include "qgsgrassprovider.h"
#include "qgsgrass.h"
#include "qgsgrassvector.h"
#include "qgsprovidermetadata.h"

#ifdef HAVE_GUI
#include "qgsnewnamedialog.h"
@@ -131,7 +130,7 @@ void QgsGrassItemActions::newMapset()
{

QStringList existingNames = QgsGrass::mapsets( mGrassObject.gisdbase(), mGrassObject.mapsetPath() );
QgsDebugMsg( "existingNames = " + existingNames.join( "," ) );
QgsDebugMsg( QStringLiteral( "existingNames = " ) + existingNames.join( ',' ) );
QRegExp regExp = QgsGrassObject::newNameRegExp( QgsGrassObject::Mapset );
Qt::CaseSensitivity caseSensitivity = QgsGrass::caseSensitivity();
QgsNewNameDialog dialog( QString(), QString(), QStringList(), existingNames, regExp, caseSensitivity );
@@ -189,7 +188,7 @@ void QgsGrassItemActions::renameGrassObject()
QStringList existingNames = QgsGrass::grassObjects( mGrassObject, mGrassObject.type() );
// remove current name to avoid warning that exists
existingNames.removeOne( mGrassObject.name() );
QgsDebugMsg( "existingNames = " + existingNames.join( "," ) );
QgsDebugMsg( QStringLiteral( "existingNames = " ) + existingNames.join( ',' ) );
QRegExp regExp = QgsGrassObject::newNameRegExp( mGrassObject.type() );
Qt::CaseSensitivity caseSensitivity = QgsGrass::caseSensitivity();
QgsNewNameDialog dialog( mGrassObject.name(), mGrassObject.name(), QStringList(), existingNames, regExp, caseSensitivity );
@@ -243,7 +242,7 @@ QString QgsGrassItemActions::newVectorMap()
{

QStringList existingNames = QgsGrass::grassObjects( mGrassObject, QgsGrassObject::Vector );
QgsDebugMsg( "existingNames = " + existingNames.join( "," ) );
QgsDebugMsg( QStringLiteral( "existingNames = " ) + existingNames.join( ',' ) );
QRegExp regExp = QgsGrassObject::newNameRegExp( QgsGrassObject::Vector );
Qt::CaseSensitivity caseSensitivity = QgsGrass::caseSensitivity();
QgsNewNameDialog dialog( QString(), QString(), QStringList(), existingNames, regExp, caseSensitivity );
@@ -286,7 +285,7 @@ void QgsGrassItemActions::newLayer( const QString &type )
QgsDebugMsg( "name = " + name );
if ( name.isEmpty() )
{
QgsDebugMsg( "culd not create map" );
QgsDebugMsg( QStringLiteral( "could not create map" ) );
return;
}

@@ -298,7 +297,7 @@ void QgsGrassItemActions::newLayer( const QString &type )
vector.openHead();
int layerNumber = vector.maxLayerNumber() + 1;

QgsDebugMsg( QString( "layerNumber = %1" ).arg( layerNumber ) );
QgsDebugMsg( QStringLiteral( "layerNumber = %1" ).arg( layerNumber ) );

QString uri = mGrassObject.mapsetPath() + "/" + name + QStringLiteral( "/%1_%2" ).arg( layerNumber ).arg( type );
QgsDebugMsg( "uri = " + uri );
@@ -330,7 +329,7 @@ QgsGrassObjectItemBase::QgsGrassObjectItemBase( const QgsGrassObject &grassObjec

//----------------------- QgsGrassLocationItem ------------------------------

QgsGrassLocationItem::QgsGrassLocationItem( QgsDataItem *parent, QString dirPath, QString path )
QgsGrassLocationItem::QgsGrassLocationItem( QgsDataItem *parent, const QString &dirPath, const QString &path )
: QgsDirectoryItem( parent, QString(), dirPath, path )
, QgsGrassObjectItemBase( QgsGrassObject() )
{
@@ -358,9 +357,9 @@ QVector<QgsDataItem *>QgsGrassLocationItem::createChildren()

QDir dir( mDirPath );

QStringList entries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name );
const auto constEntries = entries;
for ( const QString &name : constEntries )
const QStringList entries = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name );
mapsets.reserve( entries.size() );
for ( const QString &name : entries )
{
QString path = dir.absoluteFilePath( name );

@@ -375,15 +374,15 @@ QVector<QgsDataItem *>QgsGrassLocationItem::createChildren()

QIcon QgsGrassLocationItem::icon()
{
return QgsApplication::getThemeIcon( "/grass_mapset.svg" );
return QgsApplication::getThemeIcon( QStringLiteral( "/grass_mapset.svg" ) );
}


//----------------------- QgsGrassMapsetItem ------------------------------

QList<QgsGrassImport *> QgsGrassMapsetItem::sImports;

QgsGrassMapsetItem::QgsGrassMapsetItem( QgsDataItem *parent, QString dirPath, QString path )
QgsGrassMapsetItem::QgsGrassMapsetItem( QgsDataItem *parent, const QString &dirPath, const QString &path )
: QgsDirectoryItem( parent, QString(), dirPath, path )
, QgsGrassObjectItemBase( QgsGrassObject() )
, mRefreshLater( false )
@@ -411,16 +410,16 @@ QIcon QgsGrassMapsetItem::icon()
{
if ( mGrassObject == QgsGrass::getDefaultMapsetObject() )
{
return QgsApplication::getThemeIcon( "/grass_mapset_open.svg" );
return QgsApplication::getThemeIcon( QStringLiteral( "/grass_mapset_open.svg" ) );
}
else if ( mGrassObject.locationIdentical( QgsGrass::getDefaultLocationObject() ) )
{
if ( QgsGrass::instance()->isMapsetInSearchPath( mGrassObject.mapset() ) )
{
return QgsApplication::getThemeIcon( "/grass_mapset_search.svg" );
return QgsApplication::getThemeIcon( QStringLiteral( "/grass_mapset_search.svg" ) );
}
}
return QgsApplication::getThemeIcon( "/grass_mapset.svg" );
return QgsApplication::getThemeIcon( QStringLiteral( "/grass_mapset.svg" ) );
}

void QgsGrassMapsetItem::setState( Qgis::BrowserItemState state )
@@ -516,7 +515,7 @@ QVector<QgsDataItem *> QgsGrassMapsetItem::createChildren()
int topoMajor = 0;
int topoMinor = 0;
bool gotTopoVersion = QgsGrass::topoVersion( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset(), name, topoMajor, topoMinor );
QgsDebugMsg( QString( "name = %1 topoMajor = %2 topoMinor = %3" ).arg( name ).arg( topoMajor ).arg( topoMinor ) );
QgsDebugMsg( QStringLiteral( "name = %1 topoMajor = %2 topoMinor = %3" ).arg( name ).arg( topoMajor ).arg( topoMinor ) );
QString topoError;
if ( !gotTopoVersion )
{
@@ -754,7 +753,7 @@ bool QgsGrassMapsetItem::handleDrop( const QMimeData *data, Qt::DropAction )
existingNames = existingVectors;
regExp = QgsGrassObject::newNameRegExp( QgsGrassObject::Vector );
}
QgsDebugMsg( "existingNames = " + existingNames.join( "," ) );
QgsDebugMsg( QStringLiteral( "existingNames = " ) + existingNames.join( ',' ) );

if ( useCopy )
{
@@ -800,7 +799,7 @@ bool QgsGrassMapsetItem::handleDrop( const QMimeData *data, Qt::DropAction )
QgsGrassImport *import = nullptr;
if ( useCopy )
{
QgsDebugMsg( "location is the same -> g.copy" );
QgsDebugMsg( QStringLiteral( "location is the same -> g.copy" ) );
QgsGrassObject destObject( mGrassObject );
destObject.setName( destName );
destObject.setType( srcObject.type() );
@@ -822,7 +821,7 @@ bool QgsGrassMapsetItem::handleDrop( const QMimeData *data, Qt::DropAction )
{
// TODO: open dialog with size options
// use location default
QgsDebugMsg( "Unknown size -> using default location region" );
QgsDebugMsg( QStringLiteral( "Unknown size -> using default location region" ) );
struct Cell_head window;
if ( !QgsGrass::defaultRegion( mGrassObject.gisdbase(), mGrassObject.location(), &window ) )
{
@@ -869,7 +868,7 @@ bool QgsGrassMapsetItem::handleDrop( const QMimeData *data, Qt::DropAction )
pipe->set( projector );
}
QgsDebugMsg( "newExtent = " + newExtent.toString() );
QgsDebugMsg( QString( "newXSize = %1 newYSize = %2" ).arg( newXSize ).arg( newYSize ) );
QgsDebugMsg( QStringLiteral( "newXSize = %1 newYSize = %2" ).arg( newXSize ).arg( newYSize ) );

//QString path = mPath + "/" + "raster" + "/" + u.name;
import = new QgsGrassRasterImport( pipe, rasterObject, newExtent, newXSize, newYSize ); // takes pipe ownership
@@ -965,7 +964,7 @@ void QgsGrassMapsetItem::onDirectoryChanged()

void QgsGrassMapsetItem::childrenCreated()
{
QgsDebugMsg( QString( "mRefreshLater = %1" ).arg( mRefreshLater ) );
QgsDebugMsg( QStringLiteral( "mRefreshLater = %1" ).arg( mRefreshLater ) );

if ( mRefreshLater )
{
@@ -983,8 +982,8 @@ void QgsGrassMapsetItem::childrenCreated()
//------------------------ QgsGrassObjectItem ----------------------------------

QgsGrassObjectItem::QgsGrassObjectItem( QgsDataItem *parent, QgsGrassObject grassObject,
QString name, QString path, QString uri,
Qgis::BrowserLayerType layerType, QString providerKey )
const QString &name, const QString &path, const QString &uri,
Qgis::BrowserLayerType layerType, const QString &providerKey )
: QgsLayerItem( parent, name, path, uri, layerType, providerKey )
, QgsGrassObjectItemBase( grassObject )
{
@@ -1002,7 +1001,7 @@ bool QgsGrassObjectItem::equal( const QgsDataItem *other )

//----------------------- QgsGrassVectorItem ------------------------------

QgsGrassVectorItem::QgsGrassVectorItem( QgsDataItem *parent, QgsGrassObject grassObject, QString path, QString labelName, bool valid )
QgsGrassVectorItem::QgsGrassVectorItem( QgsDataItem *parent, QgsGrassObject grassObject, const QString &path, const QString &labelName, bool valid )
: QgsDataCollectionItem( parent, labelName.isEmpty() ? grassObject.name() : labelName, path )
, QgsGrassObjectItemBase( grassObject )
, mValid( valid )
@@ -1068,8 +1067,8 @@ bool QgsGrassVectorItem::equal( const QgsDataItem *other )

//----------------------- QgsGrassVectorLayerItem ------------------------------

QgsGrassVectorLayerItem::QgsGrassVectorLayerItem( QgsDataItem *parent, QgsGrassObject grassObject, QString layerName,
QString path, QString uri,
QgsGrassVectorLayerItem::QgsGrassVectorLayerItem( QgsDataItem *parent, QgsGrassObject grassObject, const QString &layerName,
const QString &path, const QString &uri,
Qgis::BrowserLayerType layerType, bool singleLayer )
: QgsGrassObjectItem( parent, grassObject, layerName, path, uri, layerType, QStringLiteral( "grass" ) )
, mSingleLayer( singleLayer )
@@ -1098,7 +1097,7 @@ bool QgsGrassVectorLayerItem::equal( const QgsDataItem *other )
//----------------------- QgsGrassRasterItem ------------------------------

QgsGrassRasterItem::QgsGrassRasterItem( QgsDataItem *parent, QgsGrassObject grassObject,
QString path, QString uri, bool isExternal )
const QString &path, const QString &uri, bool isExternal )
: QgsGrassObjectItem( parent, grassObject, grassObject.name(), path, uri, Qgis::BrowserLayerType::Raster, QStringLiteral( "grassraster" ) )
, mExternal( isExternal )
{
@@ -1122,7 +1121,7 @@ bool QgsGrassRasterItem::equal( const QgsDataItem *other )
//----------------------- QgsGrassGroupItem ------------------------------

QgsGrassGroupItem::QgsGrassGroupItem( QgsDataItem *parent, QgsGrassObject grassObject,
QString path, QString uri )
const QString &path, const QString &uri )
: QgsGrassObjectItem( parent, grassObject, grassObject.name(), path, uri, Qgis::BrowserLayerType::Raster, QStringLiteral( "grassraster" ) )
{
}
@@ -1219,7 +1218,7 @@ void QgsGrassImportItem::cancel()
{
if ( !mImport ) // should not happen
{
QgsDebugMsg( "mImport is null" );
QgsDebugMsg( QStringLiteral( "mImport is null" ) );
return;
}
if ( mImport->isCanceled() )
@@ -1286,36 +1285,39 @@ class QgsGrassDataItemProvider : public QgsDataItemProvider
}
};

class QgsGrassProviderMetadata: public QgsProviderMetadata

QgsGrassProviderMetadata::QgsGrassProviderMetadata()
: QgsProviderMetadata( PROVIDER_KEY, PROVIDER_DESCRIPTION )
{}

QgsDataProvider *QgsGrassProviderMetadata::createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
{
public:
QgsGrassProviderMetadata(): QgsProviderMetadata( PROVIDER_KEY, PROVIDER_DESCRIPTION ) {}
QgsGrassProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) override
{
Q_UNUSED( options );
Q_UNUSED( flags );
return new QgsGrassProvider( uri );
}
QList< QgsDataItemProvider * > dataItemProviders() const override
{
QList< QgsDataItemProvider * > providers;
providers << new QgsGrassDataItemProvider;
return providers;
}
Q_UNUSED( options )
Q_UNUSED( flags )
return new QgsGrassProvider( uri );
}

QList<QgsDataItemProvider *> QgsGrassProviderMetadata::dataItemProviders() const
{
QList< QgsDataItemProvider * > providers;
providers << new QgsGrassDataItemProvider;
return providers;
}

void QgsGrassProviderMetadata::initProvider()
{
// Init GRASS in the first function called by provider registry so that it is called
// on main thread, not sure but suspicious that init in thread is causing problems,
// at least on Windows, not that dataItem() is called in thread
if ( !QgsGrass::init() )
{
QgsDebugMsg( QStringLiteral( "init failed" ) );
}
}

void initProvider() override
{
// Init GRASS in the first function called by provider registry so that it is called
// on main thread, not sure but suspicious that init in thread is causing problems,
// at least on Windows, not that dataItem() is called in thread
if ( !QgsGrass::init() )
{
QgsDebugMsg( "init failed" );
}
}
};

QGISEXTERN QgsProviderMetadata *providerMetadataFactory()
{
return new QgsGrassProviderMetadata();
}

@@ -22,6 +22,7 @@
#include "qgsdirectoryitem.h"
#include "qgslayeritem.h"
#include "qgsdatacollectionitem.h"
#include "qgsprovidermetadata.h"

class QTextEdit;
class QProgressBar;
@@ -84,7 +85,7 @@ class QgsGrassLocationItem : public QgsDirectoryItem, public QgsGrassObjectItemB
Q_OBJECT

public:
QgsGrassLocationItem( QgsDataItem *parent, QString dirPath, QString path );
QgsGrassLocationItem( QgsDataItem *parent, const QString &dirPath, const QString &path );

QIcon icon() override;

@@ -104,7 +105,7 @@ class QgsGrassMapsetItem : public QgsDirectoryItem, public QgsGrassObjectItemBas
{
Q_OBJECT
public:
QgsGrassMapsetItem( QgsDataItem *parent, QString dirPath, QString path );
QgsGrassMapsetItem( QgsDataItem *parent, const QString &dirPath, const QString &path );

void setState( Qgis::BrowserItemState state ) override;

@@ -140,8 +141,8 @@ class QgsGrassObjectItem : public QgsLayerItem, public QgsGrassObjectItemBase
Q_OBJECT
public:
QgsGrassObjectItem( QgsDataItem *parent, QgsGrassObject grassObject,
QString name, QString path, QString uri,
Qgis::BrowserLayerType layerType, QString providerKey );
const QString &name, const QString &path, const QString &uri,
Qgis::BrowserLayerType layerType, const QString &providerKey );

#ifdef HAVE_GUI
QList<QAction *> actions( QWidget *parent ) override { return mActions->actions( parent ); }
@@ -161,7 +162,7 @@ class QgsGrassVectorItem : public QgsDataCollectionItem, public QgsGrassObjectIt
Q_OBJECT
public:
// labelName - name to be displayed in tree if it should be different from grassObject.name() (e.g. invalid vector)
QgsGrassVectorItem( QgsDataItem *parent, QgsGrassObject grassObject, QString path, QString labelName = QString(), bool valid = true );
QgsGrassVectorItem( QgsDataItem *parent, QgsGrassObject grassObject, const QString &path, const QString &labelName = QString(), bool valid = true );
~QgsGrassVectorItem() override;

#ifdef HAVE_GUI
@@ -185,8 +186,8 @@ class QgsGrassVectorLayerItem : public QgsGrassObjectItem
{
Q_OBJECT
public:
QgsGrassVectorLayerItem( QgsDataItem *parent, QgsGrassObject vector, QString layerName,
QString path, QString uri, Qgis::BrowserLayerType layerType, bool singleLayer );
QgsGrassVectorLayerItem( QgsDataItem *parent, QgsGrassObject vector, const QString &layerName,
const QString &path, const QString &uri, Qgis::BrowserLayerType layerType, bool singleLayer );

QString layerName() const override;
bool equal( const QgsDataItem *other ) override;
@@ -201,7 +202,7 @@ class QgsGrassRasterItem : public QgsGrassObjectItem
Q_OBJECT
public:
QgsGrassRasterItem( QgsDataItem *parent, QgsGrassObject grassObject,
QString path, QString uri, bool isExternal );
const QString &path, const QString &uri, bool isExternal );

QIcon icon() override;
bool equal( const QgsDataItem *other ) override;
@@ -217,7 +218,7 @@ class QgsGrassGroupItem : public QgsGrassObjectItem
Q_OBJECT
public:
QgsGrassGroupItem( QgsDataItem *parent, QgsGrassObject grassObject,
QString path, QString uril );
const QString &path, const QString &uril );

QIcon icon() override;

@@ -273,4 +274,16 @@ class QgsGrassImportItem : public QgsDataItem, public QgsGrassObjectItemBase
static QgsAnimatedIcon *sImportIcon;
};


class QgsGrassProviderMetadata: public QgsProviderMetadata
{
Q_OBJECT

public:
QgsGrassProviderMetadata();
QgsDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) override;
QList< QgsDataItemProvider * > dataItemProviders() const override;
void initProvider() override;
};

#endif // QGSGRASSPROVIDERMODULE_H

0 comments on commit f1aab15

Please sign in to comment.