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