QElectroTech  0.70
conductorautonumerotation.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2014 The QElectroTech team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
20 #include "qetdiagrameditor.h"
21 #include "conductor.h"
22 #include "diagram.h"
23 #include "qet.h"
26 #include "assignvariables.h"
27 
38 ConductorAutoNumerotation::ConductorAutoNumerotation(Conductor *conductor, Diagram *diagram, QUndoCommand *parent_undo) :
39  m_diagram (diagram),
40  m_conductor (conductor),
41  conductor_list (conductor -> relatedPotentialConductors().toList()),
42  m_parent_undo (parent_undo)
43 {}
44 
50  if (!m_conductor) return;
51  if (conductor_list.size() >= 1 ) numeratePotential();
52  else if (m_conductor -> properties().type == ConductorProperties::Multi) numerateNewConductor();
53 }
54 
60 {
61  if (!m_conductor) return;
62 
63  QVariant old_value, new_value;
64  ConductorProperties cp = m_conductor -> properties();
65  old_value.setValue(cp);
66  cp.text = t;
67  new_value.setValue(cp);
68 
69  QUndoCommand *undo = nullptr;
70 
71  if (m_parent_undo)
72  {
73  new QPropertyUndoCommand(m_conductor, "properties", old_value, new_value, m_parent_undo);
74  undo = m_parent_undo;
75  }
76  else
77  {
78  undo = new QUndoCommand();
79  new QPropertyUndoCommand(m_conductor, "properties", old_value, new_value, undo);
80  undo->setText(QObject::tr("Modifier les propriétés d'un conducteur", "undo caption"));
81  }
82 
83  if (!conductor_list.isEmpty())
84  {
85  if (!m_parent_undo)
86  undo->setText(QObject::tr("Modifier les propriétés de plusieurs conducteurs", "undo caption"));
87 
88  foreach (Conductor *cond, conductor_list)
89  {
90  ConductorProperties cp2 = cond -> properties();
91  old_value.setValue(cp2);
92  cp2.text = t;
93  new_value.setValue(cp2);
94  new QPropertyUndoCommand(cond, "properties", old_value, new_value, undo);
95  }
96  }
97 
98  if (!m_parent_undo)
99  m_diagram->undoStack().push(undo);
100 }
101 
110 {
111  NumerotationContext context = diagram->project()->conductorAutoNum(diagram->conductorsAutonumName());
112  if (context.isEmpty()) {
113  return;
114  }
115 
116  QString autoNum_name = diagram->project()->conductorCurrentAutoNum();
117  QString formula = autonum::numerotationContextToFormula(context);
118  cp.m_formula = formula;
119 
120  autonum::setSequential(formula, seq, context, diagram, autoNum_name);
121 
122  NumerotationContextCommands ncc (context, diagram);
123  diagram->project()->addConductorAutoNum(autoNum_name, ncc.next());
124 }
125 
131 {
132  ConductorProperties cp = conductor_list.first()->properties();
133  bool properties_equal = true;
134  foreach (const Conductor *conductor, conductor_list)
135  {
136  if (conductor->properties() != cp)
137  properties_equal = false;
138  }
139  //Every properties of the potential is equal, so we apply it to m_conductor
140  if (properties_equal)
141  {
143  m_conductor->rSequenceNum() = conductor_list.first()->sequenceNum();
144  return;
145  }
146 
147  QStringList text_list;
148  QStringList formula_list;
149  foreach (const Conductor *cc, conductor_list)
150  {
151  ConductorProperties cp = cc->properties();
152  text_list << cp.text;
153  formula_list << cp.m_formula;
154  }
155 
156 
157  //the texts is identicals
158  if (QET::eachStrIsEqual(text_list) && QET::eachStrIsEqual(formula_list))
159  {
160  QList<ConductorProperties> cp_list;
161  foreach(Conductor *c, conductor_list)
162  cp_list<<c->properties();
163 
165  cp.applyForEqualAttributes(cp_list);
166  m_conductor->rSequenceNum() = conductor_list.first()->sequenceNum();
168  }
169  //the texts isn't identicals
170  else
171  {
173  psd.exec();
174  }
175 }
176 
182 {
183  if (!m_conductor || m_diagram->conductorsAutonumName().isEmpty())
184  return;
185 
186  NumerotationContext context = m_diagram->project()->conductorAutoNum(m_diagram -> conductorsAutonumName());
187  if (context.isEmpty())
188  return;
189 
190  QString autoNum_name = m_diagram->project()->conductorCurrentAutoNum();
191  QString formula = autonum::numerotationContextToFormula(context);
192 
193  ConductorProperties cp = m_conductor -> properties();
194  cp.m_formula = formula;
196 
197  autonum::setSequential(formula, m_conductor->rSequenceNum(), context, m_diagram, autoNum_name);
198 
199  NumerotationContextCommands ncc (context, m_diagram);
200  m_diagram->project()->addConductorAutoNum(autoNum_name, ncc.next());
201 
203 }
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
void numerateNewConductor()
ConductorAutoNumerotation::numerateNewConductor create and apply a new numerotation to ...
QString conductorCurrentAutoNum() const
QETProject::conductorCurrentAutoNum.
Definition: qetproject.cpp:561
static void newProperties(Diagram *diagram, ConductorProperties &cp, autonum::sequentialNumbers &seq)
ConductorAutoNumerotation::newProperties Create a new properties according to the current autonum rul...
ConductorProperties properties
Conductor::properties.
Definition: conductor.h:48
static QString formulaToLabel(QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt=nullptr)
AssignVariables::formulaToLabel Return the with variable assigned (ready to be displayed) ...
QETDiagramEditor * diagramEditor() const
Conductor::diagramEditor.
Definition: conductor.cpp:1654
QHash< QString, NumerotationContext > conductorAutoNum() const
QETProject::conductorAutoNum.
Definition: qetproject.cpp:494
NumerotationContext next()
NumerotationContextCommands::next.
void numeratePotential()
ConductorAutoNumerotation::numeratePotential Numerate a conductor on an existing potential.
int type() const override
Definition: conductor.h:75
void applyText(const QString &)
ConductorAutoNumerotation::applyText apply the text to and all conductors at the same potential...
void setSequential(const QString &label, sequentialNumbers &seqStruct, NumerotationContext &context, Diagram *diagram, const QString &hashKey)
setSequential Fill seqStruct
QString numerotationContextToFormula(const NumerotationContext &nc)
numerotationContextToFormula
void setProperties(const ConductorProperties &property)
Definition: conductor.cpp:1495
autonum::sequentialNumbers & rSequenceNum()
Definition: conductor.h:123
void addConductorAutoNum(const QString &key, const NumerotationContext &context)
QETProject::addConductorAutoNum Add a new conductor numerotation context. If key already exist...
Definition: qetproject.cpp:588
QString conductorsAutonumName() const
Diagram::conductorsAutonumName.
Definition: diagram.cpp:488
void numerate()
ConductorAutoNumerotation::numerate execute the automatic numerotation.
QIcon tr
Definition: qeticons.cpp:204
ConductorAutoNumerotation(Conductor *conductor, Diagram *diagram, QUndoCommand *undo_parent=nullptr)
ConductorAutoNumerotation::ConductorAutoNumerotation Constructor of autonum, after create a class...
The PotentialSelectorDialog class This dialog is used when user try to connect two existing potential...
QUndoStack & undoStack()
Definition: diagram.h:337
bool isEmpty() const
NumerotationContext::isEmpty.
void applyForEqualAttributes(QList< ConductorProperties > list)
ConductorProperties::applyForEqualAttributes Test each attribute of properties in the list separatly...
QETProject * project() const
Definition: diagram.cpp:1716
bool eachStrIsEqual(const QStringList &qsl)
QET::eachStrIsEqual.
Definition: qet.cpp:584