Commit 02fdc59e authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/modules/Linphone/Timeline/Timeline): handle correctly inserted entries

parent 102bbb4c
...@@ -327,6 +327,7 @@ ...@@ -327,6 +327,7 @@
<file>ui/modules/Linphone/Styles/Timeline/TimelineStyle.qml</file> <file>ui/modules/Linphone/Styles/Timeline/TimelineStyle.qml</file>
<file>ui/modules/Linphone/TelKeypad/TelKeypadButton.qml</file> <file>ui/modules/Linphone/TelKeypad/TelKeypadButton.qml</file>
<file>ui/modules/Linphone/TelKeypad/TelKeypad.qml</file> <file>ui/modules/Linphone/TelKeypad/TelKeypad.qml</file>
<file>ui/modules/Linphone/Timeline/Timeline.js</file>
<file>ui/modules/Linphone/Timeline/Timeline.qml</file> <file>ui/modules/Linphone/Timeline/Timeline.qml</file>
<file>ui/scripts/LinphoneUtils/linphone-utils.js</file> <file>ui/scripts/LinphoneUtils/linphone-utils.js</file>
<file>ui/scripts/LinphoneUtils/qmldir</file> <file>ui/scripts/LinphoneUtils/qmldir</file>
......
// =============================================================================
// `Timeline.qml` Logic.
// =============================================================================
function setSelectedEntry (sipAddress) {
var model = timeline.model
var n = view.count
timeline._selectedSipAddress = sipAddress
for (var i = 0; i < n; i++) {
if (sipAddress === model.data(model.index(i, 0)).sipAddress) {
view.currentIndex = i
return
}
}
}
function resetSelectedEntry () {
view.currentIndex = -1
timeline._selectedSipAddress = ''
}
// -----------------------------------------------------------------------------
function handleDataChanged (topLeft, bottomRight, roles) {
var index = view.currentIndex
var model = timeline.model
var sipAddress = timeline._selectedSipAddress
if (
index !== -1 &&
sipAddress !== model.data(model.index(index, 0)).sipAddress
) {
setSelectedEntry(sipAddress)
}
}
function handleRowsAboutToBeRemoved (parent, first, last) {
var index = view.currentIndex
if (index >= first && index <= last) {
view.currentIndex = -1
}
}
function handleCountChanged () {
var sipAddress = timeline._selectedSipAddress
if (sipAddress.length > 0) {
setSelectedEntry(sipAddress)
}
}
...@@ -4,7 +4,8 @@ import QtQuick.Layouts 1.3 ...@@ -4,7 +4,8 @@ import QtQuick.Layouts 1.3
import Common 1.0 import Common 1.0
import Linphone 1.0 import Linphone 1.0
import Linphone.Styles 1.0 import Linphone.Styles 1.0
import Utils 1.0
import 'Timeline.js' as Logic
// ============================================================================= // =============================================================================
...@@ -14,9 +15,10 @@ ColumnLayout { ...@@ -14,9 +15,10 @@ ColumnLayout {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
property alias model: view.model property alias model: view.model
property string _selectedSipAddress property string _selectedSipAddress
property var _newInsertedItem
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
signal entrySelected (var entry) signal entrySelected (var entry)
...@@ -24,21 +26,11 @@ ColumnLayout { ...@@ -24,21 +26,11 @@ ColumnLayout {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function setSelectedEntry (sipAddress) { function setSelectedEntry (sipAddress) {
var n = model.rowCount() Logic.setSelectedEntry(sipAddress)
for (var i = 0; i < n; i++) {
_selectedSipAddress = sipAddress
if (sipAddress === model.data(model.index(i, 0)).sipAddress) {
view.currentIndex = i
return
}
}
} }
function resetSelectedEntry () { function resetSelectedEntry () {
view.currentIndex = -1 Logic.resetSelectedEntry()
_selectedSipAddress = ''
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -50,37 +42,8 @@ ColumnLayout { ...@@ -50,37 +42,8 @@ ColumnLayout {
Connections { Connections {
target: model target: model
// Handle if current entry was moved in timeline. onDataChanged: Logic.handleDataChanged(topLeft, bottomRight, roles)
onDataChanged: { onRowsAboutToBeRemoved: Logic.handleRowsAboutToBeRemoved (parent, first, last)
var index = view.currentIndex
if (
index !== -1 &&
_selectedSipAddress !== model.data(model.index(index, 0)).sipAddress
) {
setSelectedEntry(_selectedSipAddress)
}
}
// A timeline entry is removed from timeline if there is no history entry.
onRowsAboutToBeRemoved: {
var index = view.currentIndex
if (index >= first && index <= last) {
view.currentIndex = -1
}
}
// A entry is added when history is created.
onRowsInserted: {
if (_selectedSipAddress.length === 0) {
return
}
for (var i = first; i <= last; i++) {
if (_selectedSipAddress === model.data(model.index(i, 0)).sipAddress) {
view.currentIndex = i
}
}
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -175,5 +138,7 @@ ColumnLayout { ...@@ -175,5 +138,7 @@ ColumnLayout {
} }
} }
} }
onCountChanged: Logic.handleCountChanged()
} }
} }
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