All properties updated when parent/child/sibling is updated
This commit is contained in:
parent
8c788c7b07
commit
e48387c22c
3 changed files with 89 additions and 85 deletions
|
@ -18,7 +18,7 @@ Rectangle{
|
|||
property int absoluteMinute: parseInt(dialog.absoluteMinute, 10)
|
||||
property alias triggerstate: trigger.state
|
||||
property variant parentPoint
|
||||
property int parentPointAbsoluteHour //TEST changed from int, want "undefined"
|
||||
//property int parentPointAbsoluteHour //TEST changed from int, want "undefined"
|
||||
property alias deviceRow: pointRect.parent
|
||||
|
||||
Component.onCompleted: {
|
||||
|
@ -55,11 +55,36 @@ Rectangle{
|
|||
}
|
||||
*/
|
||||
|
||||
|
||||
//reflect changes on parent/siblings:
|
||||
onAbsoluteHourChanged: {
|
||||
updateChanges();
|
||||
//print("ABSOLUTE HOUR CHANGED");
|
||||
Scripts.updateParentAbsoluteHour();
|
||||
Scripts.updateChildPoints();
|
||||
pointRect.x = getAbsoluteXValue();
|
||||
}
|
||||
|
||||
onAbsoluteMinuteChanged: {
|
||||
updateChanges();
|
||||
}
|
||||
|
||||
onFuzzyBeforeChanged: {
|
||||
updateChanges();
|
||||
}
|
||||
|
||||
onFuzzyAfterChanged: {
|
||||
updateChanges();
|
||||
}
|
||||
|
||||
onOffsetChanged: {
|
||||
updateChanges();
|
||||
}
|
||||
|
||||
onDimvalueChanged: {
|
||||
updateChanges();
|
||||
updateBars();
|
||||
}
|
||||
|
||||
onStateChanged: {
|
||||
updateChanges();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -79,10 +104,6 @@ Rectangle{
|
|||
}
|
||||
*/
|
||||
|
||||
onDimvalueChanged: {
|
||||
updateBars();
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: pointRectMouseArea
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
|
@ -118,6 +139,7 @@ Rectangle{
|
|||
|
||||
if(parentPoint != undefined){
|
||||
parentPoint.absoluteHour = parseInt(dialog.absoluteHour, 10);
|
||||
parentPoint.absoluteMinute = parseInt(dialog.absoluteMinute, 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,6 +271,7 @@ Rectangle{
|
|||
]
|
||||
|
||||
Rectangle{
|
||||
//TODO continue fuzzy too into next/prev day
|
||||
width: minutesToTimelineUnits(fuzzyAfter + fuzzyBefore)
|
||||
height: constBarHeight
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
@ -321,6 +344,14 @@ Rectangle{
|
|||
//pointRect.xvalue = pointRect.x;
|
||||
trigger.state = "sunrise";
|
||||
}
|
||||
Scripts.updateParentWithCurrentValues();
|
||||
Scripts.updateChildPoints();
|
||||
}
|
||||
|
||||
function updateChanges(){
|
||||
Scripts.updateParentWithCurrentValues();
|
||||
Scripts.updateChildPoints();
|
||||
pointRect.x = getAbsoluteXValue();
|
||||
}
|
||||
|
||||
function getLastPointColor(){
|
||||
|
@ -377,6 +408,14 @@ Rectangle{
|
|||
Scripts.addState(state);
|
||||
}
|
||||
|
||||
function setActiveStates(activeStates){
|
||||
Scripts.setActiveStates(activeStates);
|
||||
}
|
||||
|
||||
function getActiveStates(){
|
||||
return Scripts.getActiveStates();
|
||||
}
|
||||
|
||||
function setFirstState(firstState){
|
||||
|
||||
//print("SETTING FIRST STATE");
|
||||
|
@ -455,12 +494,12 @@ Rectangle{
|
|||
//print("GETTING TICKED");
|
||||
index = Scripts.getOffsetWeekday(index);
|
||||
if(pointRect.deviceRow.parent == undefined || pointRect.deviceRow.parent.parent == undefined){ //to get rid of warnings on initialization
|
||||
print("UNDEFINED, should only be in beginning");
|
||||
//undefined, should only be in the beginning
|
||||
return "unticked.png";
|
||||
}
|
||||
var originalPoint = pointRect; // pointRect.deviceRow.parent.parent;
|
||||
var originalPoint = pointRect;
|
||||
if(pointRect.parentPoint != undefined){
|
||||
originalPoint = pointRect.parentPoint; //.deviceRow.parent.parent;
|
||||
originalPoint = pointRect.parentPoint;
|
||||
}
|
||||
if(index == pointRect.deviceRow.parent.parent.daydate.getDay()){ //TODO property or so
|
||||
//current day should always be ticked
|
||||
|
|
|
@ -395,27 +395,14 @@
|
|||
anchors.leftMargin: 10
|
||||
anchors.top: fuzzyPanel.bottom
|
||||
anchors.topMargin: 10
|
||||
//property alias absoluteHourText: inputAbsoluteHourText.text
|
||||
//property alias absoluteMinuteText: inputAbsoluteMinuteText.text
|
||||
|
||||
Row{
|
||||
Text{
|
||||
/*id: textAbsolute
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 5
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 5
|
||||
*/
|
||||
text: "Time:"
|
||||
}
|
||||
|
||||
Rectangle{
|
||||
id: inputAbsoluteHour
|
||||
//property alias absoluteHour: inputAbsoluteHourText.text
|
||||
/*anchors.left: textOffset.right
|
||||
anchors.leftMargin: 5
|
||||
anchors.verticalCenter: textOffset.verticalCenter
|
||||
*/
|
||||
width: 35
|
||||
height: inputAbsoluteHourText.height
|
||||
border.width: 1
|
||||
|
@ -431,11 +418,6 @@
|
|||
event.accepted = true;
|
||||
inputAbsoluteMinuteText.focus = true;
|
||||
}
|
||||
//text: "0"
|
||||
//onChanged:{
|
||||
// print("DIALOG HOUR CHANGED");
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
Binding {
|
||||
|
@ -447,21 +429,12 @@
|
|||
}
|
||||
|
||||
Text{
|
||||
/*id: textOffsetUnit
|
||||
anchors.left: inputOffset.right
|
||||
anchors.leftMargin: 5
|
||||
anchors.verticalCenter: textOffset.verticalCenter
|
||||
*/
|
||||
text: ":"
|
||||
}
|
||||
|
||||
Rectangle{
|
||||
id: inputAbsoluteMinute
|
||||
property alias absoluteMinute: inputAbsoluteMinuteText.text
|
||||
/*anchors.left: textOffset.right
|
||||
anchors.leftMargin: 5
|
||||
anchors.verticalCenter: textOffset.verticalCenter
|
||||
*/
|
||||
width: 35
|
||||
height: inputAbsoluteMinuteText.height
|
||||
border.width: 1
|
||||
|
|
|
@ -13,6 +13,10 @@ function getActiveStates(){
|
|||
return activeStates;
|
||||
}
|
||||
|
||||
function setActiveStates(newActiveStates){
|
||||
activeStates = newActiveStates;
|
||||
}
|
||||
|
||||
//Days:
|
||||
var weekday_name_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
|
||||
var currentDayIndex = 6; //Today...
|
||||
|
@ -108,23 +112,16 @@ function getEndsWith(pointList, dayIndex, deviceId){ //previousDayEndsWithPoint)
|
|||
dayIndex = days.length - 1;
|
||||
}
|
||||
|
||||
//TODO Avoid loop here!
|
||||
var prevDayDevice = getDeviceRow(dayIndex, deviceId);
|
||||
//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
|
||||
print("DayDeviceUndefined....................");
|
||||
return null;
|
||||
}
|
||||
//print("RETURNING A PREV POINT");
|
||||
//print("Prev day: " + days[dayIndex].daydate.getDate());
|
||||
//print("Containing: " + prevDayDevice.endPoint);
|
||||
return prevDayDevice.endPoint; // previousDayEndsWithPoint;
|
||||
}
|
||||
if(prevPoint.state == "off"){
|
||||
return null;
|
||||
}
|
||||
//print("RETURNING A POINT");
|
||||
return prevPoint; //.state, only on or dim
|
||||
return prevPoint; //only on or dim
|
||||
}
|
||||
|
||||
function getPreviousState(currentPointRect){
|
||||
|
@ -145,16 +142,13 @@ function getPreviousState(currentPointRect){
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
@ -193,10 +187,8 @@ function updateDeviceIndex(){ //TODO, better way, please...
|
|||
var startIndex = 0;
|
||||
for(var i=0;i<days[0].children[0].children.length;i++){
|
||||
var deviceListItem = days[0].children[0].children[i];
|
||||
//print("** DEVICELISTITEM: ** " + deviceListItem);
|
||||
if(deviceListItem.deviceId != undefined){
|
||||
startIndex = i;
|
||||
//print("** CORRECT DEVICELISTITEM **");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -223,37 +215,15 @@ function debugPrintDeviceIndex(){
|
|||
|
||||
function updateEndsWith(){
|
||||
updateDeviceIndex(); //TODO needed?
|
||||
//print("UPDATEENDSWITH");
|
||||
for(var device in deviceIndex){
|
||||
//for each device, order doesn't matter
|
||||
var previousEndPoint = undefined;
|
||||
//print("DeviceIndex: " + deviceIndex[device]);
|
||||
//print("DeviceId: " + device);
|
||||
|
||||
//loop through days, beginning with oldest, in search for the first Point
|
||||
var startIndex = 0;
|
||||
for(var dayIndex=0;dayIndex<days.length;dayIndex++){
|
||||
var deviceRow = days[dayIndex].children[0].children[(parseInt(deviceIndex[device]))]; //+1 TODO property somehow? Or function...
|
||||
/*
|
||||
* DEBUG
|
||||
print("day: " + days[dayIndex]);
|
||||
print("child zero: " + days[dayIndex].children[0]);
|
||||
print("deviceRow: " + deviceRow);
|
||||
print("index: " + (parseInt(deviceIndex[device])));
|
||||
print("Length: " + days[dayIndex].children[0].children.length);
|
||||
*/
|
||||
//print("deviceRow, id: " + deviceRow.deviceId);
|
||||
//print("deviceRow: " + deviceRow.children.length);
|
||||
|
||||
/*
|
||||
for (var myKey in days[dayIndex].children[0]) {
|
||||
print(myKey + " == (" + days[dayIndex].children[0][myKey] + ")");
|
||||
}
|
||||
*/
|
||||
|
||||
if(deviceRow.hasPoints()){
|
||||
//print("Dayindex " + dayIndex + " HAS POINTS ..........");
|
||||
//print("Current day index: " + currentDayIndex);
|
||||
startIndex = dayIndex;
|
||||
break;
|
||||
}
|
||||
|
@ -267,7 +237,6 @@ function updateEndsWith(){
|
|||
}
|
||||
|
||||
var deviceRow = days[dayIndex].children[0].children[parseInt(deviceIndex[device])];
|
||||
//print("ID " + deviceRow.deviceId);
|
||||
|
||||
previousEndPoint = assignContinuingBarProperties(deviceRow, previousEndPoint, dayIndex, i==0);
|
||||
|
||||
|
@ -341,7 +310,6 @@ function getDeviceRow(dayOfWeek, deviceId){
|
|||
}
|
||||
print("DeviceIndex: " + currentDeviceIndex + " och " + deviceId + ", och sedan " + days.length);
|
||||
var pointParent = dayListViewComp.children[0].children[currentDeviceIndex];
|
||||
print("Picked device id (must be same as above): " + dayListViewComp.daydate); //children[0].children[currentDeviceIndex].deviceId);
|
||||
return pointParent;
|
||||
}
|
||||
|
||||
|
@ -364,7 +332,8 @@ function addWeekPointToGUI(point){
|
|||
dynamicPoint.addState("off");
|
||||
dynamicPoint.addState("dim");
|
||||
dynamicPoint.addState("bell");
|
||||
dynamicPoint.setFirstState("dim");
|
||||
dynamicPoint.setFirstState("dim");
|
||||
//also: states, fuzzy * 2, trigger, offset, dimvalue
|
||||
}
|
||||
|
||||
//per point
|
||||
|
@ -387,14 +356,14 @@ function addChildPoint(index, point){
|
|||
function removeChildPoint(index){
|
||||
print("INDEX BEFORE REMOVE: " + childPoints[index]);
|
||||
var toBeRemoved = childPoints[index];
|
||||
delete childPoints[index]; // = undefined;
|
||||
delete childPoints[index];
|
||||
toBeRemoved.remove("true");
|
||||
print("INDEX AFTER REMOVE: " + childPoints[index]);
|
||||
}
|
||||
|
||||
function removeParentPoint(newParentPoint){
|
||||
print("Removing parent point...");
|
||||
delete childPoints[newParentPoint.deviceRow.parent.parent.daydate.getDay()]; //TODO remove this: = undefined; //remove the current point from the child list
|
||||
delete childPoints[newParentPoint.deviceRow.parent.parent.daydate.getDay()]; //remove the current point from the child list
|
||||
newParentPoint.setChildPoints(childPoints); //copy child list to current child (making it a parent)
|
||||
newParentPoint.parentPoint = undefined;
|
||||
updateParentsInChildList(newParentPoint); //update all other child points (if any) with the current point as their parent
|
||||
|
@ -415,12 +384,26 @@ function updateParentsInChildList(newParentPoint){
|
|||
function updateChildPoints(parentPoint){
|
||||
for(var point in childPoints){
|
||||
childPoints[point].absoluteHour = pointRect.absoluteHour;
|
||||
childPoints[point].absoluteMinute = pointRect.absoluteMinute;
|
||||
childPoints[point].fuzzyBefore = pointRect.fuzzyBefore;
|
||||
childPoints[point].fuzzyAfter = pointRect.fuzzyAfter;
|
||||
childPoints[point].offset = pointRect.offset;
|
||||
childPoints[point].triggerstate = pointRect.triggerstate;
|
||||
childPoints[point].dimvalue = pointRect.dimvalue;
|
||||
childPoints[point].state = pointRect.state;
|
||||
}
|
||||
}
|
||||
|
||||
function updateParentAbsoluteHour(){
|
||||
function updateParentWithCurrentValues(){
|
||||
if(pointRect.parentPoint != undefined){
|
||||
pointRect.parentPoint.absoluteHour = pointRect.absoluteHour; //TODO check if this can be done with binding without loops...
|
||||
pointRect.parentPoint.absoluteMinute = pointRect.absoluteMinute;
|
||||
pointRect.parentPoint.fuzzyBefore = pointRect.fuzzyBefore;
|
||||
pointRect.parentPoint.fuzzyAfter = pointRect.fuzzyAfter;
|
||||
pointRect.parentPoint.offset = pointRect.offset;
|
||||
pointRect.parentPoint.triggerstate = pointRect.triggerstate;
|
||||
pointRect.parentPoint.dimvalue = pointRect.dimvalue;
|
||||
pointRect.parentPoint.state = pointRect.state;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,19 +462,28 @@ function deviceEnabled(deviceId, enabled){
|
|||
|
||||
function createChildPoint(index, pointRect, deviceId){
|
||||
index = getDayIndexForDayOfWeek(index);
|
||||
var deviceRow = getDeviceRow(index, deviceId); //TODO correct index?
|
||||
var component = Qt.createComponent("ActionPoint.qml")
|
||||
var dynamicPoint = component.createObject(deviceRow)
|
||||
dynamicPoint.absoluteHour = pointRect.absoluteHour
|
||||
//print("The absolute hour is: " + pointRect.absoluteHour);
|
||||
dynamicPoint.absoluteMinute = 30 //TODO
|
||||
var deviceRow = getDeviceRow(index, deviceId);
|
||||
var component = Qt.createComponent("ActionPoint.qml");
|
||||
var dynamicPoint = component.createObject(deviceRow);
|
||||
dynamicPoint.absoluteHour = pointRect.absoluteHour;
|
||||
dynamicPoint.absoluteMinute = pointRect.absoluteMinute;
|
||||
dynamicPoint.fuzzyBefore = pointRect.fuzzyBefore;
|
||||
dynamicPoint.fuzzyAfter = pointRect.fuzzyAfter;
|
||||
dynamicPoint.offset = pointRect.offset;
|
||||
dynamicPoint.triggerstate = pointRect.triggerstate;
|
||||
dynamicPoint.dimvalue = pointRect.dimvalue;
|
||||
|
||||
dynamicPoint.parentPoint = pointRect
|
||||
dynamicPoint.x = dynamicPoint.getAbsoluteXValue();
|
||||
dynamicPoint.border.color = "blue"
|
||||
dynamicPoint.setActiveStates(pointRect.getActiveStates());
|
||||
|
||||
/*
|
||||
dynamicPoint.addState("on"); //TODO, add same states as in pointRect
|
||||
dynamicPoint.addState("off");
|
||||
dynamicPoint.addState("dim");
|
||||
dynamicPoint.addState("bell");
|
||||
*/
|
||||
dynamicPoint.setFirstState(pointRect.state);
|
||||
//print("RETURNING " + dynamicPoint);
|
||||
return dynamicPoint;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue