diff --git a/elements/nomenclatures/bases/renvoi/next_folio.elmt b/elements/nomenclatures/bases/renvoi/next_folio.elmt index c8b439d3f..56f3b20d4 100644 --- a/elements/nomenclatures/bases/renvoi/next_folio.elmt +++ b/elements/nomenclatures/bases/renvoi/next_folio.elmt @@ -1,4 +1,4 @@ - + الصفحة التالية Nächste Seite diff --git a/elements/nomenclatures/bases/renvoi/previous_folio.elmt b/elements/nomenclatures/bases/renvoi/previous_folio.elmt index 0c486248d..a99f8baaf 100644 --- a/elements/nomenclatures/bases/renvoi/previous_folio.elmt +++ b/elements/nomenclatures/bases/renvoi/previous_folio.elmt @@ -1,4 +1,4 @@ - + الصفحة السابقة Vorherige Seite diff --git a/sources/diagram.cpp b/sources/diagram.cpp index acaad2d6c..c516f9e2e 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -19,6 +19,7 @@ #include "qetgraphicsitem/conductor.h" #include "qetgraphicsitem/conductortextitem.h" #include "qetgraphicsitem/customelement.h" +#include "factory/elementfactory.h" #include "diagram.h" #include "diagramcommands.h" #include "diagramcontent.h" @@ -523,9 +524,10 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf ElementsLocation element_location = ElementsLocation(type_id); if (type_id.startsWith("embed://")) element_location.setProject(project_); - CustomElement *nvel_elmt = new CustomElement(element_location); - if (nvel_elmt -> isNull()) { - QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(nvel_elmt -> state()); + int state = 0; + Element *nvel_elmt = ElementFactory::Instance()->createElement(element_location, 0, 0, &state); + if (state) { + QString debug_message = QString("Diagram::fromXml() : Le chargement de la description de l'element %1 a echoue avec le code d'erreur %2").arg(element_location.path()).arg(state); qDebug() << qPrintable(debug_message); delete nvel_elmt; diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 959403419..c2fda0e94 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -42,6 +42,7 @@ #include #include #include +#include "factory/elementfactory.h" /** @@ -856,7 +857,7 @@ bool DiagramView::mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocati bool DiagramView::addElementAtPos(const ElementsLocation &location, const QPoint &pos) { // construit une instance de l'element correspondant a l'emplacement int state; - Element *el = new CustomElement(location, 0, 0, &state); + Element *el = ElementFactory::Instance()->createElement(location, 0, 0, &state); if (state) { delete el; return(false); diff --git a/sources/elementscollectioncache.cpp b/sources/elementscollectioncache.cpp index fb169c317..72db9f0fd 100644 --- a/sources/elementscollectioncache.cpp +++ b/sources/elementscollectioncache.cpp @@ -2,7 +2,7 @@ #include "elementscollection.h" #include "elementscategory.h" #include "elementdefinition.h" -#include "qetgraphicsitem/customelement.h" +#include "factory/elementfactory.h" /** Construct a cache for elements collections. @@ -171,7 +171,7 @@ QPixmap ElementsCollectionCache::pixmap() const { */ bool ElementsCollectionCache::fetchData(const ElementsLocation &location) { int state; - CustomElement *custom_elmt = new CustomElement(location, 0, 0, &state); + Element *custom_elmt = ElementFactory::Instance()->createElement(location, 0, 0, &state); if (state) { qDebug() << "ElementsCollectionCache::fetchData() : Le chargement du composant" << qPrintable(location.toString()) << "a echoue avec le code d'erreur" << state; } else { diff --git a/sources/elementspanel.cpp b/sources/elementspanel.cpp index bc16072d2..01a54129b 100644 --- a/sources/elementspanel.cpp +++ b/sources/elementspanel.cpp @@ -21,7 +21,7 @@ #include "diagram.h" #include "elementscategory.h" #include "elementscollectioncache.h" -#include "qetgraphicsitem/customelement.h" +#include "factory/elementfactory.h" #include "fileelementscollection.h" #include "fileelementdefinition.h" #include "qeticons.h" @@ -309,7 +309,7 @@ void ElementsPanel::startElementDrag(const ElementsLocation &location) { // element temporaire pour fournir un apercu int elmt_creation_state; - Element *temp_elmt = new CustomElement(location, 0, 0, &elmt_creation_state); + Element *temp_elmt = ElementFactory::Instance()->createElement(location, 0, 0, &elmt_creation_state); if (elmt_creation_state) { delete temp_elmt; return; diff --git a/sources/factory/elementfactory.cpp b/sources/factory/elementfactory.cpp new file mode 100644 index 000000000..36e72220e --- /dev/null +++ b/sources/factory/elementfactory.cpp @@ -0,0 +1,52 @@ +/* + Copyright 2006-2013 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech 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. + + QElectroTech 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "elementfactory.h" +#include "elementdefinition.h" +#include "elementscollectionitem.h" +#include "qetapp.h" +#include "QDomElement" +#include "qetgraphicsitem/simpleelement.h" +#include "qetgraphicsitem/reportelement.h" + +ElementFactory* ElementFactory::factory_ = 0; +/** + * @brief ElementFactory::createElement + * @param location create element at this location + * @param qgi parent item for this elemnt + * @param s diagram of the element + * @param state state of the creation + * @return the element or 0 + */ +Element * ElementFactory::createElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) { + // recupere la definition de l'element + ElementsCollectionItem *element_item = QETApp::collectionItem(location); + ElementDefinition *element_definition; + if (!element_item ||\ + !element_item -> isElement() ||\ + !(element_definition = qobject_cast(element_item))) { + if (state) *state = 1; + return 0; + } + + if (element_definition->xml().hasAttribute("link_type")) { + QString link_type = element_definition->xml().attribute("link_type"); + if (link_type == "folio_report") return (new ReportElement(location, qgi, s, state)); + } + //default if nothing match for link_type + return (new SimpleElement(location, qgi, s, state)); +} diff --git a/sources/factory/elementfactory.h b/sources/factory/elementfactory.h new file mode 100644 index 000000000..8ca708ba6 --- /dev/null +++ b/sources/factory/elementfactory.h @@ -0,0 +1,70 @@ +/* + Copyright 2006-2013 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech 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. + + QElectroTech 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef ELEMENTFACTORY_H +#define ELEMENTFACTORY_H + +#include +#include "qetgraphicsitem/element.h" + +/** + * @brief The ElementFactory class + *this class is a pattern factory and also a singleton factory. + *this class create new instance of herited class element like + *simple element or report element. + * + */ +class ElementFactory +{ + //methods for singleton pattern + public: + // return instance of factory + static ElementFactory* Instance() { + static QMutex mutex; + if (!factory_) { + mutex.lock(); + if (!factory_) factory_ = new ElementFactory(); + mutex.unlock(); + } + return factory_; + } + // delete the instance of factory + static void dropInstance () { + static QMutex mutex; + if (factory_) { + mutex.lock(); + delete factory_; + factory_ = 0; + mutex.unlock(); + } + } + //attributes + private: + static ElementFactory* factory_; + + //methods for the class factory himself + private: + ElementFactory() {} + ElementFactory (const ElementFactory &); + ElementFactory operator= (const ElementFactory &); + ~ElementFactory() {} + + public: + Element * createElement (const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0); +}; +//ElementFactory ElementFactory::factory_ = 0; +#endif // ELEMENTFACTORY_H diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index d85c7a0da..ce8f1f1ba 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -36,6 +36,7 @@ #define QUOTE(x) STRINGIFY(x) #define STRINGIFY(x) #x #include +#include "factory/elementfactory.h" #ifdef QET_ALLOW_OVERRIDE_CED_OPTION QString QETApp::common_elements_dir = QString(); @@ -141,6 +142,7 @@ QETApp::~QETApp() { delete common_collection; if (custom_tbt_collection_) delete custom_tbt_collection_; if (common_tbt_collection_) delete common_tbt_collection_; + ElementFactory::dropInstance(); } /** diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index 56a6a97ae..122af8607 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -82,12 +82,6 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qg elmt_state = 0; } -CustomElement::CustomElement(const QDomElement &xml_def_elmt, QGraphicsItem *qgi, Diagram *s, int *state) : FixedElement(qgi, s) { - int elmt_state = -1; - buildFromXml(xml_def_elmt, &elmt_state); - if (state) *state = elmt_state; -} - /** Construit l'element personnalise a partir d'un element XML representant sa definition. diff --git a/sources/qetgraphicsitem/customelement.h b/sources/qetgraphicsitem/customelement.h index 7e546444f..34a061ed7 100644 --- a/sources/qetgraphicsitem/customelement.h +++ b/sources/qetgraphicsitem/customelement.h @@ -35,7 +35,6 @@ class CustomElement : public FixedElement { // constructors, destructor public: CustomElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0); - CustomElement(const QDomElement &, QGraphicsItem * = 0, Diagram * = 0, int * = 0); virtual ~CustomElement(); private: diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 50031f267..2eb964ec3 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -28,6 +28,15 @@ class ElementTextItem; class Element : public QetGraphicsItem { Q_OBJECT + + public: + enum linkerType{ + simple = 1, + report = 2, + master = 4, + slave = 8, + bornier = 16 + }; // constructors, destructor public: @@ -78,6 +87,8 @@ class Element : public QetGraphicsItem { virtual QString typeId() const = 0; /// @return the human name for this element virtual QString name() const = 0; + /// @return the linkable type + virtual int linkType() const = 0; virtual bool isHighlighted() const; virtual void setHighlighted(bool); diff --git a/sources/qetgraphicsitem/reportelement.cpp b/sources/qetgraphicsitem/reportelement.cpp new file mode 100644 index 000000000..63acee435 --- /dev/null +++ b/sources/qetgraphicsitem/reportelement.cpp @@ -0,0 +1,26 @@ +/* + Copyright 2006-2013 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech 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. + + QElectroTech 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "reportelement.h" + +ReportElement::ReportElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) : + CustomElement(location, qgi, s, state) +{} + +int ReportElement::linkType() const { + return ReportElement::report; +} diff --git a/sources/qetgraphicsitem/reportelement.h b/sources/qetgraphicsitem/reportelement.h new file mode 100644 index 000000000..56e797ea9 --- /dev/null +++ b/sources/qetgraphicsitem/reportelement.h @@ -0,0 +1,42 @@ +/* + Copyright 2006-2013 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech 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. + + QElectroTech 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef REPORTELEMENT_H +#define REPORTELEMENT_H + +#include "customelement.h" + +/** + * @brief The ReportElement class + *this class represent an element that can be linked to an other ReportElement + * a folio report in a diagram is a element that show a wire go on an other folio + */ +class ReportElement : public CustomElement { + + Q_OBJECT + + public : + explicit ReportElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0); + + virtual int linkType() const; + + signals: + + public slots: +}; + +#endif // REPORTELEMENT_H diff --git a/sources/qetgraphicsitem/simpleelement.cpp b/sources/qetgraphicsitem/simpleelement.cpp new file mode 100644 index 000000000..e85b66d52 --- /dev/null +++ b/sources/qetgraphicsitem/simpleelement.cpp @@ -0,0 +1,26 @@ +/* + Copyright 2006-2013 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech 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. + + QElectroTech 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "simpleelement.h" + +SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) : + CustomElement(location, qgi, s, state) +{} + +int SimpleElement::linkType() const { + return SimpleElement::simple; +} diff --git a/sources/qetgraphicsitem/simpleelement.h b/sources/qetgraphicsitem/simpleelement.h new file mode 100644 index 000000000..b23cd11d2 --- /dev/null +++ b/sources/qetgraphicsitem/simpleelement.h @@ -0,0 +1,42 @@ +/* + Copyright 2006-2013 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech 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. + + QElectroTech 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef SIMPLEELEMENT_H +#define SIMPLEELEMENT_H + +#include "customelement.h" + +/** + * @brief The SimpleElement class + *this class represente a simple element with no specific attribute + */ +class SimpleElement : public CustomElement { + + Q_OBJECT + + public : + explicit SimpleElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0); + + virtual int linkType() const; + + signals: + + public slots: + +}; + +#endif // SIMPLEELEMENT_H diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index cb34f71a0..a3ef21337 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -14,19 +14,7 @@ elementpropertieswidget::elementpropertieswidget(Element *elmt, QWidget *parent) element_ (elmt), diagram_ (elmt->diagram()) { - setWindowTitle(tr("Propri\351t\351s de l'\351l\351ment")); - - tab_ = new QTabWidget(this); - tab_ -> addTab(generalWidget(), tr("G\351n\351ral")); - - dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, - Qt::Horizontal, this); - connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*))); - - QVBoxLayout *main_layout = new QVBoxLayout(this); - main_layout -> addWidget(tab_); - main_layout -> addWidget(dbb); - setLayout(main_layout); + buildInterface(); } /** @@ -89,6 +77,45 @@ QWidget* elementpropertieswidget::generalWidget() { return general_widget; } +/** + * @brief elementpropertieswidget::buildInterface + *build the interface of this dialog, the main tab can have + *different tab according to the edited element + */ +void elementpropertieswidget::buildInterface() { + + setWindowTitle(tr("Propri\351t\351s de l'\351l\351ment")); + tab_ = new QTabWidget(this); + tab_ -> addTab(generalWidget(), tr("G\351n\351ral")); + + //Add tab according to the element + switch (element_ -> linkType()) { + case Element::simple: + break; + case Element::report: + w = new QComboBox(this); + tab_ -> addTab(w, tr("Report de folio")); + break; + case Element::master: + break; + case Element::slave: + break; + case Element::bornier: + break; + default: + break; + } + + dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, + Qt::Horizontal, this); + connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*))); + + QVBoxLayout *main_layout = new QVBoxLayout(this); + main_layout -> addWidget(tab_); + main_layout -> addWidget(dbb); + setLayout(main_layout); +} + /** * @brief elementpropertieswidget::standardButtonClicked * apply action when click in the dialog standard button box diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index 31a1a00a2..36d29a770 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -13,6 +13,7 @@ class elementpropertieswidget : public QDialog private: QWidget* generalWidget(); + void buildInterface(); signals: /// Signal emitted when users wish to locate an element from the diagram within elements collection @@ -26,6 +27,7 @@ class elementpropertieswidget : public QDialog void editElement (); private: + QWidget *w; ///this widget is only for test QDialogButtonBox *dbb; Element *element_; Diagram *diagram_;