1.1 --- a/as_dataop.cpp Fri Nov 28 14:20:00 2008 +0100 1.2 +++ b/as_dataop.cpp Fri Dec 05 23:14:02 2008 +0100 1.3 @@ -1,12 +1,12 @@ 1.4 // 1.5 // OSSP asgui - Accounting system graphical user interface 1.6 -// Copyright (c) 2002-2004 The OSSP Project (http://www.ossp.org/) 1.7 -// Copyright (c) 2002-2004 Ralf S. Engelschall <rse@engelschall.com> 1.8 -// Copyright (c) 2002-2004 Michael Schloh von Bennewitz <michael@schloh.com> 1.9 -// Copyright (c) 2002-2004 Cable & Wireless Telecommunications Services GmbH 1.10 +// Copyright (c) 2002-2008 The OSSP Project (http://www.ossp.org/) 1.11 +// Copyright (c) 2002-2008 Ralf S. Engelschall <rse@engelschall.com> 1.12 +// Copyright (c) 2002-2008 Michael Schloh von Bennewitz <michael@schloh.com> 1.13 +// Copyright (c) 2002-2008 Cable & Wireless Telecommunications Services GmbH 1.14 // 1.15 // This file is part of OSSP asgui, an accounting system graphical user 1.16 -// interface which can be found at http://www.ossp.org/pkg/tool/asgui/. 1.17 +// interface which can be found at http://asgui.europalab.com/. 1.18 // 1.19 // Permission to use, copy, modify, and distribute this software for 1.20 // any purpose with or without fee is hereby granted, provided that 1.21 @@ -29,6 +29,8 @@ 1.22 // as_dataops.cpp: ISO C++ implementation 1.23 // 1.24 1.25 +#define QT3_SUPPORT 1.26 + 1.27 // System headers 1.28 #include <map> 1.29 #include <string> 1.30 @@ -37,9 +39,11 @@ 1.31 #include <qregexp.h> // Portable regular expressions 1.32 #include <qdatetime.h> 1.33 #include <qmessagebox.h> 1.34 -#include <qtextstream.h> 1.35 -#include <qpopupmenu.h> 1.36 +#include <q3textstream.h> 1.37 +#include <q3popupmenu.h> 1.38 #include <qfile.h> 1.39 +//Added by qt3to4: 1.40 +#include <QPixmap> 1.41 1.42 // User interface 1.43 #include "as_const.h" // Application constants 1.44 @@ -61,18 +65,18 @@ 1.45 { 1.46 if (Fileobj.isOpen()) { // Check state of file 1.47 Fileobj.flush(); // Begin processing file cleanly 1.48 - QTextStream Account(&Fileobj); // Convert data to stream 1.49 + Q3TextStream Account(&Fileobj); // Convert data to stream 1.50 this->loadAccounts(Account); // Pass off to do the real work 1.51 } 1.52 else { 1.53 - if (!Fileobj.open(IO_ReadOnly)) { // Try to open file 1.54 + if (!Fileobj.open(QIODevice::ReadOnly)) { // Try to open file 1.55 QString Readerrstr; 1.56 Readerrstr = trUtf8(TITRAQ_READAFILFAIL).arg(Fileobj.name()); 1.57 throw Genexcept(Readerrstr.ascii()); 1.58 } 1.59 else 1.60 Fileobj.flush(); // Begin processing file cleanly 1.61 - QTextStream Account(&Fileobj); // Convert data to stream 1.62 + Q3TextStream Account(&Fileobj); // Convert data to stream 1.63 this->loadAccounts(Account); // Pass off to do the real work 1.64 Fileobj.close(); // Finish fileop by closing 1.65 } 1.66 @@ -81,7 +85,7 @@ 1.67 // 1.68 // Load accounts themselves data from a stream 1.69 // 1.70 -void Titraqform::loadAccounts(QTextStream &Tstream) 1.71 +void Titraqform::loadAccounts(Q3TextStream &Tstream) 1.72 { 1.73 using namespace std; // Needed for hash tables with hmap 1.74 map<string, int> Hashnames; // Hashtable for storing names 1.75 @@ -109,14 +113,14 @@ 1.76 // stream and parsing the corresponding account fields out of it 1.77 while (!Line.isEmpty()) { 1.78 QString Temp; // For reading from stream 1.79 - QTextStream Asline(&Line, IO_ReadOnly); // Convert a single line 1.80 + Q3TextStream Asline(&Line, QIODevice::ReadOnly); // Convert a single line 1.81 1.82 Asline.skipWhiteSpace(); // Remove whitespaces 1.83 Asline >> Temp; // Copy revision indicator 1.84 1.85 if (Temp == QString(QChar('R'))) { // Copy the account field 1.86 Asline >> Temp; // to temporary for transfer 1.87 - string Convstring = Temp; // Convert to string (can't cast?) 1.88 + string Convstring = Temp.toStdString(); // Convert to string (can't cast?) 1.89 Hashnames[Convstring] += Hashnames[Convstring]; 1.90 } 1.91 1.92 @@ -138,11 +142,11 @@ 1.93 for (Numiter = Hashnums.begin(); Numiter != Hashnums.end(); Numiter++) { 1.94 1.95 // Count the number of lines of sorted task names 1.96 - int nNumlines = QString(Numiter->second).contains('\n'); 1.97 + int nNumlines = QString::fromStdString(Numiter->second).count('\n'); 1.98 1.99 // Iterate through the lines of task names, feeding them into the menu 1.100 for (int nIter = 0; nIter < nNumlines; nIter++) 1.101 - *m_pTaskentries << QString(Numiter->second).section('\n', nIter, nIter); 1.102 + *m_pTaskentries << QString::fromStdString(Numiter->second).section('\n', nIter, nIter); 1.103 } 1.104 } 1.105 1.106 @@ -153,15 +157,15 @@ 1.107 { 1.108 if (Fileobj.isOpen()) { // Check state of file 1.109 Fileobj.flush(); // Begin processing file cleanly 1.110 - QTextStream Asentry(&Fileobj); // Convert data to stream 1.111 + Q3TextStream Asentry(&Fileobj); // Convert data to stream 1.112 this->loadData(Asentry); // Pass off to do the real work 1.113 } 1.114 else { 1.115 - if (!Fileobj.open(IO_ReadOnly)) // Try to open file 1.116 + if (!Fileobj.open(QIODevice::ReadOnly)) // Try to open file 1.117 throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); 1.118 else 1.119 Fileobj.flush(); // Begin processing file cleanly 1.120 - QTextStream Asentry(&Fileobj); // Convert data to stream 1.121 + Q3TextStream Asentry(&Fileobj); // Convert data to stream 1.122 this->loadData(Asentry); // Pass off to do the real work 1.123 Fileobj.close(); // Finish fileop by closing 1.124 } 1.125 @@ -170,7 +174,7 @@ 1.126 // 1.127 // Load personal data from a stream 1.128 // 1.129 -void Titraqform::loadData(QTextStream &Tstream) 1.130 +void Titraqform::loadData(Q3TextStream &Tstream) 1.131 { 1.132 bool bValid = true; // Used to warn on globally invalid accounting data 1.133 int nIter = 0; // Iterator used in loop and also as a count 1.134 @@ -211,7 +215,7 @@ 1.135 bool bValid = true; // Warns on linewise invalid accounting data 1.136 QString User, Guid, Crc, Rev; // Valid admin fields 1.137 QString Date, Start, Finish, Account, Amount, Remark; // Valid user fields 1.138 - QTextStream Asline(&Line, IO_ReadOnly); // Convert a single line now 1.139 + Q3TextStream Asline(&Line, QIODevice::ReadOnly); // Convert a single line now 1.140 1.141 if (nIter % g_knBlocks == 0) // Add blocks of rows to optimize loading 1.142 m_pMaintable->setNumRows(m_pMaintable->numRows() + g_knBlocks); 1.143 @@ -269,10 +273,10 @@ 1.144 Asline.skipWhiteSpace(); // Remove whitespaces 1.145 Asline >> Account; // Copy the account field 1.146 if (!Account.isEmpty()) { 1.147 - QTableItem *pOld = m_pMaintable->item(nIter, TITRAQ_IDXTASK); 1.148 + Q3TableItem *pOld = m_pMaintable->item(nIter, TITRAQ_IDXTASK); 1.149 delete(pOld); // Get rid of the old before going with the new 1.150 - RtTableItem *pSwapitem = new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Account); 1.151 - pSwapitem->setAlignment(AlignLeft | AlignVCenter); 1.152 + RtTableItem *pSwapitem = new RtTableItem(m_pMaintable, Q3TableItem::WhenCurrent, Account); 1.153 + pSwapitem->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); 1.154 m_pMaintable->setItem(nIter, TITRAQ_IDXTASK, pSwapitem); 1.155 } 1.156 else 1.157 @@ -305,7 +309,7 @@ 1.158 else { 1.159 AS::Uuid Guidi; // For GUID production 1.160 Guidi.genId(); 1.161 - m_pMaintable->setText(nIter, TITRAQ_IDXGUID, Guidi.getString()); 1.162 + m_pMaintable->setText(nIter, TITRAQ_IDXGUID, QString::fromStdString(Guidi.getString())); 1.163 } 1.164 } 1.165 else // if isEmpty() 1.166 @@ -364,13 +368,13 @@ 1.167 { 1.168 if (Fileobj.isOpen()) { // Check state of file 1.169 Fileobj.flush(); // Begin processing file cleanly 1.170 - QTextStream Asentry(&Fileobj); // Convert data to stream 1.171 + Q3TextStream Asentry(&Fileobj); // Convert data to stream 1.172 this->saveData(Asentry); // Pass off to do the real work 1.173 } 1.174 else { 1.175 - if (!Fileobj.open(IO_WriteOnly)) // Try to open file 1.176 + if (!Fileobj.open(QIODevice::WriteOnly)) // Try to open file 1.177 throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); 1.178 - QTextStream Asentry(&Fileobj); // Convert data to stream 1.179 + Q3TextStream Asentry(&Fileobj); // Convert data to stream 1.180 this->saveData(Asentry); // Pass off to do the real work 1.181 Fileobj.close(); // Finish fileop by closing 1.182 } 1.183 @@ -379,7 +383,7 @@ 1.184 // 1.185 // Save accounting data to a stream 1.186 // 1.187 -void Titraqform::saveData(QTextStream &Tstream) 1.188 +void Titraqform::saveData(Q3TextStream &Tstream) 1.189 { 1.190 const int nRows = m_pMaintable->numRows(); // Max rows used in loop 1.191 QString Tempfield; // Current field string 1.192 @@ -393,45 +397,45 @@ 1.193 // Linewise save from the main table date, time, account, and others 1.194 for (int nIter = 0; nIter < nRows; nIter++) { 1.195 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXUSER); // Load user field text 1.196 - if (Tempfield != NULL) 1.197 + if (Tempfield.isNull()) 1.198 Tstream << Tempfield; // Save user field text 1.199 1.200 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXGUID); // Load GUID field text 1.201 - if (Tempfield != NULL) 1.202 + if (Tempfield.isNull()) 1.203 Tstream << trUtf8(" ") << Tempfield; // Save GUID field text 1.204 1.205 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXCRC); // Load CRC field text 1.206 Tempfield.remove("0x"); 1.207 - if (Tempfield != NULL) 1.208 + if (Tempfield.isNull()) 1.209 Tstream << trUtf8(" ") << Tempfield; // Save CRC field text 1.210 1.211 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXREV); // Load rev field text 1.212 - if (Tempfield != NULL) 1.213 + if (Tempfield.isNull()) 1.214 Tstream << trUtf8(" ") << Tempfield; // Save rev field text 1.215 1.216 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXDATE); // Load date field text 1.217 - if (Tempfield != NULL) 1.218 + if (Tempfield.isNull()) 1.219 Tstream << trUtf8(" ") << Tempfield; // Save date field text 1.220 1.221 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXSTART); // Load start field text 1.222 - if (Tempfield != NULL) 1.223 + if (Tempfield.isNull()) 1.224 Tstream << trUtf8(" ") << Tempfield; // Save start field text 1.225 1.226 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXFINISH); // Load end field text 1.227 - if (Tempfield != NULL) 1.228 + if (Tempfield.isNull()) 1.229 Tstream << trUtf8(" ") << Tempfield; // Save end field text 1.230 1.231 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXAMOUNT); // Load amount field text 1.232 - if (Tempfield != NULL) 1.233 + if (Tempfield.isNull()) 1.234 Tstream << trUtf8(" ") << Tempfield; // Save amount 1.235 1.236 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXTASK); // Load acct field text 1.237 - if (Tempfield != NULL) 1.238 + if (Tempfield.isNull()) 1.239 Tstream << trUtf8(" ") << Tempfield; // Save acct field text 1.240 1.241 Tempfield = m_pMaintable->text(nIter, TITRAQ_IDXREMARK); // Load remark field text 1.242 Tstream << trUtf8(" \""); // Save beginning double quote 1.243 - if (Tempfield != NULL) { 1.244 + if (Tempfield.isNull()) { 1.245 Strsearch = QRegExp::escape(Tempfield); // Incoming string escaped 1.246 Stripper.search(Strsearch); 1.247 Tempfield.truncate(Stripper.pos()); // Cut off whitespace 1.248 @@ -451,23 +455,25 @@ 1.249 const bool Titraqform::validateData(QFile &Filin) const 1.250 { 1.251 QString Firstline; // Will contain the first line of text 1.252 + char *pReadline; // Contains the read line of text file 1.253 bool bRet = false; // Set the initial return value 1.254 1.255 if (Filin.isOpen()) { // Check open state of file 1.256 Filin.flush(); // Not sure if this is needed 1.257 Filin.reset(); // Set the file index position to 0 1.258 - Filin.readLine(Firstline, QString(TITRAQ_DATAPATTERN).length() + 2L); 1.259 + Filin.readLine(pReadline, QString(TITRAQ_DATAPATTERN).length() + 2L); 1.260 } 1.261 else { 1.262 - if (!Filin.open(IO_ReadOnly)) // Try to open file 1.263 + if (!Filin.open(QIODevice::ReadOnly)) // Try to open file 1.264 throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); 1.265 else { // File is now open 1.266 - Filin.readLine(Firstline, QString(TITRAQ_DATAPATTERN).length() + 2L); 1.267 + Filin.readLine(pReadline, QString(TITRAQ_DATAPATTERN).length() + 2L); 1.268 Filin.close(); // Remember to close 1.269 } 1.270 } 1.271 1.272 try { // Pass off to worker method 1.273 + Firstline = QString::fromAscii(pReadline); 1.274 bRet = this->validateData(Firstline); 1.275 } 1.276 catch (Genexcept &) { 1.277 @@ -489,21 +495,21 @@ 1.278 QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, 1.279 TITRAQ_NOPATTERNFOUND + QString(TITRAQ_DATAPATTERN) + TITRAQ_WASNOTFOUNDIN, 1.280 QMessageBox::Critical, QMessageBox::Ok | QMessageBox::Escape, 1.281 - QMessageBox::NoButton, QMessageBox::NoButton); 1.282 + Qt::NoButton, Qt::NoButton); 1.283 Problema.exec(); // Give the user the bad news 1.284 throw Genexcept(TITRAQ_INVALIDDATA); 1.285 } 1.286 else if (Linin.section(Datapattern, 1).section('.', 0, 0).toInt() != TITRAQ_DATAVERSIONMAJ) { 1.287 QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, 1.288 TITRAQ_BADVERSIONMAJ, QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Escape, 1.289 - QMessageBox::NoButton, QMessageBox::NoButton); 1.290 + Qt::NoButton, Qt::NoButton); 1.291 Problema.exec(); // Give the user the bad news 1.292 throw Genexcept(TITRAQ_INCOMPATDATA); 1.293 } 1.294 else if (Linin.section(Datapattern, 1).section('.', 1, 1).toInt() > TITRAQ_DATAVERSIONMIN) { 1.295 QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, 1.296 TITRAQ_BADVERSIONMIN, QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Escape, 1.297 - QMessageBox::NoButton, QMessageBox::NoButton); 1.298 + Qt::NoButton, Qt::NoButton); 1.299 Problema.exec(); // Give the user the bad news 1.300 throw Genexcept(TITRAQ_INCOMPATDATA); 1.301 } 1.302 @@ -519,7 +525,7 @@ 1.303 const QString Titraqform::getRowdata(void) const 1.304 { 1.305 QString Rowdata, Tempstring; // For output string 1.306 - QTableSelection Select = m_pMaintable->selection(0); // Highlighted text 1.307 + Q3TableSelection Select = m_pMaintable->selection(0); // Highlighted text 1.308 int nTotal = Select.bottomRow() - Select.topRow() + 1; // Total row select 1.309 1.310 // Calculate rows to delete from selection highlight 1.311 @@ -569,16 +575,16 @@ 1.312 // 1.313 void Titraqform::setRowdata(QString &Rowdata) const 1.314 { 1.315 - int nRows = Rowdata.contains(QChar('\n')); // Set so many rows 1.316 + int nRows = Rowdata.count(QChar('\n')); // Set so many rows 1.317 int nCurrentrow = m_pMaintable->currentRow(); // Current table row 1.318 - QTableItem *pItem = NULL; // Old item to change out 1.319 + Q3TableItem *pItem = NULL; // Old item to change out 1.320 QString Line, User, Guid, Crc, Rev; // Admin fields in table 1.321 QString Date, Start, Finish, Amount, Task, Remark; // Viewable fields in table 1.322 - QTextStream Datastream(&Rowdata, IO_ReadOnly); // Convert data to stream 1.323 + Q3TextStream Datastream(&Rowdata, QIODevice::ReadOnly); // Convert data to stream 1.324 1.325 for (int nIter = 0; nIter < nRows; ++nIter) { 1.326 QString Singlerow = Datastream.readLine(); // For linewise operation 1.327 - QTextStream Rowstream(&Singlerow, IO_ReadOnly); // Convert row to stream 1.328 + Q3TextStream Rowstream(&Singlerow, QIODevice::ReadOnly); // Convert row to stream 1.329 1.330 Rowstream >> Line >> User >> Guid >> Crc >> Rev; // Stream data fields 1.331 Rowstream >> Date >> Start >> Finish >> Amount >> Task; // to corresponding vars 1.332 @@ -604,8 +610,8 @@ 1.333 // Change out old item and replace with new task data 1.334 pItem = m_pMaintable->item(nCurrentrow + nIter, TITRAQ_IDXTASK); 1.335 delete(pItem); // Get rid of the old before going with the new 1.336 - RtTableItem *pSwapitem = new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Task); 1.337 - pSwapitem->setAlignment(AlignLeft | AlignVCenter); 1.338 + RtTableItem *pSwapitem = new RtTableItem(m_pMaintable, Q3TableItem::WhenCurrent, Task); 1.339 + pSwapitem->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); 1.340 m_pMaintable->setItem(nCurrentrow + nIter, TITRAQ_IDXTASK, pSwapitem); 1.341 1.342 // Continue with field processing business as usual