Skip to content

Commit 4d64c8f

Browse files
committed
完成GUI化
0 parents  commit 4d64c8f

31 files changed

+3348
-0
lines changed

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# C++ objects and libs
2+
*.slo
3+
*.lo
4+
*.o
5+
*.a
6+
*.la
7+
*.lai
8+
*.so
9+
*.dll
10+
*.dylib
11+
12+
# Qt-es
13+
object_script.*.Release
14+
object_script.*.Debug
15+
*_plugin_import.cpp
16+
/.qmake.cache
17+
/.qmake.stash
18+
*.pro.user
19+
*.pro.user.*
20+
*.qbs.user
21+
*.qbs.user.*
22+
*.moc
23+
moc_*.cpp
24+
moc_*.h
25+
qrc_*.cpp
26+
ui_*.h
27+
*.qmlc
28+
*.jsc
29+
Makefile*
30+
*build-*
31+
32+
# Qt unit tests
33+
target_wrapper.*
34+
35+
# QtCreator
36+
*.autosave
37+
38+
# QtCreator Qml
39+
*.qmlproject.user
40+
*.qmlproject.user.*
41+
42+
# QtCreator CMake
43+
CMakeLists.txt.user*

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Compiler
2+
编译原理课程实验
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26430.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SyntacticAnalyzer", "SyntacticAnalyzer\SyntacticAnalyzer.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Release|x64 = Release|x64
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.ActiveCfg = Debug|x64
15+
{B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.Build.0 = Debug|x64
16+
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.ActiveCfg = Release|x64
17+
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.Build.0 = Release|x64
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "AnalysisStep.h"
2+
3+
AnalysisStep::AnalysisStep(QWidget *parent)
4+
: QWidget(parent) {
5+
ui.setupUi(this);
6+
setp_model = new TableModel;
7+
ui.setp_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
8+
init_table();
9+
10+
}
11+
12+
void AnalysisStep::add_step(map<int, vector<string>> setp) {
13+
map<int, vector<string>>:: iterator it = setp.begin();
14+
map<int, vector<string>>::iterator end = setp.end();
15+
vector<string>::iterator str_it;
16+
vector<string>::iterator str_end;
17+
int row = 0;
18+
int col = 0;
19+
for (it; it != end; it++) {
20+
int size = it->second.size();
21+
//qDebug() << "size=" << QString("%1").arg(size);
22+
//setp_model->setHeaderData(row, Qt::Vertical, QString("%1").arg(it->first));
23+
col = 0;
24+
setp_model->setItem(row, col, new QStandardItem(QString("%1").arg(it->first)));
25+
str_it = it->second.begin();
26+
str_end = it->second.end();
27+
for (str_it; str_it != str_end; str_it++) {
28+
setp_model->setItem(row, col, new QStandardItem(QString::fromLocal8Bit(str_it->data())));
29+
col++;
30+
}
31+
row++;
32+
}
33+
}
34+
35+
void AnalysisStep::clear_table() {
36+
setp_model->clear();
37+
init_table();
38+
}
39+
40+
AnalysisStep::~AnalysisStep() {
41+
delete setp_model;
42+
}
43+
44+
void AnalysisStep::init_table() {
45+
setp_model->setColumnCount(5);
46+
//setp_model->setHeaderData(0, Qt::Horizontal, QString::fromLocal8Bit("步骤"));
47+
setp_model->setHeaderData(0, Qt::Horizontal, QString::fromLocal8Bit("符号栈状态"));
48+
setp_model->setHeaderData(1, Qt::Horizontal, QString::fromLocal8Bit("关系"));
49+
setp_model->setHeaderData(2, Qt::Horizontal, QString::fromLocal8Bit("输入串状态"));
50+
setp_model->setHeaderData(3, Qt::Horizontal, QString::fromLocal8Bit("最短素短语"));
51+
setp_model->setHeaderData(4, Qt::Horizontal, QString::fromLocal8Bit("动作"));
52+
ui.setp_table->setModel(setp_model);
53+
ui.setp_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
54+
ui.setp_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
55+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
///=================================================================================================
2+
/// \file AnalysisStep.h
3+
///
4+
/// \brief 声明分析过程显示界面处理的类
5+
///=================================================================================================
6+
7+
#pragma once
8+
9+
#include <QWidget>
10+
#include "ui_AnalysisStep.h"
11+
#include "TableModel.h"
12+
#include <vector>
13+
#include <map>
14+
#include <string>
15+
#include <QDebug>
16+
using namespace std;
17+
class AnalysisStep : public QWidget {
18+
Q_OBJECT
19+
20+
public:
21+
AnalysisStep(QWidget *parent = Q_NULLPTR);
22+
void add_step(map<int, vector<string>> setp);
23+
void clear_table();
24+
~AnalysisStep();
25+
26+
private:
27+
Ui::AnalysisStep ui;
28+
TableModel *setp_model;
29+
void init_table();
30+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>AnalysisStep</class>
4+
<widget class="QWidget" name="AnalysisStep">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>811</width>
10+
<height>800</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>分析过程</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="0" column="0">
18+
<widget class="QTableView" name="setp_table">
19+
<property name="styleSheet">
20+
<string notr="true">QHeaderView::section {
21+
color: white;
22+
background-color: rgb(0, 170, 255);
23+
border: 5px solid #f6f7fa;
24+
border-radius:0px;
25+
border-color: rgb(0, 170, 255);
26+
} </string>
27+
</property>
28+
<attribute name="horizontalHeaderCascadingSectionResizes">
29+
<bool>false</bool>
30+
</attribute>
31+
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
32+
<bool>false</bool>
33+
</attribute>
34+
<attribute name="horizontalHeaderStretchLastSection">
35+
<bool>false</bool>
36+
</attribute>
37+
<attribute name="verticalHeaderVisible">
38+
<bool>true</bool>
39+
</attribute>
40+
<attribute name="verticalHeaderCascadingSectionResizes">
41+
<bool>false</bool>
42+
</attribute>
43+
<attribute name="verticalHeaderShowSortIndicator" stdset="0">
44+
<bool>false</bool>
45+
</attribute>
46+
</widget>
47+
</item>
48+
</layout>
49+
</widget>
50+
<layoutdefault spacing="6" margin="11"/>
51+
<resources/>
52+
<connections/>
53+
</ui>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include "Config.h"
2+
#include <QDebug>
3+
Config::Config(QWidget *parent)
4+
: QWidget(parent) {
5+
ui.setupUi(this);
6+
connect(ui.open_terminals, SIGNAL(clicked()), this, SLOT(open_terminal()));
7+
connect(ui.open_garmms, SIGNAL(clicked()), this, SLOT(open_grammars()));
8+
connect(ui.ok, SIGNAL(clicked()), this, SLOT(ok_btn()));
9+
connect(this, SIGNAL(file_type_send(int)), this, SLOT(open_file(int)));
10+
read_setting();
11+
}
12+
13+
14+
void Config::connect_signal_slot() {
15+
connect(ui.open_terminals, SIGNAL(clicked()), this, SLOT(open_terminal()));
16+
connect(ui.open_garmms, SIGNAL(clicked()), this, SLOT(open_grammars()));
17+
connect(ui.ok, SIGNAL(clicked()), this, SLOT(ok_btn()));
18+
connect(this, SIGNAL(file_type_send(int)), this, SLOT(open_file(int)));
19+
}
20+
21+
QString Config::get_grammars_path() {
22+
return ui.garmmars_path->text();
23+
}
24+
25+
QString Config::get_terminal_path() {
26+
return ui.terminals_path->text();
27+
}
28+
29+
Config::~Config() {
30+
}
31+
32+
void Config::open_file(int file_type) {
33+
qDebug() << "open";
34+
QFileDialog *file_dialog = new QFileDialog(this); //定义文 件对话框类
35+
file_dialog->setWindowTitle(QString::fromLocal8Bit("打开文件")); //定义文件对话框标题
36+
file_dialog->setDirectory("."); //设置默认文件路径
37+
file_dialog->setNameFilter(tr("file(*.txt)")); //设置文件过滤器
38+
file_dialog->setFileMode(QFileDialog::ExistingFile); //单个文件
39+
file_dialog->setViewMode(QFileDialog::Detail); //设置视图模式
40+
QString file_path;
41+
if (file_dialog->exec()) {
42+
QByteArray file_name_btye = file_dialog->selectedFiles()[0].toLocal8Bit();
43+
std::string file_name = file_name_btye.toStdString();
44+
file_path = QFileInfo(QString::fromStdString(file_name)).absoluteFilePath();
45+
if (file_type == 0) {
46+
teminanls_path = file_path;
47+
ui.terminals_path->setText(file_path);
48+
49+
} else {
50+
grammars_path = file_path;
51+
ui.garmmars_path->setText(file_path);
52+
}
53+
54+
}
55+
delete file_dialog;
56+
}
57+
58+
void Config::read_setting() {
59+
QSettings *read = new QSettings("config.ini", QSettings::IniFormat);
60+
QString file_name = QFileInfo(QString::fromLocal8Bit(read->value("/path/terminals").toByteArray())).absoluteFilePath();
61+
ui.terminals_path->setText(file_name);
62+
file_name = QFileInfo(QString::fromLocal8Bit(read->value("/path/grammars").toByteArray())).absoluteFilePath();
63+
ui.garmmars_path->setText(file_name);
64+
delete read;
65+
}
66+
67+
void Config::wirte_setting() {
68+
QSettings *write = new QSettings("config.ini", QSettings::IniFormat);
69+
QString file_name = ui.terminals_path->text();
70+
write->setValue("/path/terminals", file_name);
71+
file_name = ui.garmmars_path->text();
72+
write->setValue("/path/grammars", file_name);
73+
delete write;
74+
}
75+
76+
void Config::open_terminal() {
77+
emit file_type_send(0);
78+
}
79+
80+
void Config::open_grammars() {
81+
emit file_type_send(1);
82+
}
83+
84+
void Config::ok_btn() {
85+
emit finish();
86+
emit teminanls_file(ui.terminals_path->text());
87+
emit grammars_file(ui.garmmars_path->text());
88+
wirte_setting();
89+
90+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
///=================================================================================================
2+
/// \file Config.h
3+
///
4+
/// \brief 声明用于配置信息读写的类
5+
///=================================================================================================
6+
7+
#pragma once
8+
9+
#include <QWidget>
10+
#include "ui_Config.h"
11+
#include <QFileDialog>
12+
#include <QFileInfo>
13+
#include <QSettings>
14+
class Config : public QWidget {
15+
Q_OBJECT
16+
17+
public:
18+
Config(QWidget *parent = Q_NULLPTR);
19+
void connect_signal_slot();
20+
QString get_grammars_path();
21+
QString get_terminal_path();
22+
~Config();
23+
private slots:
24+
void open_terminal();
25+
void open_grammars();
26+
void ok_btn();
27+
void open_file(int file_type);
28+
signals:
29+
void teminanls_file(QString);
30+
void grammars_file(QString);
31+
void file_type_send(int file_type);
32+
void finish();
33+
34+
private:
35+
Ui::Config ui;
36+
QString teminanls_path;
37+
QString grammars_path;
38+
void read_setting();
39+
void wirte_setting();
40+
};

0 commit comments

Comments
 (0)