From 8fb22b78e3d426c1824f9a00278410a779edcb51 Mon Sep 17 00:00:00 2001 From: zsien Date: Fri, 19 Jul 2024 10:43:52 +0800 Subject: [PATCH] fix: Unable to set whether the datetime plugin is visible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 时间日期插件属于 fixed 插件 Issues: linuxdeepin/developer-center#9820 --- panels/dock/tray/package/tray.qml | 6 ++++ panels/dock/tray/trayitem.cpp | 48 +++++++++++++++++++++++++++---- panels/dock/tray/trayitem.h | 15 ++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/panels/dock/tray/package/tray.qml b/panels/dock/tray/package/tray.qml index f85b5ccdc..b6a164280 100644 --- a/panels/dock/tray/package/tray.qml +++ b/panels/dock/tray/package/tray.qml @@ -29,6 +29,12 @@ AppletItem { Applet.trayPluginModel = Qt.binding(function () { return DockCompositor.trayPluginSurfaces }) + Applet.quickPluginModel = Qt.binding(function () { + return DockCompositor.quickPluginSurfaces + }) + Applet.fixedPluginModel = Qt.binding(function () { + return DockCompositor.fixedPluginSurfaces + }) } PanelPopup { diff --git a/panels/dock/tray/trayitem.cpp b/panels/dock/tray/trayitem.cpp index c426978e4..99b3c655f 100644 --- a/panels/dock/tray/trayitem.cpp +++ b/panels/dock/tray/trayitem.cpp @@ -35,20 +35,46 @@ void TrayItem::setTrayPluginModel(QAbstractItemModel *newTrayPluginModel) emit trayPluginModelChanged(); } -DockItemInfos TrayItem::dockItemInfos() +QAbstractItemModel *TrayItem::quickPluginModel() const +{ + return m_quickPluginModel; +} + +void TrayItem::setQuickPluginModel(QAbstractItemModel *newQuickPluginModel) +{ + if (m_quickPluginModel == newQuickPluginModel) + return; + m_quickPluginModel = newQuickPluginModel; + emit quickPluginModelChanged(); +} + +QAbstractItemModel *TrayItem::fixedPluginModel() const +{ + return m_fixedPluginModel; +} + +void TrayItem::setFixedPluginModel(QAbstractItemModel *newFixedPluginModel) { - const auto targetModel = m_trayPluginModel; - if (!targetModel) + if (m_fixedPluginModel == newFixedPluginModel) + return; + m_fixedPluginModel = newFixedPluginModel; + emit fixedPluginModelChanged(); +} + +DockItemInfos TrayItem::dockItemInfosFromModel(QAbstractItemModel *model) +{ + if (!model) { return DockItemInfos{}; + } - const auto roleNames = targetModel->roleNames(); + const auto roleNames = model->roleNames(); const auto modelDataRole = roleNames.key("shellSurface", -1); if (modelDataRole < 0) return DockItemInfos{}; DockItemInfos itemInfos; - for (int i = 0; i < targetModel->rowCount(); i++) { - const auto index = targetModel->index(i, 0); + for (int i = 0; i < model->rowCount(); i++) { + const auto index = model->index(i, 0); const auto item = index.data(modelDataRole).value(); if (!item) return DockItemInfos{}; @@ -64,6 +90,16 @@ DockItemInfos TrayItem::dockItemInfos() itemInfo.visible = TraySettings::instance()->trayItemIsOnDock(itemInfo.name + "::" + itemInfo.itemKey); itemInfos << itemInfo; } + + return itemInfos; +} + +DockItemInfos TrayItem::dockItemInfos() +{ + DockItemInfos itemInfos; + itemInfos.append(dockItemInfosFromModel(m_trayPluginModel)); + itemInfos.append(dockItemInfosFromModel(m_fixedPluginModel)); + m_itemInfos = itemInfos; return m_itemInfos; } diff --git a/panels/dock/tray/trayitem.h b/panels/dock/tray/trayitem.h index e5e5a7598..e00840d29 100644 --- a/panels/dock/tray/trayitem.h +++ b/panels/dock/tray/trayitem.h @@ -16,20 +16,35 @@ class TrayItem : public DS_NAMESPACE::DApplet { Q_OBJECT Q_PROPERTY(QAbstractItemModel* trayPluginModel READ trayPluginModel WRITE setTrayPluginModel NOTIFY trayPluginModelChanged FINAL) + Q_PROPERTY(QAbstractItemModel* quickPluginModel READ quickPluginModel WRITE setQuickPluginModel NOTIFY quickPluginModelChanged FINAL) + Q_PROPERTY(QAbstractItemModel* fixedPluginModel READ fixedPluginModel WRITE setFixedPluginModel NOTIFY fixedPluginModelChanged FINAL) public: explicit TrayItem(QObject *parent = nullptr); QAbstractItemModel *trayPluginModel() const; void setTrayPluginModel(QAbstractItemModel *newTrayPluginModel); + QAbstractItemModel *quickPluginModel() const; + void setQuickPluginModel(QAbstractItemModel *newQuickPluginModel); + + QAbstractItemModel *fixedPluginModel() const; + void setFixedPluginModel(QAbstractItemModel *newFixedPluginModel); + Q_INVOKABLE DockItemInfos dockItemInfos(); Q_INVOKABLE void setItemOnDock(const QString &settingKey, const QString &itemKey, bool visible); Q_SIGNALS: void trayPluginModelChanged(); + void quickPluginModelChanged(); + void fixedPluginModelChanged(); + +private: + DockItemInfos dockItemInfosFromModel(QAbstractItemModel *model); private: QAbstractItemModel *m_trayPluginModel = nullptr; + QAbstractItemModel *m_quickPluginModel = nullptr; + QAbstractItemModel *m_fixedPluginModel = nullptr; DockItemInfos m_itemInfos; };