GCC Code Coverage Report


Directory: ./
File: QtPdCom1/MessageModel.h
Date: 2024-01-26 10:40:55
Exec Total Coverage
Lines: 0 3 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:
43 public QAbstractTableModel
44 {
45 Q_OBJECT
46 Q_PROPERTY(int rowLimit READ getRowLimit WRITE setRowLimit)
47 Q_PROPERTY(QtPdCom::Process * process READ getProcess WRITE connect)
48
49 friend class Message::Impl;
50
51 public:
52 MessageModel(QObject *parent = nullptr);
53 ~MessageModel();
54
55 void load(const QString &, const QString & = QString(),
56 const QString & = QString());
57 Q_INVOKABLE void clear();
58
59 void setRowLimit(int);
60 int getRowLimit() const;
61
62 void connect(QtPdCom::Process *);
63 QtPdCom::Process *getProcess() const;
64 Q_INVOKABLE void translate(const QString &);
65
66 void setIcon(Message::Type, const QIcon &);
67 const QIcon &getIcon(Message::Type) const;
68 void setIconPath(Message::Type, const QString &);
69
70 enum Roles {
71 DecorationPathRole = Qt::UserRole + 1,
72 TimeStringRole = Qt::UserRole + 2,
73 ResetTimeStringRole = Qt::UserRole + 3,
74 MessageTypeRole = Qt::UserRole + 4,
75 };
76 Q_ENUM(Roles)
77
78 // from QAbstractItemModel
79 virtual int rowCount(const QModelIndex &) const override;
80 virtual int columnCount(const QModelIndex &) const override;
81 virtual QVariant data(const QModelIndex &, int) const override;
82 virtual QVariant headerData(int, Qt::Orientation, int) const override;
83 virtual Qt::ItemFlags flags(const QModelIndex &) const override;
84 virtual QHash<int, QByteArray> roleNames() const override;
85 virtual bool canFetchMore(const QModelIndex &) const override;
86 virtual void fetchMore(const QModelIndex &) override;
87
88 /** Exception type.
89 */
90 struct Exception {
91 /** Constructor.
92 */
93 Exception(const QString &msg): msg(msg) {}
94 QString msg; /**< Exception message. */
95 };
96
97 signals:
98 /** Emitted, when a new message gets active.
99 *
100 * This signal announces the most recent message. It is only emitted
101 * for the first message getting active, or for a subsequent message
102 * with a higher type.
103 *
104 * \param message The message that got active. The signal is emitted
105 * with \a message being \a NULL, if no messages are
106 * active any more.
107 */
108 void currentMessage(const QtPdCom::Message *message);
109
110 /** Emitted, when a new message gets active.
111 *
112 * This signal announces any new arriving message.
113 *
114 * \param message The message that got active.
115 */
116 void anyMessage(const QtPdCom::Message *message);
117
118 protected:
119 bool event(QEvent *) override;
120
121 private:
122 class Q_DECL_HIDDEN Impl;
123 std::unique_ptr<Impl> impl;
124 };
125
126 /****************************************************************************/
127
128 } // namespace
129
130 #endif
131