2323#include < QByteArray>
2424
2525QgsRasterPipe::QgsRasterPipe ()
26- : mProvider( 0 )
27- , mRenderer( 0 )
28- , mResampleFilter( 0 )
29- , mProjector( 0 )
3026{
3127}
3228
3329QgsRasterPipe::~QgsRasterPipe ()
3430{
35- foreach ( QgsRasterInterface* filter, mFilters )
31+ foreach ( QgsRasterInterface* interface, mInterfaces )
3632 {
37- delete filter ;
33+ delete interface ;
3834 }
3935}
4036
41- bool QgsRasterPipe::connectFilters ( QVector<QgsRasterInterface*> theFilters )
37+ bool QgsRasterPipe::connect ( QVector<QgsRasterInterface*> theInterfaces )
4238{
4339 QgsDebugMsg ( " Entered" );
44- for ( int i = 1 ; i < theFilters .size (); i++ )
40+ for ( int i = 1 ; i < theInterfaces .size (); i++ )
4541 {
46- if ( ! theFilters [i]->setInput ( theFilters [i-1 ] ) )
42+ if ( ! theInterfaces [i]->setInput ( theInterfaces [i-1 ] ) )
4743 {
48- QgsDebugMsg ( QString ( " cannot connect %1 to %2" ).arg ( typeid ( *( theFilters [i] ) ).name () ).arg ( typeid ( *( theFilters [i-1 ] ) ).name () ) );
44+ QgsDebugMsg ( QString ( " cannot connect %1 to %2" ).arg ( typeid ( *( theInterfaces [i] ) ).name () ).arg ( typeid ( *( theInterfaces [i-1 ] ) ).name () ) );
4945 return false ;
5046 }
5147 }
5248 return true ;
5349}
5450
55- bool QgsRasterPipe::insert ( int idx, QgsRasterInterface* theFilter )
51+ bool QgsRasterPipe::insert ( int idx, QgsRasterInterface* theInterface )
5652{
57- QgsDebugMsg ( QString ( " insert %1 at %2" ).arg ( typeid ( *theFilter ).name () ).arg ( idx ) );
58- if ( idx > mFilters .size () )
53+ QgsDebugMsg ( QString ( " insert %1 at %2" ).arg ( typeid ( *theInterface ).name () ).arg ( idx ) );
54+ if ( idx > mInterfaces .size () )
5955 {
60- idx = mFilters .size ();
56+ idx = mInterfaces .size ();
6157 }
6258 // make a copy of pipe to test connection, we test the connections
6359 // of the whole pipe, because the types and band numbers may change
64- QVector<QgsRasterInterface*> filters = mFilters ;
60+ QVector<QgsRasterInterface*> interfaces = mInterfaces ;
6561
66- filters .insert ( idx, theFilter );
62+ interfaces .insert ( idx, theInterface );
6763 bool success = false ;
68- if ( connectFilters ( filters ) )
64+ if ( connect ( interfaces ) )
6965 {
7066 success = true ;
71- mFilters .insert ( idx, theFilter );
72- setRole ( theFilter , idx );
67+ mInterfaces .insert ( idx, theInterface );
68+ setRole ( theInterface , idx );
7369 QgsDebugMsg ( " inserted ok" );
7470 }
7571
76- // Connect or reconnect (after the test) filters
77- connectFilters ( mFilters );
72+ // Connect or reconnect (after the test) interfaces
73+ connect ( mInterfaces );
7874 return success;
7975}
8076
81- bool QgsRasterPipe::replace ( int idx, QgsRasterInterface* theFilter )
77+ bool QgsRasterPipe::replace ( int idx, QgsRasterInterface* theInterface )
8278{
83- QgsDebugMsg ( QString ( " replace by %1 at %2" ).arg ( typeid ( *theFilter ).name () ).arg ( idx ) );
84- if ( idx < 0 || idx >= mFilters .size () )
79+ QgsDebugMsg ( QString ( " replace by %1 at %2" ).arg ( typeid ( *theInterface ).name () ).arg ( idx ) );
80+ if ( idx < 0 || idx >= mInterfaces .size () )
8581 {
8682 return false ;
8783 }
88- if ( !theFilter ) return false ;
84+ if ( !theInterface ) return false ;
8985
9086 // make a copy of pipe to test connection, we test the connections
9187 // of the whole pipe, because the types and band numbers may change
92- QVector<QgsRasterInterface*> filters = mFilters ;
88+ QVector<QgsRasterInterface*> interfaces = mInterfaces ;
9389
94- filters [idx] = theFilter ;
90+ interfaces [idx] = theInterface ;
9591 bool success = false ;
96- if ( connectFilters ( filters ) )
92+ if ( connect ( interfaces ) )
9793 {
9894 success = true ;
99- delete mFilters [idx];
100- mFilters [idx] = theFilter ;
101- setRole ( theFilter , idx );
95+ delete mInterfaces [idx];
96+ mInterfaces [idx] = theInterface ;
97+ setRole ( theInterface , idx );
10298 QgsDebugMsg ( " replaced ok" );
10399 }
104100
105- // Connect or reconnect (after the test) filters
106- connectFilters ( mFilters );
101+ // Connect or reconnect (after the test) interfaces
102+ connect ( mInterfaces );
107103 return success;
108104}
109105
110- QgsRasterPipe::Role QgsRasterPipe::filterRole ( QgsRasterInterface * filter ) const
106+ QgsRasterPipe::Role QgsRasterPipe::interfaceRole ( QgsRasterInterface * interface ) const
111107{
112- if ( dynamic_cast <QgsRasterDataProvider *>( filter ) ) return ProviderRole;
113- if ( dynamic_cast <QgsRasterRenderer *>( filter ) ) return RendererRole;
114- if ( dynamic_cast <QgsRasterResampleFilter *>( filter ) ) return ResamplerRole;
115- if ( dynamic_cast <QgsRasterProjector *>( filter ) ) return ProjectorRole;
108+ if ( dynamic_cast <QgsRasterDataProvider *>( interface ) ) return ProviderRole;
109+ if ( dynamic_cast <QgsRasterRenderer *>( interface ) ) return RendererRole;
110+ if ( dynamic_cast <QgsRasterResampleFilter *>( interface ) ) return ResamplerRole;
111+ if ( dynamic_cast <QgsRasterProjector *>( interface ) ) return ProjectorRole;
116112 return UnknownRole;
117113}
118114
119- void QgsRasterPipe::setRole ( QgsRasterInterface * theFilter , int idx )
115+ void QgsRasterPipe::setRole ( QgsRasterInterface * theInterface , int idx )
120116{
121- Role role = filterRole ( theFilter );
117+ Role role = interfaceRole ( theInterface );
122118 if ( role == UnknownRole ) return ;
123119 mRoleMap .insert ( role, idx );
124120}
125121
126- void QgsRasterPipe::unsetRole ( QgsRasterInterface * theFilter )
122+ void QgsRasterPipe::unsetRole ( QgsRasterInterface * theInterface )
127123{
128- Role role = filterRole ( theFilter );
124+ Role role = interfaceRole ( theInterface );
129125 if ( role == UnknownRole ) return ;
130126 mRoleMap .remove ( role );
131127}
132128
133- bool QgsRasterPipe::setFilter ( QgsRasterInterface* theFilter )
129+ bool QgsRasterPipe::set ( QgsRasterInterface* theInterface )
134130{
135- QgsDebugMsg ( QString ( " %1" ).arg ( typeid ( *theFilter ).name () ) );
131+ QgsDebugMsg ( QString ( " %1" ).arg ( typeid ( *theInterface ).name () ) );
136132
137- if ( !theFilter ) return false ;
133+ if ( !theInterface ) return false ;
138134
139- QgsRasterDataProvider * provider = dynamic_cast <QgsRasterDataProvider *>( theFilter );
135+ QgsRasterDataProvider * provider = dynamic_cast <QgsRasterDataProvider *>( theInterface );
140136 QgsRasterRenderer * renderer;
141137 QgsRasterResampleFilter * resampleFilter;
142138 QgsRasterProjector * projector;
143139
144- Role role = filterRole ( theFilter );
140+ Role role = interfaceRole ( theInterface );
145141
146- // We dont know where to place unknown filter
142+ // We dont know where to place unknown interface
147143 if ( role == UnknownRole ) return false ;
148144
149- // if ( mFiltersMap .value ( role ) )
145+ // if ( mInterfacesMap .value ( role ) )
150146 if ( mRoleMap .contains ( role ) )
151147 {
152- // An old filter of the same role exists -> replace
148+ // An old interface of the same role exists -> replace
153149 // replace may still fail and return false
154- return replace ( mRoleMap .value ( role ), theFilter );
150+ return replace ( mRoleMap .value ( role ), theInterface );
155151 }
156152
157153 int idx = 0 ;
158154
159- // Not found, find the best default position for this kind of filter
155+ // Not found, find the best default position for this kind of interface
160156 // QgsRasterDataProvider - ProviderRole
161157 // QgsRasterRenderer - RendererRole
162158 // QgsRasterResampler - ResamplerRole
@@ -183,71 +179,71 @@ bool QgsRasterPipe::setFilter( QgsRasterInterface* theFilter )
183179 idx = qMax ( qMax ( providerIdx, rendererIdx ), resamplerIdx ) + 1 ;
184180 }
185181
186- return insert ( idx, theFilter ); // insert may still fail and return false
182+ return insert ( idx, theInterface ); // insert may still fail and return false
187183}
188184
189- QgsRasterInterface * QgsRasterPipe::filter ( Role role ) const
190- {
191- QgsDebugMsg ( QString ( " role = %1" ).arg ( role ) );
192- if ( mRoleMap .contains ( role ) )
185+ QgsRasterInterface * QgsRasterPipe::interface ( Role role ) const
193186 {
194- return mFilters .value ( mRoleMap .value ( role ) );
187+ QgsDebugMsg ( QString ( " role = %1" ).arg ( role ) );
188+ if ( mRoleMap .contains ( role ) )
189+ {
190+ return mInterfaces .value ( mRoleMap .value ( role ) );
191+ }
192+ return 0 ;
195193 }
196- return 0 ;
197- }
198194
199195QgsRasterDataProvider * QgsRasterPipe::provider () const
200196{
201- return dynamic_cast <QgsRasterDataProvider *>( filter ( ProviderRole ) );
197+ return dynamic_cast <QgsRasterDataProvider *>( interface ( ProviderRole ) );
202198}
203199
204200QgsRasterRenderer * QgsRasterPipe::renderer () const
205201{
206- return dynamic_cast <QgsRasterRenderer *>( filter ( RendererRole ) );
202+ return dynamic_cast <QgsRasterRenderer *>( interface ( RendererRole ) );
207203}
208204
209205QgsRasterResampleFilter * QgsRasterPipe::resampleFilter () const
210206{
211- return dynamic_cast <QgsRasterResampleFilter *>( filter ( ResamplerRole ) );
207+ return dynamic_cast <QgsRasterResampleFilter *>( interface ( ResamplerRole ) );
212208}
213209
214210QgsRasterProjector * QgsRasterPipe::projector () const
215211{
216- return dynamic_cast <QgsRasterProjector*>( filter ( ProjectorRole ) );
212+ return dynamic_cast <QgsRasterProjector*>( interface ( ProjectorRole ) );
217213}
218214
219215bool QgsRasterPipe::remove ( int idx )
220216{
221217 QgsDebugMsg ( QString ( " remove at %1" ).arg ( idx ) );
222218
223- if ( idx < 0 || idx >= mFilters .size () )
219+ if ( idx < 0 || idx >= mInterfaces .size () )
224220 {
225221 return false ;
226222 }
227223
228224 // make a copy of pipe to test connection, we test the connections
229225 // of the whole pipe, because the types and band numbers may change
230- QVector<QgsRasterInterface*> filters = mFilters ;
226+ QVector<QgsRasterInterface*> interfaces = mInterfaces ;
231227
232- filters .remove ( idx );
228+ interfaces .remove ( idx );
233229 bool success = false ;
234- if ( connectFilters ( filters ) )
230+ if ( connect ( interfaces ) )
235231 {
236232 success = true ;
237- unsetRole ( mFilters [idx] );
238- delete mFilters [idx];
239- mFilters .remove ( idx );
233+ unsetRole ( mInterfaces [idx] );
234+ delete mInterfaces [idx];
235+ mInterfaces .remove ( idx );
240236 QgsDebugMsg ( " removed ok" );
241237 }
242238
243- // Connect or reconnect (after the test) filters
244- connectFilters ( mFilters );
239+ // Connect or reconnect (after the test) interfaces
240+ connect ( mInterfaces );
245241 return success;
246242}
247243
248- bool QgsRasterPipe::remove ( QgsRasterInterface * theFilter )
244+ bool QgsRasterPipe::remove ( QgsRasterInterface * theInterface )
249245{
250- if ( !theFilter ) return false ;
246+ if ( !theInterface ) return false ;
251247
252- return remove ( mFilters .indexOf ( theFilter ) );
248+ return remove ( mInterfaces .indexOf ( theInterface ) );
253249}
0 commit comments