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