QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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(),
136 mEndFieldComboBox->currentField(),
137 mUnitsLineEdit->text(), mUnitSymbolLineEdit->text(),
138 mDefaultDisplayComboBox->currentData().toInt(), refValue );
139}
140
141void QgsWmsDimensionDialog::nameChanged( const QString &name )
142{
143 // reset input
144 mUnitsLabel->setEnabled( true );
145 mUnitsLineEdit->setEnabled( true );
146 mUnitsLineEdit->clear();
147 mUnitSymbolLabel->setEnabled( true );
148 mUnitSymbolLineEdit->setEnabled( true );
149 mUnitSymbolLineEdit->clear();
150 mFieldLabel->setToolTip( QString() );
151 mEndFieldLabel->setToolTip( QString() );
152 mFieldComboBox->setToolTip( QString() );
153 mEndFieldComboBox->setToolTip( QString() );
154
155 // Is the name a predefined value?
156 if ( mNameComboBox->findText( name ) != -1 )
157 {
158 const int data = mNameComboBox->currentData().toInt();
160 {
166 mFieldComboBox->setFilters( filters );
167 mEndFieldComboBox->setFilters( filters );
168 mUnitsLineEdit->setText( QStringLiteral( "ISO8601" ) );
169 mUnitsLabel->setEnabled( false );
170 mUnitsLineEdit->setEnabled( false );
171 mUnitSymbolLabel->setEnabled( false );
172 mUnitSymbolLineEdit->setEnabled( false );
173
174 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>." );
175 mFieldLabel->setToolTip( fieldToolTip );
176 mEndFieldLabel->setToolTip( fieldToolTip );
177 mFieldComboBox->setToolTip( fieldToolTip );
178 mEndFieldComboBox->setToolTip( fieldToolTip );
179 }
181 {
182 mFieldComboBox->setFilters( QgsFieldProxyModel::String | QgsFieldProxyModel::Date );
183 mEndFieldComboBox->setFilters( QgsFieldProxyModel::String | QgsFieldProxyModel::Date );
184 mUnitsLineEdit->setText( QStringLiteral( "ISO8601" ) );
185 mUnitsLabel->setEnabled( false );
186 mUnitsLineEdit->setEnabled( false );
187 mUnitSymbolLabel->setEnabled( false );
188 mUnitSymbolLineEdit->setEnabled( false );
189 }
191 {
192 mFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
193 mEndFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
194 }
195 }
196 else
197 {
198 mFieldComboBox->setFilters( QgsFieldProxyModel::AllTypes );
199 mEndFieldComboBox->setFilters( QgsFieldProxyModel::AllTypes );
200 }
201
202 fieldChanged();
203}
204
205void QgsWmsDimensionDialog::fieldChanged()
206{
207 const QString currentFieldName = mFieldComboBox->currentField();
208 const int currentFieldIndexOf = mLayer->fields().indexOf( currentFieldName );
209 QSet<QVariant> uniqueValues = mLayer->uniqueValues( currentFieldIndexOf );
210
211 const QString currentEndFieldName = mEndFieldComboBox->currentField();
212 if ( !currentEndFieldName.isEmpty() )
213 {
214 const int currentEndFieldIndexOf = mLayer->fields().indexOf( currentEndFieldName );
215 uniqueValues.unite( mLayer->uniqueValues( currentEndFieldIndexOf ) );
216 }
217 QList<QVariant> values = qgis::setToList( uniqueValues );
218 std::sort( values.begin(), values.end() );
219
220 mReferenceValueComboBox->clear();
221 mReferenceValueComboBox->addItem( QString(), QVariant() ); // Empty value
222 const auto constValues = values;
223 for ( const QVariant &v : constValues )
224 {
225 mReferenceValueComboBox->addItem( v.toString(), v );
226 }
227}
228
229void QgsWmsDimensionDialog::defaultDisplayChanged( int index )
230{
231 if ( index == 3 )
232 {
233 mReferenceValueLabel->setEnabled( true );
234 mReferenceValueComboBox->setEnabled( true );
235 }
236 else
237 {
238 mReferenceValueLabel->setEnabled( false );
239 mReferenceValueComboBox->setEnabled( false );
240 }
241}
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.