Skip to content

Commit

Permalink
test: [at] fix that the sniff can not show AT tags
Browse files Browse the repository at this point in the history
1. add judging condition for root url in funtion rowCount();
2. get the correct column in function data() for display role and edit role.

Log: fix sniff can not show AT tags
Task: https://pms.uniontech.com/task-view-278231.html
  • Loading branch information
shzhuangpub authored and deepin-bot[bot] committed Jul 31, 2023
1 parent 0e812bf commit 340ff5f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,19 @@ QModelIndex FileViewModel::parent(const QModelIndex &child) const

int FileViewModel::rowCount(const QModelIndex &parent) const
{
if (!parent.isValid())
return 1;

if (!filterSortWorker.isNull())
Q_UNUSED(parent)
/* notes:
It's no need to return 1 when parent is invalid, because there is no such scenario.
AT tool(sniff) will use this return value to make AT-tag and show each item.
If the return value is greater than 0, the AT-tags are shown normally and item
count is equal to the return value;
For AT-tool, if `parent` is invalid and return 1, then only 1 item would
be shown in AT-tool, because at that time `filterSortWorker` has not get correct children count,
but the AT-tool need a correct children count, not 1.
*/
if (!filterSortWorker.isNull()) {
return filterSortWorker->childrenCount();
}

return 0;
}
Expand All @@ -259,15 +267,25 @@ QVariant FileViewModel::data(const QModelIndex &index, int role) const
return QVariant();

FileItemData *itemData = nullptr;

int columnRole = role;
if (!parentIndex.isValid()) {
itemData = filterSortWorker->rootData();
} else {
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole: {
ItemRoles temRole = columnToRole(index.column());
if (temRole != ItemRoles::kItemUnknowRole)
columnRole = temRole;
} break;
default:
break;
}
itemData = filterSortWorker->childData(index.row());
}

if (itemData) {
return itemData->data(role);
return itemData->data(columnRole);
} else {
return QVariant();
}
Expand Down Expand Up @@ -507,6 +525,31 @@ QList<ItemRoles> FileViewModel::getColumnRoles() const
return roles;
}

ItemRoles FileViewModel::columnToRole(int column) const
{
QList<ItemRoles> roles;
bool customOnly = WorkspaceEventSequence::instance()->doFetchCustomColumnRoles(dirRootUrl, &roles);

const QVariantMap &map = DFMBASE_NAMESPACE::Application::appObtuselySetting()->value("FileViewState", dirRootUrl).toMap();
if (map.contains("headerList")) {
QVariantList headerList = map.value("headerList").toList();
if (headerList.length() > column)
return ItemRoles(headerList.at(column).toInt());

} else if (!customOnly) {
static QList<ItemRoles> defualtColumnRoleList = QList<ItemRoles>() << kItemFileDisplayNameRole
<< kItemFileLastModifiedRole
<< kItemFileSizeRole
<< kItemFileMimeTypeRole;

if (defualtColumnRoleList.length() > column) {
return defualtColumnRoleList.at(column);
}
}

return kItemUnknowRole;
}

QString FileViewModel::roleDisplayString(int role) const
{
QString displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class FileViewModel : public QAbstractItemModel
DFMGLOBAL_NAMESPACE::ItemRoles getRoleByColumn(int column) const;
int getColumnByRole(DFMGLOBAL_NAMESPACE::ItemRoles role) const;
QList<DFMGLOBAL_NAMESPACE::ItemRoles> getColumnRoles() const;
DFMGLOBAL_NAMESPACE::ItemRoles columnToRole(int column) const;
QString roleDisplayString(int role) const;

void stopTraversWork();
Expand Down

0 comments on commit 340ff5f

Please sign in to comment.