Skip to content

Commit

Permalink
fix: Unable to set whether the datetime plugin is visible
Browse files Browse the repository at this point in the history
时间日期插件属于 fixed 插件

Issues: linuxdeepin/developer-center#9820
  • Loading branch information
zsien authored and 18202781743 committed Jul 19, 2024
1 parent de7f72f commit c2ff36e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
6 changes: 6 additions & 0 deletions panels/dock/tray/package/tray.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 42 additions & 6 deletions panels/dock/tray/trayitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QObject *>();
if (!item)
return DockItemInfos{};
Expand All @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions panels/dock/tray/trayitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit c2ff36e

Please sign in to comment.