1 Star 0 Fork 0

Notepad-- Community/filesearch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
QTreeWidgetSortItem.cpp 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
爬山虎 提交于 2023-12-16 15:15 +08:00 . 提交全部代码
#include "QTreeWidgetSortItem.h"
/* 自己重新实现一个QTreeWidgetSortItem,主要是为了重载函数的排序功能,不适应默认的名字排序,而是使用
* 每个项自带的tip字符串排序。这样做是因为对齐的时候,有些空白对齐项目,并没有名称,就会导致无法排序
*/
int QTreeWidgetSortItem::s_sortType = 0;
const int FILE_SIZE = Qt::UserRole + 1;
//bool QTreeWidgetSortItem::s_syncOrder = false;
QTreeWidgetSortItem::QTreeWidgetSortItem(int type):QTreeWidgetItem(type)
{
}
QTreeWidgetSortItem::QTreeWidgetSortItem(const QStringList &strings, int type):QTreeWidgetItem(strings, type)
{
}
QTreeWidgetSortItem::~QTreeWidgetSortItem()
{
}
bool QTreeWidgetSortItem::operator<(const QTreeWidgetItem & other) const
{
if (s_sortType == 0)
{
QString a = this->data(0, Qt::ToolTipRole).toString();
QString b = other.data(0, Qt::ToolTipRole).toString();
return (a.compare(b, Qt::CaseInsensitive) > 0);
}
else if (s_sortType == 1) //按大小排序
{
qreal a = this->data(1, FILE_SIZE).toReal();
qreal b = other.data(1, FILE_SIZE).toReal();
return(a > b);
}
else if (s_sortType == 2) //by 创建时间
{
QString a = this->text(2);
QString b = other.text(2);
return(a.compare(b, Qt::CaseInsensitive) > 0);
}
else if (s_sortType == 3) //by 修改时间
{
QString a = this->text(3);
QString b = other.text(3);
return(a.compare(b, Qt::CaseInsensitive) > 0);
}
return false;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/ndd-community/filesearch.git
git@gitee.com:ndd-community/filesearch.git
ndd-community
filesearch
filesearch
master

搜索帮助