Skip to content
Permalink
Browse files

pass items to delete layer activity

  • Loading branch information
signedav committed Nov 15, 2018
1 parent 3e14761 commit fa062461b6d1da7227504f99b83b430a42e04268
@@ -314,6 +314,9 @@ Sets a custom sorting ``key`` for the item.
Move object and all its descendants to thread
%End

void setSelectedItems( const QList<QgsDataItem *> &selectedItems );
QList<QgsDataItem *> selectedItems() const;

protected:
virtual void populate( const QVector<QgsDataItem *> &children );

@@ -323,6 +323,9 @@ class CORE_EXPORT QgsDataItem : public QObject
//! Move object and all its descendants to thread
void moveToThread( QThread *targetThread );

void setSelectedItems( const QList<QgsDataItem *> &selectedItems ) { mSelectedItems = selectedItems; }
QList<QgsDataItem *> selectedItems() const { return mSelectedItems; }

protected:
virtual void populate( const QVector<QgsDataItem *> &children );

@@ -418,6 +421,7 @@ class CORE_EXPORT QgsDataItem : public QObject
QFutureWatcher< QVector <QgsDataItem *> > *mFutureWatcher;
// number of items currently in loading (populating) state
static QgsAnimatedIcon *sPopulatingIcon;
QList<QgsDataItem *> mSelectedItems;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataItem::Capabilities )
@@ -211,6 +211,7 @@ void QgsBrowserDockWidget::showContextMenu( QPoint pt )
QMenu *menu = new QMenu( this );

const QList<QMenu *> menus = item->menus( menu );
item->setSelectedItems( selectedItems );
QList<QAction *> actions = item->actions( menu );

if ( !menus.isEmpty() )
@@ -77,9 +77,21 @@ QVector<QgsDataItem *> QgsGeoPackageRootItem::createChildren()
#ifdef HAVE_GUI
QList<QAction *> QgsGeoPackageAbstractLayerItem::actions( QWidget * )
{
//dave: decide if more than one layer is selected. if more then "Delete selected Layers"
QList<QAction *> lst;
QAction *actionDeleteLayer = new QAction( tr( "Delete Layer '%1'…" ).arg( mName ), this );
connect( actionDeleteLayer, &QAction::triggered, this, &QgsGeoPackageAbstractLayerItem::deleteLayer );

const QString deleteText = selectedItems().count() == 1 ? tr( "Delete Layer '%1'…" ).arg( mName )
: tr( "Delete Selected Layers" );
QAction *actionDeleteLayer = new QAction( deleteText, this );
connect( actionDeleteLayer, &QAction::triggered, this, [ = ]
{
QList<QgsDataItem *> items = selectedItems();
for ( const QgsDataItem *item : items )
{
if ( const QgsGeoPackageAbstractLayerItem *gpkgAbstractItem = qobject_cast<const QgsGeoPackageAbstractLayerItem *>( item ) )
deleteLayer( gpkgAbstractItem );
}
} ) ;
lst.append( actionDeleteLayer );
return lst;
}
@@ -487,14 +499,15 @@ void QgsGeoPackageCollectionItem::vacuumGeoPackageDbAction()
}
}

void QgsGeoPackageAbstractLayerItem::deleteLayer()
void QgsGeoPackageAbstractLayerItem::deleteLayer( const QgsGeoPackageAbstractLayerItem *item )
{
//dave: here we are - we need to find out what other layers in the gpkg are selected and delete em
// Check if the layer(s) are in the registry
QList<QgsMapLayer *> layersList;
const auto mapLayers( QgsProject::instance()->mapLayers() );
for ( QgsMapLayer *layer : mapLayers )
{
if ( layer->publicSource() == mUri )
if ( layer->publicSource() == item->uri() )
{
layersList << layer;
}
@@ -503,13 +516,13 @@ void QgsGeoPackageAbstractLayerItem::deleteLayer()
if ( ! layersList.isEmpty( ) )
{
if ( QMessageBox::question( nullptr, QObject::tr( "Delete Layer" ), QObject::tr( "The layer <b>%1</b> exists in the current project <b>%2</b>,"
" do you want to remove it from the project and delete it?" ).arg( mName, layersList.at( 0 )->name() ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
" do you want to remove it from the project and delete it?" ).arg( item->name(), layersList.at( 0 )->name() ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
{
return;
}
}
else if ( QMessageBox::question( nullptr, QObject::tr( "Delete Layer" ),
QObject::tr( "Are you sure you want to delete layer <b>%1</b> from GeoPackage?" ).arg( mName ),
QObject::tr( "Are you sure you want to delete layer <b>%1</b> from GeoPackage?" ).arg( item->name() ),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
{
return;
@@ -528,7 +541,7 @@ void QgsGeoPackageAbstractLayerItem::deleteLayer()
}
else
{
QMessageBox::information( nullptr, tr( "Delete Layer" ), tr( "Layer <b>%1</b> deleted successfully." ).arg( mName ) );
QMessageBox::information( nullptr, tr( "Delete Layer" ), tr( "Layer <b>%1</b> deleted successfully." ).arg( item->name() ) );
if ( mParent )
mParent->refreshConnections();
}
@@ -28,6 +28,9 @@ class QgsGeoPackageAbstractLayerItem : public QgsLayerItem
{
Q_OBJECT

//! Returns layer uri or empty string if layer cannot be created
QString uri() const { return mUri; }

protected:
QgsGeoPackageAbstractLayerItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &uri, LayerType layerType, const QString &providerKey );

@@ -39,7 +42,7 @@ class QgsGeoPackageAbstractLayerItem : public QgsLayerItem
#ifdef HAVE_GUI
QList<QAction *> actions( QWidget *menu ) override;
public slots:
virtual void deleteLayer();
virtual void deleteLayer( const QgsGeoPackageAbstractLayerItem *item );
#endif
};

0 comments on commit fa06246

Please sign in to comment.
You can’t perform that action at this time.