|
15 | 15 | * * |
16 | 16 | ***************************************************************************/ |
17 | 17 |
|
| 18 | +#include <typeinfo> |
| 19 | + |
18 | 20 | #include <QByteArray> |
19 | 21 | #include <QTime> |
20 | 22 |
|
|
23 | 25 |
|
24 | 26 | QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input ) |
25 | 27 | : mInput( input ) |
26 | | - , mTimeMinSize( 300 ) // dont forget resampling! |
| 28 | + , mStatsOn( false ) |
27 | 29 | { |
28 | 30 | } |
29 | 31 |
|
@@ -51,31 +53,46 @@ void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int |
51 | 53 | time.start(); |
52 | 54 | void * b = readBlock( bandNo, extent, width, height ); |
53 | 55 |
|
54 | | - if ( width > mTimeMinSize && height > mTimeMinSize ) |
| 56 | + if ( mStatsOn ) |
55 | 57 | { |
56 | 58 | if ( mTime.size() <= bandNo ) |
57 | 59 | { |
58 | 60 | mTime.resize( bandNo + 1 ); |
59 | 61 | } |
60 | 62 | // QTime counts only in miliseconds |
61 | | - mTime[bandNo] = time.elapsed(); |
| 63 | + // We are adding time until next clear, this way the time may be collected |
| 64 | + // for the whole QgsRasterLayer::draw() for example, not just for a single part |
| 65 | + mTime[bandNo] += time.elapsed(); |
62 | 66 | QgsDebugMsg( QString( "bandNo = %2 time = %3" ).arg( bandNo ).arg( mTime[bandNo] ) ); |
63 | 67 | } |
64 | 68 | return b; |
65 | 69 | } |
66 | 70 |
|
67 | | -double QgsRasterInterface::time( ) |
| 71 | +void QgsRasterInterface::setStatsOn( bool on ) |
68 | 72 | { |
69 | | - // We can only count give total time, because we have to subtract time of previous |
| 73 | + if ( on ) |
| 74 | + { |
| 75 | + mTime.clear(); |
| 76 | + } |
| 77 | + if ( mInput ) mInput->setStatsOn( on ); |
| 78 | + mStatsOn = on; |
| 79 | +} |
| 80 | + |
| 81 | +double QgsRasterInterface::time( bool cumulative ) |
| 82 | +{ |
| 83 | + // We can calculate total time only, because we have to subtract time of previous |
70 | 84 | // interface(s) and we dont know how to assign bands to each other |
71 | 85 | double t = 0; |
72 | 86 | for ( int i = 1; i < mTime.size(); i++ ) |
73 | 87 | { |
74 | 88 | t += mTime[i]; |
75 | 89 | } |
| 90 | + if ( cumulative ) return t; |
| 91 | + |
76 | 92 | if ( mInput ) |
77 | 93 | { |
78 | | - t -= mInput->time(); |
| 94 | + QgsDebugMsgLevel( QString( "%1 cumulative time = %2 time = %3" ).arg( typeid( *( this ) ).name() ).arg( t ).arg( t - mInput->time( true ) ), 3 ); |
| 95 | + t -= mInput->time( true ); |
79 | 96 | } |
80 | 97 | return t; |
81 | 98 | } |
0 commit comments