00001 /* -*- c++ -*- (for Emacs) 00002 * 00003 * settingscontroller.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 SETTINGSCONTROLLER_H 00026 #define SETTINGSCONTROLLER_H 00027 00028 00029 #include "MvcCore/abstractcontroller.h" 00030 00031 #include <QByteArray> 00032 #include <QMultiHash> 00033 #include <QPointer> 00034 #include <QString> 00035 00036 #include "settingscontrollerevents.h" 00037 00038 class SettingsModel; 00039 00040 00055 class SettingsController : public QObject, 00056 public AbstractController { 00057 00058 Q_OBJECT 00059 00060 public: 00061 SettingsController( QObject* parent = 0 ); 00062 SettingsController( SettingsModel* model, QObject* parent = 0 ); 00063 00064 SettingsModel* settingsModel() const; 00065 00067 inline static MvcModuleId_t classModuleId() { return MvcSettings::id(); } 00069 virtual MvcModuleId_t moduleId() const { return classModuleId(); } 00070 00071 void bind( QObject* obj, const char* objProperty, 00072 const char* objSignal, const QString& settingsKey ); 00073 00074 00075 private slots: 00076 void unbind( QObject* obj ); 00077 void unbind( QObject* obj, const QString& settingsKey ); 00078 void onBoundObjectSignalled(); 00079 00080 00081 protected: 00082 inline virtual void customEvent( QEvent* e ) { 00083 CEvent* ce = dynamic_cast<CEvent*>(e); // slow :-( 00084 if ( ce != 0 ) dispatchEvent(ce); 00085 } 00086 virtual void dispatchEvent( CEvent* ); 00087 00088 virtual void changeModelEvent( CChangeModelEvent* ); 00089 00090 virtual void settingsChangeValueEvent( CSettingsChangeValueEvent* ); 00091 virtual void settingsRemoveKeyEvent( CSettingsRemoveKeyEvent* ); 00092 virtual void settingsRemoveAllEvent( CSettingsEvent* ); 00093 virtual void settingsSyncAllEvent( CSettingsEvent* ); 00094 00095 00096 private: 00097 struct BindingInfo { 00098 QByteArray objProperty; // safer than "const char*" for storage 00099 QByteArray objSignal; // ditto. 00100 QString settingsKey; 00101 }; 00102 00103 // Temporary state: 00104 QMultiHash<QObject*, BindingInfo> m_bindings; // multihash-> * bindings per obj 00105 00106 // Temporary caches: 00107 QPointer<SettingsModel> c_settingsModel; 00108 }; 00109 00110 00111 #endif // ! SETTINGSCONTROLLER_H
1.5.2