mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
simplified a bit the code in Flat_Model, and tried to fix the crash when sorting items
This commit is contained in:
parent
53c65fff9f
commit
93818f6088
@ -48,7 +48,6 @@ class ftDataMultiplex;
|
||||
class p3turtle ;
|
||||
class p3ServiceControl;
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "util/rsthreads.h"
|
||||
#include "pqi/pqiservicemonitor.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include <util/rsversioninfo.h>
|
||||
#include <util/folderiterator.h>
|
||||
#include <ft/ftserver.h>
|
||||
#include <dbase/cachestrapper.h>
|
||||
#include <retroshare/rsplugin.h>
|
||||
#include <retroshare/rsfiles.h>
|
||||
#include <pqi/pqiservice.h>
|
||||
|
@ -805,7 +805,6 @@ bool RsInit::SetHiddenLocation(const std::string& hiddenaddress, uint16_t port)
|
||||
#include <unistd.h>
|
||||
//#include <getopt.h>
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "ft/ftserver.h"
|
||||
#include "ft/ftcontroller.h"
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "dbase/findex.h"
|
||||
#include "retroshare/rsexpr.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include <algorithm>
|
||||
|
@ -194,6 +194,7 @@ int FlatStyle_RDM::rowCount(const QModelIndex &parent) const
|
||||
std::cerr << "RetroshareDirModel::rowCount(): " << parent.internalPointer();
|
||||
std::cerr << ": ";
|
||||
#endif
|
||||
RS_STACK_MUTEX(_ref_mutex) ;
|
||||
|
||||
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 2: return details.age;
|
||||
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();
|
||||
@ -765,9 +771,11 @@ QModelIndex FlatStyle_RDM::index(int row, int column, const QModelIndex & parent
|
||||
if(row < 0)
|
||||
return QModelIndex() ;
|
||||
|
||||
RS_STACK_MUTEX(_ref_mutex) ;
|
||||
|
||||
if(row < (int) _ref_entries.size())
|
||||
{
|
||||
void *ref = _ref_entries[row].first ;
|
||||
void *ref = _ref_entries[row];
|
||||
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "Creating index 2 row=" << row << ", column=" << column << ", ref=" << (void*)ref << std::endl;
|
||||
@ -903,7 +911,7 @@ void RetroshareDirModel::postMods()
|
||||
// changePersistentIndexList(piList, empty);
|
||||
|
||||
/* Clear caches */
|
||||
mCache.clear();
|
||||
//mCache.clear();
|
||||
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "RetroshareDirModel::postMods()" << std::endl;
|
||||
@ -1318,14 +1326,15 @@ void FlatStyle_RDM::postMods()
|
||||
{
|
||||
if(visible())
|
||||
{
|
||||
_ref_entries.clear() ;
|
||||
emit layoutAboutToBeChanged();
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(_ref_mutex) ;
|
||||
_ref_stack.clear() ;
|
||||
|
||||
_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 ;
|
||||
updateRefs() ;
|
||||
}
|
||||
QTimer::singleShot(100,this,SLOT(updateRefs())) ;
|
||||
}
|
||||
else
|
||||
_needs_update = true ;
|
||||
@ -1341,9 +1350,17 @@ void FlatStyle_RDM::updateRefs()
|
||||
|
||||
RetroshareDirModel::preMods() ;
|
||||
|
||||
|
||||
static const uint32_t MAX_REFS_PER_SECOND = 2000 ;
|
||||
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())
|
||||
{
|
||||
void *ref = _ref_stack.back() ;
|
||||
@ -1357,7 +1374,7 @@ void FlatStyle_RDM::updateRefs()
|
||||
if (requestDirDetails(ref, RemoteMode,details))
|
||||
{
|
||||
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
|
||||
std::cerr << "FlatStyle_RDM::postMods(): adding ref " << ref << std::endl;
|
||||
#endif
|
||||
@ -1379,6 +1396,7 @@ void FlatStyle_RDM::updateRefs()
|
||||
|
||||
if(_ref_stack.empty())
|
||||
_needs_update = false ;
|
||||
}
|
||||
|
||||
RetroshareDirModel::postMods() ;
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ class FlatStyle_RDM: public RetroshareDirModel
|
||||
|
||||
public:
|
||||
FlatStyle_RDM(bool mode)
|
||||
: RetroshareDirModel(mode)
|
||||
: RetroshareDirModel(mode), _ref_mutex("Flat file list")
|
||||
{
|
||||
_needs_update = true ;
|
||||
}
|
||||
@ -223,7 +223,8 @@ class FlatStyle_RDM: public RetroshareDirModel
|
||||
|
||||
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
|
||||
bool _needs_update ;
|
||||
};
|
||||
|
@ -145,12 +145,15 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD
|
||||
tree_proxyModel->sort(COLUMN_NAME);
|
||||
|
||||
flat_proxyModel = new SFDSortFilterProxyModel(flat_model, this);
|
||||
flat_proxyModel->setDynamicSortFilter(true);
|
||||
flat_proxyModel->setSourceModel(flat_model);
|
||||
flat_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
flat_proxyModel->setSortRole(RetroshareDirModel::SortRole);
|
||||
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.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter()));
|
||||
connect(ui.filterPatternLineEdit, SIGNAL(returnPressed()), this, SLOT(startFilter()));
|
||||
|
Loading…
Reference in New Issue
Block a user