33#include <QIntValidator>
35#include <QRegularExpression>
40#include "moc_qgsrastertransparencywidget.cpp"
42using namespace Qt::StringLiterals;
46 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
47 , mRasterLayer( layer )
48 , mMapCanvas( canvas )
51 connect( pbnAddValuesFromDisplay, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnAddValuesFromDisplay_clicked );
52 connect( pbnAddValuesManually, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnAddValuesManually_clicked );
53 connect( pbnDefaultValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnDefaultValues_clicked );
54 connect( pbnExportTransparentPixelValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnExportTransparentPixelValues_clicked );
55 connect( pbnImportTransparentPixelValues, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnImportTransparentPixelValues_clicked );
56 connect( pbnRemoveSelectedRow, &QToolButton::clicked,
this, &QgsRasterTransparencyWidget::pbnRemoveSelectedRow_clicked );
58 mNodataColorButton->setShowNoColor(
true );
59 mNodataColorButton->setColorDialogTitle( tr(
"Select NoData Color" ) );
66 leNoDataValue->setValidator(
new QgsDoubleValidator( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max(),
this ) );
69 mPixelSelectorTool =
nullptr;
77 pbnAddValuesFromDisplay->setEnabled(
false );
94 expContext = canvas->createExpressionContext();
108 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
126 gboxNoDataValue->setEnabled(
false );
127 gboxCustomTransparency->setEnabled(
false );
130 cboxTransparencyBand->setShowNotSetOption(
true, tr(
"None" ) );
131 cboxTransparencyBand->setLayer( mRasterLayer );
138 lblSrcNoDataValue->setText( tr(
"not defined" ) );
145 mSrcNoDataValueCheckBox->setEnabled( enableSrcNoData );
146 lblSrcNoDataValue->setEnabled( enableSrcNoData );
152 mNodataColorButton->setColor( renderer->
nodataColor() );
154 mNodataColorButton->setToNull();
156 mOpacityWidget->setOpacity( renderer->
opacity() );
158 cboxTransparencyBand->setBand( renderer->
alphaBand() );
164 QgsDebugMsgLevel( u
"noDataRangeList.size = %1"_s.arg( noDataRangeList.size() ), 2 );
165 if ( !noDataRangeList.isEmpty() )
168 leNoDataValue->setText( QLocale().toString( v,
'g', 20 ) );
172 leNoDataValue->setText( QString() );
177 leNoDataValue->setText( QString() );
183 populateTransparencyTable( mRasterLayer->renderer() );
186void QgsRasterTransparencyWidget::transparencyCellTextEdited(
const QString &text )
191 switch ( mCurrentMode )
193 case Mode::SingleBand:
195 QLineEdit *lineEdit = qobject_cast<QLineEdit *>( sender() );
200 for (
int r = 0; r < tableTransparency->rowCount(); r++ )
202 for (
int c = 0;
c < tableTransparency->columnCount();
c++ )
204 if ( tableTransparency->cellWidget( r,
c ) == sender() )
216 if ( column ==
static_cast<int>( SingleBandTableColumns::From ) )
218 QLineEdit *toLineEdit =
dynamic_cast<QLineEdit *
>( tableTransparency->cellWidget( row,
static_cast<int>( SingleBandTableColumns::To ) ) );
222 const bool toChanged = mTransparencyToEdited.value( row );
226 toLineEdit->setText( lineEdit->text() );
229 else if ( column ==
static_cast<int>( SingleBandTableColumns::To ) )
231 setTransparencyToEdited( row );
243void QgsRasterTransparencyWidget::pbnAddValuesFromDisplay_clicked()
245 if ( mMapCanvas && mPixelSelectorTool )
247 mMapCanvas->setMapTool( mPixelSelectorTool );
251void QgsRasterTransparencyWidget::pbnAddValuesManually_clicked()
253 QgsRasterRenderer *renderer = mRasterLayer->renderer();
259 tableTransparency->insertRow( tableTransparency->rowCount() );
261 switch ( mCurrentMode )
263 case Mode::SingleBand:
264 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::From ), std::numeric_limits<double>::quiet_NaN() );
265 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::To ), std::numeric_limits<double>::quiet_NaN() );
266 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::Opacity ), 100 );
269 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Red ), std::numeric_limits<double>::quiet_NaN() );
270 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Green ), std::numeric_limits<double>::quiet_NaN() );
271 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Blue ), std::numeric_limits<double>::quiet_NaN() );
272 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Tolerance ), 0 );
273 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Opacity ), 100 );
281void QgsRasterTransparencyWidget::pbnDefaultValues_clicked()
283 QgsRasterRenderer *r = mRasterLayer->renderer();
289 const int nBands = r->
usesBands().size();
291 setupTransparencyTable( nBands );
297void QgsRasterTransparencyWidget::pbnExportTransparentPixelValues_clicked()
299 const QgsSettings myQSettings;
300 const QString myLastDir = myQSettings.
value( u
"lastRasterFileFilterDir"_s, QDir::homePath() ).toString();
301 QString myFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Pixel Values as File" ), myLastDir, tr(
"Textfile" ) +
" (*.txt)" );
302 if ( !myFileName.isEmpty() )
304 if ( !myFileName.endsWith(
".txt"_L1, Qt::CaseInsensitive ) )
306 myFileName = myFileName +
".txt";
309 QFile myOutputFile( myFileName );
310 if ( myOutputFile.open( QFile::WriteOnly | QIODevice::Truncate ) )
312 QTextStream myOutputStream( &myOutputFile );
313 myOutputStream <<
"# " << tr(
"QGIS Generated Transparent Pixel Value Export File" ) <<
'\n';
314 switch ( mCurrentMode )
318 myOutputStream <<
"#\n#\n# " << tr(
"Red" ) <<
"\t" << tr(
"Green" ) <<
"\t" << tr(
"Blue" ) <<
"\t" << tr(
"Percent Transparent" );
319 for (
int myTableRunner = 0; myTableRunner < tableTransparency->rowCount(); myTableRunner++ )
321 myOutputStream <<
'\n'
322 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( RgbBandTableColumns::Red ) ) ) <<
"\t"
323 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( RgbBandTableColumns::Green ) ) ) <<
"\t"
324 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( RgbBandTableColumns::Blue ) ) ) <<
"\t"
325 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( RgbBandTableColumns::Opacity ) ) );
329 case Mode::SingleBand:
331 myOutputStream <<
"#\n#\n# " << tr(
"Value" ) <<
"\t" << tr(
"Percent Transparent" );
333 for (
int myTableRunner = 0; myTableRunner < tableTransparency->rowCount(); myTableRunner++ )
335 myOutputStream <<
'\n'
336 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( SingleBandTableColumns::From ) ) ) <<
"\t"
337 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( SingleBandTableColumns::To ) ) ) <<
"\t"
338 << QString::number( transparencyCellValue( myTableRunner,
static_cast<int>( SingleBandTableColumns::Opacity ) ) );
346 QMessageBox::warning(
this, tr(
"Save Pixel Values as File" ), tr(
"Write access denied. Adjust the file permissions and try again.\n\n" ) );
351void QgsRasterTransparencyWidget::pbnImportTransparentPixelValues_clicked()
353 int myLineCounter = 0;
354 bool myImportError =
false;
356 const QgsSettings myQSettings;
357 const QString myLastDir = myQSettings.
value( u
"lastRasterFileFilterDir"_s, QDir::homePath() ).toString();
358 const QString myFileName = QFileDialog::getOpenFileName(
this, tr(
"Load Pixel Values from File" ), myLastDir, tr(
"Textfile" ) +
" (*.txt)" );
359 QFile myInputFile( myFileName );
361 const thread_local QRegularExpression sRxWhitespace(
"\\s+" );
363 if ( myInputFile.open( QFile::ReadOnly ) )
365 QTextStream myInputStream( &myInputFile );
367 switch ( mCurrentMode )
371 for (
int myTableRunner = tableTransparency->rowCount() - 1; myTableRunner >= 0; myTableRunner-- )
373 tableTransparency->removeRow( myTableRunner );
376 while ( !myInputStream.atEnd() )
379 myInputLine = myInputStream.readLine();
380 if ( !myInputLine.isEmpty() )
382 if ( !myInputLine.simplified().startsWith(
'#' ) )
384 QStringList myTokens = myInputLine.split( sRxWhitespace, Qt::SkipEmptyParts );
385 if ( myTokens.count() != 4 )
387 myImportError =
true;
388 myBadLines = myBadLines + QString::number( myLineCounter ) +
":\t[" + myInputLine +
"]\n";
392 tableTransparency->insertRow( tableTransparency->rowCount() );
393 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Red ), myTokens[0].toDouble() );
394 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Green ), myTokens[1].toDouble() );
395 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Blue ), myTokens[2].toDouble() );
396 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Tolerance ), 0 );
397 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Opacity ), myTokens[3].toDouble() );
404 case Mode::SingleBand:
406 for (
int myTableRunner = tableTransparency->rowCount() - 1; myTableRunner >= 0; myTableRunner-- )
408 tableTransparency->removeRow( myTableRunner );
411 while ( !myInputStream.atEnd() )
414 myInputLine = myInputStream.readLine();
415 if ( !myInputLine.isEmpty() )
417 if ( !myInputLine.simplified().startsWith(
'#' ) )
419 QStringList myTokens = myInputLine.split( sRxWhitespace, Qt::SkipEmptyParts );
420 if ( myTokens.count() != 3 && myTokens.count() != 2 )
422 myImportError =
true;
423 myBadLines = myBadLines + QString::number( myLineCounter ) +
":\t[" + myInputLine +
"]\n";
427 if ( myTokens.count() == 2 )
429 myTokens.insert( 1, myTokens[0] );
431 tableTransparency->insertRow( tableTransparency->rowCount() );
433 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::From ), myTokens[0].toDouble() );
434 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::To ), myTokens[1].toDouble() );
435 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::Opacity ), myTokens[2].toDouble() );
446 QMessageBox::warning(
this, tr(
"Load Pixel Values from File" ), tr(
"The following lines contained errors\n\n%1" ).arg( myBadLines ) );
449 else if ( !myFileName.isEmpty() )
451 QMessageBox::warning(
this, tr(
"Load Pixel Values from File" ), tr(
"Read access denied. Adjust the file permissions and try again.\n\n" ) );
458void QgsRasterTransparencyWidget::pbnRemoveSelectedRow_clicked()
460 if ( 0 < tableTransparency->rowCount() )
462 tableTransparency->removeRow( tableTransparency->currentRow() );
478 if ( !leNoDataValue->text().isEmpty() )
480 bool myDoubleOk =
false;
484 const QgsRasterRange myNoDataRange( myNoDataValue, myNoDataValue );
485 myNoDataRangeList << myNoDataRange;
490 for (
int bandNo = 1; bandNo <= provider->
bandCount(); bandNo++ )
500 if ( rasterRenderer )
502 rasterRenderer->
setAlphaBand( cboxTransparencyBand->currentBand() );
507 switch ( mCurrentMode )
511 QVector<QgsRasterTransparency::TransparentThreeValuePixel> myTransparentThreeValuePixelList;
512 myTransparentThreeValuePixelList.reserve( tableTransparency->rowCount() );
513 for (
int myListRunner = 0; myListRunner < tableTransparency->rowCount(); myListRunner++ )
515 const double red = transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Red ) );
516 const double green = transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Green ) );
517 const double blue = transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Blue ) );
518 const double opacity = 1.0 - transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Opacity ) ) / 100.0;
519 const double tolerance = transparencyCellValue( myListRunner,
static_cast<int>( RgbBandTableColumns::Tolerance ) );
520 myTransparentThreeValuePixelList.append(
527 case Mode::SingleBand:
529 QVector<QgsRasterTransparency::TransparentSingleValuePixel> myTransparentSingleValuePixelList;
530 myTransparentSingleValuePixelList.reserve( tableTransparency->rowCount() );
531 for (
int myListRunner = 0; myListRunner < tableTransparency->rowCount(); myListRunner++ )
533 const double min = transparencyCellValue( myListRunner,
static_cast<int>( SingleBandTableColumns::From ) );
534 const double max = transparencyCellValue( myListRunner,
static_cast<int>( SingleBandTableColumns::To ) );
535 const double opacity = 1.0 - transparencyCellValue( myListRunner,
static_cast<int>( SingleBandTableColumns::Opacity ) ) / 100.0;
537 myTransparentSingleValuePixelList.append(
549 rasterRenderer->
setOpacity( mOpacityWidget->opacity() );
555 button->blockSignals(
true );
559 button->blockSignals(
false );
564 const QList<QgsPropertyOverrideButton *> propertyOverrideButtons { findChildren<QgsPropertyOverrideButton *>() };
583void QgsRasterTransparencyWidget::updateProperty()
591void QgsRasterTransparencyWidget::pixelSelected(
const QgsPointXY &canvasPoint )
593 QgsRasterRenderer *renderer = mRasterLayer->renderer();
600 if ( mMapCanvas && mPixelSelectorTool && mRasterLayer->dataProvider() )
602 mMapCanvas->unsetMapTool( mPixelSelectorTool );
604 const QgsMapSettings &ms = mMapCanvas->mapSettings();
608 const double mapUnitsPerPixel = mMapCanvas->mapUnitsPerPixel();
609 const int myWidth =
static_cast<int>( mMapCanvas->extent().width() / mapUnitsPerPixel );
610 const int myHeight =
static_cast<int>( mMapCanvas->extent().height() / mapUnitsPerPixel );
612 const QMap<int, QVariant> myPixelMap = mRasterLayer->dataProvider()->identify( myPoint,
Qgis::RasterIdentifyFormat::Value, myExtent, myWidth, myHeight ).results();
614 const QList<int> bands = renderer->
usesBands();
616 QList<double> values;
617 for (
int i = 0; i < bands.size(); ++i )
619 const int bandNo = bands.value( i );
620 if ( myPixelMap.count( bandNo ) == 1 )
626 const double value = myPixelMap.value( bandNo ).toDouble();
628 values.append( value );
632 tableTransparency->insertRow( tableTransparency->rowCount() );
634 switch ( mCurrentMode )
636 case Mode::SingleBand:
637 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::From ), values.value( 0 ) );
638 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::To ), values.value( 0 ) );
639 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( SingleBandTableColumns::Opacity ), 100 );
642 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Red ), values.value( 0 ) );
643 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Green ), values.value( 1 ) );
644 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Blue ), values.value( 2 ) );
645 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Tolerance ), 0 );
646 setTransparencyCell( tableTransparency->rowCount() - 1,
static_cast<int>( RgbBandTableColumns::Opacity ), 100 );
655void QgsRasterTransparencyWidget::populateTransparencyTable(
QgsRasterRenderer *renderer )
667 const int nBands = renderer->
usesBands().size();
668 setupTransparencyTable( nBands );
671 if ( !rasterTransparency )
676 switch ( mCurrentMode )
678 case Mode::SingleBand:
681 for (
int i = 0; i < pixelList.size(); ++i )
683 tableTransparency->insertRow( i );
684 setTransparencyCell( i,
static_cast<int>( SingleBandTableColumns::From ), pixelList[i].min );
685 setTransparencyCell( i,
static_cast<int>( SingleBandTableColumns::To ), pixelList[i].max );
686 setTransparencyCell( i,
static_cast<int>( SingleBandTableColumns::Opacity ), 100 * ( 1 - pixelList[i].opacity ) );
688 if ( pixelList[i].min != pixelList[i].max )
690 setTransparencyToEdited( i );
698 for (
int i = 0; i < pixelList.size(); ++i )
700 tableTransparency->insertRow( i );
701 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Red ), pixelList[i].red );
702 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Green ), pixelList[i].green );
703 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Blue ), pixelList[i].blue );
704 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Opacity ), 100 * ( 1 - pixelList[i].opacity ) );
707 setTransparencyCell( i,
static_cast<int>( RgbBandTableColumns::Tolerance ), !
qgsDoubleNear( pixelList[i].fuzzyToleranceRed, 0 ) ? pixelList[i].fuzzyToleranceRed : 0 );
713 tableTransparency->resizeColumnsToContents();
714 tableTransparency->resizeRowsToContents();
717void QgsRasterTransparencyWidget::setupTransparencyTable(
int nBands )
719 tableTransparency->clear();
720 tableTransparency->setColumnCount( 0 );
721 tableTransparency->setRowCount( 0 );
722 mTransparencyToEdited.clear();
726 mCurrentMode = Mode::RgbBands;
727 tableTransparency->setColumnCount(
static_cast<int>( RgbBandTableColumns::ColumnCount ) );
728 tableTransparency->horizontalHeader()->setSectionResizeMode(
static_cast<int>( RgbBandTableColumns::Red ), QHeaderView::Stretch );
729 tableTransparency->horizontalHeader()->setSectionResizeMode(
static_cast<int>( RgbBandTableColumns::Green ), QHeaderView::Stretch );
730 tableTransparency->horizontalHeader()->setSectionResizeMode(
static_cast<int>( RgbBandTableColumns::Blue ), QHeaderView::Stretch );
731 tableTransparency->horizontalHeader()->setSectionResizeMode(
static_cast<int>( RgbBandTableColumns::Tolerance ), QHeaderView::Stretch );
732 tableTransparency->horizontalHeader()->setSectionResizeMode(
static_cast<int>( RgbBandTableColumns::Opacity ), QHeaderView::Stretch );
733 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Red ),
new QTableWidgetItem( tr(
"Red" ) ) );
734 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Green ),
new QTableWidgetItem( tr(
"Green" ) ) );
735 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Blue ),
new QTableWidgetItem( tr(
"Blue" ) ) );
736 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Tolerance ),
new QTableWidgetItem( tr(
"Tolerance" ) ) );
737 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( RgbBandTableColumns::Opacity ),
new QTableWidgetItem( tr(
"Opacity [%]" ) ) );
741 mCurrentMode = Mode::SingleBand;
742 tableTransparency->setColumnCount(
static_cast<int>( SingleBandTableColumns::ColumnCount ) );
743 tableTransparency->horizontalHeader()->setSectionResizeMode(
static_cast<int>( SingleBandTableColumns::From ), QHeaderView::Stretch );
744 tableTransparency->horizontalHeader()->setSectionResizeMode(
static_cast<int>( SingleBandTableColumns::To ), QHeaderView::Stretch );
745 tableTransparency->horizontalHeader()->setSectionResizeMode(
static_cast<int>( SingleBandTableColumns::Opacity ), QHeaderView::Stretch );
746 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( SingleBandTableColumns::From ),
new QTableWidgetItem( tr(
"From" ) ) );
747 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( SingleBandTableColumns::To ),
new QTableWidgetItem( tr(
"To" ) ) );
748 tableTransparency->setHorizontalHeaderItem(
static_cast<int>( SingleBandTableColumns::Opacity ),
new QTableWidgetItem( tr(
"Opacity [%]" ) ) );
752void QgsRasterTransparencyWidget::setTransparencyCell(
int row,
int column,
double value )
755 QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
759 QLineEdit *lineEdit =
new QLineEdit();
761 lineEdit->setFrame(
false );
763 lineEdit->setContentsMargins( 1, 1, 1, 1 );
764 lineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
766 if ( column == tableTransparency->columnCount() - 1 )
770 lineEdit->setValidator(
new QIntValidator(
nullptr ) );
771 lineEdit->setText( QString::number(
static_cast<int>( value ) ) );
782 lineEdit->setValidator(
new QgsDoubleValidator(
nullptr ) );
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 );
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.