QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
20#include "qgsrasterlayer.h"
22
24 : QgsRasterRendererWidget( layer, extent )
25{
26 setupUi( this );
27
28 if ( mRasterLayer )
29 {
31 if ( !provider )
32 {
33 return;
34 }
35
36 mBandComboBox->setLayer( layer );
37
38 connect( mBandComboBox, &QgsRasterBandComboBox::bandChanged, this, [ = ]( int ) { emit widgetChanged(); } );
39 connect( mColorButton, &QgsColorButton::colorChanged, this, [ = ]( const QColor & ) { emit widgetChanged(); } );
40
41 setFromRenderer( layer->renderer() );
42 }
43}
44
46{
47 if ( !mRasterLayer )
48 {
49 return nullptr;
50 }
51
53 if ( !provider )
54 {
55 return nullptr;
56 }
57
58 QgsRasterSingleColorRenderer *renderer = new QgsRasterSingleColorRenderer( provider, mBandComboBox->currentBand(), mColorButton->color() );
59 return renderer;
60}
61
63{
64 const QgsRasterSingleColorRenderer *scr = dynamic_cast<const QgsRasterSingleColorRenderer *>( r );
65 if ( scr )
66 {
67 mBandComboBox->setBand( scr->inputBand() );
68 mColorButton->setColor( scr->color() );
69 }
70 else
71 {
72 mBandComboBox->setBand( 1 );
73 mColorButton->setColor( QColor( 0, 0, 0 ) );
74 }
75}
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.