-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathstringlistdialog.cpp
57 lines (47 loc) · 1.39 KB
/
stringlistdialog.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
#include "stringlistdialog.h"
#include "ui_stringlistdialog.h"
#include <QStringList>
#include <QInputDialog>
#include <QLineEdit>
StringListDialog::StringListDialog(QString elemType, QWidget *parent) :
QDialog(parent),
ui(new Ui::StringListDialog),
elemType(elemType)
{
ui->setupUi(this);
QObject::connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addItem()));
QObject::connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteItem()));
QObject::connect(ui->doneButton, SIGNAL(clicked()), this, SLOT(done()));
QObject::connect(ui->deleteAllButton, SIGNAL(clicked()), this, SLOT(deleteAllItem()));
}
void StringListDialog::addItem()
{
QString text = QInputDialog::getText(this, tr("Add Item"),
"Enter " + elemType + ": ",
QLineEdit::Normal, defaultValue);
ui->listWidget->addItem(new QListWidgetItem(text));
}
void StringListDialog::deleteItem()
{
QSharedPointer<QListWidgetItem> item(ui->listWidget->currentItem());
ui->listWidget->removeItemWidget(item.data());
}
void StringListDialog::deleteAllItem()
{
ui->listWidget->clear();
}
void StringListDialog::done()
{
this->close();
}
QStringList StringListDialog::getStringList() const
{
QStringList ret;
for (int i = 0; i < ui->listWidget->count(); ++i)
ret << ui->listWidget->item(i)->text();
return ret;
}
StringListDialog::~StringListDialog()
{
delete ui;
}