blob: 0048f055a02844635a8c8231c0a9b72cc09dbbe6 (
plain)
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
60
61
62
63
|
#include "usersdialog.h"
#include "ui_usersdialog.h"
#include <QRegExp>
UsersDialog::UsersDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::UsersDialog)
{
ui->setupUi(this);
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui->listWidget, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(itemChange(QListWidgetItem *)));
}
UsersDialog::~UsersDialog()
{
delete ui;
}
Q_DECLARE_METATYPE(UserInfo *)
void UsersDialog::itemChange(QListWidgetItem *item)
{
if (!item) return;
UserInfo *info = item->data(Qt::UserRole).value<UserInfo *>();
if (!info) return;
info->enabled = item->checkState() == Qt::Checked;
}
void UsersDialog::setUsers(QList<UserInfo> *users)
{
userList = users;
populateList("");
}
void UsersDialog::populateList(const QString &filter)
{
QRegExp nameFilter("*"+filter+"*");
nameFilter.setPatternSyntax(QRegExp::Wildcard);
ui->listWidget->clear();
if (userList) {
for (QList<UserInfo>::iterator it = userList->begin(); it != userList->end(); ++it) {
UserInfo &user(*it);
if (filter.isEmpty() || nameFilter.exactMatch(user.name)) {
QListWidgetItem *item = new QListWidgetItem(user.name + "\n" + user.key_id, ui->listWidget);
item->setCheckState(user.enabled ? Qt::Checked : Qt::Unchecked);
item->setData(Qt::UserRole, QVariant::fromValue(&user));
ui->listWidget->addItem(item);
}
}
}
}
void UsersDialog::on_clearButton_clicked()
{
ui->lineEdit->clear();
on_lineEdit_textChanged("");
}
void UsersDialog::on_lineEdit_textChanged(const QString &filter)
{
populateList(filter);
}
|