mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #2044 from csoler/v0.6-BugFixing
Fix for crashes in FriendList and FileLists
This commit is contained in:
commit
deaba61eec
@ -1104,15 +1104,9 @@ Qt::ItemFlags RetroshareDirModel::flags( const QModelIndex & index ) const
|
||||
/* Callback from Core*/
|
||||
void RetroshareDirModel::preMods()
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
mUpdating = true ;
|
||||
#if QT_VERSION < 0x050000
|
||||
reset();
|
||||
#else
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
#endif
|
||||
|
||||
beginResetModel();
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "RetroshareDirModel::preMods()" << std::endl;
|
||||
#endif
|
||||
@ -1121,20 +1115,14 @@ void RetroshareDirModel::preMods()
|
||||
/* Callback from Core*/
|
||||
void RetroshareDirModel::postMods()
|
||||
{
|
||||
// emit layoutAboutToBeChanged();
|
||||
mUpdating = false ;
|
||||
#if QT_VERSION >= 0x040600
|
||||
beginResetModel();
|
||||
#endif
|
||||
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "RetroshareDirModel::postMods()" << std::endl;
|
||||
#endif
|
||||
|
||||
#if QT_VERSION >= 0x040600
|
||||
endResetModel();
|
||||
#endif
|
||||
emit layoutChanged();
|
||||
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,COLUMN_COUNT-1,(void*)NULL));
|
||||
}
|
||||
|
||||
void FlatStyle_RDM::postMods()
|
||||
|
@ -152,15 +152,13 @@ void RsFriendListModel::setDisplayGroups(bool b)
|
||||
}
|
||||
void RsFriendListModel::preMods()
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
|
||||
beginResetModel();
|
||||
}
|
||||
void RsFriendListModel::postMods()
|
||||
{
|
||||
endResetModel();
|
||||
emit layoutChanged();
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
|
||||
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,columnCount()-1,(void*)NULL));
|
||||
}
|
||||
|
||||
int RsFriendListModel::rowCount(const QModelIndex& parent) const
|
||||
@ -1060,14 +1058,16 @@ void RsFriendListModel::updateInternalData()
|
||||
preMods();
|
||||
|
||||
beginRemoveRows(QModelIndex(),0,mTopLevel.size()-1);
|
||||
endRemoveRows();
|
||||
|
||||
mGroups.clear();
|
||||
mProfiles.clear();
|
||||
mLocations.clear();
|
||||
|
||||
mTopLevel.clear();
|
||||
|
||||
endRemoveRows();
|
||||
|
||||
auto TL = mTopLevel ; // This allows to fill TL without touching mTopLevel outside of [begin/end]InsertRows().
|
||||
|
||||
// create a map of profiles and groups
|
||||
std::map<RsPgpId,uint32_t> pgp_indices;
|
||||
|
||||
@ -1155,7 +1155,6 @@ void RsFriendListModel::updateInternalData()
|
||||
RsDbg() << "Creating top level list" << std::endl;
|
||||
#endif
|
||||
|
||||
mTopLevel.clear();
|
||||
std::set<RsPgpId> already_in_a_group;
|
||||
|
||||
if(mDisplayGroups) // in this case, we list all groups at the top level followed by the profiles without parent group
|
||||
@ -1170,7 +1169,7 @@ void RsFriendListModel::updateInternalData()
|
||||
e.type = ENTRY_TYPE_GROUP;
|
||||
e.group_index = i;
|
||||
|
||||
mTopLevel.push_back(e);
|
||||
TL.push_back(e);
|
||||
|
||||
for(uint32_t j=0;j<mGroups[i].child_profile_indices.size();++j)
|
||||
already_in_a_group.insert(mProfiles[mGroups[i].child_profile_indices[j]].profile_info.gpg_id);
|
||||
@ -1189,12 +1188,15 @@ void RsFriendListModel::updateInternalData()
|
||||
e.profile_index = i;
|
||||
e.group_index = UNDEFINED_GROUP_INDEX_VALUE;
|
||||
|
||||
mTopLevel.push_back(e);
|
||||
TL.push_back(e);
|
||||
}
|
||||
|
||||
// finally, tell the model client that layout has changed.
|
||||
|
||||
beginInsertRows(QModelIndex(),0,mTopLevel.size()-1);
|
||||
beginInsertRows(QModelIndex(),0,TL.size()-1);
|
||||
|
||||
mTopLevel = TL;
|
||||
|
||||
endInsertRows();
|
||||
|
||||
postMods();
|
||||
@ -1234,7 +1236,7 @@ void RsFriendListModel::collapseItem(const QModelIndex& index)
|
||||
mExpandedProfiles.erase(s);
|
||||
|
||||
// apparently we cannot be subtle here.
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,columnCount()-1,(void*)NULL));
|
||||
}
|
||||
|
||||
void RsFriendListModel::expandItem(const QModelIndex& index)
|
||||
@ -1256,10 +1258,10 @@ void RsFriendListModel::expandItem(const QModelIndex& index)
|
||||
if(hp) s += hp->profile_info.gpg_id.toStdString();
|
||||
|
||||
if(!s.empty())
|
||||
mExpandedProfiles.insert(s);
|
||||
mExpandedProfiles.insert(s);
|
||||
|
||||
// apparently we cannot be subtle here.
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mTopLevel.size()-1,columnCount()-1,(void*)NULL));
|
||||
}
|
||||
|
||||
bool RsFriendListModel::isProfileExpanded(const EntryIndex& e) const
|
||||
|
@ -454,6 +454,7 @@ void NewFriendList::processSettings(bool load)
|
||||
|
||||
if (load) // load settings
|
||||
{
|
||||
std::cerr <<"Re-loading settings..." << std::endl;
|
||||
// states
|
||||
setShowUnconnected(!Settings->value("hideUnconnected", !mProxyModel->showOfflineNodes()).toBool());
|
||||
setShowState(Settings->value("showState", mModel->getDisplayStatusString()).toBool());
|
||||
@ -1088,16 +1089,46 @@ void NewFriendList::removeGroup()
|
||||
checkInternalData(true);
|
||||
}
|
||||
|
||||
void NewFriendList::checkInternalData(bool force)
|
||||
void NewFriendList::applyWhileKeepingTree(std::function<void()> predicate)
|
||||
{
|
||||
std::set<QString> expanded_indexes;
|
||||
std::set<QString> selected_indexes;
|
||||
std::set<QString> selected_indexes;
|
||||
|
||||
saveExpandedPathsAndSelection(expanded_indexes, selected_indexes);
|
||||
saveExpandedPathsAndSelection(expanded_indexes, selected_indexes);
|
||||
|
||||
mModel->checkInternalData(force);
|
||||
// This is a hack to avoid crashes on windows while calling endInsertRows(). I'm not sure wether these crashes are
|
||||
// due to a Qt bug, or a misuse of the proxy model on my side. Anyway, this solves them for good.
|
||||
// As a side effect we need to save/restore hidden columns because setSourceModel() resets this setting.
|
||||
|
||||
restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes);
|
||||
// save hidden columns and sizes
|
||||
std::vector<bool> col_visible(RsFriendListModel::COLUMN_THREAD_NB_COLUMNS);
|
||||
std::vector<int> col_sizes(RsFriendListModel::COLUMN_THREAD_NB_COLUMNS);
|
||||
|
||||
for(int i=0;i<RsFriendListModel::COLUMN_THREAD_NB_COLUMNS;++i)
|
||||
{
|
||||
col_visible[i] = !ui->peerTreeWidget->isColumnHidden(i);
|
||||
col_sizes[i] = ui->peerTreeWidget->columnWidth(i);
|
||||
}
|
||||
|
||||
|
||||
mProxyModel->setSourceModel(nullptr);
|
||||
|
||||
predicate();
|
||||
|
||||
mProxyModel->setSourceModel(mModel);
|
||||
restoreExpandedPathsAndSelection(expanded_indexes, selected_indexes);
|
||||
|
||||
// restore hidden columns
|
||||
for(uint32_t i=0;i<RsFriendListModel::COLUMN_THREAD_NB_COLUMNS;++i)
|
||||
{
|
||||
ui->peerTreeWidget->setColumnHidden(i,!col_visible[i]);
|
||||
ui->peerTreeWidget->setColumnWidth(i,col_sizes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void NewFriendList::checkInternalData(bool force)
|
||||
{
|
||||
applyWhileKeepingTree([force,this]() { mModel->checkInternalData(force) ; });
|
||||
}
|
||||
|
||||
void NewFriendList::exportFriendlistClicked()
|
||||
@ -1485,6 +1516,7 @@ bool NewFriendList::isColumnVisible(int col) const
|
||||
}
|
||||
void NewFriendList::setColumnVisible(int col,bool visible)
|
||||
{
|
||||
std::cerr << "Setting column " << col << " to be visible: " << visible << std::endl;
|
||||
ui->peerTreeWidget->setColumnHidden(col, !visible);
|
||||
}
|
||||
void NewFriendList::toggleColumnVisible()
|
||||
@ -1502,12 +1534,12 @@ void NewFriendList::toggleColumnVisible()
|
||||
|
||||
void NewFriendList::setShowState(bool show)
|
||||
{
|
||||
mModel->setDisplayStatusString(show);
|
||||
applyWhileKeepingTree([show,this]() { mModel->setDisplayStatusString(show) ; });
|
||||
}
|
||||
|
||||
void NewFriendList::setShowGroups(bool show)
|
||||
{
|
||||
mModel->setDisplayGroups(show);
|
||||
applyWhileKeepingTree([show,this]() { mModel->setDisplayGroups(show) ; });
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,7 +103,9 @@ private:
|
||||
RsFriendListModel *mModel;
|
||||
QAction *mActionSortByState;
|
||||
|
||||
void expandGroup(const RsNodeGroupId& gid);
|
||||
void applyWhileKeepingTree(std::function<void()> predicate);
|
||||
|
||||
void expandGroup(const RsNodeGroupId& gid);
|
||||
void recursRestoreExpandedItems(const QModelIndex& index, const QString& parent_path, const std::set<QString>& exp, const std::set<QString> &sel);
|
||||
void recursSaveExpandedItems(const QModelIndex& index,const QString& parent_path,std::set<QString>& exp, std::set<QString>& sel);
|
||||
void saveExpandedPathsAndSelection(std::set<QString>& expanded_indexes, std::set<QString>& selected_indexes);
|
||||
|
Loading…
Reference in New Issue
Block a user