QElectroTech  0.70
numerotationcontext.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 */
18 #include "numerotationcontext.h"
19 
20 #include <utility>
21 #include "qet.h"
22 
27 }
28 
33  fromXml(e);
34 }
35 
40  content_.clear();
41 }
42 
50 bool NumerotationContext::addValue(const QString &type, const QVariant &value, const int increase, const int initialvalue) {
51  if (!keyIsAcceptable(type) && !value.canConvert(QVariant::String)) return false;
52  if (keyIsNumber(type) && !value.canConvert(QVariant::Int)) return false;
53 
54  QString valuestr = value.toString();
55  valuestr.remove("|");
56  content_ << type + "|" + valuestr + "|" + QString::number(increase) + "|" + QString::number(initialvalue);
57  return true;
58 }
59 
64 QString NumerotationContext::operator [] (const int &i) const {
65  return (content_.at(i));
66 }
67 
72  for (int i=0; i<other.size(); ++i) content_.append(other[i]);
73 }
74 
80  return (content_.size());
81 }
82 
88  if (content_.size() > 0) return false;
89  return true;
90 }
95 QStringList NumerotationContext::itemAt(const int i) const {
96  return (content_.at(i).split("|"));
97 }
98 
104  return ("unit|unitfolio|ten|tenfolio|hundred|hundredfolio|string|idfolio|folio|plant|locmach|elementline|elementcolumn|elementprefix");
105 }
106 
112  return ("unit|unitfolio|ten|tenfolio|hundred|hundredfolio");
113 }
114 
119 bool NumerotationContext::keyIsAcceptable(const QString &type) const {
120  return (type.contains(QRegExp(validRegExpNum())));
121 }
122 
127 bool NumerotationContext::keyIsNumber(const QString &type) const {
128  return (type.contains(QRegExp(validRegExpNumber())));
129 }
130 
135 QDomElement NumerotationContext::toXml(QDomDocument &d, const QString& str) {
136  QDomElement num_auto = d.createElement(str);
137  for (int i=0; i<content_.size(); ++i) {
138  QStringList strl = itemAt(i);
139  QDomElement part = d.createElement("part");
140  part.setAttribute("type", strl.at(0));
141  part.setAttribute("value", strl.at(1));
142  part.setAttribute("increase", strl.at(2));
143  if (strl.at(0) == ("unitfolio") ||
144  strl.at(0) == ("tenfolio") ||
145  strl.at(0) == ("hundredfolio")) {
146  part.setAttribute("initialvalue", strl.at(3));
147  }
148  num_auto.appendChild(part);
149  }
150  return num_auto;
151 }
152 
157 void NumerotationContext::fromXml(QDomElement &e) {
158  clear();
159  foreach(QDomElement qde, QET::findInDomElement(e, "part")) addValue(qde.attribute("type"), qde.attribute("value"), qde.attribute("increase").toInt(), qde.attribute("initialvalue").toInt());
160 }
161 
168 void NumerotationContext::replaceValue(int index, QString content) {
169  QString sep = "|";
170  QString type = content_[index].split("|").at(0);
171  const QString& value = std::move(content);
172  QString increase = content_[index].split("|").at(2);
173  QString initvalue = content_[index].split("|").at(3);
174  content_[index].replace(content_[index], type + "|" + value + "|" + increase + "|" + initvalue);
175 }
QStringList itemAt(const int) const
NumerotationContext::itemAt.
void clear()
NumerotationContext::clear, clear the content.
void fromXml(QDomElement &)
NumerotationContext::fromXml load numerotation context from .
bool keyIsNumber(const QString &) const
NumerotationContext::keyIsNumber.
QString operator[](const int &) const
NumerotationContext::operator [].
QString validRegExpNum() const
validRegExpNum
QDomElement toXml(QDomDocument &, const QString &)
NumerotationContext::toXml Save the numerotation context in a QDomElement under the element name ...
QString validRegExpNumber() const
NumerotationContext::validRegExpNumber.
void operator<<(const NumerotationContext &)
NumerotationContext::operator << , append other.
int size() const
NumerotationContext::size.
QList< QDomElement > findInDomElement(const QDomElement &, const QString &)
Definition: qet.cpp:300
void replaceValue(int, QString)
NumerotationContext::replaceValue This class replaces the current NC field value with content...
bool keyIsAcceptable(const QString &) const
NumerotationContext::keyIsAcceptable.
bool isEmpty() const
NumerotationContext::isEmpty.
bool addValue(const QString &, const QVariant &=QVariant(1), const int=1, const int=0)
NumerotationContext::addValue, add a new value on the contexte.