Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented May 15, 2025

ported from the original feature development branch for combined icons

Summary by Sourcery

Introduce RoleGroupModel to group items in the taskmanager panel by a specified data role and integrate it into the build system.

New Features:

  • Add RoleGroupModel QAbstractProxyModel for grouping rows based on a data role.

Build:

  • Update CMakeLists to include RoleGroupModel sources and target its test executable.

Tests:

  • Add unit tests for RoleGroupModel covering grouping behavior, indexing, and dynamic row insertion/removal.

@BLumia BLumia requested review from 18202781743 and tsic404 May 15, 2025 12:07
@sourcery-ai
Copy link

sourcery-ai bot commented May 15, 2025

Reviewer's Guide

This PR introduces a new RoleGroupModel proxy to group rows by a deduplication role, integrates it into the taskmanager build setup, and adds unit tests to validate its grouping logic.

File-Level Changes

Change Details Files
Introduce RoleGroupModel proxy model for grouping rows by a specified role
  • Define RoleGroupModel class extending QAbstractProxyModel with role-based grouping
  • Override setSourceModel to rebuild internal maps and connect to source signals (rowsInserted, rowsRemoved, dataChanged, modelReset)
  • Maintain internal mapping structures (m_map, m_rowMap) and implement rebuildTreeSource and adjustMap helpers
  • Implement required proxy methods: rowCount, columnCount, data, index, parent, mapToSource, mapFromSource, roleNames
panels/dock/taskmanager/rolegroupmodel.cpp
panels/dock/taskmanager/rolegroupmodel.h
Update CMake build files to include RoleGroupModel and its tests
  • Add rolegroupmodel.cpp/h to dock-taskmanager library sources
  • Declare new rolegroupmodel_tests executable in taskmanager test CMakeLists
  • Link GTest, QtCore, QtTest, and dock-taskmanager to the new test target
  • Set include directories and register the rolegroupmodel_tests with CTest
panels/dock/taskmanager/CMakeLists.txt
tests/panels/dock/taskmanager/CMakeLists.txt
Add unit tests for RoleGroupModel behavior
  • Create rolegroupmodeltests.cpp using Google Test to verify row grouping and indexing
  • Use QStandardItemModel and QSignalSpy to simulate data changes, insertions, and removals
  • Assert correct rowCount, data access, and dynamic updates after source model modifications
tests/panels/dock/taskmanager/rolegroupmodeltests.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @BLumia - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • columnCount() should check for a valid sourceModel pointer. (link)

  • roleNames() should check for a valid sourceModel pointer. (link)

  • Implement a destructor (or cleanup routine) to delete the QList* in m_rowMap to avoid leaking those dynamically allocated lists.

  • Emit the deduplicationRoleChanged signal in setDeduplicationRole() after changing m_roleForDeduplication to keep QML bindings and observers in sync.

  • Either remove the declared hasIndex() override in the header or provide a matching implementation to prevent linker errors.

Here's what I looked at during the review
  • 🔴 General issues: 2 blocking issues, 7 other issues
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +31 to +32
if (sourceModel()) {
sourceModel()->disconnect(this);
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Disconnecting all signals from the previous source model may unintentionally break other connections.

disconnect(this) removes all sourceModel→this connections, risking other slots. Instead, disconnect only the signals you connected or store QMetaObject::Connection objects to manage them.

return m_rowMap.size();
}

int RoleGroupModel::columnCount(const QModelIndex &parent) const
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): columnCount() should check for a valid sourceModel pointer.

Add a null check for sourceModel() and return 0 if it’s unset to prevent a crash.

return sourceModel()->columnCount(parent);
}

QHash<int, QByteArray> RoleGroupModel::roleNames() const
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): roleNames() should check for a valid sourceModel pointer.

Add a null check and return an empty QHash if sourceModel() is null.

return sourceModel()->roleNames();
}

QVariant RoleGroupModel::data(const QModelIndex &index, int role) const
Copy link

Choose a reason for hiding this comment

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

issue: data() should validate the index and sourceModel pointer.

Return a default QVariant when the index is invalid or sourceModel() is null to prevent crashes.

return createIndex(pos, 0);
}

QModelIndex RoleGroupModel::mapToSource(const QModelIndex &proxyIndex) const
Copy link

Choose a reason for hiding this comment

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

issue: mapToSource() should validate proxyIndex and sourceModel pointer.

Return a default QModelIndex when proxyIndex is invalid or sourceModel() is null to prevent crashes.

return sourceModel()->index(list->value(0), 0);
}

QModelIndex RoleGroupModel::mapFromSource(const QModelIndex &sourceIndex) const
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): mapFromSource() should validate sourceIndex and sourceModel pointer.

Return a default QModelIndex if sourceIndex is invalid or sourceModel() is null to avoid crashes.


#include "rolegroupmodel.h"

TEST(RoleGroupModel, RowCountTest)
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Consider renaming test or splitting into multiple more focused tests.

Use a more descriptive name (e.g., TestGroupingAndDataRetrieval) or split this into focused tests—one for grouping, one for data access, and one for row removal—to improve readability and failure diagnosis.

Comment on lines +39 to +40
QSignalSpy spy(&model, &QAbstractItemModel::rowsRemoved);
QSignalSpy spys(&model, &QAbstractItemModel::rowsInserted);
Copy link

Choose a reason for hiding this comment

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

issue (testing): Unused signal spies should be removed or utilized.

Either remove the unused QSignalSpy instances or add assertions (e.g., EXPECT_EQ(spy.count(), expected_count)) to verify the signals.

@BLumia BLumia force-pushed the rolegroupmodel branch 2 times, most recently from 31d983d to de1c0b9 Compare May 15, 2025 12:24
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. RoleGroupModel的构造函数中,RoleGroupModel::setSourceModel(sourceModel); 应该改为 setSourceModel(sourceModel);,否则会导致编译错误。
  2. setSourceModel函数中,rebuildTreeSource();调用应该在QAbstractProxyModel::setSourceModel(model);之后,以确保源模型已经设置。
  3. setSourceModel函数中,if (sourceModel() == nullptr) return;应该放在QAbstractProxyModel::setSourceModel(model);之后,以确保源模型已经设置。
  4. data函数中,auto parentPos = static_cast<int>(index.internalId());应该改为auto parentPos = static_cast<int>(index.internalId());,否则会导致编译错误。
  5. index函数中,auto list = m_map.value(parent.data(m_roleForDeduplication).toString(), nullptr);应该改为auto list = m_map.value(parent.data(m_roleForDeduplication).toString(), nullptr);,否则会导致编译错误。
  6. mapToSource函数中,QList<int> *list = nullptr;应该改为QList<int> *list = nullptr;,否则会导致编译错误。
  7. mapFromSource函数中,auto data = sourceIndex.data(m_roleForDeduplication).toString();应该改为auto data = sourceIndex.data(m_roleForDeduplication).toString();,否则会导致编译错误。
  8. rebuildTreeSource函数中,beginResetModel();应该放在qDeleteAll(m_rowMap);之前,以确保模型重置。
  9. adjustMap函数中,for (int i = 0; i < m_rowMap.count(); ++i) {应该改为for (int i = 0; i < m_rowMap.count(); ++i) {,否则会导致编译错误。
  10. rolegroupmodeltests.cpp中,auto role = Qt::UserRole + 1;应该改为auto role = Qt::UserRole + 1;,否则会导致编译错误。

以上是代码审查意见,需要根据实际情况进行调整和修改。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, BLumia

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@BLumia BLumia merged commit 9b4fe73 into linuxdeepin:master May 15, 2025
7 of 10 checks passed
@BLumia BLumia deleted the rolegroupmodel branch May 15, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants