Support inverted IO connections
This commit is contained in:
parent
3a5711aeb9
commit
2ca8f05b65
@ -233,7 +233,8 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
||||
QUuid inputStateTypeId = connectionMap.value("inputStateTypeId").toUuid();
|
||||
QUuid outputThingId = connectionMap.value("outputThingId").toUuid();
|
||||
QUuid outputStateTypeId = connectionMap.value("outputStateTypeId").toUuid();
|
||||
IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId);
|
||||
bool inverted = connectionMap.value("inverted").toBool();
|
||||
IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted);
|
||||
m_ioConnections->addIOConnection(ioConnection);
|
||||
} else if (notification == "Integrations.IOConnectionRemoved") {
|
||||
QUuid connectionId = data.value("params").toMap().value("ioConnectionId").toUuid();
|
||||
@ -712,13 +713,14 @@ int DeviceManager::executeBrowserItemAction(const QUuid &deviceId, const QString
|
||||
return m_jsonClient->sendCommand("Actions.ExecuteBrowserItemAction", data, this, "executeBrowserItemActionResponse");
|
||||
}
|
||||
|
||||
int DeviceManager::connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId)
|
||||
int DeviceManager::connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted)
|
||||
{
|
||||
QVariantMap data;
|
||||
data.insert("inputThingId", inputThingId);
|
||||
data.insert("inputStateTypeId", inputStateTypeId);
|
||||
data.insert("outputThingId", outputThingId);
|
||||
data.insert("outputStateTypeId", outputStateTypeId);
|
||||
data.insert("inverted", inverted);
|
||||
return m_jsonClient->sendCommand("Integrations.ConnectIO", data, this, "connectIOResponse");
|
||||
}
|
||||
|
||||
@ -746,7 +748,8 @@ void DeviceManager::getIOConnectionsResponse(const QVariantMap ¶ms)
|
||||
QUuid inputStateTypeId = connectionMap.value("inputStateTypeId").toUuid();
|
||||
QUuid outputThingId = connectionMap.value("outputThingId").toUuid();
|
||||
QUuid outputStateTypeId = connectionMap.value("outputStateTypeId").toUuid();
|
||||
IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId);
|
||||
bool inverted = connectionMap.value("inverted").toBool();
|
||||
IOConnection *ioConnection = new IOConnection(id, inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted);
|
||||
m_ioConnections->addIOConnection(ioConnection);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ public:
|
||||
Q_INVOKABLE int executeBrowserItem(const QUuid &deviceId, const QString &itemId);
|
||||
Q_INVOKABLE int executeBrowserItemAction(const QUuid &deviceId, const QString &itemId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
||||
|
||||
Q_INVOKABLE int connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId);
|
||||
Q_INVOKABLE int connectIO(const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted);
|
||||
Q_INVOKABLE int disconnectIO(const QUuid &ioConnectionId);
|
||||
|
||||
private:
|
||||
|
||||
@ -30,13 +30,14 @@
|
||||
|
||||
#include "ioconnection.h"
|
||||
|
||||
IOConnection::IOConnection(const QUuid &id, const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, QObject *parent):
|
||||
IOConnection::IOConnection(const QUuid &id, const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted, QObject *parent):
|
||||
QObject(parent),
|
||||
m_id(id),
|
||||
m_inputThingId(inputThingId),
|
||||
m_inputStateTypeId(inputStateTypeId),
|
||||
m_outputThingId(outputThingId),
|
||||
m_outputStateTypeId(outputStateTypeId)
|
||||
m_outputStateTypeId(outputStateTypeId),
|
||||
m_inverted(inverted)
|
||||
{
|
||||
|
||||
}
|
||||
@ -65,3 +66,8 @@ QUuid IOConnection::outputStateTypeId() const
|
||||
{
|
||||
return m_outputStateTypeId;
|
||||
}
|
||||
|
||||
bool IOConnection::inverted() const
|
||||
{
|
||||
return m_inverted;
|
||||
}
|
||||
|
||||
@ -42,15 +42,17 @@ class IOConnection : public QObject
|
||||
Q_PROPERTY(QUuid inputStateTypeId READ inputStateTypeId CONSTANT)
|
||||
Q_PROPERTY(QUuid outputThingId READ outputThingId CONSTANT)
|
||||
Q_PROPERTY(QUuid outputStateTypeId READ outputStateTypeId CONSTANT)
|
||||
Q_PROPERTY(bool inverted READ inverted CONSTANT)
|
||||
|
||||
public:
|
||||
explicit IOConnection(const QUuid &id, const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, QObject *parent = nullptr);
|
||||
explicit IOConnection(const QUuid &id, const QUuid &inputThingId, const QUuid &inputStateTypeId, const QUuid &outputThingId, const QUuid &outputStateTypeId, bool inverted, QObject *parent = nullptr);
|
||||
|
||||
QUuid id() const;
|
||||
QUuid inputThingId() const;
|
||||
QUuid inputStateTypeId() const;
|
||||
QUuid outputThingId() const;
|
||||
QUuid outputStateTypeId() const;
|
||||
bool inverted() const;
|
||||
|
||||
private:
|
||||
QUuid m_id;
|
||||
@ -58,6 +60,7 @@ private:
|
||||
QUuid m_inputStateTypeId;
|
||||
QUuid m_outputThingId;
|
||||
QUuid m_outputStateTypeId;
|
||||
bool m_inverted = false;
|
||||
};
|
||||
|
||||
#endif // IOCONNECTION_H
|
||||
|
||||
@ -52,6 +52,8 @@ QVariant IOConnections::data(const QModelIndex &index, int role) const
|
||||
return m_list.at(index.row())->outputThingId();
|
||||
case RoleOutputStateTypeId:
|
||||
return m_list.at(index.row())->outputStateTypeId();
|
||||
case RoleInverted:
|
||||
return m_list.at(index.row())->inverted();
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
@ -63,6 +65,7 @@ QHash<int, QByteArray> IOConnections::roleNames() const
|
||||
roles.insert(RoleInputStateTypeId, "inputStateTypeId");
|
||||
roles.insert(RoleOutputThingId, "outputThingId");
|
||||
roles.insert(RoleOutputStateTypeId, "outputStateTypeId");
|
||||
roles.insert(RoleInverted, "inverted");
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,8 @@ public:
|
||||
RoleInputThingId,
|
||||
RoleInputStateTypeId,
|
||||
RoleOutputThingId,
|
||||
RoleOutputStateTypeId
|
||||
RoleOutputStateTypeId,
|
||||
RoleInverted
|
||||
};
|
||||
Q_ENUM(Roles)
|
||||
|
||||
|
||||
@ -130,7 +130,7 @@ SettingsPageBase {
|
||||
RowLayout {
|
||||
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins
|
||||
Label {
|
||||
text: qsTr("Type")
|
||||
text: qsTr("Type:")
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
Label {
|
||||
@ -329,6 +329,8 @@ SettingsPageBase {
|
||||
property IOInputConnectionWatcher inputWatcher: null
|
||||
property IOOutputConnectionWatcher outputWatcher: null
|
||||
|
||||
readonly property bool isInput: ioConnectionDialog.ioStateType.ioType == Types.IOTypeDigitalInput || ioConnectionDialog.ioStateType.ioType == Types.IOTypeAnalogInput
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Connect \"%1\" to:").arg(ioConnectionDialog.ioStateType.displayName)
|
||||
@ -408,6 +410,16 @@ SettingsPageBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
text: qsTr("Inverted")
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: invertCheckBox
|
||||
checked: ioConnectionDialog.isInput ? ioConnectionDialog.inputWatcher.ioConnection.inverted : ioConnectionDialog.outputWatcher.ioConnection.inverted
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
@ -421,6 +433,7 @@ SettingsPageBase {
|
||||
}
|
||||
Button {
|
||||
text: qsTr("Disconnect")
|
||||
enabled: ioConnectionDialog.isInput ? ioConnectionDialog.inputWatcher.ioConnection != null : ioConnectionDialog.outputWatcher.ioConnection != null
|
||||
|
||||
onClicked: {
|
||||
if (ioConnectionDialog.ioStateType.ioType == Types.IOTypeDigitalInput
|
||||
@ -435,6 +448,7 @@ SettingsPageBase {
|
||||
}
|
||||
Button {
|
||||
text: qsTr("Connect")
|
||||
enabled: ioThingComboBox.currentIndex >= 0 && ioStateComboBox.currentIndex >= 0
|
||||
|
||||
onClicked: {
|
||||
var inputThingId;
|
||||
@ -453,9 +467,10 @@ SettingsPageBase {
|
||||
outputThingId = root.device.id;
|
||||
outputStateTypeId = ioConnectionDialog.ioStateType.id;
|
||||
}
|
||||
var inverted = invertCheckBox.checked
|
||||
|
||||
print("connecting", inputThingId, inputStateTypeId, outputThingId, outputStateTypeId)
|
||||
engine.deviceManager.connectIO(inputThingId, inputStateTypeId, outputThingId, outputStateTypeId);
|
||||
print("connecting", inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted)
|
||||
engine.deviceManager.connectIO(inputThingId, inputStateTypeId, outputThingId, outputStateTypeId, inverted);
|
||||
|
||||
ioConnectionDialog.accept();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user