29#include <QStandardItemModel>
32#include "moc_qgsprocessingalignrasterlayerswidgetwrapper.cpp"
40QgsProcessingAlignRasterLayerDetailsWidget::QgsProcessingAlignRasterLayerDetailsWidget(
const QVariant &value,
QgsProject *project )
45 mOutputFileWidget->setConfirmOverwrite(
true );
49 for (
const QString &ext : extensions )
51 filters << QObject::tr(
"%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
53 mOutputFileWidget->setFilter( filters.join( QLatin1String(
";;" ) ) + QStringLiteral(
";;" ) + QObject::tr(
"All files (*.*)" ) );
68 mContext.setProject( project );
73 cmbResamplingMethod->setCurrentIndex( cmbResamplingMethod->findData(
static_cast<int>( item.
resampleMethod ) ) );
81QVariant QgsProcessingAlignRasterLayerDetailsWidget::value()
const
94QgsProcessingAlignRasterLayersPanelWidget::QgsProcessingAlignRasterLayersPanelWidget(
95 const QVariant &value,
99 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
100 , mProject( project )
102 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingAlignRasterLayersPanelWidget::configureRaster );
104 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Raster…" ) );
105 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingAlignRasterLayersPanelWidget::configureRaster );
106 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
109 mContext.setProject( project );
111 QSet<const QString> seenFiles;
112 const QVariantList valueList = value.toList();
113 for (
const QVariant &v : valueList )
116 addOption( v, titleForItem( item ),
true );
123 if ( seenFiles.contains( layer->source() ) )
127 vm[
"inputFile"] = layer->source();
128 vm[
"outputFile"] = QString();
132 const QString title = layer->source();
133 addOption( vm, title,
false );
137void QgsProcessingAlignRasterLayersPanelWidget::configureRaster()
139 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
140 if ( selection.size() != 1 )
142 QMessageBox::warning(
this, tr(
"Configure Raster" ), tr(
"Please select a single layer." ) );
146 QStandardItem *item = mModel->itemFromIndex( selection[0] );
147 const QVariant value = item->data( Qt::UserRole );
152 QgsProcessingAlignRasterLayerDetailsWidget *widget =
new QgsProcessingAlignRasterLayerDetailsWidget( value, mProject );
153 widget->setPanelTitle( tr(
"Configure Raster" ) );
154 widget->buttonBox()->hide();
156 connect( widget, &QgsProcessingAlignRasterLayerDetailsWidget::widgetChanged,
this, [
this, item, widget]() {
157 setItemValue( item, widget->value() );
164 dlg.setWindowTitle( tr(
"Configure Raster" ) );
165 QVBoxLayout *vLayout =
new QVBoxLayout();
166 QgsProcessingAlignRasterLayerDetailsWidget *widget =
new QgsProcessingAlignRasterLayerDetailsWidget( value, mProject );
167 vLayout->addWidget( widget );
168 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
169 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
170 dlg.setLayout( vLayout );
173 setItemValue( item, widget->value() );
178void QgsProcessingAlignRasterLayersPanelWidget::setItemValue( QStandardItem *item,
const QVariant &value )
180 mContext.setProject( mProject );
184 item->setText( titleForItem( rasterItem ) );
185 item->setData( value, Qt::UserRole );
198QgsProcessingAlignRasterLayersWidget::QgsProcessingAlignRasterLayersWidget( QWidget *parent )
201 QHBoxLayout *hl =
new QHBoxLayout();
202 hl->setContentsMargins( 0, 0, 0, 0 );
204 mLineEdit =
new QLineEdit();
205 mLineEdit->setEnabled(
false );
206 hl->addWidget( mLineEdit, 1 );
208 mToolButton =
new QToolButton();
209 mToolButton->setText( QString( QChar( 0x2026 ) ) );
210 hl->addWidget( mToolButton );
216 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingAlignRasterLayersWidget::showDialog );
219void QgsProcessingAlignRasterLayersWidget::setValue(
const QVariant &value )
221 if ( value.isValid() )
222 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
230void QgsProcessingAlignRasterLayersWidget::setProject(
QgsProject *project )
235void QgsProcessingAlignRasterLayersWidget::showDialog()
240 QgsProcessingAlignRasterLayersPanelWidget *widget =
new QgsProcessingAlignRasterLayersPanelWidget( mValue, mProject );
241 widget->setPanelTitle( tr(
"Input layers" ) );
242 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [
this, widget]() {
243 setValue( widget->selectedOptions() );
251 dlg.setWindowTitle( tr(
"Input layers" ) );
252 QVBoxLayout *vLayout =
new QVBoxLayout();
253 QgsProcessingAlignRasterLayersPanelWidget *widget =
new QgsProcessingAlignRasterLayersPanelWidget( mValue, mProject );
254 vLayout->addWidget( widget );
255 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
256 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
257 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
258 dlg.setLayout( vLayout );
261 setValue( widget->selectedOptions() );
266void QgsProcessingAlignRasterLayersWidget::updateSummaryText()
268 mLineEdit->setText( tr(
"%n raster layer(s) selected",
nullptr, mValue.count() ) );
281QString QgsProcessingAlignRasterLayersWidgetWrapper::parameterType()
const
288 return new QgsProcessingAlignRasterLayersWidgetWrapper( parameter, type );
291QWidget *QgsProcessingAlignRasterLayersWidgetWrapper::createWidget()
293 mPanel =
new QgsProcessingAlignRasterLayersWidget(
nullptr );
294 mPanel->setProject( widgetContext().project() );
295 if ( parameterDefinition() )
297 mPanel->setToolTip( parameterDefinition()->toolTip() );
299 connect( mPanel, &QgsProcessingAlignRasterLayersWidget::changed,
this, [
this] {
300 emit widgetValueHasChanged(
this );
310 mPanel->setProject( context.
project() );
314void QgsProcessingAlignRasterLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
319 mPanel->setValue( value );
323QVariant QgsProcessingAlignRasterLayersWidgetWrapper::widgetValue()
const
325 return mPanel ? mPanel->value() : QVariant();
ProcessingMode
Types of modes which Processing widgets can be created for.
GdalResampleAlgorithm
Resampling algorithm to be used (equivalent to GDAL's enum GDALResampleAlg).
@ RA_Lanczos
Lanczos windowed sinc interpolation (6x6 kernel).
@ RA_Q3
Third quartile (selects the third quartile of all non-NODATA contributing pixels).
@ RA_CubicSpline
Cubic B-Spline Approximation (4x4 kernel).
@ RA_Q1
First quartile (selects the first quartile of all non-NODATA contributing pixels).
@ RA_Min
Minimum (selects the minimum of all non-NODATA contributing pixels).
@ RA_Median
Median (selects the median of all non-NODATA contributing pixels).
@ RA_NearestNeighbour
Nearest neighbour (select on one input pixel).
@ RA_Average
Average (computes the average of all non-NODATA contributing pixels).
@ RA_Max
Maximum (selects the maximum of all non-NODATA contributing pixels).
@ RA_Bilinear
Bilinear (2x2 kernel).
@ RA_Mode
Mode (selects the value which appears most often of all the sampled points).
@ RA_Cubic
Cubic Convolution Approximation (4x4 kernel).
Contains information about the context in which a processing algorithm is executed.
static QString typeName()
Returns the type name for the parameter class.
static QgsAlignRasterData::RasterItem variantMapAsItem(const QVariantMap &layerVariantMap, QgsProcessingContext &context)
Converts a QVariant value (a QVariantMap) to a single input layer.
static QVariantMap itemAsVariantMap(const QgsAlignRasterData::RasterItem &item)
Converts a single input layer to QVariant representation (a QVariantMap).
Base class for the definition of processing parameters.
Contains settings which reflect the context in which a Processing parameter widget is shown.
QgsProject * project() const
Returns the project associated with the widget.
static QList< QgsRasterLayer * > compatibleRasterLayers(QgsProject *project, bool sort=true)
Returns a list of raster layers from a project which are compatible with the processing framework.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QStringList supportedFormatExtensions(RasterFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats.
Represents a raster layer.
Definition of one raster layer for alignment.
Qgis::GdalResampleAlgorithm resampleMethod
resampling method to be used
bool rescaleValues
rescaling of values according to the change of pixel size
QString inputFilename
filename of the source raster
QString outputFilename
filename of the newly created aligned raster (will be overwritten if exists already)