mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-24 23:19:29 -05:00
implemented sorting manually in channel files lists
This commit is contained in:
parent
8c3c973d02
commit
ebbdc082c0
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user