void MainWindow::surveyData()
{
int math=0, chinese=0, english=0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem *aItem= theModel->item(i, 1);
int text = aItem->text().toInt();
if (text < 60)
math++;
}
QString Math = QString::number(math);
math = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 2);
int text = aItem->text().toInt();
if (text < 60)
chinese++;
}
QString Chinese = QString::number(chinese);
chinese = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 3);
int text = aItem->text().toInt();
if (text < 60)
english++;
}
QString English = QString::number(english);
english = 0;
QStringList headerList;
headerList << " 分数段" << "数学" <<"语文"<< "英语";
ui.treeWidget->setHeaderLabels(headerList);
QTreeWidgetItem* item;
item = new QTreeWidgetItem(1001);
item->setText(0, "60分以下");
item->setText(1, Math);
item->setText(2, Chinese);
item->setText(3, English);
ui.treeWidget->addTopLevelItem (item);
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 1);
int text = aItem->text().toInt();
if (text > 60&&text<69)
math++;
}
QString Math1 = QString::number(math);
math = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 2);
int text = aItem->text().toInt();
if (text > 60&&text<69)
chinese++;
}
QString Chinese1 = QString::number(chinese);
chinese = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 3);
int text = aItem->text().toInt();
if (text > 60&&text<69)
english++;
}
QString English1 = QString::number(english);
english = 0;
item = new QTreeWidgetItem(1002);
item->setText(0, "60-69分");
item->setText(1, Math1);
item->setText(2, Chinese1);
item->setText(3, English1);
ui.treeWidget->addTopLevelItem(item);
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 1);
int text = aItem->text().toInt();
if (text > 70 && text < 79)
math++;
}
QString Math2 = QString::number(math);
math = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 2);
int text = aItem->text().toInt();
if (text > 70 && text < 79)
chinese++;
}
QString Chinese2 = QString::number(chinese);
chinese = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 3);
int text = aItem->text().toInt();
if (text > 70 && text < 79)
english++;
}
QString English2 = QString::number(english);
english = 0;
item = new QTreeWidgetItem(1003);
item->setText(0, "70-79分");
item->setText(1, Math2);
item->setText(2, Chinese2);
item->setText(3, English2);
ui.treeWidget->addTopLevelItem(item);
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 1);
int text = aItem->text().toInt();
if (text > 80 && text < 89)
math++;
}
QString Math3 = QString::number(math);
math = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 2);
int text = aItem->text().toInt();
if (text > 80 && text < 89)
chinese++;
}
QString Chinese3 = QString::number(chinese);
chinese = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 3);
int text = aItem->text().toInt();
if (text > 80 && text < 89)
english++;
}
QString English3 = QString::number(english);
english = 0;
item = new QTreeWidgetItem(1004);
item->setText(0, "80-89分");
item->setText(1, Math3);
item->setText(2, Chinese3);
item->setText(3, English3);
ui.treeWidget->addTopLevelItem(item);
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 1);
int text = aItem->text().toInt();
if (text > 90)
math++;
}
QString Math4 = QString::number(math);
math = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 2);
int text = aItem->text().toInt();
if (text > 90)
chinese++;
}
QString Chinese4 = QString::number(chinese);
chinese = 0;
for (int i = 0; i < iniDataRowCount; i++)
{
QStandardItem* aItem = theModel->item(i, 3);
int text = aItem->text().toInt();
if (text > 90)
english++;
}
QString English4 = QString::number(english);
english = 0;
item = new QTreeWidgetItem(1005);
item->setText(0, "90分以上");
item->setText(1, Math4);
item->setText(2, Chinese4);
item->setText(3, English4);
ui.treeWidget->addTopLevelItem(item);
}
大佬们,这个代码有办法简化吗?