mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Complete the export process
This commit is contained in:
parent
318d2d4eed
commit
c26edb1302
@ -19,15 +19,120 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QUiLoader>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "exportwindow.h"
|
||||
#include <stdio.h>
|
||||
|
||||
ExportWindow::ExportWindow()
|
||||
{
|
||||
setupUi(this);
|
||||
linDestPath->setText(QDir::toNativeSeparators(QDir::homePath()));
|
||||
|
||||
connect(btnCancel, SIGNAL( clicked( bool )), SLOT(quit_now()));
|
||||
connect(btnOK, SIGNAL( clicked( bool )), SLOT(process()));
|
||||
connect(btnDestPath, SIGNAL( clicked( bool )), SLOT(get_directory()));
|
||||
}
|
||||
|
||||
ExportWindow::~ExportWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ExportWindow::quit_now()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void ExportWindow::get_directory()
|
||||
{
|
||||
QString directory;
|
||||
QFileDialog fdialog;
|
||||
|
||||
fdialog.setFileMode(QFileDialog::Directory);
|
||||
|
||||
if(fdialog.exec()) {
|
||||
directory = fdialog.selectedFiles().at(0);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
linDestPath->setText(QDir::toNativeSeparators(directory));
|
||||
}
|
||||
|
||||
void ExportWindow::process()
|
||||
{
|
||||
QString fileName;
|
||||
QString dataString;
|
||||
QString suffix;
|
||||
int lines, i, j, inputpos, datalen;
|
||||
|
||||
lines = output_data.count(QChar('\n'), Qt::CaseInsensitive);
|
||||
inputpos = 0;
|
||||
|
||||
switch(cmbFileFormat->currentIndex()) {
|
||||
case 0: suffix = ".png"; break;
|
||||
case 1: suffix = ".eps"; break;
|
||||
case 2: suffix = ".svg"; break;
|
||||
}
|
||||
|
||||
for(i = 0; i < lines; i++) {
|
||||
datalen = 0;
|
||||
for(j = inputpos; ((output_data[j] != '\n') && (j < output_data.length())); j++) {
|
||||
datalen++;
|
||||
}
|
||||
dataString = output_data.mid(inputpos, datalen);
|
||||
switch(cmbFileName->currentIndex()) {
|
||||
case 0: { /* Same as Data (URL Escaped) */
|
||||
QString url_escaped;
|
||||
int m;
|
||||
char name_char;
|
||||
QChar name_qchar;
|
||||
|
||||
for(m = 0; m < dataString.length(); m++) {
|
||||
name_qchar = dataString[m];
|
||||
name_char = name_qchar.toAscii();
|
||||
|
||||
switch(name_char) {
|
||||
case '\\': url_escaped += "%5C"; break;
|
||||
case '/': url_escaped += "%2F"; break;
|
||||
case ':': url_escaped += "%3A"; break;
|
||||
case '*': url_escaped += "%2A"; break;
|
||||
case '?': url_escaped += "%3F"; break;
|
||||
case '"': url_escaped += "%22"; break;
|
||||
case '<': url_escaped += "%3C"; break;
|
||||
case '>': url_escaped += "%3E"; break;
|
||||
case '|': url_escaped += "%7C"; break;
|
||||
case '%': url_escaped += "%25"; break;
|
||||
default: url_escaped += name_qchar; break;
|
||||
}
|
||||
}
|
||||
fileName = linDestPath->text() + QDir::separator() + linPrefix->text() + url_escaped + suffix;
|
||||
}
|
||||
break;
|
||||
case 1: { /* Formatted Serial Number */
|
||||
QString biggest, this_val, outnumber;
|
||||
int number_size, val_size, m;
|
||||
|
||||
biggest = QString::number(lines + 1);
|
||||
number_size = biggest.length();
|
||||
this_val = QString::number(i + 1);
|
||||
val_size = this_val.length();
|
||||
|
||||
for(m = 0; m < (number_size - val_size); m++) {
|
||||
outnumber += QChar('0');
|
||||
}
|
||||
|
||||
outnumber += this_val;
|
||||
|
||||
fileName = linDestPath->text() + QDir::separator() + linPrefix->text() + outnumber + suffix;
|
||||
}
|
||||
break;
|
||||
}
|
||||
barcode->bc.setText(dataString.toAscii().data());
|
||||
barcode->bc.save_to_file(fileName.toAscii().data());
|
||||
inputpos += datalen + 1;
|
||||
}
|
||||
close();
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
#define EXPORTWINDOW_H
|
||||
|
||||
#include "ui_extExport.h"
|
||||
#include "barcodeitem.h"
|
||||
|
||||
class ExportWindow : public QDialog, private Ui::ExportDialog
|
||||
{
|
||||
@ -29,7 +30,13 @@ class ExportWindow : public QDialog, private Ui::ExportDialog
|
||||
public:
|
||||
ExportWindow();
|
||||
~ExportWindow();
|
||||
BarcodeItem *barcode;
|
||||
QString output_data;
|
||||
|
||||
private slots:
|
||||
void quit_now();
|
||||
void process();
|
||||
void get_directory();
|
||||
};
|
||||
|
||||
#endif
|
@ -13,22 +13,6 @@
|
||||
<property name="windowTitle">
|
||||
<string>Export Barcodes</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>130</y>
|
||||
<width>431</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="linDestPath">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@ -48,6 +32,9 @@
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>bcs_</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="cmbFileName">
|
||||
<property name="geometry">
|
||||
@ -58,6 +45,16 @@
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Same as Data</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Serial Number</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="cmbFileFormat">
|
||||
<property name="geometry">
|
||||
@ -68,6 +65,21 @@
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Portable Network Graphic (*.png)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Embedded Post Script (*.eps)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Scalable Vector Graphic (*.svg)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="btnDestPath">
|
||||
<property name="geometry">
|
||||
@ -112,7 +124,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>80</y>
|
||||
<y>70</y>
|
||||
<width>111</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
@ -125,7 +137,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>110</y>
|
||||
<y>100</y>
|
||||
<width>111</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
@ -134,40 +146,33 @@
|
||||
<string>File Format:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btnCancel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>360</x>
|
||||
<y>130</y>
|
||||
<width>80</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btnOK">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>130</y>
|
||||
<width>80</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ExportDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ExportDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -156,7 +156,6 @@ bool MainWindow::save()
|
||||
{
|
||||
bool status;
|
||||
|
||||
/* Does nothing yet! */
|
||||
QString fileName = QFileDialog::getSaveFileName(this,
|
||||
tr("Save Barcode Image"), ".",
|
||||
tr("Barcode Images (*.png *.eps *.svg)"));
|
||||
@ -198,6 +197,7 @@ int MainWindow::open_data_dialog()
|
||||
int MainWindow::open_sequence_dialog()
|
||||
{
|
||||
SequenceWindow dlg;
|
||||
dlg.barcode = &m_bc;
|
||||
return dlg.exec();
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,11 @@
|
||||
#include <QFile>
|
||||
#include <QUiLoader>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "sequencewindow.h"
|
||||
#include "exportwindow.h"
|
||||
#include <stdio.h>
|
||||
|
||||
SequenceWindow::SequenceWindow()
|
||||
{
|
||||
@ -124,6 +126,7 @@ void SequenceWindow::create_sequence()
|
||||
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;
|
||||
}
|
||||
|
||||
@ -153,9 +156,8 @@ void SequenceWindow::import()
|
||||
QString fileName;
|
||||
QFileDialog fdialog;
|
||||
QFile file;
|
||||
char *streamdata;
|
||||
int streamlen;
|
||||
QString utfstream;
|
||||
QString outstream;
|
||||
char *c;
|
||||
|
||||
fdialog.setFileMode(QFileDialog::ExistingFile);
|
||||
|
||||
@ -166,14 +168,16 @@ void SequenceWindow::import()
|
||||
}
|
||||
|
||||
file.setFileName(fileName);
|
||||
if(!file.open(QIODevice::ReadOnly)) {
|
||||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QMessageBox::critical(this, tr("Open Error"), tr("Could not open selected file."));
|
||||
return;
|
||||
}
|
||||
|
||||
QDataStream input(&file);
|
||||
streamlen = input.readRawData(streamdata, 7095);
|
||||
utfstream = streamdata; /* FIXME: Does not take account of encoding scheme of input data */
|
||||
txtPreview->setPlainText(utfstream);
|
||||
|
||||
while(file.getChar(c)) {
|
||||
outstream += QChar(*c);
|
||||
}
|
||||
|
||||
txtPreview->setPlainText(outstream);
|
||||
file.close();
|
||||
}
|
||||
|
||||
@ -182,5 +186,7 @@ void SequenceWindow::generate_sequence()
|
||||
int returnval;
|
||||
|
||||
ExportWindow dlg;
|
||||
dlg.barcode = barcode;
|
||||
dlg.output_data = txtPreview->toPlainText();
|
||||
returnval = dlg.exec();
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
#define SEQUENCEWINDOW_H
|
||||
|
||||
#include "ui_extSequence.h"
|
||||
#include "barcodeitem.h"
|
||||
|
||||
class SequenceWindow : public QDialog, private Ui::SequenceDialog
|
||||
{
|
||||
@ -29,7 +30,8 @@ class SequenceWindow : public QDialog, private Ui::SequenceDialog
|
||||
public:
|
||||
SequenceWindow();
|
||||
~SequenceWindow();
|
||||
|
||||
BarcodeItem *barcode;
|
||||
|
||||
private:
|
||||
QString apply_format(QString raw_number);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user