Skip to content

Commit

Permalink
增加规则库扩充选项,增加系统可识别动物类别查询按钮、选项勾选复位按钮,恢复添加规则窗口图标为主窗口默认图标
Browse files Browse the repository at this point in the history
  • Loading branch information
YoferChen committed Nov 20, 2020
1 parent 6dfbcc8 commit 9657723
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 67 deletions.
6 changes: 3 additions & 3 deletions AnimalRecogitionQt5.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.3.1, 2020-11-20T12:40:37. -->
<!-- Written by QtCreator 4.3.1, 2020-11-20T16:39:04. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -62,7 +62,7 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.9.0 MinGW 32bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.9.0 MinGW 32bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.59.win32_mingw53_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
Expand Down Expand Up @@ -292,7 +292,7 @@
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">AnimalRecogitionQt5.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">D:/QT Project/build-AnimalRecogitionQt5-Desktop_Qt_5_9_0_MinGW_32bit-Debug</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">D:/QT Project/build-AnimalRecogitionQt5-Desktop_Qt_5_9_0_MinGW_32bit-Release</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
Expand Down
Binary file added README.assets/image-20201120170134790.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,8 @@ F4:有黑色条纹

- 添加规则

![image-20201120152829757](README.assets/image-20201120152829757.png)
![image-20201120152829757](README.assets/image-20201120152829757.png)

- 识别

![image-20201120170134790](README.assets/image-20201120170134790.png)
2 changes: 1 addition & 1 deletion addrulesdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ AddRulesDialog::AddRulesDialog(QWidget *parent) :
}
if (close==false)
{
QMessageBox::warning(this,"文本栏不能为空","警告");
QMessageBox::warning(this,"警告","文本栏不能为空");
}
if(close==true)
{
Expand Down
8 changes: 2 additions & 6 deletions addrulesdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
<x>0</x>
<y>0</y>
<width>520</width>
<height>370</height>
<height>404</height>
</rect>
</property>
<property name="windowTitle">
<string>添加规则</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/1/30.ico</normaloff>:/1/30.ico</iconset>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="widget_rules" native="true">
Expand Down Expand Up @@ -48,7 +44,7 @@
<x>0</x>
<y>0</y>
<width>277</width>
<height>232</height>
<height>266</height>
</rect>
</property>
</widget>
Expand Down
108 changes: 53 additions & 55 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,11 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// QCheckBox *check1=new QCheckBox(ui->scrollArea);
// check1->setText("test");
// QCheckBox *check2=new QCheckBox(ui->scrollArea);
// check1->setText("test");
// QCheckBox *check3=new QCheckBox(ui->scrollArea);
// check1->setText("test");
// QCheckBox *check4=new QCheckBox(ui->scrollArea);
// check1->setText("test");
// QCheckBox *check5=new QCheckBox(ui->scrollArea);
// check1->setText("test");
// QCheckBox *check6=new QCheckBox(ui->scrollArea);
// check1->setText("test");
// ui->scrollArea->setAlignment(Qt::AlignVCenter);

pLayout = new QGridLayout();//网格布局
ui->scrollArea->widget()->setLayout(pLayout);//把布局放置到QScrollArea的内部QWidget中
pLayout->setAlignment(Qt::AlignTop);

// for(int i = 0; i < 5; i++)
// {
//// QPushButton *pBtn = new QPushButton();
//// pBtn->setText(QString("按钮%1").arg(i));
//// pBtn->setMinimumSize(QSize(60,30)); //width height
//// pLayout->addWidget(pBtn);//把按钮添加到布局控件中
// if(i%2==0)
// {
// QCheckBox *pCheck=new QCheckBox();
// pCheck->setText(QString("选项%1").arg(i));
// pCheck->setMinimumSize(QSize(60,30));
// pLayout->addWidget(pCheck,i/2,0);//把选项添加到布局控件中,第二个参数和第三个参数分别表示控件放置在第几行第几列
// }
// else
// {
// QCheckBox *pCheck=new QCheckBox();
// pCheck->setText(QString("选项%1").arg(i));
// pCheck->setMinimumSize(QSize(60,30));
// pLayout->addWidget(pCheck,i/2,1);//把选项添加到布局控件中
// }

// }

//点击添加规则按钮弹出窗口
connect(ui->btn_add_rule,&QPushButton::clicked,[=](){
//弹出窗口
Expand All @@ -73,7 +37,7 @@ MainWindow::MainWindow(QWidget *parent) :
addRulesDialog->exec(); //必须放在信号连接之后,否则接收不到信号!!!


// connect(addRulesDialog,&AddRulesDialog::sendSignal,[=](){
// connect(addRulesDialog,&AddRulesDialog::sendSignal,[=](){ //放在exec之后,接收不到信号
// qDebug()<<"Received signal!\n";
// });
}
Expand Down Expand Up @@ -108,6 +72,35 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->btn_delete_rule,&QPushButton::clicked,[=](){
deleteRuleFromList();
});

//规则库扩充
connect(ui->pushButton_rulesExpansion,&QPushButton::clicked,[=](){
rules_expansion();
QMessageBox::about(this,"规则库扩充","规则库扩充成功!");
ui->pushButton_rulesExpansion->setDisabled(true);
});

//选项复位
connect(ui->pushButton_checkReset,&QPushButton::clicked,[=](){
for(int i=0;i<rules.getRulesNum();++i)
{
if(pCheck[i]->checkState()==Qt::Checked)
{
pCheck[i]->setChecked(false);
}
}
});

//查询动物类别库
connect(ui->pushButton_getClasses,&QPushButton::clicked,[=](){
QString meg;
meg+="系统可识别的动物类别如下:\n";
for(int i=0;i<classes.size();++i)
{
meg+=" "+QString::number(i+1)+" "+classes[i]+"\n";
}
QMessageBox::about(this,"动物类别库",meg);
});
}

MainWindow::~MainWindow()
Expand All @@ -116,12 +109,6 @@ MainWindow::~MainWindow()
}


//void MainWindow::createAddRuleDialog()
//{
// addRulesDialog=new AddRulesDialog();
// addRulesDialog->exec();
//}

void MainWindow::addRuleToList(Rule *rule) //添加规则到list控件中
{
int n_pre=rule->n_pre;
Expand Down Expand Up @@ -375,19 +362,29 @@ void MainWindow::initRules()
checkAndAddFactToList(rule);
}

// Rule* rule=new Rule();
// rule->n_pre=1;
// rule->premise[0]={"有奶"};
// rule->interence={"哺乳动物"};
// rules.addRule(rule);
// addRuleToList(rule);
// checkAndAddFactToList(rule);

// Rule* rule1=strToRule(initRules[1]);
// rules.addRule(rule1);
// addRuleToList(rule1);
// checkAndAddFactToList(rule1);
}

void MainWindow::rules_expansion()
{
QStringList expRules;
expRules<<"有毛发&有奶&善跳跃&唇裂,兔子"<<"有毛发&有奶&善捕鼠&脚有肉垫,猫"<<"有毛发&有奶&鼻子上有角&褐色&皮糙肉厚&有蹄,犀牛"
<<"有毛发&有奶&黑眼圈&四肢短小,熊猫"<<"鸟类&上嘴鹰钩&会模仿人说话,鹦鹉"<<"鸟类&腿短&嘴扁平&善潜水游泳,鸭子"
<<"鸟类&上嘴鹰钩&有爪&吃肉,鹰"<<"有羽毛&卵生&善游泳&嘴扁平&腿短,鸭子"<<"有羽毛&卵生&善潜水游泳&白色或黑色&颈长&嘴大&腿长&颈部有肉只凸起,鹅"
<<"有羽毛&卵生&黑色&嘴大,鸦"<<"有羽毛&卵生&有爪&吃肉&上嘴鹰钩,鹰"<<"有羽毛&卵生&上嘴鹰钩&能模仿人说话,鹦鹉"
<<"卵生&生活在水中&生活在陆地&有皮肤呼吸&用肺呼吸&皮肤光滑&吃昆虫&会变色,青蛙"<<"卵生&生活在水中&生活在陆地&有皮肤呼吸&用肺呼吸&吃昆虫&皮肤粗糙&四肢扁&背部黑色,蝾螈"
<<"卵生&生活在水中&生活在陆地&有皮肤呼吸&用肺呼吸&吃昆虫&皮肤粗糙,蟾蜍"<<"用鳃呼吸&身体有鳍&生活在海洋中&身体扁平&两眼在头部同侧,比目鱼"
<<"用鳃呼吸&身体有鳍&生活在淡水中&身体扁平&头高尾部窄,鲫鱼"<<"生活在陆地&用肺呼吸&胎生&身体有鳞或甲&身体圆而细长&吃小动物,蛇"
<<"生活在陆地&用肺呼吸&胎生&身体有鳞或甲&有四肢&尾巴细长易断&吃昆虫,壁虎"<<"生活在陆地&用肺呼吸&胎生&身体有鳞或甲&身体圆而扁&有坚硬的壳,乌龟"
<<"生活在陆地&用肺呼吸&胎生&身体有鳞或甲&壳为黄褐色&皮肤光滑&有黑斑,玳瑁"<<"生活在陆地&用肺呼吸&胎生&身体有鳞或甲&有四肢&善游泳&皮硬黑褐色,鳄鱼";
for(int i=0;i<expRules.size();++i)
{
Rule* rule=strToRule(expRules[i]);
rules.addRule(rule);
addRuleToList(rule);
checkAndAddFactToList(rule);
classes<<rule->interence; //将推论,即动物类别加入类别数据库
}
classes=classes.toSet().toList(); //自动去重
}

void MainWindow::getAddedRule(Rule* rule)
Expand Down Expand Up @@ -416,6 +413,7 @@ void MainWindow::getAddedRule(Rule* rule)
{
classes.append(rule->interence);
}
classes=classes.toSet().toList(); //自动去重

}

1 change: 1 addition & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MainWindow : public QMainWindow
QGridLayout *pLayout;
QCheckBox *pCheck[100]; //100个事实选项
void initRules(); //初始化规则库和事实库(事实库根据规则库初始化)
void rules_expansion(); //规则库扩充,实验选做
public slots:
void getAddedRule(Rule* rule);
};
Expand Down
41 changes: 40 additions & 1 deletion mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<x>0</x>
<y>0</y>
<width>321</width>
<height>366</height>
<height>363</height>
</rect>
</property>
</widget>
Expand Down Expand Up @@ -228,6 +228,19 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_checkReset">
<property name="font">
<font>
<family>中国式手写风</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>选项复位</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_recognition">
<property name="font">
Expand Down Expand Up @@ -293,6 +306,32 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_getClasses">
<property name="font">
<font>
<family>中国式手写风</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>查询动物类别</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_rulesExpansion">
<property name="font">
<font>
<family>中国式手写风</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>规则库扩充</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down
3 changes: 3 additions & 0 deletions 编译打包方法.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
打开Qt 5.9 for Desktop (MinGW 5.3.0 32 bit)命令行,进入realse后生成的exe文件的目录下(单独拷贝到一个空文件夹中),执行以下命令编译打包:
windeployqt XXX.exe
说明:XXX是realse生成的exe文件名

0 comments on commit 9657723

Please sign in to comment.