diff options
Diffstat (limited to 'src/designer/src/lib/shared')
160 files changed, 4441 insertions, 7149 deletions
diff --git a/src/designer/src/lib/shared/actioneditor.cpp b/src/designer/src/lib/shared/actioneditor.cpp index d1ce9804e..b6f3c778c 100644 --- a/src/designer/src/lib/shared/actioneditor.cpp +++ b/src/designer/src/lib/shared/actioneditor.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 "actioneditor_p.h" #include "actionrepository_p.h" @@ -70,18 +45,19 @@ #include <QtCore/qdebug.h> #include <QtCore/qbuffer.h> -Q_DECLARE_METATYPE(QAction*) - QT_BEGIN_NAMESPACE -static const char *actionEditorViewModeKey = "ActionEditorViewMode"; +using namespace Qt::StringLiterals; + +static constexpr auto actionEditorViewModeKey = "ActionEditorViewMode"_L1; -static const char *iconPropertyC = "icon"; -static const char *shortcutPropertyC = "shortcut"; -static const char *toolTipPropertyC = "toolTip"; -static const char *checkablePropertyC = "checkable"; -static const char *objectNamePropertyC = "objectName"; -static const char *textPropertyC = "text"; +static constexpr auto iconPropertyC = "icon"_L1; +static constexpr auto shortcutPropertyC = "shortcut"_L1; +static constexpr auto menuRolePropertyC = "menuRole"_L1; +static constexpr auto toolTipPropertyC = "toolTip"_L1; +static constexpr auto checkablePropertyC = "checkable"_L1; +static constexpr auto objectNamePropertyC = "objectName"_L1; +static constexpr auto textPropertyC = "text"_L1; namespace qdesigner_internal { //-------- ActionGroupDelegate @@ -138,7 +114,8 @@ ActionEditor::ActionEditor(QDesignerFormEditorInterface *core, QWidget *parent, toolbar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); l->addWidget(toolbar); // edit actions - QIcon documentNewIcon = QIcon::fromTheme(QStringLiteral("document-new"), createIconSet(QStringLiteral("filenew.png"))); + QIcon documentNewIcon = createIconSet(QIcon::ThemeIcon::DocumentNew, + "filenew.png"_L1); m_actionNew->setIcon(documentNewIcon); m_actionNew->setEnabled(false); connect(m_actionNew, &QAction::triggered, this, &ActionEditor::slotNewAction); @@ -149,17 +126,20 @@ ActionEditor::ActionEditor(QDesignerFormEditorInterface *core, QWidget *parent, #if QT_CONFIG(clipboard) m_actionCut->setEnabled(false); connect(m_actionCut, &QAction::triggered, this, &ActionEditor::slotCut); - QIcon editCutIcon = QIcon::fromTheme(QStringLiteral("edit-cut"), createIconSet(QStringLiteral("editcut.png"))); + QIcon editCutIcon = createIconSet(QIcon::ThemeIcon::EditCut, + "editcut.png"_L1); m_actionCut->setIcon(editCutIcon); m_actionCopy->setEnabled(false); connect(m_actionCopy, &QAction::triggered, this, &ActionEditor::slotCopy); - QIcon editCopyIcon = QIcon::fromTheme(QStringLiteral("edit-copy"), createIconSet(QStringLiteral("editcopy.png"))); + QIcon editCopyIcon = createIconSet(QIcon::ThemeIcon::EditCopy, + "editcopy.png"_L1); m_actionCopy->setIcon(editCopyIcon); toolbar->addAction(m_actionCopy); connect(m_actionPaste, &QAction::triggered, this, &ActionEditor::slotPaste); - QIcon editPasteIcon = QIcon::fromTheme(QStringLiteral("edit-paste"), createIconSet(QStringLiteral("editpaste.png"))); + QIcon editPasteIcon = createIconSet(QIcon::ThemeIcon::EditPaste, + "editpaste.png"_L1); m_actionPaste->setIcon(editPasteIcon); toolbar->addAction(m_actionPaste); #endif @@ -169,7 +149,8 @@ ActionEditor::ActionEditor(QDesignerFormEditorInterface *core, QWidget *parent, connect(m_actionNavigateToSlot, &QAction::triggered, this, &ActionEditor::navigateToSlotCurrentAction); - QIcon editDeleteIcon = QIcon::fromTheme(QStringLiteral("edit-delete"), createIconSet(QStringLiteral("editdelete.png"))); + QIcon editDeleteIcon = createIconSet(QIcon::ThemeIcon::EditDelete, + "editdelete.png"_L1); m_actionDelete->setIcon(editDeleteIcon); m_actionDelete->setEnabled(false); connect(m_actionDelete, &QAction::triggered, this, &ActionEditor::slotDelete); @@ -248,9 +229,10 @@ QToolButton *ActionEditor::createConfigureMenuButton(const QString &t, QMenu **p { QToolButton *configureButton = new QToolButton; QAction *configureAction = new QAction(t, configureButton); - QIcon configureIcon = QIcon::fromTheme(QStringLiteral("document-properties"), createIconSet(QStringLiteral("configure.png"))); + QIcon configureIcon = QIcon::fromTheme(QIcon::ThemeIcon::DocumentProperties, + createIconSet("configure.png"_L1)); configureAction->setIcon(configureIcon); - QMenu *configureMenu = new QMenu; + QMenu *configureMenu = new QMenu(configureButton); configureAction->setMenu(configureMenu); configureButton->setDefaultAction(configureAction); configureButton->setPopupMode(QToolButton::InstantPopup); @@ -351,7 +333,13 @@ void ActionEditor::slotCurrentItemChanged(QAction *action) QDesignerObjectInspector *oi = qobject_cast<QDesignerObjectInspector *>(core()->objectInspector()); - if (action->associatedWidgets().isEmpty()) { + // Check if we have at least one associated QWidget: + const auto associatedObjects = action->associatedObjects(); + auto it = std::find_if(associatedObjects.cbegin(), associatedObjects.cend(), + [](QObject *obj) { + return qobject_cast<QWidget *>(obj) != nullptr; + }); + if (it == associatedObjects.cend()) { // Special case: action not in object tree. Deselect all and set in property editor fw->clearSelection(false); if (oi) @@ -400,7 +388,7 @@ void ActionEditor::setFilter(const QString &f) // Set changed state of icon property, reset when icon is cleared static void refreshIconPropertyChanged(const QAction *action, QDesignerPropertySheetExtension *sheet) { - sheet->setChanged(sheet->indexOf(QLatin1String(iconPropertyC)), !action->icon().isNull()); + sheet->setChanged(sheet->indexOf(iconPropertyC), !action->icon().isNull()); } void ActionEditor::manageAction(QAction *action) @@ -412,8 +400,8 @@ void ActionEditor::manageAction(QAction *action) return; QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), action); - sheet->setChanged(sheet->indexOf(QLatin1String(objectNamePropertyC)), true); - sheet->setChanged(sheet->indexOf(QLatin1String(textPropertyC)), true); + sheet->setChanged(sheet->indexOf(objectNamePropertyC), true); + sheet->setChanged(sheet->indexOf(textPropertyC), true); refreshIconPropertyChanged(action, sheet); m_actionView->setCurrentIndex(m_actionView->model()->addAction(action)); @@ -456,15 +444,17 @@ void ActionEditor::slotNewAction() QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), action); if (!actionData.toolTip.isEmpty()) - setInitialProperty(sheet, QLatin1String(toolTipPropertyC), actionData.toolTip); + setInitialProperty(sheet, toolTipPropertyC, actionData.toolTip); if (actionData.checkable) - setInitialProperty(sheet, QLatin1String(checkablePropertyC), QVariant(true)); + setInitialProperty(sheet, checkablePropertyC, QVariant(true)); if (!actionData.keysequence.value().isEmpty()) - setInitialProperty(sheet, QLatin1String(shortcutPropertyC), QVariant::fromValue(actionData.keysequence)); + setInitialProperty(sheet, shortcutPropertyC, QVariant::fromValue(actionData.keysequence)); + + sheet->setProperty(sheet->indexOf(iconPropertyC), QVariant::fromValue(actionData.icon)); - sheet->setProperty(sheet->indexOf(QLatin1String(iconPropertyC)), QVariant::fromValue(actionData.icon)); + setInitialProperty(sheet, menuRolePropertyC, QVariant::fromValue(actionData.menuRole)); AddActionCommand *cmd = new AddActionCommand(formWindow()); cmd->init(action); @@ -477,7 +467,7 @@ void ActionEditor::slotNewAction() static QDesignerFormWindowCommand *setIconPropertyCommand(const PropertySheetIconValue &newIcon, QAction *action, QDesignerFormWindowInterface *fw) { - const QString iconProperty = QLatin1String(iconPropertyC); + const QString iconProperty = iconPropertyC; if (newIcon.isEmpty()) { ResetPropertyCommand *cmd = new ResetPropertyCommand(fw); cmd->init(action, iconProperty); @@ -493,7 +483,7 @@ static QDesignerFormWindowCommand *setIconPropertyCommand(const PropertySheetIco static QDesignerFormWindowCommand *setKeySequencePropertyCommand(const PropertySheetKeySequenceValue &ks, QAction *action, QDesignerFormWindowInterface *fw) { - const QString shortcutProperty = QLatin1String(shortcutPropertyC); + const QString shortcutProperty = shortcutPropertyC; if (ks.value().isEmpty()) { ResetPropertyCommand *cmd = new ResetPropertyCommand(fw); cmd->init(action, shortcutProperty); @@ -542,10 +532,11 @@ void ActionEditor::editAction(QAction *action, int column) QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), action); oldActionData.name = action->objectName(); oldActionData.text = action->text(); - oldActionData.toolTip = textPropertyValue(sheet, QLatin1String(toolTipPropertyC)); - oldActionData.icon = qvariant_cast<PropertySheetIconValue>(sheet->property(sheet->indexOf(QLatin1String(iconPropertyC)))); + oldActionData.toolTip = textPropertyValue(sheet, toolTipPropertyC); + oldActionData.icon = qvariant_cast<PropertySheetIconValue>(sheet->property(sheet->indexOf(iconPropertyC))); oldActionData.keysequence = ActionModel::actionShortCut(sheet); oldActionData.checkable = action->isCheckable(); + oldActionData.menuRole.value = action->menuRole(); dlg.setActionData(oldActionData); switch (column) { @@ -564,6 +555,9 @@ void ActionEditor::editAction(QAction *action, int column) case qdesigner_internal::ActionModel::ToolTipColumn: dlg.focusTooltip(); break; + case qdesigner_internal::ActionModel::MenuRoleColumn: + dlg.focusMenuRole(); + break; } if (!dlg.exec()) @@ -577,31 +571,35 @@ void ActionEditor::editAction(QAction *action, int column) const bool severalChanges = (changeMask != ActionData::TextChanged) && (changeMask != ActionData::NameChanged) && (changeMask != ActionData::ToolTipChanged) && (changeMask != ActionData::IconChanged) - && (changeMask != ActionData::CheckableChanged) && (changeMask != ActionData::KeysequenceChanged); + && (changeMask != ActionData::CheckableChanged) && (changeMask != ActionData::KeysequenceChanged) + && (changeMask != ActionData::MenuRoleChanged); QDesignerFormWindowInterface *fw = formWindow(); QUndoStack *undoStack = fw->commandHistory(); if (severalChanges) - fw->beginCommand(QStringLiteral("Edit action")); + fw->beginCommand(u"Edit action"_s); if (changeMask & ActionData::NameChanged) - undoStack->push(createTextPropertyCommand(QLatin1String(objectNamePropertyC), newActionData.name, action, fw)); + undoStack->push(createTextPropertyCommand(objectNamePropertyC, newActionData.name, action, fw)); if (changeMask & ActionData::TextChanged) - undoStack->push(createTextPropertyCommand(QLatin1String(textPropertyC), newActionData.text, action, fw)); + undoStack->push(createTextPropertyCommand(textPropertyC, newActionData.text, action, fw)); if (changeMask & ActionData::ToolTipChanged) - undoStack->push(createTextPropertyCommand(QLatin1String(toolTipPropertyC), newActionData.toolTip, action, fw)); + undoStack->push(createTextPropertyCommand(toolTipPropertyC, newActionData.toolTip, action, fw)); if (changeMask & ActionData::IconChanged) undoStack->push(setIconPropertyCommand(newActionData.icon, action, fw)); if (changeMask & ActionData::CheckableChanged) - undoStack->push(setPropertyCommand(QLatin1String(checkablePropertyC), newActionData.checkable, false, action, fw)); + undoStack->push(setPropertyCommand(checkablePropertyC, newActionData.checkable, false, action, fw)); if (changeMask & ActionData::KeysequenceChanged) undoStack->push(setKeySequencePropertyCommand(newActionData.keysequence, action, fw)); + if (changeMask & ActionData::MenuRoleChanged) + undoStack->push(setPropertyCommand(menuRolePropertyC, static_cast<QAction::MenuRole>(newActionData.menuRole.value), QAction::NoRole, action, fw)); + if (severalChanges) fw->endCommand(); } @@ -615,7 +613,7 @@ void ActionEditor::editCurrentAction() void ActionEditor::navigateToSlotCurrentAction() { if (QAction *a = m_actionView->currentAction()) - QDesignerTaskMenu::navigateToSlot(m_core, a, QStringLiteral("triggered()")); + QDesignerTaskMenu::navigateToSlot(m_core, a, u"triggered()"_s); } void ActionEditor::deleteActions(QDesignerFormWindowInterface *fw, const ActionList &actions) @@ -674,14 +672,13 @@ void ActionEditor::slotDelete() // UnderScore: "Open file" -> actionOpen_file static QString underscore(QString text) { - const QString underscore = QString(QLatin1Char('_')); - static const QRegularExpression nonAsciiPattern(QStringLiteral("[^a-zA-Z_0-9]")); + static const QRegularExpression nonAsciiPattern(u"[^a-zA-Z_0-9]"_s); Q_ASSERT(nonAsciiPattern.isValid()); - text.replace(nonAsciiPattern, underscore); - static const QRegularExpression multipleSpacePattern(QStringLiteral("__*")); + text.replace(nonAsciiPattern, "_"_L1); + static const QRegularExpression multipleSpacePattern(u"__*"_s); Q_ASSERT(multipleSpacePattern.isValid()); - text.replace(multipleSpacePattern, underscore); - if (text.endsWith(underscore.at(0))) + text.replace(multipleSpacePattern, "_"_L1); + if (text.endsWith(u'_')) text.chop(1); return text; } @@ -736,7 +733,7 @@ void ActionEditor::resourceImageDropped(const QString &path, QAction *action) QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), action); const PropertySheetIconValue oldIcon = - qvariant_cast<PropertySheetIconValue>(sheet->property(sheet->indexOf(QLatin1String(iconPropertyC)))); + qvariant_cast<PropertySheetIconValue>(sheet->property(sheet->indexOf(iconPropertyC))); PropertySheetIconValue newIcon; newIcon.setPixmap(QIcon::Normal, QIcon::Off, PropertySheetPixmapValue(path)); if (newIcon.paths().isEmpty() || newIcon.paths() == oldIcon.paths()) @@ -793,14 +790,14 @@ void ActionEditor::slotSelectAssociatedWidget(QWidget *w) void ActionEditor::restoreSettings() { QDesignerSettingsInterface *settings = m_core->settingsManager(); - m_actionView->setViewMode(settings->value(QLatin1String(actionEditorViewModeKey), 0).toInt()); + m_actionView->setViewMode(settings->value(actionEditorViewModeKey, 0).toInt()); updateViewModeActions(); } void ActionEditor::saveSettings() { QDesignerSettingsInterface *settings = m_core->settingsManager(); - settings->setValue(QLatin1String(actionEditorViewModeKey), m_actionView->viewMode()); + settings->setValue(actionEditorViewModeKey, m_actionView->viewMode()); } void ActionEditor::updateViewModeActions() diff --git a/src/designer/src/lib/shared/actioneditor_p.h b/src/designer/src/lib/shared/actioneditor_p.h index 911289c8f..471d12d04 100644 --- a/src/designer/src/lib/shared/actioneditor_p.h +++ b/src/designer/src/lib/shared/actioneditor_p.h @@ -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 // // W A R N I N G @@ -88,7 +63,7 @@ public: static void setObjectNamingMode(ObjectNamingMode n) { m_objectNamingMode = n; } static QString actionTextToName(const QString &text, - const QString &prefix = QLatin1String("action")); + const QString &prefix = QLatin1StringView("action")); // Utility to create a configure button with menu for usage on toolbars static QToolButton *createConfigureMenuButton(const QString &t, QMenu **ptrToMenu); diff --git a/src/designer/src/lib/shared/actionprovider_p.h b/src/designer/src/lib/shared/actionprovider_p.h index 63d902951..16f987da9 100644 --- a/src/designer/src/lib/shared/actionprovider_p.h +++ b/src/designer/src/lib/shared/actionprovider_p.h @@ -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 #ifndef ACTIONPROVIDER_H #define ACTIONPROVIDER_H @@ -67,15 +42,14 @@ template <class Widget> int actionIndexAt(const Widget *w, const QPoint &pos, Qt::Orientation orientation) { const auto actions = w->actions(); - const int actionCount = actions.count(); - if (actionCount == 0) + if (actions.isEmpty()) return -1; // actionGeometry() can be wrong sometimes; it returns a geometry that // stretches to the end of the toolbar/menu bar. So, check from the beginning // in the case of a horizontal right-to-left orientation. const bool checkTopRight = orientation == Qt::Horizontal && w->layoutDirection() == Qt::RightToLeft; const QPoint topRight = QPoint(w->rect().width(), 0); - for (int index = 0; index < actionCount; ++index) { + for (qsizetype index = 0, actionCount = actions.size(); index < actionCount; ++index) { QRect g = w->actionGeometry(actions.at(index)); if (checkTopRight) g.setTopRight(topRight); @@ -83,7 +57,7 @@ template <class Widget> g.setTopLeft(QPoint(0, 0)); if (g.contains(pos)) - return index; + return int(index); } return -1; } diff --git a/src/designer/src/lib/shared/actionrepository.cpp b/src/designer/src/lib/shared/actionrepository.cpp index b9f60cdb6..59d8fc6b7 100644 --- a/src/designer/src/lib/shared/actionrepository.cpp +++ b/src/designer/src/lib/shared/actionrepository.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 "actionrepository_p.h" #include "qtresourceview_p.h" @@ -48,17 +23,18 @@ #include <QtCore/qset.h> #include <QtCore/qdebug.h> - -Q_DECLARE_METATYPE(QAction*) +#include <QtCore/qmetaobject.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace { enum { listModeIconSize = 16, iconModeIconSize = 24 }; } -static const char *actionMimeType = "action-repository/actions"; -static const char *plainTextMimeType = "text/plain"; +static constexpr auto actionMimeType = "action-repository/actions"_L1; +static constexpr auto plainTextMimeType = "text/plain"_L1; static inline QAction *actionOfItem(const QStandardItem* item) { @@ -79,6 +55,7 @@ ActionModel::ActionModel(QWidget *parent ) : headers += tr("Shortcut"); headers += tr("Checkable"); headers += tr("ToolTip"); + headers += tr("MenuRole"); Q_ASSERT(NumColumns == headers.size()); setHorizontalHeaderLabels(headers); } @@ -139,14 +116,16 @@ QModelIndex ActionModel::addAction(QAction *action) // Find the associated menus and toolbars, ignore toolbuttons QWidgetList ActionModel::associatedWidgets(const QAction *action) { - QWidgetList rc = action->associatedWidgets(); - for (QWidgetList::iterator it = rc.begin(); it != rc.end(); ) - if (qobject_cast<const QMenu *>(*it) || qobject_cast<const QToolBar *>(*it)) { - ++it; - } else { - it = rc.erase(it); + const QObjectList rc = action->associatedObjects(); + QWidgetList result; + result.reserve(rc.size()); + for (QObject *obj : rc) { + if (QWidget *w = qobject_cast<QWidget *>(obj)) { + if (qobject_cast<const QMenu *>(w) || qobject_cast<const QToolBar *>(w)) + result.push_back(w); } - return rc; + } + return result; } // shortcut is a fake property, need to retrieve it via property sheet. @@ -160,7 +139,7 @@ PropertySheetKeySequenceValue ActionModel::actionShortCut(QDesignerFormEditorInt PropertySheetKeySequenceValue ActionModel::actionShortCut(const QDesignerPropertySheetExtension *sheet) { - const int index = sheet->indexOf(QStringLiteral("shortcut")); + const int index = sheet->indexOf(u"shortcut"_s); if (index == -1) return PropertySheetKeySequenceValue(); return qvariant_cast<PropertySheetKeySequenceValue>(sheet->property(index)); @@ -174,10 +153,8 @@ void ActionModel::setItems(QDesignerFormEditorInterface *core, QAction *action, // Tooltip, mostly for icon view mode QString firstTooltip = action->objectName(); const QString text = action->text(); - if (!text.isEmpty()) { - firstTooltip += QLatin1Char('\n'); - firstTooltip += text; - } + if (!text.isEmpty()) + firstTooltip += u'\n' + text; Q_ASSERT(sl.size() == NumColumns); @@ -196,7 +173,7 @@ void ActionModel::setItems(QDesignerFormEditorInterface *core, QAction *action, item->setCheckState(used ? Qt::Checked : Qt::Unchecked); if (used) { QString usedToolTip; - const QString separator = QStringLiteral(", "); + const auto separator = ", "_L1; const int count = associatedDesignerWidgets.size(); for (int i = 0; i < count; i++) { if (i) @@ -222,7 +199,11 @@ void ActionModel::setItems(QDesignerFormEditorInterface *core, QAction *action, QString toolTip = action->toolTip(); item = sl[ToolTipColumn]; item->setToolTip(toolTip); - item->setText(toolTip.replace(QLatin1Char('\n'), QLatin1Char(' '))); + item->setText(toolTip.replace(u'\n', u' ')); + // menuRole + const auto menuRole = action->menuRole(); + item = sl[MenuRoleColumn]; + item->setText(QLatin1StringView(QMetaEnum::fromType<QAction::MenuRole>().valueToKey(menuRole))); } QMimeData *ActionModel::mimeData(const QModelIndexList &indexes ) const @@ -240,7 +221,7 @@ QMimeData *ActionModel::mimeData(const QModelIndexList &indexes ) const // Resource images are plain text. The drag needs to be restricted, however. QStringList ActionModel::mimeTypes() const { - return QStringList(QLatin1String(plainTextMimeType)); + return QStringList(plainTextMimeType); } QString ActionModel::actionName(int row) const @@ -632,7 +613,7 @@ ActionRepositoryMimeData::ActionRepositoryMimeData(const ActionList &al, Qt::Dro QStringList ActionRepositoryMimeData::formats() const { - return QStringList(QLatin1String(actionMimeType)); + return QStringList(actionMimeType); } QPixmap ActionRepositoryMimeData::actionDragPixmap(const QAction *action) @@ -643,9 +624,9 @@ QPixmap ActionRepositoryMimeData::actionDragPixmap(const QAction *action) if (!icon.isNull()) return icon.pixmap(QSize(22, 22)); - const QWidgetList &associatedWidgets = action->associatedWidgets(); - for (QWidget *w : associatedWidgets) { - if (QToolButton *tb = qobject_cast<QToolButton *>(w)) + const QObjectList associatedObjects = action->associatedObjects(); + for (QObject *o : associatedObjects) { + if (QToolButton *tb = qobject_cast<QToolButton *>(o)) return tb->grab(QRect(0, 0, -1, -1)); } diff --git a/src/designer/src/lib/shared/actionrepository_p.h b/src/designer/src/lib/shared/actionrepository_p.h index e84dd8acf..bc31ccd55 100644 --- a/src/designer/src/lib/shared/actionrepository_p.h +++ b/src/designer/src/lib/shared/actionrepository_p.h @@ -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 // // W A R N I N G @@ -64,7 +39,7 @@ class QDESIGNER_SHARED_EXPORT ActionModel: public QStandardItemModel { Q_OBJECT public: - enum Columns { NameColumn, UsedColumn, TextColumn, ShortCutColumn, CheckedColumn, ToolTipColumn, NumColumns }; + enum Columns { NameColumn, UsedColumn, TextColumn, ShortCutColumn, CheckedColumn, ToolTipColumn, MenuRoleColumn, NumColumns }; enum { ActionRole = Qt::UserRole + 1000 }; explicit ActionModel(QWidget *parent = nullptr); diff --git a/src/designer/src/lib/shared/codedialog.cpp b/src/designer/src/lib/shared/codedialog.cpp index 34bc56196..f11a2ac9b 100644 --- a/src/designer/src/lib/shared/codedialog.cpp +++ b/src/designer/src/lib/shared/codedialog.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 "codedialog_p.h" #include "qdesigner_utils_p.h" @@ -46,6 +21,8 @@ #include <QtGui/qaction.h> #include <QtGui/qevent.h> +#include <QtGui/qfontdatabase.h> +#include <QtGui/qfontmetrics.h> #include <QtGui/qicon.h> #include <QtCore/qdebug.h> @@ -55,6 +32,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { // ----------------- CodeDialogPrivate struct CodeDialog::CodeDialogPrivate { @@ -77,18 +56,19 @@ CodeDialog::CodeDialog(QWidget *parent) : QDialog(parent), m_impl(new CodeDialogPrivate) { - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); QVBoxLayout *vBoxLayout = new QVBoxLayout; // Edit tool bar QToolBar *toolBar = new QToolBar; - const QIcon saveIcon = createIconSet(QStringLiteral("filesave.png")); + const QIcon saveIcon = createIconSet(QIcon::ThemeIcon::DocumentSave, + "filesave.png"_L1); QAction *saveAction = toolBar->addAction(saveIcon, tr("Save...")); connect(saveAction, &QAction::triggered, this, &CodeDialog::slotSaveAs); #if QT_CONFIG(clipboard) - const QIcon copyIcon = createIconSet(QStringLiteral("editcopy.png")); + const QIcon copyIcon = createIconSet(QIcon::ThemeIcon::EditCopy, + "editcopy.png"_L1); QAction *copyAction = toolBar->addAction(copyIcon, tr("Copy All")); connect(copyAction, &QAction::triggered, this, &CodeDialog::copyAll); #endif @@ -99,8 +79,11 @@ CodeDialog::CodeDialog(QWidget *parent) : // Edit m_impl->m_textEdit->setReadOnly(true); + const auto font = QFontDatabase::systemFont(QFontDatabase::SystemFont::FixedFont); + const int editorWidth = QFontMetrics(font, this).averageCharWidth() * 100; + m_impl->m_textEdit->setFont(font); m_impl->m_textEdit->setMinimumSize(QSize( - m_impl->m_findWidget->minimumSize().width(), + qMax(editorWidth, m_impl->m_findWidget->minimumSize().width()), 500)); vBoxLayout->addWidget(m_impl->m_textEdit); @@ -162,11 +145,11 @@ bool CodeDialog::generateCode(const QDesignerFormWindowInterface *fw, tempPattern += QDir::separator(); const QString fileName = fw->fileName(); if (fileName.isEmpty()) { - tempPattern += QStringLiteral("designer"); + tempPattern += "designer"_L1; } else { tempPattern += QFileInfo(fileName).baseName(); } - tempPattern += QStringLiteral("XXXXXX.ui"); + tempPattern += "XXXXXX.ui"_L1; // Write to temp file QTemporaryFile tempFormFile(tempPattern); @@ -204,15 +187,15 @@ bool CodeDialog::showCodeDialog(const QDesignerFormWindowInterface *fw, dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setCode(code); dialog->setFormFileName(fw->fileName()); - QString languageName; + QLatin1StringView languageName; switch (language) { case UicLanguage::Cpp: - languageName = QLatin1String("C++"); - dialog->setMimeType(QLatin1String("text/x-chdr")); + languageName = "C++"_L1; + dialog->setMimeType(u"text/x-chdr"_s); break; case UicLanguage::Python: - languageName = QLatin1String("Python"); - dialog->setMimeType(QLatin1String("text/x-python")); + languageName = "Python"_L1; + dialog->setMimeType(u"text/x-python"_s); break; } dialog->setWindowTitle(tr("%1 - [%2 Code]"). @@ -236,8 +219,8 @@ void CodeDialog::slotSaveAs() if (!uiFile.isEmpty()) { QFileInfo uiFi(uiFile); fileDialog.setDirectory(uiFi.absolutePath()); - fileDialog.selectFile(QLatin1String("ui_") + uiFi.baseName() - + QLatin1Char('.') + suffix); + fileDialog.selectFile("ui_"_L1 + uiFi.baseName() + + '.'_L1 + suffix); } while (true) { diff --git a/src/designer/src/lib/shared/codedialog_p.h b/src/designer/src/lib/shared/codedialog_p.h index 37f798c4f..e68f48a24 100644 --- a/src/designer/src/lib/shared/codedialog_p.h +++ b/src/designer/src/lib/shared/codedialog_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/connectionedit.cpp b/src/designer/src/lib/shared/connectionedit.cpp index 2382e154a..d92ca00e2 100644 --- a/src/designer/src/lib/shared/connectionedit.cpp +++ b/src/designer/src/lib/shared/connectionedit.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 "connectionedit_p.h" @@ -205,7 +180,7 @@ DeleteConnectionsCommand::DeleteConnectionsCommand(ConnectionEdit *edit, void DeleteConnectionsCommand::redo() { - for (Connection *con : qAsConst(m_con_list)) { + for (Connection *con : std::as_const(m_con_list)) { const int idx = edit()->indexOfConnection(con); emit edit()->aboutToRemoveConnection(con); Q_ASSERT(edit()->m_con_list.contains(con)); @@ -219,7 +194,7 @@ void DeleteConnectionsCommand::redo() void DeleteConnectionsCommand::undo() { - for (Connection *con : qAsConst(m_con_list)) { + for (Connection *con : std::as_const(m_con_list)) { Q_ASSERT(!edit()->m_con_list.contains(con)); emit edit()->aboutToAddConnection(edit()->m_con_list.size()); edit()->m_con_list.append(con); @@ -633,7 +608,7 @@ void Connection::trimLine() { if (m_source == nullptr || m_source_pos == QPoint(-1, -1) || m_target_pos == QPoint(-1, -1)) return; - int cnt = m_knee_list.size(); + auto cnt = m_knee_list.size(); if (cnt < 2) return; @@ -722,7 +697,7 @@ QRegion Connection::region() const { QRegion result; - for (int i = 0; i < m_knee_list.size() - 1; ++i) + for (qsizetype i = 0; i < m_knee_list.size() - 1; ++i) result = result.united(lineRect(m_knee_list.at(i), m_knee_list.at(i + 1))); if (!m_arrow_head.isEmpty()) { @@ -755,7 +730,7 @@ void Connection::update(bool update_widgets) const void Connection::paint(QPainter *p) const { - for (int i = 0; i < m_knee_list.size() - 1; ++i) + for (qsizetype i = 0; i < m_knee_list.size() - 1; ++i) p->drawLine(m_knee_list.at(i), m_knee_list.at(i + 1)); if (!m_arrow_head.isEmpty()) { @@ -787,7 +762,7 @@ QRect Connection::endPointRect(EndPoint::Type type) const CETypes::LineDir Connection::labelDir(EndPoint::Type type) const { - const int cnt = m_knee_list.size(); + const auto cnt = m_knee_list.size(); if (cnt < 2) return RightDir; @@ -807,7 +782,7 @@ CETypes::LineDir Connection::labelDir(EndPoint::Type type) const QRect Connection::labelRect(EndPoint::Type type) const { - const int cnt = m_knee_list.size(); + const auto cnt = m_knee_list.size(); if (cnt < 2) return QRect(); const QString text = label(type); @@ -985,7 +960,7 @@ void ConnectionEdit::updateBackground() if (!m_enable_update_background) return; - for (Connection *c : qAsConst(m_con_list)) + for (Connection *c : std::as_const(m_con_list)) c->updateVisibility(); updateLines(); @@ -1063,7 +1038,7 @@ void ConnectionEdit::paintEvent(QPaintEvent *e) WidgetSet heavy_highlight_set, light_highlight_set; - for (Connection *con : qAsConst(m_con_list)) { + for (Connection *con : std::as_const(m_con_list)) { if (!con->isVisible()) continue; @@ -1081,7 +1056,7 @@ void ConnectionEdit::paintEvent(QPaintEvent *e) c.setAlpha(BG_ALPHA); p.setBrush(c); - for (QWidget *w : qAsConst(heavy_highlight_set)) { + for (QWidget *w : std::as_const(heavy_highlight_set)) { p.drawRect(fixRect(widgetRect(w))); light_highlight_set.remove(w); } @@ -1091,12 +1066,12 @@ void ConnectionEdit::paintEvent(QPaintEvent *e) c.setAlpha(BG_ALPHA); p.setBrush(c); - for (QWidget *w : qAsConst(light_highlight_set)) + for (QWidget *w : std::as_const(light_highlight_set)) p.drawRect(fixRect(widgetRect(w))); p.setBrush(palette().color(QPalette::Base)); p.setPen(palette().color(QPalette::Text)); - for (Connection *con : qAsConst(m_con_list)) { + for (Connection *con : std::as_const(m_con_list)) { if (con->isVisible()) { paintLabel(&p, EndPoint::Source, con); paintLabel(&p, EndPoint::Target, con); @@ -1106,7 +1081,7 @@ void ConnectionEdit::paintEvent(QPaintEvent *e) p.setPen(m_active_color); p.setBrush(m_active_color); - for (Connection *con : qAsConst(m_con_list)) { + for (Connection *con : std::as_const(m_con_list)) { if (!selected(con) || !con->isVisible()) continue; @@ -1358,9 +1333,9 @@ static ConnectionEdit::ConnectionSet findConnectionsOf(const ConnectionEdit::Con { ConnectionEdit::ConnectionSet rc; - const ConnectionEdit::ConnectionList::const_iterator ccend = cl.constEnd(); + const auto ccend = cl.cend(); for ( ; oi1 != oi2; ++oi1) { - for (ConnectionEdit::ConnectionList::const_iterator cit = cl.constBegin(); cit != ccend; ++cit) { + for (auto cit = cl.constBegin(); cit != ccend; ++cit) { Connection *con = *cit; if (con->object(ConnectionEdit::EndPoint::Source) == *oi1 || con->object(ConnectionEdit::EndPoint::Target) == *oi1) rc.insert(con, con); @@ -1427,7 +1402,7 @@ bool ConnectionEdit::selected(const Connection *con) const void ConnectionEdit::selectNone() { - for (Connection *con : qAsConst(m_sel_con_set)) + for (Connection *con : std::as_const(m_sel_con_set)) con->update(); m_sel_con_set.clear(); @@ -1437,7 +1412,7 @@ void ConnectionEdit::selectAll() { if (m_sel_con_set.size() == m_con_list.size()) return; - for (Connection *con : qAsConst(m_con_list)) + for (Connection *con : std::as_const(m_con_list)) setSelected(con, true); } @@ -1516,7 +1491,7 @@ void ConnectionEdit::addConnection(Connection *con) void ConnectionEdit::updateLines() { - for (Connection *con : qAsConst(m_con_list)) + for (Connection *con : std::as_const(m_con_list)) con->checkWidgets(); } diff --git a/src/designer/src/lib/shared/connectionedit_p.h b/src/designer/src/lib/shared/connectionedit_p.h index ca4560fda..3cfce754b 100644 --- a/src/designer/src/lib/shared/connectionedit_p.h +++ b/src/designer/src/lib/shared/connectionedit_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/csshighlighter.cpp b/src/designer/src/lib/shared/csshighlighter.cpp index 115b77c17..d34e7e4de 100644 --- a/src/designer/src/lib/shared/csshighlighter.cpp +++ b/src/designer/src/lib/shared/csshighlighter.cpp @@ -1,39 +1,17 @@ -/**************************************************************************** -** -** 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 "csshighlighter_p.h" QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { -CssHighlighter::CssHighlighter(QTextDocument *document) -: QSyntaxHighlighter(document) +CssHighlighter::CssHighlighter(const CssHighlightColors &colors, + QTextDocument *document) + : QSyntaxHighlighter(document), m_colors(colors) { } @@ -53,7 +31,7 @@ void CssHighlighter::highlightBlock(const QString& text) { Comment, Comment, Comment, Comment, Comment, Comment, Comment, -1, MaybeCommentEnd } // MaybeCommentEnd }; - int lastIndex = 0; + qsizetype lastIndex = 0; bool lastWasSlash = false; int state = previousBlockState(), save_state; if (state == -1) { @@ -65,8 +43,8 @@ void CssHighlighter::highlightBlock(const QString& text) // The initial state is based on the precense of a : and the absense of a {. // This is because Qt style sheets support both a full stylesheet as well as // an inline form with just properties. - state = save_state = (text.indexOf(QLatin1Char(':')) > -1 && - text.indexOf(QLatin1Char('{')) == -1) ? Property : Selector; + state = save_state = (text.indexOf(u':') > -1 && + text.indexOf(u'{') == -1) ? Property : Selector; } else { save_state = state>>16; state &= 0x00ff; @@ -78,7 +56,7 @@ void CssHighlighter::highlightBlock(const QString& text) state = save_state; } - for (int i = 0; i < text.length(); i++) { + for (qsizetype i = 0; i < text.size(); ++i) { int token = ALNUM; const QChar c = text.at(i); const char a = c.toLatin1(); @@ -130,39 +108,39 @@ void CssHighlighter::highlightBlock(const QString& text) } } - highlight(text, lastIndex, text.length() - lastIndex, state); + highlight(text, lastIndex, text.size() - lastIndex, state); setCurrentBlockState(state + (save_state<<16)); } void CssHighlighter::highlight(const QString &text, int start, int length, int state) { - if (start >= text.length() || length <= 0) + if (start >= text.size() || length <= 0) return; QTextCharFormat format; switch (state) { case Selector: - setFormat(start, length, Qt::darkRed); + setFormat(start, length, m_colors.selector); break; case Property: - setFormat(start, length, Qt::blue); + setFormat(start, length, m_colors.property); break; case Value: - setFormat(start, length, Qt::black); + setFormat(start, length, m_colors.value); break; case Pseudo1: - setFormat(start, length, Qt::darkRed); + setFormat(start, length, m_colors.pseudo1); break; case Pseudo2: - setFormat(start, length, Qt::darkRed); + setFormat(start, length, m_colors.pseudo2); break; case Quote: - setFormat(start, length, Qt::darkMagenta); + setFormat(start, length, m_colors.quote); break; case Comment: case MaybeCommentEnd: - format.setForeground(Qt::darkGreen); + format.setForeground(m_colors.comment); setFormat(start, length, format); break; default: diff --git a/src/designer/src/lib/shared/csshighlighter_p.h b/src/designer/src/lib/shared/csshighlighter_p.h index 8af8cd337..bad7e9f7d 100644 --- a/src/designer/src/lib/shared/csshighlighter_p.h +++ b/src/designer/src/lib/shared/csshighlighter_p.h @@ -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 // // W A R N I N G @@ -41,17 +16,30 @@ #define CSSHIGHLIGHTER_H #include <QtGui/qsyntaxhighlighter.h> +#include <QtGui/qcolor.h> #include "shared_global_p.h" QT_BEGIN_NAMESPACE namespace qdesigner_internal { +struct CssHighlightColors +{ + QColor selector; + QColor property; + QColor value; + QColor pseudo1; + QColor pseudo2; + QColor quote; + QColor comment; +}; + class QDESIGNER_SHARED_EXPORT CssHighlighter : public QSyntaxHighlighter { Q_OBJECT public: - explicit CssHighlighter(QTextDocument *document); + explicit CssHighlighter(const CssHighlightColors &colors, + QTextDocument *document); protected: void highlightBlock(const QString&) override; @@ -60,6 +48,8 @@ protected: private: enum State { Selector, Property, Value, Pseudo, Pseudo1, Pseudo2, Quote, MaybeComment, Comment, MaybeCommentEnd }; + + const CssHighlightColors m_colors; }; } // namespace qdesigner_internal diff --git a/src/designer/src/lib/shared/deviceprofile.cpp b/src/designer/src/lib/shared/deviceprofile.cpp index fbe65abaf..25148b526 100644 --- a/src/designer/src/lib/shared/deviceprofile.cpp +++ b/src/designer/src/lib/shared/deviceprofile.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 "deviceprofile_p.h" @@ -46,18 +21,24 @@ #include <QtCore/qxmlstream.h> -static const char *dpiXPropertyC = "_q_customDpiX"; -static const char *dpiYPropertyC = "_q_customDpiY"; +static const char dpiXPropertyC[] = "_q_customDpiX"; +static const char dpiYPropertyC[] = "_q_customDpiY"; + +QT_BEGIN_NAMESPACE + +using namespace Qt::StringLiterals; + +namespace qdesigner_internal { // XML serialization static const char *xmlVersionC="1.0"; static const char *rootElementC="deviceprofile"; -static const char *nameElementC = "name"; -static const char *fontFamilyElementC = "fontfamily"; -static const char *fontPointSizeElementC = "fontpointsize"; -static const char *dPIXElementC = "dpix"; -static const char *dPIYElementC = "dpiy"; -static const char *styleElementC = "style"; +static constexpr auto nameElementC = "name"_L1; +static constexpr auto fontFamilyElementC = "fontfamily"_L1; +static constexpr auto fontPointSizeElementC = "fontpointsize"_L1; +static constexpr auto dPIXElementC = "dpix"_L1; +static constexpr auto dPIYElementC = "dpiy"_L1; +static constexpr auto styleElementC = "style"_L1; /* DeviceProfile: * For preview purposes (preview, widget box, new form dialog), the @@ -69,10 +50,6 @@ static const char *styleElementC = "style"; * In addition, the widgetfactory maintains the system settings style * and applies it when creating widgets. */ -QT_BEGIN_NAMESPACE - -namespace qdesigner_internal { - // ---------------- DeviceProfileData class DeviceProfileData : public QSharedData { public: @@ -286,9 +263,9 @@ void DeviceProfile::apply(const QDesignerFormEditorInterface *core, QWidget *wid } } -bool DeviceProfile::equals(const DeviceProfile& rhs) const +bool comparesEqual(const DeviceProfile &lhs, const DeviceProfile &rhs) noexcept { - const DeviceProfileData &d = *m_d; + const DeviceProfileData &d = *lhs.m_d; const DeviceProfileData &rhs_d = *rhs.m_d; return d.m_fontPointSize == rhs_d.m_fontPointSize && d.m_dpiX == rhs_d.m_dpiX && d.m_dpiY == rhs_d.m_dpiY && d.m_fontFamily == rhs_d.m_fontFamily && @@ -307,20 +284,20 @@ QString DeviceProfile::toXml() const const DeviceProfileData &d = *m_d; QString rc; QXmlStreamWriter writer(&rc); - writer.writeStartDocument(QLatin1String(xmlVersionC)); - writer.writeStartElement(QLatin1String(rootElementC)); - writeElement(writer, QLatin1String(nameElementC), d.m_name); + writer.writeStartDocument(QLatin1StringView(xmlVersionC)); + writer.writeStartElement(QLatin1StringView(rootElementC)); + writeElement(writer, nameElementC, d.m_name); if (!d.m_fontFamily.isEmpty()) - writeElement(writer, QLatin1String(fontFamilyElementC), d.m_fontFamily); + writeElement(writer, fontFamilyElementC, d.m_fontFamily); if (d.m_fontPointSize >= 0) - writeElement(writer, QLatin1String(fontPointSizeElementC), QString::number(d.m_fontPointSize)); + writeElement(writer, fontPointSizeElementC, QString::number(d.m_fontPointSize)); if (d.m_dpiX > 0) - writeElement(writer, QLatin1String(dPIXElementC), QString::number(d.m_dpiX)); + writeElement(writer, dPIXElementC, QString::number(d.m_dpiX)); if (d.m_dpiY > 0) - writeElement(writer, QLatin1String(dPIYElementC), QString::number(d.m_dpiY)); + writeElement(writer, dPIYElementC, QString::number(d.m_dpiY)); if (!d.m_style.isEmpty()) - writeElement(writer, QLatin1String(styleElementC), d.m_style); + writeElement(writer, styleElementC, d.m_style); writer.writeEndElement(); writer.writeEndDocument(); @@ -336,7 +313,7 @@ static ParseStage nextStage(ParseStage currentStage, QStringView startElement) { switch (currentStage) { case ParseBeginning: - if (startElement == QLatin1String(rootElementC)) + if (startElement == QLatin1StringView(rootElementC)) return ParseWithinRoot; break; case ParseWithinRoot: @@ -346,17 +323,17 @@ static ParseStage nextStage(ParseStage currentStage, QStringView startElement) case ParseDPIX: case ParseDPIY: case ParseStyle: - if (startElement == QLatin1String(nameElementC)) + if (startElement == nameElementC) return ParseName; - if (startElement == QLatin1String(fontFamilyElementC)) + if (startElement == fontFamilyElementC) return ParseFontFamily; - if (startElement == QLatin1String(fontPointSizeElementC)) + if (startElement == fontPointSizeElementC) return ParseFontPointSize; - if (startElement == QLatin1String(dPIXElementC)) + if (startElement == dPIXElementC) return ParseDPIX; - if (startElement == QLatin1String(dPIYElementC)) + if (startElement == dPIYElementC) return ParseDPIY; - if (startElement == QLatin1String(styleElementC)) + if (startElement == styleElementC) return ParseStyle; break; case ParseError: diff --git a/src/designer/src/lib/shared/deviceprofile_p.h b/src/designer/src/lib/shared/deviceprofile_p.h index 60b9518c5..273a1a1a2 100644 --- a/src/designer/src/lib/shared/deviceprofile_p.h +++ b/src/designer/src/lib/shared/deviceprofile_p.h @@ -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 // // W A R N I N G @@ -42,6 +17,7 @@ #include "shared_global_p.h" +#include <QtCore/qcompare.h> #include <QtCore/qstring.h> #include <QtCore/qshareddata.h> @@ -101,8 +77,6 @@ public: static void systemResolution(int *dpiX, int *dpiY); static void widgetResolution(const QWidget *w, int *dpiX, int *dpiY); - bool equals(const DeviceProfile& rhs) const; - // Apply to form/preview (using font inheritance) enum ApplyMode { /* Pre-Apply to parent widget of form being edited: Apply font @@ -123,16 +97,14 @@ public: bool fromXml(const QString &xml, QString *errorMessage); private: + friend QDESIGNER_SHARED_EXPORT bool comparesEqual(const DeviceProfile &lhs, + const DeviceProfile &rhs) noexcept; + Q_DECLARE_EQUALITY_COMPARABLE(DeviceProfile) + QSharedDataPointer<DeviceProfileData> m_d; }; -inline bool operator==(const DeviceProfile &s1, const DeviceProfile &s2) - { return s1.equals(s2); } -inline bool operator!=(const DeviceProfile &s1, const DeviceProfile &s2) - { return !s1.equals(s2); } - -} - +} // namespace qdesigner_internal QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/dialoggui.cpp b/src/designer/src/lib/shared/dialoggui.cpp index 613a42143..168462ad3 100644 --- a/src/designer/src/lib/shared/dialoggui.cpp +++ b/src/designer/src/lib/shared/dialoggui.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 "dialoggui_p.h" diff --git a/src/designer/src/lib/shared/dialoggui_p.h b/src/designer/src/lib/shared/dialoggui_p.h index 4b5f2829f..a60c90494 100644 --- a/src/designer/src/lib/shared/dialoggui_p.h +++ b/src/designer/src/lib/shared/dialoggui_p.h @@ -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 #ifndef DIALOGGUI #define DIALOGGUI diff --git a/src/designer/src/lib/shared/extensionfactory_p.h b/src/designer/src/lib/shared/extensionfactory_p.h index b1afaf66a..7c34728b6 100644 --- a/src/designer/src/lib/shared/extensionfactory_p.h +++ b/src/designer/src/lib/shared/extensionfactory_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/formlayoutmenu.cpp b/src/designer/src/lib/shared/formlayoutmenu.cpp index f4b9255ff..0c7313770 100644 --- a/src/designer/src/lib/shared/formlayoutmenu.cpp +++ b/src/designer/src/lib/shared/formlayoutmenu.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 "formlayoutmenu_p.h" #include "layoutinfo_p.h" @@ -56,14 +31,16 @@ #include <QtCore/qhash.h> #include <QtCore/qdebug.h> -static const char *buddyPropertyC = "buddy"; +QT_BEGIN_NAMESPACE + +using namespace Qt::StringLiterals; + +static constexpr auto buddyPropertyC = "buddy"_L1; static const char *fieldWidgetBaseClasses[] = { "QLineEdit", "QComboBox", "QSpinBox", "QDoubleSpinBox", "QCheckBox", "QDateEdit", "QTimeEdit", "QDateTimeEdit", "QDial", "QWidget" }; -QT_BEGIN_NAMESPACE - namespace qdesigner_internal { // Struct that describes a row of controls (descriptive label and control) to @@ -118,7 +95,7 @@ private: // Check for buddy marker in string const QRegularExpression m_buddyMarkerRegexp; - Ui::FormLayoutRowDialog m_ui; + QT_PREPEND_NAMESPACE(Ui)::FormLayoutRowDialog m_ui; bool m_labelNameEdited; bool m_fieldNameEdited; bool m_buddyClicked; @@ -127,19 +104,18 @@ private: FormLayoutRowDialog::FormLayoutRowDialog(QDesignerFormEditorInterface *core, QWidget *parent) : QDialog(parent), - m_buddyMarkerRegexp(QStringLiteral("\\&[^&]")), + m_buddyMarkerRegexp(u"\\&[^&]"_s), m_labelNameEdited(false), m_fieldNameEdited(false), m_buddyClicked(false) { Q_ASSERT(m_buddyMarkerRegexp.isValid()); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setModal(true); m_ui.setupUi(this); connect(m_ui.labelTextLineEdit, &QLineEdit::textEdited, this, &FormLayoutRowDialog::labelTextEdited); - QRegularExpressionValidator *nameValidator = new QRegularExpressionValidator(QRegularExpression(QStringLiteral("^[a-zA-Z0-9_]+$")), this); + auto *nameValidator = new QRegularExpressionValidator(QRegularExpression(u"^[a-zA-Z0-9_]+$"_s), this); Q_ASSERT(nameValidator->regularExpression().isValid()); m_ui.labelNameLineEdit->setValidator(nameValidator); @@ -240,11 +216,11 @@ void FormLayoutRowDialog::labelTextEdited(const QString &text) // "namespace::QLineEdit"->"LineEdit" static inline QString postFixFromClassName(QString className) { - const int index = className.lastIndexOf(QStringLiteral("::")); + const int index = className.lastIndexOf("::"_L1); if (index != -1) className.remove(0, index + 2); if (className.size() > 2) - if (className.at(0) == QLatin1Char('Q') || className.at(0) == QLatin1Char('K')) + if (className.at(0) == u'Q' || className.at(0) == u'K') if (className.at(1).isUpper()) className.remove(0, 1); return className; @@ -290,10 +266,8 @@ static inline PrefixCharacterKind prefixCharacterKind(const QChar &c) static QString prefixFromLabel(const QString &prefix) { QString rc; - const int length = prefix.size(); bool lastWasAcceptable = false; - for (int i = 0 ; i < length; i++) { - const QChar c = prefix.at(i); + for (const QChar &c : prefix) { const PrefixCharacterKind kind = prefixCharacterKind(c); const bool acceptable = kind != PC_Invalid; if (acceptable) { @@ -323,7 +297,7 @@ void FormLayoutRowDialog::updateObjectNames(bool updateLabel, bool updateField) const QString prefix = prefixFromLabel(labelText()); // Set names if (doUpdateLabel) - m_ui.labelNameLineEdit->setText(prefix + QStringLiteral("Label")); + m_ui.labelNameLineEdit->setText(prefix + "Label"_L1); if (doUpdateField) m_ui.fieldNameLineEdit->setText(prefix + postFixFromClassName(fieldClass())); } @@ -356,19 +330,16 @@ void FormLayoutRowDialog::buddyClicked() * from them ("QLineEdit", "CustomLineEdit", "QComboBox"...). */ QStringList FormLayoutRowDialog::fieldWidgetClasses(QDesignerFormEditorInterface *core) { - // Base class -> custom widgets map - typedef QMultiHash<QString, QString> ClassMap; - static QStringList rc; if (rc.isEmpty()) { // Turn known base classes into list QStringList baseClasses; for (auto fw : fieldWidgetBaseClasses) - baseClasses.append(QLatin1String(fw)); + baseClasses.append(QLatin1StringView(fw)); // Scan for custom widgets that inherit them and store them in a // multimap of base class->custom widgets unless we have a language // extension installed which might do funny things with custom widgets. - ClassMap customClassMap; + QMultiHash<QString, QString> customClassMap; // Base class -> custom widgets map if (qt_extension<QDesignerLanguageExtension *>(core->extensionManager(), core) == nullptr) { const QDesignerWidgetDataBaseInterface *wdb = core->widgetDataBase(); const int wdbCount = wdb->count(); @@ -405,23 +376,23 @@ static QFormLayout *managedFormLayout(const QDesignerFormEditorInterface *core, // Create the widgets of a control row and apply text properties contained // in the struct, called by addFormLayoutRow() -static QPair<QWidget *,QWidget *> +static std::pair<QWidget *,QWidget *> createWidgets(const FormLayoutRow &row, QWidget *parent, QDesignerFormWindowInterface *formWindow) { QDesignerFormEditorInterface *core = formWindow->core(); QDesignerWidgetFactoryInterface *wf = core->widgetFactory(); - QPair<QWidget *,QWidget *> rc = QPair<QWidget *,QWidget *>(wf->createWidget(QStringLiteral("QLabel"), parent), - wf->createWidget(row.fieldClassName, parent)); + std::pair<QWidget *,QWidget *> rc{wf->createWidget(u"QLabel"_s, parent), + wf->createWidget(row.fieldClassName, parent)}; // Set up properties of the label - const QString objectNameProperty = QStringLiteral("objectName"); + const QString objectNameProperty = u"objectName"_s; QDesignerPropertySheetExtension *labelSheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), rc.first); int nameIndex = labelSheet->indexOf(objectNameProperty); labelSheet->setProperty(nameIndex, QVariant::fromValue(PropertySheetStringValue(row.labelName))); labelSheet->setChanged(nameIndex, true); formWindow->ensureUniqueObjectName(rc.first); - const int textIndex = labelSheet->indexOf(QStringLiteral("text")); + const int textIndex = labelSheet->indexOf(u"text"_s); labelSheet->setProperty(textIndex, QVariant::fromValue(PropertySheetStringValue(row.labelText))); labelSheet->setChanged(textIndex, true); // Set up properties of the control @@ -445,7 +416,7 @@ static void addFormLayoutRow(const FormLayoutRow &formLayoutRow, int row, QWidge undoStack->beginMacro(macroName); // Create a list of widget insertion commands and pass them a cell position - const QPair<QWidget *,QWidget *> widgetPair = createWidgets(formLayoutRow, w, formWindow); + const auto widgetPair = createWidgets(formLayoutRow, w, formWindow); InsertWidgetCommand *labelCmd = new InsertWidgetCommand(formWindow); labelCmd->init(widgetPair.first, false, row, 0); @@ -455,7 +426,7 @@ static void addFormLayoutRow(const FormLayoutRow &formLayoutRow, int row, QWidge undoStack->push(controlCmd); if (formLayoutRow.buddy) { SetPropertyCommand *buddyCommand = new SetPropertyCommand(formWindow); - buddyCommand->init(widgetPair.first, QLatin1String(buddyPropertyC), widgetPair.second->objectName()); + buddyCommand->init(widgetPair.first, buddyPropertyC, widgetPair.second->objectName()); undoStack->push(buddyCommand); } undoStack->endMacro(); diff --git a/src/designer/src/lib/shared/formlayoutmenu_p.h b/src/designer/src/lib/shared/formlayoutmenu_p.h index d4b56ac96..3f4bac070 100644 --- a/src/designer/src/lib/shared/formlayoutmenu_p.h +++ b/src/designer/src/lib/shared/formlayoutmenu_p.h @@ -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 #ifndef FORMLAYOUTMENU #define FORMLAYOUTMENU diff --git a/src/designer/src/lib/shared/formwindowbase.cpp b/src/designer/src/lib/shared/formwindowbase.cpp index 8a126c1a1..17dde0409 100644 --- a/src/designer/src/lib/shared/formwindowbase.cpp +++ b/src/designer/src/lib/shared/formwindowbase.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 "formwindowbase_p.h" #include "connectionedit_p.h" @@ -60,12 +35,15 @@ #include <QtGui/qaction.h> #include <QtCore/qdebug.h> +#include <QtCore/qhash.h> #include <QtCore/qlist.h> #include <QtCore/qset.h> #include <QtCore/qtimer.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { class FormWindowBasePrivate { @@ -80,8 +58,8 @@ public: DesignerPixmapCache *m_pixmapCache; DesignerIconCache *m_iconCache; QtResourceSet *m_resourceSet; - QMap<QDesignerPropertySheet *, QMap<int, bool> > m_reloadableResources; // bool is dummy, QMap used as QSet - QMap<QDesignerPropertySheet *, QObject *> m_reloadablePropertySheets; + QHash<QDesignerPropertySheet *, QSet<int>> m_reloadableResources; + QHash<QDesignerPropertySheet *, QObject *> m_reloadablePropertySheets; const DeviceProfile m_deviceProfile; FormWindowBase::LineTerminatorMode m_lineTerminatorMode; FormWindowBase::ResourceFileSaveMode m_saveResourcesBehaviour; @@ -157,13 +135,13 @@ void FormWindowBase::setResourceSet(QtResourceSet *resourceSet) void FormWindowBase::addReloadableProperty(QDesignerPropertySheet *sheet, int index) { connectSheet(sheet); - m_d->m_reloadableResources[sheet][index] = true; + m_d->m_reloadableResources[sheet].insert(index); } void FormWindowBase::removeReloadableProperty(QDesignerPropertySheet *sheet, int index) { m_d->m_reloadableResources[sheet].remove(index); - if (!m_d->m_reloadableResources[sheet].count()) { + if (m_d->m_reloadableResources[sheet].isEmpty()) { m_d->m_reloadableResources.remove(sheet); disconnectSheet(sheet); } @@ -229,14 +207,13 @@ void FormWindowBase::reloadProperties() iconCache()->clear(); for (auto it = m_d->m_reloadableResources.cbegin(), end = m_d->m_reloadableResources.cend(); it != end; ++it) { QDesignerPropertySheet *sheet = it.key(); - for (auto jt = it.value().begin(), end = it.value().end(); jt != end; ++jt) { - const int index = jt.key(); + for (int index : it.value()) { const QVariant newValue = sheet->property(index); - if (qobject_cast<QLabel *>(sheet->object()) && sheet->propertyName(index) == QStringLiteral("text")) { + if (qobject_cast<QLabel *>(sheet->object()) && sheet->propertyName(index) == "text"_L1) { const PropertySheetStringValue newString = qvariant_cast<PropertySheetStringValue>(newValue); // optimize a bit, reset only if the text value might contain a reference to qt resources // (however reloading of icons other than taken from resources might not work here) - if (newString.value().contains(QStringLiteral(":/"))) { + if (newString.value().contains(":/"_L1)) { const QVariant resetValue = QVariant::fromValue(PropertySheetStringValue()); sheet->setProperty(index, resetValue); } @@ -246,7 +223,7 @@ void FormWindowBase::reloadProperties() if (QTabWidget *tabWidget = qobject_cast<QTabWidget *>(sheet->object())) { const int count = tabWidget->count(); const int current = tabWidget->currentIndex(); - const QString currentTabIcon = QStringLiteral("currentTabIcon"); + const QString currentTabIcon = u"currentTabIcon"_s; for (int i = 0; i < count; i++) { tabWidget->setCurrentIndex(i); const int index = sheet->indexOf(currentTabIcon); @@ -256,7 +233,7 @@ void FormWindowBase::reloadProperties() } else if (QToolBox *toolBox = qobject_cast<QToolBox *>(sheet->object())) { const int count = toolBox->count(); const int current = toolBox->currentIndex(); - const QString currentItemIcon = QStringLiteral("currentItemIcon"); + const QString currentItemIcon = u"currentItemIcon"_s; for (int i = 0; i < count; i++) { toolBox->setCurrentIndex(i); const int index = sheet->indexOf(currentItemIcon); @@ -265,7 +242,7 @@ void FormWindowBase::reloadProperties() toolBox->setCurrentIndex(current); } } - for (QObject *object : qAsConst(m_d->m_reloadablePropertySheets)) { + for (QObject *object : std::as_const(m_d->m_reloadablePropertySheets)) { reloadIconResources(iconCache(), object); } } @@ -317,10 +294,8 @@ static void recursiveUpdate(QWidget *w) { w->update(); - const QObjectList &l = w->children(); - const QObjectList::const_iterator cend = l.constEnd(); - for (QObjectList::const_iterator it = l.constBegin(); it != cend; ++it) { - if (QWidget *w = qobject_cast<QWidget*>(*it)) + for (auto *child : w->children()) { + if (QWidget *w = qobject_cast<QWidget*>(child)) recursiveUpdate(w); } } @@ -451,7 +426,7 @@ void FormWindowBase::deleteWidgetList(const QWidgetList &widget_list) tr("Delete '%1'").arg(widget_list.constFirst()->objectName()) : tr("Delete"); commandHistory()->beginMacro(description); - for (QWidget *w : qAsConst(widget_list)) { + for (QWidget *w : std::as_const(widget_list)) { emit widgetRemoved(w); DeleteWidgetCommand *cmd = new DeleteWidgetCommand(this); cmd->init(w); @@ -468,7 +443,7 @@ QMenu *FormWindowBase::createExtensionTaskMenu(QDesignerFormWindowInterface *fw, QExtensionManager *em = fw->core()->extensionManager(); if (const QDesignerTaskMenuExtension *extTaskMenu = qt_extension<QDesignerTaskMenuExtension*>(em, o)) actions += extTaskMenu->taskActions(); - if (const QDesignerTaskMenuExtension *intTaskMenu = qobject_cast<QDesignerTaskMenuExtension *>(em->extension(o, QStringLiteral("QDesignerInternalTaskMenuExtension")))) { + if (const auto *intTaskMenu = qobject_cast<QDesignerTaskMenuExtension *>(em->extension(o, u"QDesignerInternalTaskMenuExtension"_s))) { if (!actions.isEmpty()) { QAction *a = new QAction(fw); a->setSeparator(true); @@ -484,9 +459,8 @@ QMenu *FormWindowBase::createExtensionTaskMenu(QDesignerFormWindowInterface *fw, actions.push_back(a); } QMenu *rc = new QMenu; - const ActionList::const_iterator cend = actions.constEnd(); - for (ActionList::const_iterator it = actions.constBegin(); it != cend; ++it) - rc->addAction(*it); + for (auto *a : std::as_const(actions)) + rc->addAction(a); return rc; } diff --git a/src/designer/src/lib/shared/formwindowbase_p.h b/src/designer/src/lib/shared/formwindowbase_p.h index b240aa521..77fd7b8c8 100644 --- a/src/designer/src/lib/shared/formwindowbase_p.h +++ b/src/designer/src/lib/shared/formwindowbase_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/grid.cpp b/src/designer/src/lib/shared/grid.cpp index 9f9ff7d65..f4906a113 100644 --- a/src/designer/src/lib/shared/grid.cpp +++ b/src/designer/src/lib/shared/grid.cpp @@ -1,35 +1,12 @@ -/**************************************************************************** -** -** 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 "grid_p.h" #include <QtCore/qlist.h> #include <QtCore/qstring.h> +#include <QtCore/qvariant.h> +#include <QtCore/qmap.h> #include <QtGui/qevent.h> #include <QtGui/qpainter.h> @@ -57,7 +34,7 @@ template <class T> // Obtain a value form QVariantMap template <class T> static inline bool valueFromVariantMap(const QVariantMap &v, const QString &key, T &value) { - const QVariantMap::const_iterator it = v.constFind(key); + const auto it = v.constFind(key); const bool found = it != v.constEnd(); if (found) value = qvariant_cast<T>(it.value()); @@ -79,11 +56,11 @@ Grid::Grid() : bool Grid::fromVariantMap(const QVariantMap& vm) { Grid grid; - bool anyData = valueFromVariantMap(vm, QLatin1String(KEY_VISIBLE), grid.m_visible); - anyData |= valueFromVariantMap(vm, QLatin1String(KEY_SNAPX), grid.m_snapX); - anyData |= valueFromVariantMap(vm, QLatin1String(KEY_SNAPY), grid.m_snapY); - anyData |= valueFromVariantMap(vm, QLatin1String(KEY_DELTAX), grid.m_deltaX); - anyData |= valueFromVariantMap(vm, QLatin1String(KEY_DELTAY), grid.m_deltaY); + bool anyData = valueFromVariantMap(vm, QLatin1StringView(KEY_VISIBLE), grid.m_visible); + anyData |= valueFromVariantMap(vm, QLatin1StringView(KEY_SNAPX), grid.m_snapX); + anyData |= valueFromVariantMap(vm, QLatin1StringView(KEY_SNAPY), grid.m_snapY); + anyData |= valueFromVariantMap(vm, QLatin1StringView(KEY_DELTAX), grid.m_deltaX); + anyData |= valueFromVariantMap(vm, QLatin1StringView(KEY_DELTAY), grid.m_deltaY); if (!anyData) return false; if (grid.m_deltaX == 0 || grid.m_deltaY == 0) { @@ -103,11 +80,11 @@ QVariantMap Grid::toVariantMap(bool forceKeys) const void Grid::addToVariantMap(QVariantMap& vm, bool forceKeys) const { - valueToVariantMap(m_visible, defaultVisible, QLatin1String(KEY_VISIBLE), vm, forceKeys); - valueToVariantMap(m_snapX, defaultSnap, QLatin1String(KEY_SNAPX), vm, forceKeys); - valueToVariantMap(m_snapY, defaultSnap, QLatin1String(KEY_SNAPY), vm, forceKeys); - valueToVariantMap(m_deltaX, DEFAULT_GRID, QLatin1String(KEY_DELTAX), vm, forceKeys); - valueToVariantMap(m_deltaY, DEFAULT_GRID, QLatin1String(KEY_DELTAY), vm, forceKeys); + valueToVariantMap(m_visible, defaultVisible, QLatin1StringView(KEY_VISIBLE), vm, forceKeys); + valueToVariantMap(m_snapX, defaultSnap, QLatin1StringView(KEY_SNAPX), vm, forceKeys); + valueToVariantMap(m_snapY, defaultSnap, QLatin1StringView(KEY_SNAPY), vm, forceKeys); + valueToVariantMap(m_deltaX, DEFAULT_GRID, QLatin1StringView(KEY_DELTAX), vm, forceKeys); + valueToVariantMap(m_deltaY, DEFAULT_GRID, QLatin1StringView(KEY_DELTAY), vm, forceKeys); } void Grid::paint(QWidget *widget, QPaintEvent *e) const @@ -135,7 +112,7 @@ void Grid::paint(QPainter &p, const QWidget *widget, QPaintEvent *e) const points.reserve((yend - ystart) / m_deltaY + 1); for (int y = ystart; y <= yend; y += m_deltaY) points.push_back(QPointF(x, y)); - p.drawPoints( &(*points.begin()), points.count()); + p.drawPoints( &(*points.begin()), points.size()); points.clear(); } } @@ -170,14 +147,6 @@ int Grid::widgetHandleAdjustY(int y) const return m_snapY ? (y / m_deltaY) * m_deltaY + 1 : y; } -bool Grid::equals(const Grid &rhs) const -{ - return m_visible == rhs.m_visible && - m_snapX == rhs.m_snapX && - m_snapY == rhs.m_snapY && - m_deltaX == rhs.m_deltaX && - m_deltaY == rhs.m_deltaY; -} } QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/grid_p.h b/src/designer/src/lib/shared/grid_p.h index ca80eba03..606732884 100644 --- a/src/designer/src/lib/shared/grid_p.h +++ b/src/designer/src/lib/shared/grid_p.h @@ -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 // // W A R N I N G @@ -42,6 +17,7 @@ #include "shared_global_p.h" +#include <QtCore/qcompare.h> #include <QtCore/qvariant.h> QT_BEGIN_NAMESPACE @@ -86,11 +62,15 @@ public: int widgetHandleAdjustX(int x) const; int widgetHandleAdjustY(int y) const; - inline bool operator==(const Grid &rhs) const { return equals(rhs); } - inline bool operator!=(const Grid &rhs) const { return !equals(rhs); } - private: - bool equals(const Grid &rhs) const; + friend bool comparesEqual(const Grid &lhs, const Grid &rhs) noexcept + { + return lhs.m_visible == rhs.m_visible + && lhs.m_snapX == rhs.m_snapX && lhs.m_snapY == rhs.m_snapY + && lhs.m_deltaX == rhs.m_deltaX && lhs.m_deltaY == rhs.m_deltaY; + } + Q_DECLARE_EQUALITY_COMPARABLE(Grid) + int snapValue(int value, int grid) const; bool m_visible; bool m_snapX; diff --git a/src/designer/src/lib/shared/gridpanel.cpp b/src/designer/src/lib/shared/gridpanel.cpp index 80485d0bc..a5f6ae654 100644 --- a/src/designer/src/lib/shared/gridpanel.cpp +++ b/src/designer/src/lib/shared/gridpanel.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 "gridpanel_p.h" #include "ui_gridpanel.h" @@ -37,7 +12,7 @@ namespace qdesigner_internal { GridPanel::GridPanel(QWidget *parentWidget) : QWidget(parentWidget) { - m_ui = new Ui::GridPanel; + m_ui = new QT_PREPEND_NAMESPACE(qdesigner_internal)::Ui::GridPanel; m_ui->setupUi(this); connect(m_ui->m_resetButton, &QAbstractButton::clicked, this, &GridPanel::reset); diff --git a/src/designer/src/lib/shared/gridpanel_p.h b/src/designer/src/lib/shared/gridpanel_p.h index c468caaf8..000a250ad 100644 --- a/src/designer/src/lib/shared/gridpanel_p.h +++ b/src/designer/src/lib/shared/gridpanel_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/htmlhighlighter.cpp b/src/designer/src/lib/shared/htmlhighlighter.cpp index a3b7b3391..59e2a5efa 100644 --- a/src/designer/src/lib/shared/htmlhighlighter.cpp +++ b/src/designer/src/lib/shared/htmlhighlighter.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 <QtCore/qtextstream.h> #include <QtWidgets/qtextedit.h> @@ -33,6 +8,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { HtmlHighlighter::HtmlHighlighter(QTextEdit *textEdit) @@ -71,23 +48,13 @@ void HtmlHighlighter::setFormatFor(Construct construct, void HtmlHighlighter::highlightBlock(const QString &text) { - static const QLatin1Char tab = QLatin1Char('\t'); - static const QLatin1Char space = QLatin1Char(' '); - static const QLatin1Char amp = QLatin1Char('&'); - static const QLatin1Char startTag = QLatin1Char('<'); - static const QLatin1Char endTag = QLatin1Char('>'); - static const QLatin1Char quot = QLatin1Char('"'); - static const QLatin1Char apos = QLatin1Char('\''); - static const QLatin1Char semicolon = QLatin1Char(';'); - static const QLatin1Char equals = QLatin1Char('='); - static const QLatin1String startComment("<!--"); - static const QLatin1String endComment("-->"); - static const QLatin1String endElement("/>"); + static const QChar tab = u'\t'; + static const QChar space = u' '; int state = previousBlockState(); - int len = text.length(); - int start = 0; - int pos = 0; + qsizetype len = text.size(); + qsizetype start = 0; + qsizetype pos = 0; while (pos < len) { switch (state) { @@ -95,18 +62,19 @@ void HtmlHighlighter::highlightBlock(const QString &text) default: while (pos < len) { QChar ch = text.at(pos); - if (ch == startTag) { - if (text.mid(pos, 4) == startComment) { + if (ch == u'<') { + if (QStringView{text}.sliced(pos).startsWith("<!--"_L1)) { state = InComment; } else { state = InTag; start = pos; while (pos < len && text.at(pos) != space - && text.at(pos) != endTag + && text.at(pos) != u'>' && text.at(pos) != tab - && text.mid(pos, 2) != endElement) + && !QStringView{text}.sliced(pos).startsWith("/>"_L1)) { ++pos; - if (text.mid(pos, 2) == endElement) + } + if (QStringView{text}.sliced(pos).startsWith("/>"_L1)) ++pos; setFormat(start, pos - start, m_formats[Tag]); @@ -114,9 +82,9 @@ void HtmlHighlighter::highlightBlock(const QString &text) } break; } - if (ch == amp) { + if (ch == u'&') { start = pos; - while (pos < len && text.at(pos++) != semicolon) + while (pos < len && text.at(pos++) != u';') ; setFormat(start, pos - start, m_formats[Entity]); @@ -129,7 +97,7 @@ void HtmlHighlighter::highlightBlock(const QString &text) case InComment: start = pos; for ( ; pos < len; ++pos) { - if (text.mid(pos, 3) == endComment) { + if (QStringView{text}.sliced(pos).startsWith("-->"_L1)) { pos += 3; state = NormalState; break; @@ -143,14 +111,14 @@ void HtmlHighlighter::highlightBlock(const QString &text) QChar ch = text.at(pos); if (quote.isNull()) { start = pos; - if (ch == apos || ch == quot) { + if (ch == '\''_L1 || ch == u'"') { quote = ch; - } else if (ch == endTag) { + } else if (ch == u'>') { ++pos; setFormat(start, pos - start, m_formats[Tag]); state = NormalState; break; - } else if (text.mid(pos, 2) == endElement) { + } else if (QStringView{text}.sliced(pos).startsWith("/>"_L1)) { pos += 2; setFormat(start, pos - start, m_formats[Tag]); state = NormalState; @@ -161,7 +129,7 @@ void HtmlHighlighter::highlightBlock(const QString &text) ++pos; while (pos < len && text.at(pos) != space && text.at(pos) != tab - && text.at(pos) != equals) + && text.at(pos) != u'=') ++pos; setFormat(start, pos - start, m_formats[Attribute]); start = pos; diff --git a/src/designer/src/lib/shared/htmlhighlighter_p.h b/src/designer/src/lib/shared/htmlhighlighter_p.h index e63186166..e86bfce97 100644 --- a/src/designer/src/lib/shared/htmlhighlighter_p.h +++ b/src/designer/src/lib/shared/htmlhighlighter_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/icon-naming-spec.txt b/src/designer/src/lib/shared/icon-naming-spec.txt new file mode 100644 index 000000000..e9b854769 --- /dev/null +++ b/src/designer/src/lib/shared/icon-naming-spec.txt @@ -0,0 +1,309 @@ +# https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html + +# Table 2. Standard Action Icons +address-book-new +application-exit +appointment-new +call-start +call-stop +contact-new +document-new +document-open +document-open-recent +document-page-setup +document-print +document-print-preview +document-properties +document-revert +document-save +document-save-as +document-send +edit-clear +edit-copy +edit-cut +edit-delete +edit-find +edit-find-replace +edit-paste +edit-redo +edit-select-all +edit-undo +folder-new +format-indent-less +format-indent-more +format-justify-center +format-justify-fill +format-justify-left +format-justify-right +format-text-direction-ltr +format-text-direction-rtl +format-text-bold +format-text-italic +format-text-underline +format-text-strikethrough +go-bottom +go-down +go-first +go-home +go-jump +go-last +go-next +go-previous +go-top +go-up +help-about +help-contents +help-faq +insert-image +insert-link +insert-object +insert-text +list-add +list-remove +mail-forward +mail-mark-important +mail-mark-junk +mail-mark-notjunk +mail-mark-read +mail-mark-unread +mail-message-new +mail-reply-all +mail-reply-sender +mail-send +mail-send-receive +media-eject +media-playback-pause +media-playback-start +media-playback-stop +media-record +media-seek-backward +media-seek-forward +media-skip-backward +media-skip-forward +object-flip-horizontal +object-flip-vertical +object-rotate-left +object-rotate-right +process-stop +system-lock-screen +system-log-out +system-run +system-search +system-reboot +system-shutdown +tools-check-spelling +view-fullscreen +view-refresh +view-restore +view-sort-ascending +view-sort-descending +window-close +window-new +zoom-fit-best +zoom-in +zoom-original +zoom-out + +# Table 3. Standard Animation Icons +process-working + +# Table 4. Standard Application Icons +accessories-calculator +accessories-character-map +accessories-dictionary +accessories-text-editor +help-browser +multimedia-volume-control +preferences-desktop-accessibility +preferences-desktop-font +preferences-desktop-keyboard +preferences-desktop-locale +preferences-desktop-multimedia +preferences-desktop-screensaver +preferences-desktop-theme +preferences-desktop-wallpaper +system-file-manager +system-software-install +system-software-update +utilities-system-monitor +utilities-terminal + +# Table 5. Standard Category Icons +applications-accessories +applications-development +applications-engineering +applications-games +applications-graphics +applications-internet +applications-multimedia +applications-office +applications-other +applications-science +applications-system +applications-utilities +preferences-desktop +preferences-desktop-peripherals +preferences-desktop-personal +preferences-other +preferences-system +preferences-system-network +system-help + +# Table 6. Standard Device Icons +audio-card +audio-input-microphone +battery +camera-photo +camera-video +camera-web +computer +drive-harddisk +drive-optical +drive-removable-media +input-gaming +input-keyboard +input-mouse +input-tablet +media-flash +media-floppy +media-optical +media-tape +modem +multimedia-player +network-wired +network-wireless +pda +phone +printer +scanner +video-display + +# Table 7. Standard Emblem Icons +emblem-default +emblem-documents +emblem-downloads +emblem-favorite +emblem-important +emblem-mail +emblem-photos +emblem-readonly +emblem-shared +emblem-symbolic-link +emblem-synchronized +emblem-system +emblem-unreadable + +# Table 8. Standard Emotion Icons +face-angel +face-angry +face-cool +face-crying +face-devilish +face-embarrassed +face-kiss +face-laugh +face-monkey +face-plain +face-raspberry +face-sad +face-sick +face-smile +face-smile-big +face-smirk +face-surprise +face-tired +face-uncertain +face-wink +face-worried + +# Table 9. Standard International Icons +flag-aa + +# Table 10. Standard MIME Type Icons +application-x-executable +audio-x-generic +font-x-generic +image-x-generic +package-x-generic +text-html +text-x-generic +text-x-generic-template +text-x-script +video-x-generic +x-office-address-book +x-office-calendar +x-office-document +x-office-presentation +x-office-spreadsheet + +# Table 11. Standard Place Icons +folder +folder-remote +network-server +network-workgroup +start-here +user-bookmarks +user-desktop +user-home +user-trash + +# Table 12. Standard Status Icons +appointment-missed +appointment-soon +audio-volume-high +audio-volume-low +audio-volume-medium +audio-volume-muted +battery-caution +battery-low +dialog-error +dialog-information +dialog-password +dialog-question +dialog-warning +folder-drag-accept +folder-open +folder-visiting +image-loading +image-missing +mail-attachment +mail-unread +mail-read +mail-replied +mail-signed +mail-signed-verified +media-playlist-repeat +media-playlist-shuffle +network-error +network-idle +network-offline +network-receive +network-transmit +network-transmit-receive +printer-error +printer-printing +security-high +security-medium +security-low +software-update-available +software-update-urgent +sync-error +sync-synchronizing +task-due +task-past-due +user-available +user-away +user-idle +user-offline +user-trash-full +weather-clear +weather-clear-night +weather-few-clouds +weather-few-clouds-night +weather-fog +weather-overcast +weather-severe-alert +weather-showers +weather-showers-scattered +weather-snow +weather-storm diff --git a/src/designer/src/lib/shared/iconloader.cpp b/src/designer/src/lib/shared/iconloader.cpp index 13c9ad4f7..ecb97ba2b 100644 --- a/src/designer/src/lib/shared/iconloader.cpp +++ b/src/designer/src/lib/shared/iconloader.cpp @@ -1,63 +1,62 @@ -/**************************************************************************** -** -** 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 "iconloader_p.h" #include <QtCore/qfile.h> +#include <QtCore/qoperatingsystemversion.h> #include <QtGui/qicon.h> #include <QtGui/qpixmap.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { -QDESIGNER_SHARED_EXPORT QIcon createIconSet(const QString &name) +QDESIGNER_SHARED_EXPORT QIcon createIconSet(QIcon::ThemeIcon themeIcon, + QLatin1StringView name) { - const QStringList candidates = QStringList() - << (QString::fromUtf8(":/qt-project.org/formeditor/images/") + name) + return QOperatingSystemVersion::currentType() != QOperatingSystemVersion::MacOS + && QIcon::hasThemeIcon(themeIcon) + ? QIcon::fromTheme(themeIcon) : createIconSet(name); +} + +template <class StringView> +static inline QIcon createIconSetHelper(StringView name) +{ + constexpr QLatin1StringView prefixes[] = { + ":/qt-project.org/formeditor/images/"_L1, #ifdef Q_OS_MACOS - << (QString::fromUtf8(":/qt-project.org/formeditor/images/mac/") + name) + ":/qt-project.org/formeditor/images/mac/"_L1, #else - << (QString::fromUtf8(":/qt-project.org/formeditor/images/win/") + name) + ":/qt-project.org/formeditor/images/win/"_L1, #endif - << (QString::fromUtf8(":/qt-project.org/formeditor/images/designer_") + name); + ":/qt-project.org/formeditor/images/designer_"_L1 + }; - for (const QString &f : candidates) { + for (QLatin1StringView prefix : prefixes) { + const QString f = prefix + name; if (QFile::exists(f)) return QIcon(f); } - return QIcon(); + return {}; +} + +QDESIGNER_SHARED_EXPORT QIcon createIconSet(QStringView name) +{ + return createIconSetHelper(name); +} + +QDESIGNER_SHARED_EXPORT QIcon createIconSet(QLatin1StringView name) +{ + return createIconSetHelper(name); } QDESIGNER_SHARED_EXPORT QIcon emptyIcon() { - return QIcon(QStringLiteral(":/qt-project.org/formeditor/images/emptyicon.png")); + return QIcon(u":/qt-project.org/formeditor/images/emptyicon.png"_s); } static QIcon buildIcon(const QString &prefix, const int *sizes, size_t sizeCount) @@ -65,7 +64,7 @@ static QIcon buildIcon(const QString &prefix, const int *sizes, size_t sizeCount QIcon result; for (size_t i = 0; i < sizeCount; ++i) { const QString size = QString::number(sizes[i]); - const QPixmap pixmap(prefix + size + QLatin1Char('x') + size + QStringLiteral(".png")); + const QPixmap pixmap(prefix + size + 'x'_L1 + size + ".png"_L1); Q_ASSERT(!pixmap.size().isEmpty()); result.addPixmap(pixmap); } @@ -74,9 +73,9 @@ static QIcon buildIcon(const QString &prefix, const int *sizes, size_t sizeCount QDESIGNER_SHARED_EXPORT QIcon qtLogoIcon() { - static const int sizes[] = {16, 24, 32, 64}; + static const int sizes[] = {16, 24, 32, 64, 128}; static const QIcon result = - buildIcon(QStringLiteral(":/qt-project.org/formeditor/images/qtlogo"), + buildIcon(u":/qt-project.org/formeditor/images/qtlogo"_s, sizes, sizeof(sizes) / sizeof(sizes[0])); return result; } diff --git a/src/designer/src/lib/shared/iconloader_p.h b/src/designer/src/lib/shared/iconloader_p.h index 5932a18c1..c054d677c 100644 --- a/src/designer/src/lib/shared/iconloader_p.h +++ b/src/designer/src/lib/shared/iconloader_p.h @@ -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 // // W A R N I N G @@ -42,6 +17,8 @@ #include "shared_global_p.h" +#include <QtGui/qicon.h> + QT_BEGIN_NAMESPACE class QString; @@ -49,7 +26,10 @@ class QIcon; namespace qdesigner_internal { -QDESIGNER_SHARED_EXPORT QIcon createIconSet(const QString &name); +QDESIGNER_SHARED_EXPORT QIcon createIconSet(QStringView name); +QDESIGNER_SHARED_EXPORT QIcon createIconSet(QLatin1StringView name); +QDESIGNER_SHARED_EXPORT QIcon createIconSet(QIcon::ThemeIcon themeIcon, + QLatin1StringView name); QDESIGNER_SHARED_EXPORT QIcon emptyIcon(); QDESIGNER_SHARED_EXPORT QIcon qtLogoIcon(); diff --git a/src/designer/src/lib/shared/iconselector.cpp b/src/designer/src/lib/shared/iconselector.cpp index 7b3c7a6b0..60c404423 100644 --- a/src/designer/src/lib/shared/iconselector.cpp +++ b/src/designer/src/lib/shared/iconselector.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 "iconselector_p.h" #include "qdesigner_utils_p.h" @@ -39,7 +14,9 @@ #include <QtDesigner/abstractlanguage.h> #include <QtDesigner/abstractintegration.h> #include <QtDesigner/qextensionmanager.h> +#include <QtDesigner/private/resourcebuilder_p.h> +#include <QtWidgets/qabstractitemview.h> #include <QtWidgets/qtoolbutton.h> #include <QtWidgets/qcombobox.h> #include <QtWidgets/qdialogbuttonbox.h> @@ -59,10 +36,53 @@ #include <QtCore/qdebug.h> #include <QtCore/qlist.h> +#include <utility> + QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { +using ThemeIconEnumEntry = std::pair<QString, QIcon>; + +static const QList<ThemeIconEnumEntry> &themeEnumIcons() +{ + static QList<ThemeIconEnumEntry> result; + if (result.isEmpty()) { + const QStringList &names = QResourceBuilder::themeIconNames(); + result.reserve(names.size()); + for (qsizetype i = 0, size = names.size(); i < size; ++i) + result.append({names.at(i), QIcon::fromTheme(QIcon::ThemeIcon(i))}); + } + return result; +} + +static void initThemeCombo(QComboBox *cb) +{ + cb->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + + for (const auto &te : themeEnumIcons()) + cb->addItem(te.second, te.first); + + cb->setCurrentIndex(-1); +} + +// Validator for theme line edit, accepts empty or non-blank strings. +class BlankSuppressingValidator : public QValidator { +public: + explicit BlankSuppressingValidator(QObject * parent = nullptr) : QValidator(parent) {} + State validate(QString &input, int &pos) const override + { + const auto blankPos = input.indexOf(u' '); + if (blankPos != -1) { + pos = blankPos; + return Invalid; + } + return Acceptable; + } +}; + // -------------------- LanguageResourceDialogPrivate class LanguageResourceDialogPrivate { LanguageResourceDialog *q_ptr; @@ -100,13 +120,14 @@ void LanguageResourceDialogPrivate::init(LanguageResourceDialog *p) QLayout *layout = new QVBoxLayout(p); layout->addWidget(m_browser); layout->addWidget(m_dialogButtonBox); - QObject::connect(m_dialogButtonBox, SIGNAL(accepted()), p, SLOT(slotAccepted())); + QObject::connect(m_dialogButtonBox, &QDialogButtonBox::accepted, p, [this] { slotAccepted(); }); QObject::connect(m_dialogButtonBox, &QDialogButtonBox::rejected, p, &QDialog::reject); - QObject::connect(m_browser, SIGNAL(currentPathChanged(QString)), p, SLOT(slotPathChanged(QString))); - QObject::connect(m_browser, SIGNAL(pathActivated(QString)), p, SLOT(slotAccepted())); + QObject::connect(m_browser, &QDesignerResourceBrowserInterface::currentPathChanged, + p, [this](const QString &fileName) { slotPathChanged(fileName); }); + QObject::connect(m_browser, &QDesignerResourceBrowserInterface::pathActivated, + p, [this] { slotAccepted(); }); p->setModal(true); p->setWindowTitle(LanguageResourceDialog::tr("Choose Resource")); - p->setWindowFlags(p->windowFlags() & ~Qt::WindowContextHelpButtonHint); setOkButtonEnabled(false); } @@ -169,12 +190,24 @@ LanguageResourceDialog* LanguageResourceDialog::create(QDesignerFormEditorInterf // ------------ IconSelectorPrivate -static inline QPixmap emptyPixmap() +struct QIconStateName { - QImage img(16, 16, QImage::Format_ARGB32_Premultiplied); - img.fill(0); - return QPixmap::fromImage(img); -} + std::pair<QIcon::Mode, QIcon::State> state; + const char *name; +}; + +constexpr QIconStateName stateToName[] = { + {{QIcon::Normal, QIcon::Off}, QT_TRANSLATE_NOOP("IconSelector", "Normal Off")}, + {{QIcon::Normal, QIcon::On}, QT_TRANSLATE_NOOP("IconSelector", "Normal On")}, + {{QIcon::Disabled, QIcon::Off}, QT_TRANSLATE_NOOP("IconSelector", "Disabled Off")}, + {{QIcon::Disabled, QIcon::On}, QT_TRANSLATE_NOOP("IconSelector", "Disabled On")}, + {{QIcon::Active, QIcon::Off}, QT_TRANSLATE_NOOP("IconSelector", "Active Off")}, + {{QIcon::Active, QIcon::On}, QT_TRANSLATE_NOOP("IconSelector", "Active On")}, + {{QIcon::Selected, QIcon::Off}, QT_TRANSLATE_NOOP("IconSelector", "Selected Off")}, + {{QIcon::Selected, QIcon::On}, QT_TRANSLATE_NOOP("IconSelector", "Selected On")} +}; + +constexpr int stateToNameSize = int(sizeof(stateToName) / sizeof(stateToName[0])); class IconSelectorPrivate { @@ -191,10 +224,12 @@ public: void slotResetAllActivated(); void slotUpdate(); - QList<QPair<QPair<QIcon::Mode, QIcon::State>, QString> > m_stateToName; // could be static map - - QMap<QPair<QIcon::Mode, QIcon::State>, int> m_stateToIndex; - QMap<int, QPair<QIcon::Mode, QIcon::State> > m_indexToState; + std::pair<QIcon::Mode, QIcon::State> currentState() const + { + const int i = m_stateComboBox->currentIndex(); + return i >= 0 && i < stateToNameSize + ? stateToName[i].state : std::pair<QIcon::Mode, QIcon::State>{}; + } const QIcon m_emptyIcon; QComboBox *m_stateComboBox = nullptr; @@ -214,12 +249,10 @@ void IconSelectorPrivate::slotUpdate() if (m_iconCache) icon = m_iconCache->icon(m_icon); - QMap<QPair<QIcon::Mode, QIcon::State>, PropertySheetPixmapValue> paths = m_icon.paths(); - for (auto itIndex = m_stateToIndex.cbegin(), end = m_stateToIndex.cend(); itIndex != end; ++itIndex) { - const QPair<QIcon::Mode, QIcon::State> state = itIndex.key(); + const auto &paths = m_icon.paths(); + for (int index = 0; index < stateToNameSize; ++index) { + const auto &state = stateToName[index].state; const PropertySheetPixmapValue pixmap = paths.value(state); - const int index = itIndex.value(); - QIcon pixmapIcon = QIcon(icon.pixmap(16, 16, state.first, state.second)); if (pixmapIcon.isNull()) pixmapIcon = m_emptyIcon; @@ -230,8 +263,7 @@ void IconSelectorPrivate::slotUpdate() m_stateComboBox->setItemData(index, font, Qt::FontRole); } - QPair<QIcon::Mode, QIcon::State> state = m_indexToState.value(m_stateComboBox->currentIndex()); - PropertySheetPixmapValue currentPixmap = paths.value(state); + PropertySheetPixmapValue currentPixmap = paths.value(currentState()); m_resetAction->setEnabled(!currentPixmap.path().isEmpty()); m_resetAllAction->setEnabled(!paths.isEmpty()); m_stateComboBox->update(); @@ -244,7 +276,7 @@ void IconSelectorPrivate::slotStateActivated() void IconSelectorPrivate::slotSetActivated() { - QPair<QIcon::Mode, QIcon::State> state = m_indexToState.value(m_stateComboBox->currentIndex()); + const auto state = currentState(); const PropertySheetPixmapValue pixmap = m_icon.pixmap(state.first, state.second); // Default to resource const PropertySheetPixmapValue::PixmapSource ps = pixmap.path().isEmpty() ? PropertySheetPixmapValue::ResourcePixmap : pixmap.pixmapSource(m_core); @@ -283,7 +315,7 @@ QString IconSelector::choosePixmapResource(QDesignerFormEditorInterface *core, Q void IconSelectorPrivate::slotSetResourceActivated() { - const QPair<QIcon::Mode, QIcon::State> state = m_indexToState.value(m_stateComboBox->currentIndex()); + const auto state = currentState(); PropertySheetPixmapValue pixmap = m_icon.pixmap(state.first, state.second); const QString oldPath = pixmap.path(); @@ -332,19 +364,18 @@ static QString imageFilter() { QString filter = QApplication::translate("IconSelector", "All Pixmaps ("); const auto supportedImageFormats = QImageReader::supportedImageFormats(); - const QString jpeg = QStringLiteral("JPEG"); - const int count = supportedImageFormats.count(); - for (int i = 0; i< count; ++i) { + const qsizetype count = supportedImageFormats.size(); + for (qsizetype i = 0; i < count; ++i) { if (i) - filter += QLatin1Char(' '); - filter += QStringLiteral("*."); + filter += u' '; + filter += "*."_L1; const QString outputFormat = QString::fromUtf8(supportedImageFormats.at(i)); - if (outputFormat != jpeg) + if (outputFormat != "JPEG"_L1) filter += outputFormat.toLower(); else - filter += QStringLiteral("jpg *.jpeg"); + filter += "jpg *.jpeg"_L1; } - filter += QLatin1Char(')'); + filter += u')'; return filter; } @@ -368,7 +399,7 @@ QString IconSelector::choosePixmapFile(const QString &directory, QDesignerDialog void IconSelectorPrivate::slotSetFileActivated() { - QPair<QIcon::Mode, QIcon::State> state = m_indexToState.value(m_stateComboBox->currentIndex()); + const auto state = currentState(); PropertySheetPixmapValue pixmap = m_icon.pixmap(state.first, state.second); const QString newPath = IconSelector::choosePixmapFile(pixmap.path(), m_core->dialogGui(), q_ptr); @@ -384,7 +415,7 @@ void IconSelectorPrivate::slotSetFileActivated() void IconSelectorPrivate::slotResetActivated() { - QPair<QIcon::Mode, QIcon::State> state = m_indexToState.value(m_stateComboBox->currentIndex()); + const auto state = currentState(); PropertySheetPixmapValue pixmap = m_icon.pixmap(state.first, state.second); const PropertySheetPixmapValue newPixmap; @@ -421,15 +452,6 @@ IconSelector::IconSelector(QWidget *parent) : l->addWidget(d_ptr->m_iconButton); l->setContentsMargins(QMargins()); - d_ptr->m_stateToName << qMakePair(qMakePair(QIcon::Normal, QIcon::Off), tr("Normal Off") ); - d_ptr->m_stateToName << qMakePair(qMakePair(QIcon::Normal, QIcon::On), tr("Normal On") ); - d_ptr->m_stateToName << qMakePair(qMakePair(QIcon::Disabled, QIcon::Off), tr("Disabled Off") ); - d_ptr->m_stateToName << qMakePair(qMakePair(QIcon::Disabled, QIcon::On), tr("Disabled On") ); - d_ptr->m_stateToName << qMakePair(qMakePair(QIcon::Active, QIcon::Off), tr("Active Off") ); - d_ptr->m_stateToName << qMakePair(qMakePair(QIcon::Active, QIcon::On), tr("Active On") ); - d_ptr->m_stateToName << qMakePair(qMakePair(QIcon::Selected, QIcon::Off), tr("Selected Off") ); - d_ptr->m_stateToName << qMakePair(qMakePair(QIcon::Selected, QIcon::On), tr("Selected On") ); - QMenu *setMenu = new QMenu(this); QAction *setResourceAction = new QAction(tr("Choose Resource..."), this); @@ -438,7 +460,7 @@ IconSelector::IconSelector(QWidget *parent) : d_ptr->m_resetAllAction = new QAction(tr("Reset All"), this); d_ptr->m_resetAction->setEnabled(false); d_ptr->m_resetAllAction->setEnabled(false); - //d_ptr->m_resetAction->setIcon(createIconSet(QString::fromUtf8("resetproperty.png"))); + //d_ptr->m_resetAction->setIcon(createIconSet("resetproperty.png"_L1)); setMenu->addAction(setResourceAction); setMenu->addAction(setFileAction); @@ -446,28 +468,23 @@ IconSelector::IconSelector(QWidget *parent) : setMenu->addAction(d_ptr->m_resetAction); setMenu->addAction(d_ptr->m_resetAllAction); - int index = 0; - QStringList items; - for (const auto &item : qAsConst(d_ptr->m_stateToName)) { - const QPair<QIcon::Mode, QIcon::State> state = item.first; - const QString name = item.second; - - items.append(name); - d_ptr->m_stateToIndex[state] = index; - d_ptr->m_indexToState[index] = state; - index++; - } - d_ptr->m_stateComboBox->addItems(items); + for (const auto &item : stateToName) + d_ptr->m_stateComboBox->addItem(tr(item.name)); d_ptr->m_iconButton->setMenu(setMenu); - connect(d_ptr->m_stateComboBox, SIGNAL(activated(int)), this, SLOT(slotStateActivated())); - connect(d_ptr->m_iconButton, SIGNAL(clicked()), this, SLOT(slotSetActivated())); - connect(setResourceAction, SIGNAL(triggered()), this, SLOT(slotSetResourceActivated())); - connect(setFileAction, SIGNAL(triggered()), this, SLOT(slotSetFileActivated())); - connect(d_ptr->m_resetAction, SIGNAL(triggered()), this, SLOT(slotResetActivated())); - connect(d_ptr->m_resetAllAction, SIGNAL(triggered()), this, SLOT(slotResetAllActivated())); - + connect(d_ptr->m_stateComboBox, &QComboBox::activated, + this, [this] { d_ptr->slotStateActivated(); }); + connect(d_ptr->m_iconButton, &QAbstractButton::clicked, + this, [this] { d_ptr->slotSetActivated(); }); + connect(setResourceAction, &QAction::triggered, + this, [this] { d_ptr->slotSetResourceActivated(); }); + connect(setFileAction, &QAction::triggered, + this, [this] { d_ptr->slotSetFileActivated(); }); + connect(d_ptr->m_resetAction, &QAction::triggered, + this, [this] { d_ptr->slotResetActivated(); }); + connect(d_ptr->m_resetAllAction, &QAction::triggered, + this, [this] { d_ptr->slotResetAllActivated(); }); d_ptr->slotUpdate(); } @@ -497,117 +514,134 @@ void IconSelector::setFormEditor(QDesignerFormEditorInterface *core) void IconSelector::setIconCache(DesignerIconCache *iconCache) { d_ptr->m_iconCache = iconCache; - connect(iconCache, SIGNAL(reloaded()), this, SLOT(slotUpdate())); + connect(iconCache, &DesignerIconCache::reloaded, this, [this] { d_ptr->slotUpdate(); }); d_ptr->slotUpdate(); } void IconSelector::setPixmapCache(DesignerPixmapCache *pixmapCache) { d_ptr->m_pixmapCache = pixmapCache; - connect(pixmapCache, SIGNAL(reloaded()), this, SLOT(slotUpdate())); + connect(pixmapCache, &DesignerPixmapCache::reloaded, this, [this] { d_ptr->slotUpdate(); }); d_ptr->slotUpdate(); } // --- IconThemeEditor -// Validator for theme line edit, accepts empty or non-blank strings. -class BlankSuppressingValidator : public QValidator { -public: - explicit BlankSuppressingValidator(QObject * parent = nullptr) : QValidator(parent) {} - - State validate(QString &input, int &pos) const override - { - const int blankPos = input.indexOf(QLatin1Char(' ')); - if (blankPos != -1) { - pos = blankPos; - return Invalid; - } - return Acceptable; - } -}; +static const QMap<QString, QIcon> &themeIcons() +{ + static QMap<QString, QIcon> result; + if (result.isEmpty()) { + QFile file(u":/qt-project.org/designer/icon-naming-spec.txt"_s); + if (file.open(QIODevice::ReadOnly)) { + while (!file.atEnd()) { + const auto line = file.readLine().trimmed(); + if (line.isEmpty() || line.startsWith('#')) + continue; + const auto iconName = QString::fromUtf8(line); + result.insert(iconName, QIcon::fromTheme(iconName)); + } + file.close(); + } + } + return result; +} struct IconThemeEditorPrivate { - IconThemeEditorPrivate(); + void create(QWidget *topLevel, bool wantResetButton); - const QPixmap m_emptyPixmap; - QLineEdit *m_themeLineEdit; - QLabel *m_themeLabel; + QComboBox *m_themeComboBox{}; + QToolButton *m_themeResetButton{}; }; -IconThemeEditorPrivate::IconThemeEditorPrivate() : - m_emptyPixmap(emptyPixmap()), - m_themeLineEdit(new QLineEdit), - m_themeLabel(new QLabel) +void IconThemeEditorPrivate::create(QWidget *topLevel, bool wantResetButton) { + m_themeComboBox = new QComboBox(); + QHBoxLayout *mainHLayout = new QHBoxLayout(topLevel); + mainHLayout->setContentsMargins({}); + mainHLayout->addWidget(m_themeComboBox); + if (wantResetButton) { + m_themeResetButton = new QToolButton; + m_themeResetButton->setIcon(createIconSet("resetproperty.png"_L1)); + mainHLayout->addWidget(m_themeResetButton); + } + topLevel->setFocusProxy(m_themeComboBox); } IconThemeEditor::IconThemeEditor(QWidget *parent, bool wantResetButton) : QWidget (parent), d(new IconThemeEditorPrivate) { - QHBoxLayout *mainHLayout = new QHBoxLayout; - mainHLayout->setContentsMargins(QMargins()); + d->create(this, wantResetButton); + d->m_themeComboBox->setEditable(true); + + const auto icons = themeIcons(); + for (auto i = icons.constBegin(); i != icons.constEnd(); ++i) + d->m_themeComboBox->addItem(i.value(), i.key()); + d->m_themeComboBox->setCurrentIndex(-1); + d->m_themeComboBox->lineEdit()->setValidator(new BlankSuppressingValidator(this)); + connect(d->m_themeComboBox, &QComboBox::currentTextChanged, this, &IconThemeEditor::edited); + if (wantResetButton) + connect(d->m_themeResetButton, &QAbstractButton::clicked, this, &IconThemeEditor::reset); +} + +IconThemeEditor::~IconThemeEditor() = default; - // Vertically center theme preview label - d->m_themeLabel->setPixmap(d->m_emptyPixmap); +void IconThemeEditor::reset() +{ + d->m_themeComboBox->setCurrentIndex(-1); + emit edited(QString()); +} - QVBoxLayout *themeLabelVLayout = new QVBoxLayout; - d->m_themeLabel->setMargin(1); - themeLabelVLayout->setContentsMargins(QMargins()); - themeLabelVLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); - themeLabelVLayout->addWidget(d->m_themeLabel); - themeLabelVLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); - mainHLayout->addLayout(themeLabelVLayout); +QString IconThemeEditor::theme() const +{ + return d->m_themeComboBox->currentText(); +} - d->m_themeLineEdit = new QLineEdit; - d->m_themeLineEdit->setValidator(new BlankSuppressingValidator(d->m_themeLineEdit)); - connect(d->m_themeLineEdit, &QLineEdit::textChanged, this, &IconThemeEditor::slotChanged); - connect(d->m_themeLineEdit, &QLineEdit::textEdited, this, &IconThemeEditor::edited); - mainHLayout->addWidget(d->m_themeLineEdit); +void IconThemeEditor::setTheme(const QString &t) +{ + d->m_themeComboBox->setCurrentText(t); +} - if (wantResetButton) { - QToolButton *themeResetButton = new QToolButton; - themeResetButton->setIcon(createIconSet(QStringLiteral("resetproperty.png"))); - connect(themeResetButton, &QAbstractButton::clicked, this, &IconThemeEditor::reset); - mainHLayout->addWidget(themeResetButton); - } +IconThemeEnumEditor::IconThemeEnumEditor(QWidget *parent, bool wantResetButton) : + QWidget (parent), d(new IconThemeEditorPrivate) +{ + d->create(this, wantResetButton); + initThemeCombo(d->m_themeComboBox); - setLayout(mainHLayout); - setFocusProxy(d->m_themeLineEdit); + connect(d->m_themeComboBox, &QComboBox::currentIndexChanged, + this, &IconThemeEnumEditor::edited); + if (wantResetButton) + connect(d->m_themeResetButton, &QAbstractButton::clicked, this, &IconThemeEnumEditor::reset); } -IconThemeEditor::~IconThemeEditor() = default; +IconThemeEnumEditor::~IconThemeEnumEditor() = default; -void IconThemeEditor::reset() +void IconThemeEnumEditor::reset() { - d->m_themeLineEdit->clear(); - emit edited(QString()); + d->m_themeComboBox->setCurrentIndex(-1); + emit edited(-1); } -void IconThemeEditor::slotChanged(const QString &theme) +int IconThemeEnumEditor::themeEnum() const { - updatePreview(theme); + return d->m_themeComboBox->currentIndex(); } -void IconThemeEditor::updatePreview(const QString &t) +void IconThemeEnumEditor::setThemeEnum(int t) { - // Update preview label with icon. - if (t.isEmpty() || !QIcon::hasThemeIcon(t)) { // Empty - if (d->m_themeLabel->pixmap(Qt::ReturnByValue).cacheKey() != d->m_emptyPixmap.cacheKey()) - d->m_themeLabel->setPixmap(d->m_emptyPixmap); - } else { - const QIcon icon = QIcon::fromTheme(t); - d->m_themeLabel->setPixmap(icon.pixmap(d->m_emptyPixmap.size())); - } + Q_ASSERT(t >= -1 && t < int(QIcon::ThemeIcon::NThemeIcons)); + d->m_themeComboBox->setCurrentIndex(t); } -QString IconThemeEditor::theme() const +QString IconThemeEnumEditor::iconName(int e) { - return d->m_themeLineEdit->text(); + return QResourceBuilder::themeIconNames().value(e); } -void IconThemeEditor::setTheme(const QString &t) +QComboBox *IconThemeEnumEditor::createComboBox(QWidget *parent) { - d->m_themeLineEdit->setText(t); + auto *result = new QComboBox(parent); + initThemeCombo(result); + return result; } } // qdesigner_internal diff --git a/src/designer/src/lib/shared/iconselector_p.h b/src/designer/src/lib/shared/iconselector_p.h index 40e38acdd..4a4238e66 100644 --- a/src/designer/src/lib/shared/iconselector_p.h +++ b/src/designer/src/lib/shared/iconselector_p.h @@ -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 // // W A R N I N G @@ -50,6 +25,8 @@ QT_BEGIN_NAMESPACE +class QComboBox; + class QtResourceModel; class QDesignerFormEditorInterface; class QDesignerDialogGuiInterface; @@ -81,8 +58,6 @@ private: QScopedPointer<class LanguageResourceDialogPrivate> d_ptr; Q_DECLARE_PRIVATE(LanguageResourceDialog) Q_DISABLE_COPY_MOVE(LanguageResourceDialog) - Q_PRIVATE_SLOT(d_func(), void slotAccepted()) - Q_PRIVATE_SLOT(d_func(), void slotPathChanged(QString)) }; @@ -114,14 +89,6 @@ private: QScopedPointer<class IconSelectorPrivate> d_ptr; Q_DECLARE_PRIVATE(IconSelector) Q_DISABLE_COPY_MOVE(IconSelector) - - Q_PRIVATE_SLOT(d_func(), void slotStateActivated()) - Q_PRIVATE_SLOT(d_func(), void slotSetActivated()) - Q_PRIVATE_SLOT(d_func(), void slotSetResourceActivated()) - Q_PRIVATE_SLOT(d_func(), void slotSetFileActivated()) - Q_PRIVATE_SLOT(d_func(), void slotResetActivated()) - Q_PRIVATE_SLOT(d_func(), void slotResetAllActivated()) - Q_PRIVATE_SLOT(d_func(), void slotUpdate()) }; // IconThemeEditor: Let's the user input theme icon names and shows a preview label. @@ -142,12 +109,32 @@ signals: public slots: void reset(); -private slots: - void slotChanged(const QString &); - private: - void updatePreview(const QString &); + QScopedPointer<IconThemeEditorPrivate> d; +}; + +// IconThemeEnumEditor: Let's the user input theme icon enum values +// (QIcon::ThemeIcon) and shows a preview label. -1 means nothing selected. +class QDESIGNER_SHARED_EXPORT IconThemeEnumEditor : public QWidget +{ + Q_OBJECT +public: + explicit IconThemeEnumEditor(QWidget *parent = nullptr, bool wantResetButton = true); + ~IconThemeEnumEditor() override; + int themeEnum() const; + void setThemeEnum(int); + + static QString iconName(int e); + static QComboBox *createComboBox(QWidget *parent = nullptr); + +signals: + void edited(int); + +public slots: + void reset(); + +private: QScopedPointer<IconThemeEditorPrivate> d; }; diff --git a/src/designer/src/lib/shared/invisible_widget.cpp b/src/designer/src/lib/shared/invisible_widget.cpp index 78d8c77d6..7fec394ba 100644 --- a/src/designer/src/lib/shared/invisible_widget.cpp +++ b/src/designer/src/lib/shared/invisible_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 "invisible_widget_p.h" diff --git a/src/designer/src/lib/shared/invisible_widget_p.h b/src/designer/src/lib/shared/invisible_widget_p.h index 423e5d293..30a7970d4 100644 --- a/src/designer/src/lib/shared/invisible_widget_p.h +++ b/src/designer/src/lib/shared/invisible_widget_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/layout.cpp b/src/designer/src/lib/shared/layout.cpp index ce2351d65..b35361a38 100644 --- a/src/designer/src/lib/shared/layout.cpp +++ b/src/designer/src/lib/shared/layout.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 "layout_p.h" #include "layoutdecoration.h" @@ -43,6 +18,7 @@ #include <QtDesigner/qextensionmanager.h> #include <QtCore/qdebug.h> +#include <QtCore/qhash.h> #include <QtCore/qlist.h> #include <QtCore/qset.h> @@ -63,7 +39,7 @@ QT_BEGIN_NAMESPACE -enum { FormLayoutColumns = 2 }; +using namespace Qt::StringLiterals; namespace qdesigner_internal { @@ -140,7 +116,7 @@ void Layout::setup() // Widgets which are already laid out are thrown away here too QMultiMap<QWidget*, QWidget*> lists; - for (QWidget *w : qAsConst(m_widgets)) { + for (QWidget *w : std::as_const(m_widgets)) { QWidget *p = w->parentWidget(); if (p && LayoutInfo::layoutType(m_formWindow->core(), p) != LayoutInfo::NoLayout @@ -153,7 +129,7 @@ void Layout::setup() QWidgetList lastList; const QWidgetList &parents = lists.keys(); for (QWidget *p : parents) { - if (lists.count(p) > lastList.count()) + if (lists.count(p) > lastList.size()) lastList = lists.values(p); } @@ -162,7 +138,7 @@ void Layout::setup() // best list has only one entry and we do not layout a container, // we leave here. QDesignerWidgetDataBaseInterface *widgetDataBase = m_formWindow->core()->widgetDataBase(); - if (lastList.count() < 2 && + if (lastList.size() < 2 && (!m_layoutBase || (!widgetDataBase->isContainer(m_layoutBase, false) && m_layoutBase != m_formWindow->mainContainer())) @@ -184,7 +160,7 @@ void Layout::setup() // be placed and connect to widgetDestroyed() signals of the // widgets to get informed if one gets deleted to be able to // handle that and do not crash in this case - for (QWidget *w : qAsConst(m_widgets)) { + for (QWidget *w : std::as_const(m_widgets)) { connect(w, &QObject::destroyed, this, &Layout::widgetDestroyed); m_startPoint = QPoint(qMin(m_startPoint.x(), w->x()), qMin(m_startPoint.y(), w->y())); const QRect rc(w->geometry()); @@ -209,7 +185,7 @@ void Layout::widgetDestroyed() bool Layout::prepareLayout(bool &needMove, bool &needReparent) { - for (QWidget *widget : qAsConst(m_widgets)) + for (QWidget *widget : std::as_const(m_widgets)) widget->raise(); needMove = !m_layoutBase; @@ -220,10 +196,10 @@ bool Layout::prepareLayout(bool &needMove, bool &needReparent) if (m_layoutBase == nullptr) { const bool useSplitter = m_layoutType == LayoutInfo::HSplitter || m_layoutType == LayoutInfo::VSplitter; - const QString baseWidgetClassName = useSplitter ? QLatin1String("QSplitter") : QLatin1String("QLayoutWidget"); + const QString baseWidgetClassName = useSplitter ? u"QSplitter"_s : u"QLayoutWidget"_s; m_layoutBase = widgetFactory->createWidget(baseWidgetClassName, widgetFactory->containerOfWidget(m_parentWidget)); if (useSplitter) { - m_layoutBase->setObjectName(QStringLiteral("splitter")); + m_layoutBase->setObjectName(u"splitter"_s); m_formWindow->ensureUniqueObjectName(m_layoutBase); } } else { @@ -319,7 +295,7 @@ void Layout::finishLayout(bool needMove, QLayout *layout) void Layout::undoLayout() { - if (!m_widgets.count()) + if (m_widgets.isEmpty()) return; m_formWindow->selectWidget(m_layoutBase, false); @@ -365,14 +341,13 @@ void Layout::undoLayout() void Layout::breakLayout() { - typedef QMap<QWidget *, QRect> WidgetRectMap; - WidgetRectMap rects; + QHash<QWidget *, QRect> rects; /* Store the geometry of the widgets. The idea is to give the user space * to rearrange them, so, we do a adjustSize() on them, unless they want * to grow (expanding widgets like QTextEdit), in which the geometry is * preserved. Note that historically, geometries were re-applied * only after breaking splitters. */ - for (QWidget *w : qAsConst(m_widgets)) { + for (QWidget *w : std::as_const(m_widgets)) { const QRect geom = w->geometry(); const QSize sizeHint = w->sizeHint(); const bool restoreGeometry = sizeHint.isEmpty() || sizeHint.width() > geom.width() || sizeHint.height() > geom.height(); @@ -427,11 +402,11 @@ static QString suggestLayoutName(const char *className) { // Legacy if (!qstrcmp(className, "QHBoxLayout")) - return QStringLiteral("horizontalLayout"); + return u"horizontalLayout"_s; if (!qstrcmp(className, "QVBoxLayout")) - return QStringLiteral("verticalLayout"); + return u"verticalLayout"_s; if (!qstrcmp(className, "QGridLayout")) - return QStringLiteral("gridLayout"); + return u"gridLayout"_s; return qtify(QString::fromUtf8(className)); } @@ -445,10 +420,10 @@ QLayout *Layout::createLayout(int type) // QLayoutWidget QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(m_formWindow->core()->extensionManager(), layout); if (sheet && qobject_cast<QLayoutWidget*>(m_layoutBase)) { - sheet->setProperty(sheet->indexOf(QStringLiteral("leftMargin")), 0); - sheet->setProperty(sheet->indexOf(QStringLiteral("topMargin")), 0); - sheet->setProperty(sheet->indexOf(QStringLiteral("rightMargin")), 0); - sheet->setProperty(sheet->indexOf(QStringLiteral("bottomMargin")), 0); + sheet->setProperty(sheet->indexOf(u"leftMargin"_s), 0); + sheet->setProperty(sheet->indexOf(u"topMargin"_s), 0); + sheet->setProperty(sheet->indexOf(u"rightMargin"_s), 0); + sheet->setProperty(sheet->indexOf(u"bottomMargin"_s), 0); } return layout; } @@ -512,9 +487,7 @@ void BoxLayout::doLayout() QDesignerWidgetItemInstaller wii; // Make sure we use QDesignerWidgetItem. - const QWidgetList::const_iterator cend = widgets().constEnd(); - for (QWidgetList::const_iterator it = widgets().constBegin(); it != cend; ++it) { - QWidget *w = *it; + for (auto *w : widgets()) { if (needReparent) reparentToLayoutBase(w); @@ -564,10 +537,7 @@ void SplitterLayout::doLayout() QSplitter *splitter = qobject_cast<QSplitter*>(layoutBaseWidget()); Q_ASSERT(splitter != nullptr); - - const QWidgetList::const_iterator cend = widgets().constEnd(); - for (QWidgetList::const_iterator it = widgets().constBegin(); it != cend; ++it) { - QWidget *w = *it; + for (auto *w : widgets()) { if (needReparent) reparentToLayoutBase(w); splitter->addWidget(w); @@ -580,19 +550,21 @@ void SplitterLayout::doLayout() // ---------- Grid: Helper for laying out grids -class Grid +class GridHelper { - Q_DISABLE_COPY_MOVE(Grid); + Q_DISABLE_COPY_MOVE(GridHelper); public: + enum { FormLayoutColumns = 2 }; + enum Mode { GridLayout, // Arbitrary size/supports span FormLayout // 2-column/no span }; - Grid(Mode mode); + GridHelper(Mode mode); void resize(int nrows, int ncols); - ~Grid(); + ~GridHelper(); QWidget* cell(int row, int col) const { return m_cells[ row * m_ncols + col]; } @@ -631,7 +603,7 @@ private: QWidget** m_cells; // widget matrix w11, w12, w21... }; -Grid::Grid(Mode mode) : +GridHelper::GridHelper(Mode mode) : m_mode(mode), m_nrows(0), m_ncols(0), @@ -639,12 +611,12 @@ Grid::Grid(Mode mode) : { } -Grid::~Grid() +GridHelper::~GridHelper() { delete [] m_cells; } -void Grid::resize(int nrows, int ncols) +void GridHelper::resize(int nrows, int ncols) { delete [] m_cells; m_cells = nullptr; @@ -656,7 +628,7 @@ void Grid::resize(int nrows, int ncols) } } -void Grid::setCells(const QRect &c, QWidget* w) +void GridHelper::setCells(const QRect &c, QWidget* w) { const int bottom = c.top() + c.height(); const int width = c.width(); @@ -667,7 +639,7 @@ void Grid::setCells(const QRect &c, QWidget* w) } } -int Grid::countRow(int r, int c) const +int GridHelper::countRow(int r, int c) const { QWidget* w = cell(r, c); int i = c + 1; @@ -676,7 +648,7 @@ int Grid::countRow(int r, int c) const return i - c; } -int Grid::countCol(int r, int c) const +int GridHelper::countCol(int r, int c) const { QWidget* w = cell(r, c); int i = r + 1; @@ -685,19 +657,19 @@ int Grid::countCol(int r, int c) const return i - r; } -void Grid::setCol(int r, int c, QWidget* w, int count) +void GridHelper::setCol(int r, int c, QWidget* w, int count) { for (int i = 0; i < count; i++) setCell(r + i, c, w); } -void Grid::setRow(int r, int c, QWidget* w, int count) +void GridHelper::setRow(int r, int c, QWidget* w, int count) { for (int i = 0; i < count; i++) setCell(r, c + i, w); } -bool Grid::isWidgetStartCol(int c) const +bool GridHelper::isWidgetStartCol(int c) const { for (int r = 0; r < m_nrows; r++) { if (cell(r, c) && ((c==0) || (cell(r, c) != cell(r, c-1)))) { @@ -707,7 +679,7 @@ bool Grid::isWidgetStartCol(int c) const return false; } -bool Grid::isWidgetEndCol(int c) const +bool GridHelper::isWidgetEndCol(int c) const { for (int r = 0; r < m_nrows; r++) { if (cell(r, c) && ((c == m_ncols-1) || (cell(r, c) != cell(r, c+1)))) @@ -716,7 +688,7 @@ bool Grid::isWidgetEndCol(int c) const return false; } -bool Grid::isWidgetStartRow(int r) const +bool GridHelper::isWidgetStartRow(int r) const { for ( int c = 0; c < m_ncols; c++) { if (cell(r, c) && ((r==0) || (cell(r, c) != cell(r-1, c)))) @@ -725,7 +697,7 @@ bool Grid::isWidgetStartRow(int r) const return false; } -bool Grid::isWidgetEndRow(int r) const +bool GridHelper::isWidgetEndRow(int r) const { for (int c = 0; c < m_ncols; c++) { if (cell(r, c) && ((r == m_nrows-1) || (cell(r, c) != cell(r+1, c)))) @@ -735,7 +707,7 @@ bool Grid::isWidgetEndRow(int r) const } -bool Grid::isWidgetTopLeft(int r, int c) const +bool GridHelper::isWidgetTopLeft(int r, int c) const { QWidget* w = cell(r, c); if (!w) @@ -743,7 +715,7 @@ bool Grid::isWidgetTopLeft(int r, int c) const return (!r || cell(r-1, c) != w) && (!c || cell(r, c-1) != w); } -void Grid::extendLeft() +void GridHelper::extendLeft() { for (int c = 1; c < m_ncols; c++) { for (int r = 0; r < m_nrows; r++) { @@ -774,7 +746,7 @@ void Grid::extendLeft() } -void Grid::extendRight() +void GridHelper::extendRight() { for (int c = m_ncols - 2; c >= 0; c--) { for (int r = 0; r < m_nrows; r++) { @@ -804,7 +776,7 @@ void Grid::extendRight() } -void Grid::extendUp() +void GridHelper::extendUp() { for (int r = 1; r < m_nrows; r++) { for (int c = 0; c < m_ncols; c++) { @@ -833,7 +805,7 @@ void Grid::extendUp() } } -void Grid::extendDown() +void GridHelper::extendDown() { for (int r = m_nrows - 2; r >= 0; r--) { for (int c = 0; c < m_ncols; c++) { @@ -862,7 +834,7 @@ void Grid::extendDown() } } -void Grid::simplify() +void GridHelper::simplify() { switch (m_mode) { case GridLayout: @@ -892,7 +864,7 @@ void Grid::simplify() } -void Grid::shrink() +void GridHelper::shrink() { // tick off the occupied cols/rows (bordering on widget edges) QList<bool> columns(m_ncols, false); @@ -928,7 +900,7 @@ void Grid::shrink() m_ncols = simplifiedNCols; } -bool Grid::shrinkFormLayoutSpans() +bool GridHelper::shrinkFormLayoutSpans() { bool shrunk = false; using WidgetSet = QSet<QWidget *>; @@ -940,9 +912,7 @@ bool Grid::shrinkFormLayoutSpans() widgets.insert(w); // Restrict the widget span: max horizontal span at column 0: 2, anything else: 1 const int maxRowSpan = 1; - const WidgetSet::const_iterator cend = widgets.constEnd(); - for (WidgetSet::const_iterator it = widgets.constBegin(); it != cend ; ++it) { - QWidget *w = *it; + for (auto *w : std::as_const(widgets)) { int row, col, rowspan, colspan; if (!locateWidget(w, row, col, rowspan, colspan)) { qDebug("ooops, widget '%s' does not fit in layout", w->objectName().toUtf8().constData()); @@ -969,7 +939,7 @@ bool Grid::shrinkFormLayoutSpans() return shrunk; } -void Grid::reallocFormLayout() +void GridHelper::reallocFormLayout() { // Columns matching? -> happy! if (m_ncols == FormLayoutColumns) @@ -1033,7 +1003,7 @@ void Grid::reallocFormLayout() m_ncols = FormLayoutColumns; } -bool Grid::locateWidget(QWidget *w, int &row, int &col, int &rowspan, int &colspan) const +bool GridHelper::locateWidget(QWidget *w, int &row, int &col, int &rowspan, int &colspan) const { const int end = m_nrows * m_ncols; const int startIndex = std::find(m_cells, m_cells + end, w) - m_cells; @@ -1071,13 +1041,13 @@ public: protected: QWidgetList buildGrid(const QWidgetList &); - Grid m_grid; + GridHelper m_grid; }; template <class GridLikeLayout, int LayoutType, int GridMode> GridLayout<GridLikeLayout, LayoutType, GridMode>::GridLayout(const QWidgetList &wl, QWidget *p, QDesignerFormWindowInterface *fw, QWidget *lb) : Layout(wl, p, fw, lb, LayoutInfo::Grid), - m_grid(static_cast<Grid::Mode>(GridMode)) + m_grid(static_cast<GridHelper::Mode>(GridMode)) { } @@ -1095,9 +1065,7 @@ void GridLayout<GridLikeLayout, LayoutType, GridMode>::doLayout() QDesignerWidgetItemInstaller wii; // Make sure we use QDesignerWidgetItem. - const QWidgetList::const_iterator cend = widgets().constEnd(); - for (QWidgetList::const_iterator it = widgets().constBegin(); it != cend; ++it) { - QWidget *w = *it; + for (auto *w : widgets()) { int r = 0, c = 0, rs = 0, cs = 0; if (m_grid.locateWidget(w, r, c, rs, cs)) { @@ -1127,7 +1095,7 @@ void removeIntVecDuplicates(QList<int> &v) if (v.size() < 2) return; - for (QList<int>::iterator current = v.begin() ; (current != v.end()) && ((current+1) != v.end()) ; ) + for (auto current = v.begin() ; (current != v.end()) && ((current + 1) != v.end()) ; ) if ( *current == *(current+1) ) v.erase(current+1); else @@ -1153,14 +1121,14 @@ QWidgetList GridLayout<GridLikeLayout, LayoutType, GridMode>::buildGrid(const QW // ----------------------------------------------------------------- // We need a list of both start and stop values for x- & y-axis - const int widgetCount = widgetList.size(); + const auto widgetCount = widgetList.size(); QList<int> x( widgetCount * 2 ); QList<int> y( widgetCount * 2 ); // Using push_back would look nicer, but operator[] is much faster - int index = 0; - for (int i = 0; i < widgetCount; ++i) { - const QRect widgetPos = expandGeometry(widgetList.at(i)->geometry()); + qsizetype index = 0; + for (const auto *w : widgetList) { + const QRect widgetPos = expandGeometry(w->geometry()); x[index] = widgetPos.left(); x[index+1] = widgetPos.right(); y[index] = widgetPos.top(); @@ -1179,9 +1147,7 @@ QWidgetList GridLayout<GridLikeLayout, LayoutType, GridMode>::buildGrid(const QW // enough space m_grid.resize(y.size(), x.size()); - const QWidgetList::const_iterator cend = widgetList.constEnd(); - for (QWidgetList::const_iterator it = widgetList.constBegin(); it != cend; ++it) { - QWidget *w = *it; + for (auto *w : widgetList) { // Mark the cells in the grid that contains a widget const QRect widgetPos = expandGeometry(w->geometry()); QRect c(0, 0, 0, 0); // rect of columns/rows @@ -1191,8 +1157,8 @@ QWidgetList GridLayout<GridLikeLayout, LayoutType, GridMode>::buildGrid(const QW Q_ASSERT(leftIdx != -1); c.setLeft(leftIdx); c.setRight(leftIdx); - for (int cw=leftIdx; cw<x.size(); cw++) - if (x[cw] < widgetPos.right()) + for (qsizetype cw = leftIdx; cw < x.size(); ++cw) + if (x.at(cw) < widgetPos.right()) c.setRight(cw); else break; @@ -1201,8 +1167,8 @@ QWidgetList GridLayout<GridLikeLayout, LayoutType, GridMode>::buildGrid(const QW Q_ASSERT(topIdx != -1); c.setTop(topIdx); c.setBottom(topIdx); - for (int ch=topIdx; ch<y.size(); ch++) - if (y[ch] < widgetPos.bottom()) + for (qsizetype ch = topIdx; ch < y.size(); ++ch) + if (y.at(ch) < widgetPos.bottom()) c.setBottom(ch); else break; @@ -1228,7 +1194,7 @@ Layout* Layout::createLayout(const QWidgetList &widgets, QWidget *parentWidget, { switch (layoutType) { case LayoutInfo::Grid: - return new GridLayout<QGridLayout, LayoutInfo::Grid, Grid::GridLayout>(widgets, parentWidget, fw, layoutBase); + return new GridLayout<QGridLayout, LayoutInfo::Grid, GridHelper::GridLayout>(widgets, parentWidget, fw, layoutBase); case LayoutInfo::HBox: case LayoutInfo::VBox: { const Qt::Orientation orientation = layoutType == LayoutInfo::HBox ? Qt::Horizontal : Qt::Vertical; @@ -1240,7 +1206,7 @@ Layout* Layout::createLayout(const QWidgetList &widgets, QWidget *parentWidget, return new SplitterLayout(widgets, parentWidget, fw, layoutBase, orientation); } case LayoutInfo::Form: - return new GridLayout<QFormLayout, LayoutInfo::Form, Grid::FormLayout>(widgets, parentWidget, fw, layoutBase); + return new GridLayout<QFormLayout, LayoutInfo::Form, GridHelper::FormLayout>(widgets, parentWidget, fw, layoutBase); default: break; } diff --git a/src/designer/src/lib/shared/layout_p.h b/src/designer/src/lib/shared/layout_p.h index e6cd69a63..2dd8ee7e6 100644 --- a/src/designer/src/lib/shared/layout_p.h +++ b/src/designer/src/lib/shared/layout_p.h @@ -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 // // W A R N I N G @@ -102,8 +77,7 @@ private slots: private: QWidgetList m_widgets; QWidget *m_parentWidget; - typedef QHash<QWidget *, QRect> WidgetGeometryHash; - WidgetGeometryHash m_geometries; + QHash<QWidget *, QRect> m_geometries; QWidget *m_layoutBase; QDesignerFormWindowInterface *m_formWindow; const LayoutInfo::Type m_layoutType; diff --git a/src/designer/src/lib/shared/layoutinfo.cpp b/src/designer/src/lib/shared/layoutinfo.cpp index 0374de582..182e42f37 100644 --- a/src/designer/src/lib/shared/layoutinfo.cpp +++ b/src/designer/src/lib/shared/layoutinfo.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 "layoutinfo_p.h" @@ -42,6 +17,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { /*! \overload @@ -64,13 +41,12 @@ LayoutInfo::Type LayoutInfo::layoutType(const QDesignerFormEditorInterface *core static const QHash<QString, LayoutInfo::Type> &layoutNameTypeMap() { - static QHash<QString, LayoutInfo::Type> nameTypeMap; - if (nameTypeMap.isEmpty()) { - nameTypeMap.insert(QStringLiteral("QVBoxLayout"), LayoutInfo::VBox); - nameTypeMap.insert(QStringLiteral("QHBoxLayout"), LayoutInfo::HBox); - nameTypeMap.insert(QStringLiteral("QGridLayout"), LayoutInfo::Grid); - nameTypeMap.insert(QStringLiteral("QFormLayout"), LayoutInfo::Form); - } + static const QHash<QString, LayoutInfo::Type> nameTypeMap = { + {u"QVBoxLayout"_s, LayoutInfo::VBox}, + {u"QHBoxLayout"_s, LayoutInfo::HBox}, + {u"QGridLayout"_s, LayoutInfo::Grid}, + {u"QFormLayout"_s, LayoutInfo::Form} + }; return nameTypeMap; } diff --git a/src/designer/src/lib/shared/layoutinfo_p.h b/src/designer/src/lib/shared/layoutinfo_p.h index e5326203a..7ddb2129f 100644 --- a/src/designer/src/lib/shared/layoutinfo_p.h +++ b/src/designer/src/lib/shared/layoutinfo_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/metadatabase.cpp b/src/designer/src/lib/shared/metadatabase.cpp index ed0de8dd6..77d6aa23c 100644 --- a/src/designer/src/lib/shared/metadatabase.cpp +++ b/src/designer/src/lib/shared/metadatabase.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 "metadatabase_p.h" #include "widgetdatabase_p.h" @@ -170,8 +145,7 @@ QObjectList MetaDataBase::objects() const { QObjectList result; - ItemMap::const_iterator it = m_items.begin(); - for (; it != m_items.end(); ++it) { + for (auto it = m_items.cbegin(), cend = m_items.cend(); it != cend; ++it) { if (it.value()->enabled()) result.append(it.key()); } diff --git a/src/designer/src/lib/shared/metadatabase_p.h b/src/designer/src/lib/shared/metadatabase_p.h index 48dee4086..2117f5975 100644 --- a/src/designer/src/lib/shared/metadatabase_p.h +++ b/src/designer/src/lib/shared/metadatabase_p.h @@ -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 // // W A R N I N G @@ -106,8 +81,7 @@ private slots: private: QDesignerFormEditorInterface *m_core; - typedef QHash<QObject *, MetaDataBaseItem*> ItemMap; - ItemMap m_items; + QHash<QObject *, MetaDataBaseItem *> m_items; }; // promotion convenience diff --git a/src/designer/src/lib/shared/morphmenu.cpp b/src/designer/src/lib/shared/morphmenu.cpp index 976a27ded..3e7c053ca 100644 --- a/src/designer/src/lib/shared/morphmenu.cpp +++ b/src/designer/src/lib/shared/morphmenu.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 "morphmenu_p.h" #include "formwindowbase_p.h" @@ -73,9 +48,11 @@ Q_DECLARE_METATYPE(QWidgetList) QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // Helpers for the dynamic properties that store Z/Widget order -static const char *widgetOrderPropertyC = "_q_widgetOrder"; -static const char *zOrderPropertyC = "_q_zOrder"; +static const char widgetOrderPropertyC[] = "_q_widgetOrder"; +static const char zOrderPropertyC[] = "_q_zOrder"; /* Morphing in Designer: * It is possible to morph: @@ -147,9 +124,8 @@ static MorphCategory category(const QWidget *w) static QStringList classesOfCategory(MorphCategory cat) { - typedef QMap<MorphCategory, QStringList> CandidateCache; - static CandidateCache candidateCache; - CandidateCache::iterator it = candidateCache.find(cat); + static QMap<MorphCategory, QStringList> candidateCache; + auto it = candidateCache.find(cat); if (it == candidateCache.end()) { it = candidateCache.insert(cat, QStringList()); QStringList &l = it.value(); @@ -159,29 +135,29 @@ static QStringList classesOfCategory(MorphCategory cat) case MorphSimpleContainer: // Do not generally allow to morph into a layout. // This can be risky in case of container pages,etc. - l << QStringLiteral("QWidget") << QStringLiteral("QFrame") << QStringLiteral("QGroupBox"); + l << u"QWidget"_s << u"QFrame"_s << u"QGroupBox"_s; break; case MorphPageContainer: - l << QStringLiteral("QTabWidget") << QStringLiteral("QStackedWidget") << QStringLiteral("QToolBox"); + l << u"QTabWidget"_s << u"QStackedWidget"_s << u"QToolBox"_s; break; case MorphItemView: - l << QStringLiteral("QListView") << QStringLiteral("QListWidget") - << QStringLiteral("QTreeView") << QStringLiteral("QTreeWidget") - << QStringLiteral("QTableView") << QStringLiteral("QTableWidget") - << QStringLiteral("QColumnView"); + l << u"QListView"_s << u"QListWidget"_s + << u"QTreeView"_s << u"QTreeWidget"_s + << u"QTableView"_s << u"QTableWidget"_s + << u"QColumnView"_s; break; case MorphButton: - l << QStringLiteral("QCheckBox") << QStringLiteral("QRadioButton") - << QStringLiteral("QPushButton") << QStringLiteral("QToolButton") - << QStringLiteral("QCommandLinkButton"); + l << u"QCheckBox"_s << u"QRadioButton"_s + << u"QPushButton"_s << u"QToolButton"_s + << u"QCommandLinkButton"_s; break; case MorphSpinBox: - l << QStringLiteral("QDateTimeEdit") << QStringLiteral("QDateEdit") - << QStringLiteral("QTimeEdit") - << QStringLiteral("QSpinBox") << QStringLiteral("QDoubleSpinBox"); + l << u"QDateTimeEdit"_s << u"QDateEdit"_s + << u"QTimeEdit"_s + << u"QSpinBox"_s << u"QDoubleSpinBox"_s; break; case MorphTextEdit: - l << QStringLiteral("QTextEdit") << QStringLiteral("QPlainTextEdit") << QStringLiteral("QTextBrowser"); + l << u"QTextEdit"_s << u"QPlainTextEdit"_s << u"QTextBrowser"_s; break; } } @@ -211,9 +187,9 @@ static QString suggestObjectName(const QString &oldClassName, const QString &new { QString oldClassPart = oldClassName; QString newClassPart = newClassName; - if (oldClassPart.startsWith(QLatin1Char('Q'))) + if (oldClassPart.startsWith(u'Q')) oldClassPart.remove(0, 1); - if (newClassPart.startsWith(QLatin1Char('Q'))) + if (newClassPart.startsWith(u'Q')) newClassPart.remove(0, 1); QString newName = oldName; @@ -301,7 +277,7 @@ bool MorphWidgetCommand::addMorphMacro(QDesignerFormWindowInterface *fw, QWidget // restore buddy using the QByteArray name. if (buddyLabel) { SetPropertyCommand *buddyCmd = new SetPropertyCommand(fw); - buddyCmd->init(buddyLabel, QStringLiteral("buddy"), QVariant(newWidgetName.toUtf8())); + buddyCmd->init(buddyLabel, u"buddy"_s, QVariant(newWidgetName.toUtf8())); us->push(buddyCmd); } us->endMacro(); @@ -341,14 +317,13 @@ bool MorphWidgetCommand::init(QWidget *widget, const QString &newClassName) // If the target has a container extension, we add enough new pages to take // up the children of the before widget if (QDesignerContainerExtension* c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_afterWidget)) { - if (const int pageCount = childContainers(core, m_beforeWidget).size()) { - const QString qWidget = QStringLiteral("QWidget"); + if (const auto pageCount = childContainers(core, m_beforeWidget).size()) { const QString containerName = m_afterWidget->objectName(); - for (int i = 0; i < pageCount; i++) { + for (qsizetype i = 0; i < pageCount; ++i) { QString name = containerName; - name += QStringLiteral("Page"); + name += "Page"_L1; name += QString::number(i + 1); - QWidget *page = core->widgetFactory()->createWidget(qWidget); + QWidget *page = core->widgetFactory()->createWidget(u"QWidget"_s); page->setObjectName(name); fw->ensureUniqueObjectName(page); c->addWidget(page); @@ -360,12 +335,11 @@ bool MorphWidgetCommand::init(QWidget *widget, const QString &newClassName) // Copy over applicable properties const QDesignerPropertySheetExtension *beforeSheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), widget); QDesignerPropertySheetExtension *afterSheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), m_afterWidget); - const QString objectNameProperty = QStringLiteral("objectName"); const int count = beforeSheet->count(); for (int i = 0; i < count; i++) if (beforeSheet->isVisible(i) && beforeSheet->isChanged(i)) { const QString name = beforeSheet->propertyName(i); - if (name != objectNameProperty) { + if (name != "objectName"_L1) { const int afterIndex = afterSheet->indexOf(name); if (afterIndex != -1 && afterSheet->isVisible(afterIndex) && afterSheet->propertyGroup(afterIndex) == beforeSheet->propertyGroup(i)) { afterSheet->setProperty(i, beforeSheet->property(i)); @@ -406,8 +380,8 @@ void MorphWidgetCommand::morph(QWidget *before, QWidget *after) QWidgetList beforeChildContainers = childContainers(fw->core(), before); QWidgetList afterChildContainers = childContainers(fw->core(), after); Q_ASSERT(beforeChildContainers.size() == afterChildContainers.size()); - const int childContainerCount = beforeChildContainers.size(); - for (int i = 0; i < childContainerCount; i++) { + const auto childContainerCount = beforeChildContainers.size(); + for (qsizetype i = 0; i < childContainerCount; ++i) { QWidget *beforeChildContainer = beforeChildContainers.at(i); QWidget *afterChildContainer = afterChildContainers.at(i); if (QLayout *childLayout = beforeChildContainer->layout()) { @@ -507,11 +481,11 @@ bool MorphWidgetCommand::canMorph(QDesignerFormWindowInterface *fw, QWidget *w, return true; // Check children. All child containers must be non-laid-out or have managed layouts const QWidgetList pages = childContainers(core, w); - const int pageCount = pages.size(); + const auto pageCount = pages.size(); if (ptrToChildContainerCount) *ptrToChildContainerCount = pageCount; if (pageCount) { - for (int i = 0; i < pageCount; i++) + for (qsizetype i = 0; i < pageCount; ++i) if (QLayout *cl = pages.at(i)->layout()) if (!core->metaDataBase()->item(cl)) return false; @@ -598,10 +572,8 @@ bool MorphMenu::populateMenu(QWidget *w, QDesignerFormWindowInterface *fw) } // Add actions - const QStringList::const_iterator cend = c.constEnd(); - for (QStringList::const_iterator it = c.constBegin(); it != cend; ++it) { - if (*it != oldClassName) { - const QString className = *it; + for (const auto &className : c) { + if (className != oldClassName) { m_menu->addAction(className, this, [this, className] { this->slotMorph(className); }); } diff --git a/src/designer/src/lib/shared/morphmenu_p.h b/src/designer/src/lib/shared/morphmenu_p.h index eba1bdf3a..dbd94f6ea 100644 --- a/src/designer/src/lib/shared/morphmenu_p.h +++ b/src/designer/src/lib/shared/morphmenu_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/newactiondialog.cpp b/src/designer/src/lib/shared/newactiondialog.cpp index d5380bfcb..5bbb5d725 100644 --- a/src/designer/src/lib/shared/newactiondialog.cpp +++ b/src/designer/src/lib/shared/newactiondialog.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 "newactiondialog_p.h" #include "ui_newactiondialog.h" @@ -37,10 +12,13 @@ #include <QtDesigner/abstractformwindow.h> #include <QtDesigner/abstractformeditor.h> +#include <QtCore/QMetaEnum> #include <QtWidgets/qpushbutton.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { // Returns a combination of ChangeMask flags unsigned ActionData::compare(const ActionData &rhs) const @@ -58,13 +36,15 @@ unsigned ActionData::compare(const ActionData &rhs) const rc |= CheckableChanged; if (keysequence != rhs.keysequence) rc |= KeysequenceChanged ; + if (menuRole.value != rhs.menuRole.value) + rc |= MenuRoleChanged ; return rc; } // -------------------- NewActionDialog NewActionDialog::NewActionDialog(ActionEditor *parent) : QDialog(parent, Qt::Sheet), - m_ui(new Ui::NewActionDialog), + m_ui(new QT_PREPEND_NAMESPACE(qdesigner_internal)::Ui::NewActionDialog), m_actionEditor(parent), m_autoUpdateObjectName(true) { @@ -72,12 +52,36 @@ NewActionDialog::NewActionDialog(ActionEditor *parent) : m_ui->tooltipEditor->setTextPropertyValidationMode(ValidationRichText); connect(m_ui->toolTipToolButton, &QAbstractButton::clicked, this, &NewActionDialog::slotEditToolTip); + connect(m_ui->editActionText, &QLineEdit::textEdited, + this, &NewActionDialog::onEditActionTextTextEdited); + connect(m_ui->editObjectName, &QLineEdit::textEdited, + this, &NewActionDialog::onEditObjectNameTextEdited); - m_ui->keysequenceResetToolButton->setIcon(createIconSet(QStringLiteral("resetproperty.png"))); + m_ui->keysequenceResetToolButton->setIcon(createIconSet("resetproperty.png"_L1)); connect(m_ui->keysequenceResetToolButton, &QAbstractButton::clicked, this, &NewActionDialog::slotResetKeySequence); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + // Clear XDG icon once a theme enum is chosen and vv. + auto *iconThemeEnumEditor = m_ui->iconThemeEnumEditor; + auto *iconThemeEditor = m_ui->iconThemeEditor; + connect(iconThemeEnumEditor, &IconThemeEnumEditor::edited, + this, [iconThemeEditor](int i) { + if (i >= 0) + iconThemeEditor->reset(); + }); + connect(iconThemeEditor, &IconThemeEditor::edited, + this, [iconThemeEnumEditor](const QString &t) { + if (!t.isEmpty()) + iconThemeEnumEditor->reset(); + }); + + const auto menuRoles = QMetaEnum::fromType<QAction::MenuRole>(); + for (int i = 0; i < menuRoles.keyCount(); i++) { + const auto key = menuRoles.key(i); + const auto value = menuRoles.value(i); + m_ui->menuRole->addItem(QLatin1StringView(key), value); + } + focusText(); updateButtons(); @@ -121,6 +125,11 @@ void NewActionDialog::focusCheckable() m_ui->checkableCheckBox->setFocus(); } +void NewActionDialog::focusMenuRole() +{ + m_ui->menuRole->setFocus(); +} + QString NewActionDialog::actionText() const { return m_ui->editActionText->text(); @@ -138,9 +147,12 @@ ActionData NewActionDialog::actionData() const rc.name = actionName(); rc.toolTip = m_ui->tooltipEditor->text(); rc.icon = m_ui->iconSelector->icon(); - rc.icon.setTheme(m_ui->iconThemeEditor->theme()); + const int themeEnum = m_ui->iconThemeEnumEditor->themeEnum(); + rc.icon.setThemeEnum(themeEnum); + rc.icon.setTheme(themeEnum == -1 ? m_ui->iconThemeEditor->theme() : QString{}); rc.checkable = m_ui->checkableCheckBox->checkState() == Qt::Checked; rc.keysequence = PropertySheetKeySequenceValue(m_ui->keySequenceEdit->keySequence()); + rc.menuRole.value = m_ui->menuRole->currentData().toInt(); return rc; } @@ -149,17 +161,19 @@ void NewActionDialog::setActionData(const ActionData &d) m_ui->editActionText->setText(d.text); m_ui->editObjectName->setText(d.name); m_ui->iconSelector->setIcon(d.icon.unthemed()); + m_ui->iconThemeEnumEditor->setThemeEnum(d.icon.themeEnum()); m_ui->iconThemeEditor->setTheme(d.icon.theme()); m_ui->tooltipEditor->setText(d.toolTip); m_ui->keySequenceEdit->setKeySequence(d.keysequence.value()); m_ui->checkableCheckBox->setCheckState(d.checkable ? Qt::Checked : Qt::Unchecked); + m_ui->menuRole->setCurrentIndex(m_ui->menuRole->findData(d.menuRole.value)); // Suppress updating of the object name from the text for existing actions. m_autoUpdateObjectName = d.name.isEmpty(); updateButtons(); } -void NewActionDialog::on_editActionText_textEdited(const QString &text) +void NewActionDialog::onEditActionTextTextEdited(const QString &text) { if (m_autoUpdateObjectName) m_ui->editObjectName->setText(ActionEditor::actionTextToName(text)); @@ -167,7 +181,7 @@ void NewActionDialog::on_editActionText_textEdited(const QString &text) updateButtons(); } -void NewActionDialog::on_editObjectName_textEdited(const QString&) +void NewActionDialog::onEditObjectNameTextEdited(const QString&) { updateButtons(); m_autoUpdateObjectName = false; diff --git a/src/designer/src/lib/shared/newactiondialog.ui b/src/designer/src/lib/shared/newactiondialog.ui index 005e6dc2d..7fd99842b 100644 --- a/src/designer/src/lib/shared/newactiondialog.ui +++ b/src/designer/src/lib/shared/newactiondialog.ui @@ -1,40 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <comment>********************************************************************* -** -** 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$ -** -*********************************************************************</comment> + <comment> +* Copyright (C) 2016 The Qt Company Ltd. +* SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +</comment> <class>qdesigner_internal::NewActionDialog</class> <widget class="QDialog" name="qdesigner_internal::NewActionDialog"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>366</width> - <height>270</height> + <width>381</width> + <height>291</height> </rect> </property> <property name="windowTitle"> @@ -110,20 +87,20 @@ </item> </layout> </item> - <item row="3" column="0"> + <item row="4" column="0"> <widget class="QLabel" name="iconThemeLabel"> <property name="text"> - <string>Icon th&eme:</string> + <string>Icon &XDG theme:</string> </property> <property name="buddy"> <cstring>iconThemeEditor</cstring> </property> </widget> </item> - <item row="3" column="1"> + <item row="4" column="1"> <widget class="qdesigner_internal::IconThemeEditor" name="iconThemeEditor" native="true"/> </item> - <item row="4" column="0"> + <item row="5" column="0"> <widget class="QLabel" name="iconLabel"> <property name="text"> <string>&Icon:</string> @@ -133,7 +110,7 @@ </property> </widget> </item> - <item row="4" column="1"> + <item row="5" column="1"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="qdesigner_internal::IconSelector" name="iconSelector" native="true"/> @@ -153,14 +130,14 @@ </item> </layout> </item> - <item row="5" column="1"> + <item row="6" column="1"> <widget class="QCheckBox" name="checkableCheckBox"> <property name="text"> <string/> </property> </widget> </item> - <item row="5" column="0"> + <item row="6" column="0"> <widget class="QLabel" name="checkableLabel"> <property name="text"> <string>&Checkable:</string> @@ -170,7 +147,7 @@ </property> </widget> </item> - <item row="6" column="0"> + <item row="7" column="0"> <widget class="QLabel" name="shortcutLabel"> <property name="text"> <string>&Shortcut:</string> @@ -180,10 +157,10 @@ </property> </widget> </item> - <item row="6" column="1"> + <item row="7" column="1"> <layout class="QHBoxLayout" name="keysequenceLayout"> <item> - <widget class="QKeySequenceEdit" name="keySequenceEdit" native="true"> + <widget class="QKeySequenceEdit" name="keySequenceEdit"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> <horstretch>0</horstretch> @@ -201,6 +178,32 @@ </item> </layout> </item> + <item row="8" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>&Menu role:</string> + </property> + <property name="buddy"> + <cstring>menuRole</cstring> + </property> + </widget> + </item> + <item row="8" column="1"> + <widget class="QComboBox" name="menuRole"/> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="iconThemeEnumLabel"> + <property name="text"> + <string>Icon &theme:</string> + </property> + <property name="buddy"> + <cstring>iconThemeEnumEditor</cstring> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="qdesigner_internal::IconThemeEnumEditor" name="iconThemeEnumEditor" native="true"/> + </item> </layout> </item> <item> @@ -254,6 +257,12 @@ <header>iconselector_p.h</header> <container>1</container> </customwidget> + <customwidget> + <class>qdesigner_internal::IconThemeEnumEditor</class> + <extends>QWidget</extends> + <header>iconselector_p.h</header> + <container>1</container> + </customwidget> </customwidgets> <tabstops> <tabstop>editActionText</tabstop> diff --git a/src/designer/src/lib/shared/newactiondialog_p.h b/src/designer/src/lib/shared/newactiondialog_p.h index f6e3b1dd7..de42d16f0 100644 --- a/src/designer/src/lib/shared/newactiondialog_p.h +++ b/src/designer/src/lib/shared/newactiondialog_p.h @@ -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 #ifndef NEWACTIONDIALOG_P_H #define NEWACTIONDIALOG_P_H @@ -44,6 +19,7 @@ #include <QtWidgets/qdialog.h> #include <QtGui/qkeysequence.h> +#include <QtCore/qcompare.h> QT_BEGIN_NAMESPACE @@ -59,7 +35,8 @@ struct ActionData { enum ChangeMask { TextChanged = 0x1, NameChanged = 0x2, ToolTipChanged = 0x4, - IconChanged = 0x8, CheckableChanged = 0x10, KeysequenceChanged = 0x20 + IconChanged = 0x8, CheckableChanged = 0x10, KeysequenceChanged = 0x20, + MenuRoleChanged = 0x40 }; // Returns a combination of ChangeMask flags @@ -71,10 +48,14 @@ struct ActionData { PropertySheetIconValue icon; bool checkable{false}; PropertySheetKeySequenceValue keysequence; -}; + PropertySheetFlagValue menuRole; -inline bool operator==(const ActionData &a1, const ActionData &a2) { return a1.compare(a2) == 0u; } -inline bool operator!=(const ActionData &a1, const ActionData &a2) { return a1.compare(a2) != 0u; } + friend bool comparesEqual(const ActionData &lhs, const ActionData &rhs) noexcept + { + return lhs.compare(rhs) == 0; + } + Q_DECLARE_EQUALITY_COMPARABLE(ActionData) +}; class NewActionDialog: public QDialog { @@ -95,10 +76,12 @@ public slots: void focusTooltip(); void focusShortcut(); void focusCheckable(); + void focusMenuRole(); private slots: - void on_editActionText_textEdited(const QString &text); - void on_editObjectName_textEdited(const QString &text); + void onEditActionTextTextEdited(const QString &text); + void onEditObjectNameTextEdited(const QString &text); + void slotEditToolTip(); void slotResetKeySequence(); diff --git a/src/designer/src/lib/shared/newformwidget.cpp b/src/designer/src/lib/shared/newformwidget.cpp index c4b659ed6..383b3fc5a 100644 --- a/src/designer/src/lib/shared/newformwidget.cpp +++ b/src/designer/src/lib/shared/newformwidget.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 "newformwidget_p.h" #include "ui_newformwidget.h" @@ -57,6 +32,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + enum { profileComboIndexOffset = 1 }; enum { debugNewFormWidget = 0 }; @@ -67,14 +44,14 @@ enum NewForm_CustomRole { ClassNameRole = Qt::UserRole + 101 }; -static const char *newFormObjectNameC = "Form"; +static constexpr auto newFormObjectNameC = "Form"_L1; // Create a form name for an arbitrary class. If it is Qt, qtify it, // else return "Form". static QString formName(const QString &className) { - if (!className.startsWith(QLatin1Char('Q'))) - return QLatin1String(newFormObjectNameC); + if (!className.startsWith(u'Q')) + return newFormObjectNameC; QString rc = className; rc.remove(0, 1); return rc; @@ -125,7 +102,7 @@ static const struct TemplateSize templateSizes[] = NewFormWidget::NewFormWidget(QDesignerFormEditorInterface *core, QWidget *parentWidget) : QDesignerNewFormWidgetInterface(parentWidget), m_core(core), - m_ui(new Ui::NewFormWidget), + m_ui(new QT_PREPEND_NAMESPACE(qdesigner_internal)::Ui::NewFormWidget), m_currentItem(nullptr), m_acceptedItem(nullptr) { @@ -139,14 +116,22 @@ NewFormWidget::NewFormWidget(QDesignerFormEditorInterface *core, QWidget *parent m_ui->treeWidget->header()->hide(); m_ui->treeWidget->header()->setStretchLastSection(true); m_ui->lblPreview->setBackgroundRole(QPalette::Base); + + connect(m_ui->treeWidget, &QTreeWidget::itemActivated, + this, &NewFormWidget::treeWidgetItemActivated); + connect(m_ui->treeWidget, &QTreeWidget::currentItemChanged, + this, &NewFormWidget::treeWidgetCurrentItemChanged); + connect(m_ui->treeWidget, &QTreeWidget::itemPressed, + this, &NewFormWidget::treeWidgetItemPressed); + QDesignerSharedSettings settings(m_core); - QString uiExtension = QStringLiteral("ui"); - QString templatePath = QStringLiteral(":/qt-project.org/designer/templates/forms"); + QString uiExtension = u"ui"_s; + QString templatePath = u":/qt-project.org/designer/templates/forms"_s; QDesignerLanguageExtension *lang = qt_extension<QDesignerLanguageExtension *>(core->extensionManager(), core); if (lang) { - templatePath = QStringLiteral(":/templates/forms"); + templatePath = u":/templates/forms"_s; uiExtension = lang->uiExtension(); } @@ -156,9 +141,8 @@ NewFormWidget::NewFormWidget(QDesignerFormEditorInterface *core, QWidget *parent loadFrom(templatePath, true, uiExtension, formTemplate, selectedItem); // Additional template paths const QStringList formTemplatePaths = settings.formTemplatePaths(); - const QStringList::const_iterator ftcend = formTemplatePaths.constEnd(); - for (QStringList::const_iterator it = formTemplatePaths.constBegin(); it != ftcend; ++it) - loadFrom(*it, false, uiExtension, formTemplate, selectedItem); + for (const auto &ftp : formTemplatePaths) + loadFrom(ftp, false, uiExtension, formTemplate, selectedItem); // Widgets/custom widgets if (!lang) { @@ -189,7 +173,7 @@ NewFormWidget::NewFormWidget(QDesignerFormEditorInterface *core, QWidget *parent if (m_deviceProfiles.isEmpty()) { m_ui->profileComboBox->setEnabled(false); } else { - for (const auto &deviceProfile : qAsConst(m_deviceProfiles)) + for (const auto &deviceProfile : std::as_const(m_deviceProfiles)) m_ui->profileComboBox->addItem(deviceProfile.name()); const int ci = settings.currentDeviceProfileIndex(); if (ci >= 0) @@ -215,7 +199,7 @@ NewFormWidget::~NewFormWidget() delete m_ui; } -void NewFormWidget::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *) +void NewFormWidget::treeWidgetCurrentItemChanged(QTreeWidgetItem *current) { if (debugNewFormWidget) qDebug() << Q_FUNC_INFO << current; @@ -246,7 +230,7 @@ bool NewFormWidget::showCurrentItemPixmap() return rc; } -void NewFormWidget::on_treeWidget_itemActivated(QTreeWidgetItem *item) +void NewFormWidget::treeWidgetItemActivated(QTreeWidgetItem *item) { if (debugNewFormWidget) qDebug() << Q_FUNC_INFO << item; @@ -259,7 +243,7 @@ QPixmap NewFormWidget::formPreviewPixmap(const QTreeWidgetItem *item) { // Cache pixmaps per item/device profile const ItemPixmapCacheKey cacheKey(item, profileComboIndex()); - ItemPixmapCache::iterator it = m_itemPixmapCache.find(cacheKey); + auto it = m_itemPixmapCache.find(cacheKey); if (it == m_itemPixmapCache.end()) { // file or string? const QVariant fileName = item->data(0, TemplateNameRole); @@ -404,13 +388,13 @@ void NewFormWidget::loadFrom(const QString &path, bool resourceFile, const QStri return; // Iterate through the directory and add the templates - const QFileInfoList list = dir.entryInfoList(QStringList(QStringLiteral("*.") + uiExtension), + const QFileInfoList list = dir.entryInfoList(QStringList{"*."_L1 + uiExtension}, QDir::Files); if (list.isEmpty()) return; - const QChar separator = resourceFile ? QChar(QLatin1Char('/')) + const QChar separator = resourceFile ? QChar(u'/') : QDir::separator(); QTreeWidgetItem *root = new QTreeWidgetItem(m_ui->treeWidget); root->setFlags(root->flags() & ~Qt::ItemIsSelectable); @@ -426,22 +410,19 @@ void NewFormWidget::loadFrom(const QString &path, bool resourceFile, const QStri visiblePath = QDir::toNativeSeparators(visiblePath); } - const QChar underscore = QLatin1Char('_'); - const QChar blank = QLatin1Char(' '); - root->setText(0, visiblePath.replace(underscore, blank)); + root->setText(0, visiblePath.replace(u'_', u' ')); root->setToolTip(0, path); - const QFileInfoList::const_iterator lcend = list.constEnd(); - for (QFileInfoList::const_iterator it = list.constBegin(); it != lcend; ++it) { - if (!it->isFile()) + for (const auto &fi : list) { + if (!fi.isFile()) continue; QTreeWidgetItem *item = new QTreeWidgetItem(root); - const QString text = it->baseName().replace(underscore, blank); + const QString text = fi.baseName().replace(u'_', u' '); if (selectedItemFound == nullptr && text == selectedItem) selectedItemFound = item; item->setText(0, text); - item->setData(0, TemplateNameRole, it->absoluteFilePath()); + item->setData(0, TemplateNameRole, fi.absoluteFilePath()); } } @@ -453,18 +434,16 @@ void NewFormWidget::loadFrom(const QString &title, const QStringList &nameList, QTreeWidgetItem *root = new QTreeWidgetItem(m_ui->treeWidget); root->setFlags(root->flags() & ~Qt::ItemIsSelectable); root->setText(0, title); - const QStringList::const_iterator cend = nameList.constEnd(); - for (QStringList::const_iterator it = nameList.constBegin(); it != cend; ++it) { - const QString text = *it; + for (const auto &text : nameList) { QTreeWidgetItem *item = new QTreeWidgetItem(root); item->setText(0, text); if (selectedItemFound == nullptr && text == selectedItem) selectedItemFound = item; - item->setData(0, ClassNameRole, *it); + item->setData(0, ClassNameRole, text); } } -void NewFormWidget::on_treeWidget_itemPressed(QTreeWidgetItem *item) +void NewFormWidget::treeWidgetItemPressed(QTreeWidgetItem *item) { if (item && !item->parent()) item->setExpanded(!item->isExpanded()); @@ -506,7 +485,7 @@ QString NewFormWidget::itemToTemplate(const QTreeWidgetItem *item, QString *erro const QFileInfo fiBase(fileName); QString sizeFileName; QTextStream(&sizeFileName) << fiBase.path() << QDir::separator() - << size.width() << QLatin1Char('x') << size.height() << QDir::separator() + << size.width() << 'x' << size.height() << QDir::separator() << fiBase.fileName(); if (QFileInfo(sizeFileName).isFile()) return readAll(sizeFileName, errorMessage); diff --git a/src/designer/src/lib/shared/newformwidget.ui b/src/designer/src/lib/shared/newformwidget.ui index c45e2c00a..8cf6f638b 100644 --- a/src/designer/src/lib/shared/newformwidget.ui +++ b/src/designer/src/lib/shared/newformwidget.ui @@ -1,32 +1,8 @@ -<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <comment>********************************************************************* -** -** 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$ -** -*********************************************************************</comment> +<comment> +* Copyright (C) 2016 The Qt Company Ltd. +* SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +</comment> <class>qdesigner_internal::NewFormWidget</class> <widget class="QWidget" name="qdesigner_internal::NewFormWidget"> <property name="geometry"> diff --git a/src/designer/src/lib/shared/newformwidget_p.h b/src/designer/src/lib/shared/newformwidget_p.h index c7a5e2a08..d9acbd2a3 100644 --- a/src/designer/src/lib/shared/newformwidget_p.h +++ b/src/designer/src/lib/shared/newformwidget_p.h @@ -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 #ifndef NEWFORMWIDGET_H #define NEWFORMWIDGET_H @@ -86,9 +61,9 @@ public: const qdesigner_internal::DeviceProfile &dp); private slots: - void on_treeWidget_itemActivated(QTreeWidgetItem *item); - void on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *); - void on_treeWidget_itemPressed(QTreeWidgetItem *item); + void treeWidgetItemActivated(QTreeWidgetItem *item); + void treeWidgetCurrentItemChanged(QTreeWidgetItem *current); + void treeWidgetItemPressed(QTreeWidgetItem *item); void slotDeviceProfileIndexChanged(int idx); private: @@ -112,7 +87,7 @@ private: bool showCurrentItemPixmap(); // Pixmap cache (item, profile combo index) - using ItemPixmapCacheKey = QPair<const QTreeWidgetItem *, int>; + using ItemPixmapCacheKey = std::pair<const QTreeWidgetItem *, int>; using ItemPixmapCache = QMap<ItemPixmapCacheKey, QPixmap>; ItemPixmapCache m_itemPixmapCache; diff --git a/src/designer/src/lib/shared/orderdialog.cpp b/src/designer/src/lib/shared/orderdialog.cpp index 51389a974..faa13501a 100644 --- a/src/designer/src/lib/shared/orderdialog.cpp +++ b/src/designer/src/lib/shared/orderdialog.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 "orderdialog_p.h" #include "iconloader_p.h" @@ -38,19 +13,20 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // OrderDialog: Used to reorder the pages of QStackedWidget and QToolBox. // Provides up and down buttons as well as DnD via QAbstractItemView::InternalMove mode namespace qdesigner_internal { OrderDialog::OrderDialog(QWidget *parent) : QDialog(parent), - m_ui(new Ui::OrderDialog), + m_ui(new QT_PREPEND_NAMESPACE(qdesigner_internal)::Ui::OrderDialog), m_format(PageOrderFormat) { m_ui->setupUi(this); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - m_ui->upButton->setIcon(createIconSet(QString::fromUtf8("up.png"))); - m_ui->downButton->setIcon(createIconSet(QString::fromUtf8("down.png"))); + m_ui->upButton->setIcon(createIconSet("up.png"_L1)); + m_ui->downButton->setIcon(createIconSet("down.png"_L1)); m_ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked, this, &OrderDialog::slotReset); @@ -59,6 +35,11 @@ OrderDialog::OrderDialog(QWidget *parent) : connect(m_ui->pageList->model(), &QAbstractItemModel::rowsRemoved, this, &OrderDialog::slotEnableButtonsAfterDnD); + connect(m_ui->upButton, &QAbstractButton::clicked, this, &OrderDialog::upButtonClicked); + connect(m_ui->downButton, &QAbstractButton::clicked, this, &OrderDialog::downButtonClicked); + connect(m_ui->pageList, &QListWidget::currentRowChanged, + this, &OrderDialog::pageListCurrentRowChanged); + m_ui->upButton->setEnabled(false); m_ui->downButton->setEnabled(false); } @@ -79,17 +60,16 @@ void OrderDialog::setPageList(const QWidgetList &pages) // The old index is set as user data on the item instead of the QWidget* // because DnD is enabled which requires the user data to serializable m_orderMap.clear(); - const int count = pages.count(); - for (int i=0; i < count; ++i) - m_orderMap.insert(i, pages.at(i)); + const qsizetype count = pages.size(); + for (qsizetype i = 0; i < count; ++i) + m_orderMap.insert(int(i), pages.at(i)); buildList(); } void OrderDialog::buildList() { m_ui->pageList->clear(); - const OrderMap::const_iterator cend = m_orderMap.constEnd(); - for (OrderMap::const_iterator it = m_orderMap.constBegin(); it != cend; ++it) { + for (auto it = m_orderMap.cbegin(), cend = m_orderMap.cend(); it != cend; ++it) { QListWidgetItem *item = new QListWidgetItem(); const int index = it.key(); switch (m_format) { @@ -124,7 +104,7 @@ QWidgetList OrderDialog::pageList() const return rc; } -void OrderDialog::on_upButton_clicked() +void OrderDialog::upButtonClicked() { const int row = m_ui->pageList->currentRow(); if (row <= 0) @@ -134,7 +114,7 @@ void OrderDialog::on_upButton_clicked() m_ui->pageList->setCurrentRow(row - 1); } -void OrderDialog::on_downButton_clicked() +void OrderDialog::downButtonClicked() { const int row = m_ui->pageList->currentRow(); if (row == -1 || row == m_ui->pageList->count() - 1) @@ -149,7 +129,7 @@ void OrderDialog::slotEnableButtonsAfterDnD() enableButtons(m_ui->pageList->currentRow()); } -void OrderDialog::on_pageList_currentRowChanged(int r) +void OrderDialog::pageListCurrentRowChanged(int r) { enableButtons(r); } diff --git a/src/designer/src/lib/shared/orderdialog.ui b/src/designer/src/lib/shared/orderdialog.ui index d56cb65cd..0af976dfe 100644 --- a/src/designer/src/lib/shared/orderdialog.ui +++ b/src/designer/src/lib/shared/orderdialog.ui @@ -1,31 +1,8 @@ <ui version="4.0" > - <comment>********************************************************************* -** -** 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$ -** -*********************************************************************</comment> +<comment> +* Copyright (C) 2016 The Qt Company Ltd. +* SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +</comment> <class>qdesigner_internal::OrderDialog</class> <widget class="QDialog" name="qdesigner_internal::OrderDialog" > <property name="geometry" > diff --git a/src/designer/src/lib/shared/orderdialog_p.h b/src/designer/src/lib/shared/orderdialog_p.h index 5c28be6e5..2fb506f07 100644 --- a/src/designer/src/lib/shared/orderdialog_p.h +++ b/src/designer/src/lib/shared/orderdialog_p.h @@ -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 // // W A R N I N G @@ -78,9 +53,9 @@ public: Format format() const { return m_format; } private slots: - void on_upButton_clicked(); - void on_downButton_clicked(); - void on_pageList_currentRowChanged(int row); + void upButtonClicked(); + void downButtonClicked(); + void pageListCurrentRowChanged(int row); void slotEnableButtonsAfterDnD(); void slotReset(); @@ -88,8 +63,7 @@ private: void buildList(); void enableButtons(int r); - typedef QMap<int, QWidget*> OrderMap; - OrderMap m_orderMap; + QMap<int, QWidget *> m_orderMap; Ui::OrderDialog* m_ui; Format m_format; }; diff --git a/src/designer/src/lib/shared/plaintexteditor.cpp b/src/designer/src/lib/shared/plaintexteditor.cpp index 91f842f62..ad6708c9f 100644 --- a/src/designer/src/lib/shared/plaintexteditor.cpp +++ b/src/designer/src/lib/shared/plaintexteditor.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 "plaintexteditor_p.h" @@ -38,9 +13,10 @@ QT_BEGIN_NAMESPACE -static const char *PlainTextDialogC = "PlainTextDialog"; -static const char *Geometry = "Geometry"; +using namespace Qt::StringLiterals; +static constexpr auto PlainTextDialogC = "PlainTextDialog"_L1; +static constexpr auto PlainTextEditorGeometryC = "Geometry"_L1; namespace qdesigner_internal { @@ -50,7 +26,6 @@ PlainTextEditorDialog::PlainTextEditorDialog(QDesignerFormEditorInterface *core, m_core(core) { setWindowTitle(tr("Edit text")); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); QVBoxLayout *vlayout = new QVBoxLayout(this); vlayout->addWidget(m_editor); @@ -63,10 +38,10 @@ PlainTextEditorDialog::PlainTextEditorDialog(QDesignerFormEditorInterface *core, vlayout->addWidget(buttonBox); QDesignerSettingsInterface *settings = core->settingsManager(); - settings->beginGroup(QLatin1String(PlainTextDialogC)); + settings->beginGroup(PlainTextDialogC); - if (settings->contains(QLatin1String(Geometry))) - restoreGeometry(settings->value(QLatin1String(Geometry)).toByteArray()); + if (settings->contains(PlainTextEditorGeometryC)) + restoreGeometry(settings->value(PlainTextEditorGeometryC).toByteArray()); settings->endGroup(); } @@ -74,9 +49,9 @@ PlainTextEditorDialog::PlainTextEditorDialog(QDesignerFormEditorInterface *core, PlainTextEditorDialog::~PlainTextEditorDialog() { QDesignerSettingsInterface *settings = m_core->settingsManager(); - settings->beginGroup(QLatin1String(PlainTextDialogC)); + settings->beginGroup(PlainTextDialogC); - settings->setValue(QLatin1String(Geometry), saveGeometry()); + settings->setValue(PlainTextEditorGeometryC, saveGeometry()); settings->endGroup(); } diff --git a/src/designer/src/lib/shared/plaintexteditor_p.h b/src/designer/src/lib/shared/plaintexteditor_p.h index b628b8c0d..988a5f5cb 100644 --- a/src/designer/src/lib/shared/plaintexteditor_p.h +++ b/src/designer/src/lib/shared/plaintexteditor_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/plugindialog.cpp b/src/designer/src/lib/shared/plugindialog.cpp index de96d55d2..fb4ec4e6a 100644 --- a/src/designer/src/lib/shared/plugindialog.cpp +++ b/src/designer/src/lib/shared/plugindialog.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 "plugindialog_p.h" @@ -47,11 +22,14 @@ # include <QtGui/QClipboard> #endif +#include <QtCore/qdir.h> #include <QtCore/qfileinfo.h> #include <QtCore/qpluginloader.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + enum { ErrorItemRole = Qt::UserRole + 1 }; namespace qdesigner_internal { @@ -109,7 +87,7 @@ void PluginDialog::populateTreeWidget() QPluginLoader loader(fileName); const QFileInfo fileInfo(fileName); - QTreeWidgetItem *pluginItem = setPluginItem(topLevelItem, fileInfo.fileName(), boldFont); + QTreeWidgetItem *pluginItem = setPluginItem(topLevelItem, fileInfo, boldFont); if (QObject *plugin = loader.instance()) { if (const QDesignerCustomWidgetCollectionInterface *c = qobject_cast<QDesignerCustomWidgetCollectionInterface*>(plugin)) { @@ -130,10 +108,10 @@ void PluginDialog::populateTreeWidget() const QFont boldFont = topLevelItem->font(0); for (const QString &plugin : notLoadedPlugins) { const QString failureReason = pluginManager->failureReason(plugin); - const QString htmlFailureReason = QLatin1String("<html><head/><body><p>") + const QString htmlFailureReason = "<html><head/><body><p>"_L1 + failureReason.toHtmlEscaped() - + QLatin1String("</p></body></html>"); - QTreeWidgetItem *pluginItem = setPluginItem(topLevelItem, plugin, boldFont); + + "</p></body></html>"_L1; + QTreeWidgetItem *pluginItem = setPluginItem(topLevelItem, QFileInfo(plugin), boldFont); auto errorItem = setItem(pluginItem, failureReason, htmlFailureReason, QString(), QIcon()); errorItem->setData(0, ErrorItemRole, QVariant(true)); @@ -141,10 +119,10 @@ void PluginDialog::populateTreeWidget() } if (ui.treeWidget->topLevelItemCount() == 0) { - ui.label->setText(tr("Qt Designer couldn't find any plugins")); + ui.label->setText(tr("Qt Widgets Designer couldn't find any plugins")); ui.treeWidget->hide(); } else { - ui.label->setText(tr("Qt Designer found the following plugins")); + ui.label->setText(tr("Qt Widgets Designer found the following plugins")); } } @@ -163,11 +141,15 @@ QTreeWidgetItem* PluginDialog::setTopLevelItem(const QString &itemName) } QTreeWidgetItem* PluginDialog::setPluginItem(QTreeWidgetItem *topLevelItem, - const QString &itemName, const QFont &font) + const QFileInfo &file, const QFont &font) { QTreeWidgetItem *pluginItem = new QTreeWidgetItem(topLevelItem); + QString toolTip = QDir::toNativeSeparators(file.absoluteFilePath()); + if (file.exists()) + toolTip += u'\n' + file.lastModified().toString(); pluginItem->setFont(0, font); - pluginItem->setText(0, itemName); + pluginItem->setText(0, file.fileName()); + pluginItem->setToolTip(0, toolTip); pluginItem->setExpanded(true); pluginItem->setIcon(0, style()->standardPixmap(QStyle::SP_DirOpenIcon)); diff --git a/src/designer/src/lib/shared/plugindialog.ui b/src/designer/src/lib/shared/plugindialog.ui index a05199342..39cf22c8b 100644 --- a/src/designer/src/lib/shared/plugindialog.ui +++ b/src/designer/src/lib/shared/plugindialog.ui @@ -1,32 +1,8 @@ -<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <comment>********************************************************************* -** -** 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$ -** -*********************************************************************</comment> +<comment> +* Copyright (C) 2016 The Qt Company Ltd. +* SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +</comment> <class>PluginDialog</class> <widget class="QDialog" name="PluginDialog"> <property name="geometry"> diff --git a/src/designer/src/lib/shared/plugindialog_p.h b/src/designer/src/lib/shared/plugindialog_p.h index 939ce68b1..cbdad6019 100644 --- a/src/designer/src/lib/shared/plugindialog_p.h +++ b/src/designer/src/lib/shared/plugindialog_p.h @@ -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 #ifndef PLUGINDIALOG_H #define PLUGINDIALOG_H @@ -44,6 +19,8 @@ QT_BEGIN_NAMESPACE +class QFileInfo; + class QDesignerFormEditorInterface; namespace qdesigner_internal { @@ -62,13 +39,13 @@ private: void populateTreeWidget(); QTreeWidgetItem* setTopLevelItem(const QString &itemName); QTreeWidgetItem* setPluginItem(QTreeWidgetItem *topLevelItem, - const QString &itemName, const QFont &font); + const QFileInfo &file, const QFont &font); QTreeWidgetItem *setItem(QTreeWidgetItem *pluginItem, const QString &name, const QString &toolTip, const QString &whatsThis, const QIcon &icon); QDesignerFormEditorInterface *m_core; - Ui::PluginDialog ui; + QT_PREPEND_NAMESPACE(Ui)::PluginDialog ui; QIcon interfaceIcon; QIcon featureIcon; }; diff --git a/src/designer/src/lib/shared/pluginmanager.cpp b/src/designer/src/lib/shared/pluginmanager.cpp index 6c39f8e88..cc520997c 100644 --- a/src/designer/src/lib/shared/pluginmanager.cpp +++ b/src/designer/src/lib/shared/pluginmanager.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 "pluginmanager_p.h" #include "qdesigner_utils_p.h" @@ -50,21 +25,23 @@ #include <QtCore/qxmlstream.h> -static const char *uiElementC = "ui"; -static const char *languageAttributeC = "language"; -static const char *widgetElementC = "widget"; -static const char *displayNameAttributeC = "displayname"; -static const char *classAttributeC = "class"; -static const char *customwidgetElementC = "customwidget"; -static const char *extendsElementC = "extends"; -static const char *addPageMethodC = "addpagemethod"; -static const char *propertySpecsC = "propertyspecifications"; -static const char *stringPropertySpecC = "stringpropertyspecification"; -static const char propertyToolTipC[] = "tooltip"; -static const char *stringPropertyNameAttrC = "name"; -static const char *stringPropertyTypeAttrC = "type"; -static const char *stringPropertyNoTrAttrC = "notr"; -static const char *jambiLanguageC = "jambi"; +using namespace Qt::StringLiterals; + +static constexpr auto uiElementC = "ui"_L1; +static constexpr auto languageAttributeC = "language"_L1; +static constexpr auto widgetElementC = "widget"_L1; +static constexpr auto displayNameAttributeC = "displayname"_L1; +static constexpr auto classAttributeC = "class"_L1; +static constexpr auto customwidgetElementC = "customwidget"_L1; +static constexpr auto extendsElementC = "extends"_L1; +static constexpr auto addPageMethodC = "addpagemethod"_L1; +static constexpr auto propertySpecsC = "propertyspecifications"_L1; +static constexpr auto stringPropertySpecC = "stringpropertyspecification"_L1; +static constexpr auto propertyToolTipC = "tooltip"_L1; +static constexpr auto stringPropertyNameAttrC = "name"_L1; +static constexpr auto stringPropertyTypeAttrC = "type"_L1; +static constexpr auto stringPropertyNoTrAttrC = "notr"_L1; +static constexpr auto jambiLanguageC = "jambi"_L1; enum { debugPluginManager = 0 }; @@ -99,9 +76,9 @@ QStringList QDesignerPluginManager::defaultPluginPaths() const QStringList path_list = QCoreApplication::libraryPaths(); for (const QString &path : path_list) - result.append(path + u"/designer"_qs); + result.append(path + "/designer"_L1); - result.append(qdesigner_internal::dataDirectory() + u"/plugins"_qs); + result.append(qdesigner_internal::dataDirectory() + "/plugins"_L1); return result; } @@ -111,11 +88,11 @@ QStringList QDesignerPluginManager::defaultPluginPaths() static inline QString getDesignerLanguage(QDesignerFormEditorInterface *core) { if (QDesignerLanguageExtension *lang = qt_extension<QDesignerLanguageExtension *>(core->extensionManager(), core)) { - if (lang->uiExtension() == QStringLiteral("jui")) - return QLatin1String(jambiLanguageC); - return QStringLiteral("unknown"); + if (lang->uiExtension() == "jui"_L1) + return jambiLanguageC; + return u"unknown"_s; } - return QStringLiteral("c++"); + return u"c++"_s; } // ---------------- QDesignerCustomWidgetSharedData @@ -123,9 +100,7 @@ static inline QString getDesignerLanguage(QDesignerFormEditorInterface *core) class QDesignerCustomWidgetSharedData : public QSharedData { public: // Type of a string property - using StringPropertyType = QPair<qdesigner_internal::TextPropertyValidationMode, bool>; - using StringPropertyTypeMap = QHash<QString, StringPropertyType>; - using PropertyToolTipMap = QHash<QString, QString>; + using StringPropertyType = std::pair<qdesigner_internal::TextPropertyValidationMode, bool>; explicit QDesignerCustomWidgetSharedData(const QString &thePluginPath) : pluginPath(thePluginPath) {} void clearXML(); @@ -138,8 +113,8 @@ public: QString xmlAddPageMethod; QString xmlExtends; - StringPropertyTypeMap xmlStringPropertyTypeMap; - PropertyToolTipMap propertyToolTipMap; + QHash<QString, StringPropertyType> xmlStringPropertyTypeMap; + QHash<QString, QString> propertyToolTipMap; }; void QDesignerCustomWidgetSharedData::clearXML() @@ -211,7 +186,7 @@ QString QDesignerCustomWidgetData::pluginPath() const bool QDesignerCustomWidgetData::xmlStringPropertyType(const QString &name, StringPropertyType *type) const { - QDesignerCustomWidgetSharedData::StringPropertyTypeMap::const_iterator it = m_d->xmlStringPropertyTypeMap.constFind(name); + const auto it = m_d->xmlStringPropertyTypeMap.constFind(name); if (it == m_d->xmlStringPropertyTypeMap.constEnd()) { *type = StringPropertyType(qdesigner_internal::ValidationRichText, true); return false; @@ -262,19 +237,19 @@ static inline QString msgAttributeMissing(const QString &name) static qdesigner_internal::TextPropertyValidationMode typeStringToType(const QString &v, bool *ok) { *ok = true; - if (v == QStringLiteral("multiline")) + if (v == "multiline"_L1) return qdesigner_internal::ValidationMultiLine; - if (v == QStringLiteral("richtext")) + if (v == "richtext"_L1) return qdesigner_internal::ValidationRichText; - if (v == QStringLiteral("stylesheet")) + if (v == "stylesheet"_L1) return qdesigner_internal::ValidationStyleSheet; - if (v == QStringLiteral("singleline")) + if (v == "singleline"_L1) return qdesigner_internal::ValidationSingleLine; - if (v == QStringLiteral("objectname")) + if (v == "objectname"_L1) return qdesigner_internal::ValidationObjectName; - if (v == QStringLiteral("objectnamescope")) + if (v == "objectnamescope"_L1) return qdesigner_internal::ValidationObjectNameScope; - if (v == QStringLiteral("url")) + if (v == "url"_L1) return qdesigner_internal::ValidationURL; *ok = false; return qdesigner_internal::ValidationRichText; @@ -284,12 +259,12 @@ static bool parsePropertySpecs(QXmlStreamReader &sr, QDesignerCustomWidgetSharedData *data, QString *errorMessage) { - const QString propertySpecs = QLatin1String(propertySpecsC); - const QString stringPropertySpec = QLatin1String(stringPropertySpecC); - const QString propertyToolTip = QLatin1String(propertyToolTipC); - const QString stringPropertyTypeAttr = QLatin1String(stringPropertyTypeAttrC); - const QString stringPropertyNoTrAttr = QLatin1String(stringPropertyNoTrAttrC); - const QString stringPropertyNameAttr = QLatin1String(stringPropertyNameAttrC); + const QString propertySpecs = propertySpecsC; + const QString stringPropertySpec = stringPropertySpecC; + const QString propertyToolTip = propertyToolTipC; + const QString stringPropertyTypeAttr = stringPropertyTypeAttrC; + const QString stringPropertyNoTrAttr = stringPropertyNoTrAttrC; + const QString stringPropertyNameAttr = stringPropertyNameAttrC; while (!sr.atEnd()) { switch(sr.readNext()) { @@ -309,7 +284,7 @@ static bool parsePropertySpecs(QXmlStreamReader &sr, return false; } bool typeOk; - const bool noTr = notrS == QStringLiteral("true") || notrS == QStringLiteral("1"); + const bool noTr = notrS == "true"_L1 || notrS == "1"_L1; QDesignerCustomWidgetSharedData::StringPropertyType v(typeStringToType(type, &typeOk), !noTr); if (!typeOk) { *errorMessage = QDesignerPluginManager::tr("'%1' is not a valid string property specification.").arg(type); @@ -332,6 +307,7 @@ static bool parsePropertySpecs(QXmlStreamReader &sr, case QXmlStreamReader::EndElement: // Outer </stringproperties> if (sr.name() == propertySpecs) return true; + break; default: break; } @@ -355,8 +331,8 @@ QDesignerCustomWidgetData::ParseResult ParseResult rc = ParseOk; // Parse for the (optional) <ui> or the first <widget> element QStringList elements; - elements.push_back(QLatin1String(uiElementC)); - elements.push_back(QLatin1String(widgetElementC)); + elements.push_back(uiElementC); + elements.push_back(widgetElementC); for (int i = 0; i < 2 && !foundWidget; i++) { switch (findElement(elements, sr)) { case FindError: @@ -367,13 +343,13 @@ QDesignerCustomWidgetData::ParseResult return ParseError; case 0: { // <ui> const QXmlStreamAttributes attributes = sr.attributes(); - data.xmlLanguage = attributes.value(QLatin1String(languageAttributeC)).toString(); - data.xmlDisplayName = attributes.value(QLatin1String(displayNameAttributeC)).toString(); + data.xmlLanguage = attributes.value(languageAttributeC).toString(); + data.xmlDisplayName = attributes.value(displayNameAttributeC).toString(); foundUI = true; } break; case 1: // <widget>: Do some sanity checks - data.xmlClassName = sr.attributes().value(QLatin1String(classAttributeC)).toString(); + data.xmlClassName = sr.attributes().value(classAttributeC).toString(); if (data.xmlClassName.isEmpty()) { *errorMessage = QDesignerPluginManager::tr("The class attribute for the class %1 is missing.").arg(name); rc = ParseWarning; @@ -391,7 +367,7 @@ QDesignerCustomWidgetData::ParseResult if (!foundUI) return rc; elements.clear(); - elements.push_back(QLatin1String(customwidgetElementC)); + elements.push_back(customwidgetElementC); switch (findElement(elements, sr)) { case FindError: *errorMessage = msgXmlError(name, sr.errorString()); @@ -402,10 +378,7 @@ QDesignerCustomWidgetData::ParseResult break; } // Find <extends>, <addPageMethod>, <stringproperties> - elements.clear(); - elements.push_back(QLatin1String(extendsElementC)); - elements.push_back(QLatin1String(addPageMethodC)); - elements.push_back(QLatin1String(propertySpecsC)); + elements = {extendsElementC, addPageMethodC, propertySpecsC}; while (true) { switch (findElement(elements, sr)) { case FindError: @@ -442,7 +415,7 @@ QDesignerCustomWidgetData::ParseResult class QDesignerPluginManagerPrivate { public: - using ClassNamePropertyNameKey = QPair<QString, QString>; + using ClassNamePropertyNameKey = std::pair<QString, QString>; QDesignerPluginManagerPrivate(QDesignerFormEditorInterface *core); @@ -460,8 +433,7 @@ class QDesignerPluginManagerPrivate { // TODO: QPluginLoader also caches invalid plugins -> This seems to be dead code QStringList m_disabledPlugins; - typedef QMap<QString, QString> FailedPluginMap; - FailedPluginMap m_failedPlugins; + QMap<QString, QString> m_failedPlugins; // Synced lists of custom widgets and their data. Note that the list // must be ordered for collections to appear in order. @@ -544,12 +516,18 @@ void QDesignerPluginManagerPrivate::addCustomWidgets(QObject *o, // As of 4.4, the header will be distributed with the Eclipse plugin. QDesignerPluginManager::QDesignerPluginManager(QDesignerFormEditorInterface *core) : + QDesignerPluginManager(QStringList{}, core) +{ +} + +QDesignerPluginManager::QDesignerPluginManager(const QStringList &pluginPaths, + QDesignerFormEditorInterface *core) : QObject(core), m_d(new QDesignerPluginManagerPrivate(core)) { - m_d->m_pluginPaths = defaultPluginPaths(); + m_d->m_pluginPaths = pluginPaths.isEmpty() ? defaultPluginPaths() : pluginPaths; const QSettings settings(qApp->organizationName(), QDesignerQSettings::settingsApplicationName()); - m_d->m_disabledPlugins = unique(settings.value(QStringLiteral("PluginManager/DisabledPlugins")).toStringList()); + m_d->m_disabledPlugins = unique(settings.value("PluginManager/DisabledPlugins").toStringList()); // Register plugins updateRegisteredPlugins(); @@ -584,15 +562,14 @@ QStringList QDesignerPluginManager::findPlugins(const QString &path) // Load symbolic links but make sure all file names are unique as not // to fall for something like 'libplugin.so.1 -> libplugin.so' QStringList result; - const QFileInfoList::const_iterator icend = infoList.constEnd(); - for (QFileInfoList::const_iterator it = infoList.constBegin(); it != icend; ++it) { + for (const auto &fi : infoList) { QString fileName; - if (it->isSymLink()) { - const QFileInfo linkTarget = QFileInfo(it->symLinkTarget()); + if (fi.isSymLink()) { + const QFileInfo linkTarget = QFileInfo(fi.symLinkTarget()); if (linkTarget.exists() && linkTarget.isFile()) fileName = linkTarget.absoluteFilePath(); } else { - fileName = it->absoluteFilePath(); + fileName = fi.absoluteFilePath(); } if (!fileName.isEmpty() && QLibrary::isLibrary(fileName) && !result.contains(fileName)) result += fileName; @@ -651,7 +628,7 @@ void QDesignerPluginManager::updateRegisteredPlugins() if (debugPluginManager) qDebug() << Q_FUNC_INFO; m_d->m_registeredPlugins.clear(); - for (const QString &path : qAsConst(m_d->m_pluginPaths)) + for (const QString &path : std::as_const(m_d->m_pluginPaths)) registerPath(path); } @@ -661,7 +638,7 @@ bool QDesignerPluginManager::registerNewPlugins() qDebug() << Q_FUNC_INFO; const int before = m_d->m_registeredPlugins.size(); - for (const QString &path : qAsConst(m_d->m_pluginPaths)) + for (const QString &path : std::as_const(m_d->m_pluginPaths)) registerPath(path); const bool newPluginsFound = m_d->m_registeredPlugins.size() > before; // We force a re-initialize as Jambi collection might return @@ -693,7 +670,7 @@ void QDesignerPluginManager::registerPlugin(const QString &plugin) QPluginLoader loader(plugin); if (loader.isLoaded() || loader.load()) { m_d->m_registeredPlugins += plugin; - QDesignerPluginManagerPrivate::FailedPluginMap::iterator fit = m_d->m_failedPlugins.find(plugin); + const auto fit = m_d->m_failedPlugins.find(plugin); if (fit != m_d->m_failedPlugins.end()) m_d->m_failedPlugins.erase(fit); return; @@ -708,8 +685,8 @@ void QDesignerPluginManager::registerPlugin(const QString &plugin) bool QDesignerPluginManager::syncSettings() { QSettings settings(qApp->organizationName(), QDesignerQSettings::settingsApplicationName()); - settings.beginGroup(QStringLiteral("PluginManager")); - settings.setValue(QStringLiteral("DisabledPlugins"), m_d->m_disabledPlugins); + settings.beginGroup("PluginManager"); + settings.setValue("DisabledPlugins", m_d->m_disabledPlugins); settings.endGroup(); return settings.status() == QSettings::NoError; } @@ -732,7 +709,7 @@ void QDesignerPluginManager::ensureInitialized() for (QObject *o : staticPluginObjects) m_d->addCustomWidgets(o, staticPluginPath, designerLanguage); } - for (const QString &plugin : qAsConst(m_d->m_registeredPlugins)) { + for (const QString &plugin : std::as_const(m_d->m_registeredPlugins)) { if (QObject *o = instance(plugin)) m_d->addCustomWidgets(o, plugin, designerLanguage); } @@ -756,8 +733,7 @@ QDesignerCustomWidgetData QDesignerPluginManager::customWidgetData(QDesignerCust QDesignerCustomWidgetData QDesignerPluginManager::customWidgetData(const QString &name) const { - const int count = m_d->m_customWidgets.size(); - for (int i = 0; i < count; i++) + for (qsizetype i = 0, count = m_d->m_customWidgets.size(); i < count; ++i) if (m_d->m_customWidgets.at(i)->name() == name) return m_d->m_customWidgetData.at(i); return QDesignerCustomWidgetData(); diff --git a/src/designer/src/lib/shared/pluginmanager_p.h b/src/designer/src/lib/shared/pluginmanager_p.h index 373d0fe51..be0f4bfd7 100644 --- a/src/designer/src/lib/shared/pluginmanager_p.h +++ b/src/designer/src/lib/shared/pluginmanager_p.h @@ -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 // // W A R N I N G @@ -61,7 +36,7 @@ class QDesignerCustomWidgetSharedData; class QDESIGNER_SHARED_EXPORT QDesignerCustomWidgetData { public: // StringPropertyType: validation mode and translatable flag. - typedef QPair<qdesigner_internal::TextPropertyValidationMode, bool> StringPropertyType; + using StringPropertyType = std::pair<qdesigner_internal::TextPropertyValidationMode, bool>; explicit QDesignerCustomWidgetData(const QString &pluginPath = QString()); @@ -102,6 +77,8 @@ public: using CustomWidgetList = QList<QDesignerCustomWidgetInterface *>; explicit QDesignerPluginManager(QDesignerFormEditorInterface *core); + explicit QDesignerPluginManager(const QStringList &pluginPaths, + QDesignerFormEditorInterface *core); ~QDesignerPluginManager() override; QDesignerFormEditorInterface *core() const; @@ -129,6 +106,8 @@ public: bool registerNewPlugins(); + static QStringList defaultPluginPaths(); + public slots: bool syncSettings(); void ensureInitialized(); @@ -139,8 +118,6 @@ private: void registerPlugin(const QString &plugin); private: - static QStringList defaultPluginPaths(); - QDesignerPluginManagerPrivate *m_d; }; diff --git a/src/designer/src/lib/shared/previewconfigurationwidget.cpp b/src/designer/src/lib/shared/previewconfigurationwidget.cpp index bf8d0b60e..49a654856 100644 --- a/src/designer/src/lib/shared/previewconfigurationwidget.cpp +++ b/src/designer/src/lib/shared/previewconfigurationwidget.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 "previewconfigurationwidget_p.h" #include "ui_previewconfigurationwidget.h" @@ -48,15 +23,15 @@ #include <QtCore/qfileinfo.h> #include <QtCore/qshareddata.h> - -static const char *skinResourcePathC = ":/skins/"; - QT_BEGIN_NAMESPACE -static const char *skinExtensionC = "skin"; +using namespace Qt::StringLiterals; + +static constexpr auto skinResourcePathC = ":/skins/"_L1; +static constexpr auto skinExtensionC = "skin"_L1; // Pair of skin name, path -typedef QPair<QString, QString> SkinNamePath; +using SkinNamePath = std::pair<QString, QString>; using Skins = QList<SkinNamePath>; enum { SkinComboNoneIndex = 0 }; @@ -64,16 +39,12 @@ enum { SkinComboNoneIndex = 0 }; static const Skins &defaultSkins() { static Skins rc; if (rc.isEmpty()) { - const QString skinPath = QLatin1String(skinResourcePathC); - QString pattern = QStringLiteral("*."); - pattern += QLatin1String(skinExtensionC); - const QDir dir(skinPath, pattern); + const QDir dir(skinResourcePathC, "*."_L1 + skinExtensionC); const QFileInfoList list = dir.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot, QDir::Name); if (list.isEmpty()) return rc; - const QFileInfoList::const_iterator lcend = list.constEnd(); - for (QFileInfoList::const_iterator it = list.constBegin(); it != lcend; ++it) - rc.push_back(SkinNamePath(it->baseName(), it->filePath())); + for (const auto &fi : list) + rc.append(SkinNamePath(fi.baseName(), fi.filePath())); } return rc; } @@ -109,7 +80,7 @@ private: const QString m_defaultStyle; QGroupBox *m_parent; - Ui::PreviewConfigurationWidget m_ui; + QT_PREPEND_NAMESPACE(Ui)::PreviewConfigurationWidget m_ui; int m_firstUserSkinIndex; int m_browseSkinIndex; @@ -134,17 +105,18 @@ PreviewConfigurationWidget::PreviewConfigurationWidgetPrivate::PreviewConfigurat // sheet m_ui.m_appStyleSheetLineEdit->setTextPropertyValidationMode(qdesigner_internal::ValidationStyleSheet); - m_ui.m_appStyleSheetClearButton->setIcon(qdesigner_internal::createIconSet(QString::fromUtf8("resetproperty.png"))); + m_ui.m_appStyleSheetClearButton->setIcon(qdesigner_internal::createIconSet("resetproperty.png"_L1)); QObject::connect(m_ui.m_appStyleSheetClearButton, &QAbstractButton::clicked, m_ui.m_appStyleSheetLineEdit, &qdesigner_internal::TextPropertyEditor::clear); - m_ui.m_skinRemoveButton->setIcon(qdesigner_internal::createIconSet(QString::fromUtf8("editdelete.png"))); + m_ui.m_skinRemoveButton->setIcon(qdesigner_internal::createIconSet(QIcon::ThemeIcon::EditDelete, + "editdelete.png"_L1)); // skins: find default skins (resources) m_ui.m_skinRemoveButton->setEnabled(false); Skins skins = defaultSkins(); skins.push_front(SkinNamePath(PreviewConfigurationWidget::tr("None"), QString())); - for (const auto &skin : qAsConst(skins)) + for (const auto &skin : std::as_const(skins)) m_ui.m_skinCombo->addItem(skin.first, QVariant(skin.second)); m_browseSkinIndex = m_firstUserSkinIndex = skins.size(); m_ui.m_skinCombo->addItem(PreviewConfigurationWidget::tr("Browse..."), QString()); @@ -172,14 +144,12 @@ void PreviewConfigurationWidget::PreviewConfigurationWidgetPrivate::addUserSkins { if (files.isEmpty()) return; - const QStringList ::const_iterator fcend = files.constEnd(); - for (QStringList::const_iterator it = files.constBegin(); it != fcend; ++it) { - const QFileInfo fi(*it); - if (fi.isDir() && fi.isReadable()) { - m_ui.m_skinCombo->insertItem(m_browseSkinIndex++, fi.baseName(), QVariant(*it)); - } else { - qWarning() << "Unable to access the skin directory '" << *it << "'."; - } + for (const auto &f : files) { + const QFileInfo fi(f); + if (fi.isDir() && fi.isReadable()) + m_ui.m_skinCombo->insertItem(m_browseSkinIndex++, fi.baseName(), QVariant(f)); + else + qWarning() << "Unable to access the skin directory '" << f << "'."; } } @@ -268,7 +238,7 @@ int PreviewConfigurationWidget::PreviewConfigurationWidgetPrivate::browseSkin() dlg.setOption(QFileDialog::ShowDirsOnly); const QString title = tr("Load Custom Device Skin"); dlg.setWindowTitle(title); - dlg.setNameFilter(tr("All QVFB Skins (*.%1)").arg(QLatin1String(skinExtensionC))); + dlg.setNameFilter(tr("All QVFB Skins (*.%1)").arg(skinExtensionC)); int rc = m_lastSkinIndex; do { diff --git a/src/designer/src/lib/shared/previewconfigurationwidget_p.h b/src/designer/src/lib/shared/previewconfigurationwidget_p.h index c469cef2d..ec5e2bed3 100644 --- a/src/designer/src/lib/shared/previewconfigurationwidget_p.h +++ b/src/designer/src/lib/shared/previewconfigurationwidget_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/previewmanager.cpp b/src/designer/src/lib/shared/previewmanager.cpp index 3d04346f3..ce9a58e72 100644 --- a/src/designer/src/lib/shared/previewmanager.cpp +++ b/src/designer/src/lib/shared/previewmanager.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 "formwindowbase_p.h" #include "previewmanager_p.h" @@ -58,10 +33,13 @@ #include <QtCore/qdebug.h> #include <QtCore/qlist.h> #include <QtCore/qmap.h> +#include <QtCore/qpointer.h> #include <QtCore/qshareddata.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static inline int compare(const qdesigner_internal::PreviewConfiguration &pc1, const qdesigner_internal::PreviewConfiguration &pc2) { int rc = pc1.style().compare(pc2.style()); @@ -73,7 +51,7 @@ static inline int compare(const qdesigner_internal::PreviewConfiguration &pc1, c return pc1.deviceSkin().compare(pc2.deviceSkin()); } -namespace { +namespace qdesigner_internal { // ------ PreviewData (data associated with a preview window) struct PreviewData { PreviewData(const QPointer<QWidget> &widget, const QDesignerFormWindowInterface *formWindow, const qdesigner_internal::PreviewConfiguration &pc); @@ -90,9 +68,6 @@ namespace { m_configuration(pc) { } -} - -namespace qdesigner_internal { /* In designer, we have the situation that laid-out maincontainers have * a geometry set (which might differ from their sizeHint()). The QGraphicsItem @@ -433,9 +408,9 @@ void ZoomablePreviewDeviceSkin::fitWidget(const QSize &size) // ------------- PreviewConfiguration -static const char *styleKey = "Style"; -static const char *appStyleSheetKey = "AppStyleSheet"; -static const char *skinKey = "Skin"; +static constexpr auto styleKey = "Style"_L1; +static constexpr auto appStyleSheetKey = "AppStyleSheet"_L1; +static constexpr auto skinKey = "Skin"_L1; PreviewConfiguration::PreviewConfiguration() : m_d(new PreviewConfigurationData) @@ -503,30 +478,29 @@ void PreviewConfiguration::toSettings(const QString &prefix, QDesignerSettingsIn { const PreviewConfigurationData &d = *m_d; settings->beginGroup(prefix); - settings->setValue(QLatin1String(styleKey), d.m_style); - settings->setValue(QLatin1String(appStyleSheetKey), d.m_applicationStyleSheet); - settings->setValue(QLatin1String(skinKey), d.m_deviceSkin); + settings->setValue(styleKey, d.m_style); + settings->setValue(appStyleSheetKey, d.m_applicationStyleSheet); + settings->setValue(skinKey, d.m_deviceSkin); settings->endGroup(); } void PreviewConfiguration::fromSettings(const QString &prefix, const QDesignerSettingsInterface *settings) { clear(); - QString key = prefix; - key += QLatin1Char('/'); - const int prefixSize = key.size(); + QString key = prefix + u'/'; + const auto prefixSize = key.size(); PreviewConfigurationData &d = *m_d; const QVariant emptyString = QVariant(QString()); - key += QLatin1String(styleKey); + key += styleKey; d.m_style = settings->value(key, emptyString).toString(); - key.replace(prefixSize, key.size() - prefixSize, QLatin1String(appStyleSheetKey)); + key.replace(prefixSize, key.size() - prefixSize, appStyleSheetKey); d.m_applicationStyleSheet = settings->value(key, emptyString).toString(); - key.replace(prefixSize, key.size() - prefixSize, QLatin1String(skinKey)); + key.replace(prefixSize, key.size() - prefixSize, skinKey); d.m_deviceSkin = settings->value(key, emptyString).toString(); } @@ -559,8 +533,7 @@ public: PreviewDataList m_previews; - typedef QMap<QString, DeviceSkinParameters> DeviceSkinConfigCache; - DeviceSkinConfigCache m_deviceSkinConfigCache; + QMap<QString, DeviceSkinParameters> m_deviceSkinConfigCache; QDesignerFormEditorInterface *m_core; bool m_updateBlocked; @@ -703,7 +676,7 @@ QWidget *PreviewManager::createPreview(const QDesignerFormWindowInterface *fw, return formWidget; } // Embed into skin. find config in cache - PreviewManagerPrivate::DeviceSkinConfigCache::iterator it = d->m_deviceSkinConfigCache.find(deviceSkin); + auto it = d->m_deviceSkinConfigCache.find(deviceSkin); if (it == d->m_deviceSkinConfigCache.end()) { DeviceSkinParameters parameters; if (!parameters.read(deviceSkin, DeviceSkinParameters::ReadAll, errorMessage)) { @@ -796,15 +769,13 @@ QWidget *PreviewManager::showPreview(const QDesignerFormWindowInterface *fw, QWidget *PreviewManager::raise(const QDesignerFormWindowInterface *fw, const PreviewConfiguration &pc) { - using PreviewDataList = PreviewManagerPrivate::PreviewDataList; if (d->m_previews.isEmpty()) return nullptr; // find matching window - const PreviewDataList::const_iterator cend = d->m_previews.constEnd(); - for (PreviewDataList::const_iterator it = d->m_previews.constBegin(); it != cend ;++it) { - QWidget * w = it->m_widget; - if (w && it->m_formWindow == fw && it->m_configuration == pc) { + for (const auto &pd : std::as_const(d->m_previews)) { + QWidget *w = pd.m_widget; + if (w && pd.m_formWindow == fw && pd.m_configuration == pc) { w->raise(); w->activateWindow(); return w; @@ -818,9 +789,9 @@ void PreviewManager::closeAllPreviews() if (!d->m_previews.isEmpty()) { d->m_updateBlocked = true; d->m_activePreview = nullptr; - for (auto it = d->m_previews.constBegin(), cend = d->m_previews.constEnd(); it != cend ;++it) { - if (it->m_widget) - it->m_widget->close(); + for (const auto &pd : std::as_const(d->m_previews)) { + if (pd.m_widget) + pd.m_widget->close(); } d->m_previews.clear(); d->m_updateBlocked = false; @@ -830,11 +801,10 @@ void PreviewManager::closeAllPreviews() void PreviewManager::updatePreviewClosed(QWidget *w) { - using PreviewDataList = PreviewManagerPrivate::PreviewDataList; if (d->m_updateBlocked) return; // Purge out all 0 or widgets to be deleted - for (PreviewDataList::iterator it = d->m_previews.begin(); it != d->m_previews.end() ; ) { + for (auto it = d->m_previews.begin(); it != d->m_previews.end() ; ) { QWidget *iw = it->m_widget; // Might be 0 when catching QEvent::Destroyed if (iw == nullptr || iw == w) { it = d->m_previews.erase(it); diff --git a/src/designer/src/lib/shared/previewmanager_p.h b/src/designer/src/lib/shared/previewmanager_p.h index 83c4ae7c0..aa17d384b 100644 --- a/src/designer/src/lib/shared/previewmanager_p.h +++ b/src/designer/src/lib/shared/previewmanager_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/promotionmodel.cpp b/src/designer/src/lib/shared/promotionmodel.cpp index 37136ced6..8d9851936 100644 --- a/src/designer/src/lib/shared/promotionmodel.cpp +++ b/src/designer/src/lib/shared/promotionmodel.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 "promotionmodel_p.h" #include "widgetdatabase_p.h" @@ -137,18 +112,18 @@ namespace qdesigner_internal { QDesignerWidgetDataBaseItemInterface *baseClass = nullptr; QStandardItem *baseItem = nullptr; - const PromotedClasses::const_iterator bcend = promotedClasses.constEnd(); - for (PromotedClasses::const_iterator it = promotedClasses.constBegin(); it != bcend; ++it) { + for (auto &pi : promotedClasses) { // Start a new base class? - if (baseClass != it->baseItem) { - baseClass = it->baseItem; - const StandardItemList baseRow = baseModelRow(it->baseItem); + if (baseClass != pi.baseItem) { + baseClass = pi.baseItem; + const StandardItemList baseRow = baseModelRow(pi.baseItem); baseItem = baseRow.constFirst(); appendRow(baseRow); } Q_ASSERT(baseItem); // Append derived - baseItem->appendRow(promotedModelRow(it->baseItem, it->promotedItem, usedPromotedClasses.contains(it->promotedItem->name()))); + baseItem->appendRow(promotedModelRow(pi.baseItem, pi.promotedItem, + usedPromotedClasses.contains(pi.promotedItem->name()))); } } diff --git a/src/designer/src/lib/shared/promotionmodel_p.h b/src/designer/src/lib/shared/promotionmodel_p.h index 3acd119ff..c92017b86 100644 --- a/src/designer/src/lib/shared/promotionmodel_p.h +++ b/src/designer/src/lib/shared/promotionmodel_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/promotiontaskmenu.cpp b/src/designer/src/lib/shared/promotiontaskmenu.cpp index c458d2604..7cedb226b 100644 --- a/src/designer/src/lib/shared/promotiontaskmenu.cpp +++ b/src/designer/src/lib/shared/promotiontaskmenu.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 "promotiontaskmenu_p.h" #include "qdesigner_promotiondialog_p.h" @@ -146,10 +121,9 @@ PromotionTaskMenu::PromotionState PromotionTaskMenu::createPromotionActions(QDe QMenu *candidatesMenu = new QMenu(); // Create a sub menu - const WidgetDataBaseItemList::const_iterator cend = candidates.constEnd(); // Set up actions and map class names - for (WidgetDataBaseItemList::const_iterator it = candidates.constBegin(); it != cend; ++it) { - const QString customClassName = (*it)->name(); + for (auto *item : candidates) { + const QString customClassName = item->name(); candidatesMenu->addAction(customClassName, this, [this, customClassName] { this->slotPromoteToCustomWidget(customClassName); }); } @@ -169,7 +143,7 @@ void PromotionTaskMenu::addActions(QDesignerFormWindowInterface *fw, unsigned fl ActionList &actionList) { Q_ASSERT(m_widget); - const int previousSize = actionList.size(); + const auto previousSize = actionList.size(); const PromotionState promotionState = createPromotionActions(fw); // Promotion candidates/demote @@ -290,9 +264,7 @@ PromotionTaskMenu::PromotionSelectionList PromotionTaskMenu::promotionSelectionL designerObjectInspector->getSelection(s); // Find objects of similar state const QWidgetList &source = m_mode == ModeManagedMultiSelection ? s.managed : s.unmanaged; - const QWidgetList::const_iterator cend = source.constEnd(); - for (QWidgetList::const_iterator it = source.constBegin(); it != cend; ++it) { - QWidget *w = *it; + for (auto *w : source) { if (w != m_widget) { // Selection state mismatch if (intro->metaObject(w)->className() != className || isPromoted(core, w) != promoted) diff --git a/src/designer/src/lib/shared/promotiontaskmenu_p.h b/src/designer/src/lib/shared/promotiontaskmenu_p.h index ee9f53db0..371d95d6d 100644 --- a/src/designer/src/lib/shared/promotiontaskmenu_p.h +++ b/src/designer/src/lib/shared/promotiontaskmenu_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/propertylineedit.cpp b/src/designer/src/lib/shared/propertylineedit.cpp index 6e5b68412..bea91010a 100644 --- a/src/designer/src/lib/shared/propertylineedit.cpp +++ b/src/designer/src/lib/shared/propertylineedit.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 "propertylineedit_p.h" @@ -33,6 +8,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { PropertyLineEdit::PropertyLineEdit(QWidget *parent) : QLineEdit(parent), m_wantNewLine(false) @@ -55,14 +32,14 @@ namespace qdesigner_internal { } void PropertyLineEdit::insertNewLine() { - insertText(QStringLiteral("\\n")); + insertText(u"\\n"_s); } void PropertyLineEdit::insertText(const QString &text) { // position cursor after new text and grab focus const int oldCursorPosition = cursorPosition (); insert(text); - setCursorPosition (oldCursorPosition + text.length()); + setCursorPosition (oldCursorPosition + text.size()); setFocus(Qt::OtherFocusReason); } diff --git a/src/designer/src/lib/shared/propertylineedit_p.h b/src/designer/src/lib/shared/propertylineedit_p.h index a408f8a9d..d1a1c9428 100644 --- a/src/designer/src/lib/shared/propertylineedit_p.h +++ b/src/designer/src/lib/shared/propertylineedit_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_command.cpp b/src/designer/src/lib/shared/qdesigner_command.cpp index d6a6416ae..2633224e6 100644 --- a/src/designer/src/lib/shared/qdesigner_command.cpp +++ b/src/designer/src/lib/shared/qdesigner_command.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 "qdesigner_command_p.h" #include "qdesigner_propertycommand_p.h" @@ -75,10 +50,12 @@ Q_DECLARE_METATYPE(QWidgetList) QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static inline void setPropertySheetWindowTitle(const QDesignerFormEditorInterface *core, QObject *o, const QString &t) { if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), o)) { - const int idx = sheet->indexOf(QStringLiteral("windowTitle")); + const int idx = sheet->indexOf(u"windowTitle"_s); if (idx != -1) { sheet->setProperty(idx, t); sheet->setChanged(idx, true); @@ -89,8 +66,8 @@ static inline void setPropertySheetWindowTitle(const QDesignerFormEditorInterfac namespace qdesigner_internal { // Helpers for the dynamic properties that store Z/Widget order -static const char *widgetOrderPropertyC = "_q_widgetOrder"; -static const char *zOrderPropertyC = "_q_zOrder"; +static const char widgetOrderPropertyC[] = "_q_widgetOrder"; +static const char zOrderPropertyC[] = "_q_zOrder"; static void addToWidgetListDynamicProperty(QWidget *parentWidget, QWidget *widget, const char *name, int index = -1) { @@ -144,7 +121,7 @@ void InsertWidgetCommand::init(QWidget *widget, bool already_in_form, int layout m_cell.first = layoutRow; m_cell.second = layoutColumn; } else { - m_cell = deco ? deco->currentCell() : qMakePair(0, 0); + m_cell = deco ? deco->currentCell() : std::make_pair(0, 0); } m_widgetWasManaged = already_in_form; } @@ -153,10 +130,8 @@ static void recursiveUpdate(QWidget *w) { w->update(); - const QObjectList &l = w->children(); - const QObjectList::const_iterator cend = l.end(); - for ( QObjectList::const_iterator it = l.begin(); it != cend; ++it) { - if (QWidget *w = qobject_cast<QWidget*>(*it)) + for (auto *child : w->children()) { + if (QWidget *w = qobject_cast<QWidget*>(child)) recursiveUpdate(w); } } @@ -236,7 +211,7 @@ void InsertWidgetCommand::refreshBuddyLabels() if (label_list.isEmpty()) return; - const QString buddyProperty = QStringLiteral("buddy"); + const QString buddyProperty = u"buddy"_s; const QByteArray objectNameU8 = m_widget->objectName().toUtf8(); // Re-set the buddy (The sheet locates the object by name and sets it) for (QLabel *label : label_list) { @@ -266,8 +241,8 @@ void ChangeZOrderCommand::init(QWidget *widget) setText(QApplication::translate("Command", "Change Z-order of '%1'").arg(widget->objectName())); m_oldParentZOrder = qvariant_cast<QWidgetList>(widget->parentWidget()->property("_q_zOrder")); - const int index = m_oldParentZOrder.indexOf(m_widget); - if (index != -1 && index + 1 < m_oldParentZOrder.count()) + const qsizetype index = m_oldParentZOrder.indexOf(m_widget); + if (index != -1 && index + 1 < m_oldParentZOrder.size()) m_oldPreceding = m_oldParentZOrder.at(index + 1); } @@ -347,17 +322,14 @@ void ManageWidgetCommandHelper::init(const QDesignerFormWindowInterface *fw, QWi m_managedChildren.clear(); const QWidgetList children = m_widget->findChildren<QWidget *>(); - if (children.isEmpty()) - return; - m_managedChildren.reserve(children.size()); - const QWidgetList::const_iterator lcend = children.constEnd(); - for (QWidgetList::const_iterator it = children.constBegin(); it != lcend; ++it) - if (fw->isManaged(*it)) - m_managedChildren.push_back(*it); + for (auto *w : children) { + if (fw->isManaged(w)) + m_managedChildren.push_back(w); + } } -void ManageWidgetCommandHelper::init(QWidget *widget, const WidgetVector &managedChildren) +void ManageWidgetCommandHelper::init(QWidget *widget, const QWidgetList &managedChildren) { m_widget = widget; m_managedChildren = managedChildren; @@ -367,21 +339,15 @@ void ManageWidgetCommandHelper::manage(QDesignerFormWindowInterface *fw) { // Manage the managed children after parent fw->manageWidget(m_widget); - if (!m_managedChildren.isEmpty()) { - const WidgetVector::const_iterator lcend = m_managedChildren.constEnd(); - for (WidgetVector::const_iterator it = m_managedChildren.constBegin(); it != lcend; ++it) - fw->manageWidget(*it); - } + for (auto *w : std::as_const(m_managedChildren)) + fw->manageWidget(w); } void ManageWidgetCommandHelper::unmanage(QDesignerFormWindowInterface *fw) { // Unmanage the managed children first - if (!m_managedChildren.isEmpty()) { - const WidgetVector::const_iterator lcend = m_managedChildren.constEnd(); - for (WidgetVector::const_iterator it = m_managedChildren.constBegin(); it != lcend; ++it) - fw->unmanageWidget(*it); - } + for (auto *w : std::as_const(m_managedChildren)) + fw->unmanageWidget(w); fw->unmanageWidget(m_widget); } @@ -625,7 +591,7 @@ void PromoteToCustomWidgetCommand::init(const WidgetPointerList &widgets,const Q void PromoteToCustomWidgetCommand::redo() { - for (QWidget *w : qAsConst(m_widgets)) { + for (QWidget *w : std::as_const(m_widgets)) { if (w) promoteWidget(core(), w, m_customClassName); } @@ -644,7 +610,7 @@ void PromoteToCustomWidgetCommand::updateSelection() void PromoteToCustomWidgetCommand::undo() { - for (QWidget *w : qAsConst(m_widgets)) { + for (QWidget *w : std::as_const(m_widgets)) { if (w) demoteWidget(core(), w); } @@ -697,11 +663,10 @@ void CursorSelectionState::restore(QDesignerFormWindowInterface *formWindow) con } else { // Select current as last formWindow->clearSelection(false); - const WidgetPointerList::const_iterator cend = m_selection.constEnd(); - for (WidgetPointerList::const_iterator it = m_selection.constBegin(); it != cend; ++it) - if (QWidget *w = *it) - if (w != m_current) - formWindow->selectWidget(*it, true); + for (const auto &wp : m_selection) { + if (!wp.isNull() && wp.data() != m_current) + formWindow->selectWidget(wp.data(), true); + } if (m_current) formWindow->selectWidget(m_current, true); } @@ -857,7 +822,7 @@ void BreakLayoutCommand::redo() m_layout->breakLayout(); delete deco; // release the extension - for (QWidget *widget : qAsConst(m_widgets)) { + for (QWidget *widget : std::as_const(m_widgets)) { widget->resize(widget->size().expandedTo(QSize(16, 16))); } // Update unless we are in an intermediate state of morphing layout @@ -994,7 +959,7 @@ void ToolBoxCommand::addPage() QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(formWindow()->core()->extensionManager(), m_toolBox); if (sheet) { qdesigner_internal::PropertySheetStringValue itemText(m_itemText); - sheet->setProperty(sheet->indexOf(QStringLiteral("currentItemText")), QVariant::fromValue(itemText)); + sheet->setProperty(sheet->indexOf(u"currentItemText"_s), QVariant::fromValue(itemText)); } m_widget->show(); @@ -1085,7 +1050,7 @@ void AddToolBoxPageCommand::init(QToolBox *toolBox, InsertionMode mode) m_widget = new QDesignerWidget(formWindow(), m_toolBox); m_itemText = QApplication::translate("Command", "Page"); m_itemIcon = QIcon(); - m_widget->setObjectName(QStringLiteral("page")); + m_widget->setObjectName(u"page"_s); formWindow()->ensureUniqueObjectName(m_widget); setText(QApplication::translate("Command", "Insert Page")); @@ -1146,7 +1111,8 @@ void TabWidgetCommand::addPage() QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(formWindow()->core()->extensionManager(), m_tabWidget); if (sheet) { qdesigner_internal::PropertySheetStringValue itemText(m_itemText); - sheet->setProperty(sheet->indexOf(QStringLiteral("currentTabText")), QVariant::fromValue(itemText)); + sheet->setProperty(sheet->indexOf(u"currentTabText"_s), + QVariant::fromValue(itemText)); } formWindow()->clearSelection(); @@ -1202,7 +1168,7 @@ void AddTabPageCommand::init(QTabWidget *tabWidget, InsertionMode mode) m_widget = new QDesignerWidget(formWindow(), m_tabWidget); m_itemText = QApplication::translate("Command", "Page"); m_itemIcon = QIcon(); - m_widget->setObjectName(QStringLiteral("tab")); + m_widget->setObjectName(u"tab"_s); formWindow()->ensureUniqueObjectName(m_widget); setText(QApplication::translate("Command", "Insert Page")); @@ -1378,7 +1344,7 @@ void AddStackedWidgetPageCommand::init(QStackedWidget *stackedWidget, InsertionM if (mode == InsertAfter) m_index++; m_widget = new QDesignerWidget(formWindow(), m_stackedWidget); - m_widget->setObjectName(QStringLiteral("page")); + m_widget->setObjectName(u"page"_s); formWindow()->ensureUniqueObjectName(m_widget); setText(QApplication::translate("Command", "Insert Page")); @@ -1437,7 +1403,7 @@ void CreateMenuBarCommand::init(QMainWindow *mainWindow) { m_mainWindow = mainWindow; QDesignerFormEditorInterface *core = formWindow()->core(); - m_menuBar = qobject_cast<QMenuBar*>(core->widgetFactory()->createWidget(QStringLiteral("QMenuBar"), m_mainWindow)); + m_menuBar = qobject_cast<QMenuBar*>(core->widgetFactory()->createWidget(u"QMenuBar"_s, m_mainWindow)); core->widgetFactory()->initialize(m_menuBar); } @@ -1448,7 +1414,7 @@ void CreateMenuBarCommand::redo() c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow); c->addWidget(m_menuBar); - m_menuBar->setObjectName(QStringLiteral("menuBar")); + m_menuBar->setObjectName(u"menuBar"_s); formWindow()->ensureUniqueObjectName(m_menuBar); core->metaDataBase()->add(m_menuBar); formWindow()->emitSelectionChanged(); @@ -1528,7 +1494,7 @@ void CreateStatusBarCommand::init(QMainWindow *mainWindow) { m_mainWindow = mainWindow; QDesignerFormEditorInterface *core = formWindow()->core(); - m_statusBar = qobject_cast<QStatusBar*>(core->widgetFactory()->createWidget(QStringLiteral("QStatusBar"), m_mainWindow)); + m_statusBar = qobject_cast<QStatusBar*>(core->widgetFactory()->createWidget(u"QStatusBar"_s, m_mainWindow)); core->widgetFactory()->initialize(m_statusBar); } @@ -1539,7 +1505,7 @@ void CreateStatusBarCommand::redo() c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow); c->addWidget(m_statusBar); - m_statusBar->setObjectName(QStringLiteral("statusBar")); + m_statusBar->setObjectName(u"statusBar"_s); formWindow()->ensureUniqueObjectName(m_statusBar); core->metaDataBase()->add(m_statusBar); formWindow()->emitSelectionChanged(); @@ -1616,7 +1582,7 @@ void AddToolBarCommand::init(QMainWindow *mainWindow, Qt::ToolBarArea area) m_mainWindow = mainWindow; QDesignerWidgetFactoryInterface * wf = formWindow()->core()->widgetFactory(); // Pass on 0 parent first to avoid reparenting flicker. - m_toolBar = qobject_cast<QToolBar*>(wf->createWidget(QStringLiteral("QToolBar"), nullptr)); + m_toolBar = qobject_cast<QToolBar*>(wf->createWidget(u"QToolBar"_s, nullptr)); m_toolBar->setProperty("_q_desiredArea", QVariant(area)); wf->initialize(m_toolBar); m_toolBar->hide(); @@ -1630,7 +1596,7 @@ void AddToolBarCommand::redo() QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow); c->addWidget(m_toolBar); - m_toolBar->setObjectName(QStringLiteral("toolBar")); + m_toolBar->setObjectName(u"toolBar"_s); formWindow()->ensureUniqueObjectName(m_toolBar); setPropertySheetWindowTitle(core, m_toolBar, m_toolBar->objectName()); formWindow()->emitSelectionChanged(); @@ -1679,7 +1645,7 @@ void AddDockWidgetCommand::init(QMainWindow *mainWindow) { m_mainWindow = mainWindow; QDesignerFormEditorInterface *core = formWindow()->core(); - m_dockWidget = qobject_cast<QDockWidget*>(core->widgetFactory()->createWidget(QStringLiteral("QDockWidget"), m_mainWindow)); + m_dockWidget = qobject_cast<QDockWidget*>(core->widgetFactory()->createWidget(u"QDockWidget"_s, m_mainWindow)); } void AddDockWidgetCommand::redo() @@ -1688,7 +1654,7 @@ void AddDockWidgetCommand::redo() QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow); c->addWidget(m_dockWidget); - m_dockWidget->setObjectName(QStringLiteral("dockWidget")); + m_dockWidget->setObjectName(u"dockWidget"_s); formWindow()->ensureUniqueObjectName(m_dockWidget); formWindow()->manageWidget(m_dockWidget); formWindow()->emitSelectionChanged(); @@ -1769,7 +1735,7 @@ void AdjustWidgetSizeCommand::updatePropertyEditor() const { if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) { if (propertyEditor->object() == m_widget) - propertyEditor->setPropertyValue(QStringLiteral("geometry"), m_widget->geometry(), true); + propertyEditor->setPropertyValue(u"geometry"_s, m_widget->geometry(), true); } } // ------------ ChangeFormLayoutItemRoleCommand @@ -2043,16 +2009,16 @@ void AddContainerWidgetPageCommand::init(QWidget *containerWidget, ContainerType case PageContainer: setText(QApplication::translate("Command", "Insert Page")); m_widget = new QDesignerWidget(formWindow(), m_containerWidget); - m_widget->setObjectName(QStringLiteral("page")); + m_widget->setObjectName(u"page"_s); break; case MdiContainer: setText(QApplication::translate("Command", "Insert Subwindow")); m_widget = new QDesignerWidget(formWindow(), m_containerWidget); - m_widget->setObjectName(QStringLiteral("subwindow")); + m_widget->setObjectName(u"subwindow"_s); setPropertySheetWindowTitle(core, m_widget, QApplication::translate("Command", "Subwindow")); break; case WizardContainer: // Apply style, don't manage - m_widget = core->widgetFactory()->createWidget(QStringLiteral("QWizardPage"), nullptr); + m_widget = core->widgetFactory()->createWidget(u"QWizardPage"_s, nullptr); break; } formWindow()->ensureUniqueObjectName(m_widget); @@ -2145,9 +2111,7 @@ static void copyRolesFromItem(ItemData *id, const T *item, bool editor) template<class T> static void copyRolesToItem(const ItemData *id, T *item, DesignerIconCache *iconCache, bool editor) { - QHash<int, QVariant>::const_iterator it = id->m_properties.constBegin(), - end = id->m_properties.constEnd(); - for (; it != end; ++it) + for (auto it = id->m_properties.cbegin(), end = id->m_properties.cend(); it != end; ++it) { if (it.value().isValid()) { if (!editor && it.key() == ItemFlagsShadowRole) { item->setFlags((Qt::ItemFlags)it.value().toInt()); @@ -2173,6 +2137,7 @@ static void copyRolesToItem(const ItemData *id, T *item, DesignerIconCache *icon } } } + } if (editor) item->setFlags(item->flags() | Qt::ItemIsEditable); @@ -2221,8 +2186,7 @@ ItemData::ItemData(const QTreeWidgetItem *item, int column) void ItemData::fillTreeItemColumn(QTreeWidgetItem *item, int column, DesignerIconCache *iconCache) const { - QHash<int, QVariant>::const_iterator it = m_properties.constBegin(), end = m_properties.constEnd(); - for (; it != end; ++it) + for (auto it = m_properties.cbegin(), end = m_properties.cend(); it != end; ++it) { if (it.value().isValid()) { item->setData(column, it.key(), it.value()); switch (it.key()) { @@ -2244,6 +2208,7 @@ void ItemData::fillTreeItemColumn(QTreeWidgetItem *item, int column, DesignerIco break; } } + } } ListContents::ListContents(const QTreeWidgetItem *item) @@ -2420,19 +2385,19 @@ void TableWidgetContents::applyToTableWidget(QTableWidget *tableWidget, Designer row++; } // items - const TableItemMap::const_iterator icend = m_items.constEnd(); - for (TableItemMap::const_iterator it = m_items.constBegin(); it != icend; ++ it) - tableWidget->setItem(it.key().first, it.key().second, it.value().createTableItem(iconCache, editor)); + for (auto it = m_items.cbegin(), icend = m_items.cend(); it != icend; ++ it) { + tableWidget->setItem(it.key().first, it.key().second, + it.value().createTableItem(iconCache, editor)); + } } -bool TableWidgetContents::operator==(const TableWidgetContents &rhs) const +bool comparesEqual(const TableWidgetContents &lhs, + const TableWidgetContents &rhs) noexcept { - if (m_columnCount != rhs.m_columnCount || m_rowCount != rhs.m_rowCount) - return false; - - return m_horizontalHeader.m_items == rhs.m_horizontalHeader.m_items && - m_verticalHeader.m_items == rhs.m_verticalHeader.m_items && - m_items == rhs.m_items; + return lhs.m_columnCount == rhs.m_columnCount && lhs.m_rowCount == rhs.m_rowCount && + lhs.m_horizontalHeader.m_items == rhs.m_horizontalHeader.m_items && + lhs.m_verticalHeader.m_items == rhs.m_verticalHeader.m_items && + lhs.m_items == rhs.m_items; } // ---- ChangeTableContentsCommand ---- @@ -2502,12 +2467,11 @@ QTreeWidgetItem *TreeWidgetContents::ItemContents::createTreeItem(DesignerIconCa return item; } -bool TreeWidgetContents::ItemContents::operator==(const TreeWidgetContents::ItemContents &rhs) const +bool comparesEqual(const TreeWidgetContents::ItemContents &lhs, + const TreeWidgetContents::ItemContents &rhs) noexcept { - return - m_itemFlags == rhs.m_itemFlags && - m_items == rhs.m_items && - m_children == rhs.m_children; + return lhs.m_itemFlags == rhs.m_itemFlags && lhs.m_items == rhs.m_items + && lhs.m_children == rhs.m_children; } void TreeWidgetContents::clear() @@ -2528,20 +2492,13 @@ void TreeWidgetContents::applyToTreeWidget(QTreeWidget *treeWidget, DesignerIcon { treeWidget->clear(); - treeWidget->setColumnCount(m_headerItem.m_items.count()); + treeWidget->setColumnCount(m_headerItem.m_items.size()); treeWidget->setHeaderItem(m_headerItem.createTreeItem(iconCache)); for (const ItemContents &ic : m_rootItems) treeWidget->addTopLevelItem(ic.createTreeItem(iconCache, editor)); treeWidget->expandAll(); } -bool TreeWidgetContents::operator==(const TreeWidgetContents &rhs) const -{ - return - m_headerItem == rhs.m_headerItem && - m_rootItems == rhs.m_rootItems; -} - // ---- ChangeTreeContentsCommand ---- ChangeTreeContentsCommand::ChangeTreeContentsCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Change Tree Contents"), formWindow), @@ -2653,19 +2610,19 @@ static RemoveActionCommand::ActionData findActionIn(QAction *action) { RemoveActionCommand::ActionData result; // We only want menus and toolbars, no toolbuttons. - const QWidgetList &associatedWidgets = action->associatedWidgets(); - for (QWidget *widget : associatedWidgets) { - if (qobject_cast<const QMenu *>(widget) || qobject_cast<const QToolBar *>(widget)) { - const auto actionList = widget->actions(); - const int size = actionList.size(); - for (int i = 0; i < size; ++i) { - if (actionList.at(i) == action) { - QAction *before = nullptr; - if (i + 1 < size) - before = actionList.at(i + 1); - result.append(RemoveActionCommand::ActionDataItem(before, widget)); - break; - } + const QObjectList associatedObjects = action->associatedObjects(); + for (QObject *obj : associatedObjects) { + if (!qobject_cast<const QMenu *>(obj) && !qobject_cast<const QToolBar *>(obj)) + continue; + QWidget *widget = static_cast<QWidget *>(obj); + const auto actionList = widget->actions(); + for (qsizetype i = 0, size = actionList.size(); i < size; ++i) { + if (actionList.at(i) == action) { + QAction *before = nullptr; + if (i + 1 < size) + before = actionList.at(i + 1); + result.append(RemoveActionCommand::ActionDataItem(before, widget)); + break; } } } @@ -2683,7 +2640,7 @@ void RemoveActionCommand::init(QAction *action) void RemoveActionCommand::redo() { QDesignerFormWindowInterface *fw = formWindow(); - for (const ActionDataItem &item : qAsConst(m_actionData)) { + for (const ActionDataItem &item : std::as_const(m_actionData)) { item.widget->removeAction(m_action); } // Notify components (for example, signal slot editor) @@ -2700,7 +2657,7 @@ void RemoveActionCommand::undo() { core()->actionEditor()->setFormWindow(formWindow()); core()->actionEditor()->manageAction(m_action); - for (const ActionDataItem &item : qAsConst(m_actionData)) + for (const ActionDataItem &item : std::as_const(m_actionData)) item.widget->insertAction(item.before, m_action); if (!m_actionData.isEmpty()) core()->objectInspector()->setFormWindow(formWindow()); diff --git a/src/designer/src/lib/shared/qdesigner_command2.cpp b/src/designer/src/lib/shared/qdesigner_command2.cpp index ac035f6ec..cc8cff4f6 100644 --- a/src/designer/src/lib/shared/qdesigner_command2.cpp +++ b/src/designer/src/lib/shared/qdesigner_command2.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 "qdesigner_command2_p.h" #include "formwindowbase_p.h" diff --git a/src/designer/src/lib/shared/qdesigner_command2_p.h b/src/designer/src/lib/shared/qdesigner_command2_p.h index 6d5fd00b9..bfe32cdd4 100644 --- a/src/designer/src/lib/shared/qdesigner_command2_p.h +++ b/src/designer/src/lib/shared/qdesigner_command2_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_command_p.h b/src/designer/src/lib/shared/qdesigner_command_p.h index 0c1f5764c..e3239ce5c 100644 --- a/src/designer/src/lib/shared/qdesigner_command_p.h +++ b/src/designer/src/lib/shared/qdesigner_command_p.h @@ -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 // // W A R N I N G @@ -51,12 +26,14 @@ #include <QtGui/qicon.h> +#include <QtCore/qcompare.h> #include <QtCore/qhash.h> #include <QtCore/qlist.h> #include <QtCore/qmap.h> #include <QtCore/qobject.h> #include <QtCore/qpair.h> #include <QtCore/qpoint.h> +#include <QtCore/qpointer.h> #include <QtCore/qrect.h> QT_BEGIN_NAMESPACE @@ -107,7 +84,7 @@ private: QPointer<QWidget> m_widget; QDesignerLayoutDecorationExtension::InsertMode m_insertMode; - QPair<int, int> m_cell; + std::pair<int, int> m_cell; LayoutHelper* m_layoutHelper; bool m_widgetWasManaged; }; @@ -181,19 +158,17 @@ private: // Helper to correctly unmanage a widget and its children for delete operations class QDESIGNER_SHARED_EXPORT ManageWidgetCommandHelper { public: - using WidgetVector = QList<QWidget *>; - ManageWidgetCommandHelper(); void init(const QDesignerFormWindowInterface *fw, QWidget *widget); - void init(QWidget *widget, const WidgetVector &managedChildren); + void init(QWidget *widget, const QWidgetList &managedChildren); void manage(QDesignerFormWindowInterface *fw); void unmanage(QDesignerFormWindowInterface *fw); - const WidgetVector &managedChildren() const { return m_managedChildren; } + const QWidgetList &managedChildren() const { return m_managedChildren; } private: QWidget *m_widget = nullptr; - WidgetVector m_managedChildren; + QWidgetList m_managedChildren; }; class QDESIGNER_SHARED_EXPORT DeleteWidgetCommand: public QDesignerFormWindowCommand @@ -853,10 +828,14 @@ struct QDESIGNER_SHARED_EXPORT ItemData { void fillTreeItemColumn(QTreeWidgetItem *item, int column, DesignerIconCache *iconCache) const; bool isValid() const { return !m_properties.isEmpty(); } - bool operator==(const ItemData &rhs) const { return m_properties == rhs.m_properties; } - bool operator!=(const ItemData &rhs) const { return m_properties != rhs.m_properties; } QHash<int, QVariant> m_properties; + + friend bool comparesEqual(const ItemData &lhs, const ItemData &rhs) noexcept + { + return lhs.m_properties == rhs.m_properties; + } + Q_DECLARE_EQUALITY_COMPARABLE(ItemData) }; struct QDESIGNER_SHARED_EXPORT ListContents { @@ -872,18 +851,20 @@ struct QDESIGNER_SHARED_EXPORT ListContents { void createFromComboBox(const QComboBox *listWidget); void applyToComboBox(QComboBox *listWidget, DesignerIconCache *iconCache) const; - bool operator==(const ListContents &rhs) const { return m_items == rhs.m_items; } - bool operator!=(const ListContents &rhs) const { return m_items != rhs.m_items; } - QList<ItemData> m_items; + + friend bool comparesEqual(const ListContents &lhs, const ListContents &rhs) noexcept + { + return lhs.m_items == rhs.m_items; + } + Q_DECLARE_EQUALITY_COMPARABLE(ListContents) }; // Data structure representing the contents of a QTableWidget with // methods to retrieve and apply for ChangeTableContentsCommand struct QDESIGNER_SHARED_EXPORT TableWidgetContents { - using CellRowColumnAddress = QPair<int, int>; - using TableItemMap = QMap<CellRowColumnAddress, ItemData>; + using CellRowColumnAddress = std::pair<int, int>; TableWidgetContents(); void clear(); @@ -891,9 +872,6 @@ struct QDESIGNER_SHARED_EXPORT TableWidgetContents { void fromTableWidget(const QTableWidget *tableWidget, bool editor); void applyToTableWidget(QTableWidget *tableWidget, DesignerIconCache *iconCache, bool editor) const; - bool operator==(const TableWidgetContents &rhs) const; - bool operator!=(const TableWidgetContents &rhs) const { return !(*this == rhs); } - static bool nonEmpty(const QTableWidgetItem *item, int headerColumn); static QString defaultHeaderText(int i); static void insertHeaderItem(const QTableWidgetItem *item, int i, ListContents *header, bool editor); @@ -902,7 +880,12 @@ struct QDESIGNER_SHARED_EXPORT TableWidgetContents { int m_rowCount = 0; ListContents m_horizontalHeader; ListContents m_verticalHeader; - TableItemMap m_items; + QMap<CellRowColumnAddress, ItemData> m_items; + + friend QDESIGNER_SHARED_EXPORT + bool comparesEqual(const TableWidgetContents &lhs, + const TableWidgetContents &rhs) noexcept; + Q_DECLARE_EQUALITY_COMPARABLE(TableWidgetContents) }; class QDESIGNER_SHARED_EXPORT ChangeTableContentsCommand: public QDesignerFormWindowCommand @@ -930,14 +913,16 @@ struct QDESIGNER_SHARED_EXPORT TreeWidgetContents { ItemContents(const QTreeWidgetItem *item, bool editor); QTreeWidgetItem *createTreeItem(DesignerIconCache *iconCache, bool editor) const; - bool operator==(const ItemContents &rhs) const; - bool operator!=(const ItemContents &rhs) const { return !(*this == rhs); } - int m_itemFlags = -1; //bool m_firstColumnSpanned:1; //bool m_hidden:1; //bool m_expanded:1; QList<ItemContents> m_children; + + friend QDESIGNER_SHARED_EXPORT + bool comparesEqual(const ItemContents &lhs, + const ItemContents &rhs) noexcept; + Q_DECLARE_EQUALITY_COMPARABLE(ItemContents) }; void clear(); @@ -945,11 +930,15 @@ struct QDESIGNER_SHARED_EXPORT TreeWidgetContents { void fromTreeWidget(const QTreeWidget *treeWidget, bool editor); void applyToTreeWidget(QTreeWidget *treeWidget, DesignerIconCache *iconCache, bool editor) const; - bool operator==(const TreeWidgetContents &rhs) const; - bool operator!=(const TreeWidgetContents &rhs) const { return !(*this == rhs); } - ListContents m_headerItem; QList<ItemContents> m_rootItems; + + friend bool comparesEqual(const TreeWidgetContents &lhs, + const TreeWidgetContents &rhs) noexcept + { + return lhs.m_headerItem == rhs.m_headerItem && lhs.m_rootItems == rhs.m_rootItems; + } + Q_DECLARE_EQUALITY_COMPARABLE(TreeWidgetContents) }; class QDESIGNER_SHARED_EXPORT ChangeTreeContentsCommand: public QDesignerFormWindowCommand diff --git a/src/designer/src/lib/shared/qdesigner_dnditem.cpp b/src/designer/src/lib/shared/qdesigner_dnditem.cpp index 4a7864372..d7875f55c 100644 --- a/src/designer/src/lib/shared/qdesigner_dnditem.cpp +++ b/src/designer/src/lib/shared/qdesigner_dnditem.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 "qdesigner_dnditem_p.h" #include "formwindowbase_p.h" @@ -146,8 +121,8 @@ QDesignerMimeData::QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag break; default: { // determine size of drag decoration by uniting all geometries - const QDesignerDnDItems::const_iterator cend = m_items.constEnd(); - QDesignerDnDItems::const_iterator it =m_items.constBegin(); + const auto cend = m_items.cend(); + auto it = m_items.cbegin(); QRect unitedGeometry = (*it)->decoration()->geometry(); const qreal devicePixelRatio = (*it)->decoration()->devicePixelRatioF(); for (++it; it != cend; ++it ) @@ -165,8 +140,8 @@ QDesignerMimeData::QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag QPainter painter(&image); QPainter maskPainter(&mask); decorationTopLeft = unitedGeometry.topLeft(); - for (it = m_items.constBegin() ; it != cend; ++it ) { - QWidget *w = (*it)->decoration(); + for (auto *item : std::as_const(m_items)) { + QWidget *w = item->decoration(); const QPixmap wp = w->grab(QRect(0, 0, -1, -1)); const QPoint pos = w->pos() - decorationTopLeft; painter.drawPixmap(pos, wp); @@ -194,9 +169,7 @@ QDesignerMimeData::QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag QDesignerMimeData::~QDesignerMimeData() { - const QDesignerDnDItems::const_iterator cend = m_items.constEnd(); - for (QDesignerDnDItems::const_iterator it = m_items.constBegin(); it != cend; ++it ) - delete *it; + qDeleteAll(m_items); } Qt::DropAction QDesignerMimeData::proposedDropAction() const @@ -214,16 +187,17 @@ Qt::DropAction QDesignerMimeData::execDrag(const QDesignerDnDItems &items, QWidg // Store pointers to widgets that are to be re-shown if a move operation is canceled QWidgetList reshowWidgets; - const QDesignerDnDItems::const_iterator cend = items.constEnd(); - for (QDesignerDnDItems::const_iterator it = items.constBegin(); it != cend; ++it ) - if (QWidget *w = (*it)->widget()) - if ((*it)->type() == QDesignerDnDItemInterface::MoveDrop) + for (auto *item : items) { + if (QWidget *w = item->widget()) { + if (item->type() == QDesignerDnDItemInterface::MoveDrop) reshowWidgets.push_back(w); + } + } const Qt::DropAction executedAction = drag->exec(Qt::CopyAction|Qt::MoveAction, mimeData->proposedDropAction()); if (executedAction == Qt::IgnoreAction) { - for (QWidget *w : qAsConst(reshowWidgets)) + for (QWidget *w : std::as_const(reshowWidgets)) w->show(); } @@ -234,24 +208,24 @@ Qt::DropAction QDesignerMimeData::execDrag(const QDesignerDnDItems &items, QWidg void QDesignerMimeData::moveDecoration(const QPoint &globalPos) const { const QPoint relativeDistance = globalPos - m_globalStartPos; - const QDesignerDnDItems::const_iterator cend = m_items.constEnd(); - for (QDesignerDnDItems::const_iterator it =m_items.constBegin(); it != cend; ++it ) { - QWidget *w = (*it)->decoration(); + for (auto *item : m_items) { + QWidget *w = item->decoration(); w->move(w->pos() + relativeDistance); } } void QDesignerMimeData::removeMovedWidgetsFromSourceForm(const QDesignerDnDItems &items) { - typedef QMultiMap<FormWindowBase *, QWidget *> FormWidgetMap; - FormWidgetMap formWidgetMap; + QMultiMap<FormWindowBase *, QWidget *> formWidgetMap; // Find moved widgets per form - const QDesignerDnDItems::const_iterator cend = items.constEnd(); - for (QDesignerDnDItems::const_iterator it = items.constBegin(); it != cend; ++it ) - if ((*it)->type() == QDesignerDnDItemInterface::MoveDrop) - if (QWidget *w = (*it)->widget()) - if (FormWindowBase *fb = qobject_cast<FormWindowBase *>((*it)->source())) + for (auto *item : items) { + if (item->type() == QDesignerDnDItemInterface::MoveDrop) { + if (QWidget *w = item->widget()) { + if (FormWindowBase *fb = qobject_cast<FormWindowBase *>(item->source())) formWidgetMap.insert(fb, w); + } + } + } const auto &formWindows = formWidgetMap.uniqueKeys(); for (FormWindowBase *fb : formWindows) diff --git a/src/designer/src/lib/shared/qdesigner_dnditem_p.h b/src/designer/src/lib/shared/qdesigner_dnditem_p.h index 36419389b..aecd626a9 100644 --- a/src/designer/src/lib/shared/qdesigner_dnditem_p.h +++ b/src/designer/src/lib/shared/qdesigner_dnditem_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_dockwidget.cpp b/src/designer/src/lib/shared/qdesigner_dockwidget.cpp index d29fcaba2..9b857efff 100644 --- a/src/designer/src/lib/shared/qdesigner_dockwidget.cpp +++ b/src/designer/src/lib/shared/qdesigner_dockwidget.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 "qdesigner_dockwidget_p.h" #include "layoutinfo_p.h" @@ -42,12 +17,14 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + bool QDockWidgetPropertySheet::isEnabled(int index) const { const QString &name = propertyName(index); - if (name == QLatin1String("dockWidgetArea")) + if (name == "dockWidgetArea"_L1) return static_cast<const QDesignerDockWidget *>(object())->docked(); - if (name == QLatin1String("docked")) + if (name == "docked"_L1) return static_cast<const QDesignerDockWidget *>(object())->inMainWindow(); return QDesignerPropertySheet::isEnabled(index); } diff --git a/src/designer/src/lib/shared/qdesigner_dockwidget_p.h b/src/designer/src/lib/shared/qdesigner_dockwidget_p.h index a39ece90d..f8031c045 100644 --- a/src/designer/src/lib/shared/qdesigner_dockwidget_p.h +++ b/src/designer/src/lib/shared/qdesigner_dockwidget_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_formbuilder.cpp b/src/designer/src/lib/shared/qdesigner_formbuilder.cpp index 3b25125af..ff52bfd4b 100644 --- a/src/designer/src/lib/shared/qdesigner_formbuilder.cpp +++ b/src/designer/src/lib/shared/qdesigner_formbuilder.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 "qdesigner_formbuilder_p.h" #include "dynamicpropertysheet.h" @@ -69,6 +44,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { QDesignerFormBuilder::QDesignerFormBuilder(QDesignerFormEditorInterface *core, @@ -123,11 +100,11 @@ QWidget *QDesignerFormBuilder::createWidget(const QString &widgetName, QWidget * { QWidget *widget = nullptr; - if (widgetName == QStringLiteral("QToolBar")) { + if (widgetName == "QToolBar"_L1) { widget = new QToolBar(parentWidget); - } else if (widgetName == QStringLiteral("QMenu")) { + } else if (widgetName == "QMenu"_L1) { widget = new QMenu(parentWidget); - } else if (widgetName == QStringLiteral("QMenuBar")) { + } else if (widgetName == "QMenuBar"_L1) { widget = new QMenuBar(parentWidget); } else { widget = core()->widgetFactory()->createWidget(widgetName, parentWidget); @@ -231,7 +208,7 @@ void QDesignerFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), o); const QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core()->extensionManager(), o); - const bool changingMetaObject = WidgetFactory::classNameOf(core(), o) == QStringLiteral("QAxWidget"); + const bool changingMetaObject = WidgetFactory::classNameOf(core(), o) == "QAxWidget"_L1; const QDesignerMetaObjectInterface *meta = core()->introspection()->metaObject(o); const bool dynamicPropertiesAllowed = dynamicSheet && dynamicSheet->dynamicPropertiesAllowed(); @@ -267,7 +244,7 @@ void QDesignerFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> QObject *obj = o; QAbstractScrollArea *scroll = qobject_cast<QAbstractScrollArea *>(o); - if (scroll && attributeName == QStringLiteral("cursor") && scroll->viewport()) + if (scroll && attributeName == "cursor"_L1 && scroll->viewport()) obj = scroll->viewport(); // a real property @@ -346,12 +323,8 @@ QWidget *QDesignerFormBuilder::createPreview(const QDesignerFormWindowInterface } // Fake application style sheet by prepending. (If this doesn't work, fake by nesting // into parent widget). - if (!appStyleSheet.isEmpty()) { - QString styleSheet = appStyleSheet; - styleSheet += QLatin1Char('\n'); - styleSheet += widget->styleSheet(); - widget->setStyleSheet(styleSheet); - } + if (!appStyleSheet.isEmpty()) + widget->setStyleSheet(appStyleSheet + u'\n' + widget->styleSheet()); return widget; } diff --git a/src/designer/src/lib/shared/qdesigner_formbuilder_p.h b/src/designer/src/lib/shared/qdesigner_formbuilder_p.h index ceaf1b395..a4652f60a 100644 --- a/src/designer/src/lib/shared/qdesigner_formbuilder_p.h +++ b/src/designer/src/lib/shared/qdesigner_formbuilder_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_formeditorcommand.cpp b/src/designer/src/lib/shared/qdesigner_formeditorcommand.cpp index 926bc0b3d..89727103f 100644 --- a/src/designer/src/lib/shared/qdesigner_formeditorcommand.cpp +++ b/src/designer/src/lib/shared/qdesigner_formeditorcommand.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 "qdesigner_formeditorcommand_p.h" diff --git a/src/designer/src/lib/shared/qdesigner_formeditorcommand_p.h b/src/designer/src/lib/shared/qdesigner_formeditorcommand_p.h index 071c090c6..8b7d8c9ac 100644 --- a/src/designer/src/lib/shared/qdesigner_formeditorcommand_p.h +++ b/src/designer/src/lib/shared/qdesigner_formeditorcommand_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_formwindowcommand.cpp b/src/designer/src/lib/shared/qdesigner_formwindowcommand.cpp index 190540db2..48687277e 100644 --- a/src/designer/src/lib/shared/qdesigner_formwindowcommand.cpp +++ b/src/designer/src/lib/shared/qdesigner_formwindowcommand.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 "qdesigner_formwindowcommand_p.h" @@ -46,6 +21,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { // ---- QDesignerFormWindowCommand ---- @@ -104,7 +81,7 @@ void QDesignerFormWindowCommand::updateBuddies(QDesignerFormWindowInterface *for if (label_list.isEmpty()) return; - const QString buddyProperty = QStringLiteral("buddy"); + const QString buddyProperty = u"buddy"_s; const QByteArray oldNameU8 = old_name.toUtf8(); const QByteArray newNameU8 = new_name.toUtf8(); diff --git a/src/designer/src/lib/shared/qdesigner_formwindowcommand_p.h b/src/designer/src/lib/shared/qdesigner_formwindowcommand_p.h index ff5328792..a2d2ad165 100644 --- a/src/designer/src/lib/shared/qdesigner_formwindowcommand_p.h +++ b/src/designer/src/lib/shared/qdesigner_formwindowcommand_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_formwindowmanager.cpp b/src/designer/src/lib/shared/qdesigner_formwindowmanager.cpp index 243a2cac7..449161993 100644 --- a/src/designer/src/lib/shared/qdesigner_formwindowmanager.cpp +++ b/src/designer/src/lib/shared/qdesigner_formwindowmanager.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 "qdesigner_formwindowmanager_p.h" #include "plugindialog_p.h" @@ -33,7 +8,7 @@ QT_BEGIN_NAMESPACE -using namespace qdesigner_internal; +namespace qdesigner_internal { /*! \class qdesigner_internal::QDesignerFormWindowManager @@ -71,4 +46,6 @@ void QDesignerFormWindowManager::showPluginDialog() dlg.exec(); } +} // namespace qdesigner_internal + QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/qdesigner_formwindowmanager_p.h b/src/designer/src/lib/shared/qdesigner_formwindowmanager_p.h index 5ee960fd8..e4864d710 100644 --- a/src/designer/src/lib/shared/qdesigner_formwindowmanager_p.h +++ b/src/designer/src/lib/shared/qdesigner_formwindowmanager_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_introspection.cpp b/src/designer/src/lib/shared/qdesigner_introspection.cpp index 89dc6350e..60a4272d7 100644 --- a/src/designer/src/lib/shared/qdesigner_introspection.cpp +++ b/src/designer/src/lib/shared/qdesigner_introspection.cpp @@ -1,39 +1,17 @@ -/**************************************************************************** -** -** 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 "qdesigner_introspection_p.h" +#include <QtCore/qobject.h> #include <QtCore/qlist.h> #include <QtCore/qmetaobject.h> #include <QtCore/qstringlist.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // Qt Implementation static QStringList byteArrayListToStringList(const QByteArrayList &l) { @@ -63,6 +41,7 @@ namespace { int keyToValue(const QString &key) const override { return m_enum.keyToValue(key.toUtf8()); } int keysToValue(const QString &keys) const override { return m_enum.keysToValue(keys.toUtf8()); } QString name() const override { return m_name; } + QString enumName() const override { return charToQString(m_enum.enumName()); } QString scope() const override { return m_scope; } QString separator() const override; int value(int index) const override { return m_enum.value(index); } @@ -84,8 +63,7 @@ namespace { QString QDesignerMetaEnum::separator() const { - static const QString rc = QStringLiteral("::"); - return rc; + return u"::"_s; } // ------- QDesignerMetaProperty @@ -343,7 +321,7 @@ namespace qdesigner_internal { const QDesignerMetaObjectInterface* QDesignerIntrospection::metaObjectForQMetaObject(const QMetaObject *metaObject) const { - MetaObjectMap::iterator it = m_metaObjectMap.find(metaObject); + auto it = m_metaObjectMap.find(metaObject); if (it == m_metaObjectMap.end()) it = m_metaObjectMap.insert(metaObject, new QDesignerMetaObject(this, metaObject)); return it.value(); diff --git a/src/designer/src/lib/shared/qdesigner_introspection_p.h b/src/designer/src/lib/shared/qdesigner_introspection_p.h index 6c4d37e4d..1cdf0aa4f 100644 --- a/src/designer/src/lib/shared/qdesigner_introspection_p.h +++ b/src/designer/src/lib/shared/qdesigner_introspection_p.h @@ -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 // // W A R N I N G @@ -42,7 +17,7 @@ #include "shared_global_p.h" #include <abstractintrospection_p.h> -#include <QtCore/qmap.h> +#include <QtCore/qhash.h> QT_BEGIN_NAMESPACE @@ -59,10 +34,9 @@ namespace qdesigner_internal { const QDesignerMetaObjectInterface* metaObject(const QObject *object) const override; const QDesignerMetaObjectInterface* metaObjectForQMetaObject(const QMetaObject *metaObject) const; - private: - using MetaObjectMap = QMap<const QMetaObject*, QDesignerMetaObjectInterface*>; - mutable MetaObjectMap m_metaObjectMap; + private: + mutable QHash<const QMetaObject *, QDesignerMetaObjectInterface *> m_metaObjectMap; }; } diff --git a/src/designer/src/lib/shared/qdesigner_membersheet.cpp b/src/designer/src/lib/shared/qdesigner_membersheet.cpp index 2e62aab7f..5451222fe 100644 --- a/src/designer/src/lib/shared/qdesigner_membersheet.cpp +++ b/src/designer/src/lib/shared/qdesigner_membersheet.cpp @@ -1,64 +1,26 @@ -/**************************************************************************** -** -** 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 "qdesigner_membersheet_p.h" +#include "qdesigner_propertysheet_p.h" #include <QtDesigner/abstractformeditor.h> #include <abstractintrospection_p.h> #include <QtWidgets/qwidget.h> + QT_BEGIN_NAMESPACE -static QList<QByteArray> stringListToByteArray(const QStringList &l) +using namespace Qt::StringLiterals; + +static QByteArrayList stringListToByteArray(const QStringList &l) { - if (l.isEmpty()) - return QList<QByteArray>(); - QList<QByteArray> rc; - const QStringList::const_iterator cend = l.constEnd(); - for (QStringList::const_iterator it = l.constBegin(); it != cend; ++it) - rc += it->toUtf8(); + QByteArrayList rc; + for (const auto &s : l) + rc += s.toUtf8(); return rc; } -// Find the form editor in the hierarchy. -// We know that the parent of the sheet is the extension manager -// whose parent is the core. - -static QDesignerFormEditorInterface *formEditorForObject(QObject *o) { - do { - if (QDesignerFormEditorInterface* core = qobject_cast<QDesignerFormEditorInterface*>(o)) - return core; - o = o->parent(); - } while(o); - Q_ASSERT(o); - return nullptr; -} - // ------------ QDesignerMemberSheetPrivate class QDesignerMemberSheetPrivate { public: @@ -73,25 +35,22 @@ public: bool visible{true}; }; - using InfoHash = QHash<int, Info>; - Info &ensureInfo(int index); - InfoHash m_info; + QHash<int, Info> m_info; }; QDesignerMemberSheetPrivate::QDesignerMemberSheetPrivate(QObject *object, QObject *sheetParent) : - m_core(formEditorForObject(sheetParent)), + m_core(QDesignerPropertySheet::formEditorForObject(sheetParent)), m_meta(m_core->introspection()->metaObject(object)) { } QDesignerMemberSheetPrivate::Info &QDesignerMemberSheetPrivate::ensureInfo(int index) { - InfoHash::iterator it = m_info.find(index); - if (it == m_info.end()) { + auto it = m_info.find(index); + if (it == m_info.end()) it = m_info.insert(index, Info()); - } return it.value(); } @@ -183,7 +142,7 @@ bool QDesignerMemberSheet::isSlot(int index) const bool QDesignerMemberSheet::inheritedFromWidget(int index) const { - return declaredInClass(index) == QStringLiteral("QWidget") || declaredInClass(index) == QStringLiteral("QObject"); + return declaredInClass(index) == "QWidget"_L1 || declaredInClass(index) == "QObject"_L1; } @@ -202,24 +161,24 @@ bool QDesignerMemberSheet::signalMatchesSlot(const QString &signal, const QStrin bool result = true; do { - int signal_idx = signal.indexOf(QLatin1Char('(')); - int slot_idx = slot.indexOf(QLatin1Char('(')); + qsizetype signal_idx = signal.indexOf(u'('); + qsizetype slot_idx = slot.indexOf(u'('); if (signal_idx == -1 || slot_idx == -1) break; ++signal_idx; ++slot_idx; - if (slot.at(slot_idx) == QLatin1Char(')')) + if (slot.at(slot_idx) == u')') break; while (signal_idx < signal.size() && slot_idx < slot.size()) { const QChar signal_c = signal.at(signal_idx); const QChar slot_c = slot.at(slot_idx); - if (signal_c == QLatin1Char(',') && slot_c == QLatin1Char(')')) + if (signal_c == u',' && slot_c == u')') break; - if (signal_c == QLatin1Char(')') && slot_c == QLatin1Char(')')) + if (signal_c == u')' && slot_c == u')') break; if (signal_c != slot_c) { diff --git a/src/designer/src/lib/shared/qdesigner_membersheet_p.h b/src/designer/src/lib/shared/qdesigner_membersheet_p.h index b67ad3792..b8df5e2fb 100644 --- a/src/designer/src/lib/shared/qdesigner_membersheet_p.h +++ b/src/designer/src/lib/shared/qdesigner_membersheet_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_menu.cpp b/src/designer/src/lib/shared/qdesigner_menu.cpp index 35a116bae..c19f98dec 100644 --- a/src/designer/src/lib/shared/qdesigner_menu.cpp +++ b/src/designer/src/lib/shared/qdesigner_menu.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 "qdesigner_menu_p.h" #include "qdesigner_menubar_p.h" @@ -56,11 +31,9 @@ #include <QtCore/qtimer.h> #include <QtCore/qdebug.h> -Q_DECLARE_METATYPE(QAction*) - QT_BEGIN_NAMESPACE -using namespace qdesigner_internal; +using namespace Qt::StringLiterals; // give the user a little more space to click on the sub menu rectangle static inline void extendClickableArea(QRect *subMenuRect, Qt::LayoutDirection dir) @@ -78,10 +51,10 @@ static inline void extendClickableArea(QRect *subMenuRect, Qt::LayoutDirection d QDesignerMenu::QDesignerMenu(QWidget *parent) : QMenu(parent), - m_subMenuPixmap(QPixmap(QStringLiteral(":/qt-project.org/formeditor/images/submenu.png"))), + m_subMenuPixmap(QPixmap(u":/qt-project.org/formeditor/images/submenu.png"_s)), m_currentIndex(0), - m_addItem(new SpecialMenuAction(this)), - m_addSeparator(new SpecialMenuAction(this)), + m_addItem(new qdesigner_internal::SpecialMenuAction(this)), + m_addSeparator(new qdesigner_internal::SpecialMenuAction(this)), m_showSubMenuTimer(new QTimer(this)), m_deactivateWindowTimer(new QTimer(this)), m_adjustSizeTimer(new QTimer(this)), @@ -104,7 +77,7 @@ QDesignerMenu::QDesignerMenu(QWidget *parent) : connect(m_deactivateWindowTimer, &QTimer::timeout, this, &QDesignerMenu::slotDeactivateNow); - m_editor->setObjectName(QStringLiteral("__qt__passive_editor")); + m_editor->setObjectName(u"__qt__passive_editor"_s); m_editor->hide(); m_editor->installEventFilter(this); @@ -152,6 +125,8 @@ bool QDesignerMenu::handleEvent(QWidget *widget, QEvent *event) void QDesignerMenu::startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers) { + using namespace qdesigner_internal; + const int index = findAction(pos); if (index >= realActionCount()) return; @@ -161,7 +136,7 @@ void QDesignerMenu::startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers QDesignerFormWindowInterface *fw = formWindow(); const Qt::DropAction dropAction = (modifiers & Qt::ControlModifier) ? Qt::CopyAction : Qt::MoveAction; if (dropAction == Qt::MoveAction) { - RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw); + auto *cmd = new RemoveActionFromCommand(fw); cmd->init(this, action, actions().at(index + 1)); fw->commandHistory()->push(cmd); } @@ -176,7 +151,7 @@ void QDesignerMenu::startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers if (drag->exec(dropAction) == Qt::IgnoreAction) { if (dropAction == Qt::MoveAction) { QAction *previous = safeActionAt(index); - InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); + auto *cmd = new InsertActionIntoCommand(fw); cmd->init(this, action, previous); fw->commandHistory()->push(cmd); } @@ -224,7 +199,7 @@ bool QDesignerMenu::handleKeyPressEvent(QWidget * /*widget*/, QKeyEvent *e) break; case Qt::Key_PageDown: - m_currentIndex = actions().count() - 1; + m_currentIndex = actions().size() - 1; break; case Qt::Key_Enter: @@ -460,7 +435,7 @@ bool QDesignerMenu::handleContextMenuEvent(QWidget *, QContextMenuEvent *event) const int index = findAction(mapFromGlobal(event->globalPos())); QAction *action = safeActionAt(index); - if (qobject_cast<SpecialMenuAction*>(action)) + if (qobject_cast<qdesigner_internal::SpecialMenuAction*>(action)) return true; QMenu menu; @@ -502,14 +477,14 @@ void QDesignerMenu::slotAddSeparator() fw->beginCommand(tr("Add separator")); QAction *sep = createAction(QString(), true); - InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); + auto *cmd = new qdesigner_internal::InsertActionIntoCommand(fw); cmd->init(this, sep, action_before); fw->commandHistory()->push(cmd); if (parentMenu()) { QAction *parent_action = parentMenu()->currentAction(); if (parent_action->menu() == nullptr) { - CreateSubmenuCommand *cmd = new CreateSubmenuCommand(fw); + auto *cmd = new qdesigner_internal::CreateSubmenuCommand(fw); cmd->init(parentMenu(), parentMenu()->currentAction()); fw->commandHistory()->push(cmd); } @@ -533,7 +508,7 @@ void QDesignerMenu::deleteAction(QAction *a) action_before = safeActionAt(pos + 1); QDesignerFormWindowInterface *fw = formWindow(); - RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw); + auto *cmd = new qdesigner_internal::RemoveActionFromCommand(fw); cmd->init(this, a, action_before); fw->commandHistory()->push(cmd); } @@ -549,7 +524,7 @@ QRect QDesignerMenu::subMenuPixmapRect(QAction *action) const bool QDesignerMenu::hasSubMenuPixmap(QAction *action) const { return action != nullptr - && qobject_cast<SpecialMenuAction*>(action) == 0 + && qobject_cast<qdesigner_internal::SpecialMenuAction*>(action) == nullptr && !action->isSeparator() && !action->menu() && canCreateSubMenu(action); @@ -563,6 +538,8 @@ void QDesignerMenu::showEvent ( QShowEvent * event ) void QDesignerMenu::paintEvent(QPaintEvent *event) { + using namespace qdesigner_internal; + QMenu::paintEvent(event); QPainter p(this); @@ -697,7 +674,7 @@ QDesignerMenu::ActionDragCheck QDesignerMenu::checkAction(QAction *action) const if (!action || (action->menu() && action->menu()->parentWidget() != const_cast<QDesignerMenu*>(this))) return NoActionDrag; // menu action!! nothing to do - if (!Utils::isObjectAncestorOf(formWindow()->mainContainer(), action)) + if (!qdesigner_internal::Utils::isObjectAncestorOf(formWindow()->mainContainer(), action)) return NoActionDrag; // the action belongs to another form window if (actions().contains(action)) @@ -708,7 +685,7 @@ QDesignerMenu::ActionDragCheck QDesignerMenu::checkAction(QAction *action) const void QDesignerMenu::dragEnterEvent(QDragEnterEvent *event) { - const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData()); + auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData()); if (!d || d->actionList().isEmpty()) { event->ignore(); return; @@ -740,7 +717,7 @@ void QDesignerMenu::dragMoveEvent(QDragMoveEvent *event) return; } - const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData()); + auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData()); if (!d || d->actionList().isEmpty()) { event->ignore(); return; @@ -785,7 +762,7 @@ void QDesignerMenu::dropEvent(QDropEvent *event) m_dragging = false; QDesignerFormWindowInterface *fw = formWindow(); - const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData()); + auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData()); if (!d || d->actionList().isEmpty()) { event->ignore(); return; @@ -794,10 +771,10 @@ void QDesignerMenu::dropEvent(QDropEvent *event) if (action && checkAction(action) == AcceptActionDrag) { event->acceptProposedAction(); int index = findAction(event->position().toPoint()); - index = qMin(index, actions().count() - 1); + index = qMin(index, actions().size() - 1); fw->beginCommand(tr("Insert action")); - InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); + auto *cmd = new qdesigner_internal::InsertActionIntoCommand(fw); cmd->init(this, action, safeActionAt(index)); fw->commandHistory()->push(cmd); @@ -806,7 +783,7 @@ void QDesignerMenu::dropEvent(QDropEvent *event) if (parentMenu()) { QAction *parent_action = parentMenu()->currentAction(); if (parent_action->menu() == nullptr) { - CreateSubmenuCommand *cmd = new CreateSubmenuCommand(fw); + auto *cmd = new qdesigner_internal::CreateSubmenuCommand(fw); cmd->init(parentMenu(), parentMenu()->currentAction(), action); fw->commandHistory()->push(cmd); } @@ -877,6 +854,8 @@ bool QDesignerMenu::hideSubMenuOnCursorKey() // Return false to indicate the event must be propagated to the menu bar. bool QDesignerMenu::showSubMenuOnCursorKey() { + using namespace qdesigner_internal; + const QAction *action = currentAction(); if (qobject_cast<const SpecialMenuAction*>(action) || action->isSeparator()) { @@ -924,7 +903,7 @@ void QDesignerMenu::moveUp(bool ctrl) void QDesignerMenu::moveDown(bool ctrl) { - if (m_currentIndex == actions().count() - 1) { + if (m_currentIndex == actions().size() - 1) { return; } @@ -932,7 +911,7 @@ void QDesignerMenu::moveDown(bool ctrl) (void) swap(m_currentIndex + 1, m_currentIndex); ++m_currentIndex; - m_currentIndex = qMin(actions().count() - 1, m_currentIndex); + m_currentIndex = qMin(actions().size() - 1, m_currentIndex); update(); if (!ctrl) selectCurrentAction(); @@ -940,7 +919,7 @@ void QDesignerMenu::moveDown(bool ctrl) QAction *QDesignerMenu::currentAction() const { - if (m_currentIndex < 0 || m_currentIndex >= actions().count()) + if (m_currentIndex < 0 || m_currentIndex >= actions().size()) return nullptr; return safeActionAt(m_currentIndex); @@ -948,11 +927,13 @@ QAction *QDesignerMenu::currentAction() const int QDesignerMenu::realActionCount() const { - return actions().count() - 2; // 2 fake actions + return actions().size() - 2; // 2 fake actions } void QDesignerMenu::selectCurrentAction() { + using namespace qdesigner_internal; + QAction *action = currentAction(); if (!action || action == m_addSeparator || action == m_addItem) return; @@ -982,6 +963,8 @@ void QDesignerMenu::selectCurrentAction() void QDesignerMenu::createRealMenuAction(QAction *action) { + using namespace qdesigner_internal; + if (action->menu()) return; // nothing to do @@ -998,7 +981,7 @@ void QDesignerMenu::createRealMenuAction(QAction *action) core->widgetFactory()->initialize(menu); - const QString niceObjectName = ActionEditor::actionTextToName(menu->title(), QStringLiteral("menu")); + const QString niceObjectName = ActionEditor::actionTextToName(menu->title(), u"menu"_s); menu->setObjectName(niceObjectName); core->metaDataBase()->add(menu); @@ -1035,16 +1018,15 @@ QDesignerMenu *QDesignerMenu::findOrCreateSubMenu(QAction *action) bool QDesignerMenu::canCreateSubMenu(QAction *action) const // ### improve it's a bit too slow { - const QWidgetList &associatedWidgets = action->associatedWidgets(); - for (const QWidget *aw : associatedWidgets) { - if (aw != this) { - if (const QMenu *m = qobject_cast<const QMenu *>(aw)) { + const QObjectList associatedObjects = action->associatedObjects(); + for (const QObject *ao : associatedObjects) { + if (ao != this) { + if (const QMenu *m = qobject_cast<const QMenu *>(ao)) { if (m->actions().contains(action)) return false; // sorry - } else { - if (const QToolBar *tb = qobject_cast<const QToolBar *>(aw)) - if (tb->actions().contains(action)) - return false; // sorry + } else if (const QToolBar *tb = qobject_cast<const QToolBar *>(ao)) { + if (tb->actions().contains(action)) + return false; // sorry } } } @@ -1095,6 +1077,8 @@ void QDesignerMenu::slotShowSubMenuNow() void QDesignerMenu::showSubMenu(QAction *action) { + using namespace qdesigner_internal; + m_showSubMenuTimer->stop(); if (m_editor->isVisible() || !action || qobject_cast<SpecialMenuAction*>(action) @@ -1148,14 +1132,14 @@ void QDesignerMenu::enterEditMode() fw->beginCommand(tr("Add separator")); QAction *sep = createAction(QString(), true); - InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); + auto *cmd = new qdesigner_internal::InsertActionIntoCommand(fw); cmd->init(this, sep, safeActionAt(realActionCount())); fw->commandHistory()->push(cmd); if (parentMenu()) { QAction *parent_action = parentMenu()->currentAction(); if (parent_action->menu() == nullptr) { - CreateSubmenuCommand *cmd = new CreateSubmenuCommand(fw); + auto *cmd = new qdesigner_internal::CreateSubmenuCommand(fw); cmd->init(parentMenu(), parentMenu()->currentAction()); fw->commandHistory()->push(cmd); } @@ -1170,6 +1154,8 @@ void QDesignerMenu::enterEditMode() void QDesignerMenu::leaveEditMode(LeaveEditMode mode) { + using namespace qdesigner_internal; + if (mode == Default) return; @@ -1183,19 +1169,19 @@ void QDesignerMenu::leaveEditMode(LeaveEditMode mode) Q_ASSERT(fw != nullptr); fw->beginCommand(QApplication::translate("Command", "Insert action")); action = createAction(ActionEditor::actionTextToName(m_editor->text())); - InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); + auto *cmd = new qdesigner_internal::InsertActionIntoCommand(fw); cmd->init(this, action, currentAction()); fw->commandHistory()->push(cmd); } - SetPropertyCommand *cmd = new SetPropertyCommand(fw); - cmd->init(action, QStringLiteral("text"), m_editor->text()); + auto *cmd = new qdesigner_internal::SetPropertyCommand(fw); + cmd->init(action, u"text"_s, m_editor->text()); fw->commandHistory()->push(cmd); if (parentMenu()) { QAction *parent_action = parentMenu()->currentAction(); if (parent_action->menu() == nullptr) { - CreateSubmenuCommand *cmd = new CreateSubmenuCommand(fw); + auto *cmd = new qdesigner_internal::CreateSubmenuCommand(fw); cmd->init(parentMenu(), parentMenu()->currentAction(), action); fw->commandHistory()->push(cmd); } @@ -1246,12 +1232,14 @@ QAction *QDesignerMenu::createAction(const QString &objectName, bool separator) { QDesignerFormWindowInterface *fw = formWindow(); Q_ASSERT(fw); - return ToolBarEventFilter::createAction(fw, objectName, separator); + return qdesigner_internal::ToolBarEventFilter::createAction(fw, objectName, separator); } // ### share with QDesignerMenu::swap bool QDesignerMenu::swap(int a, int b) { + using namespace qdesigner_internal; + const int left = qMin(a, b); int right = qMax(a, b); @@ -1274,21 +1262,21 @@ bool QDesignerMenu::swap(int a, int b) QAction *action_b_before = safeActionAt(right + 1); - RemoveActionFromCommand *cmd1 = new RemoveActionFromCommand(fw); + auto *cmd1 = new qdesigner_internal::RemoveActionFromCommand(fw); cmd1->init(this, action_b, action_b_before, false); fw->commandHistory()->push(cmd1); QAction *action_a_before = safeActionAt(left + 1); - InsertActionIntoCommand *cmd2 = new InsertActionIntoCommand(fw); + auto *cmd2 = new qdesigner_internal::InsertActionIntoCommand(fw); cmd2->init(this, action_b, action_a_before, false); fw->commandHistory()->push(cmd2); - RemoveActionFromCommand *cmd3 = new RemoveActionFromCommand(fw); + auto *cmd3 = new qdesigner_internal::RemoveActionFromCommand(fw); cmd3->init(this, action_a, action_b, false); fw->commandHistory()->push(cmd3); - InsertActionIntoCommand *cmd4 = new InsertActionIntoCommand(fw); + auto *cmd4 = new qdesigner_internal::InsertActionIntoCommand(fw); cmd4->init(this, action_a, action_b_before, true); fw->commandHistory()->push(cmd4); @@ -1299,7 +1287,7 @@ bool QDesignerMenu::swap(int a, int b) QAction *QDesignerMenu::safeActionAt(int index) const { - if (index < 0 || index >= actions().count()) + if (index < 0 || index >= actions().size()) return nullptr; return actions().at(index); @@ -1322,7 +1310,7 @@ void QDesignerMenu::deleteAction() action_before = safeActionAt(pos + 1); QDesignerFormWindowInterface *fw = formWindow(); - RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw); + auto *cmd = new qdesigner_internal::RemoveActionFromCommand(fw); cmd->init(this, action, action_before); fw->commandHistory()->push(cmd); diff --git a/src/designer/src/lib/shared/qdesigner_menu_p.h b/src/designer/src/lib/shared/qdesigner_menu_p.h index 1093961eb..a3212ad69 100644 --- a/src/designer/src/lib/shared/qdesigner_menu_p.h +++ b/src/designer/src/lib/shared/qdesigner_menu_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_menubar.cpp b/src/designer/src/lib/shared/qdesigner_menubar.cpp index 51bab619e..7b442ed31 100644 --- a/src/designer/src/lib/shared/qdesigner_menubar.cpp +++ b/src/designer/src/lib/shared/qdesigner_menubar.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 "qdesigner_menubar_p.h" #include "qdesigner_menu_p.h" @@ -52,13 +27,11 @@ #include <QtGui/qpainter.h> #include <QtGui/qevent.h> -Q_DECLARE_METATYPE(QAction*) - QT_BEGIN_NAMESPACE -using ActionList = QList<QAction *>; +using namespace Qt::StringLiterals; -using namespace qdesigner_internal; +using ActionList = QList<QAction *>; namespace qdesigner_internal { @@ -77,9 +50,9 @@ SpecialMenuAction::~SpecialMenuAction() = default; ///////////////////////////////////////////////////////////////////////////////////////////////////////// QDesignerMenuBar::QDesignerMenuBar(QWidget *parent) : QMenuBar(parent), - m_addMenu(new SpecialMenuAction(this)), + m_addMenu(new qdesigner_internal::SpecialMenuAction(this)), m_editor(new QLineEdit(this)), - m_promotionTaskMenu(new PromotionTaskMenu(this, PromotionTaskMenu::ModeSingleWidget, this)) + m_promotionTaskMenu(new qdesigner_internal::PromotionTaskMenu(this, qdesigner_internal::PromotionTaskMenu::ModeSingleWidget, this)) { setContextMenuPolicy(Qt::DefaultContextMenu); @@ -94,7 +67,7 @@ QDesignerMenuBar::QDesignerMenuBar(QWidget *parent) : italic.setItalic(true); m_addMenu->setFont(italic); - m_editor->setObjectName(QStringLiteral("__qt__passive_editor")); + m_editor->setObjectName(u"__qt__passive_editor"_s); m_editor->hide(); m_editor->installEventFilter(this); installEventFilter(this); @@ -110,7 +83,7 @@ void QDesignerMenuBar::paintEvent(QPaintEvent *event) const auto &actionList = actions(); for (QAction *a : actionList) { - if (qobject_cast<SpecialMenuAction*>(a)) { + if (qobject_cast<qdesigner_internal::SpecialMenuAction*>(a)) { const QRect g = actionGeometry(a); QLinearGradient lg(g.left(), g.top(), g.left(), g.bottom()); lg.setColorAt(0.0, Qt::transparent); @@ -223,7 +196,7 @@ bool QDesignerMenuBar::handleKeyPressEvent(QWidget *, QKeyEvent *e) break; case Qt::Key_PageDown: - m_currentIndex = actions().count() - 1; + m_currentIndex = actions().size() - 1; break; case Qt::Key_Enter: @@ -287,6 +260,8 @@ bool QDesignerMenuBar::handleKeyPressEvent(QWidget *, QKeyEvent *e) void QDesignerMenuBar::startDrag(const QPoint &pos) { + using namespace qdesigner_internal; + const int index = findAction(pos); if (m_currentIndex == -1 || index >= realActionCount()) return; @@ -294,7 +269,7 @@ void QDesignerMenuBar::startDrag(const QPoint &pos) QAction *action = safeActionAt(index); QDesignerFormWindowInterface *fw = formWindow(); - RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw); + auto *cmd = new qdesigner_internal::RemoveActionFromCommand(fw); cmd->init(this, action, actions().at(index + 1)); fw->commandHistory()->push(cmd); @@ -310,7 +285,7 @@ void QDesignerMenuBar::startDrag(const QPoint &pos) m_currentIndex = -1; if (drag->exec(Qt::MoveAction) == Qt::IgnoreAction) { - InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); + auto *cmd = new qdesigner_internal::InsertActionIntoCommand(fw); cmd->init(this, action, safeActionAt(index)); fw->commandHistory()->push(cmd); @@ -365,7 +340,7 @@ bool QDesignerMenuBar::handleMouseMoveEvent(QWidget *, QMouseEvent *event) return true; const int index = actionIndexAt(this, m_startPosition, Qt::Horizontal); - if (index < actions().count()) { + if (index < actions().size()) { hideMenu(index); update(); } @@ -378,6 +353,8 @@ bool QDesignerMenuBar::handleMouseMoveEvent(QWidget *, QMouseEvent *event) ActionList QDesignerMenuBar::contextMenuActions() { + using namespace qdesigner_internal; + ActionList rc; if (QAction *action = safeActionAt(m_currentIndex)) { if (!qobject_cast<SpecialMenuAction*>(action)) { @@ -412,9 +389,8 @@ bool QDesignerMenuBar::handleContextMenuEvent(QWidget *, QContextMenuEvent *even QMenu menu; const ActionList al = contextMenuActions(); - const ActionList::const_iterator acend = al.constEnd(); - for (ActionList::const_iterator it = al.constBegin(); it != acend; ++it) - menu.addAction(*it); + for (auto *a : al) + menu.addAction(a); menu.exec(event->globalPos()); return true; } @@ -425,7 +401,7 @@ void QDesignerMenuBar::slotRemoveMenuBar() QDesignerFormWindowInterface *fw = formWindow(); - DeleteMenuBarCommand *cmd = new DeleteMenuBarCommand(fw); + auto *cmd = new qdesigner_internal::DeleteMenuBarCommand(fw); cmd->init(this); fw->commandHistory()->push(cmd); } @@ -444,6 +420,8 @@ void QDesignerMenuBar::enterEditMode() void QDesignerMenuBar::leaveEditMode(LeaveEditMode mode) { + using namespace qdesigner_internal; + m_editor->releaseKeyboard(); if (mode == Default) @@ -462,20 +440,20 @@ void QDesignerMenuBar::leaveEditMode(LeaveEditMode mode) fw->beginCommand(QApplication::translate("Command", "Change Title")); } else { fw->beginCommand(QApplication::translate("Command", "Insert Menu")); - const QString niceObjectName = ActionEditor::actionTextToName(m_editor->text(), QStringLiteral("menu")); - QMenu *menu = qobject_cast<QMenu*>(fw->core()->widgetFactory()->createWidget(QStringLiteral("QMenu"), this)); + const QString niceObjectName = ActionEditor::actionTextToName(m_editor->text(), u"menu"_s); + QMenu *menu = qobject_cast<QMenu*>(fw->core()->widgetFactory()->createWidget(u"QMenu"_s, this)); fw->core()->widgetFactory()->initialize(menu); menu->setObjectName(niceObjectName); menu->setTitle(tr("Menu")); fw->ensureUniqueObjectName(menu); action = menu->menuAction(); - AddMenuActionCommand *cmd = new AddMenuActionCommand(fw); + auto *cmd = new qdesigner_internal::AddMenuActionCommand(fw); cmd->init(action, m_addMenu, this, this); fw->commandHistory()->push(cmd); } - SetPropertyCommand *cmd = new SetPropertyCommand(fw); - cmd->init(action, QStringLiteral("text"), m_editor->text()); + auto *cmd = new qdesigner_internal::SetPropertyCommand(fw); + cmd->init(action, u"text"_s, m_editor->text()); fw->commandHistory()->push(cmd); fw->endCommand(); } @@ -503,7 +481,7 @@ void QDesignerMenuBar::showLineEdit() m_editor->selectAll(); m_editor->setGeometry(actionGeometry(action)); m_editor->show(); - qApp->setActiveWindow(m_editor); + m_editor->activateWindow(); m_editor->setFocus(); m_editor->grabKeyboard(); } @@ -585,7 +563,7 @@ void QDesignerMenuBar::adjustIndicator(const QPoint &pos) QDesignerMenuBar::ActionDragCheck QDesignerMenuBar::checkAction(QAction *action) const { // action belongs to another form - if (!action || !Utils::isObjectAncestorOf(formWindow()->mainContainer(), action)) + if (!action || !qdesigner_internal::Utils::isObjectAncestorOf(formWindow()->mainContainer(), action)) return NoActionDrag; if (!action->menu()) @@ -603,7 +581,7 @@ QDesignerMenuBar::ActionDragCheck QDesignerMenuBar::checkAction(QAction *action) void QDesignerMenuBar::dragEnterEvent(QDragEnterEvent *event) { - const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData()); + auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData()); if (!d || d->actionList().isEmpty()) { event->ignore(); return; @@ -628,7 +606,7 @@ void QDesignerMenuBar::dragEnterEvent(QDragEnterEvent *event) void QDesignerMenuBar::dragMoveEvent(QDragMoveEvent *event) { - const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData()); + auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData()); if (!d || d->actionList().isEmpty()) { event->ignore(); return; @@ -661,16 +639,16 @@ void QDesignerMenuBar::dropEvent(QDropEvent *event) { m_dragging = false; - if (const ActionRepositoryMimeData *d = qobject_cast<const ActionRepositoryMimeData*>(event->mimeData())) { + if (auto *d = qobject_cast<const qdesigner_internal::ActionRepositoryMimeData*>(event->mimeData())) { QAction *action = d->actionList().first(); if (checkAction(action) == AcceptActionDrag) { event->acceptProposedAction(); int index = findAction(event->position().toPoint()); - index = qMin(index, actions().count() - 1); + index = qMin(index, actions().size() - 1); QDesignerFormWindowInterface *fw = formWindow(); - InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); + auto *cmd = new qdesigner_internal::InsertActionIntoCommand(fw); cmd->init(this, action, safeActionAt(index)); fw->commandHistory()->push(cmd); @@ -705,7 +683,7 @@ QDesignerActionProviderExtension *QDesignerMenuBar::actionProvider() QAction *QDesignerMenuBar::currentAction() const { - if (m_currentIndex < 0 || m_currentIndex >= actions().count()) + if (m_currentIndex < 0 || m_currentIndex >= actions().size()) return nullptr; return safeActionAt(m_currentIndex); @@ -713,7 +691,7 @@ QAction *QDesignerMenuBar::currentAction() const int QDesignerMenuBar::realActionCount() const { - return actions().count() - 1; // 1 fake actions + return actions().size() - 1; // 1 fake actions } bool QDesignerMenuBar::dragging() const @@ -753,7 +731,7 @@ void QDesignerMenuBar::movePrevious(bool ctrl) void QDesignerMenuBar::moveNext(bool ctrl) { const bool swapped = ctrl && swapActions(m_currentIndex + 1, m_currentIndex); - const int newIndex = qMin(actions().count() - 1, m_currentIndex + 1); + const int newIndex = qMin(actions().size() - 1, m_currentIndex + 1); if (swapped || newIndex != m_currentIndex) { m_currentIndex = newIndex; updateCurrentAction(!ctrl); @@ -802,14 +780,14 @@ void QDesignerMenuBar::deleteMenu() void QDesignerMenuBar::deleteMenuAction(QAction *action) { - if (action && !qobject_cast<SpecialMenuAction*>(action)) { + if (action && !qobject_cast<qdesigner_internal::SpecialMenuAction*>(action)) { const int pos = actions().indexOf(action); QAction *action_before = nullptr; if (pos != -1) action_before = safeActionAt(pos + 1); QDesignerFormWindowInterface *fw = formWindow(); - RemoveMenuActionCommand *cmd = new RemoveMenuActionCommand(fw); + auto *cmd = new qdesigner_internal::RemoveMenuActionCommand(fw); cmd->init(action, action_before, this, this); fw->commandHistory()->push(cmd); } @@ -858,7 +836,7 @@ void QDesignerMenuBar::showMenu(int index) QAction *QDesignerMenuBar::safeActionAt(int index) const { - if (index < 0 || index >= actions().count()) + if (index < 0 || index >= actions().size()) return nullptr; return actions().at(index); @@ -866,6 +844,8 @@ QAction *QDesignerMenuBar::safeActionAt(int index) const bool QDesignerMenuBar::swapActions(int a, int b) { + using namespace qdesigner_internal; + const int left = qMin(a, b); int right = qMax(a, b); @@ -888,21 +868,21 @@ bool QDesignerMenuBar::swapActions(int a, int b) QAction *action_b_before = safeActionAt(right + 1); QDesignerFormWindowInterface *fw = formWindow(); - RemoveActionFromCommand *cmd1 = new RemoveActionFromCommand(fw); + auto *cmd1 = new qdesigner_internal::RemoveActionFromCommand(fw); cmd1->init(this, action_b, action_b_before, false); fw->commandHistory()->push(cmd1); QAction *action_a_before = safeActionAt(left + 1); - InsertActionIntoCommand *cmd2 = new InsertActionIntoCommand(fw); + auto *cmd2 = new qdesigner_internal::InsertActionIntoCommand(fw); cmd2->init(this, action_b, action_a_before, false); fw->commandHistory()->push(cmd2); - RemoveActionFromCommand *cmd3 = new RemoveActionFromCommand(fw); + auto *cmd3 = new qdesigner_internal::RemoveActionFromCommand(fw); cmd3->init(this, action_a, action_b, false); fw->commandHistory()->push(cmd3); - InsertActionIntoCommand *cmd4 = new InsertActionIntoCommand(fw); + auto *cmd4 = new qdesigner_internal::InsertActionIntoCommand(fw); cmd4->init(this, action_a, action_b_before, true); fw->commandHistory()->push(cmd4); @@ -923,6 +903,8 @@ void QDesignerMenuBar::keyReleaseEvent(QKeyEvent *event) void QDesignerMenuBar::updateCurrentAction(bool selectAction) { + using namespace qdesigner_internal; + update(); if (!selectAction) diff --git a/src/designer/src/lib/shared/qdesigner_menubar_p.h b/src/designer/src/lib/shared/qdesigner_menubar_p.h index 8b6e5383e..e1d02e3fa 100644 --- a/src/designer/src/lib/shared/qdesigner_menubar_p.h +++ b/src/designer/src/lib/shared/qdesigner_menubar_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_objectinspector.cpp b/src/designer/src/lib/shared/qdesigner_objectinspector.cpp index c672dca70..9d5465031 100644 --- a/src/designer/src/lib/shared/qdesigner_objectinspector.cpp +++ b/src/designer/src/lib/shared/qdesigner_objectinspector.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 "qdesigner_objectinspector_p.h" diff --git a/src/designer/src/lib/shared/qdesigner_objectinspector_p.h b/src/designer/src/lib/shared/qdesigner_objectinspector_p.h index be7925d6e..e43954392 100644 --- a/src/designer/src/lib/shared/qdesigner_objectinspector_p.h +++ b/src/designer/src/lib/shared/qdesigner_objectinspector_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_promotion.cpp b/src/designer/src/lib/shared/qdesigner_promotion.cpp index 08b2848fd..eb78dd413 100644 --- a/src/designer/src/lib/shared/qdesigner_promotion.cpp +++ b/src/designer/src/lib/shared/qdesigner_promotion.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 "qdesigner_promotion_p.h" #include "widgetdatabase_p.h" @@ -44,19 +19,20 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace { // Return a set of on-promotable classes const QSet<QString> &nonPromotableClasses() { - static QSet<QString> rc; - if (rc.isEmpty()) { - rc.insert(QStringLiteral("Line")); - rc.insert(QStringLiteral("QAction")); - rc.insert(QStringLiteral("Spacer")); - rc.insert(QStringLiteral("QMainWindow")); - rc.insert(QStringLiteral("QDialog")); - rc.insert(QStringLiteral("QMdiArea")); - rc.insert(QStringLiteral("QMdiSubWindow")); - } + static const QSet<QString> rc = { + u"Line"_s, + u"QAction"_s, + u"Spacer"_s, + u"QMainWindow"_s, + u"QDialog"_s, + u"QMdiArea"_s, + u"QMdiSubWindow"_s + }; return rc; } @@ -84,13 +60,14 @@ namespace { } // extract class name from xml "<widget class="QWidget" ...>". Quite a hack. - QString classNameFromXml(QString xml) { - static const QString tag = QStringLiteral("class=\""); + QString classNameFromXml(QString xml) + { + constexpr auto tag = "class=\""_L1; const int pos = xml.indexOf(tag); if (pos == -1) return QString(); xml.remove(0, pos + tag.size()); - const int closingPos = xml.indexOf(QLatin1Char('"')); + const auto closingPos = xml.indexOf(u'"'); if (closingPos == -1) return QString(); xml.remove(closingPos, xml.size() - closingPos); @@ -193,8 +170,7 @@ namespace qdesigner_internal { if (nonPromotableClasses().contains(name)) return false; - if (name.startsWith(QStringLiteral("QDesigner")) || - name.startsWith(QStringLiteral("QLayout"))) + if (name.startsWith("QDesigner"_L1) || name.startsWith("QLayout"_L1)) return false; return true; @@ -204,9 +180,7 @@ namespace qdesigner_internal { { using ClassNameItemMap = QMap<QString, QDesignerWidgetDataBaseItemInterface *>; // A map containing base classes and their promoted classes. - using BaseClassPromotedMap = QMap<QString, ClassNameItemMap>; - - BaseClassPromotedMap baseClassPromotedMap; + QMap<QString, ClassNameItemMap> baseClassPromotedMap; QDesignerWidgetDataBaseInterface *widgetDataBase = m_core->widgetDataBase(); // Look for promoted classes and insert into map according to base class. @@ -215,7 +189,7 @@ namespace qdesigner_internal { QDesignerWidgetDataBaseItemInterface *dbItem = widgetDataBase->item(i); if (dbItem->isPromoted()) { const QString baseClassName = dbItem->extends(); - BaseClassPromotedMap::iterator it = baseClassPromotedMap.find(baseClassName); + auto it = baseClassPromotedMap.find(baseClassName); if (it == baseClassPromotedMap.end()) { it = baseClassPromotedMap.insert(baseClassName, ClassNameItemMap()); } @@ -228,14 +202,12 @@ namespace qdesigner_internal { if (baseClassPromotedMap.isEmpty()) return rc; - const BaseClassPromotedMap::const_iterator bcend = baseClassPromotedMap.constEnd(); - for (BaseClassPromotedMap::const_iterator bit = baseClassPromotedMap.constBegin(); bit != bcend; ++bit) { + for (auto bit = baseClassPromotedMap.cbegin(), bcend = baseClassPromotedMap.cend(); bit != bcend; ++bit) { const int baseIndex = widgetDataBase->indexOfClassName(bit.key()); Q_ASSERT(baseIndex >= 0); QDesignerWidgetDataBaseItemInterface *baseItem = widgetDataBase->item(baseIndex); // promoted - const ClassNameItemMap::const_iterator pcend = bit.value().constEnd(); - for (ClassNameItemMap::const_iterator pit = bit.value().constBegin(); pit != pcend; ++pit) { + for (auto pit = bit.value().cbegin(), pcend = bit.value().cend(); pit != pcend; ++pit) { PromotedClass item; item.baseItem = baseItem; item.promotedItem = pit.value(); @@ -265,11 +237,10 @@ namespace qdesigner_internal { if (!scratchPadClasses.isEmpty()) { // Check whether these are actually promoted QDesignerWidgetDataBaseInterface *widgetDataBase = m_core->widgetDataBase(); - QStringList::const_iterator cend = scratchPadClasses.constEnd(); - for (QStringList::const_iterator it = scratchPadClasses.constBegin(); it != cend; ++it ) { - const int index = widgetDataBase->indexOfClassName(*it); + for (const auto &scItem : scratchPadClasses) { + const int index = widgetDataBase->indexOfClassName(scItem); if (index != -1 && widgetDataBase->item(index)->isPromoted()) - rc += *it; + rc.insert(scItem); } } } @@ -301,12 +272,12 @@ namespace qdesigner_internal { // class B will depend on it. When removing QWebView, the base class of B will // be changed to that of QWebView by the below code. const PromotedClasses promotedList = promotedClasses(); - for (PromotedClasses::const_iterator it = promotedList.constBegin(), end = promotedList.constEnd(); it != end; ++it) { - if (it->baseItem->name() == className) { + for (const auto &pc : promotedList) { + if (pc.baseItem->name() == className) { const QString extends = widgetDataBase->item(index)->extends(); - qWarning().nospace() << "Warning: Promoted class " << it->promotedItem->name() + qWarning().nospace() << "Warning: Promoted class " << pc.promotedItem->name() << " extends " << className << ", changing its base class to " << extends << '.'; - it->promotedItem->setExtends(extends); + pc.promotedItem->setExtends(extends); } } widgetDataBase->remove(index); diff --git a/src/designer/src/lib/shared/qdesigner_promotion_p.h b/src/designer/src/lib/shared/qdesigner_promotion_p.h index 3448fd999..e268296ac 100644 --- a/src/designer/src/lib/shared/qdesigner_promotion_p.h +++ b/src/designer/src/lib/shared/qdesigner_promotion_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_promotiondialog.cpp b/src/designer/src/lib/shared/qdesigner_promotiondialog.cpp index d8fc28acd..286ee3538 100644 --- a/src/designer/src/lib/shared/qdesigner_promotiondialog.cpp +++ b/src/designer/src/lib/shared/qdesigner_promotiondialog.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 "qdesigner_promotiondialog_p.h" #include "promotionmodel_p.h" @@ -60,6 +35,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { // PromotionParameters struct PromotionParameters { @@ -83,7 +60,7 @@ namespace qdesigner_internal { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); QHBoxLayout *hboxLayout = new QHBoxLayout(this); - m_classNameEdit->setValidator(new QRegularExpressionValidator(QRegularExpression(QStringLiteral("^[_a-zA-Z:][:_a-zA-Z0-9]*$")), m_classNameEdit)); + m_classNameEdit->setValidator(new QRegularExpressionValidator(QRegularExpression(u"^[_a-zA-Z:][:_a-zA-Z0-9]*$"_s), m_classNameEdit)); connect(m_classNameEdit, &QLineEdit::textChanged, this, &NewPromotedClassPanel::slotNameChanged); connect(m_includeFileEdit, &QLineEdit::textChanged, @@ -106,7 +83,7 @@ namespace qdesigner_internal { formLayout->addRow(label, m_includeFileEdit); m_includeFileEdit->setToolTip(toolTip); - toolTip = tr("Indicates that header file is a global header file. Does not have any effect on Qt for Python."); + toolTip = tr("Indicates that the header file is a global header file. Does not have any effect on Qt for Python."); label = new QLabel(tr("Global include")); label->setToolTip(toolTip); formLayout->addRow(label, m_globalIncludeCheckBox); @@ -154,12 +131,11 @@ namespace qdesigner_internal { void NewPromotedClassPanel::slotNameChanged(const QString &className) { // Suggest a name if (!className.isEmpty()) { - const QChar dot(QLatin1Char('.')); QString suggestedHeader = m_promotedHeaderLowerCase ? className.toLower() : className; - suggestedHeader.replace(QStringLiteral("::"), QString(QLatin1Char('_'))); - if (!m_promotedHeaderSuffix.startsWith(dot)) - suggestedHeader += dot; + suggestedHeader.replace("::"_L1, "_"_L1); + if (!m_promotedHeaderSuffix.startsWith(u'.')) + suggestedHeader += u'.'; suggestedHeader += m_promotedHeaderSuffix; const bool blocked = m_includeFileEdit->blockSignals(true); @@ -208,12 +184,11 @@ namespace qdesigner_internal { m_model(new PromotionModel(core)), m_treeView(new QTreeView), m_buttonBox(nullptr), - m_removeButton(new QPushButton(createIconSet(QString::fromUtf8("minus.png")), QString())) + m_removeButton(new QPushButton(createIconSet("minus.png"_L1), QString())) { m_buttonBox = createButtonBox(); setModal(true); setWindowTitle(tr("Promoted Widgets")); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); QVBoxLayout *vboxLayout = new QVBoxLayout(this); @@ -252,7 +227,7 @@ namespace qdesigner_internal { preselectedBaseClass = baseClassNameList.indexOf(m_promotableWidgetClassName); } if (preselectedBaseClass == -1) - preselectedBaseClass = baseClassNameList.indexOf(QStringLiteral("QFrame")); + preselectedBaseClass = baseClassNameList.indexOf("QFrame"_L1); NewPromotedClassPanel *newPromotedClassPanel = new NewPromotedClassPanel(baseClassNameList, preselectedBaseClass); newPromotedClassPanel->setPromotedHeaderSuffix(core->integration()->headerSuffix()); @@ -306,10 +281,8 @@ namespace qdesigner_internal { if (rc.isEmpty()) { // Convert the item list into a string list. const WidgetDataBaseItemList dbItems = promotion->promotionBaseClasses(); - const WidgetDataBaseItemList::const_iterator cend = dbItems.constEnd(); - for (WidgetDataBaseItemList::const_iterator it = dbItems.constBegin() ; it != cend; ++it) { - rc.push_back( (*it)->name()); - } + for (auto *item : dbItems) + rc.append(item->name()); } return rc; } diff --git a/src/designer/src/lib/shared/qdesigner_promotiondialog_p.h b/src/designer/src/lib/shared/qdesigner_promotiondialog_p.h index e9cb7d4fe..f39b2bd54 100644 --- a/src/designer/src/lib/shared/qdesigner_promotiondialog_p.h +++ b/src/designer/src/lib/shared/qdesigner_promotiondialog_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp index 223fd76ae..f24675e7b 100644 --- a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp +++ b/src/designer/src/lib/shared/qdesigner_propertycommand.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 "qdesigner_propertycommand_p.h" #include "qdesigner_utils_p.h" @@ -59,6 +34,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace { enum { debugPropertyCommands = 0 }; @@ -69,21 +46,21 @@ QString fontMask(unsigned m) { QString rc; if (m & QFontFamiliesResolved) - rc += QStringLiteral("Family"); + rc += "Family"_L1; if (m & QFont::SizeResolved) - rc += QStringLiteral("Size "); + rc += "Size "_L1; if (m & QFont::WeightResolved) - rc += QStringLiteral("Bold "); + rc += "Bold "_L1; if (m & QFont::StyleResolved) - rc += QStringLiteral("Style "); + rc += "Style "_L1; if (m & QFont::UnderlineResolved) - rc += QStringLiteral("Underline "); + rc += "Underline "_L1; if (m & QFont::StrikeOutResolved) - rc += QStringLiteral("StrikeOut "); + rc += "StrikeOut "_L1; if (m & QFont::KerningResolved) - rc += QStringLiteral("Kerning "); + rc += "Kerning "_L1; if (m & QFont::StyleStrategyResolved) - rc += QStringLiteral("StyleStrategy"); + rc += "StyleStrategy"_L1; return rc; } @@ -91,22 +68,20 @@ QString fontMask(unsigned m) QString fontString(const QFont &f) { QString rc; { - const QChar comma = QLatin1Char(','); QTextStream str(&rc); - str << QStringLiteral("QFont(\"") << f.family() << comma << - f.pointSize(); + str << "QFont(\"" << f.family() << ',' << f.pointSize(); if (f.bold()) - str << comma << QStringLiteral("bold"); + str << ',' << "bold"; if (f.italic()) - str << comma << QStringLiteral("italic"); + str << ',' << "italic"; if (f.underline()) - str << comma << QStringLiteral("underline"); + str << ',' << "underline"; if (f.strikeOut()) - str << comma << QStringLiteral("strikeOut"); + str << ',' << "strikeOut"; if (f.kerning()) - str << comma << QStringLiteral("kerning"); - str << comma << f.styleStrategy() << QStringLiteral(" resolve: ") - << fontMask(f.resolveMask()) << QLatin1Char(')'); + str << ',' << "kerning"; + str << ',' << f.styleStrategy() << " resolve: " + << fontMask(f.resolveMask()) << ')'; } return rc; } @@ -170,16 +145,16 @@ enum KeySequenceSubPropertyMask { SubPropertyKeySequenceValue = 1, SubPropertyKe SubPropertyKeySequenceTranslatable = 4, SubPropertyKeySequenceDisambiguation = 8, SubPropertyKeySequenceId = 16 }; -enum CommonSubPropertyMask { SubPropertyAll = 0xFFFFFFFF }; +enum CommonSubPropertyMask : quint64 { SubPropertyAll = quint64(-1) }; // Set the mask flag in mask if the properties do not match. #define COMPARE_SUBPROPERTY(object1, object2, getter, mask, maskFlag) \ if (object1.getter() != object2.getter()) (mask) |= (maskFlag); // find changed subproperties of a rectangle -unsigned compareSubProperties(const QRect & r1, const QRect & r2) +quint64 compareSubProperties(const QRect & r1, const QRect & r2) { - unsigned rc = 0; + quint64 rc = 0; COMPARE_SUBPROPERTY(r1, r2, x, rc, SubPropertyX) COMPARE_SUBPROPERTY(r1, r2, y, rc, SubPropertyY) COMPARE_SUBPROPERTY(r1, r2, width, rc, SubPropertyWidth) @@ -188,17 +163,17 @@ unsigned compareSubProperties(const QRect & r1, const QRect & r2) } // find changed subproperties of a QSize -unsigned compareSubProperties(const QSize & r1, const QSize & r2) +quint64 compareSubProperties(const QSize & r1, const QSize & r2) { - unsigned rc = 0; + quint64 rc = 0; COMPARE_SUBPROPERTY(r1, r2, width, rc, SubPropertyWidth) COMPARE_SUBPROPERTY(r1, r2, height, rc, SubPropertyHeight) return rc; } // find changed subproperties of a QSizePolicy -unsigned compareSubProperties(const QSizePolicy & sp1, const QSizePolicy & sp2) +quint64 compareSubProperties(const QSizePolicy & sp1, const QSizePolicy & sp2) { - unsigned rc = 0; + quint64 rc = 0; COMPARE_SUBPROPERTY(sp1, sp2, horizontalPolicy, rc, SubPropertyHSizePolicy) COMPARE_SUBPROPERTY(sp1, sp2, horizontalStretch, rc, SubPropertyHStretch) COMPARE_SUBPROPERTY(sp1, sp2, verticalPolicy, rc, SubPropertyVSizePolicy) @@ -206,9 +181,9 @@ unsigned compareSubProperties(const QSizePolicy & sp1, const QSizePolicy & sp2) return rc; } // find changed subproperties of qdesigner_internal::PropertySheetStringValue -unsigned compareSubProperties(const qdesigner_internal::PropertySheetStringValue & str1, const qdesigner_internal::PropertySheetStringValue & str2) +quint64 compareSubProperties(const qdesigner_internal::PropertySheetStringValue & str1, const qdesigner_internal::PropertySheetStringValue & str2) { - unsigned rc = 0; + quint64 rc = 0; COMPARE_SUBPROPERTY(str1, str2, value, rc, SubPropertyStringValue) COMPARE_SUBPROPERTY(str1, str2, comment, rc, SubPropertyStringComment) COMPARE_SUBPROPERTY(str1, str2, translatable, rc, SubPropertyStringTranslatable) @@ -217,9 +192,9 @@ unsigned compareSubProperties(const qdesigner_internal::PropertySheetStringValue return rc; } // find changed subproperties of qdesigner_internal::PropertySheetStringListValue -unsigned compareSubProperties(const qdesigner_internal::PropertySheetStringListValue & str1, const qdesigner_internal::PropertySheetStringListValue & str2) +quint64 compareSubProperties(const qdesigner_internal::PropertySheetStringListValue & str1, const qdesigner_internal::PropertySheetStringListValue & str2) { - unsigned rc = 0; + quint64 rc = 0; COMPARE_SUBPROPERTY(str1, str2, value, rc, SubPropertyStringListValue) COMPARE_SUBPROPERTY(str1, str2, comment, rc, SubPropertyStringListComment) COMPARE_SUBPROPERTY(str1, str2, translatable, rc, SubPropertyStringListTranslatable) @@ -228,9 +203,9 @@ unsigned compareSubProperties(const qdesigner_internal::PropertySheetStringListV return rc; } // find changed subproperties of qdesigner_internal::PropertySheetKeySequenceValue -unsigned compareSubProperties(const qdesigner_internal::PropertySheetKeySequenceValue & str1, const qdesigner_internal::PropertySheetKeySequenceValue & str2) +quint64 compareSubProperties(const qdesigner_internal::PropertySheetKeySequenceValue & str1, const qdesigner_internal::PropertySheetKeySequenceValue & str2) { - unsigned rc = 0; + quint64 rc = 0; COMPARE_SUBPROPERTY(str1, str2, value, rc, SubPropertyKeySequenceValue) COMPARE_SUBPROPERTY(str1, str2, comment, rc, SubPropertyKeySequenceComment) COMPARE_SUBPROPERTY(str1, str2, translatable, rc, SubPropertyKeySequenceTranslatable) @@ -245,8 +220,8 @@ template <class Property> void compareFontSubProperty(const QFont & f1, const QFont & f2, Property (QFont::*getter) () const, - unsigned maskBit, - unsigned &mask) + quint64 maskBit, + quint64 &mask) { const bool f1Changed = f1.resolveMask() & maskBit; const bool f2Changed = f2.resolveMask() & maskBit; @@ -260,60 +235,55 @@ void compareFontSubProperty(const QFont & f1, } } // find changed subproperties of a QFont -unsigned compareSubProperties(const QFont & f1, const QFont & f2) +quint64 compareSubProperties(const QFont & f1, const QFont & f2) { - unsigned rc = 0; + quint64 rc = 0; compareFontSubProperty(f1, f2, &QFont::family, QFontFamiliesResolved, rc); compareFontSubProperty(f1, f2, &QFont::pointSize, QFont::SizeResolved, rc); - compareFontSubProperty(f1, f2, &QFont::bold, QFont::WeightResolved, rc); + compareFontSubProperty(f1, f2, &QFont::weight, QFont::WeightResolved, rc); compareFontSubProperty(f1, f2, &QFont::italic, QFont::StyleResolved, rc); compareFontSubProperty(f1, f2, &QFont::underline, QFont::UnderlineResolved, rc); compareFontSubProperty(f1, f2, &QFont::strikeOut, QFont::StrikeOutResolved, rc); compareFontSubProperty(f1, f2, &QFont::kerning, QFont::KerningResolved, rc); compareFontSubProperty(f1, f2, &QFont::styleStrategy, QFont::StyleStrategyResolved, rc); + compareFontSubProperty(f1, f2, &QFont::hintingPreference, QFont::HintingPreferenceResolved, rc); if (debugPropertyCommands) qDebug() << "compareSubProperties " << fontString(f1) << fontString(f2) << "\n\treturns " << fontMask(rc); return rc; } -// Compare colors of a role -bool roleColorChanged(const QPalette & p1, const QPalette & p2, QPalette::ColorRole role) -{ - for (int group = QPalette::Active; group < QPalette::NColorGroups; group++) { - const QPalette::ColorGroup pgroup = static_cast<QPalette::ColorGroup>(group); - if (p1.color(pgroup, role) != p2.color(pgroup, role)) - return true; - } - return false; -} // find changed subproperties of a QPalette taking the [undocumented] resolve flags into account -unsigned compareSubProperties(const QPalette & p1, const QPalette & p2) +quint64 compareSubProperties(const QPalette & p1, const QPalette & p2) { - unsigned rc = 0; - unsigned maskBit = 1u; + quint64 rc = 0; // generate a mask for each role - const unsigned p1Changed = p1.resolveMask(); - const unsigned p2Changed = p2.resolveMask(); - for (int role = QPalette::WindowText; role < QPalette::NColorRoles; role++, maskBit <<= 1u) { - const bool p1RoleChanged = p1Changed & maskBit; - const bool p2RoleChanged = p2Changed & maskBit; - // Role has been set/reset in editor - if (p1RoleChanged != p2RoleChanged) { - rc |= maskBit; - } else { - // Was modified in both palettes: Compare values. - if (p1RoleChanged && p2RoleChanged && roleColorChanged(p1, p2, static_cast<QPalette::ColorRole>(role))) + const auto p1Changed = p1.resolveMask(); + const auto p2Changed = p2.resolveMask(); + + for (int r = 0; r < static_cast<int>(QPalette::NColorRoles); ++r) { + for (int g = 0; g < static_cast<int>(QPalette::NColorGroups); ++g) { + const auto role = static_cast<QPalette::ColorRole>(r); + const auto group = static_cast<QPalette::ColorGroup>(g); + const auto maskBit = qdesigner_internal::paletteResolveMask(group, role); + const bool p1RoleChanged = p1Changed & maskBit; + const bool p2RoleChanged = p2Changed & maskBit; + if (p1RoleChanged != p2RoleChanged // Role has been set/reset in editor + // Was modified in both palettes: Compare values. + || (p1RoleChanged && p2RoleChanged + && p1.brush(group, role).color() != p2.brush(group, role).color())) { rc |= maskBit; + } } } + return rc; } // find changed subproperties of a QAlignment which is a flag combination of vertical and horizontal -unsigned compareSubProperties(Qt::Alignment a1, Qt::Alignment a2) +quint64 compareSubProperties(Qt::Alignment a1, Qt::Alignment a2) { - unsigned rc = 0; + quint64 rc = 0; if ((a1 & Qt::AlignHorizontal_Mask) != (a2 & Qt::AlignHorizontal_Mask)) rc |= SubPropertyHorizontalAlignment; if ((a1 & Qt::AlignVertical_Mask) != (a2 & Qt::AlignVertical_Mask)) @@ -326,7 +296,7 @@ Qt::Alignment variantToAlignment(const QVariant & q) return Qt::Alignment(qdesigner_internal::Utils::valueOf(q)); } // find changed subproperties of a variant -unsigned compareSubProperties(const QVariant & q1, const QVariant & q2, qdesigner_internal::SpecialProperty specialProperty) +quint64 compareSubProperties(const QVariant & q1, const QVariant & q2, qdesigner_internal::SpecialProperty specialProperty) { // Do not clobber new value in the comparison function in // case someone sets a QString on a PropertySheetStringValue. @@ -472,38 +442,40 @@ QFont applyFontSubProperty(const QFont &oldValue, const QFont &newValue, unsigne QFont rc = oldValue; setFontSubProperty(mask, newValue, QFontFamiliesResolved, &QFont::family, &QFont::setFamily, rc); setFontSubProperty(mask, newValue, QFont::SizeResolved, &QFont::pointSize, &QFont::setPointSize, rc); - setFontSubProperty(mask, newValue, QFont::WeightResolved, &QFont::bold, &QFont::setBold, rc); + setFontSubProperty(mask, newValue, QFont::WeightResolved, &QFont::weight, &QFont::setWeight, rc); setFontSubProperty(mask, newValue, QFont::StyleResolved, &QFont::italic, &QFont::setItalic, rc); setFontSubProperty(mask, newValue, QFont::UnderlineResolved, &QFont::underline, &QFont::setUnderline, rc); setFontSubProperty(mask, newValue, QFont::StrikeOutResolved, &QFont::strikeOut, &QFont::setStrikeOut, rc); setFontSubProperty(mask, newValue, QFont::KerningResolved, &QFont::kerning, &QFont::setKerning, rc); setFontSubProperty(mask, newValue, QFont::StyleStrategyResolved, &QFont::styleStrategy, &QFont::setStyleStrategy, rc); + setFontSubProperty(mask, newValue, QFont::HintingPreferenceResolved, &QFont::hintingPreference, &QFont::setHintingPreference, rc); if (debugPropertyCommands) qDebug() << "applyFontSubProperty old " << fontMask(oldValue.resolveMask()) << " new " << fontMask(newValue.resolveMask()) << " return: " << fontMask(rc.resolveMask()); return rc; } // apply changed subproperties to a QPalette -QPalette applyPaletteSubProperty(const QPalette &oldValue, const QPalette &newValue, unsigned mask) +QPalette applyPaletteSubProperty(const QPalette &oldValue, const QPalette &newValue, + quint64 mask) { QPalette rc = oldValue; - // apply a mask for each role - unsigned maskBit = 1u; - for (int role = QPalette::WindowText; role < QPalette::NColorRoles; role++, maskBit <<= 1u) { - if (mask & maskBit) { - for (int group = QPalette::Active; group < QPalette::NColorGroups; group++) { - const QPalette::ColorGroup pgroup = static_cast<QPalette::ColorGroup>(group); - const QPalette::ColorRole prole = static_cast<QPalette::ColorRole>(role); - rc.setColor(pgroup, prole, newValue.color(pgroup, prole)); + // apply a mask for each role/group + for (int r = 0; r < static_cast<int>(QPalette::NColorRoles); ++r) { + for (int g = 0; g < static_cast<int>(QPalette::NColorGroups); ++g) { + const auto role = static_cast<QPalette::ColorRole>(r); + const auto group = static_cast<QPalette::ColorGroup>(g); + const auto maskBit = qdesigner_internal::paletteResolveMask(group, role); + if (mask & maskBit) { + rc.setColor(group, role, newValue.color(group, role)); + // Set the resolve bit from NewValue in return value + auto resolveMask = rc.resolveMask(); + const bool origFlag = newValue.resolveMask() & maskBit; + if (origFlag) + resolveMask |= maskBit; + else + resolveMask &= ~maskBit; + rc.setResolveMask(resolveMask); } - // Set the resolve bit from NewValue in return value - uint r = rc.resolveMask(); - const bool origFlag = newValue.resolveMask() & maskBit; - if (origFlag) - r |= maskBit; - else - r &= ~maskBit; - rc.setResolveMask(r); } } return rc; @@ -526,7 +498,9 @@ Qt::Alignment applyAlignmentSubProperty(Qt::Alignment oldValue, Qt::Alignment ne namespace qdesigner_internal { // apply changed subproperties to a variant -PropertyHelper::Value applySubProperty(const QVariant &oldValue, const QVariant &newValue, qdesigner_internal::SpecialProperty specialProperty, unsigned mask, bool changed) +PropertyHelper::Value applySubProperty(const QVariant &oldValue, const QVariant &newValue, + qdesigner_internal::SpecialProperty specialProperty, + quint64 mask, bool changed) { if (mask == SubPropertyAll) return PropertyHelper::Value(newValue, changed); @@ -603,35 +577,35 @@ PropertyHelper::Value applySubProperty(const QVariant &oldValue, const QVariant // figure out special property enum SpecialProperty getSpecialProperty(const QString& propertyName) { - if (propertyName == QStringLiteral("objectName")) + if (propertyName == "objectName"_L1) return SP_ObjectName; - if (propertyName == QStringLiteral("layoutName")) + if (propertyName == "layoutName"_L1) return SP_LayoutName; - if (propertyName == QStringLiteral("spacerName")) + if (propertyName == "spacerName"_L1) return SP_SpacerName; - if (propertyName == QStringLiteral("icon")) + if (propertyName == "icon"_L1) return SP_Icon; - if (propertyName == QStringLiteral("currentTabName")) + if (propertyName == "currentTabName"_L1) return SP_CurrentTabName; - if (propertyName == QStringLiteral("currentItemName")) + if (propertyName == "currentItemName"_L1) return SP_CurrentItemName; - if (propertyName == QStringLiteral("currentPageName")) + if (propertyName == "currentPageName"_L1) return SP_CurrentPageName; - if (propertyName == QStringLiteral("geometry")) + if (propertyName == "geometry"_L1) return SP_Geometry; - if (propertyName == QStringLiteral("windowTitle")) + if (propertyName == "windowTitle"_L1) return SP_WindowTitle; - if (propertyName == QStringLiteral("minimumSize")) + if (propertyName == "minimumSize"_L1) return SP_MinimumSize; - if (propertyName == QStringLiteral("maximumSize")) + if (propertyName == "maximumSize"_L1) return SP_MaximumSize; - if (propertyName == QStringLiteral("alignment")) + if (propertyName == "alignment"_L1) return SP_Alignment; - if (propertyName == QStringLiteral("autoDefault")) + if (propertyName == "autoDefault"_L1) return SP_AutoDefault; - if (propertyName == QStringLiteral("shortcut")) + if (propertyName == "shortcut"_L1) return SP_Shortcut; - if (propertyName == QStringLiteral("orientation")) + if (propertyName == "orientation"_L1) return SP_Orientation; return SP_None; } @@ -651,8 +625,14 @@ PropertyHelper::PropertyHelper(QObject* object, m_parentWidget = (qobject_cast<QWidget*>(object))->parentWidget(); m_objectType = OT_Widget; } else { - if (const QAction *action = qobject_cast<const QAction *>(m_object)) - m_objectType = action->associatedWidgets().isEmpty() ? OT_FreeAction : OT_AssociatedAction; + if (const QAction *action = qobject_cast<const QAction *>(m_object)) { + const QObjectList associatedObjects = action->associatedObjects(); + auto it = std::find_if(associatedObjects.cbegin(), associatedObjects.cend(), + [](QObject *obj) { + return qobject_cast<QWidget *>(obj) != nullptr; + }); + m_objectType = (it == associatedObjects.cend()) ? OT_FreeAction : OT_AssociatedAction; + } } if(debugPropertyCommands) @@ -828,7 +808,8 @@ void PropertyHelper::ensureUniqueObjectName(QDesignerFormWindowInterface *fw, QO } } -PropertyHelper::Value PropertyHelper::setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, unsigned subPropertyMask) +PropertyHelper::Value PropertyHelper::setValue(QDesignerFormWindowInterface *fw, const QVariant &value, + bool changed, quint64 subPropertyMask) { // Set new whole value if (subPropertyMask == SubPropertyAll) @@ -900,7 +881,7 @@ QVariant PropertyHelper::findDefaultValue(QDesignerFormWindowInterface *fw) cons PropertyHelper::Value PropertyHelper::restoreDefaultValue(QDesignerFormWindowInterface *fw) { - Value defaultValue = qMakePair(QVariant(), false); + Value defaultValue{{}, false}; const QVariant currentValue = m_propertySheet->property(m_index); // try to reset sheet, else try to find default if (m_propertySheet->reset(m_index)) { @@ -988,7 +969,7 @@ bool PropertyListCommand::add(QObject *object, const QString &propertyName) const PropertyDescription description(propertyName, sheet, index); - if (m_propertyHelperList.isEmpty()) { + if (m_propertyHelperList.empty()) { // first entry m_propertyDescription = description; } else { @@ -998,21 +979,22 @@ bool PropertyListCommand::add(QObject *object, const QString &propertyName) return false; } - const PropertyHelperPtr ph(createPropertyHelper(object, m_propertyDescription.m_specialProperty, sheet, index)); - m_propertyHelperList.push_back(ph); + auto ph = createPropertyHelper(object, m_propertyDescription.m_specialProperty, sheet, index); + m_propertyHelperList.push_back(std::move(ph)); return true; } -PropertyHelper *PropertyListCommand::createPropertyHelper(QObject *object, SpecialProperty sp, - QDesignerPropertySheetExtension *sheet, int sheetIndex) const +std::unique_ptr<PropertyHelper> +PropertyListCommand::createPropertyHelper(QObject *object, SpecialProperty sp, + QDesignerPropertySheetExtension *sheet, int sheetIndex) const { - return new PropertyHelper(object, sp, sheet, sheetIndex); + return std::make_unique<PropertyHelper>(object, sp, sheet, sheetIndex); } // Init from a list and make sure referenceObject is added first to obtain the right property group bool PropertyListCommand::initList(const QObjectList &list, const QString &apropertyName, QObject *referenceObject) { - propertyHelperList().clear(); + m_propertyHelperList.clear(); // Ensure the referenceObject (property editor) is first, so the right property group is chosen. if (referenceObject) { @@ -1024,41 +1006,44 @@ bool PropertyListCommand::initList(const QObjectList &list, const QString &aprop add(o, apropertyName); } - return !propertyHelperList().isEmpty(); + return !m_propertyHelperList.empty(); } QObject* PropertyListCommand::object(int index) const { - Q_ASSERT(index < m_propertyHelperList.size()); - return m_propertyHelperList.at(index)->object(); + Q_ASSERT(size_t(index) < m_propertyHelperList.size()); + return m_propertyHelperList[index]->object(); } QVariant PropertyListCommand::oldValue(int index) const { - Q_ASSERT(index < m_propertyHelperList.size()); - return m_propertyHelperList.at(index)->oldValue(); + Q_ASSERT(size_t(index) < m_propertyHelperList.size()); + return m_propertyHelperList[index]->oldValue(); } void PropertyListCommand::setOldValue(const QVariant &oldValue, int index) { - Q_ASSERT(index < m_propertyHelperList.size()); - m_propertyHelperList.at(index)->setOldValue(oldValue); + Q_ASSERT(size_t(index) < m_propertyHelperList.size()); + m_propertyHelperList[index]->setOldValue(oldValue); } // ----- SetValueFunction: Set a new value when applied to a PropertyHelper. class SetValueFunction { public: - SetValueFunction(QDesignerFormWindowInterface *formWindow, const PropertyHelper::Value &newValue, unsigned subPropertyMask); + SetValueFunction(QDesignerFormWindowInterface *formWindow, const PropertyHelper::Value &newValue, + quint64 subPropertyMask); PropertyHelper::Value operator()(PropertyHelper&); private: QDesignerFormWindowInterface *m_formWindow; const PropertyHelper::Value m_newValue; - const unsigned m_subPropertyMask; + const quint64 m_subPropertyMask; }; -SetValueFunction::SetValueFunction(QDesignerFormWindowInterface *formWindow, const PropertyHelper::Value &newValue, unsigned subPropertyMask) : +SetValueFunction::SetValueFunction(QDesignerFormWindowInterface *formWindow, + const PropertyHelper::Value &newValue, + quint64 subPropertyMask) : m_formWindow(formWindow), m_newValue(newValue), m_subPropertyMask(subPropertyMask) @@ -1102,8 +1087,8 @@ template <class PropertyListIterator, class Function> QDesignerPropertyEditorInterface *propertyEditor = core->propertyEditor(); bool updatedPropertyEditor = false; - for (PropertyListIterator it = begin; it != end; ++it) { - PropertyHelper *ph = it->data(); + for (auto it = begin; it != end; ++it) { + PropertyHelper *ph = it->get(); if (QObject* object = ph->object()) { // Might have been deleted in the meantime const PropertyHelper::Value newValue = function( *ph ); updateMask |= ph->updateMask(); @@ -1120,7 +1105,7 @@ template <class PropertyListIterator, class Function> // set a new value, return update mask -unsigned PropertyListCommand::setValue(const QVariant &value, bool changed, unsigned subPropertyMask) +unsigned PropertyListCommand::setValue(const QVariant &value, bool changed, quint64 subPropertyMask) { if(debugPropertyCommands) qDebug() << "PropertyListCommand::setValue(" << value @@ -1184,10 +1169,10 @@ void PropertyListCommand::undo() // check if lists are aequivalent for command merging (same widgets and props) bool PropertyListCommand::canMergeLists(const PropertyHelperList& other) const { - if (m_propertyHelperList.size() != other.size()) + if (m_propertyHelperList.size() != other.size()) return false; - for (int i = 0; i < m_propertyHelperList.size(); i++) { - if (!m_propertyHelperList.at(i)->canMerge(*other.at(i))) + for (size_t i = 0; i < m_propertyHelperList.size(); ++i) { + if (!m_propertyHelperList[i]->canMerge(*other[i])) return false; } return true; @@ -1233,7 +1218,7 @@ bool SetPropertyCommand::init(const QObjectList &list, const QString &apropertyN return true; } -unsigned SetPropertyCommand::subPropertyMask(const QVariant &newValue, QObject *referenceObject) +quint64 SetPropertyCommand::subPropertyMask(const QVariant &newValue, QObject *referenceObject) { // figure out the mask of changed sub properties when comparing newValue to the current value of the reference object. if (!referenceObject) @@ -1253,9 +1238,9 @@ void SetPropertyCommand::setDescription() { if (propertyHelperList().size() == 1) { setText(QApplication::translate("Command", "Changed '%1' of '%2'") - .arg(propertyName(), propertyHelperList().at(0)->object()->objectName())); + .arg(propertyName(), propertyHelperList().front()->object()->objectName())); } else { - int count = propertyHelperList().size(); + int count = static_cast<int>(propertyHelperList().size()); setText(QCoreApplication::translate("Command", "Changed '%1' of %n objects", "", count).arg(propertyName())); } } @@ -1353,9 +1338,9 @@ void ResetPropertyCommand::setDescription() { if (propertyHelperList().size() == 1) { setText(QCoreApplication::translate("Command", "Reset '%1' of '%2'") - .arg(propertyName(), propertyHelperList().at(0)->object()->objectName())); + .arg(propertyName(), propertyHelperList().front()->object()->objectName())); } else { - int count = propertyHelperList().size(); + int count = static_cast<int>(propertyHelperList().size()); setText(QCoreApplication::translate("Command", "Reset '%1' of %n objects", "", count).arg(propertyName())); } } @@ -1412,7 +1397,7 @@ bool AddDynamicPropertyCommand::init(const QObjectList &selection, QObject *curr void AddDynamicPropertyCommand::redo() { QDesignerFormEditorInterface *core = formWindow()->core(); - for (QObject *obj : qAsConst(m_selection)) { + for (QObject *obj : std::as_const(m_selection)) { QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj); dynamicSheet->addDynamicProperty(m_propertyName, m_value); if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) { @@ -1425,7 +1410,7 @@ void AddDynamicPropertyCommand::redo() void AddDynamicPropertyCommand::undo() { QDesignerFormEditorInterface *core = formWindow()->core(); - for (QObject *obj : qAsConst(m_selection)) { + for (QObject *obj : std::as_const(m_selection)) { QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), obj); QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj); dynamicSheet->removeDynamicProperty(sheet->indexOf(m_propertyName)); @@ -1473,7 +1458,8 @@ bool RemoveDynamicPropertyCommand::init(const QObjectList &selection, QObject *c if (!dynamicSheet->isDynamicProperty(index)) return false; - m_objectToValueAndChanged[current] = qMakePair(propertySheet->property(index), propertySheet->isChanged(index)); + m_objectToValueAndChanged[current] = {propertySheet->property(index), + propertySheet->isChanged(index)}; for (QObject *obj : selection) { if (m_objectToValueAndChanged.contains(obj)) @@ -1483,7 +1469,8 @@ bool RemoveDynamicPropertyCommand::init(const QObjectList &selection, QObject *c dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj); const int idx = propertySheet->indexOf(m_propertyName); if (dynamicSheet->isDynamicProperty(idx)) - m_objectToValueAndChanged[obj] = qMakePair(propertySheet->property(idx), propertySheet->isChanged(idx)); + m_objectToValueAndChanged[obj] = {propertySheet->property(idx), + propertySheet->isChanged(idx)}; } setDescription(); @@ -1493,8 +1480,7 @@ bool RemoveDynamicPropertyCommand::init(const QObjectList &selection, QObject *c void RemoveDynamicPropertyCommand::redo() { QDesignerFormEditorInterface *core = formWindow()->core(); - QMap<QObject *, QPair<QVariant, bool> >::ConstIterator it = m_objectToValueAndChanged.constBegin(); - while (it != m_objectToValueAndChanged.constEnd()) { + for (auto it = m_objectToValueAndChanged.cbegin(), end = m_objectToValueAndChanged.cend(); it != end; ++it) { QObject *obj = it.key(); QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj); QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), obj); @@ -1503,15 +1489,13 @@ void RemoveDynamicPropertyCommand::redo() if (propertyEditor->object() == obj) propertyEditor->setObject(obj); } - ++it; } } void RemoveDynamicPropertyCommand::undo() { QDesignerFormEditorInterface *core = formWindow()->core(); - QMap<QObject *, QPair<QVariant, bool> >::ConstIterator it = m_objectToValueAndChanged.constBegin(); - while (it != m_objectToValueAndChanged.constEnd()) { + for (auto it = m_objectToValueAndChanged.cbegin(), end = m_objectToValueAndChanged.cend(); it != end; ++it) { QObject *obj = it.key(); QDesignerPropertySheetExtension *propertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), obj); QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core->extensionManager(), obj); @@ -1521,7 +1505,6 @@ void RemoveDynamicPropertyCommand::undo() if (propertyEditor->object() == obj) propertyEditor->setObject(obj); } - ++it; } } diff --git a/src/designer/src/lib/shared/qdesigner_propertycommand_p.h b/src/designer/src/lib/shared/qdesigner_propertycommand_p.h index 7afd7b55a..d069e76b1 100644 --- a/src/designer/src/lib/shared/qdesigner_propertycommand_p.h +++ b/src/designer/src/lib/shared/qdesigner_propertycommand_p.h @@ -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 // // W A R N I N G @@ -43,8 +18,10 @@ #include "qdesigner_formwindowcommand_p.h" #include <QtCore/qvariant.h> +#include <QtCore/qhash.h> #include <QtCore/qlist.h> #include <QtCore/qpair.h> +#include <QtCore/qpointer.h> #include <QtCore/qsharedpointer.h> QT_BEGIN_NAMESPACE @@ -72,7 +49,7 @@ class QDESIGNER_SHARED_EXPORT PropertyHelper { Q_DISABLE_COPY(PropertyHelper) public: // A pair of Value and changed flag - using Value = QPair<QVariant, bool>; + using Value = std::pair<QVariant, bool>; enum ObjectType {OT_Object, OT_FreeAction, OT_AssociatedAction, OT_Widget}; @@ -86,7 +63,8 @@ public: SpecialProperty specialProperty() const { return m_specialProperty; } // set a new value. Can be overwritten to perform a transformation (see // handling of Arrow key move in FormWindow class). - virtual Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, unsigned subPropertyMask); + virtual Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value, + bool changed, quint64 subPropertyMask); // restore old value Value restoreOldValue(QDesignerFormWindowInterface *fw); @@ -147,8 +125,8 @@ public: void undo() override; protected: - using PropertyHelperPtr = QSharedPointer<PropertyHelper>; - using PropertyHelperList = QList<PropertyHelperPtr>; + using PropertyHelperPtr = std::unique_ptr<PropertyHelper>; + using PropertyHelperList = std::vector<PropertyHelperPtr>; // add an object bool add(QObject *object, const QString &propertyName); @@ -157,7 +135,7 @@ protected: bool initList(const QObjectList &list, const QString &apropertyName, QObject *referenceObject = nullptr); // set a new value, return update mask - unsigned setValue(const QVariant &value, bool changed, unsigned subPropertyMask); + unsigned setValue(const QVariant &value, bool changed, quint64 subPropertyMask); // restore old value, return update mask unsigned restoreOldValue(); @@ -193,8 +171,9 @@ protected: const PropertyDescription &propertyDescription() const { return m_propertyDescription; } protected: - virtual PropertyHelper *createPropertyHelper(QObject *o, SpecialProperty sp, - QDesignerPropertySheetExtension *sheet, int sheetIndex) const; + virtual std::unique_ptr<PropertyHelper> + createPropertyHelper(QObject *o, SpecialProperty sp, + QDesignerPropertySheetExtension *sheet, int sheetIndex) const; private: PropertyDescription m_propertyDescription; @@ -227,10 +206,10 @@ protected: virtual QVariant mergeValue(const QVariant &newValue); private: - unsigned subPropertyMask(const QVariant &newValue, QObject *referenceObject); + quint64 subPropertyMask(const QVariant &newValue, QObject *referenceObject); void setDescription(); QVariant m_newValue; - unsigned m_subPropertyMask; + quint64 m_subPropertyMask; }; class QDESIGNER_SHARED_EXPORT ResetPropertyCommand: public PropertyListCommand @@ -259,14 +238,14 @@ class QDESIGNER_SHARED_EXPORT AddDynamicPropertyCommand: public QDesignerFormWin public: explicit AddDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow); - bool init(const QList<QObject *> &selection, QObject *current, const QString &propertyName, const QVariant &value); + bool init(const QObjectList &selection, QObject *current, const QString &propertyName, const QVariant &value); void redo() override; void undo() override; private: void setDescription(); QString m_propertyName; - QList<QObject *> m_selection; + QObjectList m_selection; QVariant m_value; }; @@ -276,14 +255,14 @@ class QDESIGNER_SHARED_EXPORT RemoveDynamicPropertyCommand: public QDesignerForm public: explicit RemoveDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow); - bool init(const QList<QObject *> &selection, QObject *current, const QString &propertyName); + bool init(const QObjectList &selection, QObject *current, const QString &propertyName); void redo() override; void undo() override; private: void setDescription(); QString m_propertyName; - QMap<QObject *, QPair<QVariant, bool> > m_objectToValueAndChanged; + QHash<QObject *, std::pair<QVariant, bool> > m_objectToValueAndChanged; }; } // namespace qdesigner_internal diff --git a/src/designer/src/lib/shared/qdesigner_propertyeditor.cpp b/src/designer/src/lib/shared/qdesigner_propertyeditor.cpp index a31b6ab08..42a04b753 100644 --- a/src/designer/src/lib/shared/qdesigner_propertyeditor.cpp +++ b/src/designer/src/lib/shared/qdesigner_propertyeditor.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 "qdesigner_propertyeditor_p.h" #include "pluginmanager_p.h" @@ -42,6 +17,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { using StringPropertyParameters = QDesignerPropertyEditor::StringPropertyParameters; // A map of property name to type @@ -54,31 +31,31 @@ static const PropertyNameTypeMap &stringPropertyTypes() if (propertyNameTypeMap.isEmpty()) { const StringPropertyParameters richtext(ValidationRichText, true); // Accessibility. Both are texts the narrator reads - propertyNameTypeMap.insert(QStringLiteral("accessibleDescription"), richtext); - propertyNameTypeMap.insert(QStringLiteral("accessibleName"), richtext); + propertyNameTypeMap.insert(u"accessibleDescription"_s, richtext); + propertyNameTypeMap.insert(u"accessibleName"_s, richtext); // object names const StringPropertyParameters objectName(ValidationObjectName, false); - propertyNameTypeMap.insert(QStringLiteral("buddy"), objectName); - propertyNameTypeMap.insert(QStringLiteral("currentItemName"), objectName); - propertyNameTypeMap.insert(QStringLiteral("currentPageName"), objectName); - propertyNameTypeMap.insert(QStringLiteral("currentTabName"), objectName); - propertyNameTypeMap.insert(QStringLiteral("layoutName"), objectName); - propertyNameTypeMap.insert(QStringLiteral("spacerName"), objectName); + propertyNameTypeMap.insert(u"buddy"_s, objectName); + propertyNameTypeMap.insert(u"currentItemName"_s, objectName); + propertyNameTypeMap.insert(u"currentPageName"_s, objectName); + propertyNameTypeMap.insert(u"currentTabName"_s, objectName); + propertyNameTypeMap.insert(u"layoutName"_s, objectName); + propertyNameTypeMap.insert(u"spacerName"_s, objectName); // Style sheet - propertyNameTypeMap.insert(QStringLiteral("styleSheet"), StringPropertyParameters(ValidationStyleSheet, false)); + propertyNameTypeMap.insert(u"styleSheet"_s, StringPropertyParameters(ValidationStyleSheet, false)); // Buttons/ QCommandLinkButton const StringPropertyParameters multiline(ValidationMultiLine, true); - propertyNameTypeMap.insert(QStringLiteral("description"), multiline); - propertyNameTypeMap.insert(QStringLiteral("iconText"), multiline); + propertyNameTypeMap.insert(u"description"_s, multiline); + propertyNameTypeMap.insert(u"iconText"_s, multiline); // Tooltips, etc. - propertyNameTypeMap.insert(QStringLiteral("toolTip"), richtext); - propertyNameTypeMap.insert(QStringLiteral("whatsThis"), richtext); - propertyNameTypeMap.insert(QStringLiteral("windowIconText"), richtext); - propertyNameTypeMap.insert(QStringLiteral("html"), richtext); + propertyNameTypeMap.insert(u"toolTip"_s, richtext); + propertyNameTypeMap.insert(u"whatsThis"_s, richtext); + propertyNameTypeMap.insert(u"windowIconText"_s, richtext); + propertyNameTypeMap.insert(u"html"_s, richtext); // A QWizard page id - propertyNameTypeMap.insert(QStringLiteral("pageId"), StringPropertyParameters(ValidationSingleLine, false)); + propertyNameTypeMap.insert(u"pageId"_s, StringPropertyParameters(ValidationSingleLine, false)); // QPlainTextEdit - propertyNameTypeMap.insert(QStringLiteral("plainText"), StringPropertyParameters(ValidationMultiLine, true)); + propertyNameTypeMap.insert(u"plainText"_s, StringPropertyParameters(ValidationMultiLine, true)); } return propertyNameTypeMap; } @@ -110,7 +87,7 @@ QDesignerPropertyEditor::StringPropertyParameters QDesignerPropertyEditor::textP const QString &propertyName, bool isMainContainer) { // object name - no comment - if (propertyName == QStringLiteral("objectName")) { + if (propertyName == "objectName"_L1) { const TextPropertyValidationMode vm = isMainContainer ? ValidationObjectNameScope : ValidationObjectName; return StringPropertyParameters(vm, false); } @@ -128,12 +105,12 @@ QDesignerPropertyEditor::StringPropertyParameters QDesignerPropertyEditor::textP return StringPropertyParameters(ValidationMultiLine, true); // Check hardcoded property ames - const PropertyNameTypeMap::const_iterator hit = stringPropertyTypes().constFind(propertyName); + const auto hit = stringPropertyTypes().constFind(propertyName); if (hit != stringPropertyTypes().constEnd()) return hit.value(); // text: Check according to widget type. - if (propertyName == QStringLiteral("text")) { + if (propertyName == "text"_L1) { if (qobject_cast<const QAction *>(object) || qobject_cast<const QLineEdit *>(object)) return StringPropertyParameters(ValidationSingleLine, true); if (qobject_cast<const QAbstractButton *>(object)) @@ -142,14 +119,14 @@ QDesignerPropertyEditor::StringPropertyParameters QDesignerPropertyEditor::textP } // Fuzzy matching - if (propertyName.endsWith(QStringLiteral("Name"))) + if (propertyName.endsWith("Name"_L1)) return StringPropertyParameters(ValidationSingleLine, true); - if (propertyName.endsWith(QStringLiteral("ToolTip"))) + if (propertyName.endsWith("ToolTip"_L1)) return StringPropertyParameters(ValidationRichText, true); #ifdef Q_OS_WIN // No translation for the active X "control" property - if (propertyName == QStringLiteral("control") && className == QStringLiteral("QAxWidget")) + if (propertyName == "control"_L1 && className == "QAxWidget"_L1) return StringPropertyParameters(ValidationSingleLine, false); #endif diff --git a/src/designer/src/lib/shared/qdesigner_propertyeditor_p.h b/src/designer/src/lib/shared/qdesigner_propertyeditor_p.h index 5995cd21e..0aa1feb45 100644 --- a/src/designer/src/lib/shared/qdesigner_propertyeditor_p.h +++ b/src/designer/src/lib/shared/qdesigner_propertyeditor_p.h @@ -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 // // W A R N I N G @@ -59,7 +34,7 @@ public: explicit QDesignerPropertyEditor(QWidget *parent = nullptr, Qt::WindowFlags flags = {}); // A pair <ValidationMode, bool isTranslatable>. - using StringPropertyParameters = QPair<TextPropertyValidationMode, bool>; + using StringPropertyParameters = std::pair<TextPropertyValidationMode, bool>; // Return a pair of validation mode and flag indicating whether property is translatable // for textual properties. diff --git a/src/designer/src/lib/shared/qdesigner_propertysheet.cpp b/src/designer/src/lib/shared/qdesigner_propertysheet.cpp index 209582b1e..573cfed4a 100644 --- a/src/designer/src/lib/shared/qdesigner_propertysheet.cpp +++ b/src/designer/src/lib/shared/qdesigner_propertysheet.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 "qdesigner_propertysheet_p.h" #include "qdesigner_utils_p.h" @@ -56,9 +31,12 @@ #include <QtGui/qaction.h> #include <QtCore/qdebug.h> +#include <QtCore/qhash.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #define USE_LAYOUT_SIZE_CONSTRAINT static const QDesignerMetaObjectInterface *propertyIntroducedBy(const QDesignerMetaObjectInterface *meta, int index) @@ -81,40 +59,26 @@ static const QDesignerMetaObjectInterface *propertyIntroducedBy(const QDesignerM // old forms, QLayoutWidget will show up as ''; however, the uic code will // still use 'verticalLayout' (in case someone accesses it). New Layouts get autogenerated names, // legacy forms will keep their empty names (unless someone types in a new name). -static const char *layoutObjectNameC = "layoutName"; -static const char *layoutLeftMarginC = "layoutLeftMargin"; -static const char *layoutTopMarginC = "layoutTopMargin"; -static const char *layoutRightMarginC = "layoutRightMargin"; -static const char *layoutBottomMarginC = "layoutBottomMargin"; -static const char *layoutSpacingC = "layoutSpacing"; -static const char *layoutHorizontalSpacingC = "layoutHorizontalSpacing"; -static const char *layoutVerticalSpacingC = "layoutVerticalSpacing"; -static const char *layoutSizeConstraintC = "layoutSizeConstraint"; +static constexpr auto layoutObjectNameC = "layoutName"_L1; +static constexpr auto layoutLeftMarginC = "layoutLeftMargin"_L1; +static constexpr auto layoutTopMarginC = "layoutTopMargin"_L1; +static constexpr auto layoutRightMarginC = "layoutRightMargin"_L1; +static constexpr auto layoutBottomMarginC = "layoutBottomMargin"_L1; +static constexpr auto layoutSpacingC = "layoutSpacing"_L1; +static constexpr auto layoutHorizontalSpacingC = "layoutHorizontalSpacing"_L1; +static constexpr auto layoutVerticalSpacingC = "layoutVerticalSpacing"_L1; +static constexpr auto layoutSizeConstraintC = "layoutSizeConstraint"_L1; // form layout -static const char *layoutFieldGrowthPolicyC = "layoutFieldGrowthPolicy"; -static const char *layoutRowWrapPolicyC = "layoutRowWrapPolicy"; -static const char *layoutLabelAlignmentC = "layoutLabelAlignment"; -static const char *layoutFormAlignmentC = "layoutFormAlignment"; +static constexpr auto layoutFieldGrowthPolicyC = "layoutFieldGrowthPolicy"_L1; +static constexpr auto layoutRowWrapPolicyC = "layoutRowWrapPolicy"_L1; +static constexpr auto layoutLabelAlignmentC = "layoutLabelAlignment"_L1; +static constexpr auto layoutFormAlignmentC = "layoutFormAlignment"_L1; // stretches -static const char *layoutboxStretchPropertyC = "layoutStretch"; -static const char *layoutGridRowStretchPropertyC = "layoutRowStretch"; -static const char *layoutGridColumnStretchPropertyC = "layoutColumnStretch"; -static const char *layoutGridRowMinimumHeightC = "layoutRowMinimumHeight"; -static const char *layoutGridColumnMinimumWidthC = "layoutColumnMinimumWidth"; - -// Find the form editor in the hierarchy. -// We know that the parent of the sheet is the extension manager -// whose parent is the core. - -static QDesignerFormEditorInterface *formEditorForObject(QObject *o) { - do { - if (QDesignerFormEditorInterface* core = qobject_cast<QDesignerFormEditorInterface*>(o)) - return core; - o = o->parent(); - } while(o); - Q_ASSERT(o); - return nullptr; -} +static constexpr auto layoutboxStretchPropertyC = "layoutStretch"_L1; +static constexpr auto layoutGridRowStretchPropertyC = "layoutRowStretch"_L1; +static constexpr auto layoutGridColumnStretchPropertyC = "layoutColumnStretch"_L1; +static constexpr auto layoutGridRowMinimumHeightC = "layoutRowMinimumHeight"_L1; +static constexpr auto layoutGridColumnMinimumWidthC = "layoutColumnMinimumWidth"_L1; static bool hasLayoutAttributes(QDesignerFormEditorInterface *core, QObject *object) { @@ -132,15 +96,14 @@ static bool hasLayoutAttributes(QDesignerFormEditorInterface *core, QObject *obj // Cache DesignerMetaEnum by scope/name of a QMetaEnum static const qdesigner_internal::DesignerMetaEnum &designerMetaEnumFor(const QDesignerMetaEnumInterface *me) { - using ScopeNameKey = QPair<QString, QString>; - using DesignerMetaEnumCache = QMap<ScopeNameKey, qdesigner_internal::DesignerMetaEnum>; - static DesignerMetaEnumCache cache; + using ScopeNameKey = std::pair<QString, QString>; + static QMap<ScopeNameKey, qdesigner_internal::DesignerMetaEnum> cache; const QString name = me->name(); const QString scope = me->scope(); const ScopeNameKey key = ScopeNameKey(scope, name); - DesignerMetaEnumCache::iterator it = cache.find(key); + auto it = cache.find(key); if (it == cache.end()) { qdesigner_internal::DesignerMetaEnum dme = qdesigner_internal::DesignerMetaEnum(name, scope, me->separator()); const int keyCount = me->keyCount(); @@ -154,17 +117,16 @@ static const qdesigner_internal::DesignerMetaEnum &designerMetaEnumFor(const QDe // Cache DesignerMetaFlags by scope/name of a QMetaEnum static const qdesigner_internal::DesignerMetaFlags &designerMetaFlagsFor(const QDesignerMetaEnumInterface *me) { - using ScopeNameKey = QPair<QString, QString>; - using DesignerMetaFlagsCache = QMap<ScopeNameKey, qdesigner_internal::DesignerMetaFlags>; - static DesignerMetaFlagsCache cache; + using ScopeNameKey = std::pair<QString, QString>; + static QMap<ScopeNameKey, qdesigner_internal::DesignerMetaFlags> cache; const QString name = me->name(); const QString scope = me->scope(); const ScopeNameKey key = ScopeNameKey(scope, name); - DesignerMetaFlagsCache::iterator it = cache.find(key); + auto it = cache.find(key); if (it == cache.end()) { - qdesigner_internal::DesignerMetaFlags dme = qdesigner_internal::DesignerMetaFlags(name, scope, me->separator()); + auto dme = qdesigner_internal::DesignerMetaFlags(me->enumName(), scope, me->separator()); const int keyCount = me->keyCount(); for (int i=0; i < keyCount; ++i) dme.addKey(me->value(i), me->key(i)); @@ -183,7 +145,7 @@ public: explicit QDesignerPropertySheetPrivate(QDesignerPropertySheet *sheetPublic, QObject *object, QObject *sheetParent); bool invalidIndex(const char *functionName, int index) const; - inline int count() const { return m_meta->propertyCount() + m_addProperties.count(); } + inline int count() const { return m_meta->propertyCount() + m_addProperties.size(); } PropertyType propertyType(int index) const; QString transformLayoutPropertyName(int index) const; @@ -235,8 +197,7 @@ public: const ObjectType m_objectType; const ObjectFlags m_objectFlags; - using InfoHash = QHash<int, Info>; - InfoHash m_info; + QHash<int, Info> m_info; QHash<int, QVariant> m_fakeProperties; QHash<int, QVariant> m_addProperties; QHash<QString, int> m_addIndex; @@ -392,7 +353,7 @@ void QDesignerPropertySheetPrivate::setKeySequenceProperty(int index, const qdes QDesignerPropertySheetPrivate::QDesignerPropertySheetPrivate(QDesignerPropertySheet *sheetPublic, QObject *object, QObject *sheetParent) : q(sheetPublic), - m_core(formEditorForObject(sheetParent)), + m_core(QDesignerPropertySheet::formEditorForObject(sheetParent)), m_meta(m_core->introspection()->metaObject(object)), m_objectType(QDesignerPropertySheet::objectTypeFromObject(object)), m_objectFlags(QDesignerPropertySheet::objectFlagsFromObject(object)), @@ -460,7 +421,7 @@ QLayout* QDesignerPropertySheetPrivate::layout(QDesignerPropertySheetExtension * QDesignerPropertySheetPrivate::Info &QDesignerPropertySheetPrivate::ensureInfo(int index) { - InfoHash::iterator it = m_info.find(index); + auto it = m_info.find(index); if (it == m_info.end()) it = m_info.insert(index, Info()); return it.value(); @@ -468,7 +429,7 @@ QDesignerPropertySheetPrivate::Info &QDesignerPropertySheetPrivate::ensureInfo(i QDesignerPropertySheet::PropertyType QDesignerPropertySheetPrivate::propertyType(int index) const { - const InfoHash::const_iterator it = m_info.constFind(index); + const auto it = m_info.constFind(index); if (it == m_info.constEnd()) return QDesignerPropertySheet::PropertyNone; return it.value().propertyType; @@ -477,28 +438,27 @@ QDesignerPropertySheet::PropertyType QDesignerPropertySheetPrivate::propertyType QString QDesignerPropertySheetPrivate::transformLayoutPropertyName(int index) const { using TypeNameMap = QMap<QDesignerPropertySheet::PropertyType, QString>; - static TypeNameMap typeNameMap; - if (typeNameMap.isEmpty()) { - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutObjectName, QStringLiteral("objectName")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutLeftMargin, QStringLiteral("leftMargin")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutTopMargin, QStringLiteral("topMargin")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutRightMargin, QStringLiteral("rightMargin")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutBottomMargin, QStringLiteral("bottomMargin")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutSpacing, QStringLiteral("spacing")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutHorizontalSpacing, QStringLiteral("horizontalSpacing")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutVerticalSpacing, QStringLiteral("verticalSpacing")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutSizeConstraint, QStringLiteral("sizeConstraint")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutFieldGrowthPolicy, QStringLiteral("fieldGrowthPolicy")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutRowWrapPolicy, QStringLiteral("rowWrapPolicy")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutLabelAlignment, QStringLiteral("labelAlignment")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutFormAlignment, QStringLiteral("formAlignment")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutBoxStretch, QStringLiteral("stretch")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridRowStretch, QStringLiteral("rowStretch")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridColumnStretch, QStringLiteral("columnStretch")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridRowMinimumHeight, QStringLiteral("rowMinimumHeight")); - typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridColumnMinimumWidth, QStringLiteral("columnMinimumWidth")); - } - const TypeNameMap::const_iterator it = typeNameMap.constFind(propertyType(index)); + static const TypeNameMap typeNameMap = { + {QDesignerPropertySheet::PropertyLayoutObjectName, u"objectName"_s}, + {QDesignerPropertySheet::PropertyLayoutLeftMargin, u"leftMargin"_s}, + {QDesignerPropertySheet::PropertyLayoutTopMargin, u"topMargin"_s}, + {QDesignerPropertySheet::PropertyLayoutRightMargin, u"rightMargin"_s}, + {QDesignerPropertySheet::PropertyLayoutBottomMargin, u"bottomMargin"_s}, + {QDesignerPropertySheet::PropertyLayoutSpacing, u"spacing"_s}, + {QDesignerPropertySheet::PropertyLayoutHorizontalSpacing, u"horizontalSpacing"_s}, + {QDesignerPropertySheet::PropertyLayoutVerticalSpacing, u"verticalSpacing"_s}, + {QDesignerPropertySheet::PropertyLayoutSizeConstraint, u"sizeConstraint"_s}, + {QDesignerPropertySheet::PropertyLayoutFieldGrowthPolicy, u"fieldGrowthPolicy"_s}, + {QDesignerPropertySheet::PropertyLayoutRowWrapPolicy, u"rowWrapPolicy"_s}, + {QDesignerPropertySheet::PropertyLayoutLabelAlignment, u"labelAlignment"_s}, + {QDesignerPropertySheet::PropertyLayoutFormAlignment, u"formAlignment"_s}, + {QDesignerPropertySheet::PropertyLayoutBoxStretch, u"stretch"_s}, + {QDesignerPropertySheet::PropertyLayoutGridRowStretch, u"rowStretch"_s}, + {QDesignerPropertySheet::PropertyLayoutGridColumnStretch, u"columnStretch"_s}, + {QDesignerPropertySheet::PropertyLayoutGridRowMinimumHeight, u"rowMinimumHeight"_s}, + {QDesignerPropertySheet::PropertyLayoutGridColumnMinimumWidth, u"columnMinimumWidth"_s} + }; + const auto it = typeNameMap.constFind(propertyType(index)); if (it != typeNameMap.constEnd()) return it.value(); return QString(); @@ -536,44 +496,42 @@ QDesignerPropertySheet::ObjectFlags QDesignerPropertySheet::objectFlagsFromObjec QDesignerPropertySheet::PropertyType QDesignerPropertySheet::propertyTypeFromName(const QString &name) { - typedef QHash<QString, PropertyType> PropertyTypeHash; - static PropertyTypeHash propertyTypeHash; - if (propertyTypeHash.isEmpty()) { - propertyTypeHash.insert(QLatin1String(layoutObjectNameC), PropertyLayoutObjectName); - propertyTypeHash.insert(QLatin1String(layoutLeftMarginC), PropertyLayoutLeftMargin); - propertyTypeHash.insert(QLatin1String(layoutTopMarginC), PropertyLayoutTopMargin); - propertyTypeHash.insert(QLatin1String(layoutRightMarginC), PropertyLayoutRightMargin); - propertyTypeHash.insert(QLatin1String(layoutBottomMarginC), PropertyLayoutBottomMargin); - propertyTypeHash.insert(QLatin1String(layoutSpacingC), PropertyLayoutSpacing); - propertyTypeHash.insert(QLatin1String(layoutHorizontalSpacingC), PropertyLayoutHorizontalSpacing); - propertyTypeHash.insert(QLatin1String(layoutVerticalSpacingC), PropertyLayoutVerticalSpacing); - propertyTypeHash.insert(QLatin1String(layoutSizeConstraintC), PropertyLayoutSizeConstraint); - propertyTypeHash.insert(QLatin1String(layoutFieldGrowthPolicyC), PropertyLayoutFieldGrowthPolicy); - propertyTypeHash.insert(QLatin1String(layoutRowWrapPolicyC), PropertyLayoutRowWrapPolicy); - propertyTypeHash.insert(QLatin1String(layoutLabelAlignmentC), PropertyLayoutLabelAlignment); - propertyTypeHash.insert(QLatin1String(layoutFormAlignmentC), PropertyLayoutFormAlignment); - propertyTypeHash.insert(QLatin1String(layoutboxStretchPropertyC), PropertyLayoutBoxStretch); - propertyTypeHash.insert(QLatin1String(layoutGridRowStretchPropertyC), PropertyLayoutGridRowStretch); - propertyTypeHash.insert(QLatin1String(layoutGridColumnStretchPropertyC), PropertyLayoutGridColumnStretch); - propertyTypeHash.insert(QLatin1String(layoutGridRowMinimumHeightC), PropertyLayoutGridRowMinimumHeight); - propertyTypeHash.insert(QLatin1String(layoutGridColumnMinimumWidthC), PropertyLayoutGridColumnMinimumWidth); - propertyTypeHash.insert(QStringLiteral("buddy"), PropertyBuddy); - propertyTypeHash.insert(QStringLiteral("geometry"), PropertyGeometry); - propertyTypeHash.insert(QStringLiteral("checked"), PropertyChecked); - propertyTypeHash.insert(QStringLiteral("checkable"), PropertyCheckable); - propertyTypeHash.insert(QStringLiteral("accessibleName"), PropertyAccessibility); - propertyTypeHash.insert(QStringLiteral("accessibleDescription"), PropertyAccessibility); - propertyTypeHash.insert(QStringLiteral("visible"), PropertyVisible); - propertyTypeHash.insert(QStringLiteral("windowTitle"), PropertyWindowTitle); - propertyTypeHash.insert(QStringLiteral("windowIcon"), PropertyWindowIcon); - propertyTypeHash.insert(QStringLiteral("windowFilePath"), PropertyWindowFilePath); - propertyTypeHash.insert(QStringLiteral("windowOpacity"), PropertyWindowOpacity); - propertyTypeHash.insert(QStringLiteral("windowIconText"), PropertyWindowIconText); - propertyTypeHash.insert(QStringLiteral("windowModality"), PropertyWindowModality); - propertyTypeHash.insert(QStringLiteral("windowModified"), PropertyWindowModified); - propertyTypeHash.insert(QStringLiteral("styleSheet"), PropertyStyleSheet); - propertyTypeHash.insert(QStringLiteral("text"), PropertyText); - } + static const QHash<QString, PropertyType> propertyTypeHash = { + {layoutObjectNameC, PropertyLayoutObjectName}, + {layoutLeftMarginC, PropertyLayoutLeftMargin}, + {layoutTopMarginC, PropertyLayoutTopMargin}, + {layoutRightMarginC, PropertyLayoutRightMargin}, + {layoutBottomMarginC, PropertyLayoutBottomMargin}, + {layoutSpacingC, PropertyLayoutSpacing}, + {layoutHorizontalSpacingC, PropertyLayoutHorizontalSpacing}, + {layoutVerticalSpacingC, PropertyLayoutVerticalSpacing}, + {layoutSizeConstraintC, PropertyLayoutSizeConstraint}, + {layoutFieldGrowthPolicyC, PropertyLayoutFieldGrowthPolicy}, + {layoutRowWrapPolicyC, PropertyLayoutRowWrapPolicy}, + {layoutLabelAlignmentC, PropertyLayoutLabelAlignment}, + {layoutFormAlignmentC, PropertyLayoutFormAlignment}, + {layoutboxStretchPropertyC, PropertyLayoutBoxStretch}, + {layoutGridRowStretchPropertyC, PropertyLayoutGridRowStretch}, + {layoutGridColumnStretchPropertyC, PropertyLayoutGridColumnStretch}, + {layoutGridRowMinimumHeightC, PropertyLayoutGridRowMinimumHeight}, + {layoutGridColumnMinimumWidthC, PropertyLayoutGridColumnMinimumWidth}, + {u"buddy"_s, PropertyBuddy}, + {u"geometry"_s, PropertyGeometry}, + {u"checked"_s, PropertyChecked}, + {u"checkable"_s, PropertyCheckable}, + {u"accessibleName"_s, PropertyAccessibility}, + {u"accessibleDescription"_s, PropertyAccessibility}, + {u"visible"_s, PropertyVisible}, + {u"windowTitle"_s, PropertyWindowTitle}, + {u"windowIcon"_s, PropertyWindowIcon}, + {u"windowFilePath"_s, PropertyWindowFilePath}, + {u"windowOpacity"_s, PropertyWindowOpacity}, + {u"windowIconText"_s, PropertyWindowIconText}, + {u"windowModality"_s, PropertyWindowModality}, + {u"windowModified"_s, PropertyWindowModified}, + {u"styleSheet"_s, PropertyStyleSheet}, + {u"text"_s, PropertyText} + }; return propertyTypeHash.value(name, PropertyNone); } @@ -584,7 +542,7 @@ QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent) using Info = QDesignerPropertySheetPrivate::Info; const QDesignerMetaObjectInterface *baseMeta = d->m_meta; - while (baseMeta &&baseMeta->className().startsWith(QStringLiteral("QDesigner"))) { + while (baseMeta &&baseMeta->className().startsWith("QDesigner"_L1)) { baseMeta = baseMeta->superClass(); } Q_ASSERT(baseMeta != nullptr); @@ -640,28 +598,28 @@ QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent) } if (object->isWidgetType()) { - createFakeProperty(QStringLiteral("focusPolicy")); - createFakeProperty(QStringLiteral("cursor")); - createFakeProperty(QStringLiteral("toolTip")); - createFakeProperty(QStringLiteral("whatsThis")); - createFakeProperty(QStringLiteral("acceptDrops")); - createFakeProperty(QStringLiteral("dragEnabled")); + createFakeProperty(u"focusPolicy"_s); + createFakeProperty(u"cursor"_s); + createFakeProperty(u"toolTip"_s); + createFakeProperty(u"whatsThis"_s); + createFakeProperty(u"acceptDrops"_s); + createFakeProperty(u"dragEnabled"_s); // windowModality/Opacity is visible only for the main container, in which case the form windows enables it on loading - setVisible(createFakeProperty(QStringLiteral("windowModality")), false); - setVisible(createFakeProperty(QStringLiteral("windowOpacity"), double(1.0)), false); + setVisible(createFakeProperty(u"windowModality"_s), false); + setVisible(createFakeProperty(u"windowOpacity"_s, double(1.0)), false); if (qobject_cast<const QToolBar *>(d->m_object)) { // prevent toolbars from being dragged off - createFakeProperty(QStringLiteral("floatable"), QVariant(true)); + createFakeProperty(u"floatable"_s, QVariant(true)); } else { if (qobject_cast<const QMenuBar *>(d->m_object)) { // Keep the menu bar editable in the form even if a native menu bar is used. const bool nativeMenuBarDefault = !QCoreApplication::testAttribute(Qt::AA_DontUseNativeMenuBar); - createFakeProperty(QStringLiteral("nativeMenuBar"), QVariant(nativeMenuBarDefault)); + createFakeProperty(u"nativeMenuBar"_s, QVariant(nativeMenuBarDefault)); } } if (d->m_canHaveLayoutAttributes) { - static const QString layoutGroup = QStringLiteral("Layout"); - const char* fakeLayoutProperties[] = { + const QString layoutGroup = u"Layout"_s; + static constexpr QLatin1StringView fakeLayoutProperties[] = { layoutObjectNameC, layoutLeftMarginC, layoutTopMarginC, layoutRightMarginC, layoutBottomMarginC, layoutSpacingC, layoutHorizontalSpacingC, layoutVerticalSpacingC, layoutFieldGrowthPolicyC, layoutRowWrapPolicyC, layoutLabelAlignmentC, layoutFormAlignmentC, layoutboxStretchPropertyC, layoutGridRowStretchPropertyC, layoutGridColumnStretchPropertyC, @@ -670,42 +628,37 @@ QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent) , layoutSizeConstraintC #endif }; - const int fakeLayoutPropertyCount = sizeof(fakeLayoutProperties)/sizeof(const char*); + static constexpr int fakeLayoutPropertyCount = sizeof(fakeLayoutProperties)/sizeof(fakeLayoutProperties[0]); const int size = count(); for (int i = 0; i < fakeLayoutPropertyCount; i++) { - createFakeProperty(QLatin1String(fakeLayoutProperties[i]), 0); + createFakeProperty(fakeLayoutProperties[i], 0); setAttribute(size + i, true); setPropertyGroup(size + i, layoutGroup); } } if (d->m_objectType == ObjectLabel) - createFakeProperty(QStringLiteral("buddy"), QVariant(QByteArray())); + createFakeProperty(u"buddy"_s, QVariant(QByteArray())); /* We need to create a fake property since the property does not work * for non-toplevel windows or on other systems than Mac and only if * it is above a certain Mac OS version. */ if (qobject_cast<const QMainWindow *>(d->m_object)) - createFakeProperty(QStringLiteral("unifiedTitleAndToolBarOnMac"), false); + createFakeProperty(u"unifiedTitleAndToolBarOnMac"_s, false); } if (qobject_cast<const QDialog*>(object)) { - createFakeProperty(QStringLiteral("modal")); + createFakeProperty(u"modal"_s); } if (qobject_cast<const QDockWidget*>(object)) { - createFakeProperty(QStringLiteral("floating")); + createFakeProperty(u"floating"_s); } - using ByteArrayList = QList<QByteArray>; - const ByteArrayList names = object->dynamicPropertyNames(); - if (!names.isEmpty()) { - const ByteArrayList::const_iterator cend = names.constEnd(); - for (ByteArrayList::const_iterator it = names.constBegin(); it != cend; ++it) { - const char* cName = it->constData(); - const QString name = QString::fromLatin1(cName); - const int idx = addDynamicProperty(name, object->property(cName)); - if (idx != -1) - d->ensureInfo(idx).kind = QDesignerPropertySheetPrivate::DefaultDynamicProperty; - } + const QByteArrayList names = object->dynamicPropertyNames(); + for (const auto &nameB : names) { + const QString name = QString::fromLatin1(nameB); + const int idx = addDynamicProperty(name, object->property(nameB.constData())); + if (idx != -1) + d->ensureInfo(idx).kind = QDesignerPropertySheetPrivate::DefaultDynamicProperty; } } @@ -727,8 +680,7 @@ bool QDesignerPropertySheet::dynamicPropertiesAllowed() const bool QDesignerPropertySheet::canAddDynamicProperty(const QString &propName) const { // used internally - if (propName == QStringLiteral("database") || - propName == QStringLiteral("buttonGroupId")) + if (propName == "database"_L1 || propName == "buttonGroupId"_L1) return false; const int index = d->m_meta->indexOfProperty(propName); if (index != -1) @@ -738,7 +690,7 @@ bool QDesignerPropertySheet::canAddDynamicProperty(const QString &propName) cons return !isVisible(idx); // dynamic property already exists } return QDesignerPropertySheet::internalDynamicPropertiesEnabled() - || !propName.startsWith(QStringLiteral("_q_")); + || !propName.startsWith("_q_"_L1); } int QDesignerPropertySheet::addDynamicProperty(const QString &propName, const QVariant &value) @@ -863,6 +815,7 @@ bool QDesignerPropertySheet::isDynamic(int index) const case PropertyLayoutGridColumnMinimumWidth: if (d->m_object->isWidgetType() && d->m_canHaveLayoutAttributes) return false; + break; default: break; } @@ -1015,7 +968,7 @@ QString QDesignerPropertySheet::propertyGroup(int index) const return g; if (propertyType(index) == PropertyAccessibility) - return QString::fromUtf8("Accessibility"); + return u"Accessibility"_s; if (isAdditionalProperty(index)) return d->m_meta->className(); @@ -1255,7 +1208,7 @@ void QDesignerPropertySheet::setProperty(int index, const QVariant &value) const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); p->write(d->m_object, resolvePropertyValue(index, value)); if (qobject_cast<QGroupBox *>(d->m_object) && propertyType(index) == PropertyCheckable) { - const int idx = indexOf(QStringLiteral("focusPolicy")); + const int idx = indexOf(u"focusPolicy"_s); if (!isChanged(idx)) { qdesigner_internal::PropertySheetEnumValue e = qvariant_cast<qdesigner_internal::PropertySheetEnumValue>(property(idx)); if (value.toBool()) { @@ -1292,7 +1245,7 @@ bool QDesignerPropertySheet::reset(int index) if (d->isStringProperty(index)) { qdesigner_internal::PropertySheetStringValue value; // Main container: Reset to stored class name as not to change the file names generated by uic. - if (propertyName(index) == QStringLiteral("objectName")) { + if (propertyName(index) == "objectName"_L1) { const QVariant classNameDefaultV = d->m_object->property("_q_classname"); if (classNameDefaultV.isValid()) value.setValue(classNameDefaultV.toString()); @@ -1495,7 +1448,7 @@ bool QDesignerPropertySheet::isFakeLayoutProperty(int index) const } // Visible vs. Enabled: In Qt 5, it was possible to define a boolean function -// for the DESIGNABLE attribute of Q_PROPERTY. Qt Designer would use that to +// for the DESIGNABLE attribute of Q_PROPERTY. Qt Widgets Designer would use that to // determine isEnabled() for the property and return isVisible() = false // for properties that specified 'false' for DESIGNABLE. // This was used for example for the "checked" property of QAbstractButton, @@ -1657,6 +1610,20 @@ void QDesignerPropertySheet::setInternalDynamicPropertiesEnabled(bool v) QDesignerPropertySheetPrivate::m_internalDynamicPropertiesEnabled = v; } +// Find the form editor in the hierarchy. +// We know that the parent of the sheet is the extension manager +// whose parent is the core. +QDesignerFormEditorInterface *QDesignerPropertySheet::formEditorForObject(QObject *o) +{ + do { + if (auto *core = qobject_cast<QDesignerFormEditorInterface*>(o)) + return core; + o = o->parent(); + } while (o); + Q_ASSERT(o); + return nullptr; +} + // ---------- QDesignerAbstractPropertySheetFactory struct QDesignerAbstractPropertySheetFactory::PropertySheetFactoryPrivate { @@ -1664,8 +1631,7 @@ struct QDesignerAbstractPropertySheetFactory::PropertySheetFactoryPrivate { const QString m_propertySheetId; const QString m_dynamicPropertySheetId; - using ExtensionMap = QMap<QObject*, QObject*>; - ExtensionMap m_extensions; + QHash<QObject *, QObject *> m_extensions; }; QDesignerAbstractPropertySheetFactory::PropertySheetFactoryPrivate::PropertySheetFactoryPrivate() : diff --git a/src/designer/src/lib/shared/qdesigner_propertysheet_p.h b/src/designer/src/lib/shared/qdesigner_propertysheet_p.h index e066d0c4f..b9f88626f 100644 --- a/src/designer/src/lib/shared/qdesigner_propertysheet_p.h +++ b/src/designer/src/lib/shared/qdesigner_propertysheet_p.h @@ -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 // // W A R N I N G @@ -119,6 +94,8 @@ public: static bool internalDynamicPropertiesEnabled(); static void setInternalDynamicPropertiesEnabled(bool v); + static QDesignerFormEditorInterface *formEditorForObject(QObject *o); + protected: bool isAdditionalProperty(int index) const; bool isFakeProperty(int index) const; @@ -254,7 +231,7 @@ void QDesignerPropertySheetFactory<Object, PropertySheet>::registerExtension(QEx // Standard property sheet -typedef QDesignerPropertySheetFactory<QObject, QDesignerPropertySheet> QDesignerDefaultPropertySheetFactory; +using QDesignerDefaultPropertySheetFactory = QDesignerPropertySheetFactory<QObject, QDesignerPropertySheet>; Q_DECLARE_OPERATORS_FOR_FLAGS(QDesignerPropertySheet::ObjectFlags) diff --git a/src/designer/src/lib/shared/qdesigner_qsettings.cpp b/src/designer/src/lib/shared/qdesigner_qsettings.cpp index 0fa7d676e..3105132a0 100644 --- a/src/designer/src/lib/shared/qdesigner_qsettings.cpp +++ b/src/designer/src/lib/shared/qdesigner_qsettings.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 "qdesigner_qsettings_p.h" diff --git a/src/designer/src/lib/shared/qdesigner_qsettings_p.h b/src/designer/src/lib/shared/qdesigner_qsettings_p.h index fe25142ea..12c6efd25 100644 --- a/src/designer/src/lib/shared/qdesigner_qsettings_p.h +++ b/src/designer/src/lib/shared/qdesigner_qsettings_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_stackedbox.cpp b/src/designer/src/lib/shared/qdesigner_stackedbox.cpp index c62b12972..993dd6089 100644 --- a/src/designer/src/lib/shared/qdesigner_stackedbox.cpp +++ b/src/designer/src/lib/shared/qdesigner_stackedbox.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 "qdesigner_stackedbox_p.h" #include "qdesigner_command_p.h" @@ -46,7 +21,10 @@ QT_BEGIN_NAMESPACE -static QToolButton *createToolButton(QWidget *parent, Qt::ArrowType at, const QString &name) { +using namespace Qt::StringLiterals; + +static QToolButton *createToolButton(QWidget *parent, Qt::ArrowType at, const QString &name) +{ QToolButton *rc = new QToolButton(); rc->setAttribute(Qt::WA_NoChildEventsForParent, true); rc->setParent(parent); @@ -63,8 +41,8 @@ QStackedWidgetPreviewEventFilter::QStackedWidgetPreviewEventFilter(QStackedWidge QObject(parent), m_buttonToolTipEnabled(false), // Not on preview m_stackedWidget(parent), - m_prev(createToolButton(m_stackedWidget, Qt::LeftArrow, QStringLiteral("__qt__passive_prev"))), - m_next(createToolButton(m_stackedWidget, Qt::RightArrow, QStringLiteral("__qt__passive_next"))) + m_prev(createToolButton(m_stackedWidget, Qt::LeftArrow, u"__qt__passive_prev"_s)), + m_next(createToolButton(m_stackedWidget, Qt::RightArrow, u"__qt__passive_next"_s)) { connect(m_prev, &QAbstractButton::clicked, this, &QStackedWidgetPreviewEventFilter::prevPage); connect(m_next, &QAbstractButton::clicked, this, &QStackedWidgetPreviewEventFilter::nextPage); @@ -158,7 +136,7 @@ static inline QString stackedClassName(QStackedWidget *w) { if (const QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(w)) return qdesigner_internal::WidgetFactory::classNameOf(fw->core(), w); - return QStringLiteral("Stacked widget"); + return u"Stacked widget"_s; } void QStackedWidgetPreviewEventFilter::updateButtonToolTip(QObject *o) @@ -290,7 +268,7 @@ void QStackedWidgetEventFilter::gotoPage(int page) { // Are we on a form or in a preview? if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(stackedWidget())) { qdesigner_internal::SetPropertyCommand *cmd = new qdesigner_internal::SetPropertyCommand(fw); - cmd->init(stackedWidget(), QStringLiteral("currentIndex"), page); + cmd->init(stackedWidget(), u"currentIndex"_s, page); fw->commandHistory()->push(cmd); fw->emitSelectionChanged(); // Magically prevent an endless loop triggered by auto-repeat. updateButtons(); @@ -335,25 +313,25 @@ QMenu *QStackedWidgetEventFilter::addContextMenuActions(QMenu *popup) // -------- QStackedWidgetPropertySheet -static const char *pagePropertyName = "currentPageName"; +static constexpr auto pagePropertyName = "currentPageName"_L1; QStackedWidgetPropertySheet::QStackedWidgetPropertySheet(QStackedWidget *object, QObject *parent) : QDesignerPropertySheet(object, parent), m_stackedWidget(object) { - createFakeProperty(QLatin1String(pagePropertyName), QString()); + createFakeProperty(pagePropertyName, QString()); } bool QStackedWidgetPropertySheet::isEnabled(int index) const { - if (propertyName(index) != QLatin1String(pagePropertyName)) + if (propertyName(index) != pagePropertyName) return QDesignerPropertySheet::isEnabled(index); return m_stackedWidget->currentWidget() != nullptr; } void QStackedWidgetPropertySheet::setProperty(int index, const QVariant &value) { - if (propertyName(index) == QLatin1String(pagePropertyName)) { + if (propertyName(index) == pagePropertyName) { if (QWidget *w = m_stackedWidget->currentWidget()) w->setObjectName(value.toString()); } else { @@ -363,7 +341,7 @@ void QStackedWidgetPropertySheet::setProperty(int index, const QVariant &value) QVariant QStackedWidgetPropertySheet::property(int index) const { - if (propertyName(index) == QLatin1String(pagePropertyName)) { + if (propertyName(index) == pagePropertyName) { if (const QWidget *w = m_stackedWidget->currentWidget()) return w->objectName(); return QString(); @@ -373,7 +351,7 @@ QVariant QStackedWidgetPropertySheet::property(int index) const bool QStackedWidgetPropertySheet::reset(int index) { - if (propertyName(index) == QLatin1String(pagePropertyName)) { + if (propertyName(index) == pagePropertyName) { setProperty(index, QString()); return true; } @@ -382,7 +360,7 @@ bool QStackedWidgetPropertySheet::reset(int index) bool QStackedWidgetPropertySheet::checkProperty(const QString &propertyName) { - return propertyName != QLatin1String(pagePropertyName); + return propertyName != pagePropertyName; } QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/qdesigner_stackedbox_p.h b/src/designer/src/lib/shared/qdesigner_stackedbox_p.h index 36b876d78..9ef21fcfd 100644 --- a/src/designer/src/lib/shared/qdesigner_stackedbox_p.h +++ b/src/designer/src/lib/shared/qdesigner_stackedbox_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_tabwidget.cpp b/src/designer/src/lib/shared/qdesigner_tabwidget.cpp index 9325e386d..36d0c3798 100644 --- a/src/designer/src/lib/shared/qdesigner_tabwidget.cpp +++ b/src/designer/src/lib/shared/qdesigner_tabwidget.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 "qdesigner_tabwidget_p.h" #include "qdesigner_command_p.h" @@ -49,6 +24,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { // Store tab widget as drag source class MyMimeData : public QMimeData @@ -179,7 +156,7 @@ bool QTabWidgetEventFilter::eventFilter(QObject *o, QEvent *e) if (tabbar->tabRect(i).contains(m_pressPoint)) { if (i != tabbar->currentIndex()) { qdesigner_internal::SetPropertyCommand *cmd = new qdesigner_internal::SetPropertyCommand(fw); - cmd->init(m_tabWidget, QStringLiteral("currentIndex"), i); + cmd->init(m_tabWidget, u"currentIndex"_s, i); fw->commandHistory()->push(cmd); } break; @@ -381,39 +358,37 @@ QMenu *QTabWidgetEventFilter::addContextMenuActions(QMenu *popup) // ----------- QTabWidgetPropertySheet -static const char *currentTabTextKey = "currentTabText"; -static const char *currentTabNameKey = "currentTabName"; -static const char *currentTabIconKey = "currentTabIcon"; -static const char *currentTabToolTipKey = "currentTabToolTip"; -static const char *currentTabWhatsThisKey = "currentTabWhatsThis"; -static const char *tabMovableKey = "movable"; +static constexpr auto currentTabTextKey = "currentTabText"_L1; +static constexpr auto currentTabNameKey = "currentTabName"_L1; +static constexpr auto currentTabIconKey = "currentTabIcon"_L1; +static constexpr auto currentTabToolTipKey = "currentTabToolTip"_L1; +static constexpr auto currentTabWhatsThisKey = "currentTabWhatsThis"_L1; +static constexpr auto tabMovableKey = "movable"_L1; QTabWidgetPropertySheet::QTabWidgetPropertySheet(QTabWidget *object, QObject *parent) : QDesignerPropertySheet(object, parent), m_tabWidget(object) { - createFakeProperty(QLatin1String(currentTabTextKey), QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); - createFakeProperty(QLatin1String(currentTabNameKey), QString()); - createFakeProperty(QLatin1String(currentTabIconKey), QVariant::fromValue(qdesigner_internal::PropertySheetIconValue())); + createFakeProperty(currentTabTextKey, QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); + createFakeProperty(currentTabNameKey, QString()); + createFakeProperty(currentTabIconKey, QVariant::fromValue(qdesigner_internal::PropertySheetIconValue())); if (formWindowBase()) - formWindowBase()->addReloadableProperty(this, indexOf(QLatin1String(currentTabIconKey))); - createFakeProperty(QLatin1String(currentTabToolTipKey), QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); - createFakeProperty(QLatin1String(currentTabWhatsThisKey), QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); + formWindowBase()->addReloadableProperty(this, indexOf(currentTabIconKey)); + createFakeProperty(currentTabToolTipKey, QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); + createFakeProperty(currentTabWhatsThisKey, QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); // Prevent the tab widget's drag and drop handling from interfering with Designer's - createFakeProperty(QLatin1String(tabMovableKey), QVariant(false)); + createFakeProperty(tabMovableKey, QVariant(false)); } QTabWidgetPropertySheet::TabWidgetProperty QTabWidgetPropertySheet::tabWidgetPropertyFromName(const QString &name) { - using TabWidgetPropertyHash = QHash<QString, TabWidgetProperty>; - static TabWidgetPropertyHash tabWidgetPropertyHash; - if (tabWidgetPropertyHash.isEmpty()) { - tabWidgetPropertyHash.insert(QLatin1String(currentTabTextKey), PropertyCurrentTabText); - tabWidgetPropertyHash.insert(QLatin1String(currentTabNameKey), PropertyCurrentTabName); - tabWidgetPropertyHash.insert(QLatin1String(currentTabIconKey), PropertyCurrentTabIcon); - tabWidgetPropertyHash.insert(QLatin1String(currentTabToolTipKey), PropertyCurrentTabToolTip); - tabWidgetPropertyHash.insert(QLatin1String(currentTabWhatsThisKey), PropertyCurrentTabWhatsThis); - } + static const QHash<QString, TabWidgetProperty> tabWidgetPropertyHash = { + {currentTabTextKey, PropertyCurrentTabText}, + {currentTabNameKey, PropertyCurrentTabName}, + {currentTabIconKey, PropertyCurrentTabIcon}, + {currentTabToolTipKey, PropertyCurrentTabToolTip}, + {currentTabWhatsThisKey, PropertyCurrentTabWhatsThis} + }; return tabWidgetPropertyHash.value(name, PropertyTabWidgetNone); } diff --git a/src/designer/src/lib/shared/qdesigner_tabwidget_p.h b/src/designer/src/lib/shared/qdesigner_tabwidget_p.h index 1a488fe69..c83d93aed 100644 --- a/src/designer/src/lib/shared/qdesigner_tabwidget_p.h +++ b/src/designer/src/lib/shared/qdesigner_tabwidget_p.h @@ -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 // // W A R N I N G @@ -44,6 +19,7 @@ #include "qdesigner_propertysheet_p.h" #include "qdesigner_utils_p.h" +#include <QtCore/qhash.h> #include <QtCore/qpointer.h> #include <QtGui/qicon.h> @@ -130,7 +106,7 @@ private: qdesigner_internal::PropertySheetStringValue whatsthis; qdesigner_internal::PropertySheetIconValue icon; }; - QMap<QWidget *, PageData> m_pageToData; + QHash<QWidget *, PageData> m_pageToData; }; using QTabWidgetPropertySheetFactory = QDesignerPropertySheetFactory<QTabWidget, QTabWidgetPropertySheet>; diff --git a/src/designer/src/lib/shared/qdesigner_taskmenu.cpp b/src/designer/src/lib/shared/qdesigner_taskmenu.cpp index e51cd3a73..8bdf01f37 100644 --- a/src/designer/src/lib/shared/qdesigner_taskmenu.cpp +++ b/src/designer/src/lib/shared/qdesigner_taskmenu.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 "qdesigner_taskmenu_p.h" #include "qdesigner_command_p.h" @@ -77,6 +52,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static inline QAction *createSeparatorHelper(QObject *parent) { QAction *rc = new QAction(parent); rc->setSeparator(true); @@ -88,8 +65,7 @@ static QString objName(const QDesignerFormEditorInterface *core, QObject *object = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), object); Q_ASSERT(sheet != nullptr); - const QString objectNameProperty = QStringLiteral("objectName"); - const int index = sheet->indexOf(objectNameProperty); + const int index = sheet->indexOf(u"objectName"_s); const QVariant v = sheet->property(index); if (v.canConvert<qdesigner_internal::PropertySheetStringValue>()) return v.value<qdesigner_internal::PropertySheetStringValue>().value(); @@ -116,7 +92,6 @@ ObjectNameDialog::ObjectNameDialog(QWidget *parent, const QString &oldName) qdesigner_internal::ValidationObjectName)) { setWindowTitle(QCoreApplication::translate("ObjectNameDialog", "Change Object Name")); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); QVBoxLayout *vboxLayout = new QVBoxLayout(this); vboxLayout->addWidget(new QLabel(QCoreApplication::translate("ObjectNameDialog", "Object Name"))); @@ -146,20 +121,22 @@ namespace qdesigner_internal { // Sub menu displaying the alignment options of a widget in a managed // grid/box layout cell. -class LayoutAlignmentMenu { +class LayoutAlignmentMenu : public QObject { + Q_OBJECT public: explicit LayoutAlignmentMenu(QObject *parent); QAction *subMenuAction() const { return m_subMenuAction; } - void connect(QObject *receiver, const char *aSlot); - // Set up enabled state and checked actions according to widget (managed box/grid) bool setAlignment(const QDesignerFormEditorInterface *core, QWidget *w); // Return the currently checked alignment Qt::Alignment alignment() const; +signals: + void changed(); + private: enum Actions { HorizNone, Left, HorizCenter, Right, VerticalNone, Top, VerticalCenter, Bottom }; static QAction *createAction(const QString &text, int data, QMenu *menu, QActionGroup *ag); @@ -180,13 +157,15 @@ QAction *LayoutAlignmentMenu::createAction(const QString &text, int data, QMenu return a; } -LayoutAlignmentMenu::LayoutAlignmentMenu(QObject *parent) : +LayoutAlignmentMenu::LayoutAlignmentMenu(QObject *parent) : QObject(parent), m_subMenuAction(new QAction(QDesignerTaskMenu::tr("Layout Alignment"), parent)), m_horizGroup(new QActionGroup(parent)), m_verticalGroup(new QActionGroup(parent)) { m_horizGroup->setExclusive(true); m_verticalGroup->setExclusive(true); + connect(m_horizGroup, &QActionGroup::triggered, this, &LayoutAlignmentMenu::changed); + connect(m_verticalGroup, &QActionGroup::triggered, this, &LayoutAlignmentMenu::changed); QMenu *menu = new QMenu; m_subMenuAction->setMenu(menu); @@ -202,18 +181,12 @@ LayoutAlignmentMenu::LayoutAlignmentMenu(QObject *parent) : m_actions[Bottom] = createAction(QDesignerTaskMenu::tr("Bottom"), Qt::AlignBottom, menu, m_verticalGroup); } -void LayoutAlignmentMenu::connect(QObject *receiver, const char *aSlot) -{ - QObject::connect(m_horizGroup, SIGNAL(triggered(QAction*)), receiver, aSlot); - QObject::connect(m_verticalGroup, SIGNAL(triggered(QAction*)), receiver, aSlot); -} - bool LayoutAlignmentMenu::setAlignment(const QDesignerFormEditorInterface *core, QWidget *w) { bool enabled; const Qt::Alignment alignment = LayoutAlignmentCommand::alignmentOf(core, w, &enabled); + m_subMenuAction->setEnabled(enabled); if (!enabled) { - m_subMenuAction->setEnabled(false); m_actions[HorizNone]->setChecked(true); m_actions[VerticalNone]->setChecked(true); return false; @@ -370,18 +343,19 @@ QDesignerTaskMenu::QDesignerTaskMenu(QWidget *widget, QObject *parent) : [this] () { this->addToolBar(Qt::TopToolBarArea); }); auto areaMenu = new QMenu; d->m_addAreaSubMenu->setMenu(areaMenu); - areaMenu->addAction(QDesignerTaskMenu::tr("Left"), + areaMenu->addAction(QDesignerTaskMenu::tr("Left"), this, [this] () { this->addToolBar(Qt::LeftToolBarArea); }); - areaMenu->addAction(QDesignerTaskMenu::tr("Right"), + areaMenu->addAction(QDesignerTaskMenu::tr("Right"), this, [this] () { this->addToolBar(Qt::RightToolBarArea); }); - areaMenu->addAction(QDesignerTaskMenu::tr("Bottom"), + areaMenu->addAction(QDesignerTaskMenu::tr("Bottom"), this, [this] () { this->addToolBar(Qt::BottomToolBarArea); }); connect(d->m_addStatusBar, &QAction::triggered, this, &QDesignerTaskMenu::createStatusBar); connect(d->m_removeStatusBar, &QAction::triggered, this, &QDesignerTaskMenu::removeStatusBar); connect(d->m_containerFakeMethods, &QAction::triggered, this, &QDesignerTaskMenu::containerFakeMethods); connect(d->m_navigateToSlot, &QAction::triggered, this, &QDesignerTaskMenu::slotNavigateToSlot); connect(d->m_sizeActionGroup, &QActionGroup::triggered, this, &QDesignerTaskMenu::applySize); - d->m_layoutAlignmentMenu.connect(this, SLOT(slotLayoutAlignment())); + connect(&d->m_layoutAlignmentMenu, &LayoutAlignmentMenu::changed, + this, &QDesignerTaskMenu::slotLayoutAlignment); } QDesignerTaskMenu::~QDesignerTaskMenu() @@ -531,10 +505,10 @@ void QDesignerTaskMenu::changeObjectName() if (dialog.exec() == QDialog::Accepted) { const QString newObjectName = dialog.newObjectName(); if (!newObjectName.isEmpty() && newObjectName != oldObjectName ) { - const QString objectNameProperty = QStringLiteral("objectName"); PropertySheetStringValue objectNameValue; objectNameValue.setValue(newObjectName); - setProperty(fw, CurrentWidgetMode, objectNameProperty, QVariant::fromValue(objectNameValue)); + setProperty(fw, CurrentWidgetMode, u"objectName"_s, + QVariant::fromValue(objectNameValue)); } } } @@ -590,12 +564,12 @@ void QDesignerTaskMenu::changeTextProperty(const QString &propertyName, const QS void QDesignerTaskMenu::changeToolTip() { - changeTextProperty(QStringLiteral("toolTip"), tr("Edit ToolTip"), MultiSelectionMode, Qt::AutoText); + changeTextProperty(u"toolTip"_s, tr("Edit ToolTip"), MultiSelectionMode, Qt::AutoText); } void QDesignerTaskMenu::changeWhatsThis() { - changeTextProperty(QStringLiteral("whatsThis"), tr("Edit WhatsThis"), MultiSelectionMode, Qt::AutoText); + changeTextProperty(u"whatsThis"_s, tr("Edit WhatsThis"), MultiSelectionMode, Qt::AutoText); } void QDesignerTaskMenu::changeStyleSheet() @@ -655,7 +629,7 @@ static void createSizeCommand(QDesignerFormWindowInterface *fw, QWidget *w, int if (flags & ApplyMinimumHeight) minimumSize.setHeight(size.height()); SetPropertyCommand* cmd = new SetPropertyCommand(fw); - cmd->init(w, QStringLiteral("minimumSize"), minimumSize); + cmd->init(w, u"minimumSize"_s, minimumSize); fw->commandHistory()->push(cmd); } if (flags & (ApplyMaximumWidth|ApplyMaximumHeight)) { @@ -665,7 +639,7 @@ static void createSizeCommand(QDesignerFormWindowInterface *fw, QWidget *w, int if (flags & ApplyMaximumHeight) maximumSize.setHeight(size.height()); SetPropertyCommand* cmd = new SetPropertyCommand(fw); - cmd->init(w, QStringLiteral("maximumSize"), maximumSize); + cmd->init(w, u"maximumSize"_s, maximumSize); fw->commandHistory()->push(cmd); } } @@ -681,10 +655,10 @@ void QDesignerTaskMenu::applySize(QAction *a) return; const int mask = a->data().toInt(); - const int size = selection.size(); - fw->commandHistory()->beginMacro(tr("Set size constraint on %n widget(s)", nullptr, size)); - for (int i = 0; i < size; i++) - createSizeCommand(fw, selection.at(i), mask); + fw->commandHistory()->beginMacro(tr("Set size constraint on %n widget(s)", nullptr, + int(selection.size()))); + for (auto *w : selection) + createSizeCommand(fw, w, mask); fw->commandHistory()->endMacro(); } @@ -703,10 +677,10 @@ template <class Container> Selection s; designerObjectInspector->getSelection(s); const QWidgetList &source = fw->isManaged(current) ? s.managed : s.unmanaged; - const QWidgetList::const_iterator cend = source.constEnd(); - for ( QWidgetList::const_iterator it = source.constBegin(); it != cend; ++it) - if (*it != current) // was first - c->push_back(*it); + for (auto *w : source) { + if (w != current) // was first + c->append(w); + } } QObjectList QDesignerTaskMenu::applicableObjects(const QDesignerFormWindowInterface *fw, PropertyMode pm) const @@ -748,3 +722,5 @@ void QDesignerTaskMenu::slotLayoutAlignment() } // namespace qdesigner_internal QT_END_NAMESPACE + +#include "qdesigner_taskmenu.moc" diff --git a/src/designer/src/lib/shared/qdesigner_taskmenu_p.h b/src/designer/src/lib/shared/qdesigner_taskmenu_p.h index b4bc23da4..9c504f893 100644 --- a/src/designer/src/lib/shared/qdesigner_taskmenu_p.h +++ b/src/designer/src/lib/shared/qdesigner_taskmenu_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_toolbar.cpp b/src/designer/src/lib/shared/qdesigner_toolbar.cpp index 5e8eeccdd..a5d75d23f 100644 --- a/src/designer/src/lib/shared/qdesigner_toolbar.cpp +++ b/src/designer/src/lib/shared/qdesigner_toolbar.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 "qdesigner_toolbar_p.h" #include "qdesigner_command_p.h" @@ -52,10 +27,10 @@ #include <QtCore/qdebug.h> -Q_DECLARE_METATYPE(QAction*) - QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + using ActionList = QList<QAction *>; namespace qdesigner_internal { @@ -90,6 +65,7 @@ bool ToolBarEventFilter::eventFilter (QObject *watched, QEvent *event) if (watched != m_toolBar) return QObject::eventFilter (watched, event); + bool handled = false; switch (event->type()) { case QEvent::ChildAdded: { // Children should not interact with the mouse @@ -101,24 +77,32 @@ bool ToolBarEventFilter::eventFilter (QObject *watched, QEvent *event) } break; case QEvent::ContextMenu: - return handleContextMenuEvent(static_cast<QContextMenuEvent*>(event)); + handled = handleContextMenuEvent(static_cast<QContextMenuEvent*>(event)); + break; case QEvent::DragEnter: case QEvent::DragMove: - return handleDragEnterMoveEvent(static_cast<QDragMoveEvent *>(event)); + handled = handleDragEnterMoveEvent(static_cast<QDragMoveEvent *>(event)); + break; case QEvent::DragLeave: - return handleDragLeaveEvent(static_cast<QDragLeaveEvent *>(event)); + handled = handleDragLeaveEvent(static_cast<QDragLeaveEvent *>(event)); + break; case QEvent::Drop: - return handleDropEvent(static_cast<QDropEvent *>(event)); + handled = handleDropEvent(static_cast<QDropEvent *>(event)); + break; case QEvent::MouseButtonPress: - return handleMousePressEvent(static_cast<QMouseEvent*>(event)); + handled = handleMousePressEvent(static_cast<QMouseEvent*>(event)); + break; case QEvent::MouseButtonRelease: - return handleMouseReleaseEvent(static_cast<QMouseEvent*>(event)); + handled = handleMouseReleaseEvent(static_cast<QMouseEvent*>(event)); + break; case QEvent::MouseMove: - return handleMouseMoveEvent(static_cast<QMouseEvent*>(event)); + handled = handleMouseMoveEvent(static_cast<QMouseEvent*>(event)); + break; default: break; } - return QObject::eventFilter (watched, event); + + return handled || QObject::eventFilter(watched, event); } ActionList ToolBarEventFilter::contextMenuActions(const QPoint &globalPos) @@ -173,9 +157,8 @@ bool ToolBarEventFilter::handleContextMenuEvent(QContextMenuEvent * event ) const ActionList al = contextMenuActions(event->globalPos()); QMenu menu(nullptr); - const ActionList::const_iterator acend = al.constEnd(); - for (ActionList::const_iterator it = al.constBegin(); it != acend; ++it) - menu.addAction(*it); + for (auto *a : al) + menu.addAction(a); menu.exec(globalPos); return true; } @@ -195,7 +178,7 @@ void ToolBarEventFilter::slotRemoveSelectedAction() const ActionList actions = m_toolBar->actions(); const int pos = actions.indexOf(a); QAction *action_before = nullptr; - if (pos != -1 && actions.count() > pos + 1) + if (pos != -1 && actions.size() > pos + 1) action_before = actions.at(pos + 1); RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw); @@ -218,7 +201,7 @@ void ToolBarEventFilter::slotInsertSeparator() QAction *theSender = qobject_cast<QAction*>(sender()); QAction *previous = qvariant_cast<QAction *>(theSender->data()); fw->beginCommand(tr("Insert Separator")); - QAction *action = createAction(fw, QStringLiteral("separator"), true); + QAction *action = createAction(fw, u"separator"_s, true); InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); cmd->init(m_toolBar, action, previous); fw->commandHistory()->push(cmd); @@ -276,9 +259,13 @@ bool ToolBarEventFilter::handleMousePressEvent(QMouseEvent *event) } core->propertyEditor()->setObject(m_toolBar); } - m_startPosition = m_toolBar->mapFromGlobal(event->globalPosition().toPoint()); - event->accept(); - return true; + const auto pos = m_toolBar->mapFromGlobal(event->globalPosition().toPoint()); + if (actionIndexAt(m_toolBar, pos, m_toolBar->orientation()) != -1) { + m_startPosition = pos; + event->accept(); + return true; + } + return false; } bool ToolBarEventFilter::handleMouseReleaseEvent(QMouseEvent *event) @@ -298,8 +285,8 @@ bool ToolBarEventFilter::handleMouseMoveEvent(QMouseEvent *event) return false; const QPoint pos = m_toolBar->mapFromGlobal(event->globalPosition().toPoint()); - if ((pos - m_startPosition).manhattanLength() > qApp->startDragDistance()) { - startDrag(m_startPosition, event->modifiers()); + if ((pos - m_startPosition).manhattanLength() > QApplication::startDragDistance() + && startDrag(m_startPosition, event->modifiers())) { m_startPosition = QPoint(); event->accept(); return true; @@ -381,11 +368,11 @@ bool ToolBarEventFilter::handleDropEvent(QDropEvent *event) return true; } -void ToolBarEventFilter::startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers) +bool ToolBarEventFilter::startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers) { const int index = actionIndexAt(m_toolBar, pos, m_toolBar->orientation()); if (index == - 1) - return; + return false; const ActionList actions = m_toolBar->actions(); QAction *action = actions.at(index); @@ -416,6 +403,7 @@ void ToolBarEventFilter::startDrag(const QPoint &pos, Qt::KeyboardModifiers modi fw->commandHistory()->push(cmd); } } + return true; } QAction *ToolBarEventFilter::actionAt(const QToolBar *tb, const QPoint &pos) diff --git a/src/designer/src/lib/shared/qdesigner_toolbar_p.h b/src/designer/src/lib/shared/qdesigner_toolbar_p.h index a3fa2c2ad..bd897ae0a 100644 --- a/src/designer/src/lib/shared/qdesigner_toolbar_p.h +++ b/src/designer/src/lib/shared/qdesigner_toolbar_p.h @@ -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 // // W A R N I N G @@ -109,7 +84,7 @@ private: QDesignerFormWindowInterface *formWindow() const; void adjustDragIndicator(const QPoint &pos); void hideDragIndicator(); - void startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers); + bool startDrag(const QPoint &pos, Qt::KeyboardModifiers modifiers); bool withinHandleArea(const QPoint &pos) const; QToolBar *m_toolBar; diff --git a/src/designer/src/lib/shared/qdesigner_toolbox.cpp b/src/designer/src/lib/shared/qdesigner_toolbox.cpp index 26b36c8f9..0295e4d07 100644 --- a/src/designer/src/lib/shared/qdesigner_toolbox.cpp +++ b/src/designer/src/lib/shared/qdesigner_toolbox.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 "qdesigner_toolbox_p.h" #include "qdesigner_command_p.h" @@ -46,6 +21,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QToolBoxHelper::QToolBoxHelper(QToolBox *toolbox) : QObject(toolbox), m_toolbox(toolbox), @@ -233,11 +210,11 @@ QMenu *QToolBoxHelper::addContextMenuActions(QMenu *popup) const // -------- QToolBoxWidgetPropertySheet -static const char *currentItemTextKey = "currentItemText"; -static const char *currentItemNameKey = "currentItemName"; -static const char *currentItemIconKey = "currentItemIcon"; -static const char *currentItemToolTipKey = "currentItemToolTip"; -static const char *tabSpacingKey = "tabSpacing"; +static constexpr auto currentItemTextKey = "currentItemText"_L1; +static constexpr auto currentItemNameKey = "currentItemName"_L1; +static constexpr auto currentItemIconKey = "currentItemIcon"_L1; +static constexpr auto currentItemToolTipKey = "currentItemToolTip"_L1; +static constexpr auto tabSpacingKey = "tabSpacing"_L1; enum { tabSpacingDefault = -1 }; @@ -245,26 +222,24 @@ QToolBoxWidgetPropertySheet::QToolBoxWidgetPropertySheet(QToolBox *object, QObje QDesignerPropertySheet(object, parent), m_toolBox(object) { - createFakeProperty(QLatin1String(currentItemTextKey), QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); - createFakeProperty(QLatin1String(currentItemNameKey), QString()); - createFakeProperty(QLatin1String(currentItemIconKey), QVariant::fromValue(qdesigner_internal::PropertySheetIconValue())); + createFakeProperty(currentItemTextKey, QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); + createFakeProperty(currentItemNameKey, QString()); + createFakeProperty(currentItemIconKey, QVariant::fromValue(qdesigner_internal::PropertySheetIconValue())); if (formWindowBase()) - formWindowBase()->addReloadableProperty(this, indexOf(QLatin1String(currentItemIconKey))); - createFakeProperty(QLatin1String(currentItemToolTipKey), QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); - createFakeProperty(QLatin1String(tabSpacingKey), QVariant(tabSpacingDefault)); + formWindowBase()->addReloadableProperty(this, indexOf(currentItemIconKey)); + createFakeProperty(currentItemToolTipKey, QVariant::fromValue(qdesigner_internal::PropertySheetStringValue())); + createFakeProperty(tabSpacingKey, QVariant(tabSpacingDefault)); } QToolBoxWidgetPropertySheet::ToolBoxProperty QToolBoxWidgetPropertySheet::toolBoxPropertyFromName(const QString &name) { - using ToolBoxPropertyHash = QHash<QString, ToolBoxProperty>; - static ToolBoxPropertyHash toolBoxPropertyHash; - if (toolBoxPropertyHash.isEmpty()) { - toolBoxPropertyHash.insert(QLatin1String(currentItemTextKey), PropertyCurrentItemText); - toolBoxPropertyHash.insert(QLatin1String(currentItemNameKey), PropertyCurrentItemName); - toolBoxPropertyHash.insert(QLatin1String(currentItemIconKey), PropertyCurrentItemIcon); - toolBoxPropertyHash.insert(QLatin1String(currentItemToolTipKey), PropertyCurrentItemToolTip); - toolBoxPropertyHash.insert(QLatin1String(tabSpacingKey), PropertyTabSpacing); - } + static const QHash<QString, ToolBoxProperty> toolBoxPropertyHash = { + {currentItemTextKey, PropertyCurrentItemText}, + {currentItemNameKey, PropertyCurrentItemName}, + {currentItemIconKey, PropertyCurrentItemIcon}, + {currentItemToolTipKey, PropertyCurrentItemToolTip}, + {tabSpacingKey, PropertyTabSpacing} + }; return toolBoxPropertyHash.value(name, PropertyToolBoxNone); } diff --git a/src/designer/src/lib/shared/qdesigner_toolbox_p.h b/src/designer/src/lib/shared/qdesigner_toolbox_p.h index 9828ff2c3..8a86e23e6 100644 --- a/src/designer/src/lib/shared/qdesigner_toolbox_p.h +++ b/src/designer/src/lib/shared/qdesigner_toolbox_p.h @@ -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 // // W A R N I N G @@ -117,7 +92,7 @@ private: qdesigner_internal::PropertySheetStringValue tooltip; qdesigner_internal::PropertySheetIconValue icon; }; - QMap<QWidget *, PageData> m_pageToData; + QHash<QWidget *, PageData> m_pageToData; }; using QToolBoxWidgetPropertySheetFactory = QDesignerPropertySheetFactory<QToolBox, QToolBoxWidgetPropertySheet>; diff --git a/src/designer/src/lib/shared/qdesigner_utils.cpp b/src/designer/src/lib/shared/qdesigner_utils.cpp index a8c253117..67ff4df2d 100644 --- a/src/designer/src/lib/shared/qdesigner_utils.cpp +++ b/src/designer/src/lib/shared/qdesigner_utils.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 "qdesigner_utils_p.h" #include "qdesigner_propertycommand_p.h" @@ -38,7 +13,10 @@ #include <QtDesigner/taskmenu.h> #include <QtDesigner/qextensionmanager.h> +#include <QtCore/qcoreapplication.h> #include <QtCore/qdir.h> +#include <QtCore/qfileinfo.h> +#include <QtCore/qoperatingsystemversion.h> #include <QtCore/qprocess.h> #include <QtCore/qlibraryinfo.h> #include <QtCore/qdebug.h> @@ -48,6 +26,7 @@ #include <QtWidgets/qapplication.h> #include <QtGui/qicon.h> +#include <QtGui/qpalette.h> #include <QtGui/qpixmap.h> #include <QtWidgets/qlistwidget.h> #include <QtWidgets/qtreewidget.h> @@ -56,19 +35,21 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { // ### FIXME Qt 8: Remove (QTBUG-96005) QString legacyDataDirectory() { - return QDir::homePath() + u"/.designer"_qs; + return QDir::homePath() + u"/.designer"_s; } QString dataDirectory() { #if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) - + u'/' + QCoreApplication::organizationName() + u"/Designer"_qs; + + u'/' + QCoreApplication::organizationName() + u"/Designer"_s; #else return legacyDataDirectory(); #endif @@ -177,18 +158,19 @@ namespace qdesigner_internal { return QCoreApplication::translate("DesignerMetaEnum", "%1 is not a valid enumeration value of '%2'.") - .arg(value).arg(name()); + .arg(value).arg(enumName()); } QString DesignerMetaEnum::messageParseFailed(const QString &s) const { return QCoreApplication::translate("DesignerMetaEnum", "'%1' could not be converted to an enumeration value of type '%2'.") - .arg(s, name()); + .arg(s, enumName()); } // -------------- DesignerMetaFlags - DesignerMetaFlags::DesignerMetaFlags(const QString &name, const QString &scope, const QString &separator) : - MetaEnum<uint>(name, scope, separator) + DesignerMetaFlags::DesignerMetaFlags(const QString &enumName, const QString &scope, + const QString &separator) : + MetaEnum<uint>(enumName, scope, separator) { } @@ -196,18 +178,18 @@ namespace qdesigner_internal { QStringList rc; const uint v = static_cast<uint>(ivalue); - for (auto it = keyToValueMap().constBegin(), cend = keyToValueMap().constEnd(); it != cend; ++it ) { - const uint itemValue = it.value(); + for (auto it = keyToValueMap().begin(), end = keyToValueMap().end(); it != end; ++it) { + const uint itemValue = it->second; // Check for equality first as flag values can be 0 or -1, too. Takes preference over a bitwise flag if (v == itemValue) { rc.clear(); - rc.push_back(it.key()); + rc.push_back(it->first); return rc; } // Do not add 0-flags (None-flags) if (itemValue) if ((v & itemValue) == itemValue) - rc.push_back(it.key()); + rc.push_back(it->first); } return rc; } @@ -219,16 +201,14 @@ namespace qdesigner_internal if (flagIds.isEmpty()) return QString(); - const QChar delimiter = QLatin1Char('|'); QString rc; - const QStringList::const_iterator cend = flagIds.constEnd(); - for (QStringList::const_iterator it = flagIds.constBegin(); it != cend; ++it) { + for (const auto &id : flagIds) { if (!rc.isEmpty()) - rc += delimiter ; + rc += u'|'; if (sm == FullyQualified) - appendQualifiedName(*it, rc); + appendQualifiedName(id, rc); else - rc += *it; + rc += id; } return rc; } @@ -243,9 +223,9 @@ namespace qdesigner_internal } uint flags = 0; bool valueOk = true; - QStringList keys = s.split(QString(QLatin1Char('|'))); - for (auto it = keys.constBegin(), cend = keys.constEnd(); it != cend; ++it) { - const uint flagValue = keyToValue(*it, &valueOk); + const auto keys = QStringView{s}.split(u'|'); + for (const auto &key : keys) { + const uint flagValue = keyToValue(key, &valueOk); if (!valueOk) { flags = 0; break; @@ -261,7 +241,7 @@ namespace qdesigner_internal { return QCoreApplication::translate("DesignerMetaFlags", "'%1' could not be converted to a flag value of type '%2'.") - .arg(s, name()); + .arg(s, enumName()); } // ---------- PropertySheetEnumValue @@ -294,12 +274,7 @@ namespace qdesigner_internal { if (const QDesignerLanguageExtension *lang = qt_extension<QDesignerLanguageExtension *>(core->extensionManager(), core)) return lang->isLanguageResource(path) ? LanguageResourcePixmap : FilePixmap; - return path.startsWith(QLatin1Char(':')) ? ResourcePixmap : FilePixmap; - } - - int PropertySheetPixmapValue::compare(const PropertySheetPixmapValue &other) const - { - return m_path.compare(other.m_path); + return path.startsWith(u':') ? ResourcePixmap : FilePixmap; } QString PropertySheetPixmapValue::path() const @@ -320,6 +295,7 @@ namespace qdesigner_internal public: PropertySheetIconValue::ModeStateToPixmapMap m_paths; QString m_theme; + int m_themeEnum = -1; }; PropertySheetIconValue::PropertySheetIconValue(const PropertySheetPixmapValue &pixmap) : @@ -335,52 +311,37 @@ namespace qdesigner_internal PropertySheetIconValue::~PropertySheetIconValue() = default; - PropertySheetIconValue::PropertySheetIconValue(const PropertySheetIconValue &rhs) : - m_data(rhs.m_data) - { - } + PropertySheetIconValue::PropertySheetIconValue(const PropertySheetIconValue &rhs) noexcept = default; + PropertySheetIconValue &PropertySheetIconValue::operator=(const PropertySheetIconValue &rhs) = default; - PropertySheetIconValue &PropertySheetIconValue::operator=(const PropertySheetIconValue &rhs) - { - if (this != &rhs) - m_data.operator=(rhs.m_data); - return *this; - } + PropertySheetIconValue::PropertySheetIconValue(PropertySheetIconValue &&) noexcept = default; + PropertySheetIconValue &PropertySheetIconValue::operator=(PropertySheetIconValue &&) noexcept = default; + +} // namespace qdesigner_internal + +namespace qdesigner_internal { - bool PropertySheetIconValue::equals(const PropertySheetIconValue &rhs) const + size_t qHash(const PropertySheetIconValue &p, size_t seed) noexcept { - return m_data->m_theme == rhs.m_data->m_theme && m_data->m_paths == rhs.m_data->m_paths; + // qHash for paths making use of the existing QPair hash functions. + const auto *d = p.m_data.constData(); + return qHashMulti(seed, d->m_paths, d->m_themeEnum, d->m_theme); } - bool PropertySheetIconValue::operator<(const PropertySheetIconValue &other) const + bool comparesEqual(const PropertySheetIconValue &lhs, + const PropertySheetIconValue &rhs) noexcept { - if (const int themeCmp = m_data->m_theme.compare(other.m_data->m_theme)) - return themeCmp < 0; - auto itThis = m_data->m_paths.cbegin(); - auto itThisEnd = m_data->m_paths.cend(); - auto itOther = other.m_data->m_paths.cbegin(); - auto itOtherEnd = other.m_data->m_paths.cend(); - while (itThis != itThisEnd && itOther != itOtherEnd) { - const ModeStateKey thisPair = itThis.key(); - const ModeStateKey otherPair = itOther.key(); - if (thisPair < otherPair) - return true; - if (otherPair < thisPair) - return false; - const int crc = itThis.value().compare(itOther.value()); - if (crc < 0) - return true; - if (crc > 0) - return false; - ++itThis; - ++itOther; - } - return itOther != itOtherEnd; + const auto *lhsd = lhs.m_data.constData(); + const auto *rhsd = rhs.m_data.constData(); + return lhsd == rhsd + || (lhsd->m_themeEnum == rhsd->m_themeEnum + && lhsd->m_theme == rhsd->m_theme && lhsd->m_paths == rhsd->m_paths); } bool PropertySheetIconValue::isEmpty() const { - return m_data->m_theme.isEmpty() && m_data->m_paths.isEmpty(); + return m_data->m_themeEnum == -1 && m_data->m_theme.isEmpty() + && m_data->m_paths.isEmpty(); } QString PropertySheetIconValue::theme() const @@ -393,15 +354,25 @@ namespace qdesigner_internal m_data->m_theme = t; } + int PropertySheetIconValue::themeEnum() const + { + return m_data->m_themeEnum; + } + + void PropertySheetIconValue::setThemeEnum(int e) + { + m_data->m_themeEnum = e; + } + PropertySheetPixmapValue PropertySheetIconValue::pixmap(QIcon::Mode mode, QIcon::State state) const { - const ModeStateKey pair = qMakePair(mode, state); + const ModeStateKey pair{mode, state}; return m_data->m_paths.value(pair); } void PropertySheetIconValue::setPixmap(QIcon::Mode mode, QIcon::State state, const PropertySheetPixmapValue &pixmap) { - const ModeStateKey pair = qMakePair(mode, state); + const ModeStateKey pair{mode, state}; if (pixmap.path().isEmpty()) m_data->m_paths.remove(pair); else @@ -410,7 +381,7 @@ namespace qdesigner_internal QPixmap DesignerPixmapCache::pixmap(const PropertySheetPixmapValue &value) const { - QMap<PropertySheetPixmapValue, QPixmap>::const_iterator it = m_cache.constFind(value); + const auto it = m_cache.constFind(value); if (it != m_cache.constEnd()) return it.value(); @@ -436,6 +407,11 @@ namespace qdesigner_internal return it.value(); // Match on the theme first if it is available. + if (value.themeEnum() != -1) { + const QIcon themeIcon = QIcon::fromTheme(static_cast<QIcon::ThemeIcon>(value.themeEnum())); + m_cache.insert(value, themeIcon); + return themeIcon; + } if (!value.theme().isEmpty()) { const QString theme = value.theme(); if (QIcon::hasThemeIcon(theme)) { @@ -470,14 +446,6 @@ namespace qdesigner_internal PropertySheetTranslatableData::PropertySheetTranslatableData(bool translatable, const QString &disambiguation, const QString &comment) : m_translatable(translatable), m_disambiguation(disambiguation), m_comment(comment) { } - bool PropertySheetTranslatableData::equals(const PropertySheetTranslatableData &rhs) const - { - return m_translatable == rhs.m_translatable - && m_disambiguation == rhs.m_disambiguation - && m_comment == rhs.m_comment - && m_id == rhs.m_id; - } - PropertySheetStringValue::PropertySheetStringValue(const QString &value, bool translatable, const QString &disambiguation, const QString &comment) : PropertySheetTranslatableData(translatable, disambiguation, comment), m_value(value) {} @@ -492,11 +460,6 @@ namespace qdesigner_internal m_value = value; } - bool PropertySheetStringValue::equals(const PropertySheetStringValue &rhs) const - { - return m_value == rhs.m_value && PropertySheetTranslatableData::equals(rhs); - } - PropertySheetStringListValue::PropertySheetStringListValue(const QStringList &value, bool translatable, const QString &disambiguation, @@ -515,11 +478,6 @@ namespace qdesigner_internal m_value = value; } - bool PropertySheetStringListValue::equals(const PropertySheetStringListValue &rhs) const - { - return m_value == rhs.m_value && PropertySheetTranslatableData::equals(rhs); - } - QStringList m_value; @@ -560,12 +518,6 @@ namespace qdesigner_internal return m_standardKey != QKeySequence::UnknownKey; } - bool PropertySheetKeySequenceValue::equals(const PropertySheetKeySequenceValue &rhs) const - { - return m_value == rhs.m_value && m_standardKey == rhs.m_standardKey - && PropertySheetTranslatableData::equals(rhs); - } - /* IconSubPropertyMask: Assign each icon sub-property (pixmaps for the * various states/modes and the theme) a flag bit (see QFont) so that they * can be handled individually when assigning property values to @@ -582,7 +534,8 @@ namespace qdesigner_internal ActiveOnIconMask = 0x20, SelectedOffIconMask = 0x40, SelectedOnIconMask = 0x80, - ThemeIconMask = 0x10000 + ThemeIconMask = 0x10000, + ThemeEnumIconMask = 0x20000 }; static inline uint iconStateToSubPropertyFlag(QIcon::Mode mode, QIcon::State state) @@ -600,28 +553,28 @@ namespace qdesigner_internal return state == QIcon::On ? NormalOnIconMask : NormalOffIconMask; } - static inline QPair<QIcon::Mode, QIcon::State> subPropertyFlagToIconModeState(unsigned flag) + static inline std::pair<QIcon::Mode, QIcon::State> subPropertyFlagToIconModeState(unsigned flag) { switch (flag) { case NormalOnIconMask: - return qMakePair(QIcon::Normal, QIcon::On); + return {QIcon::Normal, QIcon::On}; case DisabledOffIconMask: - return qMakePair(QIcon::Disabled, QIcon::Off); + return {QIcon::Disabled, QIcon::Off}; case DisabledOnIconMask: - return qMakePair(QIcon::Disabled, QIcon::On); + return {QIcon::Disabled, QIcon::On}; case ActiveOffIconMask: - return qMakePair(QIcon::Active, QIcon::Off); + return {QIcon::Active, QIcon::Off}; case ActiveOnIconMask: - return qMakePair(QIcon::Active, QIcon::On); + return {QIcon::Active, QIcon::On}; case SelectedOffIconMask: - return qMakePair(QIcon::Selected, QIcon::Off); + return {QIcon::Selected, QIcon::Off}; case SelectedOnIconMask: - return qMakePair(QIcon::Selected, QIcon::On); + return {QIcon::Selected, QIcon::On}; case NormalOffIconMask: default: break; } - return qMakePair(QIcon::Normal, QIcon::Off); + return {QIcon::Normal, QIcon::Off}; } uint PropertySheetIconValue::mask() const @@ -631,6 +584,8 @@ namespace qdesigner_internal flags |= iconStateToSubPropertyFlag(it.key().first, it.key().second); if (!m_data->m_theme.isEmpty()) flags |= ThemeIconMask; + if (m_data->m_themeEnum != -1) + flags |= ThemeEnumIconMask; return flags; } @@ -640,13 +595,16 @@ namespace qdesigner_internal for (int i = 0; i < 8; i++) { const uint flag = 1 << i; if (diffMask & flag) { // if state is set in both icons, compare the values - const QPair<QIcon::Mode, QIcon::State> state = subPropertyFlagToIconModeState(flag); + const auto state = subPropertyFlagToIconModeState(flag); if (pixmap(state.first, state.second) == other.pixmap(state.first, state.second)) diffMask &= ~flag; } } if ((diffMask & ThemeIconMask) && theme() == other.theme()) diffMask &= ~ThemeIconMask; + if ((diffMask & ThemeEnumIconMask) && themeEnum() == other.themeEnum()) + diffMask &= ~ThemeEnumIconMask; + return diffMask; } @@ -661,6 +619,7 @@ namespace qdesigner_internal { PropertySheetIconValue rc(*this); rc.m_data->m_theme.clear(); + rc.m_data->m_themeEnum = -1; return rc; } @@ -675,6 +634,8 @@ namespace qdesigner_internal } if (mask & ThemeIconMask) setTheme(other.theme()); + if (mask & ThemeEnumIconMask) + setThemeEnum(other.themeEnum()); } const PropertySheetIconValue::ModeStateToPixmapMap &PropertySheetIconValue::paths() const @@ -682,17 +643,24 @@ namespace qdesigner_internal return m_data->m_paths; } - QDESIGNER_SHARED_EXPORT QDebug operator<<(QDebug d, const PropertySheetIconValue &p) + QDESIGNER_SHARED_EXPORT QDebug operator<<(QDebug debug, const PropertySheetIconValue &p) { - QDebug nospace = d.nospace(); - nospace << "PropertySheetIconValue theme='" << p.theme() << "' "; + QDebugStateSaver saver(debug); + debug.nospace(); + debug.noquote(); + debug << "PropertySheetIconValue(mask=0x" << Qt::hex << p.mask() << Qt::dec << ", "; + if (p.themeEnum() != -1) + debug << "theme=" << p.themeEnum() << ", "; + if (!p.theme().isEmpty()) + debug << "XDG theme=\"" << p.theme() << "\", "; const PropertySheetIconValue::ModeStateToPixmapMap &paths = p.paths(); - for (auto it = paths.constBegin(), cend = paths.constEnd(); it != cend; ++it) - nospace << " mode=" << it.key().first << ",state=" << it.key().second - << ",'" << it.value().path() << '\''; - nospace << " mask=0x" << QString::number(p.mask(), 16); - return d; + for (auto it = paths.constBegin(), cend = paths.constEnd(); it != cend; ++it) { + debug << " mode=" << it.key().first << ",state=" << it.key().second + << ", \"" << it.value().path() << '"'; + } + debug << ')'; + return debug; } QDESIGNER_SHARED_EXPORT QDesignerFormWindowCommand *createTextPropertyCommand(const QString &propertyName, const QString &text, QObject *object, QDesignerFormWindowInterface *fw) @@ -719,8 +687,8 @@ namespace qdesigner_internal } } if (!action) { - if (const QDesignerTaskMenuExtension *taskMenu = qobject_cast<QDesignerTaskMenuExtension *>( - core->extensionManager()->extension(managedWidget, QStringLiteral("QDesignerInternalTaskMenuExtension")))) { + if (const auto *taskMenu = qobject_cast<QDesignerTaskMenuExtension *>( + core->extensionManager()->extension(managedWidget, u"QDesignerInternalTaskMenuExtension"_s))) { action = taskMenu->preferredEditAction(); if (!action) { const auto actions = taskMenu->taskActions(); @@ -737,12 +705,25 @@ namespace qdesigner_internal { QProcess uic; QStringList arguments; - QString binary = QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath) + QStringLiteral("/uic"); + static constexpr auto uicBinary = + QOperatingSystemVersion::currentType() != QOperatingSystemVersion::Windows + ? "/uic"_L1 : "/uic.exe"_L1; + QString binary = QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath) + uicBinary; + // In a PySide6 installation, there is no libexec directory; uic.exe is + // in the main wheel directory next to designer.exe. + if (!QFileInfo::exists(binary)) + binary = QCoreApplication::applicationDirPath() + uicBinary; + if (!QFileInfo::exists(binary)) { + errorMessage = QApplication::translate("Designer", "%1 does not exist."). + arg(QDir::toNativeSeparators(binary)); + return false; + } + switch (language) { case UicLanguage::Cpp: break; case UicLanguage::Python: - arguments << QLatin1String("-g") << QLatin1String("python"); + arguments << u"-g"_s << u"python"_s; break; } arguments << fileName; @@ -772,14 +753,14 @@ namespace qdesigner_internal Q_ASSERT(qname.isEmpty() == false); - if (qname.count() > 1 && qname.at(1).isUpper()) { + if (qname.size() > 1 && qname.at(1).isUpper()) { const QChar first = qname.at(0); - if (first == QLatin1Char('Q') || first == QLatin1Char('K')) + if (first == u'Q' || first == u'K') qname.remove(0, 1); } - const int len = qname.count(); - for (int i = 0; i < len && qname.at(i).isUpper(); i++) + const qsizetype len = qname.size(); + for (qsizetype i = 0; i < len && qname.at(i).isUpper(); ++i) qname[i] = qname.at(i).toLower(); return qname; @@ -800,6 +781,24 @@ namespace qdesigner_internal m_widget->setUpdatesEnabled(true); } +// from qpalette.cpp +quint64 paletteResolveMask(QPalette::ColorGroup colorGroup, + QPalette::ColorRole colorRole) +{ + if (colorRole == QPalette::Accent) + colorRole = QPalette::NoRole; // See qtbase/17c589df94a2245ee92d45839c2cba73566d7310 + const auto offset = quint64(QPalette::NColorRoles - 1) * quint64(colorGroup); + const auto bitPos = quint64(colorRole) + offset; + return 1ull << bitPos; +} + +quint64 paletteResolveMask(QPalette::ColorRole colorRole) +{ + return paletteResolveMask(QPalette::Active, colorRole) + | paletteResolveMask(QPalette::Inactive, colorRole) + | paletteResolveMask(QPalette::Disabled, colorRole); +} + } // namespace qdesigner_internal QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/qdesigner_utils_p.h b/src/designer/src/lib/shared/qdesigner_utils_p.h index 73d907bed..223a12337 100644 --- a/src/designer/src/lib/shared/qdesigner_utils_p.h +++ b/src/designer/src/lib/shared/qdesigner_utils_p.h @@ -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 // // W A R N I N G @@ -44,13 +19,16 @@ #include <QtDesigner/abstractformwindow.h> +#include <QtCore/qcompare.h> +#include <QtCore/qhash.h> #include <QtCore/qvariant.h> #include <QtCore/qshareddata.h> -#include <QtCore/qmap.h> #include <QtWidgets/qmainwindow.h> #include <QtGui/qicon.h> #include <QtGui/qpixmap.h> +#include <map> + QT_BEGIN_NAMESPACE class QDebug; @@ -85,17 +63,17 @@ template <class IntType> class MetaEnum { public: - using KeyToValueMap = QMap<QString, IntType>; + using KeyToValueMap = std::map<QString, IntType, std::less<>>; - MetaEnum(const QString &name, const QString &scope, const QString &separator); + MetaEnum(const QString &enumName, const QString &scope, const QString &separator); MetaEnum() = default; void addKey(IntType value, const QString &name); QString valueToKey(IntType value, bool *ok = nullptr) const; // Ignorant of scopes. - IntType keyToValue(QString key, bool *ok = nullptr) const; + IntType keyToValue(QStringView key, bool *ok = nullptr) const; - const QString &name() const { return m_name; } + const QString &enumName() const { return m_enumName; } const QString &scope() const { return m_scope; } const QString &separator() const { return m_separator; } @@ -106,7 +84,7 @@ protected: void appendQualifiedName(const QString &key, QString &target) const; private: - QString m_name; + QString m_enumName; QString m_scope; QString m_separator; KeyToValueMap m_keyToValueMap; @@ -114,8 +92,8 @@ private: }; template <class IntType> -MetaEnum<IntType>::MetaEnum(const QString &name, const QString &scope, const QString &separator) : - m_name(name), +MetaEnum<IntType>::MetaEnum(const QString &enumName, const QString &scope, const QString &separator) : + m_enumName(enumName), m_scope(scope), m_separator(separator) { @@ -124,29 +102,36 @@ MetaEnum<IntType>::MetaEnum(const QString &name, const QString &scope, const QSt template <class IntType> void MetaEnum<IntType>::addKey(IntType value, const QString &name) { - m_keyToValueMap.insert(name, value); + m_keyToValueMap.insert({name, value}); m_keys.append(name); } template <class IntType> QString MetaEnum<IntType>::valueToKey(IntType value, bool *ok) const { - const QString rc = m_keyToValueMap.key(value); + QString rc; + for (auto it = m_keyToValueMap.begin(), end = m_keyToValueMap.end(); it != end; ++it) { + if (it->second == value) { + rc = it->first; + break; + } + } if (ok) *ok = !rc.isEmpty(); return rc; } template <class IntType> -IntType MetaEnum<IntType>::keyToValue(QString key, bool *ok) const +IntType MetaEnum<IntType>::keyToValue(QStringView key, bool *ok) const { - if (!m_scope.isEmpty() && key.startsWith(m_scope)) - key.remove(0, m_scope.size() + m_separator.size()); - const typename KeyToValueMap::const_iterator it = m_keyToValueMap.find(key); - const bool found = it != m_keyToValueMap.constEnd(); + const auto lastSep = key.lastIndexOf(m_separator); + if (lastSep != -1) + key = key.sliced(lastSep + m_separator.size()); + const auto it = m_keyToValueMap.find(key); + const bool found = it != m_keyToValueMap.end(); if (ok) *ok = found; - return found ? it.value() : IntType(0); + return found ? it->second : IntType(0); } template <class IntType> @@ -156,7 +141,7 @@ void MetaEnum<IntType>::appendQualifiedName(const QString &key, QString &target) target += m_scope; target += m_separator; } - target += key; + target += m_enumName + m_separator + key; } // -------------- DesignerMetaEnum: Meta type for enumerations @@ -184,7 +169,8 @@ public: class QDESIGNER_SHARED_EXPORT DesignerMetaFlags : public MetaEnum<uint> { public: - DesignerMetaFlags(const QString &name, const QString &scope, const QString &separator); + explicit DesignerMetaFlags(const QString &enumName, const QString &scope, + const QString &separator); DesignerMetaFlags() = default; enum SerializationMode { FullyQualified, NameOnly }; @@ -225,10 +211,6 @@ public: PropertySheetPixmapValue(const QString &path); PropertySheetPixmapValue(); - bool operator==(const PropertySheetPixmapValue &other) const { return compare(other) == 0; } - bool operator!=(const PropertySheetPixmapValue &other) const { return compare(other) != 0; } - bool operator<(const PropertySheetPixmapValue &other) const { return compare(other) < 0; } - // Check where a pixmap comes from enum PixmapSource { LanguageResourcePixmap , ResourcePixmap, FilePixmap }; static PixmapSource getPixmapSource(QDesignerFormEditorInterface *core, const QString & path); @@ -238,9 +220,18 @@ public: QString path() const; void setPath(const QString &path); // passing the empty path resets the pixmap - int compare(const PropertySheetPixmapValue &other) const; - private: + friend size_t qHash(const PropertySheetPixmapValue &p, size_t seed = 0) noexcept + { + return qHash(p.m_path, seed); + } + friend bool comparesEqual(const PropertySheetPixmapValue &lhs, + const PropertySheetPixmapValue &rhs) noexcept + { + return lhs.m_path == rhs.m_path; + } + Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetPixmapValue) + QString m_path; }; @@ -251,21 +242,22 @@ class PropertySheetIconValueData; class QDESIGNER_SHARED_EXPORT PropertySheetIconValue { public: - PropertySheetIconValue(const PropertySheetPixmapValue &pixmap); + explicit PropertySheetIconValue(const PropertySheetPixmapValue &pixmap); PropertySheetIconValue(); ~PropertySheetIconValue(); - PropertySheetIconValue(const PropertySheetIconValue &); + PropertySheetIconValue(const PropertySheetIconValue &) noexcept; PropertySheetIconValue &operator=(const PropertySheetIconValue &); - - bool operator==(const PropertySheetIconValue &other) const { return equals(other); } - bool operator!=(const PropertySheetIconValue &other) const { return !equals(other); } - bool operator<(const PropertySheetIconValue &other) const; + PropertySheetIconValue(PropertySheetIconValue &&) noexcept; + PropertySheetIconValue &operator=(PropertySheetIconValue &&) noexcept; bool isEmpty() const; QString theme() const; void setTheme(const QString &); + int themeEnum() const; + void setThemeEnum(int e); + PropertySheetPixmapValue pixmap(QIcon::Mode mode, QIcon::State state) const; void setPixmap(QIcon::Mode mode, QIcon::State state, const PropertySheetPixmapValue &path); // passing the empty path resets the pixmap @@ -277,13 +269,21 @@ class QDESIGNER_SHARED_EXPORT PropertySheetIconValue PropertySheetIconValue themed() const; PropertySheetIconValue unthemed() const; - using ModeStateKey = QPair<QIcon::Mode, QIcon::State>; + using ModeStateKey = std::pair<QIcon::Mode, QIcon::State>; using ModeStateToPixmapMap = QMap<ModeStateKey, PropertySheetPixmapValue>; const ModeStateToPixmapMap &paths() const; private: - bool equals(const PropertySheetIconValue &rhs) const; + friend QDESIGNER_SHARED_EXPORT + size_t qHash(const PropertySheetIconValue &p, size_t seed) noexcept; + friend size_t qHash(const PropertySheetIconValue &p) noexcept + { return qHash(p, 0); } + friend QDESIGNER_SHARED_EXPORT + bool comparesEqual(const PropertySheetIconValue &lhs, + const PropertySheetIconValue &rhs) noexcept; + Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetIconValue) + QSharedDataPointer<PropertySheetIconValueData> m_data; }; @@ -299,7 +299,7 @@ public: signals: void reloaded(); private: - mutable QMap<PropertySheetPixmapValue, QPixmap> m_cache; + mutable QHash<PropertySheetPixmapValue, QPixmap> m_cache; friend class FormWindowBase; }; @@ -313,7 +313,7 @@ public: signals: void reloaded(); private: - mutable QMap<PropertySheetIconValue, QIcon> m_cache; + mutable QHash<PropertySheetIconValue, QIcon> m_cache; DesignerPixmapCache *m_pixmapCache; friend class FormWindowBase; }; @@ -325,7 +325,6 @@ protected: PropertySheetTranslatableData(bool translatable = true, const QString &disambiguation = QString(), const QString &comment = QString()); - bool equals(const PropertySheetTranslatableData &rhs) const; public: bool translatable() const { return m_translatable; } @@ -338,6 +337,16 @@ public: void setId(const QString &id) { m_id = id; } private: + friend bool comparesEqual(const PropertySheetTranslatableData &lhs, + const PropertySheetTranslatableData &rhs) noexcept + { + return lhs.m_translatable == rhs.m_translatable + && lhs.m_disambiguation == rhs.m_disambiguation + && lhs.m_comment == rhs.m_comment + && lhs.m_id == rhs.m_id; + } + Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetTranslatableData) + bool m_translatable; QString m_disambiguation; QString m_comment; @@ -351,14 +360,18 @@ public: PropertySheetStringValue(const QString &value = QString(), bool translatable = true, const QString &disambiguation = QString(), const QString &comment = QString()); - bool operator==(const PropertySheetStringValue &other) const { return equals(other); } - bool operator!=(const PropertySheetStringValue &other) const { return !equals(other); } - QString value() const; void setValue(const QString &value); private: - bool equals(const PropertySheetStringValue &rhs) const; + friend bool comparesEqual(const PropertySheetStringValue &lhs, + const PropertySheetStringValue &rhs) noexcept + { + const PropertySheetTranslatableData &upLhs = lhs; + const PropertySheetTranslatableData &upRhs = rhs; + return lhs.m_value == rhs.m_value && upLhs == upRhs; + } + Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetStringValue) QString m_value; }; @@ -372,14 +385,18 @@ public: const QString &disambiguation = QString(), const QString &comment = QString()); - bool operator==(const PropertySheetStringListValue &other) const { return equals(other); } - bool operator!=(const PropertySheetStringListValue &other) const { return !equals(other); } - QStringList value() const; void setValue(const QStringList &value); private: - bool equals(const PropertySheetStringListValue &rhs) const; + friend bool comparesEqual(const PropertySheetStringListValue &lhs, + const PropertySheetStringListValue &rhs) noexcept + { + const PropertySheetTranslatableData &upLhs = lhs; + const PropertySheetTranslatableData &upRhs = rhs; + return lhs.m_value == rhs.m_value && upLhs == upRhs; + } + Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetStringListValue) QStringList m_value; }; @@ -397,9 +414,6 @@ public: const QString &disambiguation = QString(), const QString &comment = QString()); - bool operator==(const PropertySheetKeySequenceValue &other) const { return equals(other); } - bool operator!=(const PropertySheetKeySequenceValue &other) const { return !equals(other); } - QKeySequence value() const; void setValue(const QKeySequence &value); QKeySequence::StandardKey standardKey() const; @@ -407,7 +421,15 @@ public: bool isStandardKey() const; private: - bool equals(const PropertySheetKeySequenceValue &rhs) const; + friend bool comparesEqual(const PropertySheetKeySequenceValue &lhs, + const PropertySheetKeySequenceValue &rhs) noexcept + { + const PropertySheetTranslatableData &upLhs = lhs; + const PropertySheetTranslatableData &upRhs = rhs; + return lhs.m_value == rhs.m_value && lhs.m_standardKey == rhs.m_standardKey + && upLhs == upRhs; + } + Q_DECLARE_EQUALITY_COMPARABLE(PropertySheetKeySequenceValue) QKeySequence m_value; QKeySequence::StandardKey m_standardKey; @@ -468,6 +490,12 @@ private: const bool m_enabled; }; +// QPalette helpers: Mask for a single color role/group +QDESIGNER_SHARED_EXPORT quint64 paletteResolveMask(QPalette::ColorGroup colorGroup, + QPalette::ColorRole colorRole); +// Mask for the colors of a role in all groups (Active/Inactive/Disabled) +QDESIGNER_SHARED_EXPORT quint64 paletteResolveMask(QPalette::ColorRole colorRole); + namespace Utils { inline int valueOf(const QVariant &value, bool *ok = nullptr) diff --git a/src/designer/src/lib/shared/qdesigner_widget.cpp b/src/designer/src/lib/shared/qdesigner_widget.cpp index b4f885006..88f43d5ab 100644 --- a/src/designer/src/lib/shared/qdesigner_widget.cpp +++ b/src/designer/src/lib/shared/qdesigner_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 "qdesigner_widget_p.h" #include "formwindowbase_p.h" diff --git a/src/designer/src/lib/shared/qdesigner_widget_p.h b/src/designer/src/lib/shared/qdesigner_widget_p.h index c12970692..4deeaaf83 100644 --- a/src/designer/src/lib/shared/qdesigner_widget_p.h +++ b/src/designer/src/lib/shared/qdesigner_widget_p.h @@ -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 // // W A R N I N G @@ -80,7 +55,7 @@ public: explicit QDesignerDialog(QDesignerFormWindowInterface *fw, QWidget *parent); QSize minimumSizeHint() const override - { return QWidget::minimumSizeHint().expandedTo(QSize(16, 16)); } + { return QDialog::minimumSizeHint().expandedTo(QSize(16, 16)); } protected: void paintEvent(QPaintEvent *e) override; diff --git a/src/designer/src/lib/shared/qdesigner_widgetbox.cpp b/src/designer/src/lib/shared/qdesigner_widgetbox.cpp index 03cd9a3ad..260f68a9c 100644 --- a/src/designer/src/lib/shared/qdesigner_widgetbox.cpp +++ b/src/designer/src/lib/shared/qdesigner_widgetbox.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 "qdesigner_widgetbox_p.h" #include "qdesigner_utils_p.h" @@ -38,6 +13,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QDesignerWidgetBoxWidgetData : public QSharedData { public: @@ -86,7 +63,8 @@ QString QDesignerWidgetBoxInterface::Widget::name() const void QDesignerWidgetBoxInterface::Widget::setName(const QString &aname) { - m_data->m_name = aname; + if (m_data->m_name != aname) + m_data->m_name = aname; } QString QDesignerWidgetBoxInterface::Widget::domXml() const @@ -96,7 +74,8 @@ QString QDesignerWidgetBoxInterface::Widget::domXml() const void QDesignerWidgetBoxInterface::Widget::setDomXml(const QString &xml) { - m_data->m_xml = xml; + if (m_data->m_xml != xml) + m_data->m_xml = xml; } QString QDesignerWidgetBoxInterface::Widget::iconName() const @@ -106,7 +85,8 @@ QString QDesignerWidgetBoxInterface::Widget::iconName() const void QDesignerWidgetBoxInterface::Widget::setIconName(const QString &icon_name) { - m_data->m_icon_name = icon_name; + if (m_data->m_icon_name != icon_name) + m_data->m_icon_name = icon_name; } QDesignerWidgetBoxInterface::Widget::Type QDesignerWidgetBoxInterface::Widget::type() const @@ -116,7 +96,8 @@ QDesignerWidgetBoxInterface::Widget::Type QDesignerWidgetBoxInterface::Widget::t void QDesignerWidgetBoxInterface::Widget::setType(Type atype) { - m_data->m_type = atype; + if (m_data->m_type != atype) + m_data->m_type = atype; } bool QDesignerWidgetBoxInterface::Widget::isNull() const @@ -150,7 +131,6 @@ bool QDesignerWidgetBox::findWidget(const QDesignerWidgetBoxInterface *wbox, // Note that entry names do not necessarily match the class name // (at least, not for the standard widgets), so, // look in the XML for the class name of the first widget to appear - const QString widgetTag = QStringLiteral("<widget"); QString pattern = QStringLiteral("^<widget\\s+class\\s*=\\s*\""); pattern += className; pattern += QStringLiteral("\".*$"); @@ -164,7 +144,7 @@ bool QDesignerWidgetBox::findWidget(const QDesignerWidgetBoxInterface *wbox, for (int w = 0; w < widgetCount; w++) { const Widget widget = cat.widget(w); QString xml = widget.domXml(); // Erase the <ui> tag that can be present starting from 4.4 - const int widgetTagIndex = xml.indexOf(widgetTag); + const auto widgetTagIndex = xml.indexOf("<widget"_L1); if (widgetTagIndex != -1) { xml.remove(0, widgetTagIndex); if (regexp.match(xml).hasMatch()) { @@ -196,12 +176,12 @@ DomUI *QDesignerWidgetBox::xmlToUi(const QString &name, const QString &xml, bool continue; } - if (name.compare(QStringLiteral("widget"), Qt::CaseInsensitive) == 0) { // 4.3 legacy, wrap into DomUI + if (name.compare("widget"_L1, Qt::CaseInsensitive) == 0) { // 4.3 legacy, wrap into DomUI ui = new DomUI; DomWidget *widget = new DomWidget; widget->read(reader); ui->setElementWidget(widget); - } else if (name.compare(QStringLiteral("ui"), Qt::CaseInsensitive) == 0) { // 4.4 + } else if (name.compare("ui"_L1, Qt::CaseInsensitive) == 0) { // 4.4 ui = new DomUI; ui->read(reader); } else { @@ -228,7 +208,7 @@ DomUI *QDesignerWidgetBox::xmlToUi(const QString &name, const QString &xml, bool if (insertFakeTopLevel) { DomWidget *fakeTopLevel = new DomWidget; - fakeTopLevel->setAttributeClass(QStringLiteral("QWidget")); + fakeTopLevel->setAttributeClass(u"QWidget"_s); QList<DomWidget *> children; children.push_back(ui->takeElementWidget()); fakeTopLevel->setElementWidget(children); diff --git a/src/designer/src/lib/shared/qdesigner_widgetbox_p.h b/src/designer/src/lib/shared/qdesigner_widgetbox_p.h index cad8e04da..813d65893 100644 --- a/src/designer/src/lib/shared/qdesigner_widgetbox_p.h +++ b/src/designer/src/lib/shared/qdesigner_widgetbox_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qdesigner_widgetitem.cpp b/src/designer/src/lib/shared/qdesigner_widgetitem.cpp index e6e6cd00a..b986aede8 100644 --- a/src/designer/src/lib/shared/qdesigner_widgetitem.cpp +++ b/src/designer/src/lib/shared/qdesigner_widgetitem.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 "qdesigner_widgetitem_p.h" #include "qdesigner_widget_p.h" diff --git a/src/designer/src/lib/shared/qdesigner_widgetitem_p.h b/src/designer/src/lib/shared/qdesigner_widgetitem_p.h index 7b3ed395f..b7a533e08 100644 --- a/src/designer/src/lib/shared/qdesigner_widgetitem_p.h +++ b/src/designer/src/lib/shared/qdesigner_widgetitem_p.h @@ -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 // // W A R N I N G 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); } diff --git a/src/designer/src/lib/shared/qlayout_widget_p.h b/src/designer/src/lib/shared/qlayout_widget_p.h index 1efe3a905..16185d5ec 100644 --- a/src/designer/src/lib/shared/qlayout_widget_p.h +++ b/src/designer/src/lib/shared/qlayout_widget_p.h @@ -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 // // W A R N I N G @@ -182,7 +157,7 @@ public: InsertMode currentInsertMode() const override { return m_currentInsertMode; } - QPair<int, int> currentCell() const override { return m_currentCell; } + std::pair<int, int> currentCell() const override { return m_currentCell; } int findItemAt(const QPoint &pos) const override; int indexOf(QWidget *widget) const override; @@ -201,6 +176,7 @@ public: // grid helpers: find item index static int findItemAt(QGridLayout *, int row, int column); + using QDesignerLayoutDecorationExtension::findItemAt; // grid helpers: Quick check whether simplify should be enabled for grids. May return false positives. static bool canSimplifyQuickCheck(const QGridLayout *); static bool canSimplifyQuickCheck(const QFormLayout *fl); @@ -224,7 +200,7 @@ protected: QWidget *widget() const { return m_widget; } void setInsertMode(InsertMode im); - void setCurrentCell(const QPair<int, int> &cell); + void setCurrentCell(const std::pair<int, int> &cell); private: enum Indicator { LeftIndicator, TopIndicator, RightIndicator, BottomIndicator, NumIndicators }; @@ -239,7 +215,7 @@ private: QPointer<QWidget> m_indicators[NumIndicators]; int m_currentIndex; InsertMode m_currentInsertMode; - QPair<int, int> m_currentCell; + std::pair<int, int> m_currentCell; }; } // namespace qdesigner_internal diff --git a/src/designer/src/lib/shared/qsimpleresource.cpp b/src/designer/src/lib/shared/qsimpleresource.cpp index e988d0731..2b0ef4a07 100644 --- a/src/designer/src/lib/shared/qsimpleresource.cpp +++ b/src/designer/src/lib/shared/qsimpleresource.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 "qsimpleresource_p.h" #include "widgetfactory_p.h" @@ -51,6 +26,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { bool QSimpleResource::m_warningsEnabled = true; @@ -158,16 +135,16 @@ void QSimpleResource::addCustomWidgetsToWidgetDatabase(const QDesignerFormEditor QList<DomCustomWidget *> &custom_widget_list) { QDesignerWidgetDataBaseInterface *db = core->widgetDataBase(); - for (int i=0; i < custom_widget_list.size(); ) { + for (qsizetype i = 0; i < custom_widget_list.size(); ) { bool classInserted = false; - DomCustomWidget *custom_widget = custom_widget_list[i]; + DomCustomWidget *custom_widget = custom_widget_list.at(i); const QString customClassName = custom_widget->elementClass(); const QString base_class = custom_widget->elementExtends(); QString includeFile; IncludeType includeType = IncludeLocal; if (const DomHeader *header = custom_widget->elementHeader()) { includeFile = header->text(); - if (header->hasAttributeLocation() && header->attributeLocation() == QStringLiteral("global")) + if (header->hasAttributeLocation() && header->attributeLocation() == "global"_L1) includeType = IncludeGlobal; } const bool domIsContainer = custom_widget->elementContainer(); @@ -228,8 +205,8 @@ void QSimpleResource::handleDomCustomWidgets(const QDesignerFormEditorInterface } // Oops, there are classes left whose base class could not be found. // Default them to QWidget with warnings. - const QString fallBackBaseClass = QStringLiteral("QWidget"); - for (DomCustomWidget *custom_widget : qAsConst(custom_widget_list)) { + const QString fallBackBaseClass = u"QWidget"_s; + for (DomCustomWidget *custom_widget : std::as_const(custom_widget_list)) { const QString customClassName = custom_widget->elementClass(); const QString base_class = custom_widget->elementExtends(); qDebug() << "** WARNING The base class " << base_class << " of the custom widget class " << customClassName diff --git a/src/designer/src/lib/shared/qsimpleresource_p.h b/src/designer/src/lib/shared/qsimpleresource_p.h index 2c8ae1456..37b9f5c04 100644 --- a/src/designer/src/lib/shared/qsimpleresource_p.h +++ b/src/designer/src/lib/shared/qsimpleresource_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/qtresourceeditordialog.cpp b/src/designer/src/lib/shared/qtresourceeditordialog.cpp index 613c5d0c9..589363e54 100644 --- a/src/designer/src/lib/shared/qtresourceeditordialog.cpp +++ b/src/designer/src/lib/shared/qtresourceeditordialog.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 "qtresourceeditordialog_p.h" #include "ui_qtresourceeditordialog.h" @@ -36,6 +11,7 @@ #include <QtDesigner/abstractsettings.h> #include <QtDesigner/abstractformeditor.h> +#include <QtCore/qcompare.h> #include <QtCore/qfileinfo.h> #include <QtCore/qdir.h> #include <QtCore/qcoreapplication.h> @@ -49,15 +25,17 @@ QT_BEGIN_NAMESPACE -static const char *rccRootTag = "RCC"; -static const char *rccTag = "qresource"; -static const char *rccFileTag = "file"; -static const char *rccAliasAttribute = "alias"; -static const char *rccPrefixAttribute = "prefix"; -static const char *rccLangAttribute = "lang"; -static const char *SplitterPosition = "SplitterPosition"; -static const char *Geometry = "Geometry"; -static const char *QrcDialogC = "QrcDialog"; +using namespace Qt::StringLiterals; + +static constexpr auto rccRootTag = "RCC"_L1; +static constexpr auto rccTag = "qresource"_L1; +static constexpr auto rccFileTag = "file"_L1; +static constexpr auto rccAliasAttribute = "alias"_L1; +static constexpr auto rccPrefixAttribute = "prefix"_L1; +static constexpr auto rccLangAttribute = "lang"_L1; +static constexpr auto SplitterPosition = "SplitterPosition"_L1; +static constexpr auto ResourceEditorGeometry = "Geometry"_L1; +static constexpr auto QrcDialogC = "QrcDialog"_L1; static QString msgOverwrite(const QString &fname) { @@ -69,48 +47,71 @@ static QString msgTagMismatch(const QString &got, const QString &expected) return QCoreApplication::translate("QtResourceEditorDialog", "The file does not appear to be a resource file; element '%1' was found where '%2' was expected.").arg(got, expected); } -namespace { +namespace qdesigner_internal { // below 3 data classes should be derived from QSharedData and made implicit shared class -struct QtResourceFileData { +struct QtResourceFileData +{ QString path; QString alias; - bool operator==(const QtResourceFileData &other) const - { return path == other.path && alias == other.alias; } + + friend bool comparesEqual(const QtResourceFileData &lhs, + const QtResourceFileData &rhs) noexcept + { + return lhs.path == rhs.path && lhs.alias == rhs.alias; + } + Q_DECLARE_EQUALITY_COMPARABLE(QtResourceFileData) }; -struct QtResourcePrefixData { +struct QtResourcePrefixData +{ QString prefix; QString language; QList<QtResourceFileData> resourceFileList; - bool operator==(const QtResourcePrefixData &other) const + + friend bool comparesEqual(const QtResourcePrefixData &lhs, + const QtResourcePrefixData &rhs) noexcept { - return prefix == other.prefix && language == other.language - && resourceFileList == other.resourceFileList; + return lhs.prefix == rhs.prefix && lhs.language == rhs.language + && lhs.resourceFileList == rhs.resourceFileList; } + Q_DECLARE_EQUALITY_COMPARABLE(QtResourcePrefixData) }; -struct QtQrcFileData { +struct QtQrcFileData +{ QString qrcPath; QList<QtResourcePrefixData> resourceList; - bool operator==(const QtQrcFileData &other) const - { return qrcPath == other.qrcPath && resourceList == other.resourceList; } + + friend bool comparesEqual(const QtQrcFileData &lhs, + const QtQrcFileData &rhs) noexcept + { + return lhs.qrcPath == rhs.qrcPath && lhs.resourceList == rhs.resourceList; + } + Q_DECLARE_EQUALITY_COMPARABLE(QtQrcFileData) }; -bool loadResourceFileData(const QDomElement &fileElem, QtResourceFileData *fileData, QString *errorMessage) +} // namespace qdesigner_internal + +using QtResourcePrefixData = qdesigner_internal::QtResourcePrefixData; +using QtResourceFileData = qdesigner_internal::QtResourceFileData; +using QtQrcFileData = qdesigner_internal::QtQrcFileData; + +static bool loadResourceFileData(const QDomElement &fileElem, QtResourceFileData *fileData, + QString *errorMessage) { if (!fileData) return false; - if (fileElem.tagName() != QLatin1String(rccFileTag)) { - *errorMessage = msgTagMismatch(fileElem.tagName(), QLatin1String(rccFileTag)); + if (fileElem.tagName() != rccFileTag) { + *errorMessage = msgTagMismatch(fileElem.tagName(), rccFileTag); return false; } QtResourceFileData &data = *fileData; data.path = fileElem.text(); - data.alias = fileElem.attribute(QLatin1String(rccAliasAttribute)); + data.alias = fileElem.attribute(rccAliasAttribute); return true; } @@ -120,15 +121,15 @@ static bool loadResourcePrefixData(const QDomElement &prefixElem, QtResourcePref if (!prefixData) return false; - if (prefixElem.tagName() != QLatin1String(rccTag)) { - *errorMessage = msgTagMismatch(prefixElem.tagName(), QLatin1String(rccTag)); + if (prefixElem.tagName() != rccTag) { + *errorMessage = msgTagMismatch(prefixElem.tagName(), rccTag); return false; } QtResourcePrefixData &data = *prefixData; - data.prefix = prefixElem.attribute(QLatin1String(rccPrefixAttribute)); - data.language = prefixElem.attribute(QLatin1String(rccLangAttribute)); + data.prefix = prefixElem.attribute(rccPrefixAttribute); + data.language = prefixElem.attribute(rccLangAttribute); QDomElement fileElem = prefixElem.firstChildElement(); while (!fileElem.isNull()) { QtResourceFileData fileData; @@ -148,8 +149,8 @@ static bool loadQrcFileData(const QDomDocument &doc, const QString &path, QtQrcF QtQrcFileData &data = *qrcFileData; QDomElement docElem = doc.documentElement(); - if (docElem.tagName() != QLatin1String(rccRootTag)) { - *errorMessage = msgTagMismatch(docElem.tagName(), QLatin1String(rccRootTag)); + if (docElem.tagName() != rccRootTag) { + *errorMessage = msgTagMismatch(docElem.tagName(), rccRootTag); return false; } @@ -167,11 +168,11 @@ static bool loadQrcFileData(const QDomDocument &doc, const QString &path, QtQrcF return true; } -QDomElement saveResourceFileData(QDomDocument &doc, const QtResourceFileData &fileData) +static QDomElement saveResourceFileData(QDomDocument &doc, const QtResourceFileData &fileData) { - QDomElement fileElem = doc.createElement(QLatin1String(rccFileTag)); + QDomElement fileElem = doc.createElement(rccFileTag); if (!fileData.alias.isEmpty()) - fileElem.setAttribute(QLatin1String(rccAliasAttribute), fileData.alias); + fileElem.setAttribute(rccAliasAttribute, fileData.alias); QDomText textElem = doc.createTextNode(fileData.path); fileElem.appendChild(textElem); @@ -179,13 +180,13 @@ QDomElement saveResourceFileData(QDomDocument &doc, const QtResourceFileData &fi return fileElem; } -QDomElement saveResourcePrefixData(QDomDocument &doc, const QtResourcePrefixData &prefixData) +static QDomElement saveResourcePrefixData(QDomDocument &doc, const QtResourcePrefixData &prefixData) { - QDomElement prefixElem = doc.createElement(QLatin1String(rccTag)); + QDomElement prefixElem = doc.createElement(rccTag); if (!prefixData.prefix.isEmpty()) - prefixElem.setAttribute(QLatin1String(rccPrefixAttribute), prefixData.prefix); + prefixElem.setAttribute(rccPrefixAttribute, prefixData.prefix); if (!prefixData.language.isEmpty()) - prefixElem.setAttribute(QLatin1String(rccLangAttribute), prefixData.language); + prefixElem.setAttribute(rccLangAttribute, prefixData.language); for (const QtResourceFileData &rfd : prefixData.resourceFileList) { QDomElement fileElem = saveResourceFileData(doc, rfd); @@ -195,10 +196,10 @@ QDomElement saveResourcePrefixData(QDomDocument &doc, const QtResourcePrefixData return prefixElem; } -QDomDocument saveQrcFileData(const QtQrcFileData &qrcFileData) +static QDomDocument saveQrcFileData(const QtQrcFileData &qrcFileData) { QDomDocument doc; - QDomElement docElem = doc.createElement(QLatin1String(rccRootTag)); + QDomElement docElem = doc.createElement(rccRootTag); for (const QtResourcePrefixData &prefixData : qrcFileData.resourceList) { QDomElement prefixElem = saveResourcePrefixData(doc, prefixData); @@ -208,6 +209,9 @@ QDomDocument saveQrcFileData(const QtQrcFileData &qrcFileData) return doc; } + +namespace qdesigner_internal { + // --------------- QtResourceFile class QtResourceFile { public: @@ -334,9 +338,9 @@ private: QList<QtQrcFile *> m_qrcFiles; QMap<QString, QtQrcFile *> m_pathToQrc; - QMap<QtQrcFile *, bool> m_qrcFileToExists; - QMap<QtResourcePrefix *, QtQrcFile *> m_prefixToQrc; - QMap<QtResourceFile *, QtResourcePrefix *> m_fileToPrefix; + QHash<QtQrcFile *, bool> m_qrcFileToExists; + QHash<QtResourcePrefix *, QtQrcFile *> m_prefixToQrc; + QHash<QtResourceFile *, QtResourcePrefix *> m_fileToPrefix; QMap<QString, QList<QtResourceFile *> > m_fullPathToResourceFiles; QMap<QString, QIcon> m_fullPathToIcon; QMap<QString, bool> m_fullPathToExists; @@ -784,9 +788,12 @@ void QtQrcManager::removeResourceFile(QtResourceFile *resourceFile) delete resourceFile; } +} // namespace qdesigner_internal - -} +using QtResourceFile = qdesigner_internal::QtResourceFile; +using QtResourcePrefix = qdesigner_internal::QtResourcePrefix; +using QtQrcFile = qdesigner_internal::QtQrcFile; +using QtQrcManager = qdesigner_internal::QtQrcManager; // ----------------- QtResourceEditorDialogPrivate class QtResourceEditorDialogPrivate @@ -859,16 +866,16 @@ public: QtQrcManager *m_qrcManager = nullptr; QList<QtQrcFileData> m_initialState; - QMap<QtQrcFile *, QListWidgetItem *> m_qrcFileToItem; - QMap<QListWidgetItem *, QtQrcFile *> m_itemToQrcFile; - QMap<QtResourcePrefix *, QStandardItem *> m_resourcePrefixToPrefixItem; - QMap<QtResourcePrefix *, QStandardItem *> m_resourcePrefixToLanguageItem; - QMap<QStandardItem *, QtResourcePrefix *> m_prefixItemToResourcePrefix; - QMap<QStandardItem *, QtResourcePrefix *> m_languageItemToResourcePrefix; - QMap<QtResourceFile *, QStandardItem *> m_resourceFileToPathItem; - QMap<QtResourceFile *, QStandardItem *> m_resourceFileToAliasItem; - QMap<QStandardItem *, QtResourceFile *> m_pathItemToResourceFile; - QMap<QStandardItem *, QtResourceFile *> m_aliasItemToResourceFile; + QHash<QtQrcFile *, QListWidgetItem *> m_qrcFileToItem; + QHash<QListWidgetItem *, QtQrcFile *> m_itemToQrcFile; + QHash<QtResourcePrefix *, QStandardItem *> m_resourcePrefixToPrefixItem; + QHash<QtResourcePrefix *, QStandardItem *> m_resourcePrefixToLanguageItem; + QHash<QStandardItem *, QtResourcePrefix *> m_prefixItemToResourcePrefix; + QHash<QStandardItem *, QtResourcePrefix *> m_languageItemToResourcePrefix; + QHash<QtResourceFile *, QStandardItem *> m_resourceFileToPathItem; + QHash<QtResourceFile *, QStandardItem *> m_resourceFileToAliasItem; + QHash<QStandardItem *, QtResourceFile *> m_pathItemToResourceFile; + QHash<QStandardItem *, QtResourceFile *> m_aliasItemToResourceFile; bool m_ignoreCurrentChanged = false; bool m_firstQrcFileDialog = true; @@ -1186,7 +1193,7 @@ void QtResourceEditorDialogPrivate::slotCurrentQrcFileChanged(QListWidgetItem *i return; if (m_currentQrcFile) { - QMap<QtResourcePrefix *, QStandardItem *> currentPrefixList = m_resourcePrefixToPrefixItem; + QHash<QtResourcePrefix *, QStandardItem *> currentPrefixList = m_resourcePrefixToPrefixItem; for (auto it = currentPrefixList.cbegin(), end = currentPrefixList.cend(); it != end; ++it) { QtResourcePrefix *resourcePrefix = it.key(); const auto currentResourceFiles = resourcePrefix->resourceFiles(); @@ -1312,8 +1319,6 @@ void QtResourceEditorDialogPrivate::slotTreeViewItemChanged(QStandardItem *item) QString QtResourceEditorDialogPrivate::getSaveFileNameWithExtension(QWidget *parent, const QString &title, QString dir, const QString &filter, const QString &extension) const { - const QChar dot = QLatin1Char('.'); - QString saveFile; while (true) { saveFile = m_dlgGui->getSaveFileName(parent, title, dir, filter, nullptr, QFileDialog::DontConfirmOverwrite); @@ -1321,10 +1326,8 @@ QString QtResourceEditorDialogPrivate::getSaveFileNameWithExtension(QWidget *par return saveFile; const QFileInfo fInfo(saveFile); - if (fInfo.suffix().isEmpty() && !fInfo.fileName().endsWith(dot)) { - saveFile += dot; - saveFile += extension; - } + if (fInfo.suffix().isEmpty() && !fInfo.fileName().endsWith(u'.')) + saveFile += u'.' + extension; const QFileInfo fi(saveFile); if (!fi.exists()) @@ -1352,7 +1355,7 @@ void QtResourceEditorDialogPrivate::slotNewQrcFile() QCoreApplication::translate("QtResourceEditorDialog", "New Resource File"), m_firstQrcFileDialog ? qrcStartDirectory() : QString(), QCoreApplication::translate("QtResourceEditorDialog", "Resource files (*.qrc)"), - QStringLiteral("qrc")); + u"qrc"_s); if (qrcPath.isEmpty()) return; @@ -1543,7 +1546,7 @@ void QtResourceEditorDialogPrivate::slotAddFiles() QtResourceFile *nextResourceFile = m_qrcManager->nextResourceFile(currentResourceFile); if (!currentResourceFile) { const auto resourceFiles = currentResourcePrefix->resourceFiles(); - if (resourceFiles.count() > 0) + if (!resourceFiles.isEmpty()) nextResourceFile = resourceFiles.first(); } @@ -1552,7 +1555,7 @@ void QtResourceEditorDialogPrivate::slotAddFiles() const QDir dir(fi.absolutePath()); for (QString resourcePath : resourcePaths) { QString relativePath = dir.relativeFilePath(resourcePath); - if (relativePath.startsWith(QStringLiteral(".."))) { + if (relativePath.startsWith(".."_L1)) { QMessageBox msgBox(QMessageBox::Warning, QCoreApplication::translate("QtResourceEditorDialog", "Incorrect Path"), outOfPathWarning(relativePath), QMessageBox::Cancel); @@ -1667,7 +1670,7 @@ void QtResourceEditorDialogPrivate::slotClonePrefix() QDir dir(fi.dir()); QString oldSuffix = fi.completeSuffix(); if (!oldSuffix.isEmpty()) - oldSuffix = QLatin1Char('.') + oldSuffix; + oldSuffix = u'.' + oldSuffix; const QString newBaseName = fi.baseName() + suffix + oldSuffix; const QString newPath = QDir::cleanPath(dir.filePath(newBaseName)); m_qrcManager->insertResourceFile(newResourcePrefix, newPath, @@ -1765,7 +1768,7 @@ QString QtResourceEditorDialogPrivate::browseForNewLocation(const QString &resou QCoreApplication::translate("QtResourceEditorDialog", "Copy As"), initialPath); QString relativePath = rootDir.relativeFilePath(newPath); - if (relativePath.startsWith(QStringLiteral(".."))) { + if (relativePath.startsWith(".."_L1)) { if (warning(QCoreApplication::translate("QtResourceEditorDialog", "Copy As"), QCoreApplication::translate("QtResourceEditorDialog", "<p>The selected file:</p>" "<p>%1</p><p>is outside of the current resource file's directory:</p><p>%2</p>" @@ -1827,16 +1830,15 @@ bool QtResourceEditorDialogPrivate::loadQrcFile(const QString &path, QtQrcFileDa file.close(); QDomDocument doc; - int errLine, errCol; - if (!doc.setContent(dataArray, errorMessage, &errLine, &errCol)) { + if (QDomDocument::ParseResult result = doc.setContent(dataArray)) { + return loadQrcFileData(doc, path, qrcFileData, errorMessage); + } else { *errorMessage = QCoreApplication::translate("QtResourceEditorDialog", "A parse error occurred at line %1, column %2 of %3:\n%4") - .arg(errLine).arg(errCol).arg(path, *errorMessage); + .arg(result.errorLine).arg(result.errorColumn).arg(path, result.errorMessage); return false; } - - return loadQrcFileData(doc, path, qrcFileData, errorMessage); } bool QtResourceEditorDialogPrivate::saveQrcFile(const QtQrcFileData &qrcFileData) @@ -1881,41 +1883,42 @@ QtResourceEditorDialog::QtResourceEditorDialog(QDesignerFormEditorInterface *cor d_ptr->m_dlgGui = dlgGui; d_ptr->m_core = core; - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowTitle(tr("Edit Resources")); - connect(d_ptr->m_qrcManager, SIGNAL(qrcFileInserted(QtQrcFile*)), - this, SLOT(slotQrcFileInserted(QtQrcFile*))); - connect(d_ptr->m_qrcManager, SIGNAL(qrcFileMoved(QtQrcFile*,QtQrcFile*)), - this, SLOT(slotQrcFileMoved(QtQrcFile*))); - connect(d_ptr->m_qrcManager, SIGNAL(qrcFileRemoved(QtQrcFile*)), - this, SLOT(slotQrcFileRemoved(QtQrcFile*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourcePrefixInserted(QtResourcePrefix*)), - this, SLOT(slotResourcePrefixInserted(QtResourcePrefix*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourcePrefixMoved(QtResourcePrefix*,QtResourcePrefix*)), - this, SLOT(slotResourcePrefixMoved(QtResourcePrefix*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourcePrefixChanged(QtResourcePrefix*,QString)), - this, SLOT(slotResourcePrefixChanged(QtResourcePrefix*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourceLanguageChanged(QtResourcePrefix*,QString)), - this, SLOT(slotResourceLanguageChanged(QtResourcePrefix*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourcePrefixRemoved(QtResourcePrefix*)), - this, SLOT(slotResourcePrefixRemoved(QtResourcePrefix*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourceFileInserted(QtResourceFile*)), - this, SLOT(slotResourceFileInserted(QtResourceFile*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourceFileMoved(QtResourceFile*,QtResourceFile*)), - this, SLOT(slotResourceFileMoved(QtResourceFile*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourceAliasChanged(QtResourceFile*,QString)), - this, SLOT(slotResourceAliasChanged(QtResourceFile*))); - connect(d_ptr->m_qrcManager, SIGNAL(resourceFileRemoved(QtResourceFile*)), - this, SLOT(slotResourceFileRemoved(QtResourceFile*))); - - QIcon upIcon = qdesigner_internal::createIconSet(QString::fromUtf8("up.png")); - QIcon downIcon = qdesigner_internal::createIconSet(QString::fromUtf8("down.png")); - QIcon minusIcon = qdesigner_internal::createIconSet(QString::fromUtf8("minus-16.png")); - QIcon newIcon = qdesigner_internal::createIconSet(QString::fromUtf8("filenew-16.png")); - QIcon openIcon = qdesigner_internal::createIconSet(QString::fromUtf8("fileopen-16.png")); - QIcon removeIcon = qdesigner_internal::createIconSet(QString::fromUtf8("editdelete-16.png")); - QIcon addPrefixIcon = qdesigner_internal::createIconSet(QString::fromUtf8("prefix-add.png")); + connect(d_ptr->m_qrcManager, &QtQrcManager::qrcFileInserted, + this, [this](QtQrcFile *file) { d_ptr->slotQrcFileInserted(file); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::qrcFileMoved, + this, [this](QtQrcFile *file) { d_ptr->slotQrcFileMoved(file); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::qrcFileRemoved, + this, [this](QtQrcFile *file) { d_ptr->slotQrcFileRemoved(file); }); + + connect(d_ptr->m_qrcManager, &QtQrcManager::resourcePrefixInserted, + this, [this](QtResourcePrefix *prefix) { d_ptr->slotResourcePrefixInserted(prefix); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::resourcePrefixMoved, + this, [this](QtResourcePrefix *prefix) { d_ptr->slotResourcePrefixMoved(prefix); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::resourcePrefixChanged, + this, [this](QtResourcePrefix *prefix) { d_ptr->slotResourcePrefixChanged(prefix); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::resourceLanguageChanged, + this, [this](QtResourcePrefix *prefix) { d_ptr->slotResourceLanguageChanged(prefix); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::resourcePrefixRemoved, + this, [this](QtResourcePrefix *prefix) { d_ptr->slotResourcePrefixRemoved(prefix); }); + + connect(d_ptr->m_qrcManager, &QtQrcManager::resourceFileInserted, + this, [this](QtResourceFile *file) { d_ptr->slotResourceFileInserted(file); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::resourceFileMoved, + this, [this](QtResourceFile *file) { d_ptr->slotResourceFileMoved(file); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::resourceAliasChanged, + this, [this](QtResourceFile *file) { d_ptr->slotResourceAliasChanged(file); }); + connect(d_ptr->m_qrcManager, &QtQrcManager::resourceFileRemoved, + this, [this](QtResourceFile *file) { d_ptr->slotResourceFileRemoved(file); }); + + QIcon upIcon = qdesigner_internal::createIconSet("up.png"_L1); + QIcon downIcon = qdesigner_internal::createIconSet("down.png"_L1); + QIcon minusIcon = qdesigner_internal::createIconSet("minus-16.png"_L1); + QIcon newIcon = qdesigner_internal::createIconSet("filenew-16.png"_L1); + QIcon openIcon = qdesigner_internal::createIconSet("fileopen-16.png"_L1); + QIcon removeIcon = qdesigner_internal::createIconSet("editdelete-16.png"_L1); + QIcon addPrefixIcon = qdesigner_internal::createIconSet("prefix-add.png"_L1); d_ptr->m_newQrcFileAction = new QAction(newIcon, tr("New..."), this); d_ptr->m_newQrcFileAction->setToolTip(tr("New Resource File")); @@ -1944,27 +1947,41 @@ QtResourceEditorDialog::QtResourceEditorDialog(QDesignerFormEditorInterface *cor d_ptr->m_ui.addResourceButton->setDefaultAction(d_ptr->m_addResourceFileAction); d_ptr->m_ui.removeResourceButton->setDefaultAction(d_ptr->m_removeAction); - connect(d_ptr->m_newQrcFileAction, SIGNAL(triggered()), this, SLOT(slotNewQrcFile())); - connect(d_ptr->m_importQrcFileAction, SIGNAL(triggered()), this, SLOT(slotImportQrcFile())); - connect(d_ptr->m_removeQrcFileAction, SIGNAL(triggered()), this, SLOT(slotRemoveQrcFile())); - connect(d_ptr->m_moveUpQrcFileAction, SIGNAL(triggered()), this, SLOT(slotMoveUpQrcFile())); - connect(d_ptr->m_moveDownQrcFileAction, SIGNAL(triggered()), this, SLOT(slotMoveDownQrcFile())); - - connect(d_ptr->m_newPrefixAction, SIGNAL(triggered()), this, SLOT(slotNewPrefix())); - connect(d_ptr->m_addResourceFileAction, SIGNAL(triggered()), this, SLOT(slotAddFiles())); - connect(d_ptr->m_changePrefixAction, SIGNAL(triggered()), this, SLOT(slotChangePrefix())); - connect(d_ptr->m_changeLanguageAction, SIGNAL(triggered()), this, SLOT(slotChangeLanguage())); - connect(d_ptr->m_changeAliasAction, SIGNAL(triggered()), this, SLOT(slotChangeAlias())); - connect(d_ptr->m_clonePrefixAction, SIGNAL(triggered()), this, SLOT(slotClonePrefix())); - connect(d_ptr->m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemove())); - connect(d_ptr->m_moveUpAction, SIGNAL(triggered()), this, SLOT(slotMoveUp())); - connect(d_ptr->m_moveDownAction, SIGNAL(triggered()), this, SLOT(slotMoveDown())); + connect(d_ptr->m_newQrcFileAction, &QAction::triggered, + this, [this] { d_ptr->slotNewQrcFile(); }); + connect(d_ptr->m_importQrcFileAction, &QAction::triggered, + this, [this] { d_ptr->slotImportQrcFile(); }); + connect(d_ptr->m_removeQrcFileAction, &QAction::triggered, + this, [this] { d_ptr->slotRemoveQrcFile(); }); + connect(d_ptr->m_moveUpQrcFileAction, &QAction::triggered, + this, [this] { d_ptr->slotMoveUpQrcFile(); }); + connect(d_ptr->m_moveDownQrcFileAction, &QAction::triggered, + this, [this] { d_ptr->slotMoveDownQrcFile(); }); + + connect(d_ptr->m_newPrefixAction, &QAction::triggered, + this, [this] { d_ptr->slotNewPrefix(); }); + connect(d_ptr->m_addResourceFileAction, &QAction::triggered, + this, [this] { d_ptr->slotAddFiles(); }); + connect(d_ptr->m_changePrefixAction, &QAction::triggered, + this, [this] { d_ptr->slotChangePrefix(); }); + connect(d_ptr->m_changeLanguageAction, &QAction::triggered, + this, [this] { d_ptr->slotChangeLanguage(); }); + connect(d_ptr->m_changeAliasAction, &QAction::triggered, + this, [this] { d_ptr->slotChangeAlias(); }); + connect(d_ptr->m_clonePrefixAction, &QAction::triggered, + this, [this] { d_ptr->slotClonePrefix(); }); + connect(d_ptr->m_removeAction, &QAction::triggered, + this, [this] { d_ptr->slotRemove(); }); + connect(d_ptr->m_moveUpAction, &QAction::triggered, + this, [this] { d_ptr->slotMoveUp(); }); + connect(d_ptr->m_moveDownAction, &QAction::triggered, + this, [this] { d_ptr->slotMoveDown(); }); d_ptr->m_ui.qrcFileList->setContextMenuPolicy(Qt::CustomContextMenu); - connect(d_ptr->m_ui.qrcFileList, SIGNAL(customContextMenuRequested(QPoint)), - this, SLOT(slotListWidgetContextMenuRequested(QPoint))); - connect(d_ptr->m_ui.qrcFileList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(slotCurrentQrcFileChanged(QListWidgetItem*))); + connect(d_ptr->m_ui.qrcFileList, &QListWidget::customContextMenuRequested, + this, [this](const QPoint &point) { d_ptr->slotListWidgetContextMenuRequested(point); }); + connect(d_ptr->m_ui.qrcFileList, &QListWidget::currentItemChanged, + this, [this](QListWidgetItem *item) { d_ptr->slotCurrentQrcFileChanged(item); }); d_ptr->m_treeModel = new QStandardItemModel(this); d_ptr->m_treeModel->setColumnCount(2); @@ -1977,12 +1994,12 @@ QtResourceEditorDialog::QtResourceEditorDialog(QDesignerFormEditorInterface *cor d_ptr->m_ui.resourceTreeView, &QTreeView::resizeColumnToContents); d_ptr->m_ui.resourceTreeView->setTextElideMode(Qt::ElideLeft); - connect(d_ptr->m_ui.resourceTreeView, SIGNAL(customContextMenuRequested(QPoint)), - this, SLOT(slotTreeViewContextMenuRequested(QPoint))); - connect(d_ptr->m_treeModel, SIGNAL(itemChanged(QStandardItem*)), - this, SLOT(slotTreeViewItemChanged(QStandardItem*))); - connect(d_ptr->m_treeSelection, SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(slotCurrentTreeViewItemChanged(QModelIndex))); + connect(d_ptr->m_ui.resourceTreeView, &QTreeView::customContextMenuRequested, + this, [this](const QPoint &point) { d_ptr->slotTreeViewContextMenuRequested(point); }); + connect(d_ptr->m_treeModel, &QStandardItemModel::itemChanged, + this, [this](QStandardItem *item) { d_ptr->slotTreeViewItemChanged(item); }); + connect(d_ptr->m_treeSelection, &QItemSelectionModel::currentChanged, + this, [this](const QModelIndex &index) { d_ptr->slotCurrentTreeViewItemChanged(index); }); d_ptr->m_ui.resourceTreeView->setColumnWidth(0, 200); @@ -1992,10 +2009,10 @@ QtResourceEditorDialog::QtResourceEditorDialog(QDesignerFormEditorInterface *cor d_ptr->m_moveDownQrcFileAction->setEnabled(false); QDesignerSettingsInterface *settings = core->settingsManager(); - settings->beginGroup(QLatin1String(QrcDialogC)); + settings->beginGroup(QrcDialogC); - d_ptr->m_ui.splitter->restoreState(settings->value(QLatin1String(SplitterPosition)).toByteArray()); - const QVariant geometry = settings->value(QLatin1String(Geometry)); + d_ptr->m_ui.splitter->restoreState(settings->value(SplitterPosition).toByteArray()); + const QVariant geometry = settings->value(ResourceEditorGeometry); if (geometry.metaType().id() == QMetaType::QByteArray) // Used to be a QRect up until 5.4.0, QTBUG-43374 restoreGeometry(geometry.toByteArray()); @@ -2005,11 +2022,13 @@ QtResourceEditorDialog::QtResourceEditorDialog(QDesignerFormEditorInterface *cor QtResourceEditorDialog::~QtResourceEditorDialog() { QDesignerSettingsInterface *settings = d_ptr->m_core->settingsManager(); - settings->beginGroup(QLatin1String(QrcDialogC)); + settings->beginGroup(QrcDialogC); - settings->setValue(QLatin1String(SplitterPosition), d_ptr->m_ui.splitter->saveState()); - settings->setValue(QLatin1String(Geometry), saveGeometry()); + settings->setValue(SplitterPosition, d_ptr->m_ui.splitter->saveState()); + settings->setValue(ResourceEditorGeometry, saveGeometry()); settings->endGroup(); + + disconnect(d_ptr->m_qrcManager, nullptr, this, nullptr); } QtResourceModel *QtResourceEditorDialog::model() const @@ -2050,13 +2069,13 @@ QString QtResourceEditorDialog::selectedResource() const if (!currentResourcePrefix) return QString(); - const QChar slash(QLatin1Char('/')); + const QChar slash(u'/'); QString resource = currentResourcePrefix->prefix(); if (!resource.startsWith(slash)) resource.prepend(slash); if (!resource.endsWith(slash)) resource.append(slash); - resource.prepend(QLatin1Char(':')); + resource.prepend(u':'); QtResourceFile *currentResourceFile = d_ptr->getCurrentResourceFile(); if (!currentResourceFile) @@ -2066,15 +2085,15 @@ QString QtResourceEditorDialog::selectedResource() const if (!currentResourceFile->alias().isEmpty()) resourceEnding = currentResourceFile->alias(); - const QString dotSlash(QStringLiteral("./")); - const QString dotDotSlash(QStringLiteral("../")); + const auto dotSlash = "./"_L1; + const auto dotDotSlash = "../"_L1; while (true) { if (resourceEnding.startsWith(slash)) resourceEnding = resourceEnding.mid(1); else if (resourceEnding.startsWith(dotSlash)) - resourceEnding = resourceEnding.mid(dotSlash.count()); + resourceEnding = resourceEnding.mid(dotSlash.size()); else if (resourceEnding.startsWith(dotDotSlash)) - resourceEnding = resourceEnding.mid(dotDotSlash.count()); + resourceEnding = resourceEnding.mid(dotDotSlash.size()); else break; } diff --git a/src/designer/src/lib/shared/qtresourceeditordialog_p.h b/src/designer/src/lib/shared/qtresourceeditordialog_p.h index 5a6ea9755..cc832a881 100644 --- a/src/designer/src/lib/shared/qtresourceeditordialog_p.h +++ b/src/designer/src/lib/shared/qtresourceeditordialog_p.h @@ -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 // // W A R N I N G @@ -74,41 +49,6 @@ private: QScopedPointer<class QtResourceEditorDialogPrivate> d_ptr; Q_DECLARE_PRIVATE(QtResourceEditorDialog) Q_DISABLE_COPY_MOVE(QtResourceEditorDialog) - - Q_PRIVATE_SLOT(d_func(), void slotQrcFileInserted(QtQrcFile *)) - Q_PRIVATE_SLOT(d_func(), void slotQrcFileMoved(QtQrcFile *)) - Q_PRIVATE_SLOT(d_func(), void slotQrcFileRemoved(QtQrcFile *)) - Q_PRIVATE_SLOT(d_func(), void slotResourcePrefixInserted(QtResourcePrefix *)) - Q_PRIVATE_SLOT(d_func(), void slotResourcePrefixMoved(QtResourcePrefix *)) - Q_PRIVATE_SLOT(d_func(), void slotResourcePrefixChanged(QtResourcePrefix *)) - Q_PRIVATE_SLOT(d_func(), void slotResourceLanguageChanged(QtResourcePrefix *)) - Q_PRIVATE_SLOT(d_func(), void slotResourcePrefixRemoved(QtResourcePrefix *)) - Q_PRIVATE_SLOT(d_func(), void slotResourceFileInserted(QtResourceFile *)) - Q_PRIVATE_SLOT(d_func(), void slotResourceFileMoved(QtResourceFile *)) - Q_PRIVATE_SLOT(d_func(), void slotResourceAliasChanged(QtResourceFile *)) - Q_PRIVATE_SLOT(d_func(), void slotResourceFileRemoved(QtResourceFile *)) - - Q_PRIVATE_SLOT(d_func(), void slotCurrentQrcFileChanged(QListWidgetItem *)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentTreeViewItemChanged(const QModelIndex &)) - Q_PRIVATE_SLOT(d_func(), void slotListWidgetContextMenuRequested(const QPoint &)) - Q_PRIVATE_SLOT(d_func(), void slotTreeViewContextMenuRequested(const QPoint &)) - Q_PRIVATE_SLOT(d_func(), void slotTreeViewItemChanged(QStandardItem *)) - - Q_PRIVATE_SLOT(d_func(), void slotNewQrcFile()) - Q_PRIVATE_SLOT(d_func(), void slotImportQrcFile()) - Q_PRIVATE_SLOT(d_func(), void slotRemoveQrcFile()) - Q_PRIVATE_SLOT(d_func(), void slotMoveUpQrcFile()) - Q_PRIVATE_SLOT(d_func(), void slotMoveDownQrcFile()) - - Q_PRIVATE_SLOT(d_func(), void slotNewPrefix()) - Q_PRIVATE_SLOT(d_func(), void slotAddFiles()) - Q_PRIVATE_SLOT(d_func(), void slotChangePrefix()) - Q_PRIVATE_SLOT(d_func(), void slotChangeLanguage()) - Q_PRIVATE_SLOT(d_func(), void slotChangeAlias()) - Q_PRIVATE_SLOT(d_func(), void slotClonePrefix()) - Q_PRIVATE_SLOT(d_func(), void slotRemove()) - Q_PRIVATE_SLOT(d_func(), void slotMoveUp()) - Q_PRIVATE_SLOT(d_func(), void slotMoveDown()) }; QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/qtresourcemodel.cpp b/src/designer/src/lib/shared/qtresourcemodel.cpp index 391cf49a3..acee5cc98 100644 --- a/src/designer/src/lib/shared/qtresourcemodel.cpp +++ b/src/designer/src/lib/shared/qtresourcemodel.cpp @@ -1,35 +1,11 @@ -/**************************************************************************** -** -** 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 "qtresourcemodel_p.h" #include "rcc_p.h" #include <QtCore/qstringlist.h> +#include <QtCore/qhash.h> #include <QtCore/qmap.h> #include <QtCore/qresource.h> #include <QtCore/qfileinfo.h> @@ -71,19 +47,18 @@ public: void activate(QtResourceSet *resourceSet, const QStringList &newPaths, int *errorCount = nullptr, QString *errorMessages = nullptr); void removeOldPaths(QtResourceSet *resourceSet, const QStringList &newPaths); - QMap<QString, bool> m_pathToModified; - QMap<QtResourceSet *, QStringList> m_resourceSetToPaths; - QMap<QtResourceSet *, bool> m_resourceSetToReload; // while path is recreated it needs to be reregistered - // (it is - in the new current resource set, but when the path was used in - // other resource set - // then later when that resource set is activated it needs to be reregistered) - QMap<QtResourceSet *, bool> m_newlyCreated; // all created but not activated yet - // (if was active at some point and it's not now it will not be on that map) - QMap<QString, QList<QtResourceSet *> > m_pathToResourceSet; - QtResourceSet *m_currentResourceSet = nullptr; + QMap<QString, bool> m_pathToModified; + QHash<QtResourceSet *, QStringList> m_resourceSetToPaths; + QHash<QtResourceSet *, bool> m_resourceSetToReload; // while path is recreated it needs to be reregistered + // (it is - in the new current resource set, but when the path was used in + // other resource set + // then later when that resource set is activated it needs to be reregistered) + QHash<QtResourceSet *, bool> m_newlyCreated; // all created but not activated yet + // (if was active at some point and it's not now it will not be on that map) + QMap<QString, QList<QtResourceSet *>> m_pathToResourceSet; + QtResourceSet *m_currentResourceSet = nullptr; - typedef QMap<QString, const QByteArray *> PathDataMap; - PathDataMap m_pathToData; + QMap<QString, const QByteArray *> m_pathToData; QMap<QString, QStringList> m_pathToContents; // qrc path to its contents. QMap<QString, QString> m_fileToQrc; // this map contains the content of active resource set only. @@ -152,7 +127,7 @@ const QByteArray *QtResourceModelPrivate::createResource(const QString &path, QS contents->clear(); do { // run RCC - RCCResourceLibrary library; + RCCResourceLibrary library(3); library.setVerbose(true); library.setInputFiles(QStringList(path)); library.setFormat(RCCResourceLibrary::Binary); @@ -163,7 +138,7 @@ const QByteArray *QtResourceModelPrivate::createResource(const QString &path, QS break; // return code cannot be fully trusted, might still be empty const ResourceDataFileMap resMap = library.resourceDataFileMap(); - if (!library.output(buffer, errorDevice)) + if (!library.output(buffer, buffer /* tempfile, unused */, errorDevice)) break; *errorCount = library.failedResources().size(); @@ -200,7 +175,7 @@ void QtResourceModelPrivate::registerResourceSet(QtResourceSet *resourceSet) for (const QString &path : toRegister) { if (debugResourceModel) qDebug() << "registerResourceSet " << path; - const PathDataMap::const_iterator itRcc = m_pathToData.constFind(path); + const auto itRcc = m_pathToData.constFind(path); if (itRcc != m_pathToData.constEnd()) { // otherwise data was not created yet const QByteArray *data = itRcc.value(); if (data) { @@ -228,7 +203,7 @@ void QtResourceModelPrivate::unregisterResourceSet(QtResourceSet *resourceSet) for (const QString &path : toUnregister) { if (debugResourceModel) qDebug() << "unregisterResourceSet " << path; - const PathDataMap::const_iterator itRcc = m_pathToData.constFind(path); + const auto itRcc = m_pathToData.constFind(path); if (itRcc != m_pathToData.constEnd()) { // otherwise data was not created yet const QByteArray *data = itRcc.value(); if (data) { @@ -259,12 +234,12 @@ void QtResourceModelPrivate::activate(QtResourceSet *resourceSet, const QStringL if (resourceSet && resourceSet->activeResourceFilePaths() != newPaths && !m_newlyCreated.contains(resourceSet)) newResourceSetChanged = true; - PathDataMap newPathToData = m_pathToData; + auto newPathToData = m_pathToData; for (const QString &path : newPaths) { if (resourceSet && !m_pathToResourceSet[path].contains(resourceSet)) m_pathToResourceSet[path].append(resourceSet); - const QMap<QString, bool>::iterator itMod = m_pathToModified.find(path); + const auto itMod = m_pathToModified.find(path); if (itMod == m_pathToModified.end() || itMod.value()) { // new path or path is already created, but needs to be recreated QStringList contents; int qrcErrorCount; @@ -313,7 +288,7 @@ void QtResourceModelPrivate::activate(QtResourceSet *resourceSet, const QStringL *errorMessages = stderrOutput; } // register - const QMap<QtResourceSet *, bool>::iterator itReload = m_resourceSetToReload.find(resourceSet); + const auto itReload = m_resourceSetToReload.find(resourceSet); if (itReload != m_resourceSetToReload.end()) { if (itReload.value()) { newResourceSetChanged = true; @@ -327,7 +302,7 @@ void QtResourceModelPrivate::activate(QtResourceSet *resourceSet, const QStringL const bool needReregister = (oldActivePaths != newPaths) || newResourceSetChanged; - QMap<QtResourceSet *, bool>::iterator itNew = m_newlyCreated.find(resourceSet); + const auto itNew = m_newlyCreated.find(resourceSet); if (itNew != m_newlyCreated.end()) { m_newlyCreated.remove(resourceSet); if (needReregister) @@ -335,7 +310,7 @@ void QtResourceModelPrivate::activate(QtResourceSet *resourceSet, const QStringL } if (!newResourceSetChanged && !needReregister && (m_currentResourceSet == resourceSet)) { - for (const QByteArray *data : qAsConst(toDelete)) + for (const QByteArray *data : std::as_const(toDelete)) deleteResource(data); return; // nothing changed @@ -344,7 +319,7 @@ void QtResourceModelPrivate::activate(QtResourceSet *resourceSet, const QStringL if (needReregister) unregisterResourceSet(m_currentResourceSet); - for (const QByteArray *data : qAsConst(toDelete)) + for (const QByteArray *data : std::as_const(toDelete)) deleteResource(data); m_pathToData = newPathToData; @@ -378,8 +353,8 @@ void QtResourceModelPrivate::removeOldPaths(QtResourceSet *resourceSet, const QS const int idx = itRemove.value().indexOf(resourceSet); if (idx >= 0) itRemove.value().removeAt(idx); - if (itRemove.value().count() == 0) { - PathDataMap::iterator it = m_pathToData.find(oldPath); + if (itRemove.value().isEmpty()) { + const auto it = m_pathToData.find(oldPath); if (it != m_pathToData.end()) deleteResource(it.value()); m_pathToResourceSet.erase(itRemove); @@ -409,7 +384,7 @@ void QtResourceModelPrivate::setWatcherEnabled(const QString &path, bool enable) void QtResourceModelPrivate::addWatcher(const QString &path) { - QMap<QString, bool>::ConstIterator it = m_fileWatchedMap.constFind(path); + const auto it = m_fileWatchedMap.constFind(path); if (it != m_fileWatchedMap.constEnd() && !it.value()) return; @@ -445,8 +420,8 @@ QtResourceModel::QtResourceModel(QObject *parent) : d_ptr->q_ptr = this; d_ptr->m_fileWatcher = new QFileSystemWatcher(this); - connect(d_ptr->m_fileWatcher, SIGNAL(fileChanged(QString)), - this, SLOT(slotFileChanged(QString))); + connect(d_ptr->m_fileWatcher, &QFileSystemWatcher::fileChanged, + this, [this](const QString &fileName) { d_ptr->slotFileChanged(fileName); }); } QtResourceModel::~QtResourceModel() @@ -465,16 +440,12 @@ QStringList QtResourceModel::loadedQrcFiles() const bool QtResourceModel::isModified(const QString &path) const { - QMap<QString, bool>::const_iterator it = d_ptr->m_pathToModified.constFind(path); - if (it != d_ptr->m_pathToModified.constEnd()) - return it.value(); - return true; + return d_ptr->m_pathToModified.value(path, true); } void QtResourceModel::setModified(const QString &path) { - QMap<QString, bool>::const_iterator itMod = d_ptr->m_pathToModified.constFind(path); - if (itMod == d_ptr->m_pathToModified.constEnd()) + if (!d_ptr->m_pathToModified.contains(path)) return; d_ptr->m_pathToModified[path] = true; @@ -539,19 +510,12 @@ void QtResourceModel::reload(const QString &path, int *errorCount, QString *erro void QtResourceModel::reload(int *errorCount, QString *errorMessages) { - QMap<QString, bool>::iterator it = d_ptr->m_pathToModified.begin(); - QMap<QString, bool>::iterator itEnd = d_ptr->m_pathToModified.end(); // will it be valid when I iterate the map and change it??? - while (it != itEnd) { - it = d_ptr->m_pathToModified.insert(it.key(), true); - ++it; - } + for (auto it = d_ptr->m_pathToModified.begin(), end = d_ptr->m_pathToModified.end(); it != end; ++it) + it.value() = true; - QMap<QtResourceSet *, bool>::iterator itReload = d_ptr->m_resourceSetToReload.begin(); - QMap<QtResourceSet *, bool>::iterator itReloadEnd = d_ptr->m_resourceSetToReload.end(); - while (itReload != itReloadEnd) { - itReload = d_ptr->m_resourceSetToReload.insert(itReload.key(), true); // empty resourceSets could be omitted here - ++itReload; - } + // empty resourceSets could be omitted here + for (auto itReload = d_ptr->m_resourceSetToReload.begin(), end = d_ptr->m_resourceSetToReload.end(); itReload != end; ++itReload) + itReload.value() = true; d_ptr->activate(d_ptr->m_currentResourceSet, d_ptr->m_resourceSetToPaths.value(d_ptr->m_currentResourceSet), errorCount, errorMessages); } @@ -584,7 +548,7 @@ bool QtResourceModel::isWatcherEnabled() const void QtResourceModel::setWatcherEnabled(const QString &path, bool enable) { - QMap<QString, bool>::Iterator it = d_ptr->m_fileWatchedMap.find(path); + const auto it = d_ptr->m_fileWatchedMap.find(path); if (it == d_ptr->m_fileWatchedMap.end()) return; diff --git a/src/designer/src/lib/shared/qtresourcemodel_p.h b/src/designer/src/lib/shared/qtresourcemodel_p.h index 65d615f52..43afe5c50 100644 --- a/src/designer/src/lib/shared/qtresourcemodel_p.h +++ b/src/designer/src/lib/shared/qtresourcemodel_p.h @@ -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 // // W A R N I N G @@ -123,8 +98,6 @@ private: QScopedPointer<class QtResourceModelPrivate> d_ptr; Q_DECLARE_PRIVATE(QtResourceModel) Q_DISABLE_COPY_MOVE(QtResourceModel) - - Q_PRIVATE_SLOT(d_func(), void slotFileChanged(const QString &)) }; QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/qtresourceview.cpp b/src/designer/src/lib/shared/qtresourceview.cpp index fa40394b5..5663b0ddc 100644 --- a/src/designer/src/lib/shared/qtresourceview.cpp +++ b/src/designer/src/lib/shared/qtresourceview.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 "qtresourceview_p.h" #include "qtresourcemodel_p.h" @@ -57,6 +32,7 @@ #include <QtCore/qmimedata.h> #include <QtCore/qfileinfo.h> #include <QtCore/qdir.h> +#include <QtCore/qhash.h> #include <QtCore/qqueue.h> #include <QtXml/qdom.h> @@ -65,15 +41,17 @@ QT_BEGIN_NAMESPACE -static const char *elementResourceData = "resource"; -static const char *typeAttribute = "type"; -static const char *typeImage = "image"; -static const char *typeStyleSheet = "stylesheet"; -static const char *typeOther = "other"; -static const char *fileAttribute = "file"; -static const char *SplitterPosition = "SplitterPosition"; -static const char *Geometry = "Geometry"; -static const char *ResourceViewDialogC = "ResourceDialog"; +using namespace Qt::StringLiterals; + +static constexpr auto elementResourceData = "resource"_L1; +static constexpr auto typeAttribute = "type"_L1; +static constexpr auto typeImage = "image"_L1; +static constexpr auto typeStyleSheet = "stylesheet"_L1; +static constexpr auto typeOther = "other"_L1; +static constexpr auto fileAttribute = "file"_L1; +static constexpr auto qrvSplitterPosition = "SplitterPosition"_L1; +static constexpr auto qrvGeometry = "Geometry"_L1; +static constexpr auto ResourceViewDialogC = "ResourceDialog"_L1; // ---------------- ResourceListWidget: A list widget that has drag enabled class ResourceListWidget : public QListWidget { @@ -160,13 +138,13 @@ public: QTreeWidget *m_treeWidget; QListWidget *m_listWidget; QSplitter *m_splitter = nullptr; - QMap<QString, QStringList> m_pathToContents; // full path to contents file names (full path to its resource filenames) - QMap<QString, QString> m_pathToParentPath; // full path to full parent path - QMap<QString, QStringList> m_pathToSubPaths; // full path to full sub paths + QMap<QString, QStringList> m_pathToContents; // full path to contents file names (full path to its resource filenames) + QMap<QString, QString> m_pathToParentPath; // full path to full parent path + QMap<QString, QStringList> m_pathToSubPaths; // full path to full sub paths QMap<QString, QTreeWidgetItem *> m_pathToItem; - QMap<QTreeWidgetItem *, QString> m_itemToPath; + QHash<QTreeWidgetItem *, QString> m_itemToPath; QMap<QString, QListWidgetItem *> m_resourceToItem; - QMap<QListWidgetItem *, QString> m_itemToResource; + QHash<QListWidgetItem *, QString> m_itemToResource; QAction *m_editResourcesAction = nullptr; QAction *m_reloadResourcesAction = nullptr; QAction *m_copyResourcePathAction = nullptr; @@ -196,7 +174,7 @@ void QtResourceViewPrivate::restoreSettings() QDesignerSettingsInterface *settings = m_core->settingsManager(); settings->beginGroup(m_settingsKey); - m_splitter->restoreState(settings->value(QLatin1String(SplitterPosition)).toByteArray()); + m_splitter->restoreState(settings->value(qrvSplitterPosition).toByteArray()); settings->endGroup(); } @@ -208,7 +186,7 @@ void QtResourceViewPrivate::saveSettings() QDesignerSettingsInterface *settings = m_core->settingsManager(); settings->beginGroup(m_settingsKey); - settings->setValue(QLatin1String(SplitterPosition), m_splitter->saveState()); + settings->setValue(qrvSplitterPosition, m_splitter->saveState()); settings->endGroup(); } @@ -362,7 +340,7 @@ void QtResourceViewPrivate::createPaths() return; // Resource root up until 4.6 was ':', changed to ":/" as of 4.7 - const QString root(QStringLiteral(":/")); + const QString root(u":/"_s); QMap<QString, QString> contents = m_resourceModel->contents(); for (auto it = contents.cbegin(), end = contents.cend(); it != end; ++it) { @@ -378,15 +356,15 @@ void QtResourceViewPrivate::createPaths() } } - QQueue<QPair<QString, QTreeWidgetItem *> > pathToParentItemQueue; - pathToParentItemQueue.enqueue(qMakePair(root, static_cast<QTreeWidgetItem *>(nullptr))); + QQueue<std::pair<QString, QTreeWidgetItem *>> pathToParentItemQueue; + pathToParentItemQueue.enqueue(std::make_pair(root, static_cast<QTreeWidgetItem *>(nullptr))); while (!pathToParentItemQueue.isEmpty()) { - QPair<QString, QTreeWidgetItem *> pathToParentItem = pathToParentItemQueue.dequeue(); + std::pair<QString, QTreeWidgetItem *> pathToParentItem = pathToParentItemQueue.dequeue(); const QString path = pathToParentItem.first; QTreeWidgetItem *item = createPath(path, pathToParentItem.second); const QStringList subPaths = m_pathToSubPaths.value(path); for (const QString &subPath : subPaths) - pathToParentItemQueue.enqueue(qMakePair(subPath, item)); + pathToParentItemQueue.enqueue(std::make_pair(subPath, item)); } } @@ -402,7 +380,7 @@ void QtResourceViewPrivate::filterOutResources() // 3) we hide these items which has pathToVisible value false. const bool matchAll = m_filterPattern.isEmpty(); - const QString root(QStringLiteral(":/")); + const QString root(u":/"_s); QQueue<QString> pathQueue; pathQueue.enqueue(root); @@ -445,21 +423,18 @@ void QtResourceViewPrivate::filterOutResources() bool searchForNewPathWithContents = true; if (!currentPath.isEmpty()) { // if the currentPath is empty we will search for a new path too - QMap<QString, bool>::ConstIterator it = pathToMatchingContents.constFind(currentPath); + const auto it = pathToMatchingContents.constFind(currentPath); if (it != pathToMatchingContents.constEnd() && it.value()) // the current item has contents, we don't need to search for another path searchForNewPathWithContents = false; } if (searchForNewPathWithContents) { // we find the first path with the matching contents - QMap<QString, bool>::ConstIterator itContents = pathToMatchingContents.constBegin(); - while (itContents != pathToMatchingContents.constEnd()) { + for (auto itContents = pathToMatchingContents.cbegin(), cend = pathToMatchingContents.cend(); itContents != cend; ++itContents) { if (itContents.value()) { newCurrentPath = itContents.key(); // the new path will be activated break; } - - itContents++; } } @@ -510,7 +485,7 @@ QTreeWidgetItem *QtResourceViewPrivate::createPath(const QString &path, QTreeWid QFileInfo di(path); substPath = di.fileName(); } else { - substPath = QStringLiteral("<resource root>"); + substPath = u"<resource root>"_s; } item->setText(0, substPath); item->setToolTip(0, path); @@ -555,23 +530,29 @@ QtResourceView::QtResourceView(QDesignerFormEditorInterface *core, QWidget *pare { d_ptr->q_ptr = this; - QIcon editIcon = QIcon::fromTheme(QStringLiteral("document-properties"), qdesigner_internal::createIconSet(QStringLiteral("edit.png"))); + QIcon editIcon = qdesigner_internal::createIconSet(QIcon::ThemeIcon::DocumentProperties, + "edit.png"_L1); d_ptr->m_editResourcesAction = new QAction(editIcon, tr("Edit Resources..."), this); d_ptr->m_toolBar->addAction(d_ptr->m_editResourcesAction); - connect(d_ptr->m_editResourcesAction, SIGNAL(triggered()), this, SLOT(slotEditResources())); + connect(d_ptr->m_editResourcesAction, &QAction::triggered, + this, [this] { d_ptr->slotEditResources(); }); d_ptr->m_editResourcesAction->setEnabled(false); - QIcon refreshIcon = QIcon::fromTheme(QStringLiteral("view-refresh"), qdesigner_internal::createIconSet(QStringLiteral("reload.png"))); + QIcon refreshIcon = qdesigner_internal::createIconSet(QIcon::ThemeIcon::ViewRefresh, + "reload.png"_L1); d_ptr->m_reloadResourcesAction = new QAction(refreshIcon, tr("Reload"), this); d_ptr->m_toolBar->addAction(d_ptr->m_reloadResourcesAction); - connect(d_ptr->m_reloadResourcesAction, SIGNAL(triggered()), this, SLOT(slotReloadResources())); + connect(d_ptr->m_reloadResourcesAction, &QAction::triggered, + this, [this] { d_ptr->slotReloadResources(); }); d_ptr->m_reloadResourcesAction->setEnabled(false); #if QT_CONFIG(clipboard) - QIcon copyIcon = QIcon::fromTheme(QStringLiteral("edit-copy"), qdesigner_internal::createIconSet(QStringLiteral("editcopy.png"))); + QIcon copyIcon = qdesigner_internal::createIconSet(QIcon::ThemeIcon::EditCopy, + "editcopy.png"_L1); d_ptr->m_copyResourcePathAction = new QAction(copyIcon, tr("Copy Path"), this); - connect(d_ptr->m_copyResourcePathAction, SIGNAL(triggered()), this, SLOT(slotCopyResourcePath())); + connect(d_ptr->m_copyResourcePathAction, &QAction::triggered, + this, [this] { d_ptr->slotCopyResourcePath(); }); d_ptr->m_copyResourcePathAction->setEnabled(false); #endif @@ -579,7 +560,8 @@ QtResourceView::QtResourceView(QDesignerFormEditorInterface *core, QWidget *pare QHBoxLayout *filterLayout = new QHBoxLayout(d_ptr->m_filterWidget); filterLayout->setContentsMargins(0, 0, 0, 0); QLineEdit *filterLineEdit = new QLineEdit(d_ptr->m_filterWidget); - connect(filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotFilterChanged(QString))); + connect(filterLineEdit, &QLineEdit::textChanged, + this, [this](const QString &text) { d_ptr->slotFilterChanged(text); }); filterLineEdit->setPlaceholderText(tr("Filter")); filterLineEdit->setClearButtonEnabled(true); filterLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored)); @@ -606,15 +588,15 @@ QtResourceView::QtResourceView(QDesignerFormEditorInterface *core, QWidget *pare d_ptr->m_listWidget->setIconSize(QSize(48, 48)); d_ptr->m_listWidget->setGridSize(QSize(64, 64)); - connect(d_ptr->m_treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), - this, SLOT(slotCurrentPathChanged(QTreeWidgetItem*))); - connect(d_ptr->m_listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(slotCurrentResourceChanged(QListWidgetItem*))); - connect(d_ptr->m_listWidget, SIGNAL(itemActivated(QListWidgetItem*)), - this, SLOT(slotResourceActivated(QListWidgetItem*))); + connect(d_ptr->m_treeWidget, &QTreeWidget::currentItemChanged, + this, [this](QTreeWidgetItem *item) { d_ptr->slotCurrentPathChanged(item); }); + connect(d_ptr->m_listWidget, &QListWidget::currentItemChanged, + this, [this](QListWidgetItem *item) { d_ptr->slotCurrentResourceChanged(item); }); + connect(d_ptr->m_listWidget, &QListWidget::itemActivated, + this, [this](QListWidgetItem *item) { d_ptr->slotResourceActivated(item); }); d_ptr->m_listWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(d_ptr->m_listWidget, SIGNAL(customContextMenuRequested(QPoint)), - this, SLOT(slotListWidgetContextMenuRequested(QPoint))); + connect(d_ptr->m_listWidget, &QListWidget::customContextMenuRequested, + this, [this](const QPoint &point) { d_ptr->slotListWidgetContextMenuRequested(point); }); } QtResourceView::~QtResourceView() @@ -693,10 +675,8 @@ void QtResourceView::setSettingsKey(const QString &key) void QtResourceView::setResourceModel(QtResourceModel *model) { - if (d_ptr->m_resourceModel) { - disconnect(d_ptr->m_resourceModel, SIGNAL(resourceSetActivated(QtResourceSet*,bool)), - this, SLOT(slotResourceSetActivated(QtResourceSet*))); - } + if (d_ptr->m_resourceModel) + disconnect(d_ptr->m_resourceModel, &QtResourceModel::resourceSetActivated, this, nullptr); // clear here d_ptr->m_treeWidget->clear(); @@ -707,8 +687,8 @@ void QtResourceView::setResourceModel(QtResourceModel *model) if (!d_ptr->m_resourceModel) return; - connect(d_ptr->m_resourceModel, SIGNAL(resourceSetActivated(QtResourceSet*,bool)), - this, SLOT(slotResourceSetActivated(QtResourceSet*))); + connect(d_ptr->m_resourceModel, &QtResourceModel::resourceSetActivated, + this, [this](QtResourceSet *resource) { d_ptr->slotResourceSetActivated(resource); }); // fill new here d_ptr->slotResourceSetActivated(d_ptr->m_resourceModel->currentResourceSet()); @@ -738,19 +718,19 @@ bool QtResourceView::dragEnabled() const QString QtResourceView::encodeMimeData(ResourceType resourceType, const QString &path) { QDomDocument doc; - QDomElement elem = doc.createElement(QLatin1String(elementResourceData)); + QDomElement elem = doc.createElement(elementResourceData); switch (resourceType) { case ResourceImage: - elem.setAttribute(QLatin1String(typeAttribute), QLatin1String(typeImage)); + elem.setAttribute(typeAttribute, typeImage); break; case ResourceStyleSheet: - elem.setAttribute(QLatin1String(typeAttribute), QLatin1String(typeStyleSheet)); + elem.setAttribute(typeAttribute, typeStyleSheet); break; case ResourceOther: - elem.setAttribute(QLatin1String(typeAttribute), QLatin1String(typeOther)); + elem.setAttribute(typeAttribute, typeOther); break; } - elem.setAttribute(QLatin1String(fileAttribute), path); + elem.setAttribute(fileAttribute, path); doc.appendChild(elem); return doc.toString(); } @@ -763,8 +743,8 @@ bool QtResourceView::decodeMimeData(const QMimeData *md, ResourceType *t, QStrin bool QtResourceView::decodeMimeData(const QString &text, ResourceType *t, QString *file) { - const QString docElementName = QLatin1String(elementResourceData); - static const QString docElementString = QLatin1Char('<') + docElementName; + static auto docElementName = elementResourceData; + static const QString docElementString = u'<' + docElementName; if (text.isEmpty() || text.indexOf(docElementString) == -1) return false; @@ -778,18 +758,18 @@ bool QtResourceView::decodeMimeData(const QString &text, ResourceType *t, QStrin return false; if (t) { - const QString typeAttr = QLatin1String(typeAttribute); + const QString typeAttr = typeAttribute; if (domElement.hasAttribute (typeAttr)) { - const QString typeValue = domElement.attribute(typeAttr, QLatin1String(typeOther)); - if (typeValue == QLatin1String(typeImage)) { + const QString typeValue = domElement.attribute(typeAttr, typeOther); + if (typeValue == typeImage) { *t = ResourceImage; } else { - *t = typeValue == QLatin1String(typeStyleSheet) ? ResourceStyleSheet : ResourceOther; + *t = typeValue == typeStyleSheet ? ResourceStyleSheet : ResourceOther; } } } if (file) { - const QString fileAttr = QLatin1String(fileAttribute); + const QString fileAttr = fileAttribute; if (domElement.hasAttribute(fileAttr)) { *file = domElement.attribute(fileAttr, QString()); } else { @@ -822,7 +802,7 @@ QtResourceViewDialogPrivate::QtResourceViewDialogPrivate(QDesignerFormEditorInte m_view(new QtResourceView(core)), m_box(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel)) { - m_view->setSettingsKey(QLatin1String(ResourceViewDialogC)); + m_view->setSettingsKey(ResourceViewDialogC); } // ------------ QtResourceViewDialog @@ -831,7 +811,6 @@ QtResourceViewDialog::QtResourceViewDialog(QDesignerFormEditorInterface *core, Q d_ptr(new QtResourceViewDialogPrivate(core)) { setWindowTitle(tr("Select Resource")); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); d_ptr->q_ptr = this; QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(d_ptr->m_view); @@ -839,14 +818,15 @@ QtResourceViewDialog::QtResourceViewDialog(QDesignerFormEditorInterface *core, Q connect(d_ptr->m_box, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(d_ptr->m_box, &QDialogButtonBox::rejected, this, &QDialog::reject); connect(d_ptr->m_view, &QtResourceView::resourceActivated, this, &QDialog::accept); - connect(d_ptr->m_view, SIGNAL(resourceSelected(QString)), this, SLOT(slotResourceSelected(QString))); + connect(d_ptr->m_view, &QtResourceView::resourceSelected, + this, [this](const QString &resource) { d_ptr->slotResourceSelected(resource); }); d_ptr->setOkButtonEnabled(false); d_ptr->m_view->setResourceModel(core->resourceModel()); QDesignerSettingsInterface *settings = core->settingsManager(); - settings->beginGroup(QLatin1String(ResourceViewDialogC)); + settings->beginGroup(ResourceViewDialogC); - const QVariant geometry = settings->value(QLatin1String(Geometry)); + const QVariant geometry = settings->value(qrvGeometry); if (geometry.metaType().id() == QMetaType::QByteArray) // Used to be a QRect up until 5.4.0, QTBUG-43374. restoreGeometry(geometry.toByteArray()); @@ -856,9 +836,9 @@ QtResourceViewDialog::QtResourceViewDialog(QDesignerFormEditorInterface *core, Q QtResourceViewDialog::~QtResourceViewDialog() { QDesignerSettingsInterface *settings = d_ptr->m_core->settingsManager(); - settings->beginGroup(QLatin1String(ResourceViewDialogC)); + settings->beginGroup(ResourceViewDialogC); - settings->setValue(QLatin1String(Geometry), saveGeometry()); + settings->setValue(qrvGeometry, saveGeometry()); settings->endGroup(); } diff --git a/src/designer/src/lib/shared/qtresourceview_p.h b/src/designer/src/lib/shared/qtresourceview_p.h index 17ec9c194..7d2ed6235 100644 --- a/src/designer/src/lib/shared/qtresourceview_p.h +++ b/src/designer/src/lib/shared/qtresourceview_p.h @@ -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 // // W A R N I N G @@ -88,21 +63,9 @@ protected: bool event(QEvent *event) override; private: - QScopedPointer<class QtResourceViewPrivate> d_ptr; Q_DECLARE_PRIVATE(QtResourceView) Q_DISABLE_COPY_MOVE(QtResourceView) - Q_PRIVATE_SLOT(d_func(), void slotResourceSetActivated(QtResourceSet *)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentPathChanged(QTreeWidgetItem *)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentResourceChanged(QListWidgetItem *)) - Q_PRIVATE_SLOT(d_func(), void slotResourceActivated(QListWidgetItem *)) - Q_PRIVATE_SLOT(d_func(), void slotEditResources()) - Q_PRIVATE_SLOT(d_func(), void slotReloadResources()) -#if QT_CONFIG(clipboard) - Q_PRIVATE_SLOT(d_func(), void slotCopyResourcePath()) -#endif - Q_PRIVATE_SLOT(d_func(), void slotListWidgetContextMenuRequested(const QPoint &pos)) - Q_PRIVATE_SLOT(d_func(), void slotFilterChanged(const QString &pattern)) }; class QDESIGNER_SHARED_EXPORT QtResourceViewDialog : public QDialog @@ -122,7 +85,6 @@ private: QScopedPointer<class QtResourceViewDialogPrivate> d_ptr; Q_DECLARE_PRIVATE(QtResourceViewDialog) Q_DISABLE_COPY_MOVE(QtResourceViewDialog) - Q_PRIVATE_SLOT(d_func(), void slotResourceSelected(const QString &)) }; QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/rcc.cpp b/src/designer/src/lib/shared/rcc.cpp index 6d271bd8a..38772d8a1 100644 --- a/src/designer/src/lib/shared/rcc.cpp +++ b/src/designer/src/lib/shared/rcc.cpp @@ -1,62 +1,42 @@ -/**************************************************************************** -** -** 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) 2018 The Qt Company Ltd. +// Copyright (C) 2018 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 /* Note: This is a copy of qtbase/src/tools/rcc/rcc.cpp. */ #include "rcc_p.h" -#include <QtCore/qbytearray.h> -#include <QtCore/qdatetime.h> -#include <QtCore/qdebug.h> -#include <QtCore/qdir.h> -#include <QtCore/qdiriterator.h> -#include <QtCore/qfile.h> -#include <QtCore/qiodevice.h> -#include <QtCore/qlocale.h> -#include <QtCore/qstack.h> -#include <QtCore/qxmlstream.h> +#include <qbytearray.h> +#include <qdatetime.h> +#include <qdebug.h> +#include <qdir.h> +#include <qdiriterator.h> +#include <qfile.h> +#include <qiodevice.h> +#include <qlocale.h> +#include <qstack.h> +#include <qxmlstream.h> #include <algorithm> +#if QT_CONFIG(zstd) +# include <zstd.h> +#endif + QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + enum { CONSTANT_USENAMESPACE = 1, CONSTANT_COMPRESSLEVEL_DEFAULT = -1, + CONSTANT_ZSTDCOMPRESSLEVEL_CHECK = 1, // Zstd level to check if compressing is a good idea + CONSTANT_ZSTDCOMPRESSLEVEL_STORE = 14, // Zstd level to actually store the data CONSTANT_COMPRESSTHRESHOLD_DEFAULT = 70 }; - -#define writeString(s) write(s, sizeof(s)) - void RCCResourceLibrary::write(const char *str, int len) { - --len; // trailing \0 on string literals... int n = m_out.size(); m_out.resize(n + len); memcpy(m_out.data() + n, str, len); @@ -64,12 +44,16 @@ void RCCResourceLibrary::write(const char *str, int len) void RCCResourceLibrary::writeByteArray(const QByteArray &other) { - m_out.append(other); + if (m_format == Pass2) { + m_outDevice->write(other); + } else { + m_out.append(other); + } } static inline QString msgOpenReadFailed(const QString &fname, const QString &why) { - return QString::fromUtf8("Unable to open %1 for reading: %2\n").arg(fname).arg(why); + return QString::fromLatin1("Unable to open %1 for reading: %2\n").arg(fname, why); } @@ -84,18 +68,25 @@ class RCCFileInfo public: enum Flags { + // must match qresource.cpp NoFlags = 0x00, Compressed = 0x01, - Directory = 0x02 + Directory = 0x02, + CompressedZstd = 0x04 }; - RCCFileInfo(const QString &name = QString(), const QFileInfo &fileInfo = QFileInfo(), - QLocale::Language language = QLocale::C, - QLocale::Country country = QLocale::AnyCountry, - uint flags = NoFlags, - int compressLevel = CONSTANT_COMPRESSLEVEL_DEFAULT, - int compressThreshold = CONSTANT_COMPRESSTHRESHOLD_DEFAULT); + + RCCFileInfo() = default; + RCCFileInfo(const QString &name, const QFileInfo &fileInfo, QLocale::Language language, + QLocale::Territory territory, uint flags, + RCCResourceLibrary::CompressionAlgorithm compressAlgo, int compressLevel, + int compressThreshold, bool noZstd, bool isEmpty); + ~RCCFileInfo(); + RCCFileInfo(const RCCFileInfo &) = delete; + RCCFileInfo &operator=(const RCCFileInfo &) = delete; + RCCFileInfo(RCCFileInfo &&) = default; + RCCFileInfo &operator=(RCCFileInfo &&other) = delete; QString resourceName() const; @@ -104,36 +95,40 @@ public: qint64 writeDataName(RCCResourceLibrary &, qint64 offset); void writeDataInfo(RCCResourceLibrary &lib); - int m_flags; + int m_flags = NoFlags; + QLocale::Language m_language = QLocale::C; + QLocale::Territory m_territory = QLocale::AnyTerritory; QString m_name; - QLocale::Language m_language; - QLocale::Country m_country; QFileInfo m_fileInfo; - RCCFileInfo *m_parent; - QHash<QString, RCCFileInfo*> m_children; - int m_compressLevel; - int m_compressThreshold; - - qint64 m_nameOffset; - qint64 m_dataOffset; - qint64 m_childOffset; + RCCFileInfo *m_parent = nullptr; + QMultiHash<QString, RCCFileInfo *> m_children; + + RCCResourceLibrary::CompressionAlgorithm m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Best; + int m_compressLevel = CONSTANT_COMPRESSLEVEL_DEFAULT; + int m_compressThreshold = CONSTANT_COMPRESSTHRESHOLD_DEFAULT; + bool m_noZstd = false; + bool m_isEmpty = false; + + qint64 m_nameOffset = 0; + qint64 m_dataOffset = 0; + qint64 m_childOffset = 0; }; -RCCFileInfo::RCCFileInfo(const QString &name, const QFileInfo &fileInfo, - QLocale::Language language, QLocale::Country country, uint flags, - int compressLevel, int compressThreshold) +RCCFileInfo::RCCFileInfo(const QString &name, const QFileInfo &fileInfo, QLocale::Language language, + QLocale::Territory territory, uint flags, + RCCResourceLibrary::CompressionAlgorithm compressAlgo, int compressLevel, + int compressThreshold, bool noZstd, bool isEmpty) + : m_flags(flags), + m_language(language), + m_territory(territory), + m_name(name), + m_fileInfo(fileInfo), + m_compressAlgo(compressAlgo), + m_compressLevel(compressLevel), + m_compressThreshold(compressThreshold), + m_noZstd(noZstd), + m_isEmpty(isEmpty) { - m_name = name; - m_fileInfo = fileInfo; - m_language = language; - m_country = country; - m_flags = flags; - m_parent = nullptr; - m_nameOffset = 0; - m_dataOffset = 0; - m_childOffset = 0; - m_compressLevel = compressLevel; - m_compressThreshold = compressThreshold; } RCCFileInfo::~RCCFileInfo() @@ -145,20 +140,23 @@ QString RCCFileInfo::resourceName() const { QString resource = m_name; for (RCCFileInfo *p = m_parent; p; p = p->m_parent) - resource = resource.prepend(p->m_name + QLatin1Char('/')); - return QLatin1Char(':') + resource; + resource = resource.prepend(p->m_name + u'/'); + resource.prepend(u':'); + return resource; } void RCCFileInfo::writeDataInfo(RCCResourceLibrary &lib) { - const bool text = (lib.m_format == RCCResourceLibrary::C_Code); + const bool text = lib.m_format == RCCResourceLibrary::C_Code; + const bool pass1 = lib.m_format == RCCResourceLibrary::Pass1; + const bool python = lib.m_format == RCCResourceLibrary::Python_Code; //some info - if (text) { + if (text || pass1) { if (m_language != QLocale::C) { lib.writeString(" // "); lib.writeByteArray(resourceName().toLocal8Bit()); lib.writeString(" ["); - lib.writeByteArray(QByteArray::number(m_country)); + lib.writeByteArray(QByteArray::number(m_territory)); lib.writeString("::"); lib.writeByteArray(QByteArray::number(m_language)); lib.writeString("[\n "); @@ -190,120 +188,228 @@ void RCCFileInfo::writeDataInfo(RCCResourceLibrary &lib) lib.writeNumber2(m_flags); // locale - lib.writeNumber2(m_country); + lib.writeNumber2(m_territory); lib.writeNumber2(m_language); //data offset lib.writeNumber4(m_dataOffset); } - if (text) + if (text || pass1) lib.writeChar('\n'); + else if (python) + lib.writeString("\\\n"); + + if (lib.formatVersion() >= 2) { + // last modified time stamp + const QDateTime lastModified = m_fileInfo.lastModified(QTimeZone::UTC); + quint64 lastmod = quint64(lastModified.isValid() ? lastModified.toMSecsSinceEpoch() : 0); + static const quint64 sourceDate = 1000 * qgetenv("QT_RCC_SOURCE_DATE_OVERRIDE").toULongLong(); + if (sourceDate != 0) + lastmod = sourceDate; + static const quint64 sourceDate2 = 1000 * qgetenv("SOURCE_DATE_EPOCH").toULongLong(); + if (sourceDate2 != 0) + lastmod = sourceDate2; + lib.writeNumber8(lastmod); + if (text || pass1) + lib.writeChar('\n'); + else if (python) + lib.writeString("\\\n"); + } } qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib, qint64 offset, QString *errorMessage) { - const bool text = (lib.m_format == RCCResourceLibrary::C_Code); + const bool text = lib.m_format == RCCResourceLibrary::C_Code; + const bool pass1 = lib.m_format == RCCResourceLibrary::Pass1; + const bool pass2 = lib.m_format == RCCResourceLibrary::Pass2; + const bool binary = lib.m_format == RCCResourceLibrary::Binary; + const bool python = lib.m_format == RCCResourceLibrary::Python_Code; //capture the offset m_dataOffset = offset; + QByteArray data; + + if (!m_isEmpty) { + //find the data to be written + QFile file(m_fileInfo.absoluteFilePath()); + if (!file.open(QFile::ReadOnly)) { + *errorMessage = msgOpenReadFailed(m_fileInfo.absoluteFilePath(), file.errorString()); + return 0; + } - //find the data to be written - QFile file(m_fileInfo.absoluteFilePath()); - if (!file.open(QFile::ReadOnly)) { - *errorMessage = msgOpenReadFailed(m_fileInfo.absoluteFilePath(), file.errorString()); - return 0; + data = file.readAll(); } - QByteArray data = file.readAll(); -#ifndef QT_NO_COMPRESS // Check if compression is useful for this file - if (m_compressLevel != 0 && data.size() != 0) { - QByteArray compressed = - qCompress(reinterpret_cast<uchar *>(data.data()), data.size(), m_compressLevel); - - int compressRatio = int(100.0 * (data.size() - compressed.size()) / data.size()); - if (compressRatio >= m_compressThreshold) { - data = compressed; - m_flags |= Compressed; + if (data.size() != 0) { +#if QT_CONFIG(zstd) + if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best && !m_noZstd) { + m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zstd; + m_compressLevel = 19; // not ZSTD_maxCLevel(), as 20+ are experimental + } + if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zstd && !m_noZstd) { + if (lib.m_zstdCCtx == nullptr) + lib.m_zstdCCtx = ZSTD_createCCtx(); + qsizetype size = data.size(); + size = ZSTD_COMPRESSBOUND(size); + + int compressLevel = m_compressLevel; + if (compressLevel < 0) + compressLevel = CONSTANT_ZSTDCOMPRESSLEVEL_CHECK; + + QByteArray compressed(size, Qt::Uninitialized); + char *dst = const_cast<char *>(compressed.constData()); + size_t n = ZSTD_compressCCtx(lib.m_zstdCCtx, dst, size, + data.constData(), data.size(), + compressLevel); + if (n * 100.0 < data.size() * 1.0 * (100 - m_compressThreshold) ) { + // compressing is worth it + if (m_compressLevel < 0) { + // heuristic compression, so recompress + n = ZSTD_compressCCtx(lib.m_zstdCCtx, dst, size, + data.constData(), data.size(), + CONSTANT_ZSTDCOMPRESSLEVEL_STORE); + } + if (ZSTD_isError(n)) { + QString msg = QString::fromLatin1("%1: error: compression with zstd failed: %2\n") + .arg(m_name, QString::fromUtf8(ZSTD_getErrorName(n))); + lib.m_errorDevice->write(msg.toUtf8()); + } else if (lib.verbose()) { + QString msg = QString::fromLatin1("%1: note: compressed using zstd (%2 -> %3)\n") + .arg(m_name).arg(data.size()).arg(n); + lib.m_errorDevice->write(msg.toUtf8()); + } + + lib.m_overallFlags |= CompressedZstd; + m_flags |= CompressedZstd; + data = std::move(compressed); + data.truncate(n); + } else if (lib.verbose()) { + QString msg = QString::fromLatin1("%1: note: not compressed\n").arg(m_name); + lib.m_errorDevice->write(msg.toUtf8()); + } + } +#endif +#ifndef QT_NO_COMPRESS + if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Best) { + m_compressAlgo = RCCResourceLibrary::CompressionAlgorithm::Zlib; + m_compressLevel = 9; + } + if (m_compressAlgo == RCCResourceLibrary::CompressionAlgorithm::Zlib) { + QByteArray compressed = + qCompress(reinterpret_cast<uchar *>(data.data()), data.size(), m_compressLevel); + + int compressRatio = int(100.0 * (data.size() - compressed.size()) / data.size()); + if (compressRatio >= m_compressThreshold) { + if (lib.verbose()) { + QString msg = QString::fromLatin1("%1: note: compressed using zlib (%2 -> %3)\n") + .arg(m_name).arg(data.size()).arg(compressed.size()); + lib.m_errorDevice->write(msg.toUtf8()); + } + data = compressed; + lib.m_overallFlags |= Compressed; + m_flags |= Compressed; + } else if (lib.verbose()) { + QString msg = QString::fromLatin1("%1: note: not compressed\n").arg(m_name); + lib.m_errorDevice->write(msg.toUtf8()); + } } - } #endif // QT_NO_COMPRESS + } // some info - if (text) { + if (text || pass1) { lib.writeString(" // "); lib.writeByteArray(m_fileInfo.absoluteFilePath().toLocal8Bit()); lib.writeString("\n "); } // write the length - - lib.writeNumber4(data.size()); - if (text) + if (text || binary || pass2 || python) + lib.writeNumber4(data.size()); + if (text || pass1) lib.writeString("\n "); + else if (python) + lib.writeString("\\\n"); offset += 4; // write the payload const char *p = data.constData(); - if (text) { + if (text || python) { for (int i = data.size(), j = 0; --i >= 0; --j) { lib.writeHex(*p++); if (j == 0) { - lib.writeString("\n "); + if (text) + lib.writeString("\n "); + else + lib.writeString("\\\n"); j = 16; } } - } else { - for (int i = data.size(); --i >= 0; ) - lib.writeChar(*p++); + } else if (binary || pass2) { + lib.writeByteArray(data); } offset += data.size(); // done - if (text) + if (text || pass1) lib.writeString("\n "); + else if (python) + lib.writeString("\\\n"); + return offset; } qint64 RCCFileInfo::writeDataName(RCCResourceLibrary &lib, qint64 offset) { - const bool text = (lib.m_format == RCCResourceLibrary::C_Code); + const bool text = lib.m_format == RCCResourceLibrary::C_Code; + const bool pass1 = lib.m_format == RCCResourceLibrary::Pass1; + const bool python = lib.m_format == RCCResourceLibrary::Python_Code; // capture the offset m_nameOffset = offset; // some info - if (text) { + if (text || pass1) { lib.writeString(" // "); lib.writeByteArray(m_name.toLocal8Bit()); lib.writeString("\n "); } // write the length - lib.writeNumber2(m_name.length()); - if (text) + lib.writeNumber2(m_name.size()); + if (text || pass1) lib.writeString("\n "); + else if (python) + lib.writeString("\\\n"); offset += 2; // write the hash lib.writeNumber4(qt_hash(m_name)); - if (text) + if (text || pass1) lib.writeString("\n "); + else if (python) + lib.writeString("\\\n"); offset += 4; // write the m_name const QChar *unicode = m_name.unicode(); - for (int i = 0; i < m_name.length(); ++i) { + for (int i = 0; i < m_name.size(); ++i) { lib.writeNumber2(unicode[i].unicode()); - if (text && i % 16 == 0) + if ((text || pass1) && i % 16 == 0) lib.writeString("\n "); + else if (python && i % 16 == 0) + lib.writeString("\\\n"); } - offset += m_name.length()*2; + offset += m_name.size()*2; // done - if (text) + if (text || pass1) lib.writeString("\n "); + else if (python) + lib.writeString("\\\n"); + return offset; } @@ -315,35 +421,48 @@ qint64 RCCFileInfo::writeDataName(RCCResourceLibrary &lib, qint64 offset) /////////////////////////////////////////////////////////// RCCResourceLibrary::Strings::Strings() : - TAG_RCC(QLatin1String("RCC")), - TAG_RESOURCE(QLatin1String("qresource")), - TAG_FILE(QLatin1String("file")), - ATTRIBUTE_LANG(QLatin1String("lang")), - ATTRIBUTE_PREFIX(QLatin1String("prefix")), - ATTRIBUTE_ALIAS(QLatin1String("alias")), - ATTRIBUTE_THRESHOLD(QLatin1String("threshold")), - ATTRIBUTE_COMPRESS(QLatin1String("compress")) + TAG_RCC("RCC"_L1), + TAG_RESOURCE("qresource"_L1), + TAG_FILE("file"_L1), + ATTRIBUTE_LANG("lang"_L1), + ATTRIBUTE_PREFIX("prefix"_L1), + ATTRIBUTE_ALIAS("alias"_L1), + ATTRIBUTE_EMPTY("empty"_L1), + ATTRIBUTE_THRESHOLD("threshold"_L1), + ATTRIBUTE_COMPRESS("compress"_L1), + ATTRIBUTE_COMPRESSALGO(QStringLiteral("compression-algorithm")) { } -RCCResourceLibrary::RCCResourceLibrary() +RCCResourceLibrary::RCCResourceLibrary(quint8 formatVersion) : m_root(nullptr), m_format(C_Code), m_verbose(false), + m_compressionAlgo(CompressionAlgorithm::Best), m_compressLevel(CONSTANT_COMPRESSLEVEL_DEFAULT), m_compressThreshold(CONSTANT_COMPRESSTHRESHOLD_DEFAULT), m_treeOffset(0), m_namesOffset(0), m_dataOffset(0), + m_overallFlags(0), m_useNameSpace(CONSTANT_USENAMESPACE), - m_errorDevice(0) + m_errorDevice(nullptr), + m_outDevice(nullptr), + m_formatVersion(formatVersion), + m_noZstd(false) { m_out.reserve(30 * 1000 * 1000); +#if QT_CONFIG(zstd) + m_zstdCCtx = nullptr; +#endif } RCCResourceLibrary::~RCCResourceLibrary() { delete m_root; +#if QT_CONFIG(zstd) + ZSTD_freeCCtx(m_zstdCCtx); +#endif } enum RCCXmlTag { @@ -351,12 +470,24 @@ enum RCCXmlTag { ResourceTag, FileTag }; +Q_DECLARE_TYPEINFO(RCCXmlTag, Q_PRIMITIVE_TYPE); + +static bool parseBoolean(QStringView value, QString *errorMsg) +{ + if (value.compare("true"_L1, Qt::CaseInsensitive) == 0) + return true; + if (value.compare("false"_L1, Qt::CaseInsensitive) == 0) + return false; + + *errorMsg = QString::fromLatin1("Invalid value for boolean attribute: '%1'").arg(value); + return false; +} bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, - const QString &fname, QString currentPath, bool ignoreErrors) + const QString &fname, QString currentPath, bool listMode) { Q_ASSERT(m_errorDevice); - const QChar slash = QLatin1Char('/'); + const QChar slash = u'/'; if (!currentPath.isEmpty() && !currentPath.endsWith(slash)) currentPath += slash; @@ -365,8 +496,10 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, QString prefix; QLocale::Language language = QLocale::c().language(); - QLocale::Country country = QLocale::c().country(); + QLocale::Territory territory = QLocale::c().territory(); QString alias; + bool empty = false; + auto compressAlgo = m_compressionAlgo; int compressLevel = m_compressLevel; int compressThreshold = m_compressThreshold; @@ -376,28 +509,28 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, case QXmlStreamReader::StartElement: if (reader.name() == m_strings.TAG_RCC) { if (!tokens.isEmpty()) - reader.raiseError(QLatin1String("expected <RCC> tag")); + reader.raiseError("expected <RCC> tag"_L1); else tokens.push(RccTag); } else if (reader.name() == m_strings.TAG_RESOURCE) { if (tokens.isEmpty() || tokens.top() != RccTag) { - reader.raiseError(QLatin1String("unexpected <RESOURCE> tag")); + reader.raiseError("unexpected <RESOURCE> tag"_L1); } else { tokens.push(ResourceTag); QXmlStreamAttributes attributes = reader.attributes(); language = QLocale::c().language(); - country = QLocale::c().country(); + territory = QLocale::c().territory(); if (attributes.hasAttribute(m_strings.ATTRIBUTE_LANG)) { QString attribute = attributes.value(m_strings.ATTRIBUTE_LANG).toString(); QLocale lang = QLocale(attribute); language = lang.language(); - if (2 == attribute.length()) { + if (2 == attribute.size()) { // Language only - country = QLocale::AnyCountry; + territory = QLocale::AnyTerritory; } else { - country = lang.country(); + territory = lang.territory(); } } @@ -411,7 +544,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, } } else if (reader.name() == m_strings.TAG_FILE) { if (tokens.isEmpty() || tokens.top() != ResourceTag) { - reader.raiseError(QLatin1String("unexpected <FILE> tag")); + reader.raiseError("unexpected <FILE> tag"_L1); } else { tokens.push(FileTag); @@ -420,20 +553,35 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, if (attributes.hasAttribute(m_strings.ATTRIBUTE_ALIAS)) alias = attributes.value(m_strings.ATTRIBUTE_ALIAS).toString(); + compressAlgo = m_compressionAlgo; compressLevel = m_compressLevel; - if (attributes.hasAttribute(m_strings.ATTRIBUTE_COMPRESS)) - compressLevel = attributes.value(m_strings.ATTRIBUTE_COMPRESS).toString().toInt(); - compressThreshold = m_compressThreshold; + + QString errorString; + if (attributes.hasAttribute(m_strings.ATTRIBUTE_EMPTY)) + empty = parseBoolean(attributes.value(m_strings.ATTRIBUTE_EMPTY), &errorString); + else + empty = false; + + if (attributes.hasAttribute(m_strings.ATTRIBUTE_COMPRESSALGO)) + compressAlgo = parseCompressionAlgorithm(attributes.value(m_strings.ATTRIBUTE_COMPRESSALGO), &errorString); + if (errorString.isEmpty() && attributes.hasAttribute(m_strings.ATTRIBUTE_COMPRESS)) { + QString value = attributes.value(m_strings.ATTRIBUTE_COMPRESS).toString(); + compressLevel = parseCompressionLevel(compressAlgo, value, &errorString); + } + + // Special case for -no-compress + if (m_compressLevel == -2) + compressAlgo = CompressionAlgorithm::None; + if (attributes.hasAttribute(m_strings.ATTRIBUTE_THRESHOLD)) compressThreshold = attributes.value(m_strings.ATTRIBUTE_THRESHOLD).toString().toInt(); - // Special case for -no-compress. Overrides all other settings. - if (m_compressLevel == -2) - compressLevel = 0; + if (!errorString.isEmpty()) + reader.raiseError(errorString); } } else { - reader.raiseError(QString(QLatin1String("unexpected tag: %1")).arg(reader.name().toString())); + reader.raiseError("unexpected tag: %1"_L1.arg(reader.name().toString())); } break; @@ -442,17 +590,17 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, if (!tokens.isEmpty() && tokens.top() == RccTag) tokens.pop(); else - reader.raiseError(QLatin1String("unexpected closing tag")); + reader.raiseError("unexpected closing tag"_L1); } else if (reader.name() == m_strings.TAG_RESOURCE) { if (!tokens.isEmpty() && tokens.top() == ResourceTag) tokens.pop(); else - reader.raiseError(QLatin1String("unexpected closing tag")); + reader.raiseError("unexpected closing tag"_L1); } else if (reader.name() == m_strings.TAG_FILE) { if (!tokens.isEmpty() && tokens.top() == FileTag) tokens.pop(); else - reader.raiseError(QLatin1String("unexpected closing tag")); + reader.raiseError("unexpected closing tag"_L1); } break; @@ -460,7 +608,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, if (reader.isWhitespace()) break; if (tokens.isEmpty() || tokens.top() != FileTag) { - reader.raiseError(QLatin1String("unexpected text")); + reader.raiseError("unexpected text"_L1); } else { QString fileName = reader.text().toString(); if (fileName.isEmpty()) { @@ -472,7 +620,7 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, alias = fileName; alias = QDir::cleanPath(alias); - while (alias.startsWith(QLatin1String("../"))) + while (alias.startsWith("../"_L1)) alias.remove(0, 3); alias = QDir::cleanPath(m_resourceRoot) + prefix + alias; @@ -480,58 +628,62 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, if (QDir::isRelativePath(absFileName)) absFileName.prepend(currentPath); QFileInfo file(absFileName); - if (!file.exists()) { - m_failedResources.push_back(absFileName); - const QString msg = QString::fromLatin1("RCC: Error in '%1': Cannot find file '%2'\n").arg(fname).arg(fileName); - m_errorDevice->write(msg.toUtf8()); - if (ignoreErrors) - continue; - else - return false; - } else if (file.isFile()) { + if (file.isDir()) { + QDir dir(file.filePath()); + if (!alias.endsWith(slash)) + alias += slash; + + QStringList filePaths; + QDirIterator it(dir, QDirIterator::FollowSymlinks|QDirIterator::Subdirectories); + while (it.hasNext()) { + it.next(); + if (it.fileName() == "."_L1 || it.fileName() == ".."_L1) + continue; + filePaths.append(it.filePath()); + } + + // make rcc output deterministic + std::sort(filePaths.begin(), filePaths.end()); + + for (const QString &filePath : filePaths) { + QFileInfo child(filePath); + const bool arc = + addFile(alias + child.fileName(), + RCCFileInfo(child.fileName(), child, language, territory, + child.isDir() ? RCCFileInfo::Directory + : RCCFileInfo::NoFlags, + compressAlgo, compressLevel, compressThreshold, + m_noZstd, empty)); + if (!arc) + m_failedResources.push_back(child.fileName()); + } + } else if (listMode || file.isFile()) { const bool arc = addFile(alias, RCCFileInfo(alias.section(slash, -1), file, language, - country, + territory, RCCFileInfo::NoFlags, + compressAlgo, compressLevel, - compressThreshold) + compressThreshold, + m_noZstd, empty) ); if (!arc) m_failedResources.push_back(absFileName); + } else if (file.exists()) { + m_failedResources.push_back(absFileName); + const QString msg = QString::fromLatin1("RCC: Error in '%1': Entry '%2' is neither a file nor a directory\n") + .arg(fname, fileName); + m_errorDevice->write(msg.toUtf8()); + return false; } else { - QDir dir; - if (file.isDir()) { - dir.setPath(file.filePath()); - } else { - dir.setPath(file.path()); - dir.setNameFilters(QStringList(file.fileName())); - if (alias.endsWith(file.fileName())) - alias = alias.left(alias.length()-file.fileName().length()); - } - if (!alias.endsWith(slash)) - alias += slash; - QDirIterator it(dir, QDirIterator::FollowSymlinks|QDirIterator::Subdirectories); - while (it.hasNext()) { - it.next(); - QFileInfo child(it.fileInfo()); - if (child.fileName() != QLatin1String(".") && child.fileName() != QLatin1String("..")) { - const bool arc = - addFile(alias + child.fileName(), - RCCFileInfo(child.fileName(), - child, - language, - country, - RCCFileInfo::NoFlags, - compressLevel, - compressThreshold) - ); - if (!arc) - m_failedResources.push_back(child.fileName()); - } - } + m_failedResources.push_back(absFileName); + const QString msg = QString::fromLatin1("RCC: Error in '%1': Cannot find file '%2'\n") + .arg(fname, fileName); + m_errorDevice->write(msg.toUtf8()); + return false; } } break; @@ -542,8 +694,6 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, } if (reader.hasError()) { - if (ignoreErrors) - return true; int errorLine = reader.lineNumber(); int errorColumn = reader.columnNumber(); QString errorMessage = reader.errorString(); @@ -553,37 +703,41 @@ bool RCCResourceLibrary::interpretResourceFile(QIODevice *inputDevice, } if (m_root == nullptr) { - const QString msg = QString::fromUtf8("RCC: Warning: No resources in '%1'.\n").arg(fname); + const QString msg = QString::fromLatin1("RCC: Warning: No resources in '%1'.\n").arg(fname); m_errorDevice->write(msg.toUtf8()); - if (!ignoreErrors && m_format == Binary) { + if (!listMode && m_format == Binary) { // create dummy entry, otherwise loading with QResource will crash - m_root = new RCCFileInfo(QString(), QFileInfo(), - QLocale::C, QLocale::AnyCountry, RCCFileInfo::Directory); + m_root = new RCCFileInfo{}; + m_root->m_flags = RCCFileInfo::Directory; } } return true; } -bool RCCResourceLibrary::addFile(const QString &alias, const RCCFileInfo &file) +bool RCCResourceLibrary::addFile(const QString &alias, RCCFileInfo file) { Q_ASSERT(m_errorDevice); if (file.m_fileInfo.size() > 0xffffffff) { - const QString msg = QString::fromUtf8("File too big: %1\n").arg(file.m_fileInfo.absoluteFilePath()); + const QString msg = QString::fromLatin1("File too big: %1\n").arg(file.m_fileInfo.absoluteFilePath()); m_errorDevice->write(msg.toUtf8()); return false; } - if (!m_root) - m_root = new RCCFileInfo(QString(), QFileInfo(), QLocale::C, QLocale::AnyCountry, RCCFileInfo::Directory); + if (!m_root) { + m_root = new RCCFileInfo{}; + m_root->m_flags = RCCFileInfo::Directory; + } RCCFileInfo *parent = m_root; - const QStringList nodes = alias.split(QLatin1Char('/')); + const QStringList nodes = alias.split(u'/'); for (int i = 1; i < nodes.size()-1; ++i) { const QString node = nodes.at(i); if (node.isEmpty()) continue; if (!parent->m_children.contains(node)) { - RCCFileInfo *s = new RCCFileInfo(node, QFileInfo(), QLocale::C, QLocale::AnyCountry, RCCFileInfo::Directory); + RCCFileInfo *s = new RCCFileInfo{}; + s->m_name = node; + s->m_flags = RCCFileInfo::Directory; s->m_parent = parent; parent->m_children.insert(node, s); parent = s; @@ -593,12 +747,18 @@ bool RCCResourceLibrary::addFile(const QString &alias, const RCCFileInfo &file) } const QString filename = nodes.at(nodes.size()-1); - RCCFileInfo *s = new RCCFileInfo(file); + RCCFileInfo *s = new RCCFileInfo(std::move(file)); s->m_parent = parent; - if (parent->m_children.contains(filename)) { - for (const QString &fileName : qAsConst(m_fileNames)) { - qWarning("%s: Warning: potential duplicate alias detected: '%s'", - qPrintable(fileName), qPrintable(filename)); + auto cbegin = parent->m_children.constFind(filename); + auto cend = parent->m_children.constEnd(); + for (auto it = cbegin; it != cend; ++it) { + if (it.key() == filename && it.value()->m_language == s->m_language && + it.value()->m_territory == s->m_territory) { + for (const QString &name : std::as_const(m_fileNames)) { + qWarning("%s: Warning: potential duplicate alias detected: '%s'", + qPrintable(name), qPrintable(filename)); + } + break; } } parent->m_children.insert(filename, s); @@ -616,22 +776,22 @@ void RCCResourceLibrary::reset() } -bool RCCResourceLibrary::readFiles(bool ignoreErrors, QIODevice &errorDevice) +bool RCCResourceLibrary::readFiles(bool listMode, QIODevice &errorDevice) { reset(); m_errorDevice = &errorDevice; //read in data if (m_verbose) { - const QString msg = QString::fromUtf8("Processing %1 files [%2]\n") - .arg(m_fileNames.size()).arg(static_cast<int>(ignoreErrors)); + const QString msg = QString::fromLatin1("Processing %1 files [listMode=%2]\n") + .arg(m_fileNames.size()).arg(static_cast<int>(listMode)); m_errorDevice->write(msg.toUtf8()); } for (int i = 0; i < m_fileNames.size(); ++i) { QFile fileIn; QString fname = m_fileNames.at(i); QString pwd; - if (fname == QLatin1String("-")) { - fname = QLatin1String("(stdin)"); + if (fname == "-"_L1) { + fname = "(stdin)"_L1; pwd = QDir::currentPath(); fileIn.setFileName(fname); if (!fileIn.open(stdin, QIODevice::ReadOnly)) { @@ -647,11 +807,11 @@ bool RCCResourceLibrary::readFiles(bool ignoreErrors, QIODevice &errorDevice) } } if (m_verbose) { - const QString msg = QString::fromUtf8("Interpreting %1\n").arg(fname); + const QString msg = QString::fromLatin1("Interpreting %1\n").arg(fname); m_errorDevice->write(msg.toUtf8()); } - if (!interpretResourceFile(&fileIn, fname, pwd, ignoreErrors)) + if (!interpretResourceFile(&fileIn, fname, pwd, listMode)) return false; } return true; @@ -667,12 +827,13 @@ QStringList RCCResourceLibrary::dataFiles() const pending.push(m_root); while (!pending.isEmpty()) { RCCFileInfo *file = pending.pop(); - for (QHash<QString, RCCFileInfo*>::iterator it = file->m_children.begin(); + for (auto it = file->m_children.begin(); it != file->m_children.end(); ++it) { RCCFileInfo *child = it.value(); if (child->m_flags & RCCFileInfo::Directory) pending.push(child); - ret.append(child->m_fileInfo.filePath()); + else + ret.append(child->m_fileInfo.filePath()); } } return ret; @@ -681,12 +842,11 @@ QStringList RCCResourceLibrary::dataFiles() const // Determine map of resource identifier (':/newPrefix/images/p1.png') to file via recursion static void resourceDataFileMapRecursion(const RCCFileInfo *m_root, const QString &path, RCCResourceLibrary::ResourceDataFileMap &m) { - const QChar slash = QLatin1Char('/'); - for (auto it = m_root->m_children.constBegin(), cend = m_root->m_children.constEnd(); it != cend; ++it) { + const QChar slash = u'/'; + const auto cend = m_root->m_children.constEnd(); + for (auto it = m_root->m_children.constBegin(); it != cend; ++it) { const RCCFileInfo *child = it.value(); - QString childName = path; - childName += slash; - childName += child->m_name; + const QString childName = path + slash + child->m_name; if (child->m_flags & RCCFileInfo::Directory) { resourceDataFileMapRecursion(child, childName, m); } else { @@ -699,13 +859,100 @@ RCCResourceLibrary::ResourceDataFileMap RCCResourceLibrary::resourceDataFileMap( { ResourceDataFileMap rc; if (m_root) - resourceDataFileMapRecursion(m_root, QString(QLatin1Char(':')), rc); + resourceDataFileMapRecursion(m_root, QString(u':'), rc); return rc; } -bool RCCResourceLibrary::output(QIODevice &outDevice, QIODevice &errorDevice) +RCCResourceLibrary::CompressionAlgorithm RCCResourceLibrary::parseCompressionAlgorithm(QStringView value, QString *errorMsg) +{ + if (value == "best"_L1) + return CompressionAlgorithm::Best; + if (value == "zlib"_L1) { +#ifdef QT_NO_COMPRESS + *errorMsg = "zlib support not compiled in"_L1; +#else + return CompressionAlgorithm::Zlib; +#endif + } else if (value == "zstd"_L1) { +#if QT_CONFIG(zstd) + return CompressionAlgorithm::Zstd; +#else + *errorMsg = "Zstandard support not compiled in"_L1; +#endif + } else if (value != "none"_L1) { + *errorMsg = QString::fromLatin1("Unknown compression algorithm '%1'").arg(value); + } + + return CompressionAlgorithm::None; +} + +int RCCResourceLibrary::parseCompressionLevel(CompressionAlgorithm algo, const QString &level, QString *errorMsg) +{ + bool ok; + int c = level.toInt(&ok); + if (ok) { + switch (algo) { + case CompressionAlgorithm::None: + case CompressionAlgorithm::Best: + return 0; + case CompressionAlgorithm::Zlib: + if (c >= 1 && c <= 9) + return c; + break; + case CompressionAlgorithm::Zstd: +#if QT_CONFIG(zstd) + if (c >= 0 && c <= ZSTD_maxCLevel()) + return c; +#endif + break; + } + } + + *errorMsg = QString::fromLatin1("invalid compression level '%1'").arg(level); + return 0; +} + +bool RCCResourceLibrary::output(QIODevice &outDevice, QIODevice &tempDevice, QIODevice &errorDevice) { m_errorDevice = &errorDevice; + + if (m_format == Pass2) { + const char pattern[] = { 'Q', 'R', 'C', '_', 'D', 'A', 'T', 'A' }; + bool foundSignature = false; + + while (true) { + char c; + for (int i = 0; i < 8; ) { + if (!tempDevice.getChar(&c)) { + if (foundSignature) + return true; + m_errorDevice->write("No data signature found\n"); + return false; + } + + if (c != pattern[i]) { + for (int k = 0; k < i; ++k) + outDevice.putChar(pattern[k]); + i = 0; + } + + if (c == pattern[i]) { + ++i; + } else { + outDevice.putChar(c); + } + } + + m_outDevice = &outDevice; + quint64 start = outDevice.pos(); + writeDataBlobs(); + quint64 len = outDevice.pos() - start; + + tempDevice.seek(tempDevice.pos() + len - 8); + foundSignature = true; + } + } + //write out if (m_verbose) m_errorDevice->write("Outputting code\n"); @@ -735,18 +982,44 @@ bool RCCResourceLibrary::output(QIODevice &outDevice, QIODevice &errorDevice) return true; } +void RCCResourceLibrary::writeDecimal(int value) +{ + Q_ASSERT(m_format != RCCResourceLibrary::Binary); + char buf[std::numeric_limits<int>::digits10 + 2]; + int n = snprintf(buf, sizeof(buf), "%d", value); + write(buf, n); +} + +static const char hexDigits[] = "0123456789abcdef"; + +inline void RCCResourceLibrary::write2HexDigits(quint8 number) +{ + writeChar(hexDigits[number >> 4]); + writeChar(hexDigits[number & 0xf]); +} + void RCCResourceLibrary::writeHex(quint8 tmp) { - const char digits[] = "0123456789abcdef"; - writeChar('0'); - writeChar('x'); - if (tmp < 16) { - writeChar(digits[tmp]); - } else { - writeChar(digits[tmp >> 4]); - writeChar(digits[tmp & 0xf]); + switch (m_format) { + case RCCResourceLibrary::Python_Code: + if (tmp >= 32 && tmp < 127 && tmp != '"' && tmp != '\\') { + writeChar(char(tmp)); + } else { + writeChar('\\'); + writeChar('x'); + write2HexDigits(tmp); + } + break; + default: + writeChar('0'); + writeChar('x'); + if (tmp < 16) + writeChar(hexDigits[tmp]); + else + write2HexDigits(tmp); + writeChar(','); + break; } - writeChar(','); } void RCCResourceLibrary::writeNumber2(quint16 number) @@ -762,12 +1035,49 @@ void RCCResourceLibrary::writeNumber2(quint16 number) void RCCResourceLibrary::writeNumber4(quint32 number) { - if (m_format == RCCResourceLibrary::Binary) { + if (m_format == RCCResourceLibrary::Pass2) { + m_outDevice->putChar(char(number >> 24)); + m_outDevice->putChar(char(number >> 16)); + m_outDevice->putChar(char(number >> 8)); + m_outDevice->putChar(char(number)); + } else if (m_format == RCCResourceLibrary::Binary) { + writeChar(number >> 24); + writeChar(number >> 16); + writeChar(number >> 8); + writeChar(number); + } else { + writeHex(number >> 24); + writeHex(number >> 16); + writeHex(number >> 8); + writeHex(number); + } +} + +void RCCResourceLibrary::writeNumber8(quint64 number) +{ + if (m_format == RCCResourceLibrary::Pass2) { + m_outDevice->putChar(char(number >> 56)); + m_outDevice->putChar(char(number >> 48)); + m_outDevice->putChar(char(number >> 40)); + m_outDevice->putChar(char(number >> 32)); + m_outDevice->putChar(char(number >> 24)); + m_outDevice->putChar(char(number >> 16)); + m_outDevice->putChar(char(number >> 8)); + m_outDevice->putChar(char(number)); + } else if (m_format == RCCResourceLibrary::Binary) { + writeChar(number >> 56); + writeChar(number >> 48); + writeChar(number >> 40); + writeChar(number >> 32); writeChar(number >> 24); writeChar(number >> 16); writeChar(number >> 8); writeChar(number); } else { + writeHex(number >> 56); + writeHex(number >> 48); + writeHex(number >> 40); + writeHex(number >> 32); writeHex(number >> 24); writeHex(number >> 16); writeHex(number >> 8); @@ -777,24 +1087,40 @@ void RCCResourceLibrary::writeNumber4(quint32 number) bool RCCResourceLibrary::writeHeader() { - if (m_format == C_Code) { + switch (m_format) { + case C_Code: + case Pass1: writeString("/****************************************************************************\n"); writeString("** Resource object code\n"); writeString("**\n"); - writeString("** Created: "); - writeByteArray(QDateTime::currentDateTime().toString().toLatin1()); - writeString("\n** by: The Resource Compiler for Qt version "); + writeString("** Created by: The Resource Compiler for Qt version "); writeByteArray(QT_VERSION_STR); writeString("\n**\n"); writeString("** WARNING! All changes made in this file will be lost!\n"); writeString( "*****************************************************************************/\n\n"); - writeString("#include <QtCore/qglobal.h>\n\n"); - } else if (m_format == Binary) { + break; + case Python_Code: + writeString("# Resource object code (Python 3)\n"); + writeString("# Created by: object code\n"); + writeString("# Created by: The Resource Compiler for Qt version "); + writeByteArray(QT_VERSION_STR); + writeString("\n"); + writeString("# WARNING! All changes made in this file will be lost!\n\n"); + writeString("from PySide"); + writeByteArray(QByteArray::number(QT_VERSION_MAJOR)); + writeString(" import QtCore\n\n"); + break; + case Binary: writeString("qres"); writeNumber4(0); writeNumber4(0); writeNumber4(0); writeNumber4(0); + if (m_formatVersion >= 3) + writeNumber4(m_overallFlags); + break; + default: + break; } return true; } @@ -802,22 +1128,30 @@ bool RCCResourceLibrary::writeHeader() bool RCCResourceLibrary::writeDataBlobs() { Q_ASSERT(m_errorDevice); - if (m_format == C_Code) + switch (m_format) { + case C_Code: writeString("static const unsigned char qt_resource_data[] = {\n"); - else if (m_format == Binary) + break; + case Python_Code: + writeString("qt_resource_data = b\"\\\n"); + break; + case Binary: m_dataOffset = m_out.size(); - QStack<RCCFileInfo*> pending; + break; + default: + break; + } if (!m_root) return false; + QStack<RCCFileInfo*> pending; pending.push(m_root); qint64 offset = 0; QString errorMessage; while (!pending.isEmpty()) { RCCFileInfo *file = pending.pop(); - for (QHash<QString, RCCFileInfo*>::iterator it = file->m_children.begin(); - it != file->m_children.end(); ++it) { + for (auto it = file->m_children.cbegin(); it != file->m_children.cend(); ++it) { RCCFileInfo *child = it.value(); if (child->m_flags & RCCFileInfo::Directory) pending.push(child); @@ -830,17 +1164,42 @@ bool RCCResourceLibrary::writeDataBlobs() } } } - if (m_format == C_Code) + switch (m_format) { + case C_Code: writeString("\n};\n\n"); + break; + case Python_Code: + writeString("\"\n\n"); + break; + case Pass1: + if (offset < 8) + offset = 8; + writeString("\nstatic const unsigned char qt_resource_data["); + writeByteArray(QByteArray::number(offset)); + writeString("] = { 'Q', 'R', 'C', '_', 'D', 'A', 'T', 'A' };\n\n"); + break; + default: + break; + } return true; } bool RCCResourceLibrary::writeDataNames() { - if (m_format == C_Code) + switch (m_format) { + case C_Code: + case Pass1: writeString("static const unsigned char qt_resource_name[] = {\n"); - else if (m_format == Binary) + break; + case Python_Code: + writeString("qt_resource_name = b\"\\\n"); + break; + case Binary: m_namesOffset = m_out.size(); + break; + default: + break; + } QHash<QString, int> names; QStack<RCCFileInfo*> pending; @@ -852,8 +1211,7 @@ bool RCCResourceLibrary::writeDataNames() qint64 offset = 0; while (!pending.isEmpty()) { RCCFileInfo *file = pending.pop(); - for (QHash<QString, RCCFileInfo*>::iterator it = file->m_children.begin(); - it != file->m_children.end(); ++it) { + for (auto it = file->m_children.cbegin(); it != file->m_children.cend(); ++it) { RCCFileInfo *child = it.value(); if (child->m_flags & RCCFileInfo::Directory) pending.push(child); @@ -865,22 +1223,46 @@ bool RCCResourceLibrary::writeDataNames() } } } - if (m_format == C_Code) + switch (m_format) { + case C_Code: + case Pass1: writeString("\n};\n\n"); + break; + case Python_Code: + writeString("\"\n\n"); + break; + default: + break; + } return true; } -static bool qt_rcc_compare_hash(const RCCFileInfo *left, const RCCFileInfo *right) +struct qt_rcc_compare_hash { - return qt_hash(left->m_name) < qt_hash(right->m_name); -} + typedef bool result_type; + result_type operator()(const RCCFileInfo *left, const RCCFileInfo *right) const + { + return qt_hash(left->m_name) < qt_hash(right->m_name); + } +}; bool RCCResourceLibrary::writeDataStructure() { - if (m_format == C_Code) + switch (m_format) { + case C_Code: + case Pass1: writeString("static const unsigned char qt_resource_struct[] = {\n"); - else if (m_format == Binary) + break; + case Python_Code: + writeString("qt_resource_struct = b\"\\\n"); + break; + case Binary: m_treeOffset = m_out.size(); + break; + default: + break; + } + QStack<RCCFileInfo*> pending; if (!m_root) @@ -894,11 +1276,12 @@ bool RCCResourceLibrary::writeDataStructure() file->m_childOffset = offset; //sort by hash value for binary lookup - auto children = file->m_children.values(); - std::sort(children.begin(), children.end(), qt_rcc_compare_hash); + QList<RCCFileInfo*> m_children = file->m_children.values(); + std::sort(m_children.begin(), m_children.end(), qt_rcc_compare_hash()); //write out the actual data now - for (RCCFileInfo *child : children) { + for (int i = 0; i < m_children.size(); ++i) { + RCCFileInfo *child = m_children.at(i); ++offset; if (child->m_flags & RCCFileInfo::Directory) pending.push(child); @@ -912,18 +1295,28 @@ bool RCCResourceLibrary::writeDataStructure() RCCFileInfo *file = pending.pop(); //sort by hash value for binary lookup - auto children = file->m_children.values(); - std::sort(children.begin(), children.end(), qt_rcc_compare_hash); + QList<RCCFileInfo*> m_children = file->m_children.values(); + std::sort(m_children.begin(), m_children.end(), qt_rcc_compare_hash()); //write out the actual data now - for (RCCFileInfo *child : children) { + for (int i = 0; i < m_children.size(); ++i) { + RCCFileInfo *child = m_children.at(i); child->writeDataInfo(*this); if (child->m_flags & RCCFileInfo::Directory) pending.push(child); } } - if (m_format == C_Code) + switch (m_format) { + case C_Code: + case Pass1: writeString("\n};\n\n"); + break; + case Python_Code: + writeString("\"\n\n"); + break; + default: + break; + } return true; } @@ -931,7 +1324,7 @@ bool RCCResourceLibrary::writeDataStructure() void RCCResourceLibrary::writeMangleNamespaceFunction(const QByteArray &name) { if (m_useNameSpace) { - writeString("QT_MANGLE_NAMESPACE("); + writeString("QT_RCC_MANGLE_NAMESPACE("); writeByteArray(name); writeChar(')'); } else { @@ -942,7 +1335,7 @@ void RCCResourceLibrary::writeMangleNamespaceFunction(const QByteArray &name) void RCCResourceLibrary::writeAddNamespaceFunction(const QByteArray &name) { if (m_useNameSpace) { - writeString("QT_PREPEND_NAMESPACE("); + writeString("QT_RCC_PREPEND_NAMESPACE("); writeByteArray(name); writeChar(')'); } else { @@ -950,82 +1343,173 @@ void RCCResourceLibrary::writeAddNamespaceFunction(const QByteArray &name) } } -static bool unacceptableChar(QChar qc) -{ - if (qc.isDigit()) - return false; - if (!qc.isLetter()) - return true; - auto c = qc.toLower().toLatin1(); - return c < 'a' || c > 'z'; -} - bool RCCResourceLibrary::writeInitializer() { - if (m_format == C_Code) { + if (m_format == C_Code || m_format == Pass1) { //write("\nQT_BEGIN_NAMESPACE\n"); - QString initName = m_initName; - if (!initName.isEmpty()) { - initName.prepend(QLatin1Char('_')); - std::replace_if(initName.begin(), initName.end(), - unacceptableChar, QLatin1Char('_')); + QString initNameStr = m_initName; + if (!initNameStr.isEmpty()) { + initNameStr.prepend(u'_'); + auto isAsciiLetterOrNumber = [] (QChar c) -> bool { + ushort ch = c.unicode(); + return (ch >= '0' && ch <= '9') || + (ch >= 'A' && ch <= 'Z') || + (ch >= 'a' && ch <= 'z') || + ch == '_'; + }; + for (QChar &c : initNameStr) { + if (!isAsciiLetterOrNumber(c)) + c = u'_'; + } } + QByteArray initName = initNameStr.toLatin1(); //init - if (m_useNameSpace) - writeString("QT_BEGIN_NAMESPACE\n\n"); + if (m_useNameSpace) { + writeString("#ifdef QT_NAMESPACE\n" + "# define QT_RCC_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name\n" + "# define QT_RCC_MANGLE_NAMESPACE0(x) x\n" + "# define QT_RCC_MANGLE_NAMESPACE1(a, b) a##_##b\n" + "# define QT_RCC_MANGLE_NAMESPACE2(a, b) QT_RCC_MANGLE_NAMESPACE1(a,b)\n" + "# define QT_RCC_MANGLE_NAMESPACE(name) QT_RCC_MANGLE_NAMESPACE2( \\\n" + " QT_RCC_MANGLE_NAMESPACE0(name), QT_RCC_MANGLE_NAMESPACE0(QT_NAMESPACE))\n" + "#else\n" + "# define QT_RCC_PREPEND_NAMESPACE(name) name\n" + "# define QT_RCC_MANGLE_NAMESPACE(name) name\n" + "#endif\n\n"); + + writeString("#ifdef QT_NAMESPACE\n" + "namespace QT_NAMESPACE {\n" + "#endif\n\n"); + } + if (m_root) { - writeString("extern Q_CORE_EXPORT bool qRegisterResourceData\n " + writeString("bool qRegisterResourceData" "(int, const unsigned char *, " - "const unsigned char *, const unsigned char *);\n\n"); - writeString("extern Q_CORE_EXPORT bool qUnregisterResourceData\n " + "const unsigned char *, const unsigned char *);\n"); + writeString("bool qUnregisterResourceData" "(int, const unsigned char *, " "const unsigned char *, const unsigned char *);\n\n"); + + if (m_overallFlags & (RCCFileInfo::Compressed | RCCFileInfo::CompressedZstd)) { + // use variable relocations with ELF and Mach-O + writeString("#if defined(__ELF__) || defined(__APPLE__)\n"); + if (m_overallFlags & RCCFileInfo::Compressed) { + writeString("static inline unsigned char qResourceFeatureZlib()\n" + "{\n" + " extern const unsigned char qt_resourceFeatureZlib;\n" + " return qt_resourceFeatureZlib;\n" + "}\n"); + } + if (m_overallFlags & RCCFileInfo::CompressedZstd) { + writeString("static inline unsigned char qResourceFeatureZstd()\n" + "{\n" + " extern const unsigned char qt_resourceFeatureZstd;\n" + " return qt_resourceFeatureZstd;\n" + "}\n"); + } + writeString("#else\n"); + if (m_overallFlags & RCCFileInfo::Compressed) + writeString("unsigned char qResourceFeatureZlib();\n"); + if (m_overallFlags & RCCFileInfo::CompressedZstd) + writeString("unsigned char qResourceFeatureZstd();\n"); + writeString("#endif\n\n"); + } } + if (m_useNameSpace) - writeString("QT_END_NAMESPACE\n\n\n"); - QString initResources = QLatin1String("qInitResources"); + writeString("#ifdef QT_NAMESPACE\n}\n#endif\n\n"); + + QByteArray initResources = "qInitResources"; initResources += initName; + + // Work around -Wmissing-declarations warnings. writeString("int "); - writeMangleNamespaceFunction(initResources.toLatin1()); + writeMangleNamespaceFunction(initResources); + writeString("();\n"); + + writeString("int "); + writeMangleNamespaceFunction(initResources); writeString("()\n{\n"); if (m_root) { - writeString(" "); + writeString(" int version = "); + writeDecimal(m_formatVersion); + writeString(";\n "); writeAddNamespaceFunction("qRegisterResourceData"); - writeString("\n (0x01, qt_resource_struct, " - "qt_resource_name, qt_resource_data);\n"); + writeString("\n (version, qt_resource_struct, " + "qt_resource_name, qt_resource_data);\n"); } writeString(" return 1;\n"); writeString("}\n\n"); - writeString("Q_CONSTRUCTOR_FUNCTION("); - writeMangleNamespaceFunction(initResources.toLatin1()); - writeString(")\n\n"); //cleanup - QString cleanResources = QLatin1String("qCleanupResources"); + QByteArray cleanResources = "qCleanupResources"; cleanResources += initName; + + // Work around -Wmissing-declarations warnings. writeString("int "); - writeMangleNamespaceFunction(cleanResources.toLatin1()); + writeMangleNamespaceFunction(cleanResources); + writeString("();\n"); + + writeString("int "); + writeMangleNamespaceFunction(cleanResources); writeString("()\n{\n"); if (m_root) { - writeString(" "); + writeString(" int version = "); + writeDecimal(m_formatVersion); + writeString(";\n "); + + // ODR-use certain symbols from QtCore if we require optional features + if (m_overallFlags & RCCFileInfo::Compressed) { + writeString("version += "); + writeAddNamespaceFunction("qResourceFeatureZlib()"); + writeString(";\n "); + } + if (m_overallFlags & RCCFileInfo::CompressedZstd) { + writeString("version += "); + writeAddNamespaceFunction("qResourceFeatureZstd()"); + writeString(";\n "); + } + writeAddNamespaceFunction("qUnregisterResourceData"); - writeString("\n (0x01, qt_resource_struct, " + writeString("\n (version, qt_resource_struct, " "qt_resource_name, qt_resource_data);\n"); } writeString(" return 1;\n"); writeString("}\n\n"); - writeString("Q_DESTRUCTOR_FUNCTION("); - writeMangleNamespaceFunction(cleanResources.toLatin1()); - writeString(")\n\n"); + + // -Wexit-time-destructors was added to clang 3.0.0 in 2011. + writeString("#ifdef __clang__\n" + "# pragma clang diagnostic push\n" + "# pragma clang diagnostic ignored \"-Wexit-time-destructors\"\n" + "#endif\n\n"); + + writeString("namespace {\n" + " struct initializer {\n"); + + if (m_useNameSpace) { + writeByteArray(" initializer() { QT_RCC_MANGLE_NAMESPACE(" + initResources + ")(); }\n" + " ~initializer() { QT_RCC_MANGLE_NAMESPACE(" + cleanResources + ")(); }\n"); + } else { + writeByteArray(" initializer() { " + initResources + "(); }\n" + " ~initializer() { " + cleanResources + "(); }\n"); + } + writeString(" } dummy;\n" + "}\n\n"); + + writeString("#ifdef __clang__\n" + "# pragma clang diagnostic pop\n" + "#endif\n"); + + } else if (m_format == Binary) { int i = 4; char *p = m_out.data(); - p[i++] = 0; // 0x01 p[i++] = 0; p[i++] = 0; - p[i++] = 1; + p[i++] = 0; + p[i++] = m_formatVersion; p[i++] = (m_treeOffset >> 24) & 0xff; p[i++] = (m_treeOffset >> 16) & 0xff; @@ -1041,6 +1525,23 @@ bool RCCResourceLibrary::writeInitializer() p[i++] = (m_namesOffset >> 16) & 0xff; p[i++] = (m_namesOffset >> 8) & 0xff; p[i++] = (m_namesOffset >> 0) & 0xff; + + if (m_formatVersion >= 3) { + p[i++] = (m_overallFlags >> 24) & 0xff; + p[i++] = (m_overallFlags >> 16) & 0xff; + p[i++] = (m_overallFlags >> 8) & 0xff; + p[i++] = (m_overallFlags >> 0) & 0xff; + } + } else if (m_format == Python_Code) { + writeString("def qInitResources():\n"); + writeString(" QtCore.qRegisterResourceData(0x"); + write2HexDigits(m_formatVersion); + writeString(", qt_resource_struct, qt_resource_name, qt_resource_data)\n\n"); + writeString("def qCleanupResources():\n"); + writeString(" QtCore.qUnregisterResourceData(0x"); + write2HexDigits(m_formatVersion); + writeString(", qt_resource_struct, qt_resource_name, qt_resource_data)\n\n"); + writeString("qInitResources()\n"); } return true; } diff --git a/src/designer/src/lib/shared/rcc_p.h b/src/designer/src/lib/shared/rcc_p.h index bd7e1c44c..82d17c875 100644 --- a/src/designer/src/lib/shared/rcc_p.h +++ b/src/designer/src/lib/shared/rcc_p.h @@ -1,30 +1,6 @@ -/**************************************************************************** -** -** 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) 2018 The Qt Company Ltd. +// Copyright (C) 2018 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // // W A R N I N G @@ -40,9 +16,11 @@ #ifndef RCC_H #define RCC_H -#include <QtCore/qstringlist.h> -#include <QtCore/qhash.h> -#include <QtCore/qstring.h> +#include <qstringlist.h> +#include <qhash.h> +#include <qstring.h> + +typedef struct ZSTD_CCtx_s ZSTD_CCtx; QT_BEGIN_NAMESPACE @@ -57,14 +35,14 @@ class RCCResourceLibrary RCCResourceLibrary &operator=(const RCCResourceLibrary &); public: - RCCResourceLibrary(); + RCCResourceLibrary(quint8 formatVersion); ~RCCResourceLibrary(); - bool output(QIODevice &out, QIODevice &errorDevice); + bool output(QIODevice &outDevice, QIODevice &tempDevice, QIODevice &errorDevice); - bool readFiles(bool ignoreErrors, QIODevice &errorDevice); + bool readFiles(bool listMode, QIODevice &errorDevice); - enum Format { Binary, C_Code }; + enum Format { Binary, C_Code, Pass1, Pass2, Python_Code }; void setFormat(Format f) { m_format = f; } Format format() const { return m_format; } @@ -83,6 +61,22 @@ public: void setInitName(const QString &name) { m_initName = name; } QString initName() const { return m_initName; } + void setOutputName(const QString &name) { m_outputName = name; } + QString outputName() const { return m_outputName; } + + enum class CompressionAlgorithm { + Zlib, + Zstd, + + Best = 99, + None = -1 + }; + + static CompressionAlgorithm parseCompressionAlgorithm(QStringView algo, QString *errorMsg); + void setCompressionAlgorithm(CompressionAlgorithm algo) { m_compressionAlgo = algo; } + CompressionAlgorithm compressionAlgorithm() const { return m_compressionAlgo; } + + static int parseCompressionLevel(CompressionAlgorithm algo, const QString &level, QString *errorMsg); void setCompressLevel(int c) { m_compressLevel = c; } int compressLevel() const { return m_compressLevel; } @@ -97,6 +91,11 @@ public: QStringList failedResources() const { return m_failedResources; } + int formatVersion() const { return m_formatVersion; } + + void setNoZstd(bool v) { m_noZstd = v; } + bool noZstd() const { return m_noZstd; } + private: struct Strings { Strings(); @@ -106,14 +105,16 @@ private: const QString ATTRIBUTE_LANG; const QString ATTRIBUTE_PREFIX; const QString ATTRIBUTE_ALIAS; + const QString ATTRIBUTE_EMPTY; const QString ATTRIBUTE_THRESHOLD; const QString ATTRIBUTE_COMPRESS; + const QString ATTRIBUTE_COMPRESSALGO; }; friend class RCCFileInfo; void reset(); - bool addFile(const QString &alias, const RCCFileInfo &file); + bool addFile(const QString &alias, RCCFileInfo file); bool interpretResourceFile(QIODevice *inputDevice, const QString &file, - QString currentPath = QString(), bool ignoreErrors = false); + QString currentPath = QString(), bool listMode = false); bool writeHeader(); bool writeDataBlobs(); bool writeDataNames(); @@ -121,29 +122,43 @@ private: bool writeInitializer(); void writeMangleNamespaceFunction(const QByteArray &name); void writeAddNamespaceFunction(const QByteArray &name); + void writeDecimal(int value); void writeHex(quint8 number); + void write2HexDigits(quint8 number); void writeNumber2(quint16 number); void writeNumber4(quint32 number); + void writeNumber8(quint64 number); void writeChar(char c) { m_out.append(c); } void writeByteArray(const QByteArray &); void write(const char *, int len); + void writeString(const char *s) { write(s, static_cast<int>(strlen(s))); } + +#if QT_CONFIG(zstd) + ZSTD_CCtx *m_zstdCCtx; +#endif const Strings m_strings; RCCFileInfo *m_root; QStringList m_fileNames; QString m_resourceRoot; QString m_initName; + QString m_outputName; Format m_format; bool m_verbose; + CompressionAlgorithm m_compressionAlgo; int m_compressLevel; int m_compressThreshold; int m_treeOffset; int m_namesOffset; int m_dataOffset; + quint32 m_overallFlags; bool m_useNameSpace; QStringList m_failedResources; QIODevice *m_errorDevice; + QIODevice *m_outDevice; QByteArray m_out; + quint8 m_formatVersion; + bool m_noZstd; }; QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/richtexteditor.cpp b/src/designer/src/lib/shared/richtexteditor.cpp index 3818de6f7..e6b414149 100644 --- a/src/designer/src/lib/shared/richtexteditor.cpp +++ b/src/designer/src/lib/shared/richtexteditor.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 "richtexteditor_p.h" #include "htmlhighlighter_p.h" @@ -61,11 +36,15 @@ #include <QtCore/qpointer.h> #include <QtCore/qxmlstream.h> +#include <algorithm> + QT_BEGIN_NAMESPACE -static const char RichTextDialogGroupC[] = "RichTextDialog"; -static const char GeometryKeyC[] = "Geometry"; -static const char TabKeyC[] = "Tab"; +using namespace Qt::StringLiterals; + +static constexpr auto RichTextDialogGroupC = "RichTextDialog"_L1; +static constexpr auto GeometryKeyC = "Geometry"_L1; +static constexpr auto TabKeyC = "Tab"_L1; const bool simplifyRichTextDefault = true; @@ -74,7 +53,7 @@ namespace qdesigner_internal { // Richtext simplification filter helpers: Elements to be discarded static inline bool filterElement(QStringView name) { - return name != QStringLiteral("meta") && name != QStringLiteral("style"); + return name != "meta"_L1 && name != "style"_L1; } // Richtext simplification filter helpers: Filter attributes of elements @@ -86,15 +65,15 @@ static inline void filterAttributes(QStringView name, return; // No style attributes for <body> - if (name == QStringLiteral("body")) { + if (name == "body"_L1) { atts->clear(); return; } // Clean out everything except 'align' for 'p' - if (name == QStringLiteral("p")) { + if (name == "p"_L1) { for (auto it = atts->begin(); it != atts->end(); ) { - if (it->name() == QStringLiteral("align")) { + if (it->name() == "align"_L1) { ++it; *paragraphAlignmentFound = true; } else { @@ -108,11 +87,8 @@ static inline void filterAttributes(QStringView name, // Richtext simplification filter helpers: Check for blank QStringView. static inline bool isWhiteSpace(QStringView in) { - const int count = in.size(); - for (int i = 0; i < count; i++) - if (!in.at(i).isSpace()) - return false; - return true; + return std::all_of(in.cbegin(), in.cend(), + [](QChar c) { return c.isSpace(); }); } // Richtext simplification filter: Remove hard-coded font settings, @@ -169,6 +145,8 @@ public: QToolBar *createToolBar(QDesignerFormEditorInterface *core, QWidget *parent = nullptr); + QString text(Qt::TextFormat format) const; + bool simplifyRichText() const { return m_simplifyRichText; } public slots: @@ -176,7 +154,6 @@ public slots: void setFontPointSize(double); void setText(const QString &text); void setSimplifyRichText(bool v); - QString text(Qt::TextFormat format) const; signals: void stateChanged(); @@ -201,17 +178,15 @@ public slots: private: RichTextEditor *m_editor; - Ui::AddLinkDialog *m_ui; + QT_PREPEND_NAMESPACE(Ui)::AddLinkDialog *m_ui; }; AddLinkDialog::AddLinkDialog(RichTextEditor *editor, QWidget *parent) : QDialog(parent), - m_ui(new Ui::AddLinkDialog) + m_ui(new QT_PREPEND_NAMESPACE(Ui)::AddLinkDialog) { m_ui->setupUi(this); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - m_editor = editor; } @@ -240,12 +215,7 @@ void AddLinkDialog::accept() const QString url = m_ui->urlInput->text(); if (!title.isEmpty()) { - QString html = QStringLiteral("<a href=\""); - html += url; - html += QStringLiteral("\">"); - html += title; - html += QStringLiteral("</a>"); - + const QString html = "<a href=\""_L1 + url + "\">"_L1 + title + "</a>"_L1; m_editor->insertHtml(html); } @@ -290,9 +260,9 @@ void HtmlTextEdit::contextMenuEvent(QContextMenuEvent *event) }; for (const Entry &e : entries) { - QAction *entityAction = new QAction(QLatin1String(e.text), + QAction *entityAction = new QAction(QLatin1StringView(e.text), htmlMenu); - entityAction->setData(QLatin1String(e.entity)); + entityAction->setData(QLatin1StringView(e.entity)); htmlMenu->addAction(entityAction); } @@ -401,7 +371,6 @@ private: }; static QAction *createCheckableAction(const QIcon &icon, const QString &text, - QObject *receiver, const char *slot, QObject *parent = nullptr) { QAction *result = new QAction(parent); @@ -409,8 +378,6 @@ static QAction *createCheckableAction(const QIcon &icon, const QString &text, result->setText(text); result->setCheckable(true); result->setChecked(false); - if (slot) - QObject::connect(result, SIGNAL(triggered(bool)), receiver, slot); return result; } @@ -440,20 +407,23 @@ RichTextEditorToolBar::RichTextEditorToolBar(QDesignerFormEditorInterface *core, // Bold, italic and underline buttons m_bold_action = createCheckableAction( - createIconSet(QStringLiteral("textbold.png")), - tr("Bold"), editor, SLOT(setFontBold(bool)), this); + createIconSet(QIcon::ThemeIcon::FormatTextBold, + "textbold.png"_L1), tr("Bold"), this); + connect(m_bold_action, &QAction::triggered, editor, &RichTextEditor::setFontBold); m_bold_action->setShortcut(tr("CTRL+B")); addAction(m_bold_action); m_italic_action = createCheckableAction( - createIconSet(QStringLiteral("textitalic.png")), - tr("Italic"), editor, SLOT(setFontItalic(bool)), this); + createIconSet(QIcon::ThemeIcon::FormatTextItalic, + "textitalic.png"_L1), tr("Italic"), this); + connect(m_italic_action, &QAction::triggered, editor, &RichTextEditor::setFontItalic); m_italic_action->setShortcut(tr("CTRL+I")); addAction(m_italic_action); m_underline_action = createCheckableAction( - createIconSet(QStringLiteral("textunder.png")), - tr("Underline"), editor, SLOT(setFontUnderline(bool)), this); + createIconSet(QIcon::ThemeIcon::FormatTextUnderline, + "textunder.png"_L1), tr("Underline"), this); + connect(m_underline_action, &QAction::triggered, editor, &RichTextEditor::setFontUnderline); m_underline_action->setShortcut(tr("CTRL+U")); addAction(m_underline_action); @@ -466,28 +436,30 @@ RichTextEditorToolBar::RichTextEditorToolBar(QDesignerFormEditorInterface *core, this, &RichTextEditorToolBar::alignmentActionTriggered); m_align_left_action = createCheckableAction( - createIconSet(QStringLiteral("textleft.png")), - tr("Left Align"), editor, nullptr, alignment_group); + createIconSet(QIcon::ThemeIcon::FormatJustifyLeft, + "textleft.png"_L1), tr("Left Align"), alignment_group); addAction(m_align_left_action); m_align_center_action = createCheckableAction( - createIconSet(QStringLiteral("textcenter.png")), - tr("Center"), editor, nullptr, alignment_group); + createIconSet(QIcon::ThemeIcon::FormatJustifyCenter, + "textcenter.png"_L1), tr("Center"), alignment_group); addAction(m_align_center_action); m_align_right_action = createCheckableAction( - createIconSet(QStringLiteral("textright.png")), - tr("Right Align"), editor, nullptr, alignment_group); + createIconSet(QIcon::ThemeIcon::FormatJustifyRight, + "textright.png"_L1), tr("Right Align"), alignment_group); addAction(m_align_right_action); m_align_justify_action = createCheckableAction( - createIconSet(QStringLiteral("textjustify.png")), - tr("Justify"), editor, nullptr, alignment_group); + createIconSet(QIcon::ThemeIcon::FormatJustifyFill, + "textjustify.png"_L1), tr("Justify"), alignment_group); addAction(m_align_justify_action); m_layoutDirectionAction = createCheckableAction( - createIconSet(QStringLiteral("righttoleft.png")), - tr("Right to Left"), this, SLOT(layoutDirectionChanged())); + createIconSet(QIcon::ThemeIcon::FormatTextDirectionRtl, + "righttoleft.png"_L1), tr("Right to Left")); + connect(m_layoutDirectionAction, &QAction::triggered, + this, &RichTextEditorToolBar::layoutDirectionChanged); addAction(m_layoutDirectionAction); addSeparator(); @@ -495,27 +467,27 @@ RichTextEditorToolBar::RichTextEditorToolBar(QDesignerFormEditorInterface *core, // Superscript and subscript buttons m_valign_sup_action = createCheckableAction( - createIconSet(QStringLiteral("textsuperscript.png")), - tr("Superscript"), - this, SLOT(setVAlignSuper(bool)), this); + createIconSet("textsuperscript.png"_L1), tr("Superscript"), this); + connect(m_valign_sup_action, &QAction::triggered, + this, &RichTextEditorToolBar::setVAlignSuper); addAction(m_valign_sup_action); m_valign_sub_action = createCheckableAction( - createIconSet(QStringLiteral("textsubscript.png")), - tr("Subscript"), - this, SLOT(setVAlignSub(bool)), this); + createIconSet("textsubscript.png"_L1), tr("Subscript"), this); + connect(m_valign_sub_action, &QAction::triggered, + this, &RichTextEditorToolBar::setVAlignSub); addAction(m_valign_sub_action); addSeparator(); // Insert hyperlink and image buttons - m_link_action->setIcon(createIconSet(QStringLiteral("textanchor.png"))); + m_link_action->setIcon(createIconSet("textanchor.png"_L1)); m_link_action->setText(tr("Insert &Link")); connect(m_link_action, &QAction::triggered, this, &RichTextEditorToolBar::insertLink); addAction(m_link_action); - m_image_action->setIcon(createIconSet(QStringLiteral("insertimage.png"))); + m_image_action->setIcon(createIconSet("insertimage.png"_L1)); m_image_action->setText(tr("Insert &Image")); connect(m_image_action, &QAction::triggered, this, &RichTextEditorToolBar::insertImage); addAction(m_image_action); @@ -531,8 +503,9 @@ RichTextEditorToolBar::RichTextEditorToolBar(QDesignerFormEditorInterface *core, // Simplify rich text m_simplify_richtext_action - = createCheckableAction(createIconSet(QStringLiteral("simplifyrichtext.png")), - tr("Simplify Rich Text"), m_editor, SLOT(setSimplifyRichText(bool))); + = createCheckableAction(createIconSet("simplifyrichtext.png"_L1), tr("Simplify Rich Text")); + connect(m_simplify_richtext_action, &QAction::triggered, + m_editor, &RichTextEditor::setSimplifyRichText); m_simplify_richtext_action->setChecked(m_editor->simplifyRichText()); connect(m_editor.data(), &RichTextEditor::simplifyRichTextChanged, m_simplify_richtext_action, &QAction::setChecked); @@ -761,13 +734,12 @@ RichTextEditorDialog::RichTextEditorDialog(QDesignerFormEditorInterface *core, Q m_initialTab(RichTextIndex) { setWindowTitle(tr("Edit text")); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); // Read settings const QDesignerSettingsInterface *settings = core->settingsManager(); - const QString rootKey = QLatin1String(RichTextDialogGroupC) + QLatin1Char('/'); - const QByteArray lastGeometry = settings->value(rootKey + QLatin1String(GeometryKeyC)).toByteArray(); - const int initialTab = settings->value(rootKey + QLatin1String(TabKeyC), QVariant(m_initialTab)).toInt(); + const QString rootKey = RichTextDialogGroupC + u'/'; + const QByteArray lastGeometry = settings->value(rootKey + GeometryKeyC).toByteArray(); + const int initialTab = settings->value(rootKey + TabKeyC, QVariant(m_initialTab)).toInt(); if (initialTab == RichTextIndex || initialTab == SourceIndex) m_initialTab = initialTab; @@ -817,10 +789,10 @@ RichTextEditorDialog::RichTextEditorDialog(QDesignerFormEditorInterface *core, Q RichTextEditorDialog::~RichTextEditorDialog() { QDesignerSettingsInterface *settings = m_core->settingsManager(); - settings->beginGroup(QLatin1String(RichTextDialogGroupC)); + settings->beginGroup(RichTextDialogGroupC); - settings->setValue(QLatin1String(GeometryKeyC), saveGeometry()); - settings->setValue(QLatin1String(TabKeyC), m_tab_widget->currentIndex()); + settings->setValue(GeometryKeyC, saveGeometry()); + settings->setValue(TabKeyC, m_tab_widget->currentIndex()); settings->endGroup(); } diff --git a/src/designer/src/lib/shared/richtexteditor_p.h b/src/designer/src/lib/shared/richtexteditor_p.h index 4fc166e3c..18a710a5c 100644 --- a/src/designer/src/lib/shared/richtexteditor_p.h +++ b/src/designer/src/lib/shared/richtexteditor_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/selectsignaldialog.cpp b/src/designer/src/lib/shared/selectsignaldialog.cpp index 576dd0bdb..1938046f4 100644 --- a/src/designer/src/lib/shared/selectsignaldialog.cpp +++ b/src/designer/src/lib/shared/selectsignaldialog.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "selectsignaldialog_p.h" @@ -59,10 +34,9 @@ using Methods = QList<SelectSignalDialog::Method>; SelectSignalDialog::SelectSignalDialog(QWidget *parent) : QDialog(parent) - , m_ui(new Ui::SelectSignalDialog) + , m_ui(new QT_PREPEND_NAMESPACE(Ui)::SelectSignalDialog) , m_model(new QStandardItemModel(0, 1, this)) { - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); m_ui->setupUi(this); m_okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok); @@ -116,7 +90,7 @@ static void appendClass(const QString &className, Methods methods, QStandardItem std::sort(methods.begin(), methods.end(), signatureLessThan); QStandardItem *topLevelItem = createTopLevelItem(className); model->appendRow(topLevelItem); - for (const SelectSignalDialog::Method &m : qAsConst(methods)) { + for (const SelectSignalDialog::Method &m : std::as_const(methods)) { QStandardItem *item = new QStandardItem(m.signature); item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); item->setData(QVariant::fromValue(m), MethodRole); diff --git a/src/designer/src/lib/shared/selectsignaldialog_p.h b/src/designer/src/lib/shared/selectsignaldialog_p.h index ab94fb1ec..01f4afe25 100644 --- a/src/designer/src/lib/shared/selectsignaldialog_p.h +++ b/src/designer/src/lib/shared/selectsignaldialog_p.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // // W A R N I N G @@ -84,7 +59,7 @@ private: Method methodFromIndex(const QModelIndex &) const; void populateModel(QDesignerFormEditorInterface *core, QObject *object); - Ui::SelectSignalDialog *m_ui; + QT_PREPEND_NAMESPACE(Ui)::SelectSignalDialog *m_ui; QPushButton *m_okButton; QStandardItemModel *m_model; }; diff --git a/src/designer/src/lib/shared/shared.qrc b/src/designer/src/lib/shared/shared.qrc deleted file mode 100644 index 734ef391f..000000000 --- a/src/designer/src/lib/shared/shared.qrc +++ /dev/null @@ -1,20 +0,0 @@ -<RCC> - <qresource prefix="/qt-project.org/designer"> - <file>defaultgradients.xml</file> - <!-- Templates --> - <file>templates/forms/Dialog_with_Buttons_Bottom.ui</file> - <file>templates/forms/240x320/Dialog_with_Buttons_Bottom.ui</file> - <file>templates/forms/320x240/Dialog_with_Buttons_Bottom.ui</file> - <file>templates/forms/480x640/Dialog_with_Buttons_Bottom.ui</file> - <file>templates/forms/640x480/Dialog_with_Buttons_Bottom.ui</file> - <file>templates/forms/Dialog_with_Buttons_Right.ui</file> - <file>templates/forms/240x320/Dialog_with_Buttons_Right.ui</file> - <file>templates/forms/320x240/Dialog_with_Buttons_Right.ui</file> - <file>templates/forms/480x640/Dialog_with_Buttons_Right.ui</file> - <file>templates/forms/640x480/Dialog_with_Buttons_Right.ui</file> - <file>templates/forms/Dialog_without_Buttons.ui</file> - <file>templates/forms/Widget.ui</file> - <file>templates/forms/Main_Window.ui</file> - </qresource> -</RCC> - diff --git a/src/designer/src/lib/shared/shared_enums_p.h b/src/designer/src/lib/shared/shared_enums_p.h index d9c3dc007..246f202de 100644 --- a/src/designer/src/lib/shared/shared_enums_p.h +++ b/src/designer/src/lib/shared/shared_enums_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/shared_global_p.h b/src/designer/src/lib/shared/shared_global_p.h index 3609e5b87..0f1db097e 100644 --- a/src/designer/src/lib/shared/shared_global_p.h +++ b/src/designer/src/lib/shared/shared_global_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/shared_settings.cpp b/src/designer/src/lib/shared/shared_settings.cpp index 6b91cff7a..aec4e59ca 100644 --- a/src/designer/src/lib/shared/shared_settings.cpp +++ b/src/designer/src/lib/shared/shared_settings.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 "shared_settings_p.h" #include "grid_p.h" @@ -44,22 +19,22 @@ QT_BEGIN_NAMESPACE -static const char *defaultGridKey = "defaultGrid"; -static const char *previewKey = "Preview"; -static const char *enabledKey = "Enabled"; -static const char *userDeviceSkinsKey= "UserDeviceSkins"; -static const char *zoomKey = "zoom"; -static const char *zoomEnabledKey = "zoomEnabled"; -static const char *deviceProfileIndexKey = "DeviceProfileIndex"; -static const char *deviceProfilesKey = "DeviceProfiles"; -static const char *formTemplatePathsKey = "FormTemplatePaths"; -static const char *formTemplateKey = "FormTemplate"; -static const char *newFormSizeKey = "NewFormSize"; -static inline QString namingModeKey() { return QStringLiteral("naming"); } -static inline QString underScoreNamingMode() { return QStringLiteral("underscore"); } -static inline QString camelCaseNamingMode() { return QStringLiteral("camelcase"); } - -using namespace qdesigner_internal; +using namespace Qt::StringLiterals; + +static constexpr auto defaultGridKey = "defaultGrid"_L1; +static constexpr auto previewKey = "Preview"_L1; +static constexpr auto enabledKey = "Enabled"_L1; +static constexpr auto userDeviceSkinsKey= "UserDeviceSkins"_L1; +static constexpr auto zoomKey = "zoom"_L1; +static constexpr auto zoomEnabledKey = "zoomEnabled"_L1; +static constexpr auto deviceProfileIndexKey = "DeviceProfileIndex"_L1; +static constexpr auto deviceProfilesKey = "DeviceProfiles"_L1; +static constexpr auto formTemplatePathsKey = "FormTemplatePaths"_L1; +static constexpr auto formTemplateKey = "FormTemplate"_L1; +static constexpr auto newFormSizeKey = "NewFormSize"_L1; +static constexpr auto namingModeKey = "naming"_L1; +static constexpr auto underScoreNamingMode = "underscore"_L1; +static constexpr auto camelCaseNamingMode = "camelcase"_L1; static bool checkTemplatePath(const QString &path, bool create) { @@ -88,7 +63,7 @@ Grid QDesignerSharedSettings::defaultGrid() const { Grid grid; const QVariantMap defaultGridMap - = m_settings->value(QLatin1String(defaultGridKey), QVariantMap()).toMap(); + = m_settings->value(defaultGridKey, QVariantMap()).toMap(); if (!defaultGridMap.isEmpty()) grid.fromVariantMap(defaultGridMap); return grid; @@ -96,7 +71,7 @@ Grid QDesignerSharedSettings::defaultGrid() const void QDesignerSharedSettings::setDefaultGrid(const Grid &grid) { - m_settings->setValue(QLatin1String(defaultGridKey), grid.toVariantMap()); + m_settings->setValue(defaultGridKey, grid.toVariantMap()); } const QStringList &QDesignerSharedSettings::defaultFormTemplatePaths() @@ -104,7 +79,7 @@ const QStringList &QDesignerSharedSettings::defaultFormTemplatePaths() static QStringList rc; if (rc.isEmpty()) { // Ensure default form template paths - const QString templatePath = QStringLiteral("/templates"); + const auto templatePath = "/templates"_L1; // home QString path = dataDirectory() + templatePath; if (checkTemplatePath(path, true)) @@ -123,7 +98,7 @@ const QStringList &QDesignerSharedSettings::defaultFormTemplatePaths() // ### FIXME Qt 8: Remove (QTBUG-96005) void QDesignerSharedSettings::migrateTemplates() { - const QString templatePath = u"/templates"_qs; + const QString templatePath = u"/templates"_s; QString path = dataDirectory() + templatePath; if (QFileInfo::exists(path)) return; @@ -141,23 +116,23 @@ void QDesignerSharedSettings::migrateTemplates() QStringList QDesignerSharedSettings::formTemplatePaths() const { - return m_settings->value(QLatin1String(formTemplatePathsKey), + return m_settings->value(formTemplatePathsKey, defaultFormTemplatePaths()).toStringList(); } void QDesignerSharedSettings::setFormTemplatePaths(const QStringList &paths) { - m_settings->setValue(QLatin1String(formTemplatePathsKey), paths); + m_settings->setValue(formTemplatePathsKey, paths); } QString QDesignerSharedSettings::formTemplate() const { - return m_settings->value(QLatin1String(formTemplateKey)).toString(); + return m_settings->value(formTemplateKey).toString(); } void QDesignerSharedSettings::setFormTemplate(const QString &t) { - m_settings->setValue(QLatin1String(formTemplateKey), t); + m_settings->setValue(formTemplateKey, t); } void QDesignerSharedSettings::setAdditionalFormTemplatePaths(const QStringList &additionalPaths) @@ -182,15 +157,15 @@ QStringList QDesignerSharedSettings::additionalFormTemplatePaths() const QSize QDesignerSharedSettings::newFormSize() const { - return m_settings->value(QLatin1String(newFormSizeKey), QSize(0, 0)).toSize(); + return m_settings->value(newFormSizeKey, QSize(0, 0)).toSize(); } void QDesignerSharedSettings::setNewFormSize(const QSize &s) { if (s.isNull()) { - m_settings->remove(QLatin1String(newFormSizeKey)); + m_settings->remove(newFormSizeKey); } else { - m_settings->setValue(QLatin1String(newFormSizeKey), s); + m_settings->setValue(newFormSizeKey, s); } } @@ -198,78 +173,78 @@ void QDesignerSharedSettings::setNewFormSize(const QSize &s) PreviewConfiguration QDesignerSharedSettings::customPreviewConfiguration() const { PreviewConfiguration configuration; - configuration.fromSettings(QLatin1String(previewKey), m_settings); + configuration.fromSettings(previewKey, m_settings); return configuration; } void QDesignerSharedSettings::setCustomPreviewConfiguration(const PreviewConfiguration &configuration) { - configuration.toSettings(QLatin1String(previewKey), m_settings); + configuration.toSettings(previewKey, m_settings); } bool QDesignerSharedSettings::isCustomPreviewConfigurationEnabled() const { - m_settings->beginGroup(QLatin1String(previewKey)); - bool isEnabled = m_settings->value(QLatin1String(enabledKey), false).toBool(); + m_settings->beginGroup(previewKey); + bool isEnabled = m_settings->value(enabledKey, false).toBool(); m_settings->endGroup(); return isEnabled; } void QDesignerSharedSettings::setCustomPreviewConfigurationEnabled(bool enabled) { - m_settings->beginGroup(QLatin1String(previewKey)); - m_settings->setValue(QLatin1String(enabledKey), enabled); + m_settings->beginGroup(previewKey); + m_settings->setValue(enabledKey, enabled); m_settings->endGroup(); } QStringList QDesignerSharedSettings::userDeviceSkins() const { - m_settings->beginGroup(QLatin1String(previewKey)); + m_settings->beginGroup(previewKey); QStringList userDeviceSkins - = m_settings->value(QLatin1String(userDeviceSkinsKey), QStringList()).toStringList(); + = m_settings->value(userDeviceSkinsKey, QStringList()).toStringList(); m_settings->endGroup(); return userDeviceSkins; } void QDesignerSharedSettings::setUserDeviceSkins(const QStringList &userDeviceSkins) { - m_settings->beginGroup(QLatin1String(previewKey)); - m_settings->setValue(QLatin1String(userDeviceSkinsKey), userDeviceSkins); + m_settings->beginGroup(previewKey); + m_settings->setValue(userDeviceSkinsKey, userDeviceSkins); m_settings->endGroup(); } int QDesignerSharedSettings::zoom() const { - return m_settings->value(QLatin1String(zoomKey), 100).toInt(); + return m_settings->value(zoomKey, 100).toInt(); } void QDesignerSharedSettings::setZoom(int z) { - m_settings->setValue(QLatin1String(zoomKey), QVariant(z)); + m_settings->setValue(zoomKey, QVariant(z)); } ObjectNamingMode QDesignerSharedSettings::objectNamingMode() const { - const QString value = m_settings->value(namingModeKey()).toString(); - return value == camelCaseNamingMode() + const QString value = m_settings->value(namingModeKey).toString(); + return value == camelCaseNamingMode ? qdesigner_internal::CamelCase : qdesigner_internal::Underscore; } void QDesignerSharedSettings::setObjectNamingMode(ObjectNamingMode n) { const QString value = n == qdesigner_internal::CamelCase - ? camelCaseNamingMode() : underScoreNamingMode(); - m_settings->setValue(namingModeKey(), QVariant(value)); + ? camelCaseNamingMode : underScoreNamingMode; + m_settings->setValue(namingModeKey, QVariant(value)); } bool QDesignerSharedSettings::zoomEnabled() const { - return m_settings->value(QLatin1String(zoomEnabledKey), false).toBool(); + return m_settings->value(zoomEnabledKey, false).toBool(); } void QDesignerSharedSettings::setZoomEnabled(bool v) { - m_settings->setValue(QLatin1String(zoomEnabledKey), v); + m_settings->setValue(zoomEnabledKey, v); } DeviceProfile QDesignerSharedSettings::currentDeviceProfile() const @@ -279,12 +254,12 @@ DeviceProfile QDesignerSharedSettings::currentDeviceProfile() const void QDesignerSharedSettings::setCurrentDeviceProfileIndex(int i) { - m_settings->setValue(QLatin1String(deviceProfileIndexKey), i); + m_settings->setValue(deviceProfileIndexKey, i); } int QDesignerSharedSettings::currentDeviceProfileIndex() const { - return m_settings->value(QLatin1String(deviceProfileIndexKey), -1).toInt(); + return m_settings->value(deviceProfileIndexKey, -1).toInt(); } static inline QString msgWarnDeviceProfileXml(const QString &msg) @@ -310,7 +285,7 @@ DeviceProfile QDesignerSharedSettings::deviceProfileAt(int idx) const QStringList QDesignerSharedSettings::deviceProfileXml() const { - return m_settings->value(QLatin1String(deviceProfilesKey), QStringList()).toStringList(); + return m_settings->value(deviceProfilesKey, QStringList()).toStringList(); } QDesignerSharedSettings::DeviceProfileList QDesignerSharedSettings::deviceProfiles() const @@ -322,9 +297,8 @@ QDesignerSharedSettings::DeviceProfileList QDesignerSharedSettings::deviceProfil // De-serialize QString errorMessage; DeviceProfile dp; - const QStringList::const_iterator scend = xmls.constEnd(); - for (QStringList::const_iterator it = xmls.constBegin(); it != scend; ++it) { - if (dp.fromXml(*it, &errorMessage)) { + for (const auto &xml : xmls) { + if (dp.fromXml(xml, &errorMessage)) { rc.push_back(dp); } else { designerWarning(msgWarnDeviceProfileXml(errorMessage)); @@ -333,13 +307,12 @@ QDesignerSharedSettings::DeviceProfileList QDesignerSharedSettings::deviceProfil return rc; } -void QDesignerSharedSettings::setDeviceProfiles(const DeviceProfileList &dp) +void QDesignerSharedSettings::setDeviceProfiles(const DeviceProfileList &dpl) { QStringList l; - const DeviceProfileList::const_iterator dcend = dp.constEnd(); - for (DeviceProfileList::const_iterator it = dp.constBegin(); it != dcend; ++it) - l.push_back(it->toXml()); - m_settings->setValue(QLatin1String(deviceProfilesKey), l); + for (const auto &dp : dpl) + l.push_back(dp.toXml()); + m_settings->setValue(deviceProfilesKey, l); } } diff --git a/src/designer/src/lib/shared/shared_settings_p.h b/src/designer/src/lib/shared/shared_settings_p.h index 1427a7687..7cf5b4c85 100644 --- a/src/designer/src/lib/shared/shared_settings_p.h +++ b/src/designer/src/lib/shared/shared_settings_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/sheet_delegate.cpp b/src/designer/src/lib/shared/sheet_delegate.cpp index 31afad7f8..77a2a1b96 100644 --- a/src/designer/src/lib/shared/sheet_delegate.cpp +++ b/src/designer/src/lib/shared/sheet_delegate.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 "sheet_delegate_p.h" diff --git a/src/designer/src/lib/shared/sheet_delegate_p.h b/src/designer/src/lib/shared/sheet_delegate_p.h index f896643f0..c58ebc5c4 100644 --- a/src/designer/src/lib/shared/sheet_delegate_p.h +++ b/src/designer/src/lib/shared/sheet_delegate_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/signalslotdialog.cpp b/src/designer/src/lib/shared/signalslotdialog.cpp index 65297030d..f4857b416 100644 --- a/src/designer/src/lib/shared/signalslotdialog.cpp +++ b/src/designer/src/lib/shared/signalslotdialog.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 "signalslotdialog_p.h" #include "ui_signalslotdialog.h" @@ -53,19 +28,21 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // Regexp to match a function signature, arguments potentially // with namespace colons. -static const char *signatureRegExp = "^[\\w+_]+\\(([\\w+:]\\*?,?)*\\)$"; -static const char *methodNameRegExp = "^[\\w+_]+$"; +static constexpr auto signatureRegExp = "^[\\w+_]+\\(([\\w+:]\\*?,?)*\\)$"_L1; +static constexpr auto methodNameRegExp = "^[\\w+_]+$"_L1; -static QStandardItem *createEditableItem(const QString &text) +static QStandardItem *createEditableItem(const QString &text) { QStandardItem *rc = new QStandardItem(text); rc->setFlags(Qt::ItemIsEnabled|Qt::ItemIsEditable|Qt::ItemIsSelectable); return rc; } -static QStandardItem *createDisabledItem(const QString &text) +static QStandardItem *createDisabledItem(const QString &text) { QStandardItem *rc = new QStandardItem(text); Qt::ItemFlags flags = rc->flags(); @@ -73,48 +50,6 @@ static QStandardItem *createDisabledItem(const QString &text) return rc; } -static void fakeMethodsFromMetaDataBase(QDesignerFormEditorInterface *core, QObject *o, QStringList &slotList, QStringList &signalList) -{ - slotList.clear(); - signalList.clear(); - if (qdesigner_internal::MetaDataBase *metaDataBase = qobject_cast<qdesigner_internal::MetaDataBase *>(core->metaDataBase())) - if (const qdesigner_internal::MetaDataBaseItem *item = metaDataBase->metaDataBaseItem(o)) { - slotList = item->fakeSlots(); - signalList = item->fakeSignals(); - } -} - -static void fakeMethodsToMetaDataBase(QDesignerFormEditorInterface *core, QObject *o, const QStringList &slotList, const QStringList &signalList) -{ - if (qdesigner_internal::MetaDataBase *metaDataBase = qobject_cast<qdesigner_internal::MetaDataBase *>(core->metaDataBase())) { - qdesigner_internal::MetaDataBaseItem *item = metaDataBase->metaDataBaseItem(o); - Q_ASSERT(item); - item->setFakeSlots(slotList); - item->setFakeSignals(signalList); - } -} - -static void existingMethodsFromMemberSheet(QDesignerFormEditorInterface *core, - QObject *o, - QStringList &slotList, QStringList &signalList) -{ - slotList.clear(); - signalList.clear(); - - QDesignerMemberSheetExtension *msheet = qt_extension<QDesignerMemberSheetExtension*>(core->extensionManager(), o); - if (!msheet) - return; - - for (int i = 0, count = msheet->count(); i < count; ++i) - if (msheet->isVisible(i)) { - if (msheet->isSlot(i)) - slotList += msheet->signature(i); - else - if (msheet->isSignal(i)) - signalList += msheet->signature(i); - } -} - namespace { // Internal helper class: A Delegate that validates using RegExps and additionally checks // on closing (adds missing parentheses). @@ -131,8 +66,8 @@ namespace { SignatureDelegate::SignatureDelegate(QObject * parent) : QItemDelegate(parent), - m_signatureRegexp(QLatin1String(signatureRegExp)), - m_methodNameRegexp(QLatin1String(methodNameRegExp)) + m_signatureRegexp(signatureRegExp), + m_methodNameRegexp(methodNameRegExp) { Q_ASSERT(m_signatureRegexp.isValid()); Q_ASSERT(m_methodNameRegexp.isValid()); @@ -155,7 +90,7 @@ namespace { QString signature = le->text(); if (!m_signatureRegexp.match(signature).hasMatch()) { if (m_methodNameRegexp.match(signature).hasMatch()) { - signature += QStringLiteral("()"); + signature += "()"_L1; le->setText(signature); } else { return; @@ -175,9 +110,15 @@ namespace { const QStringList &newFakeSlots, const QStringList &newFakeSignals); void undo() override - { fakeMethodsToMetaDataBase(core(), m_object, m_oldFakeSlots, m_oldFakeSignals); } + { + qdesigner_internal::SignalSlotDialog::fakeMethodsToMetaDataBase(core(), m_object, + m_oldFakeSlots, m_oldFakeSignals); + } void redo() override - { fakeMethodsToMetaDataBase(core(), m_object, m_newFakeSlots, m_newFakeSignals); } + { + qdesigner_internal::SignalSlotDialog::fakeMethodsToMetaDataBase(core(), m_object, + m_newFakeSlots, m_newFakeSignals); + } private: QObject *m_object; @@ -266,12 +207,11 @@ void SignaturePanel::slotAdd() m_listView->selectionModel()->clearSelection(); // find unique name for (int i = 1; ; i++) { - QString newSlot = m_newPrefix; - newSlot += QString::number(i); // Always add number, Avoid setting 'slot' for first entry - newSlot += QLatin1Char('('); + // Always add number, Avoid setting 'slot' for first entry + QString newSlot = m_newPrefix + QString::number(i) + u'('; // check for function name independent of parameters if (m_model->findItems(newSlot, Qt::MatchStartsWith, 0).isEmpty()) { - newSlot += QLatin1Char(')'); + newSlot += u')'; QStandardItem * item = createEditableItem(newSlot); m_model->appendRow(item); const QModelIndex index = m_model->indexFromItem (item); @@ -298,8 +238,8 @@ void SignaturePanel::slotRemove() if (const int row = selectedIndexes.constFirst().row()) m_listView->setCurrentIndex (selectedIndexes.constFirst().sibling(row - 1, 0)); - for (int i = selectedIndexes.size() - 1; i >= 0; i--) - qDeleteAll(m_model->takeRow(selectedIndexes[i].row())); + for (auto i = selectedIndexes.size() - 1; i >= 0; --i) + qDeleteAll(m_model->takeRow(selectedIndexes.at(i).row())); } void SignaturePanel::slotSelectionChanged(const QItemSelection &selected, const QItemSelection &) @@ -346,21 +286,23 @@ void SignaturePanel::closeEditor() SignalSlotDialog::SignalSlotDialog(QDesignerDialogGuiInterface *dialogGui, QWidget *parent, FocusMode mode) : QDialog(parent), m_focusMode(mode), - m_ui(new Ui::SignalSlotDialogClass), + m_ui(new QT_PREPEND_NAMESPACE(Ui)::SignalSlotDialogClass), m_dialogGui(dialogGui) { setModal(true); m_ui->setupUi(this); - const QIcon plusIcon = qdesigner_internal::createIconSet(QString::fromUtf8("plus.png")); - const QIcon minusIcon = qdesigner_internal::createIconSet(QString::fromUtf8("minus.png")); + const QIcon plusIcon = qdesigner_internal::createIconSet("plus.png"_L1); + const QIcon minusIcon = qdesigner_internal::createIconSet("minus.png"_L1); m_ui->addSlotButton->setIcon(plusIcon); m_ui->removeSlotButton->setIcon(minusIcon); m_ui->addSignalButton->setIcon(plusIcon); m_ui->removeSignalButton->setIcon(minusIcon); - m_slotPanel = new SignaturePanel(this, m_ui->slotListView, m_ui->addSlotButton, m_ui->removeSlotButton, QStringLiteral("slot")); - m_signalPanel = new SignaturePanel(this, m_ui->signalListView, m_ui->addSignalButton, m_ui->removeSignalButton, QStringLiteral("signal")); + m_slotPanel = new SignaturePanel(this, m_ui->slotListView, m_ui->addSlotButton, + m_ui->removeSlotButton, u"slot"_s); + m_signalPanel = new SignaturePanel(this, m_ui->signalListView, m_ui->addSignalButton, + m_ui->removeSignalButton, u"signal"_s); connect(m_slotPanel, &SignaturePanel::checkSignature, this, &SignalSlotDialog::slotCheckSignature); connect(m_signalPanel, &SignaturePanel::checkSignature, @@ -512,6 +454,51 @@ bool SignalSlotDialog::editPromotedClass(QDesignerFormEditorInterface *core, con return true; } +void SignalSlotDialog::fakeMethodsFromMetaDataBase(QDesignerFormEditorInterface *core, QObject *o, + QStringList &slotList, QStringList &signalList) +{ + slotList.clear(); + signalList.clear(); + if (auto *metaDB = qobject_cast<qdesigner_internal::MetaDataBase *>(core->metaDataBase())) { + if (const auto *item = metaDB->metaDataBaseItem(o)) { + slotList = item->fakeSlots(); + signalList = item->fakeSignals(); + } + } +} + +void SignalSlotDialog::fakeMethodsToMetaDataBase(QDesignerFormEditorInterface *core, QObject *o, + const QStringList &slotList, + const QStringList &signalList) +{ + if (auto *metaDB = qobject_cast<qdesigner_internal::MetaDataBase *>(core->metaDataBase())) { + if (auto *item = metaDB->metaDataBaseItem(o)) { + item->setFakeSlots(slotList); + item->setFakeSignals(signalList); + } + } +} + +void SignalSlotDialog::existingMethodsFromMemberSheet(QDesignerFormEditorInterface *core, QObject *o, + QStringList &slotList, QStringList &signalList) +{ + slotList.clear(); + signalList.clear(); + + auto *msheet = qt_extension<QDesignerMemberSheetExtension*>(core->extensionManager(), o); + if (!msheet) + return; + + for (qsizetype i = 0, count = msheet->count(); i < count; ++i) { + if (msheet->isVisible(i)) { + if (msheet->isSlot(i)) + slotList += msheet->signature(i); + else if (msheet->isSignal(i)) + signalList += msheet->signature(i); + } + } +} + } QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/signalslotdialog_p.h b/src/designer/src/lib/shared/signalslotdialog_p.h index e0253bcc5..748123b9a 100644 --- a/src/designer/src/lib/shared/signalslotdialog_p.h +++ b/src/designer/src/lib/shared/signalslotdialog_p.h @@ -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 // // W A R N I N G @@ -140,6 +115,14 @@ public: // Edit fake methods of a promoted class stored in WidgetDataBase on a base class instance. static bool editPromotedClass(QDesignerFormEditorInterface *core, QObject *baseObject, QWidget *parent = nullptr, FocusMode m = FocusSlots); + static void fakeMethodsFromMetaDataBase(QDesignerFormEditorInterface *core, QObject *o, + QStringList &slotList, QStringList &signalList); + static void fakeMethodsToMetaDataBase(QDesignerFormEditorInterface *core, QObject *o, + const QStringList &slotList, const QStringList &signalList); + static void existingMethodsFromMemberSheet(QDesignerFormEditorInterface *core, QObject *o, + QStringList &slotList, QStringList &signalList); + + private slots: void slotCheckSignature(const QString &signature, bool *ok); @@ -148,7 +131,7 @@ private: static bool editPromotedClass(QDesignerFormEditorInterface *core, const QString &promotedClassName, QObject *baseObject, QWidget *parent, FocusMode m); const FocusMode m_focusMode; - Ui::SignalSlotDialogClass *m_ui; + QT_PREPEND_NAMESPACE(Ui)::SignalSlotDialogClass *m_ui; QDesignerDialogGuiInterface *m_dialogGui; SignaturePanel *m_slotPanel; SignaturePanel *m_signalPanel; diff --git a/src/designer/src/lib/shared/spacer_widget.cpp b/src/designer/src/lib/shared/spacer_widget.cpp index 15daa9d8c..ac08a67be 100644 --- a/src/designer/src/lib/shared/spacer_widget.cpp +++ b/src/designer/src/lib/shared/spacer_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 "spacer_widget_p.h" #include "layoutinfo_p.h" @@ -41,6 +16,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // The Spacer widget is Designer representation of QLayoutItem. // It uses QLayoutItem's sizeHint property as QWidget // sizeHint and the QLayoutItem's sizeType property as QWidget size policy. @@ -152,7 +129,7 @@ void Spacer::resizeEvent(QResizeEvent* e) const QSize oldSize = e->oldSize(); if (oldSize.isNull() || oldSize.width() <= m_SizeOffset.width() || oldSize.height() <= m_SizeOffset.height()) if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(m_formWindow->core()->extensionManager(), this)) - sheet->setChanged(sheet->indexOf(QStringLiteral("sizeHint")), true); + sheet->setChanged(sheet->indexOf(u"sizeHint"_s), true); } updateMask(); diff --git a/src/designer/src/lib/shared/spacer_widget_p.h b/src/designer/src/lib/shared/spacer_widget_p.h index cbb9dd6d7..fb99316b1 100644 --- a/src/designer/src/lib/shared/spacer_widget_p.h +++ b/src/designer/src/lib/shared/spacer_widget_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/stylesheeteditor.cpp b/src/designer/src/lib/shared/stylesheeteditor.cpp index 2956d1abc..da15f6bf1 100644 --- a/src/designer/src/lib/shared/stylesheeteditor.cpp +++ b/src/designer/src/lib/shared/stylesheeteditor.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 "stylesheeteditor_p.h" #include "csshighlighter_p.h" @@ -60,18 +35,36 @@ QT_BEGIN_NAMESPACE -static const char *styleSheetProperty = "styleSheet"; -static const char *StyleSheetDialogC = "StyleSheetDialog"; -static const char *Geometry = "Geometry"; +using namespace Qt::StringLiterals; + +static constexpr auto styleSheetProperty = "styleSheet"_L1; +static constexpr auto StyleSheetDialogC = "StyleSheetDialog"_L1; +static constexpr auto seGeometry = "Geometry"_L1; namespace qdesigner_internal { StyleSheetEditor::StyleSheetEditor(QWidget *parent) : QTextEdit(parent) { - setTabStopDistance(fontMetrics().horizontalAdvance(QLatin1Char(' ')) * 4); + enum : int { DarkThreshold = 200 }; // Observed 239 on KDE/Dark + + setTabStopDistance(fontMetrics().horizontalAdvance(u' ') * 4); setAcceptRichText(false); - new CssHighlighter(document()); + + const QColor textColor = palette().color(QPalette::WindowText); + const bool darkMode = textColor.red() > DarkThreshold + && textColor.green() > DarkThreshold + && textColor.blue() > DarkThreshold; + + CssHighlightColors colors; + colors.selector = darkMode ? QColor(Qt::red).lighter() : QColor(Qt::darkRed); + const QColor blue(Qt::blue); + colors.property = darkMode ? blue.lighter() : blue; + colors.pseudo1 = colors.pseudo2 = colors.value = textColor; + colors.quote = darkMode ? Qt::magenta : Qt::darkMagenta; + colors.comment = darkMode ? Qt::green : Qt::darkGreen; + + new CssHighlighter(colors, document()); } // --- StyleSheetEditorDialog @@ -88,7 +81,6 @@ StyleSheetEditorDialog::StyleSheetEditorDialog(QDesignerFormEditorInterface *cor m_addFontAction(new QAction(tr("Add Font..."), this)) { setWindowTitle(tr("Edit Style Sheet")); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); @@ -150,13 +142,13 @@ StyleSheetEditorDialog::StyleSheetEditorDialog(QDesignerFormEditorInterface *cor QMenu *colorActionMenu = new QMenu(this); for (int resourceProperty = 0; resourceProperties[resourceProperty]; ++resourceProperty) { - const QString resourcePropertyName = QLatin1String(resourceProperties[resourceProperty]); + const QString resourcePropertyName = QLatin1StringView(resourceProperties[resourceProperty]); resourceActionMenu->addAction(resourcePropertyName, this, [this, resourcePropertyName] { this->slotAddResource(resourcePropertyName); }); } for (int colorProperty = 0; colorProperties[colorProperty]; ++colorProperty) { - const QString colorPropertyName = QLatin1String(colorProperties[colorProperty]); + const QString colorPropertyName = QLatin1StringView(colorProperties[colorProperty]); colorActionMenu->addAction(colorPropertyName, this, [this, colorPropertyName] { this->slotAddColor(colorPropertyName); }); gradientActionMenu->addAction(colorPropertyName, @@ -178,10 +170,10 @@ StyleSheetEditorDialog::StyleSheetEditorDialog(QDesignerFormEditorInterface *cor m_editor->setFocus(); QDesignerSettingsInterface *settings = core->settingsManager(); - settings->beginGroup(QLatin1String(StyleSheetDialogC)); + settings->beginGroup(StyleSheetDialogC); - if (settings->contains(QLatin1String(Geometry))) - restoreGeometry(settings->value(QLatin1String(Geometry)).toByteArray()); + if (settings->contains(seGeometry)) + restoreGeometry(settings->value(seGeometry).toByteArray()); settings->endGroup(); } @@ -189,9 +181,9 @@ StyleSheetEditorDialog::StyleSheetEditorDialog(QDesignerFormEditorInterface *cor StyleSheetEditorDialog::~StyleSheetEditorDialog() { QDesignerSettingsInterface *settings = m_core->settingsManager(); - settings->beginGroup(QLatin1String(StyleSheetDialogC)); + settings->beginGroup(StyleSheetDialogC); - settings->setValue(QLatin1String(Geometry), saveGeometry()); + settings->setValue(seGeometry, saveGeometry()); settings->endGroup(); } @@ -218,7 +210,7 @@ void StyleSheetEditorDialog::slotAddResource(const QString &property) { const QString path = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(), QString(), this); if (!path.isEmpty()) - insertCssProperty(property, QString(QStringLiteral("url(%1)")).arg(path)); + insertCssProperty(property, "url("_L1 + path + u')'); } void StyleSheetEditorDialog::slotAddGradient(const QString &property) @@ -238,11 +230,12 @@ void StyleSheetEditorDialog::slotAddColor(const QString &property) QString colorStr; if (color.alpha() == 255) { - colorStr = QString(QStringLiteral("rgb(%1, %2, %3)")).arg( - color.red()).arg(color.green()).arg(color.blue()); + colorStr = QString::asprintf("rgb(%d, %d, %d)", + color.red(), color.green(), color.blue()); } else { - colorStr = QString(QStringLiteral("rgba(%1, %2, %3, %4)")).arg( - color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha()); + colorStr = QString::asprintf("rgba(%d, %d, %d, %d)", + color.red(), color.green(), color.blue(), + color.alpha()); } insertCssProperty(property, colorStr); @@ -254,36 +247,34 @@ void StyleSheetEditorDialog::slotAddFont() QFont font = QFontDialog::getFont(&ok, this); if (ok) { QString fontStr; - if (font.weight() != QFont::Normal) { - fontStr += QString::number(font.weight()); - fontStr += QLatin1Char(' '); - } + if (font.weight() != QFont::Normal) + fontStr += QString::number(font.weight()) + u' '; switch (font.style()) { case QFont::StyleItalic: - fontStr += QStringLiteral("italic "); + fontStr += "italic "_L1; break; case QFont::StyleOblique: - fontStr += QStringLiteral("oblique "); + fontStr += "oblique "_L1; break; default: break; } fontStr += QString::number(font.pointSize()); - fontStr += QStringLiteral("pt \""); + fontStr += "pt \""_L1; fontStr += font.family(); - fontStr += QLatin1Char('"'); + fontStr += u'"'; - insertCssProperty(QStringLiteral("font"), fontStr); + insertCssProperty(u"font"_s, fontStr); QString decoration; if (font.underline()) - decoration += QStringLiteral("underline"); + decoration += "underline"_L1; if (font.strikeOut()) { if (!decoration.isEmpty()) - decoration += QLatin1Char(' '); - decoration += QStringLiteral("line-through"); + decoration += u' '; + decoration += "line-through"_L1; } - insertCssProperty(QStringLiteral("text-decoration"), decoration); + insertCssProperty(u"text-decoration"_s, decoration); } } @@ -298,19 +289,19 @@ void StyleSheetEditorDialog::insertCssProperty(const QString &name, const QStrin // Simple check to see if we're in a selector scope const QTextDocument *doc = m_editor->document(); - const QTextCursor closing = doc->find(QStringLiteral("}"), cursor, QTextDocument::FindBackward); - const QTextCursor opening = doc->find(QStringLiteral("{"), cursor, QTextDocument::FindBackward); + const QTextCursor closing = doc->find(u"}"_s, cursor, QTextDocument::FindBackward); + const QTextCursor opening = doc->find(u"{"_s, cursor, QTextDocument::FindBackward); const bool inSelector = !opening.isNull() && (closing.isNull() || closing.position() < opening.position()); QString insertion; if (m_editor->textCursor().block().length() != 1) - insertion += QLatin1Char('\n'); + insertion += u'\n'; if (inSelector) - insertion += QLatin1Char('\t'); + insertion += u'\t'; insertion += name; - insertion += QStringLiteral(": "); + insertion += ": "_L1; insertion += value; - insertion += QLatin1Char(';'); + insertion += u';'; cursor.insertText(insertion); cursor.endEditBlock(); } else { @@ -321,8 +312,8 @@ void StyleSheetEditorDialog::insertCssProperty(const QString &name, const QStrin void StyleSheetEditorDialog::slotRequestHelp() { - m_core->integration()->emitHelpRequested(QStringLiteral("qtwidgets"), - QStringLiteral("stylesheet-reference.html")); + m_core->integration()->emitHelpRequested(u"qtwidgets"_s, + u"stylesheet-reference.html"_s); } // See QDialog::keyPressEvent() @@ -363,10 +354,7 @@ bool StyleSheetEditorDialog::isStyleSheetValid(const QString &styleSheet) QCss::StyleSheet sheet; if (parser.parse(&sheet)) return true; - QString fullSheet = QStringLiteral("* { "); - fullSheet += styleSheet; - fullSheet += QLatin1Char('}'); - QCss::Parser parser2(fullSheet); + QCss::Parser parser2("* { "_L1 + styleSheet + '}'_L1); return parser2.parse(&sheet); } @@ -376,10 +364,10 @@ void StyleSheetEditorDialog::validateStyleSheet() setOkButtonEnabled(valid); if (valid) { m_validityLabel->setText(tr("Valid Style Sheet")); - m_validityLabel->setStyleSheet(QStringLiteral("color: green")); + m_validityLabel->setStyleSheet(u"color: green"_s); } else { m_validityLabel->setText(tr("Invalid Style Sheet")); - m_validityLabel->setStyleSheet(QStringLiteral("color: red")); + m_validityLabel->setStyleSheet(u"color: red"_s); } } @@ -402,7 +390,7 @@ StyleSheetPropertyEditorDialog::StyleSheetPropertyEditorDialog(QWidget *parent, QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(m_fw->core()->extensionManager(), m_widget); Q_ASSERT(sheet != nullptr); - const int index = sheet->indexOf(QLatin1String(styleSheetProperty)); + const int index = sheet->indexOf(styleSheetProperty); const PropertySheetStringValue value = qvariant_cast<PropertySheetStringValue>(sheet->property(index)); setText(value.value()); } @@ -410,7 +398,7 @@ StyleSheetPropertyEditorDialog::StyleSheetPropertyEditorDialog(QWidget *parent, void StyleSheetPropertyEditorDialog::applyStyleSheet() { const PropertySheetStringValue value(text(), false); - m_fw->cursor()->setWidgetProperty(m_widget, QLatin1String(styleSheetProperty), QVariant::fromValue(value)); + m_fw->cursor()->setWidgetProperty(m_widget, styleSheetProperty, QVariant::fromValue(value)); } } // namespace qdesigner_internal diff --git a/src/designer/src/lib/shared/stylesheeteditor_p.h b/src/designer/src/lib/shared/stylesheeteditor_p.h index ee6c3bc84..9943b4fa6 100644 --- a/src/designer/src/lib/shared/stylesheeteditor_p.h +++ b/src/designer/src/lib/shared/stylesheeteditor_p.h @@ -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 // // W A R N I N G diff --git a/src/designer/src/lib/shared/textpropertyeditor.cpp b/src/designer/src/lib/shared/textpropertyeditor.cpp index e78cb81b4..e345580ba 100644 --- a/src/designer/src/lib/shared/textpropertyeditor.cpp +++ b/src/designer/src/lib/shared/textpropertyeditor.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 "textpropertyeditor_p.h" #include "propertylineedit_p.h" @@ -42,9 +17,11 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace { - const QChar NewLineChar(QLatin1Char('\n')); - const QLatin1String EscapedNewLine("\\n"); + const QChar NewLineChar(u'\n'); + const auto EscapedNewLine = "\\n"_L1; // A validator that replaces offending strings class ReplacementValidator : public QValidator { @@ -155,7 +132,7 @@ namespace { QUrl UrlValidator::guessUrlFromString(const QString &string) const { const QString urlStr = string.trimmed(); - const QRegularExpression qualifiedUrl(QStringLiteral("^[a-zA-Z]+\\:.*$")); + const QRegularExpression qualifiedUrl(u"^[a-zA-Z]+\\:.*$"_s); Q_ASSERT(qualifiedUrl.isValid()); // Check if it looks like a qualified URL. Try parsing it and see. @@ -167,8 +144,8 @@ namespace { } // Might be a Qt resource - if (string.startsWith(QStringLiteral(":/"))) - return QUrl(QStringLiteral("qrc") + string); + if (string.startsWith(":/"_L1)) + return QUrl("qrc"_L1 + string); // Might be a file. if (QFile::exists(urlStr)) @@ -176,15 +153,15 @@ namespace { // Might be a short url - try to detect the schema. if (!hasSchema) { - const int dotIndex = urlStr.indexOf(QLatin1Char('.')); + const int dotIndex = urlStr.indexOf(u'.'); if (dotIndex != -1) { const QString prefix = urlStr.left(dotIndex).toLower(); QString urlString; - if (prefix == QStringLiteral("ftp")) + if (prefix == "ftp"_L1) urlString += prefix; else - urlString += QStringLiteral("http"); - urlString += QStringLiteral("://"); + urlString += "http"_L1; + urlString += "://"_L1; urlString += urlStr; const QUrl url(urlString, QUrl::TolerantMode); if (url.isValid()) @@ -246,30 +223,29 @@ namespace qdesigner_internal { break; case ValidationSingleLine: // Set a validator that replaces newline characters by a blank. - m_lineEdit->setValidator(new ReplacementValidator(m_lineEdit, NewLineChar, QString(QLatin1Char(' ')))); + m_lineEdit->setValidator(new ReplacementValidator(m_lineEdit, NewLineChar, QString(u' '))); m_lineEdit->setCompleter(nullptr); break; case ValidationObjectName: - setRegularExpressionValidator(QStringLiteral("^[_a-zA-Z][_a-zA-Z0-9]{1,1023}$")); + setRegularExpressionValidator(u"^[_a-zA-Z][_a-zA-Z0-9]{1,1023}$"_s); m_lineEdit->setCompleter(nullptr); break; case ValidationObjectNameScope: - setRegularExpressionValidator(QStringLiteral("^[_a-zA-Z:][_a-zA-Z0-9:]{1,1023}$")); + setRegularExpressionValidator(u"^[_a-zA-Z:][_a-zA-Z0-9:]{1,1023}$"_s); m_lineEdit->setCompleter(nullptr); break; case ValidationURL: { - static QStringList urlCompletions; - if (urlCompletions.isEmpty()) { - urlCompletions.push_back(QStringLiteral("about:blank")); - urlCompletions.push_back(QStringLiteral("http://")); - urlCompletions.push_back(QStringLiteral("http://www.")); - urlCompletions.push_back(QStringLiteral("http://qt.io")); - urlCompletions.push_back(QStringLiteral("file://")); - urlCompletions.push_back(QStringLiteral("ftp://")); - urlCompletions.push_back(QStringLiteral("data:")); - urlCompletions.push_back(QStringLiteral("data:text/html,")); - urlCompletions.push_back(QStringLiteral("qrc:/")); - } + static const QStringList urlCompletions = { + u"about:blank"_s, + u"http://"_s, + u"http://www."_s, + u"http://qt.io"_s, + u"file://"_s, + u"ftp://"_s, + u"data:"_s, + u"data:text/html,"_s, + u"qrc:/"_s, + }; QCompleter *completer = new QCompleter(urlCompletions, m_lineEdit); m_lineEdit->setCompleter(completer); m_lineEdit->setValidator(new UrlValidator(completer, m_lineEdit)); @@ -376,9 +352,9 @@ namespace qdesigner_internal { QString rc(s); // protect backslashes - rc.replace(QLatin1Char('\\'), QStringLiteral("\\\\")); + rc.replace('\\'_L1, "\\\\"_L1); // escape newlines - rc.replace(NewLineChar, QString(EscapedNewLine)); + rc.replace(u'\n', EscapedNewLine); return rc; } @@ -392,14 +368,14 @@ namespace qdesigner_internal { return s; QString rc(s); - for (int pos = 0; (pos = rc.indexOf(QLatin1Char('\\'),pos)) >= 0 ; ) { + for (qsizetype pos = 0; (pos = rc.indexOf(u'\\', pos)) >= 0 ; ) { // found an escaped character. If not a newline or at end of string, leave as is, else insert '\n' - const int nextpos = pos + 1; - if (nextpos >= rc.length()) // trailing '\\' + const qsizetype nextpos = pos + 1; + if (nextpos >= rc.size()) // trailing '\\' break; // Escaped NewLine - if (rc.at(nextpos) == QChar(QLatin1Char('n'))) - rc[nextpos] = NewLineChar; + if (rc.at(nextpos) == u'n') + rc[nextpos] = u'\n'; // Remove escape, go past escaped rc.remove(pos,1); pos++; diff --git a/src/designer/src/lib/shared/textpropertyeditor_p.h b/src/designer/src/lib/shared/textpropertyeditor_p.h index fa899ed9e..3d32e9d6e 100644 --- a/src/designer/src/lib/shared/textpropertyeditor_p.h +++ b/src/designer/src/lib/shared/textpropertyeditor_p.h @@ -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 // // W A R N I N G @@ -56,8 +31,6 @@ namespace qdesigner_internal { // corresponds to that of QLineEdit. class QDESIGNER_SHARED_EXPORT TextPropertyEditor : public QWidget { - TextPropertyEditor(const TextPropertyEditor &); - TextPropertyEditor& operator=(const TextPropertyEditor &); Q_OBJECT Q_PROPERTY(QString text READ text WRITE setText USER true) public: diff --git a/src/designer/src/lib/shared/widgetdatabase.cpp b/src/designer/src/lib/shared/widgetdatabase.cpp index 8621f2840..97df98f4d 100644 --- a/src/designer/src/lib/shared/widgetdatabase.cpp +++ b/src/designer/src/lib/shared/widgetdatabase.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 "widgetdatabase_p.h" #include "widgetfactory_p.h" @@ -40,23 +15,34 @@ #include <QtDesigner/abstractformeditor.h> #include <QtUiPlugin/customwidget.h> +#include <QtWidgets/QtWidgets> +#ifdef QT_OPENGLWIDGETS_LIB +#include <QtOpenGLWidgets/qopenglwidget.h> +#endif #include <QtCore/qxmlstream.h> +#include <QtCore/qcoreapplication.h> #include <QtCore/qscopedpointer.h> #include <QtCore/qdebug.h> #include <QtCore/qmetaobject.h> +#include <QtCore/qset.h> +#include <QtCore/qstring.h> #include <QtCore/qtextstream.h> #include <QtCore/qcoreapplication.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace { enum { debugWidgetDataBase = 0 }; } namespace qdesigner_internal { +using namespace Qt::StringLiterals; + // ---------------------------------------------------------- WidgetDataBaseItem::WidgetDataBaseItem(const QString &name, const QString &group) : m_name(name), @@ -247,6 +233,27 @@ WidgetDataBaseItem *WidgetDataBaseItem::clone(const QDesignerWidgetDataBaseItemI return rc; } +QString WidgetDataBaseItem::baseClassName() const +{ + return m_extends.isEmpty() ? m_baseClassName : m_extends; +} + +void WidgetDataBaseItem::setBaseClassName(const QString &b) +{ + m_baseClassName = b; +} + +static void addWidgetItem(WidgetDataBase *wdb, const char *name, const QMetaObject &mo, + const char *comment) +{ + auto *item = new WidgetDataBaseItem(QString::fromUtf8(name)); + if (auto *base = mo.superClass()) + item->setBaseClassName(QString::fromUtf8(base->className())); + if (comment[0]) + item->setToolTip(QString::fromUtf8(comment)); + wdb->append(item); +} + // ---------------------------------------------------------- WidgetDataBase::WidgetDataBase(QDesignerFormEditorInterface *core, QObject *parent) : QDesignerWidgetDataBaseInterface(parent), @@ -254,7 +261,7 @@ WidgetDataBase::WidgetDataBase(QDesignerFormEditorInterface *core, QObject *pare { #define DECLARE_LAYOUT(L, C) #define DECLARE_COMPAT_WIDGET(W, C) DECLARE_WIDGET(W, C) -#define DECLARE_WIDGET(W, C) append(new WidgetDataBaseItem(QString::fromUtf8(#W))); +#define DECLARE_WIDGET(W, C) addWidgetItem(this, #W, W::staticMetaObject, C); #include <widgets.table> @@ -263,47 +270,65 @@ WidgetDataBase::WidgetDataBase(QDesignerFormEditorInterface *core, QObject *pare #undef DECLARE_WIDGET #undef DECLARE_WIDGET_1 - append(new WidgetDataBaseItem(QString::fromUtf8("Line"))); - append(new WidgetDataBaseItem(QString::fromUtf8("Spacer"))); - append(new WidgetDataBaseItem(QString::fromUtf8("QSplitter"))); - append(new WidgetDataBaseItem(QString::fromUtf8("QLayoutWidget"))); + const QString msgAbstractClass = + QCoreApplication::translate("WidgetDataBase", + "Abstract base class that cannot be instantiated. For promotion/custom widget usage only."); + +#if QT_CONFIG(abstractbutton) + auto *abItem = new WidgetDataBaseItem(u"QAbstractButton"_s); + abItem->setToolTip(msgAbstractClass); + abItem->setBaseClassName(u"QWidget"_s); + append(abItem); +#endif // QT_CONFIG(abstractbutton) + +#if QT_CONFIG(itemviews) + auto *aivItem = new WidgetDataBaseItem(u"QAbstractItemView"_s); + aivItem->setBaseClassName(u"QAbstractScrollArea"_s); + aivItem->setToolTip(msgAbstractClass); + append(aivItem); +#endif // QT_CONFIG(itemviews) + + append(new WidgetDataBaseItem(u"Line"_s)); + append(new WidgetDataBaseItem(u"Spacer"_s)); + append(new WidgetDataBaseItem(u"QSplitter"_s)); + append(new WidgetDataBaseItem(u"QLayoutWidget"_s)); // QDesignerWidget is used as central widget and as container for tab widgets, etc. - WidgetDataBaseItem *designerWidgetItem = new WidgetDataBaseItem(QString::fromUtf8("QDesignerWidget")); + WidgetDataBaseItem *designerWidgetItem = new WidgetDataBaseItem(u"QDesignerWidget"_s); designerWidgetItem->setContainer(true); append(designerWidgetItem); - append(new WidgetDataBaseItem(QString::fromUtf8("QDesignerDialog"))); - append(new WidgetDataBaseItem(QString::fromUtf8("QDesignerMenu"))); - append(new WidgetDataBaseItem(QString::fromUtf8("QDesignerMenuBar"))); - append(new WidgetDataBaseItem(QString::fromUtf8("QDesignerDockWidget"))); - append(new WidgetDataBaseItem(QString::fromUtf8("QAction"))); - append(new WidgetDataBaseItem(QString::fromUtf8("QButtonGroup"))); + append(new WidgetDataBaseItem(u"QDesignerDialog"_s)); + append(new WidgetDataBaseItem(u"QDesignerMenu"_s)); + append(new WidgetDataBaseItem(u"QDesignerMenuBar"_s)); + append(new WidgetDataBaseItem(u"QDesignerDockWidget"_s)); + append(new WidgetDataBaseItem(u"QAction"_s)); + append(new WidgetDataBaseItem(u"QButtonGroup"_s)); // ### remove me // ### check the casts #if 0 // ### enable me after 4.1 - item(indexOfClassName(QStringLiteral("QToolBar")))->setContainer(true); + item(indexOfClassName(u"QToolBar"_s))->setContainer(true); #endif - item(indexOfClassName(QStringLiteral("QTabWidget")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QGroupBox")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QScrollArea")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QStackedWidget")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QToolBox")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QFrame")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QLayoutWidget")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QDesignerWidget")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QDesignerDialog")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QSplitter")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QMainWindow")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QDockWidget")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QDesignerDockWidget")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QMdiArea")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QWizard")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QWizardPage")))->setContainer(true); - - item(indexOfClassName(QStringLiteral("QWidget")))->setContainer(true); - item(indexOfClassName(QStringLiteral("QDialog")))->setContainer(true); + item(indexOfClassName(u"QTabWidget"_s))->setContainer(true); + item(indexOfClassName(u"QGroupBox"_s))->setContainer(true); + item(indexOfClassName(u"QScrollArea"_s))->setContainer(true); + item(indexOfClassName(u"QStackedWidget"_s))->setContainer(true); + item(indexOfClassName(u"QToolBox"_s))->setContainer(true); + item(indexOfClassName(u"QFrame"_s))->setContainer(true); + item(indexOfClassName(u"QLayoutWidget"_s))->setContainer(true); + item(indexOfClassName(u"QDesignerWidget"_s))->setContainer(true); + item(indexOfClassName(u"QDesignerDialog"_s))->setContainer(true); + item(indexOfClassName(u"QSplitter"_s))->setContainer(true); + item(indexOfClassName(u"QMainWindow"_s))->setContainer(true); + item(indexOfClassName(u"QDockWidget"_s))->setContainer(true); + item(indexOfClassName(u"QDesignerDockWidget"_s))->setContainer(true); + item(indexOfClassName(u"QMdiArea"_s))->setContainer(true); + item(indexOfClassName(u"QWizard"_s))->setContainer(true); + item(indexOfClassName(u"QWizardPage"_s))->setContainer(true); + + item(indexOfClassName(u"QWidget"_s))->setContainer(true); + item(indexOfClassName(u"QDialog"_s))->setContainer(true); } WidgetDataBase::~WidgetDataBase() = default; @@ -347,22 +372,18 @@ static WidgetDataBaseItem *createCustomWidgetItem(const QDesignerCustomWidgetInt void WidgetDataBase::loadPlugins() { - typedef QMap<QString, int> NameIndexMap; - using ItemList = QList<QDesignerWidgetDataBaseItemInterface *>; - using NameSet = QSet<QString>; // 1) create a map of existing custom classes - NameIndexMap existingCustomClasses; - NameSet nonCustomClasses; - const int count = m_items.size(); - for (int i = 0; i < count; i++) { - const QDesignerWidgetDataBaseItemInterface* item = m_items[i]; + QMap<QString, qsizetype> existingCustomClasses; + QSet<QString> nonCustomClasses; + for (qsizetype i = 0, count = m_items.size(); i < count; ++i) { + const QDesignerWidgetDataBaseItemInterface* item = m_items.at(i); if (item->isCustom() && !item->isPromoted()) existingCustomClasses.insert(item->name(), i); else nonCustomClasses.insert(item->name()); } // 2) create a list plugins - ItemList pluginList; + QList<QDesignerWidgetDataBaseItemInterface *> pluginList; const QDesignerPluginManager *pm = m_core->pluginManager(); const auto &customWidgets = pm->registeredCustomWidgets(); for (QDesignerCustomWidgetInterface* c : customWidgets) @@ -374,10 +395,10 @@ void WidgetDataBase::loadPlugins() unsigned addedPlugins = 0; unsigned removedPlugins = 0; if (!pluginList.isEmpty()) { - for (QDesignerWidgetDataBaseItemInterface *pluginItem : qAsConst(pluginList)) { + for (QDesignerWidgetDataBaseItemInterface *pluginItem : std::as_const(pluginList)) { const QString pluginName = pluginItem->name(); - NameIndexMap::iterator existingIt = existingCustomClasses.find(pluginName); - if (existingIt == existingCustomClasses.end()) { + const auto existingIt = existingCustomClasses.constFind(pluginName); + if (existingIt == existingCustomClasses.cend()) { // Add new class. if (nonCustomClasses.contains(pluginName)) { designerWarning(tr("A custom widget plugin whose class name (%1) matches that of an existing class has been found.").arg(pluginName)); @@ -387,7 +408,7 @@ void WidgetDataBase::loadPlugins() } } else { // replace existing info - const int existingIndex = existingIt.value(); + const auto existingIndex = existingIt.value(); delete m_items[existingIndex]; m_items[existingIndex] = pluginItem; existingCustomClasses.erase(existingIt); @@ -397,16 +418,14 @@ void WidgetDataBase::loadPlugins() } } // 4) remove classes that have not been matched. The stored indexes become invalid while deleting. - if (!existingCustomClasses.isEmpty()) { - NameIndexMap::const_iterator cend = existingCustomClasses.constEnd(); - for (NameIndexMap::const_iterator it = existingCustomClasses.constBegin();it != cend; ++it ) { - const int index = indexOfClassName(it.key()); - if (index != -1) { - remove(index); - removedPlugins++; - } + for (auto it = existingCustomClasses.cbegin(), cend = existingCustomClasses.cend(); it != cend; ++it ) { + const int index = indexOfClassName(it.key()); + if (index != -1) { + remove(index); + removedPlugins++; } } + if (debugWidgetDataBase) qDebug() << "WidgetDataBase::loadPlugins(): " << addedPlugins << " added, " << replacedPlugins << " replaced, " << removedPlugins << "deleted."; } @@ -456,7 +475,6 @@ void WidgetDataBase::grabStandardWidgetBoxIcons() // At this point, grab the default icons for the non-custom widgets from // the widget box. They will show up in the object inspector. if (const QDesignerWidgetBox *wb = qobject_cast<const QDesignerWidgetBox *>(m_core->widgetBox())) { - const QString qWidgetClass = QStringLiteral("QWidget"); const int itemCount = count(); for (int i = 0; i < itemCount; ++i) { QDesignerWidgetDataBaseItemInterface *dbItem = item(i); @@ -464,8 +482,8 @@ void WidgetDataBase::grabStandardWidgetBoxIcons() // Careful not to catch the layout icons when looking for // QWidget const QString name = dbItem->name(); - if (name == qWidgetClass) { - dbItem->setIcon(wb->iconForWidget(name, QStringLiteral("Containers"))); + if (name == "QWidget"_L1) { + dbItem->setIcon(wb->iconForWidget(name, u"Containers"_s)); } else { dbItem->setIcon(wb->iconForWidget(name)); } @@ -481,7 +499,7 @@ enum { NewFormWidth = 400, NewFormHeight = 300 }; // Check if class is suitable to generate a form from static inline bool isExistingTemplate(const QString &className) { - return className == QStringLiteral("QWidget") || className == QStringLiteral("QDialog") || className == QStringLiteral("QMainWindow"); + return className == "QWidget"_L1 || className == "QDialog"_L1 || className == "QMainWindow"_L1; } // Check if class is suitable to generate a form from @@ -489,9 +507,9 @@ static inline bool suitableForNewForm(const QString &className) { if (className.isEmpty()) // Missing custom widget information return false; - if (className == QStringLiteral("QSplitter")) + if (className == "QSplitter"_L1) return false; - if (className.startsWith(QStringLiteral("QDesigner")) || className.startsWith(QStringLiteral("QLayout"))) + if (className.startsWith("QDesigner"_L1) || className.startsWith("QLayout"_L1)) return false; return true; } @@ -537,8 +555,6 @@ QStringList WidgetDataBase::customFormWidgetClasses(const QDesignerFormEditorInt // properties to be suitable for new forms static QString xmlFromWidgetBox(const QDesignerFormEditorInterface *core, const QString &className, const QString &objectName) { - using PropertyList = QList<DomProperty *>; - QDesignerWidgetBoxInterface::Widget widget; const bool found = QDesignerWidgetBox::findWidget(core->widgetBox(), className, QString(), &widget); if (!found) @@ -546,22 +562,20 @@ static QString xmlFromWidgetBox(const QDesignerFormEditorInterface *core, const QScopedPointer<DomUI> domUI(QDesignerWidgetBox::xmlToUi(className, widget.domXml(), false)); if (domUI.isNull()) return QString(); - domUI->setAttributeVersion(QStringLiteral("4.0")); + domUI->setAttributeVersion(u"4.0"_s); DomWidget *domWidget = domUI->elementWidget(); if (!domWidget) return QString(); // Properties: Remove the "objectName" property in favour of the name attribute and check geometry. domWidget->setAttributeName(objectName); - const QString geometryProperty = QStringLiteral("geometry"); - const QString objectNameProperty = QStringLiteral("objectName"); - PropertyList properties = domWidget->elementProperty(); - for (PropertyList::iterator it = properties.begin(); it != properties.end(); ) { + QList<DomProperty *> properties = domWidget->elementProperty(); + for (auto it = properties.begin(); it != properties.end(); ) { DomProperty *property = *it; - if (property->attributeName() == objectNameProperty) { // remove "objectName" + if (property->attributeName() == "objectName"_L1) { // remove "objectName" it = properties.erase(it); delete property; } else { - if (property->attributeName() == geometryProperty) { // Make sure form is at least 400, 300 + if (property->attributeName() == "geometry"_L1) { // Make sure form is at least 400, 300 if (DomRect *geom = property->elementRect()) { if (geom->elementWidth() < NewFormWidth) geom->setElementWidth(NewFormWidth); @@ -576,7 +590,7 @@ static QString xmlFromWidgetBox(const QDesignerFormEditorInterface *core, const DomString *windowTitleString = new DomString; windowTitleString->setText(objectName); DomProperty *windowTitleProperty = new DomProperty; - windowTitleProperty->setAttributeName(QStringLiteral("windowTitle")); + windowTitleProperty->setAttributeName(u"windowTitle"_s); windowTitleProperty->setElementString(windowTitleString); properties.push_back(windowTitleProperty); // ------ @@ -607,11 +621,11 @@ static QString generateNewFormXML(const QString &className, const QString &simil << NewFormWidth << "</width><height>" << NewFormHeight << "</height></rect></property>" << R"(<property name="windowTitle"><string>)" << name << "</string></property>\n"; - if (similarClassName == QLatin1String("QMainWindow")) { + if (similarClassName == "QMainWindow"_L1) { str << R"(<widget class="QWidget" name="centralwidget"/>)"; - } else if (similarClassName == QLatin1String("QWizard")) { + } else if (similarClassName == "QWizard"_L1) { str << R"(<widget class="QWizardPage" name="wizardPage1"/><widget class="QWizardPage" name="wizardPage2"/>)"; - } else if (similarClassName == QLatin1String("QDockWidget")) { + } else if (similarClassName == "QDockWidget"_L1) { str << R"(<widget class="QWidget" name="dockWidgetContents"/>)"; } str << "</widget></ui>\n"; @@ -629,7 +643,7 @@ QString WidgetDataBase::formTemplate(const QDesignerFormEditorInterface *core, c // 2) If that fails, only custom main windows, custom dialogs and unsupported Qt Widgets should // be left over. Generate something that is similar to the default templates. Find a similar class. const QDesignerWidgetDataBaseInterface *wdb = core->widgetDataBase(); - QString similarClass = QStringLiteral("QWidget"); + QString similarClass = u"QWidget"_s; const int index = wdb->indexOfClassName(className); if (index != -1) { const QDesignerWidgetDataBaseItemInterface *item = wdb->item(index); @@ -643,16 +657,16 @@ QString WidgetDataBase::formTemplate(const QDesignerFormEditorInterface *core, c // Set a fixed size on a XML template QString WidgetDataBase::scaleFormTemplate(const QString &xml, const QSize &size, bool fixed) { - QScopedPointer<DomUI> domUI(QDesignerWidgetBox::xmlToUi(QStringLiteral("Form"), xml, false)); + QScopedPointer<DomUI> domUI(QDesignerWidgetBox::xmlToUi(u"Form"_s, xml, false)); if (!domUI) return QString(); DomWidget *domWidget = domUI->elementWidget(); if (!domWidget) return QString(); // Properties: Find/Ensure the geometry, minimum and maximum sizes properties - const QString geometryPropertyName = QStringLiteral("geometry"); - const QString minimumSizePropertyName = QStringLiteral("minimumSize"); - const QString maximumSizePropertyName = QStringLiteral("maximumSize"); + const QString geometryPropertyName = u"geometry"_s; + const QString minimumSizePropertyName = u"minimumSize"_s; + const QString maximumSizePropertyName = u"maximumSize"_s; DomProperty *geomProperty = nullptr; DomProperty *minimumSizeProperty = nullptr; DomProperty *maximumSizeProperty = nullptr; @@ -662,13 +676,10 @@ QString WidgetDataBase::scaleFormTemplate(const QString &xml, const QSize &size, const QString name = p->attributeName(); if (name == geometryPropertyName) { geomProperty = p; - } else { - if (name == minimumSizePropertyName) { - minimumSizeProperty = p; - } else { - if (name == maximumSizePropertyName) - maximumSizeProperty = p; - } + } else if (name == minimumSizePropertyName) { + minimumSizeProperty = p; + } else if (name == maximumSizePropertyName) { + maximumSizeProperty = p; } } if (!geomProperty) { @@ -727,20 +738,19 @@ QString WidgetDataBase::scaleFormTemplate(const QString &xml, const QSize &size, // ---- free functions QDESIGNER_SHARED_EXPORT IncludeSpecification includeSpecification(QString includeFile) { - const bool global = !includeFile.isEmpty() && - includeFile[0] == QLatin1Char('<') && - includeFile[includeFile.size() - 1] == QLatin1Char('>'); + const bool global = includeFile.startsWith(u'<') && includeFile.endsWith(u'>'); if (global) { - includeFile.remove(includeFile.size() - 1, 1); + includeFile.chop(1); includeFile.remove(0, 1); } return IncludeSpecification(includeFile, global ? IncludeGlobal : IncludeLocal); } -QDESIGNER_SHARED_EXPORT QString buildIncludeFile(QString includeFile, IncludeType includeType) { +QDESIGNER_SHARED_EXPORT QString buildIncludeFile(QString includeFile, IncludeType includeType) +{ if (includeType == IncludeGlobal && !includeFile.isEmpty()) { - includeFile.append(QLatin1Char('>')); - includeFile.insert(0, QLatin1Char('<')); + includeFile.append(u'>'); + includeFile.prepend(u'<'); } return includeFile; } @@ -803,8 +813,7 @@ QDESIGNER_SHARED_EXPORT QDesignerWidgetDataBaseItemInterface * derivedItem = WidgetDataBaseItem::clone(baseItem); // Sort of hack: If base class is QWidget, we most likely // do not want to inherit the container attribute. - static const QString qWidgetName = QStringLiteral("QWidget"); - if (baseItem->name() == qWidgetName) + if (baseItem->name() == "QWidget"_L1) derivedItem->setContainer(false); // set new props derivedItem->setName(className); diff --git a/src/designer/src/lib/shared/widgetdatabase_p.h b/src/designer/src/lib/shared/widgetdatabase_p.h index 73f00b6b6..10c3af61e 100644 --- a/src/designer/src/lib/shared/widgetdatabase_p.h +++ b/src/designer/src/lib/shared/widgetdatabase_p.h @@ -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 // // W A R N I N G @@ -106,6 +81,9 @@ public: static WidgetDataBaseItem *clone(const QDesignerWidgetDataBaseItemInterface *item); + QString baseClassName() const; // FIXME Qt 7: Move to QDesignerWidgetDataBaseItemInterface + void setBaseClassName(const QString &b); + QStringList fakeSlots() const; void setFakeSlots(const QStringList &); @@ -117,6 +95,7 @@ public: private: QString m_name; + QString m_baseClassName; QString m_group; QString m_toolTip; QString m_whatsThis; @@ -136,7 +115,7 @@ private: enum IncludeType { IncludeLocal, IncludeGlobal }; -using IncludeSpecification = QPair<QString, IncludeType>; +using IncludeSpecification = std::pair<QString, IncludeType>; QDESIGNER_SHARED_EXPORT IncludeSpecification includeSpecification(QString includeFile); QDESIGNER_SHARED_EXPORT QString buildIncludeFile(QString includeFile, IncludeType includeType); diff --git a/src/designer/src/lib/shared/widgetfactory.cpp b/src/designer/src/lib/shared/widgetfactory.cpp index 34253b32b..537ecf8a9 100644 --- a/src/designer/src/lib/shared/widgetfactory.cpp +++ b/src/designer/src/lib/shared/widgetfactory.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 "widgetfactory_p.h" #include "widgetdatabase_p.h" @@ -71,17 +46,27 @@ #include <QtCore/qmetaobject.h> #include <QtCore/qpointer.h> +#if QT_CONFIG(abstractbutton) +# include <QtWidgets/qabstractbutton.h> +#endif + +#if QT_CONFIG(itemviews) +# include <QtWidgets/qabstractitemview.h> +#endif + #ifdef QT_OPENGLWIDGETS_LIB # include <QtOpenGLWidgets/qopenglwidget.h> #endif QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #ifdef Q_OS_WIN static inline bool isAxWidget(const QObject *o) { // Is it one of QDesignerAxWidget/QDesignerAxPluginWidget? - static const char *axWidgetName = "QDesignerAx"; + static const char axWidgetName[] = "QDesignerAx"; static const size_t axWidgetNameLen = qstrlen(axWidgetName); return qstrncmp(o->metaObject()->className(), axWidgetName, axWidgetNameLen) == 0; } @@ -90,10 +75,63 @@ static inline bool isAxWidget(const QObject *o) /* Dynamic boolean property indicating object was created by the factory * for the form editor. */ -static const char *formEditorDynamicProperty = "_q_formEditorObject"; +static const char formEditorDynamicProperty[] = "_q_formEditorObject"; namespace qdesigner_internal { +#if QT_CONFIG(abstractbutton) + +class QDesignerAbstractButton : public QAbstractButton +{ +public: + using QAbstractButton::QAbstractButton; + +protected: + void paintEvent(QPaintEvent *) override {} +}; + +#endif + +#if QT_CONFIG(itemviews) + +class QDesignerAbstractItemView : public QAbstractItemView +{ +public: + using QAbstractItemView::QAbstractItemView; + + QRect visualRect(const QModelIndex &) const override + { + return QRect(QPoint(), QSize(10, 10)); + } + + void scrollTo(const QModelIndex &, ScrollHint = EnsureVisible) override {} + + QModelIndex indexAt(const QPoint &) const override + { + return {}; + } + +protected: + QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override + { + return {}; + } + + int horizontalOffset() const override { return 0; } + int verticalOffset() const override { return 0; } + + bool isIndexHidden(const QModelIndex &) const override { return false; } + + void setSelection(const QRect &, QItemSelectionModel::SelectionFlags) override {} + + QRegion visualRegionForSelection(const QItemSelection &) const override + { + return QRegion(QRect(QPoint(), QSize(10, 10))); + } +}; + +#endif // QT_CONFIG(itemviews) + // A friendly SpinBox that grants access to its QLineEdit class FriendlySpinBox : public QAbstractSpinBox { public: @@ -163,35 +201,6 @@ void WizardPageChangeWatcher::pageChanged() } } -// ---------------- WidgetFactory::Strings -WidgetFactory::Strings::Strings() : - m_alignment(QStringLiteral("alignment")), - m_bottomMargin(QStringLiteral("bottomMargin")), - m_geometry(QStringLiteral("geometry")), - m_leftMargin(QStringLiteral("leftMargin")), - m_line(QStringLiteral("Line")), - m_objectName(QStringLiteral("objectName")), - m_spacerName(QStringLiteral("spacerName")), - m_orientation(QStringLiteral("orientation")), - m_qAction(QStringLiteral("QAction")), - m_qButtonGroup(QStringLiteral("QButtonGroup")), - m_qAxWidget(QStringLiteral("QAxWidget")), - m_qDialog(QStringLiteral("QDialog")), - m_qDockWidget(QStringLiteral("QDockWidget")), - m_qLayoutWidget(QStringLiteral("QLayoutWidget")), - m_qMenu(QStringLiteral("QMenu")), - m_qMenuBar(QStringLiteral("QMenuBar")), - m_qWidget(QStringLiteral("QWidget")), - m_rightMargin(QStringLiteral("rightMargin")), - m_sizeHint(QStringLiteral("sizeHint")), - m_spacer(QStringLiteral("Spacer")), - m_text(QStringLiteral("text")), - m_title(QStringLiteral("title")), - m_topMargin(QStringLiteral("topMargin")), - m_windowIcon(QStringLiteral("windowIcon")), - m_windowTitle(QStringLiteral("windowTitle")) -{ -} // ---------------- WidgetFactory const char *WidgetFactory::disableStyleCustomPaintingPropertyC = "_q_custom_style_disabled"; @@ -228,9 +237,9 @@ QObject* WidgetFactory::createObject(const QString &className, QObject* parent) qWarning("** WARNING %s called with an empty class name", Q_FUNC_INFO); return nullptr; } - if (className == m_strings.m_qAction) + if (className == "QAction"_L1) return new QAction(parent); - if (className == m_strings.m_qButtonGroup) + if (className == "QButtonGroup"_L1) return new QButtonGroup(parent); return nullptr; } @@ -257,11 +266,11 @@ static bool classNameMatches(const QObject *created, const QString &className) QWidget* WidgetFactory::createCustomWidget(const QString &className, QWidget *parentWidget, bool *creationError) const { *creationError = false; - CustomWidgetFactoryMap::const_iterator it = m_customFactory.constFind(className); - if (it == m_customFactory.constEnd()) + + auto *factory = m_customFactory.value(className, nullptr); + if (factory == nullptr) return nullptr; - QDesignerCustomWidgetInterface *factory = it.value(); QWidget *rc = factory->createWidget(parentWidget); // shouldn't happen if (!rc) { @@ -332,25 +341,33 @@ QWidget *WidgetFactory::createWidget(const QString &widgetName, QWidget *parentW return nullptr; // 2) Special widgets - if (widgetName == m_strings.m_line) { + if (widgetName == "Line"_L1) { w = new Line(parentWidget); - } else if (widgetName == m_strings.m_qDockWidget) { +#if QT_CONFIG(abstractbutton) + } else if (widgetName == u"QAbstractButton") { + w = new QDesignerAbstractButton(parentWidget); +#endif +#if QT_CONFIG(itemviews) + } else if (widgetName == u"QAbstractItemView") { + w = new QDesignerAbstractItemView(parentWidget); +#endif + } else if (widgetName == "QDockWidget"_L1) { w = new QDesignerDockWidget(parentWidget); - } else if (widgetName == m_strings.m_qMenuBar) { + } else if (widgetName == "QMenuBar"_L1) { w = new QDesignerMenuBar(parentWidget); - } else if (widgetName == m_strings.m_qMenu) { + } else if (widgetName == "QMenu"_L1) { w = new QDesignerMenu(parentWidget); - } else if (widgetName == m_strings.m_spacer) { + } else if (widgetName == "Spacer"_L1) { w = new Spacer(parentWidget); - } else if (widgetName == m_strings.m_qLayoutWidget) { + } else if (widgetName == "QLayoutWidget"_L1) { w = fw ? new QLayoutWidget(fw, parentWidget) : new QWidget(parentWidget); - } else if (widgetName == m_strings.m_qDialog) { + } else if (widgetName == "QDialog"_L1) { if (fw) { w = new QDesignerDialog(fw, parentWidget); } else { w = new QDialog(parentWidget); } - } else if (widgetName == m_strings.m_qWidget) { + } else if (widgetName == "QWidget"_L1) { /* We want a 'QDesignerWidget' that draws a grid only for widget * forms and container extension pages (not for preview and not * for normal QWidget children on forms (legacy) */ @@ -390,13 +407,13 @@ QWidget *WidgetFactory::createWidget(const QString &widgetName, QWidget *parentW if (w) break; // 4) fallBack - const QString fallBackBaseClass = m_strings.m_qWidget; + const QString fallBackBaseClass = "QWidget"_L1; QDesignerWidgetDataBaseInterface *db = core()->widgetDataBase(); QDesignerWidgetDataBaseItemInterface *item = db->item(db->indexOfClassName(widgetName)); if (item == nullptr) { // Emergency: Create, derived from QWidget QString includeFile = widgetName.toLower(); - includeFile += QStringLiteral(".h"); + includeFile += ".h"_L1; item = appendDerived(db,widgetName, tr("%1 Widget").arg(widgetName),fallBackBaseClass, includeFile, true, true); Q_ASSERT(item); @@ -431,27 +448,27 @@ QString WidgetFactory::classNameOf(QDesignerFormEditorInterface *c, const QObjec const char *className = o->metaObject()->className(); if (!o->isWidgetType()) - return QLatin1String(className); + return QLatin1StringView(className); const QWidget *w = static_cast<const QWidget*>(o); // check promoted before designer special const QString customClassName = promotedCustomClassName(c, const_cast<QWidget*>(w)); if (!customClassName.isEmpty()) return customClassName; if (qobject_cast<const QDesignerMenuBar*>(w)) - return QStringLiteral("QMenuBar"); + return u"QMenuBar"_s; if (qobject_cast<const QDesignerMenu*>(w)) - return QStringLiteral("QMenu"); + return u"QMenu"_s; if (qobject_cast<const QDesignerDockWidget*>(w)) - return QStringLiteral("QDockWidget"); + return u"QDockWidget"_s; if (qobject_cast<const QDesignerDialog*>(w)) - return QStringLiteral("QDialog"); + return u"QDialog"_s; if (qobject_cast<const QDesignerWidget*>(w)) - return QStringLiteral("QWidget"); + return u"QWidget"_s; #ifdef Q_OS_WIN if (isAxWidget(w)) - return QStringLiteral("QAxWidget"); + return u"QAxWidget"_s; #endif - return QLatin1String(className); + return QLatin1StringView(className); } QLayout *WidgetFactory::createUnmanagedLayout(QWidget *parentWidget, int type) @@ -508,15 +525,15 @@ QLayout *WidgetFactory::createLayout(QWidget *widget, QLayout *parentLayout, int QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), layout); if (sheet) { - sheet->setChanged(sheet->indexOf(m_strings.m_objectName), true); + sheet->setChanged(sheet->indexOf(u"objectName"_s), true); if (widget->inherits("QLayoutWidget")) { - sheet->setProperty(sheet->indexOf(m_strings.m_leftMargin), 0); - sheet->setProperty(sheet->indexOf(m_strings.m_topMargin), 0); - sheet->setProperty(sheet->indexOf(m_strings.m_rightMargin), 0); - sheet->setProperty(sheet->indexOf(m_strings.m_bottomMargin), 0); + sheet->setProperty(sheet->indexOf(u"leftMargin"_s), 0); + sheet->setProperty(sheet->indexOf(u"topMargin"_s), 0); + sheet->setProperty(sheet->indexOf(u"rightMargin"_s), 0); + sheet->setProperty(sheet->indexOf(u"bottomMargin"_s), 0); } - const int index = sheet->indexOf(m_strings.m_alignment); + const int index = sheet->indexOf(u"alignment"_s); if (index != -1) sheet->setChanged(index, true); } @@ -615,11 +632,11 @@ void WidgetFactory::initialize(QObject *object) const if (!sheet) return; - sheet->setChanged(sheet->indexOf(m_strings.m_objectName), true); + sheet->setChanged(sheet->indexOf(u"objectName"_s), true); if (!object->isWidgetType()) { if (qobject_cast<QAction*>(object)) - sheet->setChanged(sheet->indexOf(m_strings.m_text), true); + sheet->setChanged(sheet->indexOf(u"text"_s), true); return; } @@ -631,32 +648,32 @@ void WidgetFactory::initialize(QObject *object) const widget->setFocusPolicy((isMenu || isMenuBar) ? Qt::StrongFocus : Qt::NoFocus); if (!isMenu) - sheet->setChanged(sheet->indexOf(m_strings.m_geometry), true); + sheet->setChanged(sheet->indexOf(u"geometry"_s), true); if (qobject_cast<Spacer*>(widget)) { - sheet->setChanged(sheet->indexOf(m_strings.m_spacerName), true); + sheet->setChanged(sheet->indexOf(u"spacerName"_s), true); return; } - const int o = sheet->indexOf(m_strings.m_orientation); + const int o = sheet->indexOf(u"orientation"_s); if (o != -1 && widget->inherits("QSplitter")) sheet->setChanged(o, true); if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) { ToolBarEventFilter::install(toolBar); - sheet->setVisible(sheet->indexOf(m_strings.m_windowTitle), true); + sheet->setVisible(sheet->indexOf(u"windowTitle"_s), true); toolBar->setFloatable(false); // prevent toolbars from being dragged off return; } if (qobject_cast<QDockWidget*>(widget)) { - sheet->setVisible(sheet->indexOf(m_strings.m_windowTitle), true); - sheet->setVisible(sheet->indexOf(m_strings.m_windowIcon), true); + sheet->setVisible(sheet->indexOf(u"windowTitle"_s), true); + sheet->setVisible(sheet->indexOf(u"windowIcon"_s), true); return; } if (isMenu) { - sheet->setChanged(sheet->indexOf(m_strings.m_title), true); + sheet->setChanged(sheet->indexOf(u"title"_s), true); return; } // helpers @@ -694,7 +711,7 @@ void WidgetFactory::initialize(QObject *object) const static inline QString classNameOfStyle(const QStyle *s) { - return QLatin1String(s->metaObject()->className()); + return QLatin1StringView(s->metaObject()->className()); } QString WidgetFactory::styleName() const @@ -722,7 +739,7 @@ QStyle *WidgetFactory::getStyle(const QString &styleName) if (isApplicationStyle(styleName)) return qApp->style(); - StyleCache::iterator it = m_styleCache.find(styleName); + auto it = m_styleCache.find(styleName); if (it == m_styleCache.end()) { QStyle *style = QStyleFactory::create(styleName); if (!style) { @@ -752,9 +769,8 @@ void WidgetFactory::applyStyleToTopLevel(QStyle *style, QWidget *widget) widget->setStyle(style); widget->setPalette(standardPalette); const QWidgetList lst = widget->findChildren<QWidget*>(); - const QWidgetList::const_iterator cend = lst.constEnd(); - for (QWidgetList::const_iterator it = lst.constBegin(); it != cend; ++it) - (*it)->setStyle(style); + for (auto *w : lst) + w->setStyle(style); } // Check for 'interactor' click on a tab bar, @@ -791,9 +807,6 @@ static bool isTabBarInteractor(const QTabBar *tabBar) static bool isPassiveInteractorHelper(const QWidget *widget) { - static const QString qtPassive = QStringLiteral("__qt__passive_"); - static const QString qtMainWindowSplitter = QStringLiteral("qt_qmainwindow_extended_splitter"); - if (qobject_cast<const QMenuBar*>(widget) #if QT_CONFIG(sizegrip) || qobject_cast<const QSizeGrip*>(widget) @@ -813,10 +826,8 @@ static bool isPassiveInteractorHelper(const QWidget *widget) } else if (qobject_cast<const QScrollBar*>(widget)) { // A scroll bar is an interactor on a QAbstractScrollArea only. if (auto parent = widget->parentWidget()) { - const QString objectName = parent->objectName(); - static const QString scrollAreaVContainer = QStringLiteral("qt_scrollarea_vcontainer"); - static const QString scrollAreaHContainer = QStringLiteral("qt_scrollarea_hcontainer"); - if (objectName == scrollAreaVContainer || objectName == scrollAreaHContainer) + const QString &objectName = parent->objectName(); + if (objectName == "qt_scrollarea_vcontainer"_L1 || objectName == "qt_scrollarea_hcontainer"_L1) return true; } } else if (qstrcmp(widget->metaObject()->className(), "QDockWidgetTitle") == 0) { @@ -825,7 +836,8 @@ static bool isPassiveInteractorHelper(const QWidget *widget) return true; } const QString &name = widget->objectName(); - return name.startsWith(qtPassive) || name == qtMainWindowSplitter; + return name.startsWith("__qt__passive_"_L1) + || name == "qt_qmainwindow_extended_splitter"_L1; } bool WidgetFactory::isPassiveInteractor(QWidget *widget) diff --git a/src/designer/src/lib/shared/widgetfactory_p.h b/src/designer/src/lib/shared/widgetfactory_p.h index e9fd4bfe6..6844ed578 100644 --- a/src/designer/src/lib/shared/widgetfactory_p.h +++ b/src/designer/src/lib/shared/widgetfactory_p.h @@ -1,30 +1,8 @@ -/**************************************************************************** -** -** 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 // // W A R N I N G @@ -119,49 +97,17 @@ public slots: void formWindowAdded(QDesignerFormWindowInterface *formWindow); private: - struct Strings { // Reduce string allocations by storing predefined strings - Strings(); - const QString m_alignment; - const QString m_bottomMargin; - const QString m_geometry; - const QString m_leftMargin; - const QString m_line; - const QString m_objectName; - const QString m_spacerName; - const QString m_orientation; - const QString m_qAction; - const QString m_qButtonGroup; - const QString m_qAxWidget; - const QString m_qDialog; - const QString m_qDockWidget; - const QString m_qLayoutWidget; - const QString m_qMenu; - const QString m_qMenuBar; - const QString m_qWidget; - const QString m_rightMargin; - const QString m_sizeHint; - const QString m_spacer; - const QString m_text; - const QString m_title; - const QString m_topMargin; - const QString m_windowIcon; - const QString m_windowTitle; - }; - QWidget* createCustomWidget(const QString &className, QWidget *parentWidget, bool *creationError) const; QDesignerFormWindowInterface *findFormWindow(QWidget *parentWidget) const; void setFormWindowStyle(QDesignerFormWindowInterface *formWindow); - const Strings m_strings; QDesignerFormEditorInterface *m_core; - using CustomWidgetFactoryMap = QMap<QString, QDesignerCustomWidgetInterface*>; - CustomWidgetFactoryMap m_customFactory; + QMap<QString, QDesignerCustomWidgetInterface *> m_customFactory; QDesignerFormWindowInterface *m_formWindow; // Points to the cached style or 0 if the default (qApp) is active QStyle *m_currentStyle; - using StyleCache = QHash<QString, QStyle *>; - StyleCache m_styleCache; + QHash<QString, QStyle *> m_styleCache; }; } // namespace qdesigner_internal diff --git a/src/designer/src/lib/shared/zoomwidget.cpp b/src/designer/src/lib/shared/zoomwidget.cpp index 6c947f4ac..57968920c 100644 --- a/src/designer/src/lib/shared/zoomwidget.cpp +++ b/src/designer/src/lib/shared/zoomwidget.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 "zoomwidget_p.h" @@ -44,6 +19,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + enum { debugZoomWidget = 0 }; static const int menuZoomList[] = { 100, 25, 50, 75, 125, 150 , 175, 200 }; @@ -249,7 +226,7 @@ QVariant ZoomProxyWidget::itemChange(GraphicsItemChange change, const QVariant & * It redirects the events to another handler of ZoomWidget as its * base class QScrollArea also implements eventFilter() for its viewport. */ -static const char *zoomedEventFilterRedirectorNameC = "__qt_ZoomedEventFilterRedirector"; +static constexpr auto zoomedEventFilterRedirectorNameC = "__qt_ZoomedEventFilterRedirector"_L1; class ZoomedEventFilterRedirector : public QObject { Q_DISABLE_COPY_MOVE(ZoomedEventFilterRedirector) @@ -266,7 +243,7 @@ ZoomedEventFilterRedirector::ZoomedEventFilterRedirector(ZoomWidget *zw, QObject QObject(parent), m_zw(zw) { - setObjectName(QLatin1String(zoomedEventFilterRedirectorNameC)); + setObjectName(zoomedEventFilterRedirectorNameC); } bool ZoomedEventFilterRedirector::eventFilter(QObject *watched, QEvent *event) @@ -293,7 +270,7 @@ void ZoomWidget::setWidget(QWidget *w, Qt::WindowFlags wFlags) scene().removeItem(m_proxy); if (QWidget *w = m_proxy->widget()) { // remove the event filter - if (QObject *evf = w->findChild<QObject*>(QLatin1String(zoomedEventFilterRedirectorNameC))) + if (QObject *evf = w->findChild<QObject*>(zoomedEventFilterRedirectorNameC)) w->removeEventFilter(evf); } m_proxy->deleteLater(); diff --git a/src/designer/src/lib/shared/zoomwidget_p.h b/src/designer/src/lib/shared/zoomwidget_p.h index 1830be4be..0e8a602eb 100644 --- a/src/designer/src/lib/shared/zoomwidget_p.h +++ b/src/designer/src/lib/shared/zoomwidget_p.h @@ -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 // // W A R N I N G |