GCC Code Coverage Report


Directory: ./
File: QtPdCom1/MessageModel.h
Date: 2025-02-27 10:29:23
Exec Total Coverage
Lines: 0 4 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2009 - 2022 Florian Pose <fp@igh.de>
4 *
5 * This file is part of the QtPdCom library.
6 *
7 * The QtPdCom library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * The QtPdCom library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21
22 #ifndef QTPDCOM_MESSAGEMODEL_H
23 #define QTPDCOM_MESSAGEMODEL_H
24
25 #include "Message.h"
26
27 #include <QAbstractTableModel>
28 #include <QIcon>
29
30 #include <memory>
31
32 namespace QtPdCom {
33
34 class Process;
35
36 /****************************************************************************/
37
38 /** List of Messages.
39 *
40 * \see Message.
41 */
42 class QTPDCOM_PUBLIC MessageModel: public QAbstractTableModel
43 {
44 Q_OBJECT
45 Q_PROPERTY(int rowLimit READ getRowLimit WRITE setRowLimit)
46 Q_PROPERTY(QtPdCom::Process *process READ getProcess WRITE connect)
47 /** Define Icon Paths for decoration role.
48 *
49 * This property is intended to be used from QML.
50 * Use the values of Message::Type as string for keys.
51 * \code
52 * MessageModel {
53 * iconPaths: {
54 * "Critical": ":/images/dialog-error.svg",
55 * "Error": ":/images/dialog-error.svg",
56 * "Information": ":/images/dialog-information.svg",
57 * "Warning": ":/images/dialog-warning.svg"
58 * }
59 * }
60 * \endcode
61 *
62 */
63 Q_PROPERTY(QVariantMap iconPaths READ getIconPathMap WRITE
64 setIconPathMap)
65
66 friend class Message::Impl;
67
68 public:
69 enum Columns {
70 TextColumn = 0,
71 TimeOccurredColumn,
72 TimeResetColumn,
73 };
74 Q_ENUM(Columns)
75
76 MessageModel(QObject *parent = nullptr);
77 ~MessageModel();
78
79 Q_INVOKABLE void
80 load(const QString &path,
81 const QString &lang = QString(),
82 const QString &pathPrefix = QString());
83 Q_INVOKABLE void clear();
84
85 void setRowLimit(int);
86 int getRowLimit() const;
87
88 void connect(QtPdCom::Process *);
89 QtPdCom::Process *getProcess() const;
90 Q_INVOKABLE void translate(const QString &);
91
92 void setIcon(Message::Type, const QIcon &);
93 const QIcon &getIcon(Message::Type) const;
94 Q_INVOKABLE void setIconPath(Message::Type, const QString &);
95
96 QVariantMap getIconPathMap() const;
97 void setIconPathMap(QVariantMap map);
98
99 enum Roles {
100 DecorationPathRole = Qt::UserRole + 1,
101 TimeStringRole = Qt::UserRole + 2,
102 ResetTimeStringRole = Qt::UserRole + 3,
103 MessageTypeRole = Qt::UserRole + 4,
104 };
105 Q_ENUM(Roles)
106
107 // from QAbstractItemModel
108 virtual int rowCount(const QModelIndex &) const override;
109 virtual int columnCount(const QModelIndex &) const override;
110 virtual QVariant data(const QModelIndex &, int) const override;
111 virtual QVariant headerData(int, Qt::Orientation, int) const override;
112 virtual Qt::ItemFlags flags(const QModelIndex &) const override;
113 virtual QHash<int, QByteArray> roleNames() const override;
114 virtual bool canFetchMore(const QModelIndex &) const override;
115 virtual void fetchMore(const QModelIndex &) override;
116
117 /** Exception type.
118 */
119 struct Exception
120 {
121 /** Constructor.
122 */
123 Exception(const QString &msg):
124 msg(msg)
125 {}
126 QString msg; /**< Exception message. */
127 };
128
129 signals:
130 /** Emitted, when a new message gets active.
131 *
132 * This signal announces the most recent message. It is only emitted
133 * for the first message getting active, or for a subsequent message
134 * with a higher type.
135 *
136 * In QML, a currentMessage property is available.
137 *
138 * \param message The message that got active. The signal is emitted
139 * with \a message being \a NULL, if no messages are
140 * active any more.
141 */
142 void currentMessage(const QtPdCom::Message *message);
143
144 /** Emitted, when a new message gets active.
145 *
146 * This signal announces any new arriving message.
147 *
148 * \param message The message that got active.
149 */
150 void anyMessage(const QtPdCom::Message *message);
151
152 protected:
153 bool event(QEvent *) override;
154
155 private:
156 class Q_DECL_HIDDEN Impl;
157 std::unique_ptr<Impl> impl;
158 };
159
160 /****************************************************************************/
161
162 } // namespace QtPdCom
163
164 #endif
165