24#include <QStandardItemModel>
26#include "moc_qgswmsdimensiondialog.cpp"
29 : QDialog( parent, f )
39 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." );
40 mNameLabel->setToolTip( nameToolTip );
41 mNameComboBox->setToolTip( nameToolTip );
44 mFieldComboBox->setLayer( mLayer );
45 mEndFieldComboBox->setLayer( mLayer );
46 mEndFieldComboBox->setAllowEmptyFieldName(
true );
48 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsWmsDimensionDialog::accept );
49 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QgsWmsDimensionDialog::reject );
52 connect( mNameComboBox, &QComboBox::editTextChanged,
this, &QgsWmsDimensionDialog::nameChanged );
53 connect( mDefaultDisplayComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsWmsDimensionDialog::defaultDisplayChanged );
56 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
57 for (
int i = 0; i < pnMetaEnum.keyCount(); i++ )
59 const QString name( pnMetaEnum.key( i ) );
60 if ( !alreadyDefinedDimensions.contains( name.toLower() ) )
62 mNameComboBox->addItem( QStringLiteral(
"%1%2" ).arg( !name.isEmpty() ? name.at( 0 ) : QString(), name.mid( 1 ).toLower() ), QVariant( pnMetaEnum.value( i ) ) );
67 mDefaultDisplayComboBox->clear();
69 for (
auto it = defaultDisplayLabels.constBegin(); it != defaultDisplayLabels.constEnd(); it++ )
71 mDefaultDisplayComboBox->addItem( it.value(), QVariant( it.key() ) );
74 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant( QgsMapLayerServerProperties::WmsDimensionInfo::AllValues ) ) );
76 mReferenceValueLabel->setEnabled(
false );
77 mReferenceValueComboBox->setEnabled(
false );
84 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
85 const int predefinedNameValue = pnMetaEnum.keyToValue(
info.name.toUpper().toStdString().c_str() );
86 if ( predefinedNameValue == -1 )
88 mNameComboBox->setEditText(
info.name );
92 mNameComboBox->setCurrentIndex( mNameComboBox->findData( QVariant( predefinedNameValue ) ) );
94 mNameComboBox->setEnabled(
false );
96 mFieldComboBox->setField(
info.fieldName );
97 mEndFieldComboBox->setField(
info.endFieldName );
99 mUnitsLineEdit->setText(
info.units );
100 mUnitSymbolLineEdit->setText(
info.unitSymbol );
102 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant(
info.defaultDisplayType ) ) );
103 if (
info.defaultDisplayType == QgsMapLayerServerProperties::WmsDimensionInfo::ReferenceValue )
105 const int referenceValueIndex = mReferenceValueComboBox->findData(
info.referenceValue );
106 if ( referenceValueIndex == -1 )
108 mReferenceValueComboBox->setEditText(
info.referenceValue.toString() );
112 mReferenceValueComboBox->setCurrentIndex( referenceValueIndex );
117 mReferenceValueComboBox->setCurrentIndex( 0 );
124 QString name = mNameComboBox->currentText();
125 if ( mNameComboBox->findText( name ) != -1 )
127 name = name.toLower();
131 const QString refText = mReferenceValueComboBox->currentText();
133 if ( mReferenceValueComboBox->findText( refText ) != -1 )
135 refValue = mReferenceValueComboBox->currentData();
137 return QgsMapLayerServerProperties::WmsDimensionInfo( name, mFieldComboBox->currentField(), mEndFieldComboBox->currentField(), mUnitsLineEdit->text(), mUnitSymbolLineEdit->text(), mDefaultDisplayComboBox->currentData().toInt(), refValue );
140void QgsWmsDimensionDialog::nameChanged(
const QString &name )
143 mUnitsLabel->setEnabled(
true );
144 mUnitsLineEdit->setEnabled(
true );
145 mUnitsLineEdit->clear();
146 mUnitSymbolLabel->setEnabled(
true );
147 mUnitSymbolLineEdit->setEnabled(
true );
148 mUnitSymbolLineEdit->clear();
149 mFieldLabel->setToolTip( QString() );
150 mEndFieldLabel->setToolTip( QString() );
151 mFieldComboBox->setToolTip( QString() );
152 mEndFieldComboBox->setToolTip( QString() );
155 if ( mNameComboBox->findText( name ) != -1 )
157 const int data = mNameComboBox->currentData().toInt();
161 mFieldComboBox->setFilters( filters );
162 mEndFieldComboBox->setFilters( filters );
163 mUnitsLineEdit->setText( QStringLiteral(
"ISO8601" ) );
164 mUnitsLabel->setEnabled(
false );
165 mUnitsLineEdit->setEnabled(
false );
166 mUnitSymbolLabel->setEnabled(
false );
167 mUnitSymbolLineEdit->setEnabled(
false );
169 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>." );
170 mFieldLabel->setToolTip( fieldToolTip );
171 mEndFieldLabel->setToolTip( fieldToolTip );
172 mFieldComboBox->setToolTip( fieldToolTip );
173 mEndFieldComboBox->setToolTip( fieldToolTip );
179 mUnitsLineEdit->setText( QStringLiteral(
"ISO8601" ) );
180 mUnitsLabel->setEnabled(
false );
181 mUnitsLineEdit->setEnabled(
false );
182 mUnitSymbolLabel->setEnabled(
false );
183 mUnitSymbolLineEdit->setEnabled(
false );
200void QgsWmsDimensionDialog::fieldChanged()
202 const QString currentFieldName = mFieldComboBox->currentField();
203 const int currentFieldIndexOf = mLayer->fields().indexOf( currentFieldName );
204 QSet<QVariant> uniqueValues = mLayer->uniqueValues( currentFieldIndexOf );
206 const QString currentEndFieldName = mEndFieldComboBox->currentField();
207 if ( !currentEndFieldName.isEmpty() )
209 const int currentEndFieldIndexOf = mLayer->fields().indexOf( currentEndFieldName );
210 uniqueValues.unite( mLayer->uniqueValues( currentEndFieldIndexOf ) );
212 QList<QVariant> values = qgis::setToList( uniqueValues );
213 std::sort( values.begin(), values.end() );
215 mReferenceValueComboBox->clear();
216 mReferenceValueComboBox->addItem( QString(), QVariant() );
217 const auto constValues = values;
218 for (
const QVariant &v : constValues )
220 mReferenceValueComboBox->addItem( v.toString(), v );
224void QgsWmsDimensionDialog::defaultDisplayChanged(
int index )
228 mReferenceValueLabel->setEnabled(
true );
229 mReferenceValueComboBox->setEnabled(
true );
233 mReferenceValueLabel->setEnabled(
false );
234 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.