zoukankan      html  css  js  c++  java
  • Kanzi编程基础2

    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     /// 
    eturn 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     }

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

  • 相关阅读:
    元旦发布DayPilot Pro 5.8源代码
    新年新开端
    PWA 2007 过期解决办法
    Document Library Explorer 2007 源代码更新下载
    发布DayPilotPro5.5.1780 SP1源代码
    MOSS自带调查列表结果图形化展示
    自定义PWA报工界面:隐藏加班项
    学习Document Library Explorer 2007源代码
    WSS&MOSS SP3 Now Available
    SQL Server 2008安装失败
  • 原文地址:https://www.cnblogs.com/littlemeng/p/5952853.html
Copyright © 2011-2022 走看看