Thu, 06 Aug 2009 13:21:30 +0200
Remove seemingly declarations unnecessary according to Qt 4.5.2 headers.
michael@1 | 1 | // |
michael@1 | 2 | // OSSP asgui - Accounting system graphical user interface |
michael@12 | 3 | // Copyright (c) 2002-2009 The OSSP Project (http://www.ossp.org/) |
michael@12 | 4 | // Copyright (c) 2002-2009 Ralf S. Engelschall <rse@engelschall.com> |
michael@12 | 5 | // Copyright (c) 2002-2009 Michael Schloh von Bennewitz <michael@schloh.com> |
michael@12 | 6 | // Copyright (c) 2002-2009 Cable & Wireless Telecommunications Services GmbH |
michael@1 | 7 | // |
michael@1 | 8 | // This file is part of OSSP asgui, an accounting system graphical user |
michael@3 | 9 | // interface which can be found at http://asgui.europalab.com/. |
michael@1 | 10 | // |
michael@1 | 11 | // Permission to use, copy, modify, and distribute this software for |
michael@1 | 12 | // any purpose with or without fee is hereby granted, provided that |
michael@1 | 13 | // the above copyright notice and this permission notice appear in all |
michael@1 | 14 | // copies. |
michael@1 | 15 | // |
michael@1 | 16 | // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
michael@1 | 17 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
michael@1 | 18 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
michael@1 | 19 | // IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR |
michael@1 | 20 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@1 | 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@1 | 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
michael@1 | 23 | // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
michael@1 | 24 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
michael@1 | 25 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
michael@1 | 26 | // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
michael@1 | 27 | // SUCH DAMAGE. |
michael@1 | 28 | // |
michael@1 | 29 | // as_reportpanel.cpp: ISO C++ implementation |
michael@1 | 30 | // |
michael@1 | 31 | |
michael@1 | 32 | #include <qvariant.h> |
michael@1 | 33 | #include <qpushbutton.h> |
michael@3 | 34 | #include <q3textedit.h> |
michael@1 | 35 | #include <qtoolbutton.h> |
michael@3 | 36 | #include <q3buttongroup.h> |
michael@3 | 37 | #include <q3popupmenu.h> |
michael@1 | 38 | #include <qlayout.h> |
michael@1 | 39 | #include <qtooltip.h> |
michael@3 | 40 | #include <q3whatsthis.h> |
michael@3 | 41 | #include <q3textstream.h> |
michael@3 | 42 | #include <q3filedialog.h> |
michael@1 | 43 | #include <qprinter.h> |
michael@3 | 44 | #include <q3paintdevicemetrics.h> |
michael@1 | 45 | #include <qpainter.h> |
michael@1 | 46 | #include <qfile.h> |
michael@1 | 47 | #include <qdir.h> |
michael@1 | 48 | |
michael@3 | 49 | //Added by qt3to4: |
michael@3 | 50 | #include <Q3HBoxLayout> |
michael@3 | 51 | #include <Q3Frame> |
michael@3 | 52 | #include <Q3VBoxLayout> |
michael@3 | 53 | |
michael@1 | 54 | #include "as_reportpanel.h" |
michael@1 | 55 | #include "as_numdial.h" |
michael@1 | 56 | #include "as_table.h" |
michael@1 | 57 | #include "as_pref.h" |
michael@1 | 58 | #include "as_generic.h" |
michael@1 | 59 | #include "as_const.h" |
michael@1 | 60 | #include "as_except.h" |
michael@1 | 61 | |
michael@1 | 62 | // Version information |
michael@1 | 63 | #define _AS_VERSION_CPP_AS_HEADER_ |
michael@1 | 64 | #include "as_version.cpp" |
michael@1 | 65 | #undef _AS_VERSION_CPP_AS_HEADER_ |
michael@1 | 66 | |
michael@1 | 67 | |
michael@1 | 68 | namespace AS { |
michael@1 | 69 | |
michael@1 | 70 | // |
michael@1 | 71 | // Constructs a Reportpanel as a child of 'pParent', with the |
michael@1 | 72 | // name 'kszName' and widget flags set to 'Flags'. |
michael@1 | 73 | // |
michael@1 | 74 | // The dialog will by default be modal, unless you set 'bModal' to |
michael@1 | 75 | // false to construct a modeless dialog. |
michael@1 | 76 | // |
michael@1 | 77 | Reportpanel::Reportpanel(TiTable *pTable, Preferences *pPreferences, |
michael@1 | 78 | QWidget *pParent, const char *kszName, |
michael@3 | 79 | bool bModal, Qt::WFlags Flags) |
michael@1 | 80 | : QDialog(pParent, kszName, bModal, Flags) |
michael@1 | 81 | { |
michael@1 | 82 | // Boilerplate code to initialize the panel |
michael@1 | 83 | if (!kszName) |
michael@1 | 84 | this->setName("Reportpanel"); |
michael@1 | 85 | |
michael@1 | 86 | // Make panel resizeable |
michael@1 | 87 | this->setSizeGripEnabled(true); |
michael@1 | 88 | this->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, |
michael@1 | 89 | (QSizePolicy::SizeType)5, 0, 0, this->sizePolicy().hasHeightForWidth())); |
michael@1 | 90 | |
michael@1 | 91 | // Store matrix and prefs members |
michael@1 | 92 | m_pReptable = pTable; |
michael@1 | 93 | m_pReprefs = pPreferences; |
michael@1 | 94 | m_pPrinter = new QPrinter; |
michael@1 | 95 | |
michael@1 | 96 | // Preset number of weeks and months to report |
michael@1 | 97 | m_nWeeks = m_pReprefs->getNumber(TITRAQ_PREFREPORTWEEKS, TITRAQ_DEFREPORTWEEKS); |
michael@1 | 98 | m_nMonths = m_pReprefs->getNumber(TITRAQ_PREFREPORTMONTHS, TITRAQ_DEFREPORTMONTHS); |
michael@1 | 99 | |
michael@1 | 100 | // Build panel using already constructed widgets and layouts |
michael@3 | 101 | m_pFormlay = new Q3VBoxLayout(this, 11, 6, "Formlayout"); |
michael@3 | 102 | m_pToolay = new Q3HBoxLayout(0, 0, 6, "Toolbuttonlay"); |
michael@3 | 103 | m_pPushlay = new Q3HBoxLayout(0, 0, 6, "Pushbuttonlay"); |
michael@1 | 104 | |
michael@1 | 105 | // Groupbox and its text display |
michael@3 | 106 | m_pBrowser = new Q3TextEdit(this, "Reportbrowser"); |
michael@3 | 107 | m_pBrowser->setTextFormat(Qt::PlainText); |
michael@1 | 108 | m_pBrowser->setReadOnly(true); |
michael@1 | 109 | m_pBrowser->setFont(QFont("Courier", 10)); |
michael@1 | 110 | m_pFormlay->addWidget(m_pBrowser); |
michael@1 | 111 | m_pFormlay->addSpacing(6); |
michael@1 | 112 | m_pFormlay->addLayout(m_pToolay); |
michael@1 | 113 | m_pFormlay->addSpacing(6); |
michael@1 | 114 | m_pFormlay->addLayout(m_pPushlay); |
michael@1 | 115 | |
michael@1 | 116 | // Tool button suite |
michael@3 | 117 | m_pWeekmonthgroup = new Q3ButtonGroup(this, "Weekmonthgroup"); |
michael@1 | 118 | m_pWeekmonthgroup->setColumnLayout(0, Qt::Horizontal); |
michael@1 | 119 | m_pWeekmonthgroup->layout()->setSpacing(11); |
michael@1 | 120 | m_pWeekmonthgroup->layout()->setMargin(0); |
michael@3 | 121 | m_pWeekmonthlay = new Q3HBoxLayout(m_pWeekmonthgroup->layout()); |
michael@3 | 122 | //m_pWeekmonthgroup->setFrameShape(QFrame::NoFrame); |
michael@1 | 123 | m_pWeekmonthgroup->setExclusive(true); |
michael@1 | 124 | m_pWeeklybutt = new QToolButton(m_pWeekmonthgroup, "Weeklybutton"); |
michael@1 | 125 | // m_pWeeklybutt->setPaletteBackgroundColor(QColor(198, 196, 186)); |
michael@3 | 126 | m_pWeeklybutt->setFocusPolicy(Qt::TabFocus); |
michael@14 | 127 | m_pWeeklybutt->setCursor(QCursor(Qt::PointingHandCursor)); |
michael@1 | 128 | m_pWeeklybutt->setToggleButton(true); |
michael@1 | 129 | m_pMonthlybutt = new QToolButton(m_pWeekmonthgroup, "Monthlybutton"); |
michael@1 | 130 | // m_pMonthlybutt->setPaletteBackgroundColor(QColor(198, 196, 186)); |
michael@3 | 131 | m_pMonthlybutt->setFocusPolicy(Qt::TabFocus); |
michael@14 | 132 | m_pMonthlybutt->setCursor(QCursor(Qt::PointingHandCursor)); |
michael@1 | 133 | m_pMonthlybutt->setToggleButton(true); |
michael@1 | 134 | |
michael@1 | 135 | // Popup for number of weeks |
michael@3 | 136 | m_pWeekpop = new Q3PopupMenu(this); |
michael@1 | 137 | if (m_pWeekpop == NULL) // Sanity check |
michael@1 | 138 | throw Genexcept("Weekly toolbutton popup creation failed."); |
michael@1 | 139 | m_pWeekpop->insertItem(trUtf8("One week"), this, SLOT(reportWeeks(int))); |
michael@1 | 140 | m_pWeekpop->insertItem(trUtf8("Two weeks"), this, SLOT(reportWeeks(int))); |
michael@1 | 141 | m_pWeekpop->insertItem(trUtf8("Three weeks"), this, SLOT(reportWeeks(int))); |
michael@1 | 142 | m_pWeekpop->insertItem(trUtf8("Four weeks"), this, SLOT(reportWeeks(int))); |
michael@1 | 143 | m_pWeekpop->insertItem(trUtf8("N... weeks"), this, SLOT(reportWeeks(int))); |
michael@1 | 144 | m_pWeekpop->setCheckable(true); |
michael@1 | 145 | m_pWeeklybutt->setPopup(m_pWeekpop); |
michael@1 | 146 | m_pWeeklybutt->setPopupDelay(TITRAQ_POPUPMSECS); |
michael@1 | 147 | |
michael@1 | 148 | { // Initialize check button correctly |
michael@1 | 149 | int nPosition = (m_nWeeks < m_pWeekpop->count()) ? m_nWeeks : m_pWeekpop->count(); |
michael@1 | 150 | m_pWeekpop->setItemChecked(m_pWeekpop->idAt(--nPosition), true); |
michael@1 | 151 | } |
michael@1 | 152 | |
michael@1 | 153 | // Popup for number of months |
michael@3 | 154 | m_pMonthpop = new Q3PopupMenu(this); |
michael@1 | 155 | if (m_pMonthpop == NULL) // Sanity check |
michael@1 | 156 | throw Genexcept("Monthly toolbutton popup creation failed."); |
michael@1 | 157 | m_pMonthpop->insertItem(trUtf8("One month"), this, SLOT(reportMonths(int))); |
michael@1 | 158 | m_pMonthpop->insertItem(trUtf8("Two months"), this, SLOT(reportMonths(int))); |
michael@1 | 159 | m_pMonthpop->insertItem(trUtf8("Three months"), this, SLOT(reportMonths(int))); |
michael@1 | 160 | m_pMonthpop->insertItem(trUtf8("Four months"), this, SLOT(reportMonths(int))); |
michael@1 | 161 | m_pMonthpop->insertItem(trUtf8("N... months"), this, SLOT(reportMonths(int))); |
michael@1 | 162 | m_pMonthpop->setCheckable(true); |
michael@1 | 163 | m_pMonthlybutt->setPopup(m_pMonthpop); |
michael@1 | 164 | m_pMonthlybutt->setPopupDelay(TITRAQ_POPUPMSECS); |
michael@1 | 165 | |
michael@1 | 166 | { // Initialize check button correctly |
michael@1 | 167 | int nPosition = (m_nMonths < m_pMonthpop->count()) ? m_nMonths : m_pMonthpop->count(); |
michael@1 | 168 | m_pMonthpop->setItemChecked(m_pMonthpop->idAt(--nPosition), true); |
michael@1 | 169 | } |
michael@1 | 170 | |
michael@1 | 171 | // Add our tool buttons |
michael@1 | 172 | m_pWeekmonthlay->addWidget(m_pWeeklybutt); |
michael@1 | 173 | m_pWeekmonthlay->addWidget(m_pMonthlybutt); |
michael@1 | 174 | m_pToolay->addWidget(m_pWeekmonthgroup); |
michael@1 | 175 | |
michael@1 | 176 | // Push button suite |
michael@1 | 177 | m_pSavebutt = new QPushButton(this, "Savebutton"); |
michael@1 | 178 | m_pSavebutt->setPaletteBackgroundColor(QColor(202, 194, 182)); |
michael@14 | 179 | m_pSavebutt->setCursor(QCursor(Qt::PointingHandCursor)); |
michael@1 | 180 | m_pPrintbutt = new QPushButton(this, "Printbutton"); |
michael@1 | 181 | m_pPrintbutt->setPaletteBackgroundColor(QColor(198, 196, 186)); |
michael@14 | 182 | m_pPrintbutt->setCursor(QCursor(Qt::PointingHandCursor)); |
michael@1 | 183 | #ifdef QT_NO_PRINTER |
michael@1 | 184 | m_pPrintbutt->setEnabled(false); |
michael@1 | 185 | #endif |
michael@1 | 186 | m_pDismissbutt = new QPushButton(this, "Dismissbutton"); |
michael@1 | 187 | m_pDismissbutt->setPaletteBackgroundColor(QColor(198, 196, 186)); |
michael@14 | 188 | m_pDismissbutt->setCursor(QCursor(Qt::PointingHandCursor)); |
michael@1 | 189 | m_pDismissbutt->setDefault(true); |
michael@1 | 190 | m_pPushlay->addWidget(m_pSavebutt); |
michael@1 | 191 | m_pPushlay->addWidget(m_pPrintbutt); |
michael@1 | 192 | m_pPushlay->addWidget(m_pDismissbutt); |
michael@1 | 193 | |
michael@1 | 194 | // Connect signals to slots, accept() and reject() are Qt implicit |
michael@1 | 195 | connect(m_pWeeklybutt, SIGNAL(clicked(void)), SLOT(reportWeeks(void))); |
michael@1 | 196 | connect(m_pMonthlybutt, SIGNAL(clicked(void)), SLOT(reportMonths(void))); |
michael@1 | 197 | connect(m_pSavebutt, SIGNAL(clicked(void)), SLOT(saveReport(void))); |
michael@1 | 198 | connect(m_pPrintbutt, SIGNAL(clicked(void)), SLOT(printReport(void))); |
michael@1 | 199 | connect(m_pDismissbutt, SIGNAL(clicked(void)), SLOT(accept(void))); |
michael@1 | 200 | this->resize(QSize(464, 332).expandedTo(minimumSizeHint())); |
michael@1 | 201 | this->textChange(); |
michael@1 | 202 | } |
michael@1 | 203 | |
michael@1 | 204 | // |
michael@1 | 205 | // Overload QDialog::exec(), and generate a report before executing modally |
michael@1 | 206 | // |
michael@1 | 207 | int Reportpanel::exec(void) |
michael@1 | 208 | { |
michael@1 | 209 | int nRet = 0; |
michael@1 | 210 | int nPeriod = m_pReprefs->getNumber(TITRAQ_PREFREPORTYPE, TITRAQ_DEFREPORTYPE); |
michael@1 | 211 | |
michael@1 | 212 | switch (nPeriod) { |
michael@1 | 213 | case TITRAQ_REPORTWEEK: |
michael@1 | 214 | this->reportWeeks(1); |
michael@1 | 215 | m_pWeekmonthgroup->setButton(TITRAQ_REPORTWEEK); |
michael@1 | 216 | break; |
michael@1 | 217 | case TITRAQ_REPORTMONTH: |
michael@1 | 218 | this->reportMonths(1); |
michael@1 | 219 | m_pWeekmonthgroup->setButton(TITRAQ_REPORTMONTH); |
michael@1 | 220 | break; |
michael@1 | 221 | default: |
michael@1 | 222 | throw Genexcept("Reportpanel: Modal event loop entered with no report period."); |
michael@1 | 223 | break; |
michael@1 | 224 | } |
michael@1 | 225 | |
michael@1 | 226 | nRet = QDialog::exec(); // Blast off |
michael@1 | 227 | |
michael@1 | 228 | // Before losing scope, the preferred report period |
michael@1 | 229 | m_pReprefs->setNumber(TITRAQ_PREFREPORTYPE, |
michael@1 | 230 | m_pWeekmonthgroup->id(m_pWeekmonthgroup->selected())); |
michael@1 | 231 | m_pReprefs->setNumber(TITRAQ_PREFREPORTWEEKS, m_nWeeks); |
michael@1 | 232 | m_pReprefs->setNumber(TITRAQ_PREFREPORTMONTHS, m_nMonths); |
michael@1 | 233 | return nRet; |
michael@1 | 234 | } |
michael@1 | 235 | |
michael@1 | 236 | // |
michael@1 | 237 | // Makes a new weekly report of so many weeks |
michael@1 | 238 | // |
michael@1 | 239 | void Reportpanel::reportWeeks(int nMenuid) |
michael@1 | 240 | { |
michael@1 | 241 | // Range of weeks to report |
michael@1 | 242 | int nFirstweek, nLastweek; |
michael@1 | 243 | |
michael@1 | 244 | // Menu index, first item is always 0 |
michael@1 | 245 | int nIndex = m_pWeekpop->indexOf(nMenuid); // Corresponds to weeks |
michael@1 | 246 | int nLastid = 0; // Last menu id selected |
michael@1 | 247 | |
michael@1 | 248 | if (m_nWeeks < m_pWeekpop->count()) |
michael@1 | 249 | nLastid = m_pWeekpop->idAt(m_nWeeks - 1); // Probably not last item |
michael@1 | 250 | else |
michael@1 | 251 | nLastid = m_pWeekpop->idAt(m_pWeekpop->count() - 1); // Last item selected |
michael@1 | 252 | |
michael@1 | 253 | // Set the button in case from a menu selection |
michael@1 | 254 | m_pWeekmonthgroup->setButton(TITRAQ_REPORTWEEK); |
michael@1 | 255 | |
michael@1 | 256 | // Update m_nWeeks only if user prefers a different number |
michael@1 | 257 | if (nIndex >= 0) { |
michael@1 | 258 | // User selected N... to indicate an arbitrary number |
michael@1 | 259 | if (nIndex == m_pWeekpop->count() - 1) { |
michael@1 | 260 | Numdial Weeksinput; |
michael@1 | 261 | Weeksinput.setNum(m_nWeeks); |
michael@1 | 262 | if (Weeksinput.exec() == QDialog::Accepted) { |
michael@1 | 263 | m_nWeeks = Weeksinput.getNum(); |
michael@1 | 264 | m_pWeekpop->setItemChecked(nLastid, false); |
michael@1 | 265 | m_pWeekpop->setItemChecked(nMenuid, true); |
michael@1 | 266 | } |
michael@1 | 267 | else |
michael@1 | 268 | return; |
michael@1 | 269 | } |
michael@1 | 270 | else { // User selected a preset menu item such as '2 weeks' |
michael@1 | 271 | m_nWeeks = nIndex + 1; |
michael@1 | 272 | m_pWeekpop->setItemChecked(nLastid, false); |
michael@1 | 273 | m_pWeekpop->setItemChecked(nMenuid, true); |
michael@1 | 274 | } |
michael@1 | 275 | } |
michael@1 | 276 | |
michael@1 | 277 | // Clear data window |
michael@1 | 278 | m_pBrowser->setUpdatesEnabled(false); |
michael@1 | 279 | m_pBrowser->clear(); |
michael@1 | 280 | |
michael@1 | 281 | // Determine first and last week numbers, then write header |
michael@1 | 282 | nLastweek = QDate::currentDate().weekNumber(); |
michael@1 | 283 | if (m_nWeeks > 1) { |
michael@1 | 284 | nFirstweek = QDate::currentDate().addDays(m_nWeeks * -7).weekNumber() + 1; |
michael@1 | 285 | this->writeHeader(nFirstweek, nLastweek); |
michael@1 | 286 | } |
michael@1 | 287 | else |
michael@1 | 288 | this->writeHeader(nLastweek); |
michael@1 | 289 | |
michael@1 | 290 | // Write new contents to data window |
michael@1 | 291 | m_pBrowser->append(this->getWeektotals(QDate::currentDate(), m_nWeeks)); |
michael@1 | 292 | if (m_pReprefs->getBool(TITRAQ_PREFDETAILON, TITRAQ_DEFDETAILON)) |
michael@1 | 293 | m_pBrowser->append(this->getWeekdetails(QDate::currentDate(), m_nWeeks)); |
michael@1 | 294 | this->writeFooter(); |
michael@1 | 295 | m_pBrowser->setCursorPosition(0, 0); |
michael@1 | 296 | m_pBrowser->ensureCursorVisible(); |
michael@1 | 297 | m_pBrowser->setUpdatesEnabled(true); |
michael@1 | 298 | m_pBrowser->repaint(false); |
michael@1 | 299 | } |
michael@1 | 300 | |
michael@1 | 301 | // |
michael@1 | 302 | // Makes a new monthly report of so many months |
michael@1 | 303 | // |
michael@1 | 304 | void Reportpanel::reportMonths(int nMenuid) |
michael@1 | 305 | { |
michael@1 | 306 | // Range of months to report |
michael@1 | 307 | QString Firstmonth, Lastmonth; |
michael@1 | 308 | |
michael@1 | 309 | // Menu index, first item is always 0 |
michael@1 | 310 | int nIndex = m_pMonthpop->indexOf(nMenuid); // Corresponds to months |
michael@1 | 311 | int nLastid = 0; // Last menu id selected |
michael@1 | 312 | |
michael@1 | 313 | if (m_nMonths < m_pMonthpop->count()) |
michael@1 | 314 | nLastid = m_pMonthpop->idAt(m_nMonths - 1); // Probably not last item |
michael@1 | 315 | else |
michael@1 | 316 | nLastid = m_pMonthpop->idAt(m_pMonthpop->count() - 1); // Last item selected |
michael@1 | 317 | |
michael@1 | 318 | // Set the button in case from a menu selection |
michael@1 | 319 | m_pWeekmonthgroup->setButton(TITRAQ_REPORTMONTH); |
michael@1 | 320 | |
michael@1 | 321 | // Update m_nMonths only if user prefers a different number |
michael@1 | 322 | if (nIndex >= 0) { |
michael@1 | 323 | // User selected N... to indicate an arbitrary number |
michael@1 | 324 | if (nIndex == m_pMonthpop->count() - 1) { |
michael@1 | 325 | Numdial Monthsinput; |
michael@1 | 326 | Monthsinput.setNum(m_nMonths); |
michael@1 | 327 | if (Monthsinput.exec() == QDialog::Accepted) { |
michael@1 | 328 | m_nMonths = Monthsinput.getNum(); |
michael@1 | 329 | m_pMonthpop->setItemChecked(nLastid, false); |
michael@1 | 330 | m_pMonthpop->setItemChecked(nMenuid, true); |
michael@1 | 331 | } |
michael@1 | 332 | else |
michael@1 | 333 | return; |
michael@1 | 334 | } |
michael@1 | 335 | else { // User selected a preset menu item such as '2 months' |
michael@1 | 336 | m_nMonths = nIndex + 1; |
michael@1 | 337 | m_pMonthpop->setItemChecked(nLastid, false); |
michael@1 | 338 | m_pMonthpop->setItemChecked(nMenuid, true); |
michael@1 | 339 | } |
michael@1 | 340 | } |
michael@1 | 341 | |
michael@1 | 342 | // Clear data window |
michael@1 | 343 | m_pBrowser->setUpdatesEnabled(false); |
michael@1 | 344 | m_pBrowser->clear(); |
michael@1 | 345 | |
michael@1 | 346 | // Determine first and last month names, then write header |
michael@1 | 347 | Lastmonth = QDate::longMonthName(QDate::currentDate().month()); |
michael@1 | 348 | if (m_nMonths > 1) { |
michael@1 | 349 | int nMonth = (QDate::currentDate().addMonths(m_nMonths * -1).month() + 12) % 12 + 1; |
michael@1 | 350 | Firstmonth = QDate::longMonthName(nMonth); |
michael@1 | 351 | this->writeHeader(Firstmonth, Lastmonth); |
michael@1 | 352 | } |
michael@1 | 353 | else |
michael@1 | 354 | this->writeHeader(Lastmonth); |
michael@1 | 355 | |
michael@1 | 356 | // Write new contents to data window |
michael@1 | 357 | m_pBrowser->append(this->getMonthtotals(QDate::currentDate(), m_nMonths)); |
michael@1 | 358 | if (m_pReprefs->getBool(TITRAQ_PREFDETAILON, TITRAQ_DEFDETAILON)) { |
michael@1 | 359 | m_pBrowser->append(this->getMonthdetails(QDate::currentDate(), m_nMonths)); |
michael@1 | 360 | } |
michael@1 | 361 | this->writeFooter(); |
michael@1 | 362 | m_pBrowser->setCursorPosition(0, 0); |
michael@1 | 363 | m_pBrowser->ensureCursorVisible(); |
michael@1 | 364 | m_pBrowser->setUpdatesEnabled(true); |
michael@1 | 365 | m_pBrowser->repaint(false); |
michael@1 | 366 | } |
michael@1 | 367 | |
michael@1 | 368 | // |
michael@1 | 369 | // Writes a report header to the display window |
michael@1 | 370 | // |
michael@1 | 371 | void Reportpanel::writeHeader(int nWeeknum) |
michael@1 | 372 | { |
michael@1 | 373 | QString Header; |
michael@1 | 374 | Header = QString("Accounting System "); |
michael@1 | 375 | Header += QString(asgui_version.v_short); |
michael@1 | 376 | Header += trUtf8("\nLocal report, username '"); |
michael@1 | 377 | Header += m_pReprefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER); |
michael@1 | 378 | Header += QString("'\n"); |
michael@1 | 379 | Header += trUtf8("Date "); |
michael@1 | 380 | Header += QDate::currentDate().toString(Qt::ISODate); |
michael@1 | 381 | Header += trUtf8(", Time "); |
michael@1 | 382 | Header += QTime::currentTime().toString(Qt::ISODate); |
michael@1 | 383 | Header += trUtf8("\nReporting for week %1...").arg(nWeeknum); |
michael@1 | 384 | Header += QString("\n\n"); |
michael@1 | 385 | m_pBrowser->setText(Header); |
michael@1 | 386 | } |
michael@1 | 387 | |
michael@1 | 388 | // |
michael@1 | 389 | // Writes a report header to the display window |
michael@1 | 390 | // |
michael@1 | 391 | void Reportpanel::writeHeader(QString Month) |
michael@1 | 392 | { |
michael@1 | 393 | QString Header; |
michael@1 | 394 | Header = QString("Accounting System "); |
michael@1 | 395 | Header += QString(asgui_version.v_short); |
michael@1 | 396 | Header += trUtf8("\nLocal report, username '"); |
michael@1 | 397 | Header += m_pReprefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER); |
michael@1 | 398 | Header += QString("'\n"); |
michael@1 | 399 | Header += trUtf8("Date "); |
michael@1 | 400 | Header += QDate::currentDate().toString(Qt::ISODate); |
michael@1 | 401 | Header += trUtf8(", Time "); |
michael@1 | 402 | Header += QTime::currentTime().toString(Qt::ISODate); |
michael@1 | 403 | Header += trUtf8("\nReporting for month %1...").arg(Month); |
michael@1 | 404 | Header += QString("\n\n"); |
michael@1 | 405 | m_pBrowser->setText(Header); |
michael@1 | 406 | } |
michael@1 | 407 | |
michael@1 | 408 | // |
michael@1 | 409 | // Writes a report header to the display window |
michael@1 | 410 | // |
michael@1 | 411 | void Reportpanel::writeHeader(int nFirst, int nLast) |
michael@1 | 412 | { |
michael@1 | 413 | QString Header; |
michael@1 | 414 | Header = QString("Accounting System "); |
michael@1 | 415 | Header += QString(asgui_version.v_short); |
michael@1 | 416 | Header += trUtf8("\nLocal report, username '"); |
michael@1 | 417 | Header += m_pReprefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER); |
michael@1 | 418 | Header += QString("'\n"); |
michael@1 | 419 | Header += trUtf8("Date "); |
michael@1 | 420 | Header += QDate::currentDate().toString(Qt::ISODate); |
michael@1 | 421 | Header += trUtf8(", Time "); |
michael@1 | 422 | Header += QTime::currentTime().toString(Qt::ISODate); |
michael@1 | 423 | Header += trUtf8("\nReporting for weeks %1 through %2...").arg(nFirst).arg(nLast); |
michael@1 | 424 | Header += QString("\n\n"); |
michael@1 | 425 | m_pBrowser->setText(Header); |
michael@1 | 426 | } |
michael@1 | 427 | |
michael@1 | 428 | // |
michael@1 | 429 | // Writes a report header to the display window |
michael@1 | 430 | // |
michael@1 | 431 | void Reportpanel::writeHeader(QString First, QString Last) |
michael@1 | 432 | { |
michael@1 | 433 | QString Header; |
michael@1 | 434 | Header = QString("Accounting System "); |
michael@1 | 435 | Header += QString(asgui_version.v_short); |
michael@1 | 436 | Header += trUtf8("\nLocal report, username '"); |
michael@1 | 437 | Header += m_pReprefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER); |
michael@1 | 438 | Header += QString("'\n"); |
michael@1 | 439 | Header += trUtf8("Date "); |
michael@1 | 440 | Header += QDate::currentDate().toString(Qt::ISODate); |
michael@1 | 441 | Header += trUtf8(", Time "); |
michael@1 | 442 | Header += QTime::currentTime().toString(Qt::ISODate); |
michael@1 | 443 | Header += trUtf8("\nReporting months %1 through %2...").arg(First).arg(Last); |
michael@1 | 444 | Header += QString("\n\n"); |
michael@1 | 445 | m_pBrowser->setText(Header); |
michael@1 | 446 | } |
michael@1 | 447 | |
michael@1 | 448 | // |
michael@1 | 449 | // Writes a report footer to the display window |
michael@1 | 450 | // |
michael@1 | 451 | void Reportpanel::writeFooter(void) |
michael@1 | 452 | { |
michael@1 | 453 | if (m_pReprefs->getBool(TITRAQ_PREFSIGNATON, TITRAQ_DEFSIGNATON)) { |
michael@1 | 454 | m_pBrowser->append(trUtf8("\n\nPrint name ________________________________________\n")); |
michael@1 | 455 | m_pBrowser->append(trUtf8("\n\nSignature ________________________________________")); |
michael@1 | 456 | } |
michael@1 | 457 | } |
michael@1 | 458 | |
michael@1 | 459 | // |
michael@1 | 460 | // Returns one week of details data |
michael@1 | 461 | // |
michael@1 | 462 | QString Reportpanel::getWeekdetails(QDate Dayref, int nWeeks) |
michael@1 | 463 | { |
michael@1 | 464 | QString Data; // Output string |
michael@1 | 465 | QString Tempstring; // Temp churning |
michael@1 | 466 | int nRows = m_pReptable->numRows(); |
michael@1 | 467 | |
michael@1 | 468 | // Find range boundaries |
michael@1 | 469 | Q_ASSERT(nWeeks > 0); |
michael@1 | 470 | QDate Tempdate; |
michael@1 | 471 | QDate Firstday; |
michael@1 | 472 | QDate Lastday; |
michael@1 | 473 | Firstday = Dayref.addDays(Dayref.dayOfWeek() * -1 + 1); |
michael@1 | 474 | Firstday = Firstday.addDays((nWeeks - 1) * -7); |
michael@1 | 475 | Lastday = Firstday.addDays(7 * nWeeks); |
michael@1 | 476 | |
michael@1 | 477 | // Write some quick header text to the outgoing string |
michael@1 | 478 | Data = trUtf8("\nDate Hours Account details\n"); |
michael@1 | 479 | Data += QString("---------- ----- ----------------------------------------\n"); |
michael@1 | 480 | |
michael@1 | 481 | // Build the long week data string |
michael@1 | 482 | for (int nIter = nRows - 1; nIter >= 0; nIter--) { |
michael@1 | 483 | // Work on this tuple only if it within the reporting range |
michael@1 | 484 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); |
michael@1 | 485 | Tempdate = QDate::fromString(m_pReptable->text(nIter, TITRAQ_IDXDATE), Qt::ISODate); |
michael@1 | 486 | if (!Tempstring.isEmpty() && Firstday <= Tempdate && Tempdate < Lastday) { |
michael@1 | 487 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXDATE); |
michael@1 | 488 | if (!Tempstring.isEmpty()) |
michael@1 | 489 | Data += Tempstring; |
michael@1 | 490 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXAMOUNT); |
michael@1 | 491 | if (!Tempstring.isEmpty()) |
michael@1 | 492 | Data += QString(TITRAQ_SEPARATORTOK) + Tempstring; |
michael@1 | 493 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); |
michael@1 | 494 | if (!Tempstring.isEmpty()) |
michael@1 | 495 | Data += QString(TITRAQ_SEPARATORTOK) + Tempstring; |
michael@1 | 496 | Data += QString("\n"); // Finish off line |
michael@1 | 497 | } |
michael@1 | 498 | } |
michael@1 | 499 | |
michael@1 | 500 | return Data; |
michael@1 | 501 | } |
michael@1 | 502 | |
michael@1 | 503 | // |
michael@1 | 504 | // Returns one week of totals data |
michael@1 | 505 | // |
michael@1 | 506 | QString Reportpanel::getWeektotals(QDate Dayref, int nWeeks) |
michael@1 | 507 | { |
michael@1 | 508 | using namespace std; // Needed for maps and hash |
michael@1 | 509 | map<string, string> Hashtasks; // Hashtable to store tasks |
michael@1 | 510 | multimap<string, string> Hashhours; // Hashtable to store hours |
michael@1 | 511 | map<string, string>::iterator Taskiter; // Hashtable task iterator |
michael@1 | 512 | multimap<string, string>::iterator Houriter; // Hashtable hour iterator |
michael@1 | 513 | |
michael@1 | 514 | QString Totals; // Data totals to return for writing |
michael@1 | 515 | QString Tempstring; // Temporary processing string |
michael@1 | 516 | QDate Tempdate; // Temporary processing date |
michael@1 | 517 | int nRows = m_pReptable->numRows(); |
michael@1 | 518 | |
michael@1 | 519 | // Find range boundaries |
michael@1 | 520 | Q_ASSERT(nWeeks > 0); |
michael@1 | 521 | QDate Firstday; |
michael@1 | 522 | QDate Lastday; |
michael@1 | 523 | Firstday = Dayref.addDays(Dayref.dayOfWeek() * -1 + 1); |
michael@1 | 524 | Firstday = Firstday.addDays((nWeeks - 1) * -7); |
michael@1 | 525 | Lastday = Firstday.addDays(7 * nWeeks); |
michael@1 | 526 | |
michael@1 | 527 | // Parse the table for interesting values |
michael@1 | 528 | for (int nIter = 0; nIter < nRows; nIter++) { |
michael@1 | 529 | // Work on this tuple only if it within the reporting range |
michael@1 | 530 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); |
michael@1 | 531 | Tempdate = QDate::fromString(m_pReptable->text(nIter, TITRAQ_IDXDATE), Qt::ISODate); |
michael@1 | 532 | if (!Tempstring.isEmpty() && Firstday <= Tempdate && Tempdate < Lastday) { |
michael@3 | 533 | string Convstring = Tempstring.toStdString(); // Convert to string (can't cast?) |
michael@1 | 534 | QTime Intable = QTime::fromString(m_pReptable->text(nIter, TITRAQ_IDXAMOUNT), Qt::ISODate); |
michael@3 | 535 | string Gethashed = Hashtasks[Convstring]; |
michael@3 | 536 | int nTothours = QString::fromStdString(Gethashed).section(':', 0, 0).toInt() + Intable.hour();; |
michael@3 | 537 | int nTotminut = QString::fromStdString(Gethashed).section(':', 1, 1).toInt() + Intable.minute(); |
michael@1 | 538 | nTothours += nTotminut / 60; |
michael@1 | 539 | nTotminut %= 60; |
michael@1 | 540 | QString Hours = QString::number(nTothours).rightJustify(3, ' '); |
michael@1 | 541 | QString Mins = QString::number(nTotminut).rightJustify(2, '0'); |
michael@3 | 542 | string Timestring = Hours.toStdString() + ':' + Mins.toStdString(); // Convert to string (can't cast?) |
michael@1 | 543 | Hashtasks[Convstring] = Timestring; // Finally store in hashtable |
michael@1 | 544 | } |
michael@1 | 545 | } |
michael@1 | 546 | |
michael@1 | 547 | // Reverse copy the tasks hashtable to both sort and index by amount key |
michael@1 | 548 | for (Taskiter = Hashtasks.begin(); Taskiter != Hashtasks.end(); Taskiter++) |
michael@1 | 549 | Hashhours.insert(pair<string, string>(Taskiter->second, Taskiter->first)); |
michael@1 | 550 | |
michael@1 | 551 | // Write the actual data totals to the outgoing string in reverse order |
michael@1 | 552 | for (Houriter = Hashhours.begin(); Houriter != Hashhours.end(); Houriter++) |
michael@3 | 553 | Totals = QString::fromStdString(Houriter->first + ' ' + Houriter->second + '\n' + Totals.toStdString()); |
michael@1 | 554 | |
michael@1 | 555 | // Write some quick header text to the outgoing string in reverse order |
michael@1 | 556 | Totals = QString("------ ----------------------------------------\n") + Totals; |
michael@1 | 557 | Totals = trUtf8("Total Account summary\n") + Totals; |
michael@1 | 558 | |
michael@1 | 559 | return Totals; // The outgoing string... its finally gone, let's go to bed |
michael@1 | 560 | } |
michael@1 | 561 | |
michael@1 | 562 | // |
michael@1 | 563 | // Returns one month of details data |
michael@1 | 564 | // |
michael@1 | 565 | QString Reportpanel::getMonthdetails(QDate Dayref, int nMonths) |
michael@1 | 566 | { |
michael@1 | 567 | QString Data; // Output string |
michael@1 | 568 | QString Tempstring; // Temp churning |
michael@1 | 569 | QDate Tempdate; // For comparing |
michael@1 | 570 | QDate Firstday; // Minimum boundary |
michael@1 | 571 | QDate Lastday; // Maximum boundary |
michael@1 | 572 | int nRows = m_pReptable->numRows(); |
michael@1 | 573 | |
michael@1 | 574 | // Find range boundaries |
michael@1 | 575 | Q_ASSERT(nMonths > 0); |
michael@1 | 576 | int nYear = Dayref.year(); |
michael@1 | 577 | int nMonth = (Dayref.addMonths(nMonths * -1).month() + 12) % 12 + 1; |
michael@1 | 578 | if (nMonth > Dayref.month()) |
michael@1 | 579 | nYear--; |
michael@1 | 580 | Firstday = QDate(nYear, nMonth, 1); |
michael@1 | 581 | Lastday = QDate(Dayref.year(), Dayref.month(), Dayref.daysInMonth()); |
michael@1 | 582 | |
michael@1 | 583 | // Write some quick header text to the outgoing string |
michael@1 | 584 | Data = trUtf8("\nDate Hours Account details\n"); |
michael@1 | 585 | Data += QString("---------- ----- ----------------------------------------\n"); |
michael@1 | 586 | |
michael@1 | 587 | // Build the long week data string |
michael@1 | 588 | for (int nIter = nRows - 1; nIter >= 0; nIter--) { |
michael@1 | 589 | // Work on this tuple only if it within the reporting range |
michael@1 | 590 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); |
michael@1 | 591 | Tempdate = QDate::fromString(m_pReptable->text(nIter, TITRAQ_IDXDATE), Qt::ISODate); |
michael@1 | 592 | if (!Tempstring.isEmpty() && Firstday <= Tempdate && Tempdate < Lastday) { |
michael@1 | 593 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXDATE); |
michael@1 | 594 | if (!Tempstring.isEmpty()) |
michael@1 | 595 | Data += Tempstring; |
michael@1 | 596 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXAMOUNT); |
michael@1 | 597 | if (!Tempstring.isEmpty()) |
michael@1 | 598 | Data += QString(TITRAQ_SEPARATORTOK) + Tempstring; |
michael@1 | 599 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); |
michael@1 | 600 | if (!Tempstring.isEmpty()) |
michael@1 | 601 | Data += QString(TITRAQ_SEPARATORTOK) + Tempstring; |
michael@1 | 602 | Data += trUtf8("\n"); // Finish off line |
michael@1 | 603 | } |
michael@1 | 604 | } |
michael@1 | 605 | |
michael@1 | 606 | return Data; |
michael@1 | 607 | } |
michael@1 | 608 | |
michael@1 | 609 | // |
michael@1 | 610 | // Returns one month of totals data |
michael@1 | 611 | // |
michael@1 | 612 | QString Reportpanel::getMonthtotals(QDate Dayref, int nMonths) |
michael@1 | 613 | { |
michael@1 | 614 | using namespace std; // Needed for maps and hash |
michael@1 | 615 | map<string, string> Hashtasks; // Hashtable to store tasks |
michael@1 | 616 | multimap<string, string> Hashhours; // Hashtable to store hours |
michael@1 | 617 | map<string, string>::iterator Taskiter; // Hashtable task iterator |
michael@1 | 618 | multimap<string, string>::iterator Houriter; // Hashtable hour iterator |
michael@1 | 619 | |
michael@1 | 620 | QString Totals; // Data totals to return for writing |
michael@1 | 621 | QString Tempstring; // Temporary processing string |
michael@1 | 622 | QDate Tempdate; // Temporary processing date |
michael@1 | 623 | int nRows = m_pReptable->numRows(); |
michael@1 | 624 | |
michael@1 | 625 | // Find range boundaries |
michael@1 | 626 | Q_ASSERT(nMonths > 0); |
michael@1 | 627 | int nYear = Dayref.year(); |
michael@1 | 628 | int nMonth = (Dayref.addMonths(nMonths * -1).month() + 12) % 12 + 1; |
michael@1 | 629 | if (nMonth > Dayref.month()) |
michael@1 | 630 | nYear--; |
michael@1 | 631 | QDate Firstday = QDate(nYear, nMonth, 1); |
michael@1 | 632 | QDate Lastday = QDate(Dayref.year(), Dayref.month(), Dayref.daysInMonth()); |
michael@1 | 633 | |
michael@1 | 634 | // Parse the table for interesting values |
michael@1 | 635 | for (int nIter = 0; nIter < nRows; nIter++) { |
michael@1 | 636 | // Work on this tuple only if it within the reporting range |
michael@1 | 637 | Tempstring = m_pReptable->text(nIter, TITRAQ_IDXTASK); |
michael@1 | 638 | Tempdate = QDate::fromString(m_pReptable->text(nIter, TITRAQ_IDXDATE), Qt::ISODate); |
michael@1 | 639 | if (!Tempstring.isEmpty() && Firstday <= Tempdate && Tempdate < Lastday) { |
michael@3 | 640 | string Convstring = Tempstring.toStdString(); // Convert to string (can't cast?) |
michael@1 | 641 | QTime Intable = QTime::fromString(m_pReptable->text(nIter, TITRAQ_IDXAMOUNT), Qt::ISODate); |
michael@3 | 642 | string Gethashed = Hashtasks[Convstring]; |
michael@3 | 643 | int nTothours = QString::fromStdString(Gethashed).section(':', 0, 0).toInt() + Intable.hour();; |
michael@3 | 644 | int nTotminut = QString::fromStdString(Gethashed).section(':', 1, 1).toInt() + Intable.minute(); |
michael@1 | 645 | nTothours += nTotminut / 60; |
michael@1 | 646 | nTotminut %= 60; |
michael@1 | 647 | QString Hours = QString::number(nTothours).rightJustify(3, ' '); |
michael@1 | 648 | QString Mins = QString::number(nTotminut).rightJustify(2, '0'); |
michael@3 | 649 | QString Timestring = Hours + ':' + Mins; // Convert to string (can't cast?) |
michael@3 | 650 | Hashtasks[Convstring] = Timestring.toStdString(); // Finally store in hashtable |
michael@1 | 651 | } |
michael@1 | 652 | } |
michael@1 | 653 | |
michael@1 | 654 | // Reverse copy the tasks hashtable to both sort and index by amount key |
michael@1 | 655 | for (Taskiter = Hashtasks.begin(); Taskiter != Hashtasks.end(); Taskiter++) |
michael@1 | 656 | Hashhours.insert(pair<string, string>(Taskiter->second, Taskiter->first)); |
michael@1 | 657 | |
michael@1 | 658 | // Write the actual data totals to the outgoing string in reverse order |
michael@1 | 659 | for (Houriter = Hashhours.begin(); Houriter != Hashhours.end(); Houriter++) |
michael@3 | 660 | Totals = QString::fromStdString(Houriter->first + ' ' + Houriter->second + '\n' + Totals.toStdString()); |
michael@1 | 661 | |
michael@1 | 662 | // Write some quick header text to the outgoing string in reverse order |
michael@1 | 663 | Totals = QString("------ ----------------------------------------\n") + Totals; |
michael@1 | 664 | Totals = trUtf8("Total Account summary\n") + Totals; |
michael@1 | 665 | |
michael@1 | 666 | return Totals; // The outgoing string... its finally gone, let's go to bed |
michael@1 | 667 | } |
michael@1 | 668 | |
michael@1 | 669 | // |
michael@1 | 670 | // Saves the currently displayed local report |
michael@1 | 671 | // |
michael@1 | 672 | void Reportpanel::saveReport(void) |
michael@1 | 673 | { |
michael@1 | 674 | int nResult = 0; // For checking user's answer |
michael@1 | 675 | QFile Report; // The resulting report file |
michael@1 | 676 | QString Filestring; // The user chosen file name to save |
michael@1 | 677 | QString Openas = m_pReprefs->getString(TITRAQ_PREFHOME, TITRAQ_DEFHOME); |
michael@1 | 678 | |
michael@1 | 679 | // And then get the name of the selected file to save to |
michael@3 | 680 | Filestring = Q3FileDialog::getSaveFileName(Openas, trUtf8("Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to save"), NULL, false); |
michael@1 | 681 | if (!Filestring.isEmpty()) { |
michael@1 | 682 | if (QFile::exists(Filestring)) { |
michael@1 | 683 | nResult = QMessageBox::warning(this, QString(TITRAQ_APPTITLE) |
michael@1 | 684 | + ' ' + asgui_version.v_short, trUtf8(TITRAQ_OVERWRITE), |
michael@1 | 685 | trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1); |
michael@1 | 686 | if (nResult = QMessageBox::Ok) { // Overwrite a file |
michael@1 | 687 | Report.setName(Filestring); // User wished name |
michael@3 | 688 | Report.open(QIODevice::WriteOnly | QIODevice::Truncate); // Open report file |
michael@3 | 689 | Q3TextStream Outstream(&Report); // Convert to stream |
michael@1 | 690 | Outstream << m_pBrowser->text(); // Write the data |
michael@1 | 691 | Report.close(); // Finish by closing |
michael@1 | 692 | } |
michael@1 | 693 | } |
michael@1 | 694 | else { // User gave a file name, and there was no preexisting file there |
michael@1 | 695 | Report.setName(Filestring); // User wished name |
michael@3 | 696 | Report.open(QIODevice::WriteOnly | QIODevice::Truncate); // Open report file |
michael@3 | 697 | Q3TextStream Outstream(&Report); // Convert to stream |
michael@1 | 698 | Outstream << m_pBrowser->text(); // Write the data |
michael@1 | 699 | Report.close(); // Finish by closing |
michael@1 | 700 | } |
michael@1 | 701 | } |
michael@1 | 702 | // Otherwise, user did not select a valid file and push okay button |
michael@1 | 703 | } |
michael@1 | 704 | |
michael@1 | 705 | // |
michael@1 | 706 | // Prints the currently displayed local report |
michael@1 | 707 | // |
michael@1 | 708 | void Reportpanel::printReport(void) |
michael@1 | 709 | { |
michael@1 | 710 | #ifndef QT_NO_PRINTER |
michael@1 | 711 | if (m_pPrinter->setup(this)) { // Opens printer dialog |
michael@1 | 712 | m_pPrinter->setFullPage(true); // Set our own margins |
michael@1 | 713 | QPainter Paint; // Our painter (for pages) |
michael@1 | 714 | Paint.begin(m_pPrinter); // Paint on printer |
michael@1 | 715 | Paint.setFont(m_pBrowser->font()); |
michael@1 | 716 | QFontMetrics Fontmetrics = Paint.fontMetrics(); |
michael@3 | 717 | Q3PaintDeviceMetrics Devmetrics(m_pPrinter); // Need width/height of printer surface |
michael@1 | 718 | const int knMargin = Devmetrics.logicalDpiX() / 2; // Half-inch margin |
michael@1 | 719 | int nYpos = knMargin; // Y position for each line |
michael@1 | 720 | int nPageno = 1; // The starting page number |
michael@1 | 721 | |
michael@1 | 722 | for (int nIter = 0; nIter < m_pBrowser->lines() && !m_pPrinter->aborted(); nIter++) { |
michael@1 | 723 | // See if there is some space on this page to paint on |
michael@1 | 724 | if (nYpos + Fontmetrics.lineSpacing() > Devmetrics.height() - knMargin) { |
michael@1 | 725 | // QString Printmsg(trUtf8("Printing page ")) |
michael@1 | 726 | // + QString::number(++nPageno) + QString("..."); |
michael@1 | 727 | // m_pStatus()->message(Printmsg); // Not in scope (crap) |
michael@1 | 728 | if (!m_pPrinter->newPage()) // Start new page |
michael@1 | 729 | break; // Some error |
michael@1 | 730 | nYpos = knMargin; // Back to top of page |
michael@1 | 731 | } |
michael@1 | 732 | Paint.drawText(knMargin, nYpos, Devmetrics.width() - 2 * knMargin, |
michael@1 | 733 | Fontmetrics.lineSpacing(), Qt::ExpandTabs, m_pBrowser->text(nIter)); |
michael@1 | 734 | nYpos += Fontmetrics.lineSpacing(); |
michael@1 | 735 | } |
michael@1 | 736 | Paint.end(); // Send job to printer |
michael@1 | 737 | // m_pStatus()->message(trUtf8("Printing completed"), 2000); // Not in scope |
michael@1 | 738 | } |
michael@1 | 739 | // m_pStatusBar()->message(trUtf8("Printing completed"), 2000); // Not in scope |
michael@1 | 740 | #endif |
michael@1 | 741 | } |
michael@1 | 742 | |
michael@1 | 743 | // |
michael@1 | 744 | // Sets the strings of the subwidgets using the current language |
michael@1 | 745 | // |
michael@1 | 746 | void Reportpanel::textChange(void) |
michael@1 | 747 | { |
michael@1 | 748 | this->setCaption(trUtf8("AS local report", "Local report using weekly or monthly data.")); |
michael@1 | 749 | |
michael@1 | 750 | // Top level push buttons associated with accept and save slots |
michael@1 | 751 | m_pSavebutt->setText(trUtf8("Save As...", "Comment for Savebutton")); |
michael@1 | 752 | QToolTip::add(m_pSavebutt, trUtf8("Saves the report text", "Comment for tooltip Savebutton")); |
michael@3 | 753 | Q3WhatsThis::add(m_pSavebutt, trUtf8("The save button saves the report text to a file", "Comment for whatsThis Savebutton")); |
michael@1 | 754 | m_pPrintbutt->setText(trUtf8("Print...", "Comment for Printbutton")); |
michael@1 | 755 | QToolTip::add(m_pPrintbutt, trUtf8("Print the report text", "Comment for tooltip Printbutton")); |
michael@3 | 756 | Q3WhatsThis::add(m_pPrintbutt, trUtf8("The print button prints the report text to a file", "Comment for whatsThis Printbutton")); |
michael@1 | 757 | m_pDismissbutt->setText(trUtf8("Dismiss", "Comment for Dismissbutton")); |
michael@1 | 758 | QToolTip::add(m_pDismissbutt, trUtf8("Closes the report panel", "Comment for tooltip Dismissbutton")); |
michael@3 | 759 | Q3WhatsThis::add(m_pDismissbutt, trUtf8("The dismiss button dismisses the report panel", "Comment for whatsThis Dismissbutton")); |
michael@1 | 760 | |
michael@1 | 761 | // Inner tool buttons for new local report generation |
michael@1 | 762 | m_pWeeklybutt->setText(trUtf8("Weekly", "Comment for Weeklybutt")); |
michael@1 | 763 | QToolTip::add(m_pWeeklybutt, trUtf8("Hold down for options", "Comment for tooltip Weeklybutt")); |
michael@3 | 764 | 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 | 765 | m_pMonthlybutt->setText(trUtf8("Monthly", "Comment for Monthlybutt")); |
michael@1 | 766 | QToolTip::add(m_pMonthlybutt, trUtf8("Hold down for options", "Comment for tooltip Monthlybutt")); |
michael@3 | 767 | 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 | 768 | } |
michael@1 | 769 | } // namespace AS |