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 (QGroupBox *button, 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 (QGroupBox *button, QObject *source, const char *readStatePropertyName, const char *writePropertyName)
 
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 123 of file KisWidgetConnectionUtils.cpp.

124{
125 const QMetaObject* meta = source->metaObject();
126 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
128
129 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
130
131 QMetaMethod signal = prop.notifySignal();
132
133 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
134 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("bool"));
135
136 const QMetaObject* dstMeta = button->metaObject();
137
138 QMetaMethod updateSlot = dstMeta->method(
139 dstMeta->indexOfSlot("setChecked(bool)"));
140 QObject::connect(source, signal, button, updateSlot);
141
142 button->setChecked(prop.read(source).toBool());
143
144 if (prop.isWritable()) {
145 QObject::connect(button, &Button::toggled,
146 source, [prop, source] (bool value) { prop.write(source, value); });
147 }
148}
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/17]

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

Definition at line 684 of file KisWidgetConnectionUtils.cpp.

685{
686 const QMetaObject* meta = source->metaObject();
687 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
689
690 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
691
692 QMetaMethod signal = prop.notifySignal();
693
694 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
695 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("qreal"));
696
697 const QMetaObject* dstMeta = widget->metaObject();
698
699 QMetaMethod updateSlot = dstMeta->method(
700 dstMeta->indexOfSlot("setAngle(qreal)"));
701 QObject::connect(source, signal, widget, updateSlot);
702
703 widget->setAngle(prop.read(source).toReal());
704
705 if (prop.isWritable()) {
706 QObject::connect(widget, &KisAngleSelector::angleChanged,
707 source, [prop, source] (qreal value) { prop.write(source, value); });
708 }
709}
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/17]

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

Definition at line 766 of file KisWidgetConnectionUtils.cpp.

767{
768 const QMetaObject* meta = source->metaObject();
769 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
771
772 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
773
774 QMetaMethod signal = prop.notifySignal();
775
776 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
777 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("KoColor"));
778
779 const QMetaObject* dstMeta = widget->metaObject();
780
781 QMetaMethod updateSlot = dstMeta->method(
782 dstMeta->indexOfSlot("setColor(KoColor)"));
783 QObject::connect(source, signal, widget, updateSlot);
784
785 widget->setColor(prop.read(source).value<KoColor>());
786
787 if (prop.isWritable()) {
788 QObject::connect(widget, &KisColorButton::changed,
789 source, [prop, source] (const KoColor &value) {
790 prop.write(source, QVariant::fromValue(value)); });
791 }
792}
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/17]

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/17]

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/17]

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

Definition at line 738 of file KisWidgetConnectionUtils.cpp.

739{
740 const QMetaObject* meta = source->metaObject();
741 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
743
744 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
745
746 QMetaMethod signal = prop.notifySignal();
747
748 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
749 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("QString"));
750
751 const QMetaObject* dstMeta = widget->metaObject();
752
753 QMetaMethod updateSlot = dstMeta->method(
754 dstMeta->indexOfSlot("setFileName(QString)"));
755 QObject::connect(source, signal, widget, updateSlot);
756
757 widget->setFileName(prop.read(source).toString());
758
759 if (prop.isWritable()) {
760 QObject::connect(widget, &KisFileNameRequester::textChanged,
761 source, [prop, source] (const QString &value) {
762 prop.write(source, value); });
763 }
764}
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/17]

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

Definition at line 362 of file KisWidgetConnectionUtils.cpp.

363{
364 const QMetaObject* meta = source->metaObject();
365 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
367
368 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
369
370 QMetaMethod signal = prop.notifySignal();
371
372 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
373 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("qreal"));
374
375 const QMetaObject* dstMeta = spinBox->metaObject();
376
377 QMetaMethod updateSlot = dstMeta->method(
378 dstMeta->indexOfSlot("setValue(qreal)"));
379 QObject::connect(source, signal, spinBox, updateSlot);
380
381 spinBox->setValue(prop.read(source).toReal());
382
383 if (prop.isWritable()) {
384 QObject::connect(spinBox, qOverload<qreal>(&KisMultipliersDoubleSliderSpinBox::valueChanged),
385 source, [prop, source] (qreal value) { prop.write(source, value); });
386 }
387}
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/17]

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

Definition at line 655 of file KisWidgetConnectionUtils.cpp.

656{
657 const QMetaObject* meta = source->metaObject();
658 QMetaProperty stateProp = meta->property(meta->indexOfProperty(property));
660
661 KIS_SAFE_ASSERT_RECOVER_RETURN(stateProp.hasNotifySignal());
662
663 QMetaMethod signal = stateProp.notifySignal();
664
665 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
666 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("SpacingState"));
667
669
670 const QMetaObject* dstMeta = helper->metaObject();
671
672 QMetaMethod updateSlot = dstMeta->method(
673 dstMeta->indexOfSlot("slotPropertyChanged(SpacingState)"));
674 QObject::connect(source, signal, helper, updateSlot);
675
676 helper->slotPropertyChanged(stateProp.read(source).value<SpacingState>());
677
678 if (stateProp.isWritable()) {
679 QObject::connect(helper, &ConnectSpacingWidgetHelper::sigWidgetChanged,
680 source, [stateProp, source] (SpacingState value) { stateProp.write(source, QVariant::fromValue(value)); });
681 }
682}

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

◆ connectControl() [8/17]

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 150 of file KisWidgetConnectionUtils.cpp.

151{
153}
void connectButtonLikeControl(Button *button, QObject *source, const char *property)

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

◆ connectControl() [9/17]

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

Definition at line 155 of file KisWidgetConnectionUtils.cpp.

156{
158}

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

◆ connectControl() [10/17]

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

Definition at line 433 of file KisWidgetConnectionUtils.cpp.

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

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

◆ connectControl() [11/17]

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

Definition at line 160 of file KisWidgetConnectionUtils.cpp.

161{
163}

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

◆ connectControl() [12/17]

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

Definition at line 597 of file KisWidgetConnectionUtils.cpp.

598{
599 const QMetaObject* meta = source->metaObject();
600 QMetaProperty stateProp = meta->property(meta->indexOfProperty(property));
602
603 KIS_SAFE_ASSERT_RECOVER_RETURN(stateProp.hasNotifySignal());
604
605 QMetaMethod signal = stateProp.notifySignal();
606
607 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
608 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("int"));
609
610 const QMetaObject* dstMeta = button->metaObject();
611
612 QMetaMethod updateSlot = dstMeta->method(
613 dstMeta->indexOfSlot("setCurrentIndex(int)"));
614 QObject::connect(source, signal, button, updateSlot);
615
616 button->setCurrentIndex(stateProp.read(source).value<int>());
617
618 if (stateProp.isWritable()) {
619 // see a comment in connectControlState(QComboBox *button, ...)
621 QObject::connect(button, qOverload<int>(&QComboBox::currentIndexChanged),
622 source, [stateProp, source] (int value) { stateProp.write(source, value); });
623 }
624}
#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/17]

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

Definition at line 224 of file KisWidgetConnectionUtils.cpp.

225{
226 const QMetaObject* meta = source->metaObject();
227 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
229
230 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
231
232 QMetaMethod signal = prop.notifySignal();
233
234 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
235 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("qreal"));
236
237 const QMetaObject* dstMeta = spinBox->metaObject();
238
239 QMetaMethod updateSlot = dstMeta->method(
240 dstMeta->indexOfSlot("setValue(qreal)"));
241 QObject::connect(source, signal, spinBox, updateSlot);
242
243 spinBox->setValue(prop.read(source).toReal());
244
245 if (prop.isWritable()) {
246 QObject::connect(spinBox, qOverload<qreal>(&QDoubleSpinBox::valueChanged),
247 source, [prop, source] (qreal value) { prop.write(source, value); });
248 }
249}

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

◆ connectControl() [14/17]

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

Definition at line 165 of file KisWidgetConnectionUtils.cpp.

166{
168}

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

◆ connectControl() [15/17]

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

Definition at line 711 of file KisWidgetConnectionUtils.cpp.

712{
713 const QMetaObject* meta = source->metaObject();
714 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
716
717 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
718
719 QMetaMethod signal = prop.notifySignal();
720
721 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
722 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("QString"));
723
724 const QMetaObject* dstMeta = widget->metaObject();
725
726 QMetaMethod updateSlot = dstMeta->method(
727 dstMeta->indexOfSlot("setText(QString)"));
728 QObject::connect(source, signal, widget, updateSlot);
729
730 widget->setText(prop.read(source).toString());
731
732 if (prop.isWritable()) {
733 QObject::connect(widget, &QLineEdit::textChanged,
734 source, [prop, source] (const QString &value) { prop.write(source, value); });
735 }
736}

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

◆ connectControl() [16/17]

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

Definition at line 197 of file KisWidgetConnectionUtils.cpp.

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

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

◆ connectControl() [17/17]

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

Definition at line 170 of file KisWidgetConnectionUtils.cpp.

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

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

◆ connectControlState() [1/6]

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

Definition at line 495 of file KisWidgetConnectionUtils.cpp.

496{
497 const QMetaObject* meta = source->metaObject();
498 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStatePropertyName));
499 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
500
501 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
502
503 QMetaMethod signal = readStateProp.notifySignal();
504
505 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
506 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("CheckBoxState"));
507
509
510 const QMetaObject* dstMeta = helper->metaObject();
511
512 QMetaMethod updateSlot = dstMeta->method(
513 dstMeta->indexOfSlot("updateState(CheckBoxState)"));
514 QObject::connect(source, signal, helper, updateSlot);
515
516 helper->updateState(readStateProp.read(source).value<CheckBoxState>());
517
518 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writePropertyName));
520 if (writeProp.isWritable()) {
521 button->connect(button, &QAbstractButton::toggled,
522 source, [writeProp, source] (bool value) { writeProp.write(source, value); });
523 }
524}
#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/6]

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

Definition at line 463 of file KisWidgetConnectionUtils.cpp.

464{
465 const QMetaObject* meta = source->metaObject();
466 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStateProperty));
467 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
468
469 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
470
471 QMetaMethod signal = readStateProp.notifySignal();
472
473 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
474 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("ButtonGroupState"));
475
477
478 const QMetaObject* dstMeta = helper->metaObject();
479
480 QMetaMethod updateSlot = dstMeta->method(
481 dstMeta->indexOfSlot("updateState(ButtonGroupState)"));
482 QObject::connect(source, signal, helper, updateSlot);
483
484 helper->updateState(readStateProp.read(source).value<ButtonGroupState>());
485
486 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writeProperty));
488
489 if (writeProp.isWritable()) {
490 QObject::connect(helper, &ConnectButtonGroupHelper::idClicked,
491 source, [writeProp, source] (int value) { writeProp.write(source, value); });
492 }
493}

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/6]

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 558 of file KisWidgetConnectionUtils.cpp.

559{
560 const QMetaObject* meta = source->metaObject();
561 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStatePropertyName));
562 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
563
564 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
565
566 QMetaMethod signal = readStateProp.notifySignal();
567
568 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
569 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("ComboBoxState"));
570
572
573 const QMetaObject* dstMeta = helper->metaObject();
574
575 QMetaMethod updateSlot = dstMeta->method(
576 dstMeta->indexOfSlot("updateState(ComboBoxState)"));
577 QObject::connect(source, signal, helper, updateSlot);
578
579 helper->updateState(readStateProp.read(source).value<ComboBoxState>());
580
581 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writePropertyName));
583
590
591 if (writeProp.isWritable()) {
592 QObject::connect(button, qOverload<int>(&QComboBox::currentIndexChanged),
593 source, [writeProp, source] (int value) { writeProp.write(source, value); });
594 }
595}
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/6]

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

Definition at line 330 of file KisWidgetConnectionUtils.cpp.

331{
332 const QMetaObject* meta = source->metaObject();
333 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStateProperty));
334 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
335
336 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
337
338 QMetaMethod signal = readStateProp.notifySignal();
339
340 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
341 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("DoubleSpinBoxState"));
342
344
345 const QMetaObject* dstMeta = helper->metaObject();
346
347 QMetaMethod updateSlot = dstMeta->method(
348 dstMeta->indexOfSlot("setState(DoubleSpinBoxState)"));
349 QObject::connect(source, signal, helper, updateSlot);
350
351 helper->setState(readStateProp.read(source).value<DoubleSpinBoxState>());
352
353 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writeProperty));
355 if (writeProp.isWritable()) {
356 QObject::connect(spinBox, qOverload<qreal>(&QDoubleSpinBox::valueChanged),
357 source, [writeProp, source] (qreal value) { writeProp.write(source, value); });
358 }
359}

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

◆ connectControlState() [5/6]

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

Definition at line 526 of file KisWidgetConnectionUtils.cpp.

527{
528 const QMetaObject* meta = source->metaObject();
529 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStatePropertyName));
530 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
531
532 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
533
534 QMetaMethod signal = readStateProp.notifySignal();
535
536 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
537 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("CheckBoxState"));
538
540
541 const QMetaObject* dstMeta = helper->metaObject();
542
543 QMetaMethod updateSlot = dstMeta->method(
544 dstMeta->indexOfSlot("updateState(CheckBoxState)"));
545 QObject::connect(source, signal, helper, updateSlot);
546
547 helper->updateState(readStateProp.read(source).value<CheckBoxState>());
548
549 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writePropertyName));
551 if (writeProp.isWritable()) {
552 button->connect(button, &QGroupBox::toggled,
553 source, [writeProp, source] (bool value) { writeProp.write(source, value); });
554 }
555}
void updateState(const CheckBoxState &state)

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

◆ connectControlState() [6/6]

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

Definition at line 275 of file KisWidgetConnectionUtils.cpp.

276{
277 const QMetaObject* meta = source->metaObject();
278 QMetaProperty readStateProp = meta->property(meta->indexOfProperty(readStateProperty));
279 SANITY_CHECK_PROPERTY_EXISTS(readStateProp);
280
281 KIS_SAFE_ASSERT_RECOVER_RETURN(readStateProp.hasNotifySignal());
282
283 QMetaMethod signal = readStateProp.notifySignal();
284
285 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterCount() >= 1);
286 KIS_SAFE_ASSERT_RECOVER_RETURN(signal.parameterType(0) == QMetaType::type("IntSpinBoxState"));
287
289
290 const QMetaObject* dstMeta = helper->metaObject();
291
292 QMetaMethod updateSlot = dstMeta->method(
293 dstMeta->indexOfSlot("setState(IntSpinBoxState)"));
294 QObject::connect(source, signal, helper, updateSlot);
295
296 helper->setState(readStateProp.read(source).value<IntSpinBoxState>());
297
298 QMetaProperty writeProp = meta->property(meta->indexOfProperty(writeProperty));
300 if (writeProp.isWritable()) {
301 QObject::connect(spinBox, qOverload<int>(&QSpinBox::valueChanged),
302 source, [writeProp, source] (int value) { writeProp.write(source, value); });
303 }
304}

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 813 of file KisWidgetConnectionUtils.cpp.

814{
815 const QMetaObject* meta = source->metaObject();
816 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
818
819 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
820
821 QMetaMethod signal = prop.notifySignal();
822
823 const QMetaObject* dstMeta = widget->metaObject();
824
825 QMetaMethod updateSlot = dstMeta->method(
826 dstMeta->indexOfSlot("setEnabled(bool)"));
827
828 QObject::connect(source, signal, widget, updateSlot);
829 widget->setEnabled(prop.read(source).toBool());
830}

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 794 of file KisWidgetConnectionUtils.cpp.

795{
796 const QMetaObject* meta = source->metaObject();
797 QMetaProperty prop = meta->property(meta->indexOfProperty(property));
799
800 KIS_SAFE_ASSERT_RECOVER_RETURN(prop.hasNotifySignal());
801
802 QMetaMethod signal = prop.notifySignal();
803
804 const QMetaObject* dstMeta = widget->metaObject();
805
806 QMetaMethod updateSlot = dstMeta->method(
807 dstMeta->indexOfSlot("setVisible(bool)"));
808
809 QObject::connect(source, signal, widget, updateSlot);
810 widget->setVisible(prop.read(source).toBool());
811}

References KIS_SAFE_ASSERT_RECOVER_RETURN, SANITY_CHECK_PROPERTY_EXISTS, and source().