Index: ossp-pkg/as/as-gui/as_reportpanel.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_reportpanel.cpp,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_reportpanel.cpp,v' 2>/dev/null --- as_reportpanel.cpp 2003/02/17 17:16:18 1.1 +++ as_reportpanel.cpp 2003/02/18 18:27:46 1.2 @@ -32,14 +32,24 @@ #include #include #include -#include +#include #include #include #include #include +#include +#include +#include +#include #include "as_reportpanel.h" #include "as_generic.h" +#include "as_const.h" + +// Version information +#define _AS_VERSION_CPP_AS_HEADER_ +#include "as_version.cpp" +#undef _AS_VERSION_CPP_AS_HEADER_ // @@ -66,7 +76,7 @@ m_pToolay = new QHBoxLayout(0, 0, 6, "Toolbuttonlay"); m_pPushlay = new QHBoxLayout(0, 0, 6, "Pushbuttonlay"); - // Groupbox and its browser + // Groupbox and its text display m_pGroupbox = new QGroupBox(this, "Groupbox"); m_pGroupbox->setFrameShape(QGroupBox::GroupBoxPanel); m_pGroupbox->setFrameShadow(QGroupBox::Sunken); @@ -75,7 +85,9 @@ m_pGroupbox->layout()->setMargin(11); m_pGrouplay = new QVBoxLayout(m_pGroupbox->layout()); m_pGrouplay->setAlignment(Qt::AlignTop); - m_pBrowser = new QTextBrowser(m_pGroupbox, "Reportbrowser"); + m_pBrowser = new QTextEdit(m_pGroupbox, "Reportbrowser"); + m_pBrowser->setTextFormat(PlainText); + m_pBrowser->setReadOnly(true); m_pGrouplay->addWidget(m_pBrowser); m_pGrouplay->addLayout(m_pToolay); @@ -96,6 +108,8 @@ m_pFormlay->addLayout(m_pPushlay); // Connect signals to slots, accept() and reject() are Qt implicit + connect(m_pWeeklybutt, SIGNAL(clicked(void)), SLOT(reportWeeks(void))); + connect(m_pMonthlybutt, SIGNAL(clicked(void)), SLOT(reportMonths(void))); connect(m_pDismissbutt, SIGNAL(clicked(void)), SLOT(accept(void))); connect(m_pSavebutt, SIGNAL(clicked(void)), SLOT(saveReport(void))); this->textChange(); @@ -103,12 +117,89 @@ } // +// Makes a new weekly report of so many weeks +// +void Reportpanel::reportWeeks(int nWeeks) +{ + m_pBrowser->clear(); + this->writeHeader(); + this->writeWeek(); +} + +// +// Makes a new monthly report of so many months +// +void Reportpanel::reportMonths(int nMonths) +{ + m_pBrowser->clear(); + this->writeHeader(); + this->writeMonth(); +} + +// +// Writes a report header to the display window +// +void Reportpanel::writeHeader(void) +{ + QString Header; + Header = QString("Accounting System 0.6.18 local report\n"); + Header += QString("User XXXXXXXXXXXXXXXXXXXX\n"); + Header += QString("Date X. February 2003\n"); + Header += QString("\n"); + m_pBrowser->setText(Header); +} + +// +// Writes one week of data to the display window +// +void Reportpanel::writeWeek(void) +{ + m_pBrowser->append(trUtf8("No events logged during week\n")); +} + +// +// Writes one month of data to the display window +// +void Reportpanel::writeMonth(void) +{ + m_pBrowser->append(trUtf8("No events logged during month\n")); +} + +// // Saves the currently displayed local report // void Reportpanel::saveReport(void) { - Prototype Unimp; - Unimp.doMbox(); + int nResult = 0; // For checking user's answer + QFile Report; // The resulting report file + QString Filestring; // The user chosen file name to save + QString Openas = QDir::homeDirPath(); // Default chooser dir + + // And then get the name of the selected file to save to + Filestring = QFileDialog::getSaveFileName(Openas, trUtf8("Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to save"), NULL, false); + if (!Filestring.isEmpty()) { + if (QFile::exists(Filestring)) { + nResult = QMessageBox::warning(this, QString(TITRAQ_APPTITLE) + + ' ' + asgui_version.v_short, trUtf8(TITRAQ_OVERWRITE), + trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1); + if (nResult = QMessageBox::Ok) { // Overwrite a file + Report.setName(Filestring); // User wished name + Report.open(IO_WriteOnly | IO_Truncate); // Open report file + QTextStream Outstream(&Report); // Convert to stream + Outstream << m_pBrowser->text(); // Write the data + Report.close(); // Finish by closing + } + } + else { // User gave a file name, and there was no preexisting file there + Report.setName(Filestring); // User wished name + Report.open(IO_WriteOnly | IO_Truncate); // Open report file + QTextStream Outstream(&Report); // Convert to stream + Outstream << m_pBrowser->text(); // Write the data + Report.close(); // Finish by closing +qDebug(m_pBrowser->text().ascii()); + } + } + // Otherwise, user did not select a valid file and push okay button } // Index: ossp-pkg/as/as-gui/as_reportpanel.h RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_reportpanel.h,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_reportpanel.h,v' 2>/dev/null --- as_reportpanel.h 2003/02/17 17:16:18 1.1 +++ as_reportpanel.h 2003/02/18 18:27:46 1.2 @@ -41,7 +41,7 @@ class QGridLayout; class QGroupBox; class QPushButton; -class QTextBrowser; +class QTextEdit; class QToolButton; class Reportpanel : public QDialog @@ -57,7 +57,7 @@ QToolButton *m_pWeeklybutt; QToolButton *m_pMonthlybutt; QToolButton *m_pBothbutt; - QTextBrowser *m_pBrowser; + QTextEdit *m_pBrowser; QPushButton *m_pSavebutt; QPushButton *m_pDismissbutt; @@ -68,8 +68,15 @@ QHBoxLayout *m_pPushlay; protected slots: - void saveReport(void); + virtual void saveReport(void); virtual void textChange(void); + virtual void reportWeeks(int nWeeks = 1); + virtual void reportMonths(int nMonths = 1); + +private: + void writeHeader(void); + void writeWeek(void); + void writeMonth(void); }; #endif // REPORTPANEL_H