24#include <QStandardItemModel>
27#include "moc_qgswmsdimensiondialog.cpp"
29using namespace Qt::StringLiterals;
32 : QDialog( parent, f )
42 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." );
43 mNameLabel->setToolTip( nameToolTip );
44 mNameComboBox->setToolTip( nameToolTip );
47 mFieldComboBox->setLayer( mLayer );
48 mEndFieldComboBox->setLayer( mLayer );
49 mEndFieldComboBox->setAllowEmptyFieldName(
true );
51 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsWmsDimensionDialog::accept );
52 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QgsWmsDimensionDialog::reject );
55 connect( mNameComboBox, &QComboBox::editTextChanged,
this, &QgsWmsDimensionDialog::nameChanged );
56 connect( mDefaultDisplayComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsWmsDimensionDialog::defaultDisplayChanged );
59 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
60 for (
int i = 0; i < pnMetaEnum.keyCount(); i++ )
62 const QString name( pnMetaEnum.key( i ) );
63 if ( !alreadyDefinedDimensions.contains( name.toLower() ) )
65 mNameComboBox->addItem( u
"%1%2"_s.arg( !name.isEmpty() ? name.at( 0 ) : QString(), name.mid( 1 ).toLower() ), QVariant( pnMetaEnum.value( i ) ) );
70 mDefaultDisplayComboBox->clear();
72 for (
auto it = defaultDisplayLabels.constBegin(); it != defaultDisplayLabels.constEnd(); it++ )
74 mDefaultDisplayComboBox->addItem( it.value(), QVariant( it.key() ) );
77 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant( QgsMapLayerServerProperties::WmsDimensionInfo::AllValues ) ) );
79 mReferenceValueLabel->setEnabled(
false );
80 mReferenceValueComboBox->setEnabled(
false );
87 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
88 const int predefinedNameValue = pnMetaEnum.keyToValue(
info.name.toUpper().toStdString().c_str() );
89 if ( predefinedNameValue == -1 )
91 mNameComboBox->setEditText(
info.name );
95 mNameComboBox->setCurrentIndex( mNameComboBox->findData( QVariant( predefinedNameValue ) ) );
97 mNameComboBox->setEnabled(
false );
99 mFieldComboBox->setField(
info.fieldName );
100 mEndFieldComboBox->setField(
info.endFieldName );
102 mUnitsLineEdit->setText(
info.units );
103 mUnitSymbolLineEdit->setText(
info.unitSymbol );
105 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant(
info.defaultDisplayType ) ) );
106 if (
info.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::ReferenceValue )
108 const int referenceValueIndex = mReferenceValueComboBox->findData(
info.referenceValue );
109 if ( referenceValueIndex == -1 )
111 mReferenceValueComboBox->setEditText(
info.referenceValue.toString() );
115 mReferenceValueComboBox->setCurrentIndex( referenceValueIndex );
120 mReferenceValueComboBox->setCurrentIndex( 0 );
127 QString name = mNameComboBox->currentText();
128 if ( mNameComboBox->findText( name ) != -1 )
130 name = name.toLower();
134 const QString refText = mReferenceValueComboBox->currentText();
136 if ( mReferenceValueComboBox->findText( refText ) != -1 )
138 refValue = mReferenceValueComboBox->currentData();
140 return QgsMapLayerServerProperties::WmsDimensionInfo( name, mFieldComboBox->currentField(), mEndFieldComboBox->currentField(), mUnitsLineEdit->text(), mUnitSymbolLineEdit->text(), mDefaultDisplayComboBox->currentData().toInt(), refValue );
143void QgsWmsDimensionDialog::nameChanged(
const QString &name )
146 mUnitsLabel->setEnabled(
true );
147 mUnitsLineEdit->setEnabled(
true );
148 mUnitsLineEdit->clear();
149 mUnitSymbolLabel->setEnabled(
true );
150 mUnitSymbolLineEdit->setEnabled(
true );
151 mUnitSymbolLineEdit->clear();
152 mFieldLabel->setToolTip( QString() );
153 mEndFieldLabel->setToolTip( QString() );
154 mFieldComboBox->setToolTip( QString() );
155 mEndFieldComboBox->setToolTip( QString() );
158 if ( mNameComboBox->findText( name ) != -1 )
160 const int data = mNameComboBox->currentData().toInt();
164 mFieldComboBox->setFilters( filters );
165 mEndFieldComboBox->setFilters( filters );
166 mUnitsLineEdit->setText( u
"ISO8601"_s );
167 mUnitsLabel->setEnabled(
false );
168 mUnitsLineEdit->setEnabled(
false );
169 mUnitSymbolLabel->setEnabled(
false );
170 mUnitSymbolLineEdit->setEnabled(
false );
172 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>." );
173 mFieldLabel->setToolTip( fieldToolTip );
174 mEndFieldLabel->setToolTip( fieldToolTip );
175 mFieldComboBox->setToolTip( fieldToolTip );
176 mEndFieldComboBox->setToolTip( fieldToolTip );
182 mUnitsLineEdit->setText( u
"ISO8601"_s );
183 mUnitsLabel->setEnabled(
false );
184 mUnitsLineEdit->setEnabled(
false );
185 mUnitSymbolLabel->setEnabled(
false );
186 mUnitSymbolLineEdit->setEnabled(
false );
203void QgsWmsDimensionDialog::fieldChanged()
205 const QString currentFieldName = mFieldComboBox->currentField();
206 const int currentFieldIndexOf = mLayer->fields().indexOf( currentFieldName );
207 QSet<QVariant> uniqueValues = mLayer->uniqueValues( currentFieldIndexOf );
209 const QString currentEndFieldName = mEndFieldComboBox->currentField();
210 if ( !currentEndFieldName.isEmpty() )
212 const int currentEndFieldIndexOf = mLayer->fields().indexOf( currentEndFieldName );
213 uniqueValues.unite( mLayer->uniqueValues( currentEndFieldIndexOf ) );
215 QList<QVariant> values = qgis::setToList( uniqueValues );
216 std::sort( values.begin(), values.end() );
218 mReferenceValueComboBox->clear();
219 mReferenceValueComboBox->addItem( QString(), QVariant() );
220 const auto constValues = values;
221 for (
const QVariant &v : constValues )
223 mReferenceValueComboBox->addItem( v.toString(), v );
227void QgsWmsDimensionDialog::defaultDisplayChanged(
int index )
231 mReferenceValueLabel->setEnabled(
true );
232 mReferenceValueComboBox->setEnabled(
true );
236 mReferenceValueLabel->setEnabled(
false );
237 mReferenceValueComboBox->setEnabled(
false );
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.
@ Numeric
All numeric fields.
static QMap< int, QString > wmsDimensionDefaultDisplayLabels()
Returns WMS Dimension default display labels.
Represents a vector layer which manages a vector based dataset.
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.