GCC Code Coverage Report


Directory: ./
File: src/MessageModel.cpp
Date: 2025-02-27 10:29:23
Exec Total Coverage
Lines: 132 230 57.4%
Branches: 142 434 32.7%

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 11 MessageModel::MessageModel(QObject *parent):
42 QAbstractTableModel(parent),
43
2/4
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
11 impl(std::unique_ptr<Impl>(new MessageModel::Impl(this)))
44 11 {}
45
46 /****************************************************************************/
47
48 /** Destructor.
49 */
50 26 MessageModel::~MessageModel()
51 {
52 11 clear();
53 15 }
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 15 void MessageModel::clear()
154 {
155
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 10 times.
15 if (impl->announcedMessageItem) {
156 5 impl->announcedMessageItem = nullptr;
157 #if PD_DEBUG_MESSAGE_MODEL
158
3/6
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
5 qDebug() << __func__ << "currentMessage null";
159 #endif
160 5 emit currentMessage(nullptr);
161 }
162
163
2/2
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 4 times.
15 if (impl->messageItemList.count()) {
164
1/2
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
11 beginRemoveRows(QModelIndex(), 0, impl->messageItemList.count() - 1);
165 11 qDeleteAll(impl->messageItemList);
166 11 impl->messageItemList.clear();
167 11 endRemoveRows();
168 }
169
170
5/8
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 15 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✓ Branch 11 taken 15 times.
✓ Branch 14 taken 20 times.
✗ Branch 15 not taken.
35 for (auto &h : impl->messageMap) {
171
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 qDeleteAll(h);
172 }
173
174 15 impl->messageMap.clear();
175 15 }
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 11 void MessageModel::connect(QtPdCom::Process *process /**< PdCom process. */
200 )
201 {
202 11 impl->processReset();
203 11 impl->messageManager = nullptr;
204 11 impl->process = process;
205
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (!process) {
207 return;
208 }
209
210 11 impl->messageManager =
211
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
11 dynamic_cast<MessageManager *>(process->getMessageManager());
212
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
11 if (impl->messageManager) {
213 33 QObject::connect(
214 11 impl->messageManager,
215 &MessageManager::processMessageSignal,
216 11 impl.get(),
217 &Impl::processMessage);
218 22 QObject::connect(
219 process,
220 &Process::processConnected,
221 11 impl.get(),
222 &Impl::reloadActiveMessages);
223 33 QObject::connect(
224 11 impl->messageManager,
225 &MessageManager::processResetSignal,
226 11 impl.get(),
227 &Impl::processReset);
228
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if (process->isConnected()) {
229 impl->reloadActiveMessages();
230 }
231 }
232 else {
233 qWarning() << QtPdCom::MessageModel::tr(
234 "Failed to connect to message manager.");
235 }
236
237
6/10
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 11 times.
✓ Branch 15 taken 6 times.
✗ Branch 16 not taken.
✓ Branch 20 taken 6 times.
✗ Branch 21 not taken.
17 for (auto h : impl->messageMap) {
238 6 Impl::MessageHash::iterator i;
239
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) {
240
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 */
241 continue;
242 }
243
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 Message *msg = i.value();
244
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
12 PdCom::Selector selector;
245
246
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) {
247 selector = PdCom::ScalarSelector({msg->getIndex()});
248 }
249 #if PD_DEBUG_MESSAGE_MODEL
250
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();
251 #endif
252 try {
253
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(
254 process,
255 msg->getPath(),
256 6 selector);
257 }
258 catch (AbstractScalarVariable::Exception &e) {
259 qWarning() << QtPdCom::MessageModel::tr(
260 "Failed to subscribe to %1: %2")
261 .arg(msg->getPath())
262 .arg(e.msg);
263 }
264 }
265 }
266 }
267
268 /****************************************************************************/
269
270 QtPdCom::Process *MessageModel::getProcess() const
271 {
272 return impl->process;
273 }
274
275 /****************************************************************************/
276
277 /** Sets a new language and notifies views.
278 */
279 void MessageModel::translate(const QString &lang)
280 {
281 impl->lang = lang;
282
283 for (int i = 0; i < impl->messageItemList.count(); i++) {
284 QModelIndex idx = index(i, 0); // only text column
285 emit dataChanged(idx, idx);
286 }
287
288 if (impl->announcedMessageItem) {
289 #if PD_DEBUG_MESSAGE_MODEL
290 qDebug() << __func__ << "currentMessage" << impl->announcedMessageItem
291 << impl->announcedMessageItem->message;
292 #endif
293 emit currentMessage(impl->announcedMessageItem->message);
294 }
295 }
296
297 /****************************************************************************/
298
299 /** Sets an icon for a specific message type.
300 */
301 void MessageModel::setIcon(Message::Type type, const QIcon &icon)
302 {
303 impl->iconHash[type] = icon;
304 if (rowCount({}) > 0) {
305 emit dataChanged(
306 index(0, TextColumn),
307 index(rowCount({}) - 1, TextColumn),
308 {Qt::DecorationRole});
309 }
310 }
311
312 /****************************************************************************/
313
314 /** \return Icon for given message type.
315 */
316 const QIcon &MessageModel::getIcon(Message::Type type) const
317 {
318 return impl->iconHash[type];
319 }
320
321 /****************************************************************************/
322
323 /** Sets the path (url) to an icon for a specific message type.
324 If the model is used with QML views this is the only way
325 to store the icon information.
326 */
327 void MessageModel::setIconPath(Message::Type type, const QString &iconPath)
328 {
329 impl->iconPathHash[type] = iconPath;
330 // and also add it to the iconHash
331 setIcon(type, QIcon(iconPath));
332 /* vice versa would be nice, but does not work because
333 to a QIcon the Path is not known */
334 }
335
336 /****************************************************************************/
337
338 QVariantMap QtPdCom::MessageModel::getIconPathMap() const
339 {
340 const auto metaEnum = QMetaEnum::fromType<Message::Type>();
341 QVariantMap ans;
342 for (auto it = impl->iconPathHash.keyBegin();
343 it != impl->iconPathHash.keyEnd();
344 ++it) {
345 ans[QString(metaEnum.valueToKey(*it))] = impl->iconPathHash[*it];
346 }
347 return ans;
348 }
349
350 /****************************************************************************/
351
352 void QtPdCom::MessageModel::setIconPathMap(QVariantMap const map)
353 {
354 const auto metaEnum = QMetaEnum::fromType<Message::Type>();
355 bool ok = false;
356 for (auto it = map.keyBegin(); it != map.keyEnd(); ++it) {
357 const auto key_enum =
358 metaEnum.keyToValue(it->toStdString().c_str(), &ok);
359 if (ok) {
360 setIconPath(
361 static_cast<QtPdCom::Message::Type>(key_enum),
362 map[*it].toString());
363 }
364 }
365 }
366
367 /****************************************************************************/
368
369 /** Implements the model interface.
370 *
371 * \returns Number of active messages.
372 */
373 4032 int MessageModel::rowCount(const QModelIndex &index) const
374 {
375
2/2
✓ Branch 1 taken 3708 times.
✓ Branch 2 taken 324 times.
4032 if (!index.isValid()) {
376 3708 return impl->messageItemList.count();
377 }
378 else {
379 324 return 0;
380 }
381 }
382
383 /****************************************************************************/
384
385 /** Implements the model interface.
386 *
387 * \returns Number of columns.
388 */
389 3097 int MessageModel::columnCount(const QModelIndex &index) const
390 {
391 Q_UNUSED(index);
392 3097 return 3;
393 }
394
395 /****************************************************************************/
396
397 /** Implements the Model interface.
398 */
399 441 QVariant MessageModel::data(const QModelIndex &index, int role) const
400 {
401
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 441 times.
441 if (!index.isValid()) {
402 return QVariant();
403 }
404
405 441 auto msgItem = impl->messageItemList[index.row()];
406
407
3/4
✓ Branch 1 taken 399 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
441 switch (index.column()) {
408 399 case TextColumn: // text
409
3/8
✓ Branch 0 taken 98 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 43 times.
✓ Branch 7 taken 258 times.
399 switch (role) {
410 98 case Qt::DisplayRole:
411
1/2
✓ Branch 4 taken 98 times.
✗ Branch 5 not taken.
98 return msgItem->getText(impl->lang);
412 case Qt::DecorationRole:
413 return impl->iconHash[msgItem->getType()];
414 case DecorationPathRole:
415 return impl->iconPathHash[msgItem->getType()];
416 case TimeStringRole:
417 // it is necessary to return other columns under
418 // column 0 because in QML a View can't address
419 // from column but only from roles
420 return msgItem->getTimeString();
421 case ResetTimeStringRole:
422 return msgItem->getResetTimeString();
423 case MessageTypeRole:
424 return msgItem->getType();
425 43 case Qt::ToolTipRole:
426 43 return impl->wrapText(
427
2/4
✓ Branch 5 taken 43 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 43 times.
✗ Branch 9 not taken.
43 msgItem->getDescription(impl->lang));
428 258 default:
429 258 return QVariant();
430 }
431 break;
432
433 30 case TimeOccurredColumn: // set time
434
1/3
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
30 switch (role) {
435 30 case Qt::DisplayRole:
436
1/2
✓ Branch 3 taken 30 times.
✗ Branch 4 not taken.
30 return msgItem->getTimeString();
437 case Qt::UserRole + 1:
438 return "";
439 default:
440 return QVariant();
441 }
442 break;
443
444 12 case TimeResetColumn: // reset time
445
1/3
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
12 switch (role) {
446 12 case Qt::DisplayRole:
447
1/2
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
12 return msgItem->getResetTimeString();
448 case Qt::UserRole + 1:
449 return "";
450 default:
451 return QVariant();
452 }
453 break;
454
455 default:
456 return QVariant();
457 }
458 }
459
460 /****************************************************************************/
461
462 /** Implements the Model interface.
463 */
464 QVariant
465 MessageModel::headerData(int section, Qt::Orientation o, int role) const
466 {
467 if (role == Qt::DisplayRole && o == Qt::Horizontal) {
468 switch (section) {
469 case TextColumn:
470 return QtPdCom::MessageModel::tr("Message");
471
472 case TimeOccurredColumn:
473 return QtPdCom::MessageModel::tr("Time");
474
475 case TimeResetColumn:
476 return QtPdCom::MessageModel::tr("Reset");
477
478 default:
479 return QVariant();
480 }
481 }
482 else {
483 return QVariant();
484 }
485 }
486
487 /****************************************************************************/
488
489 /** Implements the Model interface.
490 */
491 119 Qt::ItemFlags MessageModel::flags(const QModelIndex &index) const
492 {
493
2/2
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 36 times.
119 if (!index.isValid()) {
494 83 return Qt::ItemFlags();
495 }
496
497 36 auto msgItem {impl->messageItemList[index.row()]};
498
2/2
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 18 times.
36 return msgItem->isActive() ? Qt::ItemIsEnabled : Qt::ItemFlags();
499 }
500
501 /****************************************************************************/
502
503 /** Additional Rolename for decoration for use in QML views
504 */
505
506 83 QHash<int, QByteArray> MessageModel::roleNames() const
507 {
508 // default role names
509 83 QHash<int, QByteArray> roles = QAbstractTableModel::roleNames();
510
511 // extended role names
512
2/4
✓ Branch 2 taken 83 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 83 times.
✗ Branch 6 not taken.
83 roles[DecorationPathRole] = "decorationPath";
513
2/4
✓ Branch 2 taken 83 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 83 times.
✗ Branch 6 not taken.
83 roles[TimeStringRole] = "timeString";
514
2/4
✓ Branch 2 taken 83 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 83 times.
✗ Branch 6 not taken.
83 roles[ResetTimeStringRole] = "resetTimeString";
515
2/4
✓ Branch 2 taken 83 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 83 times.
✗ Branch 6 not taken.
83 roles[MessageTypeRole] = "messageTyp";
516 83 return roles;
517 }
518
519 /****************************************************************************/
520
521 85 void MessageModel::fetchMore(const QModelIndex &parent)
522 {
523 #if PD_DEBUG_MESSAGE_MODEL
524
3/6
✓ Branch 6 taken 85 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 85 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 85 times.
✗ Branch 14 not taken.
85 qDebug() << __func__ << parent;
525 #endif
526
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 81 times.
85 if (canFetchMore(parent)) {
527 #if PD_DEBUG_MESSAGE_MODEL
528
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";
529 #endif
530 4 impl->getHistoryMessage();
531 }
532 85 }
533
534 /****************************************************************************/
535
536 213 bool MessageModel::canFetchMore(const QModelIndex &parent) const
537 {
538
2/2
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 205 times.
426 bool ret = !parent.isValid() and impl->canFetchMore
539
1/2
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
8 and impl->historicSeqNo
540
2/4
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
221 and impl->messageItemList.count() < impl->rowLimit;
541 #if PD_DEBUG_MESSAGE_MODEL
542
6/12
✓ Branch 5 taken 213 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 213 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 213 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 213 times.
✗ Branch 16 not taken.
✓ Branch 19 taken 213 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 213 times.
✗ Branch 23 not taken.
426 qDebug() << __func__ << parent << "can" << impl->canFetchMore << "hist"
543
2/4
✓ Branch 2 taken 213 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 213 times.
✗ Branch 6 not taken.
213 << impl->historicSeqNo << "space"
544
2/4
✓ Branch 4 taken 213 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 213 times.
✗ Branch 8 not taken.
213 << (impl->messageItemList.count() < impl->rowLimit) << "ret"
545
1/2
✓ Branch 2 taken 213 times.
✗ Branch 3 not taken.
426 << ret;
546 #endif
547 213 return ret;
548 }
549
550 /****************************************************************************/
551
552 /** Event handler.
553 */
554 bool MessageModel::event(QEvent *event /**< Paint event flags. */
555 )
556 {
557 if (event->type() == QEvent::LanguageChange) {
558 emit headerDataChanged(Qt::Horizontal, 0, 1);
559 }
560
561 return QAbstractTableModel::event(event);
562 }
563
564 /****************************************************************************/
565