Skip to content

Commit 5ca4ef8

Browse files
authoredSep 17, 2020
QgsField::ConfigurationFlags: use a negative form for the flags so th… (#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
1 parent 7f92487 commit 5ca4ef8

20 files changed

+1100
-1202
lines changed
 

‎python/gui/auto_generated/qgscheckablecombobox.sip.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ Selects all items.
180180
Removes selection from all items.
181181
%End
182182

183+
protected:
184+
183185
};
184186

185187
/************************************************************************

‎src/app/locator/qgsinbuiltlocatorfilters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ QStringList QgsActiveLayerFeaturesLocatorFilter::prepare( const QString &string,
285285
QgsAttributeList subsetOfAttributes;
286286
for ( const QgsField &field : fields )
287287
{
288-
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::Searchable ) )
288+
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::NotSearchable ) )
289289
continue;
290290

291291
if ( !_fieldRestriction.isEmpty() && !field.name().startsWith( _fieldRestriction ) )

‎src/core/qgsfield.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,12 @@ QString QgsField::readableConfigurationFlag( QgsField::ConfigurationFlag flag )
352352
{
353353
case ConfigurationFlag::None:
354354
return QObject::tr( "None" );
355-
case ConfigurationFlag::Searchable:
356-
return QObject::tr( "Searchable" );
357-
case ConfigurationFlag::ExposeViaWms:
358-
return QStringLiteral( "Expose via WMS" );
359-
case ConfigurationFlag::ExposeViaWfs:
360-
return QStringLiteral( "Expose via WFS" );
361-
case ConfigurationFlag::DefaultFlags:
362-
return QObject::tr( "Default flags" );
355+
case ConfigurationFlag::NotSearchable:
356+
return QObject::tr( "Not searchable" );
357+
case ConfigurationFlag::HideFromWms:
358+
return QStringLiteral( "Do not expose via WMS" );
359+
case ConfigurationFlag::HideFromWfs:
360+
return QStringLiteral( "Do not expose via WFS" );
363361
}
364362
return QString();
365363
}

‎src/core/qgsfield.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class CORE_EXPORT QgsField
7171
* Configuration flags for fields
7272
* These flags are meant to be user-configurable
7373
* and are not describing any information from the data provider.
74+
* \note Flags are expressed in the negative forms so that default flags is None.
7475
* \since QGIS 3.16
7576
*/
7677
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
@@ -80,10 +81,9 @@ class CORE_EXPORT QgsField
8081
#endif
8182
{
8283
None = 0, //!< No flag is defined
83-
Searchable = 1 << 1, //!< Defines if the field is searchable (used in the locator search for instance)
84-
ExposeViaWms = 1 << 2, //!< Fields is available if layer is served as WMS from QGIS server
85-
ExposeViaWfs = 1 << 3, //!< Fields is available if layer is served as WFS from QGIS server
86-
DefaultFlags = Searchable | ExposeViaWms | ExposeViaWfs, //!< Default set of flags for a field
84+
NotSearchable = 1 << 1, //!< Defines if the field is searchable (used in the locator search for instance)
85+
HideFromWms = 1 << 2, //!< Fields is available if layer is served as WMS from QGIS server
86+
HideFromWfs = 1 << 3, //!< Fields is available if layer is served as WFS from QGIS server
8787
};
8888
Q_ENUM( ConfigurationFlag )
8989
Q_DECLARE_FLAGS( ConfigurationFlags, ConfigurationFlag )

‎src/core/qgsfield_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class QgsFieldPrivate : public QSharedData
116116
QString alias;
117117

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

121121
//! Default value
122122
QgsDefaultValue defaultValueDefinition;

‎src/core/qgsvectorlayer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
23212321
const QDomElement fieldWidgetElement = fieldConfigElement.elementsByTagName( QStringLiteral( "editWidget" ) ).at( 0 ).toElement();
23222322

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

23262326
const QString widgetType = fieldWidgetElement.attribute( QStringLiteral( "type" ) );
23272327
const QDomElement cfgElem = fieldConfigElement.elementsByTagName( QStringLiteral( "config" ) ).at( 0 ).toElement();
@@ -2339,8 +2339,8 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
23392339
// Attributes excluded from WMS and WFS
23402340
const QList<QPair<QString, QgsField::ConfigurationFlag>> legacyConfig
23412341
{
2342-
qMakePair( QStringLiteral( "excludeAttributesWMS" ), QgsField::ConfigurationFlag::ExposeViaWms ),
2343-
qMakePair( QStringLiteral( "excludeAttributesWFS" ), QgsField::ConfigurationFlag::ExposeViaWfs )
2342+
qMakePair( QStringLiteral( "excludeAttributesWMS" ), QgsField::ConfigurationFlag::HideFromWms ),
2343+
qMakePair( QStringLiteral( "excludeAttributesWFS" ), QgsField::ConfigurationFlag::HideFromWfs )
23442344
};
23452345
for ( const auto &config : legacyConfig )
23462346
{
@@ -2352,7 +2352,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode &layerNode, QString &errorMes
23522352
{
23532353
QString fieldName = attributeNodeList.at( i ).toElement().text();
23542354
int index = mFields.indexFromName( fieldName );
2355-
setFieldConfigurationFlag( index, config.second, false );
2355+
setFieldConfigurationFlag( index, config.second, true );
23562356
}
23572357
}
23582358
}
@@ -5503,7 +5503,7 @@ QgsField::ConfigurationFlags QgsVectorLayer::fieldConfigurationFlags( int index
55035503
{
55045504

55055505
if ( index < 0 || index >= mFields.count() )
5506-
return QgsField::ConfigurationFlag::DefaultFlags;
5506+
return QgsField::ConfigurationFlag::None;
55075507

55085508
return mFields.at( index ).configurationFlags();
55095509
}

‎src/gui/qgscheckablecombobox.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void QgsCheckBoxDelegate::paint( QPainter *painter, const QStyleOptionViewItem &
7676

7777
QgsCheckableComboBox::QgsCheckableComboBox( QWidget *parent )
7878
: QComboBox( parent )
79-
, mSeparator( QStringLiteral( ", " ) )
8079
, mModel( new QgsCheckableItemModel( this ) )
80+
, mSeparator( QStringLiteral( ", " ) )
8181
{
8282
setModel( mModel );
8383
setItemDelegate( new QgsCheckBoxDelegate( this ) );
@@ -313,3 +313,4 @@ void QgsCheckableComboBox::updateDisplayText()
313313
text = fontMetrics.elidedText( text, Qt::ElideRight, rect.width() );
314314
setEditText( text );
315315
}
316+

‎src/gui/qgscheckablecombobox.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "qgis_sip.h"
2727
#include "qgis_gui.h"
28+
#include "qgis.h"
2829

2930
class QEvent;
3031

@@ -268,15 +269,16 @@ class GUI_EXPORT QgsCheckableComboBox : public QComboBox
268269
*/
269270
void deselectAllOptions();
270271

272+
protected:
273+
QgsCheckableItemModel *mModel = nullptr;
274+
271275
private:
272276
void updateCheckedItems();
273277
void updateDisplayText();
274278

275279
QString mSeparator;
276280
QString mDefaultText;
277281

278-
QgsCheckableItemModel *mModel = nullptr;
279-
280282
bool mSkipHide = false;
281283

282284
QMenu *mContextMenu = nullptr;

‎src/gui/vector/qgssourcefieldsproperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void QgsSourceFieldsProperties::setRow( int row, int idx, const QgsField &field
275275
const QList<QgsField::ConfigurationFlag> flagList = qgsEnumMap<QgsField::ConfigurationFlag>().keys();
276276
for ( const QgsField::ConfigurationFlag flag : flagList )
277277
{
278-
if ( flag == QgsField::ConfigurationFlag::None || flag == QgsField::ConfigurationFlag::DefaultFlags )
278+
if ( flag == QgsField::ConfigurationFlag::None )
279279
continue;
280280

281281
cb->addItemWithCheckState( QgsField::readableConfigurationFlag( flag ),

‎src/server/services/wfs/qgswfsdescribefeaturetype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ namespace QgsWfs
267267
const QgsField field = fields.at( idx );
268268
QString attributeName = field.name();
269269
//skip attribute if excluded from WFS publication
270-
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWfs ) )
270+
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWfs ) )
271271
{
272272
continue;
273273
}

‎src/server/services/wfs/qgswfsgetfeature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ namespace QgsWfs
293293
{
294294
for ( const QgsField &field : fields )
295295
{
296-
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWfs ) )
296+
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWfs ) )
297297
{
298298
int fieldNameIdx = fields.indexOf( field.name() );
299299
if ( fieldNameIdx > -1 && attrIndexes.contains( fieldNameIdx ) )

‎src/server/services/wfs3/qgswfs3handlers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ QgsFields QgsWfs3AbstractItemsHandler::publishedFields( const QgsVectorLayer *vL
245245
const QgsFields &fields = vLayer->fields();
246246
for ( const QgsField &field : fields )
247247
{
248-
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWfs ) )
248+
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWfs ) )
249249
{
250250
publishedAttributes.push_back( field.name() );
251251
}

‎src/server/services/wms/qgswmsgetcapabilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ namespace QgsWms
18781878
for ( int idx = 0; idx < layerFields.count(); ++idx )
18791879
{
18801880
QgsField field = layerFields.at( idx );
1881-
if ( !field.configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWms ) )
1881+
if ( field.configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
18821882
{
18831883
continue;
18841884
}

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ namespace QgsWms
15671567
for ( int i = 0; i < featureAttributes.count(); ++i )
15681568
{
15691569
//skip attribute if it is explicitly excluded from WMS publication
1570-
if ( !fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWms ) )
1570+
if ( fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
15711571
{
15721572
continue;
15731573
}
@@ -2416,7 +2416,7 @@ namespace QgsWms
24162416
{
24172417
QString attributeName = fields.at( i ).name();
24182418
//skip attribute if it is explicitly excluded from WMS publication
2419-
if ( !fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::ExposeViaWms ) )
2419+
if ( fields.at( i ).configurationFlags().testFlag( QgsField::ConfigurationFlag::HideFromWms ) )
24202420
{
24212421
continue;
24222422
}

‎tests/testdata/qgis_server/landingpage/projects/Project1.qgs

Lines changed: 56 additions & 119 deletions
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.

‎tests/testdata/qgis_server/landingpage/projects/test_project_wms_grouped_nested_layers.qgs

Lines changed: 1012 additions & 1054 deletions
Large diffs are not rendered by default.
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.