36 for (
int i = 0; i < pipe.
size(); i++ )
45 clone->setInput( mInterfaces.at( i - 1 ) );
47 mInterfaces.append( clone );
48 if ( role != Qgis::RasterPipeInterfaceRole::Unknown )
50 mRoleMap.insert( role, i );
54 mDataDefinedProperties = pipe.mDataDefinedProperties;
59 const auto constMInterfaces = mInterfaces;
69 auto it = mRoleMap.find( Qgis::RasterPipeInterfaceRole::Provider );
70 if ( it != mRoleMap.end() )
74 dp->moveToThread( thread );
79bool QgsRasterPipe::connect( QVector<QgsRasterInterface *> interfaces )
82 for (
int i = 1; i < interfaces.size(); i++ )
84 if ( ! interfaces[i]->setInput( interfaces[i - 1] ) )
89 QgsDebugMsg( QStringLiteral(
"cannot connect %1 to %2" ).arg(
typeid( a ).name(),
typeid( b ).name() ) );
99 QgsDebugMsgLevel( QStringLiteral(
"insert %1 at %2" ).arg(
typeid( *interface ).name() ).arg( idx ), 4 );
100 if ( idx > mInterfaces.size() )
102 idx = mInterfaces.size();
106 QVector<QgsRasterInterface *> interfaces = mInterfaces;
108 interfaces.insert( idx, interface );
109 bool success =
false;
110 if ( connect( interfaces ) )
113 mInterfaces.insert( idx, interface );
114 setRole( interface, idx );
119 QgsDebugMsgLevel( QStringLiteral(
"Error inserting pipe %1" ).arg( idx ), 4 );
123 connect( mInterfaces );
129 if ( !interface )
return false;
131 QgsDebugMsgLevel( QStringLiteral(
"replace by %1 at %2" ).arg(
typeid( *interface ).name() ).arg( idx ), 4 );
132 if ( !checkBounds( idx ) )
return false;
136 QVector<QgsRasterInterface *> interfaces = mInterfaces;
138 interfaces[idx] = interface;
139 bool success =
false;
140 if ( connect( interfaces ) )
143 delete mInterfaces.at( idx );
144 mInterfaces[idx] = interface;
145 setRole( interface, idx );
150 connect( mInterfaces );
158 role = Qgis::RasterPipeInterfaceRole::Provider;
160 role = Qgis::RasterPipeInterfaceRole::Renderer;
162 role = Qgis::RasterPipeInterfaceRole::Resampler;
164 role = Qgis::RasterPipeInterfaceRole::Brightness;
166 role = Qgis::RasterPipeInterfaceRole::HueSaturation;
168 role = Qgis::RasterPipeInterfaceRole::Projector;
170 role = Qgis::RasterPipeInterfaceRole::Nuller;
179 if ( role == Qgis::RasterPipeInterfaceRole::Unknown )
182 mRoleMap.insert( role, idx );
188 if ( role == Qgis::RasterPipeInterfaceRole::Unknown )
191 const int roleIdx{ mRoleMap[role] };
192 mRoleMap.remove( role );
195 const auto roleMapValues {mRoleMap.values()};
196 if ( roleIdx < *std::max_element( roleMapValues.begin(), roleMapValues.end() ) )
198 for (
auto it = mRoleMap.cbegin(); it != mRoleMap.cend(); ++it )
200 if ( it.value() > roleIdx )
202 mRoleMap[it.key()] = it.value() - 1;
217 if ( role == Qgis::RasterPipeInterfaceRole::Unknown )
221 if ( mRoleMap.contains( role ) )
225 return replace( mRoleMap.value( role ), interface );
236 int providerIdx = mRoleMap.value( Qgis::RasterPipeInterfaceRole::Provider, -1 );
237 int rendererIdx = mRoleMap.value( Qgis::RasterPipeInterfaceRole::Renderer, -1 );
238 int resamplerIdx = mRoleMap.value( Qgis::RasterPipeInterfaceRole::Resampler, -1 );
239 int brightnessIdx = mRoleMap.value( Qgis::RasterPipeInterfaceRole::Brightness, -1 );
240 int hueSaturationIdx = mRoleMap.value( Qgis::RasterPipeInterfaceRole::HueSaturation, -1 );
242 if ( role == Qgis::RasterPipeInterfaceRole::Provider )
246 else if ( role == Qgis::RasterPipeInterfaceRole::Renderer )
248 idx = providerIdx + 1;
250 else if ( role == Qgis::RasterPipeInterfaceRole::Brightness )
252 idx = std::max( providerIdx, rendererIdx ) + 1;
254 else if ( role == Qgis::RasterPipeInterfaceRole::HueSaturation )
256 idx = std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ) + 1;
258 else if ( role == Qgis::RasterPipeInterfaceRole::Resampler )
260 idx = std::max( std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ), hueSaturationIdx ) + 1;
262 else if ( role == Qgis::RasterPipeInterfaceRole::Projector )
264 idx = std::max( std::max( std::max( std::max( providerIdx, rendererIdx ), brightnessIdx ), hueSaturationIdx ), resamplerIdx ) + 1;
267 return insert( idx, interface );
273 if ( mRoleMap.contains( role ) )
275 return mInterfaces.value( mRoleMap.value( role ) );
282 return dynamic_cast<QgsRasterDataProvider *
>( interface( Qgis::RasterPipeInterfaceRole::Provider ) );
287 return dynamic_cast<QgsRasterRenderer *
>( interface( Qgis::RasterPipeInterfaceRole::Renderer ) );
302 return dynamic_cast<QgsHueSaturationFilter *
>( interface( Qgis::RasterPipeInterfaceRole::HueSaturation ) );
307 return dynamic_cast<QgsRasterProjector *
>( interface( Qgis::RasterPipeInterfaceRole::Projector ) );
312 return dynamic_cast<QgsRasterNuller *
>( interface( Qgis::RasterPipeInterfaceRole::Nuller ) );
319 if ( !checkBounds( idx ) )
324 QVector<QgsRasterInterface *> interfaces = mInterfaces;
326 interfaces.remove( idx );
327 bool success =
false;
328 if ( connect( interfaces ) )
331 unsetRole( mInterfaces.at( idx ) );
332 delete mInterfaces.at( idx );
333 mInterfaces.remove( idx );
338 QgsDebugMsgLevel( QStringLiteral(
"Error removing pipe %1" ).arg( idx ), 4 );
342 connect( mInterfaces );
349 if ( !interface )
return false;
351 return remove( mInterfaces.indexOf( interface ) );
356 QgsDebugMsgLevel( QStringLiteral(
"idx = %1 on = %2" ).arg( idx ).arg( on ), 4 );
357 if ( !checkBounds( idx ) )
362 bool onOrig = mInterfaces.at( idx )->on();
367 mInterfaces.at( idx )->setOn( on );
369 bool success = connect( mInterfaces );
371 mInterfaces.at( idx )->setOn( onOrig );
372 connect( mInterfaces );
378 QgsDebugMsgLevel( QStringLiteral(
"idx = %1 on = %2" ).arg( idx ).arg( on ), 4 );
379 if ( !checkBounds( idx ) )
382 bool onOrig = mInterfaces.at( idx )->on();
387 mInterfaces.at( idx )->setOn( on );
389 if ( connect( mInterfaces ) )
392 mInterfaces.at( idx )->setOn( onOrig );
393 connect( mInterfaces );
398bool QgsRasterPipe::checkBounds(
int idx )
const
400 return !( idx < 0 || idx >= mInterfaces.size() );
405 mResamplingStage = stage;
407 int resamplerIndex = 0;
410 if ( interfaceRole( interface ) == Qgis::RasterPipeInterfaceRole::Resampler )
433 const double prevOpacity = r->opacity();
439 r->setOpacity( opacity );
447void QgsRasterPipe::initPropertyDefinitions()
449 const QString origin = QStringLiteral(
"raster" );
459 static std::once_flag initialized;
460 std::call_once( initialized, [ = ]( )
462 initPropertyDefinitions();
464 return sPropertyDefinitions;
RasterResamplingStage
Stage at which raster resampling occurs.
@ Provider
Resampling occurs in Provider.
@ ResampleFilter
Resampling occurs in ResamplingFilter.
RasterPipeInterfaceRole
Sublayer flags.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
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.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
Definition for a property.
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.
Contains a pipeline of raster interfaces for sequential raster processing.
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.
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.
@ RendererOpacity
Raster renderer global opacity.
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.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
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)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.