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"
//#define DEBUG_CHANNEL_MODEL
#define DEBUG_CHANNEL_FILES_MODEL
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
#endif
@ -161,8 +161,8 @@ QModelIndex RsGxsChannelPostFilesModel::index(int row, int column, const QModelI
quintptr ref = getChildRef(parent.internalId(),row);
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) << std::endl;
#ifdef DEBUG_CHANNEL_FILES_MODEL
RsDbg() << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) ;
#endif
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
{
#ifdef DEBUG_CHANNEL_MODEL
#ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << "calling data(" << index << ") role=" << role << std::endl;
#endif
@ -259,13 +259,13 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
quintptr ref = (index.isValid())?index.internalId():0 ;
uint32_t entry = 0;
#ifdef DEBUG_CHANNEL_MODEL
#ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << "data(" << index << ")" ;
#endif
if(!ref)
{
#ifdef DEBUG_CHANNEL_MODEL
#ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << " [empty]" << std::endl;
#endif
return QVariant() ;
@ -273,7 +273,7 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredFiles.size())
{
#ifdef DEBUG_CHANNEL_MODEL
#ifdef DEBUG_CHANNEL_FILES_MODEL
std::cerr << "Bad pointer: " << (void*)ref << std::endl;
#endif
return QVariant() ;
@ -443,7 +443,7 @@ void RsGxsChannelPostFilesModel::setFiles(const std::list<ChannelPostFileInfo> &
for(uint32_t i=0;i<mFiles.size();++i)
mFilteredFiles.push_back(i);
#ifdef DEBUG_CHANNEL_MODEL
#ifdef DEBUG_CHANNEL_FILES_MODEL
// debug_dump();
#endif
@ -467,7 +467,9 @@ void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& add
{
// 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();)
{
@ -475,7 +477,9 @@ void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& add
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);
auto tmp = afit;
++tmp;
@ -486,11 +490,15 @@ void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& add
++afit;
}
RsDbg() << " Remains: " << added_files.size() << " added files and " << removed_files.size() << " removed files" ;
// 2 - add whatever file remains,
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)
if(mFiles[i].mHash == f.mHash)
@ -504,6 +512,9 @@ void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& add
for(const auto& f:added_files )
{
#ifdef DEBUG_CHANNEL_FILES_MODEL
RsDbg() << " Adding new file " << f.mName ;
#endif
mFilteredFiles.push_back(mFiles.size());
mFiles.push_back(f);
}

View File

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