QGIS API Documentation 3.43.0-Master (3ee7834ace6)
qgsmaplayerserverpropertieswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayerserverpropertieswidget.cpp
3 ---------------------
4 begin : 2025/02/20
5 copyright : (C) 2025 by Julien Cabieces
6 email : julien dot cabieces at oslandia dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsmaplayerserverpropertieswidget.cpp"
19#include "qgsapplication.h"
21
22#include <QRegularExpressionValidator>
23#include <QStandardItemModel>
24
26 : QWidget( parent )
27{
28 setupUi( this );
29 connect( buttonRemoveMetadataUrl, &QPushButton::clicked, this, &QgsMapLayerServerPropertiesWidget::removeSelectedMetadataUrl );
30 connect( buttonAddMetadataUrl, &QPushButton::clicked, this, &QgsMapLayerServerPropertiesWidget::addMetadataUrl );
31}
32
34{
35 mServerProperties = serverProperties;
36 sync();
37}
38
40{
41 mHasWfsTitle = hasWfsTitle;
42 mLayerOptWfsTitleLineEdit->setVisible( mHasWfsTitle );
43 mLayerOptWfsTitleLabel->setVisible( mHasWfsTitle );
44}
45
47{
48 return mHasWfsTitle;
49}
50
52{
53 if ( !mServerProperties )
54 return false;
55
56 bool hasChanged = mServerProperties->shortName() != mLayerShortNameLineEdit->text()
57 || mServerProperties->title() != mLayerTitleLineEdit->text()
58 || mServerProperties->abstract() != mLayerAbstractTextEdit->toPlainText()
59 || mServerProperties->keywordList() != mLayerKeywordListLineEdit->text()
60 || mServerProperties->dataUrl() != mLayerDataUrlLineEdit->text()
61 || mServerProperties->dataUrlFormat() != mLayerDataUrlFormatComboBox->currentText()
62 || mServerProperties->attribution() != mLayerAttributionLineEdit->text()
63 || mServerProperties->attributionUrl() != mLayerAttributionUrlLineEdit->text()
64 || mServerProperties->legendUrl() != mLayerLegendUrlLineEdit->text()
65 || mServerProperties->legendUrlFormat() != mLayerLegendUrlFormatComboBox->currentText();
66
67 mServerProperties->setShortName( mLayerShortNameLineEdit->text() );
68 mServerProperties->setTitle( mLayerTitleLineEdit->text() );
69 mServerProperties->setAbstract( mLayerAbstractTextEdit->toPlainText() );
70 mServerProperties->setKeywordList( mLayerKeywordListLineEdit->text() );
71 mServerProperties->setDataUrl( mLayerDataUrlLineEdit->text() );
72 mServerProperties->setDataUrlFormat( mLayerDataUrlFormatComboBox->currentText() );
73 mServerProperties->setAttribution( mLayerAttributionLineEdit->text() );
74 mServerProperties->setAttributionUrl( mLayerAttributionUrlLineEdit->text() );
75 mServerProperties->setLegendUrl( mLayerLegendUrlLineEdit->text() );
76 mServerProperties->setLegendUrlFormat( mLayerLegendUrlFormatComboBox->currentText() );
77
78 if ( !mLayerOptWfsTitleLineEdit->text().isEmpty() && mLayerOptWfsTitleLineEdit->text() != mLayerTitleLineEdit->text() )
79 {
80 mServerProperties->setWfsTitle( mLayerOptWfsTitleLineEdit->text() );
81 hasChanged = true;
82 }
83 else
84 {
85 mServerProperties->setWfsTitle( QString() );
86 }
87
88 // Metadata URL
89 QList<QgsMapLayerServerProperties::MetadataUrl> metaUrls;
90 for ( int row = 0; row < mMetadataUrlModel->rowCount(); row++ )
91 {
93 metaUrl.url = mMetadataUrlModel->item( row, 0 )->text();
94 metaUrl.type = mMetadataUrlModel->item( row, 1 )->text();
95 metaUrl.format = mMetadataUrlModel->item( row, 2 )->text();
96 metaUrls.append( metaUrl );
97
98 // TODO has not necessary changed
99 hasChanged = true;
100 }
101 mServerProperties->setMetadataUrls( metaUrls );
102
103 return hasChanged;
104}
105
107{
108 if ( !mServerProperties )
109 return;
110
111 // WMS Name as layer short name
112 mLayerShortNameLineEdit->setText( mServerProperties->shortName() );
113 // WMS Name validator
114 QValidator *shortNameValidator = new QRegularExpressionValidator( QgsApplication::shortNameRegularExpression(), this );
115 mLayerShortNameLineEdit->setValidator( shortNameValidator );
116
117 //layer title and abstract
118 mLayerTitleLineEdit->setText( mServerProperties->title() );
119
120 if ( mServerProperties->wfsTitle() != mServerProperties->title() )
121 mLayerOptWfsTitleLineEdit->setText( mServerProperties->wfsTitle() );
122
123 mLayerAbstractTextEdit->setPlainText( mServerProperties->abstract() );
124 mLayerKeywordListLineEdit->setText( mServerProperties->keywordList() );
125 mLayerDataUrlLineEdit->setText( mServerProperties->dataUrl() );
126 mLayerDataUrlFormatComboBox->setCurrentIndex(
127 mLayerDataUrlFormatComboBox->findText(
128 mServerProperties->dataUrlFormat()
129 )
130 );
131 //layer attribution
132 mLayerAttributionLineEdit->setText( mServerProperties->attribution() );
133 mLayerAttributionUrlLineEdit->setText( mServerProperties->attributionUrl() );
134
135 // Setup the layer metadata URL
136 tableViewMetadataUrl->setSelectionMode( QAbstractItemView::SingleSelection );
137 tableViewMetadataUrl->setSelectionBehavior( QAbstractItemView::SelectRows );
138 tableViewMetadataUrl->horizontalHeader()->setStretchLastSection( true );
139 tableViewMetadataUrl->horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch );
140
141 mMetadataUrlModel = new QStandardItemModel( tableViewMetadataUrl );
142 mMetadataUrlModel->clear();
143 mMetadataUrlModel->setColumnCount( 3 );
144 QStringList metadataUrlHeaders;
145 metadataUrlHeaders << tr( "URL" ) << tr( "Type" ) << tr( "Format" );
146 mMetadataUrlModel->setHorizontalHeaderLabels( metadataUrlHeaders );
147 tableViewMetadataUrl->setModel( mMetadataUrlModel );
148 tableViewMetadataUrl->setItemDelegate( new MetadataUrlItemDelegate( this ) );
149
150 const QList<QgsMapLayerServerProperties::MetadataUrl> &metaUrls = mServerProperties->metadataUrls();
151 for ( const QgsMapLayerServerProperties::MetadataUrl &metaUrl : metaUrls )
152 {
153 const int row = mMetadataUrlModel->rowCount();
154 mMetadataUrlModel->setItem( row, 0, new QStandardItem( metaUrl.url ) );
155 mMetadataUrlModel->setItem( row, 1, new QStandardItem( metaUrl.type ) );
156 mMetadataUrlModel->setItem( row, 2, new QStandardItem( metaUrl.format ) );
157 }
158
159 // layer legend url
160 mLayerLegendUrlLineEdit->setText( mServerProperties->legendUrl() );
161 mLayerLegendUrlFormatComboBox->setCurrentIndex(
162 mLayerLegendUrlFormatComboBox->findText(
163 mServerProperties->legendUrlFormat()
164 )
165 );
166}
167
168void QgsMapLayerServerPropertiesWidget::addMetadataUrl()
169{
170 const int row = mMetadataUrlModel->rowCount();
171 mMetadataUrlModel->setItem( row, 0, new QStandardItem( QLatin1String() ) );
172 mMetadataUrlModel->setItem( row, 1, new QStandardItem( QLatin1String() ) );
173 mMetadataUrlModel->setItem( row, 2, new QStandardItem( QLatin1String() ) );
174}
175
176void QgsMapLayerServerPropertiesWidget::removeSelectedMetadataUrl()
177{
178 const QModelIndexList selectedRows = tableViewMetadataUrl->selectionModel()->selectedRows();
179 if ( selectedRows.empty() )
180 return;
181 mMetadataUrlModel->removeRow( selectedRows[0].row() );
182}
static QRegularExpression shortNameRegularExpression()
Returns the short name regular expression for line edit validator.
void setHasWfsTitle(bool hasWfsTitle)
Set whether or not server properties widget has to display a WFS title widget.
QgsMapLayerServerPropertiesWidget(QWidget *parent=nullptr)
Constructor.
bool hasWfsTitle() const
Returns true if widget display a WFS title widget.
void setServerProperties(QgsMapLayerServerProperties *serverProperties)
Sets the server properties serverProperties associated with the widget.
bool save()
Saves the settings to the server properties.
void sync()
Updates the widget state to match the current server properties state.
Manages QGIS Server properties for a map layer.
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
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.
QString attribution() const
Returns the attribution of the layer used 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.
QString dataUrlFormat() const
Returns the DataUrl format 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.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
QString keywordList() const
Returns the keyword list of the layerused by QGIS Server in GetCapabilities request.
QString wfsTitle() const
Returns the optional WFS title if set or the title of the layer used by QGIS WFS in GetCapabilities r...
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
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.
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
void setWfsTitle(const QString &title)
Sets the title of the layer used by QGIS Server in WFS GetCapabilities request.
QString legendUrl() const
Returns the URL for the layer's legend.
QString abstract() const
Returns the abstract of the layerused by QGIS Server in GetCapabilities request.
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.
QString format
Format specification of online resource.