initial work for OJ Problems

This commit is contained in:
royqh1979@gmail.com 2021-10-31 17:01:34 +08:00
parent b8f5f43d23
commit bb10a83942
4 changed files with 378 additions and 5 deletions

View File

@ -121,6 +121,7 @@ SOURCES += \
widgets/labelwithmenu.cpp \
widgets/macroinfomodel.cpp \
widgets/newprojectdialog.cpp \
widgets/ojproblemsetmodel.cpp \
widgets/qconsole.cpp \
widgets/qpatchedcombobox.cpp \
widgets/searchdialog.cpp \
@ -236,6 +237,7 @@ HEADERS += \
widgets/labelwithmenu.h \
widgets/macroinfomodel.h \
widgets/newprojectdialog.h \
widgets/ojproblemsetmodel.h \
widgets/qconsole.h \
widgets/qpatchedcombobox.h \
widgets/searchdialog.h \

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>946</width>
<height>657</height>
<width>1036</width>
<height>742</height>
</rect>
</property>
<property name="windowTitle">
@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
@ -262,6 +262,124 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabProblemSet">
<attribute name="title">
<string>Problem Set</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="spacing">
<number>7</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="lblProblemSet">
<property name="text">
<string>Problem Set</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_15">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="btnNewProblemSet">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/050-newsrc.png</normaloff>:/icons/images/newlook24/050-newsrc.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnAddProblem">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/002-add.png</normaloff>:/icons/images/newlook24/002-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnRemoveProblem">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/008-close.png</normaloff>:/icons/images/newlook24/008-close.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnSaveProblemSet">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/072-saveas.png</normaloff>:/icons/images/newlook24/072-saveas.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnLoadProblemSet">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/053-open.png</normaloff>:/icons/images/newlook24/053-open.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QListView" name="lstProblemSet"/>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="EditorPanel" native="true">
<property name="sizePolicy">
@ -353,7 +471,7 @@
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>6</number>
</property>
<property name="iconSize">
<size>
@ -944,6 +1062,181 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabProblem">
<attribute name="title">
<string>Problem</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="leftMargin">
<number>11</number>
</property>
<property name="topMargin">
<number>11</number>
</property>
<property name="rightMargin">
<number>11</number>
</property>
<property name="bottomMargin">
<number>11</number>
</property>
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Problem</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_6" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_17">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="btnAddProblemCase">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/002-add.png</normaloff>:/icons/images/newlook24/002-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnRemoveProblemCase">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/008-close.png</normaloff>:/icons/images/newlook24/008-close.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QListView" name="lstProblemCases"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="widget_5" native="true">
<layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Output</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Input</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Expected</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTextEdit" name="txtProblemCaseInput"/>
</item>
<item row="1" column="1">
<widget class="QTextEdit" name="txtProblemCaseOutput"/>
</item>
<item row="1" column="2">
<widget class="QTextEdit" name="txtProblemCaseExpected"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
@ -954,7 +1247,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>946</width>
<width>1036</width>
<height>25</height>
</rect>
</property>

View File

@ -0,0 +1,26 @@
#include "ojproblemsetmodel.h"
OJProblemSetModel::OJProblemSetModel(QObject *parent) : QAbstractListModel(parent)
{
}
OJProblemCaseModel::OJProblemCaseModel(QObject *parent): QAbstractListModel(parent)
{
}
const POJProbelm &OJProblemCaseModel::problem() const
{
return mProblem;
}
void OJProblemCaseModel::setProblem(const POJProbelm &newProblem)
{
mProblem = newProblem;
}
int OJProblemCaseModel::rowCount(const QModelIndex &parent) const
{
}

View File

@ -0,0 +1,52 @@
#ifndef OJPROBLEMSETMODEL_H
#define OJPROBLEMSETMODEL_H
#include <QAbstractListModel>
#include <memory>
enum class ProblemCaseTestState {
NoTested,
Passed,
Failed
};
struct OJProblemCase {
QString name;
QString input;
QString expected;
ProblemCaseTestState testState;
};
using POJProblemCase = std::shared_ptr<OJProblemCase>;
struct OJProblem {
QString name;
QVector<POJProblemCase> cases;
};
using POJProbelm = std::shared_ptr<OJProblem>;
class OJProblemCaseModel: public QAbstractListModel {
Q_OBJECT
public:
explicit OJProblemCaseModel(QObject *parent = nullptr);
const POJProbelm &problem() const;
void setProblem(const POJProbelm &newProblem);
private:
POJProbelm mProblem;
// QAbstractItemModel interface
public:
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
};
class OJProblemSetModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit OJProblemSetModel(QObject *parent = nullptr);
};
#endif // OJPROBLEMSETMODEL_H