Index: ossp-pkg/as/as-gui/TODO RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/TODO,v rcsdiff -q -kk '-r1.55' '-r1.56' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/TODO,v' 2>/dev/null --- TODO 2002/12/19 12:53:56 1.55 +++ TODO 2002/12/19 20:46:26 1.56 @@ -4,9 +4,6 @@ * * *************************************** -Consider --------- - Must do ------- Q_CHECK_PTR @@ -30,15 +27,18 @@ After every result write a status bar message On sort, selection should move with swapped rows On multiple selection, no text should appear in edit ctrls -Rework start/new/open/close/quit logic with disabled/enabled widgets Bugs ---- Overidden paintCell() might not work when called asynchronously? -When multiple new rows are added sometimes wrong row shading? Sometimes a click on add or delete toolbar button is ignored? Pressing escape on task data cells does not exit edit mode +When multiple new rows are added sometimes wrong row shading + Verified: Start prog, newDoc, addRow five times +On load, first row is duplicated and appended to end of matrix + Or: last row is duplicated, prepended to matrix, replaces a row there + Nice to have ------------ Implement an unlimited and generic undo and redo buffer class Index: ossp-pkg/as/as-gui/as_assist.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_assist.cpp,v rcsdiff -q -kk '-r1.75' '-r1.76' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_assist.cpp,v' 2>/dev/null --- as_assist.cpp 2002/12/18 14:50:58 1.75 +++ as_assist.cpp 2002/12/19 20:46:26 1.76 @@ -55,18 +55,23 @@ // User interface #include "as_gui.h" // Main classes -#include "as_except.h" // Exception classes #include "as_amount.h" // AmountBox class // Icon pixel maps #include "as_gfx/filenew.xpm" // static const char *s_kpcFilenew_xpm[] #include "as_gfx/fileopen.xpm" // static const char *s_kpcFileopen_xpm[] #include "as_gfx/filesave.xpm" // static const char *s_kpcFilesave_xpm[] +#include "as_gfx/filesaved.xpm" // static const char *s_kpcDfilesave_xpm[] #include "as_gfx/cut.xpm" // static const char *s_kpcCut_xpm[] +#include "as_gfx/cutd.xpm" // static const char *s_kpcDcut_xpm[] #include "as_gfx/copy.xpm" // static const char *s_kpcCopy_xpm[] +#include "as_gfx/copyd.xpm" // static const char *s_kpcDcopy_xpm[] #include "as_gfx/paste.xpm" // static const char *s_kpcPaste_xpm[] +#include "as_gfx/pasted.xpm" // static const char *s_kpcDcaste_xpm[] #include "as_gfx/rowadd.xpm" // static const char *s_kpcRowadd_xpm[] #include "as_gfx/rowdel.xpm" // static const char *s_kpcRowdel_xpm[] +#include "as_gfx/rowaddd.xpm" // static const char *s_kpcDrowadd_xpm[] +#include "as_gfx/rowdeld.xpm" // static const char *s_kpcDrowdel_xpm[] #include "as_gfx/osspicon.xpm" // static const char *s_kpcOsspicon_xpm[] #include "as_gfx/whatsthis.xpm" // static const char *s_kpcWhatsthis_xpm[] #include "as_gfx/statok.xpm" // static const char *s_kpcStatokay_xpm[] @@ -74,6 +79,7 @@ #include "as_gfx/statwrn.xpm" // static const char *s_kpcStatwarn_xpm[] #include "as_gfx/statvoid.xpm" // static const char *s_kpcStatvoid_xpm[] #include "as_gfx/refresh.xpm" // static const char *s_kpcRefresh_xpm[] +#include "as_gfx/refreshd.xpm" // static const char *s_kpcDrefresh_xpm[] // @@ -169,6 +175,25 @@ // void Titraqform::setupActions(void) { + QIconSet Saveiset, Cutiset, Copyiset, Pasteiset; + QIconSet Rowaddiset, Rowdeliset, Refreshiset; + + // Construct iconsets to use later for multistate action images + Saveiset.setPixmap(QPixmap(s_kpcFilesave_xpm), QIconSet::Automatic, QIconSet::Normal); + Saveiset.setPixmap(QPixmap(s_kpcDfilesave_xpm), QIconSet::Automatic, QIconSet::Disabled); + Cutiset.setPixmap(QPixmap(s_kpcCut_xpm), QIconSet::Automatic, QIconSet::Normal); + Cutiset.setPixmap(QPixmap(s_kpcDcut_xpm), QIconSet::Automatic, QIconSet::Disabled); + Copyiset.setPixmap(QPixmap(s_kpcCopy_xpm), QIconSet::Automatic, QIconSet::Normal); + Copyiset.setPixmap(QPixmap(s_kpcDcopy_xpm), QIconSet::Automatic, QIconSet::Disabled); + Pasteiset.setPixmap(QPixmap(s_kpcPaste_xpm), QIconSet::Automatic, QIconSet::Normal); + Pasteiset.setPixmap(QPixmap(s_kpcDpaste_xpm), QIconSet::Automatic, QIconSet::Disabled); + Rowaddiset.setPixmap(QPixmap(s_kpcRowadd_xpm), QIconSet::Automatic, QIconSet::Normal); + Rowaddiset.setPixmap(QPixmap(s_kpcDrowadd_xpm), QIconSet::Automatic, QIconSet::Disabled); + Rowdeliset.setPixmap(QPixmap(s_kpcRowdel_xpm), QIconSet::Automatic, QIconSet::Normal); + Rowdeliset.setPixmap(QPixmap(s_kpcDrowdel_xpm), QIconSet::Automatic, QIconSet::Disabled); + Refreshiset.setPixmap(QPixmap(s_kpcRefresh_xpm), QIconSet::Automatic, QIconSet::Normal); + Refreshiset.setPixmap(QPixmap(s_kpcDrefresh_xpm), QIconSet::Automatic, QIconSet::Disabled); + // First associate the graphics with MIME types QMimeSourceFactory::defaultFactory()->setPixmap("osspicon", QPixmap(s_kpcOsspicon_xpm)); QMimeSourceFactory::defaultFactory()->setPixmap("filenew", QPixmap(s_kpcFilenew_xpm)); @@ -206,7 +231,7 @@ m_pFileopenact->setWhatsThis(kszFileopentext); // File save current action - m_pFilesaveact = new QAction(trUtf8("Save File"), QPixmap(s_kpcFilesave_xpm), trUtf8("&Save"), CTRL+Key_S, this, "Save"); + m_pFilesaveact = new QAction(trUtf8("Save File"), Saveiset, trUtf8("&Save"), CTRL+Key_S, this, "Save"); if (m_pFilesaveact == NULL) // Sanity check throw Genexcept("Main window file save action creation failed."); connect(m_pFilesaveact, SIGNAL(activated()), this, SLOT(saveFile())); @@ -220,7 +245,7 @@ // File save selected action m_pFilesaveasact = new QAction(trUtf8("Save File As"), trUtf8("Save &As..."), 0, this, "SaveAs"); - if (m_pFilesaveasact == NULL) // Sanity check + if (m_pFilesaveasact == NULL) // Sanity check throw Genexcept("Main window file save as action creation failed."); connect(m_pFilesaveasact, SIGNAL(activated()), this, SLOT(saveAs())); m_pFilesaveasact->setWhatsThis(kszFilesavetext); @@ -236,9 +261,10 @@ if (m_pFilequitact == NULL) // Sanity check throw Genexcept("Main window file quit action creation failed."); connect(m_pFilequitact, SIGNAL(activated()), this, SLOT(close())); + connect(m_pFilequitact, SIGNAL(activated()), qApp, SLOT(quit())); // Cut action - m_pCutact = new QAction(trUtf8("Cut"), QPixmap(s_kpcCut_xpm), trUtf8("&Cut"), CTRL+Key_X, this, "Cut"); + m_pCutact = new QAction(trUtf8("Cut"), Cutiset, trUtf8("&Cut"), CTRL+Key_X, this, "Cut"); if (m_pCutact == NULL) // Sanity check throw Genexcept("Main window cut edit action creation failed."); connect(m_pCutact, SIGNAL(activated()), this, SLOT(cutEntry())); @@ -249,7 +275,7 @@ m_pCutact->setWhatsThis(kszCuttext); // Copy action - m_pCopyact = new QAction(trUtf8("Copy"), QPixmap(s_kpcCopy_xpm), trUtf8("&Copy"), CTRL+Key_C, this, "Copy"); + m_pCopyact = new QAction(trUtf8("Copy"), Copyiset, trUtf8("&Copy"), CTRL+Key_C, this, "Copy"); if (m_pCopyact == NULL) // Sanity check throw Genexcept("Main window copy edit action creation failed."); connect(m_pCopyact, SIGNAL(activated()), this, SLOT(copyEntry())); @@ -260,7 +286,7 @@ m_pCopyact->setWhatsThis(kszCopytext); // Paste action - m_pPasteact = new QAction(trUtf8("Paste"), QPixmap(s_kpcPaste_xpm), trUtf8("&Paste"), CTRL+Key_V, this, "Paste"); + m_pPasteact = new QAction(trUtf8("Paste"), Pasteiset, trUtf8("&Paste"), CTRL+Key_V, this, "Paste"); if (m_pPasteact == NULL) // Sanity check throw Genexcept("Main window paste edit action creation failed."); connect(m_pPasteact, SIGNAL(activated()), this, SLOT(pasteEntry())); @@ -271,7 +297,7 @@ m_pPasteact->setWhatsThis(kszPastetext); // Add data row action - m_pAddrowact = new QAction(trUtf8("Add Row"), QPixmap(s_kpcRowadd_xpm), trUtf8("&Add row"), Key_Insert, this, "Addrow"); + m_pAddrowact = new QAction(trUtf8("Add Row"), Rowaddiset, trUtf8("&Add row"), Key_Insert, this, "Addrow"); if (m_pAddrowact == NULL) // Sanity check throw Genexcept("Main window add row action creation failed."); connect(m_pAddrowact, SIGNAL(activated()), this, SLOT(addEntry())); @@ -282,7 +308,7 @@ m_pAddrowact->setWhatsThis(kszAddrowtext); // Delete data row action - m_pDelrowact = new QAction(trUtf8("Delete Row"), QPixmap(s_kpcRowdel_xpm), trUtf8("&Delete row"), Key_Delete, this, "Delrow"); + m_pDelrowact = new QAction(trUtf8("Delete Row"), Rowdeliset, trUtf8("&Delete row"), Key_Delete, this, "Delrow"); if (m_pDelrowact == NULL) // Sanity check throw Genexcept("Main window delete row action creation failed."); connect(m_pDelrowact, SIGNAL(activated()), this, SLOT(delEntry())); @@ -293,7 +319,7 @@ m_pDelrowact->setWhatsThis(kszDelrowtext); // Refresh data display action - m_pRefreshact = new QAction(trUtf8("Refresh Display"), QPixmap(s_kpcRefresh_xpm), trUtf8("&Refresh display"), CTRL+Key_R, this, "Refresh"); + m_pRefreshact = new QAction(trUtf8("Refresh Display"), Refreshiset, trUtf8("&Refresh display"), CTRL+Key_R, this, "Refresh"); if (m_pRefreshact == NULL) // Sanity check throw Genexcept("Main window refresh action creation failed."); connect(m_pRefreshact, SIGNAL(activated()), this, SLOT(refreshDisplay())); @@ -487,7 +513,7 @@ throw Genexcept("Main window central frame creation failed."); m_pCenframe->setFrameShape(QFrame::StyledPanel); m_pCenframe->setFrameShadow(QFrame::Sunken); - setCentralWidget(m_pCenframe); + this->setCentralWidget(m_pCenframe); // Layout controls for table, editing widgets m_pMainlayout = new QVBoxLayout(m_pCenframe, TITRAQ_MARGIN, TITRAQ_SPACING, "Mainlayout"); // For layouts @@ -518,16 +544,15 @@ // void Titraqform::setupTable(void) { - // The table itself + // Create, configure, and setup the table itself m_pMaintable = new TiTable(m_pCenframe, "Maintable"); if (m_pMaintable == NULL) // Sanity check throw Genexcept("Main window table creation failed."); m_pMaintable->setNumCols(TITRAQ_IDXTAIL); + m_pMaintable->setDirty(false); // Reset data to clean state m_pMaintable->setReadOnly(true); // Table is read only - m_pMaintable->setEnabled(false); // Table starts disabled m_pMaintable->setColumnMovingEnabled(false); // Ctrl-drag disabled m_pMaintable->setSelectionMode(QTable::MultiRow); // Multi row selection - m_pMaintable->setCurrentCell(-1, 0); // Initial row value -1 m_pMaintable->setFocusStyle(QTable::FollowStyle); // How cells are drawn m_pMaintable->setLeftMargin(0); // Get rid of the vertical header m_pMaintable->verticalHeader()->hide(); // by hiding it with a margin of 0 @@ -889,3 +914,41 @@ m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR), false); } } + +// +// [En|dis]able most ui pieces to suit or restrict user +// +void Titraqform::enableIface(bool bTurned) +{ + if (!bTurned) + m_pMaintable->setNumRows(0); // Remove table data + + // Enable or disable the widgets + m_pMaintable->setEnabled(bTurned); + m_pLineedit->setEnabled(bTurned); + m_pUseredit->setEnabled(bTurned); + m_pGuidedit->setEnabled(bTurned); + m_pCrcedit->setEnabled(bTurned); + m_pRevedit->setEnabled(bTurned); + m_pDateedit->setEnabled(bTurned); + m_pStarttime->setEnabled(bTurned); + m_pEndtime->setEnabled(bTurned); + m_pAmount->setEnabled(bTurned); + m_pTasks->setEnabled(bTurned); + m_pRemark->setEnabled(bTurned); + + // Enable or disable the actions + m_pFilesaveact->setEnabled(bTurned); + m_pFilesaveasact->setEnabled(bTurned); + m_pFilecloseact->setEnabled(bTurned); + m_pAddrowact->setEnabled(bTurned); + m_pDelrowact->setEnabled(bTurned); + m_pRefreshact->setEnabled(bTurned); + m_pCutact->setEnabled(bTurned); + m_pCopyact->setEnabled(bTurned); + m_pPasteact->setEnabled(bTurned); + + // Unconditional settings + this->updEdit(0, 0); // Update edit controls + m_pMaintable->setDirty(false); // Reset to clean data +} Index: ossp-pkg/as/as-gui/as_dataop.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_dataop.cpp,v rcsdiff -q -kk '-r1.29' '-r1.30' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_dataop.cpp,v' 2>/dev/null --- as_dataop.cpp 2002/12/19 12:53:56 1.29 +++ as_dataop.cpp 2002/12/19 20:46:26 1.30 @@ -34,7 +34,6 @@ // User interface #include "as_gui.h" // Main classes -#include "as_except.h" // Exception classes #include "as_tableitem.h" // For class RtTableItem // Icon pixel maps Index: ossp-pkg/as/as-gui/as_gui.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_gui.cpp,v rcsdiff -q -kk '-r1.32' '-r1.33' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_gui.cpp,v' 2>/dev/null --- as_gui.cpp 2002/12/18 14:50:58 1.32 +++ as_gui.cpp 2002/12/19 20:46:26 1.33 @@ -41,6 +41,15 @@ Titraqform::Titraqform(QWidget *pParent, const char *kszName, WFlags Flags) : QMainWindow(pParent, kszName, Flags) { + // Early initializations + m_pFiletools = NULL; + m_pEdittools = NULL; + m_pViewtools = NULL; + m_pWhatstools = NULL; + m_szFilename = NULL; + + // Atenzione! Order is very important in the following sequence. + // FIXME: Reorganize this procedural mess into self contained objects try { setupPrefs(); // Load general preferences setupActions(); // Create and initialize actions @@ -51,19 +60,20 @@ setupTable(); // Create and initialize table and cells setupEditlay(); // Create and initialize edit controls setupColumns(); // Prepare columns for viewing, sorting + enableIface(false); // Start things off in a empty state } catch (Genexcept& Genex) { Genex.reportErr(); exit(1); } - // Early initializations and manipulations - m_szFilename = new QString(); + // Postsetup manipulations m_pMaintable->setDirty(false); if (!kszName) setName(trUtf8("Titraqform")); resize(m_pPrefs->getNumber(TITRAQ_PREFFRAMEWIDTH, TITRAQ_DEFFRAMEWIDTH), m_pPrefs->getNumber(TITRAQ_PREFFRAMEHEIGHT, TITRAQ_DEFFRAMEHEIGHT)); + connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(savePrefs())); setCaption("OSSP Titraq"); // Rehydrate main window layout and doc positions Index: ossp-pkg/as/as-gui/as_gui.h RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_gui.h,v rcsdiff -q -kk '-r1.57' '-r1.58' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_gui.h,v' 2>/dev/null --- as_gui.h 2002/12/18 14:50:58 1.57 +++ as_gui.h 2002/12/19 20:46:26 1.58 @@ -48,6 +48,7 @@ #include #include +#include "as_except.h" // Exception classes #include "as_const.h" // For general constants #include "as_pref.h" // For class Preferences #include "as_amount.h" // For class AmountBox @@ -84,6 +85,32 @@ const QString getRowdata(void) const; // Get a whole row of data void setRowdata(QString &) const; // Set a whole row of data const int getFirstcol(void) const; // Learn which col is first + const bool isOpen(void) {return (m_szFilename == NULL) ? false : true;}; // Doc state + void setOpen(bool bDocopen = true) // Set state of document + { + if (bDocopen) { + if (m_szFilename == NULL) + m_szFilename = new QString(); + } + else + if (m_szFilename != NULL) { + delete m_szFilename; + m_szFilename = NULL; + } + }; + const QString *getFilename(void) // Get the current file name + { + if (this->isOpen()) + return m_szFilename; + else + throw Genexcept("File name does not exist."); + }; + void setFilename(const QString &Fname) // Set file name + { + if (this->isOpen()) // If a file name exists + setOpen(false); // then get rid of it first + m_szFilename = new QString(Fname); + }; // Top level members Preferences *m_pPrefs; @@ -93,9 +120,8 @@ QAction *m_pFilesaveact, *m_pFilesaveasact; QAction *m_pFilecloseact, *m_pFilequitact; QAction *m_pAddrowact, *m_pDelrowact; - QAction *m_pRefreshact; - QAction *m_pCutact, *m_pCopyact; - QAction *m_pPasteact, *m_pWritedataact; + QAction *m_pRefreshact, *m_pCutact; + QAction *m_pCopyact, *m_pPasteact; // Table, cells, and entries in package layout TiTable *m_pMaintable; @@ -208,6 +234,7 @@ void setupEditlay(void); // Editing lay void setupPieces(void); // Assemble widget pieces void setupColumns(void); // Arrange and configure columns + void enableIface(bool); // [En/dis]able most ui pieces // Data processing void loadAccounts(QFile &); // Load accounts from file Index: ossp-pkg/as/as-gui/as_main.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_main.cpp,v rcsdiff -q -kk '-r1.10' '-r1.11' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_main.cpp,v' 2>/dev/null --- as_main.cpp 2002/12/12 12:19:48 1.10 +++ as_main.cpp 2002/12/19 20:46:26 1.11 @@ -39,7 +39,5 @@ Titraqform Mainform; // Main app window App.setMainWidget(&Mainform); Mainform.show(); // Finally start the show - App.connect(&App, SIGNAL(lastWindowClosed()), &App, SLOT(quit())); - App.connect(&App, SIGNAL(aboutToQuit()), &Mainform, SLOT(savePrefs())); return App.exec(); } Index: ossp-pkg/as/as-gui/as_slot.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_slot.cpp,v rcsdiff -q -kk '-r1.72' '-r1.73' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_slot.cpp,v' 2>/dev/null --- as_slot.cpp 2002/12/19 13:23:35 1.72 +++ as_slot.cpp 2002/12/19 20:46:26 1.73 @@ -86,9 +86,6 @@ QString Selection; // Will receive the clipboard text QClipboard *pClip; // Will reference the global clipboard - // Optimize viewing by repainting cells only once after processing - m_pMaintable->setUpdatesEnabled(false); - if (Selection = pClip->text(QClipboard::Clipboard)) { // Windows and Unix nRows = Selection.contains(QChar('\n')); // How many rows this->addEntry(nRows); // Reuse slot @@ -102,8 +99,6 @@ for (int nIter = 0; nIter < nRows; nIter++) this->validateData(m_pMaintable->currentRow() + nIter, 0); } - - m_pMaintable->setUpdatesEnabled(true); // Update and repaint } // @@ -183,8 +178,8 @@ // uuid_unparse(Guid, szGuitext); // m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXGUID, szGuitext); - m_pMaintable->setUpdatesEnabled(true); // Turn updates back on - m_pMaintable->repaintContents(false); // Repaint viewport + m_pMaintable->setUpdatesEnabled(true); // Turn updates back on + m_pMaintable->repaintContents(true); // Do a general repaint of table } // @@ -232,7 +227,7 @@ nIter++; } - m_pMaintable->repaintContents(true); // Do a general repaint of table + m_pMaintable->repaintContents(false); // Do a general repaint of table m_pStatbar->message(trUtf8("Display was refreshed"), 4000); // Announce result } @@ -252,86 +247,29 @@ switch (nResult) { case 0: // First button selected, so save first this->saveFile(); // Save changes first - - // Reset widget text values before blanking table - m_pDateedit->setDate(*m_pDatezero); - m_pStarttime->setTime(QTime::QTime(0, 0)); - m_pEndtime->setTime(QTime::QTime(0, 0)); - m_pAmount->setText(NULL); - m_pTasks->setCurrentText(NULL); - m_pRemark->setText(NULL); - - m_pMaintable->setEnabled(true); // Enable the table first - m_pMaintable->setNumRows(0); // Remove all data in table - m_pLineedit->setEnabled(true); - m_pUseredit->setEnabled(true); - m_pGuidedit->setEnabled(true); - m_pCrcedit->setEnabled(true); - m_pRevedit->setEnabled(true); - m_pDateedit->setEnabled(true); - m_pStarttime->setEnabled(true); - m_pEndtime->setEnabled(true); - m_pAmount->setEnabled(true); - m_pTasks->setEnabled(true); - m_pRemark->setEnabled(true); - this->updEdit(0, 0); // Reset edit controls - this->setCaption(trUtf8("No file name")); - m_pStatbar->message(trUtf8("New document"), 4000); - *m_szFilename = ""; // Blank the file name - m_pMaintable->setDirty(false); // Reset data to clean state break; - case 1: // Second button selected, so don't save first but do new - m_pMaintable->setEnabled(true); // Enable the table first - m_pMaintable->setNumRows(0); // Remove all data in table - m_pLineedit->setEnabled(true); - m_pUseredit->setEnabled(true); - m_pGuidedit->setEnabled(true); - m_pCrcedit->setEnabled(true); - m_pRevedit->setEnabled(true); - m_pDateedit->setEnabled(true); - m_pStarttime->setEnabled(true); - m_pEndtime->setEnabled(true); - m_pAmount->setEnabled(true); - m_pTasks->setEnabled(true); - m_pRemark->setEnabled(true); - this->updEdit(0, 0); // Reset edit controls - this->setCaption(trUtf8("No file name")); - m_pStatbar->message(trUtf8("New document"), 4000); - *m_szFilename = ""; // Blank the file name - m_pMaintable->setDirty(false); // Reset data to clean state + case 1: // Second button selected, so don't save break; - case 2: // Third button selected, so don't do a new timesheet + case 2: // Third button selected, so return sofort default: + return; break; } } - else { // Data is already up to date - // Reset widget text values before blanking table - m_pDateedit->setDate(*m_pDatezero); - m_pStarttime->setTime(QTime::QTime(0, 0)); - m_pEndtime->setTime(QTime::QTime(0, 0)); - m_pAmount->setText(NULL); - m_pTasks->setCurrentText(NULL); - m_pRemark->setText(NULL); - m_pMaintable->setEnabled(true); // Enable the table first - m_pMaintable->setNumRows(0); // Remove all data in table - m_pLineedit->setEnabled(true); - m_pUseredit->setEnabled(true); - m_pGuidedit->setEnabled(true); - m_pCrcedit->setEnabled(true); - m_pRevedit->setEnabled(true); - m_pDateedit->setEnabled(true); - m_pStarttime->setEnabled(true); - m_pEndtime->setEnabled(true); - m_pAmount->setEnabled(true); - m_pTasks->setEnabled(true); - m_pRemark->setEnabled(true); - this->updEdit(0, 0); // Reset edit controls - this->setCaption(trUtf8("No file name")); - m_pStatbar->message(trUtf8("New document"), 4000); - *m_szFilename = ""; // Blank the file name - m_pMaintable->setDirty(false); // Reset data to clean state - } + // Fall through to implicit new doc code + this->enableIface(true); // Enable the interface + m_pMaintable->setNumRows(0); // Remove all data in table + this->setCaption(trUtf8("No file name")); + m_pStatbar->message(trUtf8("New document"), 4000); + this->setFilename(""); + + // Reset widget text of edit controls + m_pDateedit->setDate(*m_pDatezero); + m_pStarttime->setTime(QTime::QTime(0, 0)); + m_pEndtime->setTime(QTime::QTime(0, 0)); + m_pAmount->setText(NULL); + m_pTasks->setCurrentText(NULL); + m_pRemark->setText(NULL); } // @@ -353,7 +291,7 @@ switch (nResult) { case 0: // Save first this->saveFile(); // Save changes first - m_szFilename->operator=(Filestring); + setFilename(Filestring); // Set the new file name m_pMaintable->setNumRows(0); // Clear out old data try { loadData(Filetemp); // Pass to helper method @@ -361,25 +299,9 @@ catch (Genexcept& Genex) { Genex.reportErr(); } - // Reset and give output to main window - this->setCaption(Filestring); - m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); - m_pMaintable->setEnabled(true); // Enable the table first - m_pLineedit->setEnabled(true); - m_pUseredit->setEnabled(true); - m_pGuidedit->setEnabled(true); - m_pCrcedit->setEnabled(true); - m_pRevedit->setEnabled(true); - m_pDateedit->setEnabled(true); - m_pStarttime->setEnabled(true); - m_pEndtime->setEnabled(true); - m_pAmount->setEnabled(true); - m_pTasks->setEnabled(true); - m_pRemark->setEnabled(true); - m_pMaintable->setDirty(false); // Set the clean state break; case 1: // Don't save first but do load - m_szFilename->operator=(Filestring); + setFilename(Filestring); // Set the new file name m_pMaintable->setNumRows(0); // Clear out old data try { loadData(Filetemp); // Pass to helper method @@ -387,22 +309,6 @@ catch (Genexcept& Genex) { Genex.reportErr(); } - // Reset and give output to main window - this->setCaption(Filestring); - m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); - m_pMaintable->setEnabled(true); // Enable the table first - m_pLineedit->setEnabled(true); - m_pUseredit->setEnabled(true); - m_pGuidedit->setEnabled(true); - m_pCrcedit->setEnabled(true); - m_pRevedit->setEnabled(true); - m_pDateedit->setEnabled(true); - m_pStarttime->setEnabled(true); - m_pEndtime->setEnabled(true); - m_pAmount->setEnabled(true); - m_pTasks->setEnabled(true); - m_pRemark->setEnabled(true); - m_pMaintable->setDirty(false); // Set the clean state break; case 2: // Don't do a load timesheet default: @@ -410,31 +316,20 @@ } } else { - m_szFilename->operator=(Filestring); - m_pMaintable->setNumRows(0); // Clear out old data + setFilename(Filestring); // Set the new file name + m_pMaintable->setNumRows(0); // Clear out old data try { - loadData(Filetemp); // Pass to helper method + loadData(Filetemp); // Pass to helper method } catch (Genexcept& Genex) { Genex.reportErr(); } - // Reset and give output to main window - this->setCaption(Filestring); - m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); - m_pMaintable->setEnabled(true); // Enable the table first - m_pLineedit->setEnabled(true); - m_pUseredit->setEnabled(true); - m_pGuidedit->setEnabled(true); - m_pCrcedit->setEnabled(true); - m_pRevedit->setEnabled(true); - m_pDateedit->setEnabled(true); - m_pStarttime->setEnabled(true); - m_pEndtime->setEnabled(true); - m_pAmount->setEnabled(true); - m_pTasks->setEnabled(true); - m_pRemark->setEnabled(true); - m_pMaintable->setDirty(false); // Set the clean state } + + // Fall through to implicit open code + this->setCaption(Filestring); + m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); + this->enableIface(true); // Turn on the lights } else m_pStatbar->message(trUtf8("Loading aborted"), 4000); @@ -445,23 +340,24 @@ // void Titraqform::saveFile(void) { - // First time saves are really just saveAs in disguise - if (m_szFilename->isEmpty()) { - saveAs(); - return; - } - - // Try to open a file for writing to - QFile Filetemp(*m_szFilename); + QString Fname; try { - saveData(Filetemp); // Pass to helper method + Fname = QString(*this->getFilename()); + // First time saves are really just saveAs in disguise + if (Fname.isEmpty()) { + this->saveAs(); + return; + } + // Try to open a file for writing to + QFile Filetemp(Fname); + this->saveData(Filetemp); // Pass to helper method } 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->setCaption(Fname); + m_pStatbar->message(trUtf8("File %1 saved").arg(Fname), 4000); m_pMaintable->setDirty(false); // Set the clean state to allow close } @@ -480,7 +376,7 @@ trUtf8(TITRAQ_OVERWRITE), trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1); switch (nResult) { case 0: // Overwrite contents - *m_szFilename = Filestring; + this->setFilename(Filestring); this->saveFile(); break; case 1: // Don't overwrite @@ -504,32 +400,33 @@ { int nResult = 0; + if (!this->isOpen()) // Short circuit if user + qApp->quit(); // selects close twice + // Check modification state of current data if (m_pMaintable->isDirty()) { nResult = QMessageBox::information(this, trUtf8(TITRAQ_APPTITLE), trUtf8(TITRAQ_SAVEFIRST), trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2); - switch (nResult) { + switch (nResult) { // Maybe save before closing case 0: // Save first - this->saveFile(); // Save changes first - m_pMaintable->setDirty(false); // Reset data to clean state - pClosit->accept(); // then close timesheet + this->saveFile(); // Save changes first break; - case 1: // Don't save first but close - m_pMaintable->setDirty(false); // Reset data to clean state - pClosit->accept(); // Close timesheet + case 1: // Don't save first break; - case 2: // Don't close + case 2: // Do nothing default: pClosit->ignore(); + return; // Go away without closing break; } } - else { // Data is already up to date - m_pMaintable->setDirty(false); // Reset data to clean state - pClosit->accept(); - } + + // Fall through to implicit close code + this->enableIface(false); // Turn off the lights + this->setOpen(false); // Set doc state to closed + pClosit->ignore(); // Finish off by not closing } //