mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-15 10:00:51 -04:00
added filtering for posts
This commit is contained in:
parent
1cb6369cb6
commit
730a3be2e4
4 changed files with 70 additions and 35 deletions
|
@ -45,15 +45,17 @@ const QString RsGxsChannelPostsModel::FilterString("filtered");
|
||||||
RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent)
|
RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN), mColumns(6)
|
: QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN), mColumns(6)
|
||||||
{
|
{
|
||||||
initEmptyHierarchy(mPosts);
|
initEmptyHierarchy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGxsChannelPostsModel::initEmptyHierarchy(std::vector<RsGxsChannelPost>& posts)
|
void RsGxsChannelPostsModel::initEmptyHierarchy()
|
||||||
{
|
{
|
||||||
preMods();
|
preMods();
|
||||||
|
|
||||||
posts.resize(1); // adds a sentinel item
|
mPosts.resize(1); // adds a sentinel item
|
||||||
posts[0].mMeta.mMsgName = "Root sentinel post" ;
|
mPosts[0].mMeta.mMsgName = "Root sentinel post" ;
|
||||||
|
mFilteredPosts.resize(1);
|
||||||
|
mFilteredPosts[0] = 1;
|
||||||
|
|
||||||
postMods();
|
postMods();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +70,7 @@ void RsGxsChannelPostsModel::postMods()
|
||||||
{
|
{
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mPosts.size(),mColumns-1,(void*)NULL));
|
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredPosts.size(),mColumns-1,(void*)NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGxsChannelPostsModel::getFilesList(std::list<RsGxsFile>& files)
|
void RsGxsChannelPostsModel::getFilesList(std::list<RsGxsFile>& files)
|
||||||
|
@ -87,17 +89,43 @@ void RsGxsChannelPostsModel::getFilesList(std::list<RsGxsFile>& files)
|
||||||
files.push_back(it.second);
|
files.push_back(it.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGxsChannelPostsModel::setTreeMode(TreeMode mode)
|
void RsGxsChannelPostsModel::setFilter(const QStringList& strings, uint32_t& count)
|
||||||
{
|
{
|
||||||
if(mode == mTreeMode)
|
|
||||||
return;
|
|
||||||
|
|
||||||
preMods();
|
preMods();
|
||||||
|
|
||||||
// We're not removing/adding rows here. We're simply asking for re-draw.
|
beginRemoveRows(QModelIndex(),0,rowCount()-1);
|
||||||
|
endRemoveRows();
|
||||||
|
|
||||||
mTreeMode = mode;
|
if(strings.empty())
|
||||||
postMods();
|
{
|
||||||
|
mFilteredPosts.clear();
|
||||||
|
for(int i=0;i<mPosts.size();++i)
|
||||||
|
mFilteredPosts.push_back(i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mFilteredPosts.clear();
|
||||||
|
mFilteredPosts.push_back(0);
|
||||||
|
|
||||||
|
for(int i=1;i<mPosts.size();++i)
|
||||||
|
{
|
||||||
|
bool passes_strings = true;
|
||||||
|
|
||||||
|
for(auto& s:strings)
|
||||||
|
passes_strings = passes_strings && QString::fromStdString(mPosts[i].mMeta.mMsgName).contains(s,Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
if(passes_strings)
|
||||||
|
mFilteredPosts.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count = mFilteredPosts.size();
|
||||||
|
|
||||||
|
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(),0,rowCount()-1);
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
postMods();
|
||||||
}
|
}
|
||||||
|
|
||||||
int RsGxsChannelPostsModel::rowCount(const QModelIndex& parent) const
|
int RsGxsChannelPostsModel::rowCount(const QModelIndex& parent) const
|
||||||
|
@ -105,11 +133,11 @@ int RsGxsChannelPostsModel::rowCount(const QModelIndex& parent) const
|
||||||
if(parent.column() > 0)
|
if(parent.column() > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(mPosts.empty()) // security. Should never happen.
|
if(mFilteredPosts.empty()) // security. Should never happen.
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(!parent.isValid())
|
if(!parent.isValid())
|
||||||
return (mPosts.size()-1 + mColumns-1)/mColumns; // mPosts always has an item at 0, so size()>=1, and mColumn>=1
|
return (mFilteredPosts.size()-1 + mColumns-1)/mColumns; // mFilteredPosts always has an item at 0, so size()>=1, and mColumn>=1
|
||||||
|
|
||||||
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl;
|
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -128,10 +156,10 @@ bool RsGxsChannelPostsModel::getPostData(const QModelIndex& i,RsGxsChannelPost&
|
||||||
quintptr ref = i.internalId();
|
quintptr ref = i.internalId();
|
||||||
uint32_t entry = 0;
|
uint32_t entry = 0;
|
||||||
|
|
||||||
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mPosts.size())
|
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
|
||||||
return false ;
|
return false ;
|
||||||
|
|
||||||
fmpe = mPosts[entry];
|
fmpe = mPosts[mFilteredPosts[entry]];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -247,7 +275,7 @@ quintptr RsGxsChannelPostsModel::getParentRow(quintptr ref,int& row) const
|
||||||
{
|
{
|
||||||
ChannelPostsModelIndex ref_entry;
|
ChannelPostsModelIndex ref_entry;
|
||||||
|
|
||||||
if(!convertRefPointerToTabEntry(ref,ref_entry) || ref_entry >= mPosts.size())
|
if(!convertRefPointerToTabEntry(ref,ref_entry) || ref_entry >= mFilteredPosts.size())
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
|
||||||
if(ref_entry == 0)
|
if(ref_entry == 0)
|
||||||
|
@ -302,7 +330,7 @@ QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const
|
||||||
return QVariant() ;
|
return QVariant() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mPosts.size())
|
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_CHANNEL_MODEL
|
#ifdef DEBUG_CHANNEL_MODEL
|
||||||
std::cerr << "Bad pointer: " << (void*)ref << std::endl;
|
std::cerr << "Bad pointer: " << (void*)ref << std::endl;
|
||||||
|
@ -310,7 +338,7 @@ QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const
|
||||||
return QVariant() ;
|
return QVariant() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RsGxsChannelPost& fmpe(mPosts[entry]);
|
const RsGxsChannelPost& fmpe(mPosts[mFilteredPosts[entry]]);
|
||||||
|
|
||||||
switch(role)
|
switch(role)
|
||||||
{
|
{
|
||||||
|
@ -367,7 +395,7 @@ void RsGxsChannelPostsModel::clear()
|
||||||
preMods();
|
preMods();
|
||||||
|
|
||||||
mPosts.clear();
|
mPosts.clear();
|
||||||
initEmptyHierarchy(mPosts);
|
initEmptyHierarchy();
|
||||||
|
|
||||||
postMods();
|
postMods();
|
||||||
emit channelLoaded();
|
emit channelLoaded();
|
||||||
|
@ -385,6 +413,10 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto
|
||||||
|
|
||||||
createPostsArray(posts);
|
createPostsArray(posts);
|
||||||
|
|
||||||
|
mFilteredPosts.clear();
|
||||||
|
for(int i=0;i<mPosts.size();++i)
|
||||||
|
mFilteredPosts.push_back(i);
|
||||||
|
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
recursUpdateReadStatusAndTimes(0,has_unread_below,has_read_below) ;
|
recursUpdateReadStatusAndTimes(0,has_unread_below,has_read_below) ;
|
||||||
recursUpdateFilterStatus(0,0,QStringList());
|
recursUpdateFilterStatus(0,0,QStringList());
|
||||||
|
@ -588,7 +620,7 @@ void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_sta
|
||||||
quintptr ref = i.internalId();
|
quintptr ref = i.internalId();
|
||||||
uint32_t entry = 0;
|
uint32_t entry = 0;
|
||||||
|
|
||||||
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mPosts.size())
|
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
#warning TODO
|
#warning TODO
|
||||||
|
@ -603,11 +635,11 @@ QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid)
|
||||||
|
|
||||||
RsGxsMessageId postId = mid;
|
RsGxsMessageId postId = mid;
|
||||||
|
|
||||||
for(uint32_t i=1;i<mPosts.size();++i)
|
for(uint32_t i=1;i<mFilteredPosts.size();++i)
|
||||||
{
|
{
|
||||||
// First look into msg versions, in case the msg is a version of an existing message
|
// First look into msg versions, in case the msg is a version of an existing message
|
||||||
|
|
||||||
for(auto& msg_id:mPosts[i].mOlderVersions)
|
for(auto& msg_id:mPosts[mFilteredPosts[i]].mOlderVersions)
|
||||||
if(msg_id == postId)
|
if(msg_id == postId)
|
||||||
{
|
{
|
||||||
quintptr ref ;
|
quintptr ref ;
|
||||||
|
@ -616,7 +648,7 @@ QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid)
|
||||||
return createIndex((i-1)%mColumns, (i-1)/mColumns,ref);
|
return createIndex((i-1)%mColumns, (i-1)/mColumns,ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mPosts[i].mMeta.mMsgId == postId)
|
if(mPosts[mFilteredPosts[i]].mMeta.mMsgId == postId)
|
||||||
{
|
{
|
||||||
quintptr ref ;
|
quintptr ref ;
|
||||||
convertTabEntryToRefPointer(i,ref); // we dont use i+1 here because i is not a row, but an index in the mPosts tab
|
convertTabEntryToRefPointer(i,ref); // we dont use i+1 here because i is not a row, but an index in the mPosts tab
|
||||||
|
|
|
@ -109,7 +109,6 @@ public:
|
||||||
void updateChannel(const RsGxsGroupId& channel_group_id);
|
void updateChannel(const RsGxsGroupId& channel_group_id);
|
||||||
const RsGxsGroupId& currentGroupId() const;
|
const RsGxsGroupId& currentGroupId() const;
|
||||||
|
|
||||||
void setTreeMode(TreeMode mode) ;
|
|
||||||
void setNumColumns(int n);
|
void setNumColumns(int n);
|
||||||
|
|
||||||
// Retrieve the full list of files for all posts.
|
// Retrieve the full list of files for all posts.
|
||||||
|
@ -127,8 +126,9 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children);
|
void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children);
|
||||||
|
void setFilter(const QStringList &strings, uint32_t &count) ;
|
||||||
|
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
void setFilter(int column, const QStringList &strings, uint32_t &count) ;
|
|
||||||
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -218,9 +218,11 @@ private:
|
||||||
//void computeMessagesHierarchy(const RsGxsChannelGroup& forum_group, const std::vector<RsMsgMetaData> &msgs_array, std::vector<ChannelPostsModelPostEntry> &posts, std::map<RsGxsMessageId, std::vector<std::pair<time_t, RsGxsMessageId> > > &mPostVersions);
|
//void computeMessagesHierarchy(const RsGxsChannelGroup& forum_group, const std::vector<RsMsgMetaData> &msgs_array, std::vector<ChannelPostsModelPostEntry> &posts, std::map<RsGxsMessageId, std::vector<std::pair<time_t, RsGxsMessageId> > > &mPostVersions);
|
||||||
void createPostsArray(std::vector<RsGxsChannelPost> &posts);
|
void createPostsArray(std::vector<RsGxsChannelPost> &posts);
|
||||||
void setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost> &posts);
|
void setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost> &posts);
|
||||||
void initEmptyHierarchy(std::vector<RsGxsChannelPost>& posts);
|
void initEmptyHierarchy();
|
||||||
|
|
||||||
|
std::vector<int> mFilteredPosts; // stores the list of displayes indices due to filtering.
|
||||||
|
std::vector<RsGxsChannelPost> mPosts ; // store the list of posts updated from rsForums.
|
||||||
|
|
||||||
std::vector<RsGxsChannelPost> mPosts ; // store the list of posts updated from rsForums.
|
|
||||||
//std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > > mPostVersions; // stores versions of posts
|
//std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > > mPostVersions; // stores versions of posts
|
||||||
|
|
||||||
QColor mTextColorRead ;
|
QColor mTextColorRead ;
|
||||||
|
|
|
@ -209,6 +209,7 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI
|
||||||
GxsChannelFilesStatusWidget w(file);
|
GxsChannelFilesStatusWidget w(file);
|
||||||
|
|
||||||
w.setFixedWidth(option.rect.width());
|
w.setFixedWidth(option.rect.width());
|
||||||
|
w.setFixedHeight(option.rect.height());
|
||||||
|
|
||||||
QPixmap pixmap(w.size());
|
QPixmap pixmap(w.size());
|
||||||
pixmap.fill(QRgb(0x00ffffff)); // choose a fully transparent background
|
pixmap.fill(QRgb(0x00ffffff)); // choose a fully transparent background
|
||||||
|
@ -283,7 +284,8 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
||||||
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), ui->feedWidget, SLOT(setFilterText(QString)));
|
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), ui->feedWidget, SLOT(setFilterText(QString)));
|
||||||
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), ui->fileWidget, SLOT(setFilterText(QString)));
|
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), ui->fileWidget, SLOT(setFilterText(QString)));
|
||||||
#endif
|
#endif
|
||||||
connect(ui->filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterChanged(int)));
|
connect(ui->filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterChanged()));
|
||||||
|
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged()));
|
||||||
|
|
||||||
/* Initialize view button */
|
/* Initialize view button */
|
||||||
//setViewMode(VIEW_MODE_FEEDS); see processSettings
|
//setViewMode(VIEW_MODE_FEEDS); see processSettings
|
||||||
|
@ -743,12 +745,11 @@ void GxsChannelPostsWidgetWithModel::setViewMode(int viewMode)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxsChannelPostsWidgetWithModel::filterChanged(int filter)
|
void GxsChannelPostsWidgetWithModel::filterChanged()
|
||||||
{
|
{
|
||||||
#ifdef TODO
|
QStringList ql = ui->filterLineEdit->text().split(' ',QString::SkipEmptyParts);
|
||||||
ui->feedWidget->setFilterType(filter);
|
uint32_t count;
|
||||||
ui->fileWidget->setFilterType(filter);
|
mChannelPostsModel->setFilter(ql,count);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
|
|
|
@ -132,7 +132,7 @@ private slots:
|
||||||
void createMsg();
|
void createMsg();
|
||||||
void toggleAutoDownload();
|
void toggleAutoDownload();
|
||||||
void subscribeGroup(bool subscribe);
|
void subscribeGroup(bool subscribe);
|
||||||
void filterChanged(int filter);
|
void filterChanged();
|
||||||
void setViewMode(int viewMode);
|
void setViewMode(int viewMode);
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
void handlePostsTreeSizeChange(QSize s);
|
void handlePostsTreeSizeChange(QSize s);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue