summaryrefslogtreecommitdiffstats
path: root/src/designer
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-23 14:16:42 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-02-28 15:44:05 +0100
commit4af9febe4f5ac0fe68bd4165047c738eac501002 (patch)
tree0bc5b55fd9b3ccc8fe17c032e26b95e10444e455 /src/designer
parent16128af06741c9d81cf68a2f4c5a807f79d8a8bb (diff)
Qt Designer: Refactor the icon loader helper function createIconSet()
Split createIconSet(const QString &) into overloads for QLatin1StringView and QStringView (the latter mainly for QDesignerFormEditorInterface::createIcon(QString)). Add an overload that takes a QIcon::ThemeIcon value and returns the theme icon before going on a file search to replace the QIcon::fromTheme() calls. Pick-to: 6.7 Change-Id: I95d2c3d73139e330fcc86f404f176494a50c0ef3 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/designer')
-rw-r--r--src/designer/src/components/formeditor/formwindowmanager.cpp16
-rw-r--r--src/designer/src/designer/appfontdialog.cpp3
-rw-r--r--src/designer/src/lib/shared/actioneditor.cpp20
-rw-r--r--src/designer/src/lib/shared/iconloader.cpp22
-rw-r--r--src/designer/src/lib/shared/iconloader_p.h7
-rw-r--r--src/designer/src/lib/shared/qtresourceview.cpp12
6 files changed, 50 insertions, 30 deletions
diff --git a/src/designer/src/components/formeditor/formwindowmanager.cpp b/src/designer/src/components/formeditor/formwindowmanager.cpp
index ad304014b..1d1b8f217 100644
--- a/src/designer/src/components/formeditor/formwindowmanager.cpp
+++ b/src/designer/src/components/formeditor/formwindowmanager.cpp
@@ -342,8 +342,8 @@ QWidget *FormWindowManager::findManagedWidget(FormWindow *fw, QWidget *w)
void FormWindowManager::setupActions()
{
#if QT_CONFIG(clipboard)
- const QIcon cutIcon = QIcon::fromTheme(QIcon::ThemeIcon::EditCut,
- createIconSet(u"editcut.png"_s));
+ const QIcon cutIcon = createIconSet(QIcon::ThemeIcon::EditCut,
+ "editcut.png"_L1);
m_actionCut = new QAction(cutIcon, tr("Cu&t"), this);
m_actionCut->setObjectName(u"__qt_cut_action"_s);
m_actionCut->setShortcut(QKeySequence::Cut);
@@ -352,8 +352,7 @@ void FormWindowManager::setupActions()
connect(m_actionCut, &QAction::triggered, this, &FormWindowManager::slotActionCutActivated);
m_actionCut->setEnabled(false);
- const QIcon copyIcon = QIcon::fromTheme(QIcon::ThemeIcon::EditCopy,
- createIconSet(u"editcopy.png"_s));
+ const QIcon copyIcon = createIconSet(QIcon::ThemeIcon::EditCopy, "editcopy.png"_L1);
m_actionCopy = new QAction(copyIcon, tr("&Copy"), this);
m_actionCopy->setObjectName(u"__qt_copy_action"_s);
m_actionCopy->setShortcut(QKeySequence::Copy);
@@ -362,8 +361,7 @@ void FormWindowManager::setupActions()
connect(m_actionCopy, &QAction::triggered, this, &FormWindowManager::slotActionCopyActivated);
m_actionCopy->setEnabled(false);
- const QIcon pasteIcon = QIcon::fromTheme(QIcon::ThemeIcon::EditPaste,
- createIconSet(u"editpaste.png"_s));
+ const QIcon pasteIcon = createIconSet(QIcon::ThemeIcon::EditPaste, "editpaste.png"_L1);
m_actionPaste = new QAction(pasteIcon, tr("&Paste"), this);
m_actionPaste->setObjectName(u"__qt_paste_action"_s);
m_actionPaste->setShortcut(QKeySequence::Paste);
@@ -507,12 +505,10 @@ void FormWindowManager::setupActions()
m_actionUndo = m_undoGroup->createUndoAction(this);
m_actionUndo->setEnabled(false);
- m_actionUndo->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::EditUndo,
- createIconSet(u"undo.png"_s)));
+ m_actionUndo->setIcon(createIconSet(QIcon::ThemeIcon::EditUndo, "undo.png"_L1));
m_actionRedo = m_undoGroup->createRedoAction(this);
m_actionRedo->setEnabled(false);
- m_actionRedo->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::EditRedo,
- createIconSet(u"redo.png"_s)));
+ m_actionRedo->setIcon(createIconSet(QIcon::ThemeIcon::EditRedo, "redo.png"_L1));
m_actionShowFormWindowSettingsDialog = new QAction(tr("Form &Settings..."), this);
m_actionShowFormWindowSettingsDialog->setObjectName(u"__qt_form_settings_action"_s);
diff --git a/src/designer/src/designer/appfontdialog.cpp b/src/designer/src/designer/appfontdialog.cpp
index d6ccd3b9b..6b8bf691d 100644
--- a/src/designer/src/designer/appfontdialog.cpp
+++ b/src/designer/src/designer/appfontdialog.cpp
@@ -261,7 +261,8 @@ AppFontWidget::AppFontWidget(QWidget *parent) :
connect(m_removeButton, &QAbstractButton::clicked, this, &AppFontWidget::slotRemoveFiles);
m_removeAllButton->setToolTip(tr("Remove all font files"));
- m_removeAllButton->setIcon(qdesigner_internal::createIconSet(u"editdelete.png"_s));
+ m_removeAllButton->setIcon(qdesigner_internal::createIconSet(QIcon::ThemeIcon::EditDelete,
+ "editdelete.png"_L1));
connect(m_removeAllButton, &QAbstractButton::clicked, this, &AppFontWidget::slotRemoveAll);
QHBoxLayout *hLayout = new QHBoxLayout;
diff --git a/src/designer/src/lib/shared/actioneditor.cpp b/src/designer/src/lib/shared/actioneditor.cpp
index 7ae504fd4..36740da9b 100644
--- a/src/designer/src/lib/shared/actioneditor.cpp
+++ b/src/designer/src/lib/shared/actioneditor.cpp
@@ -114,8 +114,8 @@ ActionEditor::ActionEditor(QDesignerFormEditorInterface *core, QWidget *parent,
toolbar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
l->addWidget(toolbar);
// edit actions
- QIcon documentNewIcon = QIcon::fromTheme(QIcon::ThemeIcon::DocumentNew,
- createIconSet(u"filenew.png"_s));
+ 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);
@@ -126,20 +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(QIcon::ThemeIcon::EditCut,
- createIconSet(u"editcut.png"_s));
+ 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(QIcon::ThemeIcon::EditCopy,
- createIconSet(u"editcopy.png"_s));
+ 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(QIcon::ThemeIcon::EditPaste,
- createIconSet(u"editpaste.png"_s));
+ QIcon editPasteIcon = createIconSet(QIcon::ThemeIcon::EditPaste,
+ "editpaste.png"_L1);
m_actionPaste->setIcon(editPasteIcon);
toolbar->addAction(m_actionPaste);
#endif
@@ -149,8 +149,8 @@ ActionEditor::ActionEditor(QDesignerFormEditorInterface *core, QWidget *parent,
connect(m_actionNavigateToSlot, &QAction::triggered, this, &ActionEditor::navigateToSlotCurrentAction);
- QIcon editDeleteIcon = QIcon::fromTheme(QIcon::ThemeIcon::EditDelete,
- createIconSet(u"editdelete.png"_s));
+ 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);
diff --git a/src/designer/src/lib/shared/iconloader.cpp b/src/designer/src/lib/shared/iconloader.cpp
index 4789548a6..042b3da34 100644
--- a/src/designer/src/lib/shared/iconloader.cpp
+++ b/src/designer/src/lib/shared/iconloader.cpp
@@ -13,7 +13,15 @@ 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)
+{
+ return 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,
@@ -31,7 +39,17 @@ QDESIGNER_SHARED_EXPORT QIcon createIconSet(const QString &name)
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()
diff --git a/src/designer/src/lib/shared/iconloader_p.h b/src/designer/src/lib/shared/iconloader_p.h
index 14c7edeb5..c054d677c 100644
--- a/src/designer/src/lib/shared/iconloader_p.h
+++ b/src/designer/src/lib/shared/iconloader_p.h
@@ -17,6 +17,8 @@
#include "shared_global_p.h"
+#include <QtGui/qicon.h>
+
QT_BEGIN_NAMESPACE
class QString;
@@ -24,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/qtresourceview.cpp b/src/designer/src/lib/shared/qtresourceview.cpp
index d11000600..5663b0ddc 100644
--- a/src/designer/src/lib/shared/qtresourceview.cpp
+++ b/src/designer/src/lib/shared/qtresourceview.cpp
@@ -530,16 +530,16 @@ QtResourceView::QtResourceView(QDesignerFormEditorInterface *core, QWidget *pare
{
d_ptr->q_ptr = this;
- QIcon editIcon = QIcon::fromTheme(QIcon::ThemeIcon::DocumentProperties,
- qdesigner_internal::createIconSet(u"edit.png"_s));
+ 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, &QAction::triggered,
this, [this] { d_ptr->slotEditResources(); });
d_ptr->m_editResourcesAction->setEnabled(false);
- QIcon refreshIcon = QIcon::fromTheme(QIcon::ThemeIcon::ViewRefresh,
- qdesigner_internal::createIconSet(u"reload.png"_s));
+ 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);
@@ -548,8 +548,8 @@ QtResourceView::QtResourceView(QDesignerFormEditorInterface *core, QWidget *pare
d_ptr->m_reloadResourcesAction->setEnabled(false);
#if QT_CONFIG(clipboard)
- QIcon copyIcon = QIcon::fromTheme(QIcon::ThemeIcon::EditCopy,
- qdesigner_internal::createIconSet(u"editcopy.png"_s));
+ 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, &QAction::triggered,
this, [this] { d_ptr->slotCopyResourcePath(); });