mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 07:59:29 -05:00
added sorting and filtering for files using a QPSortFilterProxyModel but it doesnt work yet
This commit is contained in:
parent
32050af8da
commit
c9019a7e99
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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<std::pair<time_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const;
|
||||
|
||||
// This method will asynchroneously update the data
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -161,7 +161,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="channel_TW">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
|
Loading…
Reference in New Issue
Block a user