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-10 19:35:47 +00:00
|
|
|
strategy_ (0),
|
|
|
|
strategy_is_set (false)
|
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-10 19:35:47 +00:00
|
|
|
strategy_ (0),
|
|
|
|
strategy_is_set (false)
|
|
|
|
{
|
|
|
|
setNumStrategy();
|
|
|
|
}
|
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-10 19:35:47 +00:00
|
|
|
setNumStrategy();
|
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-10 19:35:47 +00:00
|
|
|
if (strategy_is_set)
|
|
|
|
strategy_ -> createNumerotation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ConductorAutoNumerotation::setText
|
|
|
|
* apply the text @t by the strategy
|
|
|
|
*/
|
|
|
|
void ConductorAutoNumerotation::setText(QString t) {
|
|
|
|
if (strategy_is_set)
|
|
|
|
strategy_ -> applyText(t);
|
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-10 19:35:47 +00:00
|
|
|
void ConductorAutoNumerotation::setNumStrategy() {
|
2013-04-10 11:10:02 +00:00
|
|
|
if (strategy_ != 0)
|
|
|
|
delete strategy_;
|
2013-04-10 19:35:47 +00:00
|
|
|
|
|
|
|
if (conductor_list.size() >= 1) {
|
|
|
|
strategy_ = new SamePotential (conductor_);
|
|
|
|
strategy_is_set = true;
|
|
|
|
}
|
|
|
|
else if (conductor_list.size() == 0) {
|
|
|
|
strategy_is_set = false;
|
|
|
|
}
|
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-18 15:53:06 +00:00
|
|
|
* @brief Set the default text to all conductors of the diagram
|
|
|
|
* @param dg the diagram
|
2013-04-18 08:00:09 +00:00
|
|
|
*/
|
|
|
|
void ConductorAutoNumerotation::removeNum_ofDiagram(Diagram *dg) {
|
|
|
|
// Get all conductors presents in diagram
|
|
|
|
QList<Conductor *> Conductors = dg -> content().conductors();
|
|
|
|
// Browse all conductors and set the default value
|
|
|
|
for (int i=0; i<Conductors.count(); i++) {
|
2013-04-18 15:53:06 +00:00
|
|
|
Conductors.at(i) -> setText( dg ->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-10 19:35:47 +00:00
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
{}
|
|
|
|
|
2013-04-04 16:57:15 +00:00
|
|
|
/**
|
|
|
|
* @brief SamePotential::createNumerotation
|
2013-04-10 19:35:47 +00:00
|
|
|
*create the numerotation for the conductor @c connected on an existing potential
|
2013-04-04 16:57:15 +00:00
|
|
|
*/
|
2013-04-10 19:35:47 +00:00
|
|
|
void SamePotential::createNumerotation() {
|
2013-04-04 16:57:15 +00:00
|
|
|
QStringList strl;
|
|
|
|
|
2013-04-10 19:35:47 +00:00
|
|
|
foreach (const Conductor *cc, c_list) strl<<(cc->text());
|
|
|
|
//the texts is identicals
|
2013-04-04 16:57:15 +00:00
|
|
|
if (eachIsEqual(strl)) {
|
|
|
|
ConductorProperties cp;
|
|
|
|
cp.text = strl.at(0);
|
2013-04-10 19:35:47 +00:00
|
|
|
conductor_ -> setProperties(cp);
|
|
|
|
conductor_ -> setText(strl.at(0));
|
2013-04-04 16:57:15 +00:00
|
|
|
}
|
2013-04-10 19:35:47 +00:00
|
|
|
//the texts isn't identicals
|
2013-04-04 16:57:15 +00:00
|
|
|
else {
|
2013-04-10 19:35:47 +00:00
|
|
|
ConductorAutoNumerotationWidget *canw = new ConductorAutoNumerotationWidget(conductor_, c_list, conductor_ -> diagramEditor());
|
|
|
|
connect(canw, SIGNAL(textIsSelected(QString)),
|
|
|
|
this, SLOT(applyText(QString)));
|
|
|
|
canw -> exec();
|
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;
|
|
|
|
}
|