00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef CONTROLLEREVENTS_H
00026 #define CONTROLLEREVENTS_H
00027
00028
00029 #include "mvcevent.h"
00030 #include "mvccontainers.h"
00031
00032
00033 class QObject;
00034
00035 class AbstractModel;
00036 class AbstractView;
00037
00038
00039
00040
00041
00042 class CEvent;
00043 class UndoRedoItem {
00044 public:
00045 UndoRedoItem( CEvent* event = 0 )
00046 : m_event(event) {}
00047 CEvent* event() const { return m_event; }
00048 private:
00049 CEvent* m_event;
00050 };
00051
00052
00060 class CEvent : public MvcEvent {
00061
00062 public:
00063
00064 enum Flag {
00065 NoFlags = 0x0,
00066 DontUpdateSender = 0x1,
00067 IsUndoEvent = 0x2,
00068 IsRedoEvent = 0x4,
00069 };
00070 Q_DECLARE_FLAGS( Flags, Flag );
00071
00072 enum Type {
00073 ChangeModel = MvcEvent::User,
00074 ViewAttach,
00075 ViewDetach,
00076 DetachAllViews,
00077 User = MvcEvent::User + 1000
00078 };
00079
00080 CEvent( Type type, QObject* sender = 0, Flags flags = NoFlags )
00081 : MvcEvent((MvcEvent::Type)type),
00082 m_sender(sender),
00083 m_flags(flags) {}
00084
00086 inline static DestType classDestType() { return Controller; }
00088 virtual DestType destType() const { return classDestType(); }
00089
00090 QObject* sender() const { return m_sender; }
00091 Flags flags() const { return m_flags; }
00092
00093 bool updateSender() const { return !(m_flags & DontUpdateSender); }
00094 bool isUndoEvent() const { return m_flags & IsUndoEvent; }
00095 bool isRedoEvent() const { return m_flags & IsRedoEvent; }
00096
00097
00098 private:
00099
00100
00101
00102 QObject* m_sender;
00103 Flags m_flags;
00104 };
00105 Q_DECLARE_OPERATORS_FOR_FLAGS( CEvent::Flags );
00106
00107
00108 class CChangeModelEvent : public CEvent, public AbstractModelContainer {
00109 public:
00110 CChangeModelEvent( AbstractModel* model,
00111 QObject* sender = 0, Flags flags = NoFlags )
00112 : CEvent(ChangeModel, sender, flags),
00113 AbstractModelContainer(model) {}
00114 };
00115
00116 class CViewAttachEvent : public CEvent, public AbstractViewContainer {
00117 public:
00118 CViewAttachEvent( AbstractView* view,
00119 QObject* sender = 0, Flags flags = NoFlags )
00120 : CEvent(ViewAttach, sender, flags),
00121 AbstractViewContainer(view) {}
00122 };
00123
00124 class CViewDetachEvent : public CEvent, public AbstractViewContainer {
00125 public:
00126 CViewDetachEvent( AbstractView* view,
00127 QObject* sender = 0, Flags flags = NoFlags )
00128 : CEvent(ViewDetach, sender, flags),
00129 AbstractViewContainer(view) {}
00130 };
00131
00132
00133 #endif // ! CONTROLLEREVENTS_H