SerializingObject.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #ifndef SERIALIZING_OBJECT_H
  25. #define SERIALIZING_OBJECT_H
  26. #include <QtCore/QString>
  27. #include "lmms_export.h"
  28. class QDomDocument;
  29. class QDomElement;
  30. class SerializingObjectHook;
  31. class LMMS_EXPORT SerializingObject
  32. {
  33. public:
  34. SerializingObject();
  35. virtual ~SerializingObject();
  36. virtual QDomElement saveState( QDomDocument & _doc, QDomElement & _parent );
  37. virtual void restoreState( const QDomElement & _this );
  38. // to be implemented by actual object
  39. virtual QString nodeName() const = 0;
  40. void setHook( SerializingObjectHook * _hook );
  41. SerializingObjectHook* hook()
  42. {
  43. return m_hook;
  44. }
  45. protected:
  46. // to be implemented by sub-objects
  47. virtual void saveSettings( QDomDocument& doc, QDomElement& element ) = 0;
  48. virtual void loadSettings( const QDomElement& element ) = 0;
  49. private:
  50. SerializingObjectHook * m_hook;
  51. } ;
  52. class SerializingObjectHook
  53. {
  54. public:
  55. SerializingObjectHook() :
  56. m_hookedIn( NULL )
  57. {
  58. }
  59. virtual ~SerializingObjectHook()
  60. {
  61. if( m_hookedIn != NULL )
  62. {
  63. m_hookedIn->setHook( NULL );
  64. }
  65. }
  66. virtual void saveSettings( QDomDocument & _doc, QDomElement & _this ) = 0;
  67. virtual void loadSettings( const QDomElement & _this ) = 0;
  68. private:
  69. SerializingObject * m_hookedIn;
  70. friend class SerializingObject;
  71. } ;
  72. #endif