michael@1: // michael@1: // OSSP asgui - Accounting system graphical user interface michael@12: // Copyright (c) 2002-2009 The OSSP Project (http://www.ossp.org/) michael@12: // Copyright (c) 2002-2009 Ralf S. Engelschall michael@12: // Copyright (c) 2002-2009 Michael Schloh von Bennewitz michael@12: // Copyright (c) 2002-2009 Cable & Wireless Telecommunications Services GmbH michael@1: // michael@1: // This file is part of OSSP asgui, an accounting system graphical user michael@3: // interface which can be found at http://asgui.europalab.com/. michael@1: // michael@1: // Permission to use, copy, modify, and distribute this software for michael@1: // any purpose with or without fee is hereby granted, provided that michael@1: // the above copyright notice and this permission notice appear in all michael@1: // copies. michael@1: // michael@1: // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED michael@1: // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF michael@1: // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. michael@1: // IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR michael@1: // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@1: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@1: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF michael@1: // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND michael@1: // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, michael@1: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT michael@1: // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@1: // SUCH DAMAGE. michael@1: // michael@1: // as_reportpanel.cpp: ISO C++ implementation michael@1: // michael@1: michael@3: #define QT3_SUPPORT michael@3: michael@1: #include michael@1: #include michael@3: #include michael@1: #include michael@3: #include michael@3: #include michael@1: #include michael@1: #include michael@3: #include michael@3: #include michael@3: #include michael@1: #include michael@3: #include michael@1: #include michael@1: #include michael@1: #include michael@1: michael@3: //Added by qt3to4: michael@3: #include michael@3: #include michael@3: #include michael@3: michael@1: #include "as_reportpanel.h" michael@1: #include "as_numdial.h" michael@1: #include "as_table.h" michael@1: #include "as_pref.h" michael@1: #include "as_generic.h" michael@1: #include "as_const.h" michael@1: #include "as_except.h" michael@1: michael@1: // Version information michael@1: #define _AS_VERSION_CPP_AS_HEADER_ michael@1: #include "as_version.cpp" michael@1: #undef _AS_VERSION_CPP_AS_HEADER_ michael@1: michael@1: michael@1: namespace AS { michael@1: michael@1: // michael@1: // Constructs a Reportpanel as a child of 'pParent', with the michael@1: // name 'kszName' and widget flags set to 'Flags'. michael@1: // michael@1: // The dialog will by default be modal, unless you set 'bModal' to michael@1: // false to construct a modeless dialog. michael@1: // michael@1: Reportpanel::Reportpanel(TiTable *pTable, Preferences *pPreferences, michael@1: QWidget *pParent, const char *kszName, michael@3: bool bModal, Qt::WFlags Flags) michael@1: : QDialog(pParent, kszName, bModal, Flags) michael@1: { michael@1: // Boilerplate code to initialize the panel michael@1: if (!kszName) michael@1: this->setName("Reportpanel"); michael@1: michael@1: // Make panel resizeable michael@1: this->setSizeGripEnabled(true); michael@1: this->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, michael@1: (QSizePolicy::SizeType)5, 0, 0, this->sizePolicy().hasHeightForWidth())); michael@1: michael@1: // Store matrix and prefs members michael@1: m_pReptable = pTable; michael@1: m_pReprefs = pPreferences; michael@1: m_pPrinter = new QPrinter; michael@1: michael@1: // Preset number of weeks and months to report michael@1: m_nWeeks = m_pReprefs->getNumber(TITRAQ_PREFREPORTWEEKS, TITRAQ_DEFREPORTWEEKS); michael@1: m_nMonths = m_pReprefs->getNumber(TITRAQ_PREFREPORTMONTHS, TITRAQ_DEFREPORTMONTHS); michael@1: michael@1: // Build panel using already constructed widgets and layouts michael@3: m_pFormlay = new Q3VBoxLayout(this, 11, 6, "Formlayout"); michael@3: m_pToolay = new Q3HBoxLayout(0, 0, 6, "Toolbuttonlay"); michael@3: m_pPushlay = new Q3HBoxLayout(0, 0, 6, "Pushbuttonlay"); michael@1: michael@1: // Groupbox and its text display michael@3: m_pBrowser = new Q3TextEdit(this, "Reportbrowser"); michael@3: m_pBrowser->setTextFormat(Qt::PlainText); michael@1: m_pBrowser->setReadOnly(true); michael@1: m_pBrowser->setFont(QFont("Courier", 10)); michael@1: m_pFormlay->addWidget(m_pBrowser); michael@1: m_pFormlay->addSpacing(6); michael@1: m_pFormlay->addLayout(m_pToolay); michael@1: m_pFormlay->addSpacing(6); michael@1: m_pFormlay->addLayout(m_pPushlay); michael@1: michael@1: // Tool button suite michael@3: m_pWeekmonthgroup = new Q3ButtonGroup(this, "Weekmonthgroup"); michael@1: m_pWeekmonthgroup->setColumnLayout(0, Qt::Horizontal); michael@1: m_pWeekmonthgroup->layout()->setSpacing(11); michael@1: m_pWeekmonthgroup->layout()->setMargin(0); michael@3: m_pWeekmonthlay = new Q3HBoxLayout(m_pWeekmonthgroup->layout()); michael@3: //m_pWeekmonthgroup->setFrameShape(QFrame::NoFrame); michael@1: m_pWeekmonthgroup->setExclusive(true); michael@1: m_pWeeklybutt = new QToolButton(m_pWeekmonthgroup, "Weeklybutton"); michael@1: // m_pWeeklybutt->setPaletteBackgroundColor(QColor(198, 196, 186)); michael@3: m_pWeeklybutt->setFocusPolicy(Qt::TabFocus); michael@1: m_pWeeklybutt->setCursor(QCursor(13)); michael@1: m_pWeeklybutt->setToggleButton(true); michael@1: m_pMonthlybutt = new QToolButton(m_pWeekmonthgroup, "Monthlybutton"); michael@1: // m_pMonthlybutt->setPaletteBackgroundColor(QColor(198, 196, 186)); michael@3: m_pMonthlybutt->setFocusPolicy(Qt::TabFocus); michael@1: m_pMonthlybutt->setCursor(QCursor(13)); michael@1: m_pMonthlybutt->setToggleButton(true); michael@1: michael@1: // Popup for number of weeks michael@3: m_pWeekpop = new Q3PopupMenu(this); michael@1: if (m_pWeekpop == NULL) // Sanity check michael@1: throw Genexcept("Weekly toolbutton popup creation failed."); michael@1: m_pWeekpop->insertItem(trUtf8("One week"), this, SLOT(reportWeeks(int))); michael@1: m_pWeekpop->insertItem(trUtf8("Two weeks"), this, SLOT(reportWeeks(int))); michael@1: m_pWeekpop->insertItem(trUtf8("Three weeks"), this, SLOT(reportWeeks(int))); michael@1: m_pWeekpop->insertItem(trUtf8("Four weeks"), this, SLOT(reportWeeks(int))); michael@1: m_pWeekpop->insertItem(trUtf8("N... weeks"), this, SLOT(reportWeeks(int))); michael@1: m_pWeekpop->setCheckable(true); michael@1: m_pWeeklybutt->setPopup(m_pWeekpop); michael@1: m_pWeeklybutt->setPopupDelay(TITRAQ_POPUPMSECS); michael@1: michael@1: { // Initialize check button correctly michael@1: int nPosition = (m_nWeeks < m_pWeekpop->count()) ? m_nWeeks : m_pWeekpop->count(); michael@1: m_pWeekpop->setItemChecked(m_pWeekpop->idAt(--nPosition), true); michael@1: } michael@1: michael@1: // Popup for number of months michael@3: m_pMonthpop = new Q3PopupMenu(this); michael@1: if (m_pMonthpop == NULL) // Sanity check michael@1: throw Genexcept("Monthly toolbutton popup creation failed."); michael@1: m_pMonthpop->insertItem(trUtf8("One month"), this, SLOT(reportMonths(int))); michael@1: m_pMonthpop->insertItem(trUtf8("Two months"), this, SLOT(reportMonths(int))); michael@1: m_pMonthpop->insertItem(trUtf8("Three months"), this, SLOT(reportMonths(int))); michael@1: m_pMonthpop->insertItem(trUtf8("Four months"), this, SLOT(reportMonths(int))); michael@1: m_pMonthpop->insertItem(trUtf8("N... months"), this, SLOT(reportMonths(int))); michael@1: m_pMonthpop->setCheckable(true); michael@1: m_pMonthlybutt->setPopup(m_pMonthpop); michael@1: m_pMonthlybutt->setPopupDelay(TITRAQ_POPUPMSECS); michael@1: michael@1: { // Initialize check button correctly michael@1: int nPosition = (m_nMonths < m_pMonthpop->count()) ? m_nMonths : m_pMonthpop->count(); michael@1: m_pMonthpop->setItemChecked(m_pMonthpop->idAt(--nPosition), true); michael@1: } michael@1: michael@1: // Add our tool buttons michael@1: m_pWeekmonthlay->addWidget(m_pWeeklybutt); michael@1: m_pWeekmonthlay->addWidget(m_pMonthlybutt); michael@1: m_pToolay->addWidget(m_pWeekmonthgroup); michael@1: michael@1: // Push button suite michael@1: m_pSavebutt = new QPushButton(this, "Savebutton"); michael@1: m_pSavebutt->setPaletteBackgroundColor(QColor(202, 194, 182)); michael@1: m_pSavebutt->setCursor(QCursor(13)); michael@1: m_pPrintbutt = new QPushButton(this, "Printbutton"); michael@1: m_pPrintbutt->setPaletteBackgroundColor(QColor(198, 196, 186)); michael@1: m_pPrintbutt->setCursor(QCursor(13)); michael@1: #ifdef QT_NO_PRINTER michael@1: m_pPrintbutt->setEnabled(false); michael@1: #endif michael@1: m_pDismissbutt = new QPushButton(this, "Dismissbutton"); michael@1: m_pDismissbutt->setPaletteBackgroundColor(QColor(198, 196, 186)); michael@1: m_pDismissbutt->setCursor(QCursor(13)); michael@1: m_pDismissbutt->setDefault(true); michael@1: m_pPushlay->addWidget(m_pSavebutt); michael@1: m_pPushlay->addWidget(m_pPrintbutt); michael@1: m_pPushlay->addWidget(m_pDismissbutt); michael@1: michael@1: // Connect signals to slots, accept() and reject() are Qt implicit michael@1: connect(m_pWeeklybutt, SIGNAL(clicked(void)), SLOT(reportWeeks(void))); michael@1: connect(m_pMonthlybutt, SIGNAL(clicked(void)), SLOT(reportMonths(void))); michael@1: connect(m_pSavebutt, SIGNAL(clicked(void)), SLOT(saveReport(void))); michael@1: connect(m_pPrintbutt, SIGNAL(clicked(void)), SLOT(printReport(void))); michael@1: connect(m_pDismissbutt, SIGNAL(clicked(void)), SLOT(accept(void))); michael@1: this->resize(QSize(464, 332).expandedTo(minimumSizeHint())); michael@1: this->textChange(); michael@1: } michael@1: michael@1: // michael@1: // Overload QDialog::exec(), and generate a report before executing modally michael@1: // michael@1: int Reportpanel::exec(void) michael@1: { michael@1: int nRet = 0; michael@1: int nPeriod = m_pReprefs->getNumber(TITRAQ_PREFREPORTYPE, TITRAQ_DEFREPORTYPE); michael@1: michael@1: switch (nPeriod) { michael@1: case TITRAQ_REPORTWEEK: michael@1: this->reportWeeks(1); michael@1: m_pWeekmonthgroup->setButton(TITRAQ_REPORTWEEK); michael@1: break; michael@1: case TITRAQ_REPORTMONTH: michael@1: this->reportMonths(1); michael@1: m_pWeekmonthgroup->setButton(TITRAQ_REPORTMONTH); michael@1: break; michael@1: default: michael@1: throw Genexcept("Reportpanel: Modal event loop entered with no report period."); michael@1: break; michael@1: } michael@1: michael@1: nRet = QDialog::exec(); // Blast off michael@1: michael@1: // Before losing scope, the preferred report period michael@1: m_pReprefs->setNumber(TITRAQ_PREFREPORTYPE, michael@1: m_pWeekmonthgroup->id(m_pWeekmonthgroup->selected())); michael@1: m_pReprefs->setNumber(TITRAQ_PREFREPORTWEEKS, m_nWeeks); michael@1: m_pReprefs->setNumber(TITRAQ_PREFREPORTMONTHS, m_nMonths); michael@1: return nRet; michael@1: } michael@1: michael@1: // michael@1: // Makes a new weekly report of so many weeks michael@1: // michael@1: void Reportpanel::reportWeeks(int nMenuid) michael@1: { michael@1: // Range of weeks to report michael@1: int nFirstweek, nLastweek; michael@1: michael@1: // Menu index, first item is always 0 michael@1: int nIndex = m_pWeekpop->indexOf(nMenuid); // Corresponds to weeks michael@1: int nLastid = 0; // Last menu id selected michael@1: michael@1: if (m_nWeeks < m_pWeekpop->count()) michael@1: nLastid = m_pWeekpop->idAt(m_nWeeks - 1); // Probably not last item michael@1: else michael@1: nLastid = m_pWeekpop->idAt(m_pWeekpop->count() - 1); // Last item selected michael@1: michael@1: // Set the button in case from a menu selection michael@1: m_pWeekmonthgroup->setButton(TITRAQ_REPORTWEEK); michael@1: michael@1: // Update m_nWeeks only if user prefers a different number michael@1: if (nIndex >= 0) { michael@1: // User selected N... to indicate an arbitrary number michael@1: if (nIndex == m_pWeekpop->count() - 1) { michael@1: Numdial Weeksinput; michael@1: Weeksinput.setNum(m_nWeeks); michael@1: if (Weeksinput.exec() == QDialog::Accepted) { michael@1: m_nWeeks = Weeksinput.getNum(); michael@1: m_pWeekpop->setItemChecked(nLastid, false); michael@1: m_pWeekpop->setItemChecked(nMenuid, true); michael@1: } michael@1: else michael@1: return; michael@1: } michael@1: else { // User selected a preset menu item such as '2 weeks' michael@1: m_nWeeks = nIndex + 1; michael@1: m_pWeekpop->setItemChecked(nLastid, false); michael@1: m_pWeekpop->setItemChecked(nMenuid, true); michael@1: } michael@1: } michael@1: michael@1: // Clear data window michael@1: m_pBrowser->setUpdatesEnabled(false); michael@1: m_pBrowser->clear(); michael@1: michael@1: // Determine first and last week numbers, then write header michael@1: nLastweek = QDate::currentDate().weekNumber(); michael@1: if (m_nWeeks > 1) { michael@1: nFirstweek = QDate::currentDate().addDays(m_nWeeks * -7).weekNumber() + 1; michael@1: this->writeHeader(nFirstweek, nLastweek); michael@1: } michael@1: else michael@1: this->writeHeader(nLastweek); michael@1: michael@1: // Write new contents to data window michael@1: m_pBrowser->append(this->getWeektotals(QDate::currentDate(), m_nWeeks)); michael@1: if (m_pReprefs->getBool(TITRAQ_PREFDETAILON, TITRAQ_DEFDETAILON)) michael@1: m_pBrowser->append(this->getWeekdetails(QDate::currentDate(), m_nWeeks)); michael@1: this->writeFooter(); michael@1: m_pBrowser->setCursorPosition(0, 0); michael@1: m_pBrowser->ensureCursorVisible(); michael@1: m_pBrowser->setUpdatesEnabled(true); michael@1: m_pBrowser->repaint(false); michael@1: } michael@1: michael@1: // michael@1: // Makes a new monthly report of so many months michael@1: // michael@1: void Reportpanel::reportMonths(int nMenuid) michael@1: { michael@1: // Range of months to report michael@1: QString Firstmonth, Lastmonth; michael@1: michael@1: // Menu index, first item is always 0 michael@1: int nIndex = m_pMonthpop->indexOf(nMenuid); // Corresponds to months michael@1: int nLastid = 0; // Last menu id selected michael@1: michael@1: if (m_nMonths < m_pMonthpop->count()) michael@1: nLastid = m_pMonthpop->idAt(m_nMonths - 1); // Probably not last item michael@1: else michael@1: nLastid = m_pMonthpop->idAt(m_pMonthpop->count() - 1); // Last item selected michael@1: michael@1: // Set the button in case from a menu selection michael@1: m_pWeekmonthgroup->setButton(TITRAQ_REPORTMONTH); michael@1: michael@1: // Update m_nMonths only if user prefers a different number michael@1: if (nIndex >= 0) { michael@1: // User selected N... to indicate an arbitrary number michael@1: if (nIndex == m_pMonthpop->count() - 1) { michael@1: Numdial Monthsinput; michael@1: Monthsinput.setNum(m_nMonths); michael@1: if (Monthsinput.exec() == QDialog::Accepted) { michael@1: m_nMonths = Monthsinput.getNum(); michael@1: m_pMonthpop->setItemChecked(nLastid, false); michael@1: m_pMonthpop->setItemChecked(nMenuid, true); michael@1: } michael@1: else michael@1: return; michael@1: } michael@1: else { // User selected a preset menu item such as '2 months' michael@1: m_nMonths = nIndex + 1; michael@1: m_pMonthpop->setItemChecked(nLastid, false); michael@1: m_pMonthpop->setItemChecked(nMenuid, true); michael@1: } michael@1: } michael@1: michael@1: // Clear data window michael@1: m_pBrowser->setUpdatesEnabled(false); michael@1: m_pBrowser->clear(); michael@1: michael@1: // Determine first and last month names, then write header michael@1: Lastmonth = QDate::longMonthName(QDate::currentDate().month()); michael@1: if (m_nMonths > 1) { michael@1: int nMonth = (QDate::currentDate().addMonths(m_nMonths * -1).month() + 12) % 12 + 1; michael@1: Firstmonth = QDate::longMonthName(nMonth); michael@1: this->writeHeader(Firstmonth, Lastmonth); michael@1: } michael@1: else michael@1: this->writeHeader(Lastmonth); michael@1: michael@1: // Write new contents to data window michael@1: m_pBrowser->append(this->getMonthtotals(QDate::currentDate(), m_nMonths)); michael@1: if (m_pReprefs->getBool(TITRAQ_PREFDETAILON, TITRAQ_DEFDETAILON)) { michael@1: m_pBrowser->append(this->getMonthdetails(QDate::currentDate(), m_nMonths)); michael@1: } michael@1: this->writeFooter(); michael@1: m_pBrowser->setCursorPosition(0, 0); michael@1: m_pBrowser->ensureCursorVisible(); michael@1: m_pBrowser->setUpdatesEnabled(true); michael@1: m_pBrowser->repaint(false); michael@1: } michael@1: michael@1: // michael@1: // Writes a report header to the display window michael@1: // michael@1: void Reportpanel::writeHeader(int nWeeknum) michael@1: { michael@1: QString Header; michael@1: Header = QString("Accounting System "); michael@1: Header += QString(asgui_version.v_short); michael@1: Header += trUtf8("\nLocal report, username '"); michael@1: Header += m_pReprefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER); michael@1: Header += QString("'\n"); michael@1: Header += trUtf8("Date "); michael@1: Header += QDate::currentDate().toString(Qt::ISODate); michael@1: Header += trUtf8(", Time "); michael@1: Header += QTime::currentTime().toString(Qt::ISODate); michael@1: Header += trUtf8("\nReporting for week %1...").arg(nWeeknum); michael@1: Header += QString("\n\n"); michael@1: m_pBrowser->setText(Header); michael@1: } michael@1: michael@1: // michael@1: // Writes a report header to the display window michael@1: // michael@1: void Reportpanel::writeHeader(QString Month) michael@1: { michael@1: QString Header; michael@1: Header = QString("Accounting System "); michael@1: Header += QString(asgui_version.v_short); michael@1: Header += trUtf8("\nLocal report, username '"); michael@1: Header += m_pReprefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER); michael@1: Header += QString("'\n"); michael@1: Header += trUtf8("Date "); michael@1: Header += QDate::currentDate().toString(Qt::ISODate); michael@1: Header += trUtf8(", Time "); michael@1: Header += QTime::currentTime().toString(Qt::ISODate); michael@1: Header += trUtf8("\nReporting for month %1...").arg(Month); michael@1: Header += QString("\n\n"); michael@1: m_pBrowser->setText(Header); michael@1: } michael@1: michael@1: // michael@1: // Writes a report header to the display window michael@1: // michael@1: void Reportpanel::writeHeader(int nFirst, int nLast) michael@1: { michael@1: QString Header; michael@1: Header = QString("Accounting System "); michael@1: Header += QString(asgui_version.v_short); michael@1: Header += trUtf8("\nLocal report, username '"); michael@1: Header += m_pReprefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER); michael@1: Header += QString("'\n"); michael@1: Header += trUtf8("Date "); michael@1: Header += QDate::currentDate().toString(Qt::ISODate); michael@1: Header += trUtf8(", Time "); michael@1: Header += QTime::currentTime().toString(Qt::ISODate); michael@1: Header += trUtf8("\nReporting for weeks %1 through %2...").arg(nFirst).arg(nLast); michael@1: Header += QString("\n\n"); michael@1: m_pBrowser->setText(Header); michael@1: } michael@1: michael@1: // michael@1: // Writes a report header to the display window michael@1: // michael@1: void Reportpanel::writeHeader(QString First, QString Last) michael@1: { michael@1: QString Header; michael@1: Header = QString("Accounting System "); michael@1: Header += QString(asgui_version.v_short); michael@1: Header += trUtf8("\nLocal report, username '"); michael@1: Header += m_pReprefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER); michael@1: Header += QString("'\n"); michael@1: Header += trUtf8("Date "); michael@1: Header += QDate::currentDate().toString(Qt::ISODate); michael@1: Header += trUtf8(", Time "); michael@1: Header += QTime::currentTime().toString(Qt::ISODate); michael@1: Header += trUtf8("\nReporting months %1 through %2...").arg(First).arg(Last); michael@1: Header += QString("\n\n"); michael@1: m_pBrowser->setText(Header); michael@1: } michael@1: michael@1: // michael@1: // Writes a report footer to the display window michael@1: // michael@1: void Reportpanel::writeFooter(void) michael@1: { michael@1: if (m_pReprefs->getBool(TITRAQ_PREFSIGNATON, TITRAQ_DEFSIGNATON)) { michael@1: m_pBrowser->append(trUtf8("\n\nPrint name ________________________________________\n")); michael@1: m_pBrowser->append(trUtf8("\n\nSignature ________________________________________")); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Returns one week of details data michael@1: // michael@1: QString Reportpanel::getWeekdetails(QDate Dayref, int nWeeks) michael@1: { michael@1: QString Data; // Output string michael@1: QString Tempstring; // Temp churning michael@1: int nRows = m_pReptable->numRows(); michael@1: michael@1: // Find range boundaries michael@1: Q_ASSERT(nWeeks > 0); michael@1: QDate Tempdate; michael@1: QDate Firstday; michael@1: QDate Lastday; michael@1: Firstday = Dayref.addDays(Dayref.dayOfWeek() * -1 + 1); michael@1: Firstday = Firstday.addDays((nWeeks - 1) * -7); michael@1: Lastday = Firstday.addDays(7 * nWeeks); michael@1: michael@1: // Write some quick header text to the outgoing string michael@1: Data = trUtf8("\nDate Hours Account details\n"); michael@1: Data += QString("---------- ----- ----------------------------------------\n"); michael@1: michael@1: // Build the long week data string michael@1: for (int nIter = nRows - 1; nIter >= 0; nIter--) { michael@1: // Work on this tuple only if it within the reporting range michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); michael@1: Tempdate = QDate::fromString(m_pReptable->text(nIter, TITRAQ_IDXDATE), Qt::ISODate); michael@1: if (!Tempstring.isEmpty() && Firstday <= Tempdate && Tempdate < Lastday) { michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXDATE); michael@1: if (!Tempstring.isEmpty()) michael@1: Data += Tempstring; michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXAMOUNT); michael@1: if (!Tempstring.isEmpty()) michael@1: Data += QString(TITRAQ_SEPARATORTOK) + Tempstring; michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); michael@1: if (!Tempstring.isEmpty()) michael@1: Data += QString(TITRAQ_SEPARATORTOK) + Tempstring; michael@1: Data += QString("\n"); // Finish off line michael@1: } michael@1: } michael@1: michael@1: return Data; michael@1: } michael@1: michael@1: // michael@1: // Returns one week of totals data michael@1: // michael@1: QString Reportpanel::getWeektotals(QDate Dayref, int nWeeks) michael@1: { michael@1: using namespace std; // Needed for maps and hash michael@1: map Hashtasks; // Hashtable to store tasks michael@1: multimap Hashhours; // Hashtable to store hours michael@1: map::iterator Taskiter; // Hashtable task iterator michael@1: multimap::iterator Houriter; // Hashtable hour iterator michael@1: michael@1: QString Totals; // Data totals to return for writing michael@1: QString Tempstring; // Temporary processing string michael@1: QDate Tempdate; // Temporary processing date michael@1: int nRows = m_pReptable->numRows(); michael@1: michael@1: // Find range boundaries michael@1: Q_ASSERT(nWeeks > 0); michael@1: QDate Firstday; michael@1: QDate Lastday; michael@1: Firstday = Dayref.addDays(Dayref.dayOfWeek() * -1 + 1); michael@1: Firstday = Firstday.addDays((nWeeks - 1) * -7); michael@1: Lastday = Firstday.addDays(7 * nWeeks); michael@1: michael@1: // Parse the table for interesting values michael@1: for (int nIter = 0; nIter < nRows; nIter++) { michael@1: // Work on this tuple only if it within the reporting range michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); michael@1: Tempdate = QDate::fromString(m_pReptable->text(nIter, TITRAQ_IDXDATE), Qt::ISODate); michael@1: if (!Tempstring.isEmpty() && Firstday <= Tempdate && Tempdate < Lastday) { michael@3: string Convstring = Tempstring.toStdString(); // Convert to string (can't cast?) michael@1: QTime Intable = QTime::fromString(m_pReptable->text(nIter, TITRAQ_IDXAMOUNT), Qt::ISODate); michael@3: string Gethashed = Hashtasks[Convstring]; michael@3: int nTothours = QString::fromStdString(Gethashed).section(':', 0, 0).toInt() + Intable.hour();; michael@3: int nTotminut = QString::fromStdString(Gethashed).section(':', 1, 1).toInt() + Intable.minute(); michael@1: nTothours += nTotminut / 60; michael@1: nTotminut %= 60; michael@1: QString Hours = QString::number(nTothours).rightJustify(3, ' '); michael@1: QString Mins = QString::number(nTotminut).rightJustify(2, '0'); michael@3: string Timestring = Hours.toStdString() + ':' + Mins.toStdString(); // Convert to string (can't cast?) michael@1: Hashtasks[Convstring] = Timestring; // Finally store in hashtable michael@1: } michael@1: } michael@1: michael@1: // Reverse copy the tasks hashtable to both sort and index by amount key michael@1: for (Taskiter = Hashtasks.begin(); Taskiter != Hashtasks.end(); Taskiter++) michael@1: Hashhours.insert(pair(Taskiter->second, Taskiter->first)); michael@1: michael@1: // Write the actual data totals to the outgoing string in reverse order michael@1: for (Houriter = Hashhours.begin(); Houriter != Hashhours.end(); Houriter++) michael@3: Totals = QString::fromStdString(Houriter->first + ' ' + Houriter->second + '\n' + Totals.toStdString()); michael@1: michael@1: // Write some quick header text to the outgoing string in reverse order michael@1: Totals = QString("------ ----------------------------------------\n") + Totals; michael@1: Totals = trUtf8("Total Account summary\n") + Totals; michael@1: michael@1: return Totals; // The outgoing string... its finally gone, let's go to bed michael@1: } michael@1: michael@1: // michael@1: // Returns one month of details data michael@1: // michael@1: QString Reportpanel::getMonthdetails(QDate Dayref, int nMonths) michael@1: { michael@1: QString Data; // Output string michael@1: QString Tempstring; // Temp churning michael@1: QDate Tempdate; // For comparing michael@1: QDate Firstday; // Minimum boundary michael@1: QDate Lastday; // Maximum boundary michael@1: int nRows = m_pReptable->numRows(); michael@1: michael@1: // Find range boundaries michael@1: Q_ASSERT(nMonths > 0); michael@1: int nYear = Dayref.year(); michael@1: int nMonth = (Dayref.addMonths(nMonths * -1).month() + 12) % 12 + 1; michael@1: if (nMonth > Dayref.month()) michael@1: nYear--; michael@1: Firstday = QDate(nYear, nMonth, 1); michael@1: Lastday = QDate(Dayref.year(), Dayref.month(), Dayref.daysInMonth()); michael@1: michael@1: // Write some quick header text to the outgoing string michael@1: Data = trUtf8("\nDate Hours Account details\n"); michael@1: Data += QString("---------- ----- ----------------------------------------\n"); michael@1: michael@1: // Build the long week data string michael@1: for (int nIter = nRows - 1; nIter >= 0; nIter--) { michael@1: // Work on this tuple only if it within the reporting range michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); michael@1: Tempdate = QDate::fromString(m_pReptable->text(nIter, TITRAQ_IDXDATE), Qt::ISODate); michael@1: if (!Tempstring.isEmpty() && Firstday <= Tempdate && Tempdate < Lastday) { michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXDATE); michael@1: if (!Tempstring.isEmpty()) michael@1: Data += Tempstring; michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXAMOUNT); michael@1: if (!Tempstring.isEmpty()) michael@1: Data += QString(TITRAQ_SEPARATORTOK) + Tempstring; michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); michael@1: if (!Tempstring.isEmpty()) michael@1: Data += QString(TITRAQ_SEPARATORTOK) + Tempstring; michael@1: Data += trUtf8("\n"); // Finish off line michael@1: } michael@1: } michael@1: michael@1: return Data; michael@1: } michael@1: michael@1: // michael@1: // Returns one month of totals data michael@1: // michael@1: QString Reportpanel::getMonthtotals(QDate Dayref, int nMonths) michael@1: { michael@1: using namespace std; // Needed for maps and hash michael@1: map Hashtasks; // Hashtable to store tasks michael@1: multimap Hashhours; // Hashtable to store hours michael@1: map::iterator Taskiter; // Hashtable task iterator michael@1: multimap::iterator Houriter; // Hashtable hour iterator michael@1: michael@1: QString Totals; // Data totals to return for writing michael@1: QString Tempstring; // Temporary processing string michael@1: QDate Tempdate; // Temporary processing date michael@1: int nRows = m_pReptable->numRows(); michael@1: michael@1: // Find range boundaries michael@1: Q_ASSERT(nMonths > 0); michael@1: int nYear = Dayref.year(); michael@1: int nMonth = (Dayref.addMonths(nMonths * -1).month() + 12) % 12 + 1; michael@1: if (nMonth > Dayref.month()) michael@1: nYear--; michael@1: QDate Firstday = QDate(nYear, nMonth, 1); michael@1: QDate Lastday = QDate(Dayref.year(), Dayref.month(), Dayref.daysInMonth()); michael@1: michael@1: // Parse the table for interesting values michael@1: for (int nIter = 0; nIter < nRows; nIter++) { michael@1: // Work on this tuple only if it within the reporting range michael@1: Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); michael@1: Tempdate = QDate::fromString(m_pReptable->text(nIter, TITRAQ_IDXDATE), Qt::ISODate); michael@1: if (!Tempstring.isEmpty() && Firstday <= Tempdate && Tempdate < Lastday) { michael@3: string Convstring = Tempstring.toStdString(); // Convert to string (can't cast?) michael@1: QTime Intable = QTime::fromString(m_pReptable->text(nIter, TITRAQ_IDXAMOUNT), Qt::ISODate); michael@3: string Gethashed = Hashtasks[Convstring]; michael@3: int nTothours = QString::fromStdString(Gethashed).section(':', 0, 0).toInt() + Intable.hour();; michael@3: int nTotminut = QString::fromStdString(Gethashed).section(':', 1, 1).toInt() + Intable.minute(); michael@1: nTothours += nTotminut / 60; michael@1: nTotminut %= 60; michael@1: QString Hours = QString::number(nTothours).rightJustify(3, ' '); michael@1: QString Mins = QString::number(nTotminut).rightJustify(2, '0'); michael@3: QString Timestring = Hours + ':' + Mins; // Convert to string (can't cast?) michael@3: Hashtasks[Convstring] = Timestring.toStdString(); // Finally store in hashtable michael@1: } michael@1: } michael@1: michael@1: // Reverse copy the tasks hashtable to both sort and index by amount key michael@1: for (Taskiter = Hashtasks.begin(); Taskiter != Hashtasks.end(); Taskiter++) michael@1: Hashhours.insert(pair(Taskiter->second, Taskiter->first)); michael@1: michael@1: // Write the actual data totals to the outgoing string in reverse order michael@1: for (Houriter = Hashhours.begin(); Houriter != Hashhours.end(); Houriter++) michael@3: Totals = QString::fromStdString(Houriter->first + ' ' + Houriter->second + '\n' + Totals.toStdString()); michael@1: michael@1: // Write some quick header text to the outgoing string in reverse order michael@1: Totals = QString("------ ----------------------------------------\n") + Totals; michael@1: Totals = trUtf8("Total Account summary\n") + Totals; michael@1: michael@1: return Totals; // The outgoing string... its finally gone, let's go to bed michael@1: } michael@1: michael@1: // michael@1: // Saves the currently displayed local report michael@1: // michael@1: void Reportpanel::saveReport(void) michael@1: { michael@1: int nResult = 0; // For checking user's answer michael@1: QFile Report; // The resulting report file michael@1: QString Filestring; // The user chosen file name to save michael@1: QString Openas = m_pReprefs->getString(TITRAQ_PREFHOME, TITRAQ_DEFHOME); michael@1: michael@1: // And then get the name of the selected file to save to michael@3: Filestring = Q3FileDialog::getSaveFileName(Openas, trUtf8("Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to save"), NULL, false); michael@1: if (!Filestring.isEmpty()) { michael@1: if (QFile::exists(Filestring)) { michael@1: nResult = QMessageBox::warning(this, QString(TITRAQ_APPTITLE) michael@1: + ' ' + asgui_version.v_short, trUtf8(TITRAQ_OVERWRITE), michael@1: trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1); michael@1: if (nResult = QMessageBox::Ok) { // Overwrite a file michael@1: Report.setName(Filestring); // User wished name michael@3: Report.open(QIODevice::WriteOnly | QIODevice::Truncate); // Open report file michael@3: Q3TextStream Outstream(&Report); // Convert to stream michael@1: Outstream << m_pBrowser->text(); // Write the data michael@1: Report.close(); // Finish by closing michael@1: } michael@1: } michael@1: else { // User gave a file name, and there was no preexisting file there michael@1: Report.setName(Filestring); // User wished name michael@3: Report.open(QIODevice::WriteOnly | QIODevice::Truncate); // Open report file michael@3: Q3TextStream Outstream(&Report); // Convert to stream michael@1: Outstream << m_pBrowser->text(); // Write the data michael@1: Report.close(); // Finish by closing michael@1: } michael@1: } michael@1: // Otherwise, user did not select a valid file and push okay button michael@1: } michael@1: michael@1: // michael@1: // Prints the currently displayed local report michael@1: // michael@1: void Reportpanel::printReport(void) michael@1: { michael@1: #ifndef QT_NO_PRINTER michael@1: if (m_pPrinter->setup(this)) { // Opens printer dialog michael@1: m_pPrinter->setFullPage(true); // Set our own margins michael@1: QPainter Paint; // Our painter (for pages) michael@1: Paint.begin(m_pPrinter); // Paint on printer michael@1: Paint.setFont(m_pBrowser->font()); michael@1: QFontMetrics Fontmetrics = Paint.fontMetrics(); michael@3: Q3PaintDeviceMetrics Devmetrics(m_pPrinter); // Need width/height of printer surface michael@1: const int knMargin = Devmetrics.logicalDpiX() / 2; // Half-inch margin michael@1: int nYpos = knMargin; // Y position for each line michael@1: int nPageno = 1; // The starting page number michael@1: michael@1: for (int nIter = 0; nIter < m_pBrowser->lines() && !m_pPrinter->aborted(); nIter++) { michael@1: // See if there is some space on this page to paint on michael@1: if (nYpos + Fontmetrics.lineSpacing() > Devmetrics.height() - knMargin) { michael@1: // QString Printmsg(trUtf8("Printing page ")) michael@1: // + QString::number(++nPageno) + QString("..."); michael@1: // m_pStatus()->message(Printmsg); // Not in scope (crap) michael@1: if (!m_pPrinter->newPage()) // Start new page michael@1: break; // Some error michael@1: nYpos = knMargin; // Back to top of page michael@1: } michael@1: Paint.drawText(knMargin, nYpos, Devmetrics.width() - 2 * knMargin, michael@1: Fontmetrics.lineSpacing(), Qt::ExpandTabs, m_pBrowser->text(nIter)); michael@1: nYpos += Fontmetrics.lineSpacing(); michael@1: } michael@1: Paint.end(); // Send job to printer michael@1: // m_pStatus()->message(trUtf8("Printing completed"), 2000); // Not in scope michael@1: } michael@1: // m_pStatusBar()->message(trUtf8("Printing completed"), 2000); // Not in scope michael@1: #endif michael@1: } michael@1: michael@1: // michael@1: // Sets the strings of the subwidgets using the current language michael@1: // michael@1: void Reportpanel::textChange(void) michael@1: { michael@1: this->setCaption(trUtf8("AS local report", "Local report using weekly or monthly data.")); michael@1: michael@1: // Top level push buttons associated with accept and save slots michael@1: m_pSavebutt->setText(trUtf8("Save As...", "Comment for Savebutton")); michael@1: QToolTip::add(m_pSavebutt, trUtf8("Saves the report text", "Comment for tooltip Savebutton")); michael@3: Q3WhatsThis::add(m_pSavebutt, trUtf8("The save button saves the report text to a file", "Comment for whatsThis Savebutton")); michael@1: m_pPrintbutt->setText(trUtf8("Print...", "Comment for Printbutton")); michael@1: QToolTip::add(m_pPrintbutt, trUtf8("Print the report text", "Comment for tooltip Printbutton")); michael@3: Q3WhatsThis::add(m_pPrintbutt, trUtf8("The print button prints the report text to a file", "Comment for whatsThis Printbutton")); michael@1: m_pDismissbutt->setText(trUtf8("Dismiss", "Comment for Dismissbutton")); michael@1: QToolTip::add(m_pDismissbutt, trUtf8("Closes the report panel", "Comment for tooltip Dismissbutton")); michael@3: Q3WhatsThis::add(m_pDismissbutt, trUtf8("The dismiss button dismisses the report panel", "Comment for whatsThis Dismissbutton")); michael@1: michael@1: // Inner tool buttons for new local report generation michael@1: m_pWeeklybutt->setText(trUtf8("Weekly", "Comment for Weeklybutt")); michael@1: QToolTip::add(m_pWeeklybutt, trUtf8("Hold down for options", "Comment for tooltip Weeklybutt")); michael@3: Q3WhatsThis::add(m_pWeeklybutt, trUtf8("The Weekly button generates a new weekly report.\nHold this button down to specify many weeks.", "Comment for whatsThis Weeklybutt")); michael@1: m_pMonthlybutt->setText(trUtf8("Monthly", "Comment for Monthlybutt")); michael@1: QToolTip::add(m_pMonthlybutt, trUtf8("Hold down for options", "Comment for tooltip Monthlybutt")); michael@3: Q3WhatsThis::add(m_pMonthlybutt, trUtf8("The Monthly button makes a new monthly report.\nHold this button down to specify how many months.", "Comment for whatsThis Monthlybutt")); michael@1: } michael@1: } // namespace AS