GUI: Retab data/export/sequencewindow.cpp (no code changes)

This commit is contained in:
gitlost 2020-10-27 15:21:50 +00:00
parent d2f86e01e6
commit 6bdd7e8509
3 changed files with 198 additions and 200 deletions

View file

@ -1,6 +1,6 @@
/*
Zint Barcode Generator - the open source barcode generator
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -16,8 +16,9 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* vim: set ts=4 sw=4 et : */
#include <QDebug>
//#include <QDebug>
#include <QFile>
#include <QUiLoader>
#include <QFileDialog>
@ -26,29 +27,28 @@
#include "sequencewindow.h"
#include "exportwindow.h"
#include <stdio.h>
SequenceWindow::SequenceWindow()
{
setupUi(this);
setupUi(this);
QSettings settings;
settings.setIniCodec("UTF-8");
QValidator *intvalid = new QIntValidator(this);
QValidator *intvalid = new QIntValidator(this);
linStartVal->setText(settings.value("studio/sequence/start_value", "1").toString());
linEndVal->setText(settings.value("studio/sequence/end_value", "10").toString());
linIncVal->setText(settings.value("studio/sequence/increment", "1").toString());
linFormat->setText(settings.value("studio/sequence/format", "$$$$$$").toString());
linStartVal->setText(settings.value("studio/sequence/start_value", "1").toString());
linEndVal->setText(settings.value("studio/sequence/end_value", "10").toString());
linIncVal->setText(settings.value("studio/sequence/increment", "1").toString());
linFormat->setText(settings.value("studio/sequence/format", "$$$$$$").toString());
linStartVal->setValidator(intvalid);
linEndVal->setValidator(intvalid);
linIncVal->setValidator(intvalid);
connect(btnClose, SIGNAL( clicked( bool )), SLOT(quit_now()));
connect(btnReset, SIGNAL( clicked( bool )), SLOT(reset_preview()));
connect(btnCreate, SIGNAL( clicked( bool )), SLOT(create_sequence()));
connect(txtPreview, SIGNAL( textChanged()), SLOT(check_generate()));
connect(btnImport, SIGNAL( clicked( bool )), SLOT(import()));
connect(btnExport, SIGNAL( clicked( bool )), SLOT(generate_sequence()));
linStartVal->setValidator(intvalid);
linEndVal->setValidator(intvalid);
linIncVal->setValidator(intvalid);
connect(btnClose, SIGNAL( clicked( bool )), SLOT(quit_now()));
connect(btnReset, SIGNAL( clicked( bool )), SLOT(reset_preview()));
connect(btnCreate, SIGNAL( clicked( bool )), SLOT(create_sequence()));
connect(txtPreview, SIGNAL( textChanged()), SLOT(check_generate()));
connect(btnImport, SIGNAL( clicked( bool )), SLOT(import()));
connect(btnExport, SIGNAL( clicked( bool )), SLOT(generate_sequence()));
}
SequenceWindow::~SequenceWindow()
@ -64,107 +64,107 @@ SequenceWindow::~SequenceWindow()
void SequenceWindow::quit_now()
{
close();
close();
}
void SequenceWindow::reset_preview()
{
txtPreview->clear();
txtPreview->clear();
}
QString SequenceWindow::apply_format(QString raw_number)
{
QString adjusted, reversed;
QString format;
int format_len, input_len, i, inpos;
QChar format_qchar;
QString adjusted, reversed;
QString format;
int format_len, input_len, i, inpos;
QChar format_qchar;
format = linFormat->text();
input_len = raw_number.length();
format_len = format.length();
format = linFormat->text();
input_len = raw_number.length();
format_len = format.length();
inpos = input_len;
inpos = input_len;
for(i = format_len; i > 0; i--) {
format_qchar = format[i - 1];
for(i = format_len; i > 0; i--) {
format_qchar = format[i - 1];
char format_char = format_qchar.toLatin1();
switch(format_char) {
case '#':
if (inpos > 0) {
adjusted += raw_number[inpos - 1];
inpos--;
} else {
adjusted += ' ';
}
break;
case '$':
if (inpos > 0) {
adjusted += raw_number[inpos - 1];
inpos--;
} else {
adjusted += '0';
}
break;
case '*':
if (inpos > 0) {
adjusted += raw_number[inpos - 1];
inpos--;
} else {
adjusted += '*';
}
break;
default:
adjusted += format_char;
break;
}
}
switch(format_char) {
case '#':
if (inpos > 0) {
adjusted += raw_number[inpos - 1];
inpos--;
} else {
adjusted += ' ';
}
break;
case '$':
if (inpos > 0) {
adjusted += raw_number[inpos - 1];
inpos--;
} else {
adjusted += '0';
}
break;
case '*':
if (inpos > 0) {
adjusted += raw_number[inpos - 1];
inpos--;
} else {
adjusted += '*';
}
break;
default:
adjusted += format_char;
break;
}
}
for(i = format_len; i > 0; i--) {
reversed += adjusted[i - 1];
}
for(i = format_len; i > 0; i--) {
reversed += adjusted[i - 1];
}
return reversed;
return reversed;
}
void SequenceWindow::create_sequence()
{
QString startval, endval, incval, part, outputtext;
int start, stop, step, i;
bool ok;
QString startval, endval, incval, part, outputtext;
int start, stop, step, i;
bool ok;
startval = linStartVal->text();
endval = linEndVal->text();
incval = linIncVal->text();
start = startval.toInt(&ok, 10);
stop = endval.toInt(&ok, 10);
step = incval.toInt(&ok, 10);
startval = linStartVal->text();
endval = linEndVal->text();
incval = linIncVal->text();
start = startval.toInt(&ok, 10);
stop = endval.toInt(&ok, 10);
step = incval.toInt(&ok, 10);
if((stop <= start) || (step <= 0)) {
QMessageBox::critical(this, tr("Sequence Error"), tr("One or more of the input values is incorrect."));
return;
}
if((stop <= start) || (step <= 0)) {
QMessageBox::critical(this, tr("Sequence Error"), tr("One or more of the input values is incorrect."));
return;
}
for(i = start; i <= stop; i += step) {
part = apply_format(QString::number(i, 10));
part += '\n';
outputtext += part;
}
for(i = start; i <= stop; i += step) {
part = apply_format(QString::number(i, 10));
part += '\n';
outputtext += part;
}
txtPreview->setPlainText(outputtext);
txtPreview->setPlainText(outputtext);
}
void SequenceWindow::check_generate()
{
QString preview_copy;
QString preview_copy;
preview_copy = txtPreview->toPlainText();
if(preview_copy.isEmpty()) {
btnExport->setEnabled(false);
lblExport->setEnabled(false);
} else {
btnExport->setEnabled(true);
lblExport->setEnabled(true);
}
preview_copy = txtPreview->toPlainText();
if(preview_copy.isEmpty()) {
btnExport->setEnabled(false);
lblExport->setEnabled(false);
} else {
btnExport->setEnabled(true);
lblExport->setEnabled(true);
}
}
void SequenceWindow::import()
@ -201,9 +201,8 @@ void SequenceWindow::import()
void SequenceWindow::generate_sequence()
{
ExportWindow dlg;
dlg.barcode = barcode;
dlg.output_data = txtPreview->toPlainText();
dlg.exec();
ExportWindow dlg;
dlg.barcode = barcode;
dlg.output_data = txtPreview->toPlainText();
dlg.exec();
}