Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrePTJ committed Mar 25, 2024
1 parent 5c18bbb commit 2c360a8
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
60 changes: 60 additions & 0 deletions src/models/timeSheetModel.cpp
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;
}
34 changes: 34 additions & 0 deletions src/models/timeSheetModel.h
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
17 changes: 17 additions & 0 deletions src/qml/TimeSheetDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
16 changes: 14 additions & 2 deletions src/qml/TimeSheetModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ApplicationWindow {
ListView {
id: timeSheetHistoryView
anchors.fill: parent
model: TimeSheetModel {}
model: timeSheetModel
delegate: TimeSheetDelegate {}
}
}

0 comments on commit 2c360a8

Please sign in to comment.