Hide extra options from Make Permanent dialog

We don't want to e.g. allow users to change the CRS or drop
fields in this dialog.
This commit is contained in:
Nyall Dawson 2018-08-03 16:34:12 +10:00
parent f8afc5077f
commit b8323a9bec
5 changed files with 46 additions and 12 deletions

View File

@ -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()
@ -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() ) );

View File

@ -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"
@ -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() );

View File

@ -50,6 +50,7 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, i
, mAttributeTableItemChangedSlotEnabled( true )
, mReplaceRawFieldValuesStateChangedSlotEnabled( true )
, mActionOnExistingFile( QgsVectorFileWriter::CreateOrOverwriteFile )
, mOptions( static_cast< Options >( options ) )
{
if ( layer )
{
@ -58,7 +59,7 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, i
}
setup();
if ( !( options & Symbology ) )
if ( !( mOptions & Symbology ) )
{
mSymbologyExportLabel->hide();
mSymbologyExportComboBox->hide();
@ -66,6 +67,26 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, i
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 );
}
@ -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 );
@ -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

View File

@ -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 );
@ -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

View File

@ -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>