Skip to content
Permalink
Browse files
Started widget for multiband color
  • Loading branch information
mhugent committed Feb 17, 2012
1 parent ae2899a commit 200124916daa2f18f15cbeca175ae36f630deeea
@@ -388,7 +388,7 @@ INCLUDE_DIRECTORIES(
../core
../core/gps ../core/gps/qextserialport
../core/composer ../core/raster ../core/renderer ../core/symbology ../core/symbology-ng
../gui ../gui/symbology-ng ../gui/attributetable
../gui ../gui/symbology-ng ../gui/attributetable ../gui/raster
../plugins
../python
gps
@@ -39,6 +39,10 @@
#include "qgsrastertransparency.h"
#include "qgsmaptoolemitpoint.h"

#include "qgsrasterrendererregistry.h"
#include "qgsmultibandcolorrendererwidget.h"
#include "qgspalettedrendererwidget.h"

#include <QTableWidgetItem>
#include <QHeaderView>

@@ -67,7 +71,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
: QDialog( parent, fl ),
// Constant that signals property not used.
TRSTRING_NOT_SET( tr( "Not Set" ) ),
mRasterLayer( qobject_cast<QgsRasterLayer *>( lyr ) )
mRasterLayer( qobject_cast<QgsRasterLayer *>( lyr ) ), mRendererWidget( 0 )
{
ignoreSpinBoxEvent = false; //Short circuit signal loop between min max field and stdDev spin box
mGrayMinimumMaximumEstimated = true;
@@ -329,6 +333,19 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
}
mMaximumOversamplingSpinBox->setValue( renderer->maxOversampling() );
}

//insert renderer widgets into registry
QgsRasterRendererRegistry::instance()->insertWidgetFunction( "paletted", QgsPalettedRendererWidget::create );
QgsRasterRendererRegistry::instance()->insertWidgetFunction( "multibandcolor", QgsMultiBandColorRendererWidget::create );

//fill available renderers into combo box
QList< QgsRasterRendererRegistryEntry > rendererEntries = QgsRasterRendererRegistry::instance()->entries();
QList< QgsRasterRendererRegistryEntry >::const_iterator rendererIt = rendererEntries.constBegin();
for ( ; rendererIt != rendererEntries.constEnd(); ++rendererIt )
{
mRenderTypeComboBox->addItem( rendererIt->visibleName, rendererIt->name );
}
on_mRenderTypeComboBox_currentIndexChanged( mRenderTypeComboBox->currentIndex() );
} // QgsRasterLayerProperties ctor


@@ -1397,6 +1414,11 @@ void QgsRasterLayerProperties::apply()
pixmapLegend->setScaledContents( true );
pixmapLegend->repaint();

//set renderer from widget
QgsRasterRendererWidget* rendererWidget = dynamic_cast<QgsRasterRendererWidget*>( mRendererStackedWidget->currentWidget() );
mRasterLayer->setRenderer( rendererWidget->renderer() );

#if 0
//set the appropriate render style
if ( rbtnSingleBand->isChecked() )
{
@@ -1489,6 +1511,7 @@ void QgsRasterLayerProperties::apply()
}
}
//set render style finished
#endif //0


//resampling
@@ -1715,6 +1738,29 @@ void QgsRasterLayerProperties::on_buttonBuildPyramids_clicked()
txtbMetadata->document()->setDefaultStyleSheet( myStyle );
}

void QgsRasterLayerProperties::on_mRenderTypeComboBox_currentIndexChanged( int index )
{
delete mRendererWidget;
mRendererWidget = 0;

if ( index < 0 )
{
return;
}

QString rendererName = mRenderTypeComboBox->itemData( index ).toString();

QgsRasterRendererRegistryEntry rendererEntry;
if ( QgsRasterRendererRegistry::instance()->rendererData( rendererName, rendererEntry ) )
{
if ( rendererEntry.widgetCreateFunction )
{
mRendererWidget = ( *rendererEntry.widgetCreateFunction )( mRasterLayer );
mRendererStackedWidget->addWidget( mRendererWidget );
}
}
}

void QgsRasterLayerProperties::on_cboBlue_currentIndexChanged( const QString& theText )
{
if ( TRSTRING_NOT_SET != theText )
@@ -29,6 +29,7 @@ class QgsMapLayer;
class QgsMapCanvas;
class QgsRasterLayer;
class QgsMapToolEmitPoint;
class QgsRasterRendererWidget;

/**Property sheet for a raster map layer
*@author Tim Sutton
@@ -99,6 +100,7 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
void userDefinedMinMax_textEdited( QString );

private slots:
void on_mRenderTypeComboBox_currentIndexChanged( int index );
/** This slow handles necessary interface modifications (i.e. loading min max values) */
void on_cboBlue_currentIndexChanged( const QString& );
/** This slow handles necessary interface modifications (i.e. loading min max values) */
@@ -186,6 +188,8 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
*/
//bool mRasterLayerIsInternal;

QgsRasterRendererWidget* mRendererWidget;

/** \brief Clear current color map table and population with values from new list */
void populateColorMapTable( const QList<QgsColorRampShader::ColorRampItem>& );

@@ -35,6 +35,11 @@ QgsMultiBandColorRenderer::~QgsMultiBandColorRenderer()
{
}

QgsRasterRenderer* QgsMultiBandColorRenderer::create( const QDomElement& elem )
{
return 0;
}

void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
{
if ( !p || !mProvider || !viewPort || !theQgsMapToPixel )
@@ -21,6 +21,7 @@
#include "qgsrasterrenderer.h"

class QgsContrastEnhancement;
class QDomElement;

/**Renderer for multiband images with the color components*/
class QgsMultiBandColorRenderer: public QgsRasterRenderer
@@ -31,8 +32,17 @@ class QgsMultiBandColorRenderer: public QgsRasterRenderer
QgsContrastEnhancement* blueEnhancement = 0 );
~QgsMultiBandColorRenderer();

static QgsRasterRenderer* create( const QDomElement& elem );

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

int redBand() const { return mRedBand; }
void setRedBand( int band ) { mRedBand = band; }
int greenBand() const { return mGreenBand; }
void setGreenBand( int band ) { mGreenBand = band; }
int blueBand() const { return mBlueBand; }
void setBlueBand( int band ) { mBlueBand = band; }

const QgsContrastEnhancement* redContrastEnhancement() const { return mRedContrastEnhancement; }
void setRedContrastEnhancement( QgsContrastEnhancement* ce ) { mRedContrastEnhancement = ce; }

@@ -32,6 +32,25 @@ QgsPalettedRasterRenderer::~QgsPalettedRasterRenderer()
delete[] mColors;
}

QgsRasterRenderer* QgsPalettedRasterRenderer::create( const QDomElement& elem )
{
return 0;
}

QColor* QgsPalettedRasterRenderer::colors() const
{
if ( mNColors < 1 )
{
return 0;
}
QColor* colorArray = new QColor[ mNColors ];
for ( int i = 0; i < mNColors; ++i )
{
colorArray[i] = mColors[i];
}
return colorArray;
}

void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )
{
if ( !p || !mProvider || !viewPort || !theQgsMapToPixel )
@@ -21,15 +21,23 @@
#include "qgsrasterrenderer.h"

class QColor;
class QDomElement;

class QgsPalettedRasterRenderer: public QgsRasterRenderer
{
public:
/**Renderer owns color array*/
QgsPalettedRasterRenderer( QgsRasterDataProvider* provider, int bandNumber, QColor* colorArray, int nColors );
~QgsPalettedRasterRenderer();
static QgsRasterRenderer* create( const QDomElement& elem );

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

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

private:
int mBandNumber;
/**Color array*/
@@ -16,12 +16,14 @@
***************************************************************************/

#include "qgsrasterrendererregistry.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgspalettedrasterrenderer.h"

QgsRasterRendererRegistry* QgsRasterRendererRegistry::mInstance = 0;

QgsRasterRendererRegistry* QgsRasterRendererRegistry::instance()
{
if( !mInstance )
if ( !mInstance )
{
mInstance = new QgsRasterRendererRegistry();
}
@@ -30,6 +32,21 @@ QgsRasterRendererRegistry* QgsRasterRendererRegistry::instance()

QgsRasterRendererRegistry::QgsRasterRendererRegistry()
{
//add entry for palleted renderer
QgsRasterRendererRegistryEntry palettedEntry;
palettedEntry.name = "paletted";
palettedEntry.visibleName = QObject::tr( "Paletted" );
palettedEntry.rendererCreateFunction = QgsPalettedRasterRenderer::create;
//widget function will be assigned later in raster properties dialog with QgsRasterRendererRegistry::insertWidgetFunction
palettedEntry.widgetCreateFunction = 0;
insert( palettedEntry );

QgsRasterRendererRegistryEntry multiBandColorEntry;
multiBandColorEntry.name = "multibandcolor";
multiBandColorEntry.visibleName = QObject::tr( "Multiband color" );
palettedEntry.rendererCreateFunction = QgsMultiBandColorRenderer::create;
multiBandColorEntry.widgetCreateFunction = 0;
insert( multiBandColorEntry );
}

QgsRasterRendererRegistry::~QgsRasterRendererRegistry()
@@ -41,15 +58,42 @@ void QgsRasterRendererRegistry::insert( QgsRasterRendererRegistryEntry entry )
mEntries.insert( entry.name, entry );
}

void QgsRasterRendererRegistry::insertWidgetFunction( const QString& rendererName, QgsRasterRendererWidgetCreateFunc func )
{
if ( !mEntries.contains( rendererName ) )
{
return;
}

mEntries[rendererName].widgetCreateFunction = func;
}

bool QgsRasterRendererRegistry::rendererData( const QString& rendererName, QgsRasterRendererRegistryEntry& data ) const
{
QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.find( rendererName );
if( it == mEntries.constEnd() )
if ( it == mEntries.constEnd() )
{
return false;
}
data = it.value();
return true;
}

QStringList QgsRasterRendererRegistry::renderersList() const
{
return QStringList( mEntries.keys() );
}

QList< QgsRasterRendererRegistryEntry > QgsRasterRendererRegistry::entries() const
{
QList< QgsRasterRendererRegistryEntry > result;

QHash< QString, QgsRasterRendererRegistryEntry >::const_iterator it = mEntries.constBegin();
for ( ; it != mEntries.constEnd(); ++it )
{
result.push_back( it.value() );
}
return result;
}


@@ -21,16 +21,21 @@
#include <QHash>
#include <QString>

class QDomElement;
class QgsRasterDataProvider;
class QgsRasterLayer;
class QgsRasterRenderer;
class QgsRasterRendererWidget;

typedef QgsRasterRenderer*(*QgsRasterRendererCreateFunc)(const QDomElement&);
typedef QgsRasterRenderer*( *QgsRasterRendererCreateFunc )( const QDomElement& );
typedef QgsRasterRendererWidget*( *QgsRasterRendererWidgetCreateFunc )( QgsRasterLayer* );

struct QgsRasterRendererRegistryEntry
{
QString name;
QString visibleName; //visible (and translatable) name
QgsRasterRendererCreateFunc rendererCreateFunction; //pointer to create function
//pointer to create function for renderer widget
QgsRasterRendererWidgetCreateFunc widgetCreateFunction; //pointer to create function for renderer widget
};

class QgsRasterRendererRegistry
@@ -40,7 +45,10 @@ class QgsRasterRendererRegistry
~QgsRasterRendererRegistry();

void insert( QgsRasterRendererRegistryEntry entry );
void insertWidgetFunction( const QString& rendererName, QgsRasterRendererWidgetCreateFunc func );
bool rendererData( const QString& rendererName, QgsRasterRendererRegistryEntry& data ) const;
QStringList renderersList() const;
QList< QgsRasterRendererRegistryEntry > entries() const;

protected:
QgsRasterRendererRegistry();
@@ -1,6 +1,9 @@

SET(QGIS_GUI_SRCS

raster/qgsmultibandcolorrendererwidget.cpp
raster/qgspalettedrendererwidget.cpp

symbology-ng/qgsbrushstylecombobox.cpp
symbology-ng/qgscolorrampcombobox.cpp
symbology-ng/qgsdashspacedialog.cpp
@@ -80,6 +83,9 @@ qgsquerybuilder.cpp

SET(QGIS_GUI_MOC_HDRS

raster/qgspalettedrendererwidget.h
raster/qgsmultibandcolorrendererwidget.h

symbology-ng/qgsdashspacedialog.h
symbology-ng/qgssymbollayerv2widget.h
symbology-ng/qgssymbolv2propertiesdialog.h
@@ -212,6 +218,7 @@ ELSE (WITH_INTERNAL_SPATIALITE)
ENDIF (WITH_INTERNAL_SPATIALITE)

INCLUDE_DIRECTORIES(${GEOS_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${GDAL_INCLUDE_DIR})

IF (WIN32)
IF (MSVC)

0 comments on commit 2001249

Please sign in to comment.