Skip to content

Commit

Permalink
QgsField::ConfigurationFlags: use a negative form for the flags so th… (
Browse files Browse the repository at this point in the history
#38805)

* QgsField::ConfigurationFlags: use a negative form for the flags so that default flags is None

this will make this futureproof, so newly added flags won't cause trouble for compatibility with old projects

* follow up

* remove template class

* fix order of init

* follow up

* Revert "update test projects (open and save)"

This reverts commit c738609.

* DoNotExposeVia -> HideFrom
  • Loading branch information
3nids committed Sep 17, 2020
1 parent 7f92487 commit 5ca4ef8
Show file tree
Hide file tree
Showing 20 changed files with 1,100 additions and 1,202 deletions.
2 changes: 2 additions & 0 deletions python/gui/auto_generated/qgscheckablecombobox.sip.in
Expand Up @@ -180,6 +180,8 @@ Selects all items.
Removes selection from all items.
%End

protected:

};

/************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/app/locator/qgsinbuiltlocatorfilters.cpp
Expand Up @@ -285,7 +285,7 @@ QStringList QgsActiveLayerFeaturesLocatorFilter::prepare( const QString &string,
QgsAttributeList subsetOfAttributes;
for ( const QgsField &field : fields )
{
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::Searchable ) )
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::NotSearchable ) )
continue;

if ( !_fieldRestriction.isEmpty() && !field.name().startsWith( _fieldRestriction ) )
Expand Down
14 changes: 6 additions & 8 deletions src/core/qgsfield.cpp
Expand Up @@ -352,14 +352,12 @@ QString QgsField::readableConfigurationFlag( QgsField::ConfigurationFlag flag )
{
case ConfigurationFlag::None:
return QObject::tr( "None" );
case ConfigurationFlag::Searchable:
return QObject::tr( "Searchable" );
case ConfigurationFlag::ExposeViaWms:
return QStringLiteral( "Expose via WMS" );
case ConfigurationFlag::ExposeViaWfs:
return QStringLiteral( "Expose via WFS" );
case ConfigurationFlag::DefaultFlags:
return QObject::tr( "Default flags" );
case ConfigurationFlag::NotSearchable:
return QObject::tr( "Not searchable" );
case ConfigurationFlag::HideFromWms:
return QStringLiteral( "Do not expose via WMS" );
case ConfigurationFlag::HideFromWfs:
return QStringLiteral( "Do not expose via WFS" );
}
return QString();
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsfield.h
Expand Up @@ -71,6 +71,7 @@ class CORE_EXPORT QgsField
* Configuration flags for fields
* These flags are meant to be user-configurable
* and are not describing any information from the data provider.
* \note Flags are expressed in the negative forms so that default flags is None.
* \since QGIS 3.16
*/
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
Expand All @@ -80,10 +81,9 @@ class CORE_EXPORT QgsField
#endif
{
None = 0, //!< No flag is defined
Searchable = 1 << 1, //!< Defines if the field is searchable (used in the locator search for instance)
ExposeViaWms = 1 << 2, //!< Fields is available if layer is served as WMS from QGIS server
ExposeViaWfs = 1 << 3, //!< Fields is available if layer is served as WFS from QGIS server
DefaultFlags = Searchable | ExposeViaWms | ExposeViaWfs, //!< Default set of flags for a field
NotSearchable = 1 << 1, //!< Defines if the field is searchable (used in the locator search for instance)
HideFromWms = 1 << 2, //!< Fields is available if layer is served as WMS from QGIS server
HideFromWfs = 1 << 3, //!< Fields is available if layer is served as WFS from QGIS server
};
Q_ENUM( ConfigurationFlag )
Q_DECLARE_FLAGS( ConfigurationFlags, ConfigurationFlag )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfield_p.h
Expand Up @@ -116,7 +116,7 @@ class QgsFieldPrivate : public QSharedData
QString alias;

//! Flags for the field (searchable, …)
QgsField::ConfigurationFlags flags = QgsField::ConfigurationFlag::DefaultFlags;
QgsField::ConfigurationFlags flags = QgsField::ConfigurationFlag::None;

//! Default value
QgsDefaultValue defaultValueDefinition;
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2321,7 +2321,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
const QDomElement fieldWidgetElement = fieldConfigElement.elementsByTagName( QStringLiteral( "editWidget" ) ).at( 0 ).toElement();

QString fieldName = fieldConfigElement.attribute( QStringLiteral( "name" ) );
mFieldConfigurationFlags[fieldName] = qgsFlagKeysToValue( fieldConfigElement.attribute( QStringLiteral( "configurationFlags" ) ), QgsField::ConfigurationFlag::DefaultFlags );
mFieldConfigurationFlags[fieldName] = qgsFlagKeysToValue( fieldConfigElement.attribute( QStringLiteral( "configurationFlags" ) ), QgsField::ConfigurationFlag::None );

const QString widgetType = fieldWidgetElement.attribute( QStringLiteral( "type" ) );
const QDomElement cfgElem = fieldConfigElement.elementsByTagName( QStringLiteral( "config" ) ).at( 0 ).toElement();
Expand All @@ -2339,8 +2339,8 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
// Attributes excluded from WMS and WFS
const QList<QPair<QString, QgsField::ConfigurationFlag>> legacyConfig
{
qMakePair( QStringLiteral( "excludeAttributesWMS" ), QgsField::ConfigurationFlag::ExposeViaWms ),
qMakePair( QStringLiteral( "excludeAttributesWFS" ), QgsField::ConfigurationFlag::ExposeViaWfs )
qMakePair( QStringLiteral( "excludeAttributesWMS" ), QgsField::ConfigurationFlag::HideFromWms ),
qMakePair( QStringLiteral( "excludeAttributesWFS" ), QgsField::ConfigurationFlag::HideFromWfs )
};
for ( const auto &config : legacyConfig )
{
Expand All @@ -2352,7 +2352,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
{
QString fieldName = attributeNodeList.at( i ).toElement().text();
int index = mFields.indexFromName( fieldName );
setFieldConfigurationFlag( index, config.second, false );
setFieldConfigurationFlag( index, config.second, true );
}
}
}
Expand Down Expand Up @@ -5503,7 +5503,7 @@ QgsField::ConfigurationFlags QgsVectorLayer::fieldConfigurationFlags( int index
{

if ( index < 0 || index >= mFields.count() )
return QgsField::ConfigurationFlag::DefaultFlags;
return QgsField::ConfigurationFlag::None;

return mFields.at( index ).configurationFlags();
}
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgscheckablecombobox.cpp
Expand Up @@ -76,8 +76,8 @@ void QgsCheckBoxDelegate::paint( QPainter *painter, const QStyleOptionViewItem &

QgsCheckableComboBox::QgsCheckableComboBox( QWidget *parent )
: QComboBox( parent )
, mSeparator( QStringLiteral( ", " ) )
, mModel( new QgsCheckableItemModel( this ) )
, mSeparator( QStringLiteral( ", " ) )
{
setModel( mModel );
setItemDelegate( new QgsCheckBoxDelegate( this ) );
Expand Down Expand Up @@ -313,3 +313,4 @@ void QgsCheckableComboBox::updateDisplayText()
text = fontMetrics.elidedText( text, Qt::ElideRight, rect.width() );
setEditText( text );
}

6 changes: 4 additions & 2 deletions src/gui/qgscheckablecombobox.h
Expand Up @@ -25,6 +25,7 @@

#include "qgis_sip.h"
#include "qgis_gui.h"
#include "qgis.h"

class QEvent;

Expand Down Expand Up @@ -268,15 +269,16 @@ class GUI_EXPORT QgsCheckableComboBox : public QComboBox
*/
void deselectAllOptions();

protected:
QgsCheckableItemModel *mModel = nullptr;

private:
void updateCheckedItems();
void updateDisplayText();

QString mSeparator;
QString mDefaultText;

QgsCheckableItemModel *mModel = nullptr;

bool mSkipHide = false;

QMenu *mContextMenu = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/vector/qgssourcefieldsproperties.cpp
Expand Up @@ -275,7 +275,7 @@ void QgsSourceFieldsProperties::setRow( int row, int idx, const QgsField &field
const QList<QgsField::ConfigurationFlag> flagList = qgsEnumMap<QgsField::ConfigurationFlag>().keys();
for ( const QgsField::ConfigurationFlag flag : flagList )
{
if ( flag == QgsField::ConfigurationFlag::None || flag == QgsField::ConfigurationFlag::DefaultFlags )
if ( flag == QgsField::ConfigurationFlag::None )
continue;

cb->addItemWithCheckState( QgsField::readableConfigurationFlag( flag ),
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wfs/qgswfsdescribefeaturetype.cpp
Expand Up @@ -267,7 +267,7 @@ namespace QgsWfs
const QgsField field = fields.at( idx );
QString attributeName = field.name();
//skip attribute if excluded from WFS publication
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWfs ) )
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWfs ) )
{
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wfs/qgswfsgetfeature.cpp
Expand Up @@ -293,7 +293,7 @@ namespace QgsWfs
{
for ( const QgsField &field : fields )
{
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWfs ) )
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWfs ) )
{
int fieldNameIdx = fields.indexOf( field.name() );
if ( fieldNameIdx > -1 && attrIndexes.contains( fieldNameIdx ) )
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wfs3/qgswfs3handlers.cpp
Expand Up @@ -245,7 +245,7 @@ QgsFields QgsWfs3AbstractItemsHandler::publishedFields( const QgsVectorLayer *vL
const QgsFields &fields = vLayer->fields();
for ( const QgsField &field : fields )
{
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWfs ) )
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWfs ) )
{
publishedAttributes.push_back( field.name() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wms/qgswmsgetcapabilities.cpp
Expand Up @@ -1878,7 +1878,7 @@ namespace QgsWms
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
QgsField field = layerFields.at( idx );
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWms ) )
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
{
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -1567,7 +1567,7 @@ namespace QgsWms
for ( int i = 0; i < featureAttributes.count(); ++i )
{
//skip attribute if it is explicitly excluded from WMS publication
if ( !fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWms ) )
if ( fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
{
continue;
}
Expand Down Expand Up @@ -2416,7 +2416,7 @@ namespace QgsWms
{
QString attributeName = fields.at( i ).name();
//skip attribute if it is explicitly excluded from WMS publication
if ( !fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWms ) )
if ( fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
{
continue;
}
Expand Down

0 comments on commit 5ca4ef8

Please sign in to comment.