--- as_dataop.cpp 2002/12/12 17:14:49 1.18
+++ as_dataop.cpp 2002/12/12 18:48:16 1.19
@@ -30,15 +30,17 @@
//
// Qt general headers
-#include <qregexp.h> // Portable regular expressions
+#include <qregexp.h> // Portable regular expressions
// User interface
-#include "as_gui.h" // Main classes
-#include "as_except.h" // Exception classes
-#include "as_tableitem.h" // For class RtTableItem
+#include "as_gui.h" // Main classes
+#include "as_except.h" // Exception classes
+#include "as_tableitem.h" // For class RtTableItem
// Icon pixel maps
-#include "as_gfx/statok.xpm" // static const char *s_kpcStatokay_xpm[]
+#include "as_gfx/statok.xpm" // static const char *s_kpcStatokay_xpm[]
+#include "as_gfx/staterr.xpm" // static const char *s_kpcStaterror_xpm[]
+#include "as_gfx/statwrn.xpm" // static const char *s_kpcStatwarn_xpm[]
//
// Convenience method to load accounting data from a file
@@ -64,7 +66,7 @@
//
void Titraqform::loadData(QTextStream &Tstream)
{
- bool bValid = true; // Used to warn on invalid accounting data
+ bool bValid = true; // Used to warn on globally invalid accounting data
int nIter = 0; // Iterator used in loop and also as a count
QString Line; // Used for linewise editing and whitespace eating
QString Bitbucket; // Used for null device until we find a better way
@@ -79,6 +81,7 @@
// Set the table text by linewise reading from the input stream
// and parsing date, time, account, and other columns out of it
while (!Line.isEmpty()) {
+ bool bValid = true; // Warns on linewise invalid accounting data
QString User, Guid, Crc, Rev; // Valid admin fields
QString Date, Start, Finish, Account, Amount, Remark; // Valid user fields
QTextStream Asline(&Line, IO_ReadOnly); // Convert a single line now
@@ -88,63 +91,63 @@
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> User; // Copy the user field
- if (User != NULL)
+ if (!User.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXUSER, User);
else
bValid = false;
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> Guid; // Copy the GUID field
- if (Guid != NULL)
+ if (!Guid.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXGUID, Guid);
else
bValid = false;
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> Crc; // Copy the CRC field
- if (Crc != NULL)
+ if (!Crc.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXCRC, Crc);
else
bValid = false;
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> Rev; // Copy the rev field
- if (Rev != NULL)
+ if (!Rev.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXREV, Rev);
else
bValid = false;
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> Date; // Copy the date field
- if (Date != NULL)
+ if (!Date.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXDATE, Date);
else
bValid = false;
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> Start; // Copy the start field
- if (Start != NULL)
+ if (!Start.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXSTART, Start);
else
bValid = false;
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> Finish; // Copy the finish field
- if (Start != NULL)
+ if (!Start.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXFINISH, Finish);
else
bValid = false;
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> Amount; // Copy the amount field
- if (Amount != NULL)
+ if (!Amount.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXAMOUNT, Amount);
else
bValid = false;
Asline.skipWhiteSpace(); // Remove whitespaces
Asline >> Account; // Copy the account field
- if (Account != NULL) {
+ if (!Account.isEmpty()) {
QTableItem *pOld = m_pMaintable->item(nIter, TITRAQ_IDXTASK);
delete(pOld); // Get rid of the old before going with the new
m_pMaintable->setItem(nIter, TITRAQ_IDXTASK, new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Account));
@@ -154,11 +157,15 @@
Asline.skipWhiteSpace(); // Remove whitespaces
Remark = Asline.read(); // Copy the remark field
- if (Remark != NULL)
+ if (!Remark.isEmpty())
m_pMaintable->setText(nIter, TITRAQ_IDXREMARK, Remark);
- // Dynamically display status and line numbers
- m_pMaintable->setPixmap(nIter, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatokay_xpm));
+ if (bValid) // Show a bitmap to signal valid or error state
+ m_pMaintable->setPixmap(nIter, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatokay_xpm));
+ else
+ m_pMaintable->setPixmap(nIter, TITRAQ_IDXSTATUS, QPixmap(s_kpcStaterror_xpm));
+
+ // Insert a line number dynamically
m_pMaintable->setText(nIter, TITRAQ_IDXLINE, (QString::number(nIter)).rightJustify(4, QChar('0')));
nIter++; // The big increment
@@ -258,3 +265,88 @@
Tstream << endl; // Append a newline
}
}
+
+//
+// Get a whole row of data
+//
+const QString Titraqform::getRowdata(void) const
+{
+ QString Rowdata; // For output string
+ QTableSelection Select = m_pMaintable->selection(0); // Highlighted text
+ int nTotal = Select.bottomRow() - Select.topRow() + 1; // Total row select
+
+ // Calculate rows to delete from selection highlight
+ for (int nIter = 0; nIter < nTotal; ++nIter) {
+ // Build the row data string one field at a time, adding seps inbetween
+ Rowdata += m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXDATE);
+ Rowdata += trUtf8(TITRAQ_SEPARATORTOK);
+ // Rowdata += m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXUSER);
+ // Rowdata += trUtf8(TITRAQ_SEPARATORTOK);
+ Rowdata += m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXSTART);
+ Rowdata += trUtf8(TITRAQ_SEPARATORTOK);
+ Rowdata += m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXFINISH);
+ Rowdata += trUtf8(TITRAQ_SEPARATORTOK);
+ Rowdata += m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXAMOUNT);
+ Rowdata += trUtf8(TITRAQ_SEPARATORTOK);
+ Rowdata += m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXTASK);
+ Rowdata += trUtf8(TITRAQ_SEPARATORTOK);
+ Rowdata += m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXREMARK);
+ Rowdata += trUtf8("\n"); // Finish off line
+ }
+
+ return Rowdata;
+}
+
+//
+// Set a whole row of data
+//
+void Titraqform::setRowdata(QString &Rowdata) const
+{
+ int nRows = Rowdata.contains(QChar('\n')); // Set so many rows
+ int nCurrentrow = m_pMaintable->currentRow(); // Current table row
+ QTableItem *pItem = NULL; // Old item to change out
+ QString Date, Start, Finish, Amount, Task, Remark; // Text fields in table
+ QTextStream Datastream(&Rowdata, IO_ReadOnly); // Convert data to stream
+
+ for (int nIter = 0; nIter < nRows; ++nIter) {
+ Datastream >> Date >> Start; // Stream data fields
+ Datastream >> Finish >> Amount >> Task; // to corresponding vars
+ Datastream.skipWhiteSpace(); // Remove whitespaces
+ Remark = Datastream.readLine(); // Remark is a whole line
+
+ // Set the table row data one field at a time, skipping seps inbetween
+ m_pMaintable->setText(nCurrentrow + nIter, TITRAQ_IDXDATE, Date);
+// m_pMaintable->setText(nCurrentrow + nIter, TITRAQ_IDXUSER, User);
+ m_pMaintable->setText(nCurrentrow + nIter, TITRAQ_IDXSTART, Start);
+ m_pMaintable->setText(nCurrentrow + nIter, TITRAQ_IDXFINISH, Finish);
+ m_pMaintable->setText(nCurrentrow + nIter, TITRAQ_IDXAMOUNT, Amount);
+
+// // FIXME: Why doesn't this code change the RtTableItem text in place?
+// RtTableItem *pTask = NULL; // Derived and special
+// pItem = m_pMaintable->item(nCurrentrow + nIter, TITRAQ_IDXTASK);
+// pTask = static_cast<RtTableItem *>(pItem);
+// pTask->setText(Task);
+
+ // Change out old item and replace with new task data
+ pItem = m_pMaintable->item(nCurrentrow + nIter, TITRAQ_IDXTASK);
+ delete(pItem); // Get rid of the old before going with the new
+ m_pMaintable->setItem(nCurrentrow + nIter, TITRAQ_IDXTASK, new RtTableItem(m_pMaintable, QTableItem::WhenCurrent, Task));
+
+ // Continue with field processing business as usual
+ m_pMaintable->setText(nCurrentrow + nIter, TITRAQ_IDXREMARK, Remark);
+ }
+}
+
+//
+// Discover which column is the first in view
+//
+const int Titraqform::getFirstcol(void) const
+{
+ int nIter = 0; // Is both iterator in loop and column number returned
+
+ // Use column selector menu popup as sole key to determining column state
+ while (nIter < TITRAQ_IDXTAIL && !m_pColspopup->isItemChecked(m_pColspopup->idAt(++nIter)))
+ TITRAQ_NOP;
+
+ return nIter - 1; // Return one less to account for start of item offset
+}
|