88 static const QHash<QString, LayoutPropertyType> namePropertyMap = {
89 {leftMargin, LayoutPropertyLeftMargin},
90 {topMargin, LayoutPropertyTopMargin},
91 {rightMargin, LayoutPropertyRightMargin},
92 {bottomMargin, LayoutPropertyBottomMargin},
93 {horizontalSpacing, LayoutPropertyHorizontalSpacing},
94 {verticalSpacing, LayoutPropertyVerticalSpacing},
95 {spacing, LayoutPropertySpacing},
96#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
97 {sizeConstraint, LayoutPropertySizeConstraint},
99 {horizontalSizeConstraint, LayoutPropertyHorizontalSizeConstraint},
100 {verticalSizeConstraint, LayoutPropertyVerticalSizeConstraint},
102 {boxStretchPropertyC, LayoutPropertyBoxStretch},
103 {gridRowStretchPropertyC, LayoutPropertyGridRowStretch},
104 {gridColumnStretchPropertyC, LayoutPropertyGridColumnStretch},
105 {gridRowMinimumHeightPropertyC, LayoutPropertyGridRowMinimumHeight},
106 {gridColumnMinimumWidthPropertyC, LayoutPropertyGridColumnMinimumWidth}
108 return namePropertyMap.value(name, LayoutPropertyNone);
114 int left, top, right, bottom;
115 l->getContentsMargins(&left, &top, &right, &bottom);
117 case LayoutPropertyLeftMargin:
119 case LayoutPropertyTopMargin:
121 case LayoutPropertyRightMargin:
123 case LayoutPropertyBottomMargin:
135 int left, top, right, bottom;
136 l->getContentsMargins(&left, &top, &right, &bottom);
138 case LayoutPropertyLeftMargin:
141 case LayoutPropertyTopMargin:
144 case LayoutPropertyRightMargin:
147 case LayoutPropertyBottomMargin:
154 l->setContentsMargins(left, top, right, bottom);
166 : QDesignerPropertySheet(l, parent), m_layout(l)
168 const QString layoutGroup = u"Layout"_s;
169 int pindex = createFakeProperty(leftMargin, 0);
170 setPropertyGroup(pindex, layoutGroup);
172 pindex = createFakeProperty(topMargin, 0);
173 setPropertyGroup(pindex, layoutGroup);
175 pindex = createFakeProperty(rightMargin, 0);
176 setPropertyGroup(pindex, layoutGroup);
178 pindex = createFakeProperty(bottomMargin, 0);
179 setPropertyGroup(pindex, layoutGroup);
181 const int visibleMask = LayoutProperties::visibleProperties(m_layout);
182 if (visibleMask & LayoutProperties::HorizSpacingProperty) {
183 pindex = createFakeProperty(horizontalSpacing, 0);
184 setPropertyGroup(pindex, layoutGroup);
186 pindex = createFakeProperty(verticalSpacing, 0);
187 setPropertyGroup(pindex, layoutGroup);
189 setAttribute(indexOf(spacing),
true);
193 if (visibleMask & LayoutProperties::BoxStretchProperty) {
194 pindex = createFakeProperty(boxStretchPropertyC, QByteArray());
195 setPropertyGroup(pindex, layoutGroup);
196 setAttribute(pindex,
true);
199 if (visibleMask & LayoutProperties::GridColumnStretchProperty) {
200 const QByteArray empty;
201 pindex = createFakeProperty(gridRowStretchPropertyC, empty);
202 setPropertyGroup(pindex, layoutGroup);
203 setAttribute(pindex,
true);
204 pindex = createFakeProperty(gridColumnStretchPropertyC, empty);
205 setPropertyGroup(pindex, layoutGroup);
206 setAttribute(pindex,
true);
207 pindex = createFakeProperty(gridRowMinimumHeightPropertyC, empty);
208 setPropertyGroup(pindex, layoutGroup);
209 setAttribute(pindex,
true);
210 pindex = createFakeProperty(gridColumnMinimumWidthPropertyC, empty);
211 setPropertyGroup(pindex, layoutGroup);
212 setAttribute(pindex,
true);
219#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
220 pindex = createFakeProperty(sizeConstraint);
221 setPropertyGroup(pindex, layoutGroup);
223 pindex = createFakeProperty(horizontalSizeConstraint);
224 setPropertyGroup(pindex, layoutGroup);
225 pindex = createFakeProperty(verticalSizeConstraint);
226 setPropertyGroup(pindex, layoutGroup);
234 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
235 if (QLayoutWidget *lw = qobject_cast<QLayoutWidget *>(m_layout->parent())) {
237 case LayoutPropertyLeftMargin:
238 lw->setLayoutLeftMargin(value.toInt());
240 case LayoutPropertyTopMargin:
241 lw->setLayoutTopMargin(value.toInt());
243 case LayoutPropertyRightMargin:
244 lw->setLayoutRightMargin(value.toInt());
246 case LayoutPropertyBottomMargin:
247 lw->setLayoutBottomMargin(value.toInt());
254 case LayoutPropertyLeftMargin:
255 case LayoutPropertyTopMargin:
256 case LayoutPropertyRightMargin:
257 case LayoutPropertyBottomMargin:
258 setLayoutMargin(m_layout, type, value.toInt());
260 case LayoutPropertyHorizontalSpacing:
261 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
262 grid->setHorizontalSpacing(value.toInt());
265 if (QFormLayout *form = qobject_cast<QFormLayout *>(m_layout)) {
266 form->setHorizontalSpacing(value.toInt());
270 case LayoutPropertyVerticalSpacing:
271 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
272 grid->setVerticalSpacing(value.toInt());
275 if (QFormLayout *form = qobject_cast<QFormLayout *>(m_layout)) {
276 form->setVerticalSpacing(value.toInt());
280 case LayoutPropertyBoxStretch:
283 if (QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout)) {
284 const QString stretch = value.toString();
285 if (isIntegerList(stretch))
286 QFormBuilderExtra::setBoxLayoutStretch(value.toString(), box);
289 case LayoutPropertyGridRowStretch:
290 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
291 const QString stretch = value.toString();
292 if (isIntegerList(stretch))
293 QFormBuilderExtra::setGridLayoutRowStretch(stretch, grid);
296 case LayoutPropertyGridColumnStretch:
297 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
298 const QString stretch = value.toString();
299 if (isIntegerList(stretch))
300 QFormBuilderExtra::setGridLayoutColumnStretch(value.toString(), grid);
303 case LayoutPropertyGridRowMinimumHeight:
304 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
305 const QString minSize = value.toString();
306 if (isIntegerList(minSize))
307 QFormBuilderExtra::setGridLayoutRowMinimumHeight(minSize, grid);
310 case LayoutPropertyGridColumnMinimumWidth:
311 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout)) {
312 const QString minSize = value.toString();
313 if (isIntegerList(minSize))
314 QFormBuilderExtra::setGridLayoutColumnMinimumWidth(minSize, grid);
320 QDesignerPropertySheet::setProperty(index, value);
325 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
326 if (
const QLayoutWidget *lw = qobject_cast<QLayoutWidget *>(m_layout->parent())) {
328 case LayoutPropertyLeftMargin:
329 return lw->layoutLeftMargin();
330 case LayoutPropertyTopMargin:
331 return lw->layoutTopMargin();
332 case LayoutPropertyRightMargin:
333 return lw->layoutRightMargin();
334 case LayoutPropertyBottomMargin:
335 return lw->layoutBottomMargin();
341 case LayoutPropertyLeftMargin:
342 case LayoutPropertyTopMargin:
343 case LayoutPropertyRightMargin:
344 case LayoutPropertyBottomMargin:
345 return getLayoutMargin(m_layout, type);
346 case LayoutPropertyHorizontalSpacing:
347 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
348 return grid->horizontalSpacing();
349 if (
const QFormLayout *form = qobject_cast<QFormLayout *>(m_layout))
350 return form->horizontalSpacing();
352 case LayoutPropertyVerticalSpacing:
353 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
354 return grid->verticalSpacing();
355 if (
const QFormLayout *form = qobject_cast<QFormLayout *>(m_layout))
356 return form->verticalSpacing();
358 case LayoutPropertyBoxStretch:
359 if (
const QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout))
360 return QVariant(QByteArray(QFormBuilderExtra::boxLayoutStretch(box).toUtf8()));
362 case LayoutPropertyGridRowStretch:
363 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
364 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutRowStretch(grid).toUtf8()));
366 case LayoutPropertyGridColumnStretch:
367 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
368 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutColumnStretch(grid).toUtf8()));
370 case LayoutPropertyGridRowMinimumHeight:
371 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
372 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutRowMinimumHeight(grid).toUtf8()));
374 case LayoutPropertyGridColumnMinimumWidth:
375 if (
const QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
376 return QVariant(QByteArray(QFormBuilderExtra::gridLayoutColumnMinimumWidth(grid).toUtf8()));
381 return QDesignerPropertySheet::property(index);
386 int left, top, right, bottom;
387 m_layout->getContentsMargins(&left, &top, &right, &bottom);
388 const LayoutPropertyType type = layoutPropertyType(propertyName(index));
391 case LayoutPropertyLeftMargin:
392 m_layout->setContentsMargins(-1, top, right, bottom);
394 case LayoutPropertyTopMargin:
395 m_layout->setContentsMargins(left, -1, right, bottom);
397 case LayoutPropertyRightMargin:
398 m_layout->setContentsMargins(left, top, -1, bottom);
400 case LayoutPropertyBottomMargin:
401 m_layout->setContentsMargins(left, top, right, -1);
403 case LayoutPropertyBoxStretch:
404 if (QBoxLayout *box = qobject_cast<QBoxLayout *>(m_layout))
405 QFormBuilderExtra::clearBoxLayoutStretch(box);
407 case LayoutPropertyGridRowStretch:
408 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
409 QFormBuilderExtra::clearGridLayoutRowStretch(grid);
411 case LayoutPropertyGridColumnStretch:
412 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
413 QFormBuilderExtra::clearGridLayoutColumnStretch(grid);
415 case LayoutPropertyGridRowMinimumHeight:
416 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
417 QFormBuilderExtra::clearGridLayoutRowMinimumHeight(grid);
419 case LayoutPropertyGridColumnMinimumWidth:
420 if (QGridLayout *grid = qobject_cast<QGridLayout *>(m_layout))
421 QFormBuilderExtra::clearGridLayoutColumnMinimumWidth(grid);
424 rc = QDesignerPropertySheet::reset(index);
446void LayoutPropertySheet::stretchAttributesToDom(QDesignerFormEditorInterface *core, QLayout *lt, DomLayout *domLayout)
450 const int visibleMask = LayoutProperties::visibleProperties(lt);
451 if (!(visibleMask & (LayoutProperties::BoxStretchProperty|LayoutProperties::GridColumnStretchProperty|LayoutProperties::GridRowStretchProperty)))
453 const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), lt);
457 if (visibleMask & LayoutProperties::BoxStretchProperty) {
458 const int index = sheet->indexOf(boxStretchPropertyC);
459 Q_ASSERT(index != -1);
460 if (sheet->isChanged(index))
461 domLayout->setAttributeStretch(sheet->property(index).toString());
463 if (visibleMask & LayoutProperties::GridColumnStretchProperty) {
464 const int index = sheet->indexOf(gridColumnStretchPropertyC);
465 Q_ASSERT(index != -1);
466 if (sheet->isChanged(index))
467 domLayout->setAttributeColumnStretch(sheet->property(index).toString());
469 if (visibleMask & LayoutProperties::GridRowStretchProperty) {
470 const int index = sheet->indexOf(gridRowStretchPropertyC);
471 Q_ASSERT(index != -1);
472 if (sheet->isChanged(index))
473 domLayout->setAttributeRowStretch(sheet->property(index).toString());
475 if (visibleMask & LayoutProperties::GridRowMinimumHeightProperty) {
476 const int index = sheet->indexOf(gridRowMinimumHeightPropertyC);
477 Q_ASSERT(index != -1);
478 if (sheet->isChanged(index))
479 domLayout->setAttributeRowMinimumHeight(sheet->property(index).toString());
481 if (visibleMask & LayoutProperties::GridColumnMinimumWidthProperty) {
482 const int index = sheet->indexOf(gridColumnMinimumWidthPropertyC);
483 Q_ASSERT(index != -1);
484 if (sheet->isChanged(index))
485 domLayout->setAttributeColumnMinimumWidth(sheet->property(index).toString());
489void LayoutPropertySheet::markChangedStretchProperties(QDesignerFormEditorInterface *core, QLayout *lt,
const DomLayout *domLayout)
493 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), lt);
495 if (!domLayout->attributeStretch().isEmpty())
496 sheet->setChanged(sheet->indexOf(boxStretchPropertyC),
true);
497 if (!domLayout->attributeRowStretch().isEmpty())
498 sheet->setChanged(sheet->indexOf(gridRowStretchPropertyC),
true);
499 if (!domLayout->attributeColumnStretch().isEmpty())
500 sheet->setChanged(sheet->indexOf(gridColumnStretchPropertyC),
true);
501 if (!domLayout->attributeColumnMinimumWidth().isEmpty())
502 sheet->setChanged(sheet->indexOf(gridColumnMinimumWidthPropertyC),
true);
503 if (!domLayout->attributeRowMinimumHeight().isEmpty())
504 sheet->setChanged(sheet->indexOf(gridRowMinimumHeightPropertyC),
true);