• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • configuredialog
  • configureagents
configureagentlistmodel.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "configureagentlistmodel.h"
19 
20 #include <QColor>
21 
22 
23 ConfigureAgentListModel::ConfigureAgentListModel(QObject* parent) :
24  QAbstractListModel(parent),
25  mAgentItems()
26 {
27 }
28 
29 ConfigureAgentListModel::~ConfigureAgentListModel()
30 {
31 }
32 
33 bool ConfigureAgentListModel::insertRows(int row, int count, const QModelIndex& parent)
34 {
35  if (row > rowCount()) {
36  return false;
37  }
38 
39  if (count <= 0) {
40  count = 1;
41  }
42 
43  beginInsertRows(parent, row, row + count - 1);
44  for (int i = 0; i < count; ++i) {
45  ConfigureAgentItem info;
46  mAgentItems.insert(row, info);
47  }
48  endInsertRows();
49 
50  return true;
51 }
52 
53 bool ConfigureAgentListModel::setData(const QModelIndex& index, const QVariant& value, int role)
54 {
55  const int row = index.row();
56  if (row >= rowCount()) {
57  return false;
58  }
59 
60  switch (role) {
61  case Qt::DisplayRole:
62  mAgentItems[row].setAgentName(value.toString());
63  break;
64  case DescriptionRole:
65  mAgentItems[row].setDescription(value.toString());
66  break;
67  case PathRole:
68  mAgentItems[row].setPath(value.toString());
69  break;
70  case InterfaceNameRole:
71  mAgentItems[row].setInterfaceName(value.toString());
72  break;
73  case FailedRole:
74  mAgentItems[row].setFailed(value.toBool());
75  break;
76  case Qt::CheckStateRole:
77  mAgentItems[row].setChecked(value.toBool());
78  break;
79  default:
80  return false;
81  }
82 
83  emit dataChanged(index, index);
84  return true;
85 }
86 
87 QVariant ConfigureAgentListModel::data(const QModelIndex& index, int role) const
88 {
89  const int row = index.row();
90  if (row < rowCount()) {
91  switch (role) {
92  case Qt::DisplayRole:
93  return mAgentItems[row].agentName();
94  case DescriptionRole:
95  return mAgentItems[row].description();
96  case PathRole:
97  return mAgentItems[row].path();
98  case InterfaceNameRole:
99  return mAgentItems[row].interfaceName();
100  case FailedRole:
101  return mAgentItems[row].failed();
102  case Qt::CheckStateRole:
103  return mAgentItems[row].checked();
104  case Qt::BackgroundColorRole:
105  if (mAgentItems[row].failed()) {
106  return Qt::red;
107  } else {
108  return QColor();
109  }
110  default:
111  break;
112  }
113  }
114 
115  return QVariant();
116 }
117 
118 int ConfigureAgentListModel::rowCount(const QModelIndex& parent) const
119 {
120  Q_UNUSED(parent);
121  return mAgentItems.count();
122 }
123 
QModelIndex
ConfigureAgentListModel::insertRows
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: configureagentlistmodel.cpp:33
QVector::insert
void insert(int i, const T &value)
ConfigureAgentListModel::InterfaceNameRole
Definition: configureagentlistmodel.h:36
ConfigureAgentListModel::PathRole
Definition: configureagentlistmodel.h:35
QAbstractItemModel::dataChanged
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
ConfigureAgentListModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: configureagentlistmodel.cpp:87
ConfigureAgentItem
Definition: configureagentitem.h:23
QAbstractItemModel::endInsertRows
void endInsertRows()
QObject
ConfigureAgentListModel::ConfigureAgentListModel
ConfigureAgentListModel(QObject *parent=0)
Definition: configureagentlistmodel.cpp:23
ConfigureAgentListModel::FailedRole
Definition: configureagentlistmodel.h:37
QAbstractListModel
ConfigureAgentListModel::DescriptionRole
Definition: configureagentlistmodel.h:34
QModelIndex::row
int row() const
configureagentlistmodel.h
QColor
QAbstractItemModel::beginInsertRows
void beginInsertRows(const QModelIndex &parent, int first, int last)
ConfigureAgentListModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: configureagentlistmodel.cpp:118
QVector::count
int count(const T &value) const
QVariant::toBool
bool toBool() const
ConfigureAgentListModel::~ConfigureAgentListModel
virtual ~ConfigureAgentListModel()
Definition: configureagentlistmodel.cpp:29
QVariant::toString
QString toString() const
ConfigureAgentListModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Definition: configureagentlistmodel.cpp:53
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal