partial impl of the group question widget

This commit is contained in:
jorenchik
2024-09-30 23:10:52 +03:00
parent 59558ba866
commit 9ec8d75a7f
2 changed files with 84 additions and 15 deletions

View File

@@ -238,7 +238,7 @@ void CreateMdems(std::vector<Question*>& questions) {
mdems[i]->wBack->layout()->addWidget(label);
}
}
mdems[i]->labelCount = groups.size();
mdems[i]->labelCount = elements.size();
}
if (!mdems[i]->wMdem->isVisible()) {
mdems[i]->wMdem->show();

View File

@@ -18,6 +18,7 @@
#include <qwidget.h>
#include <QStandardItemModel>
#include <QDropEvent>
#include <iostream>
#include "trainWindow.h"
#include "parser.h"
@@ -53,12 +54,14 @@ QListView *itemListView;
QStandardItemModel *orderModel;
class CustomListView : public QListView
QWidget *wGroupQuestion;
class OrderListView : public QListView
{
Q_OBJECT
public:
explicit CustomListView(QWidget *parent = nullptr) : QListView(parent) {}
explicit OrderListView(QWidget *parent = nullptr) : QListView(parent) {}
protected:
void dropEvent(QDropEvent *event) override
@@ -81,9 +84,38 @@ protected:
}
};
class MoveListView : public QListView
{
Q_OBJECT
public:
explicit MoveListView(QWidget *parent = nullptr) : QListView(parent) {}
protected:
void dropEvent(QDropEvent *event) override
{
QModelIndex sourceIndex = currentIndex();
QModelIndex targetIndex = indexAt(event->pos());
if (sourceIndex.isValid() && targetIndex.isValid()) {
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(this->model());
if (model) {
QVariant sourceData = model->data(sourceIndex);
QVariant targetData = model->data(targetIndex);
model->setData(sourceIndex, targetData);
model->setData(targetIndex, sourceData);
event->ignore();
}
} else {
event->ignore();
}
}
};
#include "trainWindow.moc"
CustomListView *orderList;
OrderListView *orderList;
QStandardItem *makeItem(std::string content, bool isCheckable) {
auto *item = new QStandardItem();
@@ -131,7 +163,7 @@ void initTrainWindow() {
auto listStyle =
"QListView {"
" background-color: white;"
" border: 1px solid black;"
" border: 0px solid black;"
"}"
"QListView::item::first {"
" padding: 5px 0 0 0;"
@@ -178,7 +210,7 @@ void initTrainWindow() {
{ // Make order list.
orderModel = new QStandardItemModel();
orderList = new CustomListView();
orderList = new OrderListView();
orderList->setModel(orderModel);
orderList->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
@@ -234,10 +266,14 @@ void initTrainWindow() {
}
{ // Make group question view.
auto wGroupQuestion = new QWidget();
wGroupQuestion = new QWidget();
wGroupQuestion->setStyleSheet(
"border:none;"
);
auto hGroupQuestion = new QHBoxLayout();
wGroupQuestion->setLayout(hGroupQuestion);
// Items on the left.
auto itemScroll = new QScrollArea();
auto vItems = new QVBoxLayout();
itemScroll->setLayout(vItems);
@@ -245,22 +281,44 @@ void initTrainWindow() {
itemListView = new QListView();
itemListView->setModel(itemModel);
itemListView->setStyleSheet(listStyle);
for (int i = 0; i < 50; ++i) {
itemModel->appendRow(makeItem("Item I", false));
}
itemListView->setDragEnabled(true);
itemListView->setDragDropMode(QAbstractItemView::DragDrop);
itemListView->setDefaultDropAction(Qt::MoveAction);
vItems->addWidget(itemListView);
hGroupQuestion->addWidget(itemScroll);
// Items on the right.
auto wGroupBox = new QWidget();
auto vGroupBox = new QVBoxLayout();
auto groupScroll = new QScrollArea();
auto wGroups = new QScrollArea();
auto vGroups = new QVBoxLayout();
auto groupSpacer = new QSpacerItem(50, 50, QSizePolicy::Minimum, QSizePolicy::Expanding);
wGroupBox->setLayout(vGroupBox);
vGroupBox->addWidget(groupScroll);
groupScroll->setLayout(vGroups);
wGroups->setLayout(vGroups);
hGroupQuestion->addWidget(wGroupBox);
vGroupBox->addWidget(wGroups);
{
auto groupLabel = new QLabel("Group I");
auto scrollArea = new QScrollArea();
auto groupModel = new QStandardItemModel();
auto groupList = new QListView();
groupList->setModel(groupModel);
groupList->setMaximumHeight(100);
vGroups->addWidget(groupLabel);
vGroups->addWidget(groupList);
groupList->setStyleSheet(listStyle);
groupList->setAcceptDrops(true);
groupList->setDragDropMode(QAbstractItemView::DragDrop);
groupList->setDefaultDropAction(Qt::MoveAction);
}
vGroups->addItem(groupSpacer);
std::cout << wGroupBox->geometry().height() << std::endl;
itemListView->setEditTriggers(QAbstractItemView::NoEditTriggers);
wGroupQuestion->hide();
questionBox->layout()->addWidget(wGroupQuestion);
}
@@ -277,6 +335,7 @@ void hideQuestionElements() {
answerText->hide();
orderList->hide();
listView->hide();
wGroupQuestion->hide();
}
void setupAnswerQuestion(MultiElementQuestion *question) {
@@ -362,7 +421,17 @@ void setupMultiChoiceQuestion(MultiElementQuestion *question) {
void setupGroupQuestion(GroupQuestion *question) {
hideQuestionElements();
// TODO
lQuestionText->setText(
QString::fromStdString(question->QuestionText)
);
lQuestionText->show();
wGroupQuestion->show();
for (auto group: question->Groups) {
for (auto item: group.elements) {
itemModel->appendRow(makeItem(item, false));
}
}
auto showAnswer = [](bool checked) {
QObject::disconnect(btnTriggerAnswer, 0, 0, 0);