22#include <QStandardItemModel>
38QgsProcessingAlignRasterLayerDetailsWidget::QgsProcessingAlignRasterLayerDetailsWidget(
const QVariant &value,
QgsProject *project )
43 mOutputFileWidget->setConfirmOverwrite(
true );
47 for (
const QString &ext : extensions )
49 filters << QObject::tr(
"%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
51 mOutputFileWidget->setFilter( filters.join( QLatin1String(
";;" ) ) + QStringLiteral(
";;" ) + QObject::tr(
"All files (*.*)" ) );
66 mContext.setProject( project );
71 cmbResamplingMethod->setCurrentIndex( cmbResamplingMethod->findData(
static_cast<int>( item.
resampleMethod ) ) );
79QVariant QgsProcessingAlignRasterLayerDetailsWidget::value()
const
92QgsProcessingAlignRasterLayersPanelWidget::QgsProcessingAlignRasterLayersPanelWidget(
93 const QVariant &value,
96 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
99 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingAlignRasterLayersPanelWidget::configureRaster );
101 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Raster…" ) );
102 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingAlignRasterLayersPanelWidget::configureRaster );
103 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
106 mContext.setProject( project );
108 QSet<const QString > seenFiles;
109 const QVariantList valueList = value.toList();
110 for (
const QVariant &v : valueList )
113 addOption( v, titleForItem( item ),
true );
120 if ( seenFiles.contains( layer->source() ) )
124 vm[
"inputFile"] = layer->source();
125 vm[
"outputFile"] = QString();
129 const QString title = layer->source();
130 addOption( vm, title,
false );
134void QgsProcessingAlignRasterLayersPanelWidget::configureRaster()
136 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
137 if ( selection.size() != 1 )
139 QMessageBox::warning(
this, tr(
"Configure Raster" ), tr(
"Please select a single layer." ) );
143 QStandardItem *item = mModel->itemFromIndex( selection[0] );
144 const QVariant value = item->data( Qt::UserRole );
149 QgsProcessingAlignRasterLayerDetailsWidget *widget =
new QgsProcessingAlignRasterLayerDetailsWidget( value, mProject );
150 widget->setPanelTitle( tr(
"Configure Raster" ) );
151 widget->buttonBox()->hide();
153 connect( widget, &QgsProcessingAlignRasterLayerDetailsWidget::widgetChanged,
this, [ = ]()
155 setItemValue( item, widget->value() );
162 dlg.setWindowTitle( tr(
"Configure Raster" ) );
163 QVBoxLayout *vLayout =
new QVBoxLayout();
164 QgsProcessingAlignRasterLayerDetailsWidget *widget =
new QgsProcessingAlignRasterLayerDetailsWidget( value, mProject );
165 vLayout->addWidget( widget );
166 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
167 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
168 dlg.setLayout( vLayout );
171 setItemValue( item, widget->value() );
176void QgsProcessingAlignRasterLayersPanelWidget::setItemValue( QStandardItem *item,
const QVariant &value )
178 mContext.setProject( mProject );
182 item->setText( titleForItem( rasterItem ) );
183 item->setData( value, Qt::UserRole );
196QgsProcessingAlignRasterLayersWidget::QgsProcessingAlignRasterLayersWidget( QWidget *parent )
199 QHBoxLayout *hl =
new QHBoxLayout();
200 hl->setContentsMargins( 0, 0, 0, 0 );
202 mLineEdit =
new QLineEdit();
203 mLineEdit->setEnabled(
false );
204 hl->addWidget( mLineEdit, 1 );
206 mToolButton =
new QToolButton();
207 mToolButton->setText( QString( QChar( 0x2026 ) ) );
208 hl->addWidget( mToolButton );
214 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingAlignRasterLayersWidget::showDialog );
217void QgsProcessingAlignRasterLayersWidget::setValue(
const QVariant &value )
219 if ( value.isValid() )
220 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
228void QgsProcessingAlignRasterLayersWidget::setProject(
QgsProject *project )
233void QgsProcessingAlignRasterLayersWidget::showDialog()
238 QgsProcessingAlignRasterLayersPanelWidget *widget =
new QgsProcessingAlignRasterLayersPanelWidget( mValue, mProject );
239 widget->setPanelTitle( tr(
"Input layers" ) );
240 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
242 setValue( widget->selectedOptions() );
250 dlg.setWindowTitle( tr(
"Input layers" ) );
251 QVBoxLayout *vLayout =
new QVBoxLayout();
252 QgsProcessingAlignRasterLayersPanelWidget *widget =
new QgsProcessingAlignRasterLayersPanelWidget( mValue, mProject );
253 vLayout->addWidget( widget );
254 widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
255 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
256 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
257 dlg.setLayout( vLayout );
260 setValue( widget->selectedOptions() );
265void QgsProcessingAlignRasterLayersWidget::updateSummaryText()
267 mLineEdit->setText( tr(
"%n raster layer(s) selected",
nullptr, mValue.count() ) );
280QString QgsProcessingAlignRasterLayersWidgetWrapper::parameterType()
const
287 return new QgsProcessingAlignRasterLayersWidgetWrapper( parameter, type );
290QWidget *QgsProcessingAlignRasterLayersWidgetWrapper::createWidget()
292 mPanel =
new QgsProcessingAlignRasterLayersWidget(
nullptr );
293 mPanel->setProject( widgetContext().project() );
294 connect( mPanel, &QgsProcessingAlignRasterLayersWidget::changed,
this, [ = ]
296 emit widgetValueHasChanged(
this );
306 mPanel->setProject( context.
project() );
310void QgsProcessingAlignRasterLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
315 mPanel->setValue( value );
319QVariant QgsProcessingAlignRasterLayersWidgetWrapper::widgetValue()
const
321 return mPanel ? mPanel->value() : QVariant();
324QStringList QgsProcessingAlignRasterLayersWidgetWrapper::compatibleParameterTypes()
const
335QStringList QgsProcessingAlignRasterLayersWidgetWrapper::compatibleOutputTypes()
const
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.
WidgetType
Types of dialogs which Processing widgets can be created for.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
static QString typeName()
Returns the type name for the output class.
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.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
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,...
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)