89 static const QHash<QString, LayoutPropertyType> namePropertyMap = {
90 {leftMargin, LayoutPropertyLeftMargin},
91 {topMargin, LayoutPropertyTopMargin},
92 {rightMargin, LayoutPropertyRightMargin},
93 {bottomMargin, LayoutPropertyBottomMargin},
94 {horizontalSpacing, LayoutPropertyHorizontalSpacing},
95 {verticalSpacing, LayoutPropertyVerticalSpacing},
96 {spacing, LayoutPropertySpacing},
97#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
98 {sizeConstraint, LayoutPropertySizeConstraint},
100 {horizontalSizeConstraint, LayoutPropertyHorizontalSizeConstraint},
101 {verticalSizeConstraint, LayoutPropertyVerticalSizeConstraint},
103 {boxStretchPropertyC, LayoutPropertyBoxStretch},
104 {gridRowStretchPropertyC, LayoutPropertyGridRowStretch},
105 {gridColumnStretchPropertyC, LayoutPropertyGridColumnStretch},
106 {gridRowMinimumHeightPropertyC, LayoutPropertyGridRowMinimumHeight},
107 {gridColumnMinimumWidthPropertyC, LayoutPropertyGridColumnMinimumWidth}
109 return namePropertyMap.value(name, LayoutPropertyNone);
115 int left, top, right, bottom;
116 l->getContentsMargins(&left, &top, &right, &bottom);
118 case LayoutPropertyLeftMargin:
120 case LayoutPropertyTopMargin:
122 case LayoutPropertyRightMargin:
124 case LayoutPropertyBottomMargin:
136 int left, top, right, bottom;
137 l->getContentsMargins(&left, &top, &right, &bottom);
139 case LayoutPropertyLeftMargin:
142 case LayoutPropertyTopMargin:
145 case LayoutPropertyRightMargin:
148 case LayoutPropertyBottomMargin:
155 l->setContentsMargins(left, top, right, bottom);
167 : QDesignerPropertySheet(l, parent), m_layout(l)
169 const QString layoutGroup = u"Layout"_s;
170 int pindex = createFakeProperty(leftMargin, 0);
171 setPropertyGroup(pindex, layoutGroup);
173 pindex = createFakeProperty(topMargin, 0);
174 setPropertyGroup(pindex, layoutGroup);
176 pindex = createFakeProperty(rightMargin, 0);
177 setPropertyGroup(pindex, layoutGroup);
179 pindex = createFakeProperty(bottomMargin, 0);
180 setPropertyGroup(pindex, layoutGroup);
182 const int visibleMask = LayoutProperties::visibleProperties(m_layout);
183 if (visibleMask & LayoutProperties::HorizSpacingProperty) {
184 pindex = createFakeProperty(horizontalSpacing, 0);
185 setPropertyGroup(pindex, layoutGroup);
187 pindex = createFakeProperty(verticalSpacing, 0);
188 setPropertyGroup(pindex, layoutGroup);
190 setAttribute(indexOf(spacing),
true);
194 if (visibleMask & LayoutProperties::BoxStretchProperty) {
195 pindex = createFakeProperty(boxStretchPropertyC, QByteArray());
196 setPropertyGroup(pindex, layoutGroup);
197 setAttribute(pindex,
true);
200 if (visibleMask & LayoutProperties::GridColumnStretchProperty) {
201 const QByteArray empty;
202 pindex = createFakeProperty(gridRowStretchPropertyC, empty);
203 setPropertyGroup(pindex, layoutGroup);
204 setAttribute(pindex,
true);
205 pindex = createFakeProperty(gridColumnStretchPropertyC, empty);
206 setPropertyGroup(pindex, layoutGroup);
207 setAttribute(pindex,
true);
208 pindex = createFakeProperty(gridRowMinimumHeightPropertyC, empty);
209 setPropertyGroup(pindex, layoutGroup);
210 setAttribute(pindex,
true);
211 pindex = createFakeProperty(gridColumnMinimumWidthPropertyC, empty);
212 setPropertyGroup(pindex, layoutGroup);
213 setAttribute(pindex,
true);
220#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
221 pindex = createFakeProperty(sizeConstraint);
222 setPropertyGroup(pindex, layoutGroup);
224 pindex = createFakeProperty(horizontalSizeConstraint);
225 setPropertyGroup(pindex, layoutGroup);
226 pindex = createFakeProperty(verticalSizeConstraint);
227 setPropertyGroup(pindex, layoutGroup);
235 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
236 if (QLayoutWidget *lw = qobject_cast<QLayoutWidget *>(m_layout->parent())) {
238 case LayoutPropertyLeftMargin:
239 lw->setLayoutLeftMargin(value.toInt());
241 case LayoutPropertyTopMargin:
242 lw->setLayoutTopMargin(value.toInt());
244 case LayoutPropertyRightMargin:
245 lw->setLayoutRightMargin(value.toInt());
247 case LayoutPropertyBottomMargin:
248 lw->setLayoutBottomMargin(value.toInt());
255 case LayoutPropertyLeftMargin:
256 case LayoutPropertyTopMargin:
257 case LayoutPropertyRightMargin:
258 case LayoutPropertyBottomMargin:
259 setLayoutMargin(m_layout, type, value.toInt());
261 case LayoutPropertyHorizontalSpacing:
262 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
263 grid->setHorizontalSpacing(value.toInt());
266 if (QFormLayout *form = qobject_cast<QFormLayout *>(m_layout)) {
267 form->setHorizontalSpacing(value.toInt());
271 case LayoutPropertyVerticalSpacing:
272 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
273 grid->setVerticalSpacing(value.toInt());
276 if (QFormLayout *form = qobject_cast<QFormLayout *>(m_layout)) {
277 form->setVerticalSpacing(value.toInt());
281 case LayoutPropertyBoxStretch:
284 if (QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout)) {
285 const QString stretch = value.toString();
286 if (isIntegerList(stretch))
287 QFormBuilderExtra::setBoxLayoutStretch(value.toString(), box);
290 case LayoutPropertyGridRowStretch:
291 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
292 const QString stretch = value.toString();
293 if (isIntegerList(stretch))
294 QFormBuilderExtra::setGridLayoutRowStretch(stretch, grid);
297 case LayoutPropertyGridColumnStretch:
298 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
299 const QString stretch = value.toString();
300 if (isIntegerList(stretch))
301 QFormBuilderExtra::setGridLayoutColumnStretch(value.toString(), grid);
304 case LayoutPropertyGridRowMinimumHeight:
305 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
306 const QString minSize = value.toString();
307 if (isIntegerList(minSize))
308 QFormBuilderExtra::setGridLayoutRowMinimumHeight(minSize, grid);
311 case LayoutPropertyGridColumnMinimumWidth:
312 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
313 const QString minSize = value.toString();
314 if (isIntegerList(minSize))
315 QFormBuilderExtra::setGridLayoutColumnMinimumWidth(minSize, grid);
321 QDesignerPropertySheet::setProperty(index, value);
326 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
327 if (
const QLayoutWidget *lw = qobject_cast<QLayoutWidget *>(m_layout->parent())) {
329 case LayoutPropertyLeftMargin:
330 return lw->layoutLeftMargin();
331 case LayoutPropertyTopMargin:
332 return lw->layoutTopMargin();
333 case LayoutPropertyRightMargin:
334 return lw->layoutRightMargin();
335 case LayoutPropertyBottomMargin:
336 return lw->layoutBottomMargin();
342 case LayoutPropertyLeftMargin:
343 case LayoutPropertyTopMargin:
344 case LayoutPropertyRightMargin:
345 case LayoutPropertyBottomMargin:
346 return getLayoutMargin(m_layout, type);
347 case LayoutPropertyHorizontalSpacing:
348 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
349 return grid->horizontalSpacing();
350 if (
const QFormLayout *form = qobject_cast<QFormLayout *>(m_layout))
351 return form->horizontalSpacing();
353 case LayoutPropertyVerticalSpacing:
354 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
355 return grid->verticalSpacing();
356 if (
const QFormLayout *form = qobject_cast<QFormLayout *>(m_layout))
357 return form->verticalSpacing();
359 case LayoutPropertyBoxStretch:
360 if (
const QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout))
361 return QVariant(QByteArray(QFormBuilderExtra::boxLayoutStretch(box).toUtf8()));
363 case LayoutPropertyGridRowStretch:
364 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
365 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutRowStretch(grid).toUtf8()));
367 case LayoutPropertyGridColumnStretch:
368 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
369 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutColumnStretch(grid).toUtf8()));
371 case LayoutPropertyGridRowMinimumHeight:
372 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
373 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutRowMinimumHeight(grid).toUtf8()));
375 case LayoutPropertyGridColumnMinimumWidth:
376 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
377 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutColumnMinimumWidth(grid).toUtf8()));
382 return QDesignerPropertySheet::property(index);
387 int left, top, right, bottom;
388 m_layout->getContentsMargins(&left, &top, &right, &bottom);
389 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
392 case LayoutPropertyLeftMargin:
393 m_layout->setContentsMargins(-1, top, right, bottom);
395 case LayoutPropertyTopMargin:
396 m_layout->setContentsMargins(left, -1, right, bottom);
398 case LayoutPropertyRightMargin:
399 m_layout->setContentsMargins(left, top, -1, bottom);
401 case LayoutPropertyBottomMargin:
402 m_layout->setContentsMargins(left, top, right, -1);
404 case LayoutPropertyBoxStretch:
405 if (QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout))
406 QFormBuilderExtra::clearBoxLayoutStretch(box);
408 case LayoutPropertyGridRowStretch:
409 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
410 QFormBuilderExtra::clearGridLayoutRowStretch(grid);
412 case LayoutPropertyGridColumnStretch:
413 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
414 QFormBuilderExtra::clearGridLayoutColumnStretch(grid);
416 case LayoutPropertyGridRowMinimumHeight:
417 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
418 QFormBuilderExtra::clearGridLayoutRowMinimumHeight(grid);
420 case LayoutPropertyGridColumnMinimumWidth:
421 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
422 QFormBuilderExtra::clearGridLayoutColumnMinimumWidth(grid);
425 rc = QDesignerPropertySheet::reset(index);
447void LayoutPropertySheet::stretchAttributesToDom(QDesignerFormEditorInterface *core, QLayout *lt, DomLayout *domLayout)
451 const int visibleMask = LayoutProperties::visibleProperties(lt);
452 if (!(visibleMask & (LayoutProperties::BoxStretchProperty|LayoutProperties::GridColumnStretchProperty|LayoutProperties::GridRowStretchProperty)))
454 const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), lt);
458 if (visibleMask & LayoutProperties::BoxStretchProperty) {
459 const int index = sheet->indexOf(boxStretchPropertyC);
460 Q_ASSERT(index != -1);
461 if (sheet->isChanged(index))
462 domLayout->setAttributeStretch(sheet->property(index).toString());
464 if (visibleMask & LayoutProperties::GridColumnStretchProperty) {
465 const int index = sheet->indexOf(gridColumnStretchPropertyC);
466 Q_ASSERT(index != -1);
467 if (sheet->isChanged(index))
468 domLayout->setAttributeColumnStretch(sheet->property(index).toString());
470 if (visibleMask & LayoutProperties::GridRowStretchProperty) {
471 const int index = sheet->indexOf(gridRowStretchPropertyC);
472 Q_ASSERT(index != -1);
473 if (sheet->isChanged(index))
474 domLayout->setAttributeRowStretch(sheet->property(index).toString());
476 if (visibleMask & LayoutProperties::GridRowMinimumHeightProperty) {
477 const int index = sheet->indexOf(gridRowMinimumHeightPropertyC);
478 Q_ASSERT(index != -1);
479 if (sheet->isChanged(index))
480 domLayout->setAttributeRowMinimumHeight(sheet->property(index).toString());
482 if (visibleMask & LayoutProperties::GridColumnMinimumWidthProperty) {
483 const int index = sheet->indexOf(gridColumnMinimumWidthPropertyC);
484 Q_ASSERT(index != -1);
485 if (sheet->isChanged(index))
486 domLayout->setAttributeColumnMinimumWidth(sheet->property(index).toString());
490void LayoutPropertySheet::markChangedStretchProperties(QDesignerFormEditorInterface *core, QLayout *lt,
const DomLayout *domLayout)
494 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), lt);
496 if (!domLayout->attributeStretch().isEmpty())
497 sheet->setChanged(sheet->indexOf(boxStretchPropertyC),
true);
498 if (!domLayout->attributeRowStretch().isEmpty())
499 sheet->setChanged(sheet->indexOf(gridRowStretchPropertyC),
true);
500 if (!domLayout->attributeColumnStretch().isEmpty())
501 sheet->setChanged(sheet->indexOf(gridColumnStretchPropertyC),
true);
502 if (!domLayout->attributeColumnMinimumWidth().isEmpty())
503 sheet->setChanged(sheet->indexOf(gridColumnMinimumWidthPropertyC),
true);
504 if (!domLayout->attributeRowMinimumHeight().isEmpty())
505 sheet->setChanged(sheet->indexOf(gridRowMinimumHeightPropertyC),
true);