OSSP CVS Repository

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

Check-in Number: 2884
Date: 2002-Nov-25 00:11:56 (local)
2002-Nov-24 23:11:56 (UTC)
User:ms
Branch:
Comment: Implemented table data saving to a local file, and began new accessor method group with setDirty().
Tickets:
Inspections:
Files:
ossp-pkg/as/as-gui/TODO      1.13 -> 1.14     1 inserted, 0 deleted
ossp-pkg/as/as-gui/as_dataop.cpp      1.5 -> 1.6     82 inserted, 9 deleted
ossp-pkg/as/as-gui/as_gui.cpp      1.19 -> 1.20     1 inserted, 1 deleted
ossp-pkg/as/as-gui/as_gui.h      1.21 -> 1.22     7 inserted, 2 deleted
ossp-pkg/as/as-gui/as_slot.cpp      1.10 -> 1.11     12 inserted, 23 deleted
ossp-pkg/titraq/TODO      1.13 -> 1.14     1 inserted, 0 deleted
ossp-pkg/titraq/tidatops.cpp      1.5 -> 1.6     82 inserted, 9 deleted
ossp-pkg/titraq/titraq.cpp      1.19 -> 1.20     1 inserted, 1 deleted
ossp-pkg/titraq/titraq.h      1.21 -> 1.22     7 inserted, 2 deleted
ossp-pkg/titraq/titslot.cpp      1.10 -> 1.11     12 inserted, 23 deleted

ossp-pkg/as/as-gui/TODO 1.13 -> 1.14

--- TODO 2002/11/24 20:39:31     1.13
+++ TODO 2002/11/24 23:11:56     1.14
@@ -25,6 +25,7 @@
 Generally maintain Preference class
   Implement missing interface methods
 Review destruction of all members, compare with setupPrefs
+Memory optimization needed in tidataops
 
 Dreams
 ------


ossp-pkg/as/as-gui/as_dataop.cpp 1.5 -> 1.6

--- as_dataop.cpp        2002/11/22 21:51:58     1.5
+++ as_dataop.cpp        2002/11/24 23:11:56     1.6
@@ -4,6 +4,7 @@
 #include "titrex.h"     // Exception classes
 #include "titabitem.h"  // For class RtTableItem
 
+
 //
 // Convenience method to load accounting data from a file
 //
@@ -16,7 +17,7 @@
     }
     else {
         if (!Fileobj.open(IO_ReadOnly)) // Try to open file
-            throw Genexcept("Could not open accounting file.");
+            throw Genexcept("Could not read open accounting file.");
         QTextStream Asentry(&Fileobj);  // Convert data to stream
         this->loadData(Asentry);        // Pass off to do the real work
         Fileobj.close();                // Finish fileop by closing
@@ -29,7 +30,7 @@
 void Titraqform::loadData(QTextStream &Tstream)
 {
     bool bValid = true; // Used to warn on invalid accounting data
-    int i = 0;          // Iterator used in loop and also as a count
+    int nIter = 0;      // Iterator used in loop and also as a count
 
     // Optimize viewing by repainting cells only once after processing
     m_pMaintable->setUpdatesEnabled(false);
@@ -44,41 +45,113 @@
             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
+        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
         if (Date != NULL)
-            m_pMaintable->setText(i, 0, Date);
+            m_pMaintable->setText(nIter, 0, Date);
         else
             bValid = false;
 
         Asline >> Account;  // Copy to the bit bucket
         Asline >> Account;  // Copy the account field
         if (Account != NULL) {
-            m_pMaintable->setItem(i, 4, new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Account));
+            m_pMaintable->setItem(nIter, 4, new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Account));
         }
         else
             bValid = false;
 
         Asline >> Amount;   // Copy the amount field
         if (Amount != NULL)
-            m_pMaintable->setText(i, 3, Amount);
+            m_pMaintable->setText(nIter, 3, Amount);
         else
             bValid = false;
 
         Remark = Asline.read(); // Copy the remark field
         if (Remark != NULL)
-            m_pMaintable->setText(i, 5, Remark);
+            m_pMaintable->setText(nIter, 5, Remark);
 
-        i++; // The big increment
+        nIter++; // The big increment
     }
 
     m_pMaintable->setUpdatesEnabled(true);  // Repaint all
-    m_pMaintable->setNumRows(i - 1);        // Trim unneeded rows
+    m_pMaintable->setNumRows(nIter - 1);    // Trim unneeded rows
     m_pRemark->setText(trUtf8("Loaded text goes here"));
     m_pRemark->setEdited(false);            // Reset widget
 
     if (!bValid)
         throw Genexcept("Warning, invalid accounting data.");
 }
+
+//
+// Convenience method to save accounting data to a file
+//
+void Titraqform::saveData(QFile &Fileobj)
+{
+    if (Fileobj.isOpen()) {             // Check state of file
+        Fileobj.flush();                // Begin processing file cleanly
+        QTextStream 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
+            throw Genexcept("Could not write open accounting file.");
+        QTextStream Asentry(&Fileobj);  // Convert data to stream
+        this->saveData(Asentry);        // Pass off to do the real work
+        Fileobj.close();                // Finish fileop by closing
+    }
+}
+
+//
+// Save accounting data to a stream
+//
+void Titraqform::saveData(QTextStream &Tstream)
+{
+    const int nRows = m_pMaintable->numRows();      // Max rows used in loop
+    QString Tempfield;                              // Current field string
+    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++) {
+        Tempfield = m_pMaintable->text(nIter, 0);   // Load date field text
+        if (Tempfield != NULL)
+            Tstream << Tempfield << trUtf8(" ");    // Save date field text
+        else
+            bValid = false;
+
+        Tstream << trUtf8("user ");                 // Save user field text
+
+/*        Tempfield = m_pMaintable->text(nIter, 1);   // Load start field text
+        if (Tempfield != NULL)
+            Tstream << Tempfield << trUtf8(" ");    // Save start field text
+        else
+            bValid = false;
+
+        Tempfield = m_pMaintable->text(nIter, 2);   // Load end field text
+        if (Tempfield != NULL)
+            Tstream << Tempfield << trUtf8(" ");    // Save end field text
+        else
+            bValid = false;*/
+
+        Tempfield = m_pMaintable->text(nIter, 4);   // Load amount field text
+        if (Tempfield != NULL)
+            Tstream << Tempfield << trUtf8(" ");    // Save amount field text
+        else
+            bValid = false;
+
+        Tempfield = m_pMaintable->text(nIter, 3);   // Load acct field text
+        if (Tempfield != NULL)
+            Tstream << Tempfield << trUtf8(" ");    // Save acct field text
+        else
+            bValid = false;
+
+        Tempfield = m_pMaintable->text(nIter, 5);   // Load remark field text
+        if (Tempfield != NULL)
+            Tstream << Tempfield << trUtf8(" ");    // Save remark field text
+        else
+            bValid = false;
+
+        Tstream << endl;                            // Append a newline
+    }
+}


ossp-pkg/as/as-gui/as_gui.cpp 1.19 -> 1.20

--- as_gui.cpp   2002/11/24 20:39:32     1.19
+++ as_gui.cpp   2002/11/24 23:11:56     1.20
@@ -23,7 +23,7 @@
     QMainWindow(pParent, kszName, Flags)
 {
     // Early member initialization
-    m_bDirt = false;
+    this->setDirty(false);
     m_szFilename = new QString();
 
     // Initial widget manipulations


ossp-pkg/as/as-gui/as_gui.h 1.21 -> 1.22

--- as_gui.h     2002/11/24 20:39:32     1.21
+++ as_gui.h     2002/11/24 23:11:56     1.22
@@ -120,10 +120,13 @@
     QString     *m_szFilename;
 
     // Standard members
-    bool        m_bDirt;                // To track dirty and clean states
+    bool        m_bDirt;                    // To track dirty and clean states
 
     // Standard methods
-    bool isDirty(void);                 // Check for changed state danger
+    bool isDirty(void) {return m_bDirt;};    // Check for changed state danger
+
+    // Accessor methods
+    void setDirty(bool bDirty = true) {m_bDirt = bDirty;};  // Clean or dirty
 
     // Constructor helpers
     void setupPrefs(void);              // Preferences
@@ -140,6 +143,8 @@
     // Data processing
     void loadData(QFile &);             // Load accounting data from file
     void loadData(QTextStream &);       // Load accounting data from stream
+    void saveData(QFile &);             // Save accounting data to file
+    void saveData(QTextStream &);       // Save accounting data to stream
 };
 
 #endif // TITRAQMWIN_H


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

--- as_slot.cpp  2002/11/22 21:51:58     1.10
+++ as_slot.cpp  2002/11/24 23:11:56     1.11
@@ -70,8 +70,10 @@
         catch (Genexcept& Genex) {
             Genex.reportErr();
         }
-        setCaption(Filestring);
+        // Reset and give output to main window
+        this->setCaption(Filestring);
         m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
+        this->setDirty(false);          // Set the clean state
     }
     else
         m_pStatbar->message(trUtf8("Loading aborted"), 4000);
@@ -90,21 +92,16 @@
 
     // Try to open a file for writing to
     QFile Filetemp(*m_szFilename);
-    if (!Filetemp.open(IO_WriteOnly)) {
-        m_pStatbar->message(QString(trUtf8("Could not write to %1")).arg(*m_szFilename), 4000);
-        return;
+    try {
+        saveData(Filetemp); // Pass to helper method
     }
-
-    // Serialize file contents and write to text line
-    QTextStream Filestream(&Filetemp);
-    Filestream << m_pRemark->text();
-    Filetemp.close();
-
-    // Reset the text line, and give output to main window
-    m_pRemark->setEdited(FALSE);
-    setCaption(*m_szFilename);
-    m_pStatbar->message(QString(trUtf8("File %1 saved")).arg(*m_szFilename), 4000);
-    m_bDirt = false;    // Set the clean state to allow a close operation
+    catch (Genexcept& Genex) {
+        Genex.reportErr();
+    }
+    // Reset and give output to main window
+    this->setCaption(*m_szFilename);
+    m_pStatbar->message(trUtf8("File %1 saved").arg(*m_szFilename), 4000);
+    this->setDirty(false);  // Set the clean state to allow close
 }
 
 //
@@ -154,14 +151,6 @@
 }
 
 //
-// Check to see if state has changed since last save
-//
-bool Titraqform::isDirty(void)
-{
-    return m_bDirt;
-}
-
-//
 // Edit menu cut
 //
 void Titraqform::cut(void)






CVSTrac 2.0.1