1 /* 2 * SerializingObject.h - declaration of class SerializingObject 3 * 4 * Copyright (c) 2008-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net> 5 * 6 * This file is part of LMMS - https://lmms.io 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public 19 * License along with this program (see COPYING); if not, write to the 20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301 USA. 22 * 23 */ 24 25 #ifndef SERIALIZING_OBJECT_H 26 #define SERIALIZING_OBJECT_H 27 28 #include <QtCore/QString> 29 30 #include "export.h" 31 32 33 class QDomDocument; 34 class QDomElement; 35 36 class SerializingObjectHook; 37 38 39 class EXPORT SerializingObject 40 { 41 public: 42 SerializingObject(); 43 virtual ~SerializingObject(); 44 45 virtual QDomElement saveState( QDomDocument & _doc, QDomElement & _parent ); 46 47 virtual void restoreState( const QDomElement & _this ); 48 49 50 // to be implemented by actual object 51 virtual QString nodeName() const = 0; 52 53 void setHook( SerializingObjectHook * _hook ); 54 hook()55 SerializingObjectHook* hook() 56 { 57 return m_hook; 58 } 59 60 61 protected: 62 // to be implemented by sub-objects 63 virtual void saveSettings( QDomDocument& doc, QDomElement& element ) = 0; 64 virtual void loadSettings( const QDomElement& element ) = 0; 65 66 67 private: 68 SerializingObjectHook * m_hook; 69 70 } ; 71 72 73 class SerializingObjectHook 74 { 75 public: SerializingObjectHook()76 SerializingObjectHook() : 77 m_hookedIn( NULL ) 78 { 79 } ~SerializingObjectHook()80 virtual ~SerializingObjectHook() 81 { 82 if( m_hookedIn != NULL ) 83 { 84 m_hookedIn->setHook( NULL ); 85 } 86 } 87 88 virtual void saveSettings( QDomDocument & _doc, QDomElement & _this ) = 0; 89 virtual void loadSettings( const QDomElement & _this ) = 0; 90 91 private: 92 SerializingObject * m_hookedIn; 93 94 friend class SerializingObject; 95 96 } ; 97 98 99 #endif 100 101