KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
GuiSettings Class Reference

Persistent GUI settings storage for widget geometry, header states, and directories. More...

#include <guisettings.h>

+ Inheritance diagram for GuiSettings:
+ Collaboration diagram for GuiSettings:

Signals

void settingsChanged ()
 Emitted when any setting value changes.
 

Public Member Functions

 GuiSettings ()
 Construct a GuiSettings object backed by the default QSettings store.
 
void setLastWindowPosition (const QWidget *widget, const QPoint &pos)
 Persist the last position of a widget.
 
QPoint getLastWindowPosition (QWidget *widget, const QSize &defaultSize=QSize()) const
 Retrieve the last saved position of a widget.
 
void setLastWindowSize (const QWidget *widget, const QSize &size)
 Persist the last size of a widget.
 
QSize getLastWindowSize (const QWidget *widget, const QSize &defaultSize=QSize())
 Retrieve the last saved size of a widget.
 
bool widgetHasPersistentGeometry (const QWidget *widget) const
 Return whether any geometry has been saved for a widget.
 
void saveLastSplitterState (QSplitter *splitter)
 Save the current state of a QSplitter.
 
void restoreLastSplitterState (QSplitter *splitter)
 Restore a previously saved QSplitter state.
 
void saveLastHeaderState (QHeaderView *header)
 Save the current state of a QHeaderView.
 
void restoreLastHeaderState (QHeaderView *header)
 Restore a previously saved QHeaderView state.
 
void saveLastHeaderState (QHeaderView *header, AbstractItemModel *model)
 Save header state using the model's column definitions as keys.
 
void restoreLastHeaderState (QHeaderView *header, AbstractItemModel *model)
 Restore header state using the model's column definitions as keys.
 
void saveTreeViewState (TreeViewBase *treeView)
 Save the expansion/selection state of a TreeViewBase.
 
void restoreTreeViewState (TreeViewBase *treeView)
 Restore the expansion/selection state of a TreeViewBase.
 
void setStringValue (const QString &key, const QString &value)
 Persist an arbitrary string value.
 
QString getStringValue (const QString &key) const
 Retrieve an arbitrary string value.
 
void setVariantValue (const QString &key, const QVariant &value)
 Persist an arbitrary QVariant value.
 
QVariant getVariantValue (const QString &key) const
 Retrieve an arbitrary QVariant value.
 
void setByteArrayValue (const QString &key, const QByteArray &value)
 Persist an arbitrary byte array value.
 
QByteArray getByteArrayValue (const QString &key) const
 Retrieve an arbitrary byte array value.
 
int maxRecentFiles () const
 Return the maximum number of recent files to track.
 
void setMaxRecentFiles (int value)
 Set the maximum number of recent files to track.
 
QString lastDirectory (const QString &extension) const
 Return the last directory used for a given file extension.
 
QString lastDirectory (int fileType) const
 Return the last directory used for a given file-type integer.
 
virtual void saveLastDirectory (const QString &extension, const QString &value)
 Save the last directory used for a given file extension.
 
virtual void saveLastDirectory (int fileType, const QString &value)
 Save the last directory used for a given file-type integer.
 
void sync ()
 Synchronize settings file to disk and reload any changed values.
 
int fontSize () const
 Return the persisted font size.
 
void setFontSize (int value)
 Persist the font size.
 

Static Public Member Functions

static GuiSettingsglobalInstance ()
 Return the process-wide GuiSettings singleton.
 
static void setGlobalInstance (GuiSettings *value)
 Set the process-wide GuiSettings singleton.
 

Protected Member Functions

virtual void ensureValidDefaults ()
 Override to ensure sane default values on first run.
 

Static Protected Member Functions

static QString makeStandardKey (const QString &key)
 Build a settings key prefixed with the application key.
 
static QString makeKey (const QString &key, const QString &subKey)
 Build a compound settings key from two parts.
 
static QString makeObjectKey (const QObject *object)
 Build a settings key based on a QObject's identity.
 
static QString makeFileTypeKey (const QString &key, const QString &extension)
 Build a settings key based on a file extension.
 
static QString makeFileTypeKey (const QString &key, int fileType)
 Build a settings key based on a file-type integer.
 
static QString makeCompoundObjectKey (const QString &key, const QObject *object)
 Build a compound settings key from a base key and a QObject.
 

Protected Attributes

QSettings _settings
 Underlying QSettings storage.
 

Static Protected Attributes

static const QString KEY_APP
 Settings key for the application group.
 
static const QString KEY_FONT_SIZE
 Settings key for the saved font size.
 
static const QString KEY_HEADER_STATE_HORIZ
 Settings key for the horizontal header state.
 
static const QString KEY_HEADER_STATE_VERT
 Settings key for the vertical header state.
 
static const QString KEY_LAST_DIRECTORY
 Settings key for the last-used directory.
 
static const QString KEY_LAST_WIDGET_POS
 Settings key for the last widget position.
 
static const QString KEY_LAST_WIDGET_SIZE
 Settings key for the last widget size.
 
static const QString KEY_MODEL_HEADER_STATE_HORIZ
 Settings key for the horizontal model header state.
 
static const QString KEY_MODEL_HEADER_STATE_VERT
 Settings key for the vertical model header state.
 
static const QString KEY_SPLITTER_STATE_HORIZ
 Settings key for the horizontal splitter state.
 
static const QString KEY_SPLITTER_STATE_VERT
 Settings key for the vertical splitter state.
 
static const QString KEY_TREEVIEW_STATE
 Settings key for the tree view expansion state.
 

Detailed Description

Persistent GUI settings storage for widget geometry, header states, and directories.

GuiSettings wraps QSettings to provide typed, named accessors for common GUI state such as window positions, sizes, splitter states, header view states, and last-used directories. Subclass to add application-specific settings.

A process-wide singleton can be registered with setGlobalInstance() and retrieved with globalInstance().

Definition at line 33 of file guisettings.h.

Member Function Documentation

◆ fontSize()

int GuiSettings::fontSize ( ) const
inline

Return the persisted font size.

Returns
Font point size, or 0 if not set

Definition at line 220 of file guisettings.h.

◆ getByteArrayValue()

QByteArray GuiSettings::getByteArrayValue ( const QString &  key) const
inline

Retrieve an arbitrary byte array value.

Parameters
keySettings key
Returns
Saved byte array, or empty array if not found

Definition at line 169 of file guisettings.h.

◆ getLastWindowPosition()

QPoint GuiSettings::getLastWindowPosition ( QWidget *  widget,
const QSize &  defaultSize = QSize() 
) const

Retrieve the last saved position of a widget.

Parameters
widgetWidget to look up
defaultSizeDefault size used to compute a centred position if no position is saved
Returns
Saved position, or a sensible default

◆ getLastWindowSize()

QSize GuiSettings::getLastWindowSize ( const QWidget *  widget,
const QSize &  defaultSize = QSize() 
)

Retrieve the last saved size of a widget.

Parameters
widgetWidget to look up
defaultSizeSize to return if nothing is saved
Returns
Saved size, or defaultSize

◆ getStringValue()

QString GuiSettings::getStringValue ( const QString &  key) const
inline

Retrieve an arbitrary string value.

Parameters
keySettings key
Returns
Saved string, or empty string if not found

Definition at line 141 of file guisettings.h.

◆ getVariantValue()

QVariant GuiSettings::getVariantValue ( const QString &  key) const
inline

Retrieve an arbitrary QVariant value.

Parameters
keySettings key
Returns
Saved variant, or invalid QVariant if not found

Definition at line 155 of file guisettings.h.

◆ globalInstance()

static GuiSettings * GuiSettings::globalInstance ( )
static

Return the process-wide GuiSettings singleton.

Returns
Global GuiSettings instance, or nullptr if not set

◆ lastDirectory() [1/2]

QString GuiSettings::lastDirectory ( const QString &  extension) const
inline

Return the last directory used for a given file extension.

Parameters
extensionFile extension (without leading dot)
Returns
Last directory path string

Definition at line 188 of file guisettings.h.

◆ lastDirectory() [2/2]

QString GuiSettings::lastDirectory ( int  fileType) const
inline

Return the last directory used for a given file-type integer.

Parameters
fileTypeApplication-defined file type integer
Returns
Last directory path string

Definition at line 195 of file guisettings.h.

◆ makeKey()

static QString GuiSettings::makeKey ( const QString &  key,
const QString &  subKey 
)
inlinestaticprotected

Build a compound settings key from two parts.

Definition at line 248 of file guisettings.h.

◆ makeStandardKey()

static QString GuiSettings::makeStandardKey ( const QString &  key)
inlinestaticprotected

Build a settings key prefixed with the application key.

Definition at line 246 of file guisettings.h.

◆ maxRecentFiles()

int GuiSettings::maxRecentFiles ( ) const
inline

Return the maximum number of recent files to track.

Returns
Maximum recent file count

Definition at line 175 of file guisettings.h.

◆ restoreLastHeaderState() [1/2]

void GuiSettings::restoreLastHeaderState ( QHeaderView *  header)

Restore a previously saved QHeaderView state.

Parameters
headerHeader view to restore

◆ restoreLastHeaderState() [2/2]

void GuiSettings::restoreLastHeaderState ( QHeaderView *  header,
AbstractItemModel model 
)

Restore header state using the model's column definitions as keys.

Parameters
headerHeader view to restore
modelModel providing column metadata for keying

◆ restoreLastSplitterState()

void GuiSettings::restoreLastSplitterState ( QSplitter *  splitter)

Restore a previously saved QSplitter state.

Parameters
splitterSplitter to restore

◆ restoreTreeViewState()

void GuiSettings::restoreTreeViewState ( TreeViewBase treeView)

Restore the expansion/selection state of a TreeViewBase.

Parameters
treeViewTree view to restore

◆ saveLastDirectory() [1/2]

virtual void GuiSettings::saveLastDirectory ( const QString &  extension,
const QString &  value 
)
inlinevirtual

Save the last directory used for a given file extension.

Parameters
extensionFile extension (without leading dot)
valueDirectory path to save

Definition at line 202 of file guisettings.h.

◆ saveLastDirectory() [2/2]

virtual void GuiSettings::saveLastDirectory ( int  fileType,
const QString &  value 
)
inlinevirtual

Save the last directory used for a given file-type integer.

Parameters
fileTypeApplication-defined file type integer
valueDirectory path to save

Definition at line 209 of file guisettings.h.

◆ saveLastHeaderState() [1/2]

void GuiSettings::saveLastHeaderState ( QHeaderView *  header)

Save the current state of a QHeaderView.

Parameters
headerHeader view whose state to save

◆ saveLastHeaderState() [2/2]

void GuiSettings::saveLastHeaderState ( QHeaderView *  header,
AbstractItemModel model 
)

Save header state using the model's column definitions as keys.

Parameters
headerHeader view whose state to save
modelModel providing column metadata for keying

◆ saveLastSplitterState()

void GuiSettings::saveLastSplitterState ( QSplitter *  splitter)

Save the current state of a QSplitter.

Parameters
splitterSplitter whose state to save

◆ saveTreeViewState()

void GuiSettings::saveTreeViewState ( TreeViewBase treeView)

Save the expansion/selection state of a TreeViewBase.

Parameters
treeViewTree view whose state to save

◆ setByteArrayValue()

void GuiSettings::setByteArrayValue ( const QString &  key,
const QByteArray &  value 
)
inline

Persist an arbitrary byte array value.

Parameters
keySettings key
valueByte array to save

Definition at line 162 of file guisettings.h.

◆ setFontSize()

void GuiSettings::setFontSize ( int  value)
inline

Persist the font size.

Parameters
valueFont point size

Definition at line 226 of file guisettings.h.

◆ setGlobalInstance()

static void GuiSettings::setGlobalInstance ( GuiSettings value)
inlinestatic

Set the process-wide GuiSettings singleton.

Parameters
valueInstance to register as global

Definition at line 238 of file guisettings.h.

◆ setLastWindowPosition()

void GuiSettings::setLastWindowPosition ( const QWidget *  widget,
const QPoint &  pos 
)
inline

Persist the last position of a widget.

Parameters
widgetWidget whose position to save (key is based on objectName)
posPosition to save

Definition at line 47 of file guisettings.h.

◆ setLastWindowSize()

void GuiSettings::setLastWindowSize ( const QWidget *  widget,
const QSize &  size 
)
inline

Persist the last size of a widget.

Parameters
widgetWidget whose size to save
sizeSize to save

Definition at line 62 of file guisettings.h.

◆ setMaxRecentFiles()

void GuiSettings::setMaxRecentFiles ( int  value)
inline

Set the maximum number of recent files to track.

Parameters
valueMaximum recent file count

Definition at line 181 of file guisettings.h.

◆ setStringValue()

void GuiSettings::setStringValue ( const QString &  key,
const QString &  value 
)
inline

Persist an arbitrary string value.

Parameters
keySettings key
valueString to save

Definition at line 134 of file guisettings.h.

◆ setVariantValue()

void GuiSettings::setVariantValue ( const QString &  key,
const QVariant &  value 
)
inline

Persist an arbitrary QVariant value.

Parameters
keySettings key
valueVariant to save

Definition at line 148 of file guisettings.h.

◆ widgetHasPersistentGeometry()

bool GuiSettings::widgetHasPersistentGeometry ( const QWidget *  widget) const

Return whether any geometry has been saved for a widget.

Parameters
widgetWidget to check
Returns
true if a saved position or size exists

Member Data Documentation

◆ _settings

QSettings GuiSettings::_settings
protected

Underlying QSettings storage.

Definition at line 262 of file guisettings.h.

◆ KEY_APP

const QString GuiSettings::KEY_APP
staticprotected

Settings key for the application group.

Definition at line 265 of file guisettings.h.

◆ KEY_FONT_SIZE

const QString GuiSettings::KEY_FONT_SIZE
staticprotected

Settings key for the saved font size.

Definition at line 267 of file guisettings.h.

◆ KEY_HEADER_STATE_HORIZ

const QString GuiSettings::KEY_HEADER_STATE_HORIZ
staticprotected

Settings key for the horizontal header state.

Definition at line 269 of file guisettings.h.

◆ KEY_HEADER_STATE_VERT

const QString GuiSettings::KEY_HEADER_STATE_VERT
staticprotected

Settings key for the vertical header state.

Definition at line 271 of file guisettings.h.

◆ KEY_LAST_DIRECTORY

const QString GuiSettings::KEY_LAST_DIRECTORY
staticprotected

Settings key for the last-used directory.

Definition at line 273 of file guisettings.h.

◆ KEY_LAST_WIDGET_POS

const QString GuiSettings::KEY_LAST_WIDGET_POS
staticprotected

Settings key for the last widget position.

Definition at line 275 of file guisettings.h.

◆ KEY_LAST_WIDGET_SIZE

const QString GuiSettings::KEY_LAST_WIDGET_SIZE
staticprotected

Settings key for the last widget size.

Definition at line 277 of file guisettings.h.

◆ KEY_MODEL_HEADER_STATE_HORIZ

const QString GuiSettings::KEY_MODEL_HEADER_STATE_HORIZ
staticprotected

Settings key for the horizontal model header state.

Definition at line 279 of file guisettings.h.

◆ KEY_MODEL_HEADER_STATE_VERT

const QString GuiSettings::KEY_MODEL_HEADER_STATE_VERT
staticprotected

Settings key for the vertical model header state.

Definition at line 281 of file guisettings.h.

◆ KEY_SPLITTER_STATE_HORIZ

const QString GuiSettings::KEY_SPLITTER_STATE_HORIZ
staticprotected

Settings key for the horizontal splitter state.

Definition at line 283 of file guisettings.h.

◆ KEY_SPLITTER_STATE_VERT

const QString GuiSettings::KEY_SPLITTER_STATE_VERT
staticprotected

Settings key for the vertical splitter state.

Definition at line 285 of file guisettings.h.

◆ KEY_TREEVIEW_STATE

const QString GuiSettings::KEY_TREEVIEW_STATE
staticprotected

Settings key for the tree view expansion state.

Definition at line 287 of file guisettings.h.


The documentation for this class was generated from the following file: