OSSP CVS Repository

ossp - Check-in [2868]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2868
Date: 2002-Nov-22 20:42:25 (local)
2002-Nov-22 19:42:25 (UTC)
User:ms
Branch:
Comment: Added exceptions to data ops, completed main static file loading logic, and removed hard coded table limits.
Tickets:
Inspections:
Files:
ossp-pkg/as/as-gui/TODO      1.9 -> 1.10     1 inserted, 0 deleted
ossp-pkg/as/as-gui/as_assist.cpp      1.8 -> 1.9     2 inserted, 7 deleted
ossp-pkg/as/as-gui/as_dataop.cpp      1.1 -> 1.2     56 inserted, 8 deleted
ossp-pkg/as/as-gui/as_gui.h      1.17 -> 1.18     1 inserted, 1 deleted
ossp-pkg/as/as-gui/as_slot.cpp      1.7 -> 1.8     13 inserted, 6 deleted
ossp-pkg/titraq/TODO      1.9 -> 1.10     1 inserted, 0 deleted
ossp-pkg/titraq/tidatops.cpp      1.1 -> 1.2     56 inserted, 8 deleted
ossp-pkg/titraq/titassist.cpp      1.8 -> 1.9     2 inserted, 7 deleted
ossp-pkg/titraq/titraq.h      1.17 -> 1.18     1 inserted, 1 deleted
ossp-pkg/titraq/titslot.cpp      1.7 -> 1.8     13 inserted, 6 deleted

ossp-pkg/as/as-gui/TODO 1.9 -> 1.10

--- TODO 2002/11/22 11:46:32     1.9
+++ TODO 2002/11/22 19:42:25     1.10
@@ -17,6 +17,7 @@
 configure soll ueberpruefen ob libqt[-mt] threads braucht,
   dann wenn so, soll den LIBS -pthread hardgecodet haben
 Report errors in all slot code and tidatops by throwing exceptions
+Make sure that exception is rethrown from second loadData on upwards
 
 Dreams
 ------


ossp-pkg/as/as-gui/as_assist.cpp 1.8 -> 1.9

--- as_assist.cpp        2002/11/21 15:37:08     1.8
+++ as_assist.cpp        2002/11/22 19:42:25     1.9
@@ -250,7 +250,6 @@
     m_pMaintable = new QTable(m_pCenframe, "Maintable");
     if (m_pMaintable == NULL)   // Sanity check
         throw Genexcept("Main window table creation failed.");
-    m_pMaintable->setNumRows(g_knRows);
     m_pMaintable->setNumCols(g_knCols);
     m_pMaintable->setReadOnly(true);                    // Table is read only
     m_pMaintable->setColumnMovingEnabled(false);        // Ctrl-drag disabled
@@ -259,7 +258,7 @@
     m_pMaintable->verticalHeader()->hide();     // by hiding it with a margin of 0
     m_pMaintable->horizontalHeader()->setResizeEnabled(false);
     m_pMaintable->setColumnStretchable(g_knCols - 1, true);
-    m_pMaintable->setSorting(true);
+    m_pMaintable->setSorting(false);
 
     // Table header row
     m_pTablehead = m_pMaintable->horizontalHeader();
@@ -271,11 +270,7 @@
     m_pTablehead->setLabel(4, QObject::trUtf8("Task"), 70);
     m_pTablehead->setLabel(5, QObject::trUtf8("Remark"));
 
-//    // Make a generic table item for all rows
-//    for (int i = 0; i < g_knRows; ++i)
-//        m_pMaintable->setItem(i, 0, new QTableItem(m_pMaintable, QTableItem::WhenCurrent, NULL));
-
-    m_pPackagelayout->addWidget(m_pMaintable); // Finally add the damn table
+    m_pPackagelayout->addWidget(m_pMaintable);  // Finally add the damn table
 }
 
 //


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.");
+}


ossp-pkg/as/as-gui/as_gui.h 1.17 -> 1.18

--- as_gui.h     2002/11/22 11:46:32     1.17
+++ as_gui.h     2002/11/22 19:42:25     1.18
@@ -21,7 +21,7 @@
 
 
 // Main table size
-const int g_knRows = 16;
+const int g_knBlocks = 32;
 const int g_knCols = 6;
 
 // Main application form window


ossp-pkg/as/as-gui/as_slot.cpp 1.7 -> 1.8

--- as_slot.cpp  2002/11/22 11:46:32     1.7
+++ as_slot.cpp  2002/11/22 19:42:25     1.8
@@ -3,6 +3,8 @@
 
 // User interface
 #include "titraq.h"             // Main classes
+#include "titrex.h"             // Exception classes
+#include "titabitem.h"          // For our custom table items
 #include "generic.h"            // Generic classes
 
 // Icon pixel maps
@@ -49,10 +51,9 @@
 //
 void Titraqform::newDoc(void)
 {
-    Prototype Unimp;
-    Unimp.doMbox();
-//    Titraqform *pNewform = new Titraqform;
-//    pNewform->show();
+    // The only way in Qt 3.X to clear rows efficiently
+    m_pMaintable->setNumRows(0);            // Get rid of any data in table
+    m_pMaintable->setNumRows(g_knBlocks);   // ...and then add them back in
 }
 
 //
@@ -62,8 +63,14 @@
 {
     QString Filestring = QFileDialog::getOpenFileName("/export/home/mschloh/tmp/bifftest/ms.txt", QString::null, this, trUtf8("Chooser Dialog"), trUtf8("Choose a file to open"));
     if (!Filestring.isEmpty()) {
-        QFile Filetemp(Filestring); // File to load
-        loadData(Filetemp);         // Pass to helper method
+        m_pMaintable->setNumRows(0);    // Clear out old data
+        QFile Filetemp(Filestring);     // File to load
+        try {
+            loadData(Filetemp);         // Pass to helper method
+        }
+        catch (Genexcept& Genex) {
+            Genex.reportErr();
+        }
         setCaption(Filestring);
         m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
     }






CVSTrac 2.0.1