diff options
Diffstat (limited to 'src/designer/src/components/widgetbox')
11 files changed, 128 insertions, 388 deletions
diff --git a/src/designer/src/components/widgetbox/widgetbox.cpp b/src/designer/src/components/widgetbox/widgetbox.cpp index bf42f2048..7294799f9 100644 --- a/src/designer/src/components/widgetbox/widgetbox.cpp +++ b/src/designer/src/components/widgetbox/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 "widgetbox.h" #include "widgetboxtreewidget.h" @@ -110,7 +85,7 @@ WidgetBox::WidgetBox(QDesignerFormEditorInterface *core, QWidget *parent, Qt::Wi l->addWidget(toolBar); // View - connect(m_view, &WidgetBoxTreeWidget::pressed, + connect(m_view, &WidgetBoxTreeWidget::widgetBoxPressed, this, &WidgetBox::handleMousePress); l->addWidget(m_view); diff --git a/src/designer/src/components/widgetbox/widgetbox.h b/src/designer/src/components/widgetbox/widgetbox.h index 27e1b461a..cf43b63b4 100644 --- a/src/designer/src/components/widgetbox/widgetbox.h +++ b/src/designer/src/components/widgetbox/widgetbox.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 WIDGETBOX_H #define WIDGETBOX_H diff --git a/src/designer/src/components/widgetbox/widgetbox.qrc b/src/designer/src/components/widgetbox/widgetbox.qrc deleted file mode 100644 index 2cac8a95e..000000000 --- a/src/designer/src/components/widgetbox/widgetbox.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/qt-project.org/widgetbox"> - <file>widgetbox.xml</file> - </qresource> -</RCC> diff --git a/src/designer/src/components/widgetbox/widgetbox.xml b/src/designer/src/components/widgetbox/widgetbox.xml index 802c28f67..4cb29cd20 100644 --- a/src/designer/src/components/widgetbox/widgetbox.xml +++ b/src/designer/src/components/widgetbox/widgetbox.xml @@ -1,31 +1,7 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!--/*************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Linguist module 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 +--> <widgetbox version="4.2"> <category name="Layouts"> diff --git a/src/designer/src/components/widgetbox/widgetbox_dnditem.cpp b/src/designer/src/components/widgetbox/widgetbox_dnditem.cpp index c44fa4169..afbfc0567 100644 --- a/src/designer/src/components/widgetbox/widgetbox_dnditem.cpp +++ b/src/designer/src/components/widgetbox/widgetbox_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 "widgetbox_dnditem.h" @@ -47,6 +22,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace qdesigner_internal { /******************************************************************************* ** WidgetBoxResource @@ -83,7 +60,7 @@ WidgetBoxResource::WidgetBoxResource(QDesignerFormEditorInterface *core) : QWidget *WidgetBoxResource::createWidget(const QString &widgetName, QWidget *parentWidget, const QString &name) { - if (widgetName == QStringLiteral("Spacer")) { + if (widgetName == "Spacer"_L1) { Spacer *spacer = new Spacer(parentWidget); spacer->setObjectName(name); return spacer; @@ -124,9 +101,8 @@ void WidgetBoxResource::createCustomWidgets(DomCustomWidgets *dc) static QSize geometryProp(const DomWidget *dw) { const auto &prop_list = dw->elementProperty(); - const QString geometry = QStringLiteral("geometry"); for (DomProperty *prop : prop_list) { - if (prop->attributeName() != geometry) + if (prop->attributeName() != "geometry"_L1) continue; DomRect *dr = prop->elementRect(); if (dr == nullptr) diff --git a/src/designer/src/components/widgetbox/widgetbox_dnditem.h b/src/designer/src/components/widgetbox/widgetbox_dnditem.h index 1a5e3bade..f8f25d58e 100644 --- a/src/designer/src/components/widgetbox/widgetbox_dnditem.h +++ b/src/designer/src/components/widgetbox/widgetbox_dnditem.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 WIDGETBOX_DNDITEM_H #define WIDGETBOX_DNDITEM_H diff --git a/src/designer/src/components/widgetbox/widgetbox_global.h b/src/designer/src/components/widgetbox/widgetbox_global.h index 06f0e2b7c..68ebc3554 100644 --- a/src/designer/src/components/widgetbox/widgetbox_global.h +++ b/src/designer/src/components/widgetbox/widgetbox_global.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 WIDGETBOX_GLOBAL_H #define WIDGETBOX_GLOBAL_H diff --git a/src/designer/src/components/widgetbox/widgetboxcategorylistview.cpp b/src/designer/src/components/widgetbox/widgetboxcategorylistview.cpp index 2f5b7f536..1e90ef08e 100644 --- a/src/designer/src/components/widgetbox/widgetboxcategorylistview.cpp +++ b/src/designer/src/components/widgetbox/widgetboxcategorylistview.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 "widgetboxcategorylistview.h" @@ -46,13 +21,15 @@ #include <QtCore/qtextstream.h> #include <QtCore/qregularexpression.h> -static const char *widgetElementC = "widget"; -static const char *nameAttributeC = "name"; -static const char *uiOpeningTagC = "<ui>"; -static const char *uiClosingTagC = "</ui>"; - QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + +static constexpr auto widgetElementC = "widget"_L1; +static constexpr auto nameAttributeC = "name"_L1; +static constexpr auto uiOpeningTagC = "<ui>"_L1; +static constexpr auto uiClosingTagC = "</ui>"_L1; + enum { FilterRole = Qt::UserRole + 11 }; static QString domToString(const QDomElement &elt) @@ -130,10 +107,8 @@ public: bool removeCustomWidgets(); private: - using WidgetBoxCategoryEntrys = QList<WidgetBoxCategoryEntry>; - QDesignerFormEditorInterface *m_core; - WidgetBoxCategoryEntrys m_items; + QList<WidgetBoxCategoryEntry> m_items; QListView::ViewMode m_viewMode; }; @@ -163,8 +138,7 @@ void WidgetBoxCategoryModel::setViewMode(QListView::ViewMode vm) int WidgetBoxCategoryModel::indexOfWidget(const QString &name) { - const int count = m_items.size(); - for (int i = 0; i < count; i++) + for (qsizetype i = 0, count = m_items.size(); i < count; ++i) if (m_items.at(i).widget.name() == name) return i; return -1; @@ -173,9 +147,8 @@ int WidgetBoxCategoryModel::indexOfWidget(const QString &name) QDesignerWidgetBoxInterface::Category WidgetBoxCategoryModel::category() const { QDesignerWidgetBoxInterface::Category rc; - const WidgetBoxCategoryEntrys::const_iterator cend = m_items.constEnd(); - for (WidgetBoxCategoryEntrys::const_iterator it = m_items.constBegin(); it != cend; ++it) - rc.addWidget(it->widget); + for (const auto &c : m_items) + rc.addWidget(c.widget); return rc; } @@ -184,7 +157,7 @@ bool WidgetBoxCategoryModel::removeCustomWidgets() // Typically, we are a whole category of custom widgets, so, remove all // and do reset. bool changed = false; - for (WidgetBoxCategoryEntrys::iterator it = m_items.begin(); it != m_items.end(); ) + for (auto it = m_items.begin(); it != m_items.end(); ) if (it->widget.type() == QDesignerWidgetBoxInterface::Widget::Custom) { if (!changed) beginResetModel(); @@ -200,21 +173,21 @@ bool WidgetBoxCategoryModel::removeCustomWidgets() void WidgetBoxCategoryModel::addWidget(const QDesignerWidgetBoxInterface::Widget &widget, const QIcon &icon,bool editable) { - // build item. Filter on name + class name if it is different and not a layout. + static const QRegularExpression classNameRegExp(QStringLiteral("<widget +class *= *\"([^\"]+)\"")); + Q_ASSERT(classNameRegExp.isValid()); + const auto match = classNameRegExp.match(widget.domXml()); + const QString className = match.hasMatch() ? match.captured(1) : QString{}; + + // Filter on name + class name if it is different and not a layout. QString filter = widget.name(); - if (!filter.contains(QStringLiteral("Layout"))) { - static const QRegularExpression classNameRegExp(QStringLiteral("<widget +class *= *\"([^\"]+)\"")); - Q_ASSERT(classNameRegExp.isValid()); - const QRegularExpressionMatch match = classNameRegExp.match(widget.domXml()); - if (match.hasMatch()) { - const QString className = match.captured(1); - if (!filter.contains(className)) - filter += className; - } - } + if (!className.isEmpty() && !filter.contains("Layout"_L1) && !filter.contains(className)) + filter += className; + WidgetBoxCategoryEntry item(widget, filter, icon, editable); const QDesignerWidgetDataBaseInterface *db = m_core->widgetDataBase(); - const int dbIndex = db->indexOfClassName(widget.name()); + int dbIndex = className.isEmpty() ? -1 : db->indexOfClassName(className); + if (dbIndex == -1) + dbIndex = db->indexOfClassName(widget.name()); if (dbIndex != -1) { const QDesignerWidgetDataBaseItemInterface *dbItem = db->item(dbIndex); const QString toolTip = dbItem->toolTip(); @@ -251,10 +224,8 @@ QVariant WidgetBoxCategoryModel::data(const QModelIndex &index, int role) const return QVariant(item.toolTip); // Icon mode tooltip should contain the class name QString tt = item.widget.name(); - if (!item.toolTip.isEmpty()) { - tt += QLatin1Char('\n'); - tt += item.toolTip; - } + if (!item.toolTip.isEmpty()) + tt += u'\n' + item.toolTip; return QVariant(tt); } @@ -279,9 +250,9 @@ bool WidgetBoxCategoryModel::setData(const QModelIndex &index, const QVariant &v item.widget.setName(newName); const QDomDocument doc = stringToDom(WidgetBoxCategoryListView::widgetDomXml(item.widget)); - QDomElement widget_elt = doc.firstChildElement(QLatin1String(widgetElementC)); + QDomElement widget_elt = doc.firstChildElement(widgetElementC); if (!widget_elt.isNull()) { - widget_elt.setAttribute(QLatin1String(nameAttributeC), newName); + widget_elt.setAttribute(nameAttributeC, newName); item.widget.setDomXml(domToString(widget_elt)); } emit dataChanged(index, index); @@ -351,7 +322,7 @@ QWidget *WidgetBoxCategoryEntryDelegate::createEditor(QWidget *parent, { QWidget *result = QItemDelegate::createEditor(parent, option, index); if (QLineEdit *line_edit = qobject_cast<QLineEdit*>(result)) { - static const QRegularExpression re(QStringLiteral("^[_a-zA-Z][_a-zA-Z0-9]*$")); + static const QRegularExpression re(u"^[_a-zA-Z][_a-zA-Z0-9]*$"_s); Q_ASSERT(re.isValid()); line_edit->setValidator(new QRegularExpressionValidator(re, line_edit)); } @@ -409,7 +380,7 @@ void WidgetBoxCategoryListView::slotPressed(const QModelIndex &index) const QDesignerWidgetBoxInterface::Widget wgt = m_model->widgetAt(m_proxyModel->mapToSource(index)); if (wgt.isNull()) return; - emit pressed(wgt.name(), widgetDomXml(wgt), QCursor::pos()); + emit widgetBoxPressed(wgt.name(), widgetDomXml(wgt), QCursor::pos()); } void WidgetBoxCategoryListView::removeCurrentItem() @@ -475,13 +446,8 @@ QString WidgetBoxCategoryListView::widgetDomXml(const QDesignerWidgetBoxInterfac { QString domXml = widget.domXml(); - if (domXml.isEmpty()) { - domXml = QLatin1String(uiOpeningTagC); - domXml += QStringLiteral("<widget class=\""); - domXml += widget.name(); - domXml += QStringLiteral("\"/>"); - domXml += QLatin1String(uiClosingTagC); - } + if (domXml.isEmpty()) + domXml = uiOpeningTagC + "<widget class=\""_L1 + widget.name() +"\"/>"_L1 + uiClosingTagC; return domXml; } diff --git a/src/designer/src/components/widgetbox/widgetboxcategorylistview.h b/src/designer/src/components/widgetbox/widgetboxcategorylistview.h index 28db852f6..9223a2f49 100644 --- a/src/designer/src/components/widgetbox/widgetboxcategorylistview.h +++ b/src/designer/src/components/widgetbox/widgetboxcategorylistview.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 WIDGETBOXCATEGORYLISTVIEW_H #define WIDGETBOXCATEGORYLISTVIEW_H @@ -79,7 +54,7 @@ public: signals: void scratchPadChanged(); - void pressed(const QString &name, const QString &xml, const QPoint &globalPos); + void widgetBoxPressed(const QString &name, const QString &xml, const QPoint &globalPos); void itemRemoved(); void lastItemRemoved(); diff --git a/src/designer/src/components/widgetbox/widgetboxtreewidget.cpp b/src/designer/src/components/widgetbox/widgetboxtreewidget.cpp index 1fef65ffb..4dca4a1d1 100644 --- a/src/designer/src/components/widgetbox/widgetboxtreewidget.cpp +++ b/src/designer/src/components/widgetbox/widgetboxtreewidget.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 "widgetboxtreewidget.h" #include "widgetboxcategorylistview.h" @@ -57,23 +32,25 @@ #include <QtCore/qtimer.h> #include <QtCore/qdebug.h> -static const char *widgetBoxRootElementC = "widgetbox"; -static const char *widgetElementC = "widget"; -static const char *uiElementC = "ui"; -static const char *categoryElementC = "category"; -static const char *categoryEntryElementC = "categoryentry"; -static const char *nameAttributeC = "name"; -static const char *typeAttributeC = "type"; -static const char *iconAttributeC = "icon"; -static const char *defaultTypeValueC = "default"; -static const char *customValueC = "custom"; -static const char *iconPrefixC = "__qt_icon__"; -static const char *scratchPadValueC = "scratchpad"; -static const char *invisibleNameC = "[invisible]"; +QT_BEGIN_NAMESPACE -enum TopLevelRole { NORMAL_ITEM, SCRATCHPAD_ITEM, CUSTOM_ITEM }; +using namespace Qt::StringLiterals; + +static constexpr auto widgetBoxRootElementC = "widgetbox"_L1; +static constexpr auto wbWidgetElementC = "widget"_L1; +static constexpr auto uiElementC = "ui"_L1; +static constexpr auto categoryElementC = "category"_L1; +static constexpr auto categoryEntryElementC = "categoryentry"_L1; +static constexpr auto wbNameAttributeC = "name"_L1; +static constexpr auto typeAttributeC = "type"_L1; +static constexpr auto iconAttributeC = "icon"_L1; +static constexpr auto defaultTypeValueC = "default"_L1; +static constexpr auto customValueC = "custom"_L1; +static constexpr auto iconPrefixC = "__qt_icon__"_L1; +static constexpr auto scratchPadValueC = "scratchpad"_L1; +static constexpr auto invisibleNameC = "[invisible]"_L1; -QT_BEGIN_NAMESPACE +enum TopLevelRole { NORMAL_ITEM, SCRATCHPAD_ITEM, CUSTOM_ITEM }; static void setTopLevelRole(TopLevelRole tlr, QTreeWidgetItem *item) { @@ -113,8 +90,8 @@ QIcon WidgetBoxTreeWidget::iconForWidget(const QString &iconName) const if (iconName.isEmpty()) return qdesigner_internal::qtLogoIcon(); - if (iconName.startsWith(QLatin1String(iconPrefixC))) { - const IconCache::const_iterator it = m_pluginIcons.constFind(iconName); + if (iconName.startsWith(iconPrefixC)) { + const auto it = m_pluginIcons.constFind(iconName); if (it != m_pluginIcons.constEnd()) return it.value(); } @@ -131,9 +108,9 @@ WidgetBoxCategoryListView *WidgetBoxTreeWidget::categoryViewAt(int idx) const return rc; } -static const char widgetBoxSettingsGroupC[] = "WidgetBox"; -static const char widgetBoxExpandedKeyC[] = "Closed categories"; -static const char widgetBoxViewModeKeyC[] = "View mode"; +static constexpr auto widgetBoxSettingsGroupC = "WidgetBox"_L1; +static constexpr auto widgetBoxExpandedKeyC = "Closed categories"_L1; +static constexpr auto widgetBoxViewModeKeyC = "View mode"_L1; void WidgetBoxTreeWidget::saveExpandedState() const { @@ -146,9 +123,9 @@ void WidgetBoxTreeWidget::saveExpandedState() const } } QDesignerSettingsInterface *settings = m_core->settingsManager(); - settings->beginGroup(QLatin1String(widgetBoxSettingsGroupC)); - settings->setValue(QLatin1String(widgetBoxExpandedKeyC), closedCategories); - settings->setValue(QLatin1String(widgetBoxViewModeKeyC), m_iconMode); + settings->beginGroup(widgetBoxSettingsGroupC); + settings->setValue(widgetBoxExpandedKeyC, closedCategories); + settings->setValue(widgetBoxViewModeKeyC, m_iconMode); settings->endGroup(); } @@ -156,10 +133,10 @@ void WidgetBoxTreeWidget::restoreExpandedState() { using StringSet = QSet<QString>; QDesignerSettingsInterface *settings = m_core->settingsManager(); - const QString groupKey = QLatin1String(widgetBoxSettingsGroupC) + QLatin1Char('/'); - m_iconMode = settings->value(groupKey + QLatin1String(widgetBoxViewModeKeyC)).toBool(); + const QString groupKey = widgetBoxSettingsGroupC + u'/'; + m_iconMode = settings->value(groupKey + widgetBoxViewModeKeyC).toBool(); updateViewMode(); - const auto &closedCategoryList = settings->value(groupKey + QLatin1String(widgetBoxExpandedKeyC), QStringList()).toStringList(); + const auto &closedCategoryList = settings->value(groupKey + widgetBoxExpandedKeyC, QStringList()).toStringList(); const StringSet closedCategories(closedCategoryList.cbegin(), closedCategoryList.cend()); expandAll(); if (closedCategories.isEmpty()) @@ -253,8 +230,8 @@ WidgetBoxCategoryListView *WidgetBoxTreeWidget::addCategoryView(QTreeWidgetItem categoryView->setViewMode(iconMode ? QListView::IconMode : QListView::ListMode); connect(categoryView, &WidgetBoxCategoryListView::scratchPadChanged, this, &WidgetBoxTreeWidget::slotSave); - connect(categoryView, &WidgetBoxCategoryListView::pressed, - this, &WidgetBoxTreeWidget::pressed); + connect(categoryView, &WidgetBoxCategoryListView::widgetBoxPressed, + this, &WidgetBoxTreeWidget::widgetBoxPressed); connect(categoryView, &WidgetBoxCategoryListView::itemRemoved, this, &WidgetBoxTreeWidget::slotScratchPadItemDeleted); connect(categoryView, &WidgetBoxCategoryListView::lastItemRemoved, @@ -325,7 +302,7 @@ bool WidgetBoxTreeWidget::loadContents(const QString &contents) return false; } - for (const Category &cat : qAsConst(cat_list)) + for (const Category &cat : std::as_const(cat_list)) addCategory(cat); addCustomCategories(false); @@ -345,9 +322,8 @@ void WidgetBoxTreeWidget::addCustomCategories(bool replace) } // re-add const CategoryList customList = loadCustomCategoryList(); - const CategoryList::const_iterator cend = customList.constEnd(); - for (CategoryList::const_iterator it = customList.constBegin(); it != cend; ++it) - addCategory(*it); + for (const auto &c : customList) + addCategory(c); } static inline QString msgXmlError(const QString &fileName, const QXmlStreamReader &r) @@ -377,33 +353,33 @@ bool WidgetBoxTreeWidget::readCategories(const QString &fileName, const QString switch (reader.readNext()) { case QXmlStreamReader::StartElement: { const auto tag = reader.name(); - if (tag == QLatin1String(widgetBoxRootElementC)) { + if (tag == widgetBoxRootElementC) { //<widgetbox version="4.5"> continue; } - if (tag == QLatin1String(categoryElementC)) { + if (tag == categoryElementC) { // <category name="Layouts"> const QXmlStreamAttributes attributes = reader.attributes(); - const QString categoryName = attributes.value(QLatin1String(nameAttributeC)).toString(); - if (categoryName == QLatin1String(invisibleNameC)) { + const QString categoryName = attributes.value(wbNameAttributeC).toString(); + if (categoryName == invisibleNameC) { ignoreEntries = true; } else { Category category(categoryName); - if (attributes.value(QLatin1String(typeAttributeC)) == QLatin1String(scratchPadValueC)) + if (attributes.value(typeAttributeC) == scratchPadValueC) category.setType(Category::Scratchpad); cats->push_back(category); } continue; } - if (tag == QLatin1String(categoryEntryElementC)) { + if (tag == categoryEntryElementC) { // <categoryentry name="Vertical Layout" icon="win/editvlayout.png" type="default"> if (!ignoreEntries) { QXmlStreamAttributes attr = reader.attributes(); - const QString widgetName = attr.value(QLatin1String(nameAttributeC)).toString(); - const QString widgetIcon = attr.value(QLatin1String(iconAttributeC)).toString(); + const QString widgetName = attr.value(wbNameAttributeC).toString(); + const QString widgetIcon = attr.value(iconAttributeC).toString(); const WidgetBoxTreeWidget::Widget::Type widgetType = - attr.value(QLatin1String(typeAttributeC)).toString() - == QLatin1String(customValueC) ? + attr.value(typeAttributeC).toString() + == customValueC ? WidgetBoxTreeWidget::Widget::Custom : WidgetBoxTreeWidget::Widget::Default; @@ -422,14 +398,14 @@ bool WidgetBoxTreeWidget::readCategories(const QString &fileName, const QString } case QXmlStreamReader::EndElement: { const auto tag = reader.name(); - if (tag == QLatin1String(widgetBoxRootElementC)) { + if (tag == widgetBoxRootElementC) { continue; } - if (tag == QLatin1String(categoryElementC)) { + if (tag == categoryElementC) { ignoreEntries = false; continue; } - if (tag == QLatin1String(categoryEntryElementC)) { + if (tag == categoryEntryElementC) { continue; } break; @@ -483,10 +459,10 @@ bool WidgetBoxTreeWidget::readWidget(Widget *w, const QString &xml, QXmlStreamRe if (nesting++ == 0) { // First element must be <ui> or (legacy) <widget> const auto name = r.name(); - if (name == QLatin1String(uiElementC)) { + if (name == uiElementC) { startTagPosition = currentPosition; } else { - if (name == QLatin1String(widgetElementC)) { + if (name == wbWidgetElementC) { startTagPosition = currentPosition; parsedWidgetTag = true; } else { @@ -496,7 +472,7 @@ bool WidgetBoxTreeWidget::readWidget(Widget *w, const QString &xml, QXmlStreamRe } } else { // We are within <ui> looking for the first <widget> tag - if (!parsedWidgetTag && r.name() == QLatin1String(widgetElementC)) { + if (!parsedWidgetTag && r.name() == wbWidgetElementC) { parsedWidgetTag = true; } } @@ -523,23 +499,22 @@ bool WidgetBoxTreeWidget::readWidget(Widget *w, const QString &xml, QXmlStreamRe } // Oddity: Startposition is 1 off QString widgetXml = xml.mid(startTagPosition, endTagPosition - startTagPosition); - const QChar lessThan = QLatin1Char('<'); - if (!widgetXml.startsWith(lessThan)) - widgetXml.prepend(lessThan); + if (!widgetXml.startsWith(u'<')) + widgetXml.prepend(u'<'); w->setDomXml(widgetXml); return true; } void WidgetBoxTreeWidget::writeCategories(QXmlStreamWriter &writer, const CategoryList &cat_list) const { - const QString widgetbox = QLatin1String(widgetBoxRootElementC); - const QString name = QLatin1String(nameAttributeC); - const QString type = QLatin1String(typeAttributeC); - const QString icon = QLatin1String(iconAttributeC); - const QString defaultType = QLatin1String(defaultTypeValueC); - const QString category = QLatin1String(categoryElementC); - const QString categoryEntry = QLatin1String(categoryEntryElementC); - const QString iconPrefix = QLatin1String(iconPrefixC); + const QString widgetbox = widgetBoxRootElementC; + const QString name = wbNameAttributeC; + const QString type = typeAttributeC; + const QString icon = iconAttributeC; + const QString defaultType = defaultTypeValueC; + const QString category = categoryElementC; + const QString categoryEntry = categoryEntryElementC; + const QString iconPrefix = iconPrefixC; // // <widgetbox> @@ -561,7 +536,7 @@ void WidgetBoxTreeWidget::writeCategories(QXmlStreamWriter &writer, const Catego writer.writeStartElement(category); writer.writeAttribute(name, cat.name()); if (cat.type() == Category::Scratchpad) - writer.writeAttribute(type, QLatin1String(scratchPadValueC)); + writer.writeAttribute(type, scratchPadValueC); const int widgetCount = cat.widgetCount(); for (int i = 0; i < widgetCount; ++i) { @@ -620,8 +595,8 @@ WidgetBoxTreeWidget::CategoryList WidgetBoxTreeWidget::loadCustomCategoryList() static const QString customCatName = tr("Custom Widgets"); - const QString invisible = QLatin1String(invisibleNameC); - const QString iconPrefix = QLatin1String(iconPrefixC); + const QString invisible = invisibleNameC; + const QString iconPrefix = iconPrefixC; for (QDesignerCustomWidgetInterface *c : customWidgets) { const QString dom_xml = c->domXml(); @@ -963,13 +938,15 @@ void WidgetBoxTreeWidget::dropWidgets(const QList<QDesignerDnDItemInterface*> &i if (added) { save(); - QApplication::setActiveWindow(this); + activateWindow(); // Is the new item visible in filtered mode? const WidgetBoxCategoryListView::AccessMode am = WidgetBoxCategoryListView::FilteredAccess; if (const int count = categoryView->count(am)) categoryView->setCurrentItem(am, count - 1); categoryView->adjustSize(); // XXX adjustSubListSize(scratch_item); + doItemsLayout(); + scrollToItem(scratch_item, PositionAtTop); } } diff --git a/src/designer/src/components/widgetbox/widgetboxtreewidget.h b/src/designer/src/components/widgetbox/widgetboxtreewidget.h index 0961e658d..f55708105 100644 --- a/src/designer/src/components/widgetbox/widgetboxtreewidget.h +++ b/src/designer/src/components/widgetbox/widgetboxtreewidget.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 WIDGETBOXTREEWIDGET_H #define WIDGETBOXTREEWIDGET_H @@ -82,7 +57,8 @@ public: QIcon iconForWidget(const QString &iconName) const; signals: - void pressed(const QString &name, const QString &dom_xml, const QPoint &global_mouse_pos); + void widgetBoxPressed(const QString &name, const QString &dom_xml, + const QPoint &global_mouse_pos); public slots: void filter(const QString &); @@ -123,8 +99,7 @@ private: QDesignerFormEditorInterface *m_core; QString m_file_name; - using IconCache = QHash<QString, QIcon>; - mutable IconCache m_pluginIcons; + mutable QHash<QString, QIcon> m_pluginIcons; bool m_iconMode; QTimer *m_scratchPadDeleteTimer; }; |