mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
revamp class conductorautonumerotation
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2120 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -1275,7 +1275,7 @@ void Conductor::displayedTextChanged() {
|
|||||||
QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
|
QMessageBox::No| QMessageBox::Yes, QMessageBox::Yes);
|
||||||
if (qmbreturn == QMessageBox::Yes){
|
if (qmbreturn == QMessageBox::Yes){
|
||||||
ConductorAutoNumerotation can(this);
|
ConductorAutoNumerotation can(this);
|
||||||
can.setText(text_item -> toPlainText());
|
can.applyText(text_item -> toPlainText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (qmbreturn == 0 || qmbreturn == QMessageBox::No) {
|
if (qmbreturn == 0 || qmbreturn == QMessageBox::No) {
|
||||||
|
|||||||
@@ -12,8 +12,7 @@
|
|||||||
ConductorAutoNumerotation::ConductorAutoNumerotation() :
|
ConductorAutoNumerotation::ConductorAutoNumerotation() :
|
||||||
conductor_ (0),
|
conductor_ (0),
|
||||||
diagram_ (0),
|
diagram_ (0),
|
||||||
strategy_ (0),
|
strategy_ (0)
|
||||||
strategy_is_set (false)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,11 +23,8 @@ ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) :
|
|||||||
conductor_ (c),
|
conductor_ (c),
|
||||||
diagram_ (c -> diagram()),
|
diagram_ (c -> diagram()),
|
||||||
conductor_list(c -> relatedPotentialConductors()),
|
conductor_list(c -> relatedPotentialConductors()),
|
||||||
strategy_ (0),
|
strategy_ (0)
|
||||||
strategy_is_set (false)
|
{}
|
||||||
{
|
|
||||||
setNumStrategy();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*destructor
|
*destructor
|
||||||
@@ -44,7 +40,6 @@ void ConductorAutoNumerotation::setConductor(Conductor *c) {
|
|||||||
conductor_ = c;
|
conductor_ = c;
|
||||||
diagram_ = c -> diagram();
|
diagram_ = c -> diagram();
|
||||||
conductor_list = c -> relatedPotentialConductors();
|
conductor_list = c -> relatedPotentialConductors();
|
||||||
setNumStrategy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,35 +47,76 @@ void ConductorAutoNumerotation::setConductor(Conductor *c) {
|
|||||||
* execute the automatic numerotation
|
* execute the automatic numerotation
|
||||||
*/
|
*/
|
||||||
void ConductorAutoNumerotation::numerate() {
|
void ConductorAutoNumerotation::numerate() {
|
||||||
if (strategy_is_set)
|
if (!conductor_) return;
|
||||||
strategy_ -> createNumerotation();
|
//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 {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ConductorAutoNumerotation::setText
|
* @brief ConductorAutoNumerotation::setText
|
||||||
* apply the text @t by the strategy
|
* apply the text @t by the strategy
|
||||||
*/
|
*/
|
||||||
void ConductorAutoNumerotation::setText(QString t) {
|
void ConductorAutoNumerotation::applyText(QString t) {
|
||||||
if (strategy_is_set)
|
if (!conductor_) return;
|
||||||
strategy_ -> applyText(t);
|
if (conductor_list.empty()) {
|
||||||
|
//initialize the corresponding UndoCommand object
|
||||||
|
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand (conductor_);
|
||||||
|
ConductorProperties cp;
|
||||||
|
cp = conductor_ ->properties();
|
||||||
|
ccpc -> setOldSettings(cp);
|
||||||
|
cp.text = t;
|
||||||
|
ccpc -> setNewSettings(cp);
|
||||||
|
diagram_ -> undoStack().push(ccpc);
|
||||||
|
conductor_ -> setProperties(cp);
|
||||||
|
conductor_ -> setText(t);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QSet <Conductor *> clist = conductor_list;
|
||||||
|
clist << conductor_;
|
||||||
|
QList <ConductorProperties> old_properties, new_properties;
|
||||||
|
ConductorProperties cp;
|
||||||
|
|
||||||
|
foreach (Conductor *c, clist) {
|
||||||
|
old_properties << c -> properties();
|
||||||
|
cp = c -> properties();
|
||||||
|
cp.text = t;
|
||||||
|
c -> setProperties(cp);
|
||||||
|
new_properties << c -> properties();
|
||||||
|
c -> setText(t);
|
||||||
|
}
|
||||||
|
//initialize the corresponding UndoCommand object
|
||||||
|
ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(clist);
|
||||||
|
cscpc -> setOldSettings(old_properties);
|
||||||
|
cscpc -> setNewSettings(new_properties);
|
||||||
|
diagram_ -> undoStack().push(cscpc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ConductorAutoNumerotation::setNumStrategy
|
* @brief ConductorAutoNumerotation::setNumStrategy
|
||||||
* apply the good strategy relative to the conductor
|
* apply the good strategy relative to the conductor
|
||||||
*/
|
*/
|
||||||
void ConductorAutoNumerotation::setNumStrategy() {
|
void ConductorAutoNumerotation::setNumStrategy() {}
|
||||||
if (strategy_ != 0)
|
|
||||||
delete strategy_;
|
|
||||||
|
|
||||||
if (conductor_list.size() >= 1) {
|
|
||||||
strategy_ = new SamePotential (conductor_);
|
|
||||||
strategy_is_set = true;
|
|
||||||
}
|
|
||||||
else if (conductor_list.size() == 0) {
|
|
||||||
strategy_is_set = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,76 +144,6 @@ NumStrategy::NumStrategy (Conductor *c):
|
|||||||
|
|
||||||
NumStrategy::~NumStrategy() {}
|
NumStrategy::~NumStrategy() {}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ConductorAutoNumerotationWidget::applyText
|
|
||||||
*apply the text @t on every conductors of @c_list and @conductor_
|
|
||||||
*/
|
|
||||||
void NumStrategy::applyText(QString t) {
|
|
||||||
if (!c_list.empty()) {
|
|
||||||
QSet <Conductor *> conductorslist = c_list;
|
|
||||||
conductorslist << conductor_;
|
|
||||||
QList <ConductorProperties> old_properties, new_properties;
|
|
||||||
ConductorProperties cp;
|
|
||||||
|
|
||||||
foreach (Conductor *c, conductorslist) {
|
|
||||||
old_properties << c -> properties();
|
|
||||||
cp = c -> properties();
|
|
||||||
cp.text = t;
|
|
||||||
c -> setProperties(cp);
|
|
||||||
new_properties << c -> properties();
|
|
||||||
c -> setText(t);
|
|
||||||
}
|
|
||||||
//initialize the corresponding UndoCommand object
|
|
||||||
ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(conductorslist);
|
|
||||||
cscpc -> setOldSettings(old_properties);
|
|
||||||
cscpc -> setNewSettings(new_properties);
|
|
||||||
diagram_ -> undoStack().push(cscpc);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//initialize the corresponding UndoCommand object
|
|
||||||
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand (conductor_);
|
|
||||||
ConductorProperties cp;
|
|
||||||
cp = conductor_ ->properties();
|
|
||||||
ccpc -> setOldSettings(cp);
|
|
||||||
cp.text = t;
|
|
||||||
ccpc -> setNewSettings(cp);
|
|
||||||
diagram_ -> undoStack().push(ccpc);
|
|
||||||
conductor_ -> setProperties(cp);
|
|
||||||
conductor_ -> setText(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*/
|
|
||||||
SamePotential::SamePotential(Conductor *c):
|
|
||||||
NumStrategy(c)
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief SamePotential::createNumerotation
|
|
||||||
*create the numerotation for the conductor @c connected on an existing potential
|
|
||||||
*/
|
|
||||||
void SamePotential::createNumerotation() {
|
|
||||||
QStringList strl;
|
|
||||||
|
|
||||||
foreach (const Conductor *cc, c_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_, c_list, conductor_ -> diagramEditor());
|
|
||||||
connect(canw, SIGNAL(textIsSelected(QString)),
|
|
||||||
this, SLOT(applyText(QString)));
|
|
||||||
canw -> exec();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if every text of qsl is identical, else false.
|
* @return true if every text of qsl is identical, else false.
|
||||||
|
|||||||
@@ -7,8 +7,10 @@
|
|||||||
|
|
||||||
class NumStrategy;
|
class NumStrategy;
|
||||||
|
|
||||||
class ConductorAutoNumerotation
|
class ConductorAutoNumerotation: public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//constructors & destructor
|
//constructors & destructor
|
||||||
ConductorAutoNumerotation ();
|
ConductorAutoNumerotation ();
|
||||||
@@ -18,9 +20,12 @@ class ConductorAutoNumerotation
|
|||||||
//methods
|
//methods
|
||||||
void setConductor(Conductor *);
|
void setConductor(Conductor *);
|
||||||
void numerate();
|
void numerate();
|
||||||
void setText(QString);
|
|
||||||
void removeNum_ofDiagram(Diagram *);
|
void removeNum_ofDiagram(Diagram *);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void applyText(QString);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//methods
|
//methods
|
||||||
void setNumStrategy ();
|
void setNumStrategy ();
|
||||||
@@ -30,9 +35,6 @@ class ConductorAutoNumerotation
|
|||||||
Diagram *diagram_;
|
Diagram *diagram_;
|
||||||
QSet <Conductor *> conductor_list;
|
QSet <Conductor *> conductor_list;
|
||||||
NumStrategy *strategy_;
|
NumStrategy *strategy_;
|
||||||
|
|
||||||
private:
|
|
||||||
bool strategy_is_set;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -45,9 +47,6 @@ class NumStrategy: public QObject
|
|||||||
virtual ~NumStrategy ();
|
virtual ~NumStrategy ();
|
||||||
virtual void createNumerotation() = 0; //cree la numerotation en fonction de la strategie utilisé
|
virtual void createNumerotation() = 0; //cree la numerotation en fonction de la strategie utilisé
|
||||||
|
|
||||||
public slots:
|
|
||||||
void applyText(QString);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Conductor *conductor_;
|
Conductor *conductor_;
|
||||||
QSet <Conductor *> c_list;
|
QSet <Conductor *> c_list;
|
||||||
@@ -55,14 +54,6 @@ class NumStrategy: public QObject
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class SamePotential: public NumStrategy
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SamePotential (Conductor *);
|
|
||||||
virtual void createNumerotation();
|
|
||||||
};
|
|
||||||
|
|
||||||
bool eachIsEqual (const QStringList &);
|
bool eachIsEqual (const QStringList &);
|
||||||
|
|
||||||
#endif // CONDUCTORAUTONUMEROTATION_H
|
#endif // CONDUCTORAUTONUMEROTATION_H
|
||||||
|
|||||||
Reference in New Issue
Block a user