From f1d98913d1ff9d58c7be6d89cf10196af3cd5bad Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 21 Oct 2020 22:07:45 +0200 Subject: [PATCH] fixed disabling of channel post comment box on resize and comment --- .../gui/gxschannels/GxsChannelPostsModel.cpp | 9 ++++++-- .../gui/gxschannels/GxsChannelPostsModel.h | 4 +++- .../GxsChannelPostsWidgetWithModel.cpp | 23 +++++++++++++------ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 797b2fb6f..a5a56597b 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -319,13 +319,16 @@ Qt::ItemFlags RsGxsChannelPostsModel::flags(const QModelIndex& index) const return QAbstractItemModel::flags(index); } -void RsGxsChannelPostsModel::setNumColumns(int n) +bool RsGxsChannelPostsModel::setNumColumns(int n) { if(n < 1) { RsErr() << __PRETTY_FUNCTION__ << " Attempt to set a number of column of 0. This is wrong." << std::endl; - return; + return false; } + if(mColumns == n) + return false; + preMods(); beginRemoveRows(QModelIndex(),0,rowCount()-1); @@ -337,6 +340,8 @@ void RsGxsChannelPostsModel::setNumColumns(int n) endInsertRows(); postMods(); + + return true; } quintptr RsGxsChannelPostsModel::getChildRef(quintptr ref,int index) const diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h index 931135840..d8385d24b 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h @@ -116,7 +116,9 @@ public: void triggerViewUpdate(); - void setNumColumns(int n); + // sets the number of columns. Returns 0 if nothing changes. + bool setNumColumns(int n); + void setMode(TreeMode mode); TreeMode getMode() const { return mTreeMode; } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 9e08c0038..610932ef1 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -674,8 +674,19 @@ void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s,bool forc int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(0,font(),ui->postsTree->width())))); std::cerr << "nb columns: " << n_columns << " current count=" << mChannelPostsModel->columnCount() << std::endl; - if(force || (n_columns != mChannelPostsModel->columnCount())) - mChannelPostsModel->setNumColumns(n_columns); + // save current post. The setNumColumns() indeed loses selection + + QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); + RsGxsMessageId current_mid; + + if(index.isValid()) + current_mid = index.data(Qt::UserRole).value().mMeta.mMsgId ; + + if((force || (n_columns != mChannelPostsModel->columnCount())) && mChannelPostsModel->setNumColumns(n_columns)) + { + // Restore current post. The setNumColumns() indeed loses selection + ui->postsTree->selectionModel()->setCurrentIndex(mChannelPostsModel->getIndexOfMessage(current_mid),QItemSelectionModel::ClearAndSelect); + } } void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr event) @@ -706,7 +717,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); RsGxsChannelPost post = index.data(Qt::UserRole).value() ; - QTextDocument doc; + QTextDocument doc; doc.setHtml(post.mMsg.c_str()); if(post.mMeta.mPublishTs == 0) @@ -717,6 +728,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() ui->postTime_LB->hide(); mChannelPostFilesModel->clear(); ui->details_TW->setEnabled(false); +// mSelectedPost.clear(); return; } @@ -726,9 +738,6 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() ui->postName_LB->show(); ui->postTime_LB->show(); - if(index.row()==0 && index.column()==0) - std::cerr << "here" << std::endl; - std::cerr << "showPostDetails: setting mSelectedPost to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mSelectedPost << std::endl; mSelectedPost = post.mMeta.mMsgId; @@ -741,7 +750,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() auto all_msgs_versions(post.mOlderVersions); all_msgs_versions.insert(post.mMeta.mMsgId); - ui->commentsDialog->commentLoad(post.mMeta.mGroupId, all_msgs_versions, post.mMeta.mMsgId); + ui->commentsDialog->commentLoad(post.mMeta.mGroupId, all_msgs_versions, post.mMeta.mMsgId,true); std::cerr << "Showing details about selected index : "<< index.row() << "," << index.column() << std::endl;