-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Сделал рефакторинг, написал комментарии.
- Loading branch information
Showing
32 changed files
with
1,103 additions
and
1,622 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
QT += core gui | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
TARGET = HuffmanCoding | ||
TEMPLATE = app | ||
|
||
|
||
SOURCES += main.cpp\ | ||
choose.cpp \ | ||
encoding.cpp \ | ||
decoding.cpp \ | ||
huffman.cpp \ | ||
guiutils.cpp | ||
|
||
HEADERS += choose.h \ | ||
encoding.h \ | ||
decoding.h \ | ||
huffman.h \ | ||
guiutils.h | ||
|
||
FORMS += choose.ui \ | ||
encoding.ui \ | ||
decoding.ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "choose.h" | ||
#include "ui_choose.h" | ||
#include "encoding.h" | ||
#include "decoding.h" | ||
|
||
// Конструктор: | ||
Choose::Choose(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::Choose) | ||
{ | ||
ui->setupUi(this); | ||
|
||
// Связать клик на кнопку "Сжать данные" с методом showCompressDialog(): | ||
connect(ui->compressButton, SIGNAL(clicked()), this, SLOT(showCompressDialog())); | ||
|
||
// Связать клик на кнопку "Восстановить данные" с методом showDecompressDialog(): | ||
connect(ui->decompressButton, SIGNAL(clicked()), this, SLOT(showDecompressDialog())); | ||
} | ||
|
||
// Деструктор: | ||
Choose::~Choose() | ||
{ | ||
delete ui; | ||
} | ||
|
||
// Показать диалоговое окно для сжатия данных: | ||
void Choose::showCompressDialog() | ||
{ | ||
// Диалоговое окно для сжатия данных: | ||
Encoding* en = new Encoding(this); | ||
// Если в конструктор передавать указатель на родительский виджет, | ||
// то диалоговое окно будет отцентрировано относительно родителя. | ||
|
||
// Делаем размеры диалогового окна не изменяемыми: | ||
en->setFixedSize(en->size()); | ||
|
||
en->setWindowTitle("Сжати данных по алгоритму Хаффмана"); | ||
|
||
// Показать диалоговое окно: | ||
en->exec(); | ||
} | ||
|
||
// Показать диалоговое окно для восстановления данных: | ||
void Choose::showDecompressDialog() | ||
{ | ||
// Диалоговое окно для восстановления данных: | ||
Decoding* de = new Decoding(this); | ||
// Если в конструктор передавать указатель на родительский виджет, | ||
// то диалоговое окно будет отцентрировано относительно родителя. | ||
|
||
// Делаем размеры диалогового окна не изменяемыми: | ||
de->setFixedSize(de->size()); | ||
|
||
de->setWindowTitle("Восстановление данных сжатых по алгоритму Хаффмана"); | ||
|
||
// Показать диалоговое окно: | ||
de->exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Choose</class> | ||
<widget class="QDialog" name="Choose"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>300</width> | ||
<height>200</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Сжатие и восстановление данных</string> | ||
</property> | ||
<property name="windowIcon"> | ||
<iconset> | ||
<normaloff>:/images/icon.png</normaloff>:/images/icon.png</iconset> | ||
</property> | ||
<widget class="QPushButton" name="compressButton"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>20</x> | ||
<y>20</y> | ||
<width>256</width> | ||
<height>64</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Сжать данные</string> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="decompressButton"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>20</x> | ||
<y>110</y> | ||
<width>256</width> | ||
<height>64</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Восстановить данные</string> | ||
</property> | ||
</widget> | ||
</widget> | ||
<layoutdefault spacing="6" margin="11"/> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "decoding.h" | ||
#include "ui_decoding.h" | ||
#include "QFileDialog" | ||
#include "guiutils.h" | ||
|
||
// Конструктор: | ||
Decoding::Decoding(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::Decoding) | ||
{ | ||
ui->setupUi(this); | ||
|
||
// Связать кнопку "Обзор…" с методом browseInputFile(): | ||
connect(ui->browseButton, SIGNAL(clicked()), this, SLOT(browseInputFile())); | ||
|
||
// Связать кнопку "Восстановить данные" с методом decompressFile(): | ||
connect(ui->decodeButton, SIGNAL(clicked()), this, SLOT(decompressFile())); | ||
} | ||
|
||
// Деструктор: | ||
Decoding::~Decoding() | ||
{ | ||
delete ui; | ||
} | ||
|
||
// Метод для выбора файла для восстановления: | ||
void Decoding::browseInputFile() | ||
{ | ||
// Открыть диалоговое окно для выбора файла: | ||
inputFileName = QFileDialog::getOpenFileName(this, | ||
tr("Открыть файл"), | ||
QString(), | ||
tr("Бинарные файлы (*.bin)")); | ||
|
||
ui->inputFile->setText(inputFileName); | ||
} | ||
|
||
// Восстановить сжатый файл: | ||
void Decoding::decompressFile() | ||
{ | ||
// Если имя файла пустое: | ||
if (inputFileName == "") | ||
{ | ||
showDoneMessage("Пожалуйста, выберите файл.", "Восстановление данных"); | ||
} | ||
|
||
// Иначе, если имя файла есть: | ||
else | ||
{ | ||
// Имя файла: | ||
QByteArray byteArray = inputFileName.toUtf8(); | ||
const char* inputFile = byteArray.constData(); | ||
|
||
// Сжать файл: | ||
huffmanDecode(inputFile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef DECODING_H | ||
#define DECODING_H | ||
|
||
#include <QDialog> | ||
#include "huffman.h" | ||
|
||
namespace Ui { | ||
class Decoding; | ||
} | ||
|
||
class Decoding : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
// Конструктор: | ||
explicit Decoding(QWidget *parent = 0); | ||
|
||
// Деструктор: | ||
~Decoding(); | ||
|
||
// Получить имя входного файла: | ||
QString getInputFileName(); | ||
|
||
private: | ||
|
||
// Пользовательский интерфейс: | ||
Ui::Decoding *ui; | ||
|
||
// Имя входного файла: | ||
QString inputFileName; | ||
|
||
public slots: | ||
|
||
// Метод для выбора файла для восстановления: | ||
void browseInputFile(); | ||
|
||
// Восстановить сжатый файл: | ||
void decompressFile(); | ||
}; | ||
|
||
#endif // DECODING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Decoding</class> | ||
<widget class="QDialog" name="Decoding"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>500</width> | ||
<height>79</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Dialog</string> | ||
</property> | ||
<property name="windowIcon"> | ||
<iconset> | ||
<normaloff>:/images/icon.png</normaloff>:/images/icon.png</iconset> | ||
</property> | ||
<widget class="QPushButton" name="decodeButton"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>40</y> | ||
<width>475</width> | ||
<height>23</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Восстановить данные</string> | ||
</property> | ||
</widget> | ||
<widget class="QLineEdit" name="inputFile"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>10</y> | ||
<width>401</width> | ||
<height>20</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</widget> | ||
<widget class="QPushButton" name="browseButton"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>420</x> | ||
<y>10</y> | ||
<width>64</width> | ||
<height>23</height> | ||
</rect> | ||
</property> | ||
<property name="text"> | ||
<string>Обзор…</string> | ||
</property> | ||
</widget> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "encoding.h" | ||
#include "ui_encoding.h" | ||
#include "QFileDialog" | ||
#include "guiutils.h" | ||
|
||
// Конструктор: | ||
Encoding::Encoding(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::Encoding) | ||
{ | ||
ui->setupUi(this); | ||
|
||
// Связать кнопку "Обзор…" с методом browseInputFile(): | ||
connect(ui->browseButton, SIGNAL(clicked()), this, SLOT(browseInputFile())); | ||
|
||
// Связать кнопку "Сжать данные" с методом compressFile(): | ||
connect(ui->encodeButton, SIGNAL(clicked()), this, SLOT(compressFile())); | ||
} | ||
|
||
// Деструктор: | ||
Encoding::~Encoding() | ||
{ | ||
delete ui; | ||
} | ||
|
||
// Метод для выбора файла для сжатия: | ||
void Encoding::browseInputFile() | ||
{ | ||
// Открыть диалоговое окно для выбора файла: | ||
inputFileName = QFileDialog::getOpenFileName(this, | ||
tr("Открыть файл"), | ||
QString(), | ||
tr("Текстовые файлы (*.txt)")); | ||
|
||
ui->inputFile->setText(inputFileName); | ||
} | ||
|
||
// Метод для сжатия файла: | ||
void Encoding::compressFile() | ||
{ | ||
// Если имя файла пустое: | ||
if (inputFileName == "") | ||
{ | ||
showDoneMessage("Пожалуйста, выберите файл.", "Сжатие данных"); | ||
} | ||
|
||
// Иначе, если имя файла есть: | ||
else | ||
{ | ||
// Имя файла: | ||
QByteArray byteArray = inputFileName.toUtf8(); | ||
const char* inputFile = byteArray.constData(); | ||
|
||
// Сжать файл: | ||
huffmanEncode(inputFile); | ||
} | ||
} |
Oops, something went wrong.