diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp index 86dc330cc..6b4a4b14d 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp @@ -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.mNamef2.mName); + case RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE: return (ord==Qt::AscendingOrder)?(f1.mSizef2.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.transferedfi2.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 { diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h index 17563fa6d..4f0e432ff 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h @@ -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; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index d7b565e0b..c9d0a882a 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -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) { diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index cf7ead667..90c1f76ad 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -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);