• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

ktimetracker

  • sources
  • kde-4.14
  • kdepim
  • ktimetracker
timekard.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003 by Mark Bucciarelli <mark@hubcapconsutling.com>
3  * 2007 the ktimetracker developers
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the
17  * Free Software Foundation, Inc.
18  * 51 Franklin Street, Fifth Floor
19  * Boston, MA 02110-1301 USA.
20  *
21  */
22 
23 #include "timekard.h"
24 
25 #include <cassert>
26 
27 #include <QDateTime>
28 #include <QList>
29 #include <QMap>
30 
31 #include <KDebug>
32 #include <KGlobal>
33 #include <KLocale>
34 
35 #include "timetrackerstorage.h"
36 #include "ktimetrackerutility.h" // formatTime()
37 #include "task.h"
38 #include "taskview.h"
39 
40 const int taskWidth = 40;
41 const int timeWidth = 6;
42 //const int totalTimeWidth = 7;
43 const int reportWidth = taskWidth + timeWidth;
44 
45 const QString cr = QString::fromLatin1("\n");
46 
47 QString TimeKard::totalsAsText(TaskView* taskview, ReportCriteria rc)
48 {
49  kDebug(5970) << "Entering function";
50  QString retval;
51  QString line;
52  QString buf;
53  long sum;
54  bool justThisTask=!rc.allTasks;
55 
56  line.fill('-', reportWidth);
57  line += cr;
58 
59  // header
60  retval += i18n("Task Totals") + cr;
61  retval += KGlobal::locale()->formatDateTime(QDateTime::currentDateTime());
62  retval += cr + cr;
63  retval += QString(QString::fromLatin1("%1 %2"))
64  .arg(i18n("Time"), timeWidth)
65  .arg(i18n("Task"));
66  retval += cr;
67  retval += line;
68 
69  // tasks
70  if (taskview->currentItem())
71  {
72  if (justThisTask)
73  {
74  if (!rc.sessionTimes) sum = taskview->currentItem()->totalTime();
75  else sum = taskview->currentItem()->totalSessionTime();
76  printTask(taskview->currentItem(), retval, 0, rc);
77  }
78  else // print all tasks
79  {
80  sum = 0;
81  for ( int i = 0; i < taskview->topLevelItemCount(); ++i )
82  {
83  Task *task = static_cast< Task* >( taskview->topLevelItem( i ) );
84  if (!rc.sessionTimes) sum += task->totalTime();
85  else sum += task->totalSessionTime();
86  if ( (task->totalTime() && (!rc.sessionTimes)) || (task->totalSessionTime() && rc.sessionTimes) )
87  printTask(task, retval, 0, rc);
88  }
89  }
90  // total
91  buf.fill('-', reportWidth);
92  retval += QString(QString::fromLatin1("%1")).arg(buf, timeWidth) + cr;
93  retval += QString(QString::fromLatin1("%1 %2"))
94  .arg(formatTime(sum),timeWidth)
95  .arg(i18nc( "total time of all tasks", "Total" ));
96  }
97  else
98  retval += i18n("No tasks.");
99 
100  return retval;
101 }
102 
103 // Print out "<indent for level> <task total> <task>", for task and subtasks. Used by totalsAsText.
104 void TimeKard::printTask(Task *task, QString &s, int level, const ReportCriteria &rc)
105 {
106  kDebug(5970) << "Entering function";
107  QString buf;
108 
109  s += buf.fill(' ', level);
110  if (!rc.sessionTimes)
111  {
112  s += QString(QString::fromLatin1("%1 %2"))
113  .arg(formatTime(task->totalTime()), timeWidth)
114  .arg(task->name());
115  }
116  else // print session times
117  {
118  s += QString(QString::fromLatin1("%1 %2"))
119  .arg(formatTime(task->totalSessionTime()), timeWidth)
120  .arg(task->name());
121  }
122  s += cr;
123 
124  for ( int i = 0; i < task->childCount(); ++i )
125  {
126  Task *subTask = static_cast< Task* >( task->child( i ) );
127  if ( !rc.sessionTimes )
128  {
129  if ( subTask->totalTime() ) // to avoid 00:00 entries
130  printTask(subTask, s, level+1, rc);
131  }
132  else
133  {
134  if ( subTask->totalSessionTime() ) // to avoid 00:00 entries
135  printTask(subTask, s, level+1, rc);
136  }
137  }
138 }
139 
140 Week::Week() {}
141 
142 Week::Week( const QDate &from )
143 {
144  _start = from;
145 }
146 
147 QDate Week::start() const
148 {
149  return _start;
150 }
151 
152 QDate Week::end() const
153 {
154  return _start.addDays(6);
155 }
156 
157 QString Week::name() const
158 {
159  return i18n("Week of %1", KGlobal::locale()->formatDate(start()));
160 }
161 
162 QList<Week> Week::weeksFromDateRange(const QDate& from, const QDate& to)
163 {
164  QDate start;
165  QList<Week> weeks;
166 
167  // The QDate weekNumber() method always puts monday as the first day of the
168  // week.
169  //
170  // Not that it matters here, but week 1 always includes the first Thursday
171  // of the year. For example, January 1, 2000 was a Saturday, so
172  // QDate(2000,1,1).weekNumber() returns 52.
173 
174  // Since report always shows a full week, we generate a full week of dates,
175  // even if from and to are the same date. The week starts on the day
176  // that is set in the locale settings.
177  start = from.addDays( -((7 - KGlobal::locale()->weekStartDay() + from.dayOfWeek()) % 7));
178 
179  for (QDate d = start; d <= to; d = d.addDays(7))
180  weeks.append(Week(d));
181 
182  return weeks;
183 }
184 
QObject::child
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
Task::totalSessionTime
long totalSessionTime() const
Definition: task.h:208
Week::weeksFromDateRange
static QList< Week > weeksFromDateRange(const QDate &from, const QDate &to)
Returns a list of weeks for the given date range.
Definition: timekard.cpp:162
QString::fill
QString & fill(QChar ch, int size)
reportWidth
const int reportWidth
Definition: timekard.cpp:43
Week::start
QDate start() const
Definition: timekard.cpp:147
Task::name
QString name() const
returns the name of this task.
Definition: task.cpp:695
TimeKard::totalsAsText
QString totalsAsText(TaskView *taskview, ReportCriteria rc)
Generates ascii text of task totals, for current task on down.
Definition: timekard.cpp:47
formatTime
QString formatTime(double minutes, bool decimal)
Format time for output.
Definition: ktimetrackerutility.cpp:37
timeWidth
const int timeWidth
Definition: timekard.cpp:41
taskWidth
const int taskWidth
Definition: timekard.cpp:40
QDate::dayOfWeek
int dayOfWeek() const
taskview.h
QList::append
void append(const T &value)
Week::name
QString name() const
Return the name of the week.
Definition: timekard.cpp:157
QDate
ReportCriteria
Stores entries from export dialog.
Definition: reportcriteria.h:41
QString
QList
cr
const QString cr
Definition: timekard.cpp:45
Week
Seven consecutive days.
Definition: timekard.h:45
task.h
QDateTime::currentDateTime
QDateTime currentDateTime()
ReportCriteria::allTasks
bool allTasks
True if user chose to export all tasks, not only the selected one.
Definition: reportcriteria.h:84
timekard.h
QString::fromLatin1
QString fromLatin1(const char *str, int size)
ktimetrackerutility.h
QDate::addDays
QDate addDays(int ndays) const
QTreeWidget::topLevelItem
QTreeWidgetItem * topLevelItem(int index) const
QTreeWidget::topLevelItemCount
topLevelItemCount
TaskView
Container and interface for the tasks.
Definition: taskview.h:50
Task
A class representing a task.
Definition: task.h:54
QTreeWidgetItem::childCount
int childCount() const
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
timetrackerstorage.h
Week::end
QDate end() const
Definition: timekard.cpp:152
ReportCriteria::sessionTimes
bool sessionTimes
True if user chose to export session times, not all times.
Definition: reportcriteria.h:79
TaskView::currentItem
Task * currentItem() const
Return the current item in the view, cast to a Task pointer.
Definition: taskview.cpp:399
Week::Week
Week()
Need an empty constructor to use in a QValueList.
Definition: timekard.cpp:140
Task::totalTime
long totalTime() const
Definition: task.h:206
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktimetracker

Skip menu "ktimetracker"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal