mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
chooser for the algorithm
This commit is contained in:
@@ -6,5 +6,12 @@
|
|||||||
|
|
||||||
extern QMainWindow *trainWindow;
|
extern QMainWindow *trainWindow;
|
||||||
|
|
||||||
|
enum PracticeAlgorithm {
|
||||||
|
PRIMARY,
|
||||||
|
RANDOM,
|
||||||
|
SPACED,
|
||||||
|
};
|
||||||
|
|
||||||
void initTrainWindow();
|
void initTrainWindow();
|
||||||
void setQuestions(std::vector<Question*> questions);
|
void setQuestions(std::vector<Question*> questions, PracticeAlgorithm algorithm);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <qabstractbutton.h>
|
#include <qabstractbutton.h>
|
||||||
#include <qboxlayout.h>
|
#include <qboxlayout.h>
|
||||||
|
#include <qcombobox.h>
|
||||||
#include <qdialog.h>
|
#include <qdialog.h>
|
||||||
#include <qlabel.h>
|
#include <qlabel.h>
|
||||||
#include <qlayoutitem.h>
|
#include <qlayoutitem.h>
|
||||||
@@ -597,8 +598,8 @@ void reloadMdem() {
|
|||||||
if (res.value.lastTrainedAt == 0) {
|
if (res.value.lastTrainedAt == 0) {
|
||||||
trainedAt = 0;
|
trainedAt = 0;
|
||||||
} else {
|
} else {
|
||||||
// TODO: time_zone option
|
auto timezoneOffset = settings->value("timezone").toInt();
|
||||||
trainedAt = res.value.lastTrainedAt + 3600 * 2;
|
trainedAt = res.value.lastTrainedAt + 3600 * timezoneOffset;
|
||||||
}
|
}
|
||||||
std::cout << std::format("Last trained at: {}", trainedAt) << std::endl;
|
std::cout << std::format("Last trained at: {}", trainedAt) << std::endl;
|
||||||
|
|
||||||
@@ -608,6 +609,10 @@ void reloadMdem() {
|
|||||||
} else {
|
} else {
|
||||||
std::cout << std::format("Compilation error: {}", res.error) << std::endl;
|
std::cout << std::format("Compilation error: {}", res.error) << std::endl;
|
||||||
|
|
||||||
|
for (auto question: res.value.questions) {
|
||||||
|
delete question;
|
||||||
|
}
|
||||||
|
|
||||||
// Show errors.
|
// Show errors.
|
||||||
hMdemScroll->removeItem(mdemSpacer);
|
hMdemScroll->removeItem(mdemSpacer);
|
||||||
auto errorView = acquireError();
|
auto errorView = acquireError();
|
||||||
@@ -657,6 +662,9 @@ void pickDirectory(QString directory) {
|
|||||||
void setupEditorSave(bool checked) {
|
void setupEditorSave(bool checked) {
|
||||||
auto res = transpile(editor->text().toStdString(), true);
|
auto res = transpile(editor->text().toStdString(), true);
|
||||||
if (res.error.length() > 0) {
|
if (res.error.length() > 0) {
|
||||||
|
for (auto question: res.value.questions) {
|
||||||
|
delete question;
|
||||||
|
}
|
||||||
QMessageBox::information(
|
QMessageBox::information(
|
||||||
nullptr,
|
nullptr,
|
||||||
"Editing error",
|
"Editing error",
|
||||||
@@ -906,20 +914,22 @@ int main(int argc, char *argv[]) {
|
|||||||
add = new QToolButton;
|
add = new QToolButton;
|
||||||
save = new QToolButton;
|
save = new QToolButton;
|
||||||
load = new QToolButton;
|
load = new QToolButton;
|
||||||
|
auto cbAlgorithm = new QComboBox;
|
||||||
practice = new QToolButton;
|
practice = new QToolButton;
|
||||||
|
|
||||||
hTop->addWidget(add);
|
hTop->addWidget(add);
|
||||||
hTop->addWidget(save);
|
hTop->addWidget(save);
|
||||||
hTop->addWidget(load);
|
hTop->addWidget(load);
|
||||||
|
hTop->addWidget(cbAlgorithm);
|
||||||
hTop->addWidget(practice);
|
hTop->addWidget(practice);
|
||||||
QObject::connect(add, &QToolButton::clicked, []() {
|
|
||||||
// MARK1
|
|
||||||
});
|
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
add->setText("Add");
|
add->setText("Add");
|
||||||
save->setText("Save");
|
save->setText("Save");
|
||||||
load->setText("Load");
|
load->setText("Load");
|
||||||
|
cbAlgorithm->addItem("Primary", PRIMARY);
|
||||||
|
cbAlgorithm->addItem("Random", RANDOM);
|
||||||
|
cbAlgorithm->addItem("Spaced", SPACED);
|
||||||
practice->setText("Practice");
|
practice->setText("Practice");
|
||||||
|
|
||||||
QObject::connect(add, &QToolButton::clicked, []() {
|
QObject::connect(add, &QToolButton::clicked, []() {
|
||||||
@@ -936,10 +946,13 @@ int main(int argc, char *argv[]) {
|
|||||||
QObject::connect(
|
QObject::connect(
|
||||||
practice,
|
practice,
|
||||||
&QToolButton::clicked,
|
&QToolButton::clicked,
|
||||||
[](bool checked) {
|
[cbAlgorithm](bool checked) {
|
||||||
trainWindow->show();
|
trainWindow->show();
|
||||||
trainWindow->resize(600, 300);
|
trainWindow->resize(600, 300);
|
||||||
setQuestions(questions);
|
setQuestions(
|
||||||
|
questions,
|
||||||
|
static_cast<PracticeAlgorithm>(cbAlgorithm->currentData().toInt())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -235,12 +235,7 @@ std::vector<GroupView*> groupViews;
|
|||||||
std::default_random_engine rng;
|
std::default_random_engine rng;
|
||||||
std::vector<QStandardItem*> itemPool;
|
std::vector<QStandardItem*> itemPool;
|
||||||
|
|
||||||
/*QStandardItem *makeItem(std::string content, bool isCheckable) {*/
|
PracticeAlgorithm practiceAlgoritm;
|
||||||
/* auto *item = new QStandardItem(); */
|
|
||||||
/* item->setText(QString::fromStdString(content));*/
|
|
||||||
/* item->setCheckable(isCheckable);*/
|
|
||||||
/* return item;*/
|
|
||||||
/*};*/
|
|
||||||
|
|
||||||
#define ITEM_POOL_CHUNK 200
|
#define ITEM_POOL_CHUNK 200
|
||||||
|
|
||||||
@@ -422,7 +417,6 @@ void setupGroupQuestion(GroupQuestion *question) {
|
|||||||
groupView->itemList.setModel(&groupView->itemModel);
|
groupView->itemList.setModel(&groupView->itemModel);
|
||||||
groupView->itemList.setMaximumHeight(100);
|
groupView->itemList.setMaximumHeight(100);
|
||||||
groupView->itemList.setItemDelegate(itemDelegate);
|
groupView->itemList.setItemDelegate(itemDelegate);
|
||||||
/*groupView->itemScroll.setWidget(&groupView->itemScroll);*/
|
|
||||||
groupView->widget.setLayout(&groupView->vWidget);
|
groupView->widget.setLayout(&groupView->vWidget);
|
||||||
groupView->widget.layout()->addWidget(&groupView->label);
|
groupView->widget.layout()->addWidget(&groupView->label);
|
||||||
groupView->widget.layout()->addWidget(&groupView->itemList);
|
groupView->widget.layout()->addWidget(&groupView->itemList);
|
||||||
@@ -517,7 +511,7 @@ void updatePaginationVisibility() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setQuestions(std::vector<Question*> questions) {
|
void setQuestions(std::vector<Question*> questions, PracticeAlgorithm algorithm) {
|
||||||
trainQuestions = questions;
|
trainQuestions = questions;
|
||||||
if (questions.size() <= 0) {
|
if (questions.size() <= 0) {
|
||||||
return;
|
return;
|
||||||
@@ -525,6 +519,7 @@ void setQuestions(std::vector<Question*> questions) {
|
|||||||
currentQuestionIndex = 0;
|
currentQuestionIndex = 0;
|
||||||
updatePaginationVisibility();
|
updatePaginationVisibility();
|
||||||
setupQuestion(trainQuestions[currentQuestionIndex]);
|
setupQuestion(trainQuestions[currentQuestionIndex]);
|
||||||
|
practiceAlgoritm = algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initTrainWindow() {
|
void initTrainWindow() {
|
||||||
@@ -642,11 +637,21 @@ void initTrainWindow() {
|
|||||||
|
|
||||||
btnNext->setText("Next");
|
btnNext->setText("Next");
|
||||||
QObject::connect(btnNext, &QToolButton::clicked, []() {
|
QObject::connect(btnNext, &QToolButton::clicked, []() {
|
||||||
|
switch (practiceAlgoritm) {
|
||||||
|
case PRIMARY:
|
||||||
currentQuestionIndex++;
|
currentQuestionIndex++;
|
||||||
if (currentQuestionIndex < trainQuestions.size()) {
|
if (currentQuestionIndex < trainQuestions.size()) {
|
||||||
setupQuestion(trainQuestions[currentQuestionIndex]);
|
setupQuestion(trainQuestions[currentQuestionIndex]);
|
||||||
}
|
}
|
||||||
updatePaginationVisibility();
|
updatePaginationVisibility();
|
||||||
|
break;
|
||||||
|
case RANDOM:
|
||||||
|
// TODO: implement
|
||||||
|
break;
|
||||||
|
case SPACED:
|
||||||
|
// TODO: implement
|
||||||
|
break;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
questionBox->setObjectName("question-box");
|
questionBox->setObjectName("question-box");
|
||||||
actionButtons->setStyleSheet(QString(
|
actionButtons->setStyleSheet(QString(
|
||||||
|
|||||||
Reference in New Issue
Block a user