Changeset 645ef2
- Timestamp:
- 01/17/12 15:18:03 (4 months ago)
- Branches:
- ('master', 'deebf2045e7119c339412580f37a1e653f7d5715')('controller-upgrade', '00f95d22e12d96ef089e0902ef62ae8ce841dc6f')
- Children:
- deebf2045e7119c339412580f37a1e653f7d5715
- Parents:
- 5ce0b81e39f7ef7fca38b915ed42b6d3bef1ce91
- git-author:
- Stefan Persson <stefan.persson@telldus.se>2012-01-17 15:10:46+01:00
- git-committer:
- Stefan Persson <stefan.persson@telldus.se>2012-01-17 15:18:03+01:00
- Location:
- telldus-gui/Plugins
- Files:
-
- 6 edited
-
Sensors/SensorList.qml (modified) (4 diffs)
-
Sensors/SensorView.qml (modified) (1 diff)
-
Sensors/__init__.js (modified) (4 diffs)
-
Sensors/sensor.cpp (modified) (4 diffs)
-
Sensors/sensor.h (modified) (3 diffs)
-
Settings/settings.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
telldus-gui/Plugins/Sensors/SensorList.qml
r64e2b3 r645ef2 5 5 id: sensorList 6 6 spacing: 1 7 8 SensorView {9 id: sensorView10 }11 7 12 8 BorderImage { … … 23 19 } 24 20 HeaderTitle { 21 text: "" 22 anchors.right: sensorid.left 23 visible: main.state == "EDIT" 24 width: 50 25 } 26 HeaderTitle { 27 id: sensorid 25 28 text: "ID" 26 29 anchors.right: modelTitle.left … … 59 62 Repeater { 60 63 model: sensorModel 61 delegate: sensorView64 delegate: SensorView{ state: main.state == "EDIT" ? 'EDIT' : ''} 62 65 } 63 66 Row{ … … 72 75 } 73 76 else{ 74 main.state ="VIEW"77 main.state = "VIEW" 75 78 } 76 79 } 77 80 } 78 /*79 Rectangle {80 //TODO should this button exist at all, or always save?81 width: 5082 height: 2083 visible: main.state == "EDIT"84 Text{85 anchors.centerIn: parent86 text: "Cancel"87 }88 MouseArea{89 anchors.fill: parent90 onClicked: {91 main.state ="VIEW"92 }93 }94 }95 */96 81 } 97 82 } -
telldus-gui/Plugins/Sensors/SensorView.qml
r99c2b0 r645ef2 2 2 import QtDesktop 0.1 3 3 4 Component { 5 id: sensorView 6 Item{ 7 id: sensorViewItem 8 visible: main.state == "EDIT" || modelData.showInList 9 height: childrenRect.height 4 Item{ 5 id: sensorViewItem 6 visible: state == "EDIT" || modelData.showInList 7 height: childrenRect.height 8 width: parent ? parent.width : 0 9 10 states:[ 11 State { 12 name: "EDIT" 13 } 14 ] 15 16 BorderImage { 17 source: "row_bg.png" 18 border.left: 5; border.top: 5 19 border.right: 5; border.bottom: 5 20 height: sensorInfo.height 10 21 width: parent.width 11 22 12 property string state: main.state 13 onStateChanged: { 14 if (state != "EDIT") { 15 modelData.setName(nameEdit.text) 23 Text { 24 visible: sensorViewItem.state != "EDIT" 25 anchors.left: parent.left 26 anchors.leftMargin: 15 27 height: 40 28 verticalAlignment: Text.AlignVCenter 29 text: modelData.name == '' ? '<unnamed>' : modelData.name; 30 color: "#004275" 31 } 32 TextField { 33 id: nameEdit 34 visible: sensorViewItem.state == "EDIT" 35 anchors.left: parent.left 36 anchors.leftMargin: 15 37 anchors.top: parent.top 38 anchors.topMargin: (40-nameEdit.height)/2 39 text: modelData.name; 40 placeholderText: 'Enter a name' 41 onTextChanged: modelData.name = text 42 } 43 44 Text{ 45 anchors.right: sensorid.left 46 visible: sensorViewItem.state == "EDIT" 47 height: 40 48 verticalAlignment: Text.AlignVCenter 49 text: "Delete" 50 font.underline: true 51 color: "#004275" 52 width: 50 53 MouseArea{ 54 anchors.fill: parent 55 onClicked: { 56 confirmDeletion.visible = true; 57 } 58 } 59 } 60 Text{ 61 id: sensorid 62 anchors.right: model.left 63 visible: sensorViewItem.state == "EDIT" 64 height: 40 65 verticalAlignment: Text.AlignVCenter 66 text: modelData.id 67 color: "#004275" 68 width: 50 69 } 70 Text{ 71 id: model 72 anchors.right: visibleinlistcheckbox.left 73 visible: sensorViewItem.state == "EDIT" 74 height: 40 75 verticalAlignment: Text.AlignVCenter 76 text: modelData.model 77 color: "#004275" 78 width: 100 79 } 80 Item { 81 id: visibleinlistcheckbox 82 height: 40 83 width: 100 84 anchors.right: sensorInfo.left 85 CheckBox { 86 id: checkBox 87 anchors.centerIn: parent 88 width: checkBox.height 89 visible: sensorViewItem.state == "EDIT" 90 checked: modelData.showInList 91 onClicked: modelData.setShowInList(!modelData.showInList) 16 92 } 17 93 } 18 94 19 BorderImage { 20 source: "row_bg.png" 21 border.left: 5; border.top: 5 22 border.right: 5; border.bottom: 5 23 height: sensorInfo.height 24 width: parent.width 25 26 Text { 27 visible: main.state == "VIEW" 28 anchors.left: parent.left 29 anchors.leftMargin: 15 30 height: 40 31 verticalAlignment: Text.AlignVCenter 32 text: modelData.name == '' ? '<unnamed>' : modelData.name; 33 color: "#004275" 95 Column { 96 id: sensorInfo 97 anchors.right: parent.right 98 width: 250 99 SensorValue { 100 visible: modelData.hasTemperature 101 text: visible ? modelData.sensorValue(1).value + '°C' : '' 102 icon: "icon_temp.png" 103 lastUpdated: visible ? modelData.sensorValue(1).lastUpdated : new Date() 34 104 } 35 TextField { 36 id: nameEdit 37 visible: main.state == "EDIT" 38 anchors.left: parent.left 39 anchors.leftMargin: 15 40 anchors.top: parent.top 41 anchors.topMargin: (40-nameEdit.height)/2 42 text: modelData.name; 43 placeholderText: 'Enter a name' 44 } 45 Text{ 46 anchors.right: model.left 47 visible: main.state == "EDIT" 48 height: 40 49 verticalAlignment: Text.AlignVCenter 50 text: modelData.id 51 color: "#004275" 52 width: 50 53 } 54 Text{ 55 id: model 56 anchors.right: visibleinlistcheckbox.left 57 visible: main.state == "EDIT" 58 height: 40 59 verticalAlignment: Text.AlignVCenter 60 text: modelData.model 61 color: "#004275" 62 width: 100 63 } 64 Item { 65 id: visibleinlistcheckbox 66 height: 40 67 width: 100 68 anchors.right: sensorInfo.left 69 CheckBox { 70 id: checkBox 71 anchors.centerIn: parent 72 width: checkBox.height 73 visible: main.state == "EDIT" 74 checked: modelData.showInList 75 onClicked: modelData.setShowInList(!modelData.showInList) 76 } 77 } 78 79 Column { 80 id: sensorInfo 81 anchors.right: parent.right 82 width: 250 83 SensorValue { 84 visible: modelData.hasTemperature 85 text: visible ? modelData.sensorValue(1).value + '°C' : '' 86 icon: "icon_temp.png" 87 lastUpdated: visible ? modelData.sensorValue(1).lastUpdated : new Date() 88 } 89 SensorValue { 90 visible: modelData.hasHumidity 91 text: visible ? modelData.sensorValue(2).value + '%' : '' 92 icon: "icon_humidity.png" 93 lastUpdated: visible ? modelData.sensorValue(2).lastUpdated : new Date() 94 } 105 SensorValue { 106 visible: modelData.hasHumidity 107 text: visible ? modelData.sensorValue(2).value + '%' : '' 108 icon: "icon_humidity.png" 109 lastUpdated: visible ? modelData.sensorValue(2).lastUpdated : new Date() 95 110 } 96 111 } 97 112 } 113 114 Dialog{ 115 id: confirmDeletion 116 modal: true 117 title: "Confirm deletion" 118 Text{ 119 id: descriptionHeadline 120 text:"Delete this sensor?" 121 font.bold: true 122 } 123 Text{ 124 id: descriptionText 125 anchors.top: descriptionHeadline.bottom 126 anchors.topMargin: 10 127 width: parent.width - 20 128 anchors.left: parent.left 129 anchors.leftMargin: 10 130 text: "Please note that a sensor that is still transmitting will reappear here again, but it will be hidden in the list by default." 131 wrapMode: Text.Wrap 132 } 133 134 onAccepted: { 135 deleteSensor.callWith(modelData.protocol, modelData.model, modelData.id); 136 } 137 } 98 138 } -
telldus-gui/Plugins/Sensors/__init__.js
ref9a20 r645ef2 7 7 8 8 com.telldus.sensors = function() { 9 var sensorList = new com.telldus.qml.array(); 10 9 var sensorList; 11 10 function init() { 12 11 var sensorData = 0; 12 sensorList = loadSensorModel(); 13 sensorList.rowsRemoved.connect(function(){saveSensorModel();}); 14 sensorList.rowsInserted.connect(function(){saveSensorModel();}); 15 13 16 while(sensorData = com.telldus.core.sensor()) { 14 17 var p = sensorData["protocol"]; … … 20 23 if (types & type) { 21 24 sensorValue = com.telldus.core.sensorValue(p, m, id, type); 22 sensorEvent(p, m, id, type, sensorValue["value"], sensorValue["timestamp"] );25 sensorEvent(p, m, id, type, sensorValue["value"], sensorValue["timestamp"], true); 23 26 } 24 27 } … … 29 32 30 33 com.telldus.core.sensorEvent.connect(sensorEvent); 31 view = new com.telldus.qml.view({}); 34 view = new com.telldus.qml.view({ 35 deleteSensor: deleteSensor 36 }); 32 37 33 38 view.setProperty('sensorModel', sensorList); 39 saveSensorModel(); 34 40 view.load("main.qml"); 35 41 application.addWidget("sensors.gui", "icon.png", view); 36 42 } 37 43 38 function sensorEvent(protocol, model, id, dataType, value, timestamp) { 44 function createSensor(protocol, model, id, name, showInList){ 45 var sensor = new com.telldus.sensors.sensor(); 46 sensor.protocol = protocol; 47 sensor.model = model; 48 sensor.id = id; 49 sensor.name = name; 50 sensor.nameChanged.connect(function() { saveSensorModel(); }); 51 sensor.showInList = showInList; 52 sensor.showInListChanged.connect(function() { saveSensorModel(); }); 53 return sensor; 54 } 55 56 function deleteSensor(protocol, model, id){ 57 var i = 0; 58 var found = false; 59 for (; i < sensorList.length; ++i) { 60 if (sensorList.get(i).protocol != protocol) { 61 continue; 62 } 63 if (sensorList.get(i).model != model) { 64 continue; 65 } 66 if (sensorList.get(i).id != id) { 67 continue; 68 } 69 found = true; 70 break; 71 } 72 if(found){ 73 sensorList.removeLater(i); 74 } 75 } 76 77 function loadSensorModel(){ 78 var settings = new com.telldus.settings(); 79 var sensors = new com.telldus.qml.array(); 80 81 var sensorProperties = settings.value("sensors", ""); 82 if(sensorProperties){ 83 for (var i = 0; i < sensorProperties.length; i++) { 84 var sensor = createSensor(sensorProperties[i].protocol, sensorProperties[i].model, sensorProperties[i].id, sensorProperties[i].name, sensorProperties[i].showInList=="true"); 85 for (var j = 0; j < sensorProperties[i].values.length; j++) { 86 sensor.setValue(sensorProperties[i].values[j].type, sensorProperties[i].values[j].value, sensorProperties[i].values[j].lastUpdated) 87 } 88 sensors.push(sensor); 89 } 90 } 91 return sensors; 92 } 93 94 function saveSensorModel(){ 95 var settings = new com.telldus.settings(); 96 var sensorProperties = new Array(); 97 98 for (var i = 0; i < sensorList.length; ++i) { 99 var sensor = sensorList.get(i); 100 101 var allValues = new Array(); 102 if(sensor.hasHumidity){ 103 var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_HUMIDITY); 104 var value = {type: com.telldus.core.TELLSTICK_HUMIDITY, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value}; 105 allValues.push(value); 106 } 107 if(sensor.hasTemperature){ 108 var sensorValue = sensor.sensorValue(com.telldus.core.TELLSTICK_TEMPERATURE); 109 var value = {type: com.telldus.core.TELLSTICK_TEMPERATURE, lastUpdated: sensorValue.lastUpdated, value: sensorValue.value}; 110 allValues.push(value); 111 } 112 113 var sensorProp = {protocol:sensor.protocol, model:sensor.model, id:sensor.id, values:allValues, name:sensor.name, showInList:sensor.showInList}; 114 sensorProperties.push(sensorProp); 115 } 116 117 settings.setValue("sensors", sensorProperties); 118 } 119 120 function sensorEvent(protocol, model, id, dataType, value, timestamp, avoidSave) { 121 39 122 var sensor = 0; 40 123 for (var i = 0; i < sensorList.length; ++i) { … … 53 136 54 137 if (!sensor) { 55 sensor = new com.telldus.sensors.sensor(); 56 sensor.protocol = protocol; 57 sensor.model = model; 58 sensor.id = id; 59 sensor.showInList = false; 138 sensor = createSensor(protocol, model, id, "", false); 60 139 sensorList.push(sensor); 61 print("Create new");62 } else {63 print("Update");64 140 } 65 141 66 print("Sensor event", protocol, model, id, dataType, value, timestamp);67 142 sensor.setValue(dataType, value, timestamp); 143 144 if(!avoidSave){ 145 saveSensorModel(); 146 } 68 147 } 69 148 -
telldus-gui/Plugins/Sensors/sensor.cpp
r99c2b0 r645ef2 18 18 d = new PrivateData; 19 19 d->id = 0; 20 d->showInList = false; 20 21 } 21 22 … … 51 52 52 53 void Sensor::setName(const QString &name) { 54 if (name == d->name) { 55 return; 56 } 53 57 d->name = name; 54 58 emit nameChanged(); … … 68 72 } 69 73 70 SensorValue* Sensor::sensorValue(int type) {74 QObject * Sensor::sensorValue(int type) { 71 75 return (d->values.contains(type) ? d->values[type] : 0); 72 76 } … … 91 95 92 96 bool Sensor::showInList() const{ 93 //TODO showInList and name must be persistent...94 97 return d->showInList; 95 98 } -
telldus-gui/Plugins/Sensors/sensor.h
ref9a20 r645ef2 18 18 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 19 19 Q_PROPERTY(QString protocol READ protocol WRITE setProtocol NOTIFY protocolChanged) 20 Q_PROPERTY(bool showInList READ showInList NOTIFY showInListChanged)20 Q_PROPERTY(bool showInList READ showInList WRITE setShowInList NOTIFY showInListChanged) 21 21 22 22 public: … … 33 33 34 34 QString name() const; 35 //void setName(const QString &name);36 35 37 36 QString protocol() const; … … 41 40 bool showInList() const; 42 41 43 Q_INVOKABLE SensorValue*sensorValue(int type);42 Q_INVOKABLE QObject *sensorValue(int type); 44 43 Q_INVOKABLE void setValue(int type, const QString &value, const QDateTime ×tamp); 45 44 Q_INVOKABLE void setName(const QString &name); -
telldus-gui/Plugins/Settings/settings.cpp
r6281cf r645ef2 27 27 d->s.setValue("size", list.size()); 28 28 d->s.setValue("type", "array"); 29 //d->s.beginWriteArray("list"); //TODO write or read? What prefix? 29 30 for (int i = 0; i < list.size(); ++i) { 30 d->s.setArrayIndex(i);31 //d->s.setArrayIndex(i); 31 32 this->setValue(QString::number(i), list.at(i)); 32 33 } 34 //d->s.endArray(); 33 35 d->s.endGroup(); 34 36
Note: See TracChangeset
for help on using the changeset viewer.
