From 6e3ee14209963c9a7190cc76925cc736fea83218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Wed, 2 Oct 2019 21:30:32 +0800 Subject: Ticket history class --- tickethistory.cxx | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tickethistory.cxx (limited to 'tickethistory.cxx') diff --git a/tickethistory.cxx b/tickethistory.cxx new file mode 100644 index 0000000..d1af392 --- /dev/null +++ b/tickethistory.cxx @@ -0,0 +1,88 @@ +#include +#include "qrtclient/tickethistory.hxx" + +namespace RTClient { + + int TicketHistoryList::rowCount(QModelIndex const& parent) const + { + Q_UNUSED(parent) + return histories.count(); + } + + QVariant TicketHistoryList::data(QModelIndex const& index, int role) const + { + auto row = index.row(); + + if (row < 0 || row >= histories.count()) return QVariant(); + + auto history = histories[row]; + switch (role) { + case IdRole: + return history.id(); + case TicketRole: + return history.ticket(); + case TimeTakenRole: + return history.timeTaken(); + case TypeRole: + return history.type(); + case FieldRole: + return history.field(); + case OldValueRole: + return history.oldValue(); + case NewValueRole: + return history.newValue(); + case DataRole: + return history.data(); + case DescriptionRole: + return history.description(); + case ContentRole: + return history.content(); + case CreatorRole: + return history.creator(); + case CreatedRole: + return history.created(); + /* + case AttachmentsRole: + return history.attachments(); + */ + default: + return QVariant(); + } + } + + QHash TicketHistoryList::roleNames() const + { + return QHash{ + {IdRole, "id"} + , {TicketRole, "ticket"} + , {TimeTakenRole, "timeTaken"} + , {TypeRole, "type"} + , {FieldRole, "field"} + , {OldValueRole, "oldValue"} + , {NewValueRole, "newValue"} + , {DataRole, "data"} + , {DescriptionRole, "description"} + , {ContentRole, "content"} + , {CreatorRole, "creator"} + , {CreatedRole, "created"} +// , {AttachmentsRole, "attachments"} + }; + } + + void TicketHistoryList::addTicketHistory(TicketHistory const& history) + { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + histories << history; + endInsertRows(); + } + + void TicketHistoryList::update(rtclient_ticket_history_list* list) + { + if (list) + for (size_t i = 0; i < list->length; i++) + addTicketHistory + (TicketHistory{list->histories[i]}); + emit updated(); + } + +} -- cgit v1.2.3