Skip to content

Commit db7f9a5

Browse files
committed
pipe in properties dialog
1 parent d937dbb commit db7f9a5

15 files changed

+161
-21
lines changed

src/app/qgsrasterlayerproperties.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
***************************************************************************/
1717

1818
#include <limits>
19+
#include <typeinfo>
1920

2021
#include "qgsmaptopixel.h"
2122
#include "qgsmapcanvas.h"
@@ -294,6 +295,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
294295
}
295296
}
296297
on_mRenderTypeComboBox_currentIndexChanged( mRenderTypeComboBox->currentIndex() );
298+
299+
updatePipeList();
297300
} // QgsRasterLayerProperties ctor
298301

299302

@@ -1600,3 +1603,40 @@ void QgsRasterLayerProperties::toggleBuildPyramidsButton()
16001603
}
16011604
}
16021605

1606+
void QgsRasterLayerProperties::updatePipeList()
1607+
{
1608+
QgsDebugMsg("Entered");
1609+
1610+
mPipeTreeWidget->setColumnCount( 3 );
1611+
//mPipeTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
1612+
mPipeTreeWidget->header()->setResizeMode( QHeaderView::ResizeToContents );
1613+
1614+
QStringList labels;
1615+
labels << tr( "Filter" ) << tr("Bands") << tr( "Tot time" ) << tr( "Avg time" );
1616+
mPipeTreeWidget->setHeaderLabels( labels );
1617+
1618+
QgsRasterPipe *pipe = mRasterLayer->pipe();
1619+
for ( int i = 0; i < pipe->size(); i++ )
1620+
{
1621+
QgsRasterInterface * filter = pipe->at(i);
1622+
QStringList texts;
1623+
QString name;
1624+
// Unfortunately at this moment not all filters inherits from QObject
1625+
QObject *o = dynamic_cast<QObject*>( filter);
1626+
if ( o )
1627+
{
1628+
//name = o->objectName(); // gives empty with provider
1629+
name = o->metaObject()->className();
1630+
}
1631+
else
1632+
{
1633+
name = QString(typeid(*filter).name()).replace ( QRegExp(".*Qgs"), "Qgs" );
1634+
}
1635+
1636+
texts << name << QString("%1").arg( filter->bandCount() );
1637+
texts << QString("%1 ms").arg( filter->time(0) ) << QString("%1 ms").arg( filter->avgTime(), 0, 'd' );
1638+
QTreeWidgetItem *item = new QTreeWidgetItem( texts );
1639+
1640+
mPipeTreeWidget->addTopLevelItem ( item );
1641+
}
1642+
}

src/app/qgsrasterlayerproperties.h

+3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
151151
qreal mGradientHeight;
152152
qreal mGradientWidth;
153153

154+
/** Update pipe tab - filters list */
155+
void updatePipeList();
156+
154157
QgsMapCanvas* mMapCanvas;
155158
QgsMapToolEmitPoint* mPixelSelectorTool;
156159
};

src/core/qgsrasterprojector.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,10 @@ void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent,
555555
QgsDebugMsg( "Entered" );
556556
if ( !mInput ) return 0;
557557

558-
int bandNumber = 0;
558+
int bandNumber = 1;
559559
if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS )
560560
{
561-
return mInput->readBlock( bandNumber, extent, width, height );
561+
return mInput->block( bandNumber, extent, width, height );
562562
}
563563

564564
mDestExtent = extent;
@@ -575,7 +575,7 @@ void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent,
575575
return 0;
576576
}
577577

578-
void * inputData = mInput->readBlock( bandNumber, srcExtent(), srcCols(), srcRows() );
578+
void * inputData = mInput->block( bandNumber, srcExtent(), srcCols(), srcRows() );
579579

580580
if ( !inputData ) return 0;
581581

src/core/raster/qgsmultibandcolorrenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void * QgsMultiBandColorRenderer::readBlock( int bandNo, QgsRectangle const & e
176176
bandIt = bands.constBegin();
177177
for ( ; bandIt != bands.constEnd(); ++bandIt )
178178
{
179-
bandData[*bandIt] = mInput->readBlock( *bandIt, extent, width, height );
179+
bandData[*bandIt] = mInput->block( *bandIt, extent, width, height );
180180
if ( !bandData[*bandIt] ) return 0;
181181
}
182182

src/core/raster/qgspalettedrasterrenderer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & e
9595
}
9696

9797
QgsRasterInterface::DataType rasterType = ( QgsRasterInterface::DataType )mInput->dataType( mBandNumber );
98-
void* rasterData = mInput->readBlock( bandNo, extent, width, height );
98+
void* rasterData = mInput->block( bandNo, extent, width, height );
9999
double currentOpacity = mOpacity;
100100

101101
//rendering is faster without considering user-defined transparency
@@ -104,7 +104,7 @@ void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & e
104104

105105
if ( mAlphaBand > 0 && mAlphaBand != mBandNumber )
106106
{
107-
transparencyData = mInput->readBlock( mAlphaBand, extent, width, height );
107+
transparencyData = mInput->block( mAlphaBand, extent, width, height );
108108
}
109109
else if ( mAlphaBand == mBandNumber )
110110
{

src/core/raster/qgsrasterdrawer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
5757
}
5858

5959
// last pipe filter has only 1 band
60-
int bandNumber = 0;
60+
int bandNumber = 1;
6161
startRasterRead( bandNumber, viewPort, theQgsMapToPixel );
6262

6363
//number of cols/rows in output pixels
@@ -167,7 +167,7 @@ bool QgsRasterDrawer::readNextRasterPart( int bandNumber, QgsRasterViewPort* vie
167167
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / ( double )pInfo.nRows * viewPortExtent.height();
168168
QgsRectangle blockRect( xmin, ymin, xmax, ymax );
169169

170-
pInfo.data = mInput->readBlock( bandNumber, blockRect, nCols, nRows );
170+
pInfo.data = mInput->block( bandNumber, blockRect, nCols, nRows );
171171

172172
*rasterData = pInfo.data;
173173
topLeftCol = pInfo.currentCol;

src/core/raster/qgsrasterinterface.cpp

+54-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
#include "qgslogger.h"
2020

2121
#include <QByteArray>
22+
#include <QTime>
2223

23-
QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input, Role role ):
24-
mInput( input )
25-
, mRole( role )
24+
QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input, Role role )
25+
: mInput( input )
26+
, mRole( role )
27+
, mTimeMinSize(150)
2628
{
2729
}
2830

@@ -43,3 +45,52 @@ QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format
4345
uchar * data = ( uchar * ) malloc( size );
4446
return new QImage( data, width, height, format );
4547
}
48+
49+
void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int width, int height )
50+
{
51+
QTime time;
52+
time.start();
53+
void * b = readBlock( bandNo, extent, width, height );
54+
55+
if ( width > mTimeMinSize && height > mTimeMinSize )
56+
{
57+
if ( mTime.size() <= bandNo )
58+
{
59+
mTime.resize( bandNo+1 );
60+
}
61+
mTime[bandNo] = time.elapsed();
62+
QgsDebugMsg ( QString("mRole = %1 bandNo = %2 time = %3" ).arg(mRole).arg(bandNo).arg(mTime[bandNo]) );
63+
}
64+
return b;
65+
}
66+
67+
double QgsRasterInterface::time( int bandNo )
68+
{
69+
double t = 0;
70+
if ( bandNo == 0 )
71+
{
72+
for ( int i = 1; i < mTime.size(); i++ )
73+
{
74+
t += mTime[i];
75+
}
76+
}
77+
else
78+
{
79+
t = mTime.value( bandNo );
80+
}
81+
QgsDebugMsg ( QString("mRole = %1 bandNo = %2 time = %3" ).arg(mRole).arg(bandNo).arg(t) );
82+
return t;
83+
}
84+
85+
double QgsRasterInterface::avgTime( )
86+
{
87+
// Not perfect because Qtime measures ms only and we dont count rendered bands
88+
double t = 0;
89+
int count = 0;
90+
for ( int i = 1; i < mTime.size(); i++ )
91+
{
92+
t += mTime[i];
93+
if ( mTime[i] > 0 ) count++;
94+
}
95+
return count > 0 ? t/count : 0;
96+
}

src/core/raster/qgsrasterinterface.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
118118
return UnknownDataType;
119119
}
120120

121-
/** Get numbur of bands */
121+
/** Get number of bands */
122122
virtual int bandCount() const
123123
{
124124
return 1;
@@ -131,6 +131,13 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
131131
* Returns pointer to data.
132132
* Caller is responsible to free the memory returned.
133133
*/
134+
void * block( int bandNo, QgsRectangle const & extent, int width, int height );
135+
136+
/** Read block of data using given extent and size.
137+
* Method to be implemented by subclasses.
138+
* Returns pointer to data.
139+
* Caller is responsible to free the memory returned.
140+
*/
134141
virtual void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
135142
{
136143
Q_UNUSED( bandNo ); Q_UNUSED( extent ); Q_UNUSED( width ); Q_UNUSED( height );
@@ -146,14 +153,26 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
146153
*/
147154
QImage * createImage( int width, int height, QImage::Format format );
148155

156+
// Clear last rendering time
157+
void clearTime() { mTime.clear(); if ( mInput ) mInput->clearTime(); }
158+
159+
// Last time consumed by block()
160+
// Returns total time (for all bands) if bandNo is 0
161+
double time( int bandNo );
162+
double avgTime();
163+
149164
//protected:
150165

151166
Role mRole;
152167

153168
// QgsRasterInterface from used as input, data are read from it
154169
QgsRasterInterface* mInput;
155170

171+
// Last rendering time
172+
QVector<double> mTime;
156173

174+
// minimum block size to record time (to ignore thumbnails etc)
175+
int mTimeMinSize;
157176
};
158177

159178
#endif

src/core/raster/qgsrasterlayer.h

+3
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
364364
const QgsRasterResampleFilter* resampleFilter() const { return dynamic_cast<QgsRasterResampleFilter*>( mPipe.filter( QgsRasterInterface::ResamplerRole ) ); }
365365
QgsRasterResampleFilter * resampleFilter() { return dynamic_cast<QgsRasterResampleFilter*>( mPipe.filter( QgsRasterInterface::ResamplerRole ) ); }
366366

367+
/** Get raster pipe */
368+
QgsRasterPipe * pipe() { return &mPipe; }
369+
367370
/** \brief Accessor to find out how many standard deviations are being plotted */
368371
double standardDeviations() const { return mStandardDeviations; }
369372

src/core/raster/qgsrasterpipe.h

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class CORE_EXPORT QgsRasterPipe //: public QObject
6464
//QgsRasterInterface * filter ( QgsRasterInterface::Role role );
6565
QgsRasterInterface * filter ( QgsRasterInterface::Role role ) const;
6666

67+
int size() { return mFilters.size(); }
68+
QgsRasterInterface * at( int idx ) { return mFilters.at(idx); }
6769
QgsRasterInterface * last() { return mFilters.last(); }
6870

6971
/** Delete all filters */

src/core/raster/qgsrasterresamplefilter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ void * QgsRasterResampleFilter::readBlock( int bandNo, QgsRectangle const & ext
100100
int resHeight = height * oversamplingY;
101101

102102
// At moment we know that we read rendered image
103-
int bandNumber = 0;
104-
void *rasterData = mInput->readBlock( bandNumber, extent, resWidth, resHeight );
103+
int bandNumber = 1;
104+
void *rasterData = mInput->block( bandNumber, extent, resWidth, resHeight );
105105

106106
//resample image
107107
if (( mZoomedInResampler || mZoomedOutResampler ) && !doubleNear( oversamplingX, 1.0 ) && !doubleNear( oversamplingY, 1.0 ) )

src/core/raster/qgssinglebandcolordatarenderer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void * QgsSingleBandColorDataRenderer::readBlock( int bandNo, QgsRectangle cons
5757

5858
QgsRasterInterface::DataType rasterType = ( QgsRasterInterface::DataType )mInput->dataType( mBand );
5959

60-
void* rasterData = mInput->readBlock( bandNo, extent, width, height );
60+
void* rasterData = mInput->block( bandNo, extent, width, height );
6161

6262
currentRasterPos = 0;
6363
QImage img( width, height, QImage::Format_ARGB32 );

src/core/raster/qgssinglebandgrayrenderer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void * QgsSingleBandGrayRenderer::readBlock( int bandNo, QgsRectangle const & e
7474
alphaType = ( QgsRasterInterface::DataType )mInput->dataType( mAlphaBand );
7575
}
7676

77-
void* rasterData = mInput->readBlock( mGrayBand, extent, width, height );
77+
void* rasterData = mInput->block( mGrayBand, extent, width, height );
7878
if ( !rasterData ) return 0;
7979

8080
void* alphaData = 0;
@@ -84,7 +84,7 @@ void * QgsSingleBandGrayRenderer::readBlock( int bandNo, QgsRectangle const & e
8484

8585
if ( mAlphaBand > 0 && mGrayBand != mAlphaBand )
8686
{
87-
alphaData = mInput->readBlock( mAlphaBand, extent, width, height );
87+
alphaData = mInput->block( mAlphaBand, extent, width, height );
8888
if ( !alphaData ) {
8989
free ( rasterData );
9090
return 0;

src/core/raster/qgssinglebandpseudocolorrenderer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void * QgsSingleBandPseudoColorRenderer::readBlock( int bandNo, QgsRectangle co
7676
double currentOpacity = mOpacity;
7777
QgsRasterInterface::DataType rasterType = ( QgsRasterInterface::DataType )mInput->dataType( mBand );
7878

79-
void* rasterData = mInput->readBlock( mBand, extent, width, height );
79+
void* rasterData = mInput->block( mBand, extent, width, height );
8080

8181
int red, green, blue;
8282
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
@@ -86,7 +86,7 @@ void * QgsSingleBandPseudoColorRenderer::readBlock( int bandNo, QgsRectangle co
8686

8787
if ( mAlphaBand > 0 && mAlphaBand != mBand )
8888
{
89-
transparencyData = mInput->readBlock( mAlphaBand, extent, width, height );
89+
transparencyData = mInput->block( mAlphaBand, extent, width, height );
9090
}
9191
else if ( mAlphaBand == mBand )
9292
{

src/ui/qgsrasterlayerpropertiesbase.ui

+24-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>706</width>
10-
<height>663</height>
10+
<height>652</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -825,7 +825,7 @@
825825
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
826826
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
827827
p, li { white-space: pre-wrap; }
828-
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
828+
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
829829
&lt;table border=&quot;0&quot; style=&quot;-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;&quot;&gt;
830830
&lt;tr&gt;
831831
&lt;td style=&quot;border: none;&quot;&gt;
@@ -952,6 +952,28 @@ p, li { white-space: pre-wrap; }
952952
</item>
953953
</layout>
954954
</widget>
955+
<widget class="QWidget" name="tabPagePipe">
956+
<attribute name="title">
957+
<string>Pipe (debug)</string>
958+
</attribute>
959+
<layout class="QVBoxLayout" name="verticalLayout">
960+
<item>
961+
<widget class="QTreeWidget" name="mPipeTreeWidget">
962+
<attribute name="headerStretchLastSection">
963+
<bool>true</bool>
964+
</attribute>
965+
<attribute name="headerStretchLastSection">
966+
<bool>true</bool>
967+
</attribute>
968+
<column>
969+
<property name="text">
970+
<string notr="true">1</string>
971+
</property>
972+
</column>
973+
</widget>
974+
</item>
975+
</layout>
976+
</widget>
955977
</widget>
956978
</item>
957979
<item row="2" column="0" colspan="4">

0 commit comments

Comments
 (0)