mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-15 01:17:16 -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
|
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;
|
return 0;
|
||||||
|
|
||||||
|
if(parent.internalId() == 0)
|
||||||
if(mDisplayGroups)
|
if(mDisplayGroups)
|
||||||
{
|
|
||||||
if(mGroups.empty()) // security. Should never happen.
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if(parent.internalPointer() == NULL)
|
|
||||||
return mGroups.size();
|
return mGroups.size();
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return mProfiles.size();
|
||||||
if(mProfiles.empty()) // security. Should never happen.
|
|
||||||
|
EntryIndex index;
|
||||||
|
if(!convertInternalIdToIndex(parent.internalId(),index))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(parent.internalPointer() == NULL)
|
if(index.type == ENTRY_TYPE_GROUP)
|
||||||
return mProfiles.size();
|
return mGroups[index.ind].peerIds.size();
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -123,6 +116,16 @@ bool RsFriendListModel::hasChildren(const QModelIndex &parent) const
|
|||||||
if(!parent.isValid())
|
if(!parent.isValid())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +211,36 @@ QModelIndex RsFriendListModel::parent(const QModelIndex& index) const
|
|||||||
if(!index.isValid())
|
if(!index.isValid())
|
||||||
return QModelIndex();
|
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();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,6 @@ NewFriendList::NewFriendList(QWidget *parent) :
|
|||||||
ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
|
ui->filterLineEdit->setPlaceholderText(tr("Search")) ;
|
||||||
ui->filterLineEdit->showFilterIcon();
|
ui->filterLineEdit->showFilterIcon();
|
||||||
|
|
||||||
|
|
||||||
mModel = new RsFriendListModel();
|
mModel = new RsFriendListModel();
|
||||||
ui->peerTreeWidget->setModel(mModel);
|
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(), headerText, COLUMN_NAME, QString("%1 %2").arg(tr("Search"), headerText));
|
||||||
// ui->filterLineEdit->addFilter(QIcon(), tr("ID"), COLUMN_ID, tr("Search ID"));
|
// ui->filterLineEdit->addFilter(QIcon(), tr("ID"), COLUMN_ID, tr("Search ID"));
|
||||||
|
|
||||||
// mActionSortByState = new QAction(tr("Sort by state"), this);
|
mActionSortByState = new QAction(tr("Sort by state"), this);
|
||||||
// mActionSortByState->setCheckable(true);
|
mActionSortByState->setCheckable(true);
|
||||||
// connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(sortByState(bool)));
|
connect(mActionSortByState, SIGNAL(toggled(bool)), this, SLOT(sortByState(bool)));
|
||||||
// ui->peerTreeWidget->addContextMenuAction(mActionSortByState);
|
// ui->peerTreeWidget->addContextMenuAction(mActionSortByState);
|
||||||
|
|
||||||
/* Set sort */
|
/* Set sort */
|
||||||
@ -178,6 +177,8 @@ NewFriendList::NewFriendList(QWidget *parent) :
|
|||||||
|
|
||||||
/* Initialize display menu */
|
/* Initialize display menu */
|
||||||
createDisplayMenu();
|
createDisplayMenu();
|
||||||
|
|
||||||
|
mModel->updateInternalData();
|
||||||
}
|
}
|
||||||
|
|
||||||
NewFriendList::~NewFriendList()
|
NewFriendList::~NewFriendList()
|
||||||
|
Loading…
Reference in New Issue
Block a user