1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef TInspector_Preferences_H
17 #define TInspector_Preferences_H
19 #include <TCollection_AsciiString.hxx>
20 #include <inspector/TInspectorAPI_PreferencesDataMap.hxx>
22 #include <Standard_WarningsDisable.hxx>
23 #include <QDomElement>
24 #include <Standard_WarningsRestore.hxx>
26 //! The class to read/write custom plugin preferences in XML format.
27 //! The preferences file is intended to know about:
28 //! - dock window placement
29 //! - tree view columns: visibility, width
30 class TInspector_Preferences
33 //! Constructs the communicator.
34 TInspector_Preferences() {}
37 virtual ~TInspector_Preferences() {}
39 static Standard_CString PreferencesFileName() { return ".tinspector.xml"; }
41 //! Sets path to a preferences file
42 //! \param thePath a path
43 void SetDirectory (const TCollection_AsciiString& thePath) { reset(); myDirectory = thePath; }
45 //! Returns path to a preferences file
47 TCollection_AsciiString GetDirectory() const { return myDirectory; }
49 //! Returns plugin preferences
50 //! \param thePluginName a plugin name
51 Standard_EXPORT void GetPreferences (const TCollection_AsciiString& thePluginName,
52 TInspectorAPI_PreferencesDataMap& theItem);
54 //! Stores plugin preferences
55 //! \param thePluginName a plugin name
56 //! \theItem container of plugin preferences values in form: <name, value>
57 void SetPreferences (const TCollection_AsciiString& thePluginName, const TInspectorAPI_PreferencesDataMap& theItem)
58 { myLoadedPreferences.Bind(thePluginName, theItem); }
60 //! Store plugin preferences into a preferences file
61 Standard_EXPORT void StorePreferences();
63 //! Remove plugin preferences file
64 Standard_EXPORT void RemovePreferences();
67 //! Loads the directory preference file with filling internal container
68 void loadPreferences();
70 //! clears all internal containers with information of already loaded file
71 void reset() { myLoadedPreferences.Clear(); myIsLoadedPreferences = Standard_False; }
73 //! Reads plugin preferences and fill container
74 void readPluginItem(const QDomElement thePluginElement, TInspectorAPI_PreferencesDataMap& theItem);
76 //! Returns text of attribute document
77 static Standard_CString documentKey() { return "document"; }
79 //! Returns text of attribute plugin
80 static Standard_CString pluginKey() { return "plugin"; }
82 //! Returns text of attribute parameter
83 static Standard_CString parameterKey() { return "parameter"; }
85 //! Returns text of attribute name
86 static Standard_CString nameKey() { return "name"; }
88 //! Returns text of attribute value
89 static Standard_CString valueKey() { return "value"; }
92 //! directory of preferences file
93 TCollection_AsciiString myDirectory;
94 //! container of already loaded preferences : cache
95 NCollection_DataMap<TCollection_AsciiString, TInspectorAPI_PreferencesDataMap> myLoadedPreferences;
96 //! state whether the preferences of the current directory is loaded
97 Standard_Boolean myIsLoadedPreferences;