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
6#include "layoutinfo_p.h"
10
11#include <QtDesigner/abstractformeditor.h>
12#include <QtDesigner/abstractmetadatabase.h>
13
14#include <QtWidgets/qapplication.h>
15#include <QtWidgets/qlayout.h>
16
18
19namespace qdesigner_internal {
20
29
35
37{
38 int oldType;
40 if (!canMorph(fw, w, &oldType) || oldType == newType)
41 return false;
44 // Find all managed widgets
47 const int count = layout->count();
48 for (int i = 0; i < count ; i++) {
49 if (QWidget *w = layout->itemAt(i)->widget())
50 if (fw->isManaged(w))
52 }
53 const bool reparentLayoutWidget = false; // leave QLayoutWidget intact
57 return true;
58}
59
61{
64 // We want a managed widget or a container page
65 // with a level-0 managed layout
68 if (!layout)
69 return false;
73 switch (type) {
74 case LayoutInfo::HBox:
75 case LayoutInfo::VBox:
76 case LayoutInfo::Grid:
77 case LayoutInfo::Form:
78 return true;
79 break;
80 case LayoutInfo::NoLayout:
81 case LayoutInfo::HSplitter: // Nothing doing
84 break;
85 }
86 return false;
87}
88
90{
93 /* Transfer applicable properties which is a cross-section of the modified
94 * properties except object name. */
100 if (applicableMask)
102 }
103}
104
110
112{
113 const QString oldName = LayoutInfo::layoutName(static_cast<LayoutInfo::Type>(oldType));
114 const QString newName = LayoutInfo::layoutName(static_cast<LayoutInfo::Type>(newType));
116 return QApplication::translate("Command", "Change layout of '%1' from %2 to %3").arg(widgetName, oldName, newName);
117}
118
119LayoutAlignmentCommand::LayoutAlignmentCommand(QDesignerFormWindowInterface *formWindow) :
120 QDesignerFormWindowCommand(QApplication::translate("Command", "Change layout alignment"), formWindow),
121 m_widget(nullptr)
122{
123}
124
125bool LayoutAlignmentCommand::init(QWidget *w, Qt::Alignment alignment)
126{
127 bool enabled;
128 m_newAlignment = alignment;
129 m_oldAlignment = LayoutAlignmentCommand::alignmentOf(core(), w, &enabled);
130 m_widget = w;
131 return enabled;
132}
133
135{
136 LayoutAlignmentCommand::applyAlignment(core(), m_widget, m_newAlignment);
137}
138
140{
141 LayoutAlignmentCommand::applyAlignment(core(), m_widget, m_oldAlignment);
142}
143
144// Find out alignment and return whether command is enabled.
145Qt::Alignment LayoutAlignmentCommand::alignmentOf(const QDesignerFormEditorInterface *core, QWidget *w, bool *enabledIn)
146{
147 bool managed;
148 QLayout *layout;
149
150 if (enabledIn)
151 *enabledIn = false;
152 // Can only work on a managed layout
153 const LayoutInfo::Type type = LayoutInfo::laidoutWidgetType(core, w, &managed, &layout);
154 const bool enabled = layout && managed &&
155 (type == LayoutInfo::HBox || type == LayoutInfo::VBox
156 || type == LayoutInfo::Grid);
157 if (!enabled)
158 return {};
159 // Get alignment
160 const int index = layout->indexOf(w);
161 Q_ASSERT(index >= 0);
162 if (enabledIn)
163 *enabledIn = true;
164 return layout->itemAt(index)->alignment();
165}
166
167void LayoutAlignmentCommand::applyAlignment(const QDesignerFormEditorInterface *core, QWidget *w, Qt::Alignment a)
168{
169 // Find layout and apply to item
170 QLayout *layout;
171 LayoutInfo::laidoutWidgetType(core, w, nullptr, &layout);
172 if (layout) {
173 const int index = layout->indexOf(w);
174 if (index >= 0) {
175 layout->itemAt(index)->setAlignment(a);
176 layout->update();
177 }
178 }
179}
180
181} // namespace qdesigner_internal
182
183QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:421
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.