Mailcommon

invalidfilterlistmodel.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "invalidfilterlistmodel.h"
8
9using namespace MailCommon;
10
11InvalidFilterListModel::InvalidFilterListModel(QObject *parent)
12 : QAbstractListModel(parent)
13{
14}
15
16InvalidFilterListModel::~InvalidFilterListModel() = default;
17
18bool 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 }
34
35 return true;
36}
37
38bool 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
57 return true;
58}
59
60QVariant 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
77int InvalidFilterListModel::rowCount(const QModelIndex &parent) const
78{
79 Q_UNUSED(parent)
80 return mInvalidFilterItems.count();
81}
82
83#include "moc_invalidfilterlistmodel.cpp"
The filter dialog.
void beginInsertRows(const QModelIndex &parent, int first, int last)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
qsizetype count() const const
iterator insert(const_iterator before, parameter_type value)
int row() const const
Q_EMITQ_EMIT
QObject * parent() const const
DisplayRole
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.