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

kalarm

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