mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fixed filtering of messages in new forum Model
This commit is contained in:
parent
a51eba1db2
commit
917695e832
@ -25,10 +25,9 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent)
|
||||
{
|
||||
initEmptyHierarchy(mPosts);
|
||||
|
||||
|
||||
mFilterColumn=0;
|
||||
mUseChildTS=false;
|
||||
mFlatView=false;
|
||||
mFilteringEnabled=false;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
if(mFilterColumn < 0)
|
||||
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() ))
|
||||
if(!mFilteringEnabled || (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER))
|
||||
return QVariant(FilterString);
|
||||
|
||||
return QVariant(QString());
|
||||
}
|
||||
|
||||
default:
|
||||
return QVariant(FilterString);
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsForumModel::setFilter(int column,const std::list<std::string>& strings)
|
||||
uint32_t RsGxsForumModel::recursUpdateFilterStatus(ForumModelIndex i,int column,const QStringList& strings)
|
||||
{
|
||||
mFilterColumn = column;
|
||||
mFilterStrings = strings;
|
||||
QString s ;
|
||||
uint32_t count = 0;
|
||||
|
||||
switch(column)
|
||||
{
|
||||
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
|
||||
{
|
||||
// if(column != COLUMN_THREAD_DATA)
|
||||
// if(column != COLUMN_THREAD_DATA)
|
||||
// return QVariant();
|
||||
|
||||
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)
|
||||
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();
|
||||
}
|
||||
|
||||
@ -568,6 +616,7 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<F
|
||||
|
||||
bool has_unread_below,has_read_below ;
|
||||
recursUpdateReadStatus(0,has_unread_below,has_read_below) ;
|
||||
recursUpdateFilterStatus(0,0,QStringList());
|
||||
#ifndef DEBUG_FORUMMODEL
|
||||
debug_dump();
|
||||
#endif
|
||||
@ -655,7 +704,7 @@ void RsGxsForumModel::generateMissingItem(const RsGxsMessageId &msgId,ForumModel
|
||||
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.mAuthorId = msg.mMeta.mAuthorId;
|
||||
@ -903,7 +952,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
|
||||
#endif
|
||||
|
||||
ForumModelPostEntry entry;
|
||||
convertMsgToPostEntry(forum_group,msg, mUseChildTS, mFilterColumn,entry);
|
||||
convertMsgToPostEntry(forum_group,msg, mUseChildTS, entry);
|
||||
|
||||
ForumModelIndex entry_index = addEntry(posts,entry,0);
|
||||
|
||||
@ -995,7 +1044,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
|
||||
|
||||
|
||||
ForumModelPostEntry e ;
|
||||
convertMsgToPostEntry(forum_group,msg,mUseChildTS,mFilterColumn,e) ;
|
||||
convertMsgToPostEntry(forum_group,msg,mUseChildTS,e) ;
|
||||
ForumModelIndex e_index = addEntry(posts,e, threadPair.second);
|
||||
|
||||
//calculateExpand(msg, item);
|
||||
|
@ -36,6 +36,8 @@ struct ForumModelPostEntry
|
||||
FLAG_POST_IS_REDACTED = 0x0004,
|
||||
FLAG_POST_HAS_UNREAD_CHILDREN = 0x0008,
|
||||
FLAG_POST_HAS_READ_CHILDREN = 0x0010,
|
||||
FLAG_POST_PASSES_FILTER = 0x0020,
|
||||
FLAG_POST_CHILDREN_PASSES_FILTER = 0x0040,
|
||||
};
|
||||
|
||||
std::string mTitle ;
|
||||
@ -120,7 +122,7 @@ public:
|
||||
void setTextColorMissing (QColor color) { mTextColorMissing = color;}
|
||||
|
||||
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 columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
@ -164,8 +166,7 @@ private:
|
||||
|
||||
bool mUseChildTS;
|
||||
bool mFlatView;
|
||||
int mFilterColumn;
|
||||
std::list<std::string> mFilterStrings;
|
||||
bool mFilteringEnabled;
|
||||
|
||||
void *getParentRef(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 recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below);
|
||||
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 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 setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions);
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <QPainter>
|
||||
|
||||
#include "util/qtthreadsutils.h"
|
||||
#include "util/misc.h"
|
||||
#include "GxsForumThreadWidget.h"
|
||||
#include "ui_GxsForumThreadWidget.h"
|
||||
#include "GxsForumsFillThread.h"
|
||||
@ -359,7 +360,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
|
||||
|
||||
mSubscribeFlags = 0;
|
||||
mSignFlags = 0;
|
||||
mInProcessSettings = false;
|
||||
mUnreadCount = 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("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("Content"), RsGxsForumModel::COLUMN_THREAD_CONTENT, tr("Search Content"));
|
||||
//ui->filterLineEdit->addFilter(QIcon(), tr("Content"), RsGxsForumModel::COLUMN_THREAD_CONTENT, tr("Search Content"));
|
||||
// see processSettings
|
||||
//ui->filterLineEdit->setCurrentFilter(COLUMN_THREAD_TITLE);
|
||||
|
||||
@ -539,8 +539,6 @@ GxsForumThreadWidget::~GxsForumThreadWidget()
|
||||
|
||||
void GxsForumThreadWidget::processSettings(bool load)
|
||||
{
|
||||
mInProcessSettings = true;
|
||||
|
||||
QHeaderView *header = ui->threadTreeWidget->header();
|
||||
|
||||
Settings->beginGroup(QString("ForumThreadWidget"));
|
||||
@ -575,7 +573,6 @@ void GxsForumThreadWidget::processSettings(bool load)
|
||||
}
|
||||
|
||||
Settings->endGroup();
|
||||
mInProcessSettings = false;
|
||||
}
|
||||
|
||||
void GxsForumThreadWidget::groupIdChanged()
|
||||
@ -2671,16 +2668,13 @@ void GxsForumThreadWidget::changedViewBox()
|
||||
|
||||
void GxsForumThreadWidget::filterColumnChanged(int column)
|
||||
{
|
||||
if (mInProcessSettings) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
if (column == RsGxsForumModel::COLUMN_THREAD_CONTENT) {
|
||||
// need content ... refill
|
||||
//insertThreads();
|
||||
} else {
|
||||
#endif
|
||||
filterItems(ui->filterLineEdit->text());
|
||||
}
|
||||
|
||||
// save index
|
||||
Settings->setValueToGroup("ForumThreadWidget", "filterColumn", column);
|
||||
@ -2688,24 +2682,22 @@ void GxsForumThreadWidget::filterColumnChanged(int column)
|
||||
|
||||
void GxsForumThreadWidget::filterItems(const QString& text)
|
||||
{
|
||||
//FileSearchFlags flags = isRemote()?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL;
|
||||
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();
|
||||
|
||||
mThreadModel->setFilter(filterColumn,keywords) ;
|
||||
uint32_t count;
|
||||
mThreadModel->setFilter(filterColumn,lst,count) ;
|
||||
|
||||
//if(found > 0)
|
||||
// expandAll();
|
||||
if(!lst.empty())
|
||||
ui->threadTreeWidget->expandAll();
|
||||
else
|
||||
ui->threadTreeWidget->collapseAll();
|
||||
|
||||
//if(found == 0)
|
||||
// ui.filterLineEdit->setToolTip(tr("No result.")) ;
|
||||
//else
|
||||
// ui.filterLineEdit->setToolTip(tr("Found %1 results.").arg(found)) ;
|
||||
if(count > 0)
|
||||
ui->filterLineEdit->setToolTip(tr("No result.")) ;
|
||||
else
|
||||
ui->filterLineEdit->setToolTip(tr("Found %1 results.").arg(count)) ;
|
||||
}
|
||||
|
||||
bool GxsForumThreadWidget::filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn)
|
||||
|
Loading…
Reference in New Issue
Block a user