safe.gui.tools.wizard_dialog module

InaSAFE Disaster risk assessment tool by AusAid GUI InaSAFE Wizard Dialog.

Contact : ole.moller.nielsen@gmail.com

Note

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

class safe.gui.tools.wizard_dialog.LayerBrowserProxyModel(parent)[source]

Bases: PyQt4.QtGui.QSortFilterProxyModel

Proxy model for hiding unsupported branches in the layer browser.

filterAcceptsRow(source_row, source_parent)[source]

The filter method

Note

This filter hides top-level items of unsupported branches
and also leaf items containing xml files.

Enabled root items: QgsDirectoryItem, QgsFavouritesItem, QgsPGRootItem.

Disabled root items: QgsMssqlRootItem, QgsSLRootItem, QgsOWSRootItem, QgsWCSRootItem, QgsWFSRootItem, QgsWMSRootItem.

Disabled leaf items: QgsLayerItem and QgsOgrLayerItem with path ending with ‘.xml’

Parameters:
  • source_row (int) – Parent widget of the model
  • source_parent (QModelIndex) – Parent item index
Returns:

Item validation result

Return type:

bool

class safe.gui.tools.wizard_dialog.WizardDialog(parent=None, iface=None, dock=None)[source]

Bases: PyQt4.QtGui.QDialog, Ui_WizardDialogBase

Dialog implementation class for the InaSAFE wizard.

additional_keywords_for_the_layer()[source]

Return a list of valid additional keywords for the current layer.

Returns:A list where each value represents a valid additional kw.
Return type:list
age_ratios_are_valid()[source]

Return true if the sum of age ratios is good, otherwise False.

Good means their sum does not exceed 1.

Returns:Tuple of boolean and float. Boolean represent good or not good, while float represent the summation of age ratio. If some ratio do not use global default, the summation is set to 0.
Return type:tuple
are_all_extra_keywords_selected()[source]

Ensure all all additional keyword are set by user

Returns:True if all additional keyword widgets are set
Return type:boolean
auto_select_one_item(list_widget)[source]

Select item in the list in list_widget if it’s the only item.

Parameters:list_widget (QListWidget) – The list widget that want to be checked.
classifications_for_layer()[source]

Return a list of valid classifications for a layer.

Returns:A list where each value represents a valid classification.
Return type:list
compute_next_step(current_step)[source]

Determine the next step to be switched to.

Parameters:current_step (int) – The present step number.
Returns:The next step number or None if finished.
Return type:int
compute_previous_step(current_step)[source]

Determine the previous step to be switched to (by the Back button).

Parameters:current_step (int) – The present step number.
Returns:The previous step number.
Return type:int
extra_keyword_changed(widget)[source]
Populate slave widget if exists and enable the Next button
if all extra keywords are set.
Parameters:widget (dict) – Metadata of the widget where the event happened.
field_keyword_for_the_layer()[source]

Return the proper keyword for field for the current layer. Expected values are: ‘field’, ‘structure_class_field’, road_class_field

Returns:the field keyword
Return type:string
get_aggregation_attributes()[source]

Obtain the value of aggregation attributes set by user.

Returns:The key and value of aggregation attributes.
Return type:dict
get_compatible_layers_from_canvas(category)[source]

Collect compatible layers from map canvas.

Note

Returns layers with keywords and layermode matching the category and compatible with the selected impact function. Also returns layers without keywords with layermode compatible with the selected impact function.

Parameters:category (string) – The category to filter for.
Returns:Metadata of found layers.
Return type:list of dicts
get_current_step()[source]

Return current step of the wizard.

Returns:Current step of the wizard.
Return type:int
get_existing_keyword(keyword)[source]

Obtain an existing keyword’s value.

Parameters:keyword (str) – A keyword from keywords.
Returns:The value of the keyword.
Return type:str
get_keywords()[source]

Obtain the state of the dialog as a keywords dict.

Returns:Keywords reflecting the state of the dialog.
Return type:dict
get_layer_description_from_browser(category)[source]

Obtain the description of the browser layer selected by user.

Parameters:category (string) – The category of the layer to get the description.
Returns:Tuple of boolean and string. Boolean is true if layer is validated as compatible for current role (impact function and category) and false otherwise. String contains a description of the selected layer or an error message.
Return type:tuple
get_layer_description_from_canvas(layer, purpose)[source]

Obtain the description of a canvas layer selected by user.

Parameters:
  • layer (QgsMapLayer) – The QGIS layer.
  • category (string) – The category of the layer to get the description.
Returns:

description of the selected layer.

Return type:

string

get_layer_geometry_id(layer=None)[source]

Obtain layer mode of a given layer.

If no layer specified, the current layer is used

:param layer : layer to examine :type layer: QgsMapLayer or None

Returns:The layer mode.
Return type:str
go_to_step(step)[source]
Set the stacked widget to the given step, set up the buttons,
and run all operations that should start immediately after entering the new step.
Parameters:step (int) – The step number to be moved to.
hazard_categories_for_layer()[source]

Return a list of valid hazard categories for a layer.

Returns:A list where each value represents a valid hazard category.
Return type:list
is_layer_compatible(layer, layer_purpose, keywords=None)[source]
Validate if a given layer is compatible for selected IF
as a given layer_purpose
Parameters:
  • layer (QgsVectorLayer | QgsRasterLayer) – The layer to be validated
  • layer_purpose (string) – The layer_purpose the layer is validated for
  • keywords (None, dict) – The layer keywords
Returns:

True if layer is appropriate for the selected role

Return type:

boolean

is_ready_to_next_step(step)[source]
Check if the step we enter is initially complete. If so, there is
no reason to block the Next button.
Parameters:step (int) – The present step number.
Returns:True if new step may be enabled.
Return type:bool
layer_description_html(layer, keywords=None)[source]
Form a html description of a given layer based on the layer
parameters and keywords if provided
Parameters:
  • layer (QgsMapLayer) – The layer to get the description
  • keywords (None, dict) – The layer keywords
Returns:

The html description in tabular format, ready to use in a label or tool tip.

Return type:

str

layermodes_for_layer()[source]

Return a list of valid layer modes for a layer.

Returns:A list where each value represents a valid layer mode.
Return type:list
layers_intersect(layer_a, layer_b)[source]

Check if extents of two layers intersect.

Parameters:
  • layer_a (QgsMapLayer) – One of the two layers to test overlapping
  • layer_b (QgsMapLayer) – The second of the two layers to test overlapping
Returns:

true if the layers intersect, false if they are disjoint

Return type:

boolean

list_compatible_layers_from_canvas(category, list_widget)[source]

Fill given list widget with compatible layers.

Note

Uses get_compatible_layers_from_canvas() to filter layers

Parameters:
  • category (string) – The category to filter for.
  • list_widget (QListWidget) – The list widget to be filled with layers.
Returns:

Metadata of found layers.

Return type:

list of dicts

on_cboAdultRatioAttribute_currentIndexChanged()[source]

Automatic slot executed when the adult ratio attribute is changed.

When the user changes the adult ratio attribute (cboAdultRatioAttribute), it will change the enabled value of dsbAdultRatioDefault. If value is ‘Use default’, enable dsbAdultRatioDefault. Otherwise, disabled it.

on_cboElderlyRatioAttribute_currentIndexChanged()[source]

Automatic slot executed when the adult ratio attribute is changed.

When the user changes the elderly ratio attribute (cboElderlyRatioAttribute), it will change the enabled value of dsbElderlyRatioDefault. If value is ‘Use default’, enable dsbElderlyRatioDefault. Otherwise, disabled it.

on_cboExtraKeyword1_currentIndexChanged(indx)[source]
This is an automatic Qt slot executed when the
1st extra keyword combobox selection changes.
Parameters:indx (int or str) – The new index.
on_cboExtraKeyword2_currentIndexChanged(indx)[source]
This is an automatic Qt slot executed when the
2nd extra keyword combobox selection changes.
Parameters:indx (int or str) – The new index.
on_cboExtraKeyword3_currentIndexChanged(indx)[source]
This is an automatic Qt slot executed when the
3rd extra keyword combobox selection changes.
Parameters:indx (int or str) – The new index.
on_cboExtraKeyword4_currentIndexChanged(indx)[source]
This is an automatic Qt slot executed when the
4th extra keyword combobox selection changes.
Parameters:indx (int or str) – The new index.
on_cboExtraKeyword5_currentIndexChanged(indx)[source]
This is an automatic Qt slot executed when the
5th extra keyword combobox selection changes.
Parameters:indx (int or str) – The new index.
on_cboExtraKeyword6_currentIndexChanged(indx)[source]
This is an automatic Qt slot executed when the
6th extra keyword combobox selection changes.
Parameters:indx (int or str) – The new index.
on_cboExtraKeyword7_currentIndexChanged(indx)[source]
This is an automatic Qt slot executed when the
7th extra keyword combobox selection changes.
Parameters:indx (int or str) – The new index.
on_cboExtraKeyword8_currentIndexChanged(indx)[source]
This is an automatic Qt slot executed when the
8th extra keyword combobox selection changes.
Parameters:indx (int or str) – The new index.
on_cboFemaleRatioAttribute_currentIndexChanged()[source]

Automatic slot executed when the female ratio attribute is changed.

When the user changes the female ratio attribute (cboFemaleRatioAttribute), it will change the enabled value of dsbFemaleRatioDefault. If value is ‘Use default’, enable dsbFemaleRatioDefault. Otherwise, disabled it.

on_cboYouthRatioAttribute_currentIndexChanged()[source]

Automatic slot executed when the youth ratio attribute is changed.

When the user changes the youth ratio attribute (cboYouthRatioAttribute), it will change the enabled value of dsbYouthRatioDefault. If value is ‘Use default’, enable dsbYouthRatioDefault. Otherwise, disabled it.

on_leTitle_textChanged()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the title value changes.

on_lstCanvasAggLayers_itemSelectionChanged()[source]

Update layer description label

Note

This is an automatic Qt slot executed when the category selection changes.

on_lstCanvasExpLayers_itemSelectionChanged()[source]

Update layer description label

Note

This is an automatic Qt slot executed when the category selection changes.

on_lstCanvasHazLayers_itemSelectionChanged()[source]

Update layer description label

Note

This is an automatic Qt slot executed when the category selection changes.

on_lstCategories_itemSelectionChanged()[source]

Update purpose description label.

Note

This is an automatic Qt slot executed when the category selection changes.

on_lstClassifications_itemSelectionChanged()[source]

Update classification description label and unlock the Next button.

Note

This is an automatic Qt slot executed when the field selection changes.

on_lstFields_itemSelectionChanged()[source]

Update field description label and unlock the Next button.

Note

This is an automatic Qt slot executed when the field selection changes.

on_lstFunctions_itemSelectionChanged()[source]

Update function description label

Note

This is an automatic Qt slot executed when the category selection changes.

on_lstHazardCategories_itemSelectionChanged()[source]

Update hazard category description label.

Note

This is an automatic Qt slot executed when the category selection changes.

on_lstLayerModes_itemSelectionChanged()[source]

Update layer mode description label and unit widgets.

Note

This is an automatic Qt slot executed when the subcategory selection changes.

on_lstSubcategories_itemSelectionChanged()[source]

Update subcategory description label.

Note

This is an automatic Qt slot executed when the subcategory selection changes.

on_lstUnits_itemSelectionChanged()[source]

Update unit description label and field widgets.

Note

This is an automatic Qt slot executed when the unit selection changes.

on_pbnBack_released()[source]

Handle the Back button release.

Note

This is an automatic Qt slot executed when the Back button is released.

on_pbnNext_released()[source]

Handle the Next button release.

Note

This is an automatic Qt slot executed when the Next button is released.

on_pbnReportComposer_released()[source]

Handle the Open Report in Web Broseer button release.

Note

This is an automatic Qt slot executed when the Next button is released.

on_pbnReportPDF_released()[source]

Handle the Generate PDF button release.

Note

This is an automatic Qt slot executed when the Next button is released.

on_pbnReportWeb_released()[source]

Handle the Open Report in Web Browser button release.

Note

This is an automatic Qt slot executed when the Next button is released.

on_rbAggLayerFromBrowser_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbAggLayerFromCanvas_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbAggLayerNoAggregation_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbExpLayerFromBrowser_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbExpLayerFromCanvas_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbExtentLayer_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbExtentScreen_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbExtentUser_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbHazLayerFromBrowser_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_rbHazLayerFromCanvas_toggled()[source]

Unlock the Next button

Note

This is an automatic Qt slot executed when the radiobutton is activated.

on_tblFunctions1_cellDoubleClicked(row, column)[source]

Choose selected hazard x exposure combination and go ahead.

Note

This is an automatic Qt slot executed when the category selection changes.

on_tblFunctions1_itemSelectionChanged()[source]

Choose selected hazard x exposure combination.

Note

This is an automatic Qt slot executed when the category selection changes.

on_tblFunctions2_cellDoubleClicked(row, column)[source]

Click handler for selecting hazard and exposure constraints.

Parameters:
  • row (int) – The row that the user clicked on.
  • column (int) – The column that the user clicked on.

Note

This is an automatic Qt slot executed when the category selection changes.

on_tblFunctions2_itemSelectionChanged()[source]

Choose selected hazard x exposure constraints combination.

Note

This is an automatic Qt slot executed when the category selection changes.

pg_path_to_uri(path)[source]

Convert layer path from QgsBrowserModel to full QgsDataSourceURI

Parameters:path (string) – The layer path from QgsBrowserModel
Returns:layer uri
Return type:QgsDataSourceURI
populate_cbo_aggregation_attribute(ratio_attribute_key, cbo_ratio_attribute)[source]

Populate the combo box cbo_ratio_attribute for ratio_attribute_key.

Parameters:
  • ratio_attribute_key (str) – A ratio attribute key that saved in keywords.
  • cbo_ratio_attribute (QComboBox) – A combo box that wants to be populated.
populate_classified_values(unassigned_values, assigned_values, default_classes)[source]

Populate lstUniqueValues and treeClasses.from the parameters.

Parameters:
  • unassigned_values (list) – List of values that haven’t been assigned to a class. It will be put in self.lstUniqueValues.
  • assigned_values (dict) – Dictionary with class as the key and list of value as the the value of the dictionary. It will be put in self.treeClasses.
  • default_classes (list) – Default classes from unit.
populate_function_table_1()[source]

Populate the tblFunctions1 table with available functions.

populate_value_widget_from_field(widget, field_name)[source]
Populate the slave widget with unique values of the field
selected in the master widget.
Parameters:
  • widget (QComboBox) – The widget to be populated
  • field_name (str) – Name of the field to take the values from
purposes_for_layer()[source]

Return a list of valid purposes for the current layer.

Returns:A list where each value represents a valid purpose.
Return type:list
resizeEvent(ev)[source]

Trigger MessageViewer size update on window resize

Note

This is an automatic Qt slot executed when the window size changes.

save_current_keywords()[source]

Save keywords to the layer.

It will write out the keywords for the current layer. This method is based on the KeywordsDialog class.

selected_allowresampling()[source]

Obtain the allow_resampling state selected by user.

Note

Returns none if not set or not relevant

Returns:Value of the allow_resampling or None for not-set.
Return type:boolean or None
selected_canvas_agglayer()[source]

Obtain the canvas aggregation layer selected by user.

Returns:The currently selected map layer in the list.
Return type:QgsMapLayer
selected_canvas_explayer()[source]

Obtain the canvas exposure layer selected by user.

Returns:The currently selected map layer in the list.
Return type:QgsMapLayer
selected_canvas_hazlayer()[source]

Obtain the canvas layer selected by user.

Returns:The currently selected map layer in the list.
Return type:QgsMapLayer
selected_category()[source]

Obtain the layer purpose selected by user.

Returns:Metadata of the selected layer purpose.
Return type:dict, None
selected_classification()[source]

Obtain the classification selected by user.

Returns:Metadata of the selected classification.
Return type:dict, None
selected_extra_keywords()[source]

Obtain the extra keywords selected by user.

Returns:Metadata of the extra keywords.
Return type:dict, None
selected_field()[source]

Obtain the field selected by user.

Returns:Keyword of the selected field.
Return type:string, None
selected_function()[source]

Obtain the impact function selected by user.

Returns:metadata of the selected function.
Return type:dict, None
selected_functions_1()[source]

Obtain functions available for hazard an exposure selected by user.

Returns:List of the available functions metadata.
Return type:list, None
selected_functions_2()[source]

Obtain functions available for hazard and exposure selected by user.

Returns:List of the available functions metadata.
Return type:list, None
selected_hazard_category()[source]

Obtain the hazard category selected by user.

Returns:Metadata of the selected hazard category.
Return type:dict, None
selected_impact_function_constraints()[source]

Obtain impact function constraints selected by user.

Returns:Tuple of metadata of hazard, exposure, hazard layer constraints and exposure layer constraints
Return type:tuple
selected_layermode()[source]

Obtain the layer mode selected by user. :returns: selected layer mode. :rtype: string, None

selected_mapping()[source]

Obtain the value-to-class mapping set by user.

Returns:The complete mapping as a dict of lists.
Return type:dict
selected_subcategory()[source]

Obtain the subcategory selected by user.

Returns:Metadata of the selected subcategory.
Return type:dict, None
selected_unit()[source]

Obtain the unit selected by user.

Returns:Metadata of the selected unit.
Return type:dict, None
set_function_centric_mode()[source]

Set the Wizard to the Function Centric mode

set_keywords_creation_mode(layer=None)[source]

Set the Wizard to the Keywords Creation mode :param layer: Layer to set the keywords for :type layer: QgsMapLayer

set_mode_label_to_ifcw()[source]

Set the mode label to the IFCW

set_mode_label_to_keywords_creation()[source]

Set the mode label to the Keywords Creation/Update mode

set_tool_tip()[source]

Set tool tip as helper text for some objects.

set_widgets_step_fc_agglayer_disjoint()[source]

Set widgets on the Aggregation Layer Disjoint tab

set_widgets_step_fc_agglayer_from_browser()[source]

Set widgets on the Aggregation Layer From Browser tab

set_widgets_step_fc_agglayer_from_canvas()[source]

Set widgets on the Aggregation Layer from Canvas tab

set_widgets_step_fc_agglayer_origin()[source]

Set widgets on the Aggregation Layer Origin Type tab

set_widgets_step_fc_analysis()[source]

Set widgets on the Progress tab

set_widgets_step_fc_disjoint_layers()[source]

Set widgets on the Disjoint Layers tab

set_widgets_step_fc_explayer_from_browser()[source]

Set widgets on the Exposure Layer From Browser tab

set_widgets_step_fc_explayer_from_canvas()[source]

Set widgets on the Exposure Layer From Canvas tab

set_widgets_step_fc_explayer_origin()[source]

Set widgets on the Exposure Layer Origin Type tab

set_widgets_step_fc_extent()[source]

Set widgets on the Extent tab

set_widgets_step_fc_extent_disjoint()[source]

Set widgets on the Extent Disjoint tab

set_widgets_step_fc_function_1()[source]

Set widgets on the Impact Functions Table 1 tab.

set_widgets_step_fc_function_2()[source]

Set widgets on the Impact Functions Table 2 tab.

set_widgets_step_fc_function_3()[source]

Set widgets on the Impact Functions tab.

set_widgets_step_fc_hazlayer_from_browser()[source]

Set widgets on the Hazard Layer From Browser tab

set_widgets_step_fc_hazlayer_from_canvas()[source]

Set widgets on the Hazard Layer From TOC tab

set_widgets_step_fc_hazlayer_origin()[source]

Set widgets on the Hazard Layer Origin Type tab.

set_widgets_step_fc_params()[source]

Set widgets on the Params tab

set_widgets_step_fc_summary()[source]

Set widgets on the Summary tab

set_widgets_step_kw_aggregation()[source]

Set widgets on the aggregation tab.

set_widgets_step_kw_category()[source]

Set widgets on the layer purpose tab.

set_widgets_step_kw_classification()[source]

Set widgets on the Classification tab.

set_widgets_step_kw_classify()[source]

Set widgets on the Classify tab.

set_widgets_step_kw_extrakeywords()[source]

Set widgets on the Extra Keywords tab.

set_widgets_step_kw_field()[source]

Set widgets on the Field tab.

set_widgets_step_kw_hazard_category()[source]

Set widgets on the Hazard Category tab.

set_widgets_step_kw_layermode()[source]

Set widgets on the LayerMode tab.

set_widgets_step_kw_resample()[source]

Set widgets on the Resample tab.

set_widgets_step_kw_source()[source]

Set widgets on the Source tab.

set_widgets_step_kw_subcategory()[source]

Set widgets on the Subcategory tab.

set_widgets_step_kw_title()[source]

Set widgets on the Title tab.

set_widgets_step_kw_unit()[source]

Set widgets on the Unit tab.

setup_and_run_analysis()[source]

Execute analysis after the tab is displayed

start_capture_coordinates()[source]

Enter the coordinate capture mode

stop_capture_coordinates()[source]

Exit the coordinate capture mode

subcategories_for_layer()[source]
Return a list of valid subcategories for a layer.
Subcategory is hazard type or exposure type.
Returns:A list where each value represents a valid subcategory.
Return type:list
tvBrowserAggregation_selection_changed()[source]

Update layer description label

tvBrowserExposure_selection_changed()[source]

Update layer description label

tvBrowserHazard_selection_changed()[source]

Update layer description label

unsuitable_layer_description_html(layer, layer_purpose, keywords=None)[source]
Form a html description of a given non-matching layer based on
the currently selected impact function requirements vs layer’s parameters and keywords if provided, as
Parameters:
  • layer (QgsVectorLayer | QgsRasterLayer) – The layer to be validated
  • layer_purpose (string) – The layer_purpose the layer is validated for
  • keywords (None, dict) – The layer keywords
Returns:

The html description in tabular format, ready to use in a label or tool tip.

Return type:

str

update_MessageViewer_size()[source]

Update maximumHeight size of the MessageViewer to fit its parent tab

This is a workaround for a bug that makes MessageViewer flooding up to maximumHeight on Windows.

update_dragged_item_flags(item, column)[source]

Fix the drop flag after the item is dropped.

Check if it looks like an item dragged from QListWidget to QTreeWidget and disable the drop flag. For some reasons the flag is set when dragging.

Parameters:
  • item
  • column

Note

This is a slot executed when the item change.

validate_extent()[source]

Check if the selected extent intersects source data.

Returns:true if extent intersects both layers, false if is disjoint
Return type:boolean
write_extent()[source]

After the extent selection, save the extent and disconnect signals

safe.gui.tools.wizard_dialog.get_question_text(constant)[source]

Find a constant by name and return its value.

Parameters:constant (string) – The name of the constant to look for.
Returns:The value of the constant or red error message.
Return type:string