33#include <QIntValidator>
35#include <QRegularExpression>
39#include "moc_qgsrastertransparencywidget.cpp"
43 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
44 , mRasterLayer( layer )
45 , mMapCanvas( canvas )
48 connect( pbnAddValuesFromDisplay, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnAddValuesFromDisplay_clicked );
49 connect( pbnAddValuesManually, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnAddValuesManually_clicked );
50 connect( pbnDefaultValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnDefaultValues_clicked );
51 connect( pbnExportTransparentPixelValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnExportTransparentPixelValues_clicked );
52 connect( pbnImportTransparentPixelValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnImportTransparentPixelValues_clicked );
53 connect( pbnRemoveSelectedRow, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnRemoveSelectedRow_clicked );
55 mNodataColorButton->setShowNoColor(
true );
56 mNodataColorButton->setColorDialogTitle( tr(
"Select NoData Color" ) );
63 leNoDataValue->setValidator(
new QgsDoubleValidator( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max(),
this ) );
66 mPixelSelectorTool =
nullptr;
74 pbnAddValuesFromDisplay->setEnabled(
false );
91 expContext = canvas->createExpressionContext();
105 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
123 gboxNoDataValue->setEnabled(
false );
124 gboxCustomTransparency->setEnabled(
false );
127 cboxTransparencyBand->setShowNotSetOption(
true, tr(
"None" ) );
128 cboxTransparencyBand->setLayer( mRasterLayer );
135 lblSrcNoDataValue->setText( tr(
"not defined" ) );
142 mSrcNoDataValueCheckBox->setEnabled( enableSrcNoData );
143 lblSrcNoDataValue->setEnabled( enableSrcNoData );
149 mNodataColorButton->setColor( renderer->
nodataColor() );
151 mNodataColorButton->setToNull();
153 mOpacityWidget->setOpacity( renderer->
opacity() );
155 cboxTransparencyBand->setBand( renderer->
alphaBand() );
161 QgsDebugMsgLevel( QStringLiteral(
"noDataRangeList.size = %1" ).arg( noDataRangeList.size() ), 2 );
162 if ( !noDataRangeList.isEmpty() )
165 leNoDataValue->setText( QLocale().toString( v,
'g', 20 ) );
169 leNoDataValue->setText( QString() );
174 leNoDataValue->setText( QString() );
180 populateTransparencyTable( mRasterLayer->renderer() );
183void QgsRasterTransparencyWidget::transparencyCellTextEdited(
const QString &text )
188 switch ( mCurrentMode )
190 case Mode::SingleBand:
192 QLineEdit *lineEdit = qobject_cast<QLineEdit *>( sender() );
197 for (
int r = 0; r < tableTransparency->rowCount(); r++ )
199 for (
int c = 0;
c < tableTransparency->columnCount();
c++ )
201 if ( tableTransparency->cellWidget( r,
c ) == sender() )
211 QgsDebugMsgLevel( QStringLiteral(
"row = %1 column =%2" ).arg( row ).arg( column ), 2 );
213 if ( column ==
static_cast<int>( SingleBandTableColumns::From ) )
215 QLineEdit *toLineEdit =
dynamic_cast<QLineEdit *
>( tableTransparency->cellWidget( row,
static_cast<int>( SingleBandTableColumns::To ) ) );
219 const bool toChanged = mTransparencyToEdited.value( row );
223 toLineEdit->setText( lineEdit->text() );
226 else if ( column ==
static_cast<int>( SingleBandTableColumns::To ) )
228 setTransparencyToEdited( row );
240void QgsRasterTransparencyWidget::pbnAddValuesFromDisplay_clicked()
242 if ( mMapCanvas && mPixelSelectorTool )
244 mMapCanvas->setMapTool( mPixelSelectorTool );
248void QgsRasterTransparencyWidget::pbnAddValuesManually_clicked()
250 QgsRasterRenderer *renderer = mRasterLayer->renderer();
256 tableTransparency->insertRow( tableTransparency->rowCount() );
259 switch ( mCurrentMode )
261 case Mode::SingleBand:
270 for (
int i = 0; i < n; i++ )
272 setTransparencyCell( tableTransparency->rowCount() - 1, i, std::numeric_limits<double>::quiet_NaN() );
275 switch ( mCurrentMode )
277 case Mode::SingleBand:
278 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::Opacity ), 100 );
282 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Opacity ), 100 );
290void QgsRasterTransparencyWidget::pbnDefaultValues_clicked()
292 QgsRasterRenderer *r = mRasterLayer->renderer();
298 const int nBands = r->
usesBands().size();
300 setupTransparencyTable( nBands );
306void QgsRasterTransparencyWidget::pbnExportTransparentPixelValues_clicked()
308 const QgsSettings myQSettings;
309 const QString myLastDir = myQSettings.
value( QStringLiteral(
"lastRasterFileFilterDir" ), QDir::homePath() ).toString();
310 QString myFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Pixel Values as File" ), myLastDir, tr(
"Textfile" ) +
" (*.txt)" );
311 if ( !myFileName.isEmpty() )
313 if ( !myFileName.endsWith( QLatin1String(
".txt" ), Qt::CaseInsensitive ) )
315 myFileName = myFileName +
".txt";
318 QFile myOutputFile( myFileName );
319 if ( myOutputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
321 QTextStream myOutputStream( &myOutputFile );
322 myOutputStream <<
"# " << tr(
"QGIS Generated Transparent Pixel Value Export File" ) <<
'\n';
323 switch ( mCurrentMode )
327 myOutputStream <<
"#\n#\n# " << tr(
"Red" ) <<
"\t" << tr(
"Green" ) <<
"\t" << tr(
"Blue" ) <<
"\t" << tr(
"Percent Transparent" );
328 for (
int myTableRunner = 0; myTableRunner < tableTransparency->rowCount(); myTableRunner++ )
330 myOutputStream <<
'\n'
331 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( RgbBandTableColumns::Red ) ) ) <<
"\t"
332 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( RgbBandTableColumns::Green ) ) ) <<
"\t"
333 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( RgbBandTableColumns::Blue ) ) ) <<
"\t"
334 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( RgbBandTableColumns::Opacity ) ) );
338 case Mode::SingleBand:
340 myOutputStream <<
"#\n#\n# " << tr(
"Value" ) <<
"\t" << tr(
"Percent Transparent" );
342 for (
int myTableRunner = 0; myTableRunner < tableTransparency->rowCount(); myTableRunner++ )
344 myOutputStream <<
'\n'
345 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( SingleBandTableColumns::From ) ) ) <<
"\t"
346 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( SingleBandTableColumns::To ) ) ) <<
"\t"
347 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( SingleBandTableColumns::Opacity ) ) );
355 QMessageBox::warning(
this, tr(
"Save Pixel Values as File" ), tr(
"Write access denied. Adjust the file permissions and try again.\n\n" ) );
360void QgsRasterTransparencyWidget::pbnImportTransparentPixelValues_clicked()
362 int myLineCounter = 0;
363 bool myImportError =
false;
365 const QgsSettings myQSettings;
366 const QString myLastDir = myQSettings.
value( QStringLiteral(
"lastRasterFileFilterDir" ), QDir::homePath() ).toString();
367 const QString myFileName = QFileDialog::getOpenFileName(
this, tr(
"Load Pixel Values from File" ), myLastDir, tr(
"Textfile" ) +
" (*.txt)" );
368 QFile myInputFile( myFileName );
370 const thread_local QRegularExpression sRxWhitespace(
"\\s+" );
372 if ( myInputFile.open( QFile::ReadOnly ) )
374 QTextStream myInputStream( &myInputFile );
376 switch ( mCurrentMode )
380 for (
int myTableRunner = tableTransparency->rowCount() - 1; myTableRunner >= 0; myTableRunner-- )
382 tableTransparency->removeRow( myTableRunner );
385 while ( !myInputStream.atEnd() )
388 myInputLine = myInputStream.readLine();
389 if ( !myInputLine.isEmpty() )
391 if ( !myInputLine.simplified().startsWith(
'#' ) )
393 QStringList myTokens = myInputLine.split( sRxWhitespace, Qt::SkipEmptyParts );
394 if ( myTokens.count() != 4 )
396 myImportError =
true;
397 myBadLines = myBadLines + QString::number( myLineCounter ) +
":\t[" + myInputLine +
"]\n";
401 tableTransparency->insertRow( tableTransparency->rowCount() );
402 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Red ), myTokens[0].toDouble() );
403 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Green ), myTokens[1].toDouble() );
404 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Blue ), myTokens[2].toDouble() );
405 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Tolerance ), 0 );
406 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Opacity ), myTokens[3].toDouble() );
413 case Mode::SingleBand:
415 for (
int myTableRunner = tableTransparency->rowCount() - 1; myTableRunner >= 0; myTableRunner-- )
417 tableTransparency->removeRow( myTableRunner );
420 while ( !myInputStream.atEnd() )
423 myInputLine = myInputStream.readLine();
424 if ( !myInputLine.isEmpty() )
426 if ( !myInputLine.simplified().startsWith(
'#' ) )
428 QStringList myTokens = myInputLine.split( sRxWhitespace, Qt::SkipEmptyParts );
429 if ( myTokens.count() != 3 && myTokens.count() != 2 )
431 myImportError =
true;
432 myBadLines = myBadLines + QString::number( myLineCounter ) +
":\t[" + myInputLine +
"]\n";
436 if ( myTokens.count() == 2 )
438 myTokens.insert( 1, myTokens[0] );
440 tableTransparency->insertRow( tableTransparency->rowCount() );
442 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::From ), myTokens[0].toDouble() );
443 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::To ), myTokens[1].toDouble() );
444 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::Opacity ), myTokens[2].toDouble() );
455 QMessageBox::warning(
this, tr(
"Load Pixel Values from File" ), tr(
"The following lines contained errors\n\n%1" ).arg( myBadLines ) );
458 else if ( !myFileName.isEmpty() )
460 QMessageBox::warning(
this, tr(
"Load Pixel Values from File" ), tr(
"Read access denied. Adjust the file permissions and try again.\n\n" ) );
467void QgsRasterTransparencyWidget::pbnRemoveSelectedRow_clicked()
469 if ( 0 < tableTransparency->rowCount() )
471 tableTransparency->removeRow( tableTransparency->currentRow() );
487 if ( !leNoDataValue->text().isEmpty() )
489 bool myDoubleOk =
false;
493 const QgsRasterRange myNoDataRange( myNoDataValue, myNoDataValue );
494 myNoDataRangeList << myNoDataRange;
499 for (
int bandNo = 1; bandNo <= provider->
bandCount(); bandNo++ )
509 if ( rasterRenderer )
511 rasterRenderer->
setAlphaBand( cboxTransparencyBand->currentBand() );
516 switch ( mCurrentMode )
520 QVector<QgsRasterTransparency::TransparentThreeValuePixel> myTransparentThreeValuePixelList;
521 myTransparentThreeValuePixelList.reserve( tableTransparency->rowCount() );
522 for (
int myListRunner = 0; myListRunner < tableTransparency->rowCount(); myListRunner++ )
524 const double red = transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Red ) );
525 const double green = transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Green ) );
526 const double blue = transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Blue ) );
527 const double opacity = 1.0 - transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Opacity ) ) / 100.0;
528 const double tolerance = transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Tolerance ) );
529 myTransparentThreeValuePixelList.append(
536 case Mode::SingleBand:
538 QVector<QgsRasterTransparency::TransparentSingleValuePixel> myTransparentSingleValuePixelList;
539 myTransparentSingleValuePixelList.reserve( tableTransparency->rowCount() );
540 for (
int myListRunner = 0; myListRunner < tableTransparency->rowCount(); myListRunner++ )
542 const double min = transparencyCellValue( myListRunner,
static_cast<int>( SingleBandTableColumns::From ) );
543 const double max = transparencyCellValue( myListRunner,
static_cast<int>( SingleBandTableColumns::To ) );
544 const double opacity = 1.0 - transparencyCellValue( myListRunner,
static_cast<int>( SingleBandTableColumns::Opacity ) ) / 100.0;
546 myTransparentSingleValuePixelList.append(
558 rasterRenderer->
setOpacity( mOpacityWidget->opacity() );
564 button->blockSignals(
true );
568 button->blockSignals(
false );
573 const QList<QgsPropertyOverrideButton *> propertyOverrideButtons { findChildren<QgsPropertyOverrideButton *>() };
592void QgsRasterTransparencyWidget::updateProperty()
600void QgsRasterTransparencyWidget::pixelSelected(
const QgsPointXY &canvasPoint )
602 QgsRasterRenderer *renderer = mRasterLayer->renderer();
609 if ( mMapCanvas && mPixelSelectorTool && mRasterLayer->dataProvider() )
611 mMapCanvas->unsetMapTool( mPixelSelectorTool );
613 const QgsMapSettings &ms = mMapCanvas->mapSettings();
617 const double mapUnitsPerPixel = mMapCanvas->mapUnitsPerPixel();
618 const int myWidth =
static_cast<int>( mMapCanvas->extent().width() / mapUnitsPerPixel );
619 const int myHeight =
static_cast<int>( mMapCanvas->extent().height() / mapUnitsPerPixel );
621 const QMap<int, QVariant> myPixelMap = mRasterLayer->dataProvider()->identify( myPoint,
Qgis::RasterIdentifyFormat::Value, myExtent, myWidth, myHeight ).results();
623 const QList<int> bands = renderer->
usesBands();
625 QList<double> values;
626 for (
int i = 0; i < bands.size(); ++i )
628 const int bandNo = bands.value( i );
629 if ( myPixelMap.count( bandNo ) == 1 )
635 const double value = myPixelMap.value( bandNo ).toDouble();
636 QgsDebugMsgLevel( QStringLiteral(
"value = %1" ).arg( value, 0,
'g', 17 ), 2 );
637 values.append( value );
641 tableTransparency->insertRow( tableTransparency->rowCount() );
643 switch ( mCurrentMode )
645 case Mode::SingleBand:
646 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::From ), values.value( 0 ) );
647 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::To ), values.value( 0 ) );
648 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::Opacity ), 100 );
651 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Red ), values.value( 0 ) );
652 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Green ), values.value( 1 ) );
653 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Blue ), values.value( 2 ) );
654 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Tolerance ), 0 );
655 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Opacity ), 100 );
664void QgsRasterTransparencyWidget::populateTransparencyTable(
QgsRasterRenderer *renderer )
676 const int nBands = renderer->
usesBands().size();
677 setupTransparencyTable( nBands );
680 if ( !rasterTransparency )
685 switch ( mCurrentMode )
687 case Mode::SingleBand:
690 for (
int i = 0; i < pixelList.size(); ++i )
692 tableTransparency->insertRow( i );
693 setTransparencyCell( i,
static_cast<int>( SingleBandTableColumns::From ), pixelList[i].min );
694 setTransparencyCell( i,
static_cast<int>( SingleBandTableColumns::To ), pixelList[i].max );
695 setTransparencyCell( i,
static_cast<int>( SingleBandTableColumns::Opacity ), 100 * ( 1 - pixelList[i].opacity ) );
697 if ( pixelList[i].min != pixelList[i].max )
699 setTransparencyToEdited( i );
707 for (
int i = 0; i < pixelList.size(); ++i )
709 tableTransparency->insertRow( i );
710 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Red ), pixelList[i].red );
711 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Green ), pixelList[i].green );
712 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Blue ), pixelList[i].blue );
713 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Opacity ), 100 * ( 1 - pixelList[i].opacity ) );
716 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Tolerance ), !
qgsDoubleNear( pixelList[i].fuzzyToleranceRed, 0 ) ? pixelList[i].fuzzyToleranceRed : 0 );
722 tableTransparency->resizeColumnsToContents();
723 tableTransparency->resizeRowsToContents();
726void QgsRasterTransparencyWidget::setupTransparencyTable(
int nBands )
728 tableTransparency->clear();
729 tableTransparency->setColumnCount( 0 );
730 tableTransparency->setRowCount( 0 );
731 mTransparencyToEdited.clear();
735 mCurrentMode = Mode::RgbBands;
736 tableTransparency->setColumnCount(
static_cast<int>( RgbBandTableColumns::ColumnCount ) );
737 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Red ),
new QTableWidgetItem( tr(
"Red" ) ) );
738 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Green ),
new QTableWidgetItem( tr(
"Green" ) ) );
739 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Blue ),
new QTableWidgetItem( tr(
"Blue" ) ) );
740 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Tolerance ),
new QTableWidgetItem( tr(
"Tolerance" ) ) );
741 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Opacity ),
new QTableWidgetItem( tr(
"Percent Transparent" ) ) );
745 mCurrentMode = Mode::SingleBand;
746 tableTransparency->setColumnCount(
static_cast<int>( SingleBandTableColumns::ColumnCount ) );
747 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( SingleBandTableColumns::From ),
new QTableWidgetItem( tr(
"From" ) ) );
748 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( SingleBandTableColumns::To ),
new QTableWidgetItem( tr(
"To" ) ) );
749 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( SingleBandTableColumns::Opacity ),
new QTableWidgetItem( tr(
"Percent Transparent" ) ) );
753void QgsRasterTransparencyWidget::setTransparencyCell(
int row,
int column,
double value )
755 QgsDebugMsgLevel( QStringLiteral(
"value = %1" ).arg( value, 0,
'g', 17 ), 2 );
756 QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
760 QLineEdit *lineEdit =
new QLineEdit();
761 lineEdit->setFrame(
false );
763 lineEdit->setContentsMargins( 1, 1, 1, 1 );
765 if ( column == tableTransparency->columnCount() - 1 )
769 lineEdit->setValidator(
new QIntValidator(
nullptr ) );
770 lineEdit->setText( QString::number(
static_cast<int>( value ) ) );
781 lineEdit->setValidator(
new QgsDoubleValidator(
nullptr ) );
782 if ( !std::isnan( value ) )
785 valueString = QLocale().toString( v );
789 lineEdit->setValidator(
new QIntValidator(
nullptr ) );
790 if ( !std::isnan( value ) )
792 valueString = QString::number(
static_cast<int>( value ) );
796 lineEdit->setText( valueString );
799 tableTransparency->setCellWidget( row, column, lineEdit );
800 adjustTransparencyCellWidth( row, column );
802 if ( mCurrentMode == Mode::SingleBand && ( column ==
static_cast<int>( SingleBandTableColumns::From ) || column ==
static_cast<int>( SingleBandTableColumns::To ) ) )
804 connect( lineEdit, &QLineEdit::textEdited,
this, &QgsRasterTransparencyWidget::transparencyCellTextEdited );
810void QgsRasterTransparencyWidget::adjustTransparencyCellWidth(
int row,
int column )
812 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( tableTransparency->cellWidget( row, column ) );
816 int width = std::max( lineEdit->fontMetrics().boundingRect( lineEdit->text() ).width() + 10, 100 );
817 width = std::max( width, tableTransparency->columnWidth( column ) );
819 lineEdit->setFixedWidth( width );
822void QgsRasterTransparencyWidget::setTransparencyToEdited(
int row )
824 if ( row >= mTransparencyToEdited.size() )
826 mTransparencyToEdited.resize( row + 1 );
828 mTransparencyToEdited[row] =
true;
831double QgsRasterTransparencyWidget::transparencyCellValue(
int row,
int column )
833 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( tableTransparency->cellWidget( row, column ) );
834 if ( !lineEdit || lineEdit->text().isEmpty() )
836 return std::numeric_limits<double>::quiet_NaN();
843 return mPixelSelectorTool;
@ Float32
Thirty two bit floating point (float).
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
@ Float64
Sixty four bit floating point (double).
@ Value
Numerical pixel value.
A custom validator which allows entry of doubles in a locale-tolerant way.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Map canvas is a class for displaying all GIS data types on a canvas.
Contains configuration for rendering maps.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
void bandChanged(int band)
Emitted when the currently selected band changes.
static QString printValue(double value, bool localized=false)
Print double value with all necessary significant digits.
Base class for raster data providers.
virtual bool sourceHasNoDataValue(int bandNo) const
Returns true if source band has no data value.
virtual bool useSourceNoDataValue(int bandNo) const
Returns the source nodata value usage.
Qgis::DataType sourceDataType(int bandNo) const override=0
Returns source data type for the band specified by number, source data type may be shorter than dataT...
virtual void setUseSourceNoDataValue(int bandNo, bool use)
Sets the source nodata value usage.
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
virtual int bandCount() const =0
Gets number of bands.
Represents a raster layer.
Property
Data definable properties.
@ RendererOpacity
Raster renderer global opacity.
static QgsPropertiesDefinition propertyDefinitions()
Returns the definitions for data defined properties available for use in raster pipes.
Represents a range of raster values between min and max, optionally including the min and max value.
Raster renderer pipe that applies colors to a raster.
QColor nodataColor() const
Returns the color to use for shading nodata pixels.
const QgsRasterTransparency * rasterTransparency() const
double opacity() const
Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
void setAlphaBand(int band)
void setOpacity(double opacity)
Sets the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
void setRasterTransparency(QgsRasterTransparency *t)
void setNodataColor(const QColor &color)
Sets the color to use for shading nodata pixels.
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
void setTransparentSingleValuePixelList(const QVector< QgsRasterTransparency::TransparentSingleValuePixel > &newList)
Sets the transparent single value pixel list, replacing the whole existing list.
QVector< QgsRasterTransparency::TransparentSingleValuePixel > transparentSingleValuePixelList() const
Returns the transparent single value pixel list.
void setTransparentThreeValuePixelList(const QVector< QgsRasterTransparency::TransparentThreeValuePixel > &newList)
Sets the transparent three value pixel list, replacing the whole existing list.
QVector< QgsRasterTransparency::TransparentThreeValuePixel > transparentThreeValuePixelList() const
Returns the transparent three value pixel list.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
#define QgsDebugMsgLevel(str, level)
QList< QgsRasterRange > QgsRasterRangeList
Defines the transparency for a range of single-band pixel values.
Defines the transparency for a RGB pixel value.