simplified a bit the code in Flat_Model, and tried to fix the crash when sorting items

This commit is contained in:
mr-alice 2016-09-13 21:23:27 +02:00
parent 53c65fff9f
commit 93818f6088
7 changed files with 77 additions and 59 deletions

View File

@ -48,7 +48,6 @@ class ftDataMultiplex;
class p3turtle ; class p3turtle ;
class p3ServiceControl; class p3ServiceControl;
#include "dbase/cachestrapper.h"
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "pqi/pqiservicemonitor.h" #include "pqi/pqiservicemonitor.h"
#include "pqi/p3cfgmgr.h" #include "pqi/p3cfgmgr.h"

View File

@ -17,7 +17,6 @@
#include <util/rsversioninfo.h> #include <util/rsversioninfo.h>
#include <util/folderiterator.h> #include <util/folderiterator.h>
#include <ft/ftserver.h> #include <ft/ftserver.h>
#include <dbase/cachestrapper.h>
#include <retroshare/rsplugin.h> #include <retroshare/rsplugin.h>
#include <retroshare/rsfiles.h> #include <retroshare/rsfiles.h>
#include <pqi/pqiservice.h> #include <pqi/pqiservice.h>

View File

@ -805,7 +805,6 @@ bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port)
#include <unistd.h> #include <unistd.h>
//#include <getopt.h> //#include <getopt.h>
#include "dbase/cachestrapper.h"
#include "ft/ftserver.h" #include "ft/ftserver.h"
#include "ft/ftcontroller.h" #include "ft/ftcontroller.h"

View File

@ -24,7 +24,6 @@
*/ */
#include "dbase/findex.h"
#include "retroshare/rsexpr.h" #include "retroshare/rsexpr.h"
#include "retroshare/rstypes.h" #include "retroshare/rstypes.h"
#include <algorithm> #include <algorithm>

View File

@ -194,6 +194,7 @@ int FlatStyle_RDM::rowCount(const QModelIndex &parent) const
std::cerr << "RetroshareDirModel::rowCount(): " << parent.internalPointer(); std::cerr << "RetroshareDirModel::rowCount(): " << parent.internalPointer();
std::cerr << ": "; std::cerr << ": ";
#endif #endif
RS_STACK_MUTEX(_ref_mutex) ;
return _ref_entries.size() ; return _ref_entries.size() ;
} }
@ -501,7 +502,12 @@ QVariant FlatStyle_RDM::sortRole(const QModelIndex& index,const DirDetails& deta
case 1: return (qulonglong) details.count; case 1: return (qulonglong) details.count;
case 2: return details.age; case 2: return details.age;
case 3: return QString::fromUtf8(rsPeers->getPeerName(details.id).c_str()); case 3: return QString::fromUtf8(rsPeers->getPeerName(details.id).c_str());
case 4: return _ref_entries[index.row()].second ;
case 4: {
RS_STACK_MUTEX(_ref_mutex) ;
return computeDirectoryPath(details);
}
} }
} }
return QVariant(); return QVariant();
@ -765,9 +771,11 @@ QModelIndex FlatStyle_RDM::index(int row, int column, const QModelIndex & parent
if(row < 0) if(row < 0)
return QModelIndex() ; return QModelIndex() ;
RS_STACK_MUTEX(_ref_mutex) ;
if(row < (int) _ref_entries.size()) if(row < (int) _ref_entries.size())
{ {
void *ref = _ref_entries[row].first ; void *ref = _ref_entries[row];
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "Creating index 2 row=" << row << ", column=" << column << ", ref=" << (void*)ref << std::endl; std::cerr << "Creating index 2 row=" << row << ", column=" << column << ", ref=" << (void*)ref << std::endl;
@ -903,7 +911,7 @@ void RetroshareDirModel::postMods()
// changePersistentIndexList(piList, empty); // changePersistentIndexList(piList, empty);
/* Clear caches */ /* Clear caches */
mCache.clear(); //mCache.clear();
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RetroshareDirModel::postMods()" << std::endl; std::cerr << "RetroshareDirModel::postMods()" << std::endl;
@ -1318,14 +1326,15 @@ void FlatStyle_RDM::postMods()
{ {
if(visible()) if(visible())
{ {
_ref_entries.clear() ; emit layoutAboutToBeChanged();
{
RS_STACK_MUTEX(_ref_mutex) ;
_ref_stack.clear() ; _ref_stack.clear() ;
_ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory _ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory
std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl;
_needs_update = false ; _needs_update = false ;
updateRefs() ; }
QTimer::singleShot(100,this,SLOT(updateRefs())) ;
} }
else else
_needs_update = true ; _needs_update = true ;
@ -1341,9 +1350,17 @@ void FlatStyle_RDM::updateRefs()
RetroshareDirModel::preMods() ; RetroshareDirModel::preMods() ;
static const uint32_t MAX_REFS_PER_SECOND = 2000 ; static const uint32_t MAX_REFS_PER_SECOND = 2000 ;
uint32_t nb_treated_refs = 0 ; uint32_t nb_treated_refs = 0 ;
{
RS_STACK_MUTEX(_ref_mutex) ;
_ref_entries.clear() ;
std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl;
while(!_ref_stack.empty()) while(!_ref_stack.empty())
{ {
void *ref = _ref_stack.back() ; void *ref = _ref_stack.back() ;
@ -1357,7 +1374,7 @@ void FlatStyle_RDM::updateRefs()
if (requestDirDetails(ref, RemoteMode,details)) if (requestDirDetails(ref, RemoteMode,details))
{ {
if(details.type == DIR_TYPE_FILE) // only push files, not directories nor persons. if(details.type == DIR_TYPE_FILE) // only push files, not directories nor persons.
_ref_entries.push_back(std::pair<void*,QString>(ref,computeDirectoryPath(details))); _ref_entries.push_back(ref) ;
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "FlatStyle_RDM::postMods(): adding ref " << ref << std::endl; std::cerr << "FlatStyle_RDM::postMods(): adding ref " << ref << std::endl;
#endif #endif
@ -1379,6 +1396,7 @@ void FlatStyle_RDM::updateRefs()
if(_ref_stack.empty()) if(_ref_stack.empty())
_needs_update = false ; _needs_update = false ;
}
RetroshareDirModel::postMods() ; RetroshareDirModel::postMods() ;
} }

View File

@ -194,7 +194,7 @@ class FlatStyle_RDM: public RetroshareDirModel
public: public:
FlatStyle_RDM(bool mode) FlatStyle_RDM(bool mode)
: RetroshareDirModel(mode) : RetroshareDirModel(mode), _ref_mutex("Flat file list")
{ {
_needs_update = true ; _needs_update = true ;
} }
@ -223,7 +223,8 @@ class FlatStyle_RDM: public RetroshareDirModel
QString computeDirectoryPath(const DirDetails& details) const ; QString computeDirectoryPath(const DirDetails& details) const ;
std::vector<std::pair<void *,QString> > _ref_entries ;// used to store the refs to display mutable RsMutex _ref_mutex ;
std::vector<void *> _ref_entries ;// used to store the refs to display
std::vector<void *> _ref_stack ; // used to store the refs to update std::vector<void *> _ref_stack ; // used to store the refs to update
bool _needs_update ; bool _needs_update ;
}; };

View File

@ -145,12 +145,15 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD
tree_proxyModel->sort(COLUMN_NAME); tree_proxyModel->sort(COLUMN_NAME);
flat_proxyModel = new SFDSortFilterProxyModel(flat_model, this); flat_proxyModel = new SFDSortFilterProxyModel(flat_model, this);
flat_proxyModel->setDynamicSortFilter(true);
flat_proxyModel->setSourceModel(flat_model); flat_proxyModel->setSourceModel(flat_model);
flat_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); flat_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
flat_proxyModel->setSortRole(RetroshareDirModel::SortRole); flat_proxyModel->setSortRole(RetroshareDirModel::SortRole);
flat_proxyModel->sort(COLUMN_NAME); flat_proxyModel->sort(COLUMN_NAME);
// Mr.Alice: I removed this because it causes a crash for some obscur reason. Apparently when the model is changed, the proxy model cannot
// deal with the change by itself. Should I call something specific? I've no idea. Removing this does not seem to cause any harm either.
//flat_proxyModel->setDynamicSortFilter(true);
connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter())); connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter()));
connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter())); connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter()));