MvcSettings/models/settingsmodel.h

Go to the documentation of this file.
00001 /*  -*- c++ -*-  (for Emacs)
00002  *
00003  *  settingsmodel.h
00004  *  Digest
00005  * 
00006  *  Created by Aidan Lane on Wed Aug 31 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 SETTINGSMODEL_H
00026 #define SETTINGSMODEL_H
00027 
00028 
00029 #include "MvcCore/abstractmodel.h"
00030 
00031 #include <QPointer>
00032 #include <QSettings>
00033 
00034 #include "settingsmodelevents.h"
00035 
00036 class SettingsController;
00037 
00038 
00039 class SettingsModel : public QObject, public AbstractModel {
00040 
00041   Q_OBJECT
00042 
00043 public:
00044   SettingsModel( const QString& organization,
00045                  const QString& application = QString(),
00046                  QObject* parent = 0 );
00047   SettingsModel( QSettings::Scope scope,
00048                  const QString& organization,
00049                  const QString& application = QString(),
00050                  QObject* parent = 0 );
00051   SettingsModel( QSettings::Format format,
00052                  QSettings::Scope scope,
00053                  const QString& organization,
00054                  const QString& application = QString(),
00055                  QObject* parent = 0 );
00056   SettingsModel( const QString& fileName,
00057                  QSettings::Format format,
00058                  QObject* parent = 0 );
00059   SettingsModel( QObject* parent = 0 );
00060 
00061   SettingsController* settingsController() const;
00062 
00063   const QSettings* constSettings() const;
00064   QVariant value( const QString& key,
00065                   const QVariant& defaultValue = QVariant() ) const;
00066 
00068   inline static MvcModuleId_t classModuleId() { return MvcSettings::id(); }
00070   virtual MvcModuleId_t moduleId() const { return classModuleId(); }
00071 
00072 
00073 protected:
00074   inline virtual void customEvent( QEvent* e ) {
00075     MEvent* me = dynamic_cast<MEvent*>(e); // slow :-(
00076     if ( me != 0 ) dispatchEvent(me);
00077   }
00078   virtual void dispatchEvent( MEvent* );
00079 
00080   virtual void changeControllerEvent( MChangeControllerEvent* );
00081 
00082   virtual void settingsChangeValueEvent( MSettingsChangeValueEvent* );
00083   virtual void settingsRemoveKeyEvent( MSettingsRemoveKeyEvent* );
00084   virtual void settingsRemoveAllEvent( MSettingsEvent* );
00085   virtual void settingsSyncAllEvent( MSettingsEvent* );
00086 
00087   QSettings* settings() const;
00088 
00089 
00090 private:
00091   // Persistent state:
00092   QSettings* m_settings;
00093 
00094   // Temporary caches:
00095   QPointer<SettingsController> c_settingsController;
00096 };
00097 
00098 
00099 #endif // ! SETTINGSMODEL_H

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