| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/***************************************************************************** |
| 2 |
|
|
* |
| 3 |
|
|
* Copyright (C) 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 "MessageItem.h" |
| 23 |
|
|
#include "MessageImpl.h" |
| 24 |
|
|
|
| 25 |
|
|
namespace QtPdCom { |
| 26 |
|
|
|
| 27 |
|
|
/****************************************************************************/ |
| 28 |
|
|
|
| 29 |
|
✗ |
bool seqNoLessThan(uint32_t a, uint32_t b) |
| 30 |
|
|
{ |
| 31 |
|
✗ |
return int32_t(a - b) > 0; // greater seqNos shall be on top of the list |
| 32 |
|
|
} |
| 33 |
|
|
|
| 34 |
|
|
/****************************************************************************/ |
| 35 |
|
|
|
| 36 |
|
✗ |
MessageModel::Impl::MessageItem::MessageItem( |
| 37 |
|
|
Message *message, |
| 38 |
|
|
MessageModel::Impl *modelImpl, |
| 39 |
|
✗ |
quint64 setTime): |
| 40 |
|
|
message{message}, |
| 41 |
|
|
modelImpl{modelImpl}, |
| 42 |
|
|
seqNo{0}, |
| 43 |
|
|
setTime{setTime}, |
| 44 |
|
✗ |
resetTime{0} |
| 45 |
|
|
{ |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
/****************************************************************************/ |
| 49 |
|
|
|
| 50 |
|
✗ |
Message::Type MessageModel::Impl::MessageItem::getType() const |
| 51 |
|
|
{ |
| 52 |
|
✗ |
return message->getType(); |
| 53 |
|
|
} |
| 54 |
|
|
|
| 55 |
|
|
/****************************************************************************/ |
| 56 |
|
|
|
| 57 |
|
✗ |
QString MessageModel::Impl::MessageItem::getText( |
| 58 |
|
|
const QString &lang) const |
| 59 |
|
|
{ |
| 60 |
|
✗ |
return message->getText(lang); |
| 61 |
|
|
} |
| 62 |
|
|
|
| 63 |
|
|
/****************************************************************************/ |
| 64 |
|
|
|
| 65 |
|
✗ |
QString MessageModel::Impl::MessageItem::getDescription( |
| 66 |
|
|
const QString &lang) const |
| 67 |
|
|
{ |
| 68 |
|
✗ |
return message->getDescription(lang); |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
|
/****************************************************************************/ |
| 72 |
|
|
|
| 73 |
|
✗ |
QString MessageModel::Impl::MessageItem::getTimeString() const |
| 74 |
|
|
{ |
| 75 |
|
✗ |
return message->impl->timeString(setTime); |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
|
/****************************************************************************/ |
| 79 |
|
|
|
| 80 |
|
✗ |
QString MessageModel::Impl::MessageItem::getResetTimeString() const |
| 81 |
|
|
{ |
| 82 |
|
✗ |
if (resetTime) { |
| 83 |
|
✗ |
return message->impl->timeString(resetTime); |
| 84 |
|
|
} |
| 85 |
|
|
else { |
| 86 |
|
✗ |
return QString(); |
| 87 |
|
|
} |
| 88 |
|
|
} |
| 89 |
|
|
|
| 90 |
|
|
/****************************************************************************/ |
| 91 |
|
|
|
| 92 |
|
✗ |
bool MessageModel::Impl::MessageItem::isActive() const |
| 93 |
|
|
{ |
| 94 |
|
✗ |
return resetTime == 0; |
| 95 |
|
|
} |
| 96 |
|
|
|
| 97 |
|
|
/****************************************************************************/ |
| 98 |
|
|
|
| 99 |
|
✗ |
bool MessageModel::Impl::MessageItem::seqNoLessThan(const MessageItem *a, |
| 100 |
|
|
const MessageItem *b) |
| 101 |
|
|
{ |
| 102 |
|
✗ |
return QtPdCom::seqNoLessThan(a->seqNo, b->seqNo); |
| 103 |
|
|
} |
| 104 |
|
|
|
| 105 |
|
|
/****************************************************************************/ |
| 106 |
|
|
|
| 107 |
|
✗ |
bool MessageModel::Impl::MessageItem::setTimeLessThan(const MessageItem *a, |
| 108 |
|
|
const MessageItem *b) |
| 109 |
|
|
{ |
| 110 |
|
✗ |
qint64 diff = a->setTime - b->setTime; |
| 111 |
|
|
return diff > 0 |
| 112 |
|
✗ |
or (!diff and seqNoLessThan(a, b)); |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
|
|
/****************************************************************************/ |
| 116 |
|
|
|
| 117 |
|
✗ |
bool MessageModel::Impl::MessageItem::levelNoLessThan( |
| 118 |
|
|
const MessageModel::Impl::MessageItem *a, const MessageItem *b) |
| 119 |
|
|
{ |
| 120 |
|
✗ |
bool aIsReset = a->resetTime; |
| 121 |
|
✗ |
bool bIsReset = b->resetTime; |
| 122 |
|
|
|
| 123 |
|
|
/* sorting rules: |
| 124 |
|
|
* |
| 125 |
|
|
* - if a message is reset, it should be displayed below all active |
| 126 |
|
|
* messages. |
| 127 |
|
|
* - among reset messages, the sorting should happen just accorting the |
| 128 |
|
|
* time (and sequence number, if time is equal), so ignoring the type |
| 129 |
|
|
* for reset messages. |
| 130 |
|
|
* - for active messages, those with more critical types shall be |
| 131 |
|
|
* displayed on top of the list, thus the set time shall be as ordering |
| 132 |
|
|
* citerion for active messages with the same type. |
| 133 |
|
|
*/ |
| 134 |
|
|
|
| 135 |
|
✗ |
bool ret = (!aIsReset and !bIsReset |
| 136 |
|
✗ |
and (a->getType() > b->getType() // critical types on top |
| 137 |
|
✗ |
or (a->getType() == b->getType() |
| 138 |
|
✗ |
and setTimeLessThan(a, b)))) |
| 139 |
|
✗ |
or (bIsReset |
| 140 |
|
✗ |
and (!aIsReset or seqNoLessThan(a, b))); |
| 141 |
|
✗ |
return ret; |
| 142 |
|
|
} |
| 143 |
|
|
|
| 144 |
|
|
/****************************************************************************/ |
| 145 |
|
|
|
| 146 |
|
✗ |
bool MessageModel::Impl::MessageItem::lessThan(const MessageItem *a, |
| 147 |
|
|
const MessageItem *b) |
| 148 |
|
|
{ |
| 149 |
|
✗ |
return a->modelImpl->lessThan(a, b); |
| 150 |
|
|
} |
| 151 |
|
|
|
| 152 |
|
|
/****************************************************************************/ |
| 153 |
|
|
|
| 154 |
|
|
} // namespace |
| 155 |
|
|
|
| 156 |
|
|
/****************************************************************************/ |
| 157 |
|
|
|