From c26edb1302deeff5f4dc27e0ba5fcf5f81e4f37c Mon Sep 17 00:00:00 2001 From: hooper114 Date: Sun, 20 Sep 2009 15:40:46 +0000 Subject: [PATCH] Complete the export process --- frontend_qt4/exportwindow.cpp | 105 ++++++++++++++++++++++++++++++ frontend_qt4/exportwindow.h | 7 ++ frontend_qt4/extExport.ui | 109 +++++++++++++++++--------------- frontend_qt4/mainwindow.cpp | 2 +- frontend_qt4/sequencewindow.cpp | 24 ++++--- frontend_qt4/sequencewindow.h | 4 +- 6 files changed, 188 insertions(+), 63 deletions(-) diff --git a/frontend_qt4/exportwindow.cpp b/frontend_qt4/exportwindow.cpp index 6ba29135..40c27b6e 100644 --- a/frontend_qt4/exportwindow.cpp +++ b/frontend_qt4/exportwindow.cpp @@ -19,15 +19,120 @@ #include #include +#include +#include #include "exportwindow.h" +#include 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(); +} \ No newline at end of file diff --git a/frontend_qt4/exportwindow.h b/frontend_qt4/exportwindow.h index 1536f575..14a2fd57 100644 --- a/frontend_qt4/exportwindow.h +++ b/frontend_qt4/exportwindow.h @@ -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 \ No newline at end of file diff --git a/frontend_qt4/extExport.ui b/frontend_qt4/extExport.ui index f8019f44..dde34689 100644 --- a/frontend_qt4/extExport.ui +++ b/frontend_qt4/extExport.ui @@ -13,22 +13,6 @@ Export Barcodes - - - - 10 - 130 - 431 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - @@ -48,6 +32,9 @@ 22 + + bcs_ + @@ -58,6 +45,16 @@ 22 + + + Same as Data + + + + + Serial Number + + @@ -68,6 +65,21 @@ 22 + + + Portable Network Graphic (*.png) + + + + + Embedded Post Script (*.eps) + + + + + Scalable Vector Graphic (*.svg) + + @@ -112,7 +124,7 @@ 10 - 80 + 70 111 16 @@ -125,7 +137,7 @@ 10 - 110 + 100 111 16 @@ -134,40 +146,33 @@ File Format: + + + + 360 + 130 + 80 + 26 + + + + Cancel + + + + + + 270 + 130 + 80 + 26 + + + + OK + + - - - buttonBox - accepted() - ExportDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - ExportDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/frontend_qt4/mainwindow.cpp b/frontend_qt4/mainwindow.cpp index ebf5962a..177055f0 100644 --- a/frontend_qt4/mainwindow.cpp +++ b/frontend_qt4/mainwindow.cpp @@ -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(); } diff --git a/frontend_qt4/sequencewindow.cpp b/frontend_qt4/sequencewindow.cpp index ff79de7c..83f378a8 100644 --- a/frontend_qt4/sequencewindow.cpp +++ b/frontend_qt4/sequencewindow.cpp @@ -21,9 +21,11 @@ #include #include #include +#include #include "sequencewindow.h" #include "exportwindow.h" +#include 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(); } \ No newline at end of file diff --git a/frontend_qt4/sequencewindow.h b/frontend_qt4/sequencewindow.h index 54d591ab..0aa34469 100644 --- a/frontend_qt4/sequencewindow.h +++ b/frontend_qt4/sequencewindow.h @@ -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);