#include "uniform_design.h"
#include "ui_uniform_design.h"
Uniform_design::Uniform_design(QWidget *parent) :
QWidget(parent),
ui(new Ui::Uniform_design)
{
ui->setupUi(this);
init_data();
get_software_path();
}
Uniform_design::~Uniform_design()
{
delete ui;
}
void Uniform_design::init_data()
{
map_data();
ui->lineEdit->setEnabled(false);
ui->lineEdit_2->setEnabled(false);
QString str = ui->comboBox->currentText();
QString table_str = map_u.value(str);
qDebug()<<table_str;
QStringList teplist = table_str.split(",");
QString row_str = teplist.at(0);
ui->lineEdit->setText(row_str);
QStringList list_combox;
for(int i=1;i<teplist.size();i++)
{
list_combox<<teplist.at(i);
}
if(list_combox.size()>0)
{
ui->comboBox_2->addItems(list_combox);
}
qDebug()<<"2";
QString col_str = ui->comboBox_2->currentText();
set_table(ui->lineEdit->text(),ui->comboBox_2->currentText());
}
void Uniform_design::map_data()
{
map_u.clear();
map_u.insert("U5(5^3)","5,2,3");
map_u.insert("U6*(6^4)","6,2,3,4");
map_u.insert("U7(7^4)","7,2,3,4");
map_u.insert("U7*(7^4)","7,2,3");
map_u.insert("U8*(8^5)","8,2,3,4");
map_u.insert("U9(9^5)","9,2,3,4");
map_u.insert("U9*(9^4)","9,2,3");
map_u.insert("U10*(10^8)","10,2,3,4,5,6");
map_u.insert("U11(11^6)","11,2,3,4,5,6");
map_u.insert("U11*(11^4)","11,2,3");
map_u.insert("U12*(12^10)","12,2,3,4,5,6,7");
map_u.insert("U13(13^8)","13,2,3,4,5,6");
map_u.insert("U13*(13^4)","13,2,3,4");
map_u.insert("U14*(14^5)","14,2,3,4");
map_u.insert("U15(15^5)","15,2,3,4");
map_u.insert("U15*(15^7)","15,2,3,4,5");
map_u.insert("U16*(16^12)","16,2,3,4,5,6,7");
map_u.insert("U17(17^8)","17,2,3,4,5,6,7");
map_u.insert("U17*(17^5)","17,2,3,4");
map_u.insert("U18*(18^11)","18,2,3,4,5,6,7");
map_u.insert("U19(19^7)","19,2,3,4,5,6,7");
map_u.insert("U19*(19^7)","19,2,3,4,5");
map_u.insert("U20*(20^7)","20,2,3,4,5,6");
map_u.insert("U21(21^6)","21,2,3,4,5,6");
map_u.insert("U21*(21^7)","21,2,3,4,5");
map_u.insert("U22*(22^11)","22,2,3,4,5,6,7");
map_u.insert("U23(23^13)","23,2,3,4,5,6,7");
map_u.insert("U23*(23^7)","23,2,3,4,5");
map_u.insert("U24*(24^9)","24,2,3,4,5,6,7");
map_u.insert("U25(25^9)","25,2,3,4,5,6,7");
map_u.insert("U25*(25^11)","25,2,3,4,5");
map_u.insert("U26*(26^11)","26,2,3,4,5,6,7");
map_u.insert("U27(27^11)","27,2,3,4,5,6,7");
map_u.insert("U27*(27^10)","27,2,3,4,5");
map_u.insert("U28*(28^8)","28,2,3,4,5,6,7");
map_u.insert("U29(29^8)","29,2,3,4,5,6,7");
map_u.insert("U30*(30^13)","30,2,3,4,5,6,7");
map_u.insert("U31(31^12)","31,2,3,4,5,6,7");
map_u.insert("U31*(31^10)","31,2,3,4,5");
map_u.insert("U37(37^12)","37,2,3,4,5,6,7");
}
void Uniform_design::set_table(QString row_str, QString col_str)
{
ui->tableWidget_79->setRowCount(0);
ui->tableWidget_79->setRowCount(row_str.toInt()+1);
ui->tableWidget_79->setColumnCount(col_str.toInt());
}
void Uniform_design::map_list_data(QList<double> list,int i)
{
if(list.size()>1)
{
map_list.clear();
for(int i=0;i<list.size();i++)
{
map_list.insert(QString::number(i+1),QString::number(list.at(i)));
qDebug()<< "key"<<i+1<<"value"<<list.at(i);
}
for(int num=0;num<ui->tableWidget_80->rowCount();num++)
{
QString str = ui->tableWidget_80->item(num,i)->text();
if(str.contains("\n"))
{
str.remove(str.size()-1,1);
}
ui->tableWidget_80->item(num,i)->setText(map_list.value(str));
qDebug()<<str <<"-"<<num<<i<<"-"<<map_list.value(str);
}
ui->lineEdit_2->setText(bias_value);
}
}
void Uniform_design::visit_table()
{
QString str = ui->comboBox->currentText();
if(str.contains("*"))
{
str.replace("*","x");
}
read_txt(software_path+str+".txt",ui->tableWidget_82);
read_txt(software_path+str+"user.txt",ui->tableWidget_81);
}
void Uniform_design::create_table()
{
//插入表中 先找到对应的表和列
visit_table();
}
void Uniform_design::on_pushButton_clicked()
{
init_data();
ui->tableWidget_80->setRowCount(0);
ui->tableWidget_81->setRowCount(0);
ui->tableWidget_82->setRowCount(0);
ui->tableWidget_80->horizontalHeader()->setVisible(false);
}
void Uniform_design::on_pushButton_2_clicked()
{
create_table();
add_uniform_table();
//获取表格的数据进行排序
for(int i=0;i<ui->tableWidget_79->columnCount();i++)
{
QList<double>list_dle;
for(int k=1;k<ui->tableWidget_79->rowCount();k++)
{
if(ui->tableWidget_79->item(k,i) == 0)
{
qDebug()<<"row col"<<k<<i;
QMessageBox::warning(NULL, QStringLiteral("提示"), QString::fromLocal8Bit("请将因素水平表填好在执行操作"));
return;
}
else
{
list_dle<<ui->tableWidget_79->item(k,i)->text().toDouble();
}
}
qSort(list_dle);
//形成映射关系
qDebug()<<list_dle;
map_list_data(list_dle,i);
}
}
void Uniform_design::on_comboBox_activated(const QString &arg1)
{
ui->tableWidget_80->setRowCount(0);
QStringList list;
list.clear();
ui->tableWidget_80->setHorizontalHeaderLabels(list);
QString table_str = map_u.value(arg1);
QStringList teplist = table_str.split(",");
QString row_str = teplist.at(0);
ui->lineEdit->setText(row_str);
QStringList list_combox;
ui->comboBox_2->clear();
for(int i=1;i<teplist.size();i++)
{
list_combox<<teplist.at(i);
}
if(list_combox.size()>0)
{
ui->comboBox_2->addItems(list_combox);
}
set_table(ui->lineEdit->text(),ui->comboBox_2->currentText());
}
void Uniform_design::on_comboBox_2_activated(const QString &arg1)
{
ui->tableWidget_79->setRowCount(0);
set_table(ui->lineEdit->text(),ui->comboBox_2->currentText());
}
void Uniform_design::write_txt(QString path, QStringList list)
{
QFile file(path);
if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
return;
}
QTextStream stream(&file);
for(int i=0;i<list.size();i++)
{
QString temp_str = list.at(i);
if(i == list.size()-1)
{
temp_str.remove(temp_str.size()-1,1);
}
stream<<temp_str;
}
file.close();
}
void Uniform_design::get_tabletable(QTableWidget *tablewidget)
{
//遍历表格取出选值范围
tale_data_list.clear();
for(int i=0;i<tablewidget->rowCount();i++)
{
QString tStr = "";
for(int j=0;j<tablewidget->columnCount();j++)
{
if(tablewidget->item(i,j) != 0)
{
tStr = tStr + tablewidget->item(i,j)->text() + "\t";
}
else
{
tStr = tStr + "" + "\t";
}
}
if(tStr !="")
{
tStr.remove(tStr.size()-1,1);
tale_data_list<<tStr + "\n";
}
}
qDebug()<<tale_data_list;
if(tale_data_list.size()<1)
{
QMessageBox::warning(NULL, QStringLiteral("提示"), QString::fromLocal8Bit("请填表"));
return;
}
}
void Uniform_design::get_software_path()
{
QDir dir(qApp->applicationDirPath());
dir.cdUp();
// dir.cdUp();
software_path = dir.absolutePath() + QString("/uniform_tables/");
qDebug()<<software_path;
}
void Uniform_design::read_txt(QString path,QTableWidget *tablewidget)
{