preferencesEntry.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: preferencesEntry.h,v 1.10.16.1 2007/03/25 21:26:02 oliver Exp $
00005 //
00006 
00007 #ifndef BALL_VIEW_KERNEL_PREFERENCES_ENTRY
00008 #define BALL_VIEW_KERNEL_PREFERENCES_ENTRY
00009 
00010 #ifndef BALL_FORMAT_INIFILE_H
00011 # include <BALL/FORMAT/INIFile.h>
00012 #endif
00013 
00014 #ifndef BALL_DATATYPE_HASHSET_H
00015 # include <BALL/DATATYPE/hashSet.h>
00016 #endif
00017 
00018 
00019 class QWidget;
00020 class QObject;
00021 class QStackedWidget;
00022 
00023 namespace BALL
00024 {
00025   class INIFile;
00026 
00027   namespace VIEW
00028   {
00068     class BALL_VIEW_EXPORT PreferencesEntry
00069     {
00070       public:
00071 
00078       class BALL_VIEW_EXPORT ExtendedPreferencesObject
00079       {
00080         public:
00081 
00083         ExtendedPreferencesObject() {};
00084 
00086         virtual ~ExtendedPreferencesObject() {};
00087 
00089         virtual bool getValue(String&) const = 0;
00090 
00092         virtual bool setValue(const String&) = 0;
00093       };
00094 
00096       typedef List<std::pair<QWidget*, String> > StackPages;
00097 
00099       PreferencesEntry();
00100 
00102       virtual ~PreferencesEntry();
00103 
00105       virtual void writePreferenceEntries(INIFile& inifile);
00106 
00108       virtual void readPreferenceEntries(const INIFile& inifile);
00109 
00111       void setINIFileSectionName(const String& name) { inifile_section_name_ = name;}
00112 
00114       const String& getINIFileSectionName() const { return inifile_section_name_;}
00115 
00119       void setWidgetStackName(const String& name);
00120 
00122       StackPages& getStackPages() { return stack_pages_;}
00123 
00127       void setWidgetStack(QStackedWidget* stack);
00128 
00130       virtual void showStackPage(Position nr);
00131 
00133       virtual void showStackPage(QWidget* widget);
00134 
00136       virtual Position currentStackPage() const;
00137 
00139       virtual void restoreDefaultValues(bool all = false);
00140 
00144       virtual void storeValues();
00145 
00149       virtual void restoreValues(bool all = false);
00150 
00157       virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
00158 
00159       protected:
00160 
00162       typedef HashMap<const QObject*, String> ValueMap;
00163 
00167       void registerWidgets_();
00168 
00169       /*_ Registration for objects, that are not automatically supported.
00170           Should no be needed, but if the need should arive, call it in the constructor of the derived class.
00171       */
00172       void registerObject_(QObject* widget);
00173 
00174       /*_ Unregistration for objects, that are automatically registered.
00175           Should no be needed, but if the need should arive, call it in the constructor of the derived class
00176           after registerWidgets_()
00177       */
00178       void unregisterObject_(QObject* widget);
00179 
00183       void registerWidgetForHelpSystem_(const QWidget* widget, const String& url);
00184 
00185       //_ Helper function to restore the values of the current stack widget or all values
00186       void restoreValues_(bool all, const ValueMap& map);
00187 
00188       //_ Add a stack entry
00189       void insertStackEntry_(QWidget*, const String& name);
00190 
00191       //_ Check if the object's data can be transformed into a string
00192       bool isSupported_(QObject& widget);
00193 
00194       //_ Transform the object's data into a string
00195       bool getValue_(const QObject* widget, String& value);
00196 
00197       //_ Restore the widget's data from a string
00198       bool setValue_(QObject* widget, const String& value);
00199 
00200       // name for the section in the INIFile
00201       String inifile_section_name_;
00202 
00203       // all registered child objects
00204       HashSet<QObject*> registered_objects_;
00205 
00206       // stored default and last values for each registered object
00207       ValueMap default_values_, last_values_;
00208 
00209       // if the derived class has its own QStackedWidget, it is stored here
00210       QStackedWidget* widget_stack_;
00211 
00212       StackPages stack_pages_;
00213     };
00214 
00215   } // namespace VIEW
00216 } // namespace BALL
00217 
00218 #endif // BALL_VIEW_KERNEL_PREFERENCES_ENTRY