MvcCore/controllers/controllerevents.h

Go to the documentation of this file.
00001 /*  -*- c++ -*-  (for Emacs)
00002  *
00003  *  controllerevents.h
00004  *  Digest
00005  * 
00006  *  Created by Aidan Lane on Sun Aug 28 2005.
00007  *  Copyright (c) 2005 Optimisation and Constraint Solving Group,
00008  *  Monash University. All rights reserved.
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 // TODO: move this stack to a separate class
00040 // TODO: allow this to be used with abstract controller ?
00041 // TODO: write doc about posting the undoEvent -> postEvent deletes it!
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 ); // typesafe flags
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   /* Note: The sender can't be const, as the doc may need to send message back
00100    *       (e.g. to revert changes).
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

Generated on Mon Jul 30 09:46:50 2007 for Digest by  doxygen 1.5.2