OSSP CVS Repository

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

ossp-pkg/as/as-gui/as_dataop.cpp 1.1 -> 1.2

--- as_dataop.cpp        2002/11/22 11:46:32     1.1
+++ as_dataop.cpp        2002/11/22 19:42:25     1.2
@@ -1,4 +1,7 @@
-#include "titraq.h"
+#include <qregexp.h>    // Portable regular expressions
+
+#include "titraq.h"     // Main classes
+#include "titrex.h"     // Exception classes
 
 
 //
@@ -9,13 +12,13 @@
     if (Fileobj.isOpen()) {             // Check state of file
         Fileobj.flush();                // Begin processing file cleanly
         QTextStream Asentry(&Fileobj);  // Convert data to stream
-        loadData(Asentry);              // Pass off to do the real work
+        this->loadData(Asentry);        // Pass off to do the real work
     }
     else {
-        if (!Fileobj.open(IO_ReadOnly)) // Need a wrapped exception here,
-            return;                     // instead of a short circuit
+        if (!Fileobj.open(IO_ReadOnly)) // Try to open file
+            throw Genexcept("Could not open accounting file.");
         QTextStream Asentry(&Fileobj);  // Convert data to stream
-        loadData(Asentry);              // Pass off to do the real work
+        this->loadData(Asentry);        // Pass off to do the real work
         Fileobj.close();                // Finish fileop by closing
     }
 }
@@ -25,7 +28,52 @@
 //
 void Titraqform::loadData(QTextStream &Tstream)
 {
-    m_pRemark->setText(Tstream.readLine()); // Read from stream
-    m_pRemark->setEdited(false);            // Reset widget
-}
+    bool bValid = true; // Used to warn on invalid accounting data
+
+    // Set the table text by linewise reading from the input stream
+    // and parsing date, time, account, and other columns out of it
+    for (int i = 0; !Tstream.atEnd(); i++) {
+        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
+
+        if (i % g_knBlocks == 0) // Add blocks of rows to optimize loading speed
+            m_pMaintable->setNumRows(m_pMaintable->numRows() + g_knBlocks);
+
+        Asline >> Date; // Copy the date field
+        if (Date != NULL)
+            m_pMaintable->setText(i, 0, Date);
+        else
+            bValid = false;
 
+        Asline >> Account;  // Copy to the bit bucket
+        Asline >> Account;  // Copy the account field
+        if (Account != NULL) {
+            QRegExp Shorten("/(\\w+)$");
+            Account = QRegExp::escape(Account);
+            Account.remove(0, Shorten.search(Account));
+            m_pMaintable->setText(i, 4, Shorten.cap(Shorten.numCaptures()));
+        }
+        else
+            bValid = false;
+
+        Asline >> Amount;   // Copy the amount field
+        if (Amount != NULL)
+            m_pMaintable->setText(i, 3, Amount);
+        else
+            bValid = false;
+
+        Remark = Asline.read(); // Copy the remark field
+        if (Remark != NULL)
+            m_pMaintable->setText(i, 5, Remark);
+    }
+
+    m_pRemark->setText(trUtf8("Loaded text goes here"));
+    m_pRemark->setEdited(false);    // Reset widget
+
+    if (!bValid)
+        throw Genexcept("Warning, invalid accounting data.");
+}

CVSTrac 2.0.1