Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
51 lines (42 loc) · 1.58 KB
/
Copy pathmainwindow.cpp
File metadata and controls
51 lines (42 loc) · 1.58 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "include/editDistance.h"
void MainWindow::MetricSlotWrapper(std::function<size_t(std::wstring, std::wstring)> func, QLabel* outputLabel) {
// Очистка - ввод - обработка - вывод
ui->ErrorMsg->setText("");
std::wstring str1 = ui->textEdit->toPlainText().toStdWString();
std::wstring str2 = ui->textEdit_2->toPlainText().toStdWString();
size_t distance = func(str1, str2);
QString output = QString("%1").arg(distance);
outputLabel->setText(output);
}
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::ClearOutput() {
// Чтобы при изменении ввода удалялся неактуальный вывод
ui->ErrorMsg->setText("");
ui->LevensteinLabel->setText("");
ui->DamerauLevensteinLabel->setText("");
ui->LCSLabel->setText("");
ui->HammingLabel->setText("");
}
void MainWindow::Levenstein_slot() {
MetricSlotWrapper(Levenstein<wchar_t>, ui->LevensteinLabel);
}
void MainWindow::DamerauLevenstein_slot() {
MetricSlotWrapper(DamerauLevenstein<wchar_t>, ui->DamerauLevensteinLabel);
}
void MainWindow::LCS_slot() {
MetricSlotWrapper(Lcs<wchar_t>, ui->LCSLabel);
}
void MainWindow::Hamming_slot() {
try {
MetricSlotWrapper(Hamming<wchar_t>, ui->HammingLabel);
} catch (std::invalid_argument exc) {
ui->ErrorMsg->setText("Введите две строки одинаковой длины");
}
}