• 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
eventlistmodel.h
Go to the documentation of this file.
1 /*
2  * eventlistmodel.h - model class for lists of alarms or templates
3  * Program: kalarm
4  * Copyright © 2007-2012 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 #ifndef EVENTLISTMODEL_H
22 #define EVENTLISTMODEL_H
23 
24 #include "kalarm.h"
25 
26 #include "alarmresources.h"
27 
28 #include <kalarmcal/kacalendar.h>
29 #include <kalarmcal/kaevent.h>
30 
31 #include <QAbstractTableModel>
32 #include <QSortFilterProxyModel>
33 #include <QList>
34 #include <QSize>
35 
36 class QPixmap;
37 namespace KCal { class Event; }
38 
39 using namespace KAlarmCal;
40 
41 
42 class EventListModel : public QAbstractTableModel
43 {
44  Q_OBJECT
45  public:
46  enum { // data columns
47  TimeColumn, TimeToColumn, RepeatColumn, ColourColumn, TypeColumn, TextColumn,
48  TemplateNameColumn,
49  ColumnCount
50  };
51  enum { // additional roles
52  StatusRole = Qt::UserRole, // return ACTIVE/ARCHIVED
53  ValueRole, // return numeric value
54  SortRole, // return the value to use for sorting
55  EnabledRole // return true for enabled alarm, false for disabled
56  };
57 
58  static EventListModel* alarms();
59  static EventListModel* templates();
60  ~EventListModel();
61  virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
62  virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
63  virtual QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
64  virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
65  virtual bool setData(const QModelIndex&, const QVariant& value, int role = Qt::EditRole);
66  virtual QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const;
67  virtual Qt::ItemFlags flags(const QModelIndex&) const;
68  static int iconWidth() { return mIconSize.width(); }
69  QModelIndex eventIndex(const KAEvent*) const;
70  QModelIndex eventIndex(const QString& eventId) const;
71  void addEvent(KAEvent*);
72  void addEvents(const KAEvent::List&);
73  bool updateEvent(KAEvent* event) { return updateEvent(mEvents.indexOf(event)); }
74  bool updateEvent(const QString& eventId) { return updateEvent(findEvent(eventId)); }
75  bool updateEvent(const QString& oldId, KAEvent* newEvent);
76  void removeEvent(const KAEvent* event) { removeEvent(mEvents.indexOf(const_cast<KAEvent*>(event))); }
77  void removeEvent(const QString& eventId) { removeEvent(findEvent(eventId)); }
78  void removeResource(AlarmResource*);
79  KAEvent* event(int row) const;
80  static KAEvent* event(const QModelIndex&);
81  void updateCommandError(const QString& eventId);
82  bool haveEvents() const { return mHaveEvents; }
83  static void resourceStatusChanged(AlarmResource*, AlarmResources::Change);
84 
85  public slots:
86  void reload();
87 
88  signals:
89  void haveEventsStatus(bool have);
90 
91  private slots:
92  void slotUpdateTimeTo();
93  void slotUpdateArchivedColour(const QColor&);
94  void slotUpdateDisabledColour(const QColor&);
95  void slotUpdateHolidays();
96  void slotUpdateWorkingHours();
97  void slotResourceLoaded(AlarmResource*, bool active);
98  void slotResourceStatusChanged(AlarmResource*, AlarmResources::Change);
99 
100  private:
101  explicit EventListModel(CalEvent::Types, QObject* parent = 0);
102  bool updateEvent(int row);
103  void removeEvent(int row);
104  int findEvent(const QString& eventId) const;
105  void updateHaveEvents(bool have) { mHaveEvents = have; emit haveEventsStatus(have); }
106  QString repeatText(const KAEvent*) const;
107  QString repeatOrder(const KAEvent*) const;
108  QPixmap* eventIcon(const KAEvent*) const;
109  QString whatsThisText(int column) const;
110 
111  static EventListModel* mAlarmInstance; // the instance containing all alarms
112  static EventListModel* mTemplateInstance; // the instance containing all templates
113  static QPixmap* mTextIcon;
114  static QPixmap* mFileIcon;
115  static QPixmap* mCommandIcon;
116  static QPixmap* mEmailIcon;
117  static QPixmap* mAudioIcon;
118  static QSize mIconSize; // maximum size of any icon
119  static int mTimeHourPos; // position of hour within time string, or -1 if leading zeroes included
120 
121  KAEvent::List mEvents;
122  CalEvent::Types mStatus; // types of events contained in this model
123  bool mHaveEvents;// there are events in this model
124 
125  using QObject::event; // prevent "hidden" warning
126 };
127 
128 
129 class EventListFilterModel : public QSortFilterProxyModel
130 {
131  Q_OBJECT
132  public:
133  explicit EventListFilterModel(EventListModel* baseModel, QObject* parent = 0);
134  KAEvent* event(int row) const;
135  KAEvent* event(const QModelIndex&) const;
136  QModelIndex eventIndex(const KAEvent*) const;
137  QModelIndex eventIndex(const QString& eventId) const;
138 
139  private slots:
140  void slotDataChanged(const QModelIndex&, const QModelIndex&);
141 
142  private:
143  using QObject::event; // prevent "hidden" warning
144 };
145 
146 #endif // EVENTLISTMODEL_H
147 
148 // vim: et sw=4:
EventListFilterModel
Definition: eventlistmodel.h:129
EventListModel::ValueRole
Definition: eventlistmodel.h:53
EventListModel::SortRole
Definition: eventlistmodel.h:54
EventListModel::removeEvent
void removeEvent(const KAEvent *event)
Definition: eventlistmodel.h:76
QObject
EventListModel::iconWidth
static int iconWidth()
Definition: eventlistmodel.h:68
EventListModel::removeEvent
void removeEvent(const QString &eventId)
Definition: eventlistmodel.h:77
EventListModel::TemplateNameColumn
Definition: eventlistmodel.h:48
EventListModel::TypeColumn
Definition: eventlistmodel.h:47
QSortFilterProxyModel
EventListModel::updateEvent
bool updateEvent(KAEvent *event)
Definition: eventlistmodel.h:73
EventListModel::updateEvent
bool updateEvent(const QString &eventId)
Definition: eventlistmodel.h:74
EventListModel
Definition: eventlistmodel.h:42
kalarm.h
EventListModel::haveEvents
bool haveEvents() const
Definition: eventlistmodel.h:82
QAbstractTableModel
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