QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgswmsdimensiondialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswmsdimensiondialog.cpp
3 ------------------
4 begin : August 20, 2019
5 copyright : (C) 2019 by René-Luc D'Hont
6 email : rldhont 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_qgswmsdimensiondialog.cpp"
20#include "qgsvectorlayer.h"
21#include "qgsfieldcombobox.h"
22
23#include <QStandardItemModel>
24#include <QPushButton>
25
26QgsWmsDimensionDialog::QgsWmsDimensionDialog( QgsVectorLayer *layer, QStringList alreadyDefinedDimensions, QWidget *parent, Qt::WindowFlags f )
27 : QDialog( parent, f )
28 , mLayer( layer )
29{
30 setupUi( this );
31
32 if ( !mLayer )
33 {
34 return;
35 }
36
37 const QString nameToolTip = tr( "OAPIF supports \"Name\" and \"Date\" only. For \"WMS\", \"Time\" and \"Elevation\" are predefined values according to OGC specifications but it can be user-defined." );
38 mNameLabel->setToolTip( nameToolTip );
39 mNameComboBox->setToolTip( nameToolTip );
40
41 // Set field combobox
42 mFieldComboBox->setLayer( mLayer );
43 mEndFieldComboBox->setLayer( mLayer );
44 mEndFieldComboBox->setAllowEmptyFieldName( true );
45
46 connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsWmsDimensionDialog::accept );
47 connect( buttonBox, &QDialogButtonBox::rejected, this, &QgsWmsDimensionDialog::reject );
48 connect( mFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsWmsDimensionDialog::fieldChanged );
49 connect( mEndFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsWmsDimensionDialog::fieldChanged );
50 connect( mNameComboBox, &QComboBox::editTextChanged, this, &QgsWmsDimensionDialog::nameChanged );
51 connect( mDefaultDisplayComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsWmsDimensionDialog::defaultDisplayChanged );
52
53 // Set available names
54 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
55 for ( int i = 0; i < pnMetaEnum.keyCount(); i++ )
56 {
57 const QString name( pnMetaEnum.key( i ) );
58 if ( !alreadyDefinedDimensions.contains( name.toLower() ) )
59 {
60 mNameComboBox->addItem( QStringLiteral( "%1%2" ).arg( !name.isEmpty() ? name.at( 0 ) : QString(), name.mid( 1 ).toLower() ), QVariant( pnMetaEnum.value( i ) ) );
61 }
62 }
63
64 // Set default display combobox
65 mDefaultDisplayComboBox->clear();
66 QMap<int, QString> defaultDisplayLabels = QgsMapLayerServerProperties::wmsDimensionDefaultDisplayLabels();
67 for ( auto it = defaultDisplayLabels.constBegin(); it != defaultDisplayLabels.constEnd(); it++ )
68 {
69 mDefaultDisplayComboBox->addItem( it.value(), QVariant( it.key() ) );
70 }
71 // Set default display to All values
72 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant( QgsMapLayerServerProperties::WmsDimensionInfo::AllValues ) ) );
73
74 mReferenceValueLabel->setEnabled( false );
75 mReferenceValueComboBox->setEnabled( false );
76
77 fieldChanged();
78}
79
81{
82 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
83 const int predefinedNameValue = pnMetaEnum.keyToValue( info.name.toUpper().toStdString().c_str() );
84 if ( predefinedNameValue == -1 )
85 {
86 mNameComboBox->setEditText( info.name );
87 }
88 else
89 {
90 mNameComboBox->setCurrentIndex( mNameComboBox->findData( QVariant( predefinedNameValue ) ) );
91 }
92 mNameComboBox->setEnabled( false );
93
94 mFieldComboBox->setField( info.fieldName );
95 mEndFieldComboBox->setField( info.endFieldName );
96
97 mUnitsLineEdit->setText( info.units );
98 mUnitSymbolLineEdit->setText( info.unitSymbol );
99
100 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant( info.defaultDisplayType ) ) );
101 if ( info.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::ReferenceValue )
102 {
103 const int referenceValueIndex = mReferenceValueComboBox->findData( info.referenceValue );
104 if ( referenceValueIndex == -1 )
105 {
106 mReferenceValueComboBox->setEditText( info.referenceValue.toString() );
107 }
108 else
109 {
110 mReferenceValueComboBox->setCurrentIndex( referenceValueIndex );
111 }
112 }
113 else
114 {
115 mReferenceValueComboBox->setCurrentIndex( 0 );
116 }
117}
118
120{
121 // Is the name a predefined value?
122 QString name = mNameComboBox->currentText();
123 if ( mNameComboBox->findText( name ) != -1 )
124 {
125 name = name.toLower();
126 }
127
128 // Gets the reference value
129 const QString refText = mReferenceValueComboBox->currentText();
130 QVariant refValue;
131 if ( mReferenceValueComboBox->findText( refText ) != -1 )
132 {
133 refValue = mReferenceValueComboBox->currentData();
134 }
135 return QgsMapLayerServerProperties::WmsDimensionInfo( name, mFieldComboBox->currentField(), mEndFieldComboBox->currentField(), mUnitsLineEdit->text(), mUnitSymbolLineEdit->text(), mDefaultDisplayComboBox->currentData().toInt(), refValue );
136}
137
138void QgsWmsDimensionDialog::nameChanged( const QString &name )
139{
140 // reset input
141 mUnitsLabel->setEnabled( true );
142 mUnitsLineEdit->setEnabled( true );
143 mUnitsLineEdit->clear();
144 mUnitSymbolLabel->setEnabled( true );
145 mUnitSymbolLineEdit->setEnabled( true );
146 mUnitSymbolLineEdit->clear();
147 mFieldLabel->setToolTip( QString() );
148 mEndFieldLabel->setToolTip( QString() );
149 mFieldComboBox->setToolTip( QString() );
150 mEndFieldComboBox->setToolTip( QString() );
151
152 // Is the name a predefined value?
153 if ( mNameComboBox->findText( name ) != -1 )
154 {
155 const int data = mNameComboBox->currentData().toInt();
157 {
159 mFieldComboBox->setFilters( filters );
160 mEndFieldComboBox->setFilters( filters );
161 mUnitsLineEdit->setText( QStringLiteral( "ISO8601" ) );
162 mUnitsLabel->setEnabled( false );
163 mUnitsLineEdit->setEnabled( false );
164 mUnitSymbolLabel->setEnabled( false );
165 mUnitSymbolLineEdit->setEnabled( false );
166
167 const QString fieldToolTip = tr( "If a string is used, it must be formatted according to <a href=\"https://www.iso.org/iso-8601-date-and-time-format.html\">ISO8601</a>." );
168 mFieldLabel->setToolTip( fieldToolTip );
169 mEndFieldLabel->setToolTip( fieldToolTip );
170 mFieldComboBox->setToolTip( fieldToolTip );
171 mEndFieldComboBox->setToolTip( fieldToolTip );
172 }
174 {
175 mFieldComboBox->setFilters( QgsFieldProxyModel::String | QgsFieldProxyModel::Date );
176 mEndFieldComboBox->setFilters( QgsFieldProxyModel::String | QgsFieldProxyModel::Date );
177 mUnitsLineEdit->setText( QStringLiteral( "ISO8601" ) );
178 mUnitsLabel->setEnabled( false );
179 mUnitsLineEdit->setEnabled( false );
180 mUnitSymbolLabel->setEnabled( false );
181 mUnitSymbolLineEdit->setEnabled( false );
182 }
184 {
185 mFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
186 mEndFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
187 }
188 }
189 else
190 {
191 mFieldComboBox->setFilters( QgsFieldProxyModel::AllTypes );
192 mEndFieldComboBox->setFilters( QgsFieldProxyModel::AllTypes );
193 }
194
195 fieldChanged();
196}
197
198void QgsWmsDimensionDialog::fieldChanged()
199{
200 const QString currentFieldName = mFieldComboBox->currentField();
201 const int currentFieldIndexOf = mLayer->fields().indexOf( currentFieldName );
202 QSet<QVariant> uniqueValues = mLayer->uniqueValues( currentFieldIndexOf );
203
204 const QString currentEndFieldName = mEndFieldComboBox->currentField();
205 if ( !currentEndFieldName.isEmpty() )
206 {
207 const int currentEndFieldIndexOf = mLayer->fields().indexOf( currentEndFieldName );
208 uniqueValues.unite( mLayer->uniqueValues( currentEndFieldIndexOf ) );
209 }
210 QList<QVariant> values = qgis::setToList( uniqueValues );
211 std::sort( values.begin(), values.end() );
212
213 mReferenceValueComboBox->clear();
214 mReferenceValueComboBox->addItem( QString(), QVariant() ); // Empty value
215 const auto constValues = values;
216 for ( const QVariant &v : constValues )
217 {
218 mReferenceValueComboBox->addItem( v.toString(), v );
219 }
220}
221
222void QgsWmsDimensionDialog::defaultDisplayChanged( int index )
223{
224 if ( index == 3 )
225 {
226 mReferenceValueLabel->setEnabled( true );
227 mReferenceValueComboBox->setEnabled( true );
228 }
229 else
230 {
231 mReferenceValueLabel->setEnabled( false );
232 mReferenceValueComboBox->setEnabled( false );
233 }
234}
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
@ DateTime
Datetime fields.
@ LongLong
Longlong fields.
@ AllTypes
All field types.
@ Date
Date or datetime fields.
@ Int
Integer fields.
@ String
String fields.
@ Numeric
All numeric fields.
QFlags< Filter > Filters
Q_INVOKABLE int indexOf(const QString &fieldName) const
Gets the field index from the field name.
static QMap< int, QString > wmsDimensionDefaultDisplayLabels()
Returns WMS Dimension default display labels.
Represents a vector layer which manages a vector based data sets.
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
void setInfo(const QgsMapLayerServerProperties::WmsDimensionInfo &info)
QgsWmsDimensionDialog(QgsVectorLayer *layer, QStringList alreadyDefinedDimensions, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
QgsMapLayerServerProperties::WmsDimensionInfo info() const
Setting to define QGIS Server WMS Dimension.