mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 08:59:50 -05:00
improved FriendList Model
This commit is contained in:
parent
7ccb05b77a
commit
833661fc24
@ -73,28 +73,21 @@ void RsFriendListModel::postMods()
|
||||
|
||||
int RsFriendListModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
if(!parent.isValid())
|
||||
if(parent.column() >= COLUMN_THREAD_NB_COLUMNS)
|
||||
return 0;
|
||||
|
||||
if(parent.column() > 0)
|
||||
return 0;
|
||||
|
||||
if(mDisplayGroups)
|
||||
{
|
||||
if(mGroups.empty()) // security. Should never happen.
|
||||
return 0;
|
||||
|
||||
if(parent.internalPointer() == NULL)
|
||||
if(parent.internalId() == 0)
|
||||
if(mDisplayGroups)
|
||||
return mGroups.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mProfiles.empty()) // security. Should never happen.
|
||||
return 0;
|
||||
|
||||
if(parent.internalPointer() == NULL)
|
||||
else
|
||||
return mProfiles.size();
|
||||
}
|
||||
|
||||
EntryIndex index;
|
||||
if(!convertInternalIdToIndex(parent.internalId(),index))
|
||||
return 0;
|
||||
|
||||
if(index.type == ENTRY_TYPE_GROUP)
|
||||
return mGroups[index.ind].peerIds.size();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -123,7 +116,17 @@ bool RsFriendListModel::hasChildren(const QModelIndex &parent) const
|
||||
if(!parent.isValid())
|
||||
return true;
|
||||
|
||||
return false ;
|
||||
EntryIndex parent_index ;
|
||||
convertInternalIdToIndex(parent.internalId(),parent_index);
|
||||
|
||||
if(parent_index.type == ENTRY_TYPE_NODE)
|
||||
return false;
|
||||
if(parent_index.type == ENTRY_TYPE_PROFILE)
|
||||
return false; // TODO
|
||||
if(parent_index.type == ENTRY_TYPE_GROUP)
|
||||
return !mGroups[parent_index.ind].peerIds.empty();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RsFriendListModel::convertIndexToInternalId(const EntryIndex& e,quintptr& id)
|
||||
@ -208,6 +211,36 @@ QModelIndex RsFriendListModel::parent(const QModelIndex& index) const
|
||||
if(!index.isValid())
|
||||
return QModelIndex();
|
||||
|
||||
EntryIndex I ;
|
||||
convertInternalIdToIndex(index.internalId(),I);
|
||||
|
||||
if(I.type == ENTRY_TYPE_GROUP)
|
||||
return QModelIndex();
|
||||
|
||||
if(I.type == ENTRY_TYPE_PROFILE)
|
||||
if(mDisplayGroups)
|
||||
{
|
||||
for(int i=0;i<mGroups.size();++i)
|
||||
if(mGroups[i].peerIds.find(mProfiles[I.ind].gpg_id) != mGroups[i].peerIds.end()) // this is costly. We should store indices
|
||||
{
|
||||
quintptr ref ;
|
||||
EntryIndex parent_index(ENTRY_TYPE_GROUP,i);
|
||||
convertIndexToInternalId(parent_index,ref);
|
||||
|
||||
return createIndex(i,0,ref);
|
||||
}
|
||||
}
|
||||
else
|
||||
return QModelIndex();
|
||||
|
||||
// if(i.type == ENTRY_TYPE_NODE)
|
||||
// {
|
||||
// quintptr ref ;
|
||||
// convertIndexToInternalId(parent_index,ref);
|
||||
//
|
||||
// return createIndex(parent_row,0,ref);
|
||||
// }
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
|
@ -108,15 +108,15 @@
|
||||
Q_DECLARE_METATYPE(ElidedLabel*)
|
||||
|
||||
NewFriendList::NewFriendList(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::NewFriendList()),
|
||||
// mCompareRole(new RSTreeWidgetItemCompareRole),
|
||||
QWidget(parent),
|
||||
ui(new Ui::NewFriendList()),
|
||||
// mCompareRole(new RSTreeWidgetItemCompareRole),
|
||||
mShowGroups(true),
|
||||
mShowState(false),
|
||||
mHideUnconnected(false),
|
||||
groupsHasChanged(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->peerTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(peerTreeWidgetCustomPopupMenu()));
|
||||
//connect(ui->peerTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(expandItem(QTreeWidgetItem *)) );
|
||||
@ -134,7 +134,6 @@ NewFriendList::NewFriendList(QWidget *parent) :
|
||||
ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
|
||||
ui->filterLineEdit->showFilterIcon();
|
||||
|
||||
|
||||
mModel = new RsFriendListModel();
|
||||
ui->peerTreeWidget->setModel(mModel);
|
||||
|
||||
@ -146,9 +145,9 @@ NewFriendList::NewFriendList(QWidget *parent) :
|
||||
// ui->filterLineEdit->addFilter(QIcon(), headerText, COLUMN_NAME, QString("%1 %2").arg(tr("Search"), headerText));
|
||||
// ui->filterLineEdit->addFilter(QIcon(), tr("ID"), COLUMN_ID, tr("Search ID"));
|
||||
|
||||
// mActionSortByState = new QAction(tr("Sort by state"), this);
|
||||
// mActionSortByState->setCheckable(true);
|
||||
// connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(sortByState(bool)));
|
||||
mActionSortByState = new QAction(tr("Sort by state"), this);
|
||||
mActionSortByState->setCheckable(true);
|
||||
connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(sortByState(bool)));
|
||||
// ui->peerTreeWidget->addContextMenuAction(mActionSortByState);
|
||||
|
||||
/* Set sort */
|
||||
@ -178,6 +177,8 @@ NewFriendList::NewFriendList(QWidget *parent) :
|
||||
|
||||
/* Initialize display menu */
|
||||
createDisplayMenu();
|
||||
|
||||
mModel->updateInternalData();
|
||||
}
|
||||
|
||||
NewFriendList::~NewFriendList()
|
||||
|
Loading…
Reference in New Issue
Block a user