From 4a07e5e38cb31097f965863f1fec3587a811d7d2 Mon Sep 17 00:00:00 2001 From: blacksun Date: Fri, 3 May 2013 17:35:22 +0000 Subject: [PATCH] revamp conductorautonumerotation and add autonumerotation class git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2142 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/autonumerotation.cpp | 5 + sources/autonumerotation.h | 22 ++++ sources/conductorautonumerotation.cpp | 146 ++++++++++++++------------ sources/conductorautonumerotation.h | 57 +++++----- sources/ui/dialogconductorautonum.cpp | 2 +- 5 files changed, 130 insertions(+), 102 deletions(-) create mode 100644 sources/autonumerotation.cpp create mode 100644 sources/autonumerotation.h diff --git a/sources/autonumerotation.cpp b/sources/autonumerotation.cpp new file mode 100644 index 000000000..9b593c789 --- /dev/null +++ b/sources/autonumerotation.cpp @@ -0,0 +1,5 @@ +#include "autonumerotation.h" + +AutoNumerotation::AutoNumerotation(Diagram *d): + diagram_ (d) +{} diff --git a/sources/autonumerotation.h b/sources/autonumerotation.h new file mode 100644 index 000000000..c90ee971e --- /dev/null +++ b/sources/autonumerotation.h @@ -0,0 +1,22 @@ +#ifndef AUTONUMEROTATION_H +#define AUTONUMEROTATION_H + +#include "diagram.h" + +class AutoNumerotation: public QObject +{ + Q_OBJECT + + public: + AutoNumerotation(Diagram *); + virtual void numerate() = 0; + + public slots: + virtual void applyText(QString) = 0; + + protected: + Diagram *diagram_; + NumerotationContext num_context; +}; + +#endif // AUTONUMEROTATION_H diff --git a/sources/conductorautonumerotation.cpp b/sources/conductorautonumerotation.cpp index 9d6e114e1..90d4e1b9e 100644 --- a/sources/conductorautonumerotation.cpp +++ b/sources/conductorautonumerotation.cpp @@ -1,48 +1,46 @@ -#include +/* + 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 "conductorautonumerotation.h" #include "conductorautonumerotationwidget.h" -#include "qetdiagrameditor.h" -#include "QGraphicsView" #include "diagramcommands.h" -#include "qetapp.h" - -/** - * Constructor - */ -ConductorAutoNumerotation::ConductorAutoNumerotation() : -conductor_ (0), -diagram_ (0), -strategy_ (0) -{} +#include "numerotationcontextcommands.h" /** *Constructor * @param c the conductor to apply automatic numerotation */ ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) : + AutoNumerotation (c -> diagram()), conductor_ (c), - diagram_ (c -> diagram()), - conductor_list(c -> relatedPotentialConductors()), - strategy_ (0) -{} + conductor_list(c -> relatedPotentialConductors()) +{ + num_context = diagram_ -> getNumerotation(Diagram::Conductors); +} /** * Constructor * @param d a diagram to apply automatic numerotation */ ConductorAutoNumerotation::ConductorAutoNumerotation(Diagram *d) : - conductor_ (0), - diagram_ (d), - strategy_ (0) + AutoNumerotation (d), + conductor_ (NULL) {} -/** - *destructor - */ -ConductorAutoNumerotation::~ConductorAutoNumerotation() { - delete strategy_; -} - /** * @param c the conductor to apply automatic numerotation */ @@ -50,7 +48,7 @@ void ConductorAutoNumerotation::setConductor(Conductor *c) { conductor_ = c; diagram_ = c -> diagram(); conductor_list = c -> relatedPotentialConductors(); - if (strategy_) delete strategy_; + num_context = diagram_ -> getNumerotation(Diagram::Conductors); } /** @@ -59,33 +57,30 @@ void ConductorAutoNumerotation::setConductor(Conductor *c) { */ void ConductorAutoNumerotation::numerate() { if (!conductor_) return; - //conductor is on an existing potential - if (conductor_list.size() >= 1 ) { - QStringList strl; - foreach (const Conductor *cc, conductor_list) strl<<(cc->text()); - //the texts is identicals - if (eachIsEqual(strl)) { - ConductorProperties cp; - cp.text = strl.at(0); - conductor_ -> setProperties(cp); - conductor_ -> setText(strl.at(0)); - } - //the texts isn't identicals - else { - ConductorAutoNumerotationWidget *canw = new ConductorAutoNumerotationWidget(conductor_, conductor_list, conductor_ -> diagramEditor()); - connect(canw, SIGNAL(textIsSelected(QString)), - this, SLOT(applyText(QString))); - canw -> exec(); - } - } - //conductor create a new potential - else { + if (conductor_list.size() >= 1 ) numeratePotential(); + else numerateNewConductor(); +} + +/** + * @brief ConductorAutoNumerotation::numerateDiagram + * Numerate all conductor in diagram + */ +void ConductorAutoNumerotation::numerateDiagram() { + if (!diagram_) return; + //Get all potentials presents in diagram + QList > potential_list = diagram_ -> potentials(); + //Browse all potentials and set new numerotation + for (int i=0; i < potential_list.size(); ++i) { + setConductor (potential_list.at(i).toList().first()); + NumerotationContextCommands ncc(diagram_, num_context); + applyText(ncc.toRepresentedString()); + diagram_ -> setNumerotation(Diagram::Conductors, ncc.next()); } } /** - * @brief ConductorAutoNumerotation::setText - * apply the text @t by the strategy + * @brief ConductorAutoNumerotation::applyText + * apply the text @t to @conductor_ and all conductors at the same potential */ void ConductorAutoNumerotation::applyText(QString t) { if (!conductor_) return; @@ -118,18 +113,10 @@ void ConductorAutoNumerotation::applyText(QString t) { } } -/** - * @brief ConductorAutoNumerotation::setNumStrategy - * apply the good strategy relative to the conductor - */ -void ConductorAutoNumerotation::setNumStrategy() {} - - /** * @brief Set the default text to all potentials of the diagram - * @param dg the diagram */ -void ConductorAutoNumerotation::removeNum_ofDiagram() { +void ConductorAutoNumerotation::removeNumOfDiagram() { if (!diagram_) return; //Get all potentials presents in diagram QList > potential_list = diagram_ -> potentials(); @@ -140,18 +127,39 @@ void ConductorAutoNumerotation::removeNum_ofDiagram() { } } +/** + * @brief ConductorAutoNumerotation::numeratePotential + * Numerate a conductor on an existing potential + */ +void ConductorAutoNumerotation::numeratePotential() { + QStringList strl; + foreach (const Conductor *cc, conductor_list) strl<<(cc->text()); + //the texts is identicals + if (eachIsEqual(strl)) { + ConductorProperties cp; + cp.text = strl.at(0); + conductor_ -> setProperties(cp); + conductor_ -> setText(strl.at(0)); + } + //the texts isn't identicals + else { + ConductorAutoNumerotationWidget *canw = new ConductorAutoNumerotationWidget(conductor_, conductor_list, conductor_ -> diagramEditor()); + connect(canw, SIGNAL(textIsSelected(QString)), + this, SLOT(applyText(QString))); + canw -> exec(); + } +} /** - * Constructor + * @brief ConductorAutoNumerotation::numerateNewConductor + * create and apply a new numerotation to @conductor_ */ -NumStrategy::NumStrategy (Conductor *c): - conductor_ (c), - c_list (c -> relatedPotentialConductors()), - diagram_ (c -> diagram()) -{} - -NumStrategy::~NumStrategy() {} - +void ConductorAutoNumerotation::numerateNewConductor() { + if (!conductor_) return; + NumerotationContextCommands ncc (diagram_, num_context); + applyText(ncc.toRepresentedString()); + diagram_-> setNumerotation(Diagram::Conductors, ncc.next()); +} /** * @return true if every text of qsl is identical, else false. diff --git a/sources/conductorautonumerotation.h b/sources/conductorautonumerotation.h index ae7011ad3..fcc44f075 100644 --- a/sources/conductorautonumerotation.h +++ b/sources/conductorautonumerotation.h @@ -1,58 +1,51 @@ +/* + 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 CONDUCTORAUTONUMEROTATION_H #define CONDUCTORAUTONUMEROTATION_H -#include #include "conductor.h" -#include "diagram.h" +#include "numerotationcontext.h" +#include "autonumerotation.h" -class NumStrategy; - -class ConductorAutoNumerotation: public QObject +class ConductorAutoNumerotation: public AutoNumerotation { - Q_OBJECT - public: //constructors & destructor - ConductorAutoNumerotation (); ConductorAutoNumerotation (Conductor *); ConductorAutoNumerotation (Diagram *); - ~ConductorAutoNumerotation(); //methods void setConductor(Conductor *); void numerate(); - void removeNum_ofDiagram(); + void numerateDiagram(); + void removeNumOfDiagram(); public slots: void applyText(QString); - - protected: + private: //methods - void setNumStrategy (); + void numeratePotential (); + void numerateNewConductor (); //attributes Conductor *conductor_; - Diagram *diagram_; QSet conductor_list; - NumStrategy *strategy_; -}; - - -class NumStrategy: public QObject -{ - Q_OBJECT - - public: - NumStrategy (Conductor *); - virtual ~NumStrategy (); - virtual void createNumerotation() = 0; //cree la numerotation en fonction de la strategie utilisé - - protected: - Conductor *conductor_; - QSet c_list; - Diagram *diagram_; - }; bool eachIsEqual (const QStringList &); diff --git a/sources/ui/dialogconductorautonum.cpp b/sources/ui/dialogconductorautonum.cpp index 8df80d328..1aef1fba4 100644 --- a/sources/ui/dialogconductorautonum.cpp +++ b/sources/ui/dialogconductorautonum.cpp @@ -68,7 +68,7 @@ void DialogConductorAutoNum::on_pushButton_delete_clicked() { if( answer == QMessageBox::Yes) { for(int i=0; i