Wed, 29 Jun 2022 16:33:49 +0300
Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
236
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
1 | #include <QAbstractTableModel> |
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
236
diff
changeset
|
2 | #include "src/basics.h" |
236
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
3 | |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
4 | class MessageLog final : public QAbstractTableModel |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
5 | { |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
6 | Q_OBJECT |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
7 | std::vector<Message> messages; |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
8 | public: |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
9 | enum Column { |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
10 | TimeColumn, |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
11 | MessageColumn, |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
12 | }; |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
13 | static constexpr int NUM_COLUMNS = int(MessageColumn) + 1; |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
14 | explicit MessageLog(QObject *parent = nullptr); |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
15 | Q_SLOT void addMessage(const Message& message); |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
16 | |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
17 | // QAbstractItemModel interface |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
18 | public: |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
19 | QVariant headerData(int section, Qt::Orientation orientation, int role) const override; |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
20 | int rowCount(const QModelIndex& parent) const override; |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
21 | int columnCount(const QModelIndex& parent) const override; |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
22 | QVariant data(const QModelIndex& index, int role) const override; |
1fa0e1de9f0a
Made message log a model
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
diff
changeset
|
23 | }; |