74 changes: 74 additions & 0 deletions src/gui/raster/qgsmultibandcolorrendererwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/***************************************************************************
qgsmultibandcolorrendererwidget.cpp
-----------------------------------
begin : February 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmultibandcolorrendererwidget.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgsrasterlayer.h"

QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer* layer ): QgsRasterRendererWidget( layer )
{
setupUi( this );

if ( mRasterLayer )
{
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
if ( !provider )
{
return;
}

//fill available bands into combo boxes
mRedBandComboBox->addItem( tr( "Not set" ), -1 );
mGreenBandComboBox->addItem( tr( "Not set" ), -1 );
mBlueBandComboBox->addItem( tr( "Not set" ), -1 );

int nBands = provider->bandCount();
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
mRedBandComboBox->addItem( provider->colorInterpretationName( i ), i );
mGreenBandComboBox->addItem( provider->colorInterpretationName( i ), i );
mBlueBandComboBox->addItem( provider->colorInterpretationName( i ), i );
}

QgsMultiBandColorRenderer* r = dynamic_cast<QgsMultiBandColorRenderer*>( mRasterLayer->renderer() );
if ( r )
{
mRedBandComboBox->setCurrentIndex( mRedBandComboBox->findData( r->redBand() ) );
mGreenBandComboBox->setCurrentIndex( mGreenBandComboBox->findData( r->greenBand() ) );
mBlueBandComboBox->setCurrentIndex( mBlueBandComboBox->findData( r->blueBand() ) );
}
else
{
mRedBandComboBox->setCurrentIndex( mRedBandComboBox->findText( tr( "Red" ) ) );
mGreenBandComboBox->setCurrentIndex( mGreenBandComboBox->findText( tr( "Green" ) ) );
mBlueBandComboBox->setCurrentIndex( mBlueBandComboBox->findText( tr( "Blue" ) ) );
}
}
}

QgsMultiBandColorRendererWidget::~QgsMultiBandColorRendererWidget()
{
}

QgsRasterRenderer* QgsMultiBandColorRendererWidget::renderer()
{
return new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(),
mRedBandComboBox->itemData( mRedBandComboBox->currentIndex() ).toInt(),
mGreenBandComboBox->itemData( mGreenBandComboBox->currentIndex() ).toInt(),
mBlueBandComboBox->itemData( mBlueBandComboBox->currentIndex() ).toInt()
);
}
38 changes: 38 additions & 0 deletions src/gui/raster/qgsmultibandcolorrendererwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/***************************************************************************
qgsmultibandcolorrendererwidget.h
---------------------------------
begin : February 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSMULTIBANDCOLORRENDERERWIDGET_H
#define QGSMULTIBANDCOLORRENDERERWIDGET_H

#include "qgsrasterrendererwidget.h"
#include "ui_qgsmultibandcolorrendererwidgetbase.h"

class QgsRasterLayer;

class QgsMultiBandColorRendererWidget: public QgsRasterRendererWidget, private Ui::QgsMultiBandColorRendererWidgetBase
{
Q_OBJECT

public:
QgsMultiBandColorRendererWidget( QgsRasterLayer* layer );
static QgsRasterRendererWidget* create( QgsRasterLayer* layer ) { return new QgsMultiBandColorRendererWidget( layer ); }
~QgsMultiBandColorRendererWidget();

QgsRasterRenderer* renderer();
};

#endif // QGSMULTIBANDCOLORRENDERERWIDGET_H
101 changes: 101 additions & 0 deletions src/gui/raster/qgspalettedrendererwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/***************************************************************************
qgspalettedrendererwidget.cpp
-----------------------------
begin : February 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgspalettedrendererwidget.h"
#include "qgspalettedrasterrenderer.h"
#include "qgsrasterlayer.h"
#include <QColorDialog>

QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer* layer ): QgsRasterRendererWidget( layer )
{
setupUi( this );

if ( mRasterLayer )
{
QgsRasterDataProvider* provider = mRasterLayer->dataProvider();
if ( !provider )
{
return;
}

//fill available bands into combo box
int nBands = provider->bandCount();
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
mBandComboBox->addItem( provider->colorInterpretationName( i ), i );
}

QgsPalettedRasterRenderer* r = dynamic_cast<QgsPalettedRasterRenderer*>( mRasterLayer->renderer() );
if ( r )
{
//read values and colors and fill into tree widget
int nColors = r->nColors();
QColor* colors = r->colors();
for ( int i = 0; i < nColors; ++i )
{
QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget );
item->setText( 0, QString::number( i ) );
item->setBackground( 1, QBrush( colors[i] ) );
}
delete[] colors;
}
else
{
//read default palette settings from layer
QList<QgsColorRampShader::ColorRampItem>* itemList =
mRasterLayer->colorTable( mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt() );
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList->constBegin();
int index = 0;
for ( ; itemIt != itemList->constEnd(); ++itemIt )
{
QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget );
item->setText( 0, QString::number( index ) );
item->setBackground( 1, QBrush( itemIt->color ) );
++index;
}
}
}
}

QgsPalettedRendererWidget::~QgsPalettedRendererWidget()
{

}

QgsRasterRenderer* QgsPalettedRendererWidget::renderer()
{
int nColors = mTreeWidget->topLevelItemCount();
QColor* colorArray = new QColor[nColors];
for ( int i = 0; i < nColors; ++i )
{
colorArray[i] = mTreeWidget->topLevelItem( i )->background( 1 ).color();
}
int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
return new QgsPalettedRasterRenderer( mRasterLayer->dataProvider(), bandNumber, colorArray, nColors );
}

void QgsPalettedRendererWidget::on_mTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column )
{
if ( column == 1 && item ) //change item color
{
QColor c = QColorDialog::getColor( item->background( column ).color() );
if ( c.isValid() )
{
item->setBackground( column, QBrush( c ) );
}
}
}
41 changes: 41 additions & 0 deletions src/gui/raster/qgspalettedrendererwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/***************************************************************************
qgspalettedrendererwidget.h
---------------------------
begin : February 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSPALETTEDRENDERERWIDGET_H
#define QGSPALETTEDRENDERERWIDGET_H

#include "qgsrasterrendererwidget.h"
#include "ui_qgspalettedrendererwidgetbase.h"

class QgsRasterLayer;

class QgsPalettedRendererWidget: public QgsRasterRendererWidget, private Ui::QgsPalettedRendererWidgetBase
{
Q_OBJECT

public:
QgsPalettedRendererWidget( QgsRasterLayer* layer );
static QgsRasterRendererWidget* create( QgsRasterLayer* layer ) { return new QgsPalettedRendererWidget( layer ); }
~QgsPalettedRendererWidget();

QgsRasterRenderer* renderer();

private slots:
void on_mTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column );
};

#endif // QGSPALETTEDRENDERERWIDGET_H
41 changes: 41 additions & 0 deletions src/gui/raster/qgsrasterrendererwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/***************************************************************************
qgsrasterrendererwidget.h
---------------------------
begin : February 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSRASTERRENDERERWIDGET_H
#define QGSRASTERRENDERERWIDGET_H

#include <QWidget>

class QgsRasterLayer;
class QgsRasterRenderer;

class QgsRasterRendererWidget: public QWidget
{
public:
QgsRasterRendererWidget( QgsRasterLayer* layer ) { mRasterLayer = layer; }
virtual ~QgsRasterRendererWidget() {}

virtual QgsRasterRenderer* renderer() = 0;

void setRasterLayer( QgsRasterLayer* layer ) { mRasterLayer = layer; }
const QgsRasterLayer* rasterLayer() const { return mRasterLayer; }

protected:
QgsRasterLayer* mRasterLayer;
};

#endif // QGSRASTERRENDERERWIDGET_H
69 changes: 69 additions & 0 deletions src/ui/qgsmultibandcolorrendererwidgetbase.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsMultiBandColorRendererWidgetBase</class>
<widget class="QWidget" name="QgsMultiBandColorRendererWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>248</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="mRedBandLabel">
<property name="text">
<string>Red band</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mRedBandComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mGreenBandLabel">
<property name="text">
<string>Green band</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mGreenBandComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mBlueBandLabel">
<property name="text">
<string>Blue band</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mBlueBandComboBox"/>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="mMinMaxGroupBox">
<property name="title">
<string>Min/Max values</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="mContrastEnhancementGroupBox">
<property name="title">
<string>Contrast enhancement</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
55 changes: 55 additions & 0 deletions src/ui/qgspalettedrendererwidgetbase.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsPalettedRendererWidgetBase</class>
<widget class="QWidget" name="QgsPalettedRendererWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>211</width>
<height>256</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mBandLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Band</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mBandComboBox"/>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="mTreeWidget">
<column>
<property name="text">
<string>Value</string>
</property>
</column>
<column>
<property name="text">
<string>Color</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
159 changes: 134 additions & 25 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>691</width>
<height>617</height>
<width>706</width>
<height>663</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -36,6 +36,113 @@
<height>22</height>
</size>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string comment="mRendererTab">Style</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_10">
<item row="0" column="0">
<widget class="QGroupBox" name="mResamplingGroupBox_2">
<property name="title">
<string>Resampling</string>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<widget class="QLabel" name="mZoomedInResamplingLabel">
<property name="text">
<string>Zoomed in</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="mZoomedOutResamplingLabel">
<property name="text">
<string>Zoomed out</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="mMaximumOversamplingLabel">
<property name="text">
<string>Maximum oversampling</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="mZoomedInResamplingComboBox"/>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mZoomedOutResamplingComboBox"/>
</item>
<item row="1" column="2">
<widget class="QDoubleSpinBox" name="mMaximumOversamplingSpinBox"/>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="mRenderTypeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>32767</width>
<height>22</height>
</size>
</property>
<property name="text">
<string>Render type</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mRenderTypeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>26</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32767</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>318</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QStackedWidget" name="mRendererStackedWidget"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabPageSymbology">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
Expand Down Expand Up @@ -757,30 +864,30 @@
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="1" column="0">
<widget class="QComboBox" name="mZoomedInResamplingComboBox"/>
<widget class="QComboBox" name="mZoomedInResamplingComboBox_3"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mZoomedInResamplingLabel">
<widget class="QLabel" name="mZoomedInResamplingLabel_3">
<property name="text">
<string>Zoomed in</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mZoomedOutResamplingLabel">
<widget class="QLabel" name="mZoomedOutResamplingLabel_3">
<property name="text">
<string>Zoomed out</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QComboBox" name="mZoomedOutResamplingComboBox"/>
<widget class="QComboBox" name="mZoomedOutResamplingComboBox_3"/>
</item>
<item row="5" column="0">
<widget class="QDoubleSpinBox" name="mMaximumOversamplingSpinBox"/>
<widget class="QDoubleSpinBox" name="mMaximumOversamplingSpinBox_3"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mMaximumOversamplingLabel">
<widget class="QLabel" name="mMaximumOversamplingLabel_3">
<property name="text">
<string>Maximum oversampling</string>
</property>
Expand Down Expand Up @@ -1845,6 +1952,8 @@ 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;&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 Expand Up @@ -1961,17 +2070,20 @@ p, li { white-space: pre-wrap; }
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pbnLoadDefaultStyle">
<property name="text">
<string>Restore Default Style</string>
<item row="2" column="0" colspan="4">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pbnSaveDefaultStyle">
<item row="1" column="3">
<widget class="QPushButton" name="pbnSaveStyleAs">
<property name="text">
<string>Save As Default</string>
<string>Save Style ...</string>
</property>
</widget>
</item>
Expand All @@ -1982,20 +2094,17 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="pbnSaveStyleAs">
<item row="1" column="0">
<widget class="QPushButton" name="pbnLoadDefaultStyle">
<property name="text">
<string>Save Style ...</string>
<string>Restore Default Style</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
<item row="1" column="1">
<widget class="QPushButton" name="pbnSaveDefaultStyle">
<property name="text">
<string>Save As Default</string>
</property>
</widget>
</item>
Expand Down