72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
#include "uhistory.h"
|
|
|
|
#include "src/ui_uhistory.h"
|
|
#include "ui_uhistory.h"
|
|
|
|
CUIHistory::CUIHistory(QWidget* parent, CHistory* his) : QDialog(parent), ui(new Ui::CUIHistory)
|
|
{
|
|
ui->setupUi(this);
|
|
his_ = his;
|
|
|
|
connect(ui->btnExit, &QPushButton::clicked, this, [&]() { close(); });
|
|
connect(ui->btnOk, &QPushButton::clicked, this, [&]() { select_ok(); });
|
|
connect(ui->btnDel, &QPushButton::clicked, this, [&]() { del_item(); });
|
|
connect(ui->listWidget, &QListWidget::doubleClicked, this, [&](const QModelIndex& index) { double_click(index); });
|
|
}
|
|
|
|
CUIHistory::~CUIHistory()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void CUIHistory::showEvent(QShowEvent* event)
|
|
{
|
|
std::vector<std::string> vec;
|
|
his_->get_history(vec);
|
|
|
|
QStringList list;
|
|
for (const auto& data : vec) {
|
|
list.append(QString::fromStdString(data));
|
|
}
|
|
if (!list.empty()) {
|
|
ui->listWidget->addItems(list);
|
|
}
|
|
cur_.clear();
|
|
QDialog::showEvent(event);
|
|
}
|
|
|
|
void CUIHistory::select_ok()
|
|
{
|
|
auto re = ui->listWidget->selectedItems();
|
|
if (re.empty()) {
|
|
return;
|
|
}
|
|
cur_ = re[0]->text();
|
|
close();
|
|
}
|
|
|
|
void CUIHistory::del_item()
|
|
{
|
|
auto re = ui->listWidget->selectedItems();
|
|
if (re.empty()) {
|
|
return;
|
|
}
|
|
for (auto& item : re) {
|
|
delete ui->listWidget->takeItem(ui->listWidget->row(item));
|
|
}
|
|
std::vector<std::string> vec;
|
|
for (int i = 0; i < ui->listWidget->count(); ++i) {
|
|
QListWidgetItem* item = ui->listWidget->item(i);
|
|
if (item) {
|
|
vec.push_back(item->text().toStdString());
|
|
}
|
|
}
|
|
his_->write_file(vec);
|
|
}
|
|
|
|
void CUIHistory::double_click(const QModelIndex& index)
|
|
{
|
|
cur_ = index.data().toString();
|
|
close();
|
|
}
|