Checkboxes updated (correctly?) when adding points to additional weekdays

This commit is contained in:
Stefan Persson 2011-02-04 13:25:59 +00:00
parent a81cd9370a
commit 3dbcf5f331
3 changed files with 57 additions and 17 deletions

View file

@ -19,7 +19,6 @@ Rectangle{
property alias triggerstate: trigger.state
property variant parentPoint
property int parentPointAbsoluteHour //TEST changed from int, want "undefined"
property variant childPoints: []
property alias deviceRow: pointRect.parent
Component.onCompleted: {
@ -422,7 +421,7 @@ Rectangle{
pointRect.state = "off"; //previous point should be "on" or "dim"
}
function remove(){
function remove(keepDialogOpen){
if(pointRect.hangOnToBar != null){
hangOnToBar.destroy();
}
@ -431,7 +430,9 @@ Rectangle{
var pointList = pointRect.parent.children;
var deviceRow = pointRect.deviceRow;
pointRect.destroy();
dialog.hide();
if(keepDialogOpen == undefined){
dialog.hide();
}
deviceRow.updateContinuingBars()
}
@ -443,20 +444,19 @@ Rectangle{
}
function getTickedImageSource(index){
//3 fall
//alwaysticked, unticked, ticked
if(pointRect.deviceRow.parent == undefined || pointRect.deviceRow.parent.parent == undefined){ //to get rid of warnings on initialization
return "";
print("UNDEFINED, should only be in beginning");
return "unticked.png";
}
var originalDay = pointRect.deviceRow.parent.parent.daydate.getDay();
var originalPoint = pointRect; // pointRect.deviceRow.parent.parent;
if(pointRect.parentPoint != undefined){
originalDay = pointRect.parentPoint.deviceRow.parent.parent.daydate.getDay();
originalPoint = pointRect.parentPoint; //.deviceRow.parent.parent;
}
if(index == originalDay){ //TODO change, must be stored with the point insted, it's "original day" (if clicked on on another day for instance)
if(index == originalPoint.deviceRow.parent.parent.daydate.getDay()){ //TODO property or so
//current day (where the point was originally placed) should always be ticked
return "alwaysticked.png";
}
else if(pointRect.childPoints[index] == undefined){
else if(originalPoint.getChildPoint(index) == undefined){
return "unticked.png";
}
else{
@ -465,21 +465,32 @@ Rectangle{
}
function toggleTickedWeekDay(index){
var originalPointDay = pointRect.deviceRow.parent.parent.daydate.getDay(); //TODO change, must be stored with the point insted, it's "original day" (if clicked on on another day for instance)
var originalPoint = pointRect;
if(pointRect.parentPoint != undefined){
originalPointDay = pointRect.parentPoint.deviceRow.parent.parent.daydate.getDay();
originalPoint = pointRect.parentPoint;
}
if(index == originalPointDay){
if(index == originalPoint.deviceRow.parent.parent.daydate.getDay()){
//cannot change this, do nothing
return;
}
if(pointRect.childPoints[index] == undefined){
if(originalPoint.getChildPoint(index) == undefined){
print("CREATE NEW POINT");
pointRect.childPoints = deviceRow.createChildPoint(index, pointRect, deviceRow.deviceId);
originalPoint.addChildPoint(index, deviceRow.createChildPoint(index, pointRect, deviceRow.deviceId));
}
else{
print("REMOVE A POINT");
pointRect.childPoints[index].remove();
originalPoint.removeChildPoint(index);
}
}
function getChildPoint(index){
return Scripts.getChildPoint(index);
}
function addChildPoint(index, point){
Scripts.addChildPoint(index, point);
}
function removeChildPoint(index){
Scripts.removeChildPoint(index);
}
}

View file

@ -589,6 +589,10 @@
height: 30
Image{
id: tickBox
property int dialogOpacity: container.opacity
onDialogOpacityChanged: {
tickBox.source = actionPoint.getTickedImageSource(index)
}
height: 14
width: 14
source: actionPoint.getTickedImageSource(index)
@ -596,6 +600,7 @@
anchors.fill: parent
onClicked: {
actionPoint.toggleTickedWeekDay(index)
tickBox.source = actionPoint.getTickedImageSource(index)
}
}
}

View file

@ -367,6 +367,29 @@ function addWeekPointToGUI(point){
dynamicPoint.setFirstState("dim");
}
//per point
var childPoints = [];
function getChildPoint(index){
//print("INDEX");
//print(index + ": " + childPoints[index]);
return childPoints[index];
}
function addChildPoint(index, point){
childPoints[index] = point;
}
function removeChildPoint(index){
print("INDEX BEFORE REMOVE: " + childPoints[index]);
var test = childPoints[index];
childPoints[index] = undefined;
test.remove("true");
print("INDEX AFTER REMOVE: " + childPoints[index]);
}
//end per point
//must be run in "main"
function getDayIndexForDayOfWeek(dayOfWeek){
var offset = days[0].daydate.getDay();
@ -382,7 +405,7 @@ function getDayIndexForDayOfWeek(dayOfWeek){
//TODO move, pragma safe:
function getFirstPointWidth(deviceRow){
var pointList = deviceRow.children;
var pointList = deviceRow.children; //TODO should really try to avoid using "children"... make own list instead?
var firstX = deviceRow.width;
var pointWidth = 0;
for(var i=0;i<pointList.length;i++){
@ -420,5 +443,6 @@ function createChildPoint(index, pointRect, deviceId){
dynamicPoint.addState("dim");
dynamicPoint.addState("bell");
dynamicPoint.setFirstState(pointRect.state);
print("RETURNING " + dynamicPoint);
return dynamicPoint;
}