Skip to content

Commit c69afc9

Browse files
committedJan 13, 2016
script for custom widget plugin creation
1 parent 586b607 commit c69afc9

File tree

3 files changed

+190
-0
lines changed

3 files changed

+190
-0
lines changed
 

‎scripts/customwidget_create.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# This script automatically creates custom widget plugin for a given widget class name.
4+
# Use customwidget_create.sh QgsColorButton to create QgsColorButtonPlugin files.
5+
# It uses author name and email from git config.
6+
7+
# Denis Rouzaud
8+
# 13.01.2016
9+
10+
set -e
11+
12+
CLASSNAME=$1
13+
14+
TODAY=`date '+%d.%m.%Y'`
15+
YEAR=`date '+%Y'`
16+
17+
AUTHOR=`git config user.name`
18+
EMAIL=`git config user.email`
19+
20+
CLASSUPPER="${CLASSNAME^^}"
21+
CLASSLOWER="${CLASSNAME,,}"
22+
23+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
24+
25+
declare -a EXT=("cpp" "h")
26+
for i in "${EXT[@]}"
27+
do
28+
DESTFILE=$DIR/../src/customwidgets/${CLASSLOWER}plugin.$i
29+
cp $DIR/customwidget_template.$i $DESTFILE
30+
sed -i s/%DATE%/"$TODAY"/g "$DESTFILE"
31+
sed -i s/%YEAR%/"$YEAR"/g "$DESTFILE"
32+
sed -i s/%AUTHOR%/"$AUTHOR"/g "$DESTFILE"
33+
sed -i s/%EMAIL%/"$EMAIL"/g "$DESTFILE"
34+
sed -i s/%CLASSUPPERCASE%/"$CLASSUPPER"/g "$DESTFILE"
35+
sed -i s/%CLASSLOWERCASE%/"$CLASSLOWER"/g "$DESTFILE"
36+
sed -i s/%CLASSMIXEDCASE%/"$CLASSNAME"/g "$DESTFILE"
37+
done
38+
39+

‎scripts/customwidget_template.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/***************************************************************************
2+
%CLASSLOWERCASE%plugin.cpp
3+
--------------------------------------
4+
Date : %DATE%
5+
Copyright : (C) %YEAR% %AUTHOR%
6+
Email : %EMAIL%
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 "%CLASSLOWERCASE%plugin.h"
18+
#include "%CLASSLOWERCASE%.h"
19+
20+
21+
%CLASSMIXEDCASE%Plugin::%CLASSMIXEDCASE%Plugin( QObject *parent )
22+
: QObject( parent )
23+
, mInitialized( false )
24+
{
25+
}
26+
27+
QString %CLASSMIXEDCASE%Plugin::name() const
28+
{
29+
return "%CLASSMIXEDCASE%";
30+
}
31+
32+
QString %CLASSMIXEDCASE%Plugin::group() const
33+
{
34+
return QgisCustomWidgets::groupName();
35+
}
36+
37+
QString %CLASSMIXEDCASE%Plugin::includeFile() const
38+
{
39+
return "%CLASSLOWERCASE%.h";
40+
}
41+
42+
QIcon %CLASSMIXEDCASE%Plugin::icon() const
43+
{
44+
return QIcon( ":/images/icons/qgis-icon-60x60.png" );
45+
}
46+
47+
bool %CLASSMIXEDCASE%Plugin::isContainer() const
48+
{
49+
return false;
50+
}
51+
52+
QWidget *%CLASSMIXEDCASE%Plugin::createWidget( QWidget *parent )
53+
{
54+
return new %CLASSMIXEDCASE%( parent );
55+
}
56+
57+
bool %CLASSMIXEDCASE%Plugin::isInitialized() const
58+
{
59+
return mInitialized;
60+
}
61+
62+
void %CLASSMIXEDCASE%Plugin::initialize( QDesignerFormEditorInterface *core )
63+
{
64+
Q_UNUSED( core );
65+
if ( mInitialized )
66+
return;
67+
mInitialized = true;
68+
}
69+
70+
71+
QString %CLASSMIXEDCASE%Plugin::toolTip() const
72+
{
73+
return "";
74+
}
75+
76+
QString %CLASSMIXEDCASE%Plugin::whatsThis() const
77+
{
78+
return "";
79+
}
80+
81+
QString %CLASSMIXEDCASE%Plugin::domXml() const
82+
{
83+
return QString( "<ui language=\"c++\">\n"
84+
" <widget class=\"%1\" name=\"m%CLASSMIXEDCASE%\">\n"
85+
" <property name=\"geometry\">\n"
86+
" <rect>\n"
87+
" <x>0</x>\n"
88+
" <y>0</y>\n"
89+
" <width>90</width>\n"
90+
" <height>27</height>\n"
91+
" </rect>\n"
92+
" </property>\n"
93+
" </widget>\n"
94+
"</ui>\n" )
95+
.arg( name() );
96+
}

‎scripts/customwidget_template.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/***************************************************************************
2+
%CLASSLOWERCASE%plugin.h
3+
--------------------------------------
4+
Date : %DATE%
5+
Copyright : (C) %YEAR% %AUTHOR%
6+
Email : %EMAIL%
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 %CLASSUPPERCASE%PLUGIN_H
17+
#define %CLASSUPPERCASE%PLUGIN_H
18+
19+
20+
#include <QtGlobal>
21+
#if QT_VERSION < 0x050000
22+
#include <QDesignerCustomWidgetCollectionInterface>
23+
#include <QDesignerExportWidget>
24+
#else
25+
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
26+
#include <QtUiPlugin/QDesignerExportWidget>
27+
#endif
28+
29+
30+
class CUSTOMWIDGETS_EXPORT %CLASSMIXEDCASE%Plugin : public QObject, public QDesignerCustomWidgetInterface
31+
{
32+
Q_OBJECT
33+
Q_INTERFACES( QDesignerCustomWidgetInterface )
34+
35+
public:
36+
explicit %CLASSMIXEDCASE%Plugin( QObject *parent = 0 );
37+
38+
private:
39+
bool mInitialized;
40+
41+
// QDesignerCustomWidgetInterface interface
42+
public:
43+
QString name() const override;
44+
QString group() const override;
45+
QString includeFile() const override;
46+
QIcon icon() const override;
47+
bool isContainer() const override;
48+
QWidget *createWidget( QWidget *parent ) override;
49+
bool isInitialized() const override;
50+
void initialize( QDesignerFormEditorInterface *core ) override;
51+
QString toolTip() const override;
52+
QString whatsThis() const override;
53+
QString domXml() const override;
54+
};
55+
#endif // %CLASSUPPERCASE%PLUGIN_H

0 commit comments

Comments
 (0)
Please sign in to comment.