Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qteditorfactory.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
8#include <QtWidgets/qabstractitemview.h>
9#include <QtWidgets/qapplication.h>
10#include <QtWidgets/qboxlayout.h>
11#include <QtWidgets/qcolordialog.h>
12#include <QtWidgets/qcombobox.h>
13#if QT_CONFIG(datetimeedit)
14#include <QtWidgets/qdatetimeedit.h>
15#endif
16#include <QtWidgets/qfontdialog.h>
17#include <QtWidgets/qkeysequenceedit.h>
18#include <QtWidgets/qlabel.h>
19#include <QtWidgets/qlayoutitem.h>
20#include <QtWidgets/qlineedit.h>
21#include <QtWidgets/qmenu.h>
22#include <QtWidgets/qscrollbar.h>
23#include <QtWidgets/qspinbox.h>
24#include <QtWidgets/qtoolbutton.h>
25
26#include <QtGui/qevent.h>
27#include <QtGui/qvalidator.h>
28
29#include <QtCore/qhash.h>
30#include <QtCore/qregularexpression.h>
31
33
34// Set a hard coded left margin to account for the indentation
35// of the tree view icon when switching to an editor
36
37static inline void setupTreeViewEditorMargin(QLayout *lt)
38{
39 enum { DecorationMargin = 4 };
40 if (QApplication::layoutDirection() == Qt::LeftToRight)
41 lt->setContentsMargins(DecorationMargin, 0, 0, 0);
42 else
43 lt->setContentsMargins(0, 0, DecorationMargin, 0);
44}
45
46// ---------- EditorFactoryPrivate :
47// Base class for editor factory private classes. Manages mapping of properties to editors and vice versa.
48
49template <class Editor>
51{
52public:
53
57
58 Editor *createEditor(QtProperty *property, QWidget *parent);
59 void initializeEditor(QtProperty *property, Editor *e);
60 void slotEditorDestroyed(QObject *object);
61
63
65};
66
67template <class Editor>
68Editor *EditorFactoryPrivate<Editor>::createEditor(QtProperty *property, QWidget *parent)
69{
70 auto *editor = new Editor(parent);
71 initializeEditor(property, editor);
72 return editor;
73}
74
75template <class Editor>
76void EditorFactoryPrivate<Editor>::initializeEditor(QtProperty *property, Editor *editor)
77{
78 auto it = m_createdEditors.find(property);
79 if (it == m_createdEditors.end())
80 it = m_createdEditors.insert(property, EditorList());
81 it.value().append(editor);
82}
83
84template <class Editor>
85void EditorFactoryPrivate<Editor>::slotEditorDestroyed(QObject *object)
86{
87 auto pred = [object] (const Editor *e) { return object == e; };
88 for (auto it = m_createdEditors.begin(), end = m_createdEditors.end(); it != end; ++it) {
89 auto &editorList = it.value();
90 auto listIt = std::find_if(editorList.cbegin(), editorList.cend(), pred);
91 if (listIt != editorList.cend()) {
92 editorList.erase(listIt);
93 if (editorList.isEmpty())
94 m_createdEditors.erase(it) ;
95 break;
96 }
97 }
98}
99
100template <class Editor>
102{
103 for (auto it = m_createdEditors.begin(), end = m_createdEditors.end(); it != end; ++it)
104 qDeleteAll(it.value());
105 m_createdEditors.clear();
106}
107
108// ------------ QtSpinBoxFactory
109
111{
112 QtSpinBoxFactory *q_ptr = nullptr;
113 Q_DECLARE_PUBLIC(QtSpinBoxFactory)
114public:
115
117 void slotRangeChanged(QtProperty *property, int min, int max);
118 void slotSingleStepChanged(QtProperty *property, int step);
119 void slotSetValue(QtProperty *property, int value);
120};
121
122void QtSpinBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, int value)
123{
124 const auto it = m_createdEditors.constFind(property);
125 if (it == m_createdEditors.cend())
126 return;
127 for (QSpinBox *editor : it.value()) {
128 if (editor->value() != value) {
129 editor->blockSignals(true);
130 editor->setValue(value);
131 editor->blockSignals(false);
132 }
133 }
134}
135
136void QtSpinBoxFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max)
137{
138 const auto it = m_createdEditors.constFind(property);
139 if (it == m_createdEditors.cend())
140 return;
141
142 QtIntPropertyManager *manager = q_ptr->propertyManager(property);
143 if (!manager)
144 return;
145
146 for (QSpinBox *editor : it.value()) {
147 editor->blockSignals(true);
148 editor->setRange(min, max);
149 editor->setValue(manager->value(property));
150 editor->blockSignals(false);
151 }
152}
153
155{
156 const auto it = m_createdEditors.constFind(property);
157 if (it == m_createdEditors.cend())
158 return;
159 for (QSpinBox *editor : it.value()) {
160 editor->blockSignals(true);
161 editor->setSingleStep(step);
162 editor->blockSignals(false);
163 }
164}
165
167{
168 if (QtIntPropertyManager *manager = q_ptr->propertyManager(property))
169 manager->setValue(property, value);
170}
171
172/*!
173 \class QtSpinBoxFactory
174 \internal
175 \inmodule QtDesigner
176 \since 4.4
177
178 \brief The QtSpinBoxFactory class provides QSpinBox widgets for
179 properties created by QtIntPropertyManager objects.
180
181 \sa QtAbstractEditorFactory, QtIntPropertyManager
182*/
183
184/*!
185 Creates a factory with the given \a parent.
186*/
187QtSpinBoxFactory::QtSpinBoxFactory(QObject *parent)
188 : QtAbstractEditorFactory<QtIntPropertyManager>(parent), d_ptr(new QtSpinBoxFactoryPrivate())
189{
190 d_ptr->q_ptr = this;
191
192}
193
194/*!
195 Destroys this factory, and all the widgets it has created.
196*/
198{
199 d_ptr->deleteEditors();
200}
201
202/*!
203 \internal
204
205 Reimplemented from the QtAbstractEditorFactory class.
206*/
208{
209 connect(manager, &QtIntPropertyManager::valueChanged,
210 this, [this](QtProperty *property, int value)
211 { d_ptr->slotPropertyChanged(property, value); });
212 connect(manager, &QtIntPropertyManager::rangeChanged,
213 this, [this](QtProperty *property, int min, int max)
214 { d_ptr->slotRangeChanged(property, min, max); });
216 this, [this](QtProperty *property, int value)
217 { d_ptr->slotSingleStepChanged(property, value); });
218}
219
220/*!
221 \internal
222
223 Reimplemented from the QtAbstractEditorFactory class.
224*/
226 QWidget *parent)
227{
228 QSpinBox *editor = d_ptr->createEditor(property, parent);
229 editor->setSingleStep(manager->singleStep(property));
230 editor->setRange(manager->minimum(property), manager->maximum(property));
231 editor->setValue(manager->value(property));
232 editor->setKeyboardTracking(false);
233
234 connect(editor, &QSpinBox::valueChanged,
235 this, [this, property](int value) { d_ptr->slotSetValue(property, value); });
236 connect(editor, &QObject::destroyed,
237 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
238 return editor;
239}
240
241/*!
242 \internal
243
244 Reimplemented from the QtAbstractEditorFactory class.
245*/
247{
248 disconnect(manager, &QtIntPropertyManager::valueChanged, this, nullptr);
249 disconnect(manager, &QtIntPropertyManager::rangeChanged, this, nullptr);
250 disconnect(manager, &QtIntPropertyManager::singleStepChanged, this, nullptr);
251}
252
253// QtSliderFactory
254
256{
257 QtSliderFactory *q_ptr = nullptr;
258 Q_DECLARE_PUBLIC(QtSliderFactory)
259public:
261 void slotRangeChanged(QtProperty *property, int min, int max);
262 void slotSingleStepChanged(QtProperty *property, int step);
263 void slotSetValue(QtProperty *property, int value);
264};
265
266void QtSliderFactoryPrivate::slotPropertyChanged(QtProperty *property, int value)
267{
268 const auto it = m_createdEditors.constFind(property);
269 if (it == m_createdEditors.cend())
270 return;
271 for (QSlider *editor : it.value()) {
272 editor->blockSignals(true);
273 editor->setValue(value);
274 editor->blockSignals(false);
275 }
276}
277
278void QtSliderFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max)
279{
280 const auto it = m_createdEditors.constFind(property);
281 if (it == m_createdEditors.cend())
282 return;
283
284 QtIntPropertyManager *manager = q_ptr->propertyManager(property);
285 if (!manager)
286 return;
287
288 for (QSlider *editor : it.value()) {
289 editor->blockSignals(true);
290 editor->setRange(min, max);
291 editor->setValue(manager->value(property));
292 editor->blockSignals(false);
293 }
294}
295
297{
298 const auto it = m_createdEditors.constFind(property);
299 if (it == m_createdEditors.cend())
300 return;
301 for (QSlider *editor : it.value()) {
302 editor->blockSignals(true);
303 editor->setSingleStep(step);
304 editor->blockSignals(false);
305 }
306}
307
309{
310 if (QtIntPropertyManager *manager = q_ptr->propertyManager(property))
311 manager->setValue(property, value);
312}
313
314/*!
315 \class QtSliderFactory
316 \internal
317 \inmodule QtDesigner
318 \since 4.4
319
320 \brief The QtSliderFactory class provides QSlider widgets for
321 properties created by QtIntPropertyManager objects.
322
323 \sa QtAbstractEditorFactory, QtIntPropertyManager
324*/
325
326/*!
327 Creates a factory with the given \a parent.
328*/
329QtSliderFactory::QtSliderFactory(QObject *parent)
330 : QtAbstractEditorFactory<QtIntPropertyManager>(parent), d_ptr(new QtSliderFactoryPrivate())
331{
332 d_ptr->q_ptr = this;
333
334}
335
336/*!
337 Destroys this factory, and all the widgets it has created.
338*/
340{
341 d_ptr->deleteEditors();
342}
343
344/*!
345 \internal
346
347 Reimplemented from the QtAbstractEditorFactory class.
348*/
350{
351 connect(manager, &QtIntPropertyManager::valueChanged,
352 this, [this](QtProperty *property, int value)
353 { d_ptr->slotPropertyChanged(property, value); });
354 connect(manager, &QtIntPropertyManager::rangeChanged,
355 this, [this](QtProperty *property, int min, int max)
356 { d_ptr->slotRangeChanged(property, min, max); });
358 this, [this](QtProperty *property, int value)
359 { d_ptr->slotSingleStepChanged(property, value); });
360}
361
362/*!
363 \internal
364
365 Reimplemented from the QtAbstractEditorFactory class.
366*/
368 QWidget *parent)
369{
370 auto *editor = new QSlider(Qt::Horizontal, parent);
371 d_ptr->initializeEditor(property, editor);
372 editor->setSingleStep(manager->singleStep(property));
373 editor->setRange(manager->minimum(property), manager->maximum(property));
374 editor->setValue(manager->value(property));
375
376 connect(editor, &QSlider::valueChanged,
377 this, [this, property](int value) { d_ptr->slotSetValue(property, value); });
378 connect(editor, &QObject::destroyed,
379 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
380 return editor;
381}
382
383/*!
384 \internal
385
386 Reimplemented from the QtAbstractEditorFactory class.
387*/
389{
390 disconnect(manager, &QtIntPropertyManager::valueChanged, this, nullptr);
391 disconnect(manager, &QtIntPropertyManager::rangeChanged, this, nullptr);
392 disconnect(manager, &QtIntPropertyManager::singleStepChanged, this, nullptr);
393}
394
395// QtSliderFactory
396
398{
399 QtScrollBarFactory *q_ptr = nullptr;
400 Q_DECLARE_PUBLIC(QtScrollBarFactory)
401public:
403 void slotRangeChanged(QtProperty *property, int min, int max);
404 void slotSingleStepChanged(QtProperty *property, int step);
405 void slotSetValue(QtProperty *property, int value);
406};
407
408void QtScrollBarFactoryPrivate::slotPropertyChanged(QtProperty *property, int value)
409{
410 const auto it = m_createdEditors.constFind(property);
411 if (it == m_createdEditors.cend())
412 return;
413
414 for (QScrollBar *editor : it.value()) {
415 editor->blockSignals(true);
416 editor->setValue(value);
417 editor->blockSignals(false);
418 }
419}
420
421void QtScrollBarFactoryPrivate::slotRangeChanged(QtProperty *property, int min, int max)
422{
423 const auto it = m_createdEditors.constFind(property);
424 if (it == m_createdEditors.cend())
425 return;
426
427 QtIntPropertyManager *manager = q_ptr->propertyManager(property);
428 if (!manager)
429 return;
430
431 for (QScrollBar *editor : it.value()) {
432 editor->blockSignals(true);
433 editor->setRange(min, max);
434 editor->setValue(manager->value(property));
435 editor->blockSignals(false);
436 }
437}
438
440{
441 const auto it = m_createdEditors.constFind(property);
442 if (it == m_createdEditors.cend())
443 return;
444 for (QScrollBar *editor : it.value()) {
445 editor->blockSignals(true);
446 editor->setSingleStep(step);
447 editor->blockSignals(false);
448 }
449}
450
452{
453 if (QtIntPropertyManager *manager = q_ptr->propertyManager(property))
454 manager->setValue(property, value);
455}
456
457/*!
458 \class QtScrollBarFactory
459 \internal
460 \inmodule QtDesigner
461 \since 4.4
462
463 \brief The QtScrollBarFactory class provides QScrollBar widgets for
464 properties created by QtIntPropertyManager objects.
465
466 \sa QtAbstractEditorFactory, QtIntPropertyManager
467*/
468
469/*!
470 Creates a factory with the given \a parent.
471*/
472QtScrollBarFactory::QtScrollBarFactory(QObject *parent)
473 : QtAbstractEditorFactory<QtIntPropertyManager>(parent), d_ptr(new QtScrollBarFactoryPrivate())
474{
475 d_ptr->q_ptr = this;
476
477}
478
479/*!
480 Destroys this factory, and all the widgets it has created.
481*/
483{
484 d_ptr->deleteEditors();
485}
486
487/*!
488 \internal
489
490 Reimplemented from the QtAbstractEditorFactory class.
491*/
493{
494 connect(manager, &QtIntPropertyManager::valueChanged,
495 this, [this](QtProperty *property, int value)
496 { d_ptr->slotPropertyChanged(property, value); });
497 connect(manager, &QtIntPropertyManager::rangeChanged,
498 this, [this](QtProperty *property, int min, int max)
499 { d_ptr->slotRangeChanged(property, min, max); });
501 this, [this](QtProperty *property, int value)
502 { d_ptr->slotSingleStepChanged(property, value); });
503}
504
505/*!
506 \internal
507
508 Reimplemented from the QtAbstractEditorFactory class.
509*/
511 QWidget *parent)
512{
513 auto *editor = new QScrollBar(Qt::Horizontal, parent);
514 d_ptr->initializeEditor(property, editor);
515 editor->setSingleStep(manager->singleStep(property));
516 editor->setRange(manager->minimum(property), manager->maximum(property));
517 editor->setValue(manager->value(property));
518 connect(editor, &QScrollBar::valueChanged,
519 this, [this, property](int value) { d_ptr->slotSetValue(property, value); });
520 connect(editor, &QObject::destroyed,
521 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
522 return editor;
523}
524
525/*!
526 \internal
527
528 Reimplemented from the QtAbstractEditorFactory class.
529*/
531{
532 disconnect(manager, &QtIntPropertyManager::valueChanged, this, nullptr);
533 disconnect(manager, &QtIntPropertyManager::rangeChanged, this, nullptr);
534 disconnect(manager, &QtIntPropertyManager::singleStepChanged, this, nullptr);
535}
536
537// QtCheckBoxFactory
538
540{
541 QtCheckBoxFactory *q_ptr = nullptr;
542 Q_DECLARE_PUBLIC(QtCheckBoxFactory)
543public:
545 void slotSetValue(QtProperty *property, bool value);
546};
547
548void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool value)
549{
550 const auto it = m_createdEditors.constFind(property);
551 if (it == m_createdEditors.cend())
552 return;
553
554 for (QtBoolEdit *editor : it.value()) {
555 editor->blockCheckBoxSignals(true);
556 editor->setChecked(value);
557 editor->blockCheckBoxSignals(false);
558 }
559}
560
562{
563 if (QtBoolPropertyManager *manager = q_ptr->propertyManager(property))
564 manager->setValue(property, value);
565}
566
567/*!
568 \class QtCheckBoxFactory
569 \internal
570 \inmodule QtDesigner
571 \since 4.4
572
573 \brief The QtCheckBoxFactory class provides QCheckBox widgets for
574 properties created by QtBoolPropertyManager objects.
575
576 \sa QtAbstractEditorFactory, QtBoolPropertyManager
577*/
578
579/*!
580 Creates a factory with the given \a parent.
581*/
582QtCheckBoxFactory::QtCheckBoxFactory(QObject *parent)
583 : QtAbstractEditorFactory<QtBoolPropertyManager>(parent), d_ptr(new QtCheckBoxFactoryPrivate())
584{
585 d_ptr->q_ptr = this;
586
587}
588
589/*!
590 Destroys this factory, and all the widgets it has created.
591*/
593{
594 d_ptr->deleteEditors();
595}
596
597/*!
598 \internal
599
600 Reimplemented from the QtAbstractEditorFactory class.
601*/
603{
604 connect(manager, &QtBoolPropertyManager::valueChanged,
605 this, [this](QtProperty *property, bool value)
606 { d_ptr->slotPropertyChanged(property, value); });
607}
608
609/*!
610 \internal
611
612 Reimplemented from the QtAbstractEditorFactory class.
613*/
615 QWidget *parent)
616{
617 QtBoolEdit *editor = d_ptr->createEditor(property, parent);
618 editor->setChecked(manager->value(property));
619
620 connect(editor, &QtBoolEdit::toggled,
621 this, [this, property](bool value) { d_ptr->slotSetValue(property, value); });
622 connect(editor, &QObject::destroyed,
623 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
624 return editor;
625}
626
627/*!
628 \internal
629
630 Reimplemented from the QtAbstractEditorFactory class.
631*/
633{
634 disconnect(manager, &QtBoolPropertyManager::valueChanged, this, nullptr);
635}
636
637// QtDoubleSpinBoxFactory
638
640{
641 QtDoubleSpinBoxFactory *q_ptr = nullptr;
642 Q_DECLARE_PUBLIC(QtDoubleSpinBoxFactory)
643public:
644
646 void slotRangeChanged(QtProperty *property, double min, double max);
647 void slotSingleStepChanged(QtProperty *property, double step);
648 void slotDecimalsChanged(QtProperty *property, int prec);
649 void slotSetValue(QtProperty *property, double value);
650};
651
652void QtDoubleSpinBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, double value)
653{
654 const auto it = m_createdEditors.constFind(property);
655 if (it == m_createdEditors.cend())
656 return;
657 for (QDoubleSpinBox *editor : it.value()) {
658 if (editor->value() != value) {
659 editor->blockSignals(true);
660 editor->setValue(value);
661 editor->blockSignals(false);
662 }
663 }
664}
665
667 double min, double max)
668{
669 const auto it = m_createdEditors.constFind(property);
670 if (it == m_createdEditors.cend())
671 return;
672
673 QtDoublePropertyManager *manager = q_ptr->propertyManager(property);
674 if (!manager)
675 return;
676
677 for (QDoubleSpinBox *editor : it.value()) {
678 editor->blockSignals(true);
679 editor->setRange(min, max);
680 editor->setValue(manager->value(property));
681 editor->blockSignals(false);
682 }
683}
684
686{
687 const auto it = m_createdEditors.constFind(property);
688 if (it == m_createdEditors.cend())
689 return;
690
691 QtDoublePropertyManager *manager = q_ptr->propertyManager(property);
692 if (!manager)
693 return;
694
695 for (QDoubleSpinBox *editor : it.value()) {
696 editor->blockSignals(true);
697 editor->setSingleStep(step);
698 editor->blockSignals(false);
699 }
700}
701
703{
704 const auto it = m_createdEditors.constFind(property);
705 if (it == m_createdEditors.constEnd())
706 return;
707
708 QtDoublePropertyManager *manager = q_ptr->propertyManager(property);
709 if (!manager)
710 return;
711
712 for (QDoubleSpinBox *editor : it.value()) {
713 editor->blockSignals(true);
714 editor->setDecimals(prec);
715 editor->setValue(manager->value(property));
716 editor->blockSignals(false);
717 }
718}
719
721{
722 if (QtDoublePropertyManager *manager = q_ptr->propertyManager(property))
723 manager->setValue(property, value);
724}
725
726/*! \class QtDoubleSpinBoxFactory
727 \internal
728 \inmodule QtDesigner
729 \since 4.4
730
731 \brief The QtDoubleSpinBoxFactory class provides QDoubleSpinBox
732 widgets for properties created by QtDoublePropertyManager objects.
733
734 \sa QtAbstractEditorFactory, QtDoublePropertyManager
735*/
736
737/*!
738 Creates a factory with the given \a parent.
739*/
740QtDoubleSpinBoxFactory::QtDoubleSpinBoxFactory(QObject *parent)
741 : QtAbstractEditorFactory<QtDoublePropertyManager>(parent), d_ptr(new QtDoubleSpinBoxFactoryPrivate())
742{
743 d_ptr->q_ptr = this;
744
745}
746
747/*!
748 Destroys this factory, and all the widgets it has created.
749*/
751{
752 d_ptr->deleteEditors();
753}
754
755/*!
756 \internal
757
758 Reimplemented from the QtAbstractEditorFactory class.
759*/
761{
762 connect(manager, &QtDoublePropertyManager::valueChanged,
763 this, [this](QtProperty *property, double value)
764 { d_ptr->slotPropertyChanged(property, value); });
766 this, [this](QtProperty *property, double min, double max)
767 { d_ptr->slotRangeChanged(property, min, max); });
769 this, [this](QtProperty *property, double value)
770 { d_ptr->slotSingleStepChanged(property, value); });
772 this, [this](QtProperty *property, int value)
773 { d_ptr->slotDecimalsChanged(property, value); });
774}
775
776/*!
777 \internal
778
779 Reimplemented from the QtAbstractEditorFactory class.
780*/
782 QtProperty *property, QWidget *parent)
783{
784 QDoubleSpinBox *editor = d_ptr->createEditor(property, parent);
785 editor->setSingleStep(manager->singleStep(property));
786 editor->setDecimals(manager->decimals(property));
787 editor->setRange(manager->minimum(property), manager->maximum(property));
788 editor->setValue(manager->value(property));
789 editor->setKeyboardTracking(false);
790
791 connect(editor, &QDoubleSpinBox::valueChanged,
792 this, [this, property](double value) { d_ptr->slotSetValue(property, value); });
793 connect(editor, &QObject::destroyed,
794 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
795 return editor;
796}
797
798/*!
799 \internal
800
801 Reimplemented from the QtAbstractEditorFactory class.
802*/
804{
805 disconnect(manager, &QtDoublePropertyManager::valueChanged, this, nullptr);
806 disconnect(manager, &QtDoublePropertyManager::rangeChanged, this, nullptr);
807 disconnect(manager, &QtDoublePropertyManager::singleStepChanged, this, nullptr);
808 disconnect(manager, &QtDoublePropertyManager::decimalsChanged, this, nullptr);
809}
810
811// QtLineEditFactory
812
814{
815 QtLineEditFactory *q_ptr = nullptr;
816 Q_DECLARE_PUBLIC(QtLineEditFactory)
817public:
818
820 void slotRegExpChanged(QtProperty *property, const QRegularExpression &regExp);
821 void slotSetValue(QtProperty *property, const QString &value);
822};
823
824void QtLineEditFactoryPrivate::slotPropertyChanged(QtProperty *property,
825 const QString &value)
826{
827 const auto it = m_createdEditors.constFind(property);
828 if (it == m_createdEditors.constEnd())
829 return;
830
831 for (QLineEdit *editor : it.value()) {
832 if (editor->text() != value)
833 editor->setText(value);
834 }
835}
836
838 const QRegularExpression &regExp)
839{
840 const auto it = m_createdEditors.constFind(property);
841 if (it == m_createdEditors.constEnd())
842 return;
843
844 QtStringPropertyManager *manager = q_ptr->propertyManager(property);
845 if (!manager)
846 return;
847
848 for (QLineEdit *editor : it.value()) {
849 editor->blockSignals(true);
850 const QValidator *oldValidator = editor->validator();
851 QValidator *newValidator = nullptr;
852 if (regExp.isValid()) {
853 newValidator = new QRegularExpressionValidator(regExp, editor);
854 }
855 editor->setValidator(newValidator);
856 delete oldValidator;
857 editor->blockSignals(false);
858 }
859}
860
861void QtLineEditFactoryPrivate::slotSetValue(QtProperty *property, const QString &value)
862{
863 if (QtStringPropertyManager *manager = q_ptr->propertyManager(property))
864 manager->setValue(property, value);
865}
866
867/*!
868 \class QtLineEditFactory
869 \internal
870 \inmodule QtDesigner
871 \since 4.4
872
873 \brief The QtLineEditFactory class provides QLineEdit widgets for
874 properties created by QtStringPropertyManager objects.
875
876 \sa QtAbstractEditorFactory, QtStringPropertyManager
877*/
878
879/*!
880 Creates a factory with the given \a parent.
881*/
882QtLineEditFactory::QtLineEditFactory(QObject *parent)
883 : QtAbstractEditorFactory<QtStringPropertyManager>(parent), d_ptr(new QtLineEditFactoryPrivate())
884{
885 d_ptr->q_ptr = this;
886
887}
888
889/*!
890 Destroys this factory, and all the widgets it has created.
891*/
893{
894 d_ptr->deleteEditors();
895}
896
897/*!
898 \internal
899
900 Reimplemented from the QtAbstractEditorFactory class.
901*/
903{
904 connect(manager, &QtStringPropertyManager::valueChanged,
905 this, [this](QtProperty *property, const QString &value)
906 { d_ptr->slotPropertyChanged(property, value); });
908 this, [this](QtProperty *property, const QRegularExpression &value)
909 { d_ptr->slotRegExpChanged(property, value); });
910}
911
912/*!
913 \internal
914
915 Reimplemented from the QtAbstractEditorFactory class.
916*/
918 QtProperty *property, QWidget *parent)
919{
920 QLineEdit *editor = d_ptr->createEditor(property, parent);
921 QRegularExpression regExp = manager->regExp(property);
922 if (regExp.isValid() && !regExp.pattern().isEmpty()) {
923 auto *validator = new QRegularExpressionValidator(regExp, editor);
924 editor->setValidator(validator);
925 }
926 editor->setText(manager->value(property));
927
928 connect(editor, &QLineEdit::textEdited,
929 this, [this, property](const QString &value) { d_ptr->slotSetValue(property, value); });
930 connect(editor, &QObject::destroyed,
931 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
932 return editor;
933}
934
935/*!
936 \internal
937
938 Reimplemented from the QtAbstractEditorFactory class.
939*/
941{
942 disconnect(manager, &QtStringPropertyManager::valueChanged, this, nullptr);
943 disconnect(manager, &QtStringPropertyManager::regExpChanged, this, nullptr);
944}
945
946// QtDateEditFactory
947
949{
950 QtDateEditFactory *q_ptr = nullptr;
951 Q_DECLARE_PUBLIC(QtDateEditFactory)
952public:
953
955 void slotRangeChanged(QtProperty *property, QDate min, QDate max);
956 void slotSetValue(QtProperty *property, QDate value);
957};
958
959void QtDateEditFactoryPrivate::slotPropertyChanged(QtProperty *property, QDate value)
960{
961 const auto it = m_createdEditors.constFind(property);
962 if (it == m_createdEditors.constEnd())
963 return;
964 for (QDateEdit *editor : it.value()) {
965 editor->blockSignals(true);
966 editor->setDate(value);
967 editor->blockSignals(false);
968 }
969}
970
971void QtDateEditFactoryPrivate::slotRangeChanged(QtProperty *property, QDate min, QDate max)
972{
973 const auto it = m_createdEditors.constFind(property);
974 if (it == m_createdEditors.constEnd())
975 return;
976
977 QtDatePropertyManager *manager = q_ptr->propertyManager(property);
978 if (!manager)
979 return;
980
981 for (QDateEdit *editor : it.value()) {
982 editor->blockSignals(true);
983 editor->setDateRange(min, max);
984 editor->setDate(manager->value(property));
985 editor->blockSignals(false);
986 }
987}
988
990{
991 if (QtDatePropertyManager *manager = q_ptr->propertyManager(property))
992 manager->setValue(property, value);
993}
994
995/*!
996 \class QtDateEditFactory
997 \internal
998 \inmodule QtDesigner
999 \since 4.4
1000
1001 \brief The QtDateEditFactory class provides QDateEdit widgets for
1002 properties created by QtDatePropertyManager objects.
1003
1004 \sa QtAbstractEditorFactory, QtDatePropertyManager
1005*/
1006
1007/*!
1008 Creates a factory with the given \a parent.
1009*/
1010QtDateEditFactory::QtDateEditFactory(QObject *parent)
1011 : QtAbstractEditorFactory<QtDatePropertyManager>(parent), d_ptr(new QtDateEditFactoryPrivate())
1012{
1013 d_ptr->q_ptr = this;
1014
1015}
1016
1017/*!
1018 Destroys this factory, and all the widgets it has created.
1019*/
1021{
1022 d_ptr->deleteEditors();
1023}
1024
1025/*!
1026 \internal
1027
1028 Reimplemented from the QtAbstractEditorFactory class.
1029*/
1031{
1032 connect(manager, &QtDatePropertyManager::valueChanged,
1033 this, [this](QtProperty *property, QDate value)
1034 { d_ptr->slotPropertyChanged(property, value); });
1035 connect(manager, &QtDatePropertyManager::rangeChanged,
1036 this, [this](QtProperty *property, QDate min, QDate max)
1037 { d_ptr->slotRangeChanged(property, min, max); });
1038}
1039
1040/*!
1041 \internal
1042
1043 Reimplemented from the QtAbstractEditorFactory class.
1044*/
1046 QWidget *parent)
1047{
1048 QDateEdit *editor = d_ptr->createEditor(property, parent);
1049 editor->setDisplayFormat(QtPropertyBrowserUtils::dateFormat());
1050 editor->setCalendarPopup(true);
1051 editor->setDateRange(manager->minimum(property), manager->maximum(property));
1052 editor->setDate(manager->value(property));
1053
1054 connect(editor, &QDateEdit::dateChanged,
1055 this, [this, property](QDate value) { d_ptr->slotSetValue(property, value); });
1056 connect(editor, &QObject::destroyed,
1057 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
1058 return editor;
1059}
1060
1061/*!
1062 \internal
1063
1064 Reimplemented from the QtAbstractEditorFactory class.
1065*/
1067{
1068 disconnect(manager, &QtDatePropertyManager::valueChanged, this, nullptr);
1069 disconnect(manager, &QtDatePropertyManager::rangeChanged, this, nullptr);
1070}
1071
1072// QtTimeEditFactory
1073
1075{
1076 QtTimeEditFactory *q_ptr = nullptr;
1077 Q_DECLARE_PUBLIC(QtTimeEditFactory)
1078public:
1079
1081 void slotSetValue(QtProperty *property, QTime value);
1082};
1083
1084void QtTimeEditFactoryPrivate::slotPropertyChanged(QtProperty *property, QTime value)
1085{
1086 const auto it = m_createdEditors.constFind(property);
1087 if (it == m_createdEditors.constEnd())
1088 return;
1089 for (QTimeEdit *editor : it.value()) {
1090 editor->blockSignals(true);
1091 editor->setTime(value);
1092 editor->blockSignals(false);
1093 }
1094}
1095
1097{
1098 if (QtTimePropertyManager *manager = q_ptr->propertyManager(property))
1099 manager->setValue(property, value);
1100}
1101
1102/*!
1103 \class QtTimeEditFactory
1104 \internal
1105 \inmodule QtDesigner
1106 \since 4.4
1107
1108 \brief The QtTimeEditFactory class provides QTimeEdit widgets for
1109 properties created by QtTimePropertyManager objects.
1110
1111 \sa QtAbstractEditorFactory, QtTimePropertyManager
1112*/
1113
1114/*!
1115 Creates a factory with the given \a parent.
1116*/
1117QtTimeEditFactory::QtTimeEditFactory(QObject *parent)
1118 : QtAbstractEditorFactory<QtTimePropertyManager>(parent), d_ptr(new QtTimeEditFactoryPrivate())
1119{
1120 d_ptr->q_ptr = this;
1121
1122}
1123
1124/*!
1125 Destroys this factory, and all the widgets it has created.
1126*/
1128{
1129 d_ptr->deleteEditors();
1130}
1131
1132/*!
1133 \internal
1134
1135 Reimplemented from the QtAbstractEditorFactory class.
1136*/
1138{
1139 connect(manager, &QtTimePropertyManager::valueChanged,
1140 this, [this](QtProperty *property, QTime value)
1141 { d_ptr->slotPropertyChanged(property, value); });
1142}
1143
1144/*!
1145 \internal
1146
1147 Reimplemented from the QtAbstractEditorFactory class.
1148*/
1150 QWidget *parent)
1151{
1152 QTimeEdit *editor = d_ptr->createEditor(property, parent);
1153 editor->setDisplayFormat(QtPropertyBrowserUtils::timeFormat());
1154 editor->setTime(manager->value(property));
1155
1156 connect(editor, &QTimeEdit::timeChanged,
1157 this, [this, property](QTime value) { d_ptr->slotSetValue(property, value); });
1158 connect(editor, &QObject::destroyed,
1159 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
1160 return editor;
1161}
1162
1163/*!
1164 \internal
1165
1166 Reimplemented from the QtAbstractEditorFactory class.
1167*/
1169{
1170 disconnect(manager, &QtTimePropertyManager::valueChanged, this, nullptr);
1171}
1172
1173#if QT_CONFIG(datetimeedit)
1174// QtDateTimeEditFactory
1175
1176class QtDateTimeEditFactoryPrivate : public EditorFactoryPrivate<QDateTimeEdit>
1177{
1178 QtDateTimeEditFactory *q_ptr = nullptr;
1179 Q_DECLARE_PUBLIC(QtDateTimeEditFactory)
1180public:
1181
1182 void slotPropertyChanged(QtProperty *property, const QDateTime &value);
1183 void slotSetValue(QtProperty *property, const QDateTime &value);
1184
1185};
1186
1187void QtDateTimeEditFactoryPrivate::slotPropertyChanged(QtProperty *property,
1188 const QDateTime &value)
1189{
1190 const auto it = m_createdEditors.constFind(property);
1191 if (it == m_createdEditors.constEnd())
1192 return;
1193
1194 for (QDateTimeEdit *editor : it.value()) {
1195 editor->blockSignals(true);
1196 editor->setDateTime(value);
1197 editor->blockSignals(false);
1198 }
1199}
1200
1201void QtDateTimeEditFactoryPrivate::slotSetValue(QtProperty *property, const QDateTime &value)
1202{
1203 if (QtDateTimePropertyManager *manager = q_ptr->propertyManager(property))
1204 manager->setValue(property, value);
1205}
1206
1207/*!
1208 \class QtDateTimeEditFactory
1209 \internal
1210 \inmodule QtDesigner
1211 \since 4.4
1212
1213 \brief The QtDateTimeEditFactory class provides QDateTimeEdit
1214 widgets for properties created by QtDateTimePropertyManager objects.
1215
1216 \sa QtAbstractEditorFactory, QtDateTimePropertyManager
1217*/
1218
1219/*!
1220 Creates a factory with the given \a parent.
1221*/
1222QtDateTimeEditFactory::QtDateTimeEditFactory(QObject *parent)
1223 : QtAbstractEditorFactory<QtDateTimePropertyManager>(parent), d_ptr(new QtDateTimeEditFactoryPrivate())
1224{
1225 d_ptr->q_ptr = this;
1226
1227}
1228
1229/*!
1230 Destroys this factory, and all the widgets it has created.
1231*/
1232QtDateTimeEditFactory::~QtDateTimeEditFactory()
1233{
1234 d_ptr->deleteEditors();
1235}
1236
1237/*!
1238 \internal
1239
1240 Reimplemented from the QtAbstractEditorFactory class.
1241*/
1242void QtDateTimeEditFactory::connectPropertyManager(QtDateTimePropertyManager *manager)
1243{
1244 connect(manager, &QtDateTimePropertyManager::valueChanged,
1245 this, [this](QtProperty *property, const QDateTime &value)
1246 { d_ptr->slotPropertyChanged(property, value); });
1247}
1248
1249/*!
1250 \internal
1251
1252 Reimplemented from the QtAbstractEditorFactory class.
1253*/
1254QWidget *QtDateTimeEditFactory::createEditor(QtDateTimePropertyManager *manager,
1255 QtProperty *property, QWidget *parent)
1256{
1257 QDateTimeEdit *editor = d_ptr->createEditor(property, parent);
1258 editor->setDisplayFormat(QtPropertyBrowserUtils::dateTimeFormat());
1259 editor->setDateTime(manager->value(property));
1260
1261 connect(editor, &QDateTimeEdit::dateTimeChanged,
1262 this, [this, property](const QDateTime &value) { d_ptr->slotSetValue(property, value); });
1263 connect(editor, &QObject::destroyed,
1264 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
1265 return editor;
1266}
1267
1268/*!
1269 \internal
1270
1271 Reimplemented from the QtAbstractEditorFactory class.
1272*/
1273void QtDateTimeEditFactory::disconnectPropertyManager(QtDateTimePropertyManager *manager)
1274{
1275 disconnect(manager, &QtDateTimePropertyManager::valueChanged, this, nullptr);
1276}
1277#endif // datetimeedit
1278
1279// QtKeySequenceEditorFactory
1280
1282{
1283 QtKeySequenceEditorFactory *q_ptr = nullptr;
1284 Q_DECLARE_PUBLIC(QtKeySequenceEditorFactory)
1285public:
1286
1288 void slotSetValue(QtProperty *property, const QKeySequence &value);
1289};
1290
1291void QtKeySequenceEditorFactoryPrivate::slotPropertyChanged(QtProperty *property,
1292 const QKeySequence &value)
1293{
1294 const auto it = m_createdEditors.constFind(property);
1295 if (it == m_createdEditors.constEnd())
1296 return;
1297
1298 for (QKeySequenceEdit *editor : it.value()) {
1299 editor->blockSignals(true);
1300 editor->setKeySequence(value);
1301 editor->blockSignals(false);
1302 }
1303}
1304
1305void QtKeySequenceEditorFactoryPrivate::slotSetValue(QtProperty *property, const QKeySequence &value)
1306{
1307 if (QtKeySequencePropertyManager *manager = q_ptr->propertyManager(property))
1308 manager->setValue(property, value);
1309}
1310
1311/*!
1312 \class QtKeySequenceEditorFactory
1313 \internal
1314 \inmodule QtDesigner
1315 \since 4.4
1316
1317 \brief The QtKeySequenceEditorFactory class provides editor
1318 widgets for properties created by QtKeySequencePropertyManager objects.
1319
1320 \sa QtAbstractEditorFactory
1321*/
1322
1323/*!
1324 Creates a factory with the given \a parent.
1325*/
1326QtKeySequenceEditorFactory::QtKeySequenceEditorFactory(QObject *parent)
1327 : QtAbstractEditorFactory<QtKeySequencePropertyManager>(parent), d_ptr(new QtKeySequenceEditorFactoryPrivate())
1328{
1329 d_ptr->q_ptr = this;
1330
1331}
1332
1333/*!
1334 Destroys this factory, and all the widgets it has created.
1335*/
1337{
1338 d_ptr->deleteEditors();
1339}
1340
1341/*!
1342 \internal
1343
1344 Reimplemented from the QtAbstractEditorFactory class.
1345*/
1347{
1348 connect(manager, &QtKeySequencePropertyManager::valueChanged,
1349 this, [this](QtProperty *property, const QKeySequence &value)
1350 { d_ptr->slotPropertyChanged(property, value); });
1351}
1352
1353/*!
1354 \internal
1355
1356 Reimplemented from the QtAbstractEditorFactory class.
1357*/
1359 QtProperty *property, QWidget *parent)
1360{
1361 QKeySequenceEdit *editor = d_ptr->createEditor(property, parent);
1362 editor->setKeySequence(manager->value(property));
1363
1364 connect(editor, &QKeySequenceEdit::keySequenceChanged,
1365 this, [this, property](const QKeySequence &value) { d_ptr->slotSetValue(property, value); });
1366 connect(editor, &QObject::destroyed,
1367 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
1368 return editor;
1369}
1370
1371/*!
1372 \internal
1373
1374 Reimplemented from the QtAbstractEditorFactory class.
1375*/
1377{
1378 disconnect(manager, &QtKeySequencePropertyManager::valueChanged, this, nullptr);
1379}
1380
1381// QtCharEdit
1382
1383class QtCharEdit : public QWidget
1384{
1385 Q_OBJECT
1386public:
1388
1389 QChar value() const;
1390 bool eventFilter(QObject *o, QEvent *e) override;
1391public Q_SLOTS:
1392 void setValue(const QChar &value);
1393Q_SIGNALS:
1395protected:
1396 void focusInEvent(QFocusEvent *e) override;
1397 void focusOutEvent(QFocusEvent *e) override;
1398 void keyPressEvent(QKeyEvent *e) override;
1399 void keyReleaseEvent(QKeyEvent *e) override;
1400 bool event(QEvent *e) override;
1401private slots:
1402 void slotClearChar();
1403private:
1404 void handleKeyEvent(QKeyEvent *e);
1405
1406 QChar m_value;
1407 QLineEdit *m_lineEdit;
1408};
1409
1410QtCharEdit::QtCharEdit(QWidget *parent)
1411 : QWidget(parent), m_lineEdit(new QLineEdit(this))
1412{
1413 auto *layout = new QHBoxLayout(this);
1414 layout->addWidget(m_lineEdit);
1415 layout->setContentsMargins(QMargins());
1416 m_lineEdit->installEventFilter(this);
1417 m_lineEdit->setReadOnly(true);
1418 m_lineEdit->setFocusProxy(this);
1419 setFocusPolicy(m_lineEdit->focusPolicy());
1420 setAttribute(Qt::WA_InputMethodEnabled);
1421}
1422
1423bool QtCharEdit::eventFilter(QObject *o, QEvent *e)
1424{
1425 if (o == m_lineEdit && e->type() == QEvent::ContextMenu) {
1426 QContextMenuEvent *c = static_cast<QContextMenuEvent *>(e);
1427 QMenu *menu = m_lineEdit->createStandardContextMenu();
1428 const auto actions = menu->actions();
1429 for (QAction *action : actions) {
1430 action->setShortcut(QKeySequence());
1431 QString actionString = action->text();
1432 const auto pos = actionString.lastIndexOf(QLatin1Char('\t'));
1433 if (pos > 0)
1434 actionString = actionString.remove(pos, actionString.size() - pos);
1435 action->setText(actionString);
1436 }
1437 QAction *actionBefore = nullptr;
1438 if (!actions.empty())
1439 actionBefore = actions[0];
1440 auto *clearAction = new QAction(tr("Clear Char"), menu);
1441 menu->insertAction(actionBefore, clearAction);
1442 menu->insertSeparator(actionBefore);
1443 clearAction->setEnabled(!m_value.isNull());
1444 connect(clearAction, &QAction::triggered, this, &QtCharEdit::slotClearChar);
1445 menu->exec(c->globalPos());
1446 delete menu;
1447 e->accept();
1448 return true;
1449 }
1450
1451 return QWidget::eventFilter(o, e);
1452}
1453
1454void QtCharEdit::slotClearChar()
1455{
1456 if (m_value.isNull())
1457 return;
1458 setValue(QChar());
1459 emit valueChanged(m_value);
1460}
1461
1462void QtCharEdit::handleKeyEvent(QKeyEvent *e)
1463{
1464 const int key = e->key();
1465 switch (key) {
1466 case Qt::Key_Control:
1467 case Qt::Key_Shift:
1468 case Qt::Key_Meta:
1469 case Qt::Key_Alt:
1470 case Qt::Key_Super_L:
1471 case Qt::Key_Return:
1472 return;
1473 default:
1474 break;
1475 }
1476
1477 const QString text = e->text();
1478 if (text.size() != 1)
1479 return;
1480
1481 const QChar c = text.at(0);
1482 if (!c.isPrint())
1483 return;
1484
1485 if (m_value == c)
1486 return;
1487
1488 m_value = c;
1489 const QString str = m_value.isNull() ? QString() : QString(m_value);
1490 m_lineEdit->setText(str);
1491 e->accept();
1492 emit valueChanged(m_value);
1493}
1494
1495void QtCharEdit::setValue(const QChar &value)
1496{
1497 if (value == m_value)
1498 return;
1499
1500 m_value = value;
1501 QString str = value.isNull() ? QString() : QString(value);
1502 m_lineEdit->setText(str);
1503}
1504
1506{
1507 return m_value;
1508}
1509
1510void QtCharEdit::focusInEvent(QFocusEvent *e)
1511{
1512 m_lineEdit->event(e);
1513 m_lineEdit->selectAll();
1514 QWidget::focusInEvent(e);
1515}
1516
1517void QtCharEdit::focusOutEvent(QFocusEvent *e)
1518{
1519 m_lineEdit->event(e);
1520 QWidget::focusOutEvent(e);
1521}
1522
1523void QtCharEdit::keyPressEvent(QKeyEvent *e)
1524{
1525 handleKeyEvent(e);
1526 e->accept();
1527}
1528
1529void QtCharEdit::keyReleaseEvent(QKeyEvent *e)
1530{
1531 m_lineEdit->event(e);
1532}
1533
1534bool QtCharEdit::event(QEvent *e)
1535{
1536 switch(e->type()) {
1537 case QEvent::Shortcut:
1538 case QEvent::ShortcutOverride:
1539 case QEvent::KeyRelease:
1540 e->accept();
1541 return true;
1542 default:
1543 break;
1544 }
1545 return QWidget::event(e);
1546}
1547
1548// QtCharEditorFactory
1549
1551{
1552 QtCharEditorFactory *q_ptr = nullptr;
1553 Q_DECLARE_PUBLIC(QtCharEditorFactory)
1554public:
1555
1557 void slotSetValue(QtProperty *property, const QChar &value);
1558
1559};
1560
1561void QtCharEditorFactoryPrivate::slotPropertyChanged(QtProperty *property,
1562 const QChar &value)
1563{
1564 const auto it = m_createdEditors.constFind(property);
1565 if (it == m_createdEditors.constEnd())
1566 return;
1567
1568 for (QtCharEdit *editor : it.value()) {
1569 editor->blockSignals(true);
1570 editor->setValue(value);
1571 editor->blockSignals(false);
1572 }
1573}
1574
1575void QtCharEditorFactoryPrivate::slotSetValue(QtProperty *property, const QChar &value)
1576{
1577 if (QtCharPropertyManager *manager = q_ptr->propertyManager(property))
1578 manager->setValue(property, value);
1579}
1580
1581/*!
1582 \class QtCharEditorFactory
1583 \internal
1584 \inmodule QtDesigner
1585 \since 4.4
1586
1587 \brief The QtCharEditorFactory class provides editor
1588 widgets for properties created by QtCharPropertyManager objects.
1589
1590 \sa QtAbstractEditorFactory
1591*/
1592
1593/*!
1594 Creates a factory with the given \a parent.
1595*/
1596QtCharEditorFactory::QtCharEditorFactory(QObject *parent)
1597 : QtAbstractEditorFactory<QtCharPropertyManager>(parent), d_ptr(new QtCharEditorFactoryPrivate())
1598{
1599 d_ptr->q_ptr = this;
1600
1601}
1602
1603/*!
1604 Destroys this factory, and all the widgets it has created.
1605*/
1607{
1608 d_ptr->deleteEditors();
1609}
1610
1611/*!
1612 \internal
1613
1614 Reimplemented from the QtAbstractEditorFactory class.
1615*/
1617{
1618 connect(manager, &QtCharPropertyManager::valueChanged,
1619 this, [this](QtProperty *property, const QChar &value)
1620 { d_ptr->slotPropertyChanged(property, value); });
1621}
1622
1623/*!
1624 \internal
1625
1626 Reimplemented from the QtAbstractEditorFactory class.
1627*/
1629 QtProperty *property, QWidget *parent)
1630{
1631 QtCharEdit *editor = d_ptr->createEditor(property, parent);
1632 editor->setValue(manager->value(property));
1633
1634 connect(editor, &QtCharEdit::valueChanged,
1635 this, [this, property](const QChar &value) { d_ptr->slotSetValue(property, value); });
1636 connect(editor, &QObject::destroyed,
1637 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
1638 return editor;
1639}
1640
1641/*!
1642 \internal
1643
1644 Reimplemented from the QtAbstractEditorFactory class.
1645*/
1647{
1648 disconnect(manager, &QtCharPropertyManager::valueChanged, this, nullptr);
1649}
1650
1651// QtEnumEditorFactory
1652
1654{
1655 QtEnumEditorFactory *q_ptr = nullptr;
1656 Q_DECLARE_PUBLIC(QtEnumEditorFactory)
1657public:
1658
1660 void slotEnumNamesChanged(QtProperty *property, const QStringList &);
1661 void slotEnumIconsChanged(QtProperty *property, const QMap<int, QIcon> &);
1662 void slotSetValue(QtProperty *property, int value);
1663};
1664
1665void QtEnumEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, int value)
1666{
1667 const auto it = m_createdEditors.constFind(property);
1668 if (it == m_createdEditors.constEnd())
1669 return;
1670
1671 for (QComboBox *editor : it.value()) {
1672 editor->blockSignals(true);
1673 editor->setCurrentIndex(value);
1674 editor->blockSignals(false);
1675 }
1676}
1677
1679 const QStringList &enumNames)
1680{
1681 const auto it = m_createdEditors.constFind(property);
1682 if (it == m_createdEditors.constEnd())
1683 return;
1684
1685 QtEnumPropertyManager *manager = q_ptr->propertyManager(property);
1686 if (!manager)
1687 return;
1688
1689 QMap<int, QIcon> enumIcons = manager->enumIcons(property);
1690
1691 for (QComboBox *editor : it.value()) {
1692 editor->blockSignals(true);
1693 editor->clear();
1694 editor->addItems(enumNames);
1695 const auto nameCount = enumNames.size();
1696 for (qsizetype i = 0; i < nameCount; i++)
1697 editor->setItemIcon(i, enumIcons.value(i));
1698 editor->setCurrentIndex(manager->value(property));
1699 editor->blockSignals(false);
1700 }
1701}
1702
1704 const QMap<int, QIcon> &enumIcons)
1705{
1706 const auto it = m_createdEditors.constFind(property);
1707 if (it == m_createdEditors.constEnd())
1708 return;
1709
1710 QtEnumPropertyManager *manager = q_ptr->propertyManager(property);
1711 if (!manager)
1712 return;
1713
1714 const QStringList enumNames = manager->enumNames(property);
1715 for (QComboBox *editor : it.value()) {
1716 editor->blockSignals(true);
1717 const auto nameCount = enumNames.size();
1718 for (qsizetype i = 0; i < nameCount; i++)
1719 editor->setItemIcon(i, enumIcons.value(i));
1720 editor->setCurrentIndex(manager->value(property));
1721 editor->blockSignals(false);
1722 }
1723}
1724
1726{
1727 if (QtEnumPropertyManager *manager = q_ptr->propertyManager(property))
1728 manager->setValue(property, value);
1729}
1730
1731/*!
1732 \class QtEnumEditorFactory
1733 \internal
1734 \inmodule QtDesigner
1735 \since 4.4
1736
1737 \brief The QtEnumEditorFactory class provides QComboBox widgets for
1738 properties created by QtEnumPropertyManager objects.
1739
1740 \sa QtAbstractEditorFactory, QtEnumPropertyManager
1741*/
1742
1743/*!
1744 Creates a factory with the given \a parent.
1745*/
1746QtEnumEditorFactory::QtEnumEditorFactory(QObject *parent)
1747 : QtAbstractEditorFactory<QtEnumPropertyManager>(parent), d_ptr(new QtEnumEditorFactoryPrivate())
1748{
1749 d_ptr->q_ptr = this;
1750
1751}
1752
1753/*!
1754 Destroys this factory, and all the widgets it has created.
1755*/
1757{
1758 d_ptr->deleteEditors();
1759}
1760
1761/*!
1762 \internal
1763
1764 Reimplemented from the QtAbstractEditorFactory class.
1765*/
1767{
1768 connect(manager, &QtEnumPropertyManager::valueChanged,
1769 this, [this](QtProperty *property, int value)
1770 { d_ptr->slotPropertyChanged(property, value); });
1771 connect(manager, &QtEnumPropertyManager::enumNamesChanged,
1772 this, [this](QtProperty *property, const QStringList &value)
1773 { d_ptr->slotEnumNamesChanged(property, value); });
1774}
1775
1776/*!
1777 \internal
1778
1779 Reimplemented from the QtAbstractEditorFactory class.
1780*/
1782 QWidget *parent)
1783{
1784 QComboBox *editor = d_ptr->createEditor(property, parent);
1785 editor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
1786 editor->view()->setTextElideMode(Qt::ElideRight);
1787 QStringList enumNames = manager->enumNames(property);
1788 editor->addItems(enumNames);
1789 QMap<int, QIcon> enumIcons = manager->enumIcons(property);
1790 const auto enumNamesCount = enumNames.size();
1791 for (qsizetype i = 0; i < enumNamesCount; i++)
1792 editor->setItemIcon(i, enumIcons.value(i));
1793 editor->setCurrentIndex(manager->value(property));
1794
1795 connect(editor, &QComboBox::currentIndexChanged,
1796 this, [this, property](int value) { d_ptr->slotSetValue(property, value); });
1797 connect(editor, &QObject::destroyed,
1798 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
1799 return editor;
1800}
1801
1802/*!
1803 \internal
1804
1805 Reimplemented from the QtAbstractEditorFactory class.
1806*/
1808{
1809 disconnect(manager, &QtEnumPropertyManager::valueChanged, this, nullptr);
1810 disconnect(manager, &QtEnumPropertyManager::enumNamesChanged, this, nullptr);
1811}
1812
1813// QtCursorEditorFactory
1814
1833
1834void QtCursorEditorFactoryPrivate::slotPropertyChanged(QtProperty *property, const QCursor &cursor)
1835{
1836 // update enum property
1837 QtProperty *enumProp = m_propertyToEnum.value(property);
1838 if (!enumProp)
1839 return;
1840
1841 m_updatingEnum = true;
1842 auto *cdb = QtCursorDatabase::instance();
1843 m_enumPropertyManager->setValue(enumProp, cdb->cursorToValue(cursor));
1844 m_updatingEnum = false;
1845}
1846
1848{
1849 if (m_updatingEnum)
1850 return;
1851 // update cursor property
1852 QtProperty *prop = m_enumToProperty.value(property);
1853 if (!prop)
1854 return;
1855 QtCursorPropertyManager *cursorManager = q_ptr->propertyManager(prop);
1856 if (!cursorManager)
1857 return;
1858#ifndef QT_NO_CURSOR
1859 auto *cdb = QtCursorDatabase::instance();
1860 cursorManager->setValue(prop, QCursor(cdb->valueToCursor(value)));
1861#endif
1862}
1863
1865{
1866 // remove from m_editorToEnum map;
1867 // remove from m_enumToEditors map;
1868 // if m_enumToEditors doesn't contains more editors delete enum property;
1869 for (auto itEditor = m_editorToEnum.cbegin(), ecend = m_editorToEnum.cend(); itEditor != ecend; ++itEditor)
1870 if (itEditor.key() == object) {
1871 QWidget *editor = itEditor.key();
1872 QtProperty *enumProp = itEditor.value();
1873 m_editorToEnum.remove(editor);
1874 m_enumToEditors[enumProp].removeAll(editor);
1875 if (m_enumToEditors[enumProp].isEmpty()) {
1876 m_enumToEditors.remove(enumProp);
1877 QtProperty *property = m_enumToProperty.value(enumProp);
1878 m_enumToProperty.remove(enumProp);
1879 m_propertyToEnum.remove(property);
1880 delete enumProp;
1881 }
1882 return;
1883 }
1884}
1885
1886/*!
1887 \class QtCursorEditorFactory
1888 \internal
1889 \inmodule QtDesigner
1890 \since 4.4
1891
1892 \brief The QtCursorEditorFactory class provides QComboBox widgets for
1893 properties created by QtCursorPropertyManager objects.
1894
1895 \sa QtAbstractEditorFactory, QtCursorPropertyManager
1896*/
1897
1898/*!
1899 Creates a factory with the given \a parent.
1900*/
1901QtCursorEditorFactory::QtCursorEditorFactory(QObject *parent)
1902 : QtAbstractEditorFactory<QtCursorPropertyManager>(parent), d_ptr(new QtCursorEditorFactoryPrivate())
1903{
1904 d_ptr->q_ptr = this;
1905
1906 d_ptr->m_enumEditorFactory = new QtEnumEditorFactory(this);
1907 d_ptr->m_enumPropertyManager = new QtEnumPropertyManager(this);
1908 connect(d_ptr->m_enumPropertyManager, &QtEnumPropertyManager::valueChanged,
1909 this, [this](QtProperty *property, int value)
1910 { d_ptr->slotEnumChanged(property, value); });
1911 d_ptr->m_enumEditorFactory->addPropertyManager(d_ptr->m_enumPropertyManager);
1912}
1913
1914/*!
1915 Destroys this factory, and all the widgets it has created.
1916*/
1918
1919/*!
1920 \internal
1921
1922 Reimplemented from the QtAbstractEditorFactory class.
1923*/
1925{
1926 connect(manager, &QtCursorPropertyManager::valueChanged,
1927 this, [this](QtProperty *property, const QCursor &value)
1928 { d_ptr->slotPropertyChanged(property, value); });
1929}
1930
1931/*!
1932 \internal
1933
1934 Reimplemented from the QtAbstractEditorFactory class.
1935*/
1937 QWidget *parent)
1938{
1939 QtProperty *enumProp = d_ptr->m_propertyToEnum.value(property, nullptr);
1940 if (enumProp == nullptr) {
1941 enumProp = d_ptr->m_enumPropertyManager->addProperty(property->propertyName());
1942 auto *cdb = QtCursorDatabase::instance();
1943 d_ptr->m_enumPropertyManager->setEnumNames(enumProp, cdb->cursorShapeNames());
1944 d_ptr->m_enumPropertyManager->setEnumIcons(enumProp, cdb->cursorShapeIcons());
1945#ifndef QT_NO_CURSOR
1946 d_ptr->m_enumPropertyManager->setValue(enumProp, cdb->cursorToValue(manager->value(property)));
1947#endif
1948 d_ptr->m_propertyToEnum[property] = enumProp;
1949 d_ptr->m_enumToProperty[enumProp] = property;
1950 }
1951 QtAbstractEditorFactoryBase *af = d_ptr->m_enumEditorFactory;
1952 QWidget *editor = af->createEditor(enumProp, parent);
1953 d_ptr->m_enumToEditors[enumProp].append(editor);
1954 d_ptr->m_editorToEnum[editor] = enumProp;
1955 connect(editor, &QObject::destroyed,
1956 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
1957 return editor;
1958}
1959
1960/*!
1961 \internal
1962
1963 Reimplemented from the QtAbstractEditorFactory class.
1964*/
1966{
1967 disconnect(manager, &QtCursorPropertyManager::valueChanged, this, nullptr);
1968}
1969
1970// QtColorEditWidget
1971
1973 Q_OBJECT
1974
1975public:
1977
1978 bool eventFilter(QObject *obj, QEvent *ev) override;
1979
1980public Q_SLOTS:
1982
1983private Q_SLOTS:
1984 void buttonClicked();
1985
1986Q_SIGNALS:
1988
1989private:
1990 void updateColor();
1991
1992 QColor m_color;
1993 QLabel *m_pixmapLabel;
1994 QLabel *m_label;
1995 QToolButton *m_button;
1996};
1997
1998QtColorEditWidget::QtColorEditWidget(QWidget *parent) :
1999 QWidget(parent),
2000 m_pixmapLabel(new QLabel),
2001 m_label(new QLabel),
2002 m_button(new QToolButton)
2003{
2004 auto *lt = new QHBoxLayout(this);
2005 setupTreeViewEditorMargin(lt);
2006 lt->setSpacing(0);
2007 lt->addWidget(m_pixmapLabel);
2008 lt->addWidget(m_label);
2009 lt->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));
2010
2011 m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
2012 m_button->setFixedWidth(20);
2013 setFocusProxy(m_button);
2014 setFocusPolicy(m_button->focusPolicy());
2015 m_button->setText(tr("..."));
2016 m_button->installEventFilter(this);
2017 connect(m_button, &QAbstractButton::clicked, this, &QtColorEditWidget::buttonClicked);
2018 lt->addWidget(m_button);
2019 updateColor();
2020}
2021
2022void QtColorEditWidget::setValue(QColor c)
2023{
2024 if (m_color != c) {
2025 m_color = c;
2026 updateColor();
2027 }
2028}
2029
2030void QtColorEditWidget::updateColor()
2031{
2032 const auto pm =
2033 QtPropertyBrowserUtils::brushValuePixmap(QBrush(m_color),
2034 QtPropertyBrowserUtils::itemViewIconSize,
2035 devicePixelRatioF());
2036 m_pixmapLabel->setPixmap(pm);
2037 m_label->setText(QtPropertyBrowserUtils::colorValueText(m_color));
2038}
2039
2040void QtColorEditWidget::buttonClicked()
2041{
2042 const QColor newColor = QColorDialog::getColor(m_color, this, QString(), QColorDialog::ShowAlphaChannel);
2043 if (newColor.isValid() && newColor != m_color) {
2044 setValue(newColor);
2045 emit valueChanged(m_color);
2046 }
2047}
2048
2049bool QtColorEditWidget::eventFilter(QObject *obj, QEvent *ev)
2050{
2051 if (obj == m_button) {
2052 switch (ev->type()) {
2053 case QEvent::KeyPress:
2054 case QEvent::KeyRelease: { // Prevent the QToolButton from handling Enter/Escape meant control the delegate
2055 switch (static_cast<const QKeyEvent*>(ev)->key()) {
2056 case Qt::Key_Escape:
2057 case Qt::Key_Enter:
2058 case Qt::Key_Return:
2059 ev->ignore();
2060 return true;
2061 default:
2062 break;
2063 }
2064 }
2065 break;
2066 default:
2067 break;
2068 }
2069 }
2070 return QWidget::eventFilter(obj, ev);
2071}
2072
2073// QtColorEditorFactoryPrivate
2074
2075class QtColorEditorFactoryPrivate : public EditorFactoryPrivate<QtColorEditWidget>
2076{
2077 QtColorEditorFactory *q_ptr = nullptr;
2078 Q_DECLARE_PUBLIC(QtColorEditorFactory)
2079public:
2080
2081 void slotPropertyChanged(QtProperty *property, QColor value);
2082 void slotSetValue(QtProperty *property, QColor value);
2083};
2084
2085void QtColorEditorFactoryPrivate::slotPropertyChanged(QtProperty *property,
2086 QColor value)
2087{
2088 const auto it = m_createdEditors.constFind(property);
2089 if (it == m_createdEditors.constEnd())
2090 return;
2091
2092 for (QtColorEditWidget *e : it.value())
2093 e->setValue(value);
2094}
2095
2096void QtColorEditorFactoryPrivate::slotSetValue(QtProperty *property, QColor value)
2097{
2098 if (QtColorPropertyManager *manager = q_ptr->propertyManager(property))
2099 manager->setValue(property, value);
2100}
2101
2102/*!
2103 \class QtColorEditorFactory
2104 \internal
2105 \inmodule QtDesigner
2106 \since 4.4
2107
2108 \brief The QtColorEditorFactory class provides color editing for
2109 properties created by QtColorPropertyManager objects.
2110
2111 \sa QtAbstractEditorFactory, QtColorPropertyManager
2112*/
2113
2114/*!
2115 Creates a factory with the given \a parent.
2116*/
2117QtColorEditorFactory::QtColorEditorFactory(QObject *parent) :
2118 QtAbstractEditorFactory<QtColorPropertyManager>(parent),
2119 d_ptr(new QtColorEditorFactoryPrivate())
2120{
2121 d_ptr->q_ptr = this;
2122}
2123
2124/*!
2125 Destroys this factory, and all the widgets it has created.
2126*/
2128{
2129 d_ptr->deleteEditors();
2130}
2131
2132/*!
2133 \internal
2134
2135 Reimplemented from the QtAbstractEditorFactory class.
2136*/
2138{
2139 connect(manager, &QtColorPropertyManager::valueChanged,
2140 this, [this](QtProperty *property, QColor value)
2141 { d_ptr->slotPropertyChanged(property, value); });
2142}
2143
2144/*!
2145 \internal
2146
2147 Reimplemented from the QtAbstractEditorFactory class.
2148*/
2150 QtProperty *property, QWidget *parent)
2151{
2152 QtColorEditWidget *editor = d_ptr->createEditor(property, parent);
2153 editor->setValue(manager->value(property));
2154 connect(editor, &QtColorEditWidget::valueChanged,
2155 this, [this, property](QColor value) { d_ptr->slotSetValue(property, value); });
2156 connect(editor, &QObject::destroyed,
2157 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
2158 return editor;
2159}
2160
2161/*!
2162 \internal
2163
2164 Reimplemented from the QtAbstractEditorFactory class.
2165*/
2167{
2168 disconnect(manager, &QtColorPropertyManager::valueChanged, this, nullptr);
2169}
2170
2171// QtFontEditWidget
2172
2174 Q_OBJECT
2175
2176public:
2178
2179 bool eventFilter(QObject *obj, QEvent *ev) override;
2180
2181public Q_SLOTS:
2182 void setValue(const QFont &value);
2183
2184private Q_SLOTS:
2185 void buttonClicked();
2186
2187Q_SIGNALS:
2189
2190private:
2191 void updateFont();
2192
2193 QFont m_font;
2194 QLabel *m_pixmapLabel;
2195 QLabel *m_label;
2196 QToolButton *m_button;
2197};
2198
2199QtFontEditWidget::QtFontEditWidget(QWidget *parent) :
2200 QWidget(parent),
2201 m_pixmapLabel(new QLabel),
2202 m_label(new QLabel),
2203 m_button(new QToolButton)
2204{
2205 auto *lt = new QHBoxLayout(this);
2206 setupTreeViewEditorMargin(lt);
2207 lt->setSpacing(0);
2208 lt->addWidget(m_pixmapLabel);
2209 lt->addWidget(m_label);
2210 lt->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));
2211
2212 m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored);
2213 m_button->setFixedWidth(20);
2214 setFocusProxy(m_button);
2215 setFocusPolicy(m_button->focusPolicy());
2216 m_button->setText(tr("..."));
2217 m_button->installEventFilter(this);
2218 connect(m_button, &QAbstractButton::clicked, this, &QtFontEditWidget::buttonClicked);
2219 lt->addWidget(m_button);
2220 updateFont();
2221}
2222
2223void QtFontEditWidget::updateFont()
2224{
2225 const auto pm = QtPropertyBrowserUtils::fontValuePixmap(
2226 m_font, QtPropertyBrowserUtils::itemViewIconSize, devicePixelRatioF());
2227 m_pixmapLabel->setPixmap(pm);
2228 m_label->setText(QtPropertyBrowserUtils::fontValueText(m_font));
2229}
2230
2231void QtFontEditWidget::setValue(const QFont &f)
2232{
2233 if (m_font != f) {
2234 m_font = f;
2235 updateFont();
2236 }
2237}
2238
2239void QtFontEditWidget::buttonClicked()
2240{
2241 bool ok = false;
2242 QFont newFont = QFontDialog::getFont(&ok, m_font, this, tr("Select Font"));
2243 if (ok && newFont != m_font) {
2244 QFont f = m_font;
2245 // prevent mask for unchanged attributes, don't change other attributes (like kerning, etc...)
2246 if (m_font.family() != newFont.family())
2247 f.setFamily(newFont.family());
2248 if (m_font.pointSize() != newFont.pointSize())
2249 f.setPointSize(newFont.pointSize());
2250 if (m_font.bold() != newFont.bold())
2251 f.setBold(newFont.bold());
2252 if (m_font.italic() != newFont.italic())
2253 f.setItalic(newFont.italic());
2254 if (m_font.underline() != newFont.underline())
2255 f.setUnderline(newFont.underline());
2256 if (m_font.strikeOut() != newFont.strikeOut())
2257 f.setStrikeOut(newFont.strikeOut());
2258 setValue(f);
2259 emit valueChanged(m_font);
2260 }
2261}
2262
2263bool QtFontEditWidget::eventFilter(QObject *obj, QEvent *ev)
2264{
2265 if (obj == m_button) {
2266 switch (ev->type()) {
2267 case QEvent::KeyPress:
2268 case QEvent::KeyRelease: { // Prevent the QToolButton from handling Enter/Escape meant control the delegate
2269 switch (static_cast<const QKeyEvent*>(ev)->key()) {
2270 case Qt::Key_Escape:
2271 case Qt::Key_Enter:
2272 case Qt::Key_Return:
2273 ev->ignore();
2274 return true;
2275 default:
2276 break;
2277 }
2278 }
2279 break;
2280 default:
2281 break;
2282 }
2283 }
2284 return QWidget::eventFilter(obj, ev);
2285}
2286
2287// QtFontEditorFactoryPrivate
2288
2289class QtFontEditorFactoryPrivate : public EditorFactoryPrivate<QtFontEditWidget>
2290{
2291 QtFontEditorFactory *q_ptr = nullptr;
2292 Q_DECLARE_PUBLIC(QtFontEditorFactory)
2293public:
2294
2295 void slotPropertyChanged(QtProperty *property, const QFont &value);
2296 void slotSetValue(QtProperty *property, const QFont &value);
2297};
2298
2299void QtFontEditorFactoryPrivate::slotPropertyChanged(QtProperty *property,
2300 const QFont &value)
2301{
2302 const auto it = m_createdEditors.constFind(property);
2303 if (it == m_createdEditors.constEnd())
2304 return;
2305
2306 for (QtFontEditWidget *e : it.value())
2307 e->setValue(value);
2308}
2309
2310void QtFontEditorFactoryPrivate::slotSetValue(QtProperty *property, const QFont &value)
2311{
2312 if (QtFontPropertyManager *manager = q_ptr->propertyManager(property))
2313 manager->setValue(property, value);
2314}
2315
2316/*!
2317 \class QtFontEditorFactory
2318 \internal
2319 \inmodule QtDesigner
2320 \since 4.4
2321
2322 \brief The QtFontEditorFactory class provides font editing for
2323 properties created by QtFontPropertyManager objects.
2324
2325 \sa QtAbstractEditorFactory, QtFontPropertyManager
2326*/
2327
2328/*!
2329 Creates a factory with the given \a parent.
2330*/
2331QtFontEditorFactory::QtFontEditorFactory(QObject *parent) :
2332 QtAbstractEditorFactory<QtFontPropertyManager>(parent),
2333 d_ptr(new QtFontEditorFactoryPrivate())
2334{
2335 d_ptr->q_ptr = this;
2336}
2337
2338/*!
2339 Destroys this factory, and all the widgets it has created.
2340*/
2342{
2343 d_ptr->deleteEditors();
2344}
2345
2346/*!
2347 \internal
2348
2349 Reimplemented from the QtAbstractEditorFactory class.
2350*/
2352{
2353 connect(manager, &QtFontPropertyManager::valueChanged,
2354 this, [this](QtProperty *property, const QFont &value)
2355 { d_ptr->slotPropertyChanged(property, value); });
2356}
2357
2358/*!
2359 \internal
2360
2361 Reimplemented from the QtAbstractEditorFactory class.
2362*/
2364 QtProperty *property, QWidget *parent)
2365{
2366 QtFontEditWidget *editor = d_ptr->createEditor(property, parent);
2367 editor->setValue(manager->value(property));
2368 connect(editor, &QtFontEditWidget::valueChanged,
2369 this, [this, property](const QFont &value) { d_ptr->slotSetValue(property, value); });
2370 connect(editor, &QObject::destroyed,
2371 this, [this](QObject *object) { d_ptr->slotEditorDestroyed(object); });
2372 return editor;
2373}
2374
2375/*!
2376 \internal
2377
2378 Reimplemented from the QtAbstractEditorFactory class.
2379*/
2381{
2382 disconnect(manager, &QtFontPropertyManager::valueChanged, this, nullptr);
2383}
2384
2385QT_END_NAMESPACE
2386
2387#include "moc_qteditorfactory_p.cpp"
2388#include "qteditorfactory.moc"
PropertyToEditorListMap m_createdEditors
Editor * createEditor(QtProperty *property, QWidget *parent)
void initializeEditor(QtProperty *property, Editor *e)
void slotEditorDestroyed(QObject *object)
The QtAbstractEditorFactoryBase provides an interface for editor factories.
The QtBoolPropertyManager class provides and manages boolean properties.
bool value(const QtProperty *property) const
Returns the given property's value.
QChar value() const
void focusInEvent(QFocusEvent *e) override
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
void focusOutEvent(QFocusEvent *e) override
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
void keyPressEvent(QKeyEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
void keyReleaseEvent(QKeyEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
bool eventFilter(QObject *o, QEvent *e) override
Filters events if this object has been installed as an event filter for the watched object.
void slotSetValue(QtProperty *property, const QChar &value)
The QtCharEditorFactory class provides editor widgets for properties created by QtCharPropertyManager...
void disconnectPropertyManager(QtCharPropertyManager *manager) override
~QtCharEditorFactory() override
Destroys this factory, and all the widgets it has created.
void connectPropertyManager(QtCharPropertyManager *manager) override
QWidget * createEditor(QtCharPropertyManager *manager, QtProperty *property, QWidget *parent) override
The QtCharPropertyManager provides and manages QChar properties.
void slotSetValue(QtProperty *property, bool value)
The QtCheckBoxFactory class provides QCheckBox widgets for properties created by QtBoolPropertyManage...
~QtCheckBoxFactory() override
Destroys this factory, and all the widgets it has created.
QWidget * createEditor(QtBoolPropertyManager *manager, QtProperty *property, QWidget *parent) override
void disconnectPropertyManager(QtBoolPropertyManager *manager) override
void connectPropertyManager(QtBoolPropertyManager *manager) override
bool eventFilter(QObject *obj, QEvent *ev) override
Filters events if this object has been installed as an event filter for the watched object.
The QtColorEditorFactory class provides color editing for properties created by QtColorPropertyManage...
void disconnectPropertyManager(QtColorPropertyManager *manager) override
void connectPropertyManager(QtColorPropertyManager *manager) override
QWidget * createEditor(QtColorPropertyManager *manager, QtProperty *property, QWidget *parent) override
~QtColorEditorFactory() override
Destroys this factory, and all the widgets it has created.
The QtColorPropertyManager provides and manages QColor properties.
static QtCursorDatabase * instance()
QtEnumPropertyManager * m_enumPropertyManager
QHash< QWidget *, QtProperty * > m_editorToEnum
QHash< QtProperty *, QWidgetList > m_enumToEditors
QtEnumEditorFactory * m_enumEditorFactory
QHash< QtProperty *, QtProperty * > m_propertyToEnum
QHash< QtProperty *, QtProperty * > m_enumToProperty
void slotEnumChanged(QtProperty *property, int value)
void slotEditorDestroyed(QObject *object)
The QtCursorEditorFactory class provides QComboBox widgets for properties created by QtCursorProperty...
~QtCursorEditorFactory() override
Destroys this factory, and all the widgets it has created.
void disconnectPropertyManager(QtCursorPropertyManager *manager) override
void connectPropertyManager(QtCursorPropertyManager *manager) override
QWidget * createEditor(QtCursorPropertyManager *manager, QtProperty *property, QWidget *parent) override
The QtCursorPropertyManager provides and manages QCursor properties.
void slotSetValue(QtProperty *property, QDate value)
void slotRangeChanged(QtProperty *property, QDate min, QDate max)
The QtDateEditFactory class provides QDateEdit widgets for properties created by QtDatePropertyManage...
void disconnectPropertyManager(QtDatePropertyManager *manager) override
void connectPropertyManager(QtDatePropertyManager *manager) override
~QtDateEditFactory() override
Destroys this factory, and all the widgets it has created.
QWidget * createEditor(QtDatePropertyManager *manager, QtProperty *property, QWidget *parent) override
The QtDatePropertyManager provides and manages QDate properties.
void rangeChanged(QtProperty *property, QDate minVal, QDate maxVal)
This signal is emitted whenever a property created by this manager changes its range of valid dates,...
QDate minimum(const QtProperty *property) const
Returns the given property's minimum date.
QDate maximum(const QtProperty *property) const
Returns the given property's maximum date.
QDate value(const QtProperty *property) const
Returns the given property's value.
The QtDoublePropertyManager provides and manages double properties.
double singleStep(const QtProperty *property) const
Returns the given property's step value.
int decimals(const QtProperty *property) const
Returns the given property's precision, in decimals.
void singleStepChanged(QtProperty *property, double step)
This signal is emitted whenever a property created by this manager changes its single step property,...
void decimalsChanged(QtProperty *property, int prec)
This signal is emitted whenever a property created by this manager changes its precision of value,...
double minimum(const QtProperty *property) const
Returns the given property's minimum value.
double value(const QtProperty *property) const
Returns the given property's value.
void rangeChanged(QtProperty *property, double minVal, double maxVal)
This signal is emitted whenever a property created by this manager changes its range of valid values,...
double maximum(const QtProperty *property) const
Returns the given property's maximum value.
void slotSetValue(QtProperty *property, double value)
void slotSingleStepChanged(QtProperty *property, double step)
void slotDecimalsChanged(QtProperty *property, int prec)
void slotRangeChanged(QtProperty *property, double min, double max)
The QtDoubleSpinBoxFactory class provides QDoubleSpinBox widgets for properties created by QtDoublePr...
QWidget * createEditor(QtDoublePropertyManager *manager, QtProperty *property, QWidget *parent) override
void connectPropertyManager(QtDoublePropertyManager *manager) override
void disconnectPropertyManager(QtDoublePropertyManager *manager) override
~QtDoubleSpinBoxFactory() override
Destroys this factory, and all the widgets it has created.
void slotEnumNamesChanged(QtProperty *property, const QStringList &)
void slotEnumIconsChanged(QtProperty *property, const QMap< int, QIcon > &)
void slotSetValue(QtProperty *property, int value)
The QtEnumEditorFactory class provides QComboBox widgets for properties created by QtEnumPropertyMana...
~QtEnumEditorFactory() override
Destroys this factory, and all the widgets it has created.
QWidget * createEditor(QtEnumPropertyManager *manager, QtProperty *property, QWidget *parent) override
void disconnectPropertyManager(QtEnumPropertyManager *manager) override
void connectPropertyManager(QtEnumPropertyManager *manager) override
The QtEnumPropertyManager provides and manages enum properties.
int value(const QtProperty *property) const
Returns the given property's value which is an index in the list returned by enumNames().
bool eventFilter(QObject *obj, QEvent *ev) override
Filters events if this object has been installed as an event filter for the watched object.
The QtFontEditorFactory class provides font editing for properties created by QtFontPropertyManager o...
void disconnectPropertyManager(QtFontPropertyManager *manager) override
QWidget * createEditor(QtFontPropertyManager *manager, QtProperty *property, QWidget *parent) override
~QtFontEditorFactory() override
Destroys this factory, and all the widgets it has created.
void connectPropertyManager(QtFontPropertyManager *manager) override
The QtFontPropertyManager provides and manages QFont properties.
The QtIntPropertyManager provides and manages int properties.
void rangeChanged(QtProperty *property, int minVal, int maxVal)
This signal is emitted whenever a property created by this manager changes its range of valid values,...
void singleStepChanged(QtProperty *property, int step)
This signal is emitted whenever a property created by this manager changes its single step property,...
int singleStep(const QtProperty *property) const
Returns the given property's step value.
int minimum(const QtProperty *property) const
Returns the given property's minimum value.
int value(const QtProperty *property) const
Returns the given property's value.
int maximum(const QtProperty *property) const
Returns the given property's maximum value.
void slotSetValue(QtProperty *property, const QKeySequence &value)
The QtKeySequenceEditorFactory class provides editor widgets for properties created by QtKeySequenceP...
void connectPropertyManager(QtKeySequencePropertyManager *manager) override
~QtKeySequenceEditorFactory() override
Destroys this factory, and all the widgets it has created.
QWidget * createEditor(QtKeySequencePropertyManager *manager, QtProperty *property, QWidget *parent) override
void disconnectPropertyManager(QtKeySequencePropertyManager *manager) override
The QtKeySequencePropertyManager provides and manages QKeySequence properties.
void slotSetValue(QtProperty *property, const QString &value)
void slotRegExpChanged(QtProperty *property, const QRegularExpression &regExp)
The QtLineEditFactory class provides QLineEdit widgets for properties created by QtStringPropertyMana...
void disconnectPropertyManager(QtStringPropertyManager *manager) override
QWidget * createEditor(QtStringPropertyManager *manager, QtProperty *property, QWidget *parent) override
void connectPropertyManager(QtStringPropertyManager *manager) override
~QtLineEditFactory() override
Destroys this factory, and all the widgets it has created.
The QtProperty class encapsulates an instance of a property.
void slotSingleStepChanged(QtProperty *property, int step)
void slotRangeChanged(QtProperty *property, int min, int max)
void slotSetValue(QtProperty *property, int value)
The QtScrollBarFactory class provides QScrollBar widgets for properties created by QtIntPropertyManag...
~QtScrollBarFactory() override
Destroys this factory, and all the widgets it has created.
QWidget * createEditor(QtIntPropertyManager *manager, QtProperty *property, QWidget *parent) override
void connectPropertyManager(QtIntPropertyManager *manager) override
void disconnectPropertyManager(QtIntPropertyManager *manager) override
void slotSetValue(QtProperty *property, int value)
void slotSingleStepChanged(QtProperty *property, int step)
void slotRangeChanged(QtProperty *property, int min, int max)
The QtSliderFactory class provides QSlider widgets for properties created by QtIntPropertyManager obj...
void connectPropertyManager(QtIntPropertyManager *manager) override
void disconnectPropertyManager(QtIntPropertyManager *manager) override
QWidget * createEditor(QtIntPropertyManager *manager, QtProperty *property, QWidget *parent) override
~QtSliderFactory() override
Destroys this factory, and all the widgets it has created.
void slotRangeChanged(QtProperty *property, int min, int max)
void slotSetValue(QtProperty *property, int value)
void slotSingleStepChanged(QtProperty *property, int step)
The QtSpinBoxFactory class provides QSpinBox widgets for properties created by QtIntPropertyManager o...
void disconnectPropertyManager(QtIntPropertyManager *manager) override
void connectPropertyManager(QtIntPropertyManager *manager) override
~QtSpinBoxFactory() override
Destroys this factory, and all the widgets it has created.
QWidget * createEditor(QtIntPropertyManager *manager, QtProperty *property, QWidget *parent) override
The QtStringPropertyManager provides and manages QString properties.
void regExpChanged(QtProperty *property, const QRegularExpression &regExp)
This signal is emitted whenever a property created by this manager changes its currenlty set regular ...
void slotSetValue(QtProperty *property, QTime value)
The QtTimeEditFactory class provides QTimeEdit widgets for properties created by QtTimePropertyManage...
QWidget * createEditor(QtTimePropertyManager *manager, QtProperty *property, QWidget *parent) override
void disconnectPropertyManager(QtTimePropertyManager *manager) override
void connectPropertyManager(QtTimePropertyManager *manager) override
~QtTimeEditFactory() override
Destroys this factory, and all the widgets it has created.
The QtTimePropertyManager provides and manages QTime properties.
QTime value(const QtProperty *property) const
Returns the given property's value.
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE void setupTreeViewEditorMargin(QLayout *lt)