diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa582bd..4e0bd64 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,6 +40,7 @@ set(SRCS models/loggerTreeModel.cpp models/taskFilterProxyModel.cpp models/taskListModel.cpp + models/timeSheetModel.cpp monitor/desktopEventsMonitor.cpp monitor/kimaiEventsMonitor.cpp settings/settings.cpp @@ -73,6 +74,7 @@ set(HDRS models/loggerTreeModel.h models/taskFilterProxyModel.h models/taskListModel.h + models/timeSheetModel.h monitor/desktopEventsMonitor.h monitor/kimaiEventsMonitor.h settings/settings.h diff --git a/src/main.cpp b/src/main.cpp index a07b60f..4223e21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,6 +15,7 @@ #include "misc/customFmt.h" #include "misc/helpers.h" #include "models/loggerTreeModel.h" +#include "models/timeSheetModel.h" #include "settings/settings.h" using namespace kemai; @@ -85,8 +86,12 @@ int main(int argc, char* argv[]) // Setup trusted certificates KimaiClient::addTrustedCertificates(kemaiSettings.trustedCertificates); + TimeSheetModel timeSheetModel; + // Startup QQmlApplicationEngine engine; + engine.setInitialProperties({{"timeSheetModel", QVariant::fromValue(&timeSheetModel)}}); + const QUrl url("qrc:/kemai/qml/main.qml"); QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &app, diff --git a/src/models/timeSheetModel.cpp b/src/models/timeSheetModel.cpp new file mode 100644 index 0000000..be845b7 --- /dev/null +++ b/src/models/timeSheetModel.cpp @@ -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(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 TimeSheetModel::roleNames() const +{ + QHash roles; + roles[ActivityNameRole] = "activityName"; + roles[ProjectNameRole] = "projectName"; + roles[TagsRole] = "tags"; + roles[StartDateRole] = "startDate"; + roles[EndDateRole] = "endDate"; + roles[DurationRole] = "duration"; + return roles; +} diff --git a/src/models/timeSheetModel.h b/src/models/timeSheetModel.h new file mode 100644 index 0000000..6b445aa --- /dev/null +++ b/src/models/timeSheetModel.h @@ -0,0 +1,34 @@ +#pragma once + +#include + +#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 roleNames() const; + +private: + TimeSheets mTimeSheets; +}; + +} // namespace kemai diff --git a/src/qml/TimeSheetDelegate.qml b/src/qml/TimeSheetDelegate.qml index 7be6727..1873d96 100644 --- a/src/qml/TimeSheetDelegate.qml +++ b/src/qml/TimeSheetDelegate.qml @@ -29,5 +29,22 @@ ItemDelegate { id: endDateTimeLabel text: model.endDateTime } + Label { + id: durationLabel + text: model.duration + font.bold: true + } + RoundButton { + id: reloadButton + width: 20 + height: 20 + icon.source: "qrc:/icons/refresh" + } + RoundButton { + id: restartButton + width: 20 + height: 20 + icon.source: "qrc:/icons/play" + } } } diff --git a/src/qml/TimeSheetModel.qml b/src/qml/TimeSheetModel.qml index 890fab8..c45554c 100644 --- a/src/qml/TimeSheetModel.qml +++ b/src/qml/TimeSheetModel.qml @@ -9,7 +9,19 @@ ListModel { tags: [ ListElement { name: "development" } ] - startDateTime: "2024/02/01T18:12:00" - endDateTime: "2024/02/01T18:42:00" + startDateTime: "2024-02-01 18:12:00" + endDateTime: "2024-02-01 18:42:00" + duration: "3:00" + } + + ListElement { + activityName: "New UI/UX" + projectName: "kemai" + tags: [ + ListElement { name: "development" } + ] + startDateTime: "2024-02-01 18:12:00" + endDateTime: "2024-02-01 18:42:00" + duration: "6:00" } } diff --git a/src/qml/main.qml b/src/qml/main.qml index fca1ee6..0fde493 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -13,7 +13,7 @@ ApplicationWindow { ListView { id: timeSheetHistoryView anchors.fill: parent - model: TimeSheetModel {} + model: timeSheetModel delegate: TimeSheetDelegate {} } }