Skip to content

Commit

Permalink
[needs-docs] Add a "save selected features as" layer item shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Mar 29, 2018
1 parent 7900570 commit 716ba9b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -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();
Expand All @@ -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 );
}
}

Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 )
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.h
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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() )
Expand Down
5 changes: 5 additions & 0 deletions src/gui/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/gui/ogr/qgsvectorlayersaveasdialog.h
Expand Up @@ -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;

/**
Expand Down

0 comments on commit 716ba9b

Please sign in to comment.