Add Lesson 5 Task 4
This commit is contained in:
parent
9a82d4a921
commit
0172aee4af
6 changed files with 252 additions and 0 deletions
74
Lesson_5/Task_4/.gitignore
vendored
Normal file
74
Lesson_5/Task_4/.gitignore
vendored
Normal file
|
@ -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
|
||||
|
24
Lesson_5/Task_4/Task_4.pro
Normal file
24
Lesson_5/Task_4/Task_4.pro
Normal file
|
@ -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
|
11
Lesson_5/Task_4/main.cpp
Normal file
11
Lesson_5/Task_4/main.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "wordfilter.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Wordfilter w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
46
Lesson_5/Task_4/wordfilter.cpp
Normal file
46
Lesson_5/Task_4/wordfilter.cpp
Normal file
|
@ -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);
|
||||
}
|
31
Lesson_5/Task_4/wordfilter.h
Normal file
31
Lesson_5/Task_4/wordfilter.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef WORDFILTER_H
|
||||
#define WORDFILTER_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QTextStream>
|
||||
|
||||
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
|
66
Lesson_5/Task_4/wordfilter.ui
Normal file
66
Lesson_5/Task_4/wordfilter.ui
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Wordfilter</class>
|
||||
<widget class="QMainWindow" name="Wordfilter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Wordfilter</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Filtered words file:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="b_select">
|
||||
<property name="text">
|
||||
<string>Select</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTextEdit" name="e_text"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="b_filter">
|
||||
<property name="text">
|
||||
<string>Filter</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Reference in a new issue