added show unread only button. Merged list/grid buttons

This commit is contained in:
csoler 2020-08-29 17:31:48 +02:00
parent 3ba9a1eb5d
commit 89444537b1
6 changed files with 39 additions and 43 deletions

View file

@ -306,7 +306,7 @@ void RsGxsChannelPostFilesModel::setFilter(const QStringList& strings, uint32_t&
if(strings.empty()) if(strings.empty())
{ {
mFilteredFiles.clear(); mFilteredFiles.clear();
for(int i=0;i<mFiles.size();++i) for(uint32_t i=0;i<mFiles.size();++i)
mFilteredFiles.push_back(i); mFilteredFiles.push_back(i);
} }
else else
@ -314,7 +314,7 @@ void RsGxsChannelPostFilesModel::setFilter(const QStringList& strings, uint32_t&
mFilteredFiles.clear(); mFilteredFiles.clear();
//mFilteredPosts.push_back(0); //mFilteredPosts.push_back(0);
for(int i=0;i<mFiles.size();++i) for(uint32_t i=0;i<mFiles.size();++i)
{ {
bool passes_strings = true; bool passes_strings = true;

View file

@ -169,35 +169,30 @@ void RsGxsChannelPostsModel::getFilesList(std::list<ChannelPostFileInfo>& files)
files.push_back(it.second); files.push_back(it.second);
} }
void RsGxsChannelPostsModel::setFilter(const QStringList& strings, uint32_t& count) void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unread, uint32_t& count)
{ {
preMods(); preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1); beginRemoveRows(QModelIndex(),0,rowCount()-1);
endRemoveRows(); endRemoveRows();
if(strings.empty()) mFilteredPosts.clear();
//mFilteredPosts.push_back(0);
for(size_t i=0;i<mPosts.size();++i)
{ {
mFilteredPosts.clear(); bool passes_strings = true;
for(size_t i=0;i<mPosts.size();++i)
for(auto& s:strings)
passes_strings = passes_strings && QString::fromStdString(mPosts[i].mMeta.mMsgName).contains(s,Qt::CaseInsensitive);
if(strings.empty())
passes_strings = true;
if(passes_strings && (!only_unread || (IS_MSG_UNREAD(mPosts[i].mMeta.mMsgStatus) || IS_MSG_NEW(mPosts[i].mMeta.mMsgStatus))))
mFilteredPosts.push_back(i); mFilteredPosts.push_back(i);
} }
else
{
mFilteredPosts.clear();
//mFilteredPosts.push_back(0);
for(size_t i=0;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(); count = mFilteredPosts.size();
std::cerr << "After filtering: " << count << " posts remain." << std::endl; std::cerr << "After filtering: " << count << " posts remain." << std::endl;

View file

@ -134,7 +134,7 @@ public:
void setMsgReadStatus(const QModelIndex &i, bool read_status); void setMsgReadStatus(const QModelIndex &i, bool read_status);
void setAllMsgReadStatus(bool read_status); void setAllMsgReadStatus(bool read_status);
void setFilter(const QStringList &strings, uint32_t &count) ; void setFilter(const QStringList &strings, bool only_unread,uint32_t &count) ;
#ifdef TODO #ifdef TODO
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op); void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
@ -232,8 +232,6 @@ private:
std::vector<int> mFilteredPosts; // stores the list of displayes indices due to filtering. 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
QColor mTextColorRead ; QColor mTextColorRead ;
QColor mTextColorUnread ; QColor mTextColorUnread ;
QColor mTextColorUnreadChildren; QColor mTextColorUnreadChildren;

View file

@ -290,12 +290,14 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui->setupUi(this); ui->setupUi(this);
ui->list_TB->setIcon(FilesDefs::getIconFromQtResourcePath(":icons/svg/listlayout.svg")); ui->viewType_TB->setIcon(FilesDefs::getIconFromQtResourcePath(":icons/svg/gridlayout.svg"));
ui->grid_TB->setIcon(FilesDefs::getIconFromQtResourcePath(":icons/svg/gridlayout.svg")); ui->viewType_TB->setToolTip(tr("Click to switch to list view"));
whileBlocking(ui->grid_TB)->setChecked(true); connect(ui->viewType_TB,SIGNAL(clicked()),this,SLOT(switchView()));
connect(ui->list_TB,SIGNAL(clicked()),this,SLOT(switchView())); ui->showUnread_TB->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-unread.png"));
connect(ui->grid_TB,SIGNAL(clicked()),this,SLOT(switchView())); ui->showUnread_TB->setChecked(false);
ui->showUnread_TB->setToolTip(tr("Show unread posts only"));
connect(ui->showUnread_TB,SIGNAL(toggled(bool)),this,SLOT(switchOnlyUnread(bool)));
ui->postsTree->setModel(mChannelPostsModel = new RsGxsChannelPostsModel()); ui->postsTree->setModel(mChannelPostsModel = new RsGxsChannelPostsModel());
ui->postsTree->setItemDelegate(mChannelPostsDelegate = new ChannelPostDelegate()); ui->postsTree->setItemDelegate(mChannelPostsDelegate = new ChannelPostDelegate());
@ -485,16 +487,16 @@ void GxsChannelPostsWidgetWithModel::switchView()
if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID) if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID)
{ {
whileBlocking(ui->list_TB)->setChecked(true); ui->viewType_TB->setIcon(FilesDefs::getIconFromQtResourcePath(":icons/svg/listlayout.svg"));
whileBlocking(ui->grid_TB)->setChecked(false); ui->viewType_TB->setToolTip(tr("Click to switch to grid view"));
mChannelPostsDelegate->setWidgetGrid(false); mChannelPostsDelegate->setWidgetGrid(false);
mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_LIST); mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_LIST);
} }
else else
{ {
whileBlocking(ui->list_TB)->setChecked(false); ui->viewType_TB->setIcon(FilesDefs::getIconFromQtResourcePath(":icons/svg/gridlayout.svg"));
whileBlocking(ui->grid_TB)->setChecked(true); ui->viewType_TB->setToolTip(tr("Click to switch to list view"));
mChannelPostsDelegate->setWidgetGrid(true); mChannelPostsDelegate->setWidgetGrid(true);
mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_GRID); mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_GRID);
@ -749,10 +751,8 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
mChannelPostsModel->getFilesList(files); mChannelPostsModel->getFilesList(files);
mChannelFilesModel->setFiles(files); mChannelFilesModel->setFiles(files);
//ui->channelFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_FILE);
//ui->channelFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE);
ui->channelFiles_TV->setAutoSelect(true); ui->channelFiles_TV->setAutoSelect(true);
ui->channelFiles_TV->sortByColumn(0, Qt::AscendingOrder);
} }
void GxsChannelPostsWidgetWithModel::updateDisplay(bool complete) void GxsChannelPostsWidgetWithModel::updateDisplay(bool complete)
@ -1057,15 +1057,17 @@ void GxsChannelPostsWidgetWithModel::setViewMode(int viewMode)
#endif #endif
} }
void GxsChannelPostsWidgetWithModel::switchOnlyUnread(bool)
{
filterChanged(ui->filterLineEdit->text());
std::cerr << "Switched to unread/read"<< std::endl;
}
void GxsChannelPostsWidgetWithModel::filterChanged(QString s) void GxsChannelPostsWidgetWithModel::filterChanged(QString s)
{ {
QStringList ql = s.split(' ',QString::SkipEmptyParts); QStringList ql = s.split(' ',QString::SkipEmptyParts);
uint32_t count; uint32_t count;
mChannelPostsModel->setFilter(ql,count); mChannelPostsModel->setFilter(ql,ui->showUnread_TB->isChecked(),count);
mChannelFilesModel->setFilter(ql,count); mChannelFilesModel->setFilter(ql,count);
//mChannelPostFilesProxyModel->setFilterKeyColumn(RsGxsChannelPostFilesModel::COLUMN_FILES_NAME);
//mChannelPostFilesProxyModel->setFilterRegExp(s) ;// triggers a re-display. s is actually not used.
} }
#ifdef TODO #ifdef TODO

View file

@ -152,6 +152,7 @@ private slots:
void copyMessageLink(); void copyMessageLink();
void updateZoomFactor(bool zoom_or_unzoom); void updateZoomFactor(bool zoom_or_unzoom);
void switchView(); void switchView();
void switchOnlyUnread(bool b);
public slots: public slots:
void sortColumnFiles(int col,Qt::SortOrder so); void sortColumnFiles(int col,Qt::SortOrder so);

View file

@ -121,7 +121,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QToolButton" name="grid_TB"> <widget class="QToolButton" name="showUnread_TB">
<property name="text"> <property name="text">
<string>...</string> <string>...</string>
</property> </property>
@ -131,12 +131,12 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="list_TB"> <widget class="QToolButton" name="viewType_TB">
<property name="text"> <property name="text">
<string>...</string> <string>...</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>