2013-04-04 16:57:15 +00:00
|
|
|
#include <QStringList>
|
|
|
|
#include "conductorautonumerotation.h"
|
|
|
|
#include "conductorautonumerotationwidget.h"
|
|
|
|
#include "qetdiagrameditor.h"
|
|
|
|
#include "QGraphicsView"
|
2013-04-10 19:35:47 +00:00
|
|
|
#include "diagramcommands.h"
|
2013-04-18 08:00:09 +00:00
|
|
|
#include "qetapp.h"
|
2013-04-04 16:57:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
ConductorAutoNumerotation::ConductorAutoNumerotation() :
|
|
|
|
conductor_ (0),
|
|
|
|
diagram_ (0),
|
2013-04-19 13:22:30 +00:00
|
|
|
strategy_ (0)
|
2013-04-04 16:57:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*Constructor
|
2013-04-10 19:35:47 +00:00
|
|
|
* @param c the conductor to apply automatic numerotation
|
2013-04-04 16:57:15 +00:00
|
|
|
*/
|
|
|
|
ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *c) :
|
|
|
|
conductor_ (c),
|
|
|
|
diagram_ (c -> diagram()),
|
2013-04-05 16:03:05 +00:00
|
|
|
conductor_list(c -> relatedPotentialConductors()),
|
2013-04-19 13:22:30 +00:00
|
|
|
strategy_ (0)
|
|
|
|
{}
|
2013-04-04 16:57:15 +00:00
|
|
|
|
2013-04-19 14:59:20 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param d a diagram to apply automatic numerotation
|
|
|
|
*/
|
|
|
|
ConductorAutoNumerotation::ConductorAutoNumerotation(Diagram *d) :
|
|
|
|
conductor_ (0),
|
|
|
|
diagram_ (d),
|
|
|
|
strategy_ (0)
|
|
|
|
{}
|
|
|
|
|
2013-04-04 16:57:15 +00:00
|
|
|
/**
|
|
|
|
*destructor
|
|
|
|
*/
|
|
|
|
ConductorAutoNumerotation::~ConductorAutoNumerotation() {
|
|
|
|
delete strategy_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-10 19:35:47 +00:00
|
|
|
* @param c the conductor to apply automatic numerotation
|
2013-04-04 16:57:15 +00:00
|
|
|
*/
|
|
|
|
void ConductorAutoNumerotation::setConductor(Conductor *c) {
|
|
|
|
conductor_ = c;
|
|
|
|
diagram_ = c -> diagram();
|
|
|
|
conductor_list = c -> relatedPotentialConductors();
|
2013-04-21 13:55:51 +00:00
|
|
|
if (strategy_) delete strategy_;
|
2013-04-04 16:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConductorAutoNumerotation::numerate
|
2013-04-10 19:35:47 +00:00
|
|
|
* execute the automatic numerotation
|
2013-04-04 16:57:15 +00:00
|
|
|
*/
|
|
|
|
void ConductorAutoNumerotation::numerate() {
|
2013-04-19 13:22:30 +00:00
|
|
|
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 {
|
|
|
|
}
|
2013-04-10 19:35:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConductorAutoNumerotation::setText
|
|
|
|
* apply the text @t by the strategy
|
|
|
|
*/
|
2013-04-19 13:22:30 +00:00
|
|
|
void ConductorAutoNumerotation::applyText(QString t) {
|
|
|
|
if (!conductor_) return;
|
|
|
|
if (conductor_list.empty()) {
|
|
|
|
//initialize the corresponding UndoCommand object
|
|
|
|
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand (conductor_);
|
2013-04-25 22:32:29 +00:00
|
|
|
ccpc -> setOldSettings (conductor_ -> properties());
|
|
|
|
ConductorProperties cp = conductor_ -> properties();
|
2013-04-19 13:22:30 +00:00
|
|
|
cp.text = t;
|
|
|
|
ccpc -> setNewSettings(cp);
|
|
|
|
diagram_ -> undoStack().push(ccpc);
|
|
|
|
}
|
|
|
|
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;
|
2013-04-25 22:32:29 +00:00
|
|
|
new_properties << cp;
|
2013-04-19 13:22:30 +00:00
|
|
|
}
|
|
|
|
//initialize the corresponding UndoCommand object
|
|
|
|
ChangeSeveralConductorsPropertiesCommand *cscpc = new ChangeSeveralConductorsPropertiesCommand(clist);
|
|
|
|
cscpc -> setOldSettings(old_properties);
|
|
|
|
cscpc -> setNewSettings(new_properties);
|
|
|
|
diagram_ -> undoStack().push(cscpc);
|
|
|
|
}
|
2013-04-04 16:57:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 09:31:51 +00:00
|
|
|
/**
|
2013-04-10 11:10:02 +00:00
|
|
|
* @brief ConductorAutoNumerotation::setNumStrategy
|
2013-04-10 19:35:47 +00:00
|
|
|
* apply the good strategy relative to the conductor
|
2013-04-10 09:31:51 +00:00
|
|
|
*/
|
2013-04-19 13:22:30 +00:00
|
|
|
void ConductorAutoNumerotation::setNumStrategy() {}
|
2013-04-10 09:31:51 +00:00
|
|
|
|
2013-04-10 19:35:47 +00:00
|
|
|
|
2013-04-18 08:00:09 +00:00
|
|
|
/**
|
2013-04-19 14:59:20 +00:00
|
|
|
* @brief Set the default text to all potentials of the diagram
|
2013-04-18 15:53:06 +00:00
|
|
|
* @param dg the diagram
|
2013-04-18 08:00:09 +00:00
|
|
|
*/
|
2013-04-19 14:59:20 +00:00
|
|
|
void ConductorAutoNumerotation::removeNum_ofDiagram() {
|
|
|
|
if (!diagram_) return;
|
|
|
|
//Get all potentials presents in diagram
|
|
|
|
QList <QSet <Conductor *> > potential_list = diagram_ -> potentials();
|
|
|
|
//Browse all potentials and set the default text
|
|
|
|
for (int i=0; i < potential_list.size(); i++) {
|
2013-04-21 13:55:51 +00:00
|
|
|
setConductor (potential_list.at(i).toList().first());
|
|
|
|
applyText (diagram_ -> defaultConductorProperties.text);
|
2013-04-18 08:00:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-10 19:35:47 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
NumStrategy::NumStrategy (Conductor *c):
|
|
|
|
conductor_ (c),
|
|
|
|
c_list (c -> relatedPotentialConductors()),
|
|
|
|
diagram_ (c -> diagram())
|
|
|
|
{}
|
|
|
|
|
2013-04-10 11:10:02 +00:00
|
|
|
NumStrategy::~NumStrategy() {}
|
2013-04-10 09:31:51 +00:00
|
|
|
|
2013-04-04 16:57:15 +00:00
|
|
|
|
2013-04-10 19:35:47 +00:00
|
|
|
/**
|
|
|
|
* @return true if every text of qsl is identical, else false.
|
|
|
|
*/
|
2013-04-04 16:57:15 +00:00
|
|
|
bool eachIsEqual (const QStringList &qsl) {
|
|
|
|
foreach (const QString t, qsl) {
|
|
|
|
if (qsl.at(0) != t) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|