Albert
Loading...
Searching...
No Matches
plugin.h File Reference
#include "albert/config.h"
#include "albert/extension.h"
#include "albert/extension/pluginprovider/plugininstance.h"
#include <QObject>
#include <QStringLiteral>

Go to the source code of this file.

Classes

class  albert::plugin::Plugin
 Base class for native plugins. More...
 
class  albert::plugin::ExtensionPlugin
 Convenience base class for extension plugins. More...
 

Namespaces

namespace  albert
 
namespace  albert::plugin
 

Macros

#define EXPAND_STRINGIZE(s)   STRINGIZE(s)
 
#define STRINGIZE(s)   #s
 
#define ALBERT_PLUGIN_PROPERTY_NONTRIVIAL(type, name, defaultValue)
 Convenience macro for (incomplete) user property definition. More...
 
#define ALBERT_PLUGIN_PROPERTY(type, name, defaultValue)
 Convenience macro for trivial user property definition. More...
 
#define ALBERT_PLUGIN_PROPERTY_CONNECT(object, name, widget, widget_setter, widget_signal)
 Convenience macro to connect UI elemetens to albert user properties. More...
 
#define ALBERT_PLUGIN   Q_PLUGIN_METADATA(IID ALBERT_PLUGIN_IID FILE "metadata.json")
 Declare an class as Albert plugin. More...
 

Macro Definition Documentation

◆ ALBERT_PLUGIN

#define ALBERT_PLUGIN   Q_PLUGIN_METADATA(IID ALBERT_PLUGIN_IID FILE "metadata.json")

Declare an class as Albert plugin.

Sets the interface identifier to #ALBERT_PLUGIN_IID and uses the metadata file named 'metadata.json' located at CMAKE_CURRENT_SOURCE_DIR.

Note
This macro has to be put into the plugin class body. The class this macro appears on must be default-constructible, inherit QObject and contain the Q_OBJECT macro. There should be exactly one occurrence of this macro in the source code for a plugin.

◆ ALBERT_PLUGIN_PROPERTY

#define ALBERT_PLUGIN_PROPERTY (   type,
  name,
  defaultValue 
)
Value:
public: static const type name##_default{defaultValue}; \
protected: void store_##name() { settings()->setValue(EXPAND_STRINGIZE(name), name()); } \
protected: void restore_##name() { name##_ = settings()->value(EXPAND_STRINGIZE(name), name##_default).value<type>(); } \
public: void reset_##name() { name##_ = name##_default; settings()->remove(EXPAND_STRINGIZE(name)); } \
Q_SIGNAL void name##Changed(); \
Q_PROPERTY(type name READ name WRITE set_##name RESET reset_##name NOTIFY name##Changed USER true) \
private: type name##_{defaultValue}; \
public: type name() const { return name##_; } \
public: void set_##name(type val) { if (val != name()){ name##_=val; store_##name(); emit name##Changed(); } } \
ALBERT_EXPORT std::unique_ptr< QSettings > settings()
Persistent app settings. @reentrant.
#define EXPAND_STRINGIZE(s)
Definition: plugin.h:10

Convenience macro for trivial user property definition.

Writes the boilerplate code for user properties of extensions.

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

◆ ALBERT_PLUGIN_PROPERTY_CONNECT

#define ALBERT_PLUGIN_PROPERTY_CONNECT (   object,
  name,
  widget,
  widget_setter,
  widget_signal 
)
Value:
widget->widget_setter(object->name()); \
connect(widget, &std::remove_pointer<decltype(widget)>::type::widget_signal, \
object, &std::remove_pointer<decltype(object)>::type::set_##name); \
connect(object, &std::remove_pointer<decltype(object)>::type::name##Changed, \
widget, [o=object,w=widget](){ w->widget_setter(o->name()); });

Convenience macro to connect UI elemetens to albert user properties.

Parameters
objectThe object containing the property
nameThe property name
widgetThe widget to connect to
widget_setterThe setter function of the widget
widget_signalThe changed signal of the widget

◆ ALBERT_PLUGIN_PROPERTY_NONTRIVIAL

#define ALBERT_PLUGIN_PROPERTY_NONTRIVIAL (   type,
  name,
  defaultValue 
)
Value:
public: static const type name##_default{defaultValue}; \
protected: void store_##name() { settings()->setValue(EXPAND_STRINGIZE(name), name()); } \
protected: void restore_##name() { set_##name##_(settings()->value(EXPAND_STRINGIZE(name), name##_default).value<type>()); } \
public: void reset_##name() { set_##name##_(name##_default); settings()->remove(EXPAND_STRINGIZE(name)); } \
Q_SIGNAL void name##Changed(); \
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(); } } \
private: void set_##name##_(type); \
public: type name() const; \

Convenience macro for (incomplete) user property definition.

Writes the boilerplate code for user properties of extensions. The property this macro produces is incomplete. It still requires you to define

  • the public getter 'type name() const'
  • the private setter 'void set_name_(type)'
Parameters
typeThe type of the property
nameThe name of the property
defaultValueThe default value of the property

◆ EXPAND_STRINGIZE

#define EXPAND_STRINGIZE (   s)    STRINGIZE(s)

◆ STRINGIZE

#define STRINGIZE (   s)    #s