diff --git a/sources/factory/elementfactory.cpp b/sources/factory/elementfactory.cpp index 4ad66ea11..c30188744 100644 --- a/sources/factory/elementfactory.cpp +++ b/sources/factory/elementfactory.cpp @@ -23,6 +23,7 @@ #include "qetgraphicsitem/simpleelement.h" #include "qetgraphicsitem/reportelement.h" #include "qetgraphicsitem/masterelement.h" +#include "qetgraphicsitem/slaveelement.h" ElementFactory* ElementFactory::factory_ = 0; /** @@ -48,6 +49,7 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph QString link_type = element_definition->xml().attribute("link_type"); if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, s, state)); if (link_type == "master") return (new MasterElement(location, qgi, s, state)); + if (link_type == "slave") return (new SlaveElement (location, qgi, s, state)); } //default if nothing match for link_type diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 99bcbfa12..774af3881 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -33,7 +33,7 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) : internal_connections_(false), must_highlight_(false) { - link_type_ = 0; + link_type_ = Simple; uuid_ = QUuid::createUuid(); setZValue(10); } @@ -397,7 +397,9 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool uuid_= QUuid(e.attribute("uuid", QUuid::createUuid().toString())); //load informations - informations_.fromXml(e.firstChildElement("informations"), "information"); + element_informations_.fromXml(e.firstChildElement("elementInformations"), "elementInformation"); + //load kind informations + kind_informations_.fromXml(e.firstChildElement("kindInformations"), "kindInformation"); // position, selection setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble()); @@ -479,9 +481,19 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table } //save information of this element - QDomElement infos = document.createElement("informations"); - informations_.toXml(infos, "information"); - element.appendChild(infos); + if (! element_informations_.keys().isEmpty()) { + QDomElement infos = document.createElement("elementInformations"); + element_informations_.toXml(infos, "elementInformation"); + element.appendChild(infos); + } + + //save kind_informations of this element + if (! kind_informations_.keys().isEmpty()) { + QDomElement kind_infos = document.createElement("kindInformations"); + kind_informations_.toXml(kind_infos, "kindInformation"); + element.appendChild(kind_infos); + } + return(element); } diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index e4192b76d..6c8213065 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -44,15 +44,13 @@ class Element : public QetGraphicsItem { enum { Type = UserType + 1000 }; // this enum is use to know the kind of element and // to use flag for element provider class - enum {Simple = 1, + enum kind {Simple = 1, NextReport = 2, PreviousReport = 4, AllReport = 6, Master = 8, - SlaveNO = 16, - SlaveNC = 32, - AllSlave = 48, - Bornier = 64}; + Slave = 16, + Bornier = 32}; private: QSize dimensions; @@ -115,16 +113,19 @@ class Element : public QetGraphicsItem { QList connected_elements; QList tmp_uuids_link; QUuid uuid_; - int link_type_; + kind link_type_; //METHODS related to information public: - DiagramContext informations()const {return informations_;} - void setInformations(DiagramContext dc) {informations_ = dc;} + DiagramContext elementInformations()const {return element_informations_;} + void setElementInformations(DiagramContext dc) {element_informations_ = dc;} + DiagramContext kindInformations() const {return kind_informations_;} //@kind_information_ is used to store more information + //about the herited class like contactelement for know + // kind of contact (simple tempo) or number of contact show by the element. //ATTRIBUTES protected: - DiagramContext informations_; + DiagramContext element_informations_, kind_informations_; /** Draw this element diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp index 04b0e4350..77db6cc72 100644 --- a/sources/qetgraphicsitem/masterelement.cpp +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -1,3 +1,20 @@ +/* + Copyright 2006-2014 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 "masterelement.h" /** @@ -28,12 +45,9 @@ MasterElement::~MasterElement() { * For this class element must be a slave * @param elmt */ -void MasterElement::linkToElement(Element *elmt) { - // check if this element is already linked - if (connected_elements.contains(elmt)) return; - - //check if elmt is a slave - if (elmt->linkType() == SlaveNO || elmt->linkType() == SlaveNC) { +void MasterElement::linkToElement(Element *elmt) { + // check if element is slave and if isn't already linked + if (elmt->linkType() == Slave && !connected_elements.contains(elmt)) { ///TODO create the cross ref and connection connected_elements << elmt; elmt->linkToElement(this); @@ -49,7 +63,7 @@ void MasterElement::unlinkAllElements() { if (!isFree()) { foreach(Element *elmt, connected_elements) { unlinkElement(elmt); - } + } } } diff --git a/sources/qetgraphicsitem/masterelement.h b/sources/qetgraphicsitem/masterelement.h index eb3f354f3..5217c0466 100644 --- a/sources/qetgraphicsitem/masterelement.h +++ b/sources/qetgraphicsitem/masterelement.h @@ -1,3 +1,20 @@ +/* + Copyright 2006-2014 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 MASTERELEMENT_H #define MASTERELEMENT_H diff --git a/sources/qetgraphicsitem/slaveelement.cpp b/sources/qetgraphicsitem/slaveelement.cpp new file mode 100644 index 000000000..186572c26 --- /dev/null +++ b/sources/qetgraphicsitem/slaveelement.cpp @@ -0,0 +1,81 @@ +/* + Copyright 2006-2014 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 "slaveelement.h" + +/** + * @brief SlaveElement::SlaveElement + * Default constructor + * @param location location of xml definition + * @param qgi parent QGraphicItem + * @param s parent diagram + * @param state int used to know if the creation of element have error + */ +SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) : + CustomElement(location, qgi, s, state) +{ + link_type_ = Slave; +} + +/** + * @brief SlaveElement::~SlaveElement + * default destructor + */ +SlaveElement::~SlaveElement() { + unlinkAllElements(); +} + +/** + * @brief SlaveElement::linkToElement + * Link this slave to another element + * For this class element must be a master + * @param elmt + */ +void SlaveElement::linkToElement(Element *elmt) { + // check if element is master and if isn't already linked + if (elmt->linkType() == Master && !connected_elements.contains(elmt)) { + if(!isFree()) unlinkAllElements(); + connected_elements << elmt; + elmt->linkToElement(this); + } +} + +/** + * @brief SlaveElement::unlinkAllElements + * Unlink all of the element in the QList connected_elements + */ +void SlaveElement::unlinkAllElements() { + // if this element is free no need to do something + if (!isFree()) { + foreach(Element *elmt, connected_elements) { + unlinkElement(elmt); + } + } +} + +/** + * @brief SlaveElement::unlinkElement + * Unlink the given elmt in parametre + * @param elmt + */ +void SlaveElement::unlinkElement(Element *elmt) { + //Ensure elmt is linked to this element + if (connected_elements.contains(elmt)) { + connected_elements.removeOne(elmt); + elmt->unlinkElement(this); + } +} diff --git a/sources/qetgraphicsitem/slaveelement.h b/sources/qetgraphicsitem/slaveelement.h new file mode 100644 index 000000000..1fa0bddd8 --- /dev/null +++ b/sources/qetgraphicsitem/slaveelement.h @@ -0,0 +1,39 @@ +/* + Copyright 2006-2014 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 SLAVEELEMENT_H +#define SLAVEELEMENT_H + +#include "customelement.h" + +class SlaveElement : public CustomElement +{ + Q_OBJECT + public: + explicit SlaveElement (const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0); + ~SlaveElement(); + virtual void linkToElement(Element *elmt); + virtual void unlinkAllElements(); + virtual void unlinkElement(Element *elmt); + + signals: + + public slots: + +}; + +#endif // SLAVEELEMENT_H diff --git a/sources/ui/elementinfowidget.cpp b/sources/ui/elementinfowidget.cpp index 0342c8c7c..1eec80920 100644 --- a/sources/ui/elementinfowidget.cpp +++ b/sources/ui/elementinfowidget.cpp @@ -29,7 +29,7 @@ ElementInfoWidget::ElementInfoWidget(Element *elmt, QWidget *parent) : QWidget(parent), ui(new Ui::ElementInfoWidget), element_(elmt), - elmt_info(elmt->informations()) + elmt_info(elmt->elementInformations()) { ui->setupUi(this); buildInterface(); @@ -59,7 +59,7 @@ void ElementInfoWidget::apply() { eipw->text(), eipw->mustShow()); } - element_->setInformations(dc); + element_->setElementInformations(dc); } /** diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index 6d447ce41..4e26f323e 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -122,14 +122,12 @@ void elementpropertieswidget::buildInterface() { tab_ -> addTab(frp_, tr("Report de folio")); break; case Element::Master: - mpw_ = new MasterPropertiesWidget(this); - tab_ -> addTab(mpw_, tr("R\351f\351rence crois\351 (maitre)")); + mpw_ = new MasterPropertiesWidget(element_, this); + tab_ -> addTab(mpw_, tr("R\351f\351rence crois\351e (maitre)")); eiw_ = new ElementInfoWidget(element_, this); tab_ -> addTab(eiw_, tr("Information")); break; - case Element::SlaveNC: - break; - case Element::SlaveNO: + case Element::Slave: break; case Element::Bornier: break; diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index bbfc333ae..0f8e0014b 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -1,14 +1,70 @@ +/* + Copyright 2006-2014 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 "masterpropertieswidget.h" #include "ui_masterpropertieswidget.h" +#include +#include +#include -MasterPropertiesWidget::MasterPropertiesWidget(QWidget *parent) : +MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) : QWidget(parent), - ui(new Ui::MasterPropertiesWidget) + ui(new Ui::MasterPropertiesWidget), + element_(elmt) { ui->setupUi(this); + buildInterface(); } MasterPropertiesWidget::~MasterPropertiesWidget() { delete ui; } + +void MasterPropertiesWidget::buildInterface() { + ElementProvider elmt_prov(element_->diagram()->project()); + + foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) { + //label for list widget + QString widget_text; + QString title = elmt->diagram()->title(); + if (title.isEmpty()) title = tr("Sans titre"); + widget_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1) + .arg(title) + .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString()); + QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text); + ui->free_list->addItem(lwi_); + } +} + +/** + * @brief MasterPropertiesWidget::on_link_button_clicked + * move curent item in the free_list to linked_list + */ +void MasterPropertiesWidget::on_link_button_clicked() { + //take the curent item from free_list and push it to linked_list + ui->linked_list->addItem( + ui->free_list->takeItem( + ui->free_list->currentRow())); +} + +void MasterPropertiesWidget::on_unlink_button_clicked() { + //take the curent item from linked_list and push it to free_list + ui->free_list->addItem( + ui->linked_list->takeItem( + ui->linked_list->currentRow())); +} diff --git a/sources/ui/masterpropertieswidget.h b/sources/ui/masterpropertieswidget.h index 7d95bb93c..dc5f00b71 100644 --- a/sources/ui/masterpropertieswidget.h +++ b/sources/ui/masterpropertieswidget.h @@ -1,7 +1,25 @@ +/* + Copyright 2006-2014 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 MASTERPROPERTIESWIDGET_H #define MASTERPROPERTIESWIDGET_H #include +#include namespace Ui { class MasterPropertiesWidget; @@ -12,11 +30,19 @@ class MasterPropertiesWidget : public QWidget Q_OBJECT public: - explicit MasterPropertiesWidget(QWidget *parent = 0); + explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0); ~MasterPropertiesWidget(); + private: + void buildInterface(); + + private slots: + void on_link_button_clicked(); + void on_unlink_button_clicked(); + private: Ui::MasterPropertiesWidget *ui; + Element *element_; }; #endif // MASTERPROPERTIESWIDGET_H diff --git a/sources/ui/masterpropertieswidget.ui b/sources/ui/masterpropertieswidget.ui index 2d6a14bbd..2db3032c2 100644 --- a/sources/ui/masterpropertieswidget.ui +++ b/sources/ui/masterpropertieswidget.ui @@ -1,21 +1,103 @@ + - - - MasterPropertiesWidget 0 0 - 400 - 300 + 564 + 318 Form + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Délier l'élément séléctionné + + + + + + + :/ico/16x16/arrow-left.png:/ico/16x16/arrow-left.png + + + + + + + + + + Lier l'élément séléctionné + + + + + + + :/ico/16x16/arrow-right.png:/ico/16x16/arrow-right.png + + + + + + + Éléments disponibles + + + Qt::AlignCenter + + + + + + + Éléments liés + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - + + +