2014-01-29 19:14:04 +00:00
|
|
|
/*
|
2016-05-13 17:40:36 +00:00
|
|
|
Copyright 2006-2016 The QElectroTech Team
|
2014-01-29 19:14:04 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2013-05-18 18:39:53 +00:00
|
|
|
#include <QRegExp>
|
|
|
|
#include "numparteditorw.h"
|
|
|
|
#include "ui_numparteditorw.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
NumPartEditorW::NumPartEditorW(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::NumPartEditorW),
|
|
|
|
intValidator (new QIntValidator(0,99999,this))
|
|
|
|
{
|
|
|
|
ui -> setupUi(this);
|
2016-05-17 19:19:11 +00:00
|
|
|
if (parentWidget()->parentWidget()->objectName()=="FolioTab") ui->type_combo->setMaxCount(4);
|
2016-07-10 01:33:49 +00:00
|
|
|
else if (parentWidget()->parentWidget()->objectName()=="ConductorTab") ui->type_combo->setMaxCount(6);
|
2013-06-28 11:29:36 +00:00
|
|
|
setType(NumPartEditorW::unit, true);
|
2013-05-18 18:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* Build with value of @context at position i
|
|
|
|
*/
|
|
|
|
NumPartEditorW::NumPartEditorW (NumerotationContext &context, int i, QWidget *parent):
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::NumPartEditorW),
|
|
|
|
intValidator (new QIntValidator(0,99999,this))
|
|
|
|
{
|
|
|
|
ui -> setupUi(this);
|
2016-07-10 01:33:49 +00:00
|
|
|
if (parentWidget()->parentWidget()->objectName()=="FolioTab") ui->type_combo->setMaxCount(4);
|
|
|
|
else if (parentWidget()->parentWidget()->objectName()=="ConductorTab") ui->type_combo->setMaxCount(6);
|
2013-05-18 18:39:53 +00:00
|
|
|
//if @context contains nothing build with default value
|
2013-06-28 11:29:36 +00:00
|
|
|
if(context.size()==0) setType(NumPartEditorW::unit, true);
|
2013-05-18 18:39:53 +00:00
|
|
|
|
|
|
|
else {
|
|
|
|
QStringList strl = context.itemAt(i);
|
2013-06-28 11:29:36 +00:00
|
|
|
if (strl.at(0)=="unit") setType(NumPartEditorW::unit, true);
|
|
|
|
else if (strl.at(0)=="ten") setType(NumPartEditorW::ten, true);
|
|
|
|
else if (strl.at(0)=="hundred") setType(NumPartEditorW::hundred, true);
|
2013-05-18 18:39:53 +00:00
|
|
|
else if (strl.at(0)=="string") setType(NumPartEditorW::string);
|
2016-05-17 19:19:11 +00:00
|
|
|
else if (strl.at(0)=="idfolio") setType(NumPartEditorW::idfolio);
|
|
|
|
else if (strl.at(0)=="folio") setType(NumPartEditorW::folio);
|
2016-07-10 01:33:49 +00:00
|
|
|
else if (strl.at(0)=="elementline") setType(NumPartEditorW::elementline);
|
|
|
|
else if (strl.at(0)=="elementcolumn") setType(NumPartEditorW::elementcolumn);
|
|
|
|
else if (strl.at(0)=="elementprefix") setType(NumPartEditorW::elementprefix);
|
2013-05-18 18:39:53 +00:00
|
|
|
ui -> value_field -> setText(strl.at(1));
|
|
|
|
ui -> increase_spinBox -> setValue(strl.at(2).toInt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
NumPartEditorW::~NumPartEditorW()
|
|
|
|
{
|
|
|
|
delete intValidator;
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief NumPartEditorW::toNumContext
|
|
|
|
* @return the display to NumerotationContext
|
|
|
|
*/
|
|
|
|
NumerotationContext NumPartEditorW::toNumContext() {
|
|
|
|
NumerotationContext nc;
|
2013-06-28 11:29:36 +00:00
|
|
|
QString type_str;
|
|
|
|
switch (type_) {
|
|
|
|
case unit:
|
|
|
|
type_str = "unit";
|
|
|
|
break;
|
|
|
|
case ten:
|
|
|
|
type_str = "ten";
|
|
|
|
break;
|
|
|
|
case hundred:
|
|
|
|
type_str = "hundred";
|
|
|
|
break;
|
|
|
|
case string:
|
|
|
|
type_str = "string";
|
|
|
|
break;
|
2016-05-17 19:19:11 +00:00
|
|
|
case idfolio:
|
|
|
|
type_str = "idfolio";
|
|
|
|
break;
|
2013-06-28 11:29:36 +00:00
|
|
|
case folio:
|
|
|
|
type_str = "folio";
|
|
|
|
break;
|
2016-07-10 01:33:49 +00:00
|
|
|
case elementline:
|
|
|
|
type_str = "elementline";
|
|
|
|
break;
|
|
|
|
case elementcolumn:
|
|
|
|
type_str = "elementcolumn";
|
|
|
|
break;
|
|
|
|
case elementprefix:
|
|
|
|
type_str = "elementprefix";
|
|
|
|
break;
|
2013-06-28 11:29:36 +00:00
|
|
|
}
|
2013-05-18 18:39:53 +00:00
|
|
|
nc.addValue(type_str, ui -> value_field -> displayText(), ui -> increase_spinBox -> value());
|
|
|
|
return nc;
|
|
|
|
}
|
|
|
|
|
2013-06-27 14:02:59 +00:00
|
|
|
/**
|
|
|
|
* @brief NumPartEditorW::isValid
|
|
|
|
* @return true if value field isn't empty or if type is folio
|
|
|
|
*/
|
|
|
|
bool NumPartEditorW::isValid() {
|
2016-07-10 01:33:49 +00:00
|
|
|
if (type_ == folio || type_ == idfolio || type_ == elementline ||
|
|
|
|
type_ == elementcolumn || type_ == elementprefix) {return true;}
|
2016-05-17 19:19:11 +00:00
|
|
|
else if(ui -> value_field -> text().isEmpty()) {return false;}
|
|
|
|
else return true;
|
2013-06-27 14:02:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 18:39:53 +00:00
|
|
|
/**
|
|
|
|
* @brief NumPartEditorW::on_type_combo_activated
|
|
|
|
* Action when user change the type comboBox
|
|
|
|
*/
|
|
|
|
void NumPartEditorW::on_type_combo_activated(int index) {
|
|
|
|
switch (index) {
|
|
|
|
case unit:
|
|
|
|
setType(unit);
|
|
|
|
break;
|
|
|
|
case ten:
|
|
|
|
setType(ten);
|
|
|
|
break;
|
|
|
|
case hundred:
|
|
|
|
setType(hundred);
|
|
|
|
break;
|
|
|
|
case string:
|
|
|
|
setType(string);
|
|
|
|
break;
|
2016-05-17 19:19:11 +00:00
|
|
|
case idfolio:
|
|
|
|
setType(idfolio);
|
|
|
|
break;
|
2013-05-18 18:39:53 +00:00
|
|
|
case folio:
|
|
|
|
setType(folio);
|
|
|
|
break;
|
2016-07-10 01:33:49 +00:00
|
|
|
case elementline:
|
|
|
|
setType(elementline);
|
|
|
|
break;
|
|
|
|
case elementcolumn:
|
|
|
|
setType(elementcolumn);
|
|
|
|
break;
|
|
|
|
case elementprefix:
|
|
|
|
setType(elementprefix);
|
|
|
|
break;
|
2013-05-18 18:39:53 +00:00
|
|
|
};
|
2013-06-27 14:02:59 +00:00
|
|
|
emit changed();
|
2013-05-18 18:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief NumPartEditorW::on_value_field_textChanged
|
|
|
|
* emit changed when @value_field text changed
|
|
|
|
*/
|
2013-06-27 14:02:59 +00:00
|
|
|
void NumPartEditorW::on_value_field_textEdited() {
|
2013-05-18 18:39:53 +00:00
|
|
|
emit changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief NumPartEditorW::on_increase_spinBox_valueChanged
|
2013-06-28 11:29:36 +00:00
|
|
|
* emit changed when @increase_spinBox value changed
|
2013-05-18 18:39:53 +00:00
|
|
|
*/
|
2016-07-05 20:14:14 +00:00
|
|
|
void NumPartEditorW::on_increase_spinBox_valueChanged(int) {
|
2013-06-27 14:02:59 +00:00
|
|
|
if (!ui -> value_field -> text().isEmpty()) emit changed();
|
2013-05-18 18:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief NumPartEditorW::setType
|
|
|
|
* Set good behavior by type @t
|
2013-06-28 11:29:36 +00:00
|
|
|
* @param t, type used
|
|
|
|
* @param fnum, force the behavior of numeric type
|
2013-05-18 18:39:53 +00:00
|
|
|
*/
|
2013-06-28 11:29:36 +00:00
|
|
|
void NumPartEditorW::setType(NumPartEditorW::type t, bool fnum) {
|
2013-05-18 18:39:53 +00:00
|
|
|
ui -> type_combo -> setCurrentIndex(t);
|
2013-06-28 11:29:36 +00:00
|
|
|
|
|
|
|
//if @t is a numeric type and preview type @type_ isn't a numeric type
|
|
|
|
//or @fnum is true, we set numeric behavior
|
2016-07-10 01:33:49 +00:00
|
|
|
if ( ((t==unit || t==ten || t==hundred) &&
|
|
|
|
(type_==string || type_==folio || type_==idfolio ||
|
|
|
|
type_==elementcolumn || type_==elementline || type_==elementprefix))
|
|
|
|
|| fnum) {
|
2013-06-28 11:29:36 +00:00
|
|
|
ui -> value_field -> clear();
|
|
|
|
ui -> value_field -> setEnabled(true);
|
|
|
|
ui -> value_field -> setValidator(intValidator);
|
|
|
|
ui -> increase_spinBox -> setEnabled(true);
|
|
|
|
ui -> increase_spinBox -> setValue(1);
|
|
|
|
}
|
|
|
|
//@t isn't a numeric type
|
2016-07-10 01:33:49 +00:00
|
|
|
else if (t == string || t == folio || t == idfolio || t == elementline ||
|
|
|
|
t == elementcolumn || t == elementprefix) {
|
2013-06-28 11:29:36 +00:00
|
|
|
ui -> value_field -> clear();
|
|
|
|
ui -> increase_spinBox -> setDisabled(true);
|
|
|
|
if (t==string) {
|
2013-05-18 18:39:53 +00:00
|
|
|
ui -> value_field -> setValidator(0);
|
|
|
|
ui -> value_field -> setEnabled(true);
|
2013-06-28 11:29:36 +00:00
|
|
|
}
|
|
|
|
else if (t==folio) {
|
2013-05-18 18:39:53 +00:00
|
|
|
ui -> value_field -> setDisabled(true);
|
|
|
|
ui -> increase_spinBox -> setDisabled(true);
|
2013-06-28 11:29:36 +00:00
|
|
|
}
|
2016-05-17 19:19:11 +00:00
|
|
|
else if (t==idfolio) {
|
|
|
|
ui -> value_field -> setDisabled(true);
|
|
|
|
ui -> increase_spinBox -> setDisabled(true);
|
|
|
|
}
|
2016-07-10 01:33:49 +00:00
|
|
|
else if (t==elementcolumn) {
|
|
|
|
ui -> value_field -> setDisabled(true);
|
|
|
|
ui -> increase_spinBox -> setDisabled(true);
|
|
|
|
}
|
|
|
|
else if (t==elementline) {
|
|
|
|
ui -> value_field -> setDisabled(true);
|
|
|
|
ui -> increase_spinBox -> setDisabled(true);
|
|
|
|
}
|
|
|
|
else if (t==elementprefix) {
|
|
|
|
ui -> value_field -> setDisabled(true);
|
|
|
|
ui -> increase_spinBox -> setDisabled(true);
|
|
|
|
}
|
2013-06-28 11:29:36 +00:00
|
|
|
}
|
|
|
|
type_= t;
|
2013-05-18 18:39:53 +00:00
|
|
|
}
|