School Commit Init
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#include "MockTest1.h"
|
||||
|
||||
MockTest1::MockTest1(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
}
|
||||
|
||||
MockTest1::~MockTest1()
|
||||
{}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include "ui_MockTest1.h"
|
||||
|
||||
class MockTest1 : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MockTest1(QWidget *parent = nullptr);
|
||||
~MockTest1();
|
||||
|
||||
private:
|
||||
Ui::MockTest1Class ui;
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
<RCC>
|
||||
<qresource prefix="MockTest1">
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.6.33723.286
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MockTest1", "MockTest1.vcxproj", "{6E00E0F0-D4AC-45C2-8D14-87AA4438D72C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6E00E0F0-D4AC-45C2-8D14-87AA4438D72C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{6E00E0F0-D4AC-45C2-8D14-87AA4438D72C}.Debug|x64.Build.0 = Debug|x64
|
||||
{6E00E0F0-D4AC-45C2-8D14-87AA4438D72C}.Release|x64.ActiveCfg = Release|x64
|
||||
{6E00E0F0-D4AC-45C2-8D14-87AA4438D72C}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {2475A094-A48B-45CD-8181-64DC4484D0E4}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,28 @@
|
||||
<UI version="4.0" >
|
||||
<class>MockTest1Class</class>
|
||||
<widget class="QMainWindow" name="MockTest1Class" >
|
||||
<property name="objectName" >
|
||||
<string notr="true">MockTest1Class</string>
|
||||
</property>
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>MockTest1</string>
|
||||
</property> <widget class="QMenuBar" name="menuBar" />
|
||||
<widget class="QToolBar" name="mainToolBar" />
|
||||
<widget class="QWidget" name="centralWidget" />
|
||||
<widget class="QStatusBar" name="statusBar" />
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<resources>
|
||||
<include location="MockTest1.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</UI>
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{6E00E0F0-D4AC-45C2-8D14-87AA4438D72C}</ProjectGuid>
|
||||
<Keyword>QtVS_v304</Keyword>
|
||||
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">10.0.22000.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0.22000.0</WindowsTargetPlatformVersion>
|
||||
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')">
|
||||
<Import Project="$(QtMsBuild)\qt_defaults.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
|
||||
<QtInstall>6.6.0_msvc2019_64</QtInstall>
|
||||
<QtModules>core;gui;widgets</QtModules>
|
||||
<QtBuildConfig>debug</QtBuildConfig>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
|
||||
<QtInstall>6.6.0_msvc2019_64</QtInstall>
|
||||
<QtModules>core;gui;widgets</QtModules>
|
||||
<QtBuildConfig>release</QtBuildConfig>
|
||||
</PropertyGroup>
|
||||
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
|
||||
<Message Importance="High" Text="QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly." />
|
||||
</Target>
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared" />
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(QtMsBuild)\Qt.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(QtMsBuild)\Qt.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<Optimization>Disabled</Optimization>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<DebugInformationFormat>None</DebugInformationFormat>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Participant.cpp" />
|
||||
<ClCompile Include="ParticipantModel.cpp" />
|
||||
<ClCompile Include="ParticipantRepo.cpp" />
|
||||
<ClCompile Include="ParticipantView.cpp" />
|
||||
<ClCompile Include="PresenterModel.cpp" />
|
||||
<ClCompile Include="PresenterView.cpp" />
|
||||
<ClCompile Include="Question.cpp" />
|
||||
<ClCompile Include="QuestionRepo.cpp" />
|
||||
<QtRcc Include="MockTest1.qrc" />
|
||||
<QtUic Include="MockTest1.ui" />
|
||||
<QtMoc Include="MockTest1.h" />
|
||||
<ClCompile Include="MockTest1.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Participant.h" />
|
||||
<QtMoc Include="ParticipantModel.h" />
|
||||
<ClInclude Include="ParticipantRepo.h" />
|
||||
<QtMoc Include="ParticipantView.h" />
|
||||
<QtMoc Include="PresenterModel.h" />
|
||||
<QtMoc Include="PresenterView.h" />
|
||||
<ClInclude Include="Question.h" />
|
||||
<ClInclude Include="QuestionRepo.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="participants.txt" />
|
||||
<Text Include="questions.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
||||
<Import Project="$(QtMsBuild)\qt.targets" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Form Files">
|
||||
<UniqueIdentifier>{99349809-55BA-4b9d-BF79-8FDBB0286EB3}</UniqueIdentifier>
|
||||
<Extensions>ui</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Translation Files">
|
||||
<UniqueIdentifier>{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}</UniqueIdentifier>
|
||||
<Extensions>ts</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtRcc Include="MockTest1.qrc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</QtRcc>
|
||||
<QtUic Include="MockTest1.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtMoc Include="MockTest1.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<ClCompile Include="MockTest1.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Question.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Participant.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="QuestionRepo.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ParticipantRepo.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PresenterModel.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="PresenterView.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ParticipantModel.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ParticipantView.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Question.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Participant.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="QuestionRepo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ParticipantRepo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="questions.txt" />
|
||||
<Text Include="participants.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="PresenterView.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="PresenterModel.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="ParticipantModel.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="ParticipantView.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<QtLastBackgroundBuild>2023-06-11T06:42:13.1294312Z</QtLastBackgroundBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<QtLastBackgroundBuild>2023-06-11T06:42:13.5051728Z</QtLastBackgroundBuild>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "Participant.h"
|
||||
|
||||
Participant::Participant(std::string name)
|
||||
{
|
||||
this->_name = name;
|
||||
this->_score = 0;
|
||||
}
|
||||
|
||||
Participant::Participant()
|
||||
{
|
||||
this->_name = "";
|
||||
this->_score = -1;
|
||||
}
|
||||
|
||||
std::string Participant::name()
|
||||
{
|
||||
return this->_name;
|
||||
}
|
||||
|
||||
int Participant::score()
|
||||
{
|
||||
return this->_score;
|
||||
}
|
||||
|
||||
void Participant::name(std::string name)
|
||||
{
|
||||
this->_name = name;
|
||||
}
|
||||
|
||||
void Participant::score(int score)
|
||||
{
|
||||
this->_score = score;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class Participant
|
||||
{
|
||||
private:
|
||||
std::string _name;
|
||||
int _score;
|
||||
public:
|
||||
Participant(std::string name);
|
||||
Participant();
|
||||
~Participant()=default;
|
||||
std::string name();
|
||||
int score();
|
||||
void name(std::string name);
|
||||
void score(int score);
|
||||
};
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "ParticipantModel.h"
|
||||
#include <QRadioButton>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
|
||||
ParticipantModel::ParticipantModel(ParticipantRepo& repo, QuestionRepo& qrepo, QObject* parent) : repo{ repo }, qrepo{ qrepo }, QAbstractTableModel{ parent }
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ParticipantModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return this->qrepo.size();
|
||||
}
|
||||
|
||||
int ParticipantModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant ParticipantModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
int row = index.row();
|
||||
int column = index.column();
|
||||
Question q = this->qrepo.get_all()[row];
|
||||
if(role == Qt::DisplayRole)
|
||||
{
|
||||
switch(column)
|
||||
{
|
||||
case 0:
|
||||
return QString::number(q.id());
|
||||
case 1:
|
||||
return QString::fromStdString(q.text());
|
||||
case 2:
|
||||
return QString::number(q.score());
|
||||
case 3:
|
||||
return QString("Select");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(role == Qt::BackgroundRole)
|
||||
{
|
||||
if(this->answered.find(row) != this->answered.end())
|
||||
{
|
||||
return QColor{ Qt::green };
|
||||
}
|
||||
}
|
||||
return QVariant{};
|
||||
}
|
||||
|
||||
QVariant ParticipantModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if(role == Qt::DisplayRole)
|
||||
{
|
||||
if(orientation == Qt::Horizontal)
|
||||
{
|
||||
switch(section)
|
||||
{
|
||||
case 0:
|
||||
return QString{ "ID" };
|
||||
case 1:
|
||||
return QString{ "Text" };
|
||||
case 2:
|
||||
return QString{ "Score" };
|
||||
case 3:
|
||||
return QString{ "Selected" };
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return QString::number(section+1);
|
||||
}
|
||||
}
|
||||
return QVariant{};
|
||||
}
|
||||
|
||||
void ParticipantModel::answerQuestion(const int index, const std::string& answer)
|
||||
{
|
||||
|
||||
Question q = this->qrepo.get_all()[index];
|
||||
if(this->answered.find(index) != this->answered.end())
|
||||
{
|
||||
QMessageBox::critical(nullptr, "Error", "Question already answered!");
|
||||
return;
|
||||
}
|
||||
if(q.correct_answer() == answer)
|
||||
{
|
||||
QMessageBox::information(nullptr, "Correct", "Correct answer!");
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::information(nullptr, "Incorrect", "Incorrect answer!");
|
||||
}
|
||||
this->answered.insert(index);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "ParticipantRepo.h"
|
||||
#include "QuestionRepo.h"
|
||||
#include <qabstractitemmodel.h>
|
||||
#include <QVariant>
|
||||
#include <QModelIndex>
|
||||
#include <unordered_set>
|
||||
|
||||
class ParticipantModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
ParticipantRepo& repo;
|
||||
QuestionRepo& qrepo;
|
||||
std::unordered_set<int> answered;
|
||||
public:
|
||||
ParticipantModel(ParticipantRepo& repo, QuestionRepo& qrepo, QObject* parent = nullptr);
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
void answerQuestion(const int index, const std::string& answer);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "ParticipantRepo.h"
|
||||
#include <stdexcept>
|
||||
#include <fstream>
|
||||
|
||||
ParticipantRepo::ParticipantRepo(std::string file_name)
|
||||
{
|
||||
this->_file_name = file_name;
|
||||
this->read_from_file();
|
||||
}
|
||||
|
||||
std::vector<Participant> ParticipantRepo::get_all()
|
||||
{
|
||||
return this->_participants;
|
||||
}
|
||||
|
||||
int ParticipantRepo::size()
|
||||
{
|
||||
return this->_participants.size();
|
||||
}
|
||||
|
||||
void ParticipantRepo::read_from_file()
|
||||
{
|
||||
std::ifstream file(this->_file_name);
|
||||
if(!file.is_open())
|
||||
throw std::runtime_error("File could not be opened!");
|
||||
std::string line;
|
||||
while(std::getline(file, line) && !line.empty())
|
||||
{
|
||||
Participant p(line);
|
||||
this->_participants.push_back(p);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "Participant.h"
|
||||
#include <vector>
|
||||
|
||||
class ParticipantRepo
|
||||
{
|
||||
private:
|
||||
std::string _file_name;
|
||||
std::vector<Participant> _participants;
|
||||
void read_from_file();
|
||||
public :
|
||||
ParticipantRepo(std::string file_name);
|
||||
~ParticipantRepo()=default;
|
||||
std::vector<Participant> get_all();
|
||||
int size();
|
||||
void write_to_file();
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "ParticipantView.h"
|
||||
#include <QMessageBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
||||
ParticipantView::ParticipantView(ParticipantModel* model, QWidget* parent) : QWidget{ parent }, model{ model }
|
||||
{
|
||||
this->initGUI();
|
||||
this->view->setModel(model);
|
||||
this->connectSignalsAndSlots();
|
||||
}
|
||||
|
||||
ParticipantView::~ParticipantView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ParticipantView::initGUI()
|
||||
{
|
||||
this->view = new QTableView{};
|
||||
this->answerEdit = new QLineEdit{};
|
||||
this->addButton = new QPushButton{ "Add" };
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout{};
|
||||
layout->addWidget(this->view);
|
||||
layout->addWidget(this->answerEdit);
|
||||
layout->addWidget(this->addButton);
|
||||
|
||||
this->setLayout(layout);
|
||||
}
|
||||
|
||||
void ParticipantView::connectSignalsAndSlots()
|
||||
{
|
||||
QObject::connect(this->addButton, &QPushButton::clicked, this, [this]() {
|
||||
QModelIndexList selectedIndexes = this->view->selectionModel()->selectedIndexes();
|
||||
if (selectedIndexes.size() != 1 || selectedIndexes.at(0).column()!=3)
|
||||
{
|
||||
QMessageBox::critical(this, "Error", "Please select one question!");
|
||||
return;
|
||||
}
|
||||
int index = selectedIndexes.at(0).row();
|
||||
|
||||
std::string answer = this->answerEdit->text().toStdString();
|
||||
this->model->answerQuestion(index, answer);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "ParticipantModel.h"
|
||||
#include <QWidget>
|
||||
#include <QTableView>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
class ParticipantView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
ParticipantModel* model;
|
||||
QTableView* view;
|
||||
QLineEdit* answerEdit;
|
||||
QPushButton* addButton;
|
||||
void initGUI();
|
||||
void connectSignalsAndSlots();
|
||||
public:
|
||||
ParticipantView(ParticipantModel* model, QWidget* parent = nullptr);
|
||||
~ParticipantView();
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "PresenterModel.h"
|
||||
|
||||
PresenterModel::PresenterModel(QuestionRepo& repo, QObject* parent) : repo{ repo }, QAbstractTableModel{ parent }
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int PresenterModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return this->repo.size();
|
||||
}
|
||||
|
||||
int PresenterModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant PresenterModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
|
||||
std::vector<Question> questions = this->repo.get_all();
|
||||
Question q = questions[row];
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
switch (col)
|
||||
{
|
||||
case 0:
|
||||
return QString::number(q.id());
|
||||
case 1:
|
||||
return QString::fromStdString(q.text());
|
||||
case 2:
|
||||
return QString::fromStdString(q.correct_answer());
|
||||
case 3:
|
||||
return QString::number(q.score());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant PresenterModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
return QString{ "ID" };
|
||||
case 1:
|
||||
return QString{ "Text" };
|
||||
case 2:
|
||||
return QString{ "Correct Answer" };
|
||||
case 3:
|
||||
return QString{ "Score" };
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(role == Qt::DisplayRole && orientation == Qt::Vertical)
|
||||
{
|
||||
return QString::number(section+1);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void PresenterModel::addQuestion(const Question& q)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), this->rowCount(), this->rowCount());
|
||||
this->repo.add(q);
|
||||
endInsertRows();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <qabstractitemmodel.h>
|
||||
#include "QuestionRepo.h"
|
||||
|
||||
class PresenterModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QuestionRepo& repo;
|
||||
|
||||
public:
|
||||
PresenterModel(QuestionRepo& repo, QObject* parent = nullptr);
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
void addQuestion(const Question& q);
|
||||
};
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "PresenterView.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QFormLayout>
|
||||
#include <QMessageBox>
|
||||
#include <QHeaderView>
|
||||
|
||||
PresenterView::PresenterView(PresenterModel* model, QWidget* parent) : QWidget{ parent }, model{ model }
|
||||
{
|
||||
this->initGUI();
|
||||
this->view->setModel(model);
|
||||
this->connectSignalsAndSlots();
|
||||
}
|
||||
|
||||
PresenterView::~PresenterView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PresenterView::initGUI()
|
||||
{
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout{ this };
|
||||
this->setLayout(mainLayout);
|
||||
|
||||
this->view = new QTableView{};
|
||||
mainLayout->addWidget(this->view);
|
||||
|
||||
this->idEdit = new QLineEdit{};
|
||||
auto validator = new QIntValidator{};
|
||||
validator->setBottom(0);
|
||||
this->idEdit->setValidator(validator);
|
||||
this->textEdit = new QLineEdit{};
|
||||
this->answerEdit = new QLineEdit{};
|
||||
this->scoreEdit = new QLineEdit{};
|
||||
this->scoreEdit->setValidator(validator);
|
||||
this->addButton = new QPushButton{ "Add" };
|
||||
|
||||
QFormLayout* formLayout = new QFormLayout{};
|
||||
formLayout->addRow("Id", this->idEdit);
|
||||
formLayout->addRow("Text", this->textEdit);
|
||||
formLayout->addRow("Answer", this->answerEdit);
|
||||
formLayout->addRow("Score", this->scoreEdit);
|
||||
formLayout->addWidget(this->addButton);
|
||||
|
||||
mainLayout->addLayout(formLayout);
|
||||
this->view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
this->setMinimumWidth(1000);
|
||||
this->setWindowTitle("Presenter");
|
||||
}
|
||||
|
||||
void PresenterView::connectSignalsAndSlots()
|
||||
{
|
||||
QObject::connect(this->addButton, &QPushButton::clicked, this, [&](){
|
||||
if(this->idEdit->text().isEmpty() || this->textEdit->text().isEmpty() || this->answerEdit->text().isEmpty() || this->scoreEdit->text().isEmpty())
|
||||
{
|
||||
QMessageBox::critical(this, "Error", "All fields must be filled!");
|
||||
return;
|
||||
}
|
||||
int id = this->idEdit->text().toInt();
|
||||
std::string text = this->textEdit->text().toStdString();
|
||||
std::string answer = this->answerEdit->text().toStdString();
|
||||
int score = this->scoreEdit->text().toInt();
|
||||
Question q{ id, text, answer, score };
|
||||
try{
|
||||
this->model->addQuestion(q);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
QMessageBox::critical(this, "Error", e.what());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "PresenterModel.h"
|
||||
#include <QWidget>
|
||||
#include <QTableView>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
class PresenterView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
PresenterModel* model;
|
||||
QTableView* view;
|
||||
QLineEdit* idEdit;
|
||||
QLineEdit* textEdit;
|
||||
QLineEdit* answerEdit;
|
||||
QLineEdit* scoreEdit;
|
||||
QPushButton* addButton;
|
||||
void initGUI();
|
||||
void connectSignalsAndSlots();
|
||||
public:
|
||||
PresenterView(PresenterModel* model, QWidget* parent = nullptr);
|
||||
~PresenterView();
|
||||
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "Question.h"
|
||||
|
||||
Question::Question(int id, std::string text, std::string correct_answer, int score)
|
||||
{
|
||||
this->_id = id;
|
||||
this->_text = text;
|
||||
this->_correct_answer = correct_answer;
|
||||
this->_score = score;
|
||||
}
|
||||
|
||||
Question::Question()
|
||||
{
|
||||
this->_id = -1;
|
||||
this->_text = "";
|
||||
this->_correct_answer = "";
|
||||
this->_score = -1;
|
||||
}
|
||||
|
||||
int Question::id()
|
||||
{
|
||||
return this->_id;
|
||||
}
|
||||
|
||||
std::string Question::text()
|
||||
{
|
||||
return this->_text;
|
||||
}
|
||||
|
||||
std::string Question::correct_answer()
|
||||
{
|
||||
return this->_correct_answer;
|
||||
}
|
||||
|
||||
int Question::score()
|
||||
{
|
||||
return this->_score;
|
||||
}
|
||||
|
||||
void Question::id(int id)
|
||||
{
|
||||
this->_id = id;
|
||||
}
|
||||
|
||||
void Question::text(std::string text)
|
||||
{
|
||||
this->_text = text;
|
||||
}
|
||||
|
||||
void Question::correct_answer(std::string correct_answer)
|
||||
{
|
||||
this->_correct_answer = correct_answer;
|
||||
}
|
||||
|
||||
void Question::score(int score)
|
||||
{
|
||||
this->_score = score;
|
||||
}
|
||||
|
||||
void operator>>(std::string& is, Question& q)
|
||||
{
|
||||
std::string buffer;
|
||||
buffer = is.substr(0, is.find(","));
|
||||
q.id(std::stoi(buffer));
|
||||
is.erase(0, is.find(",") + 1);
|
||||
buffer = is.substr(0, is.find(","));
|
||||
q.text(buffer);
|
||||
is.erase(0, is.find(",") + 1);
|
||||
buffer = is.substr(0, is.find(","));
|
||||
q.correct_answer(buffer);
|
||||
is.erase(0, is.find(",") + 1);
|
||||
buffer = is;
|
||||
q.score(std::stoi(buffer));
|
||||
}
|
||||
|
||||
std::ofstream& operator<<(std::ofstream& os, Question& q)
|
||||
{
|
||||
os << q.id() << "," << q.text() << "," << q.correct_answer() << "," << q.score() << "\n";
|
||||
return os;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
class Question
|
||||
{
|
||||
private:
|
||||
int _id;
|
||||
std::string _text;
|
||||
std::string _correct_answer;
|
||||
int _score;
|
||||
public:
|
||||
Question(int id, std::string text, std::string correct_answer, int score);
|
||||
Question();
|
||||
~Question()=default;
|
||||
int id();
|
||||
std::string text();
|
||||
std::string correct_answer();
|
||||
int score();
|
||||
void id(int id);
|
||||
void text(std::string text);
|
||||
void correct_answer(std::string correct_answer);
|
||||
void score(int score);
|
||||
friend void operator>>(std::string& is, Question& q);
|
||||
friend std::ofstream& operator<<(std::ofstream& os, Question& q);
|
||||
|
||||
};
|
||||
|
||||
void operator>>(std::string& is, Question& q);
|
||||
std::ofstream& operator<<(std::ofstream& os, Question& q);
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "QuestionRepo.h"
|
||||
#include <stdexcept>
|
||||
|
||||
QuestionRepo::QuestionRepo(std::string file_name)
|
||||
{
|
||||
this->_file_name = file_name;
|
||||
this->read_from_file();
|
||||
}
|
||||
|
||||
QuestionRepo::~QuestionRepo()
|
||||
{
|
||||
this->write_to_file();
|
||||
}
|
||||
|
||||
void QuestionRepo::add(Question q)
|
||||
{
|
||||
for(auto& question : this->_questions)
|
||||
if(question.id() == q.id())
|
||||
throw std::runtime_error("Question already exists!");
|
||||
this->_questions.push_back(q);
|
||||
}
|
||||
|
||||
std::vector<Question> QuestionRepo::get_all()
|
||||
{
|
||||
return this->_questions;
|
||||
}
|
||||
|
||||
int QuestionRepo::size()
|
||||
{
|
||||
return this->_questions.size();
|
||||
}
|
||||
|
||||
void QuestionRepo::read_from_file()
|
||||
{
|
||||
std::ifstream file(this->_file_name);
|
||||
if(!file.is_open())
|
||||
throw std::runtime_error("File could not be opened!");
|
||||
std::string line;
|
||||
while(std::getline(file, line) && !line.empty())
|
||||
{
|
||||
Question q;
|
||||
line >> q;
|
||||
this->_questions.push_back(q);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
void QuestionRepo::write_to_file()
|
||||
{
|
||||
std::ofstream file(this->_file_name);
|
||||
if(!file.is_open())
|
||||
throw std::runtime_error("File could not be opened!");
|
||||
for(auto& question : this->_questions)
|
||||
file << question;
|
||||
file.close();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "vector"
|
||||
#include "Question.h"
|
||||
|
||||
class QuestionRepo
|
||||
{
|
||||
private:
|
||||
std::vector<Question> _questions;
|
||||
std::string _file_name;
|
||||
void read_from_file();
|
||||
void write_to_file();
|
||||
public:
|
||||
QuestionRepo(std::string file_name);
|
||||
~QuestionRepo();
|
||||
void add(Question q);
|
||||
std::vector<Question> get_all();
|
||||
int size();
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
#include <QtWidgets/QApplication>
|
||||
#include "PresenterView.h"
|
||||
#include "ParticipantView.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
QuestionRepo repo{"questions.txt"};
|
||||
ParticipantRepo prepo{"participants.txt"};
|
||||
ParticipantModel* pmodel = new ParticipantModel{ prepo, repo };
|
||||
ParticipantView* pview = new ParticipantView{ pmodel };
|
||||
PresenterModel* model = new PresenterModel{ repo };
|
||||
PresenterView* view = new PresenterView{ model};
|
||||
pview->show();
|
||||
|
||||
view->show();
|
||||
return a.exec();
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Ioan
|
||||
@@ -0,0 +1,7 @@
|
||||
1,What is the capital of UK?,London,100
|
||||
2,What is the capital of France?,Paris,100
|
||||
3,What is the capital of Germany?,Berlin,100
|
||||
4,What river runs through London?,Thames,300
|
||||
5,What is the capital of Spain?,Madrid,100
|
||||
6,What is the capital of Italy?,Rome,100
|
||||
10,3,4,4
|
||||
Reference in New Issue
Block a user