QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
24 #include <QRegularExpression>
31 return QObject::tr(
"Encoding is not correctly set. A non 'System' encoding is required" );
33 return QObject::tr(
"Layer short name is not valid. It must start with an unaccented alphabetical letter, followed by any alphanumeric letters, dot, dash or underscore" );
35 return QObject::tr(
"One or more layers or groups have the same name or short name. Both the 'name' and 'short name' for layers and groups must be unique" );
37 return QObject::tr(
"The project root name (either the project short name or project title) is not valid. It must start with an unaccented alphabetical letter, followed by any alphanumeric letters, dot, dash or underscore" );
39 return QObject::tr(
"The project root name (either the project short name or project title) is already used by a layer or a group" );
44 void QgsProjectServerValidator::browseLayerTree(
QgsLayerTreeGroup *treeGroup, QStringList &owsNames, QStringList &encodingMessages )
46 const QList< QgsLayerTreeNode * > treeGroupChildren = treeGroup->
children();
47 for (
int i = 0; i < treeGroupChildren.size(); ++i )
53 const QString shortName = treeGroupChild->
customProperty( QStringLiteral(
"wmsShortName" ) ).toString();
54 if ( shortName.isEmpty() )
55 owsNames << treeGroupChild->
name();
57 owsNames << shortName;
58 browseLayerTree( treeGroupChild, owsNames, encodingMessages );
66 const QString shortName = layer->
shortName();
67 if ( shortName.isEmpty() )
68 owsNames << layer->
name();
70 owsNames << shortName;
76 encodingMessages << layer->
name();
94 QStringList owsNames, encodingMessages;
95 browseLayerTree( project->
layerTreeRoot(), owsNames, encodingMessages );
97 QStringList duplicateNames, regExpMessages;
99 const auto constOwsNames = owsNames;
100 for (
const QString &name : constOwsNames )
102 if ( !snRegExp.match( name ).hasMatch() )
104 regExpMessages << name;
107 if ( duplicateNames.contains( name ) )
112 if ( owsNames.count( name ) > 1 )
114 duplicateNames << name;
118 if ( !duplicateNames.empty() )
124 if ( !regExpMessages.empty() )
130 if ( !encodingMessages.empty() )
137 QString rootLayerName = project->
readEntry( QStringLiteral(
"WMSRootName" ), QStringLiteral(
"/" ),
"" );
138 if ( rootLayerName.isEmpty() && !project->
title().isEmpty() )
140 rootLayerName = project->
title();
142 if ( !rootLayerName.isEmpty() )
144 if ( owsNames.count( rootLayerName ) >= 1 )
150 if ( !snRegExp.match( rootLayerName ).hasMatch() )
@ NodeGroup
Container of other groups and layers.
QString title() const
Returns the project's title.
This class is a base class for nodes in a layer tree.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
@ VectorLayer
Vector layer.
QString encoding() const
Returns the encoding which is used for accessing data.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
static QRegularExpression shortNameRegularExpression()
Returns the short name regular expression for line edit validator.
@ ProjectShortName
The project short name is not valid.
ValidationError
Errors that might be raised by the validation process.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
@ LayerEncoding
Encoding is not correctly set on a vector layer.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
@ DuplicatedNames
A duplicated layer/group name in the layer tree.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
Contains the parameters describing a project validation failure.
Layer tree node points to a map layer.
Layer tree group node serves as a container for layers and further groups.
static QString displayValidationError(QgsProjectServerValidator::ValidationError error)
Returns a human readable string for a given error.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
Represents a vector layer which manages a vector based data sets.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file.
Base class for all map layer types. This is the base class for all map layer types (vector,...
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
QString name() const override
Returns the group's name.
static bool validate(QgsProject *project, QList< QgsProjectServerValidator::ValidationResult > &results)
Validates a project to detect problems on QGIS Server, and returns true if it's considered valid.
@ ProjectRootNameConflict
The project root name is already used by a layer or a group.
@ LayerShortName
Layer/group short name is not valid.