From c69afc9e6d3d8cb5b1d7b259bada651dba3f897e Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Wed, 13 Jan 2016 11:49:04 +0100 Subject: [PATCH] script for custom widget plugin creation --- scripts/customwidget_create.sh | 39 +++++++++++++ scripts/customwidget_template.cpp | 96 +++++++++++++++++++++++++++++++ scripts/customwidget_template.h | 55 ++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100755 scripts/customwidget_create.sh create mode 100644 scripts/customwidget_template.cpp create mode 100644 scripts/customwidget_template.h diff --git a/scripts/customwidget_create.sh b/scripts/customwidget_create.sh new file mode 100755 index 000000000000..13c25bb6de15 --- /dev/null +++ b/scripts/customwidget_create.sh @@ -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 + + diff --git a/scripts/customwidget_template.cpp b/scripts/customwidget_template.cpp new file mode 100644 index 000000000000..a96740828310 --- /dev/null +++ b/scripts/customwidget_template.cpp @@ -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( "\n" + " \n" + " \n" + " \n" + " 0\n" + " 0\n" + " 90\n" + " 27\n" + " \n" + " \n" + " \n" + "\n" ) + .arg( name() ); +} diff --git a/scripts/customwidget_template.h b/scripts/customwidget_template.h new file mode 100644 index 000000000000..09f93e61b540 --- /dev/null +++ b/scripts/customwidget_template.h @@ -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 +#if QT_VERSION < 0x050000 +#include +#include +#else +#include +#include +#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