Move page index logic into WelcomePagesModel

This commit is contained in:
Lipu Fei 2019-03-26 11:34:44 +01:00
parent 20bd9ea501
commit 418ad73a63
5 changed files with 126 additions and 73 deletions

View file

@ -20,70 +20,21 @@ Item
clip: true
property int currentStep: 0
property int totalStepCount: (model == null) ? 0 : model.count
property real progressValue: (totalStepCount == 0) ? 0 : (currentStep / totalStepCount)
property var currentItem: (model == null) ? null : model.getItem(currentStep)
property var currentItem: (model == null) ? null : model.getItem(model.currentPageIndex)
property var model: null
// Convenience properties
property var progressValue: model == null ? 0 : model.currentProgress
property string pageUrl: currentItem == null ? null : currentItem.page_url
signal showNextPage()
signal showPreviousPage()
signal passLastPage() // Emitted when there is no more page to show
signal goToPage(string page_id) // Go to a specific page by the given page_id.
onShowNextPage:
{
if (currentStep < totalStepCount - 1)
{
currentStep++
}
else
{
passLastPage()
}
}
onShowPreviousPage:
{
if (currentStep > 0)
{
currentStep--
}
}
onGoToPage:
{
// find the page index
var page_index = -1
for (var i = 0; i < base.model.count; i++)
{
const item = base.model.getItem(i)
if (item.id == page_id)
{
page_index = i
break
}
}
if (page_index > 0)
{
currentStep = page_index
}
}
onVisibleChanged:
{
if (visible)
{
base.currentStep = 0
base.currentItem = base.model.getItem(base.currentStep)
}
}
onModelChanged:
{
base.currentStep = 0
}
// Call the corresponding functions in the model
onShowNextPage: model.goToNextPage()
onShowPreviousPage: model.goToPreviousPage()
onGoToPage: model.goToPage(page_id)
Rectangle // Panel background
{
@ -108,13 +59,13 @@ Item
id: contentLoader
anchors
{
margins: base.contentMargins
margins: UM.Theme.getSize("default_margin").width
top: progressBar.bottom
bottom: parent.bottom
left: parent.left
right: parent.right
}
source: base.currentItem.page_url
source: base.pageUrl
}
}
}