kalarm
eventlistmodel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef EVENTLISTMODEL_H
00022 #define EVENTLISTMODEL_H
00023
00024 #include "kalarm.h"
00025
00026 #include <QAbstractTableModel>
00027 #include <QSortFilterProxyModel>
00028 #include <QList>
00029 #include <QSize>
00030
00031 #include "kcalendar.h"
00032 #include "alarmevent.h"
00033 #include "alarmresources.h"
00034
00035 class QPixmap;
00036 namespace KCal { class Event; }
00037 class DateTime;
00038 class KAEvent;
00039
00040
00041 class EventListModel : public QAbstractTableModel
00042 {
00043 Q_OBJECT
00044 public:
00045 enum {
00046 TimeColumn, TimeToColumn, RepeatColumn, ColourColumn, TypeColumn, TextColumn,
00047 TemplateNameColumn,
00048 ColumnCount
00049 };
00050 enum {
00051 StatusRole = Qt::UserRole,
00052 ValueRole,
00053 SortRole
00054 };
00055
00056 static EventListModel* alarms();
00057 static EventListModel* templates();
00058 ~EventListModel();
00059 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
00060 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
00061 virtual QModelIndex index(int row, int column = 0, const QModelIndex& parent = QModelIndex()) const;
00062 virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
00063 virtual bool setData(const QModelIndex&, const QVariant& value, int role = Qt::EditRole);
00064 virtual QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const;
00065 virtual Qt::ItemFlags flags(const QModelIndex&) const;
00066 static int iconWidth() { return mIconSize.width(); }
00067 QModelIndex eventIndex(const KAEvent*) const;
00068 QModelIndex eventIndex(const QString& eventId) const;
00069 void addEvent(KAEvent*);
00070 void addEvents(const KAEvent::List&);
00071 bool updateEvent(KAEvent* event) { return updateEvent(mEvents.indexOf(event)); }
00072 bool updateEvent(const QString& eventId) { return updateEvent(findEvent(eventId)); }
00073 bool updateEvent(const QString& oldId, KAEvent* newEvent);
00074 void removeEvent(const KAEvent* event) { removeEvent(mEvents.indexOf(const_cast<KAEvent*>(event))); }
00075 void removeEvent(const QString& eventId) { removeEvent(findEvent(eventId)); }
00076 void removeResource(AlarmResource*);
00077 static KAEvent* event(const QModelIndex&);
00078
00079 public slots:
00080 void reload();
00081
00082 private slots:
00083 void slotUpdateTimeTo();
00084 void slotUpdateArchivedColour(const QColor&);
00085 void slotUpdateDisabledColour(const QColor&);
00086 void slotUpdateWorkingHours();
00087 void slotResourceLoaded(AlarmResource*, bool active);
00088 void slotResourceStatusChanged(AlarmResource*, AlarmResources::Change);
00089
00090 private:
00091 explicit EventListModel(KCalEvent::Status, QObject* parent = 0);
00092 bool updateEvent(int row);
00093 void removeEvent(int row);
00094 int findEvent(const QString& eventId) const;
00095 QString alarmTimeText(const DateTime&) const;
00096 QString timeToAlarmText(const DateTime&) const;
00097 QString repeatText(const KAEvent*) const;
00098 QString repeatOrder(const KAEvent*) const;
00099 QPixmap* eventIcon(const KAEvent*) const;
00100 QString whatsThisText(int column) const;
00101
00102 static EventListModel* mAlarmInstance;
00103 static EventListModel* mTemplateInstance;
00104 static QPixmap* mTextIcon;
00105 static QPixmap* mFileIcon;
00106 static QPixmap* mCommandIcon;
00107 static QPixmap* mEmailIcon;
00108 static QSize mIconSize;
00109 static int mTimeHourPos;
00110
00111 KAEvent::List mEvents;
00112 KCalEvent::Status mStatus;
00113
00114 using QObject::event;
00115 };
00116
00117
00118 class EventListFilterModel : public QSortFilterProxyModel
00119 {
00120 Q_OBJECT
00121 public:
00122 explicit EventListFilterModel(EventListModel* baseModel, QObject* parent = 0);
00123 KAEvent* event(int row) const;
00124 KAEvent* event(const QModelIndex&) const;
00125
00126 private slots:
00127 void slotDataChanged(const QModelIndex&, const QModelIndex&);
00128
00129 private:
00130 using QObject::event;
00131 };
00132
00133 #endif // EVENTLISTMODEL_H
00134