Metrics Builder View Model¶
MVC models for the metrics builder.
ActivityColumnMetricItem ¶
Bases: QStandardItem
Represents an activity's metric information for a specific column.
Source code in src/cplus_plugin/gui/metrics_builder_model.py
expression
property
¶
Gets the item's expression.
Returns:
Type | Description |
---|---|
str
|
Item's expression. |
metric_type
property
¶
Gets the metric type of the underlying data model.
Returns:
Type | Description |
---|---|
MetricType
|
The metric type of the underlying data model. |
model
property
¶
Gets the underlying activity column metric data model.
Returns:
Type | Description |
---|---|
ActivityColumnMetric
|
The underlying activity column metric data model. |
highlight_invalid ¶
Highlights the item with a red background to indicate that the activity column metric is invalid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
show |
bool
|
True to highlight the item else False to disable. A call to highlight will first verify that the data model is valid. If it is valid then the item will not be highlighted. |
required |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
is_valid ¶
Checks if the activity column metric is valid.
Returns:
Type | Description |
---|---|
bool
|
True if the activity column metric is valid else False. |
metric_type_to_str
staticmethod
¶
Returns the corresponding string representation for the given metric type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_type |
MetricType
|
Type of metric or expression. |
required |
Returns:
Type | Description |
---|---|
str
|
The corresponding string representation of the given metric type. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
type ¶
Returns the type of the standard item.
Returns:
Type | Description |
---|---|
int
|
Type identifier of the item. |
update_metric_model ¶
Updates the underlying metric model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
MetricColumn
|
Metric column containing updated properties. |
required |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
update_metric_type ¶
Updates the metric type of the underlying metric model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric_type |
MetricType
|
Metric type to be used by the model. |
required |
expression |
str
|
Expression for the given metric type. Default is an empty string. |
''
|
Source code in src/cplus_plugin/gui/metrics_builder_model.py
ActivityColumnSummaryItem ¶
Bases: QStandardItem
Provides an item for displaying the configuration of metrics for the activity by listing the specific metrics for each column.
Source code in src/cplus_plugin/gui/metrics_builder_model.py
ActivityColumnSummaryTreeModel ¶
Bases: QStandardItemModel
View model for managing activity column metric data models in a tree view.
Source code in src/cplus_plugin/gui/metrics_builder_model.py
set_summary_models ¶
Update the model to use the specified activity column metric data models.
Any existing items will be removed prior to loading the specified data models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity_metric_models |
List[List[ActivityColumnMetric]]
|
Nested list of activity column metric data models. |
required |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
ActivityMetricTableModel ¶
Bases: QStandardItemModel
View model for activity metrics in a table.
Source code in src/cplus_plugin/gui/metrics_builder_model.py
activities
property
¶
Gets all the activities in the model.
Returns:
Type | Description |
---|---|
typing.List[Activity]
|
All activities in the model. |
metric_columns
property
¶
Gets the metric columns used in the model to define the headers.
Returns:
Type | Description |
---|---|
typing.List[MetricColumn]
|
Metric columns used in the model. |
models
property
¶
Gets the mapping of activity column metric data models.
Returns:
Type | Description |
---|---|
typing.List[typing.List[ActivityColumnMetric]]
|
A nested list of activity column metrics in the same order that they are stored in the model. |
append_activity ¶
Adds an activity row in the activity metrics table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
activity |
Activity
|
Activity to be added. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the activity was successfully added else False. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
append_column ¶
Adds a column to the model based on the information in the metric column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column |
MetricColumn
|
Metric column containing information for defining the new column. |
required |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
metric_column ¶
Gets the metric column at the given location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
Index of the metric column. |
required |
Returns:
Type | Description |
---|---|
typing.Optional[MetricColumn]
|
The metric column at the given index else None if the index is invalid. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
move_column ¶
Move the column in the specified index left or right depending on the move direction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_index |
int
|
Index of the column to be moved. |
required |
direction |
HorizontalMoveDirection
|
Direction to move the column, either left or right. |
required |
Returns:
Type | Description |
---|---|
int
|
New position of the column or -1 if the column item was not moved. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
move_column_left ¶
Convenience method for moving a column to the left.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_index |
int
|
Index of the column to be moved. |
required |
Returns:
Type | Description |
---|---|
int
|
New position of the column or -1 if the column item was not moved. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
move_column_right ¶
Convenience method for moving a column to the right.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_index |
int
|
Index of the column to be moved. |
required |
Returns:
Type | Description |
---|---|
int
|
New position of the column or -1 if the column item was not moved. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
remove_column ¶
Remove the column at the specified index.
The index will be normalized to reflect the first metric column since index zero is reserved for the activity name column which is fixed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
Index of the column to be removed. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the column was successfully removed else False. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
update_column_properties ¶
Updates the properties of an underlying metric column in the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
Index of the column to the updated. |
required |
column |
MetricColumn
|
Updated column metric object. |
required |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
validate ¶
Validate the items in the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
highlight_invalid |
bool
|
True to highlight invalid activity metric column items, else False to ignore highlighting invalid items. If True, the invalid items will be highlighted for a default period of 3000ms. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the items are valid else False. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
ActivityNameTableItem ¶
Bases: QStandardItem
Represents an activity name in the metrics table.
Source code in src/cplus_plugin/gui/metrics_builder_model.py
MetricColumnListItem ¶
Bases: QStandardItem
Represents a single carbon layer path.
Source code in src/cplus_plugin/gui/metrics_builder_model.py
alignment
property
writable
¶
Gest the alignment of the column text.
Returns:
Type | Description |
---|---|
QtCore.Qt.AlignmentFlag
|
The alignment of the column text. |
auto_calculated
property
writable
¶
Indicates whether the column value is auto-calculated.
Returns:
Type | Description |
---|---|
bool
|
True if the column value is auto-calculated else False. |
expression
property
writable
¶
Gets the column-wide expression used by activity metrics.
Returns:
Type | Description |
---|---|
str
|
The column-wide expression used by the activity metrics. |
format_as_number
property
writable
¶
Gets whether the result of evaluating the column or cell metric should be formatted as a number.
Returns:
Type | Description |
---|---|
bool
|
True if the value should be formatted as a number else False. |
header
property
writable
¶
Gets the column header.
Returns:
Type | Description |
---|---|
str
|
The column header. |
is_valid
property
¶
Returns the validity status of the item.
The name and header label should be defined.
Returns:
Type | Description |
---|---|
bool
|
True if valid, else False. |
model
property
¶
Gets the underlying data model used in the item.
Returns:
Type | Description |
---|---|
MetricColumn
|
The underlying data model used in the item. |
name
property
writable
¶
Gets the name of the column.
Returns:
Type | Description |
---|---|
str
|
The name of the column. |
number_formatter
property
writable
¶
Gets the formatter used for the value of the expression result.
This is applicable if :py:attr:~format_as_number
has
been set to True.
Returns:
Type | Description |
---|---|
QgsNumericFormat
|
The number formatter to use. |
type ¶
Returns the type of the standard item.
Returns:
Type | Description |
---|---|
int
|
Type identifier of the item. |
MetricColumnListModel ¶
Bases: QStandardItemModel
View model for list-based metric column objects.
Source code in src/cplus_plugin/gui/metrics_builder_model.py
column_items
property
¶
Gets all the column items in the model.
Returns:
Type | Description |
---|---|
typing.List[MetricColumnListItem]
|
All the column items in the model. |
add_column ¶
Adds a column item to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
column_item |
MetricColumnListItem
|
Column item to be added to the model. |
required |
Returns:
Type | Description |
---|---|
MetricColumnListItem | None
|
The item successfully added to the model else None if the item could not be successfully added due to an already existing name in the model. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
add_new_column ¶
Adds a new column to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name_column |
Union[str, MetricColumn]
|
Name of the column or metric column data model. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the column was successfully added due to an already existing column with a similar name, else False. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
column_exists ¶
Checks if a column with the given name exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the column. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the column name exists, else False. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
item_from_name ¶
Gets the model item from the column name.
It performs a case-insensitive search of the first matching model item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the column. |
required |
Returns:
Type | Description |
---|---|
MetricColumnListItem
|
The first matching model item if found else None. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
move_column ¶
Moves the column item in the given row one by a level up or down as defined in the direction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row |
int
|
Position of the column item to be moved. |
required |
direction |
VerticalMoveDirection
|
Direction to move the column item. |
required |
Returns:
Type | Description |
---|---|
int
|
New position of the column item or -1 if the column item was not moved. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
move_column_down ¶
Moves the column item in the given row one level down.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row |
int
|
Column item in the given row to be moved down. |
required |
Returns:
Type | Description |
---|---|
int
|
New position of the column item or -1 if the column item was not moved down. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
move_column_up ¶
Moves the column item in the given row one level up.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row |
int
|
Column item in the given row to be moved up. |
required |
Returns:
Type | Description |
---|---|
int
|
New position of the column item or -1 if the column item was not moved up. |
Source code in src/cplus_plugin/gui/metrics_builder_model.py
remove_column ¶
Removes the column matching the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of the column to be removed. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the column was successfully removed else False if there is no column matching the given name. |