Skip to content
Permalink
Browse files
Move QgsSublayersDialog::PromptMode enum to Qgis and rename
  • Loading branch information
nyalldawson committed Jul 12, 2021
1 parent e01dc5d commit d0beaae3a48fd29fa1bebf5ef0c6d7fc59a2c14f
@@ -414,3 +414,20 @@
Qgis.FilePathType.__doc__ = 'File path types.\n\n.. versionadded:: 3.22\n\n' + '* ``Absolute``: ' + Qgis.FilePathType.Absolute.__doc__ + '\n' + '* ``Relative``: ' + Qgis.FilePathType.Relative.__doc__
# --
Qgis.FilePathType.baseClass = Qgis
QgsSublayersDialog.PromptMode = Qgis.SublayerPromptMode
# monkey patching scoped based enum
QgsSublayersDialog.PromptAlways = Qgis.SublayerPromptMode.AlwaysAsk
QgsSublayersDialog.PromptAlways.is_monkey_patched = True
QgsSublayersDialog.PromptAlways.__doc__ = "Always ask users to select from available sublayers, if sublayers are present"
QgsSublayersDialog.PromptIfNeeded = Qgis.SublayerPromptMode.AskExcludingRasterBands
QgsSublayersDialog.PromptIfNeeded.is_monkey_patched = True
QgsSublayersDialog.PromptIfNeeded.__doc__ = "Ask users to select from available sublayers, unless only raster bands are present"
QgsSublayersDialog.PromptNever = Qgis.SublayerPromptMode.NeverAskSkip
QgsSublayersDialog.PromptNever.is_monkey_patched = True
QgsSublayersDialog.PromptNever.__doc__ = "Never ask users to select sublayers, instead don't load anything"
QgsSublayersDialog.PromptLoadAll = Qgis.SublayerPromptMode.NeverAskLoadAll
QgsSublayersDialog.PromptLoadAll.is_monkey_patched = True
QgsSublayersDialog.PromptLoadAll.__doc__ = "Never ask users to select sublayers, instead automatically load all available sublayers"
Qgis.SublayerPromptMode.__doc__ = 'Specifies how to handle layer sources with multiple sublayers.\n\n.. versionadded:: 3.22\n\n' + '* ``PromptAlways``: ' + Qgis.SublayerPromptMode.AlwaysAsk.__doc__ + '\n' + '* ``PromptIfNeeded``: ' + Qgis.SublayerPromptMode.AskExcludingRasterBands.__doc__ + '\n' + '* ``PromptNever``: ' + Qgis.SublayerPromptMode.NeverAskSkip.__doc__ + '\n' + '* ``PromptLoadAll``: ' + Qgis.SublayerPromptMode.NeverAskLoadAll.__doc__
# --
Qgis.SublayerPromptMode.baseClass = Qgis
@@ -310,6 +310,14 @@ The development version
Relative,
};

enum class SublayerPromptMode
{
AlwaysAsk,
AskExcludingRasterBands,
NeverAskSkip,
NeverAskLoadAll,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;

This file was deleted.

@@ -21,18 +21,6 @@ class QgsSublayersDialog : QDialog
%End
public:

enum PromptMode
{

PromptAlways,

PromptIfNeeded,

PromptNever,

PromptLoadAll
};

enum ProviderType
{
Ogr,
@@ -451,11 +451,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
spinBoxAttrTableRowCache->setSpecialValueText( tr( "All" ) );

cmbPromptSublayers->clear();
cmbPromptSublayers->addItem( tr( "Always" ), QgsSublayersDialog::PromptAlways );
cmbPromptSublayers->addItem( tr( "If Needed" ), QgsSublayersDialog::PromptIfNeeded ); //this means, prompt if there are sublayers but no band in the main dataset
cmbPromptSublayers->addItem( tr( "Never" ), QgsSublayersDialog::PromptNever );
cmbPromptSublayers->addItem( tr( "Load All" ), QgsSublayersDialog::PromptLoadAll ); // check if this is true
cmbPromptSublayers->setCurrentIndex( cmbPromptSublayers->findData( mSettings->enumValue( QStringLiteral( "/qgis/promptForSublayers" ), QgsSublayersDialog::PromptAlways ) ) );
cmbPromptSublayers->addItem( tr( "Always" ), static_cast< int >( Qgis::SublayerPromptMode::AlwaysAsk ) );
cmbPromptSublayers->addItem( tr( "If Needed" ), static_cast< int >( Qgis::SublayerPromptMode::AskExcludingRasterBands ) ); //this means, prompt if there are sublayers but no band in the main dataset
cmbPromptSublayers->addItem( tr( "Never" ), static_cast< int >( Qgis::SublayerPromptMode::NeverAskSkip ) );
cmbPromptSublayers->addItem( tr( "Load All" ), static_cast< int >( Qgis::SublayerPromptMode::NeverAskLoadAll ) );
cmbPromptSublayers->setCurrentIndex( cmbPromptSublayers->findData( static_cast< int >( mSettings->enumValue( QStringLiteral( "/qgis/promptForSublayers" ), Qgis::SublayerPromptMode::AlwaysAsk ) ) ) );

// Scan for valid items in the browser dock
cmbScanItemsInBrowser->clear();
@@ -1589,7 +1589,7 @@ void QgsOptions::saveOptions()
mSettings->setEnumValue( QStringLiteral( "/qgis/attributeTableBehavior" ), ( QgsAttributeTableFilterModel::FilterMode )cmbAttrTableBehavior->currentData().toInt() );
mSettings->setValue( QStringLiteral( "/qgis/attributeTableView" ), mAttrTableViewComboBox->currentData() );
mSettings->setValue( QStringLiteral( "/qgis/attributeTableRowCache" ), spinBoxAttrTableRowCache->value() );
mSettings->setEnumValue( QStringLiteral( "/qgis/promptForSublayers" ), ( QgsSublayersDialog::PromptMode )cmbPromptSublayers->currentData().toInt() );
mSettings->setEnumValue( QStringLiteral( "/qgis/promptForSublayers" ), static_cast< Qgis::SublayerPromptMode >( cmbPromptSublayers->currentData().toInt() ) );

mSettings->setValue( QStringLiteral( "/qgis/scanItemsInBrowser2" ),
cmbScanItemsInBrowser->currentData().toString() );
@@ -5949,7 +5949,7 @@ bool QgisApp::askUserForZipItemLayers( const QString &path )
QVector<QgsDataItem *> childItems;
QgsZipItem *zipItem = nullptr;
QgsSettings settings;
QgsSublayersDialog::PromptMode promptLayers = settings.enumValue( QStringLiteral( "qgis/promptForSublayers" ), QgsSublayersDialog::PromptAlways );
Qgis::SublayerPromptMode promptLayers = settings.enumValue( QStringLiteral( "qgis/promptForSublayers" ), Qgis::SublayerPromptMode::AlwaysAsk );

QgsDebugMsgLevel( "askUserForZipItemLayers( " + path + ')', 2 );

@@ -5976,16 +5976,18 @@ bool QgisApp::askUserForZipItemLayers( const QString &path )
switch ( promptLayers )
{
// load all layers without prompting
case QgsSublayersDialog::PromptLoadAll:
case Qgis::SublayerPromptMode::NeverAskLoadAll:
childItems = zipItem->children();
break;

// return because we should not prompt at all
case QgsSublayersDialog::PromptNever:
case Qgis::SublayerPromptMode::NeverAskSkip:
delete zipItem;
return false;

// initialize a selection dialog and display it.
case QgsSublayersDialog::PromptAlways:
case QgsSublayersDialog::PromptIfNeeded:
case Qgis::SublayerPromptMode::AlwaysAsk:
case Qgis::SublayerPromptMode::AskExcludingRasterBands:
QgsSublayersDialog chooseSublayersDialog( QgsSublayersDialog::Vsifile, QStringLiteral( "vsi" ), this, Qt::WindowFlags(), path );
QgsSublayersDialog::LayerDefinitionList layers;

@@ -6065,11 +6067,11 @@ bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )
return false;

QgsSettings settings;
QgsSublayersDialog::PromptMode promptLayers = settings.enumValue( QStringLiteral( "qgis/promptForSublayers" ), QgsSublayersDialog::PromptAlways );
Qgis::SublayerPromptMode promptLayers = settings.enumValue( QStringLiteral( "qgis/promptForSublayers" ), Qgis::SublayerPromptMode::AlwaysAsk );

return promptLayers == QgsSublayersDialog::PromptAlways ||
promptLayers == QgsSublayersDialog::PromptLoadAll ||
( promptLayers == QgsSublayersDialog::PromptIfNeeded && layer->bandCount() == 0 );
return promptLayers == Qgis::SublayerPromptMode::AlwaysAsk ||
promptLayers == Qgis::SublayerPromptMode::NeverAskLoadAll ||
( promptLayers == Qgis::SublayerPromptMode::AskExcludingRasterBands && layer->bandCount() == 0 );
}

// This method is the method that does the real job. If the layer given in
@@ -463,6 +463,20 @@ class CORE_EXPORT Qgis
};
Q_ENUM( FilePathType )

/**
* Specifies how to handle layer sources with multiple sublayers.
*
* \since QGIS 3.22
*/
enum class SublayerPromptMode SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsSublayersDialog, PromptMode ) : int
{
AlwaysAsk SIP_MONKEYPATCH_COMPAT_NAME( PromptAlways ), //!< Always ask users to select from available sublayers, if sublayers are present
AskExcludingRasterBands SIP_MONKEYPATCH_COMPAT_NAME( PromptIfNeeded ), //!< Ask users to select from available sublayers, unless only raster bands are present
NeverAskSkip SIP_MONKEYPATCH_COMPAT_NAME( PromptNever ), //!< Never ask users to select sublayers, instead don't load anything
NeverAskLoadAll SIP_MONKEYPATCH_COMPAT_NAME( PromptLoadAll ), //!< Never ask users to select sublayers, instead automatically load all available sublayers
};
Q_ENUM( SublayerPromptMode )

/**
* Identify search radius in mm
* \since QGIS 2.3
@@ -183,7 +183,7 @@ void QgsSublayersDialog::populateLayerTable( const QgsSublayersDialog::LayerDefi
int QgsSublayersDialog::exec()
{
QgsSettings settings;
PromptMode promptLayers = settings.enumValue( QStringLiteral( "qgis/promptForSublayers" ), PromptAlways );
const Qgis::SublayerPromptMode promptLayers = settings.enumValue( QStringLiteral( "qgis/promptForSublayers" ), Qgis::SublayerPromptMode::AlwaysAsk );

// make sure three are sublayers to choose
if ( layersTable->topLevelItemCount() == 0 )
@@ -192,9 +192,9 @@ int QgsSublayersDialog::exec()
layersTable->selectAll();

// check promptForSublayers settings - perhaps this should be in QgsDataSource instead?
if ( promptLayers == PromptNever )
if ( promptLayers == Qgis::SublayerPromptMode::NeverAskSkip )
return QDialog::Rejected;
else if ( promptLayers == PromptLoadAll )
else if ( promptLayers == Qgis::SublayerPromptMode::NeverAskLoadAll )
return QDialog::Accepted;

// if there is only 1 sublayer (probably the main layer), just select that one and return
@@ -32,35 +32,6 @@ class GUI_EXPORT QgsSublayersDialog : public QDialog, private Ui::QgsSublayersDi
Q_OBJECT
public:

/**
* Prompt behavior of the QgsSublayersDialog
* \since QGIS 3.14
*/
enum PromptMode
{

/**
* always ask if there are existing sublayers
*/
PromptAlways,

/**
* always ask if there are existing sublayers, but skip if there are bands for rasters
*/
PromptIfNeeded,

/**
* never prompt, will not load anything
*/
PromptNever,

/**
* never prompt, but load all sublayers
*/
PromptLoadAll
};
Q_ENUM( PromptMode )

enum ProviderType
{
Ogr,

0 comments on commit d0beaae

Please sign in to comment.