Commit e278da64 authored by Karel Slaný's avatar Karel Slaný Committed by Martin Straka

Using Gov::FormField class.

parent 9d2e74f4
......@@ -100,6 +100,7 @@ SOURCES += \
src/datovka_shared/gov_services/service/gov_mv_skd_vp.cpp \
src/datovka_shared/gov_services/service/gov_mv_vr_vp.cpp \
src/datovka_shared/gov_services/service/gov_mv_zr_vp.cpp \
src/datovka_shared/gov_services/service/gov_service_form_field.cpp \
src/datovka_shared/gov_services/service/gov_service.cpp \
src/datovka_shared/gov_services/service/gov_szr_rob_vu.cpp \
src/datovka_shared/gov_services/service/gov_szr_rob_vvu.cpp \
......@@ -220,6 +221,7 @@ HEADERS += \
src/datovka_shared/gov_services/service/gov_mv_skd_vp.h \
src/datovka_shared/gov_services/service/gov_mv_vr_vp.h \
src/datovka_shared/gov_services/service/gov_mv_zr_vp.h \
src/datovka_shared/gov_services/service/gov_service_form_field.h \
src/datovka_shared/gov_services/service/gov_service.h \
src/datovka_shared/gov_services/service/gov_szr_rob_vu.h \
src/datovka_shared/gov_services/service/gov_szr_rob_vvu.h \
......
......@@ -8,7 +8,7 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
......
......@@ -34,20 +34,20 @@ void GovFormListModel::declareQML(void)
GovFormListModel::GovFormListModel(QObject *parent)
: QAbstractListModel(parent),
m_requiredInputList()
m_formFieldList()
{
}
GovFormListModel::GovFormListModel(const GovFormListModel &model,
QObject *parent)
: QAbstractListModel(parent),
m_requiredInputList(model.m_requiredInputList)
m_formFieldList(model.m_formFieldList)
{
}
int GovFormListModel::rowCount(const QModelIndex &parent) const
{
return !parent.isValid() ? m_requiredInputList.size() : 0;
return !parent.isValid() ? m_formFieldList.size() : 0;
}
#define PROP_KEY "gsKey"
......@@ -78,37 +78,37 @@ QHash<int, QByteArray> GovFormListModel::roleNames(void) const
QVariant GovFormListModel::data(const QModelIndex &index, int role) const
{
int row = index.row();
if (Q_UNLIKELY((row < 0) || (row >= m_requiredInputList.size()))) {
if (Q_UNLIKELY((row < 0) || (row >= m_formFieldList.size()))) {
Q_ASSERT(0);
return QVariant();
}
const Gov::RequiredInput &ri(m_requiredInputList[row]);
const Gov::FormField &ff(m_formFieldList[row]);
switch (role) {
case ROLE_GOV_SRVC_KEY:
return ri.key;
return ff.key();
break;
case ROLE_GOV_SRVC_VAL:
return ri.val;
return ff.val();
break;
case ROLE_GOV_SRVC_DESCR:
return ri.descr;
return ff.descr();
break;
case ROLE_GOV_SRVC_PLACEHOLD:
return ri.placeholder;
return ff.placeholder();
break;
case ROLE_GOV_SRVC_MANDATORY:
return ri.mandatory;
return ff.mandatory();
break;
case ROLE_GOV_SRVC_USER_INPUT:
return ri.userInput;
return ff.userInput();
break;
case ROLE_GOV_SRVC_BOX_INPUT:
return ri.boxInput;
return ff.boxInput();
break;
case ROLE_GOV_SRVC_DATE:
return ri.date;
return ff.date();
break;
default:
/* Do nothing. */
......@@ -118,9 +118,9 @@ QVariant GovFormListModel::data(const QModelIndex &index, int role) const
return QVariant();
}
const QList<Gov::RequiredInput> &GovFormListModel::allEntries(void) const
const QList<Gov::FormField> &GovFormListModel::allEntries(void) const
{
return m_requiredInputList;
return m_formFieldList;
}
Qt::ItemFlags GovFormListModel::flags(const QModelIndex &index) const
......@@ -128,31 +128,38 @@ Qt::ItemFlags GovFormListModel::flags(const QModelIndex &index) const
return QAbstractListModel::flags(index);
}
void GovFormListModel::appendEntry(const Gov::RequiredInput &entry)
void GovFormListModel::appendEntry(const Gov::FormField &entry)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_requiredInputList.append(entry);
m_formFieldList.append(entry);
endInsertRows();
}
void GovFormListModel::setEntries(const QList<Gov::RequiredInput> &entries)
void GovFormListModel::setEntries(const QList<Gov::FormField> &entries)
{
beginResetModel();
m_requiredInputList = entries;
m_formFieldList = entries;
endResetModel();
}
void GovFormListModel::setEntries(QList<Gov::FormField> &&entries)
{
beginResetModel();
m_formFieldList = entries;
endResetModel();
}
void GovFormListModel::clearAll(void)
{
beginResetModel();
m_requiredInputList.clear();
m_formFieldList.clear();
endResetModel();
}
void GovFormListModel::setProperty(int index, const QString &property,
const QVariant &value)
{
if (Q_UNLIKELY((index < 0) || (index >= m_requiredInputList.size()))) {
if (Q_UNLIKELY((index < 0) || (index >= m_formFieldList.size()))) {
Q_ASSERT(0);
return;
}
......@@ -161,15 +168,15 @@ void GovFormListModel::setProperty(int index, const QString &property,
return;
}
m_requiredInputList[index].val = value.toString();
m_formFieldList[index].setVal(value.toString());
emit dataChanged(QAbstractListModel::index(index, 0),
QAbstractListModel::index(index, 0));
}
bool GovFormListModel::haveAllMandatory(void) const
{
foreach (const Gov::RequiredInput &ri, m_requiredInputList) {
if (ri.mandatory && ri.val.isEmpty()) {
foreach (const Gov::FormField &ff, m_formFieldList) {
if (ff.mandatory() && ff.val().isEmpty()) {
return false;
}
}
......@@ -179,8 +186,8 @@ bool GovFormListModel::haveAllMandatory(void) const
bool GovFormListModel::containsMandatoryUser(void) const
{
foreach (const Gov::RequiredInput &ri, m_requiredInputList) {
if (ri.mandatory && ri.userInput) {
foreach (const Gov::FormField &ff, m_formFieldList) {
if (ff.mandatory() && ff.userInput()) {
return true;
}
}
......@@ -190,8 +197,8 @@ bool GovFormListModel::containsMandatoryUser(void) const
bool GovFormListModel::containsBoxOwnerData(void) const
{
foreach (const Gov::RequiredInput &ri, m_requiredInputList) {
if (ri.boxInput) {
foreach (const Gov::FormField &ff, m_formFieldList) {
if (ff.boxInput()) {
return true;
}
}
......
......@@ -106,7 +106,7 @@ public:
*
* @return List of all entries.
*/
const QList<Gov::RequiredInput> &allEntries(void) const;
const QList<Gov::FormField> &allEntries(void) const;
/*!
* @brief Returns item flags for given index.
......@@ -122,14 +122,17 @@ public:
*
* @param[in] entry Entry to append to model data.
*/
void appendEntry(const Gov::RequiredInput &entry);
void appendEntry(const Gov::FormField &entry);
/*!
* @brief Sets all model entries.
*
* @param[in] entryList List of entries.
*/
void setEntries(const QList<Gov::RequiredInput> &entries);
void setEntries(const QList<Gov::FormField> &entries);
#ifdef Q_COMPILER_RVALUE_REFS
void setEntries(QList<Gov::FormField> &&entries);
#endif /* Q_COMPILER_RVALUE_REFS */
/*!
* @brief Clears the model.
......@@ -191,7 +194,7 @@ public:
GovFormListModel *fromVariant(const QVariant &modelVariant);
private:
QList<Gov::RequiredInput> m_requiredInputList; /*!< Form data description. */
QList<Gov::FormField> m_formFieldList; /*!< Form data description. */
};
/* QML passes its arguments via QVariant. */
......
......@@ -131,55 +131,58 @@ bool Gov::SrvcMvCrrVbh::canSend(enum Isds::Type::DbType dbType) const
#define DATE_FORMAT "yyyy-MM-dd"
QList<Gov::RequiredInput> Gov::SrvcMvCrrVbh::requiredFields(void) const
QList<Gov::FormField> Gov::SrvcMvCrrVbh::requiredFields(void) const
{
QList<RequiredInput> formList;
QList<FormField> formList;
{
RequiredInput ri;
ri.key = DRILIC_KEY;
ri.val = m_userDrivingLicenceId;
ri.descr = tr("Driving licence ID");
ri.placeholder = tr("Enter driving licence ID without spaces");
ri.mandatory = true;
ri.userInput = true;
ri.boxInput = false;
formList.append(ri);
FormField ff;
ff.setKey(DRILIC_KEY);
ff.setVal(m_userDrivingLicenceId);
ff.setDescr(tr("Driving licence ID"));
ff.setPlaceholder(tr("Enter driving licence ID without spaces"));
ff.setMandatory(true);
ff.setUserInput(true);
//ff.setBoxInput(false);
//ff.setDate(false);
formList.append(ff);
}
{
RequiredInput ri;
ri.key = NAME_KEY;
ri.val = m_boxName;
ri.descr = tr("Data-box owner name");
ri.placeholder = QString();
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
formList.append(ri);
FormField ff;
ff.setKey(NAME_KEY);
ff.setVal(m_boxName);
ff.setDescr(tr("Data-box owner name"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
//ff.setDate(false);
formList.append(ff);
}
{
RequiredInput ri;
ri.key = SURNAME_KEY;
ri.val = m_boxSurname;
ri.descr = tr("Data-box owner surname");
ri.placeholder = QString();
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
formList.append(ri);
FormField ff;
ff.setKey(SURNAME_KEY);
ff.setVal(m_boxSurname);
ff.setDescr(tr("Data-box owner surname"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
//ff.setDate(false);
formList.append(ff);
}
{
RequiredInput ri;
ri.key = BIRTH_KEY;
ri.val = m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(DATE_FORMAT);
ri.descr = tr("Birth date");
ri.placeholder = QString();
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
ri.date = true;
formList.append(ri);
FormField ff;
ff.setKey(BIRTH_KEY);
ff.setVal(m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(DATE_FORMAT));
ff.setDescr(tr("Birth date"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
ff.setDate(true);
formList.append(ff);
}
return formList;
......
......@@ -26,6 +26,7 @@
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include <QDate>
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
namespace Gov {
......@@ -75,7 +76,7 @@ namespace Gov {
bool canSend(enum Isds::Type::DbType dbType) const Q_DECL_OVERRIDE;
virtual
QList<RequiredInput> requiredFields(void) const Q_DECL_OVERRIDE;
QList<FormField> requiredFields(void) const Q_DECL_OVERRIDE;
virtual
bool setRequiredField(const QString &key, const QString &val) Q_DECL_OVERRIDE;
......
......@@ -567,20 +567,21 @@ bool Gov::SrvcMvIrVp::canSend(enum Isds::Type::DbType dbType) const
#define IC_KEY "ic"
QList<Gov::RequiredInput> Gov::SrvcMvIrVp::requiredFields(void) const
QList<Gov::FormField> Gov::SrvcMvIrVp::requiredFields(void) const
{
QList<RequiredInput> formList;
QList<FormField> formList;
{
RequiredInput ri;
ri.key = IC_KEY;
ri.val = m_userIc;
ri.descr = tr("Subject ID (IČ)");
ri.placeholder = tr("Enter subject ID (IČ)");
ri.mandatory = true;
ri.userInput = true;
ri.boxInput = false;
formList.append(ri);
FormField ff;
ff.setKey(IC_KEY);
ff.setVal(m_userIc);
ff.setDescr(tr("Subject ID (IČ)"));
ff.setPlaceholder(tr("Enter subject ID (IČ)"));
ff.setMandatory(true);
ff.setUserInput(true);
//ff.setBoxInput(false);
//ff.setDate(false);
formList.append(ff);
}
return formList;
......
......@@ -25,6 +25,7 @@
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
namespace Gov {
......@@ -73,7 +74,7 @@ namespace Gov {
bool canSend(enum Isds::Type::DbType dbType) const Q_DECL_OVERRIDE;
virtual
QList<RequiredInput> requiredFields(void) const Q_DECL_OVERRIDE;
QList<FormField> requiredFields(void) const Q_DECL_OVERRIDE;
virtual
bool setRequiredField(const QString &key, const QString &val) Q_DECL_OVERRIDE;
......
......@@ -146,64 +146,64 @@ bool Gov::SrvcMvRtVt::canSend(enum Isds::Type::DbType dbType) const
#define DATE_FORMAT "yyyy-MM-dd"
QList<Gov::RequiredInput> Gov::SrvcMvRtVt::requiredFields(void) const
QList<Gov::FormField> Gov::SrvcMvRtVt::requiredFields(void) const
{
QList<RequiredInput> formList;
QList<FormField> formList;
{
RequiredInput ri;
ri.key = NAME_KEY;
ri.val = m_boxName;
ri.descr = tr("Data-box owner name");
ri.placeholder = QString();
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
formList.append(ri);
FormField ff;
ff.setKey(NAME_KEY);
ff.setVal(m_boxName);
ff.setDescr(tr("Data-box owner name"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
formList.append(ff);
}
{
RequiredInput ri;
ri.key = SURNAME_KEY;
ri.val = m_boxSurname;
ri.descr = tr("Data-box owner surname");
ri.placeholder = QString();
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
formList.append(ri);
FormField ff;
ff.setKey(SURNAME_KEY);
ff.setVal(m_boxSurname);
ff.setDescr(tr("Data-box owner surname"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
formList.append(ff);
}
{
RequiredInput ri;
ri.key = BIRTH_KEY;
ri.val = m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(DATE_FORMAT);
ri.descr = tr("Birth date");
ri.placeholder = QString();
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
formList.append(ri);
FormField ff;
ff.setKey(BIRTH_KEY);
ff.setVal(m_boxBirthDate.isNull() ? QString() : m_boxBirthDate.toString(DATE_FORMAT));
ff.setDescr(tr("Birth date"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
formList.append(ff);
}
{
RequiredInput ri;
ri.key = REGION_KEY;
ri.val = m_boxBirthRegion;
ri.descr = tr("Birth region");
ri.placeholder = QString();
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
formList.append(ri);
FormField ff;
ff.setKey(REGION_KEY);
ff.setVal(m_boxBirthRegion);
ff.setDescr(tr("Birth region"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
formList.append(ff);
}
{
RequiredInput ri;
ri.key = CITY_KEY;
ri.val = m_boxBirthCity;
ri.descr = tr("City");
ri.placeholder = QString();
ri.mandatory = true;
ri.userInput = false;
ri.boxInput = true;
formList.append(ri);
FormField ff;
ff.setKey(CITY_KEY);
ff.setVal(m_boxBirthCity);
ff.setDescr(tr("City"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
formList.append(ff);
}
return formList;
......
......@@ -25,6 +25,7 @@
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
namespace Gov {
......@@ -73,7 +74,7 @@ namespace Gov {
bool canSend(enum Isds::Type::DbType dbType) const Q_DECL_OVERRIDE;
virtual
QList<RequiredInput> requiredFields(void) const Q_DECL_OVERRIDE;
QList<FormField> requiredFields(void) const Q_DECL_OVERRIDE;
virtual
bool setRequiredField(const QString &key, const QString &val) Q_DECL_OVERRIDE;
......
......@@ -572,20 +572,21 @@ bool Gov::SrvcMvRtpoVt::canSend(enum Isds::Type::DbType dbType) const
#define IC_KEY "ic"
QList<Gov::RequiredInput> Gov::SrvcMvRtpoVt::requiredFields(void) const
QList<Gov::FormField> Gov::SrvcMvRtpoVt::requiredFields(void) const
{
QList<RequiredInput> formList;
QList<FormField> formList;
{
RequiredInput ri;
ri.key = IC_KEY;
ri.val = m_userIc;
ri.descr = tr("Subject ID (IČ)");
ri.placeholder = tr("Enter subject ID (IČ)");
ri.mandatory = true;
ri.userInput = true;
ri.boxInput = false;
formList.append(ri);
FormField ff;
ff.setKey(IC_KEY);
ff.setVal(m_userIc);
ff.setDescr(tr("Subject ID (IČ)"));
ff.setPlaceholder(tr("Enter subject ID (IČ)"));
ff.setMandatory(true);
ff.setUserInput(true);
//ff.setBoxInput(false);
//ff.setDate(false);
formList.append(ff);
}
return formList;
......
......@@ -25,6 +25,7 @@
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
namespace Gov {
......@@ -73,7 +74,7 @@ namespace Gov {
bool canSend(enum Isds::Type::DbType dbType) const Q_DECL_OVERRIDE;
virtual
QList<RequiredInput> requiredFields(void) const Q_DECL_OVERRIDE;
QList<FormField> requiredFields(void) const Q_DECL_OVERRIDE;
virtual
bool setRequiredField(const QString &key, const QString &val) Q_DECL_OVERRIDE;
......
......@@ -568,20 +568,21 @@ bool Gov::SrvcMvSkdVp::canSend(enum Isds::Type::DbType dbType) const
#define IC_KEY "ic"
QList<Gov::RequiredInput> Gov::SrvcMvSkdVp::requiredFields(void) const
QList<Gov::FormField> Gov::SrvcMvSkdVp::requiredFields(void) const
{
QList<RequiredInput> formList;
QList<FormField> formList;
{
RequiredInput ri;
ri.key = IC_KEY;
ri.val = m_userIc;
ri.descr = tr("Subject ID (IČ)");
ri.placeholder = tr("Enter subject ID (IČ)");
ri.mandatory = true;
ri.userInput = true;
ri.boxInput = false;
formList.append(ri);
FormField ff;
ff.setKey(IC_KEY);
ff.setVal(m_userIc);
ff.setDescr(tr("Subject ID (IČ)"));
ff.setPlaceholder(tr("Enter subject ID (IČ)"));
ff.setMandatory(true);
ff.setUserInput(true);
//ff.setBoxInput(false);
//ff.setDate(false);
formList.append(ff);
}
return formList;
......
......@@ -25,6 +25,7 @@
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
namespace Gov {
......@@ -73,7 +74,7 @@ namespace Gov {
bool canSend(enum Isds::Type::DbType dbType) const Q_DECL_OVERRIDE;
virtual
QList<RequiredInput> requiredFields(void) const Q_DECL_OVERRIDE;
QList<FormField> requiredFields(void) const Q_DECL_OVERRIDE;
virtual
bool setRequiredField(const QString &key, const QString &val) Q_DECL_OVERRIDE;
......
......@@ -601,20 +601,21 @@ bool Gov::SrvcMvVrVp::canSend(enum Isds::Type::DbType dbType) const
#define IC_KEY "ic"
QList<Gov::RequiredInput> Gov::SrvcMvVrVp::requiredFields(void) const
QList<Gov::FormField> Gov::SrvcMvVrVp::requiredFields(void) const
{
QList<RequiredInput> formList;
QList<FormField> formList;
{
RequiredInput ri;
ri.key = IC_KEY;
ri.val = m_userIc;
ri.descr = tr("Subject ID (IČ)");
ri.placeholder = tr("Enter subject ID (IČ)");
ri.mandatory = true;
ri.userInput = true;
ri.boxInput = false;
formList.append(ri);
FormField ff;
ff.setKey(IC_KEY);
ff.setVal(m_userIc);
ff.setDescr(tr("Subject ID (IČ)"));
ff.setPlaceholder(tr("Enter subject ID (IČ)"));
ff.setMandatory(true);
ff.setUserInput(true);
//ff.setBoxInput(false);
//ff.setDate(false);
formList.append(ff);
}
return formList;
......
......@@ -25,6 +25,7 @@
#include <QCoreApplication> /* Q_DECLARE_TR_FUNCTIONS */
#include "src/datovka_shared/gov_services/service/gov_service_form_field.h"
#include "src/datovka_shared/gov_services/service/gov_service.h"
namespace Gov {
......@@ -73,7 +74,7 @@ namespace Gov {
bool canSend(enum Isds::Type::DbType dbType) const Q_DECL_OVERRIDE;
virtual
QList<RequiredInput> requiredFields(void) const Q_DECL_OVERRIDE;
QList<FormField> requiredFields(void) const Q_DECL_OVERRIDE;