pSettings.sip 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*!
  2. \file pSettings.h
  3. \brief An extended QSettings class that handle ini files with different contexts.
  4. \author Filipe Azevedo aka Nox P\@sNox <pasnox@gmail.com>
  5. */
  6. /*!
  7. \ingroup Core
  8. \class pSettings
  9. \brief An extended QSettings class that handle ini files with different contexts.
  10. This class is used for storing/retreiving data using ini files with different contexts (Auto, Normal, Portable).
  11. */
  12. class pSettings : QSettings
  13. {
  14. %TypeHeaderCode
  15. #include <../src/core/pSettings.h>
  16. %End
  17. public:
  18. /*! Thie enumeration represent the possible choices for the location of your pSettings object. */
  19. enum Type {
  20. Invalid = -1, /*!< An invalid path. */
  21. Auto, /*!< The pSettings decide which enum to use. pSettings::Portable if the binary path is writable, else pSettings::Normal. */
  22. Normal, /*!< The init file will be created in the user home. */
  23. Portable /*!< The ini file will be created in the binary path. */
  24. };
  25. /*!
  26. \class pSettings::Properties
  27. \brief This class defined the properties to apply to a pSettings class.
  28. \author Filipe Azevedo aka Nox P\@sNox <pasnox@gmail.com>
  29. */
  30. struct Properties
  31. {
  32. /*!
  33. \brief A Properties object initialized with default properties
  34. \param other The properties to copy.
  35. */
  36. Properties( const pSettings::Properties& other = pSettings::defaultProperties() );
  37. /*!
  38. \brief A Properties object initialized with custom parameters.
  39. \param _name The name of the application.
  40. \param _version The application version.
  41. \param _type The pSettings::Type type.
  42. */
  43. Properties( const QString& _name, const QString& _version, pSettings::Type _type );
  44. /*!
  45. \brief Return the path where is located the ini file when using the pSettings::Normal type.
  46. \return A QString containing the absolute path of the ini file.
  47. */
  48. QString storageLocation() const;
  49. /*!
  50. \brief The absolute file path of the ini file.
  51. \return The absolute file path of the ini file.
  52. */
  53. QString settingsFilePath() const;
  54. /*!
  55. \brief Return an absolute file path of a ini file having application name \a name and application version \a version according to the current properties.
  56. \param name The application name.
  57. \param version The application version.
  58. \return The file path of the ini file.
  59. */
  60. QString settingsFilePath( const QString& name, const QString& version ) const;
  61. QString name;
  62. QString version;
  63. pSettings::Type type;
  64. };
  65. /*!
  66. \brief Create a pSettings object having parent \a parent and properties \a properties.
  67. \param parent The parent object.
  68. \param properties The properties to apply to this pSettings.
  69. */
  70. pSettings( QObject* parent = 0, const pSettings::Properties& properties = pSettings::defaultProperties() );
  71. /*!
  72. \brief Create a pSettings object having parent \a parent and properties \a properties with overrided \a name and \a version.
  73. \param parent The parent object.
  74. \param name The application name.
  75. \param version The application version.
  76. \param properties The properties to apply to this pSettings.
  77. */
  78. pSettings( QObject* parent, const QString& name, const QString& version, const pSettings::Properties& properties = pSettings::defaultProperties() );
  79. /*!
  80. \brief Return the properties applied to this pSettings.
  81. \return A Properties object.
  82. */
  83. pSettings::Properties properties() const;
  84. /*!
  85. \brief Restore the state of a QMainWindow.
  86. \param window The main window to restore state
  87. \sa QMainWindow::restoreState()
  88. \note This member is only defined if QT_GUI_LIB is defined.
  89. */
  90. virtual void restoreState( QMainWindow* window );
  91. /*!
  92. \brief Save the state of a QMainWindow.
  93. \param window The window to restore state.
  94. \sa QMainWindow::restoreState()
  95. \note This member is only defined if QT_GUI_LIB is defined.
  96. */
  97. virtual void saveState( QMainWindow* window );
  98. /*!
  99. \brief Set the default settings.
  100. You can reimplement this member to set default ini settings, by example after the first application run.
  101. */
  102. virtual void setDefaultSettings();
  103. /*!
  104. \brief Set the default properties to be used.
  105. Typically this should be defined in the main, just after the initialization of the QCoreApplication / QApplication.
  106. \param properties The properties to be used as default.
  107. */
  108. static void setDefaultProperties( const pSettings::Properties& properties );
  109. /*!
  110. \brief Return the default Properties used when creating pSettings.
  111. \return A Properties object.
  112. */
  113. static pSettings::Properties defaultProperties();
  114. protected:
  115. };