Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions applets/dde-apps/amappitemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace apps
AMAppItemModel::AMAppItemModel(QObject *parent)
: AppItemModel(parent)
, m_manager(new ObjectManager("org.desktopspec.ApplicationManager1", "/org/desktopspec/ApplicationManager1", QDBusConnection::sessionBus()))
, m_ready(false)
{
qRegisterMetaType<ObjectInterfaceMap>();
qDBusRegisterMetaType<ObjectInterfaceMap>();
Expand Down Expand Up @@ -60,9 +61,17 @@ AMAppItemModel::AMAppItemModel(QObject *parent)
appendRow(c);
}
}

setProperty("ready", true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种行为,有没有model提供的机制呀,初始化的时候,是初始化里面的数据,能使用beginResetModel这种么,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以用reset,相当于要改model初始化那边填入数据时的形式,暂时没排查有没有别的影响。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QStandardItemModel 没提供比较方便的 reset 的方式,加上暂时未排查是否有别的影响,暂时不改为完全依赖 reset 状态来载入任务栏驻留状态的写法。

qCDebug(appsLog) << "AMAppItemModel is now ready with apps counts:" << rowCount();
Comment on lines +65 to +66
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Directly setting the 'ready' property may bypass signal emission.

Use a setter for 'm_ready' that emits 'readyChanged' to ensure listeners are notified of state changes.

Suggested implementation:

        setReady(true);
        qCDebug(appsLog) << "AMAppItemModel is now ready with apps counts:" << rowCount();
void AMAppItemModel::setReady(bool ready)
{
    if (m_ready == ready)
        return;
    m_ready = ready;
    emit readyChanged(m_ready);
}

bool AMAppItemModel::ready() const
{
    return m_ready;

You must ensure that:

  1. The setReady(bool ready) method is declared in the header file (amappitemmodel.h).
  2. The readyChanged(bool) signal is declared in the header file if not already present.
  3. Any code relying on the property or signal is updated to use the setter and signal as appropriate.

});
}

bool AMAppItemModel::ready() const
{
return m_ready;
}

AMAppItem * AMAppItemModel::appItem(const QString &id)
{
for (int i = 0; i < rowCount(); i++) {
Expand Down
8 changes: 7 additions & 1 deletion applets/dde-apps/amappitemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ class AMAppItem;
class AMAppItemModel : public AppItemModel
{
Q_OBJECT

Q_PROPERTY(bool ready MEMBER m_ready READ ready NOTIFY readyChanged)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Using MEMBER in Q_PROPERTY with custom signal may not emit signal automatically.

To ensure 'readyChanged' is emitted when 'm_ready' changes, update 'm_ready' only via a setter that emits the signal.

Suggested implementation:

    Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged)
signals:
    void readyChanged(bool);

public:
    void setReady(bool ready);

private:
    bool m_ready;

You must implement the setReady(bool ready) method in the corresponding .cpp file. The implementation should look like:

void AMAppItemModel::setReady(bool ready)
{
if (m_ready == ready)
return;
m_ready = ready;
emit readyChanged(m_ready);
}

Also, ensure all updates to m_ready use setReady() instead of direct assignment.

public:
explicit AMAppItemModel(QObject *parent = nullptr);

AMAppItem * appItem(const QString &id);

bool ready() const;

signals:
void readyChanged(bool);

private:
bool m_ready;
ObjectManager *m_manager;
};
}
6 changes: 6 additions & 0 deletions applets/dde-apps/appsapplet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
, m_appModel(new AMAppItemModel(this))
, m_groupModel(new AppGroupManager(m_appModel, this))
{
connect(m_appModel, &AMAppItemModel::readyChanged, this, &AppsApplet::appModelReadyChanged);
}

AppsApplet::~AppsApplet()
Expand All @@ -39,6 +40,11 @@
return m_appModel;
}

bool AppsApplet::appModelReady() const

Check warning on line 43 in applets/dde-apps/appsapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'appModelReady' is never used.
{
return m_appModel->ready();
}

D_APPLET_CLASS(AppsApplet)
}

Expand Down
7 changes: 7 additions & 0 deletions applets/dde-apps/appsapplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AppsApplet : public DApplet
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel *appModel READ appModel CONSTANT FINAL)
Q_PROPERTY(bool appModelReady READ appModelReady NOTIFY appModelReadyChanged FINAL)
Q_PROPERTY(QAbstractItemModel *appGroupModel READ groupModel CONSTANT FINAL)

public:
Expand All @@ -29,7 +30,13 @@ class AppsApplet : public DApplet
QAbstractItemModel *appModel() const;
QAbstractItemModel *groupModel() const;

bool appModelReady() const;

signals:
void appModelReadyChanged(bool ready);

private:
bool m_appModelReady;
AMAppItemModel *m_appModel;
QAbstractItemModel *m_groupModel;
};
Expand Down
11 changes: 11 additions & 0 deletions panels/dock/taskmanager/dockglobalelementmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#include "taskmanagersettings.h"

#include <QAbstractListModel>
#include <QDBusConnection>

Check warning on line 12 in panels/dock/taskmanager/dockglobalelementmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusConnection> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonDocument>

Check warning on line 13 in panels/dock/taskmanager/dockglobalelementmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonDocument> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonObject>

Check warning on line 14 in panels/dock/taskmanager/dockglobalelementmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Check warning on line 15 in panels/dock/taskmanager/dockglobalelementmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcess>

Check warning on line 16 in panels/dock/taskmanager/dockglobalelementmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QProcess> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Q_LOGGING_CATEGORY(dockGlobalElementModelLog, "dde.shell.dock.taskmanager.dockglobalelementmodel")

#include <algorithm>

Check warning on line 20 in panels/dock/taskmanager/dockglobalelementmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <algorithm> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <tuple>

Check warning on line 21 in panels/dock/taskmanager/dockglobalelementmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <tuple> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace dock
{
Expand Down Expand Up @@ -181,6 +184,12 @@
return 1;
}

void DockGlobalElementModel::initDockedElements(bool unused)
{
Q_UNUSED(unused);
loadDockedElements();
}

void DockGlobalElementModel::loadDockedElements()
{
QList<std::tuple<QString, QString>> newDocked;
Expand Down Expand Up @@ -237,6 +246,8 @@

m_dockedElements = newDocked;

qCDebug(dockGlobalElementModelLog) << "loaded docked elements count:" << m_dockedElements.count() << "appsModel row count:" << m_appsModel->rowCount();

if (!m_data.isEmpty()) {
// MenusRole should also be handled here due to it contains the copywriting of docked or undocked
Q_EMIT dataChanged(index(0, 0), index(m_data.size() - 1, 0), {TaskManager::DockedRole, TaskManager::MenusRole});
Expand Down
3 changes: 3 additions & 0 deletions panels/dock/taskmanager/dockglobalelementmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

void requestWindowsView(const QModelIndexList &indexes) const override;

public slots:

Check warning on line 39 in panels/dock/taskmanager/dockglobalelementmodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void initDockedElements(bool unused);

private:
void loadDockedElements();
QString getMenus(const QModelIndex &index) const;
Expand Down
2 changes: 2 additions & 0 deletions panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ bool TaskManager::init()
// 初始化预览代理模型,基于合并后的数据
m_hoverPreviewModel = new HoverPreviewProxyModel(this);
m_hoverPreviewModel->setSourceModel(m_dockGlobalElementModel);

connect(applet, SIGNAL(appModelReadyChanged(bool)), m_dockGlobalElementModel, SLOT(initDockedElements(bool)));
}

connect(m_windowMonitor.data(), &AbstractWindowMonitor::windowFullscreenChanged, this, [this] (bool isFullscreen) {
Expand Down