diff --git a/Lesson_5/Task_4/.gitignore b/Lesson_5/Task_4/.gitignore new file mode 100644 index 0000000..4a0b530 --- /dev/null +++ b/Lesson_5/Task_4/.gitignore @@ -0,0 +1,74 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* +CMakeLists.txt.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/Lesson_5/Task_4/Task_4.pro b/Lesson_5/Task_4/Task_4.pro new file mode 100644 index 0000000..eed2382 --- /dev/null +++ b/Lesson_5/Task_4/Task_4.pro @@ -0,0 +1,24 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + wordfilter.cpp + +HEADERS += \ + wordfilter.h + +FORMS += \ + wordfilter.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/Lesson_5/Task_4/main.cpp b/Lesson_5/Task_4/main.cpp new file mode 100644 index 0000000..0be3d9c --- /dev/null +++ b/Lesson_5/Task_4/main.cpp @@ -0,0 +1,11 @@ +#include "wordfilter.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Wordfilter w; + w.show(); + return a.exec(); +} diff --git a/Lesson_5/Task_4/wordfilter.cpp b/Lesson_5/Task_4/wordfilter.cpp new file mode 100644 index 0000000..f8f9219 --- /dev/null +++ b/Lesson_5/Task_4/wordfilter.cpp @@ -0,0 +1,46 @@ +#include "wordfilter.h" +#include "ui_wordfilter.h" + +Wordfilter::Wordfilter(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::Wordfilter) +{ + ui->setupUi(this); + connect(ui->b_select, &QPushButton::clicked, this, &Wordfilter::selectFile); + connect(ui->b_filter, &QPushButton::clicked, this, &Wordfilter::filter); +} + +Wordfilter::~Wordfilter() +{ + delete ui; +} + +void Wordfilter::selectFile() +{ + QString fileName = QFileDialog::getOpenFileName(this, "Open word list", "", "Text files (*.txt);;All Files (*)"); + + if (fileName.isEmpty()) + return; + + QFile file(fileName); + + if (file.open(QIODevice::ReadOnly)) { + QStringList words; + QTextStream in(&file); + + while (!in.atEnd()) + words.append(in.readLine()); + + setWords(words); + } + + file.close(); +} + +void Wordfilter::filter() +{ + QString text = ui->e_text->toPlainText(); + for (QString word : m_words) + text.replace(word, "[filtered]"); + ui->e_text->setText(text); +} diff --git a/Lesson_5/Task_4/wordfilter.h b/Lesson_5/Task_4/wordfilter.h new file mode 100644 index 0000000..fa33189 --- /dev/null +++ b/Lesson_5/Task_4/wordfilter.h @@ -0,0 +1,31 @@ +#ifndef WORDFILTER_H +#define WORDFILTER_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { +class Wordfilter; +} +QT_END_NAMESPACE + +class Wordfilter : public QMainWindow +{ + Q_OBJECT + +public: + Wordfilter(QWidget *parent = nullptr); + ~Wordfilter(); + QStringList getWords() { return m_words; } + void setWords(QStringList words) { m_words = words; } + +private: + Ui::Wordfilter *ui; + void selectFile(); + void filter(); + QStringList m_words; +}; +#endif // WORDFILTER_H diff --git a/Lesson_5/Task_4/wordfilter.ui b/Lesson_5/Task_4/wordfilter.ui new file mode 100644 index 0000000..2b7a991 --- /dev/null +++ b/Lesson_5/Task_4/wordfilter.ui @@ -0,0 +1,66 @@ + + + Wordfilter + + + + 0 + 0 + 800 + 600 + + + + Wordfilter + + + + + + + + + Filtered words file: + + + + + + + Select + + + + + + + + + + + + + + Filter + + + + + + + + + + + 0 + 0 + 800 + 25 + + + + + + + +