22#include <QStandardItemModel> 
   26  : QDialog( parent, f )
 
   36  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." );
 
   37  mNameLabel->setToolTip( nameToolTip );
 
   38  mNameComboBox->setToolTip( nameToolTip );
 
   41  mFieldComboBox->setLayer( mLayer );
 
   42  mEndFieldComboBox->setLayer( mLayer );
 
   43  mEndFieldComboBox->setAllowEmptyFieldName( 
true );
 
   45  connect( buttonBox, &QDialogButtonBox::accepted, 
this, &QgsWmsDimensionDialog::accept );
 
   46  connect( buttonBox, &QDialogButtonBox::rejected, 
this, &QgsWmsDimensionDialog::reject );
 
   49  connect( mNameComboBox, &QComboBox::editTextChanged, 
this, &QgsWmsDimensionDialog::nameChanged );
 
   50  connect( mDefaultDisplayComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), 
this, &QgsWmsDimensionDialog::defaultDisplayChanged );
 
   53  const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
 
   54  for ( 
int i = 0; i < pnMetaEnum.keyCount(); i++ )
 
   56    const QString name( pnMetaEnum.key( i ) );
 
   57    if ( !alreadyDefinedDimensions.contains( name.toLower() ) )
 
   59      mNameComboBox->addItem( QStringLiteral( 
"%1%2" ).arg( !name.isEmpty() ? name.at( 0 ) : QString(), name.mid( 1 ).toLower() ), QVariant( pnMetaEnum.value( i ) ) );
 
   64  mDefaultDisplayComboBox->clear();
 
   66  for ( 
auto it = defaultDisplayLabels.constBegin(); it != defaultDisplayLabels.constEnd(); it++ )
 
   68    mDefaultDisplayComboBox->addItem( it.value(), QVariant( it.key() ) );
 
   73  mReferenceValueLabel->setEnabled( 
false );
 
   74  mReferenceValueComboBox->setEnabled( 
false );
 
   81  const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsMapLayerServerProperties::PredefinedWmsDimensionName>() );
 
   82  const int predefinedNameValue = pnMetaEnum.keyToValue( 
info.
name.toUpper().toStdString().c_str() );
 
   83  if ( predefinedNameValue == -1 )
 
   85    mNameComboBox->setEditText( 
info.
name );
 
   89    mNameComboBox->setCurrentIndex( mNameComboBox->findData( QVariant( predefinedNameValue ) ) );
 
   91  mNameComboBox->setEnabled( 
false );
 
   99  mDefaultDisplayComboBox->setCurrentIndex( mDefaultDisplayComboBox->findData( QVariant( 
info.
defaultDisplayType ) ) );
 
  102    const int referenceValueIndex = mReferenceValueComboBox->findData( 
info.
referenceValue );
 
  103    if ( referenceValueIndex == -1 )
 
  109      mReferenceValueComboBox->setCurrentIndex( referenceValueIndex );
 
  114    mReferenceValueComboBox->setCurrentIndex( 0 );
 
  121  QString name = mNameComboBox->currentText();
 
  122  if ( mNameComboBox->findText( name ) != -1 )
 
  124    name = name.toLower();
 
  128  const QString refText = mReferenceValueComboBox->currentText();
 
  130  if ( mReferenceValueComboBox->findText( refText ) != -1 )
 
  132    refValue = mReferenceValueComboBox->currentData();
 
  135         mEndFieldComboBox->currentField(),
 
  136         mUnitsLineEdit->text(), mUnitSymbolLineEdit->text(),
 
  137         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();
 
  165      mFieldComboBox->setFilters( filters );
 
  166      mEndFieldComboBox->setFilters( filters );
 
  167      mUnitsLineEdit->setText( QStringLiteral( 
"ISO8601" ) );
 
  168      mUnitsLabel->setEnabled( 
false );
 
  169      mUnitsLineEdit->setEnabled( 
false );
 
  170      mUnitSymbolLabel->setEnabled( 
false );
 
  171      mUnitSymbolLineEdit->setEnabled( 
false );
 
  173      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>." );
 
  174      mFieldLabel->setToolTip( fieldToolTip );
 
  175      mEndFieldLabel->setToolTip( fieldToolTip );
 
  176      mFieldComboBox->setToolTip( fieldToolTip );
 
  177      mEndFieldComboBox->setToolTip( fieldToolTip );
 
  183      mUnitsLineEdit->setText( QStringLiteral( 
"ISO8601" ) );
 
  184      mUnitsLabel->setEnabled( 
false );
 
  185      mUnitsLineEdit->setEnabled( 
false );
 
  186      mUnitSymbolLabel->setEnabled( 
false );
 
  187      mUnitSymbolLineEdit->setEnabled( 
false );
 
  204void QgsWmsDimensionDialog::fieldChanged()
 
  206  const QString currentFieldName = mFieldComboBox->currentField();
 
  207  const int currentFieldIndexOf = mLayer->
fields().
indexOf( currentFieldName );
 
  208  QSet<QVariant> uniqueValues = mLayer->
uniqueValues( currentFieldIndexOf );
 
  210  const QString currentEndFieldName = mEndFieldComboBox->currentField();
 
  211  if ( !currentEndFieldName.isEmpty() )
 
  213    const int currentEndFieldIndexOf = mLayer->
fields().
indexOf( currentEndFieldName );
 
  214    uniqueValues.unite( mLayer->
uniqueValues( currentEndFieldIndexOf ) );
 
  216  QList<QVariant> values = qgis::setToList( uniqueValues );
 
  217  std::sort( values.begin(), values.end() );
 
  219  mReferenceValueComboBox->clear();
 
  220  mReferenceValueComboBox->addItem( QString(), QVariant() ); 
 
  221  const auto constValues = values;
 
  222  for ( 
const QVariant &v : constValues )
 
  224    mReferenceValueComboBox->addItem( v.toString(), v );
 
  228void QgsWmsDimensionDialog::defaultDisplayChanged( 
int index )
 
  232    mReferenceValueLabel->setEnabled( 
true );
 
  233    mReferenceValueComboBox->setEnabled( 
true );
 
  237    mReferenceValueLabel->setEnabled( 
false );
 
  238    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.