From 630b4cd0bef9a49ad870f3554afe512ef395f722 Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Wed, 22 Nov 2023 14:44:41 +0800 Subject: [PATCH] chore: remove qml-module-org-kde-kitemmodels dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除 qml-module-org-kde-kitemmodels 依赖。 原本全屏视图过滤当前页面的图标用此组件提供的 sortfilterproxy 模型, 但实际实现需要一些额外的支持,比如 sort 后的排序。因而不再使用原方 案。原本的 KSortFilterProxyModel 由 MultiPageSortFilterProxyModel 替代。 Log: --- .reuse/dep5 | 6 - debian/control | 3 +- main.cpp | 2 - qml.qrc | 2 - qml/FullscreenFrame.qml | 4 +- src/models/multipageproxymodel.cpp | 4 +- src/quick/CMakeLists.txt | 2 - src/quick/ksortfilterproxymodel.cpp | 263 ---------------------------- src/quick/ksortfilterproxymodel.h | 170 ------------------ 9 files changed, 6 insertions(+), 450 deletions(-) delete mode 100644 src/quick/ksortfilterproxymodel.cpp delete mode 100644 src/quick/ksortfilterproxymodel.h diff --git a/.reuse/dep5 b/.reuse/dep5 index 47588b3a..f46792ba 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -38,9 +38,3 @@ Files: *.deepin.dde.*.xml */org.desktopspec.*.xml Copyright: UnionTech Software Technology Co., Ltd. License: GPL-3.0-or-later -# vendored from KItemModels -Files: src/quick/ksortfilterproxymodel.cpp src/quick/ksortfilterproxymodel.h -Copyright: 2010, Marco Martin - 2019, David Edmundson -License: LGPL-2.0-or-later - diff --git a/debian/control b/debian/control index 2bc21add..7bfb3e79 100644 --- a/debian/control +++ b/debian/control @@ -36,8 +36,7 @@ Depends: qml-module-qtquick-controls2, qml-module-qtquick-controls2-styles-chameleon, # v-- actually should be depended by qqc2-styles-chameleon - qml-module-qtgraphicaleffects, - qml-module-org-kde-kitemmodels + qml-module-qtgraphicaleffects Conflicts: dde-launcher Replaces: dde-launcher Description: diff --git a/main.cpp b/main.cpp index e3571ac6..b07b163d 100644 --- a/main.cpp +++ b/main.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include DCORE_USE_NAMESPACE @@ -82,7 +81,6 @@ int main(int argc, char* argv[]) LauncherController::instance().setVisible(true); } - qmlRegisterType("org.deepin.vendored", 1, 0, "KSortFilterProxyModel"); qmlRegisterType("org.deepin.launchpad", 1, 0, "MultipageSortFilterProxyModel"); qmlRegisterUncreatableType("org.deepin.launchpad", 1, 0, "AppItem", "AppItem should only be created from C++ side"); qmlRegisterSingletonInstance("org.deepin.launchpad", 1, 0, "AppsModel", &AppsModel::instance()); diff --git a/qml.qrc b/qml.qrc index fcd6975c..2a33aa11 100644 --- a/qml.qrc +++ b/qml.qrc @@ -2,9 +2,7 @@ qml/Main.qml qml/DebugDialog.qml - qml/FullscreenFrameV23.qml qml/FullscreenFrame.qml - qml/WindowedFrameV23.qml qml/WindowedFrame.qml qml/AlphabetCategory.qml qml/AppListView.qml diff --git a/qml/FullscreenFrame.qml b/qml/FullscreenFrame.qml index c966575e..ca3a4c18 100644 --- a/qml/FullscreenFrame.qml +++ b/qml/FullscreenFrame.qml @@ -9,7 +9,6 @@ import QtQuick.Layouts 1.15 import QtQuick.Controls 2.15 import QtQuick.Window 2.15 import org.deepin.dtk 1.0 -import org.deepin.vendored 1.0 import org.deepin.launchpad 1.0 @@ -148,7 +147,7 @@ Control { focus: true activeGridViewFocusOnTab: gridViewLoader.SwipeView.isCurrentItem delegate: IconItemDelegate { - dndEnabled: false + dndEnabled: true Drag.mimeData: { "application/x-dde-launcher-dnd-fullscreen": ("0," + modelData + "," + index), // "folder,page,index" "application/x-dde-launcher-dnd-desktopId": model.desktopId @@ -365,6 +364,7 @@ Control { focus: true activeGridViewFocusOnTab: folderGridViewLoader.SwipeView.isCurrentItem delegate: IconItemDelegate { + dndEnabled: true iconSource: "image://app-icon/" + iconName width: folderGridViewContainer.cellSize height: folderGridViewContainer.cellSize diff --git a/src/models/multipageproxymodel.cpp b/src/models/multipageproxymodel.cpp index 7d075a5f..b3cab178 100644 --- a/src/models/multipageproxymodel.cpp +++ b/src/models/multipageproxymodel.cpp @@ -68,7 +68,9 @@ void MultipageProxyModel::commitDndOperation(const QString &dragId, const QStrin saveItemArrangementToUserData(); // Lazy solution, just notify the view that all rows and its roles are changed so they need to be updated. - emit dataChanged(index(0, 0, QModelIndex()), index(rowCount(QModelIndex()), 0, QModelIndex())); + emit dataChanged(index(0, 0, QModelIndex()), index(rowCount(QModelIndex()), 0, QModelIndex()), { + PageRole, IndexInPageRole, FolderIdNumberRole, IconsNameRole + }); } QModelIndex MultipageProxyModel::index(int row, int column, const QModelIndex &parent) const diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index f7846694..c4522344 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -11,7 +11,6 @@ PRIVATE launcherappiconprovider.cpp launcherfoldericonprovider.cpp blurhashimageprovider.cpp - ksortfilterproxymodel.cpp ) target_sources(launcher-qml-utils PUBLIC @@ -20,7 +19,6 @@ FILES launcherappiconprovider.h launcherfoldericonprovider.h blurhashimageprovider.h - ksortfilterproxymodel.h ) target_include_directories(launcher-qml-utils PUBLIC ${CMAKE_CURRENT_LIST_DIR}) diff --git a/src/quick/ksortfilterproxymodel.cpp b/src/quick/ksortfilterproxymodel.cpp deleted file mode 100644 index d5d538b7..00000000 --- a/src/quick/ksortfilterproxymodel.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright 2010 by Marco Martin - * Copyright 2019 by David Edmundson - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "ksortfilterproxymodel.h" - -#include -#include - -// This is just an ECM-based logging category thing -//#include "kitemmodels_debug.h" -#include -Q_DECLARE_LOGGING_CATEGORY(KITEMMODELS_LOG) -Q_LOGGING_CATEGORY(KITEMMODELS_LOG, "kf.itemmodels.core", QtInfoMsg) - -KSortFilterProxyModel::KSortFilterProxyModel(QObject *parent) - : QSortFilterProxyModel(parent) -{ - setDynamicSortFilter(true); - connect(this, &KSortFilterProxyModel::modelReset, this, &KSortFilterProxyModel::rowCountChanged); - connect(this, &KSortFilterProxyModel::rowsInserted, this, &KSortFilterProxyModel::rowCountChanged); - connect(this, &KSortFilterProxyModel::rowsRemoved, this, &KSortFilterProxyModel::rowCountChanged); - // NOTE: some models actually fill their roleNames() only when they get some actual data, this works around the bad behavior - connect(this, &KSortFilterProxyModel::rowCountChanged, this, &KSortFilterProxyModel::syncRoleNames); - - connect(this, &KSortFilterProxyModel::filterRoleChanged, this, [this](int role) { - const QString roleName = QString::fromUtf8(roleNames().value(role)); - if (m_filterRoleName != roleName) { - m_filterRoleName = roleName; - Q_EMIT filterRoleNameChanged(); - } - }); - - connect(this, &KSortFilterProxyModel::sortRoleChanged, this, [this](int role) { - const QString roleName = QString::fromUtf8(roleNames().value(role)); - if (m_sortRoleName != roleName) { - m_sortRoleName = roleName; - Q_EMIT sortRoleNameChanged(); - } - }); -} - -KSortFilterProxyModel::~KSortFilterProxyModel() -{ -} - -void KSortFilterProxyModel::syncRoleNames() -{ - if (!sourceModel()) { - return; - } - - m_roleIds.clear(); - const QHash rNames = roleNames(); - m_roleIds.reserve(rNames.count()); - for (auto i = rNames.constBegin(); i != rNames.constEnd(); ++i) { - m_roleIds[QString::fromUtf8(i.value())] = i.key(); - } - - setFilterRoleName(m_filterRoleName); - setSortRoleName(m_sortRoleName); -} - -int KSortFilterProxyModel::roleNameToId(const QString &name) const -{ - return m_roleIds.value(name, Qt::DisplayRole); -} - -void KSortFilterProxyModel::setModel(QAbstractItemModel *model) -{ - if (model == sourceModel()) { - return; - } - - QSortFilterProxyModel::setSourceModel(model); - - if (m_componentCompleted) { - syncRoleNames(); - setFilterRoleName(m_filterRoleName); - setSortRoleName(m_sortRoleName); - } -} - -bool KSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const -{ - if (m_filterRowCallback.isCallable()) { - QJSEngine *engine = qjsEngine(this); - QJSValueList args = {QJSValue(source_row), engine->toScriptValue(source_parent)}; - - QJSValue result = const_cast(this)->m_filterRowCallback.call(args); - if (result.isError()) { - qCWarning(KITEMMODELS_LOG) << "Row filter callback produced an error:"; - qCWarning(KITEMMODELS_LOG) << result.toString(); - return true; - } else { - return result.toBool(); - } - } - - return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); -} - -bool KSortFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const -{ - if (m_filterColumnCallback.isCallable()) { - QJSEngine *engine = qjsEngine(this); - QJSValueList args = {QJSValue(source_column), engine->toScriptValue(source_parent)}; - - QJSValue result = const_cast(this)->m_filterColumnCallback.call(args); - if (result.isError()) { - qCWarning(KITEMMODELS_LOG) << "Row filter callback produced an error:"; - qCWarning(KITEMMODELS_LOG) << result.toString(); - return true; - } else { - return result.toBool(); - } - } - - return QSortFilterProxyModel::filterAcceptsColumn(source_column, source_parent); -} - -void KSortFilterProxyModel::setFilterString(const QString &filterString) -{ - if (filterString == m_filterString) { - return; - } - m_filterString = filterString; - QSortFilterProxyModel::setFilterFixedString(filterString); - Q_EMIT filterStringChanged(); -} - -QString KSortFilterProxyModel::filterString() const -{ - return m_filterString; -} - -QJSValue KSortFilterProxyModel::filterRowCallback() const -{ - return m_filterRowCallback; -} - -void KSortFilterProxyModel::setFilterRowCallback(const QJSValue &callback) -{ - if (m_filterRowCallback.strictlyEquals(callback)) { - return; - } - - if (!callback.isNull() && !callback.isCallable()) { - return; - } - - m_filterRowCallback = callback; - invalidateFilter(); - - Q_EMIT filterRowCallbackChanged(callback); -} - -void KSortFilterProxyModel::setFilterColumnCallback(const QJSValue &callback) -{ - if (m_filterColumnCallback.strictlyEquals(callback)) { - return; - } - - if (!callback.isNull() && !callback.isCallable()) { - return; - } - - m_filterColumnCallback = callback; - invalidateFilter(); - - Q_EMIT filterColumnCallbackChanged(callback); -} - -QJSValue KSortFilterProxyModel::filterColumnCallback() const -{ - return m_filterColumnCallback; -} - -void KSortFilterProxyModel::setFilterRoleName(const QString &roleName) -{ - QSortFilterProxyModel::setFilterRole(roleNameToId(roleName)); - if (roleName != m_filterRoleName) { - m_filterRoleName = roleName; - Q_EMIT filterRoleNameChanged(); - } -} - -QString KSortFilterProxyModel::filterRoleName() const -{ - return m_filterRoleName; -} - -void KSortFilterProxyModel::setSortRoleName(const QString &roleName) -{ - if (roleName.isEmpty()) { - sort(-1, Qt::AscendingOrder); - } else if (sourceModel()) { - QSortFilterProxyModel::setSortRole(roleNameToId(roleName)); - sort(std::max(sortColumn(), 0), sortOrder()); - } - - if (roleName != m_sortRoleName) { - m_sortRoleName = roleName; - Q_EMIT sortRoleNameChanged(); - } -} - -QString KSortFilterProxyModel::sortRoleName() const -{ - return m_sortRoleName; -} - -void KSortFilterProxyModel::setSortOrder(const Qt::SortOrder order) -{ - sort(std::max(sortColumn(), 0), order); - Q_EMIT sortOrderChanged(); -} - -void KSortFilterProxyModel::setSortColumn(int column) -{ - if (column == sortColumn()) { - return; - } - sort(column, sortOrder()); - Q_EMIT sortColumnChanged(); -} - -void KSortFilterProxyModel::classBegin() -{ -} - -void KSortFilterProxyModel::componentComplete() -{ - m_componentCompleted = true; - if (sourceModel()) { - syncRoleNames(); - setFilterRoleName(m_filterRoleName); - setSortRoleName(m_sortRoleName); - } -} - -void KSortFilterProxyModel::invalidateFilter() -{ - QSortFilterProxyModel::invalidateFilter(); -} - -#include "moc_ksortfilterproxymodel.cpp" diff --git a/src/quick/ksortfilterproxymodel.h b/src/quick/ksortfilterproxymodel.h deleted file mode 100644 index 909a2e3e..00000000 --- a/src/quick/ksortfilterproxymodel.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright 2010 by Marco Martin - * Copyright 2019 by David Edmundson - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef KSORTFILTERPROXYMODEL_H -#define KSORTFILTERPROXYMODEL_H - -#include -#include -#include -#include -#include - -/** - * @class SortFilterModel - * @short Filter and sort an existing QAbstractItemModel - * - * @since 5.67 - */ -class KSortFilterProxyModel : public QSortFilterProxyModel, public QQmlParserStatus -{ - Q_OBJECT - Q_INTERFACES(QQmlParserStatus) - /** - * The source model of this sorting proxy model. - */ - Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setModel NOTIFY sourceModelChanged) - - /** - * The string for the filter, only rows with their filterRole matching filterString will be displayed - */ - Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged) - /** - * A JavaScript callable that can be used to perform advanced filters on a given row. - * The callback is passed the source row, and source parent for a given row as arguments - * - * The callable's return value is evaluated as boolean to determine - * whether the row is accepted (true) or filtered out (false). It overrides the default implementation - * that uses filterRegExp or filterString; while filterCallback is set those two properties are - * ignored. Attempts to write a non-callable to this property are silently ignored, but you can set - * it to null. - * - * @code - * filterRowCallback: function(source_row, source_parent) { - * return sourceModel.data(sourceModel.index(source_row, 0, source_parent), Qt.DisplayRole) == "..."; - * }; - * @endcode - */ - Q_PROPERTY(QJSValue filterRowCallback READ filterRowCallback WRITE setFilterRowCallback NOTIFY filterRowCallbackChanged) - - /** - * A JavaScript callable that can be used to perform advanced filters on a given column. - * The callback is passed the source column, and source parent for a given column as arguments. - * - * @see filterRowCallback - */ - Q_PROPERTY(QJSValue filterColumnCallback READ filterColumnCallback WRITE setFilterColumnCallback NOTIFY filterColumnCallbackChanged) - - /** - * The role of the sourceModel on which the filter will be applied. - * This can either be the numerical role value or the role name as a string. - */ - Q_PROPERTY(QString filterRoleName READ filterRoleName WRITE setFilterRoleName NOTIFY filterRoleNameChanged) - - /** - * The role of the sourceModel that will be used for sorting. if empty the order will be left unaltered - * This can either be the numerical role value or the role name as a string. - */ - Q_PROPERTY(QString sortRoleName READ sortRoleName WRITE setSortRoleName NOTIFY sortRoleNameChanged) - - /** - * One of Qt.AscendingOrder or Qt.DescendingOrder - */ - Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged) - - /** - * Specify which column should be used for sorting - * The default value is -1. - * If \a sortRole is set, the default value is 0. - */ - Q_PROPERTY(int sortColumn READ sortColumn WRITE setSortColumn NOTIFY sortColumnChanged) - - /** - * The number of top level rows. - */ - Q_PROPERTY(int count READ rowCount NOTIFY rowCountChanged) - -public: - explicit KSortFilterProxyModel(QObject *parent = nullptr); - ~KSortFilterProxyModel() override; - - void setModel(QAbstractItemModel *source); - - void setFilterRowCallback(const QJSValue &callback); - QJSValue filterRowCallback() const; - - void setFilterString(const QString &filterString); - QString filterString() const; - - void setFilterColumnCallback(const QJSValue &callback); - QJSValue filterColumnCallback() const; - - void setFilterRoleName(const QString &roleName); - QString filterRoleName() const; - - void setSortRoleName(const QString &roleName); - QString sortRoleName() const; - - void setSortOrder(const Qt::SortOrder order); - void setSortColumn(int column); - - void classBegin() override; - void componentComplete() override; - -public Q_SLOTS: - /** - * Invalidates the current filtering. - * - * This function should be called if you are implementing custom filtering through - * filterRowCallback or filterColumnCallback, and your filter parameters have changed. - * - * @since 5.70 - */ - void invalidateFilter(); - -Q_SIGNALS: - void filterStringChanged(); - void filterRoleNameChanged(); - void sortRoleNameChanged(); - void sortOrderChanged(); - void sortColumnChanged(); - void sourceModelChanged(QObject *); - void filterRowCallbackChanged(const QJSValue &); - void filterColumnCallbackChanged(const QJSValue &); - void rowCountChanged(); - -protected: - int roleNameToId(const QString &name) const; - bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; - bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const override; - -protected Q_SLOTS: - void syncRoleNames(); - -private: - bool m_componentCompleted = false; - QString m_filterRoleName; - QString m_filterString; - QString m_sortRoleName; - QJSValue m_filterRowCallback; - QJSValue m_filterColumnCallback; - QHash m_roleIds; -}; -#endif