Kanzi编程基础2 - Kanzi节点读取和属性设置

UI设计师在Kanzi studio把Kanzi的节点做好后,就要编码读取这些节点并根据实际功能去控制刷新它。

Kanzi读取节点的api发生过很多次变化,从2.7、2.8到3.0,每次变化都比较大,可能是因为kanzi引擎的设计思路还不是非常确定。

 

目前3.3版本可以通过application下的screen里的方法读取,如下:

std::shared_ptr<Node> spNode = app->getScreen()->lookupNode<Node>("RootPage/MainView/RPMGauge/Scene/RPM");

lookuoNode是一个模板方法,需要传入查找的节点的类型,我们可以使用基类型Node(Kanzi所有的节点的基类为Node),然后传入相对于Screen节点的路径。同样,也可以传入一个alias,如果使用的是alias,则要加前缀'#',如"#RPM"(名为RPM的alias需要在Kanzi studio中创建)。

 

该方法获取到的是该节点的一个智能指针,获取到后就可以通过这个智能指针就可以设置该节点的属性,如可见性、可用性等。

目前可以使用两种方式来设置kanzi节点的属性,

 

第1种:

使用Node类中的具体方法设置,如里面有setVisible方法,我们可以查找到这个方法的定义

void setVisible(bool value) { setProperty(VisibleProperty, value); }
如spNode->setVisible(false);则设置该节点隐藏。

Node类中定义了很多类似的方法,具体可以查看对应的头文件。

 

第2种:

使用Node类中的setProperty方法设置,传入属性的名称和值即可。具体的定义如下:

1  /// Sets the local value of a property.
2     ///
3     /// \param propertyType The property type identifying the property to set.
4     /// \param value The value to set.
5     template <typename DataType>
6     void setProperty(const PropertyType<DataType>& propertyType, typename PropertyType<DataType>::DataType value)
7     {
8         propertyType.setter(getPropertyManager(), this, value);
9     }

可以看得出来,这个方法比较灵活,只要知道属性的定义,就可以设置所有的属性(包括自定义的属性)。

同样,对应有getProperty方法可以获取所有的属性值。

 1 /// Returns the current value of a property.
 2     ///
 3     /// The value returned by this function is the result of the property system evaluating the inputs that can affect the values of properties.
 4     /// The final value is calculated by determining the base value of the property and applying existing modifiers to it.
 5     ///
 6     /// Base value is affected by the following inputs where the highest entry in the list determines the base value:
 7     /// 1. Local value set with setProperty or loaded from kzb
 8     /// 2. Value set by a style affecting the property.
 9     /// 3. Value defined by class metadata.
10     ///
11     /// When the base value is determined the system applies modifiers to the value that can change the value or replace it completely.
12     /// The following is the list of possible modifiers, where the order of evaluation is determined by the order the modifiers were added or applied.
13     /// 1. Values defined is states of state manager.
14     /// 2. Animations.
15     ///
16     /// If no inputs to the property value can be established the system returns the value registered in the property type metadata.
17     /// \param propertyType The property type identifying the property to retrieve.
18     /// \return Returns the evaluated property value.
19     template <typename DataType>
20     DataType getProperty(const PropertyType<DataType>& propertyType) const
21     {
22         return propertyType.getter(getPropertyManager(), this);
23     }

 

基本的节点获取就是那么简单。当然,深入做下去的时候,还会发现满足不了需求的情况,后面的进阶部分会继续介绍。

 

转载于:https://www.cnblogs.com/littlemeng/p/5952853.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值