summaryrefslogtreecommitdiffstats
path: root/src/designer/src/lib/shared/qlayout_widget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/designer/src/lib/shared/qlayout_widget.cpp')
-rw-r--r--src/designer/src/lib/shared/qlayout_widget.cpp184
1 files changed, 77 insertions, 107 deletions
diff --git a/src/designer/src/lib/shared/qlayout_widget.cpp b/src/designer/src/lib/shared/qlayout_widget.cpp
index aa0502076..28b25ce84 100644
--- a/src/designer/src/lib/shared/qlayout_widget.cpp
+++ b/src/designer/src/lib/shared/qlayout_widget.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Designer of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qlayout_widget_p.h"
#include "qdesigner_utils_p.h"
@@ -48,6 +23,7 @@
#include <QtCore/qdebug.h>
#include <QtCore/qalgorithms.h>
+#include <QtCore/qhash.h>
#include <QtCore/qmap.h>
#include <QtCore/qstack.h>
#include <QtCore/qpair.h>
@@ -102,8 +78,10 @@ inline void getGridItemPosition(QFormLayout *formLayout, int index, int *row, in
QT_BEGIN_NAMESPACE
-static const char *objectNameC = "objectName";
-static const char *sizeConstraintC = "sizeConstraint";
+using namespace Qt::StringLiterals;
+
+static constexpr auto objectNameC = "objectName"_L1;
+static constexpr auto sizeConstraintC = "sizeConstraint"_L1;
/* A padding spacer element that is used to represent an empty form layout cell. It should grow with its cell.
* Should not be used on a grid as it causes resizing inconsistencies */
@@ -219,8 +197,9 @@ static bool removeEmptyCellsOnGrid(GridLikeLayout *grid, const QRect &area)
// remove, starting from last
if (!indexesToBeRemoved.isEmpty()) {
std::stable_sort(indexesToBeRemoved.begin(), indexesToBeRemoved.end());
- for (int i = indexesToBeRemoved.size() - 1; i >= 0; i--)
- delete grid->takeAt(indexesToBeRemoved[i]);
+ std::reverse(indexesToBeRemoved.begin(), indexesToBeRemoved.end());
+ for (auto i : std::as_const(indexesToBeRemoved))
+ delete grid->takeAt(i);
}
return true;
}
@@ -275,15 +254,15 @@ int LayoutProperties::visibleProperties(const QLayout *layout)
static const char *marginPropertyNamesC[] = {"leftMargin", "topMargin", "rightMargin", "bottomMargin"};
static const char *spacingPropertyNamesC[] = {"spacing", "horizontalSpacing", "verticalSpacing" };
-static const char *fieldGrowthPolicyPropertyC = "fieldGrowthPolicy";
-static const char *rowWrapPolicyPropertyC = "rowWrapPolicy";
-static const char *labelAlignmentPropertyC = "labelAlignment";
-static const char *formAlignmentPropertyC = "formAlignment";
-static const char *boxStretchPropertyC = "stretch";
-static const char *gridRowStretchPropertyC = "rowStretch";
-static const char *gridColumnStretchPropertyC = "columnStretch";
-static const char *gridRowMinimumHeightPropertyC = "rowMinimumHeight";
-static const char *gridColumnMinimumWidthPropertyC = "columnMinimumWidth";
+static constexpr auto fieldGrowthPolicyPropertyC = "fieldGrowthPolicy"_L1;
+static constexpr auto rowWrapPolicyPropertyC = "rowWrapPolicy"_L1;
+static constexpr auto labelAlignmentPropertyC = "labelAlignment"_L1;
+static constexpr auto formAlignmentPropertyC = "formAlignment"_L1;
+static constexpr auto boxStretchPropertyC = "stretch"_L1;
+static constexpr auto gridRowStretchPropertyC = "rowStretch"_L1;
+static constexpr auto gridColumnStretchPropertyC = "columnStretch"_L1;
+static constexpr auto gridRowMinimumHeightPropertyC = "rowMinimumHeight"_L1;
+static constexpr auto gridColumnMinimumWidthPropertyC = "columnMinimumWidth"_L1;
static bool intValueFromSheet(const QDesignerPropertySheetExtension *sheet, const QString &name, int *value, bool *changed)
{
@@ -315,7 +294,7 @@ int LayoutProperties::fromPropertySheet(const QDesignerFormEditorInterface *core
Q_ASSERT(sheet);
// name
if (mask & ObjectNameProperty) {
- const int nameIndex = sheet->indexOf(QLatin1String(objectNameC));
+ const int nameIndex = sheet->indexOf(objectNameC);
Q_ASSERT(nameIndex != -1);
m_objectName = sheet->property(nameIndex);
m_objectNameChanged = sheet->isChanged(nameIndex);
@@ -325,25 +304,25 @@ int LayoutProperties::fromPropertySheet(const QDesignerFormEditorInterface *core
const int marginFlags[MarginCount] = { LeftMarginProperty, TopMarginProperty, RightMarginProperty, BottomMarginProperty};
for (int i = 0; i < MarginCount; i++)
if (mask & marginFlags[i])
- if (intValueFromSheet(sheet, QLatin1String(marginPropertyNamesC[i]), m_margins + i, m_marginsChanged + i))
+ if (intValueFromSheet(sheet, QLatin1StringView(marginPropertyNamesC[i]), m_margins + i, m_marginsChanged + i))
rc |= marginFlags[i];
const int spacingFlags[] = { SpacingProperty, HorizSpacingProperty, VertSpacingProperty};
for (int i = 0; i < SpacingsCount; i++)
if (mask & spacingFlags[i])
- if (intValueFromSheet(sheet, QLatin1String(spacingPropertyNamesC[i]), m_spacings + i, m_spacingsChanged + i))
+ if (intValueFromSheet(sheet, QLatin1StringView(spacingPropertyNamesC[i]), m_spacings + i, m_spacingsChanged + i))
rc |= spacingFlags[i];
// sizeConstraint, flags
- variantPropertyFromSheet(mask, SizeConstraintProperty, sheet, QLatin1String(sizeConstraintC), &m_sizeConstraint, &m_sizeConstraintChanged, &rc);
- variantPropertyFromSheet(mask, FieldGrowthPolicyProperty, sheet, QLatin1String(fieldGrowthPolicyPropertyC), &m_fieldGrowthPolicy, &m_fieldGrowthPolicyChanged, &rc);
- variantPropertyFromSheet(mask, RowWrapPolicyProperty, sheet, QLatin1String(rowWrapPolicyPropertyC), &m_rowWrapPolicy, &m_rowWrapPolicyChanged, &rc);
- variantPropertyFromSheet(mask, LabelAlignmentProperty, sheet, QLatin1String(labelAlignmentPropertyC), &m_labelAlignment, &m_labelAlignmentChanged, &rc);
- variantPropertyFromSheet(mask, FormAlignmentProperty, sheet, QLatin1String(formAlignmentPropertyC), &m_formAlignment, &m_formAlignmentChanged, &rc);
- variantPropertyFromSheet(mask, BoxStretchProperty, sheet, QLatin1String(boxStretchPropertyC), &m_boxStretch, & m_boxStretchChanged, &rc);
- variantPropertyFromSheet(mask, GridRowStretchProperty, sheet, QLatin1String(gridRowStretchPropertyC), &m_gridRowStretch, &m_gridRowStretchChanged, &rc);
- variantPropertyFromSheet(mask, GridColumnStretchProperty, sheet, QLatin1String(gridColumnStretchPropertyC), &m_gridColumnStretch, &m_gridColumnStretchChanged, &rc);
- variantPropertyFromSheet(mask, GridRowMinimumHeightProperty, sheet, QLatin1String(gridRowMinimumHeightPropertyC), &m_gridRowMinimumHeight, &m_gridRowMinimumHeightChanged, &rc);
- variantPropertyFromSheet(mask, GridColumnMinimumWidthProperty, sheet, QLatin1String(gridColumnMinimumWidthPropertyC), &m_gridColumnMinimumWidth, &m_gridColumnMinimumWidthChanged, &rc);
+ variantPropertyFromSheet(mask, SizeConstraintProperty, sheet, sizeConstraintC, &m_sizeConstraint, &m_sizeConstraintChanged, &rc);
+ variantPropertyFromSheet(mask, FieldGrowthPolicyProperty, sheet, fieldGrowthPolicyPropertyC, &m_fieldGrowthPolicy, &m_fieldGrowthPolicyChanged, &rc);
+ variantPropertyFromSheet(mask, RowWrapPolicyProperty, sheet, rowWrapPolicyPropertyC, &m_rowWrapPolicy, &m_rowWrapPolicyChanged, &rc);
+ variantPropertyFromSheet(mask, LabelAlignmentProperty, sheet, labelAlignmentPropertyC, &m_labelAlignment, &m_labelAlignmentChanged, &rc);
+ variantPropertyFromSheet(mask, FormAlignmentProperty, sheet, formAlignmentPropertyC, &m_formAlignment, &m_formAlignmentChanged, &rc);
+ variantPropertyFromSheet(mask, BoxStretchProperty, sheet, boxStretchPropertyC, &m_boxStretch, & m_boxStretchChanged, &rc);
+ variantPropertyFromSheet(mask, GridRowStretchProperty, sheet, gridRowStretchPropertyC, &m_gridRowStretch, &m_gridRowStretchChanged, &rc);
+ variantPropertyFromSheet(mask, GridColumnStretchProperty, sheet, gridColumnStretchPropertyC, &m_gridColumnStretch, &m_gridColumnStretchChanged, &rc);
+ variantPropertyFromSheet(mask, GridRowMinimumHeightProperty, sheet, gridRowMinimumHeightPropertyC, &m_gridRowMinimumHeight, &m_gridRowMinimumHeightChanged, &rc);
+ variantPropertyFromSheet(mask, GridColumnMinimumWidthProperty, sheet, gridColumnMinimumWidthPropertyC, &m_gridColumnMinimumWidth, &m_gridColumnMinimumWidthChanged, &rc);
return rc;
}
@@ -383,7 +362,7 @@ int LayoutProperties::toPropertySheet(const QDesignerFormEditorInterface *core,
Q_ASSERT(sheet);
// name
if (mask & ObjectNameProperty) {
- const int nameIndex = sheet->indexOf(QLatin1String(objectNameC));
+ const int nameIndex = sheet->indexOf(objectNameC);
Q_ASSERT(nameIndex != -1);
sheet->setProperty(nameIndex, m_objectName);
if (applyChanged)
@@ -394,25 +373,25 @@ int LayoutProperties::toPropertySheet(const QDesignerFormEditorInterface *core,
const int marginFlags[MarginCount] = { LeftMarginProperty, TopMarginProperty, RightMarginProperty, BottomMarginProperty};
for (int i = 0; i < MarginCount; i++)
if (mask & marginFlags[i])
- if (intValueToSheet(sheet, QLatin1String(marginPropertyNamesC[i]), m_margins[i], m_marginsChanged[i], applyChanged))
+ if (intValueToSheet(sheet, QLatin1StringView(marginPropertyNamesC[i]), m_margins[i], m_marginsChanged[i], applyChanged))
rc |= marginFlags[i];
const int spacingFlags[] = { SpacingProperty, HorizSpacingProperty, VertSpacingProperty};
for (int i = 0; i < SpacingsCount; i++)
if (mask & spacingFlags[i])
- if (intValueToSheet(sheet, QLatin1String(spacingPropertyNamesC[i]), m_spacings[i], m_spacingsChanged[i], applyChanged))
+ if (intValueToSheet(sheet, QLatin1StringView(spacingPropertyNamesC[i]), m_spacings[i], m_spacingsChanged[i], applyChanged))
rc |= spacingFlags[i];
// sizeConstraint
- variantPropertyToSheet(mask, SizeConstraintProperty, applyChanged, sheet, QLatin1String(sizeConstraintC), m_sizeConstraint, m_sizeConstraintChanged, &rc);
- variantPropertyToSheet(mask, FieldGrowthPolicyProperty, applyChanged, sheet, QLatin1String(fieldGrowthPolicyPropertyC), m_fieldGrowthPolicy, m_fieldGrowthPolicyChanged, &rc);
- variantPropertyToSheet(mask, RowWrapPolicyProperty, applyChanged, sheet, QLatin1String(rowWrapPolicyPropertyC), m_rowWrapPolicy, m_rowWrapPolicyChanged, &rc);
- variantPropertyToSheet(mask, LabelAlignmentProperty, applyChanged, sheet, QLatin1String(labelAlignmentPropertyC), m_labelAlignment, m_labelAlignmentChanged, &rc);
- variantPropertyToSheet(mask, FormAlignmentProperty, applyChanged, sheet, QLatin1String(formAlignmentPropertyC), m_formAlignment, m_formAlignmentChanged, &rc);
- variantPropertyToSheet(mask, BoxStretchProperty, applyChanged, sheet, QLatin1String(boxStretchPropertyC), m_boxStretch, m_boxStretchChanged, &rc);
- variantPropertyToSheet(mask, GridRowStretchProperty, applyChanged, sheet, QLatin1String(gridRowStretchPropertyC), m_gridRowStretch, m_gridRowStretchChanged, &rc);
- variantPropertyToSheet(mask, GridColumnStretchProperty, applyChanged, sheet, QLatin1String(gridColumnStretchPropertyC), m_gridColumnStretch, m_gridColumnStretchChanged, &rc);
- variantPropertyToSheet(mask, GridRowMinimumHeightProperty, applyChanged, sheet, QLatin1String(gridRowMinimumHeightPropertyC), m_gridRowMinimumHeight, m_gridRowMinimumHeightChanged, &rc);
- variantPropertyToSheet(mask, GridColumnMinimumWidthProperty, applyChanged, sheet, QLatin1String(gridColumnMinimumWidthPropertyC), m_gridColumnMinimumWidth, m_gridColumnMinimumWidthChanged, &rc);
+ variantPropertyToSheet(mask, SizeConstraintProperty, applyChanged, sheet, sizeConstraintC, m_sizeConstraint, m_sizeConstraintChanged, &rc);
+ variantPropertyToSheet(mask, FieldGrowthPolicyProperty, applyChanged, sheet, fieldGrowthPolicyPropertyC, m_fieldGrowthPolicy, m_fieldGrowthPolicyChanged, &rc);
+ variantPropertyToSheet(mask, RowWrapPolicyProperty, applyChanged, sheet, rowWrapPolicyPropertyC, m_rowWrapPolicy, m_rowWrapPolicyChanged, &rc);
+ variantPropertyToSheet(mask, LabelAlignmentProperty, applyChanged, sheet, labelAlignmentPropertyC, m_labelAlignment, m_labelAlignmentChanged, &rc);
+ variantPropertyToSheet(mask, FormAlignmentProperty, applyChanged, sheet, formAlignmentPropertyC, m_formAlignment, m_formAlignmentChanged, &rc);
+ variantPropertyToSheet(mask, BoxStretchProperty, applyChanged, sheet, boxStretchPropertyC, m_boxStretch, m_boxStretchChanged, &rc);
+ variantPropertyToSheet(mask, GridRowStretchProperty, applyChanged, sheet, gridRowStretchPropertyC, m_gridRowStretch, m_gridRowStretchChanged, &rc);
+ variantPropertyToSheet(mask, GridColumnStretchProperty, applyChanged, sheet, gridColumnStretchPropertyC, m_gridColumnStretch, m_gridColumnStretchChanged, &rc);
+ variantPropertyToSheet(mask, GridRowMinimumHeightProperty, applyChanged, sheet, gridRowMinimumHeightPropertyC, m_gridRowMinimumHeight, m_gridRowMinimumHeightChanged, &rc);
+ variantPropertyToSheet(mask, GridColumnMinimumWidthProperty, applyChanged, sheet, gridColumnMinimumWidthPropertyC, m_gridColumnMinimumWidth, m_gridColumnMinimumWidthChanged, &rc);
return rc;
}
@@ -534,11 +513,10 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
QLayoutItem *BoxLayoutHelper::findItemOfWidget(const LayoutItemVector &lv, QWidget *w)
{
- const LayoutItemVector::const_iterator cend = lv.constEnd();
- for (LayoutItemVector::const_iterator it = lv.constBegin(); it != cend; ++it)
- if ( (*it)->widget() == w)
- return *it;
-
+ for (auto *l : lv) {
+ if (l->widget() == w)
+ return l;
+ }
return nullptr;
}
@@ -567,12 +545,11 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
if (savedState == state(boxLayout))
return;
- const int count = savedState.size();
- Q_ASSERT(count == currentState.size());
+ Q_ASSERT(savedState.size() == currentState.size());
// Take items and reassemble in saved order
const LayoutItemVector items = disassembleLayout(boxLayout);
- for (int i = 0; i < count; i++) {
- QLayoutItem *item = findItemOfWidget(items, savedState[i]);
+ for (auto *w : savedState) {
+ QLayoutItem *item = findItemOfWidget(items, w);
Q_ASSERT(item);
boxLayout->addItem(item);
}
@@ -603,18 +580,15 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
Occupied // Item bordering on it
};
// Horiontal, Vertical pair of state
- typedef QPair<DimensionCellState, DimensionCellState> CellState;
+ using CellState = std::pair<DimensionCellState, DimensionCellState>;
using CellStates = QList<CellState>;
// Figure out states of a cell and return as a flat vector of
// [column1, column2,...] (address as row * columnCount + col)
static CellStates cellStates(const QList<QRect> &rects, int numRows, int numColumns);
- typedef QMap<QWidget *, QRect> WidgetItemMap;
- typedef QMap<QWidget *, Qt::Alignment> WidgetAlignmentMap;
-
- WidgetItemMap widgetItemMap;
- WidgetAlignmentMap widgetAlignmentMap;
+ QHash<QWidget *, QRect> widgetItemMap;
+ QHash<QWidget *, Qt::Alignment> widgetAlignmentMap;
int rowCount = 0;
int colCount = 0;
@@ -629,8 +603,8 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
str << "GridLayoutState: " << gs.rowCount << " rows x " << gs.colCount
<< " cols " << gs.widgetItemMap.size() << " items\n";
- const GridLayoutState::WidgetItemMap::const_iterator wcend = gs.widgetItemMap.constEnd();
- for (GridLayoutState::WidgetItemMap::const_iterator it = gs.widgetItemMap.constBegin(); it != wcend; ++it)
+ const auto wcend = gs.widgetItemMap.constEnd();
+ for (auto it = gs.widgetItemMap.constBegin(); it != wcend; ++it)
str << "Item " << it.key() << it.value() << '\n';
return str;
}
@@ -690,19 +664,18 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
void GridLayoutState::applyToLayout(const QDesignerFormEditorInterface *core, QWidget *w) const
{
- using LayoutItemRectMap =QHash<QLayoutItem *, QRect>;
QGridLayout *grid = qobject_cast<QGridLayout *>(LayoutInfo::managedLayout(core, w));
Q_ASSERT(grid);
if (debugLayout)
qDebug() << ">GridLayoutState::applyToLayout" << *this << *grid;
const bool shrink = grid->rowCount() > rowCount || grid->columnCount() > colCount;
// Build a map of existing items to rectangles via widget map, delete spacers
- LayoutItemRectMap itemMap;
+ QHash<QLayoutItem *, QRect> itemMap;
while (grid->count()) {
QLayoutItem *item = grid->takeAt(0);
if (!LayoutInfo::isEmptyItem(item)) {
QWidget *itemWidget = item->widget();
- const WidgetItemMap::const_iterator it = widgetItemMap.constFind(itemWidget);
+ const auto it = widgetItemMap.constFind(itemWidget);
if (it == widgetItemMap.constEnd())
qFatal("GridLayoutState::applyToLayout: Attempt to apply to a layout that has a widget '%s'/'%s' added after saving the state.",
itemWidget->metaObject()->className(), itemWidget->objectName().toUtf8().constData());
@@ -717,8 +690,7 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
grid = static_cast<QGridLayout*>(recreateManagedLayout(core, w, grid));
// Add widgets items
- const LayoutItemRectMap::const_iterator icend = itemMap.constEnd();
- for (LayoutItemRectMap::const_iterator it = itemMap.constBegin(); it != icend; ++it) {
+ for (auto it = itemMap.cbegin(), icend = itemMap.cend(); it != icend; ++it) {
const QRect info = it.value();
const Qt::Alignment alignment = widgetAlignmentMap.value(it.key()->widget(), {});
grid->addItem(it.key(), info.y(), info.x(), info.height(), info.width(), alignment);
@@ -1009,8 +981,7 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
// ---------------- FormLayoutHelper
class FormLayoutHelper : public LayoutHelper {
public:
- typedef QPair<QWidget *, QWidget *> WidgetPair;
- using FormLayoutState = QList<WidgetPair>;
+ using FormLayoutState = QList<std::pair<QWidget *, QWidget *>>;
FormLayoutHelper() = default;
@@ -1103,7 +1074,7 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
const int rowCount = lt->rowCount();
if (rowCount == 0)
return FormLayoutState();
- FormLayoutState rc(rowCount, WidgetPair(0, 0));
+ FormLayoutState rc(rowCount, {nullptr, nullptr});
const int count = lt->count();
int row, column, colspan;
for (int i = 0; i < count; i++) {
@@ -1174,7 +1145,7 @@ QRect LayoutHelper::itemInfo(QLayout *lt, const QWidget *widget) const
void FormLayoutHelper::simplify(const QDesignerFormEditorInterface *core, QWidget *widgetWithManagedLayout, const QRect &restrictionArea)
{
- using LayoutItemPair = QPair<QLayoutItem*, QLayoutItem*>;
+ using LayoutItemPair = std::pair<QLayoutItem*, QLayoutItem*>;
using LayoutItemPairs = QList<LayoutItemPair>;
QFormLayout *formLayout = qobject_cast<QFormLayout *>(LayoutInfo::managedLayout(core, widgetWithManagedLayout));
@@ -1299,7 +1270,7 @@ void QLayoutSupport::setInsertMode(InsertMode im)
m_currentInsertMode = im;
}
-void QLayoutSupport::setCurrentCell(const QPair<int, int> &cell)
+void QLayoutSupport::setCurrentCell(const std::pair<int, int> &cell)
{
m_currentCell = cell;
}
@@ -1537,7 +1508,7 @@ class QBoxLayoutSupport: public QLayoutSupport
public:
QBoxLayoutSupport(QDesignerFormWindowInterface *formWindow, QWidget *widget, Qt::Orientation orientation, QObject *parent = nullptr);
- void insertWidget(QWidget *widget, const QPair<int, int> &cell) override;
+ void insertWidget(QWidget *widget, const std::pair<int, int> &cell) override;
void removeWidget(QWidget *widget) override;
void simplify() override {}
void insertRow(int /*row*/) override {}
@@ -1563,7 +1534,7 @@ void QBoxLayoutSupport::removeWidget(QWidget *widget)
// of higher index, which happens as follows:
// Drag start: The widget is hidden
// Drop: Current cell is stored, widget is removed and re-added, causing an index offset that needs to be compensated
- QPair<int, int> currCell = currentCell();
+ std::pair<int, int> currCell = currentCell();
switch (m_orientation) {
case Qt::Horizontal:
if (currCell.second > 0 && index < currCell.second ) {
@@ -1590,10 +1561,10 @@ QBoxLayoutSupport::QBoxLayoutSupport(QDesignerFormWindowInterface *formWindow, Q
void QBoxLayoutSupport::setCurrentCellFromIndicatorOnEmptyCell(int index)
{
qDebug() << "QBoxLayoutSupport::setCurrentCellFromIndicatorOnEmptyCell(): Warning: found a fake spacer inside a vbox layout at " << index;
- setCurrentCell(qMakePair(0, 0));
+ setCurrentCell({0, 0});
}
-void QBoxLayoutSupport::insertWidget(QWidget *widget, const QPair<int, int> &cell)
+void QBoxLayoutSupport::insertWidget(QWidget *widget, const std::pair<int, int> &cell)
{
switch (m_orientation) {
case Qt::Horizontal:
@@ -1607,11 +1578,10 @@ void QBoxLayoutSupport::insertWidget(QWidget *widget, const QPair<int, int> &cel
void QBoxLayoutSupport::setCurrentCellFromIndicator(Qt::Orientation indicatorOrientation, int index, int increment)
{
- if (m_orientation == Qt::Horizontal && indicatorOrientation == Qt::Vertical) {
- setCurrentCell(qMakePair(0, index + increment));
- } else if (m_orientation == Qt::Vertical && indicatorOrientation == Qt::Horizontal) {
- setCurrentCell(qMakePair(index + increment, 0));
- }
+ if (m_orientation == Qt::Horizontal && indicatorOrientation == Qt::Vertical)
+ setCurrentCell({0, index + increment});
+ else if (m_orientation == Qt::Vertical && indicatorOrientation == Qt::Horizontal)
+ setCurrentCell({index + increment, 0});
}
bool QBoxLayoutSupport::supportsIndicatorOrientation(Qt::Orientation indicatorOrientation) const
@@ -1669,7 +1639,7 @@ public:
GridLikeLayoutSupportBase(QDesignerFormWindowInterface *formWindow, QWidget *widget, LayoutHelper *helper, QObject *parent = nullptr) :
QLayoutSupport(formWindow, widget, helper, parent) {}
- void insertWidget(QWidget *widget, const QPair<int, int> &cell) override;
+ void insertWidget(QWidget *widget, const std::pair<int, int> &cell) override;
void removeWidget(QWidget *widget) override { helper()->removeWidget(layout(), widget); }
int findItemAt(int row, int column) const override;
using QLayoutSupport::findItemAt;
@@ -1701,7 +1671,7 @@ void GridLikeLayoutSupportBase<GridLikeLayout>::setCurrentCellFromIndicatorOnEmp
int row, column, rowspan, colspan;
getGridItemPosition(grid, index, &row, &column, &rowspan, &colspan);
- setCurrentCell(qMakePair(row, column));
+ setCurrentCell({row, column});
}
template <class GridLikeLayout>
@@ -1713,7 +1683,7 @@ void GridLikeLayoutSupportBase<GridLikeLayout>::setCurrentCellFromIndicator(Qt::
int row = info.top();
int column = increment ? info.right() + 1 : info.left();
checkCellForInsertion(&row, &column);
- setCurrentCell(qMakePair(row , column));
+ setCurrentCell({row, column});
}
break;
case Qt::Horizontal: {
@@ -1721,14 +1691,14 @@ void GridLikeLayoutSupportBase<GridLikeLayout>::setCurrentCellFromIndicator(Qt::
int row = increment ? info.bottom() + 1 : info.top();
int column = info.left();
checkCellForInsertion(&row, &column);
- setCurrentCell(qMakePair(row, column));
+ setCurrentCell({row, column});
}
break;
}
}
template <class GridLikeLayout>
-void GridLikeLayoutSupportBase<GridLikeLayout>::insertWidget(QWidget *widget, const QPair<int, int> &cell)
+void GridLikeLayoutSupportBase<GridLikeLayout>::insertWidget(QWidget *widget, const std::pair<int, int> &cell)
{
helper()->insertWidget(layout(), QRect(cell.second, cell.first, 1, 1), widget);
}