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 {
|
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
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -2,39 +2,116 @@ import Qt 4.7
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: main
|
id: main
|
||||||
|
state: "VIEW"
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: sensorView
|
id: sensorView
|
||||||
BorderImage {
|
Item{
|
||||||
source: "row_bg.png"
|
id: sensorViewItem
|
||||||
border.left: 5; border.top: 5
|
visible: main.state == "EDIT" || modelData.showInList
|
||||||
border.right: 5; border.bottom: 5
|
height: childrenRect.height
|
||||||
height: sensorInfo.height
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
||||||
Text {
|
BorderImage {
|
||||||
anchors.left: parent.left
|
source: "row_bg.png"
|
||||||
anchors.leftMargin: 15
|
border.left: 5; border.top: 5
|
||||||
height: 40
|
border.right: 5; border.bottom: 5
|
||||||
verticalAlignment: Text.AlignVCenter
|
height: sensorInfo.height
|
||||||
text: modelData.name;
|
width: parent.width
|
||||||
color: "#004275"
|
|
||||||
}
|
Text {
|
||||||
Column {
|
visible: main.state == "VIEW"
|
||||||
id: sensorInfo
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.leftMargin: 15
|
||||||
width: 250
|
height: 40
|
||||||
SensorValue {
|
verticalAlignment: Text.AlignVCenter
|
||||||
visible: modelData.hasTemperature
|
text: modelData.name;
|
||||||
text: visible ? modelData.sensorValue(1).value + '°C' : ''
|
color: "#004275"
|
||||||
icon: "icon_temp.png"
|
|
||||||
lastUpdated: visible ? modelData.sensorValue(1).lastUpdated : new Date()
|
|
||||||
}
|
}
|
||||||
SensorValue {
|
Rectangle{
|
||||||
visible: modelData.hasHumidity
|
color: "white"
|
||||||
text: visible ? modelData.sensorValue(2).value + '%' : ''
|
visible: main.state == "EDIT"
|
||||||
icon: "icon_humidity.png"
|
anchors.left: parent.left
|
||||||
lastUpdated: visible ? modelData.sensorValue(2).lastUpdated : new Date()
|
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
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 ×tamp
|
||||||
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();
|
||||||
|
}
|
||||||
|
|
|
@ -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 ×tamp);
|
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:
|
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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue