Skip to content

Commit aa70851

Browse files
committed
custom widgets: added color and data defined buttons, missing SIP for scale range and fix flags for field combo / expression widget
1 parent 74392f7 commit aa70851

13 files changed

+351
-6
lines changed

python/gui/gui.sip

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
%Include qgsrasterpyramidsoptionswidget.sip
7676
%Include qgsrubberband.sip
7777
%Include qgsscalecombobox.sip
78+
%Include qgsscalerangewidget.sip
7879
%Include qgssearchquerybuilder.sip
7980
%Include qgstextannotationitem.sip
8081
%Include qgsvertexmarker.sip

python/gui/qgsscalerangewidget.sip

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
class QgsScaleRangeWidget : QWidget
3+
{
4+
%TypeHeaderCode
5+
#include "qgsscalerangewidget.h"
6+
%End
7+
8+
public:
9+
explicit QgsScaleRangeWidget( QWidget *parent /TransferThis/ = 0 );
10+
~QgsScaleRangeWidget();
11+
12+
//! set the map canvas which will be used for the current scale buttons
13+
/**
14+
* @brief setMapCanvas set the map canvas which will be used for the current scale buttons
15+
* if not set, the buttons are hidden.
16+
*/
17+
void setMapCanvas( QgsMapCanvas* mapCanvas );
18+
19+
//! return the minimum scale
20+
double minimumScale();
21+
22+
//! return the maximum scale
23+
double maximumScale();
24+
25+
//! return the minimum scale denominator ( = 1 / maximum scale )
26+
double minimumScaleDenom();
27+
28+
//! return the maximum scale denominator ( = 1 / minimum scale )
29+
double maximumScaleDenom();
30+
31+
//! call to reload the project scales and apply them to the 2 scales combo boxes
32+
void reloadProjectScales();
33+
34+
public slots:
35+
void setMinimumScale( double scale );
36+
37+
void setMaximumScale( double scale );
38+
39+
void setScaleRange( double min, double max );
40+
};

src/customwidgets/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ADD_DEFINITIONS(-DQT_SHARED)
99
SET (QGIS_CUSTOMWIDGETS_SRCS
1010
qgiscustomwidgets.cpp
1111
qgscollapsiblegroupboxplugin.cpp
12+
qgscolorbuttonplugin.cpp
13+
qgsdatadefinedbuttonplugin.cpp
1214
qgsfieldcomboboxplugin.cpp
1315
qgsfieldexpressionwidgetplugin.cpp
1416
qgsmaplayercomboboxplugin.cpp
@@ -18,6 +20,8 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
1820
SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
1921
qgiscustomwidgets.h
2022
qgscollapsiblegroupboxplugin.h
23+
qgscolorbuttonplugin.h
24+
qgsdatadefinedbuttonplugin.h
2125
qgsfieldcomboboxplugin.h
2226
qgsfieldexpressionwidgetplugin.h
2327
qgsmaplayercomboboxplugin.h
@@ -33,6 +37,8 @@ ENDIF(UNIX)
3337
SET(QGIS_CUSTOMWIDGETS_HDRS
3438
qgiscustomwidgets.h
3539
qgscollapsiblegroupboxplugin.h
40+
qgscolorbuttonplugin.h
41+
qgsdatadefinedbuttonplugin.h
3642
qgsfieldcomboboxplugin.h
3743
qgsfieldexpressionwidgetplugin.h
3844
qgsmaplayercomboboxplugin.h

src/customwidgets/qgiscustomwidgets.cpp

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

2020
#include "qgscollapsiblegroupboxplugin.h"
21+
#include "qgscolorbuttonplugin.h"
22+
#include "qgsdatadefinedbuttonplugin.h"
2123
#include "qgsfieldcomboboxplugin.h"
2224
#include "qgsfieldexpressionwidgetplugin.h"
2325
#include "qgsmaplayercomboboxplugin.h"
@@ -27,13 +29,9 @@
2729
QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
2830
: QObject( parent )
2931
{
30-
31-
// !!!!!!!!!!!!!!!!!!!!!
32-
// do not forget to add the corresponding line in python/customwidgets.py
33-
// to make the custom widget available from python
34-
// !!!!!!!!!!!!!!!!!!!!!
35-
3632
mWidgets.append( new QgsCollapsibleGroupBoxPlugin );
33+
mWidgets.append( new QgsColorButtonPlugin );
34+
mWidgets.append( new QgsDataDefinedButtonPlugin );
3735
mWidgets.append( new QgsFieldComboBoxPlugin );
3836
mWidgets.append( new QgsFieldExpressionWidgetPlugin );
3937
mWidgets.append( new QgsMapLayerComboBoxPlugin );
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/***************************************************************************
2+
qgscolorbuttonplugin.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 "qgscolorbuttonplugin.h"
18+
#include "qgscolorbutton.h"
19+
20+
21+
QgsColorButtonPlugin::QgsColorButtonPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsColorButtonPlugin::name() const
29+
{
30+
return "QgsColorButton";
31+
}
32+
33+
QString QgsColorButtonPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsColorButtonPlugin::includeFile() const
39+
{
40+
return "qgscolorbutton.h";
41+
}
42+
43+
QIcon QgsColorButtonPlugin::icon() const
44+
{
45+
return QIcon();
46+
}
47+
48+
bool QgsColorButtonPlugin::isContainer() const
49+
{
50+
return false;
51+
}
52+
53+
QWidget *QgsColorButtonPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsColorButton( parent );
56+
}
57+
58+
bool QgsColorButtonPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsColorButtonPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsColorButtonPlugin::toolTip() const
73+
{
74+
return "A widget to define the scale range";
75+
}
76+
77+
QString QgsColorButtonPlugin::whatsThis() const
78+
{
79+
return "A widget to define the scale range.";
80+
}
81+
82+
QString QgsColorButtonPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mColorButton\">\n"
86+
" <property name=\"geometry\">\n"
87+
" <rect>\n"
88+
" <x>0</x>\n"
89+
" <y>0</y>\n"
90+
" <width>27</width>\n"
91+
" <height>27</height>\n"
92+
" </rect>\n"
93+
" </property>\n"
94+
" </widget>\n"
95+
"</ui>\n" )
96+
.arg( name() );
97+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/***************************************************************************
2+
qgscolorbuttonplugin.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 QGSCOLORBUTTONPLUGIN_H
17+
#define QGSCOLORBUTTONPLUGIN_H
18+
19+
#include <QDesignerExportWidget>
20+
#include <QDesignerCustomWidgetInterface>
21+
22+
23+
class QDESIGNER_WIDGET_EXPORT QgsColorButtonPlugin : public QObject, public QDesignerCustomWidgetInterface
24+
{
25+
Q_OBJECT
26+
Q_INTERFACES( QDesignerCustomWidgetInterface )
27+
28+
public:
29+
explicit QgsColorButtonPlugin( QObject *parent = 0 );
30+
31+
private:
32+
bool mInitialized;
33+
34+
// QDesignerCustomWidgetInterface interface
35+
public:
36+
QString name() const;
37+
QString group() const;
38+
QString includeFile() const;
39+
QIcon icon() const;
40+
bool isContainer() const;
41+
QWidget *createWidget( QWidget *parent );
42+
bool isInitialized() const;
43+
void initialize( QDesignerFormEditorInterface *core );
44+
QString toolTip() const;
45+
QString whatsThis() const;
46+
QString domXml() const;
47+
};
48+
#endif // QGSCOLORBUTTONPLUGIN_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/***************************************************************************
2+
qgsdatadefinedbuttonplugin.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 "qgsdatadefinedbuttonplugin.h"
18+
#include "qgsdatadefinedbutton.h"
19+
20+
21+
QgsDataDefinedButtonPlugin::QgsDataDefinedButtonPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsDataDefinedButtonPlugin::name() const
29+
{
30+
return "QgsDataDefinedButton";
31+
}
32+
33+
QString QgsDataDefinedButtonPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsDataDefinedButtonPlugin::includeFile() const
39+
{
40+
return "qgsdatadefinedbutton.h";
41+
}
42+
43+
QIcon QgsDataDefinedButtonPlugin::icon() const
44+
{
45+
return QIcon();
46+
}
47+
48+
bool QgsDataDefinedButtonPlugin::isContainer() const
49+
{
50+
return false;
51+
}
52+
53+
QWidget *QgsDataDefinedButtonPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsDataDefinedButton( parent );
56+
}
57+
58+
bool QgsDataDefinedButtonPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsDataDefinedButtonPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsDataDefinedButtonPlugin::toolTip() const
73+
{
74+
return "A widget to define the scale range";
75+
}
76+
77+
QString QgsDataDefinedButtonPlugin::whatsThis() const
78+
{
79+
return "A widget to define the scale range.";
80+
}
81+
82+
QString QgsDataDefinedButtonPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mDataDefinedButton\">\n"
86+
" <property name=\"geometry\">\n"
87+
" <rect>\n"
88+
" <x>0</x>\n"
89+
" <y>0</y>\n"
90+
" <width>27</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,48 @@
1+
/***************************************************************************
2+
qgsdatadefinedbuttonplugin.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 QGSDATADEFINEDBUTTONPLUGIN_H
17+
#define QGSDATADEFINEDBUTTONPLUGIN_H
18+
19+
#include <QDesignerExportWidget>
20+
#include <QDesignerCustomWidgetInterface>
21+
22+
23+
class QDESIGNER_WIDGET_EXPORT QgsDataDefinedButtonPlugin : public QObject, public QDesignerCustomWidgetInterface
24+
{
25+
Q_OBJECT
26+
Q_INTERFACES( QDesignerCustomWidgetInterface )
27+
28+
public:
29+
explicit QgsDataDefinedButtonPlugin( QObject *parent = 0 );
30+
31+
private:
32+
bool mInitialized;
33+
34+
// QDesignerCustomWidgetInterface interface
35+
public:
36+
QString name() const;
37+
QString group() const;
38+
QString includeFile() const;
39+
QIcon icon() const;
40+
bool isContainer() const;
41+
QWidget *createWidget( QWidget *parent );
42+
bool isInitialized() const;
43+
void initialize( QDesignerFormEditorInterface *core );
44+
QString toolTip() const;
45+
QString whatsThis() const;
46+
QString domXml() const;
47+
};
48+
#endif // QGSDATADEFINEDBUTTONPLUGIN_H

0 commit comments

Comments
 (0)