-
Notifications
You must be signed in to change notification settings - Fork 88
/
searchfellowdlg.cpp
59 lines (50 loc) · 1.46 KB
/
searchfellowdlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "searchfellowdlg.h"
#include "ui_searchfellowdlg.h"
SearchFellowDlg::SearchFellowDlg(QWidget *parent) :
QDialog(parent),
ui(new Ui::SearchFellowDlg)
{
ui->setupUi(this);
connect(ui->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(search(QString)));
connect(ui->cancelBtn, SIGNAL(pressed()), this, SLOT(hide()));
connect(ui->okBtn, SIGNAL(pressed()), this, SLOT(searchDone()));
connect(ui->resultListWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(searchDone()));
}
SearchFellowDlg::~SearchFellowDlg()
{
delete ui;
}
void SearchFellowDlg::setSearchDriver(function<vector<const Fellow*>(const QString &)> driver)
{
mSearchDriver = driver;
}
void SearchFellowDlg::search(const QString &text)
{
if (mSearchDriver)
{
mCurResult = mSearchDriver(text);
ui->resultListWidget->clear();
for (const Fellow* fellow : mCurResult)
ui->resultListWidget->addItem(QString(fellow->toString().c_str()));
if (mCurResult.size() > 0)
ui->resultListWidget->setCurrentRow(0);
ui->okBtn->setEnabled(mCurResult.size()>0);
}
}
void SearchFellowDlg::searchDone()
{
auto row = ui->resultListWidget->currentRow();
if (row >= 0)
{
emit onFellowSelected(mCurResult[row]);
hide();
}
}
void SearchFellowDlg::showEvent(QShowEvent *)
{
loadAllFellows();
}
void SearchFellowDlg::loadAllFellows()
{
search("");//search 空字符串将获得所有好友
}