QtPdCom  1.0.0
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 
43  public QAbstractTableModel
44 {
45  Q_OBJECT
46 
47  friend class Message::Impl;
48 
49  public:
50  MessageModel(QObject *parent = nullptr);
51  ~MessageModel();
52 
53  void load(const QString &, const QString & = QString(),
54  const QString & = QString());
55  void clear();
56 
57  void setRowLimit(int);
58  int getRowLimit() const;
59 
60  void connect(QtPdCom::Process *);
61  Q_INVOKABLE void translate(const QString &);
62 
63  void setIcon(Message::Type, const QIcon &);
64  const QIcon &getIcon(Message::Type) const;
65  void setIconPath(Message::Type, const QString &);
66 
67  enum Roles {
68  DecorationPathRole = Qt::UserRole + 1,
69  TimeStringRole = Qt::UserRole + 2,
70  ResetTimeStringRole = Qt::UserRole + 3,
71  MessageTypeRole = Qt::UserRole + 4,
72  };
73  Q_ENUM(Roles)
74 
75  // from QAbstractItemModel
76  virtual int rowCount(const QModelIndex &) const override;
77  virtual int columnCount(const QModelIndex &) const override;
78  virtual QVariant data(const QModelIndex &, int) const override;
79  virtual QVariant headerData(int, Qt::Orientation, int) const override;
80  virtual Qt::ItemFlags flags(const QModelIndex &) const override;
81  virtual QHash<int, QByteArray> roleNames() const override;
82  virtual bool canFetchMore(const QModelIndex &) const override;
83  virtual void fetchMore(const QModelIndex &) override;
84 
87  struct Exception {
90  Exception(const QString &msg): msg(msg) {}
91  QString msg;
92  };
93 
94  signals:
105  void currentMessage(const QtPdCom::Message *message);
106 
113  void anyMessage(const QtPdCom::Message *message);
114 
115  protected:
116  bool event(QEvent *) override;
117 
118  private:
119  class Q_DECL_HIDDEN Impl;
120  std::unique_ptr<Impl> impl;
121 };
122 
123 /****************************************************************************/
124 
125 } // namespace
126 
127 #endif
Roles
Definition: MessageModel.h:67
List of Messages.
Definition: MessageModel.h:42
PdCom::Process implementation for Qt.
Definition: Process.h:50
Definition: Message.h:31
Exception(const QString &msg)
Constructor.
Definition: MessageModel.h:90
Exception type.
Definition: MessageModel.h:87
Process message.
Definition: Message.h:37
std::unique_ptr< Impl > impl
Definition: MessageModel.h:120
Definition: MessageImpl.h:39
QString msg
Exception message.
Definition: MessageModel.h:91
#define QTPDCOM_PUBLIC
Definition: Export.h:30
Definition: MessageModelImpl.h:39
Type
Message type.
Definition: Message.h:47