Correct initial state on added points

This commit is contained in:
Stefan Persson 2011-02-02 15:29:56 +00:00
parent 9bc2aaf90c
commit 1a69bd368c
4 changed files with 69 additions and 28 deletions

View file

@ -7,6 +7,7 @@ Rectangle{
property color prevDayColor: "white" //default property color prevDayColor: "white" //default
property double prevDayOpacity: 0 //default property double prevDayOpacity: 0 //default
property int prevDayWidth: 0 //default property int prevDayWidth: 0 //default
property string firstBar: "false"
height: constBarHeight height: constBarHeight
z: 110 z: 110
@ -26,7 +27,7 @@ Rectangle{
/*color: barRectangle.prevDayColor /*color: barRectangle.prevDayColor
//getPreviousDayColor(barRectangle.currentDay, barRectangle.days, hangOnToPoint.deviceId, barRectangle.deviceIndex) //getPreviousDayColor(barRectangle.currentDay, barRectangle.days, hangOnToPoint.deviceId, barRectangle.deviceIndex)
opacity: barRectangle.prevDayOpacity opacity: barRectangle.prevDayOpacity
width: barRectangle.prevDayWidth //TODO Scripts.getBarWidth(barRectangle, hangOnToPoint, hangOnToPoint.parent.children); //TEST getNextAndPrevBarWidth before width: barRectangle.prevDayWidth //TODO Scripts.getBarWidth(barRectangle, hangOnToPoint, hangOnToPoint.parent.children);
*/ */
} }
}, },
@ -47,7 +48,7 @@ Rectangle{
anchors.left: hangOnToPoint.horizontalCenter anchors.left: hangOnToPoint.horizontalCenter
color: hangOnToPoint.actionTypeColor color: hangOnToPoint.actionTypeColor
opacity: hangOnToPoint.actionTypeOpacity opacity: hangOnToPoint.actionTypeOpacity
width: Scripts.getBarWidth(barRectangle, hangOnToPoint, hangOnToPoint.parent.children) //TEST getNextAndPrevBarWidth before width: Scripts.getBarWidth(barRectangle, hangOnToPoint, hangOnToPoint.parent.children)
} }
} }
] ]

View file

@ -337,11 +337,13 @@ Rectangle{
} }
function addState(state){ function addState(state){
print("Adding state: " + state);
Scripts.addState(state); Scripts.addState(state);
} }
function setFirstState(firstState){ function setFirstState(firstState){
//print("SETTING FIRST STATE");
var activeStates = Scripts.getActiveStates(); var activeStates = Scripts.getActiveStates();
if(activeStates == null || activeStates.length == 0){ if(activeStates == null || activeStates.length == 0){
@ -366,12 +368,13 @@ Rectangle{
if(!exists){ if(!exists){
//no "off", just set state to the first added state //no "off", just set state to the first added state
pointRect.state = activeStates[0]; pointRect.state = activeStates[0];
return; return;
} }
var previousState = Scripts.getPreviousState(pointRect); var previousState = Scripts.getPreviousState(pointRect);
if(previousState == "" || previousState == "off"){ if(previousState == undefined || previousState == "" || previousState == "off"){
//nothing on/dimmed at the moment, use first added state //nothing on/dimmed at the moment, use first added state
pointRect.state = activeStates[0]; pointRect.state = activeStates[0];
return; return;

View file

@ -182,6 +182,11 @@ import "schedulerscripts.js" as Scripts
} }
] ]
onChildrenChanged: {
//TODO REMOVE
print("-------------- CHILDREN CHANGED ----------------");
}
transitions: [ transitions: [
Transition { Transition {
from: "hiddenLeft" from: "hiddenLeft"
@ -245,8 +250,8 @@ import "schedulerscripts.js" as Scripts
//onEntered: parent.border.color = onHoverColor //onEntered: parent.border.color = onHoverColor
//onExited: parent.border.color = borderColor //onExited: parent.border.color = borderColor
onClicked: { onClicked: {
print("ENDPOINT: " + deviceRow.endPoint); //Scripts.debugPrintDeviceIndex();
Scripts.updateDeviceIndex(); //TODO why is this needed here? (but it is, adding points to empty device will get wrong state otherwise)
//print("Mainrow: " + mainRow.parent.children[0].height); //print("Mainrow: " + mainRow.parent.children[0].height);
var component = Qt.createComponent("ActionPoint.qml") var component = Qt.createComponent("ActionPoint.qml")
var dynamicPoint = component.createObject(deviceRow) var dynamicPoint = component.createObject(deviceRow)
@ -292,6 +297,7 @@ import "schedulerscripts.js" as Scripts
ActionBar{ ActionBar{
id: "continuingBar" id: "continuingBar"
hangOnToPoint: deviceRow hangOnToPoint: deviceRow
firstBar: "true"
state: "continuing" state: "continuing"
} }
@ -308,6 +314,11 @@ import "schedulerscripts.js" as Scripts
function updateContinuingBars(){ function updateContinuingBars(){
Scripts.updateEndsWith(); Scripts.updateEndsWith();
} }
function getDeviceRow(dayIndex, deviceId){
print("CALLING getDeviceRow");
return Scripts.getDeviceRow(dayIndex, deviceId);
}
} }
//} //}
} }

View file

@ -91,8 +91,8 @@ function hasBarChangingPoints(pointList){
} }
function getEndsWith(pointList, dayIndex, deviceId){ //previousDayEndsWithPoint){ function getEndsWith(pointList, dayIndex, deviceId){ //previousDayEndsWithPoint){
print("DAY INDEX: " + dayIndex); //print("DAY INDEX: " + dayIndex);
print("DEVICEID: " + deviceId); //print("DEVICEID: " + deviceId);
var prevPoint = null; var prevPoint = null;
for(var i=0;i<pointList.length;i++){ for(var i=0;i<pointList.length;i++){
if(pointList[i].isPoint != undefined && pointList[i].isPoint == "true"){ if(pointList[i].isPoint != undefined && pointList[i].isPoint == "true"){
@ -109,39 +109,58 @@ function getEndsWith(pointList, dayIndex, deviceId){ //previousDayEndsWithPoint)
} }
//TODO Avoid loop here! //TODO Avoid loop here!
var prevDayDevice = getDeviceRow(dayIndex, deviceId, days, deviceIndex); var prevDayDevice = getDeviceRow(dayIndex, deviceId);
print("PREVDAYHERE: index: " + dayIndex + " id: " + deviceId + " Daydevice: " + prevDayDevice); //print("PREVDAYHERE: index: " + dayIndex + " id: " + deviceId + " Daydevice: " + prevDayDevice);
if(prevDayDevice == undefined){ // || prevDayDevice.endPoint == undefined){ //TODO this is due to an error, but in the future use it to avoid loops if(prevDayDevice == undefined){ // || prevDayDevice.endPoint == undefined){ //TODO this is due to an error, but in the future use it to avoid loops
print("DayDeviceUndefined...................."); print("DayDeviceUndefined....................");
return null; return null;
} }
print("RETURNING A PREV POINT"); //print("RETURNING A PREV POINT");
print("Prev day: " + days[dayIndex].daydate.getDate()); //print("Prev day: " + days[dayIndex].daydate.getDate());
print("Containing: " + prevDayDevice.endPoint); //print("Containing: " + prevDayDevice.endPoint);
return prevDayDevice.endPoint; // previousDayEndsWithPoint; return prevDayDevice.endPoint; // previousDayEndsWithPoint;
} }
if(prevPoint.state == "off"){ if(prevPoint.state == "off"){
return null; return null;
} }
print("RETURNING A POINT"); //print("RETURNING A POINT");
return prevPoint; //.state, only on or dim return prevPoint; //.state, only on or dim
} }
function getPreviousState(currentPointRect){ function getPreviousState(currentPointRect){
var pointList = currentPointRect.parent.children var pointList = currentPointRect.parent.children
var prevPoint = null; var prevPoint = null;
var firstBarStateIndex;
for(var i=0;i<pointList.length;i++){ for(var i=0;i<pointList.length;i++){
if(pointList[i].isPoint != undefined && pointList[i].isPoint == "true" && pointList[i] != currentPointRect){ if(pointList[i].isPoint != undefined && pointList[i].isPoint == "true" && pointList[i] != currentPointRect){
if(pointList[i].x < currentPointRect.x && (prevPoint == null || pointList[i].x > prevPoint.x) && pointList[i].state != "bell"){ //TODO when more than "bell", make dynamic if(pointList[i].x < currentPointRect.x && (prevPoint == null || pointList[i].x > prevPoint.x) && pointList[i].state != "bell"){ //TODO when more than "bell", make dynamic
prevPoint = pointList[i]; prevPoint = pointList[i];
} }
} }
else if(pointList[i].firstBar != undefined && pointList[i].firstBar == "true"){
firstBarStateIndex = i;
}
} }
if(prevPoint == null){ if(prevPoint == null){
//no previous point,see if state continues from previous day
if(firstBarStateIndex != undefined && pointList[firstBarStateIndex].firstBar != undefined){
//print("ENDPOINT!!");
var dayIndex = currentDayIndex - 1;
if(dayIndex == -1){ //too far, begin from end again
dayIndex = days.length - 1;
}
//print("CORRECT DEVICE ID? : " + currentPointRect.deviceRow.deviceId);
var prevDayDevice = currentPointRect.parent.getDeviceRow(dayIndex, currentPointRect.deviceRow.deviceId);
if(prevDayDevice != undefined){
//print("Setting end point: ** " + prevDayDevice.endPoint);
return prevDayDevice.endPoint;
}
}
return ""; return "";
} }
return prevPoint.state; return prevPoint.state;
} }
@ -184,17 +203,27 @@ function updateDeviceIndex(){ //TODO, better way, please...
for(var i=0;i<deviceModel.length;i++){ for(var i=0;i<deviceModel.length;i++){
deviceIndex[deviceModel.get(i).id] = i + startIndex; deviceIndex[deviceModel.get(i).id] = i + startIndex;
} }
//TODO !!!!!! are devices reordered sometimes? Check that! //TODO !!!!!! are devices reordered sometimes? Or even different for different days? Check that!
}
function debugPrintDeviceIndex(){
//TODO debug
if(days.length != undefined){
print("DEBUG: " + days[0].children[0].children.length);
}
for(var key in deviceIndex){
print("** " + key + ": " + deviceIndex[key] + " **");
}
} }
function updateEndsWith(){ function updateEndsWith(){
updateDeviceIndex(); //TODO needed? updateDeviceIndex(); //TODO needed?
print("UPDATEENDSWITH"); //print("UPDATEENDSWITH");
for(var device in deviceIndex){ for(var device in deviceIndex){
//for each device, order doesn't matter //for each device, order doesn't matter
var previousEndPoint = undefined; var previousEndPoint = undefined;
print("DeviceIndex: " + deviceIndex[device]); //print("DeviceIndex: " + deviceIndex[device]);
print("DeviceId: " + device); //print("DeviceId: " + device);
//loop through days, beginning with oldest, in search for the first Point //loop through days, beginning with oldest, in search for the first Point
var startIndex = 0; var startIndex = 0;
@ -218,8 +247,8 @@ function updateEndsWith(){
*/ */
if(deviceRow.hasPoints()){ if(deviceRow.hasPoints()){
print("Dayindex " + dayIndex + " HAS POINTS .........."); //print("Dayindex " + dayIndex + " HAS POINTS ..........");
print("Current day index: " + currentDayIndex); //print("Current day index: " + currentDayIndex);
startIndex = dayIndex; startIndex = dayIndex;
break; break;
} }
@ -232,7 +261,7 @@ function updateEndsWith(){
dayIndex = dayIndex - days.length; dayIndex = dayIndex - days.length;
} }
var deviceRow = days[dayIndex].children[0].children[parseInt(deviceIndex[device])]; //+1 TODO property somehow? var deviceRow = days[dayIndex].children[0].children[parseInt(deviceIndex[device])];
//print("ID " + deviceRow.deviceId); //print("ID " + deviceRow.deviceId);
previousEndPoint = assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, i==0); previousEndPoint = assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, i==0);
@ -240,7 +269,6 @@ function updateEndsWith(){
if(i == days.length-1){ if(i == days.length-1){
//last one, bind the first one too then //last one, bind the first one too then
deviceRow = days[startIndex].children[0].children[parseInt(deviceIndex[device])]; deviceRow = days[startIndex].children[0].children[parseInt(deviceIndex[device])];
print("In last one");
assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, false); assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, false);
} }
} }
@ -266,15 +294,12 @@ function assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, fi
} }
if(deviceRow.hasPoints()){ if(deviceRow.hasPoints()){
print("A Point!!");
//TODO barWidth here... Must depend on first point... bind... somehow...
deviceRow.endPoint = getEndsWith(deviceRow.children, days[dayIndex].daydate.getDay(), deviceRow.deviceId); deviceRow.endPoint = getEndsWith(deviceRow.children, days[dayIndex].daydate.getDay(), deviceRow.deviceId);
previousEndPoint = deviceRow.endPoint; previousEndPoint = deviceRow.endPoint;
deviceRow.continuingBar.prevDayWidth = 0; deviceRow.continuingBar.prevDayWidth = 0;
deviceRow.continuingBar.state = "continuingWithLimitedWidth"; deviceRow.continuingBar.state = "continuingWithLimitedWidth";
} }
else{ else{
//print("NO points");
deviceRow.continuingBar.state = "continuing"; deviceRow.continuingBar.state = "continuing";
deviceRow.endPoint = previousEndPoint; deviceRow.endPoint = previousEndPoint;
deviceRow.continuingBar.prevDayWidth = deviceRow.width; deviceRow.continuingBar.prevDayWidth = deviceRow.width;
@ -309,8 +334,9 @@ function getDeviceRow(dayOfWeek, deviceId){
if(dayListViewComp.children.length == undefined){ if(dayListViewComp.children.length == undefined){
return null; return null;
} }
var pointParent = dayListViewComp.children[0].children[currentDeviceIndex]; //TEST was +1 print("DeviceIndex: " + currentDeviceIndex + " och " + deviceId + ", och sedan " + days.length);
print("Pointparent: " + pointParent); var pointParent = dayListViewComp.children[0].children[currentDeviceIndex];
print("Picked device id (must be same as above): " + dayListViewComp.children[0].children[currentDeviceIndex].deviceId);
return pointParent; return pointParent;
} }
@ -319,7 +345,7 @@ function addWeekPointToGUI(point){
var deviceId = point.deviceId; var deviceId = point.deviceId;
var dayOfWeek = point.day; var dayOfWeek = point.day;
print("Dayofweek: " + dayOfWeek); print("Dayofweek: " + dayOfWeek);
var pointParent = getDeviceRow(dayOfWeek, deviceId, days, deviceIndex); var pointParent = getDeviceRow(dayOfWeek, deviceId);
var component = Qt.createComponent("ActionPoint.qml") var component = Qt.createComponent("ActionPoint.qml")
var dynamicPoint = component.createObject(pointParent) var dynamicPoint = component.createObject(pointParent)