Skip to content

Commit a4e3c83

Browse files
authored
Merge pull request #4520 from nyalldawson/raster_combo_box
QgsRasterBandComboBox
2 parents 0824280 + ea4143b commit a4e3c83

31 files changed

+785
-238
lines changed

doc/api_break.dox

+8-1
Original file line numberDiff line numberDiff line change
@@ -1766,11 +1766,18 @@ QgsRasterProjector {#qgis_api_break_3_0_QgsRasterProjector}
17661766

17671767
- 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.
17681768

1769-
QgsRasterRenderer
1769+
QgsRasterRenderer {#qgis_api_break_3_0_QgsRasterRenderer}
17701770
-----------------
17711771

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

1774+
1775+
QgsRasterRendererWidget {#qgis_api_break_3_0_QgsRasterRendererWidget}
1776+
-----------------
1777+
1778+
- displayBandName() was removed.
1779+
1780+
17741781
QgsRectangle {#qgis_api_break_3_0_QgsRectangle}
17751782
------------
17761783

python/gui/gui.sip

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212

213213
%Include raster/qgsmultibandcolorrendererwidget.sip
214214
%Include raster/qgspalettedrendererwidget.sip
215+
%Include raster/qgsrasterbandcombobox.sip
215216
%Include raster/qgsrasterhistogramwidget.sip
216217
%Include raster/qgsrasterminmaxwidget.sip
217218
%Include raster/qgsrasterrendererwidget.sip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/raster/qgsrasterbandcombobox.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsRasterBandComboBox : QComboBox
13+
{
14+
%Docstring
15+
A combobox widget which displays the bands present in a raster layer.
16+
.. versionadded:: 3.0
17+
%End
18+
19+
%TypeHeaderCode
20+
#include "qgsrasterbandcombobox.h"
21+
%End
22+
public:
23+
24+
QgsRasterBandComboBox( QWidget *parent /TransferThis/ = 0 );
25+
%Docstring
26+
Constructor for QgsRasterBandComboBox.
27+
%End
28+
29+
QgsRasterLayer *layer() const;
30+
%Docstring
31+
Returns the layer currently associated with the combobox.
32+
.. seealso:: setLayer()
33+
:rtype: QgsRasterLayer
34+
%End
35+
36+
int currentBand() const;
37+
%Docstring
38+
Returns the current band number selected in the combobox, or -1
39+
if no band is selected.
40+
.. seealso:: setBand()
41+
:rtype: int
42+
%End
43+
44+
bool isShowingNotSetOption() const;
45+
%Docstring
46+
Returns true if the combo box is showing the "not set" option.
47+
.. seealso:: setShowNotSetOption()
48+
:rtype: bool
49+
%End
50+
51+
void setShowNotSetOption( bool show, const QString &string = QString() );
52+
%Docstring
53+
Sets whether the combo box should show the "not set" option.
54+
Optionally the built in "not set" text can be overridden by specifying
55+
a ``string``.
56+
.. seealso:: setShowNotSetOption()
57+
%End
58+
59+
public slots:
60+
61+
void setLayer( QgsMapLayer *layer );
62+
%Docstring
63+
Sets the raster ``layer`` for which the bands are listed in the combobox. If no layer is set
64+
or a non-raster layer is set then the combobox will be empty.
65+
.. seealso:: layer()
66+
%End
67+
68+
void setBand( int band );
69+
%Docstring
70+
Sets the current ``band`` number selected in the combobox.
71+
.. seealso:: band()
72+
%End
73+
74+
signals:
75+
76+
void bandChanged( int band );
77+
%Docstring
78+
This signal is emitted when the currently selected band changes.
79+
%End
80+
81+
};
82+
83+
/************************************************************************
84+
* This file has been generated automatically from *
85+
* *
86+
* src/gui/raster/qgsrasterbandcombobox.h *
87+
* *
88+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
89+
************************************************************************/

python/gui/raster/qgsrasterrendererwidget.sip

-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,4 @@ class QgsRasterRendererWidget: QWidget
4444
*/
4545
void widgetChanged();
4646

47-
48-
protected:
49-
/** Returns a band name for display. First choice is color name, otherwise band number*/
50-
QString displayBandName( int band ) const;
5147
};

src/app/qgsrasterlayerproperties.cpp

+4-24
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
325325
//transparency band
326326
if ( provider )
327327
{
328-
cboxTransparencyBand->addItem( tr( "None" ), -1 );
329-
int nBands = provider->bandCount();
330-
QString bandName;
331-
for ( int i = 1; i <= nBands; ++i ) //band numbering seem to start at 1
332-
{
333-
bandName = provider->generateBandName( i );
334-
335-
QString colorInterp = provider->colorInterpretationName( i );
336-
if ( colorInterp != QLatin1String( "Undefined" ) )
337-
{
338-
bandName.append( QStringLiteral( " (%1)" ).arg( colorInterp ) );
339-
}
340-
cboxTransparencyBand->addItem( bandName, i );
341-
}
328+
cboxTransparencyBand->setShowNotSetOption( true, tr( "None" ) );
329+
cboxTransparencyBand->setLayer( mRasterLayer );
342330

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

670-
int myIndex = renderer->alphaBand();
671-
if ( -1 != myIndex )
672-
{
673-
cboxTransparencyBand->setCurrentIndex( myIndex );
674-
}
675-
else
676-
{
677-
cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findText( TRSTRING_NOT_SET ) );
678-
}
658+
cboxTransparencyBand->setBand( renderer->alphaBand() );
679659
}
680660

681661
//add current NoDataValue to NoDataValue line edit
@@ -888,7 +868,7 @@ void QgsRasterLayerProperties::apply()
888868
QgsRasterRenderer *rasterRenderer = mRasterLayer->renderer();
889869
if ( rasterRenderer )
890870
{
891-
rasterRenderer->setAlphaBand( cboxTransparencyBand->currentData().toInt() );
871+
rasterRenderer->setAlphaBand( cboxTransparencyBand->currentBand() );
892872

893873
//Walk through each row in table and test value. If not valid set to 0.0 and continue building transparency list
894874
QgsRasterTransparency *rasterTransparency = new QgsRasterTransparency();

src/customwidgets/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
2929
qgspasswordlineeditplugin.cpp
3030
qgsprojectionselectionwidgetplugin.cpp
3131
qgspropertyoverridebuttonplugin.cpp
32+
qgsrasterbandcomboboxplugin.cpp
3233
qgsrelationeditorwidgetplugin.cpp
3334
qgsrelationreferencewidgetplugin.cpp
3435
qgsscalerangewidgetplugin.cpp
@@ -56,6 +57,7 @@ SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
5657
qgspasswordlineeditplugin.h
5758
qgsprojectionselectionwidgetplugin.h
5859
qgspropertyoverridebuttonplugin.h
60+
qgsrasterbandcomboboxplugin.h
5961
qgsrelationeditorwidgetplugin.h
6062
qgsrelationreferencewidgetplugin.h
6163
qgsscalerangewidgetplugin.h
@@ -87,6 +89,7 @@ SET(QGIS_CUSTOMWIDGETS_HDRS
8789
qgsmaplayercomboboxplugin.h
8890
qgsprojectionselectionwidgetplugin.h
8991
qgspropertyoverridebuttonplugin.h
92+
qgsrasterbandcomboboxplugin.h
9093
qgsrelationeditorwidgetplugin.h
9194
qgsrelationreferencewidgetplugin.h
9295
qgsscalerangewidgetplugin.h
@@ -109,7 +112,9 @@ INCLUDE_DIRECTORIES(
109112
${CMAKE_CURRENT_SOURCE_DIR}/../gui/attributetable/
110113
${CMAKE_CURRENT_SOURCE_DIR}/../gui/editorwidgets/
111114
${CMAKE_CURRENT_SOURCE_DIR}/../gui/editorwidgets/core
115+
${CMAKE_CURRENT_SOURCE_DIR}/../gui/raster/
112116
${CMAKE_BINARY_DIR}/src/core
117+
${CMAKE_BINARY_DIR}/src/core/raster/
113118
${CMAKE_BINARY_DIR}/src/gui
114119
${CMAKE_BINARY_DIR}/src/customwidgets
115120
${CMAKE_CURRENT_BINARY_DIR}/../ui/

src/customwidgets/qgiscustomwidgets.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgsmaplayercomboboxplugin.h"
3131
#include "qgsprojectionselectionwidgetplugin.h"
3232
#include "qgspropertyoverridebuttonplugin.h"
33+
#include "qgsrasterbandcomboboxplugin.h"
3334
#include "qgsrelationeditorwidgetplugin.h"
3435
#include "qgsrelationreferencewidgetplugin.h"
3536
#include "qgsscalerangewidgetplugin.h"
@@ -54,6 +55,7 @@ QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
5455
mWidgets.append( new QgsMapLayerComboBoxPlugin( this ) );
5556
mWidgets.append( new QgsProjectionSelectionWidgetPlugin( this ) );
5657
mWidgets.append( new QgsPropertyOverrideButtonPlugin( this ) );
58+
mWidgets.append( new QgsRasterBandComboBoxPlugin( this ) );
5759
mWidgets.append( new QgsRelationEditorWidgetPlugin( this ) );
5860
mWidgets.append( new QgsRelationReferenceWidgetPlugin( this ) );
5961
mWidgets.append( new QgsScaleRangeWidgetPlugin( this ) );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/***************************************************************************
2+
qgsrasterbandcomboboxplugin.cpp
3+
--------------------------------------
4+
Date : 09.05.2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall.dawson@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgiscustomwidgets.h"
17+
#include "qgsrasterbandcombobox.h"
18+
#include "qgsrasterbandcomboboxplugin.h"
19+
20+
21+
QgsRasterBandComboBoxPlugin::QgsRasterBandComboBoxPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsRasterBandComboBoxPlugin::name() const
29+
{
30+
return "QgsRasterBandComboBox";
31+
}
32+
33+
QString QgsRasterBandComboBoxPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsRasterBandComboBoxPlugin::includeFile() const
39+
{
40+
return "qgsrasterbandcombobox.h";
41+
}
42+
43+
QIcon QgsRasterBandComboBoxPlugin::icon() const
44+
{
45+
return QIcon( ":/images/icons/qgis-icon-60x60.png" );
46+
}
47+
48+
bool QgsRasterBandComboBoxPlugin::isContainer() const
49+
{
50+
return false;
51+
}
52+
53+
QWidget *QgsRasterBandComboBoxPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsRasterBandComboBox( parent );
56+
}
57+
58+
bool QgsRasterBandComboBoxPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsRasterBandComboBoxPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsRasterBandComboBoxPlugin::toolTip() const
73+
{
74+
return tr( "A combo box to list the bands from a raster layer" );
75+
}
76+
77+
QString QgsRasterBandComboBoxPlugin::whatsThis() const
78+
{
79+
return tr( "A combo box to list the bands from a raster layer." );
80+
}
81+
82+
QString QgsRasterBandComboBoxPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mRasterBandComboBox\">\n"
86+
" <property name=\"geometry\">\n"
87+
" <rect>\n"
88+
" <x>0</x>\n"
89+
" <y>0</y>\n"
90+
" <width>160</width>\n"
91+
" <height>27</height>\n"
92+
" </rect>\n"
93+
" </property>\n"
94+
" </widget>\n"
95+
"</ui>\n" )
96+
.arg( name() );
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***************************************************************************
2+
qgsrasterbandcomboboxplugin.h
3+
--------------------------------------
4+
Date : 09.05.2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall.dawson@gmail.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSRASTERBANDCOMBOBOXPLUGIN_H
17+
#define QGSRASTERBANDCOMBOBOXPLUGIN_H
18+
19+
20+
#include <QtGlobal>
21+
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
22+
#include <QtUiPlugin/QDesignerExportWidget>
23+
#include "qgis_customwidgets.h"
24+
25+
26+
class CUSTOMWIDGETS_EXPORT QgsRasterBandComboBoxPlugin : public QObject, public QDesignerCustomWidgetInterface
27+
{
28+
Q_OBJECT
29+
Q_INTERFACES( QDesignerCustomWidgetInterface )
30+
31+
public:
32+
explicit QgsRasterBandComboBoxPlugin( QObject *parent = 0 );
33+
34+
private:
35+
bool mInitialized;
36+
37+
// QDesignerCustomWidgetInterface interface
38+
public:
39+
QString name() const override;
40+
QString group() const override;
41+
QString includeFile() const override;
42+
QIcon icon() const override;
43+
bool isContainer() const override;
44+
QWidget *createWidget( QWidget *parent ) override;
45+
bool isInitialized() const override;
46+
void initialize( QDesignerFormEditorInterface *core ) override;
47+
QString toolTip() const override;
48+
QString whatsThis() const override;
49+
QString domXml() const override;
50+
};
51+
#endif // QGSRASTERBANDCOMBOBOXPLUGIN_H

src/gui/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
SET(QGIS_GUI_SRCS
22
raster/qgsmultibandcolorrendererwidget.cpp
33
raster/qgspalettedrendererwidget.cpp
4+
raster/qgsrasterbandcombobox.cpp
45
raster/qgsrasterhistogramwidget.cpp
56
raster/qgsrasterminmaxwidget.cpp
67
raster/qgsrasterrendererwidget.cpp
@@ -460,6 +461,7 @@ SET(QGIS_GUI_MOC_HDRS
460461

461462
raster/qgsmultibandcolorrendererwidget.h
462463
raster/qgspalettedrendererwidget.h
464+
raster/qgsrasterbandcombobox.h
463465
raster/qgsrasterhistogramwidget.h
464466
raster/qgsrasterminmaxwidget.h
465467
raster/qgsrasterrendererwidget.h

0 commit comments

Comments
 (0)