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,
 
   98  : QgsProcessingMultipleSelectionPanelWidget( QVariantList(), QVariantList(), parent )
 
  101  connect( listView(), &QListView::doubleClicked, 
this, &QgsProcessingAlignRasterLayersPanelWidget::configureRaster );
 
  103  QPushButton *configureLayerButton = 
new QPushButton( tr( 
"Configure Raster…" ) );
 
  104  connect( configureLayerButton, &QPushButton::clicked, 
this, &QgsProcessingAlignRasterLayersPanelWidget::configureRaster );
 
  105  buttonBox()->addButton( configureLayerButton, QDialogButtonBox::ActionRole );
 
  108  mContext.setProject( project );
 
  110  QSet<const QString> seenFiles;
 
  111  const QVariantList valueList = value.toList();
 
  112  for ( 
const QVariant &v : valueList )
 
  115    addOption( v, titleForItem( item ), 
true );
 
  122    if ( seenFiles.contains( layer->source() ) )
 
  126    vm[
"inputFile"] = layer->source();
 
  127    vm[
"outputFile"] = QString();
 
  131    const QString title = layer->source();
 
  132    addOption( vm, title, 
false );
 
  136void QgsProcessingAlignRasterLayersPanelWidget::configureRaster()
 
  138  const QModelIndexList selection = listView()->selectionModel()->selectedIndexes();
 
  139  if ( selection.size() != 1 )
 
  141    QMessageBox::warning( 
this, tr( 
"Configure Raster" ), tr( 
"Please select a single layer." ) );
 
  145  QStandardItem *item = mModel->itemFromIndex( selection[0] );
 
  146  const QVariant value = item->data( Qt::UserRole );
 
  151    QgsProcessingAlignRasterLayerDetailsWidget *widget = 
new QgsProcessingAlignRasterLayerDetailsWidget( value, mProject );
 
  152    widget->setPanelTitle( tr( 
"Configure Raster" ) );
 
  153    widget->buttonBox()->hide();
 
  155    connect( widget, &QgsProcessingAlignRasterLayerDetailsWidget::widgetChanged, 
this, [
this, item, widget]() {
 
  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, [
this, widget]() {
 
  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  if ( parameterDefinition() )
 
  296    mPanel->setToolTip( parameterDefinition()->toolTip() );
 
  298  connect( mPanel, &QgsProcessingAlignRasterLayersWidget::changed, 
this, [
this] {
 
  299    emit widgetValueHasChanged( 
this );
 
  309    mPanel->setProject( context.
project() );
 
  313void QgsProcessingAlignRasterLayersWidgetWrapper::setWidgetValue( 
const QVariant &value, 
QgsProcessingContext &context )
 
  318    mPanel->setValue( value );
 
  322QVariant QgsProcessingAlignRasterLayersWidgetWrapper::widgetValue()
 const 
  324  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)