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