mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 01:10:53 +01:00
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:
5
sources/autonumerotation.cpp
Normal file
5
sources/autonumerotation.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "autonumerotation.h"
|
||||
|
||||
AutoNumerotation::AutoNumerotation(Diagram *d):
|
||||
diagram_ (d)
|
||||
{}
|
||||
22
sources/autonumerotation.h
Normal file
22
sources/autonumerotation.h
Normal 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
|
||||
@@ -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 "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));
|
||||
if (conductor_list.size() >= 1 ) numeratePotential();
|
||||
else numerateNewConductor();
|
||||
}
|
||||
//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 {
|
||||
|
||||
/**
|
||||
* @brief ConductorAutoNumerotation::numerateDiagram
|
||||
* Numerate all conductor in diagram
|
||||
*/
|
||||
void ConductorAutoNumerotation::numerateDiagram() {
|
||||
if (!diagram_) return;
|
||||
//Get all potentials presents in diagram
|
||||
QList <QSet <Conductor *> > 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 <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):
|
||||
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.
|
||||
|
||||
@@ -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
|
||||
#define CONDUCTORAUTONUMEROTATION_H
|
||||
|
||||
#include <QObject>
|
||||
#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 *> 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 &);
|
||||
|
||||
@@ -68,7 +68,7 @@ void DialogConductorAutoNum::on_pushButton_delete_clicked() {
|
||||
if( answer == QMessageBox::Yes) {
|
||||
for(int i=0; i<listDiag.count(); i++){
|
||||
ConductorAutoNumerotation can(listDiag.at(i));
|
||||
can.removeNum_ofDiagram();
|
||||
can.removeNumOfDiagram();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user