22 #include <QStandardItemModel>
23 #include <QPushButton>
26 : QDialog( parent, f )
37 mFieldComboBox->setLayer( mLayer );
38 mEndFieldComboBox->setLayer( mLayer );
39 mEndFieldComboBox->setAllowEmptyFieldName(
true );
41 connect( buttonBox, &QDialogButtonBox::accepted,
this, &QgsWmsDimensionDialog::accept );
42 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QgsWmsDimensionDialog::reject );
45 connect( mNameComboBox, &QComboBox::editTextChanged,
this, &QgsWmsDimensionDialog::nameChanged );
46 connect( mDefaultDisplayComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsWmsDimensionDialog::defaultDisplayChanged );
49 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
50 for (
int i = 0; i < pnMetaEnum.keyCount(); i++ )
52 const QString name( pnMetaEnum.key( i ) );
53 if ( !alreadyDefinedDimensions.contains( name.toLower() ) )
55 mNameComboBox->addItem( QStringLiteral(
"%1%2" ).arg( !name.isEmpty() ? name.at( 0 ) : QString(), name.mid( 1 ).toLower() ), QVariant( pnMetaEnum.value( i ) ) );
60 mDefaultDisplayComboBox->clear();
62 for (
const int &k : defaultDisplayLabels.keys() )
64 mDefaultDisplayComboBox->addItem( defaultDisplayLabels[k], QVariant( k ) );
69 mReferenceValueLabel->setEnabled(
false );
70 mReferenceValueComboBox->setEnabled(
false );
75 const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
76 const int predefinedNameValue = pnMetaEnum.keyToValue(
info.
name.toUpper().toStdString().c_str() );
77 if ( predefinedNameValue == -1 )
79 mNameComboBox->setEditText(
info.
name );
83 mNameComboBox->setCurrentIndex( mNameComboBox->findData( QVariant( predefinedNameValue ) ) );
85 mNameComboBox->setEnabled(
false );
93 mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant(
info.
defaultDisplayType ) ) );
96 const int referenceValueIndex = mReferenceValueComboBox->findData(
info.
referenceValue );
97 if ( referenceValueIndex == -1 )
103 mReferenceValueComboBox->setCurrentIndex( referenceValueIndex );
108 mReferenceValueComboBox->setCurrentIndex( 0 );
115 QString name = mNameComboBox->currentText();
116 if ( mNameComboBox->findText( name ) != -1 )
118 name = name.toLower();
122 const QString refText = mReferenceValueComboBox->currentText();
124 if ( mReferenceValueComboBox->findText( refText ) != -1 )
126 refValue = mReferenceValueComboBox->currentData();
129 mEndFieldComboBox->currentField(),
130 mUnitsLineEdit->text(), mUnitSymbolLineEdit->text(),
131 mDefaultDisplayComboBox->currentData().toInt(), refValue );
134 void QgsWmsDimensionDialog::nameChanged(
const QString &name )
137 mUnitsLabel->setEnabled(
true );
138 mUnitsLineEdit->setEnabled(
true );
139 mUnitsLineEdit->clear();
140 mUnitSymbolLabel->setEnabled(
true );
141 mUnitSymbolLineEdit->setEnabled(
true );
142 mUnitSymbolLineEdit->clear();
145 if ( mNameComboBox->findText( name ) != -1 )
147 const int data = mNameComboBox->currentData().toInt();
155 mFieldComboBox->setFilters( filters );
156 mEndFieldComboBox->setFilters( filters );
157 mUnitsLineEdit->setText( QStringLiteral(
"ISO8601" ) );
158 mUnitsLabel->setEnabled(
false );
159 mUnitsLineEdit->setEnabled(
false );
160 mUnitSymbolLabel->setEnabled(
false );
161 mUnitSymbolLineEdit->setEnabled(
false );
167 mUnitsLineEdit->setText( QStringLiteral(
"ISO8601" ) );
168 mUnitsLabel->setEnabled(
false );
169 mUnitsLineEdit->setEnabled(
false );
170 mUnitSymbolLabel->setEnabled(
false );
171 mUnitSymbolLineEdit->setEnabled(
false );
188 void QgsWmsDimensionDialog::fieldChanged()
190 const QString currentFieldName = mFieldComboBox->currentField();
191 const int currentFieldIndexOf = mLayer->
fields().
indexOf( currentFieldName );
192 QSet<QVariant> uniqueValues = mLayer->
uniqueValues( currentFieldIndexOf );
194 const QString currentEndFieldName = mEndFieldComboBox->currentField();
195 if ( !currentEndFieldName.isEmpty() )
197 const int currentEndFieldIndexOf = mLayer->
fields().
indexOf( currentEndFieldName );
198 uniqueValues.unite( mLayer->
uniqueValues( currentEndFieldIndexOf ) );
200 QList<QVariant> values = qgis::setToList( uniqueValues );
201 std::sort( values.begin(), values.end() );
203 mReferenceValueComboBox->clear();
204 mReferenceValueComboBox->addItem( QString(), QVariant() );
205 const auto constValues = values;
206 for (
const QVariant &v : constValues )
208 mReferenceValueComboBox->addItem( v.toString(), v );
212 void QgsWmsDimensionDialog::defaultDisplayChanged(
int index )
216 mReferenceValueLabel->setEnabled(
true );
217 mReferenceValueComboBox->setEnabled(
true );
221 mReferenceValueLabel->setEnabled(
false );
222 mReferenceValueComboBox->setEnabled(
false );
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
@ DateTime
Datetime fieldss.
@ LongLong
Longlong fields.
@ AllTypes
All field types.
@ Date
Date or datetime fields.
@ Numeric
All numeric fields.
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.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
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.
@ AllValues
Display all values of the dimension.
@ ReferenceValue
Remove from current selection.