Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Expose maxOversampling parameter to user
  • Loading branch information
mhugent committed Jan 28, 2012
1 parent 3b36620 commit 2c9320a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -327,6 +327,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
{
mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
}
mMaximumOversamplingSpinBox->setValue( renderer->maxOversampling() );
}
} // QgsRasterLayerProperties ctor

Expand Down Expand Up @@ -1520,6 +1521,11 @@ void QgsRasterLayerProperties::apply()
rasterRenderer->setZoomedOutResampler( zoomedOutResampler );
}

if ( rasterRenderer )
{
rasterRenderer->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
}


//get the thumbnail for the layer
QPixmap myQPixmap = QPixmap( pixmapThumbnail->width(), pixmapThumbnail->height() );
Expand Down
22 changes: 22 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -3188,6 +3188,22 @@ bool QgsRasterLayer::readSymbology( const QDomNode& layer_node, QString& errorMe
}

//resampler

//max oversampling
if ( mRenderer )
{
QDomElement maxOversamplingElem = mnl.firstChildElement( "MaxOversampling" );
if ( !maxOversamplingElem.isNull() )
{
bool conversion;
double maxOversampling = maxOversamplingElem.text().toDouble( &conversion );
if ( conversion )
{
mRenderer->setMaxOversampling( maxOversampling );
}
}
}

QDomElement zoomedInResamplerElem = mnl.firstChildElement( "zoomedInResampler" );
if ( mRenderer && !zoomedInResamplerElem.isNull() )
{
Expand Down Expand Up @@ -3348,6 +3364,12 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
// resampler
if ( mRenderer )
{
//Max oversampling
QDomElement maxOversamplingElem = document.createElement( "MaxOversampling" );
QDomText maxOversamplingText = document.createTextNode( QString::number( mRenderer->maxOversampling() ) );
maxOversamplingElem.appendChild( maxOversamplingText );
rasterPropertiesElement.appendChild( maxOversamplingElem );

QString zoomedInResamplerString = "nearest";
const QgsRasterResampler* zoomedInResampler = mRenderer->zoomedInResampler();
if ( zoomedInResampler )
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterrenderer.cpp
Expand Up @@ -25,7 +25,7 @@
#include <QPainter>

QgsRasterRenderer::QgsRasterRenderer( QgsRasterDataProvider* provider ): mProvider( provider ), mZoomedInResampler( 0 ), mZoomedOutResampler( 0 ),
mOpacity( 1.0 ), mRasterTransparency( 0 ), mAlphaBand( -1 ), mInvertColor( false )
mOpacity( 1.0 ), mRasterTransparency( 0 ), mAlphaBand( -1 ), mInvertColor( false ), mMaxOversampling( 2.0 )
{
}

Expand Down Expand Up @@ -76,7 +76,7 @@ void QgsRasterRenderer::startRasterRead( int bandNumber, QgsRasterViewPort* view
providerExtent = t.transformBoundingBox( providerExtent );
}
double pixelRatio = mapToPixel->mapUnitsPerPixel() / ( providerExtent.width() / mProvider->xSize() );
oversampling = ( pixelRatio > 4.0 ) ? 4.0 : pixelRatio;
oversampling = ( pixelRatio > mMaxOversampling ) ? mMaxOversampling : pixelRatio;
}

//set oversampling back to 1.0 if no resampler for zoomed in / zoomed out (nearest neighbour)
Expand Down
6 changes: 6 additions & 0 deletions src/core/raster/qgsrasterrenderer.h
Expand Up @@ -69,6 +69,9 @@ class QgsRasterRenderer
void setZoomedOutResampler( QgsRasterResampler* r );
const QgsRasterResampler* zoomedOutResampler() const { return mZoomedOutResampler; }

void setMaxOversampling( double os ) { mMaxOversampling = os; }
double maxOversampling() const { return mMaxOversampling; }

protected:
inline double readValue( void *data, QgsRasterDataProvider::DataType type, int index );

Expand Down Expand Up @@ -110,6 +113,9 @@ class QgsRasterRenderer

bool mInvertColor;

/**Maximum boundary for oversampling (to avoid too much data traffic). Default: 2.0*/
double mMaxOversampling;

private:
/**Remove part into and release memory*/
void removePartInfo( int bandNumer );
Expand Down
13 changes: 12 additions & 1 deletion src/ui/qgsrasterlayerpropertiesbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>691</width>
<height>598</height>
<height>617</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -776,6 +776,16 @@
<item row="3" column="0">
<widget class="QComboBox" name="mZoomedOutResamplingComboBox"/>
</item>
<item row="5" column="0">
<widget class="QDoubleSpinBox" name="mMaximumOversamplingSpinBox"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mMaximumOversamplingLabel">
<property name="text">
<string>Maximum oversampling</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -1834,6 +1844,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:10pt;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;&quot;&gt;&lt;/p&gt;
Expand Down

0 comments on commit 2c9320a

Please sign in to comment.