Commit 11b9285a authored by Karel Slaný's avatar Karel Slaný

Using DataboxListModel insted of ListModel.

parent 7ba14443
......@@ -26,23 +26,26 @@ import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import cz.nic.mobileDatovka.modelEntries 1.0
ListView {
id: root
/* These properties must be set by caller. */
// sendMsgRecipientListModel holds recipient list from send message page (can be NULL)
property var sendMsgRecipientListModel: null
// isSendMsgAddRecipent says that we can add a databox to sendMsgRecipientListModel
property bool isSendMsgAddRecipent: false
property bool canDetailBoxes: false // enables viewing of box details
property bool canSelectBoxes: false // enables selecting of entries
/* This signal should be captured to implement find databox or add to recipient. */
signal dbClicked(string dbType, string dbID, string dbName, string dbAddress, string dbIc, string dbEffectiveOvm, string dbSendOption)
signal boxClicked(string boxId)
signal boxRemove(string boxId)
delegate: Rectangle {
id: dbItem
height: listItemHeight
width: parent.width
color: datovkaPalette.base
color: rDbSelected ? readBgColor : datovkaPalette.base
Item {
id: databoxData
anchors.fill: parent
......@@ -94,8 +97,7 @@ ListView {
MouseArea {
anchors.fill: parent
onClicked: {
dbItem.color = readBgColor
root.dbClicked(rDbType, rDbID, rDbName, rDbAddress, rDbIc, rDbEffectiveOvm, rDbSendOption)
root.boxClicked(rDbID)
}
}
Rectangle {
......@@ -110,13 +112,13 @@ ListView {
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: defaultMargin
sourceSize.height: (sendMsgRecipientListModel == null) ? navImgHeight : imgHeight
sourceSize.height: canDetailBoxes ? navImgHeight : imgHeight
source: {
// set icon based on the databox list operation
if (sendMsgRecipientListModel == null) {
if (canDetailBoxes) {
// we can view databox detail only
"qrc:/ui/next.svg"
} else if (isSendMsgAddRecipent) {
} else if (canSelectBoxes) {
// we can add databox into send message recipient list
"qrc:/ui/add.svg"
} else {
......@@ -131,15 +133,13 @@ ListView {
color: datovkaPalette.windowText
}
MouseArea {
// visible only if model is sendMsgRecipientListModel
visible: ((sendMsgRecipientListModel != null) && !isSendMsgAddRecipent)
// visible only if canDetailBoxes
visible: (!canDetailBoxes && !canSelectBoxes)
anchors.fill: parent
onClicked: {
// if sendMsgRecipientListModel is set and
// we don't add new databox into send recipient list,
// we must allow remove exist recipients from model.
if ((sendMsgRecipientListModel != null) && !isSendMsgAddRecipent) {
sendMsgRecipientListModel.remove(index)
if (!canDetailBoxes && !canSelectBoxes) {
root.boxRemove(rDbID)
}
}
} // MouseArea
......
......@@ -300,9 +300,9 @@ Item {
}
DataboxList {
id: databoxList
// Set isSendMsgAddRecipent on True if sendMsgRecipientModel is NOT NULL.
// Set canSelectBoxes to True if sendMsgRecipientModel is NOT NULL.
// It allows to add databoxes to sendMsgRecipientModel.
isSendMsgAddRecipent: !(sendMsgRecipientModel == null)
canSelectBoxes: !(sendMsgRecipientModel == null)
anchors.top: searchPanel.bottom
anchors.bottom: parent.bottom
clip: true
......@@ -312,8 +312,10 @@ Item {
width: parent.width
interactive: true
model: proxyDataboxModel
sendMsgRecipientListModel: sendMsgRecipientModel
onDbClicked: {
canDetailBoxes: sendMsgRecipientModel == null
onBoxClicked: {
var boxEntry = databoxModel.entry(boxId)
statusBar.visible = false
// If sendMsgRecipientModel is NULL, we show databox detail page
if (sendMsgRecipientModel == null) {
......@@ -321,22 +323,13 @@ Item {
"pageView": pageView,
"statusBar": statusBar,
"userName": userName,
"dbID": dbID,
"dbType": dbType
"dbID": boxEntry.dbID,
"dbType": boxEntry.dbType
}, StackView.Immediate)
} else {
// sendMsgRecipientModel exists so we can add/append new databox to sendMsgRecipientModel
var isInRecipientList = false
// remove duplications
for (var i = 0; i < sendMsgRecipientModel.rowCount(); i++) {
if (sendMsgRecipientModel.get(i).rDbID === dbID) {
isInRecipientList = true
break
}
}
if (!isInRecipientList) {
sendMsgRecipientModel.append({"rDbType": dbType, "rDbID": dbID, "rDbName": dbName, "rDbAddress": dbAddress, "rDbIc": dbIc, "rDbEffectiveOvm": dbEffectiveOvm, "rDbSendOption": dbSendOption})
}
databoxModel.selectEntry(boxEntry.dbID, true)
sendMsgRecipientModel.addEntry(boxEntry)
}
}
} // DataboxList
......
......@@ -98,7 +98,7 @@ Item {
}
/* Holds send message recipent list model */
ListModel {
DataboxListModel {
id: sendMsgRecipientModel
Component.onCompleted: {
}
......@@ -288,10 +288,13 @@ Item {
height: 600
interactive: true
model: sendMsgRecipientModel
sendMsgRecipientListModel: sendMsgRecipientModel
canDetailBoxes: sendMsgRecipientModel == null
onCountChanged: {
mainPanel.areReguiredFieldsFilled()
}
onBoxRemove: {
sendMsgRecipientModel.removeEntry(boxId)
}
} // DataboxList
}
//----ATTACHMENT SECTION------------
......
......@@ -249,12 +249,9 @@ QVariant DataboxListModel::data(const QModelIndex &index, int role) const
bool DataboxListModel::addEntry(const DataboxModelEntry &entry)
{
qDebug("%s", "BBB001");
const QString key(entry.dbID());
if (Q_UNLIKELY(key.isEmpty())) {
qDebug("%s", "BBB002");
return false;
}
......
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