Albert
Loading...
Searching...
No Matches
property.h File Reference
#include <QSettings>
Include dependency graph for property.h:

Go to the source code of this file.

Macros

#define EXPAND_STRINGIZE(s)   STRINGIZE(s)
 
#define STRINGIZE(s)   #s
 
#define ALBERT_PROPERTY_BASE(type, name, defaultValue, settings)
 Convenience macro for (incomplete) user property definition.
 
#define ALBERT_PLUGIN_PROPERTY_BASE(type, name, defaultValue)    ALBERT_PROPERTY_BASE(type, name, defaultValue, PluginInstance::settings)
 Convenience macro for (incomplete) plugin user property definition.
 
#define ALBERT_PROPERTY_GETSET(type, name, defaultValue, settings)
 Convenience macro for (incomplete) user property definition.
 
#define ALBERT_PLUGIN_PROPERTY_GETSET(type, name, defaultValue)    ALBERT_PROPERTY_GETSET(type, name, defaultValue, PluginInstance::settings)
 Convenience macro for (incomplete) plugin user property definition.
 
#define ALBERT_PROPERTY_MEMBER(type, name, member, defaultValue, settings)
 Convenience macro for user property definition using a given member.
 
#define ALBERT_PLUGIN_PROPERTY_MEMBER(type, name, member, defaultValue)    ALBERT_PROPERTY_MEMBER(type, name, member, defaultValue, PluginInstance::settings)
 Convenience macro for plugin user property definition using a given member.
 
#define ALBERT_PROPERTY(type, name, defaultValue, settings)
 Convenience macro for user property definition defining a member.
 
#define ALBERT_PLUGIN_PROPERTY(type, name, defaultValue)    ALBERT_PROPERTY(type, name, defaultValue, PluginInstance::settings)
 Convenience macro for plugin user property definition defining a member.
 
#define ALBERT_PROPERTY_CONNECT_CHECKBOX(object, name, checkbox)
 Convenience macro to connect checkboxes to boolean user properties.
 
#define ALBERT_PROPERTY_CONNECT_SPINBOX(object, name, spinbox)
 Convenience macro to connect spinboxes to int user properties.
 

Macro Definition Documentation

◆ ALBERT_PLUGIN_PROPERTY

#define ALBERT_PLUGIN_PROPERTY (   type,
  name,
  defaultValue 
)     ALBERT_PROPERTY(type, name, defaultValue, PluginInstance::settings)

Convenience macro for plugin user property definition defining a member.

Calls ALBERT_PROPERTY with PluginInstance::settings.

◆ ALBERT_PLUGIN_PROPERTY_BASE

#define ALBERT_PLUGIN_PROPERTY_BASE (   type,
  name,
  defaultValue 
)     ALBERT_PROPERTY_BASE(type, name, defaultValue, PluginInstance::settings)

Convenience macro for (incomplete) plugin user property definition.

Calls ALBERT_PROPERTY_BASE with PluginInstance::settings.

◆ ALBERT_PLUGIN_PROPERTY_GETSET

#define ALBERT_PLUGIN_PROPERTY_GETSET (   type,
  name,
  defaultValue 
)     ALBERT_PROPERTY_GETSET(type, name, defaultValue, PluginInstance::settings)

Convenience macro for (incomplete) plugin user property definition.

Calls ALBERT_PROPERTY_BASE with PluginInstance::settings.

◆ ALBERT_PLUGIN_PROPERTY_MEMBER

#define ALBERT_PLUGIN_PROPERTY_MEMBER (   type,
  name,
  member,
  defaultValue 
)     ALBERT_PROPERTY_MEMBER(type, name, member, defaultValue, PluginInstance::settings)

Convenience macro for plugin user property definition using a given member.

Calls ALBERT_PROPERTY_MEMBER with PluginInstance::settings.

◆ ALBERT_PROPERTY

#define ALBERT_PROPERTY (   type,
  name,
  defaultValue,
  settings 
)
Value:
ALBERT_PROPERTY_MEMBER(type, name, name##_, defaultValue, settings) \
protected: type name##_{name##_default()};
#define ALBERT_PROPERTY_MEMBER(type, name, member, defaultValue, settings)
Convenience macro for user property definition using a given member.
Definition property.h:107

Convenience macro for user property definition defining a member.

Extends ALBERT_PLUGIN_PROPERTY_MEMBER by (psuedo code):

<type> <name>_;

Parameters
typeThe type of the property
nameThe name of the property
defaultValueThe default value of the property

◆ ALBERT_PROPERTY_BASE

#define ALBERT_PROPERTY_BASE (   type,
  name,
  defaultValue,
  settings 
)
Value:
public: static type name##_default(){ return defaultValue; }; \
protected: void store_##name() { settings()->setValue(EXPAND_STRINGIZE(name), name()); } \
protected: void restore_##name(const auto &s = nullptr) { \
if (s) set_##name##_(s->value(EXPAND_STRINGIZE(name), name##_default()).template value<type>()); \
else set_##name##_(settings()->value(EXPAND_STRINGIZE(name), name##_default()).template value<type>()); \
} \
public: void reset_##name() { set_##name##_(name##_default()); settings()->remove(EXPAND_STRINGIZE(name)); } \
Q_SIGNAL void name##_changed(type); \
Q_PROPERTY(type name READ name WRITE set_##name RESET reset_##name NOTIFY name##_changed USER true) \
public: void set_##name(type val) { if (val != name()){ set_##name##_(val); store_##name(); emit name##_changed(val); } }
std::unique_ptr< QSettings > settings()
Persistent app settings storage.
#define EXPAND_STRINGIZE(s)
Definition property.h:6

Convenience macro for (incomplete) user property definition.

The property this macro produces is incomplete. It still requires you to provide definitions for:

  • the public getter '<type> <name>() const'
  • the private setter 'void set_<name>_(<type>)'

Expands to (psuedo code):

  • QPROPERTY(…)
  • <type> <name>default() {…}
  • void reset<name>() {…}
  • void store_<name>() {…}
  • void restore_<name>() {…}
  • void set_<name>(<type>) {…}
  • signal <name>changed();
  • <type> <name>() const; // Declaration only
  • void set<name>_(<type>); // Declaration only
Parameters
typeThe type of the property
nameThe name of the property
defaultValueThe default value of the property
settingsSomething that evaluates to a dereferencable QSettings object (*, ->). A pointer, factory, etc.

◆ ALBERT_PROPERTY_CONNECT_CHECKBOX

#define ALBERT_PROPERTY_CONNECT_CHECKBOX (   object,
  name,
  checkbox 
)
Value:
checkbox->setChecked(object->name()); \
connect(object, &std::remove_pointer<decltype(object)>::type::name##_changed, \
checkbox, &QCheckBox::setChecked); \
connect(checkbox, &QCheckBox::toggled, \
object, &std::remove_pointer<decltype(object)>::type::set_##name);

Convenience macro to connect checkboxes to boolean user properties.

Specialization of ALBERT_PLUGIN_PROPERTY_CONNECT

Parameters
objectThe object containing the property
nameThe property name
widgetThe widget pointer to connect to

◆ ALBERT_PROPERTY_CONNECT_SPINBOX

#define ALBERT_PROPERTY_CONNECT_SPINBOX (   object,
  name,
  spinbox 
)
Value:
spinbox->setValue(object->name()); \
connect(object, &std::remove_pointer<decltype(object)>::type::name##_changed, \
spinbox, &QSpinBox::setValue); \
connect(spinbox, &QSpinBox::valueChanged, \
object, &std::remove_pointer<decltype(object)>::type::set_##name);

Convenience macro to connect spinboxes to int user properties.

Specialization of ALBERT_PLUGIN_PROPERTY_CONNECT

Parameters
objectThe object containing the property
nameThe property name
widgetThe widget pointer to connect to

◆ ALBERT_PROPERTY_GETSET

#define ALBERT_PROPERTY_GETSET (   type,
  name,
  defaultValue,
  settings 
)
Value:
ALBERT_PROPERTY_BASE(type, name, defaultValue, settings) \
public: type name() const; \
private: void set_##name##_(type);
#define ALBERT_PROPERTY_BASE(type, name, defaultValue, settings)
Convenience macro for (incomplete) user property definition.
Definition property.h:36

Convenience macro for (incomplete) user property definition.

Extends ALBERT_PLUGIN_PROPERTY_BASE by (psuedo code):

  • <type> <name>() const; // Declaration only
  • void set_<name>_(<type>); // Declaration only

The property this macro produces is incomplete. It still requires you to provide definitions.

Parameters
typeThe type of the property
nameThe name of the property
defaultValueThe default value of the property
settingsSomething that evaluates to a dereferencable QSettings object (*, ->). A pointer, factory, etc.

◆ ALBERT_PROPERTY_MEMBER

#define ALBERT_PROPERTY_MEMBER (   type,
  name,
  member,
  defaultValue,
  settings 
)
Value:
ALBERT_PROPERTY_BASE(type, name, defaultValue, settings) \
public: type name() const { return member; } \
private: void set_##name##_(type val) { member=val; }

Convenience macro for user property definition using a given member.

Extends ALBERT_PLUGIN_PROPERTY_BASE by (psuedo code):

  • <type> <name>() const {…}
  • void set_<name>_(<type>) {…}
Parameters
typeThe type of the property
nameThe name of the property
memberThe member to expose as property
defaultValueThe default value of the property

◆ EXPAND_STRINGIZE

#define EXPAND_STRINGIZE (   s)    STRINGIZE(s)

◆ STRINGIZE

#define STRINGIZE (   s)    #s