35using namespace Qt::StringLiterals;
39 for (
int i = 0; i < pipe.
size(); i++ )
48 clone->setInput( mInterfaces.at( i - 1 ) );
50 mInterfaces.append( clone );
53 mRoleMap.insert( role, i );
57 mDataDefinedProperties = pipe.mDataDefinedProperties;
62 const auto constMInterfaces = mInterfaces;
73 if ( it != mRoleMap.end() )
77 dp->moveToThread( thread );
82bool QgsRasterPipe::connect( QVector<QgsRasterInterface *> interfaces )
85 for (
int i = 1; i < interfaces.size(); i++ )
87 if ( ! interfaces[i]->setInput( interfaces[i - 1] ) )
92 QgsDebugError( u
"cannot connect %1 to %2"_s.arg(
typeid( a ).name(),
typeid( b ).name() ) );
102 QgsDebugMsgLevel( u
"insert %1 at %2"_s.arg(
typeid( *interface ).name() ).arg( idx ), 4 );
103 if ( idx > mInterfaces.size() )
105 idx = mInterfaces.size();
109 QVector<QgsRasterInterface *> interfaces = mInterfaces;
111 interfaces.insert( idx, interface );
112 bool success =
false;
113 if ( connect( interfaces ) )
116 mInterfaces.insert( idx, interface );
117 setRole( interface, idx );
127 connect( mInterfaces );
133 if ( !interface )
return false;
135 QgsDebugMsgLevel( u
"replace by %1 at %2"_s.arg(
typeid( *interface ).name() ).arg( idx ), 4 );
136 if ( !checkBounds( idx ) )
return false;
140 QVector<QgsRasterInterface *> interfaces = mInterfaces;
142 interfaces[idx] = interface;
143 bool success =
false;
144 if ( connect( interfaces ) )
147 delete mInterfaces.at( idx );
148 mInterfaces[idx] = interface;
149 setRole( interface, idx );
154 connect( mInterfaces );
186 mRoleMap.insert( role, idx );
195 const int roleIdx{ mRoleMap[role] };
196 mRoleMap.remove( role );
199 const QMap<Qgis::RasterPipeInterfaceRole, int> currentRoles = mRoleMap;
200 for (
auto it = currentRoles.cbegin(); it != currentRoles.cend(); ++it )
202 if ( it.value() > roleIdx )
204 mRoleMap[it.key()] = it.value() - 1;
222 if ( mRoleMap.contains( role ) )
226 return replace( mRoleMap.value( role ), interface );
249 idx = providerIdx + 1;
253 idx = std::max( providerIdx, rendererIdx ) + 1;
257 idx = std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ) + 1;
261 idx = std::max( std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ), hueSaturationIdx ) + 1;
265 idx = std::max( std::max( std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ), hueSaturationIdx ), resamplerIdx ) + 1;
268 return insert( idx, interface );
274 if ( mRoleMap.contains( role ) )
276 return mInterfaces.value( mRoleMap.value( role ) );
320 if ( !checkBounds( idx ) )
325 QVector<QgsRasterInterface *> interfaces = mInterfaces;
327 interfaces.remove( idx );
328 bool success =
false;
329 if ( connect( interfaces ) )
332 unsetRole( mInterfaces.at( idx ) );
333 delete mInterfaces.at( idx );
334 mInterfaces.remove( idx );
343 connect( mInterfaces );
350 if ( !interface )
return false;
352 return remove( mInterfaces.indexOf( interface ) );
358 if ( !checkBounds( idx ) )
363 bool onOrig = mInterfaces.at( idx )->on();
368 mInterfaces.at( idx )->setOn( on );
370 bool success = connect( mInterfaces );
372 mInterfaces.at( idx )->setOn( onOrig );
373 connect( mInterfaces );
380 if ( !checkBounds( idx ) )
383 bool onOrig = mInterfaces.at( idx )->on();
388 mInterfaces.at( idx )->setOn( on );
390 if ( connect( mInterfaces ) )
393 mInterfaces.at( idx )->setOn( onOrig );
394 connect( mInterfaces );
399bool QgsRasterPipe::checkBounds(
int idx )
const
401 return !( idx < 0 || idx >= mInterfaces.size() );
406 mResamplingStage = stage;
408 int resamplerIndex = 0;
427 if ( !mDataDefinedProperties.hasActiveProperties() )
434 const double prevOpacity = r->opacity();
437 const double opacity = mDataDefinedProperties.valueAsDouble(
Property::RendererOpacity, context, prevOpacity, &ok ) / 100;
440 r->setOpacity( opacity );
448void QgsRasterPipe::initPropertyDefinitions()
450 const QString origin = u
"raster"_s;
460 static std::once_flag initialized;
461 std::call_once( initialized, initPropertyDefinitions );
462 return sPropertyDefinitions;
RasterResamplingStage
Stage at which raster resampling occurs.
@ Provider
Resampling occurs in Provider.
@ ResampleFilter
Resampling occurs in ResamplingFilter.
RasterPipeInterfaceRole
Raster pipe interface roles.
@ Renderer
Raster renderer role.
@ Projector
Projector role.
@ Resampler
Resampler role.
@ HueSaturation
Hue/saturation filter role (also applies grayscale/color inversion).
@ Provider
Data provider role.
@ Nuller
Raster nuller role.
@ Brightness
Brightness filter role.
Brightness/contrast and gamma correction filter pipe for rasters.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Color and saturation filter pipe for rasters.
Definition for a property.
@ Opacity
Opacity (0-100).
Base class for raster data providers.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
Raster pipe that deals with null values.
bool set(QgsRasterInterface *interface)
Inserts a new known interface in default place or replace interface of the same role if it already ex...
int size() const
Returns the size of the pipe (the number of interfaces contained in the pipe).
QgsRasterPipe()=default
Constructor for an empty QgsRasterPipe.
void moveToThread(QThread *thread)
Moves the pipe to another thread.
QgsRasterResampleFilter * resampleFilter() const
Returns the resample filter interface, or nullptr if no resample filter is present in the pipe.
bool replace(int idx, QgsRasterInterface *interface)
Attempts to replace the interface at specified index and reconnect the pipe.
QgsRasterDataProvider * provider() const
Returns the data provider interface, or nullptr if no data provider is present in the pipe.
@ RendererOpacity
Raster renderer global opacity.
bool canSetOn(int idx, bool on)
Returns true if the interface at the specified index may be switched on or off.
bool insert(int idx, QgsRasterInterface *interface)
Attempts to insert interface at specified index and connect if connection would fail,...
void setResamplingStage(Qgis::RasterResamplingStage stage)
Sets which stage of the pipe should apply resampling.
void evaluateDataDefinedProperties(QgsExpressionContext &context)
Evaluates any data defined properties set on the pipe, applying their results to the corresponding in...
QgsRasterProjector * projector() const
Returns the projector interface, or nullptr if no projector is present in the pipe.
bool remove(int idx)
Removes and deletes the interface at given index (if possible).
static QgsPropertiesDefinition propertyDefinitions()
Returns the definitions for data defined properties available for use in raster pipes.
QgsRasterRenderer * renderer() const
Returns the raster renderer interface, or nullptr if no raster renderer is present in the pipe.
Qgis::RasterResamplingStage resamplingStage() const
Returns which stage of the pipe should apply resampling.
QgsBrightnessContrastFilter * brightnessFilter() const
Returns the brightness filter interface, or nullptr if no brightness filter is present in the pipe.
QgsHueSaturationFilter * hueSaturationFilter() const
Returns the hue/saturation interface, or nullptr if no hue/saturation filter is present in the pipe.
QgsRasterNuller * nuller() const
Returns the raster nuller interface, or nullptr if no raster nuller is present in the pipe.
bool setOn(int idx, bool on)
Set whether the interface at the specified index is enabled.
Implements approximate projection support for optimised raster transformation.
Raster renderer pipe that applies colors to a raster.
Resample filter pipe for rasters.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.