主要内容

本页采用了机器翻译。点击此处可查看英文原文。

重新排列和删除度量板中的小组件

本示例展示了如何使用度量 API 来重新排列度量仪表板默认布局中的现有小组件,以及如何从度量仪表板中删除小组件。

重新排列布局中的控件

假设您想要采用度量仪表板的默认布局,并修改布局,将实际重用潜在重用的条形图移动到架构部分的底部。

1.打开度量盘的默认配置。

dashboardconfig = slmetric.dashboard.Configuration.openDefaultConfiguration();

2.从配置中获取仪表盘布局。

layout = getDashboardLayout(dashboardconfig);

仪表盘布局包含嵌套的对象层。您可以使用 getWidgets 函数来获取布局中下一层的对象。有关详细信息,请参阅getWidgets

3.要返回仪表板布局中的各个部分,请使用 getWidgets 函数。

sections = getWidgets(layout)
sections=1×4 object
    1×1 Container    1×1 Group    1×1 Group    1×1 Group

sections1x4 Container,因为度量仪表板的默认布局有四个主要部分:

  • sections(1) 包含当前模型的系统信息。

  • sections(2) 包含尺寸部分中显示的小组件。这些小组件使用 模型度量 中的尺寸度量。

  • sections(3) 包含建模规范合规性部分中显示的小组件。这些小组件使用来自 模型度量 的合规性度量。

  • sections(4) 包含架构部分中显示的小组件。这些小组件使用来自 模型度量 的架构度量。

在图中,红色数字 1、2、3 和 4 表示度量仪表板中 4 个主要部分的位置。

4.将架构部分保存到变量 archSection 中。您可以使用 sections(4) 访问架构部分。

archSection = sections(4);

5.要查看架构部分包含的内容,请使用 getWidgets 函数。

archSectionContents = getWidgets(archSection)
archSectionContents=1×2 object
    1×1 Widget    1×1 Container

Architecture 部分包含一个 Widget 对象和一个 Container 对象,它们位于一个数组中。Widget 是数组的第一个元素。Container 是数组的第二个元素。

数组中对象的顺序与对象在仪表板中显示的顺序一致。在架构部分,第一个元素出现在该部分的顶部。第二个元素出现在该部分的底部。

默认配置下:

  • 数组的第一个元素对应于 Widget,它创建了实际重用潜在重用的条形图。

  • 数组的第二个元素对应于模型复杂度模块Stateflow LOCMATLAB LOC 小组件的 Container。请注意,LOC 指的是代码行。有关详细信息,请参阅模型度量

6.将数组的第一个元素保存到变量 reuseWidget 中。

reuseWidget = archSectionContents(1) % widget
reuseWidget = 
  Widget with properties:

    Title: 'Library Reuse'
     Type: 'LibraryReuse'
       ID: '006e5f20-5400-4fbf-add9-80ed1be98d2f'

reuseWidget 中的 Type'LibraryReuse''LibraryReuse' 类型的小组件会创建实际再利用潜在再利用条形图。

7.使用 getPosition 函数确认 reuseWidget 小组件当前位于架构部分内的第一个位置。

getPosition(reuseWidget)
ans = 
1

8.将 reuseWidget 小组件移动到 Architecture 部分的底部,方法是将 reuseWidget 对象的位置设置为该部分对象数组中的第二个元素。

setPosition(reuseWidget,2);

9.将更新后的配置 dashboardconfig 保存为 XML 文件。XML 文件包含重新排列的架构部分的全新布局。

save(dashboardconfig,'Filename','DashboardConfig.xml');

10.将 XML 文件设置为度量仪表板的活动配置。

slmetric.dashboard.setActiveConfiguration(fullfile(pwd,'DashboardConfig.xml'));

11.度量仪表板会在下次打开模型仪表板时使用活动配置。

metricsdashboard vdp
Warning: The Metrics Dashboard and slmetric.Engine API will be removed in a future release.
For size, architecture, and complexity metrics, use the Model Maintainability Dashboard and metric.Engine API instead.
The Model Maintainability Dashboard and metric.Engine API can identify outdated metric results, analyze dependencies between files, and aggregate metrics across software units and components.
For more information, see <a href="matlab:helpview([docroot '/slcheck/collect-model-metric-data-1.html'])">Collect Model and Testing Metrics</a>

12.点击所有度量即可在仪表板中收集每个度量。

由于 reuseWidget 小组件被设置为第二个位置,因此实际再利用潜在再利用的条形图现在出现在架构部分的底部。

12.关闭度量盘。

从布局中移除小组件

假设您想从度量仪表板的架构部分中删除 Stateflow LOCMATLAB LOC 小组件。

1.获取您在上一节中更新的配置的新仪表板布局。

layout = getDashboardLayout(dashboardconfig);

2.使用 getWidgets 函数返回仪表板布局中的各个部分。

sections = getWidgets(layout);

3.将架构部分保存到变量 archSection 中。

archSection = sections(4);

4.使用 getWidgets 函数查看架构部分包含的内容。

archSectionContents = getWidgets(archSection)
archSectionContents=1×2 object
    1×1 Container    1×1 Widget

由于您在上一节中重新排列了控件,因此 Container 现在是数组中的第一个元素。Container 包含模型复杂度模块Stateflow LOCMATLAB LOC 小组件。

5.将 Container 保存到变量 archContainer 中。

archContainer = archSectionContents(1);

6.使用 getWidgets 函数获取 Container 中的控件。

archContainerWidgets = getWidgets(archContainer);

archContainerWidgets 是一个 1x4 CustomWidget 数组,其中:

  • archContainerWidgets(1) 包含用于模型复杂度的组件。

  • archContainerWidgets(2) 包含模块小组件

  • archContainerWidgets(3) 包含 Stateflow LOC 的小组件

  • archContainerWidgets(4) 包含 MATLAB LOC 的小组件

7.从 Container 中移除 Stateflow LOC 小组件。

removeWidget(archContainer,archContainerWidgets(3));

8.从 Container 中移除 MATLAB LOC 小组件。

removeWidget(archContainer,archContainerWidgets(4));

9.将更新后的配置 dashboardconfig 保存为 XML 文件。XML 文件包含重新排列的架构部分的全新布局。

save(dashboardconfig,'Filename','DashboardConfig.xml');

10.将 XML 文件设置为度量仪表板的活动配置。

slmetric.dashboard.setActiveConfiguration(fullfile(pwd,'DashboardConfig.xml'));

11.度量仪表板会在下次打开模型仪表板时使用活动配置。

metricsdashboard vdp
Warning: The Metrics Dashboard and slmetric.Engine API will be removed in a future release.
For size, architecture, and complexity metrics, use the Model Maintainability Dashboard and metric.Engine API instead.
The Model Maintainability Dashboard and metric.Engine API can identify outdated metric results, analyze dependencies between files, and aggregate metrics across software units and components.
For more information, see <a href="matlab:helpview([docroot '/slcheck/collect-model-metric-data-1.html'])">Collect Model and Testing Metrics</a>

架构部分不再显示 Stateflow LOCMATLAB LOC 小组件。

另请参阅

| |

主题