17#include "moc_qgsprocessingalignrasterlayerswidgetwrapper.cpp"
23#include <QStandardItemModel>
39QgsProcessingAlignRasterLayerDetailsWidget::QgsProcessingAlignRasterLayerDetailsWidget(
const QVariant &value,
QgsProject *project )
44 mOutputFileWidget->setConfirmOverwrite(
true );
48 for (
const QString &ext : extensions )
50 filters << QObject::tr(
"%1 files (*.%2)" ).arg( ext.toUpper(), ext.toLower() );
52 mOutputFileWidget->setFilter( filters.join( QLatin1String(
";;" ) ) + QStringLiteral(
";;" ) + QObject::tr(
"All files (*.*)" ) );
67 mContext.setProject( project );
72 cmbResamplingMethod->setCurrentIndex( cmbResamplingMethod->findData(
static_cast<int>( item.
resampleMethod ) ) );
80QVariant QgsProcessingAlignRasterLayerDetailsWidget::value()
const
93QgsProcessingAlignRasterLayersPanelWidget::QgsProcessingAlignRasterLayersPanelWidget(
94 const QVariant &value,
97 : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
100 connect( listView(), &QListView::doubleClicked,
this, &QgsProcessingAlignRasterLayersPanelWidget::configureRaster );
102 QPushButton *configureLayerButton =
new QPushButton( tr(
"Configure Raster…" ) );
103 connect( configureLayerButton, &QPushButton::clicked,
this, &QgsProcessingAlignRasterLayersPanelWidget::configureRaster );
104 buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
107 mContext.setProject( project );
109 QSet<const QString > seenFiles;
110 const QVariantList valueList = value.toList();
111 for (
const QVariant &v : valueList )
114 addOption( v, titleForItem( item ),
true );
121 if ( seenFiles.contains( layer->source() ) )
125 vm[
"inputFile"] = layer->source();
126 vm[
"outputFile"] = QString();
130 const QString title = layer->source();
131 addOption( vm, title,
false );
135void QgsProcessingAlignRasterLayersPanelWidget::configureRaster()
137 const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
138 if ( selection.size() != 1 )
140 QMessageBox::warning(
this, tr(
"Configure Raster" ), tr(
"Please select a single layer." ) );
144 QStandardItem *item = mModel->itemFromIndex( selection[0] );
145 const QVariant value = item->data( Qt::UserRole );
150 QgsProcessingAlignRasterLayerDetailsWidget *widget =
new QgsProcessingAlignRasterLayerDetailsWidget( value, mProject );
151 widget->setPanelTitle( tr(
"Configure Raster" ) );
152 widget->buttonBox()->hide();
154 connect( widget, &QgsProcessingAlignRasterLayerDetailsWidget::widgetChanged,
this, [ = ]()
156 setItemValue( item, widget->value() );
163 dlg.setWindowTitle( tr(
"Configure Raster" ) );
164 QVBoxLayout *vLayout =
new QVBoxLayout();
165 QgsProcessingAlignRasterLayerDetailsWidget *widget =
new QgsProcessingAlignRasterLayerDetailsWidget( value, mProject );
166 vLayout->addWidget( widget );
167 connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
168 connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
169 dlg.setLayout( vLayout );
172 setItemValue( item, widget->value() );
177void QgsProcessingAlignRasterLayersPanelWidget::setItemValue( QStandardItem *item,
const QVariant &value )
179 mContext.setProject( mProject );
183 item->setText( titleForItem( rasterItem ) );
184 item->setData( value, Qt::UserRole );
197QgsProcessingAlignRasterLayersWidget::QgsProcessingAlignRasterLayersWidget( QWidget *parent )
200 QHBoxLayout *hl =
new QHBoxLayout();
201 hl->setContentsMargins( 0, 0, 0, 0 );
203 mLineEdit =
new QLineEdit();
204 mLineEdit->setEnabled(
false );
205 hl->addWidget( mLineEdit, 1 );
207 mToolButton =
new QToolButton();
208 mToolButton->setText( QString( QChar( 0x2026 ) ) );
209 hl->addWidget( mToolButton );
215 connect( mToolButton, &QToolButton::clicked,
this, &QgsProcessingAlignRasterLayersWidget::showDialog );
218void QgsProcessingAlignRasterLayersWidget::setValue(
const QVariant &value )
220 if ( value.isValid() )
221 mValue = value.userType() == QMetaType::Type::QVariantList ? value.toList() : QVariantList() << value;
229void QgsProcessingAlignRasterLayersWidget::setProject(
QgsProject *project )
234void QgsProcessingAlignRasterLayersWidget::showDialog()
239 QgsProcessingAlignRasterLayersPanelWidget *widget =
new QgsProcessingAlignRasterLayersPanelWidget( mValue, mProject );
240 widget->setPanelTitle( tr(
"Input layers" ) );
241 connect( widget, &QgsProcessingMultipleSelectionPanelWidget::selectionChanged,
this, [ = ]()
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 connect( mPanel, &QgsProcessingAlignRasterLayersWidget::changed,
this, [ = ]
297 emit widgetValueHasChanged(
this );
307 mPanel->setProject( context.
project() );
311void QgsProcessingAlignRasterLayersWidgetWrapper::setWidgetValue(
const QVariant &value,
QgsProcessingContext &context )
316 mPanel->setValue( value );
320QVariant QgsProcessingAlignRasterLayersWidgetWrapper::widgetValue()
const
322 return mPanel ? mPanel->value() : QVariant();
325QStringList QgsProcessingAlignRasterLayersWidgetWrapper::compatibleParameterTypes()
const
336QStringList 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)