Mailcommon

invalidfilterlistmodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "invalidfilterlistmodel.h"
8 
9 using namespace MailCommon;
10 
11 InvalidFilterListModel::InvalidFilterListModel(QObject *parent)
12  : QAbstractListModel(parent)
13 {
14 }
15 
16 InvalidFilterListModel::~InvalidFilterListModel() = default;
17 
18 bool InvalidFilterListModel::insertRows(int row, int count, const QModelIndex &parent)
19 {
20  if (row > rowCount()) {
21  return false;
22  }
23 
24  if (count <= 0) {
25  count = 1;
26  }
27 
28  beginInsertRows(parent, row, row + count - 1);
29  for (int i = 0; i < count; ++i) {
30  MailCommon::InvalidFilterInfo info;
31  mInvalidFilterItems.insert(row, info);
32  }
33  endInsertRows();
34 
35  return true;
36 }
37 
38 bool InvalidFilterListModel::setData(const QModelIndex &index, const QVariant &value, int role)
39 {
40  const int row = index.row();
41  if (row >= rowCount()) {
42  return false;
43  }
44 
45  switch (role) {
46  case Qt::DisplayRole:
47  mInvalidFilterItems[row].setName(value.toString());
48  break;
49  case InformationRole:
50  mInvalidFilterItems[row].setInformation(value.toString());
51  break;
52  default:
53  return false;
54  }
55 
56  Q_EMIT dataChanged(index, index);
57  return true;
58 }
59 
60 QVariant InvalidFilterListModel::data(const QModelIndex &index, int role) const
61 {
62  const int row = index.row();
63  if (row < rowCount()) {
64  switch (role) {
65  case Qt::DisplayRole:
66  return mInvalidFilterItems[row].name();
67  case InformationRole:
68  return mInvalidFilterItems[row].information();
69  default:
70  break;
71  }
72  }
73 
74  return {};
75 }
76 
77 int InvalidFilterListModel::rowCount(const QModelIndex &parent) const
78 {
79  Q_UNUSED(parent)
80  return mInvalidFilterItems.count();
81 }
DisplayRole
int row() const const
The filter dialog.
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.