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

kalarm

  • sources
  • kde-4.12
  • kdepim
  • kalarm
templatelistfiltermodel.cpp
Go to the documentation of this file.
1 /*
2  * templatelistfiltermodel.cpp - proxy model class for lists of alarm templates
3  * Program: kalarm
4  * Copyright © 2007,2009-2011 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h" //krazy:exclude=includes (kalarm.h must be first)
22 #include "templatelistfiltermodel.h"
23 
24 #include <kalarmcal/kaevent.h>
25 #include <kalarmcal/kacalendar.h>
26 
27 #include <kdebug.h>
28 
29 using namespace KAlarmCal;
30 
31 // TemplateListFilterModel provides sorting and filtering for the alarm list model.
32 
33 
34 void TemplateListFilterModel::setTypeFilter(KAEvent::Actions type)
35 {
36  if (type != mTypeFilter)
37  {
38  mTypeFilter = type;
39  invalidateFilter();
40  }
41 }
42 
43 void TemplateListFilterModel::setTypesEnabled(KAEvent::Actions type)
44 {
45  if (type != mTypesEnabled)
46  {
47  mTypesEnabled = type;
48  invalidateFilter();
49  }
50 }
51 
52 bool TemplateListFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex&) const
53 {
54  QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0);
55  if (sourceModel()->data(sourceIndex, EventListModel::StatusRole).toInt() != CalEvent::TEMPLATE)
56  return false;
57  if (mTypeFilter == KAEvent::ACT_ALL)
58  return true;
59  KAEvent::Actions type = static_cast<EventListModel*>(sourceModel())->event(sourceIndex)->actionTypes();
60  if (type == KAEvent::ACT_DISPLAY_COMMAND)
61  type = KAEvent::ACT_DISPLAY;
62  return type & mTypeFilter;
63 }
64 
65 bool TemplateListFilterModel::filterAcceptsColumn(int sourceCol, const QModelIndex&) const
66 {
67  return sourceCol == EventListModel::TemplateNameColumn
68  || sourceCol == EventListModel::TypeColumn;
69 }
70 
71 QModelIndex TemplateListFilterModel::mapFromSource(const QModelIndex& sourceIndex) const
72 {
73  int proxyColumn;
74  switch (sourceIndex.column())
75  {
76  case EventListModel::TypeColumn:
77  proxyColumn = TypeColumn;
78  break;
79  case EventListModel::TemplateNameColumn:
80  proxyColumn = TemplateNameColumn;
81  break;
82  default:
83  return QModelIndex();
84  }
85  QModelIndex ix = EventListFilterModel::mapFromSource(sourceIndex);
86  return index(ix.row(), proxyColumn, ix.parent());
87 }
88 
89 QModelIndex TemplateListFilterModel::mapToSource(const QModelIndex& proxyIndex) const
90 {
91  int sourceColumn;
92  switch (proxyIndex.column())
93  {
94  case TypeColumn:
95  sourceColumn = EventListModel::TypeColumn;
96  break;
97  case TemplateNameColumn:
98  sourceColumn = EventListModel::TemplateNameColumn;
99  break;
100  default:
101  return QModelIndex();
102  }
103  return EventListFilterModel::mapToSource(proxyIndex);
104 }
105 
106 Qt::ItemFlags TemplateListFilterModel::flags(const QModelIndex& index) const
107 {
108  QModelIndex sourceIndex = mapToSource(index);
109  Qt::ItemFlags f = sourceModel()->flags(sourceIndex);
110  if (mTypesEnabled == KAEvent::ACT_ALL)
111  return f;
112  KAEvent::Actions type = static_cast<EventListModel*>(sourceModel())->event(sourceIndex)->actionTypes();
113  if (type == KAEvent::ACT_DISPLAY_COMMAND)
114  type = KAEvent::ACT_DISPLAY;
115  if (!(type & mTypesEnabled))
116  f = static_cast<Qt::ItemFlags>(f & ~(Qt::ItemIsEnabled | Qt::ItemIsSelectable));
117  return f;
118 }
119 
120 // vim: et sw=4:
EventListModel::StatusRole
Definition: eventlistmodel.h:52
templatelistfiltermodel.h
TemplateListFilterModel::filterAcceptsRow
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
Definition: templatelistfiltermodel.cpp:52
TemplateListFilterModel::setTypeFilter
void setTypeFilter(KAEvent::Actions)
Definition: templatelistfiltermodel.cpp:34
TemplateListFilterModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &) const
Definition: templatelistfiltermodel.cpp:106
EventListModel::TemplateNameColumn
Definition: eventlistmodel.h:48
EventListModel::TypeColumn
Definition: eventlistmodel.h:47
TemplateListFilterModel::filterAcceptsColumn
virtual bool filterAcceptsColumn(int sourceCol, const QModelIndex &sourceParent) const
Definition: templatelistfiltermodel.cpp:65
TemplateListFilterModel::mapToSource
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
Definition: templatelistfiltermodel.cpp:89
EventListModel
Definition: eventlistmodel.h:42
kalarm.h
TemplateListFilterModel::setTypesEnabled
void setTypesEnabled(KAEvent::Actions)
Definition: templatelistfiltermodel.cpp:43
TemplateListFilterModel::mapFromSource
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
Definition: templatelistfiltermodel.cpp:71
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • 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

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