mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Fixed filter in FriendList.
This commit is contained in:
parent
217c9b9538
commit
641a433f97
@ -88,6 +88,7 @@
|
||||
#define ROLE_SORT_STANDARD_GROUP Qt::UserRole + 3
|
||||
#define ROLE_SORT_NAME Qt::UserRole + 4
|
||||
#define ROLE_SORT_STATE Qt::UserRole + 5
|
||||
#define ROLE_FILTER Qt::UserRole + 6
|
||||
|
||||
#define TYPE_GPG 0
|
||||
#define TYPE_SSL 1
|
||||
@ -1049,6 +1050,9 @@ void FriendList::insertPeers()
|
||||
sslTextLabel->setVisible(!sslText.isEmpty());
|
||||
}
|
||||
|
||||
// Filter
|
||||
sslItem->setData(COLUMN_NAME, ROLE_FILTER, sslName);
|
||||
|
||||
if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) {
|
||||
// private chat is available
|
||||
sslOverlayIcon = QPixmap(":/images/chat.png");
|
||||
@ -1160,6 +1164,9 @@ void FriendList::insertPeers()
|
||||
gpgTextLabel->setVisible(!gpgText.isEmpty());
|
||||
}
|
||||
|
||||
// Filter
|
||||
gpgItem->setData(COLUMN_NAME, ROLE_FILTER, gpgName);
|
||||
|
||||
gpgItem->setData(COLUMN_LAST_CONTACT, Qt::DisplayRole, showInfoAtGpgItem ? QVariant(bestLastContact) : "");
|
||||
gpgItem->setData(COLUMN_LAST_CONTACT, ROLE_SORT_NAME, showInfoAtGpgItem ? QVariant(bestLastContact) : "");
|
||||
gpgItem->setText(COLUMN_IP, showInfoAtGpgItem ? bestIP : "");
|
||||
@ -1189,6 +1196,9 @@ void FriendList::insertPeers()
|
||||
QString groupName = GroupDefs::name(*groupInfo);
|
||||
groupItem->setText(COLUMN_NAME, QString("%1 (%2/%3)").arg(groupName).arg(onlineCount).arg(availableCount));
|
||||
|
||||
// Filter
|
||||
groupItem->setData(COLUMN_NAME, ROLE_FILTER, groupName);
|
||||
|
||||
/* Sort data */
|
||||
groupItem->setData(COLUMN_NAME, ROLE_SORT_NAME, groupName);
|
||||
}
|
||||
@ -2254,7 +2264,7 @@ void FriendList::setShowGroups(bool show)
|
||||
void FriendList::filterItems(const QString &text)
|
||||
{
|
||||
mFilterText = text;
|
||||
ui->peerTreeWidget->filterItems(COLUMN_NAME, mFilterText);
|
||||
ui->peerTreeWidget->filterItems(COLUMN_NAME, mFilterText, ROLE_FILTER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,11 +81,11 @@ void RSTreeWidget::mousePressEvent(QMouseEvent *event)
|
||||
QTreeWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void RSTreeWidget::filterItems(int filterColumn, const QString &text)
|
||||
void RSTreeWidget::filterItems(int filterColumn, const QString &text, int role)
|
||||
{
|
||||
int count = topLevelItemCount();
|
||||
for (int index = 0; index < count; ++index) {
|
||||
filterItem(topLevelItem(index), filterColumn, text);
|
||||
filterItem(topLevelItem(index), filterColumn, text, role);
|
||||
}
|
||||
|
||||
QTreeWidgetItem *item = currentItem();
|
||||
@ -95,12 +95,12 @@ void RSTreeWidget::filterItems(int filterColumn, const QString &text)
|
||||
}
|
||||
}
|
||||
|
||||
bool RSTreeWidget::filterItem(QTreeWidgetItem *item, int filterColumn, const QString &text)
|
||||
bool RSTreeWidget::filterItem(QTreeWidgetItem *item, int filterColumn, const QString &text, int role)
|
||||
{
|
||||
bool itemVisible = true;
|
||||
|
||||
if (!text.isEmpty()) {
|
||||
if (!item->text(filterColumn).contains(text, Qt::CaseInsensitive)) {
|
||||
if (!item->data(filterColumn, role).toString().contains(text, Qt::CaseInsensitive)) {
|
||||
itemVisible = false;
|
||||
}
|
||||
}
|
||||
@ -108,7 +108,7 @@ bool RSTreeWidget::filterItem(QTreeWidgetItem *item, int filterColumn, const QSt
|
||||
int visibleChildCount = 0;
|
||||
int count = item->childCount();
|
||||
for (int index = 0; index < count; ++index) {
|
||||
if (filterItem(item->child(index), filterColumn, text)) {
|
||||
if (filterItem(item->child(index), filterColumn, text, role)) {
|
||||
++visibleChildCount;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
QString placeholderText() { return mPlaceholderText; }
|
||||
void setPlaceholderText(const QString &text);
|
||||
|
||||
void filterItems(int filterColumn, const QString &text);
|
||||
void filterItems(int filterColumn, const QString &text, int role = Qt::DisplayRole);
|
||||
|
||||
void setSettingsVersion(qint32 version);
|
||||
void processSettings(bool load);
|
||||
@ -53,7 +53,7 @@ signals:
|
||||
void columnVisibleChanged(int column, bool visible);
|
||||
|
||||
private:
|
||||
bool filterItem(QTreeWidgetItem *item, int filterColumn, const QString &text);
|
||||
bool filterItem(QTreeWidgetItem *item, int filterColumn, const QString &text, int role);
|
||||
|
||||
private slots:
|
||||
void headerContextMenuRequested(const QPoint &pos);
|
||||
|
Loading…
Reference in New Issue
Block a user