diff --git a/MistakeCopy.pro b/MistakeCopy.pro index 3df8446..1cd5660 100644 --- a/MistakeCopy.pro +++ b/MistakeCopy.pro @@ -23,7 +23,6 @@ HEADERS += \ codec.h \ globalsignal.h \ mainwindow.h \ - message.h \ mlog.h \ mtextedit.h \ question.h \ @@ -38,3 +37,6 @@ FORMS += \ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + resource.qrc diff --git a/MistakeCopy.pro.user b/MistakeCopy.pro.user index ee7672c..d061ed9 100644 --- a/MistakeCopy.pro.user +++ b/MistakeCopy.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/adddialog.cpp b/adddialog.cpp index 022b540..8ea99c6 100644 --- a/adddialog.cpp +++ b/adddialog.cpp @@ -3,7 +3,9 @@ #include #include #include +#include #include +#include"globalsignal.h" #include"codec.h" AddDialog::AddDialog(QWidget *parent) : QDialog(parent), @@ -64,8 +66,10 @@ void AddDialog::on_buttonBox_accepted(){ //check & save Question this->input.set_tags_by_string(ui->lineEdit->text()); if(CheckQuestionValidity(this->input)||1){ //debug QuestionList.push_back(this->input); + emit GS.AddSignal(); + QMessageBox::information(this,"提示","添加成功"); } else{ - + QMessageBox::critical(this,"错误","输入不合法, 添加失败"); } } diff --git a/adddialog.h b/adddialog.h index 07bf6e2..bc2d482 100644 --- a/adddialog.h +++ b/adddialog.h @@ -8,7 +8,6 @@ namespace Ui { class AddDialog; } - class AddDialog : public QDialog { Q_OBJECT diff --git a/globalsignal.cpp b/globalsignal.cpp index a2cd018..720c6f9 100644 --- a/globalsignal.cpp +++ b/globalsignal.cpp @@ -3,7 +3,6 @@ GlobalSignal GS; GlobalSignal::GlobalSignal(QObject *parent) - : QObject{parent} -{ + : QObject{parent}{ } diff --git a/main.cpp b/main.cpp index 25c1b2f..e33d3e3 100644 --- a/main.cpp +++ b/main.cpp @@ -4,15 +4,10 @@ int main(int argc, char *argv[]){ qputenv("QT_SCALE_FACTOR","1.0"); QApplication a(argc, argv); - int return_value=0; - try{ - ReadQuestionListFromDir(); - MainWindow w; - w.show(); - return_value=a.exec(); - WriteQuestionListToDir(); - }catch(const char *str){ - - } + ReadQuestionListFromDir(); + MainWindow w; + w.show(); + int return_value=a.exec(); + WriteQuestionListToDir(); return return_value; } diff --git a/mainwindow.cpp b/mainwindow.cpp index d5a5d71..921f0a0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,9 +7,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow){ ui->setupUi(this); + setWindowTitle("电子错题本"); + setWindowFlags(windowFlags()&~Qt::WindowMaximizeButtonHint); + setFixedSize(this->size()); button_bonding(); connect(&GS,&GlobalSignal::DeleteSignal,this,&::MainWindow::DeleteEvent); connect(&GS,&GlobalSignal::AddSignal,this,&::MainWindow::AddEvent); + setup_tags_index(); } void MainWindow::button_bonding(){ tags_button[0]=ui->pushButton_1; tags_button[1]=ui->pushButton_2; @@ -19,11 +23,27 @@ void MainWindow::button_bonding(){ MainWindow::~MainWindow(){ delete ui; } +inline bool tags_pair_cmp(const std::pair &a,const std::pair &b){ + return a.second>b.second; +} +void MainWindow::setup_tags_index(){ + TagsMap.clear(); + for(const Question &q:QuestionList){ + QStringList tags=q.get_tags(); + for(const auto &i:tags) ++TagsMap[i]; + } + std::vector > v(TagsMap.begin(),TagsMap.end()); + std::sort(v.begin(),v.end(),tags_pair_cmp); + int length=std::min(6,(int)v.size()); + for(int i=0;isetText(v[i].first); tags_button[i]->setVisible(true); + } + while(length<6) tags_button[length++]->setVisible(false); +} void MainWindow::AddEvent(){ - } void MainWindow::DeleteEvent(int index){ - + QuestionList.erase(QuestionList.begin()+index); } void MainWindow::on_add_pushButton_clicked(){ AddDialog *ad=new AddDialog(); @@ -35,3 +55,33 @@ void MainWindow::on_view_all_pushButton_clicked(){ view->get_result(); view->show(); } +void MainWindow::on_str_search_pushButton_clicked(){ + ViewDialog *view=new ViewDialog(); + view->setWindowTitle("按内容搜索"); + view->get_result(ui->search_lineEdit->text().trimmed()); + view->show(); +} +void MainWindow::on_tags_search_pushButton_clicked(){ + QStringList spt=ui->tags_lineEdit->text().split(";"); + QStringList ref; + for(const QString &i:spt){ + if(!i.trimmed().isEmpty()) ref.push_back(i.trimmed()); + } + ViewDialog *view=new ViewDialog(); + view->setWindowTitle("按标签搜索"); + view->get_result(ref); + view->show(); +} +void MainWindow::on_tags_button_clicked(int pos)const{ + --pos; + ViewDialog *view=new ViewDialog(); + view->setWindowTitle("按标签查看"); + view->get_result(QStringList(tags_button[pos]->text())); + view->show(); +} +void MainWindow::on_pushButton_1_clicked(){on_tags_button_clicked(1);} +void MainWindow::on_pushButton_2_clicked(){on_tags_button_clicked(2);} +void MainWindow::on_pushButton_3_clicked(){on_tags_button_clicked(3);} +void MainWindow::on_pushButton_4_clicked(){on_tags_button_clicked(4);} +void MainWindow::on_pushButton_5_clicked(){on_tags_button_clicked(5);} +void MainWindow::on_pushButton_6_clicked(){on_tags_button_clicked(6);} diff --git a/mainwindow.h b/mainwindow.h index 9c1e85b..f02c276 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -13,12 +13,22 @@ class MainWindow : public QMainWindow{ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); + void setup_tags_index(); + void on_tags_button_clicked(int pos)const; private slots: void AddEvent(); void DeleteEvent(int index); void on_add_pushButton_clicked(); void on_view_all_pushButton_clicked(); + void on_str_search_pushButton_clicked(); + void on_tags_search_pushButton_clicked(); + void on_pushButton_1_clicked(); + void on_pushButton_2_clicked(); + void on_pushButton_3_clicked(); + void on_pushButton_4_clicked(); + void on_pushButton_5_clicked(); + void on_pushButton_6_clicked(); private: Ui::MainWindow *ui; diff --git a/mainwindow.ui b/mainwindow.ui index 25bb837..be2ab2c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,22 +7,39 @@ 0 0 344 - 462 + 460 + + + Microsoft YaHei UI + 8 + false + false + + MainWindow + + false + + + + - 50 + 20 20 221 31 + + QLineEdit{border:2px groove gray;border-radius:10px;padding:2px 4px;border-style: outset;} + @@ -33,6 +50,9 @@ 31 + + QLineEdit { border:2px groove gray;border-radius:10px;padding:2px 4px;border-style: outset; } + @@ -46,9 +66,9 @@ Microsoft YaHei UI - 12 + 8 false - true + false @@ -136,16 +156,67 @@ - 110 - 390 - 93 - 28 + 50 + 377 + 211 + 41 + + + Microsoft YaHei UI + -1 + false + false + + + + QPushButton{ background-color:rgb(225,225,225); border:2px groove gray;border-radius:10px;padding:2px 4px;border-style: outset;font-family: "Microsoft YaHei UI";font-size: 14px;} +QPushButton:hover{background-color:rgb(229, 241, 251); color: black;} +QPushButton:pressed{background-color:rgb(204, 228, 247);border-style: inset;} + 浏览所有题目 + + + + 280 + 20 + 30 + 30 + + + + border-style:none; +background:transparent; +border-image: url(:/D:/Nartsam/Pictures/icon/search.png) + + + + + + + + + + 280 + 160 + 30 + 30 + + + + border-style:none; +background:transparent; +border-image: url(:/D:/Nartsam/Pictures/icon/search.png); + + + + + + diff --git a/question.cpp b/question.cpp index 1371977..eaf99fe 100644 --- a/question.cpp +++ b/question.cpp @@ -1,7 +1,10 @@ #include"question.h" #include +#include +#include #include"codec.h" std::vector QuestionList; +std::map TagsMap; void Question::clear(){ text.clear(); correction.clear(); answer.clear(); notes.clear(); tags.clear(); diff --git a/question.h b/question.h index 3d4ff6e..a45d65b 100644 --- a/question.h +++ b/question.h @@ -3,7 +3,6 @@ #include #include -#include class Question{ private: QString text; //题目内容 @@ -36,7 +35,7 @@ class Question{ }; //All Questions stored here extern std::vector QuestionList; - +extern std::map TagsMap; #define DataDir "data\\" extern QString SptorStr; //Separator in file void WriteQuestionListToDir(); diff --git a/resource.qrc b/resource.qrc new file mode 100644 index 0000000..470c26f --- /dev/null +++ b/resource.qrc @@ -0,0 +1,7 @@ + + + D:/Nartsam/Pictures/icon/filled-trash.png + D:/Nartsam/Pictures/icon/share-3.png + D:/Nartsam/Pictures/icon/search.png + + diff --git a/viewdialog.cpp b/viewdialog.cpp index 64bf1f2..657b001 100644 --- a/viewdialog.cpp +++ b/viewdialog.cpp @@ -1,5 +1,7 @@ #include"viewdialog.h" #include"ui_viewdialog.h" +#include +#include #include"globalsignal.h" #include"codec.h" ViewDialog::ViewDialog(QWidget *parent) : @@ -8,6 +10,7 @@ ViewDialog::ViewDialog(QWidget *parent) : ui->setupUi(this); view_index.clear(); current_page=0; + ui->page_lineEdit->setValidator(new QIntValidator(ui->page_lineEdit)); connect(&GS,&GlobalSignal::DeleteSignal,this,&::ViewDialog::DeleteEvent); connect(&GS,&GlobalSignal::AddSignal,this,&::ViewDialog::AddEvent); } @@ -30,14 +33,23 @@ void ViewDialog::get_result(const Question &q){ } void ViewDialog::refresh(){ if(!view_index.empty()){ + ui->page_lineEdit->setReadOnly(false); ui->page_lineEdit->setText(QString::number(current_page+1)); ui->first_page_label->setText("1"); ui->last_page_label->setText(QString::number(view_index.size())); ui->textBrowser->setHtml(QuestionList[view_index[current_page]].to_html()); + ui->delete_pushButton->setEnabled(true); + ui->getsim_pushButton->setEnabled(true); } else{ - + ui->page_lineEdit->clear(); ui->page_lineEdit->setReadOnly(true); + ui->delete_pushButton->setEnabled(false); + ui->getsim_pushButton->setEnabled(false); } + if(current_page>0) ui->prev_pushButton->setEnabled(true); + else ui->prev_pushButton->setEnabled(false); + if(current_page<(int)view_index.size()-1) ui->next_pushButton->setEnabled(true); + else ui->next_pushButton->setEnabled(false); } void ViewDialog::DeleteEvent(int index){ for(int i=0;i<(int)view_index.size();i++){ @@ -48,20 +60,23 @@ void ViewDialog::DeleteEvent(int index){ } if(current_page<0) current_page=0; if(current_page>=(int)view_index.size()) current_page=view_index.size()-1; - + refresh(); } void ViewDialog::AddEvent(){ - + if(this->windowTitle()==QString("查看所有题目")){ + view_index.push_back(view_index.size()); + } + refresh(); } void ViewDialog::on_prev_pushButton_clicked(){ current_page--; if(current_page<0) current_page=0; - else refresh(); + refresh(); } void ViewDialog::on_next_pushButton_clicked(){ current_page++; if(current_page>=(int)view_index.size()) current_page=view_index.size()-1; - else refresh(); + refresh(); } void ViewDialog::on_getsim_pushButton_clicked(){ ViewDialog *chd_dia=new ViewDialog(); @@ -70,5 +85,8 @@ void ViewDialog::on_getsim_pushButton_clicked(){ chd_dia->show(); } void ViewDialog::on_delete_pushButton_clicked(){ - + QMessageBox::StandardButton res=QMessageBox::question(this,"提示","永久删除该题目, 确定吗?"); + if(res==QMessageBox::No) return; + emit GS.DeleteSignal(view_index[current_page]); + QMessageBox::information(this,"提示","删除完成"); } diff --git a/viewdialog.ui b/viewdialog.ui index 61813f0..0306962 100644 --- a/viewdialog.ui +++ b/viewdialog.ui @@ -6,184 +6,201 @@ 0 0 - 684 - 445 + 719 + 455 Dialog - - - - 25 - 61 - 631 - 331 - - - - - - - 30 - 400 - 81 - 31 - - - - - Microsoft YaHei UI - 8 - false - false - - - - 删除 - - - - - - 550 - 400 - 101 - 31 - - - - - Microsoft YaHei UI - 8 - false - false - - - - 相似题目 - - - - - - 30 - 20 - 351 - 31 - - - - - Microsoft YaHei UI - 8 - false - false - - - - 正在查看: - - - - - - 300 - 400 - 41 - 31 - - - - - Microsoft YaHei UI - 11 - false - false - - - - - - - Qt::AlignCenter - - - - - - 260 - 400 - 41 - 31 - - - - - Microsoft YaHei UI - 11 - false - false - - - - 1 - - - Qt::AlignCenter - - - - - - 340 - 400 - 41 - 31 - - - - - Microsoft YaHei UI - 11 - false - false - - - - 1 - - - Qt::AlignCenter - - - - - - 140 - 400 - 93 - 28 - - - - 上一页 - - - - - - 400 - 400 - 93 - 28 - - - - 下一页 - - + + + + + + + + Microsoft YaHei UI + 10 + false + false + + + + 删除 + + + + + + + + Microsoft YaHei UI + 10 + false + false + + + + 下一页 + + + + + + + + Microsoft YaHei UI + 10 + false + false + + + + 上一页 + + + + + + + + Microsoft YaHei UI + 10 + false + false + + + + 相似题目 + + + + + + + + 30 + 0 + + + + + Microsoft YaHei UI + 12 + false + false + + + + 0 + + + Qt::AlignCenter + + + + + + + + 30 + 0 + + + + + Microsoft YaHei UI + 12 + false + false + + + + 0 + + + Qt::AlignCenter + + + + + + + + 70 + 16777215 + + + + + Microsoft YaHei UI + 12 + false + false + + + + false + + + + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Microsoft YaHei UI + 14 + false + false + + + + 正在查看: + + + Qt::AlignCenter + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + +