kalarm
resourcemodelview.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 RESOURCEMODELVIEW_H
00022 #define RESOURCEMODELVIEW_H
00023
00024 #include "kalarm.h"
00025
00026 #include <QAbstractListModel>
00027 #include <QSortFilterProxyModel>
00028 #include <QItemDelegate>
00029 #include <QListView>
00030 #include <QList>
00031 #include <QFont>
00032 #include <QColor>
00033
00034 #include "resources/alarmresource.h"
00035 #include "resources/alarmresources.h"
00036
00037
00038 class ResourceModel : public QAbstractListModel
00039 {
00040 Q_OBJECT
00041 public:
00042 static ResourceModel* instance(QObject* parent = 0);
00043 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
00044 virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
00045 virtual QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const;
00046 virtual bool setData(const QModelIndex&, const QVariant& value, int role = Qt::EditRole);
00047 virtual Qt::ItemFlags flags(const QModelIndex&) const;
00048 AlarmResource* resource(const QModelIndex&) const;
00049 void removeResource(AlarmResource*);
00050 void notifyChange(const QModelIndex&);
00051
00052 private slots:
00053 void refresh();
00054 void addResource(AlarmResource*);
00055 void updateResource(AlarmResource*);
00056 void slotStandardChanged(AlarmResource::Type);
00057 void slotLoaded(AlarmResource*, bool active);
00058 void slotStatusChanged(AlarmResource*, AlarmResources::Change);
00059
00060 private:
00061 explicit ResourceModel(QObject* parent = 0);
00062
00063 static ResourceModel* mInstance;
00064 QList<AlarmResource*> mResources;
00065 QString mErrorPrompt;
00066 QFont mFont;
00067 };
00068
00069
00070 class ResourceFilterModel : public QSortFilterProxyModel
00071 {
00072 public:
00073 ResourceFilterModel(QAbstractItemModel* baseModel, QObject* parent);
00074 void setFilter(AlarmResource::Type);
00075 AlarmResource* resource(int row) const;
00076 AlarmResource* resource(const QModelIndex&) const;
00077 void notifyChange(int row);
00078 void notifyChange(const QModelIndex&);
00079
00080 protected:
00081 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
00082
00083 private:
00084 AlarmResource::Type mResourceType;
00085 };
00086
00087
00088 class ResourceView : public QListView
00089 {
00090 public:
00091 ResourceView(QWidget* parent = 0) : QListView(parent) {}
00092 virtual void setModel(QAbstractItemModel*);
00093 AlarmResource* resource(int row) const;
00094 AlarmResource* resource(const QModelIndex&) const;
00095 void notifyChange(int row) const;
00096 void notifyChange(const QModelIndex&) const;
00097
00098 protected:
00099 virtual void mouseReleaseEvent(QMouseEvent*);
00100 virtual bool viewportEvent(QEvent*);
00101 };
00102
00103
00104 class ResourceDelegate : public QItemDelegate
00105 {
00106 public:
00107 ResourceDelegate(ResourceView* parent = 0) : QItemDelegate(parent) {}
00108 virtual bool editorEvent(QEvent*, QAbstractItemModel*, const QStyleOptionViewItem&, const QModelIndex&);
00109 };
00110
00111 #endif // RESOURCEMODELVIEW_H
00112