Possibility to add/remove sensors from list, and change their names. Not yet persistent.
This commit is contained in:
parent
2feeb81f37
commit
8e377a12bc
5 changed files with 191 additions and 30 deletions
|
@ -14,6 +14,7 @@ Item {
|
|||
}
|
||||
Text {
|
||||
id: text
|
||||
font.weight: Font.Bold
|
||||
anchors.left: icon.right
|
||||
anchors.leftMargin: 10
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
|
|
@ -56,6 +56,7 @@ com.telldus.sensors = function() {
|
|||
sensor.protocol = protocol;
|
||||
sensor.model = model;
|
||||
sensor.id = id;
|
||||
sensor.showInList = false;
|
||||
sensorList.push(sensor);
|
||||
print("Create new");
|
||||
} else {
|
||||
|
|
|
@ -2,39 +2,116 @@ import Qt 4.7
|
|||
|
||||
Item {
|
||||
id: main
|
||||
state: "VIEW"
|
||||
|
||||
Component {
|
||||
id: sensorView
|
||||
BorderImage {
|
||||
source: "row_bg.png"
|
||||
border.left: 5; border.top: 5
|
||||
border.right: 5; border.bottom: 5
|
||||
height: sensorInfo.height
|
||||
Item{
|
||||
id: sensorViewItem
|
||||
visible: main.state == "EDIT" || modelData.showInList
|
||||
height: childrenRect.height
|
||||
width: parent.width
|
||||
|
||||
Text {
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 15
|
||||
height: 40
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: modelData.name;
|
||||
color: "#004275"
|
||||
}
|
||||
Column {
|
||||
id: sensorInfo
|
||||
anchors.right: parent.right
|
||||
width: 250
|
||||
SensorValue {
|
||||
visible: modelData.hasTemperature
|
||||
text: visible ? modelData.sensorValue(1).value + '°C' : ''
|
||||
icon: "icon_temp.png"
|
||||
lastUpdated: visible ? modelData.sensorValue(1).lastUpdated : new Date()
|
||||
BorderImage {
|
||||
source: "row_bg.png"
|
||||
border.left: 5; border.top: 5
|
||||
border.right: 5; border.bottom: 5
|
||||
height: sensorInfo.height
|
||||
width: parent.width
|
||||
|
||||
Text {
|
||||
visible: main.state == "VIEW"
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 15
|
||||
height: 40
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: modelData.name;
|
||||
color: "#004275"
|
||||
}
|
||||
SensorValue {
|
||||
visible: modelData.hasHumidity
|
||||
text: visible ? modelData.sensorValue(2).value + '%' : ''
|
||||
icon: "icon_humidity.png"
|
||||
lastUpdated: visible ? modelData.sensorValue(2).lastUpdated : new Date()
|
||||
Rectangle{
|
||||
color: "white"
|
||||
visible: main.state == "EDIT"
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 15
|
||||
width: nameEdit.width + 4
|
||||
height: 22
|
||||
TextInput{
|
||||
id: nameEdit
|
||||
anchors.centerIn: parent
|
||||
text: modelData.name;
|
||||
color: "#004275"
|
||||
|
||||
onActiveFocusChanged: {
|
||||
if(!activeFocus){
|
||||
//todo other way?
|
||||
modelData.setName(nameEdit.text);
|
||||
}
|
||||
}
|
||||
onAccepted: {
|
||||
modelData.setName(nameEdit.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
Text{
|
||||
anchors.right: model.left
|
||||
visible: main.state == "EDIT"
|
||||
height: 40
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: modelData.id
|
||||
color: "#004275"
|
||||
width: 50
|
||||
}
|
||||
Text{
|
||||
id: model
|
||||
anchors.right: visibleinlistcheckbox.left
|
||||
visible: main.state == "EDIT"
|
||||
height: 40
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
text: modelData.model
|
||||
color: "#004275"
|
||||
width: 100
|
||||
}
|
||||
Item{
|
||||
id: visibleinlistcheckbox
|
||||
anchors.right: sensorInfo.left
|
||||
visible: main.state == "EDIT"
|
||||
height: 40
|
||||
Rectangle{
|
||||
anchors.centerIn: parent
|
||||
height: 10
|
||||
width: 10
|
||||
color: "white"
|
||||
Text{
|
||||
anchors.centerIn: parent
|
||||
color: "#004275"
|
||||
text: modelData.showInList ? "X" : ""
|
||||
}
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
modelData.setShowInList(!modelData.showInList);
|
||||
}
|
||||
}
|
||||
}
|
||||
width: 100
|
||||
}
|
||||
|
||||
Column {
|
||||
id: sensorInfo
|
||||
anchors.right: parent.right
|
||||
width: 250
|
||||
SensorValue {
|
||||
visible: modelData.hasTemperature
|
||||
text: visible ? modelData.sensorValue(1).value + '°C' : ''
|
||||
icon: "icon_temp.png"
|
||||
lastUpdated: visible ? modelData.sensorValue(1).lastUpdated : new Date()
|
||||
}
|
||||
SensorValue {
|
||||
visible: modelData.hasHumidity
|
||||
text: visible ? modelData.sensorValue(2).value + '%' : ''
|
||||
icon: "icon_humidity.png"
|
||||
lastUpdated: visible ? modelData.sensorValue(2).lastUpdated : new Date()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +132,27 @@ Item {
|
|||
anchors.leftMargin: 15
|
||||
}
|
||||
HeaderTitle {
|
||||
text: "ID"
|
||||
anchors.right: modelTitle.left
|
||||
visible: main.state == "EDIT"
|
||||
width: 50
|
||||
}
|
||||
HeaderTitle {
|
||||
id: modelTitle
|
||||
text: "Model"
|
||||
anchors.right: visibleinlistTitle.left
|
||||
visible: main.state == "EDIT"
|
||||
width: 100
|
||||
}
|
||||
HeaderTitle {
|
||||
id: visibleinlistTitle
|
||||
text: "Visible in list"
|
||||
anchors.right: sensorinformationTitle.left
|
||||
visible: main.state == "EDIT"
|
||||
width: 100
|
||||
}
|
||||
HeaderTitle {
|
||||
id: sensorinformationTitle
|
||||
text: "Sensor information"
|
||||
width: 150
|
||||
anchors.right: timestampTitle.left
|
||||
|
@ -64,12 +162,53 @@ Item {
|
|||
text: "Last updated"
|
||||
width: 100
|
||||
anchors.right: parent.right
|
||||
//horizontalAlignment: Text.AlignRight
|
||||
}
|
||||
}
|
||||
Repeater {
|
||||
model: sensorModel
|
||||
delegate: sensorView
|
||||
}
|
||||
Row{
|
||||
spacing: 20
|
||||
Rectangle {
|
||||
width: 50
|
||||
height: 20
|
||||
Text{
|
||||
anchors.centerIn: parent
|
||||
text: main.state == "VIEW" ? "Edit" : "View"
|
||||
}
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
if(main.state == "VIEW"){
|
||||
main.state = "EDIT"
|
||||
}
|
||||
else{
|
||||
main.state ="VIEW"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
Rectangle {
|
||||
//TODO should this button exist at all, or always save?
|
||||
width: 50
|
||||
height: 20
|
||||
visible: main.state == "EDIT"
|
||||
Text{
|
||||
anchors.centerIn: parent
|
||||
text: "Cancel"
|
||||
}
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
main.state ="VIEW"
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#include "sensor.h"
|
||||
#include "sensorvalue.h"
|
||||
#include <telldus-core.h>
|
||||
#include <QDebug>
|
||||
|
||||
class Sensor::PrivateData {
|
||||
public:
|
||||
bool hasTemperature, hasHumidity;
|
||||
bool hasTemperature, hasHumidity, showInList;
|
||||
int id;
|
||||
QString model, name, protocol;
|
||||
QDateTime lastUpdated;
|
||||
|
@ -45,7 +46,10 @@ void Sensor::setModel(const QString &model) {
|
|||
}
|
||||
|
||||
QString Sensor::name() const {
|
||||
return QString("%1 %2").arg(this->protocol()).arg(this->id()); //TODO: Remove when name is fully implemented
|
||||
//return QString("%1 %2").arg(this->protocol()).arg(this->id()); //TODO: Remove when name is fully implemented
|
||||
if(d->name == ""){
|
||||
return "<unnamed>";
|
||||
}
|
||||
return d->name;
|
||||
}
|
||||
|
||||
|
@ -88,3 +92,13 @@ void Sensor::setValue(int type, const QString &value, const QDateTime ×tamp
|
|||
emit hasHumidityChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool Sensor::showInList() const{
|
||||
//TODO showInList and name must be persistent...
|
||||
return d->showInList;
|
||||
}
|
||||
|
||||
void Sensor::setShowInList(bool show){
|
||||
d->showInList = show;
|
||||
emit showInListChanged();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ class Sensor : public QObject
|
|||
Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged)
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
Q_PROPERTY(QString protocol READ protocol WRITE setProtocol NOTIFY protocolChanged)
|
||||
Q_PROPERTY(bool showInList READ showInList NOTIFY showInListChanged)
|
||||
|
||||
public:
|
||||
explicit Sensor(QObject *parent = 0);
|
||||
~Sensor();
|
||||
|
@ -30,15 +32,18 @@ public:
|
|||
void setModel(const QString &model);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
//void setName(const QString &name);
|
||||
|
||||
QString protocol() const;
|
||||
void setProtocol(const QString &protocol);
|
||||
|
||||
bool hasTemperature() const;
|
||||
bool showInList() const;
|
||||
|
||||
Q_INVOKABLE SensorValue *sensorValue(int type);
|
||||
Q_INVOKABLE void setValue(int type, const QString &value, const QDateTime ×tamp);
|
||||
Q_INVOKABLE void setName(const QString &name);
|
||||
Q_INVOKABLE void setShowInList(bool show);
|
||||
|
||||
signals:
|
||||
void idChanged();
|
||||
|
@ -47,6 +52,7 @@ signals:
|
|||
void modelChanged();
|
||||
void nameChanged();
|
||||
void protocolChanged();
|
||||
void showInListChanged();
|
||||
|
||||
private:
|
||||
class PrivateData;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue