Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Nartsam authored Mar 18, 2023
1 parent 95aef70 commit ac3c6ee
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 207 deletions.
4 changes: 3 additions & 1 deletion MistakeCopy.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ HEADERS += \
codec.h \
globalsignal.h \
mainwindow.h \
message.h \
mlog.h \
mtextedit.h \
question.h \
Expand All @@ -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
2 changes: 1 addition & 1 deletion MistakeCopy.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 9.0.2, 2023-03-16T21:09:22. -->
<!-- Written by QtCreator 9.0.2, 2023-03-17T22:52:44. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
6 changes: 5 additions & 1 deletion adddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include<QFile>
#include<QFileInfo>
#include<QMimeData>
#include<QMessageBox>
#include<QImageReader>
#include"globalsignal.h"
#include"codec.h"
AddDialog::AddDialog(QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -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,"错误","输入不合法, 添加失败");
}
}
1 change: 0 additions & 1 deletion adddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Ui {
class AddDialog;
}

class AddDialog : public QDialog
{
Q_OBJECT
Expand Down
3 changes: 1 addition & 2 deletions globalsignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
GlobalSignal GS;

GlobalSignal::GlobalSignal(QObject *parent)
: QObject{parent}
{
: QObject{parent}{

}
15 changes: 5 additions & 10 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
54 changes: 52 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,11 +23,27 @@ void MainWindow::button_bonding(){
MainWindow::~MainWindow(){
delete ui;
}
inline bool tags_pair_cmp(const std::pair<QString,int> &a,const std::pair<QString,int> &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<std::pair<QString,int> > 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;i<length;i++){
tags_button[i]->setText(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();
Expand All @@ -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);}
10 changes: 10 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
87 changes: 79 additions & 8 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,39 @@
<x>0</x>
<y>0</y>
<width>344</width>
<height>462</height>
<height>460</height>
</rect>
</property>
<property name="font">
<font>
<family>Microsoft YaHei UI</family>
<pointsize>8</pointsize>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLineEdit" name="search_lineEdit">
<property name="geometry">
<rect>
<x>50</x>
<x>20</x>
<y>20</y>
<width>221</width>
<height>31</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QLineEdit{border:2px groove gray;border-radius:10px;padding:2px 4px;border-style: outset;}</string>
</property>
</widget>
<widget class="QLineEdit" name="tags_lineEdit">
<property name="geometry">
Expand All @@ -33,6 +50,9 @@
<height>31</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QLineEdit { border:2px groove gray;border-radius:10px;padding:2px 4px;border-style: outset; }</string>
</property>
</widget>
<widget class="QPushButton" name="add_pushButton">
<property name="geometry">
Expand All @@ -46,9 +66,9 @@
<property name="font">
<font>
<family>Microsoft YaHei UI</family>
<pointsize>12</pointsize>
<pointsize>8</pointsize>
<italic>false</italic>
<bold>true</bold>
<bold>false</bold>
</font>
</property>
<property name="text">
Expand Down Expand Up @@ -136,16 +156,67 @@
<widget class="QPushButton" name="view_all_pushButton">
<property name="geometry">
<rect>
<x>110</x>
<y>390</y>
<width>93</width>
<height>28</height>
<x>50</x>
<y>377</y>
<width>211</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<family>Microsoft YaHei UI</family>
<pointsize>-1</pointsize>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">QPushButton{ background-color:rgb(225,225,225); border:2px groove gray;border-radius:10px;padding:2px 4px;border-style: outset;font-family: &quot;Microsoft YaHei UI&quot;;font-size: 14px;}
QPushButton:hover{background-color:rgb(229, 241, 251); color: black;}
QPushButton:pressed{background-color:rgb(204, 228, 247);border-style: inset;}</string>
</property>
<property name="text">
<string>浏览所有题目</string>
</property>
</widget>
<widget class="QPushButton" name="str_search_pushButton">
<property name="geometry">
<rect>
<x>280</x>
<y>20</y>
<width>30</width>
<height>30</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">border-style:none;
background:transparent;
border-image: url(:/D:/Nartsam/Pictures/icon/search.png)
</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QPushButton" name="tags_search_pushButton">
<property name="geometry">
<rect>
<x>280</x>
<y>160</y>
<width>30</width>
<height>30</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">border-style:none;
background:transparent;
border-image: url(:/D:/Nartsam/Pictures/icon/search.png);
</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
Expand Down
3 changes: 3 additions & 0 deletions question.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include"question.h"
#include<QDir>
#include<vector>
#include<map>
#include"codec.h"
std::vector<Question> QuestionList;
std::map<QString,int> TagsMap;
void Question::clear(){
text.clear(); correction.clear(); answer.clear();
notes.clear(); tags.clear();
Expand Down
3 changes: 1 addition & 2 deletions question.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include<QString>
#include<QDate>
#include<vector>
class Question{
private:
QString text; //题目内容
Expand Down Expand Up @@ -36,7 +35,7 @@ class Question{
};
//All Questions stored here
extern std::vector<Question> QuestionList;

extern std::map<QString,int> TagsMap;
#define DataDir "data\\"
extern QString SptorStr; //Separator in file
void WriteQuestionListToDir();
Expand Down
7 changes: 7 additions & 0 deletions resource.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/">
<file>D:/Nartsam/Pictures/icon/filled-trash.png</file>
<file>D:/Nartsam/Pictures/icon/share-3.png</file>
<file>D:/Nartsam/Pictures/icon/search.png</file>
</qresource>
</RCC>
Loading

0 comments on commit ac3c6ee

Please sign in to comment.