forked from qt-creator/qt-creator
Replace the current license disclaimer in files by a SPDX-License-Identifier. Task-number: QTBUG-67283 Change-Id: I708fd1f9f2b73d60f57cc3568646929117825813 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
49 lines
986 B
C++
49 lines
986 B
C++
// Copyright (C) 2022 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
#include "textfinder.h"
|
|
|
|
//! [1]
|
|
#include "./ui_textfinder.h"
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
//! [1]
|
|
|
|
//! [3]
|
|
TextFinder::TextFinder(QWidget *parent)
|
|
: QWidget(parent)
|
|
, ui(new Ui::TextFinder)
|
|
{
|
|
ui->setupUi(this);
|
|
loadTextFile();
|
|
}
|
|
//! [3]
|
|
|
|
TextFinder::~TextFinder()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
//! [0]
|
|
void TextFinder::loadTextFile()
|
|
{
|
|
QFile inputFile(":/input.txt");
|
|
inputFile.open(QIODevice::ReadOnly);
|
|
|
|
QTextStream in(&inputFile);
|
|
QString line = in.readAll();
|
|
inputFile.close();
|
|
|
|
ui->textEdit->setPlainText(line);
|
|
QTextCursor cursor = ui->textEdit->textCursor();
|
|
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
|
|
}
|
|
//! [0]
|
|
|
|
//! [2]
|
|
void TextFinder::on_findButton_clicked()
|
|
{
|
|
QString searchString = ui->lineEdit->text();
|
|
ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
|
|
}
|
|
//! [2]
|