QtPdCom  1.5.2
MessageModel.h
Go to the documentation of this file.
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
32namespace QtPdCom {
33
34class Process;
35
36/****************************************************************************/
37
42class 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)
63 Q_PROPERTY(QVariantMap iconPaths READ getIconPathMap WRITE
66 friend class Message::Impl;
67
73 };
74 Q_ENUM(Columns)
75
76 MessageModel(QObject *parent = nullptr);
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);
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
118 */
119 struct Exception
120 {
122 */
123 Exception(const QString &msg):
124 msg(msg)
125 {}
126 QString msg;
127 };
128
129 signals:
142 void currentMessage(const QtPdCom::Message *message);
143
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
#define QTPDCOM_PUBLIC
Definition Export.h:30
MessageModel(QObject *parent=nullptr)
Constructor.
Definition MessageModel.cpp:41
Definition MessageModelImpl.h:42
List of Messages.
Definition MessageModel.h:43
bool event(QEvent *) override
Event handler.
Definition MessageModel.cpp:572
void setIconPathMap(QVariantMap map)
Definition MessageModel.cpp:370
void currentMessage(const QtPdCom::Message *message)
Emitted, when a new message gets active.
QVariantMap getIconPathMap() const
Definition MessageModel.cpp:356
void connect(QtPdCom::Process *)
Connects messages to the given process.
Definition MessageModel.cpp:199
int getRowLimit() const
Gets the maxium number of rows to fetch.
Definition MessageModel.cpp:190
void anyMessage(const QtPdCom::Message *message)
Emitted, when a new message gets active.
QVariantMap iconPaths
Define Icon Paths for decoration role.
Definition MessageModel.h:63
Roles
Definition MessageModel.h:98
@ ResetTimeStringRole
Definition MessageModel.h:101
@ DecorationPathRole
Definition MessageModel.h:99
@ TimeStringRole
Definition MessageModel.h:100
@ MessageTypeRole
Definition MessageModel.h:102
void setRowLimit(int)
Sets the maximum number of rows to fetch.
Definition MessageModel.cpp:181
QtPdCom::Process * process
Definition MessageModel.h:46
QtPdCom::Process * getProcess() const
Definition MessageModel.cpp:288
int rowLimit
Definition MessageModel.h:45
Columns
Definition MessageModel.h:68
@ TimeOccurredColumn
Definition MessageModel.h:70
@ TimeResetColumn
Definition MessageModel.h:71
@ TextColumn
Definition MessageModel.h:69
std::unique_ptr< Impl > impl
Definition MessageModel.h:156
Process message.
Definition Message.h:39
Type
Message type.
Definition Message.h:47
PdCom::Process implementation for Qt.
Definition Process.h:72
Definition BroadcastModel.h:32
Exception(const QString &msg)
Constructor.
Definition MessageModel.h:122
Exception(const QString &msg)
Constructor.
Definition MessageModel.h:122
QString msg
Exception message.
Definition MessageModel.h:125