GCC Code Coverage Report


Directory: ./
File: qtpdcom/src/MessageModelFilter.cpp
Date: 2025-02-23 04:08:29
Exec Total Coverage
Lines: 0 18 0.0%
Branches: 0 42 0.0%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2009 - 2024 Bjarne von Horn <vh@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 "MessageModelFilter.h"
23 #include "MessageModel.h"
24
25 namespace QtPdCom {
26
27 class MessageModelFilterPrivate
28 {
29 public:
30 bool showOnlyActiveMessages = false;
31 };
32 } // namespace QtPdCom
33
34 using QtPdCom::MessageModelFilter;
35
36 MessageModelFilter::MessageModelFilter(QObject *parent):
37 QSortFilterProxyModel(parent),
38 d_ptr(new QtPdCom::MessageModelFilterPrivate())
39 {}
40
41 MessageModelFilter::~MessageModelFilter() = default;
42
43 bool MessageModelFilter::getShowOnlyActiveMessages() const
44 {
45 const Q_D(MessageModelFilter);
46 return d->showOnlyActiveMessages;
47 }
48
49 void MessageModelFilter::setShowOnlyActiveMessages(bool value)
50 {
51 Q_D(MessageModelFilter);
52 d->showOnlyActiveMessages = value;
53 }
54
55 bool MessageModelFilter::filterAcceptsRow(
56 int sourceRow,
57 const QModelIndex &sourceParent) const
58 {
59 Q_ASSERT(sourceModel());
60 const Q_D(MessageModelFilter);
61 const auto idx = sourceModel()->index(sourceRow, 0, sourceParent);
62 return !d->showOnlyActiveMessages
63 || sourceModel()
64 ->data(idx, MessageModel::ResetTimeStringRole)
65 .toString()
66 .isEmpty();
67 }
68