diff options
Diffstat (limited to 'src/designer/src/lib/shared/actionrepository.cpp')
-rw-r--r-- | src/designer/src/lib/shared/actionrepository.cpp | 81 |
1 files changed, 31 insertions, 50 deletions
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)); } |