diff -r e8292658d5b3 -r c1941114ca88 as_dataop.cpp --- a/as_dataop.cpp Fri Nov 28 14:20:00 2008 +0100 +++ b/as_dataop.cpp Fri Dec 05 23:14:02 2008 +0100 @@ -1,12 +1,12 @@ // // OSSP asgui - Accounting system graphical user interface -// Copyright (c) 2002-2004 The OSSP Project (http://www.ossp.org/) -// Copyright (c) 2002-2004 Ralf S. Engelschall -// Copyright (c) 2002-2004 Michael Schloh von Bennewitz -// Copyright (c) 2002-2004 Cable & Wireless Telecommunications Services GmbH +// Copyright (c) 2002-2008 The OSSP Project (http://www.ossp.org/) +// Copyright (c) 2002-2008 Ralf S. Engelschall +// Copyright (c) 2002-2008 Michael Schloh von Bennewitz +// Copyright (c) 2002-2008 Cable & Wireless Telecommunications Services GmbH // // This file is part of OSSP asgui, an accounting system graphical user -// interface which can be found at http://www.ossp.org/pkg/tool/asgui/. +// interface which can be found at http://asgui.europalab.com/. // // Permission to use, copy, modify, and distribute this software for // any purpose with or without fee is hereby granted, provided that @@ -29,6 +29,8 @@ // as_dataops.cpp: ISO C++ implementation // +#define QT3_SUPPORT + // System headers #include #include @@ -37,9 +39,11 @@ #include // Portable regular expressions #include #include -#include -#include +#include +#include #include +//Added by qt3to4: +#include // User interface #include "as_const.h" // Application constants @@ -61,18 +65,18 @@ { if (Fileobj.isOpen()) { // Check state of file Fileobj.flush(); // Begin processing file cleanly - QTextStream Account(&Fileobj); // Convert data to stream + Q3TextStream Account(&Fileobj); // Convert data to stream this->loadAccounts(Account); // Pass off to do the real work } else { - if (!Fileobj.open(IO_ReadOnly)) { // Try to open file + if (!Fileobj.open(QIODevice::ReadOnly)) { // Try to open file QString Readerrstr; Readerrstr = trUtf8(TITRAQ_READAFILFAIL).arg(Fileobj.name()); throw Genexcept(Readerrstr.ascii()); } else Fileobj.flush(); // Begin processing file cleanly - QTextStream Account(&Fileobj); // Convert data to stream + Q3TextStream Account(&Fileobj); // Convert data to stream this->loadAccounts(Account); // Pass off to do the real work Fileobj.close(); // Finish fileop by closing } @@ -81,7 +85,7 @@ // // Load accounts themselves data from a stream // -void Titraqform::loadAccounts(QTextStream &Tstream) +void Titraqform::loadAccounts(Q3TextStream &Tstream) { using namespace std; // Needed for hash tables with hmap map Hashnames; // Hashtable for storing names @@ -109,14 +113,14 @@ // stream and parsing the corresponding account fields out of it while (!Line.isEmpty()) { QString Temp; // For reading from stream - QTextStream Asline(&Line, IO_ReadOnly); // Convert a single line + Q3TextStream Asline(&Line, QIODevice::ReadOnly); // Convert a single line Asline.skipWhiteSpace(); // Remove whitespaces Asline >> Temp; // Copy revision indicator if (Temp == QString(QChar('R'))) { // Copy the account field Asline >> Temp; // to temporary for transfer - string Convstring = Temp; // Convert to string (can't cast?) + string Convstring = Temp.toStdString(); // Convert to string (can't cast?) Hashnames[Convstring] += Hashnames[Convstring]; } @@ -138,11 +142,11 @@ for (Numiter = Hashnums.begin(); Numiter != Hashnums.end(); Numiter++) { // Count the number of lines of sorted task names - int nNumlines = QString(Numiter->second).contains('\n'); + int nNumlines = QString::fromStdString(Numiter->second).count('\n'); // Iterate through the lines of task names, feeding them into the menu for (int nIter = 0; nIter < nNumlines; nIter++) - *m_pTaskentries << QString(Numiter->second).section('\n', nIter, nIter); + *m_pTaskentries << QString::fromStdString(Numiter->second).section('\n', nIter, nIter); } } @@ -153,15 +157,15 @@ { if (Fileobj.isOpen()) { // Check state of file Fileobj.flush(); // Begin processing file cleanly - QTextStream Asentry(&Fileobj); // Convert data to stream + Q3TextStream Asentry(&Fileobj); // Convert data to stream this->loadData(Asentry); // Pass off to do the real work } else { - if (!Fileobj.open(IO_ReadOnly)) // Try to open file + if (!Fileobj.open(QIODevice::ReadOnly)) // Try to open file throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); else Fileobj.flush(); // Begin processing file cleanly - QTextStream Asentry(&Fileobj); // Convert data to stream + Q3TextStream Asentry(&Fileobj); // Convert data to stream this->loadData(Asentry); // Pass off to do the real work Fileobj.close(); // Finish fileop by closing } @@ -170,7 +174,7 @@ // // Load personal data from a stream // -void Titraqform::loadData(QTextStream &Tstream) +void Titraqform::loadData(Q3TextStream &Tstream) { bool bValid = true; // Used to warn on globally invalid accounting data int nIter = 0; // Iterator used in loop and also as a count @@ -211,7 +215,7 @@ bool bValid = true; // Warns on linewise invalid accounting data QString User, Guid, Crc, Rev; // Valid admin fields QString Date, Start, Finish, Account, Amount, Remark; // Valid user fields - QTextStream Asline(&Line, IO_ReadOnly); // Convert a single line now + Q3TextStream Asline(&Line, QIODevice::ReadOnly); // Convert a single line now if (nIter % g_knBlocks == 0) // Add blocks of rows to optimize loading m_pMaintable->setNumRows(m_pMaintable->numRows() + g_knBlocks); @@ -269,10 +273,10 @@ Asline.skipWhiteSpace(); // Remove whitespaces Asline >> Account; // Copy the account field if (!Account.isEmpty()) { - QTableItem *pOld = m_pMaintable->item(nIter, TITRAQ_IDXTASK); + Q3TableItem *pOld = m_pMaintable->item(nIter, TITRAQ_IDXTASK); delete(pOld); // Get rid of the old before going with the new - RtTableItem *pSwapitem = new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Account); - pSwapitem->setAlignment(AlignLeft | AlignVCenter); + RtTableItem *pSwapitem = new RtTableItem(m_pMaintable, Q3TableItem::WhenCurrent, Account); + pSwapitem->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_pMaintable->setItem(nIter, TITRAQ_IDXTASK, pSwapitem); } else @@ -305,7 +309,7 @@ else { AS::Uuid Guidi; // For GUID production Guidi.genId(); - m_pMaintable->setText(nIter, TITRAQ_IDXGUID, Guidi.getString()); + m_pMaintable->setText(nIter, TITRAQ_IDXGUID, QString::fromStdString(Guidi.getString())); } } else // if isEmpty() @@ -364,13 +368,13 @@ { if (Fileobj.isOpen()) { // Check state of file Fileobj.flush(); // Begin processing file cleanly - QTextStream Asentry(&Fileobj); // Convert data to stream + Q3TextStream Asentry(&Fileobj); // Convert data to stream this->saveData(Asentry); // Pass off to do the real work } else { - if (!Fileobj.open(IO_WriteOnly)) // Try to open file + if (!Fileobj.open(QIODevice::WriteOnly)) // Try to open file throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); - QTextStream Asentry(&Fileobj); // Convert data to stream + Q3TextStream Asentry(&Fileobj); // Convert data to stream this->saveData(Asentry); // Pass off to do the real work Fileobj.close(); // Finish fileop by closing } @@ -379,7 +383,7 @@ // // Save accounting data to a stream // -void Titraqform::saveData(QTextStream &Tstream) +void Titraqform::saveData(Q3TextStream &Tstream) { const int nRows = m_pMaintable->numRows(); // Max rows used in loop QString Tempfield; // Current field string @@ -393,45 +397,45 @@ // Linewise save from the main table date, time, account, and others for (int nIter = 0; nIter < nRows; nIter++) { Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXUSER); // Load user field text - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << Tempfield; // Save user field text Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXGUID); // Load GUID field text - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << trUtf8(" ") << Tempfield; // Save GUID field text Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXCRC); // Load CRC field text Tempfield.remove("0x"); - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << trUtf8(" ") << Tempfield; // Save CRC field text Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXREV); // Load rev field text - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << trUtf8(" ") << Tempfield; // Save rev field text Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXDATE); // Load date field text - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << trUtf8(" ") << Tempfield; // Save date field text Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXSTART); // Load start field text - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << trUtf8(" ") << Tempfield; // Save start field text Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXFINISH); // Load end field text - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << trUtf8(" ") << Tempfield; // Save end field text Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXAMOUNT); // Load amount field text - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << trUtf8(" ") << Tempfield; // Save amount Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXTASK); // Load acct field text - if (Tempfield != NULL) + if (Tempfield.isNull()) Tstream << trUtf8(" ") << Tempfield; // Save acct field text Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXREMARK); // Load remark field text Tstream << trUtf8(" \""); // Save beginning double quote - if (Tempfield != NULL) { + if (Tempfield.isNull()) { Strsearch = QRegExp::escape(Tempfield); // Incoming string escaped Stripper.search(Strsearch); Tempfield.truncate(Stripper.pos()); // Cut off whitespace @@ -451,23 +455,25 @@ const bool Titraqform::validateData(QFile &Filin) const { QString Firstline; // Will contain the first line of text + char *pReadline; // Contains the read line of text file bool bRet = false; // Set the initial return value if (Filin.isOpen()) { // Check open state of file Filin.flush(); // Not sure if this is needed Filin.reset(); // Set the file index position to 0 - Filin.readLine(Firstline, QString(TITRAQ_DATAPATTERN).length() + 2L); + Filin.readLine(pReadline, QString(TITRAQ_DATAPATTERN).length() + 2L); } else { - if (!Filin.open(IO_ReadOnly)) // Try to open file + if (!Filin.open(QIODevice::ReadOnly)) // Try to open file throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); else { // File is now open - Filin.readLine(Firstline, QString(TITRAQ_DATAPATTERN).length() + 2L); + Filin.readLine(pReadline, QString(TITRAQ_DATAPATTERN).length() + 2L); Filin.close(); // Remember to close } } try { // Pass off to worker method + Firstline = QString::fromAscii(pReadline); bRet = this->validateData(Firstline); } catch (Genexcept &) { @@ -489,21 +495,21 @@ QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, TITRAQ_NOPATTERNFOUND + QString(TITRAQ_DATAPATTERN) + TITRAQ_WASNOTFOUNDIN, QMessageBox::Critical, QMessageBox::Ok | QMessageBox::Escape, - QMessageBox::NoButton, QMessageBox::NoButton); + Qt::NoButton, Qt::NoButton); Problema.exec(); // Give the user the bad news throw Genexcept(TITRAQ_INVALIDDATA); } else if (Linin.section(Datapattern, 1).section('.', 0, 0).toInt() != TITRAQ_DATAVERSIONMAJ) { QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, TITRAQ_BADVERSIONMAJ, QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Escape, - QMessageBox::NoButton, QMessageBox::NoButton); + Qt::NoButton, Qt::NoButton); Problema.exec(); // Give the user the bad news throw Genexcept(TITRAQ_INCOMPATDATA); } else if (Linin.section(Datapattern, 1).section('.', 1, 1).toInt() > TITRAQ_DATAVERSIONMIN) { QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, TITRAQ_BADVERSIONMIN, QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Escape, - QMessageBox::NoButton, QMessageBox::NoButton); + Qt::NoButton, Qt::NoButton); Problema.exec(); // Give the user the bad news throw Genexcept(TITRAQ_INCOMPATDATA); } @@ -519,7 +525,7 @@ const QString Titraqform::getRowdata(void) const { QString Rowdata, Tempstring; // For output string - QTableSelection Select = m_pMaintable->selection(0); // Highlighted text + Q3TableSelection Select = m_pMaintable->selection(0); // Highlighted text int nTotal = Select.bottomRow() - Select.topRow() + 1; // Total row select // Calculate rows to delete from selection highlight @@ -569,16 +575,16 @@ // void Titraqform::setRowdata(QString &Rowdata) const { - int nRows = Rowdata.contains(QChar('\n')); // Set so many rows + int nRows = Rowdata.count(QChar('\n')); // Set so many rows int nCurrentrow = m_pMaintable->currentRow(); // Current table row - QTableItem *pItem = NULL; // Old item to change out + Q3TableItem *pItem = NULL; // Old item to change out QString Line, User, Guid, Crc, Rev; // Admin fields in table QString Date, Start, Finish, Amount, Task, Remark; // Viewable fields in table - QTextStream Datastream(&Rowdata, IO_ReadOnly); // Convert data to stream + Q3TextStream Datastream(&Rowdata, QIODevice::ReadOnly); // Convert data to stream for (int nIter = 0; nIter < nRows; ++nIter) { QString Singlerow = Datastream.readLine(); // For linewise operation - QTextStream Rowstream(&Singlerow, IO_ReadOnly); // Convert row to stream + Q3TextStream Rowstream(&Singlerow, QIODevice::ReadOnly); // Convert row to stream Rowstream >> Line >> User >> Guid >> Crc >> Rev; // Stream data fields Rowstream >> Date >> Start >> Finish >> Amount >> Task; // to corresponding vars @@ -604,8 +610,8 @@ // Change out old item and replace with new task data pItem = m_pMaintable->item(nCurrentrow + nIter, TITRAQ_IDXTASK); delete(pItem); // Get rid of the old before going with the new - RtTableItem *pSwapitem = new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Task); - pSwapitem->setAlignment(AlignLeft | AlignVCenter); + RtTableItem *pSwapitem = new RtTableItem(m_pMaintable, Q3TableItem::WhenCurrent, Task); + pSwapitem->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_pMaintable->setItem(nCurrentrow + nIter, TITRAQ_IDXTASK, pSwapitem); // Continue with field processing business as usual