28 #include <QToolButton>
29 #include <QVBoxLayout>
37 QHBoxLayout *hl =
new QHBoxLayout();
38 hl->setContentsMargins( 0, 0, 0, 0 );
40 mLineEdit =
new QLineEdit();
41 mLineEdit->setEnabled(
false );
42 hl->addWidget( mLineEdit, 1 );
44 mToolButton =
new QToolButton();
45 mToolButton->setText( QString( QChar( 0x2026 ) ) );
46 hl->addWidget( mToolButton );
50 mLineEdit->setText( tr(
"%1 dataset groups selected" ).arg( 0 ) );
52 mToolButton->setPopupMode( QToolButton::InstantPopup );
53 QMenu *toolButtonMenu =
new QMenu(
this );
54 mActionCurrentActiveDatasetGroups = toolButtonMenu->addAction( tr(
"Current Active Dataset Group" ) );
55 connect( mActionCurrentActiveDatasetGroups,
56 &QAction::triggered,
this, &QgsProcessingMeshDatasetGroupsWidget::selectCurrentActiveDatasetGroup );
58 mActionAvailableDatasetGroups = toolButtonMenu->addAction( tr(
"Select in Available Dataset Groups" ) );
59 connect( mActionAvailableDatasetGroups, &QAction::triggered,
this, &QgsProcessingMeshDatasetGroupsWidget::showDialog );
61 mToolButton->setMenu( toolButtonMenu );
64 void QgsProcessingMeshDatasetGroupsWidget::setMeshLayer(
QgsMeshLayer *layer,
bool layerFromProject )
66 mActionCurrentActiveDatasetGroups->setEnabled( layer && layerFromProject );
67 mActionAvailableDatasetGroups->setEnabled( layer );
69 if ( mMeshLayer == layer )
72 mDatasetGroupsNames.clear();
74 if ( layerFromProject )
82 for (
int i : datasetGroupsIndexes )
85 if ( mParam->isDataTypeSupported( meta.
dataType() ) )
87 mDatasetGroupsNames[i] = meta.
name();
97 void QgsProcessingMeshDatasetGroupsWidget::setValue(
const QVariant &value )
99 if ( value.isValid() )
100 mValue = value.type() == QVariant::List ? value.toList() : QVariantList() << value;
108 QVariant QgsProcessingMeshDatasetGroupsWidget::value()
const
113 void QgsProcessingMeshDatasetGroupsWidget::showDialog()
115 QList<int> datasetGroupsIndexes;
117 QVariantList availableOptions;
120 datasetGroupsIndexes = mMeshLayer->datasetGroupsIndexes();
121 for (
int i : datasetGroupsIndexes )
124 if ( mParam->isDataTypeSupported( meta.
dataType() ) )
126 availableOptions.append( i );
127 options.append( meta.
name() );
134 for (
int i : mDatasetGroupsNames.keys() )
136 availableOptions.append( i );
137 options.append( mDatasetGroupsNames.value( i ) );
144 QgsProcessingMultipleSelectionPanelWidget *widget =
new QgsProcessingMultipleSelectionPanelWidget( availableOptions, mValue );
145 widget->setPanelTitle( tr(
"Dataset Groups Available" ) );
147 widget->setValueFormatter( [availableOptions, options](
const QVariant & v ) -> QString
149 const int index = v.toInt();
150 const int pos = availableOptions.indexOf( index );
151 return ( pos >= 0 && pos < options.size() ) ? options.at( pos ) : QString();
154 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
156 setValue( widget->selectedOptions() );
163 QgsProcessingMultipleSelectionDialog dlg( availableOptions, mValue,
this, Qt::WindowFlags() );
165 dlg.setValueFormatter( [datasetGroupsIndexes, options](
const QVariant & v ) -> QString
167 const int index = v.toInt();
168 const int pos = datasetGroupsIndexes.indexOf( index );
169 return ( pos >= 0 && pos < options.size() ) ? options.at( pos ) : QString();
173 setValue( dlg.selectedOptions() );
178 void QgsProcessingMeshDatasetGroupsWidget::selectCurrentActiveDatasetGroup()
180 QVariantList options;
181 if ( mMeshLayer && mParam )
183 int scalarDatasetGroup = mMeshLayer->rendererSettings().activeScalarDatasetGroup();
184 int vectorDatasetGroup = mMeshLayer->rendererSettings().activeVectorDatasetGroup();
186 if ( scalarDatasetGroup >= 0 && mParam->isDataTypeSupported( mMeshLayer->datasetGroupMetadata( scalarDatasetGroup ).dataType() ) )
187 options.append( scalarDatasetGroup );
189 if ( vectorDatasetGroup >= 0
190 && mParam->isDataTypeSupported( mMeshLayer->datasetGroupMetadata( vectorDatasetGroup ).dataType() )
191 && vectorDatasetGroup != scalarDatasetGroup )
192 options.append( vectorDatasetGroup );
202 QString QgsProcessingMeshDatasetGroupsWidgetWrapper::parameterType()
const
209 return new QgsProcessingMeshDatasetGroupsWidgetWrapper( parameter, type );
212 void QgsProcessingMeshDatasetGroupsWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
224 setMeshLayerWrapperValue( wrapper );
227 setMeshLayerWrapperValue( wrapper );
247 if ( mProcessingContextGenerator )
248 context = mProcessingContextGenerator->processingContext();
250 bool layerFromProject;
256 layerFromProject =
false;
265 mWidget->setMeshLayer( meshLayer, layerFromProject );
268 QWidget *QgsProcessingMeshDatasetGroupsWidgetWrapper::createWidget()
SIP_FACTORY
271 connect( mWidget, &QgsProcessingMeshDatasetGroupsWidget::changed,
this, [ = ]
273 emit widgetValueHasChanged(
this );
279 void QgsProcessingMeshDatasetGroupsWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
283 mWidget->setValue( value );
286 QVariant QgsProcessingMeshDatasetGroupsWidgetWrapper::widgetValue()
const
289 return mWidget->value();
294 void QgsProcessingMeshDatasetGroupsWidget::updateSummaryText()
296 mLineEdit->setText( tr(
"%1 options selected" ).arg( mValue.count() ) );
307 QString QgsProcessingMeshDatasetTimeWidgetWrapper::parameterType()
const
314 return new QgsProcessingMeshDatasetTimeWidgetWrapper( parameter, type );
317 void QgsProcessingMeshDatasetTimeWidgetWrapper::postInitialize(
const QList<QgsAbstractProcessingParameterWidgetWrapper *> &wrappers )
330 layerParameterWrapper = wrapper;
333 datasetGroupsParameterWrapper = wrapper;
335 setMeshLayerWrapperValue( layerParameterWrapper );
336 setDatasetGroupIndexesWrapperValue( datasetGroupsParameterWrapper );
339 setMeshLayerWrapperValue( layerParameterWrapper );
340 setDatasetGroupIndexesWrapperValue( datasetGroupsParameterWrapper );
358 if ( mProcessingContextGenerator )
359 context = mProcessingContextGenerator->processingContext();
361 bool layerFromProject;
367 layerFromProject =
false;
375 mWidget->setMeshLayer( meshLayer, layerFromProject );
385 if ( !datasetGroupsVariant.isValid() || datasetGroupsVariant.type() != QVariant::List )
386 mWidget->setDatasetGroupIndexes( QList<int>() );
388 QVariantList datasetGroupsListVariant = datasetGroupsVariant.toList();
390 QList<int> datasetGroupsIndexes;
391 for (
const QVariant &variantIndex : datasetGroupsListVariant )
392 datasetGroupsIndexes << variantIndex.toInt();
394 mWidget->setDatasetGroupIndexes( datasetGroupsIndexes );
398 QWidget *QgsProcessingMeshDatasetTimeWidgetWrapper::createWidget()
407 connect( mWidget, &QgsProcessingMeshDatasetTimeWidget::changed,
this, [ = ]
409 emit widgetValueHasChanged(
this );
415 void QgsProcessingMeshDatasetTimeWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
419 mWidget->setValue( value );
422 QVariant QgsProcessingMeshDatasetTimeWidgetWrapper::widgetValue()
const
425 return mWidget->value();
429 QgsProcessingMeshDatasetTimeWidget::QgsProcessingMeshDatasetTimeWidget( QWidget *parent,
437 dateTimeEdit->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
441 connect( radioButtonCurrentCanvasTime, &QRadioButton::toggled, [
this](
bool isChecked ) {
if ( isChecked ) this->updateValue();} );
442 connect( radioButtonDefinedDateTime, &QRadioButton::toggled, [
this](
bool isChecked ) {
if ( isChecked ) this->updateValue();} );
443 connect( radioButtonDatasetGroupTimeStep, &QRadioButton::toggled, [
this](
bool isChecked ) {
if ( isChecked ) this->updateValue();} );
444 connect( dateTimeEdit, &QgsDateTimeEdit::dateTimeChanged,
this, &QgsProcessingMeshDatasetTimeWidget::updateValue );
445 connect( comboBoxDatasetTimeStep, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
446 this, &QgsProcessingMeshDatasetTimeWidget::updateValue );
451 void QgsProcessingMeshDatasetTimeWidget::setMeshLayer(
QgsMeshLayer *layer,
bool layerFromProject )
453 if ( mMeshLayer == layer )
456 if ( layerFromProject )
463 mMeshLayer =
nullptr;
465 storeTimeStepsFromLayer( layer );
468 if ( mReferenceTime.isValid() )
469 whileBlocking( dateTimeEdit )->setDateTime( mReferenceTime );
474 void QgsProcessingMeshDatasetTimeWidget::setDatasetGroupIndexes(
const QList<int> datasetGroupIndexes )
476 if ( datasetGroupIndexes == mDatasetGroupIndexes )
478 mDatasetGroupIndexes = datasetGroupIndexes;
483 void QgsProcessingMeshDatasetTimeWidget::setValue(
const QVariant &value )
485 if ( !value.isValid() || value.type() != QVariant::Map )
488 mValue = value.toMap();
490 if ( !mValue.contains( QStringLiteral(
"type" ) ) || !mValue.contains( QStringLiteral(
"value" ) ) )
493 QString type = mValue.value( QStringLiteral(
"type" ) ).toString();
496 if ( type == QLatin1String(
"static" ) )
500 else if ( type == QLatin1String(
"dataset-time-step" ) )
502 whileBlocking( radioButtonDatasetGroupTimeStep )->setChecked(
true );
503 whileBlocking( comboBoxDatasetTimeStep )->setCurrentIndex( comboBoxDatasetTimeStep->findData( mValue.value( QStringLiteral(
"value" ) ) ) );
505 else if ( type == QLatin1String(
"dataset-time-step" ) )
507 radioButtonDefinedDateTime->setChecked(
true );
508 whileBlocking( dateTimeEdit )->setDate( mValue.value( QStringLiteral(
"value" ) ).toDate() );
510 else if ( type == QLatin1String(
"current-context-time" ) )
512 whileBlocking( radioButtonCurrentCanvasTime )->setChecked(
true );
519 QVariant QgsProcessingMeshDatasetTimeWidget::value()
const
524 void QgsProcessingMeshDatasetTimeWidget::updateWidget()
526 bool isStatic = !hasTemporalDataset();
527 setEnabled( !isStatic );
529 if ( mCanvas !=
nullptr && mCanvas->mapSettings().isTemporal() )
531 whileBlocking( radioButtonCurrentCanvasTime )->setEnabled(
true && mReferenceTime.isValid() );
532 labelCurrentCanvasTime->setText( mCanvas->mapSettings().temporalRange().begin().toString(
"yyyy-MM-dd HH:mm:ss" ) );
536 whileBlocking( radioButtonCurrentCanvasTime )->setEnabled(
false );
537 if ( radioButtonCurrentCanvasTime->isChecked() )
538 whileBlocking( radioButtonDefinedDateTime )->setChecked(
true );
541 if ( ! mReferenceTime.isValid() )
542 whileBlocking( radioButtonDatasetGroupTimeStep )->setChecked(
true );
544 whileBlocking( radioButtonDefinedDateTime )->setEnabled( mReferenceTime.isValid() );
546 dateTimeEdit->setVisible( radioButtonDefinedDateTime->isChecked() && !isStatic );
547 labelCurrentCanvasTime->setVisible( radioButtonCurrentCanvasTime->isChecked() && !isStatic );
548 comboBoxDatasetTimeStep->setVisible( radioButtonDatasetGroupTimeStep->isChecked() && !isStatic );
551 bool QgsProcessingMeshDatasetTimeWidget::hasTemporalDataset()
const
553 for (
int index : mDatasetGroupIndexes )
555 if ( mMeshLayer && mMeshLayer->datasetGroupMetadata( index ).isTemporal() )
557 else if ( mDatasetTimeSteps.contains( index ) )
565 void QgsProcessingMeshDatasetTimeWidget::populateTimeSteps()
569 populateTimeStepsFromLayer();
573 QMap<quint64, QgsMeshDatasetIndex> timeStep;
574 for (
int groupIndex : mDatasetGroupIndexes )
576 if ( !mDatasetTimeSteps.contains( groupIndex ) )
578 const QList<qint64> relativeTimeSteps = mDatasetTimeSteps.value( groupIndex );
579 for (
int index = 0; index < relativeTimeSteps.count(); ++index )
582 if ( timeStep.contains( relativeTimeSteps.at( index ) ) )
584 timeStep[relativeTimeSteps.at( index )] = datasetIndex;
588 for ( qint64 key : timeStep.keys() )
590 QString stringTime = QgsMeshLayerUtils::formatTime( key / 1000 / 3600, mReferenceTime,
QgsMeshTimeSettings() );
594 whileBlocking( comboBoxDatasetTimeStep )->addItem( stringTime, data );
599 void QgsProcessingMeshDatasetTimeWidget::populateTimeStepsFromLayer()
606 QMap<quint64, QgsMeshDatasetIndex> timeStep;
607 for (
int groupIndex : mDatasetGroupIndexes )
612 int datasetCount = mMeshLayer->datasetCount( groupIndex );
614 for (
int index = 0; index < datasetCount; ++index )
617 qint64 relativeTime = mMeshLayer->datasetRelativeTimeInMilliseconds( datasetIndex );
618 if ( timeStep.contains( relativeTime ) )
620 timeStep[relativeTime] = datasetIndex;
624 for ( qint64 key : timeStep.keys() )
626 QString stringTime = mMeshLayer->formatTime( key / 1000.0 / 3600.0 );
630 whileBlocking( comboBoxDatasetTimeStep )->addItem( stringTime, data );
634 void QgsProcessingMeshDatasetTimeWidget::storeTimeStepsFromLayer(
QgsMeshLayer *layer )
636 mDatasetTimeSteps.clear();
640 for (
int groupIndex : datasetGroupsList )
646 QList<qint64> relativeTimeSteps;
647 relativeTimeSteps.reserve( datasetCount );
648 for (
int index = 0; index < datasetCount; ++index )
650 mDatasetTimeSteps[groupIndex] = relativeTimeSteps;
654 void QgsProcessingMeshDatasetTimeWidget::buildValue()
660 mValue[QStringLiteral(
"type" )] = QStringLiteral(
"static" );
662 else if ( radioButtonDatasetGroupTimeStep->isChecked() )
664 mValue[QStringLiteral(
"type" )] = QStringLiteral(
"dataset-time-step" );
665 mValue[QStringLiteral(
"value" )] = comboBoxDatasetTimeStep->currentData();
667 else if ( radioButtonDefinedDateTime->isChecked() )
669 mValue[QStringLiteral(
"type" )] = QStringLiteral(
"defined-date-time" );
670 mValue[QStringLiteral(
"value" )] = dateTimeEdit->dateTime();
672 else if ( radioButtonCurrentCanvasTime->isChecked() && mCanvas )
674 mValue[QStringLiteral(
"type" )] = QStringLiteral(
"current-context-time" );
680 void QgsProcessingMeshDatasetTimeWidget::updateValue()
Map canvas is a class for displaying all GIS data types on a canvas.
void temporalRangeChanged()
Emitted when the map canvas temporal range changes.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
QDateTime referenceTime() const
Returns the reference time.
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
int group() const
Returns a group index.
int dataset() const
Returns a dataset index within group()
Implementation of map layer temporal properties for mesh layers.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
int datasetCount(const QgsMeshDatasetIndex &index) const
Returns the dataset count in the dataset groups.
QList< int > datasetGroupsIndexes() const
Returns the list of indexes of dataset groups handled by the layer.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
qint64 datasetRelativeTimeInMilliseconds(const QgsMeshDatasetIndex &index)
Returns the relative time (in milliseconds) of the dataset from the reference time of its group.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
Represents a mesh time settings for mesh datasets.
Contains information about the context in which a processing algorithm is executed.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
WidgetType
Types of dialogs which Processing widgets can be created for.
@ Standard
Standard algorithm dialog.
@ Batch
Batch processing dialog.
Base class for the definition of processing parameters.
QString name() const
Returns the name of the parameter.
A parameter for processing algorithms that need a list of mesh dataset groups.
static QString typeName()
Returns the type name for the parameter class.
A parameter for processing algorithms that need a list of mesh dataset index from time parameter.
static QString typeName()
Returns the type name for the parameter class.
Contains settings which reflect the context in which a Processing parameter widget is shown,...
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap ¶meters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
QgsMapLayerStore * layerStore()
Returns a pointer to the project's internal layer store.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.