代码拉取完成,页面将自动刷新
#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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。