Skip to content

Commit

Permalink
Merge branch 'master' of github.com:qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Jun 14, 2012
2 parents f3f1c43 + 9a006e4 commit 42a5eb9
Show file tree
Hide file tree
Showing 51 changed files with 694 additions and 514 deletions.
19 changes: 5 additions & 14 deletions python/core/qgsrasterlayer.sip
Expand Up @@ -35,15 +35,10 @@ public:
bool loadDefaultStyleFlag = true );

/** \brief [ data provider interface ] Constructor in provider mode */
QgsRasterLayer( int dummy,
const QString & baseName = QString(),
const QString & path = QString(),
const QString & providerLib = QString(),
const QStringList & layers = QStringList(),
const QStringList & styles = QStringList(),
const QString & format = QString(),
const QString & crs = QString());

QgsRasterLayer( const QString & uri,
const QString & baseName,
const QString & providerKey,
bool loadDefaultStyleFlag = true );

/** \brief The destructor */
~QgsRasterLayer();
Expand Down Expand Up @@ -195,11 +190,7 @@ public:
QString redBandName();

/** [ data provider interface ] Set the data provider */
void setDataProvider( const QString & provider,
const QStringList & layers,
const QStringList & styles,
const QString & format,
const QString & crs );
void setDataProvider( const QString & provider );

/** \brief Mutator for drawing style */
void setDrawingStyle( const DrawingStyle & theDrawingStyle );
Expand Down
189 changes: 189 additions & 0 deletions python/core/qgsrasterrenderer.sip
@@ -0,0 +1,189 @@
class QgsRasterRenderer
{
%TypeHeaderCode
#include "qgsrasterrenderer.h"
#include "qgspalettedrasterrenderer.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgssinglebandpseudocolorrenderer.h"
#include "qgssinglebandgrayrenderer.h"
#include "qgssinglebandcolordatarenderer.h"
%End

%ConvertToSubClassCode
if (dynamic_cast<QgsPalettedRasterRenderer*>(sipCpp) != NULL)
sipClass = sipClass_QgsPalettedRasterRenderer;
else if (dynamic_cast<QgsMultiBandColorRenderer*>(sipCpp) != NULL)
sipClass = sipClass_QgsMultiBandColorRenderer;
else if (dynamic_cast<QgsSingleBandPseudoColorRenderer*>(sipCpp) != NULL)
sipClass = sipClass_QgsSingleBandPseudoColorRenderer;
else if (dynamic_cast<QgsSingleBandGrayRenderer*>(sipCpp) != NULL)
sipClass = sipClass_QgsSingleBandGrayRenderer;
else if (dynamic_cast<QgsSingleBandGrayRenderer*>(sipCpp) != NULL)
sipClass = sipClass_QgsSingleBandGrayRenderer;
else
sipClass = 0;
%End

public:
QgsRasterRenderer( QgsRasterDataProvider* provider, const QString& type );
virtual ~QgsRasterRenderer();

virtual QString type() const;
virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel ) = 0;

bool usesTransparency( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const;

void setOpacity( double opacity );
double opacity() const;

void setRasterTransparency( QgsRasterTransparency* t );
const QgsRasterTransparency* rasterTransparency() const;

void setAlphaBand( int band );
int alphaBand() const;

void setInvertColor( bool invert );
bool invertColor() const;

/**Set resampler for zoomed in scales. Takes ownership of the object*/
void setZoomedInResampler( QgsRasterResampler* r );
const QgsRasterResampler* zoomedInResampler();

/**Set resampler for zoomed out scales. Takes ownership of the object*/
void setZoomedOutResampler( QgsRasterResampler* r );
const QgsRasterResampler* zoomedOutResampler() const;

void setMaxOversampling( double os );
double maxOversampling() const;

/**Get symbology items if provided by renderer*/
virtual void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;

virtual void writeXML( QDomDocument& doc, QDomElement& parentElem ) const = 0;

/**Sets base class members from xml. Usually called from create() methods of subclasses*/
void readXML( const QDomElement& rendererElem );
};

class QgsPalettedRasterRenderer: public QgsRasterRenderer
{
%TypeHeaderCode
#include "qgspalettedrasterrenderer.h"
%End
public:
/**Renderer owns color array*/
QgsPalettedRasterRenderer( QgsRasterDataProvider* provider, int bandNumber, QColor* colorArray, int nColors );
~QgsPalettedRasterRenderer();
static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterDataProvider* provider );

void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );

/**Returns number of colors*/
int nColors() const;
/**Returns copy of color array (caller takes ownership)*/
QColor* colors() const;

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
};

class QgsMultiBandColorRenderer: public QgsRasterRenderer
{
%TypeHeaderCode
#include "qgsmultibandcolorrenderer.h"
%End
public:
QgsMultiBandColorRenderer( QgsRasterDataProvider* provider, int redBand, int greenBand, int blueBand,
QgsContrastEnhancement* redEnhancement = 0, QgsContrastEnhancement* greenEnhancement = 0,
QgsContrastEnhancement* blueEnhancement = 0 );
~QgsMultiBandColorRenderer();

static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterDataProvider* provider );

void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );

int redBand() const;
void setRedBand( int band );
int greenBand() const;
void setGreenBand( int band );
int blueBand() const;
void setBlueBand( int band );

const QgsContrastEnhancement* redContrastEnhancement() const;
/**Takes ownership*/
void setRedContrastEnhancement( QgsContrastEnhancement* ce );

const QgsContrastEnhancement* greenContrastEnhancement() const;
/**Takes ownership*/
void setGreenContrastEnhancement( QgsContrastEnhancement* ce );

const QgsContrastEnhancement* blueContrastEnhancement() const;
/**Takes ownership*/
void setBlueContrastEnhancement( QgsContrastEnhancement* ce );

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;
};

class QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer
{
%TypeHeaderCode
#include "qgssinglebandpseudocolorrenderer.h"
%End
public:
/**Note: takes ownership of QgsRasterShader*/
QgsSingleBandPseudoColorRenderer( QgsRasterDataProvider* provider, int band, QgsRasterShader* shader );
~QgsSingleBandPseudoColorRenderer();

static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterDataProvider* provider );

virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );

/**Takes ownership of the shader*/
void setShader( QgsRasterShader* shader );
QgsRasterShader* shader();

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
};

class QgsSingleBandGrayRenderer: public QgsRasterRenderer
{
%TypeHeaderCode
#include "qgssinglebandgrayrenderer.h"
%End
public:
QgsSingleBandGrayRenderer( QgsRasterDataProvider* provider, int grayBand );
~QgsSingleBandGrayRenderer();

static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterDataProvider* provider );

virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );

int grayBand() const;
void setGrayBand( int band );
const QgsContrastEnhancement* contrastEnhancement() const;
/**Takes ownership*/
void setContrastEnhancement( QgsContrastEnhancement* ce );

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;

void legendSymbologyItems( QList< QPair< QString, QColor > >& symbolItems ) const;
};

class QgsSingleBandColorDataRenderer: public QgsRasterRenderer
{
%TypeHeaderCode
#include "qgssinglebandcolordatarenderer.h"
%End
public:
QgsSingleBandColorDataRenderer( QgsRasterDataProvider* provider, int band );
~QgsSingleBandColorDataRenderer();

static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterDataProvider* provider );

virtual void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );

void writeXML( QDomDocument& doc, QDomElement& parentElem ) const;
};
47 changes: 47 additions & 0 deletions python/core/qgsrasterresampler.sip
@@ -0,0 +1,47 @@
class QgsRasterResampler
{
%TypeHeaderCode
#include "qgsrasterresampler.h"
#include "qgsbilinearrasterresampler.h"
#include "qgscubicrasterresampler.h"

%End

%ConvertToSubClassCode
if (dynamic_cast<QgsBilinearRasterResampler*>(sipCpp) != NULL)
sipClass = sipClass_QgsBilinearRasterResampler;
else if (dynamic_cast<QgsCubicRasterResampler*>(sipCpp) != NULL)
sipClass = sipClass_QgsCubicRasterResampler;
else
sipClass = 0;
%End

public:
virtual void resample( const QImage& srcImage, QImage& dstImage ) = 0;
virtual QString type() const = 0;
};

class QgsBilinearRasterResampler: public QgsRasterResampler
{
%TypeHeaderCode
#include "qgsbilinearrasterresampler.h"
%End
public:
QgsBilinearRasterResampler();
~QgsBilinearRasterResampler();

void resample( const QImage& srcImage, QImage& dstImage );
QString type() const;
};

class QgsCubicRasterResampler: public QgsRasterResampler
{
%TypeHeaderCode
#include "qgscubicrasterresampler.h"
%End
public:
QgsCubicRasterResampler();
~QgsCubicRasterResampler();
void resample( const QImage& srcImage, QImage& dstImage );
QString type() const;
};
2 changes: 1 addition & 1 deletion python/gui/qgisinterface.sip
Expand Up @@ -46,7 +46,7 @@ class QgisInterface : QObject
//! Add a raster layer given a raster layer file name
virtual QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName = QString())=0;
//! Add a WMS layer
virtual QgsRasterLayer* addRasterLayer(const QString& url, const QString& layerName, const QString& providerKey, const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs) = 0;
virtual QgsRasterLayer* addRasterLayer(const QString& uri, const QString& baseName, const QString& providerKey) = 0;

//! Add a project
virtual bool addProject(QString theProject)=0;
Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgslegend.cpp
Expand Up @@ -2541,7 +2541,7 @@ void QgsLegend::groupSelectedLayers()
//avoid multiple refreshes of map canvas because of itemChanged signal
blockSignals( true );

QTreeWidgetItem * parent;
QTreeWidgetItem * parent = 0;
foreach( QTreeWidgetItem* item, selectedItems() )
{
parent = item->parent();
Expand Down
53 changes: 10 additions & 43 deletions src/app/qgisapp.cpp
Expand Up @@ -753,7 +753,7 @@ void QgisApp::dropEvent( QDropEvent *event )
}
else if ( u.layerType == "raster" )
{
addRasterLayer( u.uri, u.name, u.providerKey, QStringList(), QStringList(), QString(), QString() );
addRasterLayer( u.uri, u.name, u.providerKey );
}
}
}
Expand Down Expand Up @@ -2632,10 +2632,8 @@ void QgisApp::addWmsLayer()
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
return;
}
connect( wmss , SIGNAL( addRasterLayer( QString const &, QString const &, QString const &, QStringList const &, QStringList const &, QString const &,
QString const & ) ),
this , SLOT( addRasterLayer( QString const &, QString const &, QString const &, QStringList const &, QStringList const &, QString const &,
QString const & ) ) );
connect( wmss , SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this , SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
wmss->exec();
delete wmss;
}
Expand Down Expand Up @@ -6813,22 +6811,17 @@ QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterFile, QString con

/** Add a raster layer directly without prompting user for location
The caller must provide information compatible with the provider plugin
using the rasterLayerPath and baseName. The provider can use these
using the uri and baseName. The provider can use these
parameters in any way necessary to initialize the layer. The baseName
parameter is used in the Map Legend so it should be formed in a meaningful
way.
\note Copied from the equivalent addVectorLayer function in this file
TODO Make it work for rasters specifically.
*/
QgsRasterLayer* QgisApp::addRasterLayer(
QString const &rasterLayerPath,
QString const &uri,
QString const &baseName,
QString const &providerKey,
QStringList const & layers,
QStringList const & styles,
QString const &format,
QString const &crs )
QString const &providerKey )
{
QgsDebugMsg( "about to get library for " + providerKey );

Expand All @@ -6839,42 +6832,20 @@ QgsRasterLayer* QgisApp::addRasterLayer(

mMapCanvas->freeze();

// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

// create the layer
QgsRasterLayer *layer;
/* Eliminate the need to instantiate the layer based on provider type.
The caller is responsible for cobbling together the needed information to
open the layer
*/
QgsDebugMsg( "Creating new raster layer using " + rasterLayerPath
+ " with baseName of " + baseName
+ " and layer list of " + layers.join( ", " )
+ " and style list of " + styles.join( ", " )
+ " and format of " + format
+ " and providerKey of " + providerKey
+ " and CRS of " + crs );
QgsDebugMsg( "Creating new raster layer using " + uri
+ " with baseName of " + baseName );

// TODO: Remove the 0 when the raster layer becomes a full provider gateway.
layer = new QgsRasterLayer( 0, rasterLayerPath, baseName, providerKey, layers, styles, format, crs );
layer = new QgsRasterLayer( uri, baseName, providerKey );

QgsDebugMsg( "Constructed new layer." );

if ( layer && shouldAskUserForGDALSublayers( layer ) )
{
askUserForGDALSublayers( layer );

// The first layer loaded is not useful in that case. The user can select it in
// the list if he wants to load it.
delete layer;
}
else if ( layer && layer->isValid() )
if ( layer && layer->isValid() )
{
addRasterLayer( layer );

statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );

}
else
{
Expand All @@ -6889,10 +6860,6 @@ QgsRasterLayer* QgisApp::addRasterLayer(
mMapCanvas->refresh();

return layer;

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

} // QgisApp::addRasterLayer


Expand Down

0 comments on commit 42a5eb9

Please sign in to comment.