-
Notifications
You must be signed in to change notification settings - Fork 0
/
textfinder.cpp
75 lines (61 loc) · 2.02 KB
/
textfinder.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "textfinder.h"
#include "./ui_textfinder.h"
TextFinder::TextFinder(QWidget *parent)
: QWidget(parent)
, ui(new Ui::TextFinder)
{
ui->setupUi(this);
ui->addtext->setPlaceholderText("Enter text to append here");
ui->searchfield->setPlaceholderText("Enter word to find here");;
loadTextFile();
}
TextFinder::~TextFinder()
{
delete ui;
}
void TextFinder::loadTextFile(){
QFile inputFile("absolute_path_to_2input.txt");
inputFile.open(QIODevice::ReadWrite);
inputFile.seek(0);
QTextStream in(&inputFile);
QString line = in.readAll();
// qDebug() << line;
inputFile.close();
ui->textEdit->setPlainText(line);
QTextCursor cursor = ui->textEdit->textCursor();
cursor.movePosition(QTextCursor::Start , QTextCursor::MoveAnchor , 1);
}
void TextFinder::on_addbtn_clicked()
{
QString newString = ui->addtext->text();
QFile inputFile("absolute_path_to_2input.txt");
inputFile.open(QIODevice::ReadWrite);
QTextStream stream(&inputFile);
stream.seek(inputFile.size());
stream << newString <<"\n";
inputFile.close();
inputFile.open(QIODevice::ReadWrite);
QString line = stream.readAll();
ui->textEdit->setPlainText(line);
ui->addtext->clear();
}
void TextFinder::on_deleteallbtn_clicked()
{
QFile inputFile("absolute_path_to_2input.txt");
inputFile.open(QIODevice::ReadWrite | QIODevice::Truncate);
inputFile.close();
inputFile.open(QIODevice::ReadWrite);
QTextStream stream(&inputFile);
stream.seek(inputFile.size());
QString line = stream.readAll();
ui->textEdit->setPlainText(line);
}
void TextFinder::on_findbtn_clicked()
{
QString searchString = ui->searchfield->text();
QTextCursor cursor = ui->textEdit->textCursor();
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
ui->textEdit->setTextCursor(cursor);
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
ui->searchfield->clear();
}