summaryrefslogtreecommitdiff
path: root/qrtclient/tickethistory.hxx
blob: 2d766f62357b830af3c1a8f248421a150a826286 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef QRTCLIENT_TICKET_HISTORY_HXX
#define QRTCLIENT_TICKET_HISTORY_HXX

#include <QAbstractListModel>
#include <QDateTime>
#include <rtclient/ticket.h>

struct rtclient_ticket_history_list;

namespace RTClient {

	class TicketHistory
	{
		public:
			TicketHistory(struct rtclient_ticket_history* history)
				: m_id{history->id}
				, m_ticket{history->ticket}
				, m_timeTaken{history->time_taken}
				, m_type{history->type}
				, m_description{history->description}
				, m_content{history->content}
				, m_creator{history->creator}
			{
				if (history->field)
					m_field = QString{history->field};
				if (history->old_value)
					m_oldValue = QString{history->old_value};
				if (history->new_value)
					m_newValue = QString{history->new_value};
				if (history->data)
					m_data = QString{history->data};
			}
			unsigned int id() const { return m_id; }
			unsigned int ticket() const { return m_ticket; }
			unsigned int timeTaken() const { return m_timeTaken; }
//			Q_ENUM(rtclient_ticket_history_type)
			rtclient_ticket_history_type type() const { return m_type; }
			QString const& field() const { return m_field; }
			QString const& oldValue() const { return m_oldValue; }
			QString const& newValue() const { return m_newValue; }
			QString const& data() const { return m_data; }
			QString const& description() const { return m_description; }
			QString const& content() const { return m_content; }
			QString const& creator() const { return m_creator; }
			QDateTime const& created() const { return m_created; }

		private:
			unsigned int m_id;
			unsigned int m_ticket;
			unsigned int m_timeTaken;
			rtclient_ticket_history_type m_type;
			QString m_field;
			QString m_oldValue;
			QString m_newValue;
			QString m_data;
			QString m_description;
			QString m_content;
			QString m_creator;
			QDateTime m_created;
//			QList<TicketHistoryAttachment>* m_attachments;
	};

	class TicketHistoryList : public QAbstractListModel
	{
		Q_OBJECT
		Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)

		public:
			enum TicketHistoryRoles {
				IdRole = Qt::UserRole + 1,
				TicketRole,
				TimeTakenRole,
				TypeRole,
				FieldRole,
				OldValueRole,
				NewValueRole,
				DataRole,
				DescriptionRole,
				ContentRole,
				CreatorRole,
				CreatedRole/*,
				AttachmentsRole*/
			};

			explicit TicketHistoryList(QObject* parent = nullptr)
				: QAbstractListModel{parent} {}

			int rowCount(QModelIndex const& parent
					= QModelIndex()) const Q_DECL_OVERRIDE;
			QVariant data(const QModelIndex& index
					, int role = Qt::DisplayRole
					) const Q_DECL_OVERRIDE;

		public slots:
			void update(rtclient_ticket_history_list* list);

		protected:
			QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;

		signals:
			void rowCountChanged();
			void updated();

		private:
			QList<TicketHistory> histories;
			void addTicketHistory(TicketHistory const& history);
	};

}

#endif // QRTCLIENT_TICKET_HISTORY_HXX