QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsmaplayerserverproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerserverproperties.cpp
3 ------------------
4 begin : June 21, 2021
5 copyright : (C) 2021 by Etienne Trimaille
6 email : etrimaille at 3liz dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "moc_qgsmaplayerserverproperties.cpp"
20#include "qgsmaplayer.h"
22
23#include <QDomNode>
24
25// QgsServerMetadataUrlProperties
26
28{
29 return url == other.url &&
30 type == other.type &&
31 format == other.format;
32}
33
38
40{
41 mMetadataUrls.clear();
42}
43
44void QgsServerMetadataUrlProperties::readXml( const QDomNode &layer_node )
45{
46 QDomElement element = layer_node.namedItem( QStringLiteral( "metadataUrls" ) ).toElement();
47 mMetadataUrls.clear();
48 const QDomNodeList el = element.elementsByTagName( QStringLiteral( "metadataUrl" ) );
49 for ( int i = 0; i < el.size(); i++ )
50 {
51 element = el.at( i ).toElement();
53 oneUrl.type = element.attribute( QStringLiteral( "type" ) );
54 oneUrl.format = element.attribute( QStringLiteral( "format" ) );
55 oneUrl.url = element.text();
56 addMetadataUrl( oneUrl );
57 }
58}
59
60void QgsServerMetadataUrlProperties::writeXml( QDomNode &layer_node, QDomDocument &document ) const
61{
62 QDomElement urls = document.createElement( QStringLiteral( "metadataUrls" ) );
63 for ( const QgsMapLayerServerProperties::MetadataUrl &url : mMetadataUrls )
64 {
65 QDomElement urlElement = document.createElement( QStringLiteral( "metadataUrl" ) );
66 urlElement.setAttribute( QStringLiteral( "type" ), url.type );
67 urlElement.setAttribute( QStringLiteral( "format" ), url.format );
68 urlElement.appendChild( document.createTextNode( url.url ) );
69 urls.appendChild( urlElement );
70 }
71 layer_node.appendChild( urls );
72}
73
74// QgsServerWmsDimensionProperties
75
77{
78 properties->setWmsDimensions( wmsDimensions() );
79}
80
82{
83 mWmsDimensions.clear();
84}
85
86void QgsServerWmsDimensionProperties::setWmsDimensions( const QList<QgsServerWmsDimensionProperties::WmsDimensionInfo> &dimensions )
87{
88 mWmsDimensions = dimensions;
89}
90
92{
93 QMap<int, QString> labels;
94 labels[QgsServerWmsDimensionProperties::WmsDimensionInfo::AllValues] = QObject::tr( "All values" );
95 labels[QgsServerWmsDimensionProperties::WmsDimensionInfo::MinValue] = QObject::tr( "Min value" );
96 labels[QgsServerWmsDimensionProperties::WmsDimensionInfo::MaxValue] = QObject::tr( "Max value" );
97 labels[QgsServerWmsDimensionProperties::WmsDimensionInfo::ReferenceValue] = QObject::tr( "Reference value" );
98 return labels;
99}
100
102{
103 for ( const QgsServerWmsDimensionProperties::WmsDimensionInfo &dim : std::as_const( mWmsDimensions ) )
104 {
105 if ( dim.name == wmsDimInfo.name )
106 {
107 return false;
108 }
109 }
110 mWmsDimensions.append( wmsDimInfo );
111 return true;
112}
113
115{
116 for ( int i = 0; i < mWmsDimensions.size(); ++i )
117 {
118 if ( mWmsDimensions[ i ].name == wmsDimName )
119 {
120 mWmsDimensions.removeAt( i );
121 return true;
122 }
123 }
124 return false;
125}
126
127const QList< QgsServerWmsDimensionProperties::WmsDimensionInfo > QgsServerWmsDimensionProperties::wmsDimensions() const
128{
129 return mWmsDimensions;
130}
131
132void QgsServerWmsDimensionProperties::readXml( const QDomNode &layer_node )
133{
134 reset();
135
136 // Apply only for vector layers
137 if ( layer()->type() != Qgis::LayerType::Vector )
138 return;
139
140 const QgsFields fields = static_cast<const QgsVectorLayer *>( layer() )->fields();
141 // QGIS Server WMS Dimensions
142 const QDomNode wmsDimsNode = layer_node.namedItem( QStringLiteral( "wmsDimensions" ) );
143 if ( wmsDimsNode.isNull() )
144 {
145 return;
146 }
147 const QDomElement wmsDimsElem = wmsDimsNode.toElement();
148 const QDomNodeList wmsDimsList = wmsDimsElem.elementsByTagName( QStringLiteral( "dimension" ) );
149 for ( int i = 0; i < wmsDimsList.size(); ++i )
150 {
151 const QDomElement dimElem = wmsDimsList.at( i ).toElement();
152 const QString dimName = dimElem.attribute( QStringLiteral( "name" ) );
153 const QString dimFieldName = dimElem.attribute( QStringLiteral( "fieldName" ) );
154 // check field name
155 const int dimFieldNameIndex = fields.indexOf( dimFieldName );
156 if ( dimFieldNameIndex == -1 )
157 {
158 continue;
159 }
160 QVariant dimRefValue;
161 const int dimDefaultDisplayType = dimElem.attribute( QStringLiteral( "defaultDisplayType" ) ).toInt();
163 {
164 const QString dimRefValueStr = dimElem.attribute( QStringLiteral( "referenceValue" ) );
165 if ( !dimRefValueStr.isEmpty() )
166 {
167 const QgsField dimField = fields.at( dimFieldNameIndex );
168 dimRefValue = QVariant( dimRefValueStr );
169 if ( !dimField.convertCompatible( dimRefValue ) )
170 {
171 continue;
172 }
173 }
174 }
175 QgsServerWmsDimensionProperties::WmsDimensionInfo dim( dimName, dimFieldName,
176 dimElem.attribute( QStringLiteral( "endFieldName" ) ),
177 dimElem.attribute( QStringLiteral( "units" ) ),
178 dimElem.attribute( QStringLiteral( "unitSymbol" ) ),
179 dimDefaultDisplayType, dimRefValue );
180 //XXX This add O(n^2) complexity !!!!
181 // addWmsDimension( dim );
182 // Better to trust the XML:
183 mWmsDimensions.append( dim );
184 }
185}
186
187void QgsServerWmsDimensionProperties::writeXml( QDomNode &layer_node, QDomDocument &document ) const
188{
189 // save QGIS Server WMS Dimension definitions
190 if ( ! mWmsDimensions.isEmpty() )
191 {
192 QDomElement wmsDimsElem = document.createElement( QStringLiteral( "wmsDimensions" ) );
193 for ( const QgsServerWmsDimensionProperties::WmsDimensionInfo &dim : mWmsDimensions )
194 {
195 QDomElement dimElem = document.createElement( QStringLiteral( "dimension" ) );
196 dimElem.setAttribute( QStringLiteral( "name" ), dim.name );
197 dimElem.setAttribute( QStringLiteral( "fieldName" ), dim.fieldName );
198 dimElem.setAttribute( QStringLiteral( "endFieldName" ), dim.endFieldName );
199 dimElem.setAttribute( QStringLiteral( "units" ), dim.units );
200 dimElem.setAttribute( QStringLiteral( "unitSymbol" ), dim.unitSymbol );
201 dimElem.setAttribute( QStringLiteral( "defaultDisplayType" ), dim.defaultDisplayType );
202 dimElem.setAttribute( QStringLiteral( "referenceValue" ), dim.referenceValue.toString() );
203 wmsDimsElem.appendChild( dimElem );
204 }
205 layer_node.appendChild( wmsDimsElem );
206 }
207}
208
209
210// QgsMapLayerServerProperties
211
216
218{
221
222 properties->setShortName( mShortName );
223 properties->setTitle( mTitle );
224 properties->setAbstract( mAbstract );
225 properties->setKeywordList( mKeywordList );
226 properties->setDataUrl( mDataUrl );
227 properties->setDataUrlFormat( mDataUrlFormat );
228 properties->setAttribution( mAttribution );
229 properties->setAttributionUrl( mAttributionUrl );
230}
231
237
238void QgsMapLayerServerProperties::readXml( const QDomNode &layer_node ) // cppcheck-suppress duplInheritedMember
239{
242
243 //short name
244 const QDomElement shortNameElem = layer_node.firstChildElement( QStringLiteral( "shortname" ) );
245 if ( !shortNameElem.isNull() )
246 {
247 mShortName = shortNameElem.text();
248 }
249
250 //title
251 const QDomElement titleElem = layer_node.firstChildElement( QStringLiteral( "title" ) );
252 if ( !titleElem.isNull() )
253 {
254 mTitle = titleElem.text();
255 mWfsTitle = titleElem.attribute( QStringLiteral( "wfs" ) );
256 }
257
258 //abstract
259 const QDomElement abstractElem = layer_node.firstChildElement( QStringLiteral( "abstract" ) );
260 if ( !abstractElem.isNull() )
261 {
262 mAbstract = abstractElem.text();
263 }
264
265 //keywordList
266 const QDomElement keywordListElem = layer_node.firstChildElement( QStringLiteral( "keywordList" ) );
267 if ( !keywordListElem.isNull() )
268 {
269 QStringList kwdList;
270 for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
271 {
272 kwdList << n.toElement().text();
273 }
274 mKeywordList = kwdList.join( QLatin1String( ", " ) );
275 }
276
277 //dataUrl
278 const QDomElement dataUrlElem = layer_node.firstChildElement( QStringLiteral( "dataUrl" ) );
279 if ( !dataUrlElem.isNull() )
280 {
281 mDataUrl = dataUrlElem.text();
282 mDataUrlFormat = dataUrlElem.attribute( QStringLiteral( "format" ), QString() );
283 }
284
285 //attribution
286 const QDomElement attribElem = layer_node.firstChildElement( QStringLiteral( "attribution" ) );
287 if ( !attribElem.isNull() )
288 {
289 mAttribution = attribElem.text();
290 mAttributionUrl = attribElem.attribute( QStringLiteral( "href" ), QString() );
291 }
292}
293
294void QgsMapLayerServerProperties::writeXml( QDomNode &layer_node, QDomDocument &document ) const // cppcheck-suppress duplInheritedMember
295{
296 QgsServerMetadataUrlProperties::writeXml( layer_node, document );
297 QgsServerWmsDimensionProperties::writeXml( layer_node, document );
298
299 // TODO -- ideally we should also be writing mTitle, mAbstract etc, but this method is currently
300 // only called for SOME map layer subclasses!
301 // Accordingly that logic is currently left in QgsMapLayer::writeLayerXml
302}
303
@ Vector
Vector layer.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Definition qgsfield.cpp:473
Container of fields for a vector layer.
Definition qgsfields.h:46
Q_INVOKABLE int indexOf(const QString &fieldName) const
Gets the field index from the field name.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Manages QGIS Server properties for a map layer.
void readXml(const QDomNode &layer_node)
Reads server properties from project file.
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layerused by QGIS Server in GetCapabilities request.
void setAttributionUrl(const QString &url)
Sets the attribution url of the layer used by QGIS Server in GetCapabilities request.
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
void setShortName(const QString &name)
Sets the short name of the layer used by QGIS Server to identify the layer.
void copyTo(QgsMapLayerServerProperties *properties) const
Copy properties to another instance.
QgsMapLayerServerProperties(QgsMapLayer *layer=nullptr)
Constructor - Creates a Map Layer QGIS Server Properties.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves server properties to xml under the layer node.
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
void setKeywordList(const QString &keywords)
Sets the keywords list of the layerused by QGIS Server in GetCapabilities request.
void reset()
Reset properties to default.
Base class for all map layer types.
Definition qgsmaplayer.h:76
Manages QGIS Server properties for a map layer.
virtual const QgsMapLayer * layer() const =0
Gets the parent layer.
void addMetadataUrl(const QgsServerMetadataUrlProperties::MetadataUrl &metaUrl)
Add a metadataUrl for the layer.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves server properties to xml under the layer node.
void reset()
Reset properties to default.
void setMetadataUrls(const QList< QgsServerMetadataUrlProperties::MetadataUrl > &metaUrls)
Sets a the list of metadata URL for the layer.
QList< QgsServerMetadataUrlProperties::MetadataUrl > metadataUrls() const
Returns a list of metadataUrl resources associated for the layer.
void readXml(const QDomNode &layer_node)
Reads server properties from project file.
void copyTo(QgsServerMetadataUrlProperties *properties) const
Copy properties to another instance.
Manages QGIS Server properties for Wms dimensions.
void readXml(const QDomNode &layer_node)
Reads server properties from project file.
static QMap< int, QString > wmsDimensionDefaultDisplayLabels()
Returns WMS Dimension default display labels.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves server properties to xml under the layer node.
void reset()
Reset properties to default.
bool addWmsDimension(const QgsServerWmsDimensionProperties::WmsDimensionInfo &wmsDimInfo)
Adds a QGIS Server WMS Dimension.
void copyTo(QgsServerWmsDimensionProperties *properties) const
Copy properties to another instance.
bool removeWmsDimension(const QString &wmsDimName)
Removes a QGIS Server WMS Dimension.
const QList< QgsServerWmsDimensionProperties::WmsDimensionInfo > wmsDimensions() const
Returns the QGIS Server WMS Dimension list.
void setWmsDimensions(const QList< QgsServerWmsDimensionProperties::WmsDimensionInfo > &dimensions)
Set WMS Dimensions.
Represents a vector layer which manages a vector based data sets.
bool operator==(const QgsServerMetadataUrlProperties::MetadataUrl &other) const
Compare two MetadataUrl structure.
QString format
Format specification of online resource.
Setting to define QGIS Server WMS Dimension.
@ MaxValue
Modify current selection to include only select features which match.