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
inplace_editor.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
7
8#include <QtDesigner/abstractformwindow.h>
9#include <QtDesigner/abstractformwindowcursor.h>
10#include <QtDesigner/propertysheet.h>
11#include <QtDesigner/abstractformeditor.h>
12#include <QtDesigner/abstractlanguage.h>
13#include <QtDesigner/qextensionmanager.h>
14
15#include <QtCore/qvariant.h>
16
18
19using namespace Qt::StringLiterals;
20
21namespace qdesigner_internal {
22
23// ----------------- InPlaceEditor
24
25InPlaceEditor::InPlaceEditor(QWidget *widget,
26 TextPropertyValidationMode validationMode,
27 QDesignerFormWindowInterface *fw,
28 const QString& text,
29 const QRect& r) :
30 TextPropertyEditor(widget, EmbeddingInPlace, validationMode),
31 m_InPlaceWidgetHelper(this, widget, fw)
32{
33 setAlignment(m_InPlaceWidgetHelper.alignment());
34 setObjectName(u"__qt__passive_m_editor"_s);
35
36 setText(text);
37 selectAll();
38
39 setGeometry(QRect(widget->mapTo(widget->window(), r.topLeft()), r.size()));
40 setFocus();
41 show();
42
43 connect(this, &TextPropertyEditor::editingFinished,this, &QWidget::close);
44}
45
46
47// -------------- TaskMenuInlineEditor
48
50 const QString &property, QObject *parent) :
52 m_vm(vm),
54 m_widget(w),
55 m_managed(true)
56{
57}
58
59void TaskMenuInlineEditor::editText()
60{
61 m_formWindow = QDesignerFormWindowInterface::findFormWindow(m_widget);
62 if (m_formWindow.isNull())
63 return;
64 m_managed = m_formWindow->isManaged(m_widget);
65 // Close as soon as a different widget is selected
66 connect(m_formWindow.data(), &QDesignerFormWindowInterface::selectionChanged,
67 this, &TaskMenuInlineEditor::updateSelection);
68
69 // get old value
70 QDesignerFormEditorInterface *core = m_formWindow->core();
71 const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), m_widget);
72 const int index = sheet->indexOf(m_property);
73 if (index == -1)
74 return;
75 m_value = qvariant_cast<PropertySheetStringValue>(sheet->property(index));
76 const QString oldValue = m_value.value();
77
78 m_editor = new InPlaceEditor(m_widget, m_vm, m_formWindow, oldValue, editRectangle());
79 connect(m_editor.data(), &InPlaceEditor::textChanged, this, &TaskMenuInlineEditor::updateText);
80}
81
82void TaskMenuInlineEditor::updateText(const QString &text)
83{
84 // In the [rare] event we are invoked on an unmanaged widget,
85 // do not use the cursor selection
86 m_value.setValue(text);
87 if (m_managed) {
88 m_formWindow->cursor()->setProperty(m_property, QVariant::fromValue(m_value));
89 } else {
90 m_formWindow->cursor()->setWidgetProperty(m_widget, m_property, QVariant::fromValue(m_value));
91 }
92}
93
94void TaskMenuInlineEditor::updateSelection()
95{
96 if (m_editor)
97 m_editor->deleteLater();
98}
99
100}
101
102QT_END_NAMESPACE
TaskMenuInlineEditor(QWidget *w, TextPropertyValidationMode vm, const QString &property, QObject *parent)
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.