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

Using flags inside Gov::FormField.

parent 9f79f064
......@@ -112,7 +112,7 @@ ScrollableListView {
image.sourceSize.height: imgHeightHeader
image.source: "qrc:/ui/calendar.svg"
accessibleName: qsTr("Open calendar")
visible: gsDate
visible: gsTypeDate
onClicked: {
var locale = Qt.locale()
var today = new Date()
......
......@@ -50,27 +50,28 @@ int GovFormListModel::rowCount(const QModelIndex &parent) const
return !parent.isValid() ? m_formFieldList.size() : 0;
}
#define PROP_KEY "gsKey"
#define PROP_VAL "gsVal"
#define PROP_DESCR "gsDescr"
#define PROP_PLACEHOLD "gsPlacehold"
#define PROP_MANDATORY "gsMandatory"
#define PROP_USER_INPUT "gsUserInput"
#define PROP_BOX_INPUT "gsBoxInput"
#define PROP_DATE "gsDate"
/* Property keys used in QML. */
#define PK_KEY "gsKey"
#define PK_VAL "gsVal"
#define PK_DESCR "gsDescr"
#define PK_PLACEHOLD "gsPlacehold"
#define PK_MANDATORY "gsMandatory"
#define PK_USER_INPUT "gsUserInput"
#define PK_BOX_INPUT "gsBoxInput"
#define PK_TYPE_DATE "gsTypeDate"
QHash<int, QByteArray> GovFormListModel::roleNames(void) const
{
static QHash<int, QByteArray> roles;
if (roles.isEmpty()) {
roles[ROLE_GOV_SRVC_KEY] = PROP_KEY;
roles[ROLE_GOV_SRVC_VAL] = PROP_VAL;
roles[ROLE_GOV_SRVC_DESCR] = PROP_DESCR;
roles[ROLE_GOV_SRVC_PLACEHOLD] = PROP_PLACEHOLD;
roles[ROLE_GOV_SRVC_MANDATORY] = PROP_MANDATORY;
roles[ROLE_GOV_SRVC_USER_INPUT] = PROP_USER_INPUT;
roles[ROLE_GOV_SRVC_BOX_INPUT] = PROP_BOX_INPUT;
roles[ROLE_GOV_SRVC_DATE] = PROP_DATE;
roles[ROLE_GOV_SRVC_KEY] = PK_KEY;
roles[ROLE_GOV_SRVC_VAL] = PK_VAL;
roles[ROLE_GOV_SRVC_DESCR] = PK_DESCR;
roles[ROLE_GOV_SRVC_PLACEHOLD] = PK_PLACEHOLD;
roles[ROLE_GOV_SRVC_MANDATORY] = PK_MANDATORY;
roles[ROLE_GOV_SRVC_USER_INPUT] = PK_USER_INPUT;
roles[ROLE_GOV_SRVC_BOX_INPUT] = PK_BOX_INPUT;
roles[ROLE_GOV_SRVC_TYPE_DATE] = PK_TYPE_DATE;
}
return roles;
}
......@@ -99,16 +100,16 @@ QVariant GovFormListModel::data(const QModelIndex &index, int role) const
return ff.placeholder();
break;
case ROLE_GOV_SRVC_MANDATORY:
return ff.mandatory();
return ff.properties().testFlag(Gov::FormFieldType::PROP_MANDATORY);
break;
case ROLE_GOV_SRVC_USER_INPUT:
return ff.userInput();
return ff.properties().testFlag(Gov::FormFieldType::PROP_USER_INPUT);
break;
case ROLE_GOV_SRVC_BOX_INPUT:
return ff.boxInput();
return ff.properties().testFlag(Gov::FormFieldType::PROP_BOX_INPUT);
break;
case ROLE_GOV_SRVC_DATE:
return ff.date();
case ROLE_GOV_SRVC_TYPE_DATE:
return ff.properties().testFlag(Gov::FormFieldType::PROP_TYPE_DATE);
break;
default:
/* Do nothing. */
......@@ -164,7 +165,7 @@ void GovFormListModel::setProperty(int index, const QString &property,
return;
}
if (property != PROP_VAL) {
if (property != PK_VAL) {
return;
}
......@@ -176,7 +177,8 @@ void GovFormListModel::setProperty(int index, const QString &property,
bool GovFormListModel::haveAllMandatory(void) const
{
foreach (const Gov::FormField &ff, m_formFieldList) {
if (ff.mandatory() && ff.val().isEmpty()) {
if ((ff.properties() & Gov::FormFieldType::PROP_MANDATORY) &&
ff.val().isEmpty()) {
return false;
}
}
......@@ -187,7 +189,9 @@ bool GovFormListModel::haveAllMandatory(void) const
bool GovFormListModel::containsMandatoryUser(void) const
{
foreach (const Gov::FormField &ff, m_formFieldList) {
if (ff.mandatory() && ff.userInput()) {
const Gov::FormFieldType::Properties props = ff.properties();
if ((props & Gov::FormFieldType::PROP_MANDATORY) &&
(props & Gov::FormFieldType::PROP_USER_INPUT)) {
return true;
}
}
......@@ -198,7 +202,7 @@ bool GovFormListModel::containsMandatoryUser(void) const
bool GovFormListModel::containsBoxOwnerData(void) const
{
foreach (const Gov::FormField &ff, m_formFieldList) {
if (ff.boxInput()) {
if (ff.properties() & Gov::FormFieldType::PROP_BOX_INPUT) {
return true;
}
}
......
......@@ -47,7 +47,7 @@ public:
ROLE_GOV_SRVC_MANDATORY,
ROLE_GOV_SRVC_USER_INPUT,
ROLE_GOV_SRVC_BOX_INPUT,
ROLE_GOV_SRVC_DATE
ROLE_GOV_SRVC_TYPE_DATE
};
Q_ENUM(Roles)
......
......@@ -141,10 +141,8 @@ QList<Gov::FormField> Gov::SrvcMvCrrVbh::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
......@@ -154,10 +152,8 @@ QList<Gov::FormField> Gov::SrvcMvCrrVbh::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
......@@ -166,10 +162,8 @@ QList<Gov::FormField> Gov::SrvcMvCrrVbh::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
......@@ -178,10 +172,9 @@ QList<Gov::FormField> Gov::SrvcMvCrrVbh::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT |
FormFieldType::PROP_TYPE_DATE);
formList.append(ff);
}
......
......@@ -577,10 +577,8 @@ QList<Gov::FormField> Gov::SrvcMvIrVp::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
......
......@@ -156,9 +156,8 @@ QList<Gov::FormField> Gov::SrvcMvRtVt::requiredFields(void) const
ff.setVal(m_boxName);
ff.setDescr(tr("Data-box owner name"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
......@@ -167,9 +166,8 @@ QList<Gov::FormField> Gov::SrvcMvRtVt::requiredFields(void) const
ff.setVal(m_boxSurname);
ff.setDescr(tr("Data-box owner surname"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
......@@ -178,9 +176,8 @@ QList<Gov::FormField> Gov::SrvcMvRtVt::requiredFields(void) const
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.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
......@@ -189,9 +186,8 @@ QList<Gov::FormField> Gov::SrvcMvRtVt::requiredFields(void) const
ff.setVal(m_boxBirthRegion);
ff.setDescr(tr("Birth region"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
{
......@@ -200,9 +196,8 @@ QList<Gov::FormField> Gov::SrvcMvRtVt::requiredFields(void) const
ff.setVal(m_boxBirthCity);
ff.setDescr(tr("City"));
//ff.setPlaceholder(QString());
ff.setMandatory(true);
//ff.setUserInput(false);
ff.setBoxInput(true);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_BOX_INPUT);
formList.append(ff);
}
......
......@@ -582,10 +582,8 @@ QList<Gov::FormField> Gov::SrvcMvRtpoVt::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
......
......@@ -578,10 +578,8 @@ QList<Gov::FormField> Gov::SrvcMvSkdVp::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
......
......@@ -611,10 +611,8 @@ QList<Gov::FormField> Gov::SrvcMvVrVp::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
......
......@@ -577,10 +577,8 @@ QList<Gov::FormField> Gov::SrvcMvZrVp::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
......
......@@ -33,8 +33,8 @@ class Gov::FormFieldPrivate {
//Q_DISABLE_COPY(FormFieldPrivate)
public:
FormFieldPrivate(void)
: m_key(), m_val(), m_descr(), m_placeholder(), m_mandatory(false),
m_userInput(false), m_boxInput(false), m_date(false)
: m_key(), m_val(), m_descr(), m_placeholder(),
m_properties(FormFieldType::PROP_NONE)
{ }
FormFieldPrivate &operator=(const FormFieldPrivate &other) Q_DECL_NOTHROW
......@@ -43,10 +43,7 @@ public:
m_val = other.m_val;
m_descr = other.m_descr;
m_placeholder = other.m_placeholder;
m_mandatory = other.m_mandatory;
m_userInput = other.m_userInput;
m_boxInput = other.m_boxInput;
m_date = other.m_date;
m_properties = other.m_properties;
return *this;
}
......@@ -57,20 +54,14 @@ public:
(m_val == other.m_val) &&
(m_descr == other.m_descr) &&
(m_placeholder == other.m_placeholder) &&
(m_mandatory == other.m_mandatory) &&
(m_userInput == other.m_userInput) &&
(m_boxInput == other.m_boxInput) &&
(m_date == other.m_date);
(m_properties == other.m_properties);
}
QString m_key; /*!< Internal value identifier. */
QString m_val; /*!< Supplied value. */
QString m_descr; /*!< Value description. */
QString m_placeholder; /*!< Query placeholder text. */
bool m_mandatory; /*!< True if the value must be supplied. */
bool m_userInput; /*!< True if the value is provided by user input. */
bool m_boxInput; /*!< True if the value is derived from the data-box information. */
bool m_date; /*! True if the value is a date. */
FormFieldType::Properties m_properties; /*!< Field properties. */
};
Gov::FormField::FormField(void)
......@@ -266,72 +257,21 @@ void Gov::FormField::setPlaceholder(QString &&p)
}
#endif /* Q_COMPILER_RVALUE_REFS */
bool Gov::FormField::mandatory(void) const
Gov::FormFieldType::Properties Gov::FormField::properties(void) const
{
Q_D(const FormField);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return false;
}
return d->m_mandatory;
}
void Gov::FormField::setMandatory(bool m)
{
ensureFormFieldPrivate();
Q_D(FormField);
d->m_mandatory = m;
}
bool Gov::FormField::userInput(void) const
{
Q_D(const FormField);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return false;
}
return d->m_userInput;
}
void Gov::FormField::setUserInput(bool ui)
{
ensureFormFieldPrivate();
Q_D(FormField);
d->m_userInput = ui;
}
bool Gov::FormField::boxInput(void) const
{
Q_D(const FormField);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return false;
}
return d->m_boxInput;
}
void Gov::FormField::setBoxInput(bool bi)
{
ensureFormFieldPrivate();
Q_D(FormField);
d->m_boxInput = bi;
}
bool Gov::FormField::date(void) const
{
Q_D(const FormField);
if (Q_UNLIKELY(d == Q_NULLPTR)) {
return false;
return FormFieldType::PROP_NONE;
}
return d->m_date;
return d->m_properties;
}
void Gov::FormField::setDate(bool da)
void Gov::FormField::setProperties(FormFieldType::Properties p)
{
ensureFormFieldPrivate();
Q_D(FormField);
d->m_date = da;
d->m_properties = p;
}
void Gov::swap(FormField &first, FormField &second) Q_DECL_NOTHROW
......
......@@ -23,11 +23,43 @@
#pragma once
#include <QObject>
#include <QScopedPointer>
#include <QString>
namespace Gov {
/*!
* @brief Provides enumeration types for form field.
*/
class FormFieldType : public QObject {
Q_OBJECT
private:
/*!
* @brief Private constructor.
*/
explicit FormFieldType(QObject *parent = Q_NULLPTR);
public:
/*!
* @brief Describes entry properties.
*/
enum Property {
PROP_NONE = 0x00, /*!< Convenience value. */
PROP_MANDATORY = 0x01, /*!< Value is mandatory and must be provided. */
PROP_USER_INPUT = 0x02, /*!< Value is provided by the user. */
PROP_BOX_INPUT = 0x04, /*!< Value is derived from data box owner information. */
PROP_TYPE_DATE = 0x08 /*!< Is a date value. */
};
Q_DECLARE_FLAGS(Properties, Property)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
Q_FLAG(Properties)
#else /* < Qt-5.5 */
Q_FLAGS(Properties)
#endif /* >= Qt-5.5 */
};
class FormFieldPrivate;
/*!
* @brief Describes a form field.
......@@ -75,15 +107,8 @@ namespace Gov {
#ifdef Q_COMPILER_RVALUE_REFS
void setPlaceholder(QString &&p);
#endif /* Q_COMPILER_RVALUE_REFS */
/* TODO -- Define flags for the following values. */
bool mandatory(void) const;
void setMandatory(bool m);
bool userInput(void) const;
void setUserInput(bool ui);
bool boxInput(void) const;
void setBoxInput(bool bi);
bool date(void) const;
void setDate(bool da);
FormFieldType::Properties properties(void) const;
void setProperties(FormFieldType::Properties p);
private:
QScopedPointer<FormFieldPrivate> d_ptr; // std::unique_ptr ?
......@@ -91,4 +116,6 @@ namespace Gov {
void swap(FormField &first, FormField &second) Q_DECL_NOTHROW;
Q_DECLARE_OPERATORS_FOR_FLAGS(FormFieldType::Properties)
}
......@@ -144,10 +144,9 @@ QList<Gov::FormField> Gov::SrvcSzrRobVvu::requiredFields(void) const
ff.setVal(m_userFromDate.isNull() ? QString() : m_userFromDate.toString(DATE_FORMAT));
ff.setDescr(tr("From"));
ff.setPlaceholder(tr("Enter date (YYYY-MM-DD)"));
ff.setMandatory(true);
ff.setUserInput(true);
//ff.setBoxInput(false);
ff.setDate(true);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT |
FormFieldType::PROP_TYPE_DATE);
formList.append(ff);
}
{
......@@ -156,10 +155,9 @@ QList<Gov::FormField> Gov::SrvcSzrRobVvu::requiredFields(void) const
ff.setVal(m_userToDate.isNull() ? QString() : m_userToDate.toString(DATE_FORMAT));
ff.setDescr(tr("To"));
ff.setPlaceholder(tr("Enter date (YYYY-MM-DD)"));
ff.setMandatory(true);
ff.setUserInput(true);
//ff.setBoxInput(false);
ff.setDate(true);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT |
FormFieldType::PROP_TYPE_DATE);
formList.append(ff);
}
......
......@@ -163,10 +163,8 @@ QList<Gov::FormField> Gov::SrvcSzrRosVv::requiredFields(void) const
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);
ff.setProperties(FormFieldType::PROP_MANDATORY |
FormFieldType::PROP_USER_INPUT);
formList.append(ff);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment