40 #include <QPushButton> 
   41 #include <QInputDialog> 
   42 #include <QFileDialog> 
   44 #include <QMessageBox> 
   45 #include <QTextStream> 
   55   mLoadFromBandButton->setVisible( 
false ); 
 
   57   connect( mAddEntryButton, &QPushButton::clicked, 
this, &QgsColorRampShaderWidget::mAddEntryButton_clicked );
 
   58   connect( mDeleteEntryButton, &QPushButton::clicked, 
this, &QgsColorRampShaderWidget::mDeleteEntryButton_clicked );
 
   59   connect( mLoadFromBandButton, &QPushButton::clicked, 
this, &QgsColorRampShaderWidget::mLoadFromBandButton_clicked );
 
   60   connect( mLoadFromFileButton, &QPushButton::clicked, 
this, &QgsColorRampShaderWidget::mLoadFromFileButton_clicked );
 
   61   connect( mExportToFileButton, &QPushButton::clicked, 
this, &QgsColorRampShaderWidget::mExportToFileButton_clicked );
 
   62   connect( mUnitLineEdit, &QLineEdit::textEdited, 
this, &QgsColorRampShaderWidget::mUnitLineEdit_textEdited );
 
   63   connect( mColormapTreeWidget, &QTreeWidget::itemDoubleClicked, 
this, &QgsColorRampShaderWidget::mColormapTreeWidget_itemDoubleClicked );
 
   64   connect( mColorInterpolationComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsColorRampShaderWidget::mColorInterpolationComboBox_currentIndexChanged );
 
   65   connect( mClassificationModeComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsColorRampShaderWidget::mClassificationModeComboBox_currentIndexChanged );
 
   67   connect( mLegendSettingsButton, &QPushButton::clicked, 
this, &QgsColorRampShaderWidget::showLegendSettings );
 
   69   contextMenu = 
new QMenu( tr( 
"Options" ), 
this );
 
   70   contextMenu->addAction( tr( 
"Change Color…" ), 
this, SLOT( changeColor() ) );
 
   71   contextMenu->addAction( tr( 
"Change Opacity…" ), 
this, SLOT( changeOpacity() ) );
 
   74   mValueDelegate = 
new QgsLocaleAwareNumericLineEditDelegate( Qgis::DataType::UnknownDataType, 
this );
 
   75   mColormapTreeWidget->setItemDelegateForColumn( ValueColumn, mValueDelegate );
 
   77 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) 
   78   mColormapTreeWidget->setColumnWidth( ColorColumn, 
Qgis::UI_SCALE_FACTOR * fontMetrics().width( 
'X' ) * 6.6 );
 
   80   mColormapTreeWidget->setColumnWidth( ColorColumn, 
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 
'X' ) * 6.6 );
 
   83   mColormapTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
 
   84   mColormapTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
 
   85   connect( mColormapTreeWidget, &QTreeView::customContextMenuRequested, 
this, [ = ]( QPoint ) { contextMenu->exec( QCursor::pos() ); } );
 
   87   QString defaultPalette = settings.
value( QStringLiteral( 
"Raster/defaultPalette" ), 
"" ).toString();
 
   88   btnColorRamp->setColorRampFromName( defaultPalette );
 
  100   mNumberOfEntriesSpinBox->setValue( 5 ); 
 
  102   mClassificationModeComboBox_currentIndexChanged( 0 );
 
  104   resetClassifyButton();
 
  112   connect( mLabelPrecisionSpinBox, qgis::overload<int>::of( &QSpinBox::valueChanged ), 
this, [ = ]( 
int )
 
  126   mRasterDataProvider = dp;
 
  127   mLoadFromBandButton->setVisible( 
bool( mRasterDataProvider ) ); 
 
  134   Qgis::DataType dataType { ( mRasterDataProvider &&mBand > 0 ) ? mRasterDataProvider->
dataType( mBand ) : Qgis::DataType::Float64 };
 
  138   mLabelPrecisionSpinBox->setMaximum( maxDigits );
 
  139   mValueDelegate->setDataType( dataType );
 
  153   colorRampShader.
setClip( mClipCheckBox->isChecked() );
 
  156   QList<QgsColorRampShader::ColorRampItem> colorRampItems;
 
  157   int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
 
  158   QTreeWidgetItem *currentItem = 
nullptr;
 
  159   for ( 
int i = 0; i < topLevelItemCount; ++i )
 
  161     currentItem = mColormapTreeWidget->topLevelItem( i );
 
  167     newColorRampItem.
value = currentItem->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toDouble();
 
  168     newColorRampItem.
color = currentItem->data( ColorColumn, Qt::ItemDataRole::EditRole ).value<QColor>();
 
  169     newColorRampItem.
label = currentItem->text( LabelColumn );
 
  170     colorRampItems.append( newColorRampItem );
 
  173   std::sort( colorRampItems.begin(), colorRampItems.end() );
 
  176   if ( !btnColorRamp->isNull() )
 
  182   return colorRampShader;
 
  185 void QgsColorRampShaderWidget::autoLabel()
 
  188   mColormapTreeWidget->sortItems( ValueColumn, Qt::AscendingOrder );
 
  194   const QString unit = mUnitLineEdit->text();
 
  195   int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
 
  197   QTreeWidgetItem *currentItem = 
nullptr;
 
  198   for ( 
int i = 0; i < topLevelItemCount; ++i )
 
  200     currentItem = mColormapTreeWidget->topLevelItem( i );
 
  202     if ( !currentItem || currentItem->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toString().isEmpty() )
 
  207     const QString lbl = createLabel( currentItem, i, unit );
 
  209     if ( currentItem->text( LabelColumn ).isEmpty() || currentItem->text( LabelColumn ) == lbl || currentItem->foreground( LabelColumn ).color() == QColor( Qt::gray ) )
 
  211       currentItem->setText( LabelColumn, lbl );
 
  212       currentItem->setForeground( LabelColumn, QBrush( QColor( Qt::gray ) ) );
 
  218 void QgsColorRampShaderWidget::setUnitFromLabels()
 
  220   QStringList allSuffixes;
 
  222   int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
 
  223   QTreeWidgetItem *currentItem = 
nullptr;
 
  224   for ( 
int i = 0; i < topLevelItemCount; ++i )
 
  226     currentItem = mColormapTreeWidget->topLevelItem( i );
 
  228     if ( !currentItem || currentItem->text( ValueColumn ).isEmpty() )
 
  233     label = createLabel( currentItem, i, QString() );
 
  235     if ( currentItem->text( LabelColumn ).startsWith( label ) )
 
  237       allSuffixes.append( currentItem->text( LabelColumn ).mid( label.length() ) );
 
  241   QStringList suffixes = QStringList( allSuffixes );
 
  242   suffixes.removeDuplicates();
 
  245   for ( 
int i = 0; i < suffixes.count(); ++i )
 
  247     int n = allSuffixes.count( suffixes[i] );
 
  257     mUnitLineEdit->setText( unit );
 
  262 void QgsColorRampShaderWidget::dumpClasses()
 
  264   for ( 
int row = 0; row < mColormapTreeWidget->model()->rowCount(); ++row )
 
  266     const auto labelData { mColormapTreeWidget->model()->itemData( mColormapTreeWidget->model()->index( row, LabelColumn ) ) };
 
  267     const auto valueData { mColormapTreeWidget->model()->itemData( mColormapTreeWidget->model()->index( row, ValueColumn ) ) };
 
  269                       .arg( labelData[ Qt::ItemDataRole::DisplayRole ].toString(),
 
  270                             valueData[ Qt::ItemDataRole::DisplayRole ].toString() ), 2 );
 
  275 void QgsColorRampShaderWidget::mAddEntryButton_clicked()
 
  278   newItem->
setData( ValueColumn, Qt::ItemDataRole::DisplayRole, 0 );
 
  279   newItem->
setData( ColorColumn, Qt::ItemDataRole::EditRole, QColor( Qt::magenta ) );
 
  280   newItem->setText( LabelColumn, QString() );
 
  281   newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
 
  283            this, &QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited );
 
  291 void QgsColorRampShaderWidget::mDeleteEntryButton_clicked()
 
  293   QList<QTreeWidgetItem *> itemList;
 
  294   itemList = mColormapTreeWidget->selectedItems();
 
  295   if ( itemList.isEmpty() )
 
  300   const auto constItemList = itemList;
 
  301   for ( QTreeWidgetItem *item : constItemList )
 
  313   std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
 
  314   if ( !ramp || std::isnan( mMin ) || std::isnan( mMax ) )
 
  327   colorRampShader->classifyColorRamp( mNumberOfEntriesSpinBox->value(),
 
  330                                       mRasterDataProvider );
 
  331   colorRampShader->setClip( mClipCheckBox->isChecked() );
 
  333   mColormapTreeWidget->clear();
 
  335   const QList<QgsColorRampShader::ColorRampItem> colorRampItemList = colorRampShader->colorRampItemList();
 
  336   QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItemList.constBegin();
 
  337   for ( ; it != colorRampItemList.end(); ++it )
 
  340     newItem->
setData( ValueColumn, Qt::ItemDataRole::DisplayRole, it->value );
 
  341     newItem->
setData( ColorColumn, Qt::ItemDataRole::EditRole, it->color );
 
  342     newItem->setText( LabelColumn, QString() ); 
 
  343     newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
 
  345              this, &QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited );
 
  348   mClipCheckBox->setChecked( colorRampShader->clip() );
 
  354 void QgsColorRampShaderWidget::mClassificationModeComboBox_currentIndexChanged( 
int index )
 
  361 void QgsColorRampShaderWidget::updateColorRamp()
 
  363   std::unique_ptr< QgsColorRamp > ramp( 
shader().createColorRamp() );
 
  367 void QgsColorRampShaderWidget::applyColorRamp()
 
  369   std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
 
  375   if ( !btnColorRamp->colorRampName().isEmpty() )
 
  379     settings.
setValue( QStringLiteral( 
"Raster/defaultPalette" ), btnColorRamp->colorRampName() );
 
  382   bool enableContinuous = ( ramp->count() > 0 );
 
  383   mClassificationModeComboBox->setEnabled( enableContinuous );
 
  384   if ( !enableContinuous )
 
  389   int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
 
  390   if ( topLevelItemCount > 0 )
 
  394     if ( std::isnan( mMin ) || std::isnan( mMax ) )
 
  396       colormapMinMax( min, max );
 
  405     QTreeWidgetItem *currentItem = 
nullptr;
 
  406     for ( 
int i = 0; i < topLevelItemCount; ++i )
 
  408       currentItem = mColormapTreeWidget->topLevelItem( i );
 
  414       double value = currentItem->data( ValueColumn, Qt::ItemDataRole::EditRole ).toDouble( );
 
  415       double position = ( value - min ) / ( max - min );
 
  429   mColormapTreeWidget->clear();
 
  430   QList<QgsColorRampShader::ColorRampItem>::const_iterator it = colorRampItems.constBegin();
 
  432   for ( ; it != colorRampItems.constEnd(); ++it )
 
  435     newItem->
setData( ValueColumn, Qt::ItemDataRole::DisplayRole, it->value );
 
  436     newItem->
setData( ColorColumn, Qt::ItemDataRole::EditRole, it->color );
 
  437     newItem->setText( LabelColumn, it->label );
 
  438     newItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable );
 
  440              this, &QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited );
 
  451   const QString unit = mUnitLineEdit->text();
 
  452   for ( i = 0; i < mColormapTreeWidget->topLevelItemCount(); i++ )
 
  455     QString lbl { createLabel( currentItem, i, unit )};
 
  456     if ( currentItem->text( LabelColumn ).isEmpty() || currentItem->text( LabelColumn ) == lbl || currentItem->foreground( LabelColumn ).color() == QColor( Qt::gray ) )
 
  458       currentItem->setText( LabelColumn, lbl );
 
  459       currentItem->setForeground( LabelColumn, QBrush( QColor( Qt::gray ) ) );
 
  465 void QgsColorRampShaderWidget::mLoadFromBandButton_clicked()
 
  467   if ( !mRasterDataProvider )
 
  470   QList<QgsColorRampShader::ColorRampItem> colorRampList = mRasterDataProvider->
colorTable( mBand );
 
  471   if ( !colorRampList.isEmpty() )
 
  478     QMessageBox::warning( 
this, tr( 
"Load Color Map" ), tr( 
"The color map for band %1 has no entries." ).arg( mBand ) );
 
  484 void QgsColorRampShaderWidget::mLoadFromFileButton_clicked()
 
  487   QString lastDir = settings.
value( QStringLiteral( 
"lastColorMapDir" ), QDir::homePath() ).toString();
 
  488   const QString fileName = QFileDialog::getOpenFileName( 
this, tr( 
"Load Color Map from File" ), lastDir, tr( 
"Textfile (*.txt)" ) );
 
  489   if ( fileName.isEmpty() )
 
  492   QList<QgsColorRampShader::ColorRampItem> colorRampItems;
 
  498     mColormapTreeWidget->clear();
 
  500     mColorInterpolationComboBox->setCurrentIndex( mColorInterpolationComboBox->findData( type ) );
 
  504     if ( !errors.empty() )
 
  506       QMessageBox::warning( 
this, tr( 
"Load Color Map from File" ), tr( 
"The following lines contained errors\n\n" ) +  errors.join( 
'\n' ) );
 
  511     const QString error = tr( 
"An error occurred while reading the color map\n\n" ) + errors.join( 
'\n' );
 
  512     QMessageBox::warning( 
this, tr( 
"Load Color Map from File" ), error );
 
  515   QFileInfo fileInfo( fileName );
 
  516   settings.
setValue( QStringLiteral( 
"lastColorMapDir" ), fileInfo.absoluteDir().absolutePath() );
 
  522 void QgsColorRampShaderWidget::mExportToFileButton_clicked()
 
  525   QString lastDir = settings.
value( QStringLiteral( 
"lastColorMapDir" ), QDir::homePath() ).toString();
 
  526   QString fileName = QFileDialog::getSaveFileName( 
this, tr( 
"Save Color Map as File" ), lastDir, tr( 
"Textfile (*.txt)" ) );
 
  527   if ( fileName.isEmpty() )
 
  532   QList<QgsColorRampShader::ColorRampItem> colorRampItems;
 
  533   int topLevelItemCount = mColormapTreeWidget->topLevelItemCount();
 
  534   for ( 
int i = 0; i < topLevelItemCount; ++i )
 
  536     QTreeWidgetItem *currentItem = mColormapTreeWidget->topLevelItem( i );
 
  543     item.
value = currentItem->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toDouble( );
 
  544     item.
color = currentItem->data( ColorColumn, Qt::ItemDataRole::EditRole ).value<QColor>();
 
  545     item.
label = currentItem->text( LabelColumn );
 
  546     colorRampItems << item;
 
  551     QMessageBox::warning( 
this, tr( 
"Save Color Map as File" ), tr( 
"Write access denied. Adjust the file permissions and try again.\n\n" ) );
 
  554   QFileInfo fileInfo( fileName );
 
  555   settings.
setValue( QStringLiteral( 
"lastColorMapDir" ), fileInfo.absoluteDir().absolutePath() );
 
  558 void QgsColorRampShaderWidget::mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem *item, 
int column )
 
  565   if ( column == LabelColumn )
 
  568     item->setForeground( LabelColumn, QBrush() );
 
  572 void QgsColorRampShaderWidget::mColormapTreeWidget_itemEdited( QTreeWidgetItem *item, 
int column )
 
  610   whileBlocking( mColorInterpolationComboBox )->setCurrentIndex( mColorInterpolationComboBox->findData( colorRampShader.
colorRampType() ) );
 
  611   mColorInterpolationComboBox_currentIndexChanged( mColorInterpolationComboBox->currentIndex() );
 
  613   mClassificationModeComboBox_currentIndexChanged( mClassificationModeComboBox->currentIndex() );
 
  623     QString defaultPalette = settings.
value( QStringLiteral( 
"/Raster/defaultPalette" ), 
"Spectral" ).toString();
 
  624     btnColorRamp->setColorRampFromName( defaultPalette );
 
  627   mLabelPrecisionSpinBox->setValue( colorRampShader.
labelPrecision() );
 
  637 void QgsColorRampShaderWidget::mColorInterpolationComboBox_currentIndexChanged( 
int index )
 
  644   QString valueToolTip;
 
  645   switch ( interpolation )
 
  648       valueLabel = tr( 
"Value" );
 
  649       valueToolTip = tr( 
"Value for color stop" );
 
  650       mLegendSettingsButton->setEnabled( 
true );
 
  653       valueLabel = tr( 
"Value <=" );
 
  654       valueToolTip = tr( 
"Maximum value for class" );
 
  655       mLegendSettingsButton->setEnabled( 
false );
 
  658       valueLabel = tr( 
"Value =" );
 
  659       valueToolTip = tr( 
"Value for color" );
 
  660       mLegendSettingsButton->setEnabled( 
false );
 
  664   QTreeWidgetItem *header = mColormapTreeWidget->headerItem();
 
  665   header->setText( ValueColumn, valueLabel );
 
  666   header->setToolTip( ValueColumn, valueToolTip );
 
  685   resetClassifyButton();
 
  698 bool QgsColorRampShaderWidget::colormapMinMax( 
double &min, 
double &max )
 const 
  700   QTreeWidgetItem *item = mColormapTreeWidget->topLevelItem( 0 );
 
  708   if ( ! std::isnan( mMin ) && ! std::isnan( mMax ) && 
static_cast< QgsColorRampShader::Type >( mColorInterpolationComboBox->currentData().toInt() ) == QgsColorRampShader::Type::Discrete )
 
  715     min = item->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toDouble();
 
  716     item = mColormapTreeWidget->topLevelItem( mColormapTreeWidget->topLevelItemCount() - 1 );
 
  717     max = item->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toDouble();
 
  724   double min = 0, max = 0;
 
  725   if ( ! colormapMinMax( min, max ) )
 
  738 void QgsColorRampShaderWidget::resetClassifyButton()
 
  740   mClassifyButton->setEnabled( 
true );
 
  741   if ( std::isnan( mMin ) || std::isnan( mMax ) || mMin >= mMax )
 
  743     mClassifyButton->setEnabled( 
false );
 
  747 QString QgsColorRampShaderWidget::createLabel( QTreeWidgetItem *currentItem, 
int row, 
const QString unit )
 
  749   auto applyPrecision = [ = ]( 
const QString & value )
 
  751     double val { value.toDouble( ) };
 
  752     Qgis::DataType dataType { mRasterDataProvider ? mRasterDataProvider->
dataType( mBand ) : Qgis::DataType::Float64 };
 
  755       case Qgis::DataType::Int16:
 
  756       case Qgis::DataType::UInt16:
 
  757       case Qgis::DataType::Int32:
 
  758       case Qgis::DataType::UInt32:
 
  759       case Qgis::DataType::Byte:
 
  760       case Qgis::DataType::CInt16:
 
  761       case Qgis::DataType::CInt32:
 
  762       case Qgis::DataType::ARGB32:
 
  763       case Qgis::DataType::ARGB32_Premultiplied:
 
  765         return QLocale().toString( std::round( val ), 
'f', 0 );
 
  767       case Qgis::DataType::Float32:
 
  768       case Qgis::DataType::CFloat32:
 
  770         if ( mLabelPrecisionSpinBox->value() <  0 )
 
  772           const double factor = std::pow( 10, - mLabelPrecisionSpinBox->value() );
 
  773           val = 
static_cast<qlonglong
>( val / factor ) * factor;
 
  774           return QLocale().toString( val, 
'f', 0 );
 
  776         return QLocale().toString( val, 
'f', mLabelPrecisionSpinBox->value() );
 
  778       case Qgis::DataType::Float64:
 
  779       case Qgis::DataType::CFloat64:
 
  780       case Qgis::DataType::UnknownDataType:
 
  782         if ( mLabelPrecisionSpinBox->value() <  0 )
 
  784           const double factor = std::pow( 10, - mLabelPrecisionSpinBox->value() );
 
  785           val = 
static_cast<qlonglong
>( val / factor ) * factor;
 
  786           return QLocale().toString( val, 
'f', 0 );
 
  788         return QLocale().toString( val, 
'f', mLabelPrecisionSpinBox->value() );
 
  802       lbl = 
"<= " + applyPrecision( currentItem->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toString() ) + unit;
 
  804     else if ( currentItem->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toDouble( ) == std::numeric_limits<double>::infinity() )
 
  806       lbl = 
"> " + applyPrecision( mColormapTreeWidget->topLevelItem( row - 1 )->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toString() ) + unit;
 
  810       lbl = applyPrecision( mColormapTreeWidget->topLevelItem( row - 1 )->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toString() ) + 
" - " + applyPrecision( currentItem->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toString() ) + unit;
 
  815     lbl = applyPrecision( currentItem->data( ValueColumn, Qt::ItemDataRole::DisplayRole ).toString() ) + unit;
 
  822 void QgsColorRampShaderWidget::changeColor()
 
  824   QList<QTreeWidgetItem *> itemList;
 
  825   itemList = mColormapTreeWidget->selectedItems();
 
  826   if ( itemList.isEmpty() )
 
  830   QTreeWidgetItem *firstItem = itemList.first();
 
  832   QColor currentColor = firstItem->data( ColorColumn, Qt::ItemDataRole::EditRole ).value<QColor>();
 
  834   if ( panel && panel->dockMode() )
 
  841       for ( QTreeWidgetItem *item : qgis::as_const( itemList ) )
 
  843         item->setData( ColorColumn, Qt::ItemDataRole::EditRole, newColor );
 
  849     panel->openPanel( colorWidget );
 
  855     if ( newColor.isValid() )
 
  857       for ( QTreeWidgetItem *item : qgis::as_const( itemList ) )
 
  859         item->setData( ColorColumn, Qt::ItemDataRole::EditRole, newColor );
 
  868 void QgsColorRampShaderWidget::changeOpacity()
 
  870   QList<QTreeWidgetItem *> itemList;
 
  871   itemList = mColormapTreeWidget->selectedItems();
 
  872   if ( itemList.isEmpty() )
 
  876   QTreeWidgetItem *firstItem = itemList.first();
 
  879   double oldOpacity = firstItem->data( ColorColumn, Qt::ItemDataRole::EditRole ).value<QColor>().alpha() / 255 * 100;
 
  880   double opacity = QInputDialog::getDouble( 
this, tr( 
"Opacity" ), tr( 
"Change color opacity [%]" ), oldOpacity, 0.0, 100.0, 0, &ok );
 
  883     int newOpacity = 
static_cast<int>( opacity / 100 * 255 );
 
  884     const auto constItemList = itemList;
 
  885     for ( QTreeWidgetItem *item : constItemList )
 
  887       QColor newColor = item->data( ColorColumn, Qt::ItemDataRole::EditRole ).value<QColor>();
 
  888       newColor.setAlpha( newOpacity );
 
  889       item->setData( ColorColumn, Qt::ItemDataRole::EditRole, newColor );
 
  897 void QgsColorRampShaderWidget::showLegendSettings()
 
  907       mLegendSettings = legendPanel->
settings();
 
  915     dialog.setWindowTitle( tr( 
"Legend Settings" ) );
 
  918       mLegendSettings = dialog.settings();
 
DataType
Raster data types.
static const double UI_SCALE_FACTOR
UI scaling factor.
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), bool allowOpacity=false)
Returns a color selection from a color dialog.
A dialog for configuring a QgsColorRampLegendNode (QgsColorRampLegendNodeSettings).
Settings for a color ramp legend node.
A ramp shader will color a raster pixel based on a list of values ranges in a ramp.
QList< QgsColorRampShader::ColorRampItem > colorRampItemList() const
Returns the custom colormap.
ClassificationMode classificationMode() const
Returns the classification mode.
const QgsColorRampLegendNodeSettings * legendSettings() const
Returns the color ramp shader legend settings.
Type colorRampType() const
Returns the color ramp type.
void setSourceColorRamp(QgsColorRamp *colorramp)
Set the source color ramp.
ClassificationMode
Classification modes used to create the color ramp shader.
@ EqualInterval
Uses equal interval.
@ Quantile
Uses quantile (i.e. equal pixel) count.
@ Continuous
Uses breaks from color palette.
void setClip(bool clip)
Sets whether the shader should not render values out of range.
bool clip() const
Returns whether the shader will clip values which are out of range.
QgsColorRamp * sourceColorRamp() const
Returns the source color ramp.
Type
Supported methods for color interpolation.
@ Interpolated
Interpolates the color between two class breaks linearly.
@ Discrete
Assigns the color of the higher class for every pixel between two class breaks.
@ Exact
Assigns the color of the exact matching value in the color ramp item list.
void setClassificationMode(ClassificationMode classificationMode)
Sets classification mode.
void setColorRampItemList(const QList< QgsColorRampShader::ColorRampItem > &list)
Sets a custom colormap.
void setColorRampType(QgsColorRampShader::Type colorRampType)
Sets the color ramp type.
void setLegendSettings(QgsColorRampLegendNodeSettings *settings)
Sets the color ramp shader legend settings.
A delegate for showing a color swatch in a list.
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
Base class for raster data providers.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
static bool parseColorMapFile(const QString &path, QList< QgsColorRampShader::ColorRampItem > &items, QgsColorRampShader::Type &type, QStringList &errors)
Parses an exported color map file at the specified path and extracts the stored color ramp items and ...
static bool saveColorMapFile(const QString &path, const QList< QgsColorRampShader::ColorRampItem > &items, QgsColorRampShader::Type type)
Exports a list of color ramp items and ramp shader type to a color map file at the specified path.
void setLabelPrecision(int labelPrecision)
Sets label precision to labelPrecision.
int labelPrecision() const
Returns label precision.
A rectangle specified with double values.
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.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
int significantDigits(const Qgis::DataType rasterDataType)
Returns the maximum number of significant digits a for the given rasterDataType.
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)