added age to result
This commit is contained in:
parent
bc7be14c65
commit
da2aa89059
48
source/Age.cpp
Normal file
48
source/Age.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "Age.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Age::Age(unsigned int years, unsigned int months)
|
||||
: m_years(years)
|
||||
, m_months(months)
|
||||
{
|
||||
}
|
||||
|
||||
Age::Age(const QDate &birth, const QDate &reference)
|
||||
{
|
||||
if (reference < birth)
|
||||
{
|
||||
qDebug() << "test (" << reference << ") before birth (" << birth << ")";
|
||||
m_years = 0;
|
||||
m_months = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int years = reference.year() - birth.year();
|
||||
int months = reference.month() - birth.month();
|
||||
|
||||
if (months == 0 && reference.day() < birth.day())
|
||||
{
|
||||
months--;
|
||||
}
|
||||
|
||||
if (months < 0)
|
||||
{
|
||||
years--;
|
||||
months = (months + 12) % 12;
|
||||
}
|
||||
|
||||
m_years = years;
|
||||
m_months = months;
|
||||
}
|
||||
|
||||
unsigned int Age::years() const
|
||||
{
|
||||
return m_years;
|
||||
}
|
||||
|
||||
unsigned int Age::months() const
|
||||
{
|
||||
return m_months;
|
||||
}
|
13
source/Age.h
13
source/Age.h
@ -1,5 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDate>
|
||||
|
||||
class Age
|
||||
{
|
||||
private:
|
||||
unsigned int m_years = 0;
|
||||
unsigned int m_months = 0;
|
||||
|
||||
public:
|
||||
Age() = default;
|
||||
Age(unsigned int years, unsigned int months);
|
||||
Age(const QDate &birth, const QDate &reference);
|
||||
|
||||
unsigned int years() const;
|
||||
unsigned int months() const;
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ add_executable(${PROJECT_NAME}
|
||||
LogoTest.cpp
|
||||
DataModel.cpp
|
||||
mainwindow.cpp
|
||||
Age.cpp
|
||||
${LOGO_TEST_UI}
|
||||
${LOGO_TEST_QRC}
|
||||
)
|
||||
|
@ -40,4 +40,5 @@ void DataModel::pluralModelChanged()
|
||||
|
||||
void DataModel::metaDataChanged()
|
||||
{
|
||||
m_results.setAge(m_metaData.getAge());
|
||||
}
|
||||
|
@ -33,6 +33,6 @@ public:
|
||||
|
||||
Age getAge() const
|
||||
{
|
||||
return {};
|
||||
return { m_dateOfBirth, m_dateOfTest };
|
||||
}
|
||||
};
|
||||
|
@ -80,8 +80,9 @@ QVariant ResultModel::headerData(
|
||||
}
|
||||
}
|
||||
|
||||
void ResultModel::setAge(const QDate &age)
|
||||
void ResultModel::setAge(const Age &age)
|
||||
{
|
||||
qDebug() << "Age:" << age.years() << "years" << age.months() << "months";
|
||||
m_age = age;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Age.h"
|
||||
#include <vector>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QDate>
|
||||
|
||||
class TestResult
|
||||
{
|
||||
@ -38,7 +38,7 @@ class ResultModel : public QAbstractTableModel
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QDate m_age;
|
||||
Age m_age;
|
||||
std::vector<TestResult> m_results;
|
||||
|
||||
public:
|
||||
@ -53,6 +53,6 @@ public:
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
void setAge(const QDate &age);
|
||||
void setAge(const Age &age);
|
||||
void setPluralResult(size_t points);
|
||||
};
|
||||
|
Reference in New Issue
Block a user