script for custom widget plugin creation

This commit is contained in:
Denis Rouzaud 2016-01-13 11:49:04 +01:00
parent 586b607245
commit c69afc9e6d
3 changed files with 190 additions and 0 deletions

39
scripts/customwidget_create.sh Executable file
View File

@ -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

View File

@ -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() );
}

View File

@ -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