fixed disabling of channel post comment box on resize and comment

This commit is contained in:
csoler 2020-10-21 22:07:45 +02:00
parent 9d4042c401
commit f1d98913d1
3 changed files with 26 additions and 10 deletions

View File

@ -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

View File

@ -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; }

View File

@ -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<RsGxsChannelPost>().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<const RsEvent> event)
@ -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;