fixed search filter

This commit is contained in:
csoler 2019-03-12 15:59:54 +01:00
parent 59b1d44e5b
commit c9561c2684
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 94 additions and 100 deletions

View File

@ -823,7 +823,7 @@ void MessagesDialog::changeQuickView(int newrow)
case 0x05: f = RsMessageModel::QUICK_VIEW_TODO ; break;
case 0x06: f = RsMessageModel::QUICK_VIEW_LATER ; break;
default:
f = RsMessageModel::QuickViewFilter( (int)RsMessageModel::QUICK_VIEW_USER + newrow - 0x06);
f = RsMessageModel::QuickViewFilter( (int)RsMessageModel::QUICK_VIEW_USER + newrow - 0x07);
}
mMessageModel->setQuickViewFilter(f);
insertMsgTxtAndFiles(ui.messageTreeWidget->currentIndex());
@ -1438,18 +1438,6 @@ void MessagesDialog::insertMsgTxtAndFiles(const QModelIndex& index)
}
mid = index.data(RsMessageModel::MsgIdRole).toString().toStdString();
// int nCount = getSelectedMsgCount (NULL, NULL, NULL, NULL);
//
// if (nCount == 1) {
// ui.actionSaveAs->setEnabled(true);
// ui.actionPrintPreview->setEnabled(true);
// ui.actionPrint->setEnabled(true);
// } else {
// ui.actionSaveAs->setDisabled(true);
// ui.actionPrintPreview->setDisabled(true);
// ui.actionPrint->setDisabled(true);
// }
/* Save the Data.... for later */
MessageInfo msgInfo;
@ -1458,27 +1446,17 @@ void MessagesDialog::insertMsgTxtAndFiles(const QModelIndex& index)
return;
}
// QList<QTreeWidgetItem*> items;
// items.append(item);
//
// bool bSetToReadOnActive = Settings->getMsgSetToReadOnActivate();
//
// if (msgInfo.msgflags & RS_MSG_NEW) {
// // set always to read or unread
// if (bSetToReadOnActive == false || bSetToRead == false) {
// // set locally to unread
// setMsgAsReadUnread(items, false);
// } else {
// setMsgAsReadUnread(items, true);
// }
// updateMessageSummaryList();
// } else {
// if ((msgInfo.msgflags & RS_MSG_UNREAD_BY_USER) && bSetToRead && bSetToReadOnActive) {
// // set to read
// setMsgAsReadUnread(items, true);
// updateMessageSummaryList();
// }
// }
bool bSetToReadOnActive = Settings->getMsgSetToReadOnActivate();
if (msgInfo.msgflags & RS_MSG_NEW) // set always to read or unread
{
if (!bSetToReadOnActive) // set locally to unread
mMessageModel->setMsgReadStatus(index, false);
else
mMessageModel->setMsgReadStatus(index, true);
}
else if ((msgInfo.msgflags & RS_MSG_UNREAD_BY_USER) && bSetToReadOnActive) // set to read
mMessageModel->setMsgReadStatus(index, true);
updateInterface();
msgWidget->fill(mid);
@ -1565,7 +1543,21 @@ void MessagesDialog::buttonStyle()
void MessagesDialog::filterChanged(const QString& text)
{
QStringList items = text.split(' ',QString::SkipEmptyParts);
mMessageModel->setFilter(ui.filterLineEdit->currentFilter(),items);
RsMessageModel::FilterType f = RsMessageModel::FILTER_TYPE_NONE;
switch(ui.filterLineEdit->currentFilter())
{
case COLUMN_SUBJECT: f = RsMessageModel::FILTER_TYPE_SUBJECT ; break;
case COLUMN_FROM: f = RsMessageModel::FILTER_TYPE_FROM ; break;
case COLUMN_DATE: f = RsMessageModel::FILTER_TYPE_DATE ; break;
case COLUMN_CONTENT: f = RsMessageModel::FILTER_TYPE_CONTENT ; break;
case COLUMN_TAGS: f = RsMessageModel::FILTER_TYPE_TAGS ; break;
case COLUMN_ATTACHEMENTS: f = RsMessageModel::FILTER_TYPE_ATTACHMENTS ; break;
default:break;
}
mMessageModel->setFilter(f,items);
}
void MessagesDialog::filterColumnChanged(int column)
@ -1573,8 +1565,21 @@ void MessagesDialog::filterColumnChanged(int column)
if (inProcessSettings)
return;
RsMessageModel::FilterType f = RsMessageModel::FILTER_TYPE_NONE;
switch(column)
{
case COLUMN_SUBJECT: f = RsMessageModel::FILTER_TYPE_SUBJECT ; break;
case COLUMN_FROM: f = RsMessageModel::FILTER_TYPE_FROM ; break;
case COLUMN_DATE: f = RsMessageModel::FILTER_TYPE_DATE ; break;
case COLUMN_CONTENT: f = RsMessageModel::FILTER_TYPE_CONTENT ; break;
case COLUMN_TAGS: f = RsMessageModel::FILTER_TYPE_TAGS ; break;
case COLUMN_ATTACHEMENTS: f = RsMessageModel::FILTER_TYPE_ATTACHMENTS ; break;
default:break;
}
QStringList items = ui.filterLineEdit->text().split(' ',QString::SkipEmptyParts);
mMessageModel->setFilter(column,items);
mMessageModel->setFilter(f,items);
// save index
Settings->setValueToGroup("MessageDialog", "filterColumn", column);

View File

@ -51,6 +51,7 @@ RsMessageModel::RsMessageModel(QObject *parent)
mFilteringEnabled=false;
mCurrentBox = BOX_NONE;
mQuickViewFilter = QUICK_VIEW_ALL;
mFilterType = FILTER_TYPE_NONE;
}
void RsMessageModel::preMods()
@ -277,13 +278,13 @@ QVariant RsMessageModel::data(const QModelIndex &index, int role) const
QVariant RsMessageModel::textColorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const
{
// if( (fmpe.msgflags & ForumModelPostEntry::FLAG_POST_IS_MISSING))
// return QVariant(mTextColorMissing);
//
// if(IS_MSG_UNREAD(fmpe.mMsgStatus) || (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_IS_PINNED))
// return QVariant(mTextColorUnread);
// else
// return QVariant(mTextColorRead);
Rs::Msgs::MsgTagType tags;
rsMsgs->getMessageTagTypes(tags);
for(auto it(fmpe.msgtags.begin());it!=fmpe.msgtags.end();++it)
for(auto it2(tags.types.begin());it2!=tags.types.end();++it2)
if(it2->first == *it)
return QColor(it2->second.second);
return QVariant();
}
@ -298,14 +299,42 @@ QVariant RsMessageModel::statusRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col
bool RsMessageModel::passesFilter(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const
{
QString s = displayRole(fmpe,mFilterColumn).toString();
QString s ;
bool passes_strings = true ;
if(!mFilterStrings.empty())
{
switch(mFilterType)
{
case FILTER_TYPE_SUBJECT: s = displayRole(fmpe,COLUMN_THREAD_SUBJECT).toString();
break;
case FILTER_TYPE_FROM:
case FILTER_TYPE_DATE: s = displayRole(fmpe,COLUMN_THREAD_DATE).toString();
break;
case FILTER_TYPE_CONTENT: {
Rs::Msgs::MessageInfo minfo;
rsMsgs->getMessage(fmpe.msgId,minfo);
s = QTextDocument(QString::fromUtf8(minfo.msg.c_str())).toPlainText();
}
break;
case FILTER_TYPE_TAGS: s = displayRole(fmpe,COLUMN_THREAD_TAGS).toString();
break;
case FILTER_TYPE_ATTACHMENTS:
{
Rs::Msgs::MessageInfo minfo;
rsMsgs->getMessage(fmpe.msgId,minfo);
for(auto it(minfo.files.begin());it!=minfo.files.end();++it)
s += QString::fromUtf8((*it).fname.c_str())+" ";
}
};
}
if(!s.isNull())
for(auto iter(mFilterStrings.begin()); iter != mFilterStrings.end(); ++iter)
passes_strings = passes_strings && s.contains(*iter,Qt::CaseInsensitive);
else
passes_strings = true;
bool passes_quick_view =
(mQuickViewFilter==QUICK_VIEW_ALL)
@ -333,11 +362,11 @@ uint32_t RsMessageModel::updateFilterStatus(ForumModelIndex i,int column,const Q
}
void RsMessageModel::setFilter(int column,const QStringList& strings)
void RsMessageModel::setFilter(FilterType filter_type, const QStringList& strings)
{
preMods();
mFilterColumn = column;
mFilterType = filter_type;
mFilterStrings = strings;
postMods();
@ -617,56 +646,6 @@ void RsMessageModel::updateMessages()
setMessages(msgs);
}
// RsThread::async([this, group_id]()
// {
// // 1 - get message data from p3GxsForums
//
// std::list<RsGxsGroupId> forumIds;
// std::vector<RsMsgMetaData> msg_metas;
// std::vector<RsGxsForumGroup> groups;
//
// forumIds.push_back(group_id);
//
// if(!rsGxsForums->getForumsInfo(forumIds,groups))
// {
// std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum group info for forum " << group_id << std::endl;
// return;
// }
//
// if(!rsGxsForums->getForumMsgMetaData(group_id,msg_metas))
// {
// std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum message info for forum " << group_id << std::endl;
// return;
// }
//
// // 2 - sort the messages into a proper hierarchy
//
// auto post_versions = new std::map<RsGxsMessageId,std::vector<std::pair<time_t, RsGxsMessageId> > >() ;
// std::vector<ForumModelPostEntry> *vect = new std::vector<ForumModelPostEntry>();
// RsGxsForumGroup group = groups[0];
//
// computeMessagesHierarchy(group,msg_metas,*vect,*post_versions);
//
// // 3 - update the model in the UI thread.
//
// RsQThreadUtils::postToObject( [group,vect,post_versions,this]()
// {
// /* Here it goes any code you want to be executed on the Qt Gui
// * thread, for example to update the data model with new information
// * after a blocking call to RetroShare API complete, note that
// * Qt::QueuedConnection is important!
// */
//
// setPosts(group,*vect,*post_versions) ;
//
// delete vect;
// delete post_versions;
//
//
// }, this );
//
// });
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status)

View File

@ -76,6 +76,16 @@ public:
QUICK_VIEW_USER = 100
};
enum FilterType {
FILTER_TYPE_NONE = 0x00,
FILTER_TYPE_SUBJECT = 0x01, // These numbers have been carefuly chosen to match the ones in rsmsgs.h
FILTER_TYPE_FROM = 0x02,
FILTER_TYPE_DATE = 0x03,
FILTER_TYPE_CONTENT = 0x04,
FILTER_TYPE_TAGS = 0x05,
FILTER_TYPE_ATTACHMENTS = 0x06,
};
enum Roles{ SortRole = Qt::UserRole+1,
StatusRole = Qt::UserRole+2,
UnreadRole = Qt::UserRole+3,
@ -95,9 +105,9 @@ public:
void setCurrentBox(BoxName bn) ;
void setQuickViewFilter(QuickViewFilter fn) ;
void setFilter(int column, const QStringList& strings) ;
const RsMessageId& currentMessageId() const;
void setFilter(FilterType filter_type, const QStringList& strings) ;
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
@ -170,7 +180,7 @@ private:
BoxName mCurrentBox ;
QuickViewFilter mQuickViewFilter ;
QStringList mFilterStrings;
int mFilterColumn;
FilterType mFilterType;
bool mFilteringEnabled;
std::vector<Rs::Msgs::MsgInfoSummary> mMessages;