fixed filtering of messages in new forum Model

This commit is contained in:
csoler 2018-12-01 23:14:08 +01:00
parent a51eba1db2
commit 917695e832
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 103 additions and 60 deletions

View File

@ -25,10 +25,9 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent)
{ {
initEmptyHierarchy(mPosts); initEmptyHierarchy(mPosts);
mFilterColumn=0;
mUseChildTS=false; mUseChildTS=false;
mFlatView=false; mFlatView=false;
mFilteringEnabled=false;
} }
void RsGxsForumModel::initEmptyHierarchy(std::vector<ForumModelPostEntry>& posts) void RsGxsForumModel::initEmptyHierarchy(std::vector<ForumModelPostEntry>& posts)
@ -343,38 +342,84 @@ QVariant RsGxsForumModel::statusRole(const ForumModelPostEntry& fmpe,int column)
QVariant RsGxsForumModel::filterRole(const ForumModelPostEntry& fmpe,int column) const QVariant RsGxsForumModel::filterRole(const ForumModelPostEntry& fmpe,int column) const
{ {
if(mFilterColumn < 0) if(!mFilteringEnabled || (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER))
return QVariant(QString());
switch(mFilterColumn)
{
case COLUMN_THREAD_TITLE:
{
for(auto iter(mFilterStrings.begin()); iter != mFilterStrings.end(); ++iter)
if(fmpe.mTitle.end() != std::search( fmpe.mTitle.begin(), fmpe.mTitle.end(), (*iter).begin(), (*iter).end(), RsRegularExpression::CompareCharIC() ))
return QVariant(FilterString);
return QVariant(QString());
}
default:
return QVariant(FilterString); return QVariant(FilterString);
}
return QVariant(QString());
} }
void RsGxsForumModel::setFilter(int column,const std::list<std::string>& strings) uint32_t RsGxsForumModel::recursUpdateFilterStatus(ForumModelIndex i,int column,const QStringList& strings)
{ {
mFilterColumn = column; QString s ;
mFilterStrings = strings; uint32_t count = 0;
emit layoutAboutToBeChanged(); switch(column)
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); {
emit layoutChanged(); default:
case COLUMN_THREAD_DATE:
case COLUMN_THREAD_TITLE: s = displayRole(mPosts[i],column).toString();
break;
case COLUMN_THREAD_AUTHOR:
{
QString comment ;
QList<QIcon> icons;
GxsIdDetails::MakeIdDesc(mPosts[i].mAuthorId, false,s, icons, comment,GxsIdDetails::ICON_TYPE_NONE);
}
break;
}
if(!strings.empty())
{
mPosts[i].mPostFlags &= ~(ForumModelPostEntry::FLAG_POST_PASSES_FILTER | ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER);
for(auto iter(strings.begin()); iter != strings.end(); ++iter)
if(s.contains(*iter,Qt::CaseInsensitive))
{
mPosts[i].mPostFlags |= ForumModelPostEntry::FLAG_POST_PASSES_FILTER | ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER;
count++;
break;
}
}
else
{
mPosts[i].mPostFlags |= ForumModelPostEntry::FLAG_POST_PASSES_FILTER |ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER;
count++;
}
for(uint32_t j=0;j<mPosts[i].mChildren.size();++j)
{
uint32_t tmp = recursUpdateFilterStatus(mPosts[i].mChildren[j],column,strings);
count += tmp;
if(tmp > 0)
mPosts[i].mPostFlags |= ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER;
}
return count;
}
void RsGxsForumModel::setFilter(int column,const QStringList& strings,uint32_t& count)
{
emit layoutAboutToBeChanged();
if(!strings.empty())
{
count = recursUpdateFilterStatus(ForumModelIndex(0),column,strings);
mFilteringEnabled = true;
}
else
mFilteringEnabled = false;
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
emit layoutChanged();
} }
QVariant RsGxsForumModel::missingRole(const ForumModelPostEntry& fmpe,int column) const QVariant RsGxsForumModel::missingRole(const ForumModelPostEntry& fmpe,int column) const
{ {
// if(column != COLUMN_THREAD_DATA) // if(column != COLUMN_THREAD_DATA)
// return QVariant(); // return QVariant();
if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_MISSING) if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_MISSING)
@ -433,6 +478,9 @@ QVariant RsGxsForumModel::backgroundRole(const ForumModelPostEntry& fmpe,int col
if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_PINNED) if(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_PINNED)
return QVariant(QBrush(QColor(255,200,180))); return QVariant(QBrush(QColor(255,200,180)));
if(mFilteringEnabled && (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_PASSES_FILTER))
return QVariant(QBrush(QColor(255,240,210)));
return QVariant(); return QVariant();
} }
@ -568,6 +616,7 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<F
bool has_unread_below,has_read_below ; bool has_unread_below,has_read_below ;
recursUpdateReadStatus(0,has_unread_below,has_read_below) ; recursUpdateReadStatus(0,has_unread_below,has_read_below) ;
recursUpdateFilterStatus(0,0,QStringList());
#ifndef DEBUG_FORUMMODEL #ifndef DEBUG_FORUMMODEL
debug_dump(); debug_dump();
#endif #endif
@ -655,7 +704,7 @@ void RsGxsForumModel::generateMissingItem(const RsGxsMessageId &msgId,ForumModel
entry.mReputationWarningLevel = 3; entry.mReputationWarningLevel = 3;
} }
void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,const RsGxsForumMsg& msg, bool useChildTS, uint32_t filterColumn,ForumModelPostEntry& fentry) void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,const RsGxsForumMsg& msg, bool useChildTS, ForumModelPostEntry& fentry)
{ {
fentry.mTitle = msg.mMeta.mMsgName; fentry.mTitle = msg.mMeta.mMsgName;
fentry.mAuthorId = msg.mMeta.mAuthorId; fentry.mAuthorId = msg.mMeta.mAuthorId;
@ -903,7 +952,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
#endif #endif
ForumModelPostEntry entry; ForumModelPostEntry entry;
convertMsgToPostEntry(forum_group,msg, mUseChildTS, mFilterColumn,entry); convertMsgToPostEntry(forum_group,msg, mUseChildTS, entry);
ForumModelIndex entry_index = addEntry(posts,entry,0); ForumModelIndex entry_index = addEntry(posts,entry,0);
@ -995,7 +1044,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
ForumModelPostEntry e ; ForumModelPostEntry e ;
convertMsgToPostEntry(forum_group,msg,mUseChildTS,mFilterColumn,e) ; convertMsgToPostEntry(forum_group,msg,mUseChildTS,e) ;
ForumModelIndex e_index = addEntry(posts,e, threadPair.second); ForumModelIndex e_index = addEntry(posts,e, threadPair.second);
//calculateExpand(msg, item); //calculateExpand(msg, item);

View File

@ -31,11 +31,13 @@ struct ForumModelPostEntry
ForumModelPostEntry() : mPublishTs(0),mPostFlags(0),mReputationWarningLevel(0),mMsgStatus(0),prow(0) {} ForumModelPostEntry() : mPublishTs(0),mPostFlags(0),mReputationWarningLevel(0),mMsgStatus(0),prow(0) {}
enum { // flags for display of posts. To be used in mPostFlags enum { // flags for display of posts. To be used in mPostFlags
FLAG_POST_IS_PINNED = 0x0001, FLAG_POST_IS_PINNED = 0x0001,
FLAG_POST_IS_MISSING = 0x0002, FLAG_POST_IS_MISSING = 0x0002,
FLAG_POST_IS_REDACTED = 0x0004, FLAG_POST_IS_REDACTED = 0x0004,
FLAG_POST_HAS_UNREAD_CHILDREN = 0x0008, FLAG_POST_HAS_UNREAD_CHILDREN = 0x0008,
FLAG_POST_HAS_READ_CHILDREN = 0x0010, FLAG_POST_HAS_READ_CHILDREN = 0x0010,
FLAG_POST_PASSES_FILTER = 0x0020,
FLAG_POST_CHILDREN_PASSES_FILTER = 0x0040,
}; };
std::string mTitle ; std::string mTitle ;
@ -120,7 +122,7 @@ public:
void setTextColorMissing (QColor color) { mTextColorMissing = color;} void setTextColorMissing (QColor color) { mTextColorMissing = color;}
void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children); void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children);
void setFilter(int column,const std::list<std::string>& strings) ; void setFilter(int column, const QStringList &strings, uint32_t &count) ;
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
@ -164,8 +166,7 @@ private:
bool mUseChildTS; bool mUseChildTS;
bool mFlatView; bool mFlatView;
int mFilterColumn; bool mFilteringEnabled;
std::list<std::string> mFilterStrings;
void *getParentRef(void *ref,int& row) const; void *getParentRef(void *ref,int& row) const;
void *getChildRef(void *ref,int row) const; void *getChildRef(void *ref,int row) const;
@ -179,10 +180,11 @@ private:
void setForumMessageSummary(const std::vector<RsGxsForumMsg>& messages); void setForumMessageSummary(const std::vector<RsGxsForumMsg>& messages);
void recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below); void recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below);
void recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children); void recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children);
uint32_t recursUpdateFilterStatus(ForumModelIndex i,int column,const QStringList& strings);
static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry); static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry);
static ForumModelIndex addEntry(std::vector<ForumModelPostEntry>& posts,const ForumModelPostEntry& entry,ForumModelIndex parent); static ForumModelIndex addEntry(std::vector<ForumModelPostEntry>& posts,const ForumModelPostEntry& entry,ForumModelIndex parent);
static void convertMsgToPostEntry(const RsGxsForumGroup &mForumGroup, const RsGxsForumMsg& msg, bool useChildTS, uint32_t filterColumn, ForumModelPostEntry& fentry); static void convertMsgToPostEntry(const RsGxsForumGroup &mForumGroup, const RsGxsForumMsg& msg, bool useChildTS, ForumModelPostEntry& fentry);
void computeMessagesHierarchy(const RsGxsForumGroup& forum_group, const std::vector<RsGxsForumMsg>& msgs_array, std::vector<ForumModelPostEntry>& posts, std::map<RsGxsMessageId, std::vector<std::pair<time_t, RsGxsMessageId> > > &mPostVersions); void computeMessagesHierarchy(const RsGxsForumGroup& forum_group, const std::vector<RsGxsForumMsg>& msgs_array, std::vector<ForumModelPostEntry>& posts, std::map<RsGxsMessageId, std::vector<std::pair<time_t, RsGxsMessageId> > > &mPostVersions);
void setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions); void setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions);

View File

@ -25,6 +25,7 @@
#include <QPainter> #include <QPainter>
#include "util/qtthreadsutils.h" #include "util/qtthreadsutils.h"
#include "util/misc.h"
#include "GxsForumThreadWidget.h" #include "GxsForumThreadWidget.h"
#include "ui_GxsForumThreadWidget.h" #include "ui_GxsForumThreadWidget.h"
#include "GxsForumsFillThread.h" #include "GxsForumsFillThread.h"
@ -359,7 +360,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
mSubscribeFlags = 0; mSubscribeFlags = 0;
mSignFlags = 0; mSignFlags = 0;
mInProcessSettings = false;
mUnreadCount = 0; mUnreadCount = 0;
mNewCount = 0; mNewCount = 0;
@ -434,7 +434,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
ui->filterLineEdit->addFilter(QIcon(), tr("Title"), RsGxsForumModel::COLUMN_THREAD_TITLE, tr("Search Title")); ui->filterLineEdit->addFilter(QIcon(), tr("Title"), RsGxsForumModel::COLUMN_THREAD_TITLE, tr("Search Title"));
ui->filterLineEdit->addFilter(QIcon(), tr("Date"), RsGxsForumModel::COLUMN_THREAD_DATE, tr("Search Date")); ui->filterLineEdit->addFilter(QIcon(), tr("Date"), RsGxsForumModel::COLUMN_THREAD_DATE, tr("Search Date"));
ui->filterLineEdit->addFilter(QIcon(), tr("Author"), RsGxsForumModel::COLUMN_THREAD_AUTHOR, tr("Search Author")); ui->filterLineEdit->addFilter(QIcon(), tr("Author"), RsGxsForumModel::COLUMN_THREAD_AUTHOR, tr("Search Author"));
ui->filterLineEdit->addFilter(QIcon(), tr("Content"), RsGxsForumModel::COLUMN_THREAD_CONTENT, tr("Search Content")); //ui->filterLineEdit->addFilter(QIcon(), tr("Content"), RsGxsForumModel::COLUMN_THREAD_CONTENT, tr("Search Content"));
// see processSettings // see processSettings
//ui->filterLineEdit->setCurrentFilter(COLUMN_THREAD_TITLE); //ui->filterLineEdit->setCurrentFilter(COLUMN_THREAD_TITLE);
@ -539,8 +539,6 @@ GxsForumThreadWidget::~GxsForumThreadWidget()
void GxsForumThreadWidget::processSettings(bool load) void GxsForumThreadWidget::processSettings(bool load)
{ {
mInProcessSettings = true;
QHeaderView *header = ui->threadTreeWidget->header(); QHeaderView *header = ui->threadTreeWidget->header();
Settings->beginGroup(QString("ForumThreadWidget")); Settings->beginGroup(QString("ForumThreadWidget"));
@ -575,7 +573,6 @@ void GxsForumThreadWidget::processSettings(bool load)
} }
Settings->endGroup(); Settings->endGroup();
mInProcessSettings = false;
} }
void GxsForumThreadWidget::groupIdChanged() void GxsForumThreadWidget::groupIdChanged()
@ -2671,16 +2668,13 @@ void GxsForumThreadWidget::changedViewBox()
void GxsForumThreadWidget::filterColumnChanged(int column) void GxsForumThreadWidget::filterColumnChanged(int column)
{ {
if (mInProcessSettings) { #ifdef TO_REMOVE
return;
}
if (column == RsGxsForumModel::COLUMN_THREAD_CONTENT) { if (column == RsGxsForumModel::COLUMN_THREAD_CONTENT) {
// need content ... refill // need content ... refill
//insertThreads(); //insertThreads();
} else { } else {
filterItems(ui->filterLineEdit->text()); #endif
} filterItems(ui->filterLineEdit->text());
// save index // save index
Settings->setValueToGroup("ForumThreadWidget", "filterColumn", column); Settings->setValueToGroup("ForumThreadWidget", "filterColumn", column);
@ -2688,24 +2682,22 @@ void GxsForumThreadWidget::filterColumnChanged(int column)
void GxsForumThreadWidget::filterItems(const QString& text) void GxsForumThreadWidget::filterItems(const QString& text)
{ {
//FileSearchFlags flags = isRemote()?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL;
QStringList lst = text.split(" ",QString::SkipEmptyParts) ; QStringList lst = text.split(" ",QString::SkipEmptyParts) ;
std::list<std::string> keywords ;
for(auto it(lst.begin());it!=lst.end();++it)
keywords.push_back((*it).toStdString());
int filterColumn = ui->filterLineEdit->currentFilter(); int filterColumn = ui->filterLineEdit->currentFilter();
mThreadModel->setFilter(filterColumn,keywords) ; uint32_t count;
mThreadModel->setFilter(filterColumn,lst,count) ;
//if(found > 0) if(!lst.empty())
// expandAll(); ui->threadTreeWidget->expandAll();
else
ui->threadTreeWidget->collapseAll();
//if(found == 0) if(count > 0)
// ui.filterLineEdit->setToolTip(tr("No result.")) ; ui->filterLineEdit->setToolTip(tr("No result.")) ;
//else else
// ui.filterLineEdit->setToolTip(tr("Found %1 results.").arg(found)) ; ui->filterLineEdit->setToolTip(tr("Found %1 results.").arg(count)) ;
} }
bool GxsForumThreadWidget::filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn) bool GxsForumThreadWidget::filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn)