QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsrastersinglecolorrendererwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsrastersinglecolorrendererwidget.cpp
3 ---------------------------------
4 begin : April 2024
5 copyright : (C) 2024 by Mathieu Pellerin
6 email : mathieu at opengis dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "moc_qgsrastersinglecolorrendererwidget.cpp"
21#include "qgsrasterlayer.h"
23
25 : QgsRasterRendererWidget( layer, extent )
26{
27 setupUi( this );
28
29 if ( mRasterLayer )
30 {
32 if ( !provider )
33 {
34 return;
35 }
36
37 mBandComboBox->setLayer( layer );
38
39 connect( mBandComboBox, &QgsRasterBandComboBox::bandChanged, this, [=]( int ) { emit widgetChanged(); } );
40 connect( mColorButton, &QgsColorButton::colorChanged, this, [=]( const QColor & ) { emit widgetChanged(); } );
41
42 setFromRenderer( layer->renderer() );
43 }
44}
45
47{
48 if ( !mRasterLayer )
49 {
50 return nullptr;
51 }
52
54 if ( !provider )
55 {
56 return nullptr;
57 }
58
59 QgsRasterSingleColorRenderer *renderer = new QgsRasterSingleColorRenderer( provider, mBandComboBox->currentBand(), mColorButton->color() );
60 return renderer;
61}
62
64{
65 const QgsRasterSingleColorRenderer *scr = dynamic_cast<const QgsRasterSingleColorRenderer *>( r );
66 if ( scr )
67 {
68 mBandComboBox->setBand( scr->inputBand() );
69 mColorButton->setColor( scr->color() );
70 }
71 else
72 {
73 mBandComboBox->setBand( 1 );
74 mColorButton->setColor( QColor( 0, 0, 0 ) );
75 }
76}
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
void bandChanged(int band)
Emitted when the currently selected band changes.
Base class for raster data providers.
Represents a raster layer.
QgsRasterRenderer * renderer() const
Returns the raster's renderer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Abstract base class for widgets which configure a QgsRasterRenderer.
void widgetChanged()
Emitted when something on the widget has changed.
Raster renderer pipe that applies colors to a raster.
QgsRasterSingleColorRendererWidget(QgsRasterLayer *layer, const QgsRectangle &extent=QgsRectangle())
Constructs the widget.
void setFromRenderer(const QgsRasterRenderer *r)
Sets the widget state from the specified renderer.
QgsRasterRenderer * renderer() override
Creates a new renderer, using the properties defined in the widget.
Raster renderer which renders all data pixels using a single color.
int inputBand() const override
Returns the input band for the renderer, or -1 if no input band is available.
QColor color() const
Returns the single color used by the renderer.
void setColor(const QColor &color)
Sets the single color used by the renderer.
A rectangle specified with double values.