mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
show answer in group questions and order question
This commit is contained in:
@@ -206,7 +206,8 @@ QVBoxLayout *vButtonBox;
|
||||
QWidget *actionButtons;
|
||||
QHBoxLayout *hButtons;
|
||||
QSpacerItem *leftSpacer;
|
||||
QToolButton *btnTriggerAnswer;
|
||||
QToolButton *btnCheck;
|
||||
QToolButton *btnShowAnswer;
|
||||
QSpacerItem *rightSpacer;
|
||||
QToolButton *btnNext;
|
||||
|
||||
@@ -260,15 +261,16 @@ void releaseItem(QStandardItem** item) {
|
||||
(*item) = nullptr;
|
||||
}
|
||||
|
||||
auto releaseAllInModel(QStandardItemModel *model) {
|
||||
auto itemCount = model->rowCount();
|
||||
for (size_t i = 0; i < itemCount; ++i) {
|
||||
auto item = model->item(0);
|
||||
model->takeRow(item->row());
|
||||
releaseItem(&item);
|
||||
}
|
||||
};
|
||||
|
||||
void releaseAllItems() {
|
||||
auto releaseAllInModel = [](QStandardItemModel *model) {
|
||||
auto itemCount = model->rowCount();
|
||||
for (size_t i = 0; i < itemCount; ++i) {
|
||||
auto item = model->item(0);
|
||||
model->takeRow(item->row());
|
||||
releaseItem(&item);
|
||||
}
|
||||
};
|
||||
releaseAllInModel(multiChoiceModel);
|
||||
releaseAllInModel(groupItemModel);
|
||||
releaseAllInModel(orderModel);
|
||||
@@ -288,7 +290,8 @@ void hideQuestionElements() {
|
||||
btnHard->hide();
|
||||
btnMedium->hide();
|
||||
btnEasy->hide();
|
||||
btnTriggerAnswer->hide();
|
||||
btnCheck->hide();
|
||||
btnShowAnswer->hide();
|
||||
}
|
||||
|
||||
void showFeedBackButtons() {
|
||||
@@ -316,19 +319,22 @@ void setupAnswerQuestion(MultiElementQuestion *question) {
|
||||
|
||||
auto checkAnswerClicked = []() {
|
||||
answerText->show();
|
||||
btnTriggerAnswer->hide();
|
||||
btnCheck->hide();
|
||||
if (practiceAlgoritm == SPACED) {
|
||||
showFeedBackButtons();
|
||||
}
|
||||
};
|
||||
|
||||
// Rāda tikai atbildes parādīšanas opciju.
|
||||
QObject::connect(
|
||||
btnTriggerAnswer,
|
||||
btnShowAnswer,
|
||||
&QToolButton::clicked,
|
||||
[checkAnswerClicked](bool checked) {
|
||||
checkAnswerClicked();
|
||||
btnShowAnswer->hide();
|
||||
}
|
||||
);
|
||||
btnTriggerAnswer->show();
|
||||
btnShowAnswer->show();
|
||||
}
|
||||
|
||||
void setupOrderQuestion(MultiElementQuestion *question) {
|
||||
@@ -339,17 +345,22 @@ void setupOrderQuestion(MultiElementQuestion *question) {
|
||||
orderModel->clear();
|
||||
auto shuffledAnswers = question->choices;
|
||||
std::shuffle(shuffledAnswers.begin(), shuffledAnswers.end(), rng);
|
||||
for (auto answerEl: shuffledAnswers) {
|
||||
auto *item = acquireItem();
|
||||
item->setData(NEUTRAL, Qt::UserRole + 1);
|
||||
|
||||
auto addChoice = [](QStandardItem *item, std::string text) {
|
||||
item->setData(QVariant(), Qt::CheckStateRole);
|
||||
item->setCheckable(false);
|
||||
item->setText(QString::fromStdString(answerEl.answer));
|
||||
item->setText(QString::fromStdString(text));
|
||||
orderModel->appendRow(item);
|
||||
};
|
||||
for (auto answerEl: shuffledAnswers) {
|
||||
auto *item = acquireItem();
|
||||
addChoice(item, answerEl.answer);
|
||||
item->setData(NEUTRAL, Qt::UserRole + 1);
|
||||
}
|
||||
|
||||
orderList->show();
|
||||
QObject::connect(
|
||||
btnTriggerAnswer,
|
||||
btnCheck,
|
||||
&QToolButton::clicked,
|
||||
[question](bool checked) {
|
||||
for (size_t i = 0; i < orderModel->rowCount(); ++i) {
|
||||
@@ -363,14 +374,30 @@ void setupOrderQuestion(MultiElementQuestion *question) {
|
||||
}
|
||||
orderList->update();
|
||||
}
|
||||
btnTriggerAnswer->hide();
|
||||
btnCheck->hide();
|
||||
btnShowAnswer->show();
|
||||
|
||||
if (practiceAlgoritm == SPACED) {
|
||||
showFeedBackButtons();
|
||||
}
|
||||
}
|
||||
);
|
||||
btnTriggerAnswer->show();
|
||||
btnCheck->show();
|
||||
|
||||
QObject::connect(
|
||||
btnShowAnswer,
|
||||
&QToolButton::clicked,
|
||||
[question](bool checked) {
|
||||
for (size_t i = 0; i < question->choices.size(); ++i) {
|
||||
auto item = orderModel->item(i, 0);
|
||||
auto choice = question->choices[i];
|
||||
item->setData(CORRECT, Qt::UserRole + 1);
|
||||
item->setText(QString::fromStdString(choice.answer));
|
||||
orderList->update();
|
||||
}
|
||||
btnShowAnswer->hide();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
||||
@@ -391,7 +418,7 @@ void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
||||
multiChoiceList->show();
|
||||
|
||||
QObject::connect(
|
||||
btnTriggerAnswer,
|
||||
btnCheck,
|
||||
&QToolButton::clicked,
|
||||
[question](bool checked) {
|
||||
for (size_t i = 0; i < multiChoiceModel->rowCount(); ++i) {
|
||||
@@ -404,13 +431,13 @@ void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
||||
}
|
||||
multiChoiceList->update();
|
||||
}
|
||||
btnTriggerAnswer->hide();
|
||||
btnCheck->hide();
|
||||
if (practiceAlgoritm == SPACED) {
|
||||
showFeedBackButtons();
|
||||
}
|
||||
}
|
||||
);
|
||||
btnTriggerAnswer->show();
|
||||
btnCheck->show();
|
||||
}
|
||||
|
||||
void setupGroupQuestion(GroupQuestion *question) {
|
||||
@@ -451,6 +478,9 @@ void setupGroupQuestion(GroupQuestion *question) {
|
||||
return groupView;
|
||||
};
|
||||
|
||||
|
||||
/*auto getOrMakeGroup = [](int i) {*/
|
||||
/*};*/
|
||||
for (int k = 0; k < groupViews.size(); k++) {
|
||||
groupViews[k]->widget.hide();
|
||||
}
|
||||
@@ -463,7 +493,9 @@ 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();
|
||||
@@ -471,7 +503,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
||||
vGroups->addItem(groupSpacer);
|
||||
|
||||
QObject::connect(
|
||||
btnTriggerAnswer,
|
||||
btnCheck,
|
||||
&QToolButton::clicked,
|
||||
[question](bool checked) {
|
||||
for (size_t i = 0; i < groupItemModel->rowCount(); ++i) {
|
||||
@@ -499,19 +531,50 @@ void setupGroupQuestion(GroupQuestion *question) {
|
||||
}
|
||||
groupView->itemList.update();
|
||||
}
|
||||
btnTriggerAnswer->hide();
|
||||
btnCheck->hide();
|
||||
btnShowAnswer->show();
|
||||
|
||||
if (practiceAlgoritm == SPACED) {
|
||||
showFeedBackButtons();
|
||||
}
|
||||
}
|
||||
);
|
||||
btnCheck->show();
|
||||
|
||||
QObject::connect(
|
||||
btnShowAnswer,
|
||||
&QToolButton::clicked,
|
||||
[question](bool checked) {
|
||||
// TODO: release everything and add the correct things to the groups
|
||||
releaseAllInModel(groupItemModel);
|
||||
for (size_t i = 0; i < groupViews.size(); i++) {
|
||||
auto groupView = groupViews[i];
|
||||
auto group = question->groups[i];
|
||||
releaseAllInModel(&groupView->itemModel);
|
||||
for (int j = 0; j < group.elements.size(); ++j) {
|
||||
auto *qItem = acquireItem();
|
||||
auto groupElement = group.elements[j];
|
||||
qItem->setData(CORRECT, Qt::UserRole + 1);
|
||||
qItem->setCheckable(false);
|
||||
qItem->setData(QVariant(), Qt::CheckStateRole);
|
||||
qItem->setText(QString::fromStdString(groupElement));
|
||||
groupView->itemModel.appendRow(qItem);
|
||||
}
|
||||
}
|
||||
|
||||
btnShowAnswer->hide();
|
||||
if (practiceAlgoritm == SPACED) {
|
||||
showFeedBackButtons();
|
||||
}
|
||||
}
|
||||
);
|
||||
btnTriggerAnswer->show();
|
||||
}
|
||||
|
||||
void setupQuestion(Question *question) {
|
||||
hideQuestionElements();
|
||||
releaseAllItems();
|
||||
QObject::disconnect(btnTriggerAnswer, 0, 0, 0);
|
||||
QObject::disconnect(btnShowAnswer, 0, 0, 0);
|
||||
QObject::disconnect(btnCheck, 0, 0, 0);
|
||||
if (auto *q = dynamic_cast<MultiElementQuestion*>(question)) {
|
||||
switch (q->type) {
|
||||
case MultiElementType::Order:
|
||||
@@ -760,7 +823,7 @@ QMainWindow *initTrainWindow() {
|
||||
|
||||
leftSpacer = new QSpacerItem(50, 50, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
|
||||
btnTriggerAnswer = new QToolButton();
|
||||
btnCheck = new QToolButton();
|
||||
btnNotRemembered = new QToolButton();
|
||||
QObject::connect(btnNotRemembered, &QToolButton::clicked, []() {
|
||||
QString key = SETTING_NOT_REMEMBERED;
|
||||
@@ -822,18 +885,24 @@ QMainWindow *initTrainWindow() {
|
||||
}
|
||||
});
|
||||
|
||||
btnTriggerAnswer = new QToolButton();
|
||||
btnCheck = new QToolButton();
|
||||
QShortcut* shortcutCheck = new QShortcut(QKeySequence("Return"), trainWindow);
|
||||
QObject::connect(shortcutCheck, &QShortcut::activated, []() {
|
||||
btnCheck->click();
|
||||
});
|
||||
|
||||
btnShowAnswer = new QToolButton();
|
||||
QShortcut* shortcutShowAnswer = new QShortcut(QKeySequence("Return"), trainWindow);
|
||||
QObject::connect(shortcutShowAnswer, &QShortcut::activated, []() {
|
||||
btnTriggerAnswer->click();
|
||||
btnShowAnswer->click();
|
||||
});
|
||||
|
||||
rightSpacer = new QSpacerItem(50, 50, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
btnNext = new QToolButton();
|
||||
|
||||
hButtons->addItem(leftSpacer);
|
||||
hButtons->addWidget(btnTriggerAnswer);
|
||||
hButtons->addWidget(btnCheck);
|
||||
hButtons->addWidget(btnShowAnswer);
|
||||
hButtons->addWidget(btnNotRemembered);
|
||||
hButtons->addWidget(btnHard);
|
||||
hButtons->addWidget(btnMedium);
|
||||
@@ -844,8 +913,10 @@ QMainWindow *initTrainWindow() {
|
||||
vButtonBox->addWidget(actionButtons);
|
||||
actionButtons->setLayout(hButtons);
|
||||
|
||||
btnTriggerAnswer->setText("Parādīt atbildi");
|
||||
btnTriggerAnswer->hide();
|
||||
btnCheck->setText("Pārbaudīt atbildi");
|
||||
btnShowAnswer->setText("Parādīt atbildi");
|
||||
btnCheck->hide();
|
||||
btnShowAnswer->hide();
|
||||
|
||||
btnNext->setText("Nākamais");
|
||||
QObject::connect(btnNext, &QToolButton::clicked, []() {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
std::string readFile(const std::string& filePath) {
|
||||
std::ifstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("Cannot open file: " + filePath);
|
||||
throw std::runtime_error("Nevar atvērt failu: " + filePath);
|
||||
}
|
||||
|
||||
std::string content;
|
||||
@@ -33,7 +33,7 @@ int main(int argc, char* argv[]) {
|
||||
debug = true;
|
||||
showTimes = true;
|
||||
} else {
|
||||
std::cout << std::format("Unrecognized option: {}", option) << std::endl;
|
||||
std::cout << std::format("Neatpazīta opcija: {}", option) << std::endl;
|
||||
return 1;
|
||||
}
|
||||
filePath = argv[2];
|
||||
@@ -48,7 +48,7 @@ int main(int argc, char* argv[]) {
|
||||
std::string fileContent = readFile(filePath);
|
||||
end = std::chrono::high_resolution_clock::now();
|
||||
if (showTimes) {
|
||||
std::cout << showTime("I/O time") << std::endl;
|
||||
std::cout << showTime("I/O laiks") << std::endl;
|
||||
}
|
||||
|
||||
auto res = transpile(fileContent);
|
||||
|
||||
Reference in New Issue
Block a user