16#include <QIntValidator>
21#include <QRegularExpression>
25#include "moc_qgsrastertransparencywidget.cpp"
41 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
42 , mRasterLayer( layer )
43 , mMapCanvas( canvas )
46 connect( pbnAddValuesFromDisplay, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnAddValuesFromDisplay_clicked );
47 connect( pbnAddValuesManually, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnAddValuesManually_clicked );
48 connect( pbnDefaultValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnDefaultValues_clicked );
49 connect( pbnExportTransparentPixelValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnExportTransparentPixelValues_clicked );
50 connect( pbnImportTransparentPixelValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnImportTransparentPixelValues_clicked );
51 connect( pbnRemoveSelectedRow, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnRemoveSelectedRow_clicked );
53 mNodataColorButton->setShowNoColor(
true );
54 mNodataColorButton->setColorDialogTitle( tr(
"Select NoData Color" ) );
61 leNoDataValue->setValidator(
new QgsDoubleValidator( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max(),
this ) );
64 mPixelSelectorTool =
nullptr;
72 pbnAddValuesFromDisplay->setEnabled(
false );
89 expContext = canvas->createExpressionContext();
121 gboxNoDataValue->setEnabled(
false );
122 gboxCustomTransparency->setEnabled(
false );
125 cboxTransparencyBand->setShowNotSetOption(
true, tr(
"None" ) );
126 cboxTransparencyBand->setLayer( mRasterLayer );
133 lblSrcNoDataValue->setText( tr(
"not defined" ) );
140 mSrcNoDataValueCheckBox->setEnabled( enableSrcNoData );
141 lblSrcNoDataValue->setEnabled( enableSrcNoData );
147 mNodataColorButton->setColor( renderer->
nodataColor() );
149 mNodataColorButton->setToNull();
151 mOpacityWidget->setOpacity( renderer->
opacity() );
153 cboxTransparencyBand->setBand( renderer->
alphaBand() );
159 QgsDebugMsgLevel( QStringLiteral(
"noDataRangeList.size = %1" ).arg( noDataRangeList.size() ), 2 );
160 if ( !noDataRangeList.isEmpty() )
163 leNoDataValue->setText( QLocale().toString( v,
'g', 20 ) );
167 leNoDataValue->setText( QString() );
172 leNoDataValue->setText( QString() );
178 populateTransparencyTable( mRasterLayer->
renderer() );
181void QgsRasterTransparencyWidget::transparencyCellTextEdited(
const QString &text )
186 switch ( mCurrentMode )
188 case Mode::SingleBand:
190 QLineEdit *lineEdit = qobject_cast<QLineEdit *>( sender() );
195 for (
int r = 0; r < tableTransparency->rowCount(); r++ )
197 for (
int c = 0;
c < tableTransparency->columnCount();
c++ )
199 if ( tableTransparency->cellWidget( r,
c ) == sender() )
209 QgsDebugMsgLevel( QStringLiteral(
"row = %1 column =%2" ).arg( row ).arg( column ), 2 );
211 if ( column ==
static_cast< int >( SingleBandTableColumns::From ) )
213 QLineEdit *toLineEdit =
dynamic_cast<QLineEdit *
>( tableTransparency->cellWidget( row,
static_cast< int >( SingleBandTableColumns::To ) ) );
217 const bool toChanged = mTransparencyToEdited.value( row );
221 toLineEdit->setText( lineEdit->text() );
224 else if ( column ==
static_cast< int >( SingleBandTableColumns::To ) )
226 setTransparencyToEdited( row );
238void QgsRasterTransparencyWidget::pbnAddValuesFromDisplay_clicked()
240 if ( mMapCanvas && mPixelSelectorTool )
246void QgsRasterTransparencyWidget::pbnAddValuesManually_clicked()
254 tableTransparency->insertRow( tableTransparency->rowCount() );
257 switch ( mCurrentMode )
259 case Mode::SingleBand:
268 for (
int i = 0; i < n; i++ )
270 setTransparencyCell( tableTransparency->rowCount() - 1, i, std::numeric_limits<double>::quiet_NaN() );
273 switch ( mCurrentMode )
275 case Mode::SingleBand:
276 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( SingleBandTableColumns::Opacity ), 100 );
280 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( RgbBandTableColumns::Opacity ), 100 );
288void QgsRasterTransparencyWidget::pbnDefaultValues_clicked()
296 const int nBands = r->
usesBands().size();
298 setupTransparencyTable( nBands );
305void QgsRasterTransparencyWidget::pbnExportTransparentPixelValues_clicked()
308 const QString myLastDir = myQSettings.
value( QStringLiteral(
"lastRasterFileFilterDir" ), QDir::homePath() ).toString();
309 QString myFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Pixel Values as File" ), myLastDir, tr(
"Textfile" ) +
" (*.txt)" );
310 if ( !myFileName.isEmpty() )
312 if ( !myFileName.endsWith( QLatin1String(
".txt" ), Qt::CaseInsensitive ) )
314 myFileName = myFileName +
".txt";
317 QFile myOutputFile( myFileName );
318 if ( myOutputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
320 QTextStream myOutputStream( &myOutputFile );
321 myOutputStream <<
"# " << tr(
"QGIS Generated Transparent Pixel Value Export File" ) <<
'\n';
322 switch ( mCurrentMode )
326 myOutputStream <<
"#\n#\n# " << tr(
"Red" ) <<
"\t" << tr(
"Green" ) <<
"\t" << tr(
"Blue" ) <<
"\t" << tr(
"Percent Transparent" );
327 for (
int myTableRunner = 0; myTableRunner < tableTransparency->rowCount(); myTableRunner++ )
329 myOutputStream << '\n' << QString::number( transparencyCellValue( myTableRunner, static_cast< int >( RgbBandTableColumns::Red ) ) ) <<
"\t"
330 << QString::number( transparencyCellValue( myTableRunner,
static_cast< int >( RgbBandTableColumns::Green ) ) ) <<
"\t"
331 << QString::number( transparencyCellValue( myTableRunner,
static_cast< int >( RgbBandTableColumns::Blue ) ) ) <<
"\t"
332 << QString::number( transparencyCellValue( myTableRunner,
static_cast< int >( RgbBandTableColumns::Opacity ) ) );
336 case Mode::SingleBand:
338 myOutputStream <<
"#\n#\n# " << tr(
"Value" ) <<
"\t" << tr(
"Percent Transparent" );
340 for (
int myTableRunner = 0; myTableRunner < tableTransparency->rowCount(); myTableRunner++ )
342 myOutputStream << '\n' << QString::number( transparencyCellValue( myTableRunner, static_cast< int >( SingleBandTableColumns::From ) ) ) <<
"\t"
343 << QString::number( transparencyCellValue( myTableRunner,
static_cast< int >( SingleBandTableColumns::To ) ) ) <<
"\t"
344 << QString::number( transparencyCellValue( myTableRunner,
static_cast< int >( SingleBandTableColumns::Opacity ) ) );
352 QMessageBox::warning(
this, tr(
"Save Pixel Values as File" ), tr(
"Write access denied. Adjust the file permissions and try again.\n\n" ) );
357void QgsRasterTransparencyWidget::pbnImportTransparentPixelValues_clicked()
359 int myLineCounter = 0;
360 bool myImportError =
false;
363 const QString myLastDir = myQSettings.
value( QStringLiteral(
"lastRasterFileFilterDir" ), QDir::homePath() ).toString();
364 const QString myFileName = QFileDialog::getOpenFileName(
this, tr(
"Load Pixel Values from File" ), myLastDir, tr(
"Textfile" ) +
" (*.txt)" );
365 QFile myInputFile( myFileName );
367 const thread_local QRegularExpression sRxWhitespace(
"\\s+" );
369 if ( myInputFile.open( QFile::ReadOnly ) )
371 QTextStream myInputStream( &myInputFile );
373 switch ( mCurrentMode )
377 for (
int myTableRunner = tableTransparency->rowCount() - 1; myTableRunner >= 0; myTableRunner-- )
379 tableTransparency->removeRow( myTableRunner );
382 while ( !myInputStream.atEnd() )
385 myInputLine = myInputStream.readLine();
386 if ( !myInputLine.isEmpty() )
388 if ( !myInputLine.simplified().startsWith(
'#' ) )
390 QStringList myTokens = myInputLine.split( sRxWhitespace, Qt::SkipEmptyParts );
391 if ( myTokens.count() != 4 )
393 myImportError =
true;
394 myBadLines = myBadLines + QString::number( myLineCounter ) +
":\t[" + myInputLine +
"]\n";
398 tableTransparency->insertRow( tableTransparency->rowCount() );
399 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( RgbBandTableColumns::Red ), myTokens[0].toDouble() );
400 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( RgbBandTableColumns::Green ), myTokens[1].toDouble() );
401 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( RgbBandTableColumns::Blue ), myTokens[2].toDouble() );
402 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( RgbBandTableColumns::Tolerance ), 0 );
403 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( RgbBandTableColumns::Opacity ), myTokens[3].toDouble() );
410 case Mode::SingleBand:
412 for (
int myTableRunner = tableTransparency->rowCount() - 1; myTableRunner >= 0; myTableRunner-- )
414 tableTransparency->removeRow( myTableRunner );
417 while ( !myInputStream.atEnd() )
420 myInputLine = myInputStream.readLine();
421 if ( !myInputLine.isEmpty() )
423 if ( !myInputLine.simplified().startsWith(
'#' ) )
425 QStringList myTokens = myInputLine.split( sRxWhitespace, Qt::SkipEmptyParts );
426 if ( myTokens.count() != 3 && myTokens.count() != 2 )
428 myImportError =
true;
429 myBadLines = myBadLines + QString::number( myLineCounter ) +
":\t[" + myInputLine +
"]\n";
433 if ( myTokens.count() == 2 )
435 myTokens.insert( 1, myTokens[0] );
437 tableTransparency->insertRow( tableTransparency->rowCount() );
439 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( SingleBandTableColumns::From ), myTokens[0].toDouble() );
440 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( SingleBandTableColumns::To ), myTokens[1].toDouble() );
441 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast< int >( SingleBandTableColumns::Opacity ), myTokens[2].toDouble() );
452 QMessageBox::warning(
this, tr(
"Load Pixel Values from File" ), tr(
"The following lines contained errors\n\n%1" ).arg( myBadLines ) );
455 else if ( !myFileName.isEmpty() )
457 QMessageBox::warning(
this, tr(
"Load Pixel Values from File" ), tr(
"Read access denied. Adjust the file permissions and try again.\n\n" ) );
464void QgsRasterTransparencyWidget::pbnRemoveSelectedRow_clicked()
466 if ( 0 < tableTransparency->rowCount() )
468 tableTransparency->removeRow( tableTransparency->currentRow() );
484 if ( !leNoDataValue->text().isEmpty() )
486 bool myDoubleOk =
false;
490 const QgsRasterRange myNoDataRange( myNoDataValue, myNoDataValue );
491 myNoDataRangeList << myNoDataRange;
496 for (
int bandNo = 1; bandNo <= provider->
bandCount(); bandNo++ )
506 if ( rasterRenderer )
508 rasterRenderer->
setAlphaBand( cboxTransparencyBand->currentBand() );
513 switch ( mCurrentMode )
517 QVector<QgsRasterTransparency::TransparentThreeValuePixel> myTransparentThreeValuePixelList;
518 myTransparentThreeValuePixelList.reserve( tableTransparency->rowCount() );
519 for (
int myListRunner = 0; myListRunner < tableTransparency->rowCount(); myListRunner++ )
521 const double red = transparencyCellValue( myListRunner,
static_cast< int >( RgbBandTableColumns::Red ) );
522 const double green = transparencyCellValue( myListRunner,
static_cast< int >( RgbBandTableColumns::Green ) );
523 const double blue = transparencyCellValue( myListRunner,
static_cast< int >( RgbBandTableColumns::Blue ) );
524 const double opacity = 1.0 - transparencyCellValue( myListRunner,
static_cast< int >( RgbBandTableColumns::Opacity ) ) / 100.0;
525 const double tolerance = transparencyCellValue( myListRunner,
static_cast< int >( RgbBandTableColumns::Tolerance ) );
526 myTransparentThreeValuePixelList.append(
528 !
qgsDoubleNear( tolerance, 0 ) ? tolerance : 4 * std::numeric_limits<double>::epsilon(),
529 !
qgsDoubleNear( tolerance, 0 ) ? tolerance : 4 * std::numeric_limits<double>::epsilon(),
530 !
qgsDoubleNear( tolerance, 0 ) ? tolerance : 4 * std::numeric_limits<double>::epsilon() )
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 auto propertyOverrideButtons { findChildren< QgsPropertyOverrideButton * >() };
592void QgsRasterTransparencyWidget::updateProperty()
600void QgsRasterTransparencyWidget::pixelSelected(
const QgsPointXY &canvasPoint )
609 if ( mMapCanvas && mPixelSelectorTool && mRasterLayer->
dataProvider() )
618 const int myWidth =
static_cast< int >( mMapCanvas->
extent().
width() / mapUnitsPerPixel );
619 const int myHeight =
static_cast< int >( mMapCanvas->
extent().
height() / mapUnitsPerPixel );
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();
727void QgsRasterTransparencyWidget::setupTransparencyTable(
int nBands )
729 tableTransparency->clear();
730 tableTransparency->setColumnCount( 0 );
731 tableTransparency->setRowCount( 0 );
732 mTransparencyToEdited.clear();
736 mCurrentMode = Mode::RgbBands;
737 tableTransparency->setColumnCount(
static_cast< int >( RgbBandTableColumns::ColumnCount ) );
738 tableTransparency->setHorizontalHeaderItem(
static_cast< int >( RgbBandTableColumns::Red ),
new QTableWidgetItem( tr(
"Red" ) ) );
739 tableTransparency->setHorizontalHeaderItem(
static_cast< int >( RgbBandTableColumns::Green ),
new QTableWidgetItem( tr(
"Green" ) ) );
740 tableTransparency->setHorizontalHeaderItem(
static_cast< int >( RgbBandTableColumns::Blue ),
new QTableWidgetItem( tr(
"Blue" ) ) );
741 tableTransparency->setHorizontalHeaderItem(
static_cast< int >( RgbBandTableColumns::Tolerance ),
new QTableWidgetItem( tr(
"Tolerance" ) ) );
742 tableTransparency->setHorizontalHeaderItem(
static_cast< int >( RgbBandTableColumns::Opacity ),
new QTableWidgetItem( tr(
"Percent Transparent" ) ) );
746 mCurrentMode = Mode::SingleBand;
747 tableTransparency->setColumnCount(
static_cast< int >( SingleBandTableColumns::ColumnCount ) );
748 tableTransparency->setHorizontalHeaderItem(
static_cast< int >( SingleBandTableColumns::From ),
new QTableWidgetItem( tr(
"From" ) ) );
749 tableTransparency->setHorizontalHeaderItem(
static_cast< int >( SingleBandTableColumns::To ),
new QTableWidgetItem( tr(
"To" ) ) );
750 tableTransparency->setHorizontalHeaderItem(
static_cast< int >( SingleBandTableColumns::Opacity ),
new QTableWidgetItem( tr(
"Percent Transparent" ) ) );
754void QgsRasterTransparencyWidget::setTransparencyCell(
int row,
int column,
double value )
756 QgsDebugMsgLevel( QStringLiteral(
"value = %1" ).arg( value, 0,
'g', 17 ), 2 );
761 QLineEdit *lineEdit =
new QLineEdit();
762 lineEdit->setFrame(
false );
764 lineEdit->setContentsMargins( 1, 1, 1, 1 );
766 if ( column == tableTransparency->columnCount() - 1 )
770 lineEdit->setValidator(
new QIntValidator(
nullptr ) );
771 lineEdit->setText( QString::number(
static_cast<int>( value ) ) );
783 if ( !std::isnan( value ) )
786 valueString = QLocale().toString( v );
790 lineEdit->setValidator(
new QIntValidator(
nullptr ) );
791 if ( !std::isnan( value ) )
793 valueString = QString::number(
static_cast<int>( value ) );
797 lineEdit->setText( valueString );
800 tableTransparency->setCellWidget( row, column, lineEdit );
801 adjustTransparencyCellWidth( row, column );
803 if ( mCurrentMode == Mode::SingleBand && ( column ==
static_cast< int >( SingleBandTableColumns::From ) || column ==
static_cast< int >( SingleBandTableColumns::To ) ) )
805 connect( lineEdit, &QLineEdit::textEdited,
this, &QgsRasterTransparencyWidget::transparencyCellTextEdited );
811void QgsRasterTransparencyWidget::adjustTransparencyCellWidth(
int row,
int column )
813 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( tableTransparency->cellWidget( row, column ) );
817 int width = std::max( lineEdit->fontMetrics().boundingRect( lineEdit->text() ).width() + 10, 100 );
818 width = std::max( width, tableTransparency->columnWidth( column ) );
820 lineEdit->setFixedWidth( width );
823void QgsRasterTransparencyWidget::setTransparencyToEdited(
int row )
825 if ( row >= mTransparencyToEdited.size() )
827 mTransparencyToEdited.resize( row + 1 );
829 mTransparencyToEdited[row] =
true;
832double QgsRasterTransparencyWidget::transparencyCellValue(
int row,
int column )
834 QLineEdit *lineEdit =
dynamic_cast<QLineEdit *
>( tableTransparency->cellWidget( row, column ) );
835 if ( !lineEdit || lineEdit->text().isEmpty() )
837 return std::numeric_limits<double>::quiet_NaN();
844 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.
QgsDoubleValidator is a QLineEdit Validator that combines QDoubleValidator and QRegularExpressionVali...
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.
void unsetMapTool(QgsMapTool *mapTool)
Unset the current map tool or last non zoom tool.
void setMapTool(QgsMapTool *mapTool, bool clean=false)
Sets the map tool currently being used on the canvas.
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
The QgsMapSettings class contains configuration for rendering of the map.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
A class to represent a 2D point.
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.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
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 QgsRasterIdentifyResult identify(const QgsPointXY &point, Qgis::RasterIdentifyFormat format, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Identify raster value(s) found on the point position.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Returns a list of user no data value ranges.
virtual void setUserNoDataValue(int bandNo, const QgsRasterRangeList &noData)
QMap< int, QVariant > results() const
Returns the identify results.
virtual int bandCount() const =0
Gets number of bands.
Represents a raster layer.
QgsRasterPipe * pipe()
Returns the raster pipe.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the pipe's property collection, used for data defined overrides.
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.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the pipe's property collection, used for data defined overrides.
Raster values range container.
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.
A rectangle specified with double values.
double width() const
Returns the width of the rectangle.
double height() const
Returns the height of the rectangle.
This class is a composition of two QSettings instances:
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,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
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.