-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab2.cpp
More file actions
83 lines (76 loc) · 3.44 KB
/
Lab2.cpp
File metadata and controls
83 lines (76 loc) · 3.44 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "Lab2.h"
#include "DynamicArray.h"
#include "LinkedList.h"
#include "ListSequence.h"
#include "ArraySequence.h"
#include "StringBuilder.h"
#include "CString.h"
#include "Tests.h"
#include <string>
#include "StringValidator.h"
#include "vld.h"
Lab2::Lab2(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
test_window.setWindowTitle("Tests");
UpdateValidator(ui.Index, 0);
UpdateValidator(ui.Count, 1);
QObject::connect(ui.GetButton, SIGNAL(clicked()), this, SLOT(SetSubSequence()));
QObject::connect(ui.String, SIGNAL(editingFinished()), this, SLOT(UpdateValidatorIndex()));
QObject::connect(ui.Index, SIGNAL(editingFinished()), this, SLOT(UpdateValidatorCount()));
QObject::connect(ui.FindButton, SIGNAL(clicked()), this, SLOT(SetIndexFind()));
QObject::connect(ui.TestButton, SIGNAL(clicked()), this, SLOT(StartTest()));
}
void Lab2::SetSubSequence()
{
if (ui.Index->text() == "" || ui.String->text() == "" || ui.Count->text() == "")
return;
StringBuilder str = ui.String->text().toStdString();
CString sub_cstr = str.ToString().SubString(ui.Index->text().toInt(), ui.Count->text().toInt());
QString sub_qstr;
for (size_t i = 0; i < sub_cstr.Size(); i++)
sub_qstr.append(sub_cstr.CharAt(i));
ui.SubstringGet->setText(sub_qstr);
}
void Lab2::UpdateValidator(QLineEdit* line_edit, int count)
{
line_edit->setValidator(new StringValidator(count,line_edit));
}
void Lab2::SetIndexFind()
{
StringBuilder str = ui.String->text().toStdString();
size_t first_index = str.ToString().FindSubString(ui.SubstringFind->text().toStdString());
QString index_str = first_index == str.Size() ? "Not found" : std::to_string(first_index).c_str();
ui.FirstIndex->setText(index_str);
}
void Lab2::UpdateValidatorIndex()
{
UpdateValidator(ui.Index, ui.String->text().size());
if (ui.Index->text().toInt() >= ui.String->text().size())
ui.Count->setText(""), ui.Index->setText("");
else if(ui.Count->text().toInt() >= ui.String->text().size() - ui.Index->text().toInt() + 1)
ui.Count->setText("");
UpdateValidatorCount();
}
void Lab2::UpdateValidatorCount()
{
if(ui.Index->text() == "")
UpdateValidator(ui.Count, 1);
else
UpdateValidator(ui.Count, ui.String->text().size() - ui.Index->text().toInt() + 1);
if(ui.Count->text().toInt() >= ui.String->text().size() - ui.Index->text().toInt() + 1)
ui.Count->setText("");
}
void Lab2::StartTest()
{
test_window.show();
test_window.ui.TestAppendLable->setText(TestAppend() ? "<font color=\"green\">Success</font>" : "<font color=\"red\">Failure</font>");
test_window.ui.TestPrependLable->setText(TestPrepend() ? "<font color=\"green\">Success</font>" : "<font color=\"red\">Failure</font>");
test_window.ui.TestInsertLable->setText(TestInsert() ? "<font color=\"green\">Success</font>" : "<font color=\"red\">Failure</font>");
test_window.ui.TestRemoveLable->setText(TestRemove() ? "<font color=\"green\">Success</font>" : "<font color=\"red\">Failure</font>");
test_window.ui.TestReplaceLable->setText(TestReplace() ? "<font color=\"green\">Success</font>" : "<font color=\"red\">Failure</font>");
test_window.ui.TestToStringLable->setText(TestToString() ? "<font color=\"green\">Success</font>" : "<font color=\"red\">Failure</font>");
test_window.ui.TestSubStringLable->setText(TestSubString() ? "<font color=\"green\">Success</font>" : "<font color=\"red\">Failure</font>");
test_window.ui.TestFindSubStringLable->setText(TestFindSubString() ? "<font color=\"green\">Success</font>" : "<font color=\"red\">Failure</font>");
}