From cbf4ce66705c8cf6884b32f8415fa4987be32a7c Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 10 Jun 2020 19:05:41 +0200 Subject: [PATCH] fixed some errors in model --- .../gxschannels/GxsChannelPostFilesModel.cpp | 61 +++++-------------- .../GxsChannelPostsWidgetWithModel.cpp | 2 + 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp index b585d242b..8942b65b0 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp @@ -52,8 +52,7 @@ void RsGxsChannelPostFilesModel::initEmptyHierarchy(std::vector& file { preMods(); - files.resize(1); // adds a sentinel item - files[0].mName = "Root sentinel post" ; + mFiles.clear(); postMods(); } @@ -76,28 +75,6 @@ void RsGxsChannelPostFilesModel::update() emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFiles.size(),COLUMN_FILES_NB_COLUMNS-1,(void*)NULL)); } -#ifdef TODO -void RsGxsChannelPostsModel::setSortMode(SortMode mode) -{ - preMods(); - - mSortMode = mode; - - postMods(); -} - -void RsGxsForumModel::initEmptyHierarchy(std::vector& posts) -{ - preMods(); - - posts.resize(1); // adds a sentinel item - posts[0].mTitle = "Root sentinel post" ; - posts[0].mParent = 0; - - postMods(); -} -#endif - int RsGxsChannelPostFilesModel::rowCount(const QModelIndex& parent) const { if(parent.column() > 0) @@ -107,7 +84,7 @@ int RsGxsChannelPostFilesModel::rowCount(const QModelIndex& parent) const return 0; if(!parent.isValid()) - return getChildrenCount(0); + return (mFiles.size() + COLUMN_FILES_NB_COLUMNS-1)/COLUMN_FILES_NB_COLUMNS; // mFilteredPosts always has an item at 0, so size()>=1, and mColumn>=1 RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl; return 0; @@ -162,7 +139,7 @@ bool RsGxsChannelPostFilesModel::convertTabEntryToRefPointer(uint32_t entry,quin // This means that the whole software has the following build-in limitation: // * 4 B simultaenous posts. Should be enough ! - ref = (intptr_t)entry; + ref = (intptr_t)(entry+1); return true; } @@ -176,7 +153,12 @@ bool RsGxsChannelPostFilesModel::convertRefPointerToTabEntry(quintptr ref, uint3 RsErr() << "(EE) trying to make a ChannelPostsModelIndex out of a number that is larger than 2^32-1 !" << std::endl; return false ; } - entry = quintptr(val); + if(val==0) + { + RsErr() << "(EE) trying to make a ChannelPostsFileModelIndex out of index 0." << std::endl; + return false; + } + entry = val-1; return true; } @@ -218,15 +200,10 @@ quintptr RsGxsChannelPostFilesModel::getChildRef(quintptr ref,int index) const if (index < 0) return 0; - ChannelPostFilesModelIndex entry ; - - if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFiles.size()) - return 0 ; - - if(entry == 0) + if(ref == quintptr(0)) { quintptr new_ref; - convertTabEntryToRefPointer(index+1,new_ref); + convertTabEntryToRefPointer(index,new_ref); return new_ref; } else @@ -253,20 +230,12 @@ quintptr RsGxsChannelPostFilesModel::getParentRow(quintptr ref,int& row) const int RsGxsChannelPostFilesModel::getChildrenCount(quintptr ref) const { - uint32_t entry = 0 ; + uint32_t entry = 0 ; - if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFiles.size()) - return 0 ; + if(ref == quintptr(0)) + return rowCount()-1; - if(entry == 0) - { -#ifdef DEBUG_CHANNEL_MODEL - std::cerr << "Children count (flat mode): " << mFiles.size()-1 << std::endl; -#endif - return ((int)mFiles.size())-1; - } - else - return 0; + return 0; } QVariant RsGxsChannelPostFilesModel::headerData(int section, Qt::Orientation orientation, int role) const diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 846f0bcdd..d6a317151 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -468,6 +468,8 @@ void GxsChannelPostsWidgetWithModel::updateChannelFiles() ui->channelFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_FILE); ui->channelFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE); ui->channelFiles_TV->setAutoSelect(true); + + mChannelPostFilesProxyModel->sort(0, Qt::AscendingOrder); } void GxsChannelPostsWidgetWithModel::updateGroupData()