Skip to content

Commit

Permalink
Merge pull request #4520 from nyalldawson/raster_combo_box
Browse files Browse the repository at this point in the history
QgsRasterBandComboBox
  • Loading branch information
nyalldawson committed May 9, 2017
2 parents 0824280 + ea4143b commit a4e3c83
Show file tree
Hide file tree
Showing 31 changed files with 785 additions and 238 deletions.
9 changes: 8 additions & 1 deletion doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -1766,11 +1766,18 @@ QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}

- extentSize() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should be used instead of a null pointer if no transformation is required.

QgsRasterRenderer
QgsRasterRenderer {#qgis_api_break_3_0_QgsRasterRenderer}
-----------------

- MinMaxOrigin enum, minMaxOriginName(), minMaxOriginLabel(), minMaxOriginFromName() removed. Use minMaxOrigin() instead


QgsRasterRendererWidget {#qgis_api_break_3_0_QgsRasterRendererWidget}
-----------------

- displayBandName() was removed.


QgsRectangle {#qgis_api_break_3_0_QgsRectangle}
------------

Expand Down
1 change: 1 addition & 0 deletions python/gui/gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@

%Include raster/qgsmultibandcolorrendererwidget.sip
%Include raster/qgspalettedrendererwidget.sip
%Include raster/qgsrasterbandcombobox.sip
%Include raster/qgsrasterhistogramwidget.sip
%Include raster/qgsrasterminmaxwidget.sip
%Include raster/qgsrasterrendererwidget.sip
Expand Down
89 changes: 89 additions & 0 deletions python/gui/raster/qgsrasterbandcombobox.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/raster/qgsrasterbandcombobox.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsRasterBandComboBox : QComboBox
{
%Docstring
A combobox widget which displays the bands present in a raster layer.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsrasterbandcombobox.h"
%End
public:

QgsRasterBandComboBox( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsRasterBandComboBox.
%End

QgsRasterLayer *layer() const;
%Docstring
Returns the layer currently associated with the combobox.
.. seealso:: setLayer()
:rtype: QgsRasterLayer
%End

int currentBand() const;
%Docstring
Returns the current band number selected in the combobox, or -1
if no band is selected.
.. seealso:: setBand()
:rtype: int
%End

bool isShowingNotSetOption() const;
%Docstring
Returns true if the combo box is showing the "not set" option.
.. seealso:: setShowNotSetOption()
:rtype: bool
%End

void setShowNotSetOption( bool show, const QString &string = QString() );
%Docstring
Sets whether the combo box should show the "not set" option.
Optionally the built in "not set" text can be overridden by specifying
a ``string``.
.. seealso:: setShowNotSetOption()
%End

public slots:

void setLayer( QgsMapLayer *layer );
%Docstring
Sets the raster ``layer`` for which the bands are listed in the combobox. If no layer is set
or a non-raster layer is set then the combobox will be empty.
.. seealso:: layer()
%End

void setBand( int band );
%Docstring
Sets the current ``band`` number selected in the combobox.
.. seealso:: band()
%End

signals:

void bandChanged( int band );
%Docstring
This signal is emitted when the currently selected band changes.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/raster/qgsrasterbandcombobox.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
4 changes: 0 additions & 4 deletions python/gui/raster/qgsrasterrendererwidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,4 @@ class QgsRasterRendererWidget: QWidget
*/
void widgetChanged();


protected:
/** Returns a band name for display. First choice is color name, otherwise band number*/
QString displayBandName( int band ) const;
};
28 changes: 4 additions & 24 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
//transparency band
if ( provider )
{
cboxTransparencyBand->addItem( tr( "None" ), -1 );
int nBands = provider->bandCount();
QString bandName;
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
{
bandName = provider->generateBandName( i );

QString colorInterp = provider->colorInterpretationName( i );
if ( colorInterp != QLatin1String( "Undefined" ) )
{
bandName.append( QStringLiteral( " (%1)" ).arg( colorInterp ) );
}
cboxTransparencyBand->addItem( bandName, i );
}
cboxTransparencyBand->setShowNotSetOption( true, tr( "None" ) );
cboxTransparencyBand->setLayer( mRasterLayer );

// Alpha band is set in sync()
#if 0
Expand Down Expand Up @@ -667,15 +655,7 @@ void QgsRasterLayerProperties::sync()
//update the transparency percentage label
sliderTransparency_valueChanged( ( 1.0 - renderer->opacity() ) * 255 );

int myIndex = renderer->alphaBand();
if ( -1 != myIndex )
{
cboxTransparencyBand->setCurrentIndex( myIndex );
}
else
{
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findText( TRSTRING_NOT_SET ) );
}
cboxTransparencyBand->setBand( renderer->alphaBand() );
}

//add current NoDataValue to NoDataValue line edit
Expand Down Expand Up @@ -888,7 +868,7 @@ void QgsRasterLayerProperties::apply()
QgsRasterRenderer *rasterRenderer = mRasterLayer->renderer();
if ( rasterRenderer )
{
rasterRenderer->setAlphaBand( cboxTransparencyBand->currentData().toInt() );
rasterRenderer->setAlphaBand( cboxTransparencyBand->currentBand() );

//Walk through each row in table and test value. If not valid set to 0.0 and continue building transparency list
QgsRasterTransparency *rasterTransparency = new QgsRasterTransparency();
Expand Down
5 changes: 5 additions & 0 deletions src/customwidgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
qgspasswordlineeditplugin.cpp
qgsprojectionselectionwidgetplugin.cpp
qgspropertyoverridebuttonplugin.cpp
qgsrasterbandcomboboxplugin.cpp
qgsrelationeditorwidgetplugin.cpp
qgsrelationreferencewidgetplugin.cpp
qgsscalerangewidgetplugin.cpp
Expand Down Expand Up @@ -56,6 +57,7 @@ SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
qgspasswordlineeditplugin.h
qgsprojectionselectionwidgetplugin.h
qgspropertyoverridebuttonplugin.h
qgsrasterbandcomboboxplugin.h
qgsrelationeditorwidgetplugin.h
qgsrelationreferencewidgetplugin.h
qgsscalerangewidgetplugin.h
Expand Down Expand Up @@ -87,6 +89,7 @@ SET(QGIS_CUSTOMWIDGETS_HDRS
qgsmaplayercomboboxplugin.h
qgsprojectionselectionwidgetplugin.h
qgspropertyoverridebuttonplugin.h
qgsrasterbandcomboboxplugin.h
qgsrelationeditorwidgetplugin.h
qgsrelationreferencewidgetplugin.h
qgsscalerangewidgetplugin.h
Expand All @@ -109,7 +112,9 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../gui/attributetable/
${CMAKE_CURRENT_SOURCE_DIR}/../gui/editorwidgets/
${CMAKE_CURRENT_SOURCE_DIR}/../gui/editorwidgets/core
${CMAKE_CURRENT_SOURCE_DIR}/../gui/raster/
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/core/raster/
${CMAKE_BINARY_DIR}/src/gui
${CMAKE_BINARY_DIR}/src/customwidgets
${CMAKE_CURRENT_BINARY_DIR}/../ui/
Expand Down
2 changes: 2 additions & 0 deletions src/customwidgets/qgiscustomwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "qgsmaplayercomboboxplugin.h"
#include "qgsprojectionselectionwidgetplugin.h"
#include "qgspropertyoverridebuttonplugin.h"
#include "qgsrasterbandcomboboxplugin.h"
#include "qgsrelationeditorwidgetplugin.h"
#include "qgsrelationreferencewidgetplugin.h"
#include "qgsscalerangewidgetplugin.h"
Expand All @@ -54,6 +55,7 @@ QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
mWidgets.append( new QgsMapLayerComboBoxPlugin( this ) );
mWidgets.append( new QgsProjectionSelectionWidgetPlugin( this ) );
mWidgets.append( new QgsPropertyOverrideButtonPlugin( this ) );
mWidgets.append( new QgsRasterBandComboBoxPlugin( this ) );
mWidgets.append( new QgsRelationEditorWidgetPlugin( this ) );
mWidgets.append( new QgsRelationReferenceWidgetPlugin( this ) );
mWidgets.append( new QgsScaleRangeWidgetPlugin( this ) );
Expand Down
97 changes: 97 additions & 0 deletions src/customwidgets/qgsrasterbandcomboboxplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/***************************************************************************
qgsrasterbandcomboboxplugin.cpp
--------------------------------------
Date : 09.05.2017
Copyright : (C) 2017 Nyall Dawson
Email : nyall.dawson@gmail.com
***************************************************************************
* *
* 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 "qgiscustomwidgets.h"
#include "qgsrasterbandcombobox.h"
#include "qgsrasterbandcomboboxplugin.h"


QgsRasterBandComboBoxPlugin::QgsRasterBandComboBoxPlugin( QObject *parent )
: QObject( parent )
, mInitialized( false )
{
}


QString QgsRasterBandComboBoxPlugin::name() const
{
return "QgsRasterBandComboBox";
}

QString QgsRasterBandComboBoxPlugin::group() const
{
return QgisCustomWidgets::groupName();
}

QString QgsRasterBandComboBoxPlugin::includeFile() const
{
return "qgsrasterbandcombobox.h";
}

QIcon QgsRasterBandComboBoxPlugin::icon() const
{
return QIcon( ":/images/icons/qgis-icon-60x60.png" );
}

bool QgsRasterBandComboBoxPlugin::isContainer() const
{
return false;
}

QWidget *QgsRasterBandComboBoxPlugin::createWidget( QWidget *parent )
{
return new QgsRasterBandComboBox( parent );
}

bool QgsRasterBandComboBoxPlugin::isInitialized() const
{
return mInitialized;
}

void QgsRasterBandComboBoxPlugin::initialize( QDesignerFormEditorInterface *core )
{
Q_UNUSED( core );
if ( mInitialized )
return;
mInitialized = true;
}


QString QgsRasterBandComboBoxPlugin::toolTip() const
{
return tr( "A combo box to list the bands from a raster layer" );
}

QString QgsRasterBandComboBoxPlugin::whatsThis() const
{
return tr( "A combo box to list the bands from a raster layer." );
}

QString QgsRasterBandComboBoxPlugin::domXml() const
{
return QString( "<ui language=\"c++\">\n"
" <widget class=\"%1\" name=\"mRasterBandComboBox\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>160</width>\n"
" <height>27</height>\n"
" </rect>\n"
" </property>\n"
" </widget>\n"
"</ui>\n" )
.arg( name() );
}
51 changes: 51 additions & 0 deletions src/customwidgets/qgsrasterbandcomboboxplugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/***************************************************************************
qgsrasterbandcomboboxplugin.h
--------------------------------------
Date : 09.05.2017
Copyright : (C) 2017 Nyall Dawson
Email : nyall.dawson@gmail.com
***************************************************************************
* *
* 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 QGSRASTERBANDCOMBOBOXPLUGIN_H
#define QGSRASTERBANDCOMBOBOXPLUGIN_H


#include <QtGlobal>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
#include <QtUiPlugin/QDesignerExportWidget>
#include "qgis_customwidgets.h"


class CUSTOMWIDGETS_EXPORT QgsRasterBandComboBoxPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES( QDesignerCustomWidgetInterface )

public:
explicit QgsRasterBandComboBoxPlugin( QObject *parent = 0 );

private:
bool mInitialized;

// QDesignerCustomWidgetInterface interface
public:
QString name() const override;
QString group() const override;
QString includeFile() const override;
QIcon icon() const override;
bool isContainer() const override;
QWidget *createWidget( QWidget *parent ) override;
bool isInitialized() const override;
void initialize( QDesignerFormEditorInterface *core ) override;
QString toolTip() const override;
QString whatsThis() const override;
QString domXml() const override;
};
#endif // QGSRASTERBANDCOMBOBOXPLUGIN_H
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SET(QGIS_GUI_SRCS
raster/qgsmultibandcolorrendererwidget.cpp
raster/qgspalettedrendererwidget.cpp
raster/qgsrasterbandcombobox.cpp
raster/qgsrasterhistogramwidget.cpp
raster/qgsrasterminmaxwidget.cpp
raster/qgsrasterrendererwidget.cpp
Expand Down Expand Up @@ -460,6 +461,7 @@ SET(QGIS_GUI_MOC_HDRS

raster/qgsmultibandcolorrendererwidget.h
raster/qgspalettedrendererwidget.h
raster/qgsrasterbandcombobox.h
raster/qgsrasterhistogramwidget.h
raster/qgsrasterminmaxwidget.h
raster/qgsrasterrendererwidget.h
Expand Down
Loading

0 comments on commit a4e3c83

Please sign in to comment.