mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
fixed a bug with edit & saving an mdem
This commit is contained in:
@@ -86,7 +86,7 @@ struct Page {
|
|||||||
|
|
||||||
// @Debug: set the default directory for convenience. It should be configured by user
|
// @Debug: set the default directory for convenience. It should be configured by user
|
||||||
// or set to "".
|
// or set to "".
|
||||||
std::string currentPath = "/home/jorenchik/Code/mdemory/memorybase";
|
std::string currentPath = "/home/jorenchik/Code/mdemory/memorybase/";
|
||||||
std::string currentMdem = "";
|
std::string currentMdem = "";
|
||||||
/*std::string currentPath = "";*/
|
/*std::string currentPath = "";*/
|
||||||
QFileSystemModel *model;
|
QFileSystemModel *model;
|
||||||
@@ -97,6 +97,7 @@ QTreeView *mdemList;
|
|||||||
QLabel *deckListLabel;
|
QLabel *deckListLabel;
|
||||||
QVBoxLayout *hMdemScroll;
|
QVBoxLayout *hMdemScroll;
|
||||||
QList<Mdem*> mdems = QList<Mdem*>();
|
QList<Mdem*> mdems = QList<Mdem*>();
|
||||||
|
time_t trainedAt = 0;
|
||||||
std::vector<Question*> questions = std::vector<Question*>();
|
std::vector<Question*> questions = std::vector<Question*>();
|
||||||
QSpacerItem *mdemSpacer;
|
QSpacerItem *mdemSpacer;
|
||||||
std::vector<ErrorView*> errorPool;
|
std::vector<ErrorView*> errorPool;
|
||||||
@@ -140,8 +141,17 @@ void showBacklabels(Mdem *mdem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string outputMdem(std::vector<Question*> questions) {
|
std::string outputMdem(std::vector<Question*> questions, time_t time = 0) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
if (time > 0) {
|
||||||
|
std::tm* tm = std::localtime(&time);
|
||||||
|
char buffer[100];
|
||||||
|
std::strftime(buffer, sizeof(buffer), "%d.%m.%Y %H\\:%M", tm);
|
||||||
|
auto time = std::string(buffer);
|
||||||
|
ss << time << std::endl << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto question: questions) {
|
for (auto question: questions) {
|
||||||
std::string cooldownPart;
|
std::string cooldownPart;
|
||||||
if (question->Cooldown != 0) {
|
if (question->Cooldown != 0) {
|
||||||
@@ -571,13 +581,14 @@ void reloadMdem() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (res.error == "") {
|
if (res.error == "") {
|
||||||
time_t trainedAt;
|
|
||||||
if (res.value.lastTrainedAt == 0) {
|
if (res.value.lastTrainedAt == 0) {
|
||||||
trainedAt = 0;
|
trainedAt = 0;
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: time_zone option
|
||||||
trainedAt = res.value.lastTrainedAt + 3600 * 2;
|
trainedAt = res.value.lastTrainedAt + 3600 * 2;
|
||||||
}
|
}
|
||||||
std::cout << std::format("Last trained at: {}", trainedAt) << std::endl;
|
std::cout << std::format("Last trained at: {}", trainedAt) << std::endl;
|
||||||
|
|
||||||
questions = res.value.questions;
|
questions = res.value.questions;
|
||||||
makePages();
|
makePages();
|
||||||
SwitchPage(0);
|
SwitchPage(0);
|
||||||
@@ -647,8 +658,19 @@ void setupEditorSave(bool checked) {
|
|||||||
"There are no questions in your input."
|
"There are no questions in your input."
|
||||||
);
|
);
|
||||||
} else if (res.value.questions.size() == 1) {
|
} else if (res.value.questions.size() == 1) {
|
||||||
setupMdem(editMdem, res.value.questions[0]);
|
auto oldQuestion = editMdem->question;
|
||||||
showBacklabels(editMdem);
|
editMdem->question = res.value.questions[0];
|
||||||
|
for (int i = 0; i < questions.size(); ++i) {
|
||||||
|
if (questions[i] == oldQuestion) {
|
||||||
|
questions.erase(questions.begin() + i);
|
||||||
|
delete questions[i];
|
||||||
|
questions[i] = editMdem->question;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*setupMdem(editMdem, res.value.questions[0]);*/
|
||||||
|
/*showBacklabels(editMdem);*/
|
||||||
|
editorWindow->hide();
|
||||||
} else {
|
} else {
|
||||||
QMessageBox::information(
|
QMessageBox::information(
|
||||||
nullptr,
|
nullptr,
|
||||||
@@ -671,6 +693,7 @@ void setupEditorSave(bool checked) {
|
|||||||
);
|
);
|
||||||
makePages();
|
makePages();
|
||||||
SwitchPage(0);
|
SwitchPage(0);
|
||||||
|
editorWindow->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -814,12 +837,13 @@ int main(int argc, char *argv[]) {
|
|||||||
QObject::connect(add, &QToolButton::clicked, []() {
|
QObject::connect(add, &QToolButton::clicked, []() {
|
||||||
editMdem = nullptr;
|
editMdem = nullptr;
|
||||||
editorWindow->show();
|
editorWindow->show();
|
||||||
|
editor->setText("");
|
||||||
});
|
});
|
||||||
QObject::connect(load, &QToolButton::clicked, &reloadMdem);
|
QObject::connect(load, &QToolButton::clicked, &reloadMdem);
|
||||||
QObject::connect(save, &QToolButton::clicked, []() {
|
QObject::connect(save, &QToolButton::clicked, []() {
|
||||||
auto filename = getFilename(currentMdem);
|
auto filename = getFilename(currentMdem);
|
||||||
std::ofstream out("generated.mdem");
|
std::ofstream out(currentMdem);
|
||||||
out << outputMdem(questions);;
|
out << outputMdem(questions, trainedAt);
|
||||||
});
|
});
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
practice,
|
practice,
|
||||||
|
|||||||
Reference in New Issue
Block a user