Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Add ApiDocs for KisWidgetConnectionUtils.h

Dmitry Kazakovbd2a2b2bb63d
diff --git a/libs/widgets/KisWidgetConnectionUtils.h b/libs/widgets/KisWidgetConnectionUtils.h
index dc08fdb6f8..eaaabd30df 100644
--- a/libs/widgets/KisWidgetConnectionUtils.h
+++ b/libs/widgets/KisWidgetConnectionUtils.h
@@ -28,14 +28,37 @@ class QLineEdit;
class KisMultipliersDoubleSliderSpinBox;
class KisFileNameRequester;
+/**
+ * A collection of utility functions and classes that
+ * allow connecting normal QWidget-based UI-controls to
+ * lager-based structures.
+ */
namespace KisWidgetConnectionUtils {
+
+/**
+ * (*)State classes represent the entire "state" of the corresponding widget
+ *
+ * E.g. `CheckBoxState` represents if the checkbox is enabled and checked
+ * at the same time. We need to provide these values as a single struct
+ * to avoid cyclic update, caused by partial updates of the widgets.
+ *
+ * Cyclic updates may happen when the GUI-control's value should be reset
+ * into some predefined value, when the control gets disabled, but we don't
+ * want to write this "fallback value" back into the model (because it doesn't
+ * make sense with the control disabled).
+ */
template<typename T>
struct ControlState {
T value = T{};
bool enabled = true;
};
+/**
+ * ToControlState is a functor that automatically converts a pair of values
+ * into a ControlState<T>. Supposed to be used in
+ * lager::with(...).map(ToControlState{})
+ */
struct ToControlState {
template<typename T>
ControlState<std::decay_t<T>> operator()(T &&value, bool enabled) {
@@ -89,6 +112,28 @@ struct ToSpinBoxState {
using IntSpinBoxState = SpinBoxState<int>;
using DoubleSpinBoxState = SpinBoxState<qreal>;
+/**
+ * A set of functions connecting a QWidget-based control to a lager-based model.
+ *
+ * connectControl - connects only the **value** of the control to the model
+ *
+ * \param widget a widget that we connect to the model
+ * \param source the model we are connecting to
+ * \param property the qt-property of the model that will be connected to the widget;
+ * the type of the property should coincide with the value type of the widget,
+ * e.g. `bool` for `QCheckBox`
+ *
+ * connectControlState - connects the entire **state** of the control to the model
+ *
+ * \param widget a widget that we connect to the model
+ * \param source the model we are connecting to
+ * \param readStateProperty the qt-property of the model that provides the state of the control
+ * (via lager::reader); the type of the property should be a "state",
+ * e.g. `CheckBoxState`.
+ * \param writeProperty the qt-property of the model where the user-selected value will be written
+ * to (should be either lager::cursor or lager::wirter); the type of the property
+ * should coincide with the value type of the widget, e.g. `bool` for `QCheckBox`
+ */
void KRITAWIDGETS_EXPORT connectControl(QAbstractButton *button, QObject *source, const char *property);
void KRITAWIDGETS_EXPORT connectControl(QAction *button, QObject *source, const char *property);
void KRITAWIDGETS_EXPORT connectControl(QCheckBox *button, QObject *source, const char *property);