Problem solved. But not quite as planning at first.
import QtQuick 2.0
/*
Elements of model:
name - displayed text
type - type of element, for clicked event
toggle - state for radio and check btn
iconSource - path to icon
*/
/*
TYPE:
radioBtn
checkBtn
commonBtn
subMenu
*/
Item{
id: menuoptions
//property ListModel prev: listmodel
property Item curr: mainList
//TEST FUNCTIONS
property string band: "AM"
property string show: "All"
//END TEST FUNCTION
//Main Menu Radio
Item{
id: mainList
property int count: 7
property Item prev
children:
[
Item
{
property string name: "Band: "
property string type: "subMenu"
property bool toggle: false
property string iconSource: ""
property bool need: true
function onClick()
{
curr = bandList
loadModel()
}
},
Item
{
property string name: "Manage Favorites"
property string type: "subMenu"
property bool toggle: false
property string iconSource: "image://provider/common/endless_menu/list_icons/fav"
property bool need: true
function onClick()
{
curr = manageFavList
loadModel()
}
},
Item
{
property string name: "Show: "
property string type: "subMenu"
property bool toggle: false
property string iconSource: "image://provider/common/endless_menu/list_icons/active"
property bool need: true
function onClick()
{
curr = showList
loadModel()
}
},
Item
{
property string name: "Scan"
property string type: "subMenu"
property bool toggle: false
property string iconSource: "image://provider/common/endless_menu/list_icons/scan"
property bool need: true
function onClick()
{
if (!listmodel.get(menuList.currentIndex).toggle)
{
listmodel.setProperty(menuList.currentIndex, "toggle", true)
listmodel.setProperty(menuList.currentIndex, "name", "Scan")
}
else
{
listmodel.setProperty(menuList.currentIndex, "toggle", false)
listmodel.setProperty(menuList.currentIndex, "name", "Stop")
}
}
},
//optional
Item
{
property string name: "Alternative Frequency"
property string type: "checkBtn"
property bool toggle: false
property string iconSource: ""
property bool need: false
function onClick()
{
if (listmodel.get(menuList.currentIndex).toggle)
{
listmodel.setProperty(menuList.currentIndex, "toggle", false)
listmodel.setProperty(menuList.currentIndex + 1, "toggle", false)
}
else
{
listmodel.setProperty(menuList.currentIndex, "toggle", true)
}
}
},
Item
{
property string name: "Regionalization"
property string type: "checkBtn"
property bool toggle: false
property string iconSource: "image://provider/common/endless_menu/list_icons/scan"
property bool need: false
function onClick()
{
if (listmodel.get(menuList.currentIndex - 1).toggle)
{
if (listmodel.get(menuList.currentIndex).toggle)
{
listmodel.setProperty(menuList.currentIndex, "toggle", false)
}
else
{
listmodel.setProperty(menuList.currentIndex, "toggle", true)
}
}
}
},
//end optional
Item
{
property string name: "Manual Frequency Input"
property string type: "commonBtn"
property bool toggle: false
property string iconSource: ""
property bool need: true
function onClick()
{
console.log("Speller for Manual Frequency Input open!")
}
}
]
function preLoad()
{
console.log("preload Func")
children[0].name = "Band: " + band
children[2].name = "Show: " + show
if (band == "SAT" || band == "AM")
{
children[4].need = false
children[5].need = false
}
if (band == "FM")
{
children[4].need = true
children[5].need = true
}
}
}
//First Lvl subMenu Radio
Item{
id: bandList
property int count: 3
property Item prev: mainList
//Analog as mainList
}
Item{
id: manageFavList
property int count: 3
property Item prev: mainList
//Analog as mainList
function preLoad()
{
console.log("preload Func for Manage Favorite List")
//Insert into model fav stations from 0 item
//favcount = gateway.getFavCount()
}
function favClick()
{
console.log("Favorite item clicked")
}
}
Item{
id: showList
property int count: 2
property Item prev: mainList
//Analog as mainList
}
//Service Items
property alias listmodel: listmodel
ListModel{
id: listmodel
}
function loadModel()
{
console.log("loader menu")
favcount = 0;
listmodel.clear()
curr.preLoad()
for (var i=0;i<curr.count;i++)
{
if (curr.children[i].need){
listmodel.append({"name": curr.children[i].name,
"type":curr.children[i].type,
"toggle":curr.children[i].toggle,
"iconSource":curr.children[i].iconSource})
}
}
}
function actionClick(currIndex)
{
if (favcount == 0)
curr.children[currIndex].onClick()
else
{
if (currIndex <= favcount - 1)
curr.favClick()
else
curr.children[currIndex-favcount].onClick()
}
}
function toggled(index)
{
for (var i=0; i<listmodel.count; i++)
listmodel.setProperty(i, "toggle", false)
listmodel.setProperty(index, "toggle", true)
}
}
As you see, changing optionMenu solved by cleaning model and filling by elements from Item.
Each Item - is one screen.
Service Items - general component and functions.
Now I think, it would be beter to separate menuTree (Item components) in other file, because there will be 3 different OptionMenu with different Trees.