improved debug output

This commit is contained in:
csoler 2023-03-26 16:29:12 +02:00
parent 3316d75630
commit 191d7ac96e
2 changed files with 29 additions and 17 deletions

View file

@ -33,11 +33,11 @@
#include "GxsChannelPostFilesModel.h" #include "GxsChannelPostFilesModel.h"
//#define DEBUG_CHANNEL_MODEL #define DEBUG_CHANNEL_FILES_MODEL
Q_DECLARE_METATYPE(ChannelPostFileInfo) Q_DECLARE_METATYPE(ChannelPostFileInfo)
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_FILES_MODEL
static std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere static std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
#endif #endif
@ -161,8 +161,8 @@ QModelIndex RsGxsChannelPostFilesModel::index(int row, int column, const QModelI
quintptr ref = getChildRef(parent.internalId(),row); quintptr ref = getChildRef(parent.internalId(),row);
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) << std::endl; RsDbg() << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) ;
#endif #endif
return createIndex(row,column,ref) ; return createIndex(row,column,ref) ;
} }
@ -242,7 +242,7 @@ QVariant RsGxsChannelPostFilesModel::headerData(int section, Qt::Orientation /*o
QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) const QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) const
{ {
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << "calling data(" << index << ") role=" << role << std::endl; std::cerr << "calling data(" << index << ") role=" << role << std::endl;
#endif #endif
@ -259,13 +259,13 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
quintptr ref = (index.isValid())?index.internalId():0 ; quintptr ref = (index.isValid())?index.internalId():0 ;
uint32_t entry = 0; uint32_t entry = 0;
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << "data(" << index << ")" ; std::cerr << "data(" << index << ")" ;
#endif #endif
if(!ref) if(!ref)
{ {
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << " [empty]" << std::endl; std::cerr << " [empty]" << std::endl;
#endif #endif
return QVariant() ; return QVariant() ;
@ -273,7 +273,7 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredFiles.size()) if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredFiles.size())
{ {
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << "Bad pointer: " << (void*)ref << std::endl; std::cerr << "Bad pointer: " << (void*)ref << std::endl;
#endif #endif
return QVariant() ; return QVariant() ;
@ -443,7 +443,7 @@ void RsGxsChannelPostFilesModel::setFiles(const std::list<ChannelPostFileInfo> &
for(uint32_t i=0;i<mFiles.size();++i) for(uint32_t i=0;i<mFiles.size();++i)
mFilteredFiles.push_back(i); mFilteredFiles.push_back(i);
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_FILES_MODEL
// debug_dump(); // debug_dump();
#endif #endif
@ -467,7 +467,9 @@ void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& add
{ {
// 1 - remove common files from both lists // 1 - remove common files from both lists
std::cerr << "RsGxsChannelPostsFilesModel:: updating files." << std::endl; #ifdef DEBUG_CHANNEL_FILES_MODEL
RsDbg() << "RsGxsChannelPostsFilesModel:: updating files." ;
#endif
for(auto afit=added_files.begin();afit!=added_files.end();) for(auto afit=added_files.begin();afit!=added_files.end();)
{ {
@ -475,7 +477,9 @@ void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& add
if(rfit != removed_files.end()) if(rfit != removed_files.end())
{ {
std::cerr << " Eliminating common file " << rfit->mName << std::endl; #ifdef DEBUG_CHANNEL_FILES_MODEL
RsDbg() << " Eliminating common file " << rfit->mName ;
#endif
removed_files.erase(rfit); removed_files.erase(rfit);
auto tmp = afit; auto tmp = afit;
++tmp; ++tmp;
@ -486,11 +490,15 @@ void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& add
++afit; ++afit;
} }
RsDbg() << " Remains: " << added_files.size() << " added files and " << removed_files.size() << " removed files" ;
// 2 - add whatever file remains, // 2 - add whatever file remains,
for(const auto& f:removed_files) for(const auto& f:removed_files)
{ {
std::cerr << " Removing deleted file " << f.mName << std::endl; #ifdef DEBUG_CHANNEL_FILES_MODEL
RsDbg() << " Removing deleted file " << f.mName ;
#endif
for(uint32_t i=0;i<mFiles.size();++i) for(uint32_t i=0;i<mFiles.size();++i)
if(mFiles[i].mHash == f.mHash) if(mFiles[i].mHash == f.mHash)
@ -504,6 +512,9 @@ void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& add
for(const auto& f:added_files ) for(const auto& f:added_files )
{ {
#ifdef DEBUG_CHANNEL_FILES_MODEL
RsDbg() << " Adding new file " << f.mName ;
#endif
mFilteredFiles.push_back(mFiles.size()); mFilteredFiles.push_back(mFiles.size());
mFiles.push_back(f); mFiles.push_back(f);
} }

View file

@ -35,6 +35,7 @@
#include "GxsChannelPostsModel.h" #include "GxsChannelPostsModel.h"
#include "GxsChannelPostFilesModel.h" #include "GxsChannelPostFilesModel.h"
//#define DEBUG_CHANNEL_MODEL_DATA
#define DEBUG_CHANNEL_MODEL #define DEBUG_CHANNEL_MODEL
Q_DECLARE_METATYPE(RsMsgMetaData) Q_DECLARE_METATYPE(RsMsgMetaData)
@ -283,7 +284,7 @@ QModelIndex RsGxsChannelPostsModel::index(int row, int column, const 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);
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_MODEL_DATA
std::cerr << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) << std::endl; std::cerr << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) << std::endl;
#endif #endif
return createIndex(row,column,ref) ; return createIndex(row,column,ref) ;
@ -373,7 +374,7 @@ int RsGxsChannelPostsModel::getChildrenCount(quintptr ref) const
QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const
{ {
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_MODEL_DATA
std::cerr << "calling data(" << index << ") role=" << role << std::endl; std::cerr << "calling data(" << index << ") role=" << role << std::endl;
#endif #endif
@ -390,13 +391,13 @@ QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const
quintptr ref = (index.isValid())?index.internalId():0 ; quintptr ref = (index.isValid())?index.internalId():0 ;
uint32_t entry = 0; uint32_t entry = 0;
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_MODEL_DATA
std::cerr << "data(" << index << ")" ; std::cerr << "data(" << index << ")" ;
#endif #endif
if(!ref) if(!ref)
{ {
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_MODEL_DATA
std::cerr << " [empty]" << std::endl; std::cerr << " [empty]" << std::endl;
#endif #endif
return QVariant() ; return QVariant() ;
@ -404,7 +405,7 @@ QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size()) if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
{ {
#ifdef DEBUG_CHANNEL_MODEL #ifdef DEBUG_CHANNEL_MODEL_DATA
std::cerr << "Bad pointer: " << (void*)ref << std::endl; std::cerr << "Bad pointer: " << (void*)ref << std::endl;
#endif #endif
return QVariant() ; return QVariant() ;