Skip to content

Commit 43d094e

Browse files
committedJul 24, 2017
Custom widget plugin for QgsSymbolButton
1 parent f7ada81 commit 43d094e

File tree

4 files changed

+152
-1
lines changed

4 files changed

+152
-1
lines changed
 

‎src/customwidgets/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SET (QGIS_CUSTOMWIDGETS_SRCS
3838
qgsscalewidgetplugin.cpp
3939
qgsscrollareawidgetplugin.cpp
4040
qgsspinboxplugin.cpp
41+
qgssymbolbuttonplugin.cpp
4142
)
4243

4344
SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
@@ -68,6 +69,7 @@ SET (QGIS_CUSTOMWIDGETS_MOC_HDRS
6869
qgsscalewidgetplugin.h
6970
qgsscrollareawidgetplugin.h
7071
qgsspinboxplugin.h
72+
qgssymbolbuttonplugin.h
7173
)
7274

7375
IF(MSVC)

‎src/customwidgets/qgiscustomwidgets.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "qgsscalewidgetplugin.h"
4242
#include "qgsscrollareawidgetplugin.h"
4343
#include "qgsspinboxplugin.h"
44-
44+
#include "qgssymbolbuttonplugin.h"
4545

4646
QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
4747
: QObject( parent )
@@ -71,6 +71,7 @@ QgisCustomWidgets::QgisCustomWidgets( QObject *parent )
7171
mWidgets.append( new QgsScaleWidgetPlugin( this ) );
7272
mWidgets.append( new QgsScrollAreaWidgetPlugin( this ) );
7373
mWidgets.append( new QgsSpinBoxPlugin( this ) );
74+
mWidgets.append( new QgsSymbolButtonPlugin( this ) );
7475
}
7576

7677
QList<QDesignerCustomWidgetInterface *> QgisCustomWidgets::customWidgets() const
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/***************************************************************************
2+
qgssymbolbuttonplugin.cpp
3+
------------------------
4+
Date : 23.07.2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot 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 "qgssymbolbuttonplugin.h"
18+
#include "qgssymbolbutton.h"
19+
20+
21+
QgsSymbolButtonPlugin::QgsSymbolButtonPlugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
28+
QString QgsSymbolButtonPlugin::name() const
29+
{
30+
return "QgsSymbolButton";
31+
}
32+
33+
QString QgsSymbolButtonPlugin::group() const
34+
{
35+
return QgisCustomWidgets::groupName();
36+
}
37+
38+
QString QgsSymbolButtonPlugin::includeFile() const
39+
{
40+
return "qgssymbolbutton.h";
41+
}
42+
43+
QIcon QgsSymbolButtonPlugin::icon() const
44+
{
45+
return QIcon( ":/images/icons/qgis-icon-60x60.png" );
46+
}
47+
48+
bool QgsSymbolButtonPlugin::isContainer() const
49+
{
50+
return false;
51+
}
52+
53+
QWidget *QgsSymbolButtonPlugin::createWidget( QWidget *parent )
54+
{
55+
return new QgsSymbolButton( parent );
56+
}
57+
58+
bool QgsSymbolButtonPlugin::isInitialized() const
59+
{
60+
return mInitialized;
61+
}
62+
63+
void QgsSymbolButtonPlugin::initialize( QDesignerFormEditorInterface *core )
64+
{
65+
Q_UNUSED( core );
66+
if ( mInitialized )
67+
return;
68+
mInitialized = true;
69+
}
70+
71+
72+
QString QgsSymbolButtonPlugin::toolTip() const
73+
{
74+
return tr( "Select symbol" );
75+
}
76+
77+
QString QgsSymbolButtonPlugin::whatsThis() const
78+
{
79+
return "";
80+
}
81+
82+
QString QgsSymbolButtonPlugin::domXml() const
83+
{
84+
return QString( "<ui language=\"c++\">\n"
85+
" <widget class=\"%1\" name=\"mSymbolButton\">\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+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***************************************************************************
2+
qgssymbolbuttonplugin.h
3+
----------------------
4+
Date : 23.07.2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot 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 QGSSYMBOLBUTTONPLUGIN_H
17+
#define QGSSYMBOLBUTTONPLUGIN_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 QgsSymbolButtonPlugin : public QObject, public QDesignerCustomWidgetInterface
27+
{
28+
Q_OBJECT
29+
Q_INTERFACES( QDesignerCustomWidgetInterface )
30+
31+
public:
32+
explicit QgsSymbolButtonPlugin( 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 // QGSSYMBOLBUTTONPLUGIN_H

0 commit comments

Comments
 (0)
Please sign in to comment.