revamp conductorautonumerotation and add autonumerotation class

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2142 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2013-05-03 17:35:22 +00:00
parent b681d27473
commit 4a07e5e38c
5 changed files with 130 additions and 102 deletions

View File

@@ -0,0 +1,5 @@
#include "autonumerotation.h"
AutoNumerotation::AutoNumerotation(Diagram *d):
diagram_ (d)
{}

View File

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

View File

@@ -1,48 +1,46 @@
#include <QStringList> /*
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 <http://www.gnu.org/licenses/>.
*/
#include "conductorautonumerotation.h" #include "conductorautonumerotation.h"
#include "conductorautonumerotationwidget.h" #include "conductorautonumerotationwidget.h"
#include "qetdiagrameditor.h"
#include "QGraphicsView"
#include "diagramcommands.h" #include "diagramcommands.h"
#include "qetapp.h" #include "numerotationcontextcommands.h"
/**
* Constructor
*/
ConductorAutoNumerotation::ConductorAutoNumerotation() :
conductor_ (0),
diagram_ (0),
strategy_ (0)
{}
/** /**
*Constructor *Constructor
* @param c the conductor to apply automatic numerotation * @param c the conductor to apply automatic numerotation
*/ */
ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) : ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) :
AutoNumerotation (c -> diagram()),
conductor_ (c), conductor_ (c),
diagram_ (c -> diagram()), conductor_list(c -> relatedPotentialConductors())
conductor_list(c -> relatedPotentialConductors()), {
strategy_ (0) num_context = diagram_ -> getNumerotation(Diagram::Conductors);
{} }
/** /**
* Constructor * Constructor
* @param d a diagram to apply automatic numerotation * @param d a diagram to apply automatic numerotation
*/ */
ConductorAutoNumerotation::ConductorAutoNumerotation(Diagram *d) : ConductorAutoNumerotation::ConductorAutoNumerotation(Diagram *d) :
conductor_ (0), AutoNumerotation (d),
diagram_ (d), conductor_ (NULL)
strategy_ (0)
{} {}
/**
*destructor
*/
ConductorAutoNumerotation::~ConductorAutoNumerotation() {
delete strategy_;
}
/** /**
* @param c the conductor to apply automatic numerotation * @param c the conductor to apply automatic numerotation
*/ */
@@ -50,7 +48,7 @@ void ConductorAutoNumerotation::setConductor(Conductor *c) {
conductor_ = c; conductor_ = c;
diagram_ = c -> diagram(); diagram_ = c -> diagram();
conductor_list = c -> relatedPotentialConductors(); 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() { void ConductorAutoNumerotation::numerate() {
if (!conductor_) return; if (!conductor_) return;
//conductor is on an existing potential if (conductor_list.size() >= 1 ) numeratePotential();
if (conductor_list.size() >= 1 ) { else numerateNewConductor();
QStringList strl; }
foreach (const Conductor *cc, conductor_list) strl<<(cc->text());
//the texts is identicals /**
if (eachIsEqual(strl)) { * @brief ConductorAutoNumerotation::numerateDiagram
ConductorProperties cp; * Numerate all conductor in diagram
cp.text = strl.at(0); */
conductor_ -> setProperties(cp); void ConductorAutoNumerotation::numerateDiagram() {
conductor_ -> setText(strl.at(0)); if (!diagram_) return;
} //Get all potentials presents in diagram
//the texts isn't identicals QList <QSet <Conductor *> > potential_list = diagram_ -> potentials();
else { //Browse all potentials and set new numerotation
ConductorAutoNumerotationWidget *canw = new ConductorAutoNumerotationWidget(conductor_, conductor_list, conductor_ -> diagramEditor()); for (int i=0; i < potential_list.size(); ++i) {
connect(canw, SIGNAL(textIsSelected(QString)), setConductor (potential_list.at(i).toList().first());
this, SLOT(applyText(QString))); NumerotationContextCommands ncc(diagram_, num_context);
canw -> exec(); applyText(ncc.toRepresentedString());
} diagram_ -> setNumerotation(Diagram::Conductors, ncc.next());
}
//conductor create a new potential
else {
} }
} }
/** /**
* @brief ConductorAutoNumerotation::setText * @brief ConductorAutoNumerotation::applyText
* apply the text @t by the strategy * apply the text @t to @conductor_ and all conductors at the same potential
*/ */
void ConductorAutoNumerotation::applyText(QString t) { void ConductorAutoNumerotation::applyText(QString t) {
if (!conductor_) return; 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 * @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; if (!diagram_) return;
//Get all potentials presents in diagram //Get all potentials presents in diagram
QList <QSet <Conductor *> > potential_list = diagram_ -> potentials(); QList <QSet <Conductor *> > 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): void ConductorAutoNumerotation::numerateNewConductor() {
conductor_ (c), if (!conductor_) return;
c_list (c -> relatedPotentialConductors()), NumerotationContextCommands ncc (diagram_, num_context);
diagram_ (c -> diagram()) applyText(ncc.toRepresentedString());
{} diagram_-> setNumerotation(Diagram::Conductors, ncc.next());
}
NumStrategy::~NumStrategy() {}
/** /**
* @return true if every text of qsl is identical, else false. * @return true if every text of qsl is identical, else false.

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef CONDUCTORAUTONUMEROTATION_H #ifndef CONDUCTORAUTONUMEROTATION_H
#define CONDUCTORAUTONUMEROTATION_H #define CONDUCTORAUTONUMEROTATION_H
#include <QObject>
#include "conductor.h" #include "conductor.h"
#include "diagram.h" #include "numerotationcontext.h"
#include "autonumerotation.h"
class NumStrategy; class ConductorAutoNumerotation: public AutoNumerotation
class ConductorAutoNumerotation: public QObject
{ {
Q_OBJECT
public: public:
//constructors & destructor //constructors & destructor
ConductorAutoNumerotation ();
ConductorAutoNumerotation (Conductor *); ConductorAutoNumerotation (Conductor *);
ConductorAutoNumerotation (Diagram *); ConductorAutoNumerotation (Diagram *);
~ConductorAutoNumerotation();
//methods //methods
void setConductor(Conductor *); void setConductor(Conductor *);
void numerate(); void numerate();
void removeNum_ofDiagram(); void numerateDiagram();
void removeNumOfDiagram();
public slots: public slots:
void applyText(QString); void applyText(QString);
private:
protected:
//methods //methods
void setNumStrategy (); void numeratePotential ();
void numerateNewConductor ();
//attributes //attributes
Conductor *conductor_; Conductor *conductor_;
Diagram *diagram_;
QSet <Conductor *> conductor_list; QSet <Conductor *> 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 <Conductor *> c_list;
Diagram *diagram_;
}; };
bool eachIsEqual (const QStringList &); bool eachIsEqual (const QStringList &);

View File

@@ -68,7 +68,7 @@ void DialogConductorAutoNum::on_pushButton_delete_clicked() {
if( answer == QMessageBox::Yes) { if( answer == QMessageBox::Yes) {
for(int i=0; i<listDiag.count(); i++){ for(int i=0; i<listDiag.count(); i++){
ConductorAutoNumerotation can(listDiag.at(i)); ConductorAutoNumerotation can(listDiag.at(i));
can.removeNum_ofDiagram(); can.removeNumOfDiagram();
} }
} }
} }