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
formwindowsettings.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
5#include "ui_formwindowsettings.h"
6
7#include <formwindowbase_p.h>
8#include <grid_p.h>
9
10#include <QtWidgets/qstyle.h>
11
12#include <QtCore/qcompare.h>
13#include <QtCore/qregularexpression.h>
14#include <QtCore/qdebug.h>
15
16#include <algorithm>
17
18QT_BEGIN_NAMESPACE
19
20using namespace Qt::StringLiterals;
21
22namespace qdesigner_internal {
23
24// Data structure containing form dialog data providing comparison
53
54QDebug operator<<(QDebug str, const FormWindowData &d)
55{
56 str.nospace() << "LayoutDefault=" << d.layoutDefaultEnabled << ',' << d.defaultMargin
57 << ',' << d.defaultSpacing << " LayoutFunctions=" << d.layoutFunctionsEnabled << ','
58 << d.marginFunction << ',' << d.spacingFunction << " PixFunction="
59 << d.pixFunction << " Author=" << d.author << " Hints=" << d.includeHints
60 << " Grid=" << d.hasFormGrid << d.grid.deltaX() << d.grid.deltaY()
61 << " ID-based translations" << d.idBasedTranslations
62 << " ID-based translation label" << d.idBasedTranslationLabel
63 << " Connect slots by name" << d.connectSlotsByName
64 << '\n';
65 return str;
66}
67
68bool comparesEqual(const FormWindowData &lhs, const FormWindowData &rhs) noexcept
69{
74 lhs.marginFunction == rhs.marginFunction &&
75 lhs.spacingFunction == rhs.spacingFunction &&
76 lhs.pixFunction == rhs.pixFunction &&
77 lhs.author == rhs.author &&
78 lhs.includeHints == rhs.includeHints &&
79 lhs.hasFormGrid == rhs.hasFormGrid &&
80 lhs.grid == rhs.grid &&
82 lhs.idBasedTranslationLabel== rhs.idBasedTranslationLabel &&
84}
85
86void FormWindowData::fromFormWindow(FormWindowBase* fw)
87{
88 defaultMargin = defaultSpacing = INT_MIN;
89 fw->layoutDefault(&defaultMargin, &defaultSpacing);
90
91 auto container = fw->formContainer();
92 QStyle *style = container->style();
93 layoutDefaultEnabled = defaultMargin != INT_MIN || defaultSpacing != INT_MIN;
94 if (defaultMargin == INT_MIN)
95 defaultMargin = style->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr, container);
96 if (defaultSpacing == INT_MIN)
97 defaultSpacing = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, nullptr);
98
99
100 marginFunction.clear();
101 spacingFunction.clear();
102 fw->layoutFunction(&marginFunction, &spacingFunction);
103 layoutFunctionsEnabled = !marginFunction.isEmpty() || !spacingFunction.isEmpty();
104
105 pixFunction = fw->pixmapFunction();
106
107 author = fw->author();
108
109 includeHints = fw->includeHints();
110 includeHints.removeAll(QString());
111
112 hasFormGrid = fw->hasFormGrid();
113 grid = hasFormGrid ? fw->designerGrid() : FormWindowBase::defaultDesignerGrid();
114 idBasedTranslations = fw->useIdBasedTranslations();
115 idBasedTranslationLabel = fw->idBasedTranslationLabel();
116 connectSlotsByName = fw->connectSlotsByName();
117}
118
119void FormWindowData::applyToFormWindow(FormWindowBase* fw) const
120{
121 fw->setAuthor(author);
122 fw->setPixmapFunction(pixFunction);
123
125 fw->setLayoutDefault(defaultMargin, defaultSpacing);
126 } else {
127 fw->setLayoutDefault(INT_MIN, INT_MIN);
128 }
129
131 fw->setLayoutFunction(marginFunction, spacingFunction);
132 } else {
133 fw->setLayoutFunction(QString(), QString());
134 }
135
136 fw->setIncludeHints(includeHints);
137
138 const bool hadFormGrid = fw->hasFormGrid();
139 fw->setHasFormGrid(hasFormGrid);
140 if (hasFormGrid || hadFormGrid != hasFormGrid)
141 fw->setDesignerGrid(hasFormGrid ? grid : FormWindowBase::defaultDesignerGrid());
142 fw->setUseIdBasedTranslations(idBasedTranslations);
143 fw->setIdBasedTranslationLabel(idBasedTranslationLabel);
144 fw->setConnectSlotsByName(connectSlotsByName);
145}
146
147// -------------------------- FormWindowSettings
148
149FormWindowSettings::FormWindowSettings(QDesignerFormWindowInterface *parent) :
150 QDialog(parent),
151 m_ui(new QT_PREPEND_NAMESPACE(Ui)::FormWindowSettings),
152 m_formWindow(qobject_cast<FormWindowBase*>(parent)),
153 m_oldData(new FormWindowData)
154{
155 Q_ASSERT(m_formWindow);
156
157 m_ui->setupUi(this);
158 m_ui->gridPanel->setCheckable(true);
159 m_ui->gridPanel->setResetButtonVisible(false);
160
161 QString deviceProfileName = m_formWindow->deviceProfileName();
162 if (deviceProfileName.isEmpty())
163 deviceProfileName = tr("None");
164 m_ui->deviceProfileLabel->setText(tr("Device Profile: %1").arg(deviceProfileName));
165
166 m_oldData->fromFormWindow(m_formWindow);
167 setData(*m_oldData);
168}
169
171{
172 delete m_oldData;
173 delete m_ui;
174}
175
177{
179 rc.author = m_ui->authorLineEdit->text();
180
181 if (m_ui->pixmapFunctionGroupBox->isChecked()) {
182 rc.pixFunction = m_ui->pixmapFunctionLineEdit->text();
183 } else {
184 rc.pixFunction.clear();
185 }
186
187 rc.layoutDefaultEnabled = m_ui->layoutDefaultGroupBox->isChecked();
188 rc.defaultMargin = m_ui->defaultMarginSpinBox->value();
189 rc.defaultSpacing = m_ui->defaultSpacingSpinBox->value();
190
191 rc.layoutFunctionsEnabled = m_ui->layoutFunctionGroupBox->isChecked();
192 rc.marginFunction = m_ui->marginFunctionLineEdit->text();
193 rc.spacingFunction = m_ui->spacingFunctionLineEdit->text();
194
195 const QString hints = m_ui->includeHintsTextEdit->toPlainText();
196 if (!hints.isEmpty()) {
197 rc.includeHints = hints.split(u'\n');
198 // Purge out any lines consisting of blanks only
199 const QRegularExpression blankLine(u"^\\s*$"_s);
200 Q_ASSERT(blankLine.isValid());
201 rc.includeHints.erase(std::remove_if(rc.includeHints.begin(), rc.includeHints.end(),
202 [blankLine](const QString &hint){ return blankLine.match(hint).hasMatch(); }),
203 rc.includeHints.end());
204 }
205
206 rc.hasFormGrid = m_ui->gridPanel->isChecked();
207 rc.grid = m_ui->gridPanel->grid();
208 rc.idBasedTranslations = m_ui->idBasedTranslationsCheckBox->isChecked();
209 rc.idBasedTranslationLabel = m_ui->idBasedTranslationLabelLineEdit->text();
210 rc.connectSlotsByName = m_ui->connectSlotsByNameCheckBox->isChecked();
211 return rc;
212}
213
214void FormWindowSettings::setData(const FormWindowData &data)
215{
216 m_ui->layoutDefaultGroupBox->setChecked(data.layoutDefaultEnabled);
217 m_ui->defaultMarginSpinBox->setValue(data.defaultMargin);
218 m_ui->defaultSpacingSpinBox->setValue(data.defaultSpacing);
219
220 m_ui->layoutFunctionGroupBox->setChecked(data.layoutFunctionsEnabled);
221 m_ui->marginFunctionLineEdit->setText(data.marginFunction);
222 m_ui->spacingFunctionLineEdit->setText(data.spacingFunction);
223
224 m_ui->pixmapFunctionLineEdit->setText(data.pixFunction);
225 m_ui->pixmapFunctionGroupBox->setChecked(!data.pixFunction.isEmpty());
226
227 m_ui->authorLineEdit->setText(data.author);
228
229 if (data.includeHints.isEmpty()) {
230 m_ui->includeHintsTextEdit->clear();
231 } else {
232 m_ui->includeHintsTextEdit->setText(data.includeHints.join(u'\n'));
233 }
234
235 m_ui->gridPanel->setChecked(data.hasFormGrid);
236 m_ui->gridPanel->setGrid(data.grid);
237 m_ui->idBasedTranslationsCheckBox->setChecked(data.idBasedTranslations);
238 m_ui->idBasedTranslationLabelLineEdit->setText(data.idBasedTranslationLabel);
239 m_ui->connectSlotsByNameCheckBox->setChecked(data.connectSlotsByName);
240}
241
243{
244 // Anything changed? -> Apply and set dirty
245 const FormWindowData newData = data();
246 if (newData != *m_oldData) {
247 newData.applyToFormWindow(m_formWindow);
248 m_formWindow->setDirty(true);
249 }
250
251 QDialog::accept();
252}
253}
254QT_END_NAMESPACE
void accept() override
Hides the modal dialog and sets the result code to Accepted.
Auxiliary methods to store/retrieve settings.
QDebug operator<<(QDebug str, const FormWindowData &d)
void applyToFormWindow(FormWindowBase *fw) const
void fromFormWindow(FormWindowBase *fw)
friend bool comparesEqual(const FormWindowData &lhs, const FormWindowData &rhs) noexcept