implemented sorting manually in channel files lists

This commit is contained in:
csoler 2020-06-10 23:16:32 +02:00
parent 8c3c973d02
commit ebbdc082c0
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 53 additions and 8 deletions

View File

@ -370,6 +370,43 @@ void RsGxsChannelPostFilesModel::setFilter(const QStringList& strings, uint32_t&
postMods();
}
class compareOperator
{
public:
compareOperator(int column,Qt::SortOrder order): col(column),ord(order) {}
bool operator()(const RsGxsFile& f1,const RsGxsFile& f2) const
{
switch(col)
{
default:
case RsGxsChannelPostFilesModel::COLUMN_FILES_NAME: return (ord==Qt::AscendingOrder)?(f1.mName<f2.mName):(f1.mName>f2.mName);
case RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE: return (ord==Qt::AscendingOrder)?(f1.mSize<f2.mSize):(f1.mSize>f2.mSize);
case RsGxsChannelPostFilesModel::COLUMN_FILES_FILE:
{
FileInfo fi1,fi2;
rsFiles->FileDetails(f1.mHash,RS_FILE_HINTS_DOWNLOAD,fi1);
rsFiles->FileDetails(f2.mHash,RS_FILE_HINTS_DOWNLOAD,fi2);
return (ord==Qt::AscendingOrder)?(fi1.transfered<fi2.transfered):(fi1.transfered>fi2.transfered);
}
}
}
private:
int col;
Qt::SortOrder ord;
};
void RsGxsChannelPostFilesModel::sort(int column, Qt::SortOrder order)
{
std::sort(mFiles.begin(),mFiles.end(),compareOperator(column,order));
update();
}
#ifdef TODO
QVariant RsGxsForumModel::textColorRole(const ForumModelPostEntry& fmpe,int /*column*/) const
{

View File

@ -90,6 +90,7 @@ public:
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& child) const override;

View File

@ -302,7 +302,8 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
ui->channelFiles_TV->setSortingEnabled(true);
ui->channelFiles_TV->sortByColumn(0, Qt::AscendingOrder);
//connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder)));
connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnPostFiles(int,Qt::SortOrder)));
connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder)));
connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
connect(mChannelPostsModel,SIGNAL(channelLoaded()),this,SLOT(updateChannelFiles()));
@ -365,11 +366,16 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
}, mEventHandlerId, RsEventType::GXS_CHANNELS );
}
//void GxsChannelPostsWidgetWithModel::sortColumn(int col,Qt::SortOrder so)
//{
// std::cerr << "Sorting!!"<< std::endl;
// mChannelPostFilesProxyModel->sort(col,so);
//}
void GxsChannelPostsWidgetWithModel::sortColumnPostFiles(int col,Qt::SortOrder so)
{
std::cerr << "Sorting post files according to col " << col << std::endl;
mChannelPostFilesModel->sort(col,so);
}
void GxsChannelPostsWidgetWithModel::sortColumnFiles(int col,Qt::SortOrder so)
{
std::cerr << "Sorting channel files according to col " << col << std::endl;
mChannelFilesModel->sort(col,so);
}
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s)
{

View File

@ -140,8 +140,9 @@ private slots:
void handlePostsTreeSizeChange(QSize s);
void updateChannelFiles();
// public slots:
// void sortColumn(int col,Qt::SortOrder so);
public slots:
void sortColumnFiles(int col,Qt::SortOrder so);
void sortColumnPostFiles(int col,Qt::SortOrder so);
private:
void processSettings(bool load);