Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use enum class
  • Loading branch information
nyalldawson committed May 15, 2023
1 parent c259477 commit b0be3d4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
16 changes: 16 additions & 0 deletions python/gui/auto_additions/qgsvectorlayersaveasdialog.py
@@ -0,0 +1,16 @@
# The following has been generated automatically from src/gui/ogr/qgsvectorlayersaveasdialog.h
# monkey patching scoped based enum
QgsVectorLayerSaveAsDialog.Option.Symbology.__doc__ = "Show symbology options"
QgsVectorLayerSaveAsDialog.Option.DestinationCrs.__doc__ = "Show destination CRS (reprojection) option"
QgsVectorLayerSaveAsDialog.Option.Fields.__doc__ = "Show field customization group"
QgsVectorLayerSaveAsDialog.Option.AddToCanvas.__doc__ = "Show add to map option"
QgsVectorLayerSaveAsDialog.Option.SelectedOnly.__doc__ = "Show selected features only option"
QgsVectorLayerSaveAsDialog.Option.GeometryType.__doc__ = "Show geometry group"
QgsVectorLayerSaveAsDialog.Option.Extent.__doc__ = "Show extent group"
QgsVectorLayerSaveAsDialog.Option.Metadata.__doc__ = "Show metadata options"
QgsVectorLayerSaveAsDialog.Option.AllOptions.__doc__ = ""
QgsVectorLayerSaveAsDialog.Option.__doc__ = 'Available dialog options.\n\n' + '* ``Symbology``: ' + QgsVectorLayerSaveAsDialog.Option.Symbology.__doc__ + '\n' + '* ``DestinationCrs``: ' + QgsVectorLayerSaveAsDialog.Option.DestinationCrs.__doc__ + '\n' + '* ``Fields``: ' + QgsVectorLayerSaveAsDialog.Option.Fields.__doc__ + '\n' + '* ``AddToCanvas``: ' + QgsVectorLayerSaveAsDialog.Option.AddToCanvas.__doc__ + '\n' + '* ``SelectedOnly``: ' + QgsVectorLayerSaveAsDialog.Option.SelectedOnly.__doc__ + '\n' + '* ``GeometryType``: ' + QgsVectorLayerSaveAsDialog.Option.GeometryType.__doc__ + '\n' + '* ``Extent``: ' + QgsVectorLayerSaveAsDialog.Option.Extent.__doc__ + '\n' + '* ``Metadata``: ' + QgsVectorLayerSaveAsDialog.Option.Metadata.__doc__ + '\n' + '* ``AllOptions``: ' + QgsVectorLayerSaveAsDialog.Option.AllOptions.__doc__
# --
QgsVectorLayerSaveAsDialog.Option.baseClass = QgsVectorLayerSaveAsDialog
QgsVectorLayerSaveAsDialog.Options.baseClass = QgsVectorLayerSaveAsDialog
Options = QgsVectorLayerSaveAsDialog # dirty hack since SIP seems to introduce the flags in module
Expand Up @@ -22,7 +22,7 @@ Class to select destination file, type and CRS for ogr layers
%End
public:

enum Option
enum class Option
{
Symbology,
DestinationCrs,
Expand All @@ -34,11 +34,12 @@ Class to select destination file, type and CRS for ogr layers
Metadata,
AllOptions
};

typedef QFlags<QgsVectorLayerSaveAsDialog::Option> Options;



QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, Options options = AllOptions, QWidget *parent = 0, Qt::WindowFlags fl = Qt::WindowFlags() );
QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, Options options = Option::AllOptions, QWidget *parent = 0, Qt::WindowFlags fl = Qt::WindowFlags() );
%Docstring
Construct a new QgsVectorLayerSaveAsDialog
%End
Expand Down
20 changes: 10 additions & 10 deletions src/gui/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -68,35 +68,35 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, O
leLayername->setText( mDefaultOutputLayerNameFromInputLayerName );
}

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

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

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

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

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

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

if ( !( mOptions & Metadata ) )
if ( !( mOptions & Option::Metadata ) )
{
mCheckPersistMetadata->setChecked( false );
mCheckPersistMetadata->hide();
Expand Down Expand Up @@ -462,7 +462,7 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
}
else
{
if ( mOptions & Fields )
if ( mOptions & Option::Fields )
{
mAttributesSelection->setVisible( true );
isFormatForFieldsAsDisplayedValues = ( sFormat == QLatin1String( "CSV" ) ||
Expand All @@ -473,7 +473,7 @@ void QgsVectorLayerSaveAsDialog::mFormatComboBox_currentIndexChanged( int idx )
}

// Show symbology options only for some formats
if ( QgsVectorFileWriter::supportsFeatureStyles( sFormat ) && ( mOptions & Symbology ) )
if ( QgsVectorFileWriter::supportsFeatureStyles( sFormat ) && ( mOptions & Option::Symbology ) )
{
mSymbologyExportLabel->setVisible( true );
mSymbologyExportComboBox->setVisible( true );
Expand Down
16 changes: 12 additions & 4 deletions src/gui/ogr/qgsvectorlayersaveasdialog.h
Expand Up @@ -36,8 +36,10 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec

public:

//! Bitmask of options to be shown
enum Option
/**
* Available dialog options.
*/
enum class Option : int
{
Symbology = 1, //!< Show symbology options
DestinationCrs = 1 << 2, //!< Show destination CRS (reprojection) option
Expand All @@ -49,7 +51,13 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
Metadata = 1 << 8, //!< Show metadata options
AllOptions = ~0 //!< Show all options
};
Q_ENUM( Option )

/**
* Available dialog options.
*/
Q_DECLARE_FLAGS( Options, Option )
Q_FLAG( Options )

/**
* Construct a new QgsVectorLayerSaveAsDialog
Expand All @@ -61,7 +69,7 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
/**
* Construct a new QgsVectorLayerSaveAsDialog
*/
QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, Options options = AllOptions, QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() );
QgsVectorLayerSaveAsDialog( QgsVectorLayer *layer, Options options = Option::AllOptions, QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() );

/**
* The format in which the export should be written.
Expand Down Expand Up @@ -258,7 +266,7 @@ class GUI_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
QgsVectorLayer *mLayer = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QgsVectorFileWriter::ActionOnExistingFile mActionOnExistingFile;
Options mOptions = AllOptions;
Options mOptions = Option::AllOptions;
QString mDefaultOutputLayerNameFromInputLayerName;
};

Expand Down

0 comments on commit b0be3d4

Please sign in to comment.