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
qdesigner_command2.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#include "layoutinfo_p.h"
11
12#include <QtDesigner/abstractformeditor.h>
13#include <QtDesigner/abstractmetadatabase.h>
14
15#include <QtWidgets/qapplication.h>
16#include <QtWidgets/qlayout.h>
17
19
20namespace qdesigner_internal {
21
30
36
38{
39 int oldType;
41 if (!canMorph(fw, w, &oldType) || oldType == newType)
42 return false;
45 // Find all managed widgets
48 const int count = layout->count();
49 for (int i = 0; i < count ; i++) {
50 if (QWidget *w = layout->itemAt(i)->widget())
51 if (fw->isManaged(w))
53 }
54 const bool reparentLayoutWidget = false; // leave QLayoutWidget intact
58 return true;
59}
60
62{
65 // We want a managed widget or a container page
66 // with a level-0 managed layout
69 if (!layout)
70 return false;
74 switch (type) {
75 case LayoutInfo::HBox:
76 case LayoutInfo::VBox:
77 case LayoutInfo::Grid:
78 case LayoutInfo::Form:
79 return true;
80 break;
81 case LayoutInfo::NoLayout:
82 case LayoutInfo::HSplitter: // Nothing doing
85 break;
86 }
87 return false;
88}
89
91{
94 /* Transfer applicable properties which is a cross-section of the modified
95 * properties except object name. */
101 if (applicableMask)
103 }
104}
105
111
113{
114 const QString oldName = LayoutInfo::layoutName(static_cast<LayoutInfo::Type>(oldType));
115 const QString newName = LayoutInfo::layoutName(static_cast<LayoutInfo::Type>(newType));
117 return QApplication::translate("Command", "Change layout of '%1' from %2 to %3").arg(widgetName, oldName, newName);
118}
119
120LayoutAlignmentCommand::LayoutAlignmentCommand(QDesignerFormWindowInterface *formWindow) :
121 QDesignerFormWindowCommand(QApplication::translate("Command", "Change layout alignment"), formWindow),
122 m_widget(nullptr)
123{
124}
125
126bool LayoutAlignmentCommand::init(QWidget *w, Qt::Alignment alignment)
127{
128 bool enabled;
129 m_newAlignment = alignment;
130 m_oldAlignment = LayoutAlignmentCommand::alignmentOf(core(), w, &enabled);
131 m_widget = w;
132 return enabled;
133}
134
136{
137 LayoutAlignmentCommand::applyAlignment(core(), m_widget, m_newAlignment);
138}
139
141{
142 LayoutAlignmentCommand::applyAlignment(core(), m_widget, m_oldAlignment);
143}
144
145// Find out alignment and return whether command is enabled.
146Qt::Alignment LayoutAlignmentCommand::alignmentOf(const QDesignerFormEditorInterface *core, QWidget *w, bool *enabledIn)
147{
148 bool managed;
149 QLayout *layout;
150
151 if (enabledIn)
152 *enabledIn = false;
153 // Can only work on a managed layout
154 const LayoutInfo::Type type = LayoutInfo::laidoutWidgetType(core, w, &managed, &layout);
155 const bool enabled = layout && managed &&
156 (type == LayoutInfo::HBox || type == LayoutInfo::VBox
157 || type == LayoutInfo::Grid);
158 if (!enabled)
159 return {};
160 // Get alignment
161 const int index = layout->indexOf(w);
162 Q_ASSERT(index >= 0);
163 if (enabledIn)
164 *enabledIn = true;
165 return layout->itemAt(index)->alignment();
166}
167
168void LayoutAlignmentCommand::applyAlignment(const QDesignerFormEditorInterface *core, QWidget *w, Qt::Alignment a)
169{
170 // Find layout and apply to item
171 QLayout *layout;
172 LayoutInfo::laidoutWidgetType(core, w, nullptr, &layout);
173 if (layout) {
174 const int index = layout->indexOf(w);
175 if (index >= 0) {
176 layout->itemAt(index)->setAlignment(a);
177 layout->update();
178 }
179 }
180}
181
182} // namespace qdesigner_internal
183
184QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:432
void redo() override
Applies a change to the document.
bool init(QWidget *w, Qt::Alignment alignment)
void undo() override
Reverts a change to the document.
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.