OSSP CVS Repository

ossp - Difference in ossp-pkg/as/as-gui/as_dataop.cpp versions 1.10 and 1.11
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/as/as-gui/as_dataop.cpp 1.10 -> 1.11

--- as_dataop.cpp        2002/12/02 13:25:36     1.10
+++ as_dataop.cpp        2002/12/03 17:34:19     1.11
@@ -62,52 +62,62 @@
 {
     bool bValid = true; // Used to warn on invalid accounting data
     int nIter = 0;      // Iterator used in loop and also as a count
+    QString Line;       // Used for linewise editing and whitespace eating
+
+    // Strip out extra line feeds at stream start
+    while (Line.isEmpty() && !Tstream.atEnd())
+        Line = Tstream.readLine();
 
     // Optimize viewing by repainting cells only once after processing
     m_pMaintable->setUpdatesEnabled(false);
 
     // Set the table text by linewise reading from the input stream
     // and parsing date, time, account, and other columns out of it
-    while (!Tstream.atEnd()) {
-        QString Date, Account, Amount, Remark;      // Fields of a valid AS file
-
-        QString Temp;                               // Used for linewise editing
-        while (Temp.isEmpty() && !Tstream.atEnd())  // Strip out extra line feed
-            Temp = Tstream.readLine();
-        QTextStream Asline(&Temp, IO_ReadOnly);     // Convert a single line now
+    while (!Line.isEmpty()) {
+        QString Date, Account, Amount, Remark;  // Fields of a valid AS file
+        QTextStream Asline(&Line, IO_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);
 
-        Asline >> Date; // Copy the date field
+        Asline.skipWhiteSpace();    // Remove whitespaces
+        Asline >> Date;             // Copy the date field
         if (Date != NULL)
             m_pMaintable->setText(nIter, 0, Date);
         else
             bValid = false;
 
-        Asline >> Account;  // Copy to the bit bucket
-        Asline >> Account;  // Copy the account field
+        Asline >> Account;          // Copy to the bit bucket
+
+        Asline.skipWhiteSpace();    // Remove whitespaces
+        Asline >> Account;          // Copy the account field
         if (Account != NULL) {
             m_pMaintable->setItem(nIter, 4, new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Account));
         }
         else
             bValid = false;
 
-        Asline >> Amount;   // Copy the amount field
+        Asline.skipWhiteSpace();    // Remove whitespaces
+        Asline >> Amount;           // Copy the amount field
         if (Amount != NULL)
             m_pMaintable->setText(nIter, 3, Amount);
         else
             bValid = false;
 
-        Remark = Asline.read(); // Copy the remark field
+        Asline.skipWhiteSpace();    // Remove whitespaces
+        Remark = Asline.read();     // Copy the remark field
         if (Remark != NULL)
             m_pMaintable->setText(nIter, 5, Remark);
 
-        nIter++; // The big increment
+        nIter++;    // The big increment
+        Line = "";  // Clear line for next round
+
+        while (Line.isEmpty() && !Tstream.atEnd())  // Strip and get
+            Line = Tstream.readLine();              // the new line
     }
 
     m_pMaintable->setUpdatesEnabled(true);      // Update and repaint
-    m_pMaintable->setNumRows(nIter - 1);        // Trim excess rows
+    m_pMaintable->setNumRows(nIter);            // No excess rows
     m_pMaintable->setCurrentCell(nIter - 1, 0); // Move focus to last row
 
     if (!bValid)
@@ -143,7 +153,7 @@
     bool bValid = true;                             // Warn on invalid data
 
     // Linewise save from the main table date, time, account, and others
-    for (int nIter = 0; nIter <= nRows; nIter++) {
+    for (int nIter = 0; nIter < nRows; nIter++) {
         Tempfield = m_pMaintable->text(nIter, 0);   // Load date field text
         if (Tempfield != NULL)
             Tstream << Tempfield;                   // Save date field text

CVSTrac 2.0.1