1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | |
30 | #include "qdesigner_formwindowcommand_p.h" |
31 | #include "qdesigner_objectinspector_p.h" |
32 | #include "layout_p.h" |
33 | |
34 | #include <QtDesigner/abstractformeditor.h> |
35 | #include <QtDesigner/abstractformwindow.h> |
36 | #include <QtDesigner/abstractobjectinspector.h> |
37 | #include <QtDesigner/abstractactioneditor.h> |
38 | #include <QtDesigner/abstractmetadatabase.h> |
39 | #include <QtDesigner/propertysheet.h> |
40 | #include <QtDesigner/abstractpropertyeditor.h> |
41 | #include <QtDesigner/qextensionmanager.h> |
42 | |
43 | #include <QtCore/qvariant.h> |
44 | #include <QtWidgets/qwidget.h> |
45 | #include <QtWidgets/qlabel.h> |
46 | |
47 | QT_BEGIN_NAMESPACE |
48 | |
49 | namespace qdesigner_internal { |
50 | |
51 | // ---- QDesignerFormWindowCommand ---- |
52 | QDesignerFormWindowCommand::QDesignerFormWindowCommand(const QString &description, |
53 | QDesignerFormWindowInterface *formWindow, |
54 | QUndoCommand *parent) |
55 | : QUndoCommand(description, parent), |
56 | m_formWindow(formWindow) |
57 | { |
58 | } |
59 | |
60 | QDesignerFormWindowInterface *QDesignerFormWindowCommand::formWindow() const |
61 | { |
62 | return m_formWindow; |
63 | } |
64 | |
65 | QDesignerFormEditorInterface *QDesignerFormWindowCommand::core() const |
66 | { |
67 | if (QDesignerFormWindowInterface *fw = formWindow()) |
68 | return fw->core(); |
69 | |
70 | return nullptr; |
71 | } |
72 | |
73 | void QDesignerFormWindowCommand::undo() |
74 | { |
75 | cheapUpdate(); |
76 | } |
77 | |
78 | void QDesignerFormWindowCommand::redo() |
79 | { |
80 | cheapUpdate(); |
81 | } |
82 | |
83 | void QDesignerFormWindowCommand::cheapUpdate() |
84 | { |
85 | if (core()->objectInspector()) |
86 | core()->objectInspector()->setFormWindow(formWindow()); |
87 | |
88 | if (core()->actionEditor()) |
89 | core()->actionEditor()->setFormWindow(formWindow()); |
90 | } |
91 | |
92 | QDesignerPropertySheetExtension* QDesignerFormWindowCommand::propertySheet(QObject *object) const |
93 | { |
94 | return qt_extension<QDesignerPropertySheetExtension*>(manager: formWindow()->core()->extensionManager(), object); |
95 | } |
96 | |
97 | void QDesignerFormWindowCommand::updateBuddies(QDesignerFormWindowInterface *form, |
98 | const QString &old_name, |
99 | const QString &new_name) |
100 | { |
101 | QExtensionManager* extensionManager = form->core()->extensionManager(); |
102 | |
103 | const auto label_list = form->findChildren<QLabel*>(); |
104 | if (label_list.isEmpty()) |
105 | return; |
106 | |
107 | const QString buddyProperty = QStringLiteral("buddy" ); |
108 | const QByteArray oldNameU8 = old_name.toUtf8(); |
109 | const QByteArray newNameU8 = new_name.toUtf8(); |
110 | |
111 | for (QLabel *label : label_list) { |
112 | if (QDesignerPropertySheetExtension* sheet = |
113 | qt_extension<QDesignerPropertySheetExtension*>(manager: extensionManager, object: label)) { |
114 | const int idx = sheet->indexOf(name: buddyProperty); |
115 | if (idx != -1) { |
116 | const QByteArray oldBuddy = sheet->property(index: idx).toByteArray(); |
117 | if (oldBuddy == oldNameU8) |
118 | sheet->setProperty(index: idx, value: newNameU8); |
119 | } |
120 | } |
121 | } |
122 | } |
123 | |
124 | void QDesignerFormWindowCommand::selectUnmanagedObject(QObject *unmanagedObject) |
125 | { |
126 | // Keep selection in sync |
127 | if (QDesignerObjectInspector *oi = qobject_cast<QDesignerObjectInspector *>(object: core()->objectInspector())) { |
128 | oi->clearSelection(); |
129 | oi->selectObject(o: unmanagedObject); |
130 | } |
131 | core()->propertyEditor()->setObject(unmanagedObject); |
132 | } |
133 | |
134 | } // namespace qdesigner_internal |
135 | |
136 | QT_END_NAMESPACE |
137 | |