QtPdCom  1.4.1
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 
32 namespace QtPdCom {
33 
34 class Process;
35 
36 /****************************************************************************/
37 
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)
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,
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 
119  struct Exception
120  {
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
Roles
Definition: MessageModel.h:99
List of Messages.
Definition: MessageModel.h:42
PdCom::Process implementation for Qt.
Definition: Process.h:70
Definition: BroadcastModel.h:32
Exception(const QString &msg)
Constructor.
Definition: MessageModel.h:123
Exception type.
Definition: MessageModel.h:119
Definition: MessageModel.h:71
Process message.
Definition: Message.h:37
std::unique_ptr< Impl > impl
Definition: MessageModel.h:157
QString msg
Exception message.
Definition: MessageModel.h:126
#define QTPDCOM_PUBLIC
Definition: Export.h:30
Columns
Definition: MessageModel.h:69
Definition: MessageModelImpl.h:41
Definition: MessageModel.h:72
Type
Message type.
Definition: Message.h:47