Possibility to add/remove sensors from list, and change their names. Not yet persistent.

This commit is contained in:
Stefan Persson 2011-11-01 14:14:14 +01:00
parent 2feeb81f37
commit 8e377a12bc
5 changed files with 191 additions and 30 deletions

View file

@ -14,6 +14,7 @@ Item {
} }
Text { Text {
id: text id: text
font.weight: Font.Bold
anchors.left: icon.right anchors.left: icon.right
anchors.leftMargin: 10 anchors.leftMargin: 10
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter

View file

@ -56,6 +56,7 @@ com.telldus.sensors = function() {
sensor.protocol = protocol; sensor.protocol = protocol;
sensor.model = model; sensor.model = model;
sensor.id = id; sensor.id = id;
sensor.showInList = false;
sensorList.push(sensor); sensorList.push(sensor);
print("Create new"); print("Create new");
} else { } else {

View file

@ -2,9 +2,16 @@ import Qt 4.7
Item { Item {
id: main id: main
state: "VIEW"
Component { Component {
id: sensorView id: sensorView
Item{
id: sensorViewItem
visible: main.state == "EDIT" || modelData.showInList
height: childrenRect.height
width: parent.width
BorderImage { BorderImage {
source: "row_bg.png" source: "row_bg.png"
border.left: 5; border.top: 5 border.left: 5; border.top: 5
@ -13,6 +20,7 @@ Item {
width: parent.width width: parent.width
Text { Text {
visible: main.state == "VIEW"
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 15 anchors.leftMargin: 15
height: 40 height: 40
@ -20,6 +28,74 @@ Item {
text: modelData.name; text: modelData.name;
color: "#004275" color: "#004275"
} }
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 { Column {
id: sensorInfo id: sensorInfo
anchors.right: parent.right anchors.right: parent.right
@ -39,6 +115,7 @@ Item {
} }
} }
} }
}
Column { Column {
spacing: 1 spacing: 1
@ -55,6 +132,27 @@ Item {
anchors.leftMargin: 15 anchors.leftMargin: 15
} }
HeaderTitle { 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" text: "Sensor information"
width: 150 width: 150
anchors.right: timestampTitle.left anchors.right: timestampTitle.left
@ -64,12 +162,53 @@ Item {
text: "Last updated" text: "Last updated"
width: 100 width: 100
anchors.right: parent.right anchors.right: parent.right
//horizontalAlignment: Text.AlignRight
} }
} }
Repeater { Repeater {
model: sensorModel model: sensorModel
delegate: sensorView 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 anchors.fill: parent
} }
} }

View file

@ -1,10 +1,11 @@
#include "sensor.h" #include "sensor.h"
#include "sensorvalue.h" #include "sensorvalue.h"
#include <telldus-core.h> #include <telldus-core.h>
#include <QDebug>
class Sensor::PrivateData { class Sensor::PrivateData {
public: public:
bool hasTemperature, hasHumidity; bool hasTemperature, hasHumidity, showInList;
int id; int id;
QString model, name, protocol; QString model, name, protocol;
QDateTime lastUpdated; QDateTime lastUpdated;
@ -45,7 +46,10 @@ void Sensor::setModel(const QString &model) {
} }
QString Sensor::name() const { 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; return d->name;
} }
@ -88,3 +92,13 @@ void Sensor::setValue(int type, const QString &value, const QDateTime &timestamp
emit hasHumidityChanged(); 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();
}

View file

@ -17,6 +17,8 @@ class Sensor : public QObject
Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged) Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QString protocol READ protocol WRITE setProtocol NOTIFY protocolChanged) Q_PROPERTY(QString protocol READ protocol WRITE setProtocol NOTIFY protocolChanged)
Q_PROPERTY(bool showInList READ showInList NOTIFY showInListChanged)
public: public:
explicit Sensor(QObject *parent = 0); explicit Sensor(QObject *parent = 0);
~Sensor(); ~Sensor();
@ -30,15 +32,18 @@ public:
void setModel(const QString &model); void setModel(const QString &model);
QString name() const; QString name() const;
void setName(const QString &name); //void setName(const QString &name);
QString protocol() const; QString protocol() const;
void setProtocol(const QString &protocol); void setProtocol(const QString &protocol);
bool hasTemperature() const; bool hasTemperature() const;
bool showInList() const;
Q_INVOKABLE SensorValue *sensorValue(int type); Q_INVOKABLE SensorValue *sensorValue(int type);
Q_INVOKABLE void setValue(int type, const QString &value, const QDateTime &timestamp); Q_INVOKABLE void setValue(int type, const QString &value, const QDateTime &timestamp);
Q_INVOKABLE void setName(const QString &name);
Q_INVOKABLE void setShowInList(bool show);
signals: signals:
void idChanged(); void idChanged();
@ -47,6 +52,7 @@ signals:
void modelChanged(); void modelChanged();
void nameChanged(); void nameChanged();
void protocolChanged(); void protocolChanged();
void showInListChanged();
private: private:
class PrivateData; class PrivateData;