diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp index b1b7eddbd..b585d242b 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp @@ -384,14 +384,6 @@ QVariant RsGxsForumModel::statusRole(const ForumModelPostEntry& fmpe,int column) return QVariant(fmpe.mMsgStatus); } -QVariant RsGxsForumModel::filterRole(const ForumModelPostEntry& fmpe,int /*column*/) const -{ - if(!mFilteringEnabled || (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER)) - return QVariant(FilterString); - - return QVariant(QString()); -} - uint32_t RsGxsForumModel::recursUpdateFilterStatus(ForumModelIndex i,int column,const QStringList& strings) { QString s ; @@ -609,8 +601,6 @@ QVariant RsGxsChannelPostFilesModel::displayRole(const RsGxsFile& fmpe,int col) return QVariant(tr("[Unknown]")); } case COLUMN_THREAD_MSGID: return QVariant(); -#endif -#ifdef TODO if (filterColumn == COLUMN_THREAD_CONTENT) { // need content for filter QTextDocument doc; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h index eb214516a..e7dd47802 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h @@ -105,6 +105,7 @@ public: QVariant toolTipRole (const RsGxsFile& fmpe, int col) const; QVariant userRole (const RsGxsFile& fmpe, int col) const; QVariant sortRole (const RsGxsFile& fmpe, int col) const; + QVariant filterRole (const RsGxsFile& fmpe, int col) const; #ifdef TODO QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const; QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const; @@ -112,7 +113,6 @@ public: QVariant statusRole (const ForumModelPostEntry& fmpe, int col) const; QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const; QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const; - QVariant filterRole (const ForumModelPostEntry& fmpe, int col) const; QVariant textColorRole (const ForumModelPostEntry& fmpe, int col) const; QVariant backgroundRole(const ForumModelPostEntry& fmpe, int col) const; #endif diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index b2363b99c..94d6f6406 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -40,8 +40,6 @@ Q_DECLARE_METATYPE(RsGxsChannelPost) std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere -const QString RsGxsChannelPostsModel::FilterString("filtered"); - RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent) : QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN), mColumns(6) { diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h index 51d794b4b..b82f91783 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h @@ -101,8 +101,6 @@ public: QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;} QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const; - static const QString FilterString ; - std::vector > getPostVersions(const RsGxsMessageId& mid) const; // This method will asynchroneously update the data diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 3aa9084d6..1d3a47d71 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -240,6 +240,40 @@ QSize ChannelPostFilesDelegate::sizeHint(const QStyleOptionViewItem& option, con } } +class RsGxsChannelPostFilesProxyModel: public QSortFilterProxyModel +{ +public: + RsGxsChannelPostFilesProxyModel(QObject *parent = NULL): QSortFilterProxyModel(parent) {} + + bool lessThan(const QModelIndex& left, const QModelIndex& right) const override + { + return left.data(RsGxsChannelPostFilesModel::SortRole) < right.data(RsGxsChannelPostFilesModel::SortRole) ; + } + + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override + { + if(filter_list.empty()) + return true; + + QString name = sourceModel()->data(sourceModel()->index(source_row,RsGxsChannelPostFilesModel::COLUMN_FILES_NAME,source_parent)).toString(); + + for(auto& s:filter_list) + if(!name.contains(s,Qt::CaseInsensitive)) + return false; + + return true; + } + + void setFilterList(const QStringList& str) + { + filter_list = str; + invalidateFilter(); + } + +private: + QStringList filter_list; +}; + /** Constructor */ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) : GxsMessageFrameWidget(rsGxsChannels, parent), @@ -251,14 +285,24 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI ui->postsTree->setModel(mChannelPostsModel = new RsGxsChannelPostsModel()); ui->postsTree->setItemDelegate(new ChannelPostDelegate()); - ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel()); + mChannelPostFilesModel = new RsGxsChannelPostFilesModel(this); + + mChannelPostFilesProxyModel = new RsGxsChannelPostFilesProxyModel(this); + mChannelPostFilesProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + mChannelPostFilesProxyModel->setSourceModel(mChannelPostFilesModel); + mChannelPostFilesProxyModel->setDynamicSortFilter(true); + + ui->channelPostFiles_TV->setModel(mChannelPostFilesProxyModel); ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate()); ui->channelPostFiles_TV->setPlaceholderText(tr("Post files")); + ui->channelPostFiles_TV->setSortingEnabled(true); + ui->channelPostFiles_TV->sortByColumn(0, Qt::AscendingOrder); ui->channelFiles_TV->setPlaceholderText(tr("All files in the channel")); ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel()); ui->channelFiles_TV->setItemDelegate(new ChannelPostFilesDelegate()); + connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder))); connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails())); connect(mChannelPostsModel,SIGNAL(channelLoaded()),this,SLOT(updateChannelFiles())); @@ -277,6 +321,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI ui->postButton->setText(tr("Add new post")); /* add filter actions */ + ui->filterLineEdit->setPlaceholderText(tr("Search...")); connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString))); /* Initialize view button */ @@ -335,6 +380,12 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI connect(ui->postsTree,SIGNAL(sizeChanged(QSize)),this,SLOT(handlePostsTreeSizeChange(QSize))); } +void GxsChannelPostsWidgetWithModel::sortColumn(int col,Qt::SortOrder so) +{ + std::cerr << "Sorting!!"<< std::endl; + mChannelPostFilesProxyModel->sort(col,so); +} + void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s) { // adjustSize(); @@ -749,6 +800,10 @@ void GxsChannelPostsWidgetWithModel::filterChanged(QString s) QStringList ql = s.split(' ',QString::SkipEmptyParts); uint32_t count; mChannelPostsModel->setFilter(ql,count); + + mChannelPostFilesProxyModel->setFilterKeyColumn(RsGxsChannelPostFilesModel::COLUMN_FILES_NAME); + mChannelPostFilesProxyModel->setFilterList(ql); + mChannelPostFilesProxyModel->setFilterRegExp(QRegExp()) ;// triggers a re-display. } #ifdef TODO diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index 8dd9a66bd..375290f61 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -34,9 +34,11 @@ class GxsChannelPostsWidgetWithModel; class GxsChannelPostItem; class QTreeWidgetItem; +class QSortFilterProxyModel; class FeedItem; class RsGxsChannelPostsModel; class RsGxsChannelPostFilesModel; +class RsGxsChannelPostFilesProxyModel; class ChannelPostFilesDelegate: public QStyledItemDelegate { @@ -137,6 +139,7 @@ private slots: void settingsChanged(); void handlePostsTreeSizeChange(QSize s); void updateChannelFiles(); + void sortColumn(int col,Qt::SortOrder so); private: void processSettings(bool load); @@ -159,6 +162,7 @@ private: RsGxsChannelPostsModel *mChannelPostsModel; RsGxsChannelPostFilesModel *mChannelPostFilesModel; RsGxsChannelPostFilesModel *mChannelFilesModel; + RsGxsChannelPostFilesProxyModel *mChannelPostFilesProxyModel ; /* UI - from Designer */ Ui::GxsChannelPostsWidgetWithModel *ui; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui index 84a73fb9c..751c2bc69 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.ui @@ -161,7 +161,7 @@ - 1 + 2