115 changes: 108 additions & 7 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
{
setupUi( this );

mColormapTreeWidget->setColumnWidth( 1, 50 );

mColorRampComboBox->populate( QgsStyleV2::defaultStyle() );

if ( !mRasterLayer )
Expand All @@ -47,6 +49,20 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
return;
}

// Must be before adding items to mBandComboBox (signal)
mMinLineEdit->setValidator( new QDoubleValidator( mMinLineEdit ) );
mMaxLineEdit->setValidator( new QDoubleValidator( mMaxLineEdit ) );

mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this );
mMinMaxWidget->setExtent( extent );
QHBoxLayout *layout = new QHBoxLayout();
layout->setContentsMargins( 0, 0, 0, 0 );
mMinMaxContainerWidget->setLayout( layout );
layout->addWidget( mMinMaxWidget );
connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ),
this, SLOT( loadMinMax( int, double, double, int ) ) );


//fill available bands into combo box
int nBands = provider->bandCount();
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
Expand All @@ -61,6 +77,8 @@ QgsSingleBandPseudoColorRendererWidget::QgsSingleBandPseudoColorRendererWidget(
mClassificationModeComboBox->addItem( tr( "Equal interval" ) );
//quantile would be nice as well

mNumberOfEntriesSpinBox->setValue( 5 ); // some default

setFromRenderer( layer->renderer() );
}

Expand Down Expand Up @@ -109,7 +127,12 @@ QgsRasterRenderer* QgsSingleBandPseudoColorRendererWidget::renderer()
rasterShader->setRasterShaderFunction( colorRampShader );

int bandNumber = mBandComboBox->itemData( mBandComboBox->currentIndex() ).toInt();
return new QgsSingleBandPseudoColorRenderer( mRasterLayer->dataProvider(), bandNumber, rasterShader );
QgsSingleBandPseudoColorRenderer *renderer = new QgsSingleBandPseudoColorRenderer( mRasterLayer->dataProvider(), bandNumber, rasterShader );

renderer->setClassificationMin( lineEditValue( mMinLineEdit ) );
renderer->setClassificationMax( lineEditValue( mMaxLineEdit ) );
renderer->setClassificationMinMaxOrigin( mMinMaxOrigin );
return renderer;
}

void QgsSingleBandPseudoColorRendererWidget::on_mAddEntryButton_clicked()
Expand Down Expand Up @@ -190,27 +213,32 @@ void QgsSingleBandPseudoColorRendererWidget::on_mClassifyButton_clicked()
return;
}

int bandNr = mBandComboBox->itemData( bandComboIndex ).toInt();
QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
//int bandNr = mBandComboBox->itemData( bandComboIndex ).toInt();
//QgsRasterBandStats myRasterBandStats = mRasterLayer->dataProvider()->bandStatistics( bandNr );
int numberOfEntries = mNumberOfEntriesSpinBox->value();

QList<double> entryValues;
QList<QColor> entryColors;

double min = lineEditValue( mMinLineEdit );
double max = lineEditValue( mMaxLineEdit );

if ( mClassificationModeComboBox->currentText() == tr( "Equal interval" ) )
{
double currentValue = myRasterBandStats.minimumValue;
//double currentValue = myRasterBandStats.minimumValue;
double currentValue = min;
double intervalDiff;
if ( numberOfEntries > 1 )
{
//because the highest value is also an entry, there are (numberOfEntries - 1)
//intervals
intervalDiff = ( myRasterBandStats.maximumValue - myRasterBandStats.minimumValue ) /
( numberOfEntries - 1 );
//intervalDiff = ( myRasterBandStats.maximumValue - myRasterBandStats.minimumValue ) /
intervalDiff = ( max - min ) / ( numberOfEntries - 1 );
}
else
{
intervalDiff = myRasterBandStats.maximumValue - myRasterBandStats.minimumValue;
//intervalDiff = myRasterBandStats.maximumValue - myRasterBandStats.minimumValue;
intervalDiff = max - min;
}

for ( int i = 0; i < numberOfEntries; ++i )
Expand Down Expand Up @@ -515,5 +543,78 @@ void QgsSingleBandPseudoColorRendererWidget::setFromRenderer( const QgsRasterRen
}
}
}
setLineEditValue( mMinLineEdit, pr->classificationMin() );
setLineEditValue( mMaxLineEdit, pr->classificationMax() );
mMinMaxOrigin = pr->classificationMinMaxOrigin();
showMinMaxOrigin();
}
}

void QgsSingleBandPseudoColorRendererWidget::on_mBandComboBox_currentIndexChanged( int index )
{
QList<int> myBands;
myBands.append( mBandComboBox->itemData( index ).toInt() );
mMinMaxWidget->setBands( myBands );
}

void QgsSingleBandPseudoColorRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin )
{
QgsDebugMsg( QString( "theBandNo = %1 theMin = %2 theMax = %3" ).arg( theBandNo ).arg( theMin ).arg( theMax ) );

if ( qIsNaN( theMin ) )
{
mMinLineEdit->clear();
}
else
{
mMinLineEdit->setText( QString::number( theMin ) );
}

if ( qIsNaN( theMax ) )
{
mMaxLineEdit->clear();
}
else
{
mMaxLineEdit->setText( QString::number( theMax ) );
}

mMinMaxOrigin = theOrigin;
showMinMaxOrigin();
}

void QgsSingleBandPseudoColorRendererWidget::showMinMaxOrigin()
{
mMinMaxOriginLabel->setText( QgsRasterRenderer::minMaxOriginLabel( mMinMaxOrigin ) );
}

void QgsSingleBandPseudoColorRendererWidget::setLineEditValue( QLineEdit * theLineEdit, double theValue )
{
QString s;
if ( !qIsNaN( theValue ) )
{
s = QString::number( theValue );
}
theLineEdit->setText( s );
}

double QgsSingleBandPseudoColorRendererWidget::lineEditValue( const QLineEdit * theLineEdit ) const
{
if ( theLineEdit->text().isEmpty() )
{
return std::numeric_limits<double>::quiet_NaN();
}

return theLineEdit->text().toDouble();
}

void QgsSingleBandPseudoColorRendererWidget::resetClassifyButton()
{
mClassifyButton->setEnabled( true );
double min = lineEditValue( mMinLineEdit );
double max = lineEditValue( mMaxLineEdit );
if ( qIsNaN( min ) || qIsNaN( max ) || min >= max )
{
mClassifyButton->setEnabled( false );
}
}
17 changes: 17 additions & 0 deletions src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef QGSSINGLEBANDCOLORRENDERERWIDGET_H
#define QGSSINGLEBANDCOLORRENDERERWIDGET_H

#include "qgsrasterminmaxwidget.h"
#include "qgsrasterrendererwidget.h"
#include "qgscolorrampshader.h"
#include "ui_qgssinglebandpseudocolorrendererwidgetbase.h"
Expand All @@ -38,6 +39,9 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
private:
void populateColormapTreeWidget( const QList<QgsColorRampShader::ColorRampItem>& colorRampItems );

public slots:
void loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin );

private slots:
void on_mAddEntryButton_clicked();
void on_mDeleteEntryButton_clicked();
Expand All @@ -47,6 +51,19 @@ class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendere
void on_mLoadFromFileButton_clicked();
void on_mExportToFileButton_clicked();
void on_mColormapTreeWidget_itemDoubleClicked( QTreeWidgetItem* item, int column );
void on_mBandComboBox_currentIndexChanged( int index );
void on_mMinLineEdit_textChanged( const QString & text ) { Q_UNUSED( text ); resetClassifyButton(); }
void on_mMaxLineEdit_textChanged( const QString & text ) { Q_UNUSED( text ); resetClassifyButton(); }
void on_mMinLineEdit_textEdited( const QString & text ) { Q_UNUSED( text ); mMinMaxOrigin = QgsRasterRenderer::MinMaxUser; showMinMaxOrigin(); }
void on_mMaxLineEdit_textEdited( const QString & text ) { Q_UNUSED( text ); mMinMaxOrigin = QgsRasterRenderer::MinMaxUser; showMinMaxOrigin(); }

private:
void setLineEditValue( QLineEdit *theLineEdit, double theValue );
double lineEditValue( const QLineEdit *theLineEdit ) const;
void resetClassifyButton();
void showMinMaxOrigin();
QgsRasterMinMaxWidget * mMinMaxWidget;
int mMinMaxOrigin;
};

#endif // QGSSINGLEBANDCOLORRENDERERWIDGET_H
102 changes: 74 additions & 28 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>722</width>
<height>663</height>
<width>652</width>
<height>515</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -101,7 +101,27 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>318</width>
<width>150</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="mInvertColorMapCheckBox">
<property name="text">
<string>Invert color map</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
Expand All @@ -112,52 +132,71 @@
<item row="4" column="0">
<widget class="QStackedWidget" name="mRendererStackedWidget"/>
</item>
<item row="0" column="0">
<item row="5" 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">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mZoomedInResamplingLabel">
<property name="text">
<string>Zoomed in</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item>
<widget class="QComboBox" name="mZoomedInResamplingComboBox"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="mZoomedOutResamplingLabel">
<property name="text">
<string>Zoomed out</string>
</property>
</widget>
</item>
<item row="0" column="2">
<item>
<widget class="QComboBox" name="mZoomedOutResamplingComboBox"/>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="mMaximumOversamplingLabel">
<property name="text">
<string>Maximum oversampling</string>
<string>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">
<item>
<widget class="QDoubleSpinBox" name="mMaximumOversamplingSpinBox"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="mInvertColorMapCheckBox">
<property name="text">
<string>Invert color map</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabBarPage2">
Expand Down Expand Up @@ -589,7 +628,7 @@
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Less than:</string>
<string>Less than:</string>
</property>
</widget>
</item>
Expand All @@ -599,15 +638,15 @@
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>More than or equal to:</string>
<string>More than or equal to:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QgsScaleComboBox" name="cbMaximumScale"/>
<widget class="QgsScaleComboBox" name="cbMaximumScale" native="true"/>
</item>
<item row="0" column="1">
<widget class="QgsScaleComboBox" name="cbMinimumScale"/>
<widget class="QgsScaleComboBox" name="cbMinimumScale" native="true"/>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -899,7 +938,7 @@
<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;
&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;
p, li { white-space: pre-wrap; }
&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;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
Expand Down Expand Up @@ -1046,6 +1085,13 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsScaleComboBox</class>
<extends>QWidget</extends>
<header>qgsscalecombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabBar</tabstop>
<tabstop>buttonBox</tabstop>
Expand Down
511 changes: 261 additions & 250 deletions src/ui/qgsrasterminmaxwidgetbase.ui

Large diffs are not rendered by default.

535 changes: 332 additions & 203 deletions src/ui/qgssinglebandpseudocolorrendererwidgetbase.ui

Large diffs are not rendered by default.