GCC Code Coverage Report


Directory: ./
File: src/MessageModel.cpp
Date: 2025-07-04 12:28:41
Exec Total Coverage
Lines: 142 239 59.4%
Branches: 144 434 33.2%

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 #include "MessageModel.h"
23 using QtPdCom::MessageModel;
24
25 #include "MessageImpl.h"
26 #include "MessageItem.h"
27 #include "MessageManager.h"
28 #include "MessageModelImpl.h"
29 #include "Process.h"
30
31 #include <QEvent>
32 #include <QFile>
33 #include <QDomDocument>
34 #include <QMetaEnum>
35 #include <QtGlobal>
36
37 /****************************************************************************/
38
39 /** Constructor.
40 */
41 14 MessageModel::MessageModel(QObject *parent):
42 QAbstractTableModel(parent),
43
2/4
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
14 impl(std::unique_ptr<Impl>(new MessageModel::Impl(this)))
44 14 {}
45
46 /****************************************************************************/
47
48 /** Destructor.
49 */
50 35 MessageModel::~MessageModel()
51 {
52 14 clear();
53 21 }
54
55 /****************************************************************************/
56
57 /** Loads messages from an Xml file.
58 */
59 3 void MessageModel::load(
60 const QString &path, /**< Path to Xml file. */
61 const QString &lang, /**< Language identifier. */
62 const QString &pathPrefix /**< Prefix to path (with leading /). */
63 )
64 {
65
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 QFile file(path);
66
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 QDomDocument doc;
67
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 QDomElement docElem;
68
69
2/4
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
3 if (!file.open(QIODevice::ReadOnly)) {
70 throw Exception(QtPdCom::MessageModel::tr("Failed to open %1.")
71 .arg(file.fileName()));
72 }
73
74 #if QT_VERSION < 0x060500
75 {
76 6 QString errorMessage;
77 3 int errorRow, errorColumn;
78
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
3 if (!doc.setContent(&file, &errorMessage, &errorRow, &errorColumn)) {
79 throw Exception(
80 QtPdCom::MessageModel::tr("Failed to parse %1, line %2,"
81 " column %3: %4")
82 .arg(file.fileName())
83 .arg(errorRow)
84 .arg(errorColumn)
85 .arg(errorMessage));
86 }
87 }
88 #else
89 {
90 QDomDocument::ParseResult res = doc.setContent(&file);
91 if (not res) {
92 throw Exception(
93 QtPdCom::MessageModel::tr("Failed to parse %1, line %2,"
94 " column %3: %4")
95 .arg(file.fileName())
96 .arg(res.errorLine)
97 .arg(res.errorColumn)
98 .arg(res.errorMessage));
99 }
100 }
101 #endif
102
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 file.close();
103
104
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 docElem = doc.documentElement();
105
106
3/6
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
3 if (docElem.tagName() != "EtherLabPlainMessages") {
107 throw Exception(
108 QtPdCom::MessageModel::tr("Failed to process %1:"
109 " No plain message file (%2)!"));
110 }
111
112
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 QDomNodeList children = docElem.childNodes();
113
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 QDomNode node;
114
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 QDomElement child;
115
116
3/4
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 3 times.
9 for (int i = 0; i < children.size(); i++) {
117
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 node = children.item(i);
118
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
6 if (node.isElement()) {
119
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 child = node.toElement();
120
3/6
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 6 times.
✗ Branch 10 not taken.
6 if (child.tagName() == "Message") {
121 try {
122 6 QString path = Message::Impl::pathFromPlainXmlElement(
123 child,
124
2/6
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
12 pathPrefix);
125 6 int index =
126
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 Message::Impl::indexFromPlainXmlElement(child);
127
128
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 Message *&msg = impl->messageMap[path][index];
129
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!msg) {
130
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 msg = new Message();
131 }
132
2/4
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
6 msg->impl->fromPlainXmlElement(child, pathPrefix);
133
3/6
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
12 QObject::connect(
134 msg,
135 SIGNAL(stateChanged()),
136 6 impl.get(),
137 SLOT(stateChanged()));
138 }
139 catch (Message::Exception &e) {
140 qWarning() << e.msg;
141 }
142 }
143 }
144 }
145
146 3 impl->lang = lang;
147 3 }
148
149 /****************************************************************************/
150
151 /** Clears the messages.
152 */
153 21 void MessageModel::clear()
154 {
155
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 14 times.
21 if (impl->announcedMessageItem) {
156 7 impl->announcedMessageItem = nullptr;
157 #if PD_DEBUG_MESSAGE_MODEL
158
3/6
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
7 qDebug() << __func__ << "currentMessage null";
159 #endif
160 7 emit currentMessage(nullptr);
161 }
162
163
2/2
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 8 times.
21 if (impl->messageItemList.count()) {
164 13 beginResetModel();
165 13 qDeleteAll(impl->messageItemList);
166 13 impl->messageItemList.clear();
167 13 endResetModel();
168 }
169
170
5/8
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 21 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 23 times.
✓ Branch 11 taken 21 times.
✓ Branch 14 taken 23 times.
✗ Branch 15 not taken.
44 for (auto &h : impl->messageMap) {
171
1/2
✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
23 qDeleteAll(h);
172 }
173
174 21 impl->messageMap.clear();
175 21 }
176
177 /****************************************************************************/
178
179 /** Sets the maximum number of rows to fetch.
180 */
181 void MessageModel::setRowLimit(int limit /**< Maximum number of rows. */)
182 {
183 impl->rowLimit = limit;
184 }
185
186 /****************************************************************************/
187
188 /** Gets the maxium number of rows to fetch.
189 */
190 int MessageModel::getRowLimit() const
191 {
192 return impl->rowLimit;
193 }
194
195 /****************************************************************************/
196
197 /** Connects messages to the given process.
198 */
199 15 void MessageModel::connect(QtPdCom::Process *process /**< PdCom process. */
200 )
201 {
202
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 14 times.
15 if (impl->messageManager) {
203 3 disconnect(
204 1 impl->messageManager,
205 &MessageManager::processMessageSignal,
206 1 impl.get(),
207 &Impl::processMessage);
208 2 disconnect(
209 process,
210 &Process::processConnected,
211 1 impl.get(),
212 &Impl::reloadActiveMessages);
213 3 disconnect(
214 1 impl->messageManager,
215 &MessageManager::processResetSignal,
216 1 impl.get(),
217 &Impl::processReset);
218 }
219
220 15 impl->processReset();
221 15 impl->messageManager = nullptr;
222 15 impl->process = process;
223
224
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 14 times.
15 if (!process) {
225 1 return;
226 }
227
228 14 impl->messageManager =
229
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 dynamic_cast<MessageManager *>(process->getMessageManager());
230
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 if (impl->messageManager) {
231 42 QObject::connect(
232 14 impl->messageManager,
233 &MessageManager::processMessageSignal,
234 14 impl.get(),
235 &Impl::processMessage);
236 28 QObject::connect(
237 process,
238 &Process::processConnected,
239 14 impl.get(),
240 &Impl::reloadActiveMessages);
241 42 QObject::connect(
242 14 impl->messageManager,
243 &MessageManager::processResetSignal,
244 14 impl.get(),
245 &Impl::processReset);
246
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if (process->isConnected()) {
247 impl->reloadActiveMessages();
248 }
249 }
250 else {
251 qWarning() << QtPdCom::MessageModel::tr(
252 "Failed to connect to message manager.");
253 }
254
255
6/10
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 14 times.
✓ Branch 15 taken 6 times.
✗ Branch 16 not taken.
✓ Branch 20 taken 6 times.
✗ Branch 21 not taken.
20 for (auto h : impl->messageMap) {
256 6 Impl::MessageHash::iterator i;
257
5/8
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
12 for (i = h.begin(); i != h.end(); ++i) {
258
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
6 if (i.key() != -1) { /* FIXME vector messages */
259 continue;
260 }
261
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 Message *msg = i.value();
262
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
12 PdCom::Selector selector;
263
264
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
6 if (msg->getIndex() > -1) {
265 selector = PdCom::ScalarSelector({msg->getIndex()});
266 }
267 #if PD_DEBUG_MESSAGE_MODEL
268
6/12
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 6 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 6 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 6 times.
✗ Branch 20 not taken.
6 qDebug() << "Subscribing to" << msg->getPath() << msg->getIndex();
269 #endif
270 try {
271
3/8
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
12 msg->impl->variable.setVariable(
272 process,
273 msg->getPath(),
274 6 selector);
275 }
276 catch (AbstractScalarVariable::Exception &e) {
277 qWarning() << QtPdCom::MessageModel::tr(
278 "Failed to subscribe to %1: %2")
279 .arg(msg->getPath())
280 .arg(e.msg);
281 }
282 }
283 }
284 }
285
286 /****************************************************************************/
287
288 QtPdCom::Process *MessageModel::getProcess() const
289 {
290 return impl->process;
291 }
292
293 /****************************************************************************/
294
295 /** Sets a new language and notifies views.
296 */
297 void MessageModel::translate(const QString &lang)
298 {
299 impl->lang = lang;
300
301 for (int i = 0; i < impl->messageItemList.count(); i++) {
302 QModelIndex idx = index(i, 0); // only text column
303 emit dataChanged(idx, idx);
304 }
305
306 if (impl->announcedMessageItem) {
307 #if PD_DEBUG_MESSAGE_MODEL
308 qDebug() << __func__ << "currentMessage" << impl->announcedMessageItem
309 << impl->announcedMessageItem->message;
310 #endif
311 emit currentMessage(impl->announcedMessageItem->message);
312 }
313 }
314
315 /****************************************************************************/
316
317 /** Sets an icon for a specific message type.
318 */
319 void MessageModel::setIcon(Message::Type type, const QIcon &icon)
320 {
321 impl->iconHash[type] = icon;
322 if (rowCount({}) > 0) {
323 emit dataChanged(
324 index(0, TextColumn),
325 index(rowCount({}) - 1, TextColumn),
326 {Qt::DecorationRole});
327 }
328 }
329
330 /****************************************************************************/
331
332 /** \return Icon for given message type.
333 */
334 const QIcon &MessageModel::getIcon(Message::Type type) const
335 {
336 return impl->iconHash[type];
337 }
338
339 /****************************************************************************/
340
341 /** Sets the path (url) to an icon for a specific message type.
342 If the model is used with QML views this is the only way
343 to store the icon information.
344 */
345 void MessageModel::setIconPath(Message::Type type, const QString &iconPath)
346 {
347 impl->iconPathHash[type] = iconPath;
348 // and also add it to the iconHash
349 setIcon(type, QIcon(iconPath));
350 /* vice versa would be nice, but does not work because
351 to a QIcon the Path is not known */
352 }
353
354 /****************************************************************************/
355
356 QVariantMap QtPdCom::MessageModel::getIconPathMap() const
357 {
358 const auto metaEnum = QMetaEnum::fromType<Message::Type>();
359 QVariantMap ans;
360 for (auto it = impl->iconPathHash.keyBegin();
361 it != impl->iconPathHash.keyEnd();
362 ++it) {
363 ans[QString(metaEnum.valueToKey(*it))] = impl->iconPathHash[*it];
364 }
365 return ans;
366 }
367
368 /****************************************************************************/
369
370 void QtPdCom::MessageModel::setIconPathMap(QVariantMap const map)
371 {
372 const auto metaEnum = QMetaEnum::fromType<Message::Type>();
373 bool ok = false;
374 for (auto it = map.keyBegin(); it != map.keyEnd(); ++it) {
375 const auto key_enum =
376 metaEnum.keyToValue(it->toStdString().c_str(), &ok);
377 if (ok) {
378 setIconPath(
379 static_cast<QtPdCom::Message::Type>(key_enum),
380 map[*it].toString());
381 }
382 }
383 }
384
385 /****************************************************************************/
386
387 /** Implements the model interface.
388 *
389 * \returns Number of active messages.
390 */
391 3395 int MessageModel::rowCount(const QModelIndex &index) const
392 {
393
2/2
✓ Branch 1 taken 3140 times.
✓ Branch 2 taken 255 times.
3395 if (!index.isValid()) {
394 3140 return impl->messageItemList.count();
395 }
396 else {
397 255 return 0;
398 }
399 }
400
401 /****************************************************************************/
402
403 /** Implements the model interface.
404 *
405 * \returns Number of columns.
406 */
407 2525 int MessageModel::columnCount(const QModelIndex &index) const
408 {
409 Q_UNUSED(index);
410 2525 return 3;
411 }
412
413 /****************************************************************************/
414
415 /** Implements the Model interface.
416 */
417 393 QVariant MessageModel::data(const QModelIndex &index, int role) const
418 {
419
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 393 times.
393 if (!index.isValid()) {
420 return QVariant();
421 }
422
423 393 auto msgItem = impl->messageItemList[index.row()];
424
425
3/4
✓ Branch 1 taken 339 times.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
393 switch (index.column()) {
426 339 case TextColumn: // text
427
3/8
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 35 times.
✓ Branch 7 taken 210 times.
339 switch (role) {
428 94 case Qt::DisplayRole:
429
1/2
✓ Branch 4 taken 94 times.
✗ Branch 5 not taken.
94 return msgItem->getText(impl->lang);
430 case Qt::DecorationRole:
431 return impl->iconHash[msgItem->getType()];
432 case DecorationPathRole:
433 return impl->iconPathHash[msgItem->getType()];
434 case TimeStringRole:
435 // it is necessary to return other columns under
436 // column 0 because in QML a View can't address
437 // from column but only from roles
438 return msgItem->getTimeString();
439 case ResetTimeStringRole:
440 return msgItem->getResetTimeString();
441 case MessageTypeRole:
442 return msgItem->getType();
443 35 case Qt::ToolTipRole:
444 35 return impl->wrapText(
445
2/4
✓ Branch 5 taken 35 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 35 times.
✗ Branch 9 not taken.
35 msgItem->getDescription(impl->lang));
446 210 default:
447 210 return QVariant();
448 }
449 break;
450
451 38 case TimeOccurredColumn: // set time
452
1/3
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
38 switch (role) {
453 38 case Qt::DisplayRole:
454
1/2
✓ Branch 3 taken 38 times.
✗ Branch 4 not taken.
38 return msgItem->getTimeString();
455 case Qt::UserRole + 1:
456 return "";
457 default:
458 return QVariant();
459 }
460 break;
461
462 16 case TimeResetColumn: // reset time
463
1/3
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
16 switch (role) {
464 16 case Qt::DisplayRole:
465
1/2
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
16 return msgItem->getResetTimeString();
466 case Qt::UserRole + 1:
467 return "";
468 default:
469 return QVariant();
470 }
471 break;
472
473 default:
474 return QVariant();
475 }
476 }
477
478 /****************************************************************************/
479
480 /** Implements the Model interface.
481 */
482 QVariant
483 MessageModel::headerData(int section, Qt::Orientation o, int role) const
484 {
485 if (role == Qt::DisplayRole && o == Qt::Horizontal) {
486 switch (section) {
487 case TextColumn:
488 return QtPdCom::MessageModel::tr("Message");
489
490 case TimeOccurredColumn:
491 return QtPdCom::MessageModel::tr("Time");
492
493 case TimeResetColumn:
494 return QtPdCom::MessageModel::tr("Reset");
495
496 default:
497 return QVariant();
498 }
499 }
500 else {
501 return QVariant();
502 }
503 }
504
505 /****************************************************************************/
506
507 /** Implements the Model interface.
508 */
509 119 Qt::ItemFlags MessageModel::flags(const QModelIndex &index) const
510 {
511
2/2
✓ Branch 1 taken 79 times.
✓ Branch 2 taken 40 times.
119 if (!index.isValid()) {
512 79 return Qt::ItemFlags();
513 }
514
515 40 auto msgItem {impl->messageItemList[index.row()]};
516
2/2
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 18 times.
40 return msgItem->isActive() ? Qt::ItemIsEnabled : Qt::ItemFlags();
517 }
518
519 /****************************************************************************/
520
521 /** Additional Rolename for decoration for use in QML views
522 */
523
524 79 QHash<int, QByteArray> MessageModel::roleNames() const
525 {
526 // default role names
527 79 QHash<int, QByteArray> roles = QAbstractTableModel::roleNames();
528
529 // extended role names
530
2/4
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 79 times.
✗ Branch 6 not taken.
79 roles[DecorationPathRole] = "decorationPath";
531
2/4
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 79 times.
✗ Branch 6 not taken.
79 roles[TimeStringRole] = "timeString";
532
2/4
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 79 times.
✗ Branch 6 not taken.
79 roles[ResetTimeStringRole] = "resetTimeString";
533
2/4
✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 79 times.
✗ Branch 6 not taken.
79 roles[MessageTypeRole] = "messageTyp";
534 79 return roles;
535 }
536
537 /****************************************************************************/
538
539 81 void MessageModel::fetchMore(const QModelIndex &parent)
540 {
541 #if PD_DEBUG_MESSAGE_MODEL
542
3/6
✓ Branch 6 taken 81 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 81 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 81 times.
✗ Branch 14 not taken.
81 qDebug() << __func__ << parent;
543 #endif
544
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 77 times.
81 if (canFetchMore(parent)) {
545 #if PD_DEBUG_MESSAGE_MODEL
546
4/8
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 4 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 4 times.
✗ Branch 17 not taken.
4 qDebug() << __func__ << parent << "fetching";
547 #endif
548 4 impl->getHistoryMessage();
549 }
550 81 }
551
552 /****************************************************************************/
553
554 197 bool MessageModel::canFetchMore(const QModelIndex &parent) const
555 {
556
2/2
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 189 times.
394 bool ret = !parent.isValid() and impl->canFetchMore
557
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 and impl->historicSeqNo
558
2/4
✓ Branch 0 taken 197 times.
✗ Branch 1 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
205 and impl->messageItemList.count() < impl->rowLimit;
559 #if PD_DEBUG_MESSAGE_MODEL
560
6/12
✓ Branch 5 taken 197 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 197 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 197 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 197 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 197 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 197 times.
✗ Branch 23 not taken.
394 qDebug() << __func__ << parent << "can" << impl->canFetchMore << "hist"
561
2/4
✓ Branch 2 taken 197 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 197 times.
✗ Branch 6 not taken.
197 << impl->historicSeqNo << "space"
562
2/4
✓ Branch 4 taken 197 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 197 times.
✗ Branch 8 not taken.
197 << (impl->messageItemList.count() < impl->rowLimit) << "ret"
563
1/2
✓ Branch 2 taken 197 times.
✗ Branch 3 not taken.
394 << ret;
564 #endif
565 197 return ret;
566 }
567
568 /****************************************************************************/
569
570 /** Event handler.
571 */
572 bool MessageModel::event(QEvent *event /**< Paint event flags. */
573 )
574 {
575 if (event->type() == QEvent::LanguageChange) {
576 emit headerDataChanged(Qt::Horizontal, 0, 1);
577 }
578
579 return QAbstractTableModel::event(event);
580 }
581
582 /****************************************************************************/
583