2016-05-13 15:00:22 +00:00
|
|
|
/*
|
2021-02-20 12:13:46 +01:00
|
|
|
Copyright 2006-2021 The QElectroTech Team
|
2016-05-13 15:00:22 +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/>.
|
|
|
|
*/
|
|
|
|
#include "folioautonumbering.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
|
|
|
#include "../../diagram.h"
|
|
|
|
#include "../../qetproject.h"
|
2016-05-13 15:00:22 +00:00
|
|
|
#include "ui_folioautonumbering.h"
|
2020-12-08 19:57:35 +01:00
|
|
|
|
2016-05-13 15:00:22 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QtWidgets>
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
Constructor
|
|
|
|
*/
|
2016-05-13 15:00:22 +00:00
|
|
|
FolioAutonumberingW::FolioAutonumberingW(QETProject *project, QWidget *parent) :
|
2016-05-17 19:19:11 +00:00
|
|
|
QWidget(parent),
|
|
|
|
project_(project),
|
|
|
|
ui(new Ui::FolioAutonumberingW)
|
2016-05-13 15:00:22 +00:00
|
|
|
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
applyEnable(false);
|
|
|
|
ui->m_from_cb->setEnabled(false);
|
|
|
|
ui->m_new_tabs_sb->setEnabled(false);
|
|
|
|
ui->m_to_cb->setEnabled(false);
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
Destructor
|
|
|
|
*/
|
2016-05-13 15:00:22 +00:00
|
|
|
FolioAutonumberingW::~FolioAutonumberingW()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::setContext
|
2020-08-18 21:28:52 +02:00
|
|
|
construct autonums in the comboBox selected in the autonum_chooser QcomboBox
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
void FolioAutonumberingW::setContext(QList <QString> autonums)
|
|
|
|
{
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (QString str, autonums) { ui->m_autonums_cb->addItem(str);}
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::autoNumSelected
|
|
|
|
returns the current autonum selected
|
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
QString FolioAutonumberingW::autoNumSelected()
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
return ui->m_autonums_cb->currentText();
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::fromFolio
|
|
|
|
returns the current "From Folio" index
|
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
int FolioAutonumberingW::fromFolio()
|
|
|
|
{
|
2016-05-13 15:00:22 +00:00
|
|
|
return ui->m_from_cb->currentIndex()-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::toFolio
|
|
|
|
returns the current "To Folio" index
|
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
int FolioAutonumberingW::toFolio()
|
|
|
|
{
|
2016-05-13 15:00:22 +00:00
|
|
|
return ui->m_to_cb->currentIndex()+this->fromFolio()+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::newFoliosNumber
|
|
|
|
returns the number of folios to create
|
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
int FolioAutonumberingW::newFoliosNumber()
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
return ui->m_new_tabs_sb->value();
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
2020-07-15 17:43:20 +02:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::updateFolioList
|
|
|
|
update Folio List in From and To ComboBox
|
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
void FolioAutonumberingW::updateFolioList()
|
|
|
|
{
|
2020-07-15 17:43:20 +02:00
|
|
|
ui -> m_from_cb->clear();
|
|
|
|
ui -> m_to_cb->clear();
|
|
|
|
if (newFolios){
|
|
|
|
this -> on_m_create_new_tabs_rb_clicked();
|
|
|
|
} else {
|
|
|
|
this -> on_m_autonumber_tabs_rb_clicked();
|
|
|
|
}
|
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::on_m_create_new_tabs_rb_clicked
|
2016-05-13 15:00:22 +00:00
|
|
|
* Enable New Tabs SpinBox
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
void FolioAutonumberingW::on_m_create_new_tabs_rb_clicked()
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
ui->m_from_cb->setEnabled(false);
|
|
|
|
ui->m_to_cb->setEnabled(false);
|
|
|
|
ui->m_new_tabs_sb->setEnabled(true);
|
|
|
|
applyEnable();
|
|
|
|
newFolios = true;
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::on_m_autonumber_tabs_rb_clicked
|
2016-05-13 15:00:22 +00:00
|
|
|
* Enable From ComboBox, fill From ComboBox
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
void FolioAutonumberingW::on_m_autonumber_tabs_rb_clicked()
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
ui->m_new_tabs_sb->setEnabled(false);
|
|
|
|
ui->m_from_cb->setEnabled(true);
|
|
|
|
ui->m_to_cb->setEnabled(true);
|
|
|
|
if (ui->m_from_cb->count()<=0){
|
|
|
|
ui->m_from_cb->clear();
|
|
|
|
ui->m_from_cb->addItem("");
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach (Diagram *diagram, project_->diagrams()){
|
2016-05-17 19:19:11 +00:00
|
|
|
ui->m_from_cb->addItem(diagram->title());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applyEnable();
|
|
|
|
newFolios = false;
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::on_m_new_tabs_sb_valueChanged
|
2016-05-13 15:00:22 +00:00
|
|
|
* Enable Apply if any new folio is to be created
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
void FolioAutonumberingW::on_m_new_tabs_sb_valueChanged(int)
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
if (ui->m_new_tabs_sb->value()>0) applyEnable(true);
|
|
|
|
else applyEnable(false);
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief FolioAutonumberingW::on_m_from_cb_currentIndexChanged
|
2016-05-13 15:00:22 +00:00
|
|
|
* Enable To ComboBox
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
void FolioAutonumberingW::on_m_from_cb_currentIndexChanged(int)
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
int index = ui->m_from_cb->currentIndex();
|
|
|
|
ui->m_to_cb->clear();
|
|
|
|
if (index > 0){
|
|
|
|
ui->m_to_cb->setEnabled(true);
|
|
|
|
for (int i=index;i<project_->diagrams().size();i++)
|
2020-08-29 19:21:51 +02:00
|
|
|
ui->m_to_cb->addItem(project_
|
|
|
|
->diagrams().at(i)->title());
|
2016-05-17 19:19:11 +00:00
|
|
|
applyEnable(true);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
applyEnable();
|
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief SelectAutonumW::on_buttonBox_clicked
|
2020-08-18 21:28:52 +02:00
|
|
|
Action on buttonBox clicked
|
2020-08-16 11:19:36 +02:00
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
void FolioAutonumberingW::on_buttonBox_clicked(QAbstractButton *button)
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
//transform button to int
|
2016-05-13 15:00:22 +00:00
|
|
|
int answer = ui -> buttonBox -> buttonRole(button);
|
|
|
|
|
2016-05-17 19:19:11 +00:00
|
|
|
switch (answer) {
|
2016-05-13 15:00:22 +00:00
|
|
|
//help dialog - not implemented yet -
|
|
|
|
case QDialogButtonBox::HelpRole:
|
2020-08-18 21:29:12 +02:00
|
|
|
QMessageBox::information (
|
|
|
|
this,
|
|
|
|
tr("Folio Autonumbering",
|
|
|
|
"title window"),
|
|
|
|
tr("C'est ici que vous pouvez définir la manière dont seront numérotés les nouveaux folios.\n"
|
|
|
|
"-Une numérotation est composée d'une variable minimum.\n"
|
|
|
|
"-Vous pouvez ajouter ou supprimer une variable de numérotation par le biais des boutons - et +.\n"
|
|
|
|
"-Une variable de numérotation comprend : un type, une valeur et une incrémentation.\n"
|
|
|
|
|
|
|
|
"\n-les types \"Chiffre 1\", \"Chiffre 01\" et \"Chiffre 001\", représentent un type numérique défini dans le champ \"Valeur\", "
|
|
|
|
"qui s'incrémente à chaque nouveau folio de la valeur du champ \"Incrémentation\".\n"
|
|
|
|
"-\"Chiffre 01\" et \"Chiffre 001\", sont respectivement représentés sur le schéma par deux et trois digits minimum.\n"
|
|
|
|
"Si le chiffre défini dans le champ Valeur possède moins de digits que le type choisi,"
|
|
|
|
"celui-ci sera précédé par un ou deux 0 afin de respecter son type.\n"
|
|
|
|
|
|
|
|
"\n-Le type \"Texte\", représente un texte fixe.\nLe champ \"Incrémentation\" n'est pas utilisé.\n",
|
|
|
|
"help dialog about the folio autonumerotation"
|
|
|
|
));
|
2016-05-17 19:19:11 +00:00
|
|
|
break;
|
|
|
|
case QDialogButtonBox::ApplyRole:
|
|
|
|
applyEnable(true);
|
2016-05-13 15:00:22 +00:00
|
|
|
emit applyPressed();
|
2020-07-15 17:43:20 +02:00
|
|
|
updateFolioList();
|
2016-05-13 15:00:22 +00:00
|
|
|
break;
|
2016-05-17 19:19:11 +00:00
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief SelectAutonumW::applyEnable
|
|
|
|
enable/disable the apply button
|
|
|
|
*/
|
2020-08-29 19:21:51 +02:00
|
|
|
void FolioAutonumberingW::applyEnable(bool b)
|
|
|
|
{
|
2016-05-17 19:19:11 +00:00
|
|
|
if (b){
|
|
|
|
bool valid = true;
|
|
|
|
if (ui->m_create_new_tabs_rb->isChecked()){
|
|
|
|
if (ui->m_new_tabs_sb->value()==0) valid = false;
|
2020-08-29 19:21:51 +02:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Apply)
|
|
|
|
->setEnabled(valid);
|
2016-05-17 19:19:11 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (ui->m_to_cb->currentText()=="") valid = false;
|
2020-08-29 19:21:51 +02:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Apply)
|
|
|
|
->setEnabled(valid);
|
2016-05-17 19:19:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2020-08-29 19:21:51 +02:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Apply)
|
|
|
|
->setEnabled(b);
|
2016-05-17 19:19:11 +00:00
|
|
|
}
|
2016-05-13 15:00:22 +00:00
|
|
|
}
|