resurrected prev/next buttons

This commit is contained in:
csoler 2018-11-26 22:07:10 +01:00
parent 581e892d94
commit 3a76f25152
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 77 additions and 50 deletions

View File

@ -494,7 +494,7 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<F
bool has_unread_below,has_read_below ;
recursUpdateReadStatus(0,has_unread_below,has_read_below) ;
#ifdef DEBUG_FORUMMODEL
#ifndef DEBUG_FORUMMODEL
debug_dump();
#endif
@ -1009,19 +1009,6 @@ void RsGxsForumModel::recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_
mPosts[i].mPostFlags &= ~ForumModelPostEntry::FLAG_POST_HAS_READ_CHILDREN;
}
static void recursPrintModel(const std::vector<ForumModelPostEntry>& entries,ForumModelIndex index,int depth)
{
const ForumModelPostEntry& e(entries[index]);
std::cerr << std::string(depth*2,' ') << e.mAuthorId.toStdString() << " "
<< QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString() << " "
<< QString("%1").arg((uint32_t)e.mMsgStatus,8,16,QChar('0')).toStdString() << " "
<< QDateTime::fromSecsSinceEpoch(e.mPublishTs).toString().toStdString() << " \"" << e.mTitle << "\"" << std::endl;
for(uint32_t i=0;i<e.mChildren.size();++i)
recursPrintModel(entries,e.mChildren[i],depth+1);
}
QModelIndex RsGxsForumModel::getIndexOfMessage(const RsGxsMessageId& mid) const
{
// brutal search. This is not so nice, so dont call that in a loop!
@ -1038,8 +1025,21 @@ QModelIndex RsGxsForumModel::getIndexOfMessage(const RsGxsMessageId& mid) const
return QModelIndex();
}
void RsGxsForumModel::test_iterator() const
{
const_iterator it(*this);
while(it)
{
std::cerr << "Current node: " << *it << std::endl;
++it;
}
}
QModelIndex RsGxsForumModel::getNextIndex(const QModelIndex& i,bool unread_only) const
{
test_iterator();
ForumModelIndex fmi ;
convertRefPointerToTabEntry(i.internalPointer(),fmi);
@ -1130,6 +1130,20 @@ RsGxsForumModel::const_iterator::operator bool() const
return kid >= 0;
}
static void recursPrintModel(const std::vector<ForumModelPostEntry>& entries,ForumModelIndex index,int depth)
{
const ForumModelPostEntry& e(entries[index]);
std::cerr << std::string(depth*2,' ') << index << " : " << e.mAuthorId.toStdString() << " "
<< QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString() << " "
<< QString("%1").arg((uint32_t)e.mMsgStatus,8,16,QChar('0')).toStdString() << " "
<< QDateTime::fromSecsSinceEpoch(e.mPublishTs).toString().toStdString() << " \"" << e.mTitle << "\"" << std::endl;
for(uint32_t i=0;i<e.mChildren.size();++i)
recursPrintModel(entries,e.mChildren[i],depth+1);
}
void RsGxsForumModel::debug_dump()
{
std::cerr << "Model data dump:" << std::endl;

View File

@ -99,6 +99,7 @@ public:
ForumModelIndex current_parent;
const RsGxsForumModel& model;
};
void test_iterator() const;
// This method will asynchroneously update the data
void setForum(const RsGxsGroupId& forumGroup);

View File

@ -1825,24 +1825,24 @@ void GxsForumThreadWidget::insertMessage()
mStateHelper->setActive(mTokenTypeMessageData, true);
#endif
#ifdef TODO
QTreeWidgetItem *item = ui->threadTreeWidget->currentItem();
QModelIndex index = getCurrentIndex();
if (item) {
QTreeWidgetItem *parentItem = item->parent();
int index = parentItem ? parentItem->indexOfChild(item) : ui->threadTreeWidget->indexOfTopLevelItem(item);
int count = parentItem ? parentItem->childCount() : ui->threadTreeWidget->topLevelItemCount();
mStateHelper->setWidgetEnabled(ui->previousButton, (index > 0));
mStateHelper->setWidgetEnabled(ui->nextButton, (index < count - 1));
if (index.isValid())
{
QModelIndex parentIndex = index.parent();
int curr_index = index.row();
int count = mThreadModel->rowCount(parentIndex);
ui->previousButton->setEnabled(curr_index > 0);
ui->nextButton->setEnabled(curr_index < count - 1);
} else {
// there is something wrong
mStateHelper->setWidgetEnabled(ui->previousButton, false);
mStateHelper->setWidgetEnabled(ui->nextButton, false);
ui->previousButton->setEnabled(false);
ui->nextButton->setEnabled(false);
ui->versions_CB->hide();
ui->time_label->show();
return;
}
#endif
mStateHelper->setWidgetEnabled(ui->newmessageButton, (IS_GROUP_SUBSCRIBED(mSubscribeFlags) && mThreadId.isNull() == false));
@ -1984,41 +1984,53 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
void GxsForumThreadWidget::previousMessage()
{
#ifdef TODO
QTreeWidgetItem *item = ui->threadTreeWidget->currentItem();
if (item == NULL) {
return;
}
QModelIndex current_index = getCurrentIndex();
QTreeWidgetItem *parentItem = item->parent();
int index = parentItem ? parentItem->indexOfChild(item) : ui->threadTreeWidget->indexOfTopLevelItem(item);
if (index > 0) {
QTreeWidgetItem *previousItem = parentItem ? parentItem->child(index - 1) : ui->threadTreeWidget->topLevelItem(index - 1);
if (previousItem) {
ui->threadTreeWidget->setCurrentItem(previousItem);
if (!current_index.isValid())
return;
QModelIndex parentIndex = current_index.parent();
int index = current_index.row();
int count = mThreadModel->rowCount(parentIndex) ;
if (index > 0)
{
QModelIndex prevItem = mThreadModel->index(index - 1,0,parentIndex) ;
if (prevItem.isValid()) {
ui->threadTreeWidget->setCurrentIndex(prevItem);
ui->threadTreeWidget->setFocus();
}
}
#endif
ui->previousButton->setEnabled(index-1 > 0);
ui->nextButton->setEnabled(true);
}
void GxsForumThreadWidget::nextMessage()
{
#ifdef TODO
QTreeWidgetItem *item = ui->threadTreeWidget->currentItem();
if (item == NULL) {
return;
}
QModelIndex current_index = getCurrentIndex();
QTreeWidgetItem *parentItem = item->parent();
int index = parentItem ? parentItem->indexOfChild(item) : ui->threadTreeWidget->indexOfTopLevelItem(item);
int count = parentItem ? parentItem->childCount() : ui->threadTreeWidget->topLevelItemCount();
if (index < count - 1) {
QTreeWidgetItem *nextItem = parentItem ? parentItem->child(index + 1) : ui->threadTreeWidget->topLevelItem(index + 1);
if (nextItem) {
ui->threadTreeWidget->setCurrentItem(nextItem);
if (!current_index.isValid())
return;
QModelIndex parentIndex = current_index.parent();
int index = current_index.row();
int count = mThreadModel->rowCount(parentIndex) ;
if (index < count - 1)
{
QModelIndex nextItem = mThreadModel->index(index + 1,0,parentIndex) ;
if (nextItem.isValid()) {
ui->threadTreeWidget->setCurrentIndex(nextItem);
ui->threadTreeWidget->setFocus();
}
}
#endif
ui->previousButton->setEnabled(true);
ui->nextButton->setEnabled(index+1 < count - 1);
}
void GxsForumThreadWidget::downloadAllFiles()