DocumentObserver.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef APP_DOCUMENTOBSERVER_H
00025 #define APP_DOCUMENTOBSERVER_H
00026 
00027 #include <boost/signals.hpp>
00028 #include <set>
00029 
00030 namespace App
00031 {
00032 class Document;
00033 class DocumentObject;
00034 class Property;
00035 
00044 class AppExport DocumentObserver
00045 {
00046 
00047 public:
00049     DocumentObserver();
00050     DocumentObserver(Document*);
00051     virtual ~DocumentObserver();
00052 
00056     void attachDocument(Document*);
00060     void detachDocument();
00061 
00062 private:
00064     virtual void slotCreatedDocument(const App::Document& Doc) = 0;
00066     virtual void slotDeletedDocument(const App::Document& Doc) = 0;
00068     virtual void slotCreatedObject(const App::DocumentObject& Obj) = 0;
00070     virtual void slotDeletedObject(const App::DocumentObject& Obj) = 0;
00072     virtual void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) = 0;
00073 
00074 protected:
00075     Document* getDocument() const;
00076 
00077 private:
00078     App::Document* _document;
00079     typedef boost::signals::connection Connection;
00080     Connection connectApplicationCreatedDocument;
00081     Connection connectApplicationDeletedDocument;
00082     Connection connectDocumentCreatedObject;
00083     Connection connectDocumentDeletedObject;
00084     Connection connectDocumentChangedObject;
00085 };
00086 
00093 class AppExport DocumentObjectObserver : public DocumentObserver
00094 {
00095 
00096 public:
00097     typedef std::set<App::DocumentObject*>::const_iterator const_iterator;
00098 
00100     DocumentObjectObserver();
00101     virtual ~DocumentObjectObserver();
00102 
00103     const_iterator begin() const;
00104     const_iterator end() const;
00105     void addToObservation(App::DocumentObject*);
00106     void removeFromObservation(App::DocumentObject*);
00107 
00108 private:
00110     virtual void slotCreatedDocument(const App::Document& Doc);
00112     virtual void slotDeletedDocument(const App::Document& Doc);
00114     virtual void slotCreatedObject(const App::DocumentObject& Obj);
00116     virtual void slotDeletedObject(const App::DocumentObject& Obj);
00118     virtual void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop);
00119     virtual void cancelObservation() = 0;
00120 
00121 private:
00122     std::set<App::DocumentObject*> _objects;
00123 };
00124 
00125 } //namespace App
00126 
00127 #endif // APP_DOCUMENTOBSERVER_H

Generated on Wed Nov 23 19:00:08 2011 for FreeCAD by  doxygen 1.6.1