From cd679da218281c5716001a4e2055451ab9bcc926 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: Sun, 15 Sep 2019 18:42:35 +0800 Subject: A Qt Core based library that depends on librtclient and can be used for a Qt based project --- ticket.cxx | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ticket.cxx (limited to 'ticket.cxx') 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 +#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 TicketList::roleNames() const + { + return QHash{ + {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); + } + +} -- cgit v1.2.3