Skip to content

Commit

Permalink
Hide extra options from Make Permanent dialog
Browse files Browse the repository at this point in the history
We don't want to e.g. allow users to change the CRS or drop
fields in this dialog.
  • Loading branch information
nyalldawson committed Aug 3, 2018
1 parent f8afc50 commit b8323a9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -7240,7 +7240,7 @@ void QgisApp::makeMemoryLayerPermanent( QgsVectorLayer *layer )
}
};

saveAsVectorFileGeneral( layer, true, false, onSuccess, onFailure );
saveAsVectorFileGeneral( layer, true, false, onSuccess, onFailure, 0, tr( "Save Scratch Layer" ) );
}

void QgisApp::saveAsLayerDefinition()
Expand Down Expand Up @@ -7383,17 +7383,18 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOpt
saveAsVectorFileGeneral( vlayer, symbologyOption, onlySelected, onSuccess, onFailure );
}

void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOption, bool onlySelected, const std::function<void( const QString &, bool, const QString &, const QString &, const QString & )> &onSuccess, const std::function<void ( int, const QString & )> &onFailure )
void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbologyOption, bool onlySelected, const std::function<void( const QString &, bool, const QString &, const QString &, const QString & )> &onSuccess, const std::function<void ( int, const QString & )> &onFailure, int options, const QString &dialogTitle )
{
QgsCoordinateReferenceSystem destCRS;

int options = QgsVectorLayerSaveAsDialog::AllOptions;
if ( !symbologyOption )
{
options &= ~QgsVectorLayerSaveAsDialog::Symbology;
}

QgsVectorLayerSaveAsDialog *dialog = new QgsVectorLayerSaveAsDialog( vlayer, options, this );
if ( !dialogTitle.isEmpty() )
dialog->setWindowTitle( dialogTitle );

dialog->setMapCanvas( mMapCanvas );
dialog->setIncludeZ( QgsWkbTypes::hasZ( vlayer->wkbType() ) );
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgisapp.h
Expand Up @@ -156,6 +156,7 @@ class QgsLayoutQptDropHandler;
#include "qgsoptionswidgetfactory.h"
#include "qgsattributetablefiltermodel.h"
#include "qgsmasterlayoutinterface.h"
#include "ogr/qgsvectorlayersaveasdialog.h"
#include "ui_qgisapp.h"
#include "qgis_app.h"

Expand Down Expand Up @@ -1841,7 +1842,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
bool addToCanvas,
const QString &layerName,
const QString &encoding,
const QString &vectorFileName )> &onSuccess, const std::function< void ( int error, const QString &errorMessage ) > &onFailure );
const QString &vectorFileName )> &onSuccess, const std::function< void ( int error, const QString &errorMessage ) > &onFailure,
int dialogOptions = QgsVectorLayerSaveAsDialog::AllOptions,
const QString &dialogTitle = QString() );

//! Sets project properties, including map untis
void projectProperties( const QString &currentPage = QString() );
Expand Down
30 changes: 26 additions & 4 deletions src/gui/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -50,6 +50,7 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, i
, mAttributeTableItemChangedSlotEnabled( true )
, mReplaceRawFieldValuesStateChangedSlotEnabled( true )
, mActionOnExistingFile( QgsVectorFileWriter::CreateOrOverwriteFile )
, mOptions( static_cast< Options >( options ) )
{
if ( layer )
{
Expand All @@ -58,14 +59,34 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, i
}
setup();

if ( !( options & Symbology ) )
if ( !( mOptions & Symbology ) )
{
mSymbologyExportLabel->hide();
mSymbologyExportComboBox->hide();
mScaleLabel->hide();
mScaleWidget->hide();
}

if ( !( mOptions & DestinationCrs ) )
{
mCrsLabel->hide();
mCrsSelector->hide();
}
if ( !( mOptions & Fields ) )
mAttributesSelection->hide();

if ( !( mOptions & SelectedOnly ) )
mSelectedOnly->hide();

if ( !( mOptions & AddToCanvas ) )
mAddToCanvas->hide();

if ( !( mOptions & GeometryType ) )
mGeometryGroupBox->hide();

if ( !( mOptions & Extent ) )
mExtentGroupBox->hide();

mSelectedOnly->setEnabled( layer && layer->selectedFeatureCount() != 0 );
buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
}
Expand Down Expand Up @@ -376,12 +397,13 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
}
else
{
mAttributesSelection->setVisible( true );
if ( mOptions & Fields )
mAttributesSelection->setVisible( true );
fieldsAsDisplayedValues = ( sFormat == QLatin1String( "CSV" ) || sFormat == QLatin1String( "XLS" ) || sFormat == QLatin1String( "XLSX" ) || sFormat == QLatin1String( "ODS" ) );
}

// Show symbology options only for some formats
if ( QgsVectorFileWriter::supportsFeatureStyles( sFormat ) )
if ( QgsVectorFileWriter::supportsFeatureStyles( sFormat ) && ( mOptions & Symbology ) )
{
mSymbologyExportLabel->setVisible( true );
mSymbologyExportComboBox->setVisible( true );
Expand Down Expand Up @@ -878,7 +900,7 @@ QgsWkbTypes::Type QgsVectorLayerSaveAsDialog::geometryType() const
return QgsWkbTypes::Unknown;
}

return ( QgsWkbTypes::Type )currentIndexData;
return static_cast< QgsWkbTypes::Type >( currentIndexData );
}

bool QgsVectorLayerSaveAsDialog::automaticGeometryType() const
Expand Down
14 changes: 11 additions & 3 deletions src/gui/ogr/qgsvectorlayersaveasdialog.h
Expand Up @@ -38,11 +38,18 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
Q_OBJECT

public:
// bitmask of options to be shown

//! Bitmask of options to be shown
enum Options
{
Symbology = 1,
AllOptions = ~0
Symbology = 1, //!< Show symbology options
DestinationCrs = 1 << 2, //!< Show destination CRS (reprojection) option
Fields = 1 << 3, //!< Show field customisation group
AddToCanvas = 1 << 4, //!< Show add to map option
SelectedOnly = 1 << 5, //!< Show selected features only option
GeometryType = 1 << 6, //!< Show geometry group
Extent = 1 << 7, //!< Show extent group
AllOptions = ~0 //!< Show all options
};

QgsVectorLayerSaveAsDialog( long srsid, QWidget *parent = nullptr, Qt::WindowFlags fl = nullptr );
Expand Down Expand Up @@ -156,6 +163,7 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
bool mAttributeTableItemChangedSlotEnabled;
bool mReplaceRawFieldValuesStateChangedSlotEnabled;
QgsVectorFileWriter::ActionOnExistingFile mActionOnExistingFile;
Options mOptions = AllOptions;
};

#endif // QGSVECTORLAYERSAVEASDIALOG_H
2 changes: 1 addition & 1 deletion src/ui/qgsvectorlayersaveasdialogbase.ui
Expand Up @@ -24,7 +24,7 @@
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout_4">
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="mCrsLabel">
<property name="text">
<string>CRS</string>
</property>
Expand Down

0 comments on commit b8323a9

Please sign in to comment.