Skip to content

Commit ebe1f2e

Browse files
committed
added QgsFieldComboBox, QgsFieldExpressionWidget and QgsMapLayerComboBox to custom widgets
1 parent 2cf3e7c commit ebe1f2e

8 files changed

+468
-0
lines changed

src/customwidgets/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
SET (QGIS_CUSTOMWIDGETS_SRCS
66
qgiscustomwidgets.cpp
77
qgscollapsiblegroupboxplugin.cpp
8+
qgsfieldcomboboxplugin.cpp
9+
qgsfieldexpressionwidgetplugin.cpp
10+
qgsmaplayercomboboxplugin.cpp
811
qgsscalevisibilitywidgetplugin.cpp
912
)
1013

1114
SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
1215
qgiscustomwidgets.h
1316
qgscollapsiblegroupboxplugin.h
17+
qgsfieldcomboboxplugin.h
18+
qgsfieldexpressionwidgetplugin.h
19+
qgsmaplayercomboboxplugin.h
1420
qgsscalevisibilitywidgetplugin.h
1521
)
1622

@@ -23,6 +29,9 @@ ENDIF(UNIX)
2329
SET(QGIS_CUSTOMWIDGETS_HDRS
2430
qgiscustomwidgets.h
2531
qgscollapsiblegroupboxplugin.h
32+
qgsfieldcomboboxplugin.h
33+
qgsfieldexpressionwidgetplugin.h
34+
qgsmaplayercomboboxplugin.h
2635
qgsscalevisibilitywidgetplugin.h
2736
)
2837

src/customwidgets/qgiscustomwidgets.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@
1818
#include "qgiscustomwidgets.h"
1919

2020
#include "qgscollapsiblegroupboxplugin.h"
21+
#include "qgsfieldcomboboxplugin.h"
22+
#include "qgsfieldexpressionwidgetplugin.h"
23+
#include "qgsmaplayercomboboxplugin.h"
2124
#include "qgsscalevisibilitywidgetplugin.h"
2225

2326

2427
QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
2528
: QObject( parent )
2629
{
2730
mWidgets.append( new QgsCollapsibleGroupBoxPlugin );
31+
mWidgets.append( new QgsFieldComboBoxPlugin );
32+
mWidgets.append( new QgsFieldExpressionWidgetPlugin );
33+
mWidgets.append( new QgsMapLayerComboBoxPlugin );
2834
mWidgets.append( new QgsScaleVisibilityWidgetPlugin );
2935
}
3036

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***************************************************************************
2+
qgsfieldcomboboxplugin.cpp
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@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 "qgsfieldcombobox.h"
18+
#include "qgsfieldcomboboxplugin.h"
19+
20+
21+
QgsFieldComboBoxPlugin::QgsFieldComboBoxPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsFieldComboBoxPlugin::name() const
29+
{
30+
return "QgsFieldComboBox";
31+
}
32+
33+
QString QgsFieldComboBoxPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsFieldComboBoxPlugin::includeFile() const
39+
{
40+
return "qgsfieldcombobox.h";
41+
}
42+
43+
QIcon QgsFieldComboBoxPlugin::icon() const
44+
{
45+
return QIcon();
46+
}
47+
48+
bool QgsFieldComboBoxPlugin::isContainer() const
49+
{
50+
return false;
51+
}
52+
53+
QWidget *QgsFieldComboBoxPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsFieldComboBox( parent );
56+
}
57+
58+
bool QgsFieldComboBoxPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsFieldComboBoxPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsFieldComboBoxPlugin::toolTip() const
73+
{
74+
return "A combo box to list the fields of a layer";
75+
}
76+
77+
QString QgsFieldComboBoxPlugin::whatsThis() const
78+
{
79+
return "A combo box to list the field of a layer.";
80+
}
81+
82+
QString QgsFieldComboBoxPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mFieldComboBox\">\n"
86+
" <property name=\"geometry\">\n"
87+
" <rect>\n"
88+
" <x>0</x>\n"
89+
" <y>0</y>\n"
90+
" <width>300</width>\n"
91+
" <height>100</height>\n"
92+
" </rect>\n"
93+
" </property>\n"
94+
" <property name=\"toolTip\" >\n"
95+
" <string>%2</string>\n"
96+
" </property>\n"
97+
" <property name=\"whatsThis\" >\n"
98+
" <string>%3.</string>\n"
99+
" </property>\n"
100+
" </widget>\n"
101+
"</ui>\n" )
102+
.arg( name() )
103+
.arg( toolTip() )
104+
.arg( whatsThis() );
105+
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***************************************************************************
2+
qgsfieldcomboboxplugin.h
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@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 QGSFIELDCOMBOBOXPLUGIN_H
17+
#define QGSFIELDCOMBOBOXPLUGIN_H
18+
19+
#include <QDesignerCustomWidgetInterface>
20+
21+
class CUSTOMWIDGETS_EXPORT QgsFieldComboBoxPlugin : public QObject, public QDesignerCustomWidgetInterface
22+
{
23+
Q_OBJECT
24+
Q_INTERFACES( QDesignerCustomWidgetInterface )
25+
26+
public:
27+
explicit QgsFieldComboBoxPlugin( QObject *parent = 0 );
28+
29+
private:
30+
bool mInitialized;
31+
32+
// QDesignerCustomWidgetInterface interface
33+
public:
34+
QString name() const;
35+
QString group() const;
36+
QString includeFile() const;
37+
QIcon icon() const;
38+
bool isContainer() const;
39+
QWidget *createWidget( QWidget *parent );
40+
bool isInitialized() const;
41+
void initialize( QDesignerFormEditorInterface *core );
42+
QString toolTip() const;
43+
QString whatsThis() const;
44+
QString domXml() const;
45+
};
46+
#endif // QGSFIELDCOMBOBOXPLUGIN_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***************************************************************************
2+
qgsfieldexpressionwidgetplugin.cpp
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@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 "qgsfieldexpressionwidgetplugin.h"
18+
#include "qgsfieldexpressionwidget.h"
19+
20+
21+
QgsFieldExpressionWidgetPlugin::QgsFieldExpressionWidgetPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsFieldExpressionWidgetPlugin::name() const
29+
{
30+
return "QgsFieldExpressionWidget";
31+
}
32+
33+
QString QgsFieldExpressionWidgetPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsFieldExpressionWidgetPlugin::includeFile() const
39+
{
40+
return "qgsfieldexpressionwidget.h";
41+
}
42+
43+
QIcon QgsFieldExpressionWidgetPlugin::icon() const
44+
{
45+
return QIcon();
46+
}
47+
48+
bool QgsFieldExpressionWidgetPlugin::isContainer() const
49+
{
50+
return false;
51+
}
52+
53+
QWidget *QgsFieldExpressionWidgetPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsFieldExpressionWidget( parent );
56+
}
57+
58+
bool QgsFieldExpressionWidgetPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsFieldExpressionWidgetPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsFieldExpressionWidgetPlugin::toolTip() const
73+
{
74+
return "An editable combo box to enter an expression";
75+
}
76+
77+
QString QgsFieldExpressionWidgetPlugin::whatsThis() const
78+
{
79+
return "An editable combo box to enter an expression. A button allows opening the expression dialog. Expression are evaluated to detect errors.";
80+
}
81+
82+
QString QgsFieldExpressionWidgetPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mFieldExpressionWidget\">\n"
86+
" <property name=\"geometry\">\n"
87+
" <rect>\n"
88+
" <x>0</x>\n"
89+
" <y>0</y>\n"
90+
" <width>300</width>\n"
91+
" <height>100</height>\n"
92+
" </rect>\n"
93+
" </property>\n"
94+
" <property name=\"toolTip\" >\n"
95+
" <string>%2</string>\n"
96+
" </property>\n"
97+
" <property name=\"whatsThis\" >\n"
98+
" <string>%3.</string>\n"
99+
" </property>\n"
100+
" </widget>\n"
101+
"</ui>\n" )
102+
.arg( name() )
103+
.arg( toolTip() )
104+
.arg( whatsThis() );
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***************************************************************************
2+
qgsfieldexpressionwidgetplugin.h
3+
--------------------------------------
4+
Date : 25.04.2014
5+
Copyright : (C) 2014 Denis Rouzaud
6+
Email : denis.rouzaud@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 QGSFIELDEXPRESSIONWIDGETPLUGIN_H
17+
#define QGSFIELDEXPRESSIONWIDGETPLUGIN_H
18+
19+
#include <QDesignerCustomWidgetInterface>
20+
21+
class CUSTOMWIDGETS_EXPORT QgsFieldExpressionWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface
22+
{
23+
Q_OBJECT
24+
Q_INTERFACES( QDesignerCustomWidgetInterface )
25+
26+
public:
27+
explicit QgsFieldExpressionWidgetPlugin( QObject *parent = 0 );
28+
29+
private:
30+
bool mInitialized;
31+
32+
// QDesignerCustomWidgetInterface interface
33+
public:
34+
QString name() const;
35+
QString group() const;
36+
QString includeFile() const;
37+
QIcon icon() const;
38+
bool isContainer() const;
39+
QWidget *createWidget( QWidget *parent );
40+
bool isInitialized() const;
41+
void initialize( QDesignerFormEditorInterface *core );
42+
QString toolTip() const;
43+
QString whatsThis() const;
44+
QString domXml() const;
45+
};
46+
#endif // QGSFIELDEXPRESSIONWIDGETPLUGIN_H

0 commit comments

Comments
 (0)