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();
135 return QgsMapLayerServerProperties::WmsDimensionInfo( name, mFieldComboBox->currentField(), mEndFieldComboBox->currentField(), mUnitsLineEdit->text(), mUnitSymbolLineEdit->text(), mDefaultDisplayComboBox->currentData().toInt(), refValue );
138void QgsWmsDimensionDialog::nameChanged(
const QString &name )
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() );
153 if ( mNameComboBox->findText( name ) != -1 )
155 const int data = mNameComboBox->currentData().toInt();
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 );
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 );
177 mUnitsLineEdit->setText( QStringLiteral(
"ISO8601" ) );
178 mUnitsLabel->setEnabled(
false );
179 mUnitsLineEdit->setEnabled(
false );
180 mUnitSymbolLabel->setEnabled(
false );
181 mUnitSymbolLineEdit->setEnabled(
false );
198void QgsWmsDimensionDialog::fieldChanged()
200 const QString currentFieldName = mFieldComboBox->currentField();
201 const int currentFieldIndexOf = mLayer->
fields().
indexOf( currentFieldName );
202 QSet<QVariant> uniqueValues = mLayer->
uniqueValues( currentFieldIndexOf );
204 const QString currentEndFieldName = mEndFieldComboBox->currentField();
205 if ( !currentEndFieldName.isEmpty() )
207 const int currentEndFieldIndexOf = mLayer->
fields().
indexOf( currentEndFieldName );
208 uniqueValues.unite( mLayer->
uniqueValues( currentEndFieldIndexOf ) );
210 QList<QVariant> values = qgis::setToList( uniqueValues );
211 std::sort( values.begin(), values.end() );
213 mReferenceValueComboBox->clear();
214 mReferenceValueComboBox->addItem( QString(), QVariant() );
215 const auto constValues = values;
216 for (
const QVariant &v : constValues )
218 mReferenceValueComboBox->addItem( v.toString(), v );
222void QgsWmsDimensionDialog::defaultDisplayChanged(
int index )
226 mReferenceValueLabel->setEnabled(
true );
227 mReferenceValueComboBox->setEnabled(
true );
231 mReferenceValueLabel->setEnabled(
false );
232 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.