-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
script for custom widget plugin creation
- Loading branch information
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
# This script automatically creates custom widget plugin for a given widget class name. | ||
# Use customwidget_create.sh QgsColorButton to create QgsColorButtonPlugin files. | ||
# It uses author name and email from git config. | ||
|
||
# Denis Rouzaud | ||
# 13.01.2016 | ||
|
||
set -e | ||
|
||
CLASSNAME=$1 | ||
|
||
TODAY=`date '+%d.%m.%Y'` | ||
YEAR=`date '+%Y'` | ||
|
||
AUTHOR=`git config user.name` | ||
EMAIL=`git config user.email` | ||
|
||
CLASSUPPER="${CLASSNAME^^}" | ||
CLASSLOWER="${CLASSNAME,,}" | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
declare -a EXT=("cpp" "h") | ||
for i in "${EXT[@]}" | ||
do | ||
DESTFILE=$DIR/../src/customwidgets/${CLASSLOWER}plugin.$i | ||
cp $DIR/customwidget_template.$i $DESTFILE | ||
sed -i s/%DATE%/"$TODAY"/g "$DESTFILE" | ||
sed -i s/%YEAR%/"$YEAR"/g "$DESTFILE" | ||
sed -i s/%AUTHOR%/"$AUTHOR"/g "$DESTFILE" | ||
sed -i s/%EMAIL%/"$EMAIL"/g "$DESTFILE" | ||
sed -i s/%CLASSUPPERCASE%/"$CLASSUPPER"/g "$DESTFILE" | ||
sed -i s/%CLASSLOWERCASE%/"$CLASSLOWER"/g "$DESTFILE" | ||
sed -i s/%CLASSMIXEDCASE%/"$CLASSNAME"/g "$DESTFILE" | ||
done | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/*************************************************************************** | ||
%CLASSLOWERCASE%plugin.cpp | ||
-------------------------------------- | ||
Date : %DATE% | ||
Copyright : (C) %YEAR% %AUTHOR% | ||
Email : %EMAIL% | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgiscustomwidgets.h" | ||
#include "%CLASSLOWERCASE%plugin.h" | ||
#include "%CLASSLOWERCASE%.h" | ||
|
||
|
||
%CLASSMIXEDCASE%Plugin::%CLASSMIXEDCASE%Plugin( QObject *parent ) | ||
: QObject( parent ) | ||
, mInitialized( false ) | ||
{ | ||
} | ||
|
||
QString %CLASSMIXEDCASE%Plugin::name() const | ||
{ | ||
return "%CLASSMIXEDCASE%"; | ||
} | ||
|
||
QString %CLASSMIXEDCASE%Plugin::group() const | ||
{ | ||
return QgisCustomWidgets::groupName(); | ||
} | ||
|
||
QString %CLASSMIXEDCASE%Plugin::includeFile() const | ||
{ | ||
return "%CLASSLOWERCASE%.h"; | ||
} | ||
|
||
QIcon %CLASSMIXEDCASE%Plugin::icon() const | ||
{ | ||
return QIcon( ":/images/icons/qgis-icon-60x60.png" ); | ||
} | ||
|
||
bool %CLASSMIXEDCASE%Plugin::isContainer() const | ||
{ | ||
return false; | ||
} | ||
|
||
QWidget *%CLASSMIXEDCASE%Plugin::createWidget( QWidget *parent ) | ||
{ | ||
return new %CLASSMIXEDCASE%( parent ); | ||
} | ||
|
||
bool %CLASSMIXEDCASE%Plugin::isInitialized() const | ||
{ | ||
return mInitialized; | ||
} | ||
|
||
void %CLASSMIXEDCASE%Plugin::initialize( QDesignerFormEditorInterface *core ) | ||
{ | ||
Q_UNUSED( core ); | ||
if ( mInitialized ) | ||
return; | ||
mInitialized = true; | ||
} | ||
|
||
|
||
QString %CLASSMIXEDCASE%Plugin::toolTip() const | ||
{ | ||
return ""; | ||
} | ||
|
||
QString %CLASSMIXEDCASE%Plugin::whatsThis() const | ||
{ | ||
return ""; | ||
} | ||
|
||
QString %CLASSMIXEDCASE%Plugin::domXml() const | ||
{ | ||
return QString( "<ui language=\"c++\">\n" | ||
" <widget class=\"%1\" name=\"m%CLASSMIXEDCASE%\">\n" | ||
" <property name=\"geometry\">\n" | ||
" <rect>\n" | ||
" <x>0</x>\n" | ||
" <y>0</y>\n" | ||
" <width>90</width>\n" | ||
" <height>27</height>\n" | ||
" </rect>\n" | ||
" </property>\n" | ||
" </widget>\n" | ||
"</ui>\n" ) | ||
.arg( name() ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*************************************************************************** | ||
%CLASSLOWERCASE%plugin.h | ||
-------------------------------------- | ||
Date : %DATE% | ||
Copyright : (C) %YEAR% %AUTHOR% | ||
Email : %EMAIL% | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef %CLASSUPPERCASE%PLUGIN_H | ||
#define %CLASSUPPERCASE%PLUGIN_H | ||
|
||
|
||
#include <QtGlobal> | ||
#if QT_VERSION < 0x050000 | ||
#include <QDesignerCustomWidgetCollectionInterface> | ||
#include <QDesignerExportWidget> | ||
#else | ||
#include <QtUiPlugin/QDesignerCustomWidgetInterface> | ||
#include <QtUiPlugin/QDesignerExportWidget> | ||
#endif | ||
|
||
|
||
class CUSTOMWIDGETS_EXPORT %CLASSMIXEDCASE%Plugin : public QObject, public QDesignerCustomWidgetInterface | ||
{ | ||
Q_OBJECT | ||
Q_INTERFACES( QDesignerCustomWidgetInterface ) | ||
|
||
public: | ||
explicit %CLASSMIXEDCASE%Plugin( QObject *parent = 0 ); | ||
|
||
private: | ||
bool mInitialized; | ||
|
||
// QDesignerCustomWidgetInterface interface | ||
public: | ||
QString name() const override; | ||
QString group() const override; | ||
QString includeFile() const override; | ||
QIcon icon() const override; | ||
bool isContainer() const override; | ||
QWidget *createWidget( QWidget *parent ) override; | ||
bool isInitialized() const override; | ||
void initialize( QDesignerFormEditorInterface *core ) override; | ||
QString toolTip() const override; | ||
QString whatsThis() const override; | ||
QString domXml() const override; | ||
}; | ||
#endif // %CLASSUPPERCASE%PLUGIN_H |