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方法设置,传入属性的名称和值即可。具体的定义如下:
/// Sets the local value of a property.
///
/// \param propertyType The property type identifying the property to set.
/// \param value The value to set.
template <typename DataType>
void setProperty(const PropertyType<DataType>& propertyType, typename PropertyType<DataType>::DataType value)
{
propertyType.setter(getPropertyManager(), this, value);
}
可以看得出来,这个方法比较灵活,只要知道属性的定义,就可以设置所有的属性(包括自定义的属性)。
同样,对应有getProperty方法可以获取所有的属性值。
/// Returns the current value of a property.
///
/// The value returned by this function is the result of the property system evaluating the inputs that can affect the values of properties.
/// The final value is calculated by determining the base value of the property and applying existing modifiers to it.
///
/// Base value is affected by the following inputs where the highest entry in the list determines the base value:
/// 1. Local value set with setProperty or loaded from kzb
/// 2. Value set by a style affecting the property.
/// 3. Value defined by class metadata.
///
/// When the base value is determined the system applies modifiers to the value that can change the value or replace it completely.
/// The following is the list of possible modifiers, where the order of evaluation is determined by the order the modifiers were added or applied.
/// 1. Values defined is states of state manager.
/// 2. Animations.
///
/// If no inputs to the property value can be established the system returns the value registered in the property type metadata.
/// \param propertyType The property type identifying the property to retrieve.
/// \return Returns the evaluated property value.
template <typename DataType>
DataType getProperty(const PropertyType<DataType>& propertyType) const
{
return propertyType.getter(getPropertyManager(), this);
}
基本的节点获取就是那么简单。当然,深入做下去的时候,还会发现满足不了需求的情况,后面的进阶部分会继续介绍。
Kanzi编程基础2 - Kanzi节点读取和属性设置的更多相关文章
- Kanzi编程基础3 - 图片读取与显示
Kanzi开发的时候会遇到需要从外部读取图片的情况.Kanzi2.8版本和3.3版本读取方法稍有不同,我们先看看2.8版本的api. [2.8版本] 1)首先要从文件中读取一张图片 struct Kz ...
- Kanzi编程基础1 - 定时器Timer
Kanzi虽然发生了比较多的版本更迭,api也发生了很多变化,但定时器的头文件一直都在一个地方:#include "user/include/user/ui/message/kzu_mess ...
- 【基础篇】EditText的一些属性设置
设置EditText的背景颜色 private test_editText=null; test_editText= (EditText) findViewById(R.id.EditTextInp ...
- (转)Windows驱动编程基础教程
版权声明 本书是免费电子书. 作者保留一切权利.但在保证本书完整性(包括版权声明.前言.正文内容.后记.以及作者的信息),并不增删.改变其中任何文字内容的前提下,欢迎任何读者 以任何形式(包括 ...
- C#面向对象编程基础-喜课堂笔记
**************[5][C#面向对象编程基础]第1讲:类与对象**************** *************2.1.1_类与对象的概念**** ...
- 用Netty开发中间件:网络编程基础
用Netty开发中间件:网络编程基础 <Netty权威指南>在网上的评价不是很高,尤其是第一版,第二版能稍好些?入手后快速翻看了大半本,不免还是想对<Netty权威指南(第二版)&g ...
- Java网络编程和NIO详解开篇:Java网络编程基础
Java网络编程和NIO详解开篇:Java网络编程基础 计算机网络编程基础 转自:https://mp.weixin.qq.com/s/XXMz5uAFSsPdg38bth2jAA 我们是幸运的,因为 ...
- Linux基础篇–shell脚本编程基础
本章内容概要 编程基础 脚本基本格式 变量 运算 条件测试 配置用户环境 7.1 编程基础程序:指令+数据程序编程风格: 过程式:以指令为中心,数据服务于指令 对象式:以数据为中心 ...
- Spark编程基础_RDD初级编程
摘要:Spark编程基础_RDD初级编程 RDD(Resilient Distributed Dataset)叫做弹性分布式数据集,是Spark中最基本的数据抽象,它代表一个不可变.可分区.里面的元素 ...
随机推荐
- 可爱的Python_课后习题_CDay−2 完成核心功能
1. 在前文的grep 实现例子中,没有考虑子目录的处理方式,因为如果直接open 目录进行读grep 是古老实用且高效的模式文本匹配工具,在所有的Unix/Linux 系统中都会默认安装,它最常做的 ...
- 【转】Linux下apache/httpd服务启动与停止
apache服务,或者说httpd服务,如何启动,如何开机启动. 转来转去,找不到原文.. 操作系统环境:红帽5,具体如下:# uname -a Linux machine1 2.6.18-164.e ...
- mysql的三种驱动类型
http://862123204-qq-com.iteye.com/blog/1566581 1. Class.forName("com.mysql.jdbc.Driver");/ ...
- 手机app开发:浅谈APP登录方式的优劣
手机app开发公司亿合科技要是给你一个机会设计一款APP,你会用什么方式做这个APP的登录模块?根据APP的业务模型的不同会有不同的设计方法.如果是偏内容型的APP,需要优先展示内容给用户,当用户需要 ...
- JsonUtil工具类
package comm; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collec ...
- sqlite简单使用
c创建表: create table 表名称(元素名称 类型,,,): 插入数据:insert into 表名称 values(null,,,) 修改数据 : update 表名 set 字段=’ ...
- 缓解 SQL Server has encountered 727 occurrence(s) of I/O requests taking longer than 15 seconds
sql server 会记录IO等待时间超过15 seconds的请求,这时application会有 time out 现象,dba需要判断是workload,concurrecy 所致还是sql ...
- Avg_row_length是怎么计算的?
通过一下命令我们可以获取表的使用情况: root::>show table status like 'tbname'\G 结果: . row ************************** ...
- eclipse构建maven+scala+spark工程 转载
转载地址:http://jingpin.jikexueyuan.com/article/47043.html 本文先叙述如何配置eclipse中maven+scala的开发环境,之后,叙述如何实现sp ...
- 集群间Session共享问题解决方案
两个基本概念的生命周期 session: 当新客户端发现一个HTTP请求时服务端会创建一个session.并分配一个sessionID作为服务端来客户端的识别,session对象会保存在服务端.此时s ...