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

Setting gov form model data from QML page.

parent 40a89158
......@@ -51,9 +51,11 @@ ScrollableListView {
wrapMode: Text.Wrap
}
AccessibleTextField {
id: textField
height: inputItemHeight
//maximumLength: 8
font.pointSize: defaultTextFont.font.pointSize
text: gsVal
placeholderText: gsPlacehold
width: parent.width
InputLineMenu {
......@@ -67,6 +69,9 @@ ScrollableListView {
icox.open()
}
}
onTextEdited: { // onEditingFinished ?
root.model.setProperty(index, "gsVal", textField.text)
}
}
}
} // Item
......
......@@ -42,6 +42,7 @@ Item {
Component.onCompleted: {
gov.loadFormToModel(userName, gsInternId, govFormModel)
actionButton.enabled = govFormModel.haveAllMandatory()
if (gsReqField === "ic") {
icoLabel.visible = true
......@@ -60,6 +61,10 @@ Item {
GovFormListModel {
id: govFormModel
onDataChanged: {
actionButton.enabled = govFormModel.haveAllMandatory()
}
Component.onCompleted: {
}
}
......
......@@ -49,15 +49,21 @@ int GovFormListModel::rowCount(const QModelIndex &parent) const
return !parent.isValid() ? m_requiredInputList.size() : 0;
}
#define PROP_KEY "gsKey"
#define PROP_VAL "gsVal"
#define PROP_DESCR "gsDescr"
#define PROP_PLACEHOLD "gsPlacehold"
#define PROP_MANDATORY "gsMandatory"
QHash<int, QByteArray> GovFormListModel::roleNames(void) const
{
static QHash<int, QByteArray> roles;
if (roles.isEmpty()) {
roles[ROLE_GOV_SRVC_KEY] = "gsKey";
roles[ROLE_GOV_SRVC_VAL] = "gsVal";
roles[ROLE_GOV_SRVC_DESCR] = "gsDescr";
roles[ROLE_GOV_SRVC_PLACEHOLD] = "gsPlacehold";
roles[ROLE_GOV_SRVC_MANDATORY] = "gsMandatory";
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;
}
return roles;
}
......@@ -127,6 +133,34 @@ void GovFormListModel::clearAll(void)
endResetModel();
}
void GovFormListModel::setProperty(int index, const QString &property,
const QVariant &value)
{
if (Q_UNLIKELY((index < 0) || (index >= m_requiredInputList.size()))) {
Q_ASSERT(0);
return;
}
if (property != PROP_VAL) {
return;
}
m_requiredInputList[index].val = value.toString();
emit dataChanged(QAbstractListModel::index(index, 0),
QAbstractListModel::index(index, 0));
}
bool GovFormListModel::haveAllMandatory(void) const
{
foreach (const RequiredInput &ri, m_requiredInputList) {
if (ri.mandatory && ri.val.isEmpty()) {
return false;
}
}
return true;
}
GovFormListModel *GovFormListModel::fromVariant(const QVariant &modelVariant)
{
if (!modelVariant.canConvert<QObject *>()) {
......
......@@ -133,6 +133,27 @@ public:
Q_INVOKABLE
void clearAll(void);
/*!
* @brief Modify model data.
*
* @note See documentation for ListModel and sources of QQmlListModel.
*
* @param[in] index Row number.
* @param[in] property Property name to be changed.
* @param[in] value Value to be assigned to the property.
*/
Q_INVOKABLE
void setProperty(int index, const QString &property,
const QVariant &value);
/*!
* @brief Return true if all mandatory data are set.
*
* @return True if all mandatory values are set.
*/
Q_INVOKABLE
bool haveAllMandatory(void) const;
/*!
* @brief Converts QVariant obtained from QML into model pointer.
*
......
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