mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
functions in camelcase
This commit is contained in:
@@ -8,17 +8,17 @@
|
||||
|
||||
|
||||
struct Question {
|
||||
double Cooldown;
|
||||
std::string QuestionText;
|
||||
std::string Section;
|
||||
double cooldown;
|
||||
std::string questionText;
|
||||
std::string section;
|
||||
|
||||
virtual std::string ToString() const = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
virtual ~Question() = default;
|
||||
};
|
||||
|
||||
struct Choice {
|
||||
std::string Answer;
|
||||
bool IsCorrect;
|
||||
std::string answer;
|
||||
bool isCorrect;
|
||||
};
|
||||
|
||||
enum MultiElementType {
|
||||
@@ -28,10 +28,10 @@ enum MultiElementType {
|
||||
};
|
||||
|
||||
struct MultiElementQuestion : public Question {
|
||||
std::vector<Choice> Choices;
|
||||
std::vector<Choice> choices;
|
||||
MultiElementType type;
|
||||
|
||||
std::string ToString() const override;
|
||||
std::string toString() const override;
|
||||
};
|
||||
|
||||
struct Group {
|
||||
@@ -40,9 +40,9 @@ struct Group {
|
||||
};
|
||||
|
||||
struct GroupQuestion : public Question {
|
||||
std::vector<Group> Groups;
|
||||
std::vector<Group> groups;
|
||||
|
||||
std::string ToString() const override;
|
||||
std::string toString() const override;
|
||||
};
|
||||
|
||||
struct ParseInfo {
|
||||
|
||||
@@ -133,19 +133,19 @@ std::string outputMdem(std::vector<Question*> questions, time_t time = 0) {
|
||||
for (auto question: questions) {
|
||||
ss << std::endl;
|
||||
std::string cooldownPart;
|
||||
if (question->Cooldown != 0) {
|
||||
cooldownPart = std::format(" [{:.2f}]", question->Cooldown);
|
||||
if (question->cooldown != 0) {
|
||||
cooldownPart = std::format(" [{:.2f}]", question->cooldown);
|
||||
}
|
||||
ss << wrapText(
|
||||
std::format("-{}{} >\n",
|
||||
cooldownPart,
|
||||
" " + escapeText(question->QuestionText)),
|
||||
" " + escapeText(question->questionText)),
|
||||
wrap_width
|
||||
);
|
||||
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(question)) {
|
||||
for (auto choice: mw->Choices) {
|
||||
for (auto choice: mw->choices) {
|
||||
char opener;
|
||||
if (choice.IsCorrect) {
|
||||
if (choice.isCorrect) {
|
||||
opener = '+';
|
||||
} else {
|
||||
opener = '-';
|
||||
@@ -160,12 +160,12 @@ std::string outputMdem(std::vector<Question*> questions, time_t time = 0) {
|
||||
"\t{}{} {}\n",
|
||||
opener,
|
||||
orderModifier,
|
||||
escapeText(choice.Answer)
|
||||
escapeText(choice.answer)
|
||||
)
|
||||
, wrap_width);
|
||||
}
|
||||
} else if (GroupQuestion* gq = dynamic_cast<GroupQuestion*>(question)) {
|
||||
for (auto group: gq->Groups) {
|
||||
for (auto group: gq->groups) {
|
||||
ss << wrapText(
|
||||
std::format(
|
||||
"\t- {}:\n",
|
||||
@@ -207,23 +207,23 @@ void makePages() {
|
||||
|
||||
void setupMdem(Mdem *mdem, Question *question) {
|
||||
std::stringstream ss;
|
||||
if (question->Cooldown > 0) {
|
||||
ss << std::format("[{:.2f}] ", question->Cooldown);
|
||||
if (question->cooldown > 0) {
|
||||
ss << std::format("[{:.2f}] ", question->cooldown);
|
||||
}
|
||||
ss << question->QuestionText;
|
||||
ss << question->questionText;
|
||||
mdem->wFrontText.setText(
|
||||
QString::fromStdString(ss.str())
|
||||
);
|
||||
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(question)) {
|
||||
auto choices = mw->Choices;
|
||||
auto choices = mw->choices;
|
||||
for (size_t k = 0; k < choices.size(); ++k) {
|
||||
auto answer = choices[k].Answer;
|
||||
auto answer = choices[k].answer;
|
||||
switch (mw->type) {
|
||||
case MultiElementType::Order:
|
||||
answer = std::format("{}. {}", k + 1, answer);
|
||||
break;
|
||||
case MultiElementType::MultiChoice:
|
||||
if (choices[k].IsCorrect) {
|
||||
if (choices[k].isCorrect) {
|
||||
answer = std::format("+ {}", answer);
|
||||
} else {
|
||||
answer = std::format("- {}", answer);
|
||||
@@ -244,7 +244,7 @@ void setupMdem(Mdem *mdem, Question *question) {
|
||||
}
|
||||
mdem->labelCount = choices.size();
|
||||
} else if (GroupQuestion* mw = dynamic_cast<GroupQuestion*>(question)) {
|
||||
auto groups = mw->Groups;
|
||||
auto groups = mw->groups;
|
||||
std::vector<std::string> elements;
|
||||
for (size_t k = 0; k < groups.size(); ++k) {
|
||||
auto answer = groups[k].name;
|
||||
@@ -267,7 +267,7 @@ void setupMdem(Mdem *mdem, Question *question) {
|
||||
}
|
||||
}
|
||||
|
||||
void SwitchPage(int pageIdx);
|
||||
void switchPage(int pageIdx);
|
||||
|
||||
std::string getFilename(std::string path) {
|
||||
static const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
|
||||
@@ -363,7 +363,7 @@ Mdem* makeMdem() {
|
||||
}
|
||||
}
|
||||
makePages();
|
||||
SwitchPage(pagination->currentPage);
|
||||
switchPage(pagination->currentPage);
|
||||
}
|
||||
if (editMdem == mdem) {
|
||||
editorWindow->hide();
|
||||
@@ -442,14 +442,14 @@ void CreateMdems(std::vector<Question*>& questions) {
|
||||
|
||||
void update(bool isChanged) {
|
||||
if (pagination->currentPage > -1) {
|
||||
SwitchPage(pagination->currentPage);
|
||||
switchPage(pagination->currentPage);
|
||||
}
|
||||
if (currentMdem.length() > 0) {
|
||||
updateMdemInfo(getFilename(currentMdem), isChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void SwitchPage(int pageIdx) {
|
||||
void switchPage(int pageIdx) {
|
||||
pagination->currentPage = pageIdx;
|
||||
|
||||
// Hide all pagination buttons
|
||||
@@ -566,7 +566,7 @@ void reloadMdem(std::string path) {
|
||||
buffer = buffers[path];
|
||||
currentMdemBuffer = buffer;
|
||||
makePages();
|
||||
SwitchPage(0);
|
||||
switchPage(0);
|
||||
updateMdemInfo(getFilename(filename), buffer->isModified);
|
||||
currentMdem = path;
|
||||
errorView->box.hide();
|
||||
@@ -630,7 +630,7 @@ void reloadMdem(std::string path) {
|
||||
hMdemScroll->addItem(mdemSpacer);
|
||||
}
|
||||
makePages();
|
||||
SwitchPage(0);
|
||||
switchPage(0);
|
||||
updateMdemInfo(filename, false);
|
||||
} else {
|
||||
std::cout << std::format("Could not open the file: {}", currentPath.toStdString()) << std::endl;
|
||||
@@ -731,7 +731,7 @@ void setupEditorSave() {
|
||||
res.value.questions.end()
|
||||
);
|
||||
makePages();
|
||||
SwitchPage(0);
|
||||
switchPage(0);
|
||||
editorWindow->hide();
|
||||
updateMdemInfo(getFilename(currentMdem), true);
|
||||
}
|
||||
@@ -1025,7 +1025,7 @@ QMainWindow *initMdemListWindow() {
|
||||
pagination->firstButton.hide();
|
||||
QObject::connect(&pagination->firstButton, &QToolButton::clicked, []() {
|
||||
if (pagination->pages.size() > 0) {
|
||||
SwitchPage(0);
|
||||
switchPage(0);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1034,7 +1034,7 @@ QMainWindow *initMdemListWindow() {
|
||||
pagination->prevButton.hide();
|
||||
QObject::connect(&pagination->prevButton, &QToolButton::clicked, []() {
|
||||
if (pagination->pages.size() > 0) {
|
||||
SwitchPage(pagination->currentPage - 1);
|
||||
switchPage(pagination->currentPage - 1);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1047,7 +1047,7 @@ QMainWindow *initMdemListWindow() {
|
||||
auto pageNum = std::stoi(elButton->text().toStdString().c_str());
|
||||
auto pageIdx = pageNum - 1;
|
||||
if (pageIdx < pagination->pages.size()) {
|
||||
SwitchPage(pageIdx);
|
||||
switchPage(pageIdx);
|
||||
}
|
||||
});
|
||||
pagination->paginationButtons.push_back(elButton);
|
||||
@@ -1058,7 +1058,7 @@ QMainWindow *initMdemListWindow() {
|
||||
pagination->nextButton.hide();
|
||||
QObject::connect(&pagination->nextButton, &QToolButton::clicked, []() {
|
||||
if (pagination->pages.size() > 0) {
|
||||
SwitchPage(pagination->currentPage + 1);
|
||||
switchPage(pagination->currentPage + 1);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1067,7 +1067,7 @@ QMainWindow *initMdemListWindow() {
|
||||
pagination->lastButton.hide();
|
||||
QObject::connect(&pagination->lastButton, &QToolButton::clicked, []() {
|
||||
if (pagination->pages.size() > 0) {
|
||||
SwitchPage(pagination->pages.size() - 1);
|
||||
switchPage(pagination->pages.size() - 1);
|
||||
}
|
||||
});
|
||||
hPagination->addStretch(1);
|
||||
|
||||
@@ -300,7 +300,7 @@ void showFeedBackButtons() {
|
||||
|
||||
void setupAnswerQuestion(MultiElementQuestion *question) {
|
||||
lQuestionText->setText(
|
||||
QString::fromStdString(question->QuestionText)
|
||||
QString::fromStdString(question->questionText)
|
||||
);
|
||||
lQuestionText->show();
|
||||
auto ss = std::stringstream();
|
||||
@@ -333,11 +333,11 @@ void setupAnswerQuestion(MultiElementQuestion *question) {
|
||||
|
||||
void setupOrderQuestion(MultiElementQuestion *question) {
|
||||
lQuestionText->setText(
|
||||
QString::fromStdString(question->QuestionText)
|
||||
QString::fromStdString(question->questionText)
|
||||
);
|
||||
lQuestionText->show();
|
||||
orderModel->clear();
|
||||
auto shuffledAnswers = question->Choices;
|
||||
auto shuffledAnswers = question->choices;
|
||||
std::shuffle(shuffledAnswers.begin(), shuffledAnswers.end(), rng);
|
||||
for (auto answerEl: shuffledAnswers) {
|
||||
auto *item = acquireItem();
|
||||
@@ -355,7 +355,7 @@ void setupOrderQuestion(MultiElementQuestion *question) {
|
||||
for (size_t i = 0; i < orderModel->rowCount(); ++i) {
|
||||
auto item = orderModel->item(i, 0);
|
||||
auto text = item->text();
|
||||
auto isCorrect = question->Choices[i].Answer.compare(text.toStdString()) == 0;
|
||||
auto isCorrect = question->choices[i].answer.compare(text.toStdString()) == 0;
|
||||
if (isCorrect) {
|
||||
item->setData(CORRECT, Qt::UserRole + 1);
|
||||
} else {
|
||||
@@ -375,7 +375,7 @@ void setupOrderQuestion(MultiElementQuestion *question) {
|
||||
|
||||
void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
||||
lQuestionText->setText(
|
||||
QString::fromStdString(question->QuestionText)
|
||||
QString::fromStdString(question->questionText)
|
||||
);
|
||||
lQuestionText->show();
|
||||
|
||||
@@ -396,7 +396,7 @@ void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
||||
[question](bool checked) {
|
||||
for (size_t i = 0; i < multiChoiceModel->rowCount(); ++i) {
|
||||
auto item = multiChoiceModel->item(i, 0);
|
||||
auto isCorrect = question->Choices[i].IsCorrect == (item->checkState() == Qt::Checked);
|
||||
auto isCorrect = question->choices[i].isCorrect == (item->checkState() == Qt::Checked);
|
||||
if (isCorrect) {
|
||||
item->setData(CORRECT, Qt::UserRole + 1);
|
||||
} else {
|
||||
@@ -421,7 +421,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
||||
);
|
||||
|
||||
lQuestionText->setText(
|
||||
QString::fromStdString(question->QuestionText)
|
||||
QString::fromStdString(question->questionText)
|
||||
);
|
||||
lQuestionText->show();
|
||||
wGroupQuestion->show();
|
||||
@@ -454,7 +454,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
||||
for (int k = 0; k < groupViews.size(); k++) {
|
||||
groupViews[k]->widget.hide();
|
||||
}
|
||||
for (size_t i = 0; i < question->Groups.size(); i++) {
|
||||
for (size_t i = 0; i < question->groups.size(); i++) {
|
||||
GroupView *groupView;
|
||||
if (i < groupViews.size()) {
|
||||
groupView = groupViews[i];
|
||||
@@ -463,7 +463,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
||||
groupViews.push_back(groupView);
|
||||
}
|
||||
groupView->label.setText(
|
||||
QString::fromStdString(question->Groups[i].name)
|
||||
QString::fromStdString(question->groups[i].name)
|
||||
);
|
||||
vGroups->addWidget(&groupView->widget);
|
||||
groupView->widget.show();
|
||||
@@ -480,7 +480,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
||||
}
|
||||
for (size_t i = 0; i < groupViews.size(); i++) {
|
||||
auto groupView = groupViews[i];
|
||||
auto group = question->Groups[i];
|
||||
auto group = question->groups[i];
|
||||
for (int j = 0; j < groupView->itemModel.rowCount(); ++j) {
|
||||
auto item = groupView->itemModel.item(j, 0);
|
||||
auto itemText = item->text().toStdString();
|
||||
@@ -586,7 +586,7 @@ void setupNextQuestion() {
|
||||
auto lastTrainedAt = practiceBuffer->trainedAt;
|
||||
practiceBuffer->trainedAt = time;
|
||||
for (size_t i = 0; i < practiceBuffer->questions.size(); ++i) {
|
||||
auto cooldownSeconds = practiceBuffer->questions[i]->Cooldown * 3600;
|
||||
auto cooldownSeconds = practiceBuffer->questions[i]->cooldown * 3600;
|
||||
auto cooldownEndsAt = lastTrainedAt + cooldownSeconds;
|
||||
if (i != currentQuestionIndex && cooldownEndsAt <= time) {
|
||||
questionCandidates.push_back(practiceBuffer->questions[i]);
|
||||
@@ -595,7 +595,7 @@ void setupNextQuestion() {
|
||||
if (newCooldown < 0) {
|
||||
newCooldown = 0;
|
||||
}
|
||||
practiceBuffer->questions[i]->Cooldown = (double)newCooldown / 3600;
|
||||
practiceBuffer->questions[i]->cooldown = (double)newCooldown / 3600;
|
||||
}
|
||||
if (questionCandidates.size() > 0) {
|
||||
auto i = randomIndex(&questionCandidates);
|
||||
@@ -635,7 +635,7 @@ void setCooldownHours(double cooldown) {
|
||||
time_t time = getTime();
|
||||
practiceBuffer->trainedAt = time;
|
||||
auto question = practiceBuffer->questions[currentQuestionIndex];
|
||||
question->Cooldown = cooldown;
|
||||
question->cooldown = cooldown;
|
||||
update(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,31 +21,31 @@ struct QuestionElement {
|
||||
std::string content;
|
||||
};
|
||||
|
||||
std::string MultiElementQuestion::ToString() const {
|
||||
std::string MultiElementQuestion::toString() const {
|
||||
std::stringstream ss;
|
||||
for (const auto& choice : Choices) {
|
||||
for (const auto& choice : choices) {
|
||||
char opener;
|
||||
if (type == MultiElementType::Order) {
|
||||
opener = '^';
|
||||
} else if (choice.IsCorrect) {
|
||||
} else if (choice.isCorrect) {
|
||||
opener = '+';
|
||||
} else {
|
||||
opener = '-';
|
||||
}
|
||||
ss << opener << " " << choice.Answer << "; ";
|
||||
ss << opener << " " << choice.answer << "; ";
|
||||
}
|
||||
return std::format(
|
||||
"<Multiple element>\nsection:{}\nid:{}\n{}\n{}",
|
||||
Section,
|
||||
Cooldown,
|
||||
QuestionText,
|
||||
section,
|
||||
cooldown,
|
||||
questionText,
|
||||
ss.str()
|
||||
);
|
||||
}
|
||||
|
||||
std::string GroupQuestion::ToString() const {
|
||||
std::string GroupQuestion::toString() const {
|
||||
std::stringstream ss;
|
||||
for (auto group: Groups) {
|
||||
for (auto group: groups) {
|
||||
ss << group.name << ": ";
|
||||
for (auto el: group.elements) {
|
||||
ss << el << ", ";
|
||||
@@ -54,9 +54,9 @@ std::string GroupQuestion::ToString() const {
|
||||
}
|
||||
return std::format(
|
||||
"<GroupQuestion>\nsection:{}\nid:{}\n{}\n{}",
|
||||
Section,
|
||||
Cooldown,
|
||||
QuestionText,
|
||||
section,
|
||||
cooldown,
|
||||
questionText,
|
||||
ss.str()
|
||||
);
|
||||
}
|
||||
@@ -326,9 +326,9 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
if (questionElements.size() > 0) {
|
||||
if (isGroupQuestion) {
|
||||
auto *question = new GroupQuestion();
|
||||
question->Cooldown = cooldown;
|
||||
question->QuestionText = questionText;
|
||||
question->Section = section;
|
||||
question->cooldown = cooldown;
|
||||
question->questionText = questionText;
|
||||
question->section = section;
|
||||
int32_t k = -1;
|
||||
for (size_t i = 0; i < questionElements.size(); ++i) {
|
||||
auto questionElement = questionElements[i];
|
||||
@@ -336,10 +336,10 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
++k;
|
||||
auto group = Group();
|
||||
group.name = cleanContent(questionElement.content);
|
||||
question->Groups.push_back(group);
|
||||
question->groups.push_back(group);
|
||||
} else {
|
||||
if (k >= 0) {
|
||||
question->Groups[k].elements.push_back(
|
||||
question->groups[k].elements.push_back(
|
||||
cleanContent(
|
||||
questionElement.content
|
||||
)
|
||||
@@ -349,18 +349,18 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
}
|
||||
questions.push_back(question);
|
||||
if (debug) {
|
||||
std::cout << question->ToString() << "\n";
|
||||
std::cout << question->toString() << "\n";
|
||||
}
|
||||
} else {
|
||||
auto *question = new MultiElementQuestion();
|
||||
question->Cooldown = cooldown;
|
||||
question->QuestionText = cleanContent(questionText);
|
||||
question->Section = section;
|
||||
question->cooldown = cooldown;
|
||||
question->questionText = cleanContent(questionText);
|
||||
question->section = section;
|
||||
for (const auto& elem : questionElements) {
|
||||
Choice choice;
|
||||
choice.Answer = cleanContent(elem.content);
|
||||
choice.IsCorrect = !elem.isDash;
|
||||
question->Choices.push_back(choice);
|
||||
choice.answer = cleanContent(elem.content);
|
||||
choice.isCorrect = !elem.isDash;
|
||||
question->choices.push_back(choice);
|
||||
}
|
||||
questions.push_back(question);
|
||||
if (isPlusQuestion) {
|
||||
@@ -371,7 +371,7 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
question->type = MultiElementType::Regular;
|
||||
}
|
||||
if (debug) {
|
||||
std::cout << question->ToString() << "\n";
|
||||
std::cout << question->toString() << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user