OSSP CVS Repository

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

ossp-pkg/as/as-gui/as_reportpanel.cpp 1.3 -> 1.4

--- as_reportpanel.cpp   2003/02/19 18:23:16     1.3
+++ as_reportpanel.cpp   2003/02/20 16:48:00     1.4
@@ -30,10 +30,11 @@
 //
 
 #include <qvariant.h>
-#include <qgroupbox.h>
 #include <qpushbutton.h>
 #include <qtextedit.h>
 #include <qtoolbutton.h>
+#include <qbuttongroup.h>
+#include <qpopupmenu.h>
 #include <qlayout.h>
 #include <qtooltip.h>
 #include <qwhatsthis.h>
@@ -47,6 +48,7 @@
 #include "as_pref.h"
 #include "as_generic.h"
 #include "as_const.h"
+#include "as_except.h"
 
 // Version information
 #define _AS_VERSION_CPP_AS_HEADER_
@@ -54,6 +56,8 @@
 #undef  _AS_VERSION_CPP_AS_HEADER_
 
 
+namespace AS {
+
 //
 // Constructs a Reportpanel as a child of 'pParent', with the 
 // name 'kszName' and widget flags set to 'Flags'.
@@ -77,49 +81,83 @@
 
     // Store matrix and prefs members
     m_pReptable = pTable;
-//    m_pReptable->sortColumn(TITRAQ_IDXCOLDATE, true, true);
+    m_pReptable->sortColumn(TITRAQ_IDXDATE, true, true);
     m_pReprefs  = pPreferences;
 
+    // Preset number of weeks and months to report
+    m_nWeeks = m_pReprefs->getNumber(TITRAQ_PREFREPORTWEEKS, TITRAQ_DEFREPORTWEEKS);
+    m_nMonths = m_pReprefs->getNumber(TITRAQ_PREFREPORTMONTHS, TITRAQ_DEFREPORTMONTHS);
+
     // Build panel using already constructed widgets and layouts
     m_pFormlay = new QVBoxLayout(this, 11, 6, "Formlayout");
     m_pToolay = new QHBoxLayout(0, 0, 6, "Toolbuttonlay"); 
     m_pPushlay = new QHBoxLayout(0, 0, 6, "Pushbuttonlay"); 
 
     // Groupbox and its text display
-    m_pGroupbox = new QGroupBox(this, "Groupbox");
-    m_pGroupbox->setFrameShape(QGroupBox::GroupBoxPanel);
-    m_pGroupbox->setFrameShadow(QGroupBox::Sunken);
-    m_pGroupbox->setColumnLayout(0, Qt::Vertical);
-    m_pGroupbox->layout()->setSpacing(6);
-    m_pGroupbox->layout()->setMargin(11);
-    m_pGrouplay = new QVBoxLayout(m_pGroupbox->layout());
-    m_pGrouplay->setAlignment(Qt::AlignTop);
-    m_pBrowser = new QTextEdit(m_pGroupbox, "Reportbrowser");
+    m_pBrowser = new QTextEdit(this, "Reportbrowser");
     m_pBrowser->setTextFormat(PlainText);
     m_pBrowser->setReadOnly(true);
     m_pBrowser->setFont(QFont("Courier", 10));
-    m_pGrouplay->addWidget(m_pBrowser);
-    m_pGrouplay->addLayout(m_pToolay);
+    m_pFormlay->addWidget(m_pBrowser);
+    m_pFormlay->addLayout(m_pToolay);
+    m_pFormlay->addLayout(m_pPushlay);
 
     // Tool button suite
-    m_pWeeklybutt = new QToolButton(m_pGroupbox, "Weeklybutton");
-    m_pMonthlybutt = new QToolButton(m_pGroupbox, "Monthlybutton");
-    m_pBothbutt = new QToolButton(m_pGroupbox, "Bothbutton");
-    m_pToolay->addWidget(m_pWeeklybutt);
-    m_pToolay->addWidget(m_pMonthlybutt);
-    m_pToolay->addWidget(m_pBothbutt);
-    m_pFormlay->addWidget(m_pGroupbox);
+    m_pWeekmonthgroup = new QButtonGroup(this, "Weekmonthgroup");
+    m_pWeekmonthgroup->setColumnLayout(0, Qt::Horizontal);
+    m_pWeekmonthlay = new QHBoxLayout(m_pWeekmonthgroup->layout());
+    m_pWeekmonthlay->setSpacing(11);
+    m_pWeekmonthlay->setMargin(0);
+    m_pWeekmonthlay->setAlignment(Qt::AlignTop);
+    m_pWeekmonthgroup->setFrameShape(QFrame::NoFrame);
+    m_pWeekmonthgroup->setExclusive(true);
+    m_pWeeklybutt = new QToolButton(m_pWeekmonthgroup, "Weeklybutton");
+    m_pMonthlybutt = new QToolButton(m_pWeekmonthgroup, "Monthlybutton");
+    m_pBothbutt = new QToolButton(m_pWeekmonthgroup, "Bothbutton");
+    m_pWeeklybutt->setToggleButton(true);
+    m_pMonthlybutt->setToggleButton(true);
+    m_pBothbutt->setToggleButton(true);
+
+    // Popup for number of weeks
+    m_pWeekpop = new QPopupMenu(this);
+    if (m_pWeekpop == NULL) // Sanity check
+        throw Genexcept("Weekly toolbutton popup creation failed.");
+    m_pWeekpop->insertItem(tr("One week"), this, SLOT(reportWeeks(int)));
+    m_pWeekpop->insertItem(tr("Two weeks"), this, SLOT(reportWeeks(int)));
+    m_pWeekpop->insertItem(tr("Three weeks"), this, SLOT(reportWeeks(int)));
+    m_pWeekpop->insertItem(tr("Four weeks"), this, SLOT(reportWeeks(int)));
+    m_pWeekpop->insertItem(tr("N... weeks"), this, SLOT(reportWeeks(int)));
+    m_pWeeklybutt->setPopup(m_pWeekpop);
+    m_pWeeklybutt->setPopupDelay(TITRAQ_POPUPMSECS);
+
+    // Popup for number of months
+    m_pMonthpop = new QPopupMenu(this);
+    if (m_pMonthpop == NULL) // Sanity check
+        throw Genexcept("Monthly toolbutton popup creation failed.");
+    m_pMonthpop->insertItem(tr("One month"), this, SLOT(reportMonths(int)));
+    m_pMonthpop->insertItem(tr("Two months"), this, SLOT(reportMonths(int)));
+    m_pMonthpop->insertItem(tr("Three months"), this, SLOT(reportMonths(int)));
+    m_pMonthpop->insertItem(tr("Four months"), this, SLOT(reportMonths(int)));
+    m_pMonthpop->insertItem(tr("N... months"), this, SLOT(reportMonths(int)));
+    m_pMonthlybutt->setPopup(m_pMonthpop);
+    m_pMonthlybutt->setPopupDelay(TITRAQ_POPUPMSECS);
+
+    // Add our tool buttons
+    m_pWeekmonthlay->addWidget(m_pWeeklybutt);
+    m_pWeekmonthlay->addWidget(m_pMonthlybutt);
+    m_pWeekmonthlay->addWidget(m_pBothbutt);
+    m_pToolay->addWidget(m_pWeekmonthgroup);
 
     // Push button suite
     m_pSavebutt = new QPushButton(this, "Savebutton");
     m_pDismissbutt = new QPushButton(this, "Dismissbutton");
     m_pPushlay->addWidget(m_pSavebutt);
     m_pPushlay->addWidget(m_pDismissbutt);
-    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_pBothbutt, SIGNAL(clicked(void)), SLOT(reportBoth(void)));
     connect(m_pDismissbutt, SIGNAL(clicked(void)), SLOT(accept(void)));
     connect(m_pSavebutt, SIGNAL(clicked(void)), SLOT(saveReport(void)));
     this->textChange();
@@ -127,23 +165,125 @@
 }
 
 //
+// Overload QDialog::exec(), and generate a report before executing modally
+//
+int Reportpanel::exec(void)
+{
+    int nRet = 0;
+    int nPeriod = m_pReprefs->getNumber(TITRAQ_PREFREPORTYPE, TITRAQ_DEFREPORTYPE);
+
+    switch (nPeriod) {
+    case TITRAQ_REPORTWEEK:
+        this->reportWeeks(1);
+        m_pWeekmonthgroup->setButton(TITRAQ_REPORTWEEK);
+        break;
+    case TITRAQ_REPORTMONTH:
+        this->reportMonths(1);
+        m_pWeekmonthgroup->setButton(TITRAQ_REPORTMONTH);
+        break;
+    case TITRAQ_REPORTBOTH:
+        this->reportBoth(1);
+        m_pWeekmonthgroup->setButton(TITRAQ_REPORTBOTH);
+        break;
+    default:
+        throw Genexcept("Reportpanel: Modal event loop entered with no report period.");
+        break;
+    }
+
+    nRet = QDialog::exec(); // Blast off
+
+    // Before losing scope, the preferred report period
+    m_pReprefs->setNumber(TITRAQ_PREFREPORTYPE,
+        m_pWeekmonthgroup->id(m_pWeekmonthgroup->selected()));
+    m_pReprefs->setNumber(TITRAQ_PREFREPORTWEEKS, m_nWeeks);
+    m_pReprefs->setNumber(TITRAQ_PREFREPORTMONTHS, m_nMonths);
+    return nRet;
+}
+
+//
 // Makes a new weekly report of so many weeks
 //
-void Reportpanel::reportWeeks(int nWeeks)
+void Reportpanel::reportWeeks(int nMenuid)
 {
+    // Menu index, first item is always 0
+    int nIndex = m_pWeekpop->indexOf(nMenuid);
+
+    // Update m_nWeeks only if user prefers a different number
+    if (nIndex >= 0)
+        m_nWeeks = nIndex + 1;
+
+    // User selected N... to indicate an arbitrary number
+    if (nIndex == m_pWeekpop->count() - 1) {
+        Prototype Unimp;
+        Unimp.doMbox();
+    }
+
+    // Set the button in case we arrived from a menu selection
+    m_pWeekmonthgroup->setButton(TITRAQ_REPORTWEEK);
+
+    // Clear data window and write header out
+    m_pBrowser->setUpdatesEnabled(false);
     m_pBrowser->clear();
     this->writeHeader();
     m_pBrowser->append(this->getWeek());
+    this->writeFooter();
+    m_pBrowser->setCursorPosition(0, 0);
+    m_pBrowser->ensureCursorVisible();
+    m_pBrowser->setUpdatesEnabled(true);
+    m_pBrowser->repaint(false);
 }
 
 //
 // Makes a new monthly report of so many months
 //
-void Reportpanel::reportMonths(int nMonths)
+void Reportpanel::reportMonths(int nMenuid)
 {
+    // Menu index, first item is always 0
+    int nIndex = m_pMonthpop->indexOf(nMenuid);
+
+    // Update m_nMonths only if user prefers a different number
+    if (nIndex >= 0)
+        m_nMonths = nIndex + 1;
+
+    // User selected N... to indicate an arbitrary number
+    if (nIndex == m_pMonthpop->count() - 1) {
+        Prototype Unimp;
+        Unimp.doMbox();
+    }
+
+    // Set the button in case we arrived from a menu selection
+    m_pWeekmonthgroup->setButton(TITRAQ_REPORTMONTH);
+
+    // Clear data window and write header out
+    m_pBrowser->setUpdatesEnabled(false);
     m_pBrowser->clear();
     this->writeHeader();
     m_pBrowser->append(this->getMonth());
+    this->writeFooter();
+    m_pBrowser->setCursorPosition(0, 0);
+    m_pBrowser->ensureCursorVisible();
+    m_pBrowser->setUpdatesEnabled(true);
+    m_pBrowser->repaint(false);
+}
+
+//
+// Makes a new monthly report of so many weeks and months
+//
+void Reportpanel::reportBoth(int nMenuid)
+{
+    // Set the button in case we arrived from a menu selection
+    m_pWeekmonthgroup->setButton(TITRAQ_REPORTBOTH);
+
+    // Clear data window and write header out
+    m_pBrowser->setUpdatesEnabled(false);
+    m_pBrowser->clear();
+    this->writeHeader();
+    m_pBrowser->append(tr("The 'both' feature is not working yet."));
+    this->writeFooter();
+    m_pBrowser->setCursorPosition(0, 0);
+    m_pBrowser->ensureCursorVisible();
+    m_pBrowser->setUpdatesEnabled(true);
+    m_pBrowser->repaint(false);
 }
 
 //
@@ -168,6 +308,13 @@
 }
 
 //
+// Writes a report footer to the display window
+//
+void Reportpanel::writeFooter(void)
+{
+}
+
+//
 // Writes one week of data to the display window
 //
 QString Reportpanel::getWeek(QDate Dayref)
@@ -266,7 +413,6 @@
 void Reportpanel::textChange(void)
 {
     this->setCaption(tr("AS local report", "Local report using weekly data or monthly data or both."));
-    m_pGroupbox->setTitle(tr("Local report", "Comment for Groupbox"));
 
     // Top level push buttons associated with accept and save slots
     m_pDismissbutt->setText(tr("Dismiss", "Comment for Dismissbutton"));
@@ -278,12 +424,13 @@
 
     // Inner tool buttons for new local report generation
     m_pWeeklybutt->setText(tr("Weekly", "Comment for Weeklybutt"));
-    QToolTip::add(m_pWeeklybutt, tr("Generates a weekly report", "Comment for tooltip Weeklybutt"));
-    QWhatsThis::add(m_pWeeklybutt, tr("The weekly button generates a new weekly report", "Comment for whatsThis Weeklybutt"));
+    QToolTip::add(m_pWeeklybutt, tr("Hold down for options", "Comment for tooltip Weeklybutt"));
+    QWhatsThis::add(m_pWeeklybutt, tr("The weekly button generates a new weekly report. Hold this button down for options.", "Comment for whatsThis Weeklybutt"));
     m_pMonthlybutt->setText(tr("Monthly", "Comment for Monthlybutt"));
-    QToolTip::add(m_pMonthlybutt, tr("Generates a monthly report", "Comment for tooltip Monthlybutt"));
-    QWhatsThis::add(m_pMonthlybutt, tr("The monthly button generates a new monthly report", "Comment for whatsThis Monthlybutt"));
+    QToolTip::add(m_pMonthlybutt, tr("Hold down for options", "Comment for tooltip Monthlybutt"));
+    QWhatsThis::add(m_pMonthlybutt, tr("The monthly button generates a new monthly report. Hold this button down for options.", "Comment for whatsThis Monthlybutt"));
     m_pBothbutt->setText(tr("Both", "Comment for Bothbutt"));
-    QToolTip::add(m_pBothbutt, tr("Generates a both report", "Comment for tooltip Bothbutt"));
-    QWhatsThis::add(m_pBothbutt, tr("The both button generates a new report with both weekly and monthly items mixed in.", "Comment for whatsThis Bothbutt"));
+    QToolTip::add(m_pBothbutt, tr("Report with both week data and month data", "Comment for tooltip Bothbutt"));
+    QWhatsThis::add(m_pBothbutt, tr("The both button generates a new report with both weekly and monthly items mixed in. Hold this button down for options.", "Comment for whatsThis Bothbutt"));
 }
+} // namespace AS

CVSTrac 2.0.1