safe.gui.widgets.dock module

InaSAFE Disaster risk assessment tool developed by AusAid - GUI 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.widgets.dock.Dock(iface)[source]

Bases: PyQt4.QtGui.QDockWidget, Ui_DockBase

Dock implementation class for the inaSAFE plugin.

about()[source]

Open the About dialog.

accept()[source]

Execute analysis when run button is clicked.

accept_cancelled(old_keywords)[source]

Deal with user cancelling post processing option dialog.

Parameters:old_keywords (dict) – A keywords dictionary that should be reinstated.
add_above_layer(existing_layer, new_layer)[source]

Add a layer (e.g. impact layer) above another layer in the legend.

New in version 3.2.

Note

This method works in QGIS 2.4 and better only. In earlier versions it will just add the layer to the top of the layer stack.

See also

issue #2322

Parameters:
  • existing_layer (QgsMapLayer) – The layer which the new layer should be added above.
  • new_layer (QgsMapLayer) – The new layer being added. An assumption is made that the newly added layer is not already loaded in the legend or the map registry.
analysis_done
analysis_error(exception, message)[source]

A helper to spawn an error and halt processing.

An exception will be logged, busy status removed and a message displayed.

Parameters:
  • message (ErrorMessage, Message) – an ErrorMessage to display
  • exception (Exception) – An exception that was raised
block_signals()[source]

Prevent the combos and dock listening for event changes.

canvas_layerset_changed()[source]

A helper slot to update dock combos if canvas layerset changes.

Activated when the layerset has been changed (e.g. one or more layer visibilities changed). If self.show_only_visible_layers_flag is set to False this method will simply return, doing nothing.

completed()[source]

Slot activated when the process is done.

connect_layer_listener()[source]

Establish a signal/slot to listen for layers loaded in QGIS.

..seealso:: disconnect_layer_listener

define_user_analysis_extent(extent, crs)[source]

Slot called when user has defined a custom analysis extent.

Parameters:
  • extent (QgsRectangle) – Extent of the user’s preferred analysis area.
  • crs (QgsCoordinateReferenceSystem) – Coordinate reference system for user defined analysis extent.
static disable_busy_cursor()[source]

Disable the hourglass cursor and listen for layer changes.

disable_signal_receiver()[source]

Remove dispatcher for all available signal from Analysis.

disconnect_layer_listener()[source]

Destroy the signal/slot to listen for layers loaded in QGIS.

..seealso:: connect_layer_listener

draw_rubber_bands()[source]

Draw any rubber bands that are enabled.

static enable_busy_cursor()[source]

Set the hourglass enabled and stop listening for layer changes.

enable_messaging()[source]

Set up the dispatcher for messaging.

enable_signal_receiver()[source]

Setup dispatcher for all available signal from Analysis.

get_aggregation_layer()[source]

Get the QgsMapLayer currently selected in the post processing combo.

Obtain QgsMapLayer id from the userrole of the QtCombo for post processing combo return it as a QgsMapLayer.

Returns:None if no aggregation is selected or cboAggregation is disabled, otherwise a polygon layer.
Return type:QgsMapLayer, QgsVectorLayer or None
get_exposure_layer()[source]

Get the QgsMapLayer currently selected in the exposure combo.

Obtain QgsMapLayer id from the userrole of the QtCombo for exposure and return it as a QgsMapLayer.

Returns:Currently selected map layer in the exposure combo.
Return type:QgsMapLayer
get_function_id(index=None)[source]
Get the canonical impact function ID for the currently selected
function (or the specified combo entry if theIndex is supplied.
Parameters:index (int) – Optional index position in the combo that you want the function id for. Defaults to None. If not set / None the currently selected combo item’s function id will be returned.
Returns:Id of the currently selected function.
Return type:str
get_functions()[source]

Obtain a list of impact functions from the IF manager.

get_hazard_layer()[source]

Get the QgsMapLayer currently selected in the hazard combo.

Obtain QgsMapLayer id from the userrole of the QtCombo for hazard and return it as a QgsMapLayer.

Returns:The currently selected map layer in the hazard combo.
Return type:QgsMapLayer
get_layers(*args)[source]

Obtain a list of layers currently loaded in QGIS.

On invocation, this method will populate cboHazard, cboExposure and cboAggregation on the dialog with a list of available layers.

Only polygon vector layers will be added to the aggregate list.

Parameters:args (list) – Arguments that may have been passed to this slot. Typically a list of layers, but depends on which slot or function called this function.

..note:: *args is only used for debugging purposes.

getting_started_message()[source]

Generate a message for initial application state.

Returns:Information for the user on how to get started.
Return type:Message
hide_busy()[source]

A helper function to indicate processing is done.

layer_changed(layer)[source]

Handler for when the QGIS active layer is changed.

If the active layer is changed and it has keywords and a report, show the report.

Parameters:layer (QgsMapLayer, QgsRasterLayer, QgsVectorLayer) – QgsMapLayer instance that is now active
static layer_legend_index(layer)[source]

Find out where in the legend layer stack a layer is.

Note

This function requires QGIS 2.4 or greater to work. In older versions it will simply return 0.

Parameters:layer (QgsMapLayer) – A map layer currently loaded in the legend.
Returns:An integer representing the z-order of the given layer in the legend tree. If the layer cannot be found, or the QGIS version is < 2.4 it will return 0.
Return type:int
no_overlap_message()[source]

Helper which returns a message indicating no valid overlap.

not_ready_message()[source]

Help to create a message indicating inasafe is NOT ready.

Note

Assumes a valid hazard and exposure layer are loaded.

Returns:A localised message indicating we are not ready.
Return type:Message
on_cboExposure_currentIndexChanged(index)[source]

Automatic slot executed when the Exposure combo is changed.

This is here so that we can see if the ok button should be enabled.

Parameters:index – The index number of the selected exposure layer.
on_cboFunction_currentIndexChanged(index)[source]

Automatic slot executed when the Function combo is changed.

This is here so that we can see if the ok button should be enabled.

Parameters:index – The index number of the selected function.
on_cboHazard_currentIndexChanged(index)[source]

Automatic slot executed when the Hazard combo is changed.

This is here so that we can see if the ok button should be enabled.

Parameters:index – The index number of the selected hazard layer.
on_toolFunctionOptions_clicked()[source]

Automatic slot executed when toolFunctionOptions is clicked.

open_map_in_composer(impact_report)[source]

Open map in composer given MapReport instance.

..note:: (AG) See https://github.com/AIFDR/inasafe/issues/911. We
need to set the composition to the composer before loading the template.
Parameters:impact_report (ImpactReport) – Impact Report to be opened in composer.
prepare_analysis()[source]

Create analysis as a representation of current situation of dock.

print_map()[source]

Open impact report dialog used to tune report when printing.

print_map_to_pdf(impact_report)[source]

Print map to PDF given MapReport instance.

Parameters:impact_report (ImpactReport) – Impact Report instance that is ready to print
read_settings()[source]

Set the dock state from QSettings.

Do this on init and after changing options in the options dialog.

ready_message()[source]

Helper to create a message indicating inasafe is ready.

Returns Message:
 A localised message indicating we are ready to run.
restore_function_state(original_function)[source]

Restore the function combo to a known state.

Parameters:original_function (str) – Name of function that should be selected.
restore_state()[source]

Restore the state of the dock to the last known state.

save_auxiliary_files(layer, destination)[source]

Save auxiliary files when using the ‘save as’ function.

If some auxiliary files (.xml or .keywords) exist, this function will copy them when the ‘save as’ function is used on the layer.

Parameters:
  • layer (QgsMapLayer) – The layer which has been saved as.
  • destination (str) – The new filename of the layer.
save_state()[source]

Save the current state of the ui to an internal class member.

The saved state can be restored again easily using restore_state()

set_dock_title()[source]

Set the title of the dock using the current version of InaSAFE.

set_function_options_status()[source]

Helper function to toggle the tool function button based on context.

If there are function parameters to configure then enable it, otherwise disable it.

set_run_button_status()[source]

Helper function to set the run button status based on form validity.

setup_button_connectors()[source]

Setup signal/slot mechanisms for dock buttons.

show_busy()[source]

Hide the question group box and enable the busy cursor.

show_dynamic_message(message)[source]

Send a dynamic message to the message viewer.

Dynamic messages are appended to any existing content in the MessageViewer.

Parameters:message (Message) – An instance of our rich message class.
show_error_message(error_message)[source]

Send an error message to the message viewer.

Error messages cause any previous content in the MessageViewer to be replaced with new content.

Parameters:error_message (ErrorMessage) – An instance of our rich error message class.
show_generic_keywords(keywords)[source]

Show the keywords defined for the active layer.

Note

The print button will be disabled if this method is called.

Parameters:keywords (dict) – A keywords dictionary.
static show_help()[source]

Load the help text into the system browser.

show_impact_keywords(keywords)[source]

Show the keywords for an impact layer.

Note

The print button will be enabled if this method is called. Also, the question group box will be hidden and the ‘show question’ button will be shown.

Parameters:keywords (dict) – A keywords dictionary.
show_keyword_version_message(keyword_version, inasafe_version)[source]

Show a message indicating that the keywords version is mismatch

Parameters:
  • keyword_version (str) – The version of the layer’s keywords
  • inasafe_version (str) – The version of the InaSAFE

Note

The print button will be disabled if this method is called.

show_next_analysis_extent()[source]

Update the rubber band showing where the next analysis extent is.

Primary purpose of this slot is to draw a rubber band of where the analysis will be carried out based on valid intersection between layers.

This slot is called on pan, zoom, layer visibility changes and

New in version 2.1.0.

show_no_keywords_message()[source]

Show a message indicating that no keywords are defined.

Note

The print button will be disabled if this method is called.

show_results()[source]

Helper function for slot activated when the process is done.

Changed in version 3.2: - removed parameters.

Returns:Provides a report for writing to the dock.
Return type:str
show_static_message(message)[source]

Send a static message to the message viewer.

Static messages cause any previous content in the MessageViewer to be replaced with new content.

Parameters:message (Message) – An instance of our rich message class.
toggle_aggregation_combo()[source]

Toggle the aggregation combo enabled status.

Whether the combo is toggled on or off will depend on the current dock status.

toggle_rubber_bands(flag)[source]

Disabled/enable the rendering of rubber bands.

Parameters:flag (bool) – Flag to indicate if drawing of bands is active.
unblock_signals()[source]

Let the combos listen for event changes again.

update_layer_name()[source]

Writes the sender’s new layer name into the layer’s keywords

validate()[source]

Helper method to evaluate the current state of the dialog.

This function will determine if it is appropriate for the OK button to be enabled or not.

Note

The enabled state of the OK button on the dialog will NOT be updated (set True or False) depending on the outcome of the UI readiness tests performed - only True or False will be returned by the function.

Returns:A two-tuple where the first element is a Boolean reflecting the results of the validation tests and the second is a message indicating any reason why the validation may have failed.
Return type:(Boolean, Message)

Example:

flag,message = self.validate()
validate_extents()[source]

Check if the current extents are valid.

Look at the intersection between Hazard, exposure and user analysis area and see if they represent a valid, usable area for analysis.

New in version 3.1.

Returns:A two-tuple. The first element will be True if extents are usable, otherwise False. It will also return False if an invalid condition exists e.g. no hazard layer etc. The second element will be a rectangle for the analysis extent (if valid) or None.
Return type:(bool, QgisRectangle)