Krita Source Code Documentation
Loading...
Searching...
No Matches
KisWidgetConnectionUtils Namespace Reference

Classes

struct  ComboBoxState
 
class  ConnectButtonGroupHelper
 
class  ConnectCompositeOpListWidgetHelper
 
class  ConnectDoubleSpinBoxStateHelper
 
class  ConnectIntSpinBoxStateHelper
 
class  ConnectSpacingWidgetHelper
 
struct  ControlState
 
struct  FromSpacingState
 
struct  SpacingState
 
struct  SpinBoxState
 
struct  ToControlState
 
struct  ToSpacingState
 
struct  ToSpinBoxState
 

Typedefs

using ButtonGroupState = ControlState<int>
 
using CheckBoxState = ControlState<bool>
 
using DoubleSpinBoxState = SpinBoxState<qreal>
 
using IntSpinBoxState = SpinBoxState<int>
 

Functions

template<typename Button >
void connectButtonLikeControl (Button *button, QObject *source, const char *property)
 
void connectControl (KisAngleSelector *widget, QObject *source, const char *property)
 
void connectControl (KisColorButton *widget, QObject *source, const char *property)
 
void connectControl (KisCompositeOpListWidget *widget, QObject *source, const char *property)
 
void connectControl (KisCurveWidget *widget, QObject *source, const char *property)
 
void connectControl (KisFileNameRequester *widget, QObject *source, const char *property)
 
void connectControl (KisMultipliersDoubleSliderSpinBox *spinBox, QObject *source, const char *property)
 
void connectControl (KisSpacingSelectionWidget *widget, QObject *source, const char *property)
 
void connectControl (QAbstractButton *button, QObject *source, const char *property)
 
void connectControl (QAction *button, QObject *source, const char *property)
 
void connectControl (QButtonGroup *group, QObject *source, const char *property)
 
void connectControl (QCheckBox *button, QObject *source, const char *property)
 
void connectControl (QComboBox *button, QObject *source, const char *property)
 
void connectControl (QDoubleSpinBox *spinBox, QObject *source, const char *property)
 
void connectControl (QLineEdit *widget, QObject *source, const char *property)
 
void connectControl (QSlider *slider, QObject *source, const char *property)
 
void connectControl (QSpinBox *spinBox, QObject *source, const char *property)
 
void connectControlState (QAbstractButton *button, QObject *source, const char *readStatePropertyName, const char *writePropertyName)
 
void connectControlState (QButtonGroup *group, QObject *source, const char *readStateProperty, const char *writeProperty)
 
void connectControlState (QComboBox *button, QObject *source, const char *readStatePropertyName, const char *writePropertyName)
 
void connectControlState (QDoubleSpinBox *spinBox, QObject *source, const char *readStateProperty, const char *writeProperty)
 
void connectControlState (QSpinBox *spinBox, QObject *source, const char *readStateProperty, const char *writeProperty)
 
void connectWidgetEnabledToProperty (QWidget *widget, QObject *source, const char *property)
 
void connectWidgetVisibleToProperty (QWidget *widget, QObject *source, const char *property)
 

Detailed Description

A collection of utility functions and classes that allow connecting normal QWidget-based UI-controls to lager-based structures.

Typedef Documentation

◆ ButtonGroupState

◆ CheckBoxState

◆ DoubleSpinBoxState

◆ IntSpinBoxState

Function Documentation

◆ connectButtonLikeControl()

template<typename Button >
void KisWidgetConnectionUtils::connectButtonLikeControl ( Button * button,
QObject * source,
const char * property )

Definition at line 99 of file KisWidgetConnectionUtils.cpp.

100{
101 const QMetaObject* meta = source->metaObject();
102 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
104
105 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
106
107 QMetaMethod signal = prop.notifySignal();
108
109 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
110 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("bool"));
111
112 const QMetaObject* dstMeta = button->metaObject();
113
114 QMetaMethod updateSlot = dstMeta->method(
115 dstMeta->indexOfSlot("setChecked(bool)"));
116 QObject::connect(source, signal, button, updateSlot);
117
118 button->setChecked(prop.read(source).toBool());
119
120 if (prop.isWritable()) {
121 QObject::connect(button, &Button::toggled,
122 source, [prop, source] (bool value) { prop.write(source, value); });
123 }
124}
float value(const T *src, size_t ch)
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
#define SANITY_CHECK_PROPERTY_EXISTS(prop)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
QString button(const QWheelEvent &ev)

References button(), KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, source(), and value().

◆ connectControl() [1/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( KisAngleSelector * widget,
QObject * source,
const char * property )

Definition at line 624 of file KisWidgetConnectionUtils.cpp.

625{
626 const QMetaObject* meta = source->metaObject();
627 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
629
630 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
631
632 QMetaMethod signal = prop.notifySignal();
633
634 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
635 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("qreal"));
636
637 const QMetaObject* dstMeta = widget->metaObject();
638
639 QMetaMethod updateSlot = dstMeta->method(
640 dstMeta->indexOfSlot("setAngle(qreal)"));
641 QObject::connect(source, signal, widget, updateSlot);
642
643 widget->setAngle(prop.read(source).toReal());
644
645 if (prop.isWritable()) {
646 QObject::connect(widget, &KisAngleSelector::angleChanged,
647 source, [prop, source] (qreal value) { prop.write(source, value); });
648 }
649}
void setAngle(qreal newAngle)
Sets the current angle.
void angleChanged(qreal angle)

References KisAngleSelector::angleChanged(), KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, KisAngleSelector::setAngle(), source(), and value().

◆ connectControl() [2/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( KisColorButton * widget,
QObject * source,
const char * property )

Definition at line 706 of file KisWidgetConnectionUtils.cpp.

707{
708 const QMetaObject* meta = source->metaObject();
709 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
711
712 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
713
714 QMetaMethod signal = prop.notifySignal();
715
716 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
717 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("KoColor"));
718
719 const QMetaObject* dstMeta = widget->metaObject();
720
721 QMetaMethod updateSlot = dstMeta->method(
722 dstMeta->indexOfSlot("setColor(KoColor)"));
723 QObject::connect(source, signal, widget, updateSlot);
724
725 widget->setColor(prop.read(source).value<KoColor>());
726
727 if (prop.isWritable()) {
728 QObject::connect(widget, &KisColorButton::changed,
729 source, [prop, source] (const KoColor &value) {
730 prop.write(source, QVariant::fromValue(value)); });
731 }
732}
void setColor(const KoColor &c)
void changed(const KoColor &newColor)

References KisColorButton::changed(), KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, KisColorButton::setColor(), source(), and value().

◆ connectControl() [3/16]

void KRITAUI_EXPORT KisWidgetConnectionUtils::connectControl ( KisCompositeOpListWidget * widget,
QObject * source,
const char * property )

Definition at line 44 of file KisCompositeOpListConnectionHelper.cpp.

45{
46 const QMetaObject* meta = source->metaObject();
47 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
48
49 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
50
51 QMetaMethod signal = prop.notifySignal();
52
53 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
54 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("QString"));
55
57
58 const QMetaObject* dstMeta = helper->metaObject();
59
60 QMetaMethod updateSlot = dstMeta->method(
61 dstMeta->indexOfSlot("slotPropertyChanged(QString)"));
62 QObject::connect(source, signal, helper, updateSlot);
63
64 helper->slotPropertyChanged(prop.read(source).value<QString>());
65
66 if (prop.isWritable()) {
67 QObject::connect(helper, &ConnectCompositeOpListWidgetHelper::sigWidgetChanged, [prop, source] (const QString &value) { prop.write(source, QVariant::fromValue(value)); });
68 }
69}

References KIS_SAFE_ASSERT_RECOVER_RETURN, KisWidgetConnectionUtils::ConnectCompositeOpListWidgetHelper::sigWidgetChanged(), KisWidgetConnectionUtils::ConnectCompositeOpListWidgetHelper::slotPropertyChanged(), source(), and value().

◆ connectControl() [4/16]

void KRITAUI_EXPORT KisWidgetConnectionUtils::connectControl ( KisCurveWidget * widget,
QObject * source,
const char * property )

Definition at line 48 of file KisCurveWidgetConnectionHelper.cpp.

49{
50 const QMetaObject* meta = source->metaObject();
51 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
52
53 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
54
55 QMetaMethod signal = prop.notifySignal();
56
57 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
58 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("QString"));
59
60 ConnectCurveWidgetHelper *helper = new ConnectCurveWidgetHelper(widget);
61
62 const QMetaObject* dstMeta = helper->metaObject();
63
64 QMetaMethod updateSlot = dstMeta->method(
65 dstMeta->indexOfSlot("slotPropertyChanged(QString)"));
66 QObject::connect(source, signal, helper, updateSlot);
67
68 helper->slotPropertyChanged(prop.read(source).toString());
69
70 if (prop.isWritable()) {
71 QObject::connect(helper, &ConnectCurveWidgetHelper::sigWidgetChanged,
72 source, [prop, source] (const QString &value) { prop.write(source, value); });
73 }
74}

References KIS_SAFE_ASSERT_RECOVER_RETURN, source(), and value().

◆ connectControl() [5/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( KisFileNameRequester * widget,
QObject * source,
const char * property )

Definition at line 678 of file KisWidgetConnectionUtils.cpp.

679{
680 const QMetaObject* meta = source->metaObject();
681 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
683
684 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
685
686 QMetaMethod signal = prop.notifySignal();
687
688 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
689 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("QString"));
690
691 const QMetaObject* dstMeta = widget->metaObject();
692
693 QMetaMethod updateSlot = dstMeta->method(
694 dstMeta->indexOfSlot("setFileName(QString)"));
695 QObject::connect(source, signal, widget, updateSlot);
696
697 widget->setFileName(prop.read(source).toString());
698
699 if (prop.isWritable()) {
700 QObject::connect(widget, &KisFileNameRequester::textChanged,
701 source, [prop, source] (const QString &value) {
702 prop.write(source, value); });
703 }
704}
void textChanged(const QString &fileName)
void setFileName(const QString &path)

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, KisFileNameRequester::setFileName(), source(), KisFileNameRequester::textChanged(), and value().

◆ connectControl() [6/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( KisMultipliersDoubleSliderSpinBox * spinBox,
QObject * source,
const char * property )

Definition at line 333 of file KisWidgetConnectionUtils.cpp.

334{
335 const QMetaObject* meta = source->metaObject();
336 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
338
339 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
340
341 QMetaMethod signal = prop.notifySignal();
342
343 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
344 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("qreal"));
345
346 const QMetaObject* dstMeta = spinBox->metaObject();
347
348 QMetaMethod updateSlot = dstMeta->method(
349 dstMeta->indexOfSlot("setValue(qreal)"));
350 QObject::connect(source, signal, spinBox, updateSlot);
351
352 spinBox->setValue(prop.read(source).toReal());
353
354 if (prop.isWritable()) {
355 QObject::connect(spinBox, qOverload<qreal>(&KisMultipliersDoubleSliderSpinBox::valueChanged),
356 source, [prop, source] (qreal value) { prop.write(source, value); });
357 }
358}
void setValue(qreal value)
Set the value, don't use setValue()

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, KisMultipliersDoubleSliderSpinBox::setValue(), source(), value(), and KisMultipliersDoubleSliderSpinBox::valueChanged().

◆ connectControl() [7/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( KisSpacingSelectionWidget * widget,
QObject * source,
const char * property )

Definition at line 595 of file KisWidgetConnectionUtils.cpp.

596{
597 const QMetaObject* meta = source->metaObject();
598 QMetaProperty stateProp = meta->property(meta->indexOfProperty(property));
600
601 KIS_SAFE_ASSERT_RECOVER_RETURN(stateProp.hasNotifySignal());
602
603 QMetaMethod signal = stateProp.notifySignal();
604
605 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
606 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("SpacingState"));
607
609
610 const QMetaObject* dstMeta = helper->metaObject();
611
612 QMetaMethod updateSlot = dstMeta->method(
613 dstMeta->indexOfSlot("slotPropertyChanged(SpacingState)"));
614 QObject::connect(source, signal, helper, updateSlot);
615
616 helper->slotPropertyChanged(stateProp.read(source).value<SpacingState>());
617
618 if (stateProp.isWritable()) {
619 QObject::connect(helper, &ConnectSpacingWidgetHelper::sigWidgetChanged,
620 source, [stateProp, source] (SpacingState value) { stateProp.write(source, QVariant::fromValue(value)); });
621 }
622}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, KisWidgetConnectionUtils::ConnectSpacingWidgetHelper::sigWidgetChanged(), KisWidgetConnectionUtils::ConnectSpacingWidgetHelper::slotPropertyChanged(), source(), and value().

◆ connectControl() [8/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QAbstractButton * button,
QObject * source,
const char * property )

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

Parameters
widgeta widget that we connect to the model
sourcethe model we are connecting to
propertythe 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

Parameters
widgeta widget that we connect to the model
sourcethe model we are connecting to
readStatePropertythe 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.
writePropertythe qt-property of the model where the user-selected value will be written to (should be either lager::cursor or lager::writer); the type of the property should coincide with the value type of the widget, e.g. bool for QCheckBox

Definition at line 126 of file KisWidgetConnectionUtils.cpp.

127{
129}
void connectButtonLikeControl(Button *button, QObject *source, const char *property)

References button(), connectButtonLikeControl(), and source().

◆ connectControl() [9/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QAction * button,
QObject * source,
const char * property )

Definition at line 131 of file KisWidgetConnectionUtils.cpp.

132{
134}

References button(), connectButtonLikeControl(), and source().

◆ connectControl() [10/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QButtonGroup * group,
QObject * source,
const char * property )

Definition at line 404 of file KisWidgetConnectionUtils.cpp.

405{
406 const QMetaObject* meta = source->metaObject();
407 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
409
410 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
411
412 QMetaMethod signal = prop.notifySignal();
413
414 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
415 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("int"));
416
417
419
420 const QMetaObject* dstMeta = helper->metaObject();
421
422 QMetaMethod updateSlot = dstMeta->method(
423 dstMeta->indexOfSlot("updateState(int)"));
424 QObject::connect(source, signal, helper, updateSlot);
425
426 helper->updateState(prop.read(source).toInt());
427
428 if (prop.isWritable()) {
429 QObject::connect(helper, &ConnectButtonGroupHelper::idClicked,
430 source, [prop, source] (int value) { prop.write(source, value); });
431 }
432}

References KisWidgetConnectionUtils::ConnectButtonGroupHelper::idClicked(), KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, source(), KisWidgetConnectionUtils::ConnectButtonGroupHelper::updateState(), and value().

◆ connectControl() [11/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QCheckBox * button,
QObject * source,
const char * property )

Definition at line 136 of file KisWidgetConnectionUtils.cpp.

137{
139}

References button(), connectButtonLikeControl(), and source().

◆ connectControl() [12/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QComboBox * button,
QObject * source,
const char * property )

Definition at line 537 of file KisWidgetConnectionUtils.cpp.

538{
539 const QMetaObject* meta = source->metaObject();
540 QMetaProperty stateProp = meta->property(meta->indexOfProperty(property));
542
543 KIS_SAFE_ASSERT_RECOVER_RETURN(stateProp.hasNotifySignal());
544
545 QMetaMethod signal = stateProp.notifySignal();
546
547 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
548 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("int"));
549
550 const QMetaObject* dstMeta = button->metaObject();
551
552 QMetaMethod updateSlot = dstMeta->method(
553 dstMeta->indexOfSlot("setCurrentIndex(int)"));
554 QObject::connect(source, signal, button, updateSlot);
555
556 button->setCurrentIndex(stateProp.read(source).value<int>());
557
558 if (stateProp.isWritable()) {
559 // see a comment in connectControlState(QComboBox *button, ...)
561 QObject::connect(button, qOverload<int>(&QComboBox::currentIndexChanged),
562 source, [stateProp, source] (int value) { stateProp.write(source, value); });
563 }
564}
#define SANITY_CHECK_PROPERTY_METATYPE_REGISTERED(prop)

References button(), KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, SANITY_CHECK_PROPERTY_METATYPE_REGISTERED, source(), and value().

◆ connectControl() [13/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QDoubleSpinBox * spinBox,
QObject * source,
const char * property )

Definition at line 195 of file KisWidgetConnectionUtils.cpp.

196{
197 const QMetaObject* meta = source->metaObject();
198 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
200
201 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
202
203 QMetaMethod signal = prop.notifySignal();
204
205 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
206 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("qreal"));
207
208 const QMetaObject* dstMeta = spinBox->metaObject();
209
210 QMetaMethod updateSlot = dstMeta->method(
211 dstMeta->indexOfSlot("setValue(qreal)"));
212 QObject::connect(source, signal, spinBox, updateSlot);
213
214 spinBox->setValue(prop.read(source).toReal());
215
216 if (prop.isWritable()) {
217 QObject::connect(spinBox, qOverload<qreal>(&QDoubleSpinBox::valueChanged),
218 source, [prop, source] (qreal value) { prop.write(source, value); });
219 }
220}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, source(), and value().

◆ connectControl() [14/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QLineEdit * widget,
QObject * source,
const char * property )

Definition at line 651 of file KisWidgetConnectionUtils.cpp.

652{
653 const QMetaObject* meta = source->metaObject();
654 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
656
657 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
658
659 QMetaMethod signal = prop.notifySignal();
660
661 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
662 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("QString"));
663
664 const QMetaObject* dstMeta = widget->metaObject();
665
666 QMetaMethod updateSlot = dstMeta->method(
667 dstMeta->indexOfSlot("setText(QString)"));
668 QObject::connect(source, signal, widget, updateSlot);
669
670 widget->setText(prop.read(source).toString());
671
672 if (prop.isWritable()) {
673 QObject::connect(widget, &QLineEdit::textChanged,
674 source, [prop, source] (const QString &value) { prop.write(source, value); });
675 }
676}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, source(), and value().

◆ connectControl() [15/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QSlider * slider,
QObject * source,
const char * property )

Definition at line 168 of file KisWidgetConnectionUtils.cpp.

169{
170 const QMetaObject* meta = source->metaObject();
171 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
173
174 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
175
176 QMetaMethod signal = prop.notifySignal();
177
178 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
179 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("int"));
180
181 const QMetaObject* dstMeta = slider->metaObject();
182
183 QMetaMethod updateSlot = dstMeta->method(
184 dstMeta->indexOfSlot("setValue(int)"));
185 QObject::connect(source, signal, slider, updateSlot);
186
187 slider->setValue(prop.read(source).toInt());
188
189 if (prop.isWritable()) {
190 QObject::connect(slider, qOverload<int>(&QSlider::valueChanged),
191 source, [prop, source] (int value) { prop.write(source, value); });
192 }
193}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, source(), and value().

◆ connectControl() [16/16]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControl ( QSpinBox * spinBox,
QObject * source,
const char * property )

Definition at line 141 of file KisWidgetConnectionUtils.cpp.

142{
143 const QMetaObject* meta = source->metaObject();
144 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
146
147 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
148
149 QMetaMethod signal = prop.notifySignal();
150
151 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
152 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("int"));
153
154 const QMetaObject* dstMeta = spinBox->metaObject();
155
156 QMetaMethod updateSlot = dstMeta->method(
157 dstMeta->indexOfSlot("setValue(int)"));
158 QObject::connect(source, signal, spinBox, updateSlot);
159
160 spinBox->setValue(prop.read(source).toInt());
161
162 if (prop.isWritable()) {
163 QObject::connect(spinBox, qOverload<int>(&QSpinBox::valueChanged),
164 source, [prop, source] (int value) { prop.write(source, value); });
165 }
166}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, source(), and value().

◆ connectControlState() [1/5]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControlState ( QAbstractButton * button,
QObject * source,
const char * readStatePropertyName,
const char * writePropertyName )

Definition at line 466 of file KisWidgetConnectionUtils.cpp.

467{
468 const QMetaObject* meta = source->metaObject();
469 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStatePropertyName));
470 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
471
472 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
473
474 QMetaMethod signal = readStateProp.notifySignal();
475
476 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
477 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("CheckBoxState"));
478
480
481 const QMetaObject* dstMeta = helper->metaObject();
482
483 QMetaMethod updateSlot = dstMeta->method(
484 dstMeta->indexOfSlot("updateState(CheckBoxState)"));
485 QObject::connect(source, signal, helper, updateSlot);
486
487 helper->updateState(readStateProp.read(source).value<CheckBoxState>());
488
489 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writePropertyName));
491 if (writeProp.isWritable()) {
492 button->connect(button, &QAbstractButton::toggled,
493 source, [writeProp, source] (bool value) { writeProp.write(source, value); });
494 }
495}
#define SANITY_CHECK_PROPERTY_EXISTS_AND_WRITABLE(prop)
void updateState(const CheckBoxState &state)

References button(), KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, SANITY_CHECK_PROPERTY_EXISTS_AND_WRITABLE, source(), ConnectButtonStateHelper::updateState(), and value().

◆ connectControlState() [2/5]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControlState ( QButtonGroup * group,
QObject * source,
const char * readStateProperty,
const char * writeProperty )

Definition at line 434 of file KisWidgetConnectionUtils.cpp.

435{
436 const QMetaObject* meta = source->metaObject();
437 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStateProperty));
438 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
439
440 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
441
442 QMetaMethod signal = readStateProp.notifySignal();
443
444 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
445 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("ButtonGroupState"));
446
448
449 const QMetaObject* dstMeta = helper->metaObject();
450
451 QMetaMethod updateSlot = dstMeta->method(
452 dstMeta->indexOfSlot("updateState(ButtonGroupState)"));
453 QObject::connect(source, signal, helper, updateSlot);
454
455 helper->updateState(readStateProp.read(source).value<ButtonGroupState>());
456
457 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writeProperty));
459
460 if (writeProp.isWritable()) {
461 QObject::connect(helper, &ConnectButtonGroupHelper::idClicked,
462 source, [writeProp, source] (int value) { writeProp.write(source, value); });
463 }
464}

References KisWidgetConnectionUtils::ConnectButtonGroupHelper::idClicked(), KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, SANITY_CHECK_PROPERTY_EXISTS_AND_WRITABLE, source(), KisWidgetConnectionUtils::ConnectButtonGroupHelper::updateState(), and value().

◆ connectControlState() [3/5]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControlState ( QComboBox * button,
QObject * source,
const char * readStatePropertyName,
const char * writePropertyName )

On Qt5 to perform conversion from int to enum, the enum should be registered as a metatype, so we should manually verify that. For some reason, on Qt6 it is not necessary.

Definition at line 498 of file KisWidgetConnectionUtils.cpp.

499{
500 const QMetaObject* meta = source->metaObject();
501 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStatePropertyName));
502 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
503
504 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
505
506 QMetaMethod signal = readStateProp.notifySignal();
507
508 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
509 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("ComboBoxState"));
510
512
513 const QMetaObject* dstMeta = helper->metaObject();
514
515 QMetaMethod updateSlot = dstMeta->method(
516 dstMeta->indexOfSlot("updateState(ComboBoxState)"));
517 QObject::connect(source, signal, helper, updateSlot);
518
519 helper->updateState(readStateProp.read(source).value<ComboBoxState>());
520
521 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writePropertyName));
523
530
531 if (writeProp.isWritable()) {
532 QObject::connect(button, qOverload<int>(&QComboBox::currentIndexChanged),
533 source, [writeProp, source] (int value) { writeProp.write(source, value); });
534 }
535}
void updateState(const ComboBoxState &state)

References button(), KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, SANITY_CHECK_PROPERTY_EXISTS_AND_WRITABLE, SANITY_CHECK_PROPERTY_METATYPE_REGISTERED, source(), ConnectComboBoxStateHelper::updateState(), and value().

◆ connectControlState() [4/5]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControlState ( QDoubleSpinBox * spinBox,
QObject * source,
const char * readStateProperty,
const char * writeProperty )

Definition at line 301 of file KisWidgetConnectionUtils.cpp.

302{
303 const QMetaObject* meta = source->metaObject();
304 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStateProperty));
305 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
306
307 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
308
309 QMetaMethod signal = readStateProp.notifySignal();
310
311 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
312 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("DoubleSpinBoxState"));
313
315
316 const QMetaObject* dstMeta = helper->metaObject();
317
318 QMetaMethod updateSlot = dstMeta->method(
319 dstMeta->indexOfSlot("setState(DoubleSpinBoxState)"));
320 QObject::connect(source, signal, helper, updateSlot);
321
322 helper->setState(readStateProp.read(source).value<DoubleSpinBoxState>());
323
324 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writeProperty));
326 if (writeProp.isWritable()) {
327 QObject::connect(spinBox, qOverload<qreal>(&QDoubleSpinBox::valueChanged),
328 source, [writeProp, source] (qreal value) { writeProp.write(source, value); });
329 }
330}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, SANITY_CHECK_PROPERTY_EXISTS_AND_WRITABLE, KisWidgetConnectionUtils::ConnectDoubleSpinBoxStateHelper::setState(), source(), and value().

◆ connectControlState() [5/5]

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectControlState ( QSpinBox * spinBox,
QObject * source,
const char * readStateProperty,
const char * writeProperty )

Definition at line 246 of file KisWidgetConnectionUtils.cpp.

247{
248 const QMetaObject* meta = source->metaObject();
249 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStateProperty));
250 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
251
252 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
253
254 QMetaMethod signal = readStateProp.notifySignal();
255
256 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
257 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("IntSpinBoxState"));
258
260
261 const QMetaObject* dstMeta = helper->metaObject();
262
263 QMetaMethod updateSlot = dstMeta->method(
264 dstMeta->indexOfSlot("setState(IntSpinBoxState)"));
265 QObject::connect(source, signal, helper, updateSlot);
266
267 helper->setState(readStateProp.read(source).value<IntSpinBoxState>());
268
269 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writeProperty));
271 if (writeProp.isWritable()) {
272 QObject::connect(spinBox, qOverload<int>(&QSpinBox::valueChanged),
273 source, [writeProp, source] (int value) { writeProp.write(source, value); });
274 }
275}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, SANITY_CHECK_PROPERTY_EXISTS_AND_WRITABLE, KisWidgetConnectionUtils::ConnectIntSpinBoxStateHelper::setState(), source(), and value().

◆ connectWidgetEnabledToProperty()

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectWidgetEnabledToProperty ( QWidget * widget,
QObject * source,
const char * property )

Definition at line 753 of file KisWidgetConnectionUtils.cpp.

754{
755 const QMetaObject* meta = source->metaObject();
756 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
758
759 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
760
761 QMetaMethod signal = prop.notifySignal();
762
763 const QMetaObject* dstMeta = widget->metaObject();
764
765 QMetaMethod updateSlot = dstMeta->method(
766 dstMeta->indexOfSlot("setEnabled(bool)"));
767
768 QObject::connect(source, signal, widget, updateSlot);
769 widget->setEnabled(prop.read(source).toBool());
770}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, and source().

◆ connectWidgetVisibleToProperty()

void KRITAWIDGETS_EXPORT KisWidgetConnectionUtils::connectWidgetVisibleToProperty ( QWidget * widget,
QObject * source,
const char * property )

Definition at line 734 of file KisWidgetConnectionUtils.cpp.

735{
736 const QMetaObject* meta = source->metaObject();
737 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
739
740 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
741
742 QMetaMethod signal = prop.notifySignal();
743
744 const QMetaObject* dstMeta = widget->metaObject();
745
746 QMetaMethod updateSlot = dstMeta->method(
747 dstMeta->indexOfSlot("setVisible(bool)"));
748
749 QObject::connect(source, signal, widget, updateSlot);
750 widget->setVisible(prop.read(source).toBool());
751}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, and source().