Skip to content

Commit 872cd13

Browse files
committed
Add custom widget plugin for QgsRasterBandComboBox
1 parent f4b353c commit 872cd13

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

src/customwidgets/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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 ) );
Lines changed: 97 additions & 0 deletions
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+
}
Lines changed: 51 additions & 0 deletions
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/raster/qgsrasterbandcombobox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "qgis_gui.h"
2020
#include "qgis_sip.h"
21-
#include "qgsrasterlayer.h"
21+
#include "raster/qgsrasterlayer.h"
2222
#include <QComboBox>
2323

2424
class QgsMapLayer;

0 commit comments

Comments
 (0)