Skip to content

Commit

Permalink
[GRASS][FEATURE] delete raster map browser action
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed May 4, 2015
1 parent e05246d commit eb964f9
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 55 deletions.
1 change: 1 addition & 0 deletions src/providers/grass/qgsgrass.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class QgsGrassObject
//! Element type
enum Type { None, Raster, Vector, Region };

QgsGrassObject() {}
QgsGrassObject( const QString& gisdbase, const QString& location = QString::null,
const QString& mapset = QString::null, const QString& name = QString::null,
Type type = None );
Expand Down
110 changes: 62 additions & 48 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,93 +147,107 @@ QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
QString uri = mDirPath + "/" + "cellhd" + "/" + name;
QgsDebugMsg( "uri = " + uri );

QgsLayerItem *layer = new QgsLayerItem( this, name, path, uri, QgsLayerItem::Raster, "grassraster" );
layer->setState( Populated );
QgsGrassObject rasterObject( mGisdbase, mLocation, mName, name, QgsGrassObject::Raster );
QgsGrassRasterItem *layer = new QgsGrassRasterItem( this, rasterObject, path, uri );

items.append( layer );
}

return items;
}

QgsGrassVectorItem::QgsGrassVectorItem( QgsDataItem* parent, QgsGrassObject vector, QString path ) :
QgsDataCollectionItem( parent, vector.name(), path )
, mVector( vector )
QgsGrassObjectItemBase::QgsGrassObjectItemBase( QgsGrassObject grassObject ) :
mGrassObject( grassObject )
{
QgsDebugMsg( "name = " + vector.name() + " path = " + path );
setCapabilities( QgsDataItem::NoCapabilities ); // disable fertility
}

QList<QAction*> QgsGrassVectorItem::actions()
{
QList<QAction*> lst;

QAction* actionDelete = new QAction( tr( "Delete" ), this );
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteMap() ) );
lst.append( actionDelete );

return lst;
}

void QgsGrassVectorItem::deleteMap()
void QgsGrassObjectItemBase::deleteGrassObject( QgsDataItem* parent )
{
QgsDebugMsg( "Entered" );

if ( !QgsGrass::deleteObjectDialog( mVector ) )
if ( !QgsGrass::deleteObjectDialog( mGrassObject ) )
return;

// Warning if failed is currently in QgsGrass::deleteMap
if ( QgsGrass::deleteObject( mVector ) )
if ( QgsGrass::deleteObject( mGrassObject ) )
{
// message on success is redundant, like in normal file browser
if ( mParent )
mParent->refresh();
if ( parent )
parent->refresh();
}
}

QgsGrassVectorLayerItem::QgsGrassVectorLayerItem( QgsDataItem* parent, QgsGrassObject vector, QString layerName,
QString path, QString uri,
LayerType layerType, bool singleLayer )
: QgsLayerItem( parent, layerName, path, uri, layerType, "grass" )
, mVector( vector )
, mSingleLayer( singleLayer )
QgsGrassObjectItem::QgsGrassObjectItem( QgsDataItem* parent, QgsGrassObject grassObject,
QString name, QString path, QString uri,
LayerType layerType, QString providerKey,
bool deleteAction )
: QgsLayerItem( parent, name, path, uri, layerType, providerKey )
, QgsGrassObjectItemBase( grassObject )
, mDeleteAction( deleteAction )
{
setState( Populated ); // no children, to show non expandable in browser
}

QString QgsGrassVectorLayerItem::layerName() const
{
// to get map + layer when added from browser
return mVector.name() + " " + name();
}


QList<QAction*> QgsGrassVectorLayerItem::actions()
QList<QAction*> QgsGrassObjectItem::actions()
{
QList<QAction*> lst;

if ( mSingleLayer )
if ( mDeleteAction )
{
QAction* actionDelete = new QAction( tr( "Delete" ), this );
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteMap() ) );
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteGrassObject() ) );
lst.append( actionDelete );
}

return lst;
}

void QgsGrassVectorLayerItem::deleteMap()
void QgsGrassObjectItem::deleteGrassObject()
{
QgsDebugMsg( "Entered" );
QgsGrassObjectItemBase::deleteGrassObject( parent() );
}

if ( !QgsGrass::deleteObjectDialog( mVector ) )
return;
QgsGrassVectorItem::QgsGrassVectorItem( QgsDataItem* parent, QgsGrassObject grassObject, QString path ) :
QgsDataCollectionItem( parent, grassObject.name(), path )
, QgsGrassObjectItemBase( grassObject )
{
QgsDebugMsg( "name = " + grassObject.name() + " path = " + path );
setCapabilities( QgsDataItem::NoCapabilities ); // disable fertility
}

if ( QgsGrass::deleteObject( mVector ) )
{
if ( mParent )
mParent->refresh();
}
QList<QAction*> QgsGrassVectorItem::actions()
{
QList<QAction*> lst;

QAction* actionDelete = new QAction( tr( "Delete" ), this );
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteGrassObject() ) );
lst.append( actionDelete );

return lst;
}

void QgsGrassVectorItem::deleteGrassObject()
{
QgsGrassObjectItemBase::deleteGrassObject( parent() );
}

QgsGrassVectorLayerItem::QgsGrassVectorLayerItem( QgsDataItem* parent, QgsGrassObject grassObject, QString layerName,
QString path, QString uri,
LayerType layerType, bool singleLayer )
: QgsGrassObjectItem( parent, grassObject, layerName, path, uri, layerType, "grass", singleLayer )
{
}

QString QgsGrassVectorLayerItem::layerName() const
{
// to get map + layer when added from browser
return mGrassObject.name() + " " + name();
}

QgsGrassRasterItem::QgsGrassRasterItem( QgsDataItem* parent, QgsGrassObject grassObject,
QString path, QString uri )
: QgsGrassObjectItem( parent, grassObject, grassObject.name(), path, uri, QgsLayerItem::Raster, "grassraster" )
{
}

QGISEXTERN int dataCapabilities()
Expand Down
57 changes: 50 additions & 7 deletions src/providers/grass/qgsgrassprovidermodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,83 @@ class QgsGrassMapsetItem : public QgsDirectoryItem
QString mGisdbase;
};

class QgsGrassObjectItemBase
{
public:
QgsGrassObjectItemBase( QgsGrassObject grassObject );

public:
void deleteGrassObject( QgsDataItem* parent );

protected:
QgsGrassObject mGrassObject;
};

class QgsGrassObjectItem : public QgsLayerItem, public QgsGrassObjectItemBase
{
Q_OBJECT
public:
QgsGrassObjectItem( QgsDataItem* parent, QgsGrassObject grassObject,
QString name, QString path, QString uri,
LayerType layerType, QString providerKey,
bool deleteAction = true );

virtual QList<QAction*> actions() override;

public slots:
void deleteGrassObject();

protected:
//QgsGrassObject mGrassObject;
bool mDeleteAction;
};

// Vector is collection of layers
class QgsGrassVectorItem : public QgsDataCollectionItem
class QgsGrassVectorItem : public QgsDataCollectionItem, public QgsGrassObjectItemBase
{
Q_OBJECT
public:
QgsGrassVectorItem( QgsDataItem* parent, QgsGrassObject vector, QString path );
QgsGrassVectorItem( QgsDataItem* parent, QgsGrassObject grassObject, QString path );
~QgsGrassVectorItem() {}

virtual QList<QAction*> actions() override;

public slots:
void deleteMap();
void deleteGrassObject();

private:
QgsGrassObject mVector;
};

class QgsGrassVectorLayerItem : public QgsLayerItem
class QgsGrassVectorLayerItem : public QgsGrassObjectItem
{
Q_OBJECT
public:
QgsGrassVectorLayerItem( QgsDataItem* parent, QgsGrassObject vector, QString layerName,
QString path, QString uri, LayerType layerType, bool singleLayer );

QString layerName() const override;
virtual QList<QAction*> actions() override;
//virtual QList<QAction*> actions() override;

public slots:
void deleteMap();
//void deleteMap();

private:
// layer from single layer vector map (cannot have delete action)
QgsGrassObject mVector;
bool mSingleLayer;
};

class QgsGrassRasterItem : public QgsGrassObjectItem
{
Q_OBJECT
public:
QgsGrassRasterItem( QgsDataItem* parent, QgsGrassObject grassObject,
QString path, QString uri );

//virtual QList<QAction*> actions() override;

public slots:
//void deleteMap();
};

#endif // QGSGRASSPROVIDERMODULE_H

0 comments on commit eb964f9

Please sign in to comment.