Skip to content
Permalink
Browse files

[needs-docs] Add a "save selected features as" layer item shortcut

  • Loading branch information
nirvn committed Mar 29, 2018
1 parent 7900570 commit 716ba9befef61b660ca3460d51b9e56d9a514445
@@ -6959,7 +6959,7 @@ void QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer )
}


void QgisApp::saveAsFile( QgsMapLayer *layer )
void QgisApp::saveAsFile( QgsMapLayer *layer, bool onlySelected )
{
if ( !layer )
layer = activeLayer();
@@ -6974,7 +6974,7 @@ void QgisApp::saveAsFile( QgsMapLayer *layer )
}
else if ( layerType == QgsMapLayer::VectorLayer )
{
saveAsVectorFileGeneral( qobject_cast<QgsVectorLayer *>( layer ) );
saveAsVectorFileGeneral( qobject_cast<QgsVectorLayer *>( layer ), true, onlySelected );
}
}

@@ -7074,7 +7074,7 @@ QgisAppFieldValueConverter *QgisAppFieldValueConverter::clone() const

///@endcond

void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOption )
void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOption, bool onlySelected )
{
if ( !vlayer )
{
@@ -7096,6 +7096,7 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt

dialog->setMapCanvas( mMapCanvas );
dialog->setIncludeZ( QgsWkbTypes::hasZ( vlayer->wkbType() ) );
dialog->setOnlySelected( onlySelected );

if ( dialog->exec() == QDialog::Accepted )
{
@@ -692,7 +692,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

public slots:
//! save current vector layer
void saveAsFile( QgsMapLayer *layer = nullptr );
void saveAsFile( QgsMapLayer *layer = nullptr, bool onlySelected = false );
//! save qml style for the current layer
void saveStyleFile( QgsMapLayer *layer = nullptr );
//! save qrl definition for the current layer
@@ -1768,7 +1768,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

void setLayoutAtlasFeature( QgsPrintLayout *layout, QgsMapLayer *layer, const QgsFeature &feat );

void saveAsVectorFileGeneral( QgsVectorLayer *vlayer = nullptr, bool symbologyOption = true );
void saveAsVectorFileGeneral( QgsVectorLayer *vlayer = nullptr, bool symbologyOption = true, bool onlySelected = false );

/**
* Paste features from clipboard into a new memory layer.
@@ -244,10 +244,14 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
{
// save as vector file
QMenu *menuExportVector = new QMenu( tr( "Export" ), menu );
QAction *actionSaveAs = new QAction( tr( "Save as…" ), menuExportVector );
QAction *actionSaveAsDefinitionLayer = new QAction( tr( "Save as Layer Definition File…" ), menuExportVector );
QAction *actionSaveAs = new QAction( tr( "Save Features as…" ), menuExportVector );
connect( actionSaveAs, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveAsFile(); } );
menuExportVector->addAction( actionSaveAs );
QAction *actionSaveSelectedFeaturesAs = new QAction( tr( "Save Selected Features as…" ), menuExportVector );
connect( actionSaveSelectedFeaturesAs, &QAction::triggered, QgisApp::instance(), [ = ] { QgisApp::instance()->saveAsFile( nullptr, true ); } );
actionSaveSelectedFeaturesAs->setEnabled( vlayer->selectedFeatureCount() > 0 );
menuExportVector->addAction( actionSaveSelectedFeaturesAs );
QAction *actionSaveAsDefinitionLayer = new QAction( tr( "Save as Layer Definition File…" ), menuExportVector );
connect( actionSaveAsDefinitionLayer, &QAction::triggered, QgisApp::instance(), &QgisApp::saveAsLayerDefinition );
menuExportVector->addAction( actionSaveAsDefinitionLayer );
if ( vlayer->isSpatial() )
@@ -863,6 +863,11 @@ QgsRectangle QgsVectorLayerSaveAsDialog::filterExtent() const
return mExtentGroupBox->outputExtent();
}

void QgsVectorLayerSaveAsDialog::setOnlySelected( bool onlySelected )
{
mSelectedOnly->setChecked( onlySelected );
}

bool QgsVectorLayerSaveAsDialog::onlySelected() const
{
return mSelectedOnly->isChecked();
@@ -82,6 +82,14 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
bool hasFilterExtent() const;
QgsRectangle filterExtent() const;

/**
* Sets whether only selected features will be saved.
*/
void setOnlySelected( bool onlySelected );

/**
* Returns whether only selected features will be saved.
*/
bool onlySelected() const;

/**

0 comments on commit 716ba9b

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