Added tab for the DHT TreeWidgets for better view

Added a search Filter for DHT IP addresses
This commit is contained in:
defnax 2015-08-07 15:14:47 +02:00
parent fabc3a3985
commit c168765bb2
3 changed files with 655 additions and 554 deletions

View File

@ -41,6 +41,8 @@ DhtWindow::DhtWindow(QWidget *parent)
{
ui.setupUi(this);
connect( ui.filterLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterItems(QString)));
connect( ui.filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterColumnChanged(int)));
}
DhtWindow::~DhtWindow()
@ -700,3 +702,46 @@ void DhtWindow::getDHTStatus()
// }
// }
}
void DhtWindow::filterColumnChanged(int)
{
filterItems(ui.filterLineEdit->text());
}
void DhtWindow::filterItems(const QString &text)
{
int filterColumn = ui.filterLineEdit->currentFilter();
int count = ui.dhtTreeWidget->topLevelItemCount ();
for (int index = 0; index < count; ++index) {
filterItem(ui.dhtTreeWidget->topLevelItem(index), text, filterColumn);
}
}
bool DhtWindow::filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn)
{
bool visible = true;
if (text.isEmpty() == false) {
if (item->text(filterColumn).contains(text, Qt::CaseInsensitive) == false) {
visible = false;
}
}
int visibleChildCount = 0;
int count = item->childCount();
for (int index = 0; index < count; ++index) {
if (filterItem(item->child(index), text, filterColumn)) {
++visibleChildCount;
}
}
if (visible || visibleChildCount) {
item->setHidden(false);
} else {
item->setHidden(true);
}
return (visible || visibleChildCount);
}

View File

@ -42,11 +42,17 @@ public:
public slots:
virtual void updateDisplay() ;
void filterColumnChanged(int);
void filterItems(const QString &text);
protected:
//void changeEvent(QEvent *e);
private:
bool filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn);
/** Qt Designer generated object */
Ui::DhtWindow ui;

File diff suppressed because it is too large Load Diff