QElectroTech  0.70
numerotationcontextcommands.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 */
19 #include "diagram.h"
20 
25  diagram_ (d),
26  context_ (nc),
27  strategy_ (nullptr)
28 {}
29 
34  if (strategy_) delete strategy_;
35 }
36 
42  NumerotationContext contextnum;
43 
44  for (int i=0; i<context_.size(); ++i) {
45  QStringList str = context_.itemAt(i);
46  setNumStrategy(str.at(0));
47  contextnum << strategy_ -> next(context_, i);
48  }
49  return contextnum;
50 }
51 
57  NumerotationContext contextnum;
58 
59  for (int i=0; i<context_.size(); ++i) {
60  QStringList str = context_.itemAt(i);
61  setNumStrategy(str.at(0));
62  contextnum << strategy_ -> previous(context_, i);
63  }
64  return contextnum;
65 }
66 
72  QString num;
73  if (context_.size()) {
74  for (int i=0; i<context_.size(); i++) {
75  QStringList str = context_.itemAt(i);
76  setNumStrategy(str.at(0));
77  num += strategy_ -> toRepresentedString(str.at(1));
78  }
79  return num;
80  }
81  if (diagram_) return (diagram_ -> defaultConductorProperties.text);
82  return QString();
83 }
84 
90  if (strategy_) delete strategy_;
91  if (str == "unit") {
92  strategy_ = new UnitNum(diagram_);
93  return;
94  }
95  else if (str == "unitfolio") {
96  strategy_ = new UnitFNum (diagram_);
97  return;
98  }
99  else if (str == "ten") {
100  strategy_ = new TenNum (diagram_);
101  return;
102  }
103  else if (str == "tenfolio") {
104  strategy_ = new TenFNum (diagram_);
105  return;
106  }
107  else if (str == "hundred") {
108  strategy_ = new HundredNum (diagram_);
109  return;
110  }
111  else if (str == "hundredfolio") {
113  return;
114  }
115  else if (str == "string") {
116  strategy_ = new StringNum (diagram_);
117  return;
118  }
119  else if (str == "idfolio") {
120  strategy_ = new IdFolioNum (diagram_);
121  return;
122  }
123  else if (str=="folio"){
124  strategy_ = new FolioNum (diagram_);
125  return;
126  }
127  else if (str=="plant"){
128  strategy_ = new PlantNum (diagram_);
129  return;
130  }
131  else if (str=="locmach"){
132  strategy_ = new LocmachNum (diagram_);
133  return;
134  }
135  else if (str=="elementline"){
137  return;
138  }
139  else if (str=="elementcolumn"){
141  return;
142  }
143  else if (str=="elementprefix"){
145  return;
146  }
147 }
148 
149 
150 
155  diagram_ (d)
156 {}
157 
159 
165  QStringList strl = nc.itemAt(i);
166  NumerotationContext newnc;
167  newnc.addValue(strl.at(0), strl.at(1), strl.at(2).toInt());
168  return (newnc);
169 }
170 
176  QStringList strl = nc.itemAt(i);
177  NumerotationContext newnc;
178  QString value = QString::number( (strl.at(1).toInt()) + (strl.at(2).toInt()) );
179  newnc.addValue(strl.at(0), value, strl.at(2).toInt(), strl.at(3).toInt());
180  return (newnc);
181 }
182 
188  QStringList strl = nc.itemAt(i);
189  NumerotationContext newnc;
190  QString value = QString::number( (strl.at(1).toInt()) - (strl.at(2).toInt()) );
191  newnc.addValue(strl.at(0), value, strl.at(2).toInt(), strl.at(3).toInt());
192  return (newnc);
193 }
194 
199  NumStrategy(d)
200 {}
201 
206 QString UnitNum::toRepresentedString(const QString num) const {
207  return (num);
208 }
209 
214 NumerotationContext UnitNum::next (const NumerotationContext &nc, const int i) const {
215  return (nextNumber(nc, i));
216 }
217 
223  return (previousNumber(nc, i));
224 }
225 
230  NumStrategy(d)
231 {}
232 
237 QString UnitFNum::toRepresentedString(const QString num) const {
238  return (num);
239 }
240 
246  return (nextNumber(nc, i));
247 }
248 
254  return (previousNumber(nc, i));
255 }
256 
261  NumStrategy (d)
262 {}
263 
268 QString TenNum::toRepresentedString(const QString num) const {
269  int numint = num.toInt();
270  QString numstr = num;
271  if (numint<10) numstr.prepend("0");
272  return (numstr);
273 }
274 
279 NumerotationContext TenNum::next (const NumerotationContext &nc, const int i) const {
280  return (nextNumber(nc, i));
281 }
282 
288  return (previousNumber(nc, i));
289 }
290 
295  NumStrategy (d)
296 {}
297 
302 QString TenFNum::toRepresentedString(const QString num) const {
303  int numint = num.toInt();
304  QString numstr = num;
305  if (numint<10) numstr.prepend("0");
306  return (numstr);
307 }
308 
313 NumerotationContext TenFNum::next (const NumerotationContext &nc, const int i) const {
314  return (nextNumber(nc, i));
315 }
316 
322  return (previousNumber(nc, i));
323 }
324 
325 
330  NumStrategy (d)
331 {}
332 
337 QString HundredNum::toRepresentedString(const QString num) const {
338  int numint = num.toInt();
339  QString numstr = num;
340  if (numint<100) {
341  if (numint<10) {
342  numstr.prepend("00");
343  }
344  else numstr.prepend("0");
345  }
346  return (numstr);
347 }
348 
354  return (nextNumber(nc, i));
355 }
356 
362  return (previousNumber(nc, i));
363 }
364 
369  NumStrategy (d)
370 {}
371 
376 QString HundredFNum::toRepresentedString(const QString num) const {
377  int numint = num.toInt();
378  QString numstr = num;
379  if (numint<100) {
380  if (numint<10) {
381  numstr.prepend("00");
382  }
383  else numstr.prepend("0");
384  }
385  return (numstr);
386 }
387 
393  return (nextNumber(nc, i));
394 }
395 
401  return (previousNumber(nc, i));
402 }
403 
408  NumStrategy (d)
409 {}
410 
415 QString StringNum::toRepresentedString(const QString str) const {
416  return (str);
417 }
418 
424  return (nextString(nc, i));
425 }
426 
432  return (nextString(nc, i));
433 }
434 
439  NumStrategy (d)
440 {}
441 
446 QString IdFolioNum::toRepresentedString(const QString str) const {
447  Q_UNUSED(str);
448  return ("%id");
449 }
450 
456  return (nextString(nc, i));
457 }
458 
464  return (nextString(nc, i));
465 }
466 
471  NumStrategy (d)
472 {}
473 
478 QString FolioNum::toRepresentedString(const QString str) const {
479  Q_UNUSED(str);
480  return ("%F");
481 }
482 
488  return (nextString(nc, i));
489 }
490 
496  return (nextString(nc, i));
497 }
498 
503  NumStrategy (d)
504 {}
505 
510 QString PlantNum::toRepresentedString(const QString str) const {
511  Q_UNUSED(str);
512  return "%M";
513 }
514 
520  return (nextString(nc, i));
521 }
522 
528  return (nextString(nc, i));
529 }
530 
531 
536  NumStrategy (d)
537 {}
538 
543 QString LocmachNum::toRepresentedString(const QString str) const {
544  Q_UNUSED(str);
545  return "%LM";
546 }
547 
553  return (nextString(nc, i));
554 }
555 
561  return (nextString(nc, i));
562 }
563 
564 
569  NumStrategy (d)
570 {}
571 
576 QString ElementLineNum::toRepresentedString(const QString str) const {
577  Q_UNUSED(str);
578  return "%l";
579 }
580 
586  return (nextString(nc, i));
587 }
588 
594  return (nextString(nc, i));
595 }
596 
601  NumStrategy (d)
602 {}
603 
608 QString ElementColumnNum::toRepresentedString(const QString str) const {
609  Q_UNUSED(str);
610  return "%c";
611 }
612 
618  return (nextString(nc, i));
619 }
620 
626  return (nextString(nc, i));
627 }
628 
633  NumStrategy (d)
634 {}
635 
640 QString ElementPrefixNum::toRepresentedString(const QString str) const {
641  Q_UNUSED(str);
642  return "%prefix";
643 }
644 
650  return (nextString(nc, i));
651 }
652 
658  return (nextString(nc, i));
659 }
660 
NumerotationContext next(const NumerotationContext &, const int) const override
ElementColumnNum::next.
QString toRepresentedString(const QString) const override
UnitNum::toRepresentedString.
QString toRepresentedString(const QString) const override
UnitFNum::toRepresentedString.
NumerotationContext previous(const NumerotationContext &, const int) const override
UnitFNum::previous.
NumerotationContext previousNumber(const NumerotationContext &, const int) const
NumStrategy::previousNumber.
NumerotationContext nextString(const NumerotationContext &, const int) const
NumStrategy::nextString.
QStringList itemAt(const int) const
NumerotationContext::itemAt.
NumerotationContext previous(const NumerotationContext &, const int) const override
UnitNum::previous.
NumerotationContext previous(const NumerotationContext &, const int) const override
PlantNum::previous.
NumerotationContext previous(const NumerotationContext &, const int) const override
TenNum::previous.
NumerotationContext next()
NumerotationContextCommands::next.
NumerotationContext previous(const NumerotationContext &, const int) const override
HundredNum::previous.
QString toRepresentedString(const QString) const override
FolioNum::toRepresentedString.
QString toRepresentedString(const QString) const override
ElementLineNum::toRepresentedString.
NumerotationContext previous(const NumerotationContext &, const int) const override
TenFNum::previous.
NumerotationContext next(const NumerotationContext &, const int) const override
TenFNum::next.
QString toRepresentedString(const QString) const override
PlantNum::toRepresentedString.
NumerotationContext next(const NumerotationContext &, const int) const override
ElementPrefixNum::next.
NumerotationContext next(const NumerotationContext &, const int) const override
UnitNum::next.
QString toRepresentedString(const QString) const override
LocmachNum::toRepresentedString.
QString toRepresentedString(const QString) const override
ElementColumnNum::toRepresentedString.
QString toRepresentedString(const QString) const override
StringNum::toRepresentedString.
QString toRepresentedString(const QString) const override
IdFolioNum::toRepresentedString.
NumerotationContext previous()
NumerotationContextCommands::previous.
NumStrategy(Diagram *=nullptr)
NumerotationContextCommands(const NumerotationContext &, Diagram *=nullptr)
Constructor.
NumerotationContext next(const NumerotationContext &, const int) const override
IdFolioNum::next.
NumerotationContext next(const NumerotationContext &, const int) const override
HundredFNum::next.
int size() const
NumerotationContext::size.
NumerotationContext next(const NumerotationContext &, const int) const override
TenNum::next.
NumerotationContext previous(const NumerotationContext &, const int) const override
HundredFNum::previous.
QString toRepresentedString(const QString) const override
HundredFNum::toRepresentedString.
NumerotationContext previous(const NumerotationContext &, const int) const override
FolioNum::previous.
NumerotationContext previous(const NumerotationContext &, const int) const override
ElementPrefixNum::previous.
NumerotationContext next(const NumerotationContext &, const int) const override
UnitFNum::next.
NumerotationContext previous(const NumerotationContext &, const int) const override
IdFolioNum::previous.
NumerotationContext next(const NumerotationContext &, const int) const override
FolioNum::next.
NumerotationContext nextNumber(const NumerotationContext &, const int) const
NumStrategy::nextNumber.
NumerotationContext previous(const NumerotationContext &, const int) const override
ElementLineNum::previous.
NumerotationContext next(const NumerotationContext &, const int) const override
LocmachNum::next.
QString toRepresentedString(const QString) const override
TenFNum::toRepresentedString.
NumerotationContext previous(const NumerotationContext &, const int) const override
StringNum::previous.
QString toRepresentedString(const QString) const override
HundredNum::toRepresentedString.
NumerotationContext previous(const NumerotationContext &, const int) const override
ElementColumnNum::previous.
bool addValue(const QString &, const QVariant &=QVariant(1), const int=1, const int=0)
NumerotationContext::addValue, add a new value on the contexte.
NumerotationContext next(const NumerotationContext &, const int) const override
HundredNum::next.
NumerotationContext next(const NumerotationContext &, const int) const override
ElementLineNum::next.
void setNumStrategy(const QString &)
NumerotationContextCommands::setNumStrategy apply the good strategy relative to . ...
NumerotationContext next(const NumerotationContext &, const int) const override
PlantNum::next.
NumerotationContext previous(const NumerotationContext &, const int) const override
LocmachNum::previous.
QString toRepresentedString(const QString) const override
ElementPrefixNum::toRepresentedString.
NumerotationContext next(const NumerotationContext &, const int) const override
StringNum::next.
QString toRepresentedString(const QString) const override
TenNum::toRepresentedString.
QString toRepresentedString()
NumerotationContextCommands::toFinalString.