From 166f6e6bc3981a80affb277c3a48acbee244d413 Mon Sep 17 00:00:00 2001 From: patchy1-admin Date: Wed, 4 Sep 2024 18:39:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=88=86=E7=B1=BB=E6=97=B6?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E4=B8=8D=E5=90=8C=E5=88=99=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=BE=85=E5=AD=A6=E4=B9=A0=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- learningdialog.cpp | 50 ++++++++++++++++++++++++++++++++++++++++------ mainwindow.cpp | 27 +++++++++++++++++++++++-- mainwindow.h | 2 ++ 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/learningdialog.cpp b/learningdialog.cpp index 47cb8cf..d30ee94 100644 --- a/learningdialog.cpp +++ b/learningdialog.cpp @@ -91,6 +91,8 @@ void LearningDialog::set_items_table(QString filter) if(isSpeedLearn) ui->comboBox->setCurrentIndex(1); clear_question_display(); + ui->tableView->sortByColumn(0,Qt::AscendingOrder); + on_comboBox_currentTextChanged(ui->comboBox->currentText()); } void LearningDialog::set_question(int id) @@ -177,18 +179,44 @@ void LearningDialog::on_pushButton_clicked() //两次提交切换题目、生成随机排序数 if(submited) { + int newCurrentId = tableModel->index(oldRow,0).data().toInt(); + //更新随机排序数 - if(ui->comboBox->currentText() == "随机排序") + if(ui->comboBox->currentText() == "随机排序" && newCurrentId == currentId) { - tableModel->index(oldRow,0).data().toInt(); int randNum = QRandomGenerator::global()->bounded(32768); - questionSql->set_data(tableModel->index(oldRow,0).data().toInt(),"orderNum",randNum); - ui->tableView->sortByColumn(21,Qt::AscendingOrder); + questionSql->set_data(newCurrentId,"orderNum",randNum); + tableModel->select(); + }else if(ui->comboBox->currentText() == "默认排序" && newCurrentId == currentId) + { + QString state = tableModel->index(oldRow,2).data().toString(); + if(state == "learning") + { + int shortTimeCount = 0; + int row = oldRow + 1; + while(shortTimeCount < 30 && row < tableModel->rowCount()) + { + QTime gTime = QTime().fromString(tableModel->index(oldRow,5).data().toString(),"mm'm':ss's'"); + shortTimeCount += gTime.msecsSinceStartOfDay()/1000; + row++; + } + int orderNum1 = tableModel->index(row - 1,21).data().toInt(); + int orderNum2 = 32767; + if(row < tableModel->rowCount()) + { + orderNum2 = tableModel->index(row,21).data().toInt(); + } + int newOrderNum = (orderNum1 + orderNum2) / 2; + questionSql->set_data(newCurrentId,"orderNum",newOrderNum); + tableModel->select(); + } } + newCurrentId = tableModel->index(oldRow,0).data().toInt(); + //切换题目 int newRow = oldRow; - if(tableModel->index(oldRow,0).data().toInt() == currentId) + if(newCurrentId == currentId) { newRow = oldRow + 1; if(newRow >= tableModel->rowCount()) @@ -344,13 +372,23 @@ void LearningDialog::on_comboBox_currentTextChanged(const QString &arg1) int rowCount = tableModel->rowCount(); for(int i = 0;i < rowCount;i++) { - ui->tableView->setSortingEnabled(false); int randNum = QRandomGenerator::global()->bounded(32768); int id = tableModel->index(i,0).data().toInt(); questionSql->set_data(id,"orderNum",randNum); } ui->tableView->setSortingEnabled(true); ui->tableView->sortByColumn(21,Qt::AscendingOrder); + }else if(arg1 == "默认排序") + { + int rowCount = tableModel->rowCount(); + int gap = 32767 / rowCount; + for(int i = 0;i < rowCount;i++) + { + int id = tableModel->index(i,0).data().toInt(); + questionSql->set_data(id,"orderNum",i * gap); + } + ui->tableView->setSortingEnabled(true); + ui->tableView->sortByColumn(21,Qt::AscendingOrder); } ui->tableView->clearSelection(); clear_question_display(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 6d87f2e..7c21ed0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,6 +6,7 @@ MainWindow::MainWindow(QWidget *parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + currentDate = QDate::currentDate(); questionSql = new QuestionSql("question.db",this); //init questionTableView @@ -116,6 +117,23 @@ void MainWindow::reload_categoryTreeView() ui->categoryTreeView->hideColumn(1); } +void MainWindow::update_count_categoryTreeView() +{ + QSqlQuery query(QSqlDatabase::database("connection1")); + query.prepare("SELECT * FROM categories"); + query.exec(); + while(query.next()) + { + int id = query.value(0).toInt(); + if(id == 0) + continue; + int qCount = questionSql->count_total_questions(id); + int qtoLearnCount = questionSql->count_total_questions_to_learn(id); + categoryItemLists[id][2]->setText(QString::number(qtoLearnCount)); + categoryItemLists[id][3]->setText(QString::number(qCount)); + } +} + bool MainWindow::eventFilter(QObject *watched, QEvent *event) { if (watched == ui->questionTableView) { @@ -151,7 +169,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) void MainWindow::get_categoryItemTree(QStandardItem* parent,int parentId) { QSqlQuery query(QSqlDatabase::database("connection1")); - query.prepare("SELECT * FROM categories WHERE parentId = ?"); + query.prepare("SELECT * FROM categories WHERE parentId = ? ORDER BY name"); query.bindValue(0,parentId); query.exec(); while(query.next()) @@ -212,6 +230,12 @@ void MainWindow::on_categoryDelButton_clicked() void MainWindow::on_categoryTreeView_clicked(const QModelIndex &index) { + if(currentDate != QDate::currentDate()) + { + update_count_categoryTreeView(); + currentDate = QDate::currentDate(); + } + int categoryId = index.siblingAtColumn(1).data().toInt(); QString condString = questionSql->get_category_condString(categoryId); questionTableModel->setFilter(condString); @@ -709,4 +733,3 @@ void MainWindow::on_htmlImgAddButton_clicked() } } - diff --git a/mainwindow.h b/mainwindow.h index fdebd49..97d8510 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -40,6 +40,7 @@ class MainWindow : public QMainWindow void save_answerList(int id); void set_tableHeader(); void select_question_by_id(int id); + void update_count_categoryTreeView(); protected: bool eventFilter(QObject *watched, QEvent *event); @@ -106,5 +107,6 @@ private slots: HtmlTableAddDialog *htmlTableAddDialog; QuestionTagEditDialog *questionTagEditDialog; + QDate currentDate; }; #endif // MAINWINDOW_H