-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c18bbb
commit 2c360a8
Showing
7 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "timeSheetModel.h" | ||
|
||
using namespace kemai; | ||
|
||
void TimeSheetModel::setTimeSheets(const TimeSheets& timeSheets) | ||
{ | ||
beginResetModel(); | ||
mTimeSheets = timeSheets; | ||
endResetModel(); | ||
} | ||
|
||
int TimeSheetModel::rowCount(const QModelIndex& parent) const | ||
{ | ||
return static_cast<int>(mTimeSheets.size()); | ||
} | ||
|
||
QVariant TimeSheetModel::data(const QModelIndex& index, int role) const | ||
{ | ||
if (!index.isValid() || index.row() > mTimeSheets.size()) | ||
{ | ||
return {}; | ||
} | ||
|
||
const auto& it = std::next(mTimeSheets.begin(), index.row()); | ||
switch (role) | ||
{ | ||
case ActivityNameRole: | ||
return it->activity.name; | ||
case ProjectNameRole: | ||
return it->project.name; | ||
case TagsRole: | ||
return it->tags; | ||
case StartDateRole: | ||
return it->beginAt; | ||
case EndDateRole: | ||
return it->endAt; | ||
case DurationRole: { | ||
if (it->beginAt.isValid() && it->endAt.isValid()) | ||
{ | ||
return it->beginAt.secsTo(it->endAt); | ||
} | ||
return {}; | ||
} | ||
|
||
default: | ||
return {}; | ||
} | ||
} | ||
|
||
QHash<int, QByteArray> TimeSheetModel::roleNames() const | ||
{ | ||
QHash<int, QByteArray> roles; | ||
roles[ActivityNameRole] = "activityName"; | ||
roles[ProjectNameRole] = "projectName"; | ||
roles[TagsRole] = "tags"; | ||
roles[StartDateRole] = "startDate"; | ||
roles[EndDateRole] = "endDate"; | ||
roles[DurationRole] = "duration"; | ||
return roles; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <QAbstractListModel> | ||
|
||
#include "client/kimaiAPI.h" | ||
|
||
namespace kemai { | ||
|
||
class TimeSheetModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
enum TimeSheetRoles | ||
{ | ||
ActivityNameRole = Qt::UserRole + 1, | ||
ProjectNameRole, | ||
TagsRole, | ||
StartDateRole, | ||
EndDateRole, | ||
DurationRole | ||
}; | ||
|
||
void setTimeSheets(const TimeSheets& timeSheets); | ||
|
||
int rowCount(const QModelIndex& parent) const override; | ||
QVariant data(const QModelIndex& index, int role) const override; | ||
QHash<int, QByteArray> roleNames() const; | ||
|
||
private: | ||
TimeSheets mTimeSheets; | ||
}; | ||
|
||
} // namespace kemai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters