From 18de3fab975951705dac3e1c90877d2a317b2174 Mon Sep 17 00:00:00 2001 From: Jafarichen <3149829972@qq.com> Date: Thu, 16 Dec 2021 00:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UniversalTuringMachine.pro.user | 338 ++++++++++++++++---------------- mainwindow.cpp | 134 +++++++++++-- mainwindow.h | 13 +- 3 files changed, 294 insertions(+), 191 deletions(-) diff --git a/UniversalTuringMachine.pro.user b/UniversalTuringMachine.pro.user index 2c9554e..05741d0 100644 --- a/UniversalTuringMachine.pro.user +++ b/UniversalTuringMachine.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -8,7 +8,7 @@ ProjectExplorer.Project.ActiveTarget - 2 + 0 ProjectExplorer.Project.EditorSettings @@ -90,6 +90,171 @@ ProjectExplorer.Project.Target.0 + + Desktop + Qt 6.2.2 for macOS + Qt 6.2.2 for macOS + qt.qt6.622.clang_64_kit + 0 + 0 + 0 + + 0 + /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Debug + /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Release + /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Profile + /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/Users/chenhangjian/Desktop/code/UniversialTuringMachine/UniversalTuringMachine.pro + /Users/chenhangjian/Desktop/code/UniversialTuringMachine/UniversalTuringMachine.pro + false + true + true + false + true + /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Debug/UniversalTuringMachine.app/Contents/MacOS + + 1 + + + + ProjectExplorer.Project.Target.1 Ios.Device.Type Qt 6.2.2 for iOS @@ -249,7 +414,7 @@ 0 - UniversalTuringMachine + Run on Jafari’s iPad Qt4ProjectManager.IosRunConfiguration:/Users/chenhangjian/Desktop/code/UniversialTuringMachine/UniversalTuringMachine.pro /Users/chenhangjian/Desktop/code/UniversialTuringMachine/UniversalTuringMachine.pro false @@ -261,7 +426,7 @@ - ProjectExplorer.Project.Target.1 + ProjectExplorer.Project.Target.2 Ios.Simulator.Type Qt 6.2.2 for iOS Simulator @@ -428,171 +593,6 @@ 1 - - ProjectExplorer.Project.Target.2 - - Desktop - Qt 6.2.2 for macOS - Qt 6.2.2 for macOS - qt.qt6.622.clang_64_kit - 0 - 0 - 0 - - 0 - /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Debug - /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Release - /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Profile - /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:/Users/chenhangjian/Desktop/code/UniversialTuringMachine/UniversalTuringMachine.pro - /Users/chenhangjian/Desktop/code/UniversialTuringMachine/UniversalTuringMachine.pro - false - true - true - false - true - /Users/chenhangjian/Desktop/build-UniversalTuringMachine-Qt_6_2_2_for_macOS-Debug/UniversalTuringMachine.app/Contents/MacOS - - 1 - - ProjectExplorer.Project.TargetCount 3 diff --git a/mainwindow.cpp b/mainwindow.cpp index a5c0844..1b6a02e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,11 +3,19 @@ #define START_X 40 #define START_Y 40 #define DELTA_Y 50 -#define LABEL_X 50 +#define LABEL_X 20 #define LABEL_Y 40 #define LINE_X 200 #define LINE_Y 30 +QString filepath=QDir::currentPath(); +QStringList K; +QStringList Sigma; +QStringList Gamma; +QStringList Q0; +QStringList B; +QStringList F; + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -18,34 +26,34 @@ MainWindow::MainWindow(QWidget *parent) label_k = new QLabel(this); label_k->setGeometry(START_X, START_Y+DELTA_Y*0, LABEL_X, LABEL_Y); - label_k->setText("K"); + label_k->setText(" K"); label_sigma = new QLabel(this); label_sigma->setGeometry(START_X, START_Y+DELTA_Y*1, LABEL_X, LABEL_Y); - label_sigma->setText("sigma"); + label_sigma->setText(" ∑"); - label_gama = new QLabel(this); - label_gama->setGeometry(START_X, START_Y+DELTA_Y*2, LABEL_X, LABEL_Y); - label_gama->setText("gama"); + label_gamma = new QLabel(this); + label_gamma->setGeometry(START_X, START_Y+DELTA_Y*2, LABEL_X, LABEL_Y); + label_gamma->setText(" Γ"); label_q0 = new QLabel(this); label_q0->setGeometry(START_X, START_Y+DELTA_Y*3, LABEL_X, LABEL_Y); - label_q0->setText("q0"); + label_q0->setText(" q0"); label_B = new QLabel(this); label_B->setGeometry(START_X, START_Y+DELTA_Y*4, LABEL_X, LABEL_Y); - label_B->setText("B"); + label_B->setText(" B"); label_F = new QLabel(this); label_F->setGeometry(START_X, START_Y+DELTA_Y*5, LABEL_X, LABEL_Y); - label_F->setText("F"); + label_F->setText(" F"); line_k = new QLineEdit(this); line_k->setFixedSize(LINE_X,LINE_Y); line_sigma = new QLineEdit(this); line_sigma->setFixedSize(LINE_X,LINE_Y); - line_gama = new QLineEdit(this); - line_gama->setFixedSize(LINE_X,LINE_Y); + line_gamma = new QLineEdit(this); + line_gamma->setFixedSize(LINE_X,LINE_Y); line_q0 = new QLineEdit(this); line_q0->setFixedSize(LINE_X,LINE_Y); line_B = new QLineEdit(this); @@ -56,7 +64,7 @@ MainWindow::MainWindow(QWidget *parent) layout_label = new QVBoxLayout(this); layout_label->addWidget(label_k); layout_label->addWidget(label_sigma); - layout_label->addWidget(label_gama); + layout_label->addWidget(label_gamma); layout_label->addWidget(label_q0); layout_label->addWidget(label_B); layout_label->addWidget(label_F); @@ -64,7 +72,7 @@ MainWindow::MainWindow(QWidget *parent) layout_line = new QVBoxLayout(this); layout_line->addWidget(line_k); layout_line->addWidget(line_sigma); - layout_line->addWidget(line_gama); + layout_line->addWidget(line_gamma); layout_line->addWidget(line_q0); layout_line->addWidget(line_B); layout_line->addWidget(line_F); @@ -79,30 +87,33 @@ MainWindow::MainWindow(QWidget *parent) //配置文件引入窗 list_file = new QListWidget(this); - list_file->setGeometry(380, 40, 280, 220); + list_file->setGeometry(380, 40, 220, 250); + + loadFileList(); btn_import = new QPushButton(this); - btn_import->setGeometry(380, 280, 280, 40); + btn_import->setGeometry(380, 320, 220, 40); btn_import->setText("导入文件"); //状态转移函数框 list_func = new QListWidget(this); - list_func->setGeometry(700, 40, 280, 300); + list_func->setGeometry(640, 40, 340, 300); + list_func->setWrapping(true); //输入纸带 label_str = new QLabel(this); - label_str->setGeometry(380, 365, 60, 30); + label_str->setGeometry(380, 395, 60, 30); label_str->setText("输入纸带:"); line_str = new QLineEdit(this); - line_str->setGeometry(440,360,420,40); + line_str->setGeometry(440,390,420,40); btn_confirm = new QPushButton(this); - btn_confirm->setGeometry(870, 360, 50, 40); + btn_confirm->setGeometry(870, 390, 50, 40); btn_confirm->setText("确认"); btn_step = new QPushButton(this); - btn_step->setGeometry(930, 360, 50, 40); + btn_step->setGeometry(930, 390, 50, 40); btn_step->setText("下一步"); QObject::connect(btn_import, SIGNAL(clicked()), this, SLOT(importFile())); @@ -118,7 +129,60 @@ MainWindow::~MainWindow() void MainWindow::importFile() { + K.clear(); + Sigma.clear(); + Gamma.clear(); + Q0.clear(); + B.clear(); + F.clear(); + int row=list_file->currentRow(); + list_func->clear(); + QFile file(filepath + "/" + QString::number(row) + ".txt"); + if(file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream in(&file); + QString temp; + while(1) + { + temp=in.readLine(); + if(temp.size()==0) + break; + QStringList list = temp.split(" "); + list_func->addItem(" δ("+list[0]+","+list[1]+","+list[2]+")=("+list[3]+","+list[4]+") "); + append(&K,list[0]); + append(&Sigma,list[1]); + append(&Gamma,list[2]); + //Q0.append(list[0]); + append(&B,list[3]); + append(&F,list[4]); + } + } + QString k,sigma,gamma,q0,b,f; + q0="q0"; + for(int i=0;isetText(k); + line_sigma->setText(sigma); + line_gamma->setText(gamma); + line_q0->setText(q0); + line_B->setText(b); + line_F->setText(f); + + line_k->setEnabled(false); + line_sigma->setEnabled(false); + line_gamma->setEnabled(false); + line_q0->setEnabled(false); + line_B->setEnabled(false); + line_F->setEnabled(false); } void MainWindow::startSimulate() { @@ -130,3 +194,33 @@ void MainWindow::nextStep() } + +void MainWindow::loadFileList() +{ + QFile file(filepath+"/filelist.txt"); + if(file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream in(&file); + QString temp; + while(1) + { + temp=in.readLine(); + if(temp.size()==0) + break; + QStringList list = temp.split(" "); + list_file->addItem(list[1]); + } + } +} + +void MainWindow::append(QStringList* list,QString in) +{ + int flag=0; + for(int i=0;isize();i++) + { + if(list->contains(in)) + return; + } + if(flag==0) + list->append(in); +} diff --git a/mainwindow.h b/mainwindow.h index f0a2d00..7e25391 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -10,6 +10,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -22,14 +28,17 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); + void loadFileList(); + void append(QStringList* list,QString in); + public slots: void nextStep(); void importFile(); void startSimulate(); private: Ui::MainWindow *ui; - QLabel *label_k,*label_sigma,*label_gama,*label_q0,*label_B,*label_F; - QLineEdit *line_k,*line_sigma,*line_gama,*line_q0,*line_B,*line_F; + QLabel *label_k,*label_sigma,*label_gamma,*label_q0,*label_B,*label_F; + QLineEdit *line_k,*line_sigma,*line_gamma,*line_q0,*line_B,*line_F; QLineEdit *line_str; QVBoxLayout *layout_label,*layout_line; QLabel *label_str;