OSSP CVS Repository

ossp - Difference in ossp-pkg/as/as-gui/as_reportpanel.cpp versions 1.1 and 1.2
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/as/as-gui/as_reportpanel.cpp 1.1 -> 1.2

--- 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 <qvariant.h>
 #include <qgroupbox.h>
 #include <qpushbutton.h>
-#include <qtextbrowser.h>
+#include <qtextedit.h>
 #include <qtoolbutton.h>
 #include <qlayout.h>
 #include <qtooltip.h>
 #include <qwhatsthis.h>
+#include <qtextstream.h>
+#include <qfiledialog.h>
+#include <qfile.h>
+#include <qdir.h>
 
 #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
 }
 
 //

CVSTrac 2.0.1