summaryrefslogtreecommitdiff
path: root/ticket.cxx
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-15 18:42:35 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-15 18:42:35 +0800
commitcd679da218281c5716001a4e2055451ab9bcc926 (patch)
tree43c1a719690062d4c0f65bbff593b7e5e23b5eb9 /ticket.cxx
A Qt Core based library that depends on librtclient
and can be used for a Qt based project
Diffstat (limited to 'ticket.cxx')
-rw-r--r--ticket.cxx49
1 files changed, 49 insertions, 0 deletions
diff --git a/ticket.cxx b/ticket.cxx
new file mode 100644
index 0000000..381e573
--- /dev/null
+++ b/ticket.cxx
@@ -0,0 +1,49 @@
+#include <rtclient/client.h>
+#include "qrtclient/ticket.hxx"
+
+namespace RTClient {
+
+ int TicketList::rowCount(QModelIndex const& parent) const
+ {
+ Q_UNUSED(parent)
+ return tickets.count();
+ }
+
+ QVariant TicketList::data(QModelIndex const& index, int role) const
+ {
+ auto row = index.row();
+
+ if (row < 0 || row >= tickets.count()) return QVariant();
+
+ auto ticket = tickets[row];
+ switch (role) {
+ case SubjectRole:
+ return ticket.subject();
+ default:
+ return QVariant();
+ }
+ }
+
+ QHash<int, QByteArray> TicketList::roleNames() const
+ {
+ return QHash<int, QByteArray>{
+ {SubjectRole, "subject"}
+ };
+ }
+
+ void TicketList::addTicket(Ticket const& ticket)
+ {
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ tickets << ticket;
+ endInsertRows();
+ emit rowCountChanged();
+ }
+
+ void TicketList::addTickets(rt_ticketlist* ticketList)
+ {
+ for (unsigned int i = 0; i < ticketList->length; i++)
+ addTicket(Ticket{ticketList->tickets[i]});
+ rtclient_ticket_freelist(ticketList);
+ }
+
+}