QElectroTech  0.70
numparteditorw.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 <QRegExp>
19 #include "numparteditorw.h"
20 #include "ui_numparteditorw.h"
21 
25 NumPartEditorW::NumPartEditorW(int type, QWidget *parent) :
26  QWidget(parent),
27  ui(new Ui::NumPartEditorW),
28  intValidator (new QIntValidator(0,99999,this)),
29  m_edited_type(type)
30 {
31  ui -> setupUi(this);
34 }
35 
40 NumPartEditorW::NumPartEditorW (NumerotationContext &context, int i, int type, QWidget *parent):
41  QWidget(parent),
42  ui(new Ui::NumPartEditorW),
43  intValidator (new QIntValidator(0,99999,this)),
44  m_edited_type(type)
45 {
46  ui -> setupUi(this);
48  if(context.size()==0) setType(NumPartEditorW::unit, true);
49 
50  else {
51  QStringList strl = context.itemAt(i);
52  if (strl.at(0)=="unit") setType(NumPartEditorW::unit, true);
53  else if (strl.at(0)=="unitfolio") setType(NumPartEditorW::unitfolio, true);
54  else if (strl.at(0)=="ten") setType(NumPartEditorW::ten, true);
55  else if (strl.at(0)=="tenfolio") setType(NumPartEditorW::tenfolio, true);
56  else if (strl.at(0)=="hundred") setType(NumPartEditorW::hundred, true);
57  else if (strl.at(0)=="hundredfolio") setType(NumPartEditorW::hundredfolio, true);
58  else if (strl.at(0)=="string") setType(NumPartEditorW::string);
59  else if (strl.at(0)=="idfolio") setType(NumPartEditorW::idfolio);
60  else if (strl.at(0)=="folio") setType(NumPartEditorW::folio);
61  else if (strl.at(0)=="plant") setType(NumPartEditorW::plant);
62  else if (strl.at(0)=="locmach") setType(NumPartEditorW::locmach);
63  else if (strl.at(0)=="elementline") setType(NumPartEditorW::elementline);
64  else if (strl.at(0)=="elementcolumn") setType(NumPartEditorW::elementcolumn);
65  else if (strl.at(0)=="elementprefix") setType(NumPartEditorW::elementprefix);
66  ui -> value_field -> setText(strl.at(1));
67  ui -> increase_spinBox -> setValue(strl.at(2).toInt());
68  }
69 }
70 
75 {
76  delete intValidator;
77  delete ui;
78 }
79 
81 {
82  ui->type_cb->setInsertPolicy(QComboBox::InsertAtBottom);
83  QStringList items;
84  if (m_edited_type == 2)
85  {
86  items << tr("Chiffre 1") << tr("Chiffre 01")
87  << tr("Chiffre 001")
88  << tr("Texte");
89  }
90  else if (m_edited_type == 1)
91  {
92  items << tr("Chiffre 1") << tr("Chiffre 1 - Folio") << tr("Chiffre 01")
93  << tr("Chiffre 01 - Folio") << tr("Chiffre 001") << tr("Chiffre 001 - Folio")
94  << tr("Texte") << tr("N° folio") << tr("Folio") << tr("Installation") << tr("Locmach");
95  }
96  else
97  items << tr("Chiffre 1") << tr("Chiffre 1 - Folio") << tr("Chiffre 01")
98  << tr("Chiffre 01 - Folio") << tr("Chiffre 001") << tr("Chiffre 001 - Folio")
99  << tr("Texte") << tr("N° folio") << tr("Folio") << tr("Installation") << tr("Locmach")
100  << tr("Element Line") << tr("Element Column") << tr("Element Prefix");
101  ui->type_cb->insertItems(0,items);
102 }
103 
110  QString type_str;
111  switch (type_) {
112  case unit:
113  type_str = "unit";
114  break;
115  case unitfolio:
116  type_str = "unitfolio";
117  break;
118  case ten:
119  type_str = "ten";
120  break;
121  case tenfolio:
122  type_str = "tenfolio";
123  break;
124  case hundred:
125  type_str = "hundred";
126  break;
127  case hundredfolio:
128  type_str = "hundredfolio";
129  break;
130  case string:
131  type_str = "string";
132  break;
133  case idfolio:
134  type_str = "idfolio";
135  break;
136  case folio:
137  type_str = "folio";
138  break;
139  case plant:
140  type_str = "plant";
141  break;
142  case locmach:
143  type_str = "locmach";
144  break;
145  case elementline:
146  type_str = "elementline";
147  break;
148  case elementcolumn:
149  type_str = "elementcolumn";
150  break;
151  case elementprefix:
152  type_str = "elementprefix";
153  break;
154  }
155  if (type_str == "unitfolio" || type_str == "tenfolio" || type_str == "hundredfolio")
156  nc.addValue(type_str, ui -> value_field -> displayText(), ui -> increase_spinBox -> value(), ui->value_field->displayText().toInt());
157  else
158  nc.addValue(type_str, ui -> value_field -> displayText(), ui -> increase_spinBox -> value());
159  return nc;
160 }
161 
167  if (type_ == folio || type_ == idfolio || type_ == elementline || type_ == plant || type_ == locmach ||
168  type_ == elementcolumn || type_ == elementprefix) {return true;}
169  else if(ui -> value_field -> text().isEmpty()) {return false;}
170  else return true;
171 }
172 
178  if (ui->type_cb->currentText() == tr("Chiffre 1"))
179  setType(unit);
180  else if (ui->type_cb->currentText() == tr("Chiffre 1 - Folio"))
182  else if (ui->type_cb->currentText() == tr("Chiffre 01"))
183  setType(ten);
184  else if (ui->type_cb->currentText() == tr("Chiffre 01 - Folio"))
185  setType(tenfolio);
186  else if (ui->type_cb->currentText() == tr("Chiffre 001"))
187  setType(hundred);
188  else if (ui->type_cb->currentText() == tr("Chiffre 001 - Folio"))
190  else if (ui->type_cb->currentText() == tr("Texte"))
191  setType(string);
192  else if (ui->type_cb->currentText() == tr("N° folio"))
193  setType(idfolio);
194  else if (ui->type_cb->currentText() == tr("Folio"))
195  setType(folio);
196  else if (ui->type_cb->currentText() == tr("Installation"))
197  setType(plant);
198  else if (ui->type_cb->currentText() == tr("Locmach"))
199  setType(locmach);
200  else if (ui->type_cb->currentText() == tr("Element Line"))
202  else if (ui->type_cb->currentText() == tr("Element Column"))
204  else if (ui->type_cb->currentText() == tr("Element Prefix"))
206  emit changed();
207 }
208 
214  emit changed();
215 }
216 
222  if (!ui -> value_field -> text().isEmpty()) emit changed();
223 }
224 
232  setCurrentIndex(t);
233 
234  //if @t is a numeric type and preview type @type_ isn't a numeric type
235  //or @fnum is true, we set numeric behavior
236  if ( ((t==unit || t==unitfolio || t==ten || t==tenfolio || t==hundred || t==hundredfolio) &&
237  (type_==string || type_==folio || type_==plant || type_==locmach ||type_==idfolio ||
239  || fnum) {
240  ui -> value_field -> clear();
241  ui -> value_field -> setEnabled(true);
242  ui -> value_field -> setValidator(intValidator);
243  ui -> increase_spinBox -> setEnabled(true);
244  ui -> increase_spinBox -> setValue(1);
245  }
246  //@t isn't a numeric type
247  else if (t == string || t == folio || t == idfolio || t == elementline || t == plant || t == locmach ||
248  t == elementcolumn || t == elementprefix) {
249  ui -> value_field -> clear();
250  ui -> increase_spinBox -> setDisabled(true);
251  if (t==string) {
252  ui -> value_field -> setValidator(nullptr);
253  ui -> value_field -> setEnabled(true);
254  }
255  else if (t==folio) {
256  ui -> value_field -> setDisabled(true);
257  ui -> increase_spinBox -> setDisabled(true);
258  }
259  else if (t==plant) {
260  ui -> value_field -> setDisabled(true);
261  ui -> increase_spinBox -> setDisabled(true);
262  }
263  else if (t==locmach) {
264  ui -> value_field -> setDisabled(true);
265  ui -> increase_spinBox -> setDisabled(true);
266  }
267  else if (t==idfolio) {
268  ui -> value_field -> setDisabled(true);
269  ui -> increase_spinBox -> setDisabled(true);
270  }
271  else if (t==elementcolumn) {
272  ui -> value_field -> setDisabled(true);
273  ui -> increase_spinBox -> setDisabled(true);
274  }
275  else if (t==elementline) {
276  ui -> value_field -> setDisabled(true);
277  ui -> increase_spinBox -> setDisabled(true);
278  }
279  else if (t==elementprefix) {
280  ui -> value_field -> setDisabled(true);
281  ui -> increase_spinBox -> setDisabled(true);
282  }
283  }
284  type_= t;
285 }
286 
293  int i=-1;
294  if (t == unit)
295  i = ui->type_cb->findText(tr("Chiffre 1"));
296  else if (t == unitfolio)
297  i = ui->type_cb->findText(tr("Chiffre 1 - Folio"));
298  else if (t == ten)
299  i = ui->type_cb->findText(tr("Chiffre 01"));
300  else if (t == tenfolio)
301  i = ui->type_cb->findText(tr("Chiffre 01 - Folio"));
302  else if (t == hundred)
303  i = ui->type_cb->findText(tr("Chiffre 001"));
304  else if (t == hundredfolio)
305  i = ui->type_cb->findText(tr("Chiffre 001 - Folio"));
306  else if (t == string)
307  i = ui->type_cb->findText(tr("Texte"));
308  else if (t == idfolio)
309  i = ui->type_cb->findText(tr("N° folio"));
310  else if (t == folio)
311  i = ui->type_cb->findText(tr("Folio"));
312  else if (t == plant)
313  i = ui->type_cb->findText(tr("Installation"));
314  else if (t == locmach)
315  i = ui->type_cb->findText(tr("Locmach"));
316  else if (t == elementline)
317  i = ui->type_cb->findText(tr("Element Line"));
318  else if (t == elementcolumn)
319  i = ui->type_cb->findText(tr("Element Column"));
320  else if (t == elementprefix)
321  i = ui->type_cb->findText(tr("Element Prefix"));
322  ui->type_cb->setCurrentIndex(i);
323 }
~NumPartEditorW() override
NumPartEditorW(int type, QWidget *parent=nullptr)
QStringList itemAt(const int) const
NumerotationContext::itemAt.
QValidator * intValidator
void on_type_cb_activated(int)
NumPartEditorW::on_type_cb_activated Action when user change the type comboBox.
bool isValid()
NumPartEditorW::isValid.
int size() const
NumerotationContext::size.
NumerotationContext toNumContext()
NumPartEditorW::toNumContext.
QIcon tr
Definition: qeticons.cpp:204
void setType(NumPartEditorW::type t, bool=false)
NumPartEditorW::setType Set good behavior by type .
void on_increase_spinBox_valueChanged(int)
NumPartEditorW::on_increase_spinBox_valueChanged emit changed when value changed.
Ui::NumPartEditorW * ui
bool addValue(const QString &, const QVariant &=QVariant(1), const int=1, const int=0)
NumerotationContext::addValue, add a new value on the contexte.
void setCurrentIndex(NumPartEditorW::type)
NumPartEditorW::setCurrentIndex Set Current Index of type_cb.
void on_value_field_textEdited()
NumPartEditorW::on_value_field_textChanged emit changed when text changed.