diff options
Diffstat (limited to 'src/designer/src/components/formeditor/formwindow.cpp')
-rw-r--r-- | src/designer/src/components/formeditor/formwindow.cpp | 395 |
1 files changed, 169 insertions, 226 deletions
diff --git a/src/designer/src/components/formeditor/formwindow.cpp b/src/designer/src/components/formeditor/formwindow.cpp index b27b7e18e..35cb0eca6 100644 --- a/src/designer/src/components/formeditor/formwindow.cpp +++ b/src/designer/src/components/formeditor/formwindow.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 "formwindow.h" #include "formeditor.h" @@ -102,6 +77,8 @@ Q_DECLARE_METATYPE(QWidget*) QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace { class BlockSelection { @@ -168,8 +145,7 @@ private: using SelectionPool = QList<WidgetSelection *>; SelectionPool m_selectionPool; - typedef QHash<QWidget *, WidgetSelection *> SelectionHash; - SelectionHash m_usedSelections; + QHash<QWidget *, WidgetSelection *> m_usedSelections; }; FormWindow::Selection::Selection() = default; @@ -204,9 +180,9 @@ WidgetSelection *FormWindow::Selection::addWidget(FormWindow* fw, QWidget *w) return rc; } // find a free one in the pool - for (auto it = m_selectionPool.constBegin(), pend = m_selectionPool.constEnd(); it != pend; ++it) { - if (! (*it)->isUsed()) { - rc = *it; + for (auto *s : std::as_const(m_selectionPool)) { + if (!s->isUsed()) { + rc = s; break; } } @@ -479,11 +455,11 @@ void FormWindow::setMainContainer(QWidget *w) manageWidget(m_mainContainer); if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), m_mainContainer)) { - sheet->setVisible(sheet->indexOf(QStringLiteral("windowTitle")), true); - sheet->setVisible(sheet->indexOf(QStringLiteral("windowIcon")), true); - sheet->setVisible(sheet->indexOf(QStringLiteral("windowModality")), true); - sheet->setVisible(sheet->indexOf(QStringLiteral("windowOpacity")), true); - sheet->setVisible(sheet->indexOf(QStringLiteral("windowFilePath")), true); + sheet->setVisible(sheet->indexOf(u"windowTitle"_s), true); + sheet->setVisible(sheet->indexOf(u"windowIcon"_s), true); + sheet->setVisible(sheet->indexOf(u"windowModality"_s), true); + sheet->setVisible(sheet->indexOf(u"windowOpacity"_s), true); + sheet->setVisible(sheet->indexOf(u"windowFilePath"_s), true); // ### generalize } @@ -692,7 +668,7 @@ bool FormWindow::handleMouseMoveEvent(QWidget *, QWidget *, QMouseEvent *e) QSet<QWidget*> widget_set; - for (QWidget *child : qAsConst(sel)) { // Move parent layout or container? + for (QWidget *child : std::as_const(sel)) { // Move parent layout or container? QWidget *current = child; bool done = false; @@ -729,7 +705,7 @@ bool FormWindow::handleMouseMoveEvent(QWidget *, QWidget *, QMouseEvent *e) const QPoint globalPos = mapToGlobal(m_startPos); const QDesignerDnDItemInterface::DropType dropType = (mouseFlags(e->modifiers()) & CopyDragModifier) ? QDesignerDnDItemInterface::CopyDrop : QDesignerDnDItemInterface::MoveDrop; - for (QWidget *widget : qAsConst(sel)) { + for (QWidget *widget : std::as_const(sel)) { item_list.append(new FormWindowDnDItem(dropType, this, widget, globalPos)); if (dropType == QDesignerDnDItemInterface::MoveDrop) { m_selection->hide(widget); @@ -746,7 +722,7 @@ bool FormWindow::handleMouseMoveEvent(QWidget *, QWidget *, QMouseEvent *e) if (!sel.isEmpty()) // reshow selection? if (QDesignerMimeData::execDrag(item_list, core()->topLevel()) == Qt::IgnoreAction && dropType == QDesignerDnDItemInterface::MoveDrop) - for (QWidget *widget : qAsConst(sel)) + for (QWidget *widget : std::as_const(sel)) m_selection->show(widget); m_startPos = QPoint(); @@ -949,13 +925,9 @@ bool FormWindow::isMainContainer(const QWidget *w) const void FormWindow::updateChildSelections(QWidget *w) { const QWidgetList l = w->findChildren<QWidget*>(); - if (!l.isEmpty()) { - const QWidgetList::const_iterator lcend = l.constEnd(); - for (QWidgetList::const_iterator it = l.constBegin(); it != lcend; ++it) { - QWidget *w = *it; - if (isManaged(w)) - updateSelection(w); - } + for (auto *w : l) { + if (isManaged(w)) + updateSelection(w); } } @@ -1018,129 +990,98 @@ static inline void insertNames(const QDesignerMetaDataBaseInterface *metaDataBas static QSet<QString> languageKeywords() { - static QSet<QString> keywords; - if (keywords.isEmpty()) { + static const QSet<QString> keywords = { // C++ keywords - keywords.insert(QStringLiteral("asm")); - keywords.insert(QStringLiteral("auto")); - keywords.insert(QStringLiteral("bool")); - keywords.insert(QStringLiteral("break")); - keywords.insert(QStringLiteral("case")); - keywords.insert(QStringLiteral("catch")); - keywords.insert(QStringLiteral("char")); - keywords.insert(QStringLiteral("class")); - keywords.insert(QStringLiteral("const")); - keywords.insert(QStringLiteral("const_cast")); - keywords.insert(QStringLiteral("continue")); - keywords.insert(QStringLiteral("default")); - keywords.insert(QStringLiteral("delete")); - keywords.insert(QStringLiteral("do")); - keywords.insert(QStringLiteral("double")); - keywords.insert(QStringLiteral("dynamic_cast")); - keywords.insert(QStringLiteral("else")); - keywords.insert(QStringLiteral("enum")); - keywords.insert(QStringLiteral("explicit")); - keywords.insert(QStringLiteral("export")); - keywords.insert(QStringLiteral("extern")); - keywords.insert(QStringLiteral("false")); - keywords.insert(QStringLiteral("float")); - keywords.insert(QStringLiteral("for")); - keywords.insert(QStringLiteral("friend")); - keywords.insert(QStringLiteral("goto")); - keywords.insert(QStringLiteral("if")); - keywords.insert(QStringLiteral("inline")); - keywords.insert(QStringLiteral("int")); - keywords.insert(QStringLiteral("long")); - keywords.insert(QStringLiteral("mutable")); - keywords.insert(QStringLiteral("namespace")); - keywords.insert(QStringLiteral("new")); - keywords.insert(QStringLiteral("NULL")); - keywords.insert(QStringLiteral("operator")); - keywords.insert(QStringLiteral("private")); - keywords.insert(QStringLiteral("protected")); - keywords.insert(QStringLiteral("public")); - keywords.insert(QStringLiteral("register")); - keywords.insert(QStringLiteral("reinterpret_cast")); - keywords.insert(QStringLiteral("return")); - keywords.insert(QStringLiteral("short")); - keywords.insert(QStringLiteral("signed")); - keywords.insert(QStringLiteral("sizeof")); - keywords.insert(QStringLiteral("static")); - keywords.insert(QStringLiteral("static_cast")); - keywords.insert(QStringLiteral("struct")); - keywords.insert(QStringLiteral("switch")); - keywords.insert(QStringLiteral("template")); - keywords.insert(QStringLiteral("this")); - keywords.insert(QStringLiteral("throw")); - keywords.insert(QStringLiteral("true")); - keywords.insert(QStringLiteral("try")); - keywords.insert(QStringLiteral("typedef")); - keywords.insert(QStringLiteral("typeid")); - keywords.insert(QStringLiteral("typename")); - keywords.insert(QStringLiteral("union")); - keywords.insert(QStringLiteral("unsigned")); - keywords.insert(QStringLiteral("using")); - keywords.insert(QStringLiteral("virtual")); - keywords.insert(QStringLiteral("void")); - keywords.insert(QStringLiteral("volatile")); - keywords.insert(QStringLiteral("wchar_t")); - keywords.insert(QStringLiteral("while")); + u"asm"_s, + u"assert"_s, + u"auto"_s, + u"bool"_s, + u"break"_s, + u"case"_s, + u"catch"_s, + u"char"_s, + u"class"_s, + u"const"_s, + u"const_cast"_s, + u"continue"_s, + u"default"_s, + u"delete"_s, + u"do"_s, + u"double"_s, + u"dynamic_cast"_s, + u"else"_s, + u"enum"_s, + u"explicit"_s, + u"export"_s, + u"extern"_s, + u"false"_s, + u"final"_s, + u"float"_s, + u"for"_s, + u"friend"_s, + u"goto"_s, + u"if"_s, + u"inline"_s, + u"int"_s, + u"long"_s, + u"mutable"_s, + u"namespace"_s, + u"new"_s, + u"noexcept"_s, + u"NULL"_s, + u"nullptr"_s, + u"operator"_s, + u"override"_s, + u"private"_s, + u"protected"_s, + u"public"_s, + u"register"_s, + u"reinterpret_cast"_s, + u"return"_s, + u"short"_s, + u"signed"_s, + u"sizeof"_s, + u"static"_s, + u"static_cast"_s, + u"struct"_s, + u"switch"_s, + u"template"_s, + u"this"_s, + u"throw"_s, + u"true"_s, + u"try"_s, + u"typedef"_s, + u"typeid"_s, + u"typename"_s, + u"union"_s, + u"unsigned"_s, + u"using"_s, + u"virtual"_s, + u"void"_s, + u"volatile"_s, + u"wchar_t"_s, + u"while"_s, // java keywords - keywords.insert(QStringLiteral("abstract")); - keywords.insert(QStringLiteral("assert")); - keywords.insert(QStringLiteral("boolean")); - keywords.insert(QStringLiteral("break")); - keywords.insert(QStringLiteral("byte")); - keywords.insert(QStringLiteral("case")); - keywords.insert(QStringLiteral("catch")); - keywords.insert(QStringLiteral("char")); - keywords.insert(QStringLiteral("class")); - keywords.insert(QStringLiteral("const")); - keywords.insert(QStringLiteral("continue")); - keywords.insert(QStringLiteral("default")); - keywords.insert(QStringLiteral("do")); - keywords.insert(QStringLiteral("double")); - keywords.insert(QStringLiteral("else")); - keywords.insert(QStringLiteral("enum")); - keywords.insert(QStringLiteral("extends")); - keywords.insert(QStringLiteral("false")); - keywords.insert(QStringLiteral("final")); - keywords.insert(QStringLiteral("finality")); - keywords.insert(QStringLiteral("float")); - keywords.insert(QStringLiteral("for")); - keywords.insert(QStringLiteral("goto")); - keywords.insert(QStringLiteral("if")); - keywords.insert(QStringLiteral("implements")); - keywords.insert(QStringLiteral("import")); - keywords.insert(QStringLiteral("instanceof")); - keywords.insert(QStringLiteral("int")); - keywords.insert(QStringLiteral("interface")); - keywords.insert(QStringLiteral("long")); - keywords.insert(QStringLiteral("native")); - keywords.insert(QStringLiteral("new")); - keywords.insert(QStringLiteral("null")); - keywords.insert(QStringLiteral("package")); - keywords.insert(QStringLiteral("private")); - keywords.insert(QStringLiteral("protected")); - keywords.insert(QStringLiteral("public")); - keywords.insert(QStringLiteral("return")); - keywords.insert(QStringLiteral("short")); - keywords.insert(QStringLiteral("static")); - keywords.insert(QStringLiteral("strictfp")); - keywords.insert(QStringLiteral("super")); - keywords.insert(QStringLiteral("switch")); - keywords.insert(QStringLiteral("synchronized")); - keywords.insert(QStringLiteral("this")); - keywords.insert(QStringLiteral("throw")); - keywords.insert(QStringLiteral("throws")); - keywords.insert(QStringLiteral("transient")); - keywords.insert(QStringLiteral("true")); - keywords.insert(QStringLiteral("try")); - keywords.insert(QStringLiteral("void")); - keywords.insert(QStringLiteral("volatile")); - keywords.insert(QStringLiteral("while")); - } + u"abstract"_s, + u"boolean"_s, + u"byte"_s, + u"extends"_s, + u"finality"_s, + u"implements"_s, + u"import"_s, + u"instanceof"_s, + u"interface"_s, + u"native"_s, + u"null"_s, + u"package"_s, + u"strictfp"_s, + u"super"_s, + u"synchronized"_s, + u"throws"_s, + u"transient"_s, + }; + return keywords; } @@ -1174,8 +1115,7 @@ bool FormWindow::unify(QObject *w, QString &s, bool changeIt) if (!buttonGroupChildren.isEmpty()) insertNames(metaDataBase, buttonGroupChildren.constBegin(), buttonGroupChildren.constEnd(), w, existingNames); - const StringSet::const_iterator enEnd = existingNames.constEnd(); - if (existingNames.constFind(s) == enEnd) + if (!existingNames.contains(s)) return true; if (!changeIt) return false; @@ -1183,26 +1123,26 @@ bool FormWindow::unify(QObject *w, QString &s, bool changeIt) // split 'name_number' qlonglong num = 0; qlonglong factor = 1; - int idx = s.length()-1; - const ushort zeroUnicode = QLatin1Char('0').unicode(); + qsizetype idx = s.size() - 1; + const char16_t zeroUnicode = u'0'; for ( ; idx > 0 && s.at(idx).isDigit(); --idx) { num += (s.at(idx).unicode() - zeroUnicode) * factor; factor *= 10; } // Position index past '_'. - const QChar underscore = QLatin1Char('_'); + const QChar underscore = u'_'; if (idx >= 0 && s.at(idx) == underscore) { idx++; } else { num = 1; s += underscore; - idx = s.length(); + idx = s.size(); } // try 'name_n', 'name_n+1' for (num++ ; ;num++) { s.truncate(idx); s += QString::number(num); - if (existingNames.constFind(s) == enEnd) + if (!existingNames.contains(s)) break; } return false; @@ -1222,7 +1162,7 @@ void FormWindow::insertWidget(QWidget *w, const QRect &rect, QWidget *container, QRect r = rect; Q_ASSERT(r.isValid()); SetPropertyCommand *geom_cmd = new SetPropertyCommand(this); - geom_cmd->init(w, QStringLiteral("geometry"), r); // ### use rc.size() + geom_cmd->init(w, u"geometry"_s, r); // ### use rc.size() if (w->parentWidget() != container) { ReparentWidgetCommand *cmd = new ReparentWidgetCommand(this); @@ -1232,8 +1172,19 @@ void FormWindow::insertWidget(QWidget *w, const QRect &rect, QWidget *container, m_undoStack.push(geom_cmd); - InsertWidgetCommand *cmd = new InsertWidgetCommand(this); - cmd->init(w, already_in_form); + QUndoCommand *cmd = nullptr; + if (auto dockWidget = qobject_cast<QDockWidget *>(w)) { + if (auto mainWindow = qobject_cast<QMainWindow *>(container)) { + auto addDockCmd = new AddDockWidgetCommand(this); + addDockCmd->init(mainWindow, dockWidget); + cmd = addDockCmd; + } + } + if (cmd == nullptr) { + auto insertCmd = new InsertWidgetCommand(this); + insertCmd->init(w, already_in_form); + cmd = insertCmd; + } m_undoStack.push(cmd); endCommand(); @@ -1276,7 +1227,7 @@ void FormWindow::resizeWidget(QWidget *widget, const QRect &geometry) QRect r = geometry; SetPropertyCommand *cmd = new SetPropertyCommand(this); - cmd->init(widget, QStringLiteral("geometry"), r); + cmd->init(widget, u"geometry"_s, r); cmd->setText(tr("Resize")); m_undoStack.push(cmd); } @@ -1299,7 +1250,7 @@ QWidget *FormWindow::containerAt(const QPoint &pos, QWidget *notParentOf) depth = widgetDepth(container); } - for (QWidget *wit : qAsConst(m_widgets)) { + for (QWidget *wit : std::as_const(m_widgets)) { if (qobject_cast<QLayoutWidget*>(wit) || qobject_cast<QSplitter*>(wit)) continue; if (!wit->isVisibleTo(this)) @@ -1476,10 +1427,12 @@ public: QDesignerPropertySheetExtension *s, int i) : PropertyHelper(o, sp, s, i) {} - Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, unsigned subPropertyMask) override; + Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, + quint64 subPropertyMask) override; }; -PropertyHelper::Value ArrowKeyPropertyHelper::setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, unsigned subPropertyMask) +PropertyHelper::Value ArrowKeyPropertyHelper::setValue(QDesignerFormWindowInterface *fw, const QVariant &value, + bool changed, quint64 subPropertyMask) { // Apply operation to obtain the new geometry value. QWidget *w = qobject_cast<QWidget*>(object()); @@ -1499,9 +1452,10 @@ public: void init(QWidgetList &l, const ArrowKeyOperation &op); protected: - PropertyHelper *createPropertyHelper(QObject *o, SpecialProperty sp, - QDesignerPropertySheetExtension *s, int i) const override - { return new ArrowKeyPropertyHelper(o, sp, s, i); } + std::unique_ptr<PropertyHelper> + createPropertyHelper(QObject *o, SpecialProperty sp, + QDesignerPropertySheetExtension *s, int i) const override + { return std::make_unique<ArrowKeyPropertyHelper>(o, sp, s, i); } QVariant mergeValue(const QVariant &newValue) override; }; @@ -1516,9 +1470,9 @@ ArrowKeyPropertyCommand::ArrowKeyPropertyCommand(QDesignerFormWindowInterface *f void ArrowKeyPropertyCommand::init(QWidgetList &l, const ArrowKeyOperation &op) { QObjectList ol; - for (QWidget *w : qAsConst(l)) + for (QWidget *w : std::as_const(l)) ol.push_back(w); - SetPropertyCommand::init(ol, QStringLiteral("geometry"), QVariant::fromValue(op)); + SetPropertyCommand::init(ol, u"geometry"_s, QVariant::fromValue(op)); setText(op.resize ? FormWindow::tr("Key Resize") : FormWindow::tr("Key Move")); } @@ -1591,7 +1545,7 @@ bool FormWindow::handleKeyReleaseEvent(QWidget *, QWidget *, QKeyEvent *e) void FormWindow::selectAll() { bool selectionChanged = false; - for (QWidget *widget : qAsConst(m_widgets)) { + for (QWidget *widget : std::as_const(m_widgets)) { if (widget->isVisibleTo(this) && trySelectWidget(widget, true)) selectionChanged = true; } @@ -1743,15 +1697,14 @@ static inline DomUI *domUIFromClipboard(int *widgetCount, int *actionCount) { *widgetCount = *actionCount = 0; const QString clipboardText = qApp->clipboard()->text(); - if (clipboardText.isEmpty() || clipboardText.indexOf(QLatin1Char('<')) == -1) + if (clipboardText.isEmpty() || clipboardText.indexOf(u'<') == -1) return nullptr; QXmlStreamReader reader(clipboardText); DomUI *ui = nullptr; - const QString uiElement = QStringLiteral("ui"); while (!reader.atEnd()) { if (reader.readNext() == QXmlStreamReader::StartElement) { - if (reader.name().compare(uiElement, Qt::CaseInsensitive) == 0 && !ui) { + if (reader.name().compare("ui"_L1, Qt::CaseInsensitive) == 0 && !ui) { ui = new DomUI(); ui->read(reader); break; @@ -1803,9 +1756,8 @@ static void positionPastedWidgetsAtMousePosition(FormWindow *fw, const QPoint &c cursorPos = grid.snapPoint(QPoint(0, 0)); // Determine area of pasted widgets QRect pasteArea; - const QWidgetList::const_iterator lcend = l.constEnd(); - for (QWidgetList::const_iterator it = l.constBegin(); it != lcend; ++it) - pasteArea =pasteArea.isNull() ? (*it)->geometry() : pasteArea.united((*it)->geometry()); + for (auto *w : l) + pasteArea = pasteArea.isNull() ? w->geometry() : pasteArea.united(w->geometry()); // Mouse on some child? (try to position bottomRight on a free spot to // get the stacked-offset effect of Designer 4.3, that is, offset by grid if Ctrl-V is pressed continuously @@ -1817,8 +1769,8 @@ static void positionPastedWidgetsAtMousePosition(FormWindow *fw, const QPoint &c } while (true); // Move. const QPoint offset = cursorPos - pasteArea.topLeft(); - for (QWidgetList::const_iterator it = l.constBegin(); it != lcend; ++it) - (*it)->move((*it)->pos() + offset); + for (auto *w : l) + w->move(w->pos() + offset); } void FormWindow::paste(PasteMode pasteMode) @@ -1996,15 +1948,14 @@ void FormWindow::breakLayout(QWidget *w) // Find the first-order managed child widgets QWidgetList widgets; - const QObjectList children = w->children(); - const QObjectList::const_iterator cend = children.constEnd(); const QDesignerMetaDataBaseInterface *mdb = core()->metaDataBase(); - for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it) - if ( (*it)->isWidgetType()) { - QWidget *w = static_cast<QWidget*>(*it); + for (auto *o : w->children()) { + if (o->isWidgetType()) { + auto *w = static_cast<QWidget*>(o); if (mdb->item(w)) widgets.push_back(w); } + } BreakLayoutCommand *cmd = new BreakLayoutCommand(this); cmd->init(widgets, w); @@ -2031,7 +1982,7 @@ void FormWindow::raiseWidgets() return; beginCommand(tr("Raise widgets")); - for (QWidget *widget : qAsConst(widgets)) { + for (QWidget *widget : std::as_const(widgets)) { RaiseWidgetCommand *cmd = new RaiseWidgetCommand(this); cmd->init(widget); m_undoStack.push(cmd); @@ -2048,7 +1999,7 @@ void FormWindow::lowerWidgets() return; beginCommand(tr("Lower widgets")); - for (QWidget *widget : qAsConst(widgets)) { + for (QWidget *widget : std::as_const(widgets)) { LowerWidgetCommand *cmd = new LowerWidgetCommand(this); cmd->init(widget); m_undoStack.push(cmd); @@ -2188,16 +2139,15 @@ void FormWindow::layoutContainer(QWidget *w, int type) w = core()->widgetFactory()->containerOfWidget(w); - const QObjectList l = w->children(); // find managed widget children QWidgetList widgets; - const QObjectList::const_iterator ocend = l.constEnd(); - for (QObjectList::const_iterator it = l.constBegin(); it != ocend; ++it) - if ( (*it)->isWidgetType() ) { - QWidget *widget = static_cast<QWidget*>(*it); + for (auto *o : w->children()) { + if (o->isWidgetType() ) { + auto *widget = static_cast<QWidget*>(o); if (widget->isVisibleTo(this) && isManaged(widget)) widgets.append(widget); } + } if (widgets.isEmpty()) // QTBUG-50563, observed when using hand-edited forms. return; @@ -2267,9 +2217,7 @@ QAction *FormWindow::createSelectAncestorSubMenu(QWidget *w) QMenu *menu = new QMenu; QActionGroup *ag = new QActionGroup(menu); QObject::connect(ag, &QActionGroup::triggered, this, &FormWindow::slotSelectWidget); - const int size = parents.size(); - for (int i = 0; i < size; i++) { - QWidget *w = parents.at(i); + for (auto *w : std::as_const(parents)) { QAction *a = ag->addAction(objectNameOf(w)); a->setData(QVariant::fromValue(w)); menu->addAction(a); @@ -2368,7 +2316,7 @@ QPoint FormWindow::mapToForm(const QWidget *w, const QPoint &pos) const bool FormWindow::canBeBuddy(QWidget *w) const // ### rename me. { if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), w)) { - const int index = sheet->indexOf(QStringLiteral("focusPolicy")); + const int index = sheet->indexOf(u"focusPolicy"_s); if (index != -1) { bool ok = false; const Qt::FocusPolicy q = static_cast<Qt::FocusPolicy>(Utils::valueOf(sheet->property(index), &ok)); @@ -2428,9 +2376,7 @@ void FormWindow::simplifySelection(QWidgetList *sel) const } QWidgetList toBeRemoved; toBeRemoved.reserve(sel->size()); - const QWidgetList::const_iterator scend = sel->constEnd(); - for (QWidgetList::const_iterator it = sel->constBegin(); it != scend; ++it) { - QWidget *child = *it; + for (auto *child : std::as_const(*sel)) { for (QWidget *w = child; true ; ) { // Is any of the parents also selected? QWidget *parent = w->parentWidget(); if (!parent || parent == mainC) @@ -2444,11 +2390,8 @@ void FormWindow::simplifySelection(QWidgetList *sel) const } // Now we can actually remove the widgets that were marked // for removal in the previous pass. - if (!toBeRemoved.isEmpty()) { - const QWidgetList::const_iterator rcend = toBeRemoved.constEnd(); - for (QWidgetList::const_iterator it = toBeRemoved.constBegin(); it != rcend; ++it) - sel->removeAll(*it); - } + for (auto *r : std::as_const(toBeRemoved)) + sel->removeAll(r); } FormWindow *FormWindow::findFormWindow(QWidget *w) @@ -2478,8 +2421,8 @@ QWidget *FormWindow::containerAt(const QPoint &pos) static QWidget *childAt_SkipDropLine(QWidget *w, QPoint pos) { const QObjectList &child_list = w->children(); - for (int i = child_list.size() - 1; i >= 0; --i) { - QObject *child_obj = child_list[i]; + for (auto i = child_list.size() - 1; i >= 0; --i) { + QObject *child_obj = child_list.at(i); if (qobject_cast<WidgetHandle*>(child_obj) != nullptr) continue; QWidget *child = qobject_cast<QWidget*>(child_obj); @@ -2540,7 +2483,7 @@ void FormWindow::highlightWidget(QWidget *widget, const QPoint &pos, HighlightMo return; if (mode == Restore) { - const WidgetPaletteMap::iterator pit = m_palettesBeforeHighlight.find(container); + const auto pit = m_palettesBeforeHighlight.find(container); if (pit != m_palettesBeforeHighlight.end()) { container->setPalette(pit.value().first); container->setAutoFillBackground(pit.value().second); @@ -2700,7 +2643,7 @@ bool FormWindow::blockSelectionChanged(bool b) void FormWindow::editContents() { const QWidgetList sel = selectedWidgets(); - if (sel.count() == 1) { + if (sel.size() == 1) { QWidget *widget = sel.first(); if (QAction *a = preferredEditAction(core(), widget)) @@ -2818,7 +2761,7 @@ bool FormWindow::dropDockWidget(QDesignerDnDItemInterface *item, const QPoint &g QDesignerPropertySheetExtension *propertySheet = qobject_cast<QDesignerPropertySheetExtension*>(m_core->extensionManager()->extension(widget, Q_TYPEID(QDesignerPropertySheetExtension))); if (propertySheet) { - const QString dockWidgetAreaName = QStringLiteral("dockWidgetArea"); + const QString dockWidgetAreaName = u"dockWidgetArea"_s; PropertySheetEnumValue e = qvariant_cast<PropertySheetEnumValue>(propertySheet->property(propertySheet->indexOf(dockWidgetAreaName))); e.value = area; QVariant v; @@ -2864,7 +2807,7 @@ bool FormWindow::dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list, QPoint offset; QDesignerDnDItemInterface *current = nullptr; QDesignerFormWindowCursorInterface *c = cursor(); - for (QDesignerDnDItemInterface *item : qAsConst(item_list)) { + for (QDesignerDnDItemInterface *item : std::as_const(item_list)) { QWidget *w = item->widget(); if (!current) current = item; @@ -2879,7 +2822,7 @@ bool FormWindow::dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list, offset = designerGrid().snapPoint(topLeft) - topLeft; } - for (QDesignerDnDItemInterface *item : qAsConst(item_list)) { + for (QDesignerDnDItemInterface *item : std::as_const(item_list)) { DomUI *dom_ui = item->domUi(); QRect geometry = item->decoration()->geometry(); Q_ASSERT(dom_ui != nullptr); |