19#include "moc_qgswmsdimensiondialog.cpp"
23#include <QStandardItemModel>
27 : QDialog( parent, f )
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 );
42 mFieldComboBox->setLayer( mLayer );
43 mEndFieldComboBox->setLayer( mLayer );
44 mEndFieldComboBox->setAllowEmptyFieldName(
true );
46 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsWmsDimensionDialog::accept );
47 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QgsWmsDimensionDialog::reject );
50 connect( mNameComboBox, &QComboBox::editTextChanged,
this, &QgsWmsDimensionDialog::nameChanged );
51 connect( mDefaultDisplayComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsWmsDimensionDialog::defaultDisplayChanged );
54 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
55 for (
int i = 0; i < pnMetaEnum.keyCount(); i++ )
57 const QString name( pnMetaEnum.key( i ) );
58 if ( !alreadyDefinedDimensions.contains( name.toLower() ) )
60 mNameComboBox->addItem( QStringLiteral(
"%1%2" ).arg( !name.isEmpty() ? name.at( 0 ) : QString(), name.mid( 1 ).toLower() ), QVariant( pnMetaEnum.value( i ) ) );
65 mDefaultDisplayComboBox->clear();
67 for (
auto it = defaultDisplayLabels.constBegin(); it != defaultDisplayLabels.constEnd(); it++ )
69 mDefaultDisplayComboBox->addItem( it.value(), QVariant( it.key() ) );
72 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant( QgsMapLayerServerProperties::WmsDimensionInfo::AllValues ) ) );
74 mReferenceValueLabel->setEnabled(
false );
75 mReferenceValueComboBox->setEnabled(
false );
82 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
83 const int predefinedNameValue = pnMetaEnum.keyToValue(
info.
name.toUpper().toStdString().c_str() );
84 if ( predefinedNameValue == -1 )
86 mNameComboBox->setEditText(
info.
name );
90 mNameComboBox->setCurrentIndex( mNameComboBox->findData( QVariant( predefinedNameValue ) ) );
92 mNameComboBox->setEnabled(
false );
100 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant(
info.
defaultDisplayType ) ) );
103 const int referenceValueIndex = mReferenceValueComboBox->findData(
info.
referenceValue );
104 if ( referenceValueIndex == -1 )
110 mReferenceValueComboBox->setCurrentIndex( referenceValueIndex );
115 mReferenceValueComboBox->setCurrentIndex( 0 );
122 QString name = mNameComboBox->currentText();
123 if ( mNameComboBox->findText( name ) != -1 )
125 name = name.toLower();
129 const QString refText = mReferenceValueComboBox->currentText();
131 if ( mReferenceValueComboBox->findText( refText ) != -1 )
133 refValue = mReferenceValueComboBox->currentData();
136 mEndFieldComboBox->currentField(),
137 mUnitsLineEdit->text(), mUnitSymbolLineEdit->text(),
138 mDefaultDisplayComboBox->currentData().toInt(), refValue );
141void QgsWmsDimensionDialog::nameChanged(
const QString &name )
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() );
156 if ( mNameComboBox->findText( name ) != -1 )
158 const int data = mNameComboBox->currentData().toInt();
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 );
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 );
184 mUnitsLineEdit->setText( QStringLiteral(
"ISO8601" ) );
185 mUnitsLabel->setEnabled(
false );
186 mUnitsLineEdit->setEnabled(
false );
187 mUnitSymbolLabel->setEnabled(
false );
188 mUnitSymbolLineEdit->setEnabled(
false );
205void QgsWmsDimensionDialog::fieldChanged()
207 const QString currentFieldName = mFieldComboBox->currentField();
208 const int currentFieldIndexOf = mLayer->
fields().
indexOf( currentFieldName );
209 QSet<QVariant> uniqueValues = mLayer->
uniqueValues( currentFieldIndexOf );
211 const QString currentEndFieldName = mEndFieldComboBox->currentField();
212 if ( !currentEndFieldName.isEmpty() )
214 const int currentEndFieldIndexOf = mLayer->
fields().
indexOf( currentEndFieldName );
215 uniqueValues.unite( mLayer->
uniqueValues( currentEndFieldIndexOf ) );
217 QList<QVariant> values = qgis::setToList( uniqueValues );
218 std::sort( values.begin(), values.end() );
220 mReferenceValueComboBox->clear();
221 mReferenceValueComboBox->addItem( QString(), QVariant() );
222 const auto constValues = values;
223 for (
const QVariant &v : constValues )
225 mReferenceValueComboBox->addItem( v.toString(), v );
229void QgsWmsDimensionDialog::defaultDisplayChanged(
int index )
233 mReferenceValueLabel->setEnabled(
true );
234 mReferenceValueComboBox->setEnabled(
true );
238 mReferenceValueLabel->setEnabled(
false );
239 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.
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.