Skip to content

Commit

Permalink
add delete layer action to PG data items
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed Apr 15, 2012
1 parent 2e3db0c commit 9da981b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/providers/postgres/qgspostgresdataitems.cpp
Expand Up @@ -8,6 +8,8 @@

#include <QMessageBox>

QGISEXTERN bool deleteLayer( const QString& uri, QString& errCause );

// ---------------------------------------------------------------------------
QgsPGConnectionItem::QgsPGConnectionItem( QgsDataItem* parent, QString name, QString path )
: QgsDataCollectionItem( parent, name, path )
Expand Down Expand Up @@ -237,6 +239,32 @@ QgsPGLayerItem::~QgsPGLayerItem()
{
}

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

QAction* actionDeleteLayer = new QAction( tr( "Delete layer" ), this );
connect( actionDeleteLayer, SIGNAL( triggered() ), this, SLOT( deleteLayer() ) );
lst.append( actionDeleteLayer );

return lst;
}

void QgsPGLayerItem::deleteLayer()
{
QString errCause;
bool res = ::deleteLayer( mUri, errCause );
if ( !res )
{
QMessageBox::warning( 0, tr( "Delete layer" ), errCause );
}
else
{
QMessageBox::information( 0, tr( "Delete layer" ), tr( "Layer deleted successfully." ) );
mParent->refresh();
}
}

QString QgsPGLayerItem::createUri()
{
QString pkColName = mLayerProperty.pkCols.size() > 0 ? mLayerProperty.pkCols.at( 0 ) : QString::null;
Expand Down
5 changes: 5 additions & 0 deletions src/providers/postgres/qgspostgresdataitems.h
Expand Up @@ -83,6 +83,11 @@ class QgsPGLayerItem : public QgsLayerItem

QString createUri();

virtual QList<QAction*> actions();

public slots:
void deleteLayer();

private:
QgsPostgresLayerProperty mLayerProperty;
};
Expand Down

0 comments on commit 9da981b

Please sign in to comment.