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