CDPBaseComObj Class
The CDPBaseComObj class is used for communication with CDP in C++ and QML. More...
Header: | #include <CDPBaseWidgets/CDPBaseComObj.h> |
Inherits: | CDPBaseCom and |
Properties
|
|
Public Functions
CDPBaseComObj(QObject *parent = 0) | |
virtual | ~CDPBaseComObj(void) |
QString | command() |
QString | parameter() |
QString | routing() |
virtual void | setRouting(QString routing) |
virtual void | setStringPrecision(int precision) |
int | stringPrecision() |
QString | stringValue() |
- 17 public functions inherited from CDPBaseCom
Public Slots
virtual void | sendMsg(const QString &command = "") |
virtual void | setCommand(const QString ¶meter) |
virtual void | setParameter(const QString ¶meter) |
virtual void | setStringValue(const QString &value) |
Signals
void | connectionStateChanged(bool connected) |
void | stringValueChanged(const QString &stringValue) |
void | valueChanged(double value) |
void | valueChangedBool(bool value) |
void | valueChangedInt(int value) |
Reimplemented Protected Functions
virtual void | ConnectionChanged(bool bConnected) |
virtual void | setValue(double value) |
virtual bool | setValue(QString value, bool bScale) |
- 4 protected functions inherited from CDPBaseCom
Additional Inherited Members
- 2 static public members inherited from CDPBaseCom
- 4 protected functions inherited from CDPBaseCom
Detailed Description
The CDPBaseComObj class is used for communication with CDP in C++ and QML.
Usage in C++
Example showing how to receive values from a CDP object:
CDPBaseComObj *pObj = new CDPBaseComObj; pObj->setScalingFactor(1.0); pObj->setRouting("Application.Component.Signal.Value"); connect(pObj, SIGNAL(valueChanged(double)), this, SLOT(handleValue(double)));
Example showing how to change the value of a remote CDP object:
CDPBaseComObj *pObj = new CDPBaseComObj; pObj->setRouting("Application.Component.Signal.Value"); ... pObj->SetValueDouble(2.0)
Example showing how to send a message with parameter to a CDP object:
CDPBaseComObj *pObj = new CDPBaseComObj; pObj->setCommand("Select"); pObj->setParameter("DTWinch"); pObj->setRouting("Application.Component"); ... pObj->sendMsg()
Usage in QML
Example showing how to register the object for use in QML:
#include <qqml.h> #include <CDPBaseWidgets/CDPBaseComObj.h> int main (int argc, char* argv[]) { ... QApplication app(argc, argv); qmlRegisterType<CDPBaseComObj>("CDP2Qt", 1, 0, "CDPBaseComObj"); ...
Example showing how to update QML texts when registerred as above. The value changed handlers are not strictly needed. They were added to show how objects can get updated, not only by requesting data, but also by push from the com object. Both methods will update the texts when new values are received.
import QtQuick 2.0 import CDP2Qt 1.0 Item { CDPBaseComObj { id: amplitude routing: "App.Sine.Amplitude.Value" stringPrecision: 3 scaling: 1.0 onStringValueChanged: { console.log("StringValue = " + stringValue) } onValueChanged: { console.log("Value = " + value) text2.text = "Value = " + value } onConnectionStateChanged: { console.log("Connection = " + connected) } } Text { id: text1 anchors.centerIn: parent text: "Value = " + amplitude.value } Text { id: text2 anchors.top: text1.bottom; anchors.horizontalCenter: text1.horizontalCenter; text: "Value = 0" } Text { id: text3 anchors.top: text2.bottom; anchors.horizontalCenter: text1.horizontalCenter; text: "Connection = " + amplitude.connected } }
Note: Setting stringPrecision will set string precision and enable stringValue though the routed property type is double
. Leaving this at the default would prevent onStringValueChanged to trigger. The scaling property will also work for string property type as long as it can get converted to number.
Example showing how to send messages in QML. The first text shows whether or not the Sine component of App is suspended and the value of the Sine Output. The second text can be clicked to send text commands to the component to make it suspended or active.
import QtQuick 2.0 import CDP2Qt 1.0 Item { CDPBaseComObj { id: comOutput; routing: "App.Sine.Output.Value"; stringPrecision: 3} CDPBaseComObj { id: comSine; routing: "App.Sine"; command: "CM_SUSPEND"; } CDPBaseComObj { id: comSuspended; routing: "App.Sine.Suspended"; } Text { id: text1 anchors.centerIn: parent property string sineState: comSuspended.value==1 ? "Yes" : "No" text: "Suspended: " + sineState + ", Output: " + comOutput.stringValue } Text { id: text2 anchors.top: text1.bottom; anchors.horizontalCenter: text1.horizontalCenter; text: "Click to toggle Sine suspended!" } MouseArea { anchors.fill: text2; onPressed: { if (comSuspended.value == 1){ comSine.command = "CM_ACTIVATE" comSine.sendMsg() } else { comSine.command = "CM_SUSPEND" comSine.sendMsg() } } } }
Property Documentation
command : QString
This property holds the text command to send to destination triggered by sendMsg().
Access functions:
QString | command() |
virtual void | setCommand(const QString ¶meter) |
See also parameter and routing.
connected : const bool
This property holds whether or not the widget is connected to the routed object.
Notifier signal:
void | connectionStateChanged(bool connected) |
offlineValue : const QString
This property holds a value to use while the connection is . The offline value must be enabled using offlineValueEnabled. Else, latest value will be kept while the routed object is disconnected.
See also offlineValueEnabled.
offlineValueEnabled : const bool
This property holds whether or not to set offlineValue as value if routed value is not connected. Setting the property will keep the latest value while being offline.
See also offlineValue.
parameter : QString
This property holds an optional parameter that will be sent along with configured message.
Access functions:
QString | parameter() |
virtual void | setParameter(const QString ¶meter) |
See also command.
routing : QString
This property holds the routing to a remote property when command is not set. When the command is configured, the routing is assumed to be to an object that can receive messages.
Access functions:
QString | routing() |
virtual void | setRouting(QString routing) |
scaling : const double
This property holds a scaling factor that will be used on values that are sent and received. Values that are received from the routed object are multiplied by scaling while user input values are divided.
See also value.
stringPrecision : int
This property holds the number of decimals to use in stringValue. Setting this will enable stringValue also when the routed property type is not . A slight overhead might occur as numbers need to get converted to strings.
Access functions:
int | stringPrecision() |
virtual void | setStringPrecision(int precision) |
See also stringValue.
stringValue : QString
This property holds the value of the remote property as a string. When routed to an object with a type other than , the stringValue must be enabled by setting stringPrecision to a value of 0 or above. Scaling will work as as long as the string can be converted to a , but when routing such properties using value will cause less overhead.
Access functions:
QString | stringValue() |
virtual void | setStringValue(const QString &value) |
Notifier signal:
void | stringValueChanged(const QString &stringValue) |
See also stringPrecision and value.
value : const double
This property holds the numeric value of the routed object. Can also be used to set and get the value of type properties as long as the received can be converted into . The scaling property will work as usual.
Notifier signal:
void | valueChanged(double value) |
See also stringValue.
Member Function Documentation
CDPBaseComObj::CDPBaseComObj(QObject *parent = 0)
Default constructs an instance of CDPBaseComObj.
[virtual]
CDPBaseComObj::~CDPBaseComObj(void)
Destroys the instance of CDPBaseComObj. The destructor is virtual.
[virtual protected]
void CDPBaseComObj::ConnectionChanged(bool bConnected)
[virtual slot]
void CDPBaseComObj::sendMsg(const QString &command = "")
[virtual]
void CDPBaseComObj::setRouting(QString routing)
Connect to the CDP property specified in routing. When a command is provided, the routing should not end with a property, but an object capable of receiving messages.
Note: Setter function for property routing.
See also routing() and command.
[virtual protected]
void CDPBaseComObj::setValue(double value)
[virtual protected]
bool CDPBaseComObj::setValue(QString value, bool bScale)
[signal]
void CDPBaseComObj::valueChangedBool(bool value)
[signal]
void CDPBaseComObj::valueChangedInt(int value)
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.