attempt to fix crash when threads collide in forum model

This commit is contained in:
csoler 2018-12-04 09:36:06 +01:00
parent ec0bb5347e
commit fb962c4b5b
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 50 additions and 23 deletions

View File

@ -49,39 +49,46 @@ RsGxsForumModel::RsGxsForumModel(QObject *parent)
mFilteringEnabled=false; mFilteringEnabled=false;
} }
void RsGxsForumModel::preMods()
{
emit layoutAboutToBeChanged();
beginResetModel();
}
void RsGxsForumModel::postMods()
{
endResetModel();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
emit layoutChanged();
}
void RsGxsForumModel::setTreeMode(TreeMode mode) void RsGxsForumModel::setTreeMode(TreeMode mode)
{ {
if(mode == mTreeMode) if(mode == mTreeMode)
return; return;
emit layoutAboutToBeChanged(); preMods();
mTreeMode = mode; mTreeMode = mode;
postMods();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
emit layoutChanged();
} }
void RsGxsForumModel::setSortMode(SortMode mode) void RsGxsForumModel::setSortMode(SortMode mode)
{ {
emit layoutAboutToBeChanged(); preMods();
mSortMode = mode; mSortMode = mode;
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); postMods();
emit layoutChanged();
} }
void RsGxsForumModel::initEmptyHierarchy(std::vector<ForumModelPostEntry>& posts) void RsGxsForumModel::initEmptyHierarchy(std::vector<ForumModelPostEntry>& posts)
{ {
emit layoutAboutToBeChanged(); preMods();
posts.resize(1); // adds a sentinel item posts.resize(1); // adds a sentinel item
posts[0].mTitle = "Root sentinel post" ; posts[0].mTitle = "Root sentinel post" ;
posts[0].mParent = 0; posts[0].mParent = 0;
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); postMods();
emit layoutChanged();
} }
int RsGxsForumModel::rowCount(const QModelIndex& parent) const int RsGxsForumModel::rowCount(const QModelIndex& parent) const
@ -474,7 +481,7 @@ uint32_t RsGxsForumModel::recursUpdateFilterStatus(ForumModelIndex i,int column,
void RsGxsForumModel::setFilter(int column,const QStringList& strings,uint32_t& count) void RsGxsForumModel::setFilter(int column,const QStringList& strings,uint32_t& count)
{ {
emit layoutAboutToBeChanged(); preMods();
if(!strings.empty()) if(!strings.empty())
{ {
@ -484,8 +491,7 @@ void RsGxsForumModel::setFilter(int column,const QStringList& strings,uint32_t&
else else
mFilteringEnabled = false; mFilteringEnabled = false;
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); postMods();
emit layoutChanged();
} }
QVariant RsGxsForumModel::missingRole(const ForumModelPostEntry& fmpe,int column) const QVariant RsGxsForumModel::missingRole(const ForumModelPostEntry& fmpe,int column) const
@ -672,19 +678,18 @@ void RsGxsForumModel::setForum(const RsGxsGroupId& forum_group_id)
void RsGxsForumModel::clear() void RsGxsForumModel::clear()
{ {
emit layoutAboutToBeChanged(); preMods();
mPosts.clear(); mPosts.clear();
mPostVersions.clear(); mPostVersions.clear();
emit layoutChanged(); postMods();
emit forumLoaded(); emit forumLoaded();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
} }
void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions) void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions)
{ {
emit layoutAboutToBeChanged(); preMods();
mForumGroup = group; mForumGroup = group;
mPosts = posts; mPosts = posts;
@ -707,9 +712,8 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<F
debug_dump(); debug_dump();
#endif #endif
emit layoutChanged(); postMods();
emit forumLoaded(); emit forumLoaded();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
} }
void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id) void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
@ -1139,7 +1143,7 @@ void RsGxsForumModel::setMsgReadStatus(const QModelIndex& i,bool read_status,boo
if(!i.isValid()) if(!i.isValid())
return ; return ;
emit layoutAboutToBeChanged(); preMods();
void *ref = i.internalPointer(); void *ref = i.internalPointer();
uint32_t entry = 0; uint32_t entry = 0;
@ -1151,8 +1155,7 @@ void RsGxsForumModel::setMsgReadStatus(const QModelIndex& i,bool read_status,boo
recursSetMsgReadStatus(entry,read_status,with_children) ; recursSetMsgReadStatus(entry,read_status,with_children) ;
recursUpdateReadStatusAndTimes(0,has_unread_below,has_read_below); recursUpdateReadStatusAndTimes(0,has_unread_below,has_read_below);
emit layoutChanged(); postMods();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
} }
void RsGxsForumModel::recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children) void RsGxsForumModel::recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children)

View File

@ -165,6 +165,9 @@ private:
TreeMode mTreeMode; TreeMode mTreeMode;
SortMode mSortMode; SortMode mSortMode;
void preMods() ;
void postMods() ;
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;
//bool hasIndex(int row,int column,const QModelIndex& parent)const; //bool hasIndex(int row,int column,const QModelIndex& parent)const;

View File

@ -305,6 +305,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
setUpdateWhenInvisible(true); setUpdateWhenInvisible(true);
mSubscribeFlags = 0; mSubscribeFlags = 0;
mUpdating = false;
mSignFlags = 0; mSignFlags = 0;
mUnreadCount = 0; mUnreadCount = 0;
mNewCount = 0; mNewCount = 0;
@ -583,8 +584,12 @@ static void removeMessages(std::map<RsGxsGroupId, std::set<RsGxsMessageId> > &ms
void GxsForumThreadWidget::updateDisplay(bool complete) void GxsForumThreadWidget::updateDisplay(bool complete)
{ {
if(mUpdating)
return;
if (complete) { if (complete) {
/* Fill complete */ /* Fill complete */
mUpdating=true;
updateGroupData(); updateGroupData();
mThreadModel->setForum(groupId()); mThreadModel->setForum(groupId());
insertMessage(); insertMessage();
@ -604,6 +609,7 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
if (grpIds.find(groupId())!=grpIds.end()){ if (grpIds.find(groupId())!=grpIds.end()){
updateGroup = true; updateGroup = true;
/* Update threads */ /* Update threads */
mUpdating=true;
mThreadModel->setForum(groupId()); mThreadModel->setForum(groupId());
} else { } else {
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgIds; std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgIds;
@ -615,8 +621,11 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
} }
if (msgIds.find(groupId()) != msgIds.end()) if (msgIds.find(groupId()) != msgIds.end())
{
mUpdating=true;
mThreadModel->setForum(groupId()); /* Update threads */ mThreadModel->setForum(groupId()); /* Update threads */
} }
}
if (updateGroup) { if (updateGroup) {
updateGroupData(); updateGroupData();
@ -855,6 +864,9 @@ void GxsForumThreadWidget::togglethreadview_internal()
void GxsForumThreadWidget::changedVersion() void GxsForumThreadWidget::changedVersion()
{ {
if(mUpdating)
return;
mThreadId = RsGxsMessageId(ui->versions_CB->itemData(ui->versions_CB->currentIndex()).toString().toStdString()) ; mThreadId = RsGxsMessageId(ui->versions_CB->itemData(ui->versions_CB->currentIndex()).toString().toStdString()) ;
ui->postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages()) ; ui->postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages()) ;
@ -863,6 +875,9 @@ void GxsForumThreadWidget::changedVersion()
void GxsForumThreadWidget::changedThread(QModelIndex index) void GxsForumThreadWidget::changedThread(QModelIndex index)
{ {
if(mUpdating)
return;
if(!index.isValid()) if(!index.isValid())
{ {
mThreadId.clear(); mThreadId.clear();
@ -884,6 +899,9 @@ void GxsForumThreadWidget::changedThread(QModelIndex index)
void GxsForumThreadWidget::clickedThread(QModelIndex index) void GxsForumThreadWidget::clickedThread(QModelIndex index)
{ {
if(mUpdating)
return;
if(!index.isValid()) if(!index.isValid())
return; return;
@ -1622,6 +1640,8 @@ void GxsForumThreadWidget::updateGroupName()
ui->forumName->setText(QString::fromUtf8(mForumGroup.mMeta.mGroupName.c_str())); ui->forumName->setText(QString::fromUtf8(mForumGroup.mMeta.mGroupName.c_str()));
ui->threadTreeWidget->sortByColumn(RsGxsForumModel::COLUMN_THREAD_DATE, Qt::DescendingOrder); ui->threadTreeWidget->sortByColumn(RsGxsForumModel::COLUMN_THREAD_DATE, Qt::DescendingOrder);
ui->threadTreeWidget->update(); ui->threadTreeWidget->update();
mUpdating = false;
} }
void GxsForumThreadWidget::updateGroupData() void GxsForumThreadWidget::updateGroupData()
{ {

View File

@ -176,6 +176,7 @@ private:
QString mForumDescription; QString mForumDescription;
int mSubscribeFlags; int mSubscribeFlags;
int mSignFlags; int mSignFlags;
bool mUpdating;
bool mInProcessSettings; bool mInProcessSettings;
bool mInMsgAsReadUnread; bool mInMsgAsReadUnread;
int mLastViewType; int mLastViewType;