fixed bug in ModelIndex creation in channel post view, and implemented arrow key navigation

This commit is contained in:
csoler 2023-09-04 21:58:45 +02:00
parent 0ed32eb597
commit 8a20ab33b4
5 changed files with 48 additions and 1 deletions

View File

@ -95,8 +95,10 @@ void GxsCommentDialog::commentClear()
} }
void GxsCommentDialog::commentLoad(const RsGxsGroupId &grpId, const std::set<RsGxsMessageId>& msg_versions,const RsGxsMessageId& most_recent_msgId,bool use_cache) void GxsCommentDialog::commentLoad(const RsGxsGroupId &grpId, const std::set<RsGxsMessageId>& msg_versions,const RsGxsMessageId& most_recent_msgId,bool use_cache)
{ {
#ifdef DEBUG_COMMENT_DIALOG
std::cerr << "GxsCommentDialog::commentLoad(" << grpId << ", most recent msg version: " << most_recent_msgId << ")"; std::cerr << "GxsCommentDialog::commentLoad(" << grpId << ", most recent msg version: " << most_recent_msgId << ")";
std::cerr << std::endl; std::cerr << std::endl;
#endif
mGrpId = grpId; mGrpId = grpId;
mMostRecentMsgId = most_recent_msgId; mMostRecentMsgId = most_recent_msgId;

View File

@ -176,6 +176,25 @@ int RsGxsChannelPostsModel::rowCount(const QModelIndex& parent) const
return 0; return 0;
} }
int RsGxsChannelPostsModel::columnCount(int row) const
{
if(mTreeMode == TREE_MODE_GRID)
{
if(row+1 == rowCount())
{
int r = ((int)mFilteredPosts.size() % (int)mColumns);
if(r > 0)
return r;
else
return columnCount();
}
else
return columnCount();
}
else
return 2;
}
int RsGxsChannelPostsModel::columnCount(const QModelIndex &/*parent*/) const int RsGxsChannelPostsModel::columnCount(const QModelIndex &/*parent*/) const
{ {
if(mTreeMode == TREE_MODE_GRID) if(mTreeMode == TREE_MODE_GRID)
@ -245,7 +264,7 @@ bool RsGxsChannelPostsModel::convertRefPointerToTabEntry(quintptr ref, uint32_t&
QModelIndex RsGxsChannelPostsModel::index(int row, int column, const QModelIndex & parent) const QModelIndex RsGxsChannelPostsModel::index(int row, int column, const QModelIndex & parent) const
{ {
if(row < 0 || column < 0 || column >= (int)mColumns) if(row < 0 || column < 0 || row >= rowCount() || column >= columnCount(row))
return QModelIndex(); return QModelIndex();
quintptr ref = getChildRef(parent.internalId(),(mTreeMode == TREE_MODE_GRID)?(column + row*mColumns):row); quintptr ref = getChildRef(parent.internalId(),(mTreeMode == TREE_MODE_GRID)?(column + row*mColumns):row);

View File

@ -105,6 +105,7 @@ public:
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;} QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const; QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
int columnCount(int row) const; // columns in the row of this particular index.
std::vector<std::pair<time_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const; std::vector<std::pair<time_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const;

View File

@ -504,6 +504,30 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
}, mEventHandlerId, RsEventType::GXS_CHANNELS ); }, mEventHandlerId, RsEventType::GXS_CHANNELS );
} }
void GxsChannelPostsWidgetWithModel::keyPressEvent(QKeyEvent *e)
{
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
if(index.isValid() && mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID)
{
int n = mChannelPostsModel->columnCount(index.row())-1;
if(e->key() == Qt::Key_Left && index.column()==0)
{
ui->postsTree->setCurrentIndex(index.siblingAtColumn(n));
e->accept();
return;
}
if(e->key() == Qt::Key_Right && index.column()==n)
{
ui->postsTree->setCurrentIndex(index.siblingAtColumn(0));
e->accept();
return;
}
}
GxsMessageFrameWidget::keyPressEvent(e);
}
void GxsChannelPostsWidgetWithModel::resizeEvent(QResizeEvent *e) void GxsChannelPostsWidgetWithModel::resizeEvent(QResizeEvent *e)
{ {
GxsMessageFrameWidget::resizeEvent(e); GxsMessageFrameWidget::resizeEvent(e);

View File

@ -139,6 +139,7 @@ protected:
/* GxsMessageFrameWidget */ /* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read) override; virtual void setAllMessagesReadDo(bool read) override;
virtual void resizeEvent(QResizeEvent *e) override; virtual void resizeEvent(QResizeEvent *e) override;
virtual void keyPressEvent(QKeyEvent *e) override;
private slots: private slots:
void showPostDetails(); void showPostDetails();