2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2008-12-02 12:57:59 +01:00
|
|
|
#include "textfinder.h"
|
|
|
|
|
|
2009-04-02 13:33:40 +02:00
|
|
|
//! [1]
|
2022-07-05 09:51:15 +02:00
|
|
|
#include "./ui_textfinder.h"
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QTextStream>
|
2009-04-02 13:33:40 +02:00
|
|
|
//! [1]
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-02 13:33:40 +02:00
|
|
|
//! [3]
|
2009-03-24 17:35:59 +01:00
|
|
|
TextFinder::TextFinder(QWidget *parent)
|
2022-07-05 09:51:15 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
|
, ui(new Ui::TextFinder)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-03-24 17:35:59 +01:00
|
|
|
ui->setupUi(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
loadTextFile();
|
|
|
|
|
}
|
2009-04-02 13:33:40 +02:00
|
|
|
//! [3]
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
TextFinder::~TextFinder()
|
|
|
|
|
{
|
2009-03-24 17:35:59 +01:00
|
|
|
delete ui;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-24 17:57:43 +01:00
|
|
|
//! [0]
|
2008-12-02 12:01:29 +01:00
|
|
|
void TextFinder::loadTextFile()
|
|
|
|
|
{
|
|
|
|
|
QFile inputFile(":/input.txt");
|
|
|
|
|
inputFile.open(QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
|
|
QTextStream in(&inputFile);
|
|
|
|
|
QString line = in.readAll();
|
|
|
|
|
inputFile.close();
|
|
|
|
|
|
2009-03-24 17:35:59 +01:00
|
|
|
ui->textEdit->setPlainText(line);
|
|
|
|
|
QTextCursor cursor = ui->textEdit->textCursor();
|
2008-12-02 12:01:29 +01:00
|
|
|
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
|
|
|
|
|
}
|
2009-03-24 17:57:43 +01:00
|
|
|
//! [0]
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-04-02 13:33:40 +02:00
|
|
|
//! [2]
|
2008-12-02 12:01:29 +01:00
|
|
|
void TextFinder::on_findButton_clicked()
|
|
|
|
|
{
|
2009-03-24 17:35:59 +01:00
|
|
|
QString searchString = ui->lineEdit->text();
|
|
|
|
|
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-04-02 13:33:40 +02:00
|
|
|
//! [2]
|