From 4abda3c5ed22a26c97e9abbe11ac5f689f983d58 Mon Sep 17 00:00:00 2001 From: boulant Date: Wed, 26 Oct 2011 13:31:30 +0000 Subject: [PATCH] Add a end-user tools (folder tools/dlgfactory) for bootstraping a Qt dialog box. --- Makefile.am | 2 +- configure.ac | 1 + tools/dlgfactory/GenericDialog.cxx | 29 ++++++ tools/dlgfactory/GenericDialog.hxx | 27 ++++++ tools/dlgfactory/GenericDialog.ui | 89 +++++++++++++++++++ tools/dlgfactory/Makefile.am | 92 +++++++++++++++++++ tools/dlgfactory/README.txt | 12 +++ tools/dlgfactory/__GDIALOG__.cxx | 6 ++ tools/dlgfactory/__GDIALOG__.hxx | 20 +++++ tools/dlgfactory/__GDIALOG__.ui | 99 +++++++++++++++++++++ tools/dlgfactory/__QDIALOG__.cxx | 20 +++++ tools/dlgfactory/__QDIALOG__.hxx | 23 +++++ tools/dlgfactory/__QDIALOG__.ui | 67 ++++++++++++++ tools/dlgfactory/dlgfactory.sh | 137 +++++++++++++++++++++++++++++ tools/dlgfactory/gtester.cxx | 21 +++++ tools/dlgfactory/qtester.cxx | 21 +++++ 16 files changed, 665 insertions(+), 1 deletion(-) create mode 100644 tools/dlgfactory/GenericDialog.cxx create mode 100644 tools/dlgfactory/GenericDialog.hxx create mode 100644 tools/dlgfactory/GenericDialog.ui create mode 100644 tools/dlgfactory/Makefile.am create mode 100644 tools/dlgfactory/README.txt create mode 100644 tools/dlgfactory/__GDIALOG__.cxx create mode 100644 tools/dlgfactory/__GDIALOG__.hxx create mode 100644 tools/dlgfactory/__GDIALOG__.ui create mode 100644 tools/dlgfactory/__QDIALOG__.cxx create mode 100644 tools/dlgfactory/__QDIALOG__.hxx create mode 100644 tools/dlgfactory/__QDIALOG__.ui create mode 100755 tools/dlgfactory/dlgfactory.sh create mode 100644 tools/dlgfactory/gtester.cxx create mode 100644 tools/dlgfactory/qtester.cxx diff --git a/Makefile.am b/Makefile.am index ed1a9c004..567f59f1f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,7 +35,7 @@ else !GUI_ENABLE_CORBA IDLDIR = endif -SUBDIRS = $(IDLDIR) adm_local resources src doc bin +SUBDIRS = $(IDLDIR) adm_local resources src doc bin tools/dlgfactory DIST_SUBDIRS = idl adm_local resources src doc bin diff --git a/configure.ac b/configure.ac index b475a8b58..4a3d6143b 100644 --- a/configure.ac +++ b/configure.ac @@ -671,5 +671,6 @@ AC_OUTPUT([ \ src/GUI_PY/Makefile \ resources/Makefile \ idl/Makefile \ + tools/dlgfactory/Makefile \ Makefile ]) diff --git a/tools/dlgfactory/GenericDialog.cxx b/tools/dlgfactory/GenericDialog.cxx new file mode 100644 index 000000000..9b8456674 --- /dev/null +++ b/tools/dlgfactory/GenericDialog.cxx @@ -0,0 +1,29 @@ +#include "GenericDialog.hxx" + +GenericDialog::GenericDialog(QDialog *parent) : QDialog(parent) +{ + ui.setupUi(this); // A faire en premier + + /* + Personnalisez vos widgets ici si nécessaire + Réalisez des connexions supplémentaires entre signaux et slots + */ + + // The slots accept() and reject() are already connected to the + // buttonbox (inherited features) +} + +QFrame * GenericDialog::getPanel() { + return ui.centralPanel; +} + +QDialogButtonBox * GenericDialog::getButtonBox() { + return ui.buttonBox; +} + + +#include +void GenericDialog::accept() { + qDebug() << "accept() is not implemented yet"; + QDialog::accept(); +} diff --git a/tools/dlgfactory/GenericDialog.hxx b/tools/dlgfactory/GenericDialog.hxx new file mode 100644 index 000000000..ee946617d --- /dev/null +++ b/tools/dlgfactory/GenericDialog.hxx @@ -0,0 +1,27 @@ +#ifndef _GenericDialog_HXX +#define _GenericDialog_HXX + +#include +#include "ui_GenericDialog.hxx" + +class GenericDialog : public QDialog +{ + Q_OBJECT + +public: + GenericDialog(QDialog *parent = 0); + + protected: + QFrame * getPanel(); + QDialogButtonBox * getButtonBox(); + + protected slots: + void accept(); + //void reject(); + + private: + Ui_GenericDialog ui; // instance of the class defined in ui_GenericDialog.h +}; + + +#endif // _GenericDialog_HXX diff --git a/tools/dlgfactory/GenericDialog.ui b/tools/dlgfactory/GenericDialog.ui new file mode 100644 index 000000000..1fe7ae99e --- /dev/null +++ b/tools/dlgfactory/GenericDialog.ui @@ -0,0 +1,89 @@ + + GenericDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + GenericDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + GenericDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/tools/dlgfactory/Makefile.am b/tools/dlgfactory/Makefile.am new file mode 100644 index 000000000..ecf787579 --- /dev/null +++ b/tools/dlgfactory/Makefile.am @@ -0,0 +1,92 @@ +# Copyright (C) 2010 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# -* Makefile *- +# +# Author : Guillaume Boulant (EDF/R&D) + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# moc-files generation +%_moc.cxx: %.hxx + $(MOC) $< -o $@ + +# Qt form files generation (using UIC) +ui_%.hxx: %.ui + $(UIC) -o $@ $< + +UIC_FILES_QDIALOG = \ + ui_QDialogTest.hxx + +# MOC pre-processing +MOC_FILES_QDIALOG = \ + QDialogTest_moc.cxx + +BUILT_SOURCES = $(UIC_FILES_QDIALOG) $(UIC_FILES_GDIALOG) + +mostlyclean-local: + rm -f @builddir@/*_moc.cxx @builddir@/ui_*.hxx + rm @builddir@/QDialogTest* + rm @builddir@/GDialogTest* + +QDialogTest.ui: __QDIALOG__.ui __QDIALOG__.hxx __QDIALOG__.cxx dlgfactory.sh + $(srcdir)/dlgfactory.sh -n QDialogTest -t qdialog + +GDialogTest.ui: __GDIALOG__.ui __GDIALOG__.hxx __GDIALOG__.cxx dlgfactory.sh + $(srcdir)/dlgfactory.sh -n GDialogTest -t gdialog + + +QT_CXXFLAGS=@QT_INCLUDES@ @QT_MT_INCLUDES@ +QT_LIBS=@QT_LIBS@ + +# Program targets +bin_PROGRAMS = qtester gtester + +# QDialog tester +qtester_SOURCES = \ + qtester.cxx \ + QDialogTest.cxx \ + $(MOC_FILES_QDIALOG) $(UIC_FILES_QDIALOG) + +qtester_CPPFLAGS = \ + $(QT_CXXFLAGS) + +qtester_LDFLAGS = \ + $(QT_LIBS) + + +# GDialog tester +MOC_FILES_GDIALOG= \ + GenericDialog_moc.cxx \ + GDialogTest_moc.cxx + +UIC_FILES_GDIALOG= \ + ui_GenericDialog.hxx \ + ui_GDialogTest.hxx + +gtester_SOURCES = \ + gtester.cxx \ + GenericDialog.cxx \ + GDialogTest.cxx \ + $(MOC_FILES_GDIALOG) $(UIC_FILES_GDIALOG) + +gtester_CPPFLAGS = \ + $(QT_CXXFLAGS) + +gtester_LDFLAGS = \ + $(QT_LIBS) diff --git a/tools/dlgfactory/README.txt b/tools/dlgfactory/README.txt new file mode 100644 index 000000000..1ddca1679 --- /dev/null +++ b/tools/dlgfactory/README.txt @@ -0,0 +1,12 @@ +This package provides a simple tool to generates the bootstrap files +of a standard Qt dialog. Nothing original neither very smart, but just +help to initiate all this stuff the good way. + +See the header of the script dlgfactory.sh for details. + +Some use cases (basic unit test) are given in the files qtester.cxx +and gtester.cxx. The build procedure (when you type make) create test +classes called QDialogTest and GDialogTest and used respectively in +qtester and gtester. + +(gboulant - 26 oct. 2011) diff --git a/tools/dlgfactory/__GDIALOG__.cxx b/tools/dlgfactory/__GDIALOG__.cxx new file mode 100644 index 000000000..705c7213f --- /dev/null +++ b/tools/dlgfactory/__GDIALOG__.cxx @@ -0,0 +1,6 @@ +#include "__CLASSNAME__.hxx" + +__CLASSNAME__::__CLASSNAME__(QDialog *parent) : GenericDialog(parent) +{ + ui.setupUi(this->getPanel()); +} diff --git a/tools/dlgfactory/__GDIALOG__.hxx b/tools/dlgfactory/__GDIALOG__.hxx new file mode 100644 index 000000000..ab805a197 --- /dev/null +++ b/tools/dlgfactory/__GDIALOG__.hxx @@ -0,0 +1,20 @@ +#ifndef ___CLASSNAME___HXX +#define ___CLASSNAME___HXX + +#include +#include "ui___CLASSNAME__.hxx" +#include "GenericDialog.hxx" + +class __CLASSNAME__ : public GenericDialog +{ + Q_OBJECT + + public: + __CLASSNAME__(QDialog *parent = 0); + + private: + Ui___CLASSNAME__ ui; // instance of the class defined in ui___CLASSNAME__.hxx +}; + + +#endif // ___CLASSNAME___HXX diff --git a/tools/dlgfactory/__GDIALOG__.ui b/tools/dlgfactory/__GDIALOG__.ui new file mode 100644 index 000000000..7f5c27dca --- /dev/null +++ b/tools/dlgfactory/__GDIALOG__.ui @@ -0,0 +1,99 @@ + + __CLASSNAME__ + + + + 0 + 0 + 340 + 300 + + + + Form + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + 0 + + + 6 + + + + + 0 + + + 6 + + + + + Pression : + + + + + + + Température : + + + + + + + + + 0 + + + 6 + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 121 + + + + + + + + + + + diff --git a/tools/dlgfactory/__QDIALOG__.cxx b/tools/dlgfactory/__QDIALOG__.cxx new file mode 100644 index 000000000..32134c395 --- /dev/null +++ b/tools/dlgfactory/__QDIALOG__.cxx @@ -0,0 +1,20 @@ +#include "__CLASSNAME__.hxx" + +__CLASSNAME__::__CLASSNAME__(QDialog *parent) : QDialog(parent) +{ + ui.setupUi(this); // A faire en premier + + /* + Personnalisez vos widgets ici si nécessaire + Réalisez des connexions supplémentaires entre signaux et slots + */ + + // The slots accept() and reject() are already connected to the + // buttonbox (inherited features) +} + +#include +void __CLASSNAME__::accept() { + qDebug() << "accept() is not implemented yet"; + QDialog::accept(); +} diff --git a/tools/dlgfactory/__QDIALOG__.hxx b/tools/dlgfactory/__QDIALOG__.hxx new file mode 100644 index 000000000..3865e170b --- /dev/null +++ b/tools/dlgfactory/__QDIALOG__.hxx @@ -0,0 +1,23 @@ +#ifndef ___CLASSNAME___HXX +#define ___CLASSNAME___HXX + +#include +#include "ui___CLASSNAME__.hxx" + +class __CLASSNAME__ : public QDialog +{ + Q_OBJECT + + public: + __CLASSNAME__(QDialog *parent = 0); + + protected slots: + void accept(); + //void reject(); + + private: + Ui___CLASSNAME__ ui; // instance of the class defined in ui___CLASSNAME__.hxx +}; + + +#endif // ___CLASSNAME___HXX diff --git a/tools/dlgfactory/__QDIALOG__.ui b/tools/dlgfactory/__QDIALOG__.ui new file mode 100644 index 000000000..88cf24de2 --- /dev/null +++ b/tools/dlgfactory/__QDIALOG__.ui @@ -0,0 +1,67 @@ + + __CLASSNAME__ + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok + + + + + + + buttonBox + accepted() + __CLASSNAME__ + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + __CLASSNAME__ + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/tools/dlgfactory/dlgfactory.sh b/tools/dlgfactory/dlgfactory.sh new file mode 100755 index 000000000..0cbc4ca31 --- /dev/null +++ b/tools/dlgfactory/dlgfactory.sh @@ -0,0 +1,137 @@ +#!/bin/sh +# +# ================================================================== +#_debut_usage +# +# USAGE: +# +# dlgfactory.sh -n className [-t classType] +# +# +# DESCRIPTION: +# +# This script generates a set of files to initiate a dialog qt window +# (i.e. MyDialog.ui, MyDialog.hxx and MyDialog.cxx files). +# +# The dialog window can be a self-consistent class (i.e. depends only +# on Qt classes) or a classe that inherits from the class +# GenericDialog whose implementation is provided in this package and +# whose design is defined by the GenericDialog.ui file (editable using +# the qt designer). +# +# The -t option let you choose between the two possibilities (specify +# "-t qdialog" for the first case, "-t gdialog" otherwise). +# +# OPTION: +# -n : specify the name of the class (default is TestDialog) +# +# -t : specify the type of the class (default is qdialog) +# +#_fin_usage +# ================================================================== +# + +thisScript=$(which $0) +TOOLDIRNAME=$(dirname $0) + +displayUsage() +{ + cat $thisScript | sed -e '/^#_debut_usage/,/^#_fin_usage/!d' \ + -e '/^#_debut_usage/d' \ + -e '/^#_fin_usage/d' \ + -e 's/^#//g' +} + +# +# Read the options on the command line +# +className=TestDialog +classType=dialog +if [ $# -eq 0 ]; then + displayUsage + exit 1 +else + while [ $# -ne 0 ]; do + case $1 in + -n) + shift; className=$1; shift ;; + -t) + shift; classType=$1; shift ;; + *) + displayUsage;; + esac + done +fi + +if [ "$classType" == "qdialog" ]; then + sed s/__CLASSNAME__/$className/g $TOOLDIRNAME/__QDIALOG__.ui > $className.ui + sed s/__CLASSNAME__/$className/g $TOOLDIRNAME/__QDIALOG__.hxx > $className.hxx + sed s/__CLASSNAME__/$className/g $TOOLDIRNAME/__QDIALOG__.cxx > $className.cxx +else + sed s/__CLASSNAME__/$className/g $TOOLDIRNAME/__GDIALOG__.ui > $className.ui + sed s/__CLASSNAME__/$className/g $TOOLDIRNAME/__GDIALOG__.hxx > $className.hxx + sed s/__CLASSNAME__/$className/g $TOOLDIRNAME/__GDIALOG__.cxx > $className.cxx +fi + +displayMessage() +{ + cat $thisScript | sed -e '/^#_debut_message/,/^#_fin_message/!d' \ + -e '/^#_debut_message/d' \ + -e '/^#_fin_message/d' \ + -e 's/^#//g' \ + -e "s/__CLASSNAME__/$className/g" +} + +#_debut_message +## +## --------------------------------------------------------- +## Generation rules to create moc files from QObject headers +## and form source files from ui files +## --------------------------------------------------------- +## +#%_moc.cxx: %.hxx +# $(MOC) $< -o $@ +# +#ui_%.hxx: %.ui +# $(UIC) -o $@ $< +# +## +## --------------------------------------------------------- +## Declaration of form files generated by UIC and MOC files +## as BUILT_SOURCES to be used in the building process. +## --------------------------------------------------------- +## +#UIC_FILES = \ +# ui___CLASSNAME__.hxx +## +#MOC_FILES = \ +# __CLASSNAME___moc.cxx +# +#BUILT_SOURCES = $(UIC_FILES) +# +## +## --------------------------------------------------------- +## Declaration of sources files to the building process +## --------------------------------------------------------- +## MOC files and UIC files should be added to the list of undistributed +## source files with something like (where should be +## replaced by the name of the product declared by the directive +## lib_LTLIBRARIES): +## +#nodist__la_SOURCES += $(MOC_FILES) $(UIC_FILES) +# +#dist__la_SOURCES += __CLASSNAME__.cxx +#salomeinclude_HEADERS += __CLASSNAME__.hxx +# +#_la_CPPFLAGS = \ +# $(QT_CXXFLAGS) +# +#_la_LDFLAGS = \ +# $(QT_LIBS) + +#_fin_message + +echo "Note that the following directives should be present in your Makefile.am (or something like that):" +echo "" +displayMessage + diff --git a/tools/dlgfactory/gtester.cxx b/tools/dlgfactory/gtester.cxx new file mode 100644 index 000000000..ed0fc6812 --- /dev/null +++ b/tools/dlgfactory/gtester.cxx @@ -0,0 +1,21 @@ +// +// This program can be used for unit test of dialog box. +// You just have to include the interface file (*.h) and +// use the dialog class as illustrated in the functions TEST_*. +// (gboulant - 12/10/2010) +// +#include +#include +#include "GDialogTest.hxx" + +void TEST_show() { + GDialogTest * dialog = new GDialogTest(); + dialog->show(); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + TEST_show(); + return app.exec(); +} diff --git a/tools/dlgfactory/qtester.cxx b/tools/dlgfactory/qtester.cxx new file mode 100644 index 000000000..19174b76a --- /dev/null +++ b/tools/dlgfactory/qtester.cxx @@ -0,0 +1,21 @@ +// +// This program can be used for unit test of dialog box. +// You just have to include the interface file (*.h) and +// use the dialog class as illustrated in the functions TEST_*. +// (gboulant - 12/10/2010) +// +#include +#include +#include "QDialogTest.hxx" + +void TEST_show() { + QDialogTest * dialog = new QDialogTest(); + dialog->show(); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + TEST_show(); + return app.exec(); +} -- 2.39.2