def test_get_stored_settings_parameter_browser(): mock_ms = MagicMock() mock_ms.settingsdict = {'fieldlogger_export_parameter_browser': '((0, ("input_field_group_list", ("p1.u1;input;hint", "np2.u2;input2;hint2"), ), ), )'} settingskey = 'fieldlogger_export_parameter_browser' stored_settings = create_test_string(utils.get_stored_settings(mock_ms, settingskey)) reference_string = '((0, (input_field_group_list, (p1.u1;input;hint, np2.u2;input2;hint2))))' assert stored_settings == reference_string
def test_get_stored_settings_parameter_browser_real_parameter_name(): mock_ms = MagicMock() mock_ms.settingsdict = {"fieldlogger_pbrowser": '[(0, ("input_field_group_list", ["Aveflow.m3/s;numberDecimal|numberSigned;measure flow", "Accflow.m3;numberDecimal|numberSigned;measure flow"]))]'} settingskey = 'fieldlogger_pbrowser' test_string = create_test_string(utils.get_stored_settings(mock_ms, settingskey)) reference_string = '[(0, (input_field_group_list, [Aveflow.m3/s;numberDecimal|numberSigned;measure flow, Accflow.m3;numberDecimal|numberSigned;measure flow]))]' assert test_string == reference_string
def test_get_stored_settings(): mock_ms = MagicMock() mock_ms.settingsdict = {"test_settings_key": '((0, ("final_parameter_name", "testname"), ("test", "gotten_test")), (1, ("key1", "value1"), ("key2", "value2"), ("key3", "value3")))'} settingskey = 'test_settings_key' stored_settings = create_test_string(utils.get_stored_settings(mock_ms, settingskey)) reference_string = '((0, (final_parameter_name, testname), (test, gotten_test)), (1, (key1, value1), (key2, value2), (key3, value3)))' assert stored_settings == reference_string
def __init__(self, parent, midv_settings): self.iface = parent self.ms = midv_settings qgis.PyQt.QtWidgets.QDialog.__init__(self, parent) self.setAttribute(qgis.PyQt.QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) # Required by Qt4 to initialize the UI self.setWindowTitle( ru( QCoreApplication.translate('CompactWqualReportUi', "Compact water quality report")) ) # Set the title for the dialog self.manual_label.setText( "<a href=\"https://github.com/jkall/qgis-midvatten-plugin/wiki/5.-Plots-and-reports#create-compact-water-quality-report\">%s</a>" % QCoreApplication.translate('CompactWqualReportUi', '(manual)')) self.manual_label.setOpenExternalLinks(True) tables = list(db_utils.tables_columns().keys()) self.sql_table.addItems(sorted(tables)) #Use w_qual_lab as default. gui_utils.set_combobox(self.sql_table, 'w_qual_lab', add_if_not_exists=False) self.save_attrnames = [ 'num_data_cols', 'rowheader_colwidth_percent', 'empty_row_between_tables', 'page_break_between_tables', 'from_active_layer', 'from_sql_table', 'sql_table' ] self.stored_settings_key = 'compactwqualreport' self.stored_settings = utils.get_stored_settings( self.ms, self.stored_settings_key, {}) self.update_from_stored_settings(self.stored_settings) self.pushButton_ok.clicked.connect(lambda x: self.wqualreport()) #self.pushButton_cancel, PyQt4.QtCore.SIGNAL("clicked()"), lambda : self.close()) self.pushButton_update_from_string.clicked.connect( lambda x: self.ask_and_update_stored_settings()) self.sql_table.currentIndexChanged.connect( lambda: self.from_sql_table.setChecked(True)) self.empty_row_between_tables.clicked.connect( lambda: self.page_break_between_tables.setChecked(False) if self.empty_row_between_tables.isChecked() else True) self.page_break_between_tables.clicked.connect( lambda: self.empty_row_between_tables.setChecked(False) if self.page_break_between_tables.isChecked() else True) self.show()
def test_get_stored_settings_real_parameter_name(): mock_ms = MagicMock() mock_ms.settingsdict = { u"fieldlogger_pgroups": u'((0, (u"input_field_group_list", [u"Aveflow.m3/s;numberDecimal|numberSigned;measure flow", u"Accflow.m3;numberDecimal|numberSigned;measure flow"])))' } settingskey = u'fieldlogger_pgroups' test_string = create_test_string( utils.get_stored_settings(mock_ms, settingskey)) reference_string = u'(0, (input_field_group_list, [Aveflow.m3/s;numberDecimal|numberSigned;measure flow, Accflow.m3;numberDecimal|numberSigned;measure flow]))' assert test_string == reference_string
def __init__(self, parent, midv_settings): self.iface = parent self.ms = midv_settings qgis.PyQt.QtWidgets.QDialog.__init__(self, parent) self.setAttribute(qgis.PyQt.QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) # Required by Qt4 to initialize the UI self.stored_settings_key = 'customdrillreportstoredsettings' self.stored_settings = utils.get_stored_settings(self.ms, self.stored_settings_key, {}) self.update_from_stored_settings(self.stored_settings) self.pushButton_ok.clicked.connect(lambda x: self.drillreport()) self.pushButton_cancel.clicked.connect(lambda x: self.close()) self.pushButton_update_from_string.clicked.connect(lambda x: self.ask_and_update_stored_settings()) self.show()
def __init__(self, parent, midv_settings): self.iface = parent self.ms = midv_settings qgis.PyQt.QtWidgets.QDialog.__init__(self, parent) self.setAttribute(qgis.PyQt.QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) # Required by Qt4 to initialize the UI self.stored_settings_key = 'customdrillreportstoredsettings' self.stored_settings = utils.get_stored_settings( self.ms, self.stored_settings_key, {}) self.update_from_stored_settings(self.stored_settings) self.pushButton_ok.clicked.connect(lambda x: self.drillreport()) self.pushButton_cancel.clicked.connect(lambda x: self.close()) self.pushButton_update_from_string.clicked.connect( lambda x: self.ask_and_update_stored_settings()) self.show()
def __init__(self, parent, midv_settings): self.iface = parent self.ms = midv_settings PyQt4.QtGui.QDialog.__init__(self, parent) self.setAttribute(PyQt4.QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) # Required by Qt4 to initialize the UI self.stored_settings_key = u'customdrillreportstoredsettings' self.stored_settings = utils.get_stored_settings( self.ms, self.stored_settings_key, {}) self.update_from_stored_settings(self.stored_settings) self.connect(self.pushButton_ok, PyQt4.QtCore.SIGNAL("clicked()"), self.drillreport) self.connect(self.pushButton_cancel, PyQt4.QtCore.SIGNAL("clicked()"), lambda: self.close()) self.connect(self.pushButton_update_from_string, PyQt4.QtCore.SIGNAL("clicked()"), self.ask_and_update_stored_settings) self.show()
def __init__(self, parent, midv_settings): self.iface = parent self.ms = midv_settings PyQt4.QtGui.QDialog.__init__(self, parent) self.setAttribute(PyQt4.QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) # Required by Qt4 to initialize the UI self.setWindowTitle( ru( QCoreApplication.translate(u'ExportToFieldLogger', u"Export to Fieldlogger dialog")) ) # Set the title for the dialog self.widget.setMinimumWidth(180) tables_columns = db_utils.tables_columns() self.parameter_groups = None self.stored_settingskey = 'fieldlogger_export_pgroups' self.stored_settingskey_parameterbrowser = 'fieldlogger_export_pbrowser' for settingskey in [ self.stored_settingskey, self.stored_settingskey_parameterbrowser ]: if settingskey not in self.ms.settingsdict: utils.MessagebarAndLog.warning(bar_msg=ru( QCoreApplication.translate( u'ExportToFieldLogger', u'%s did not exist in settingsdict')) % settingskey) self.parameter_groups = self.create_parameter_groups_using_stored_settings( utils.get_stored_settings(self.ms, self.stored_settingskey), self.connect) if self.parameter_groups is None or not self.parameter_groups: self.parameter_groups = [ParameterGroup(self.connect)] self.main_vertical_layout.addWidget( PyQt4.QtGui.QLabel( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'Fieldlogger input fields and locations:')))) self.main_vertical_layout.addWidget(get_line()) self.splitter = SplitterWithHandel(PyQt4.QtCore.Qt.Vertical) self.main_vertical_layout.addWidget(self.splitter) #This is about adding a messagebar to the fieldlogger window. But for some reason qgis crashes or closes #when the timer ends for the regular messagebar #self.lbl = MessageBar(self.splitter) #qgis.utils.iface.optional_bar = self.lbl self.widgets_layouts = self.init_splitters_layouts(self.splitter) if self.parameter_groups: for export_object in self.parameter_groups: self.add_parameter_group_to_gui(self.widgets_layouts, export_object) #Buttons #ParameterUnitBrowser self.parameter_browser = ParameterBrowser(tables_columns, self.connect, self.widget) self.parameter_browser_button = PyQt4.QtGui.QPushButton( ru( QCoreApplication.translate(u'ExportToFieldLogger', u'Create Input Fields'))) self.gridLayout_buttons.addWidget(self.parameter_browser_button, 0, 0) self.connect(self.parameter_browser_button, PyQt4.QtCore.SIGNAL("clicked()"), lambda: self.parameter_browser.show()) self.update_parameter_browser_using_stored_settings( utils.get_stored_settings( self.ms, self.stored_settingskey_parameterbrowser), self.parameter_browser) self.add_parameter_group = PyQt4.QtGui.QPushButton( ru( QCoreApplication.translate(u'ExportToFieldLogger', u'More Fields and Locations'))) self.add_parameter_group.setToolTip( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'Creates an additional empty input field group.'))) self.gridLayout_buttons.addWidget(self.add_parameter_group, 1, 0) #Lambda and map is used to run several functions for every button click self.connect( self.add_parameter_group, PyQt4.QtCore.SIGNAL("clicked()"), lambda: map(lambda x: x(), [ lambda: self.parameter_groups.append( ParameterGroup(self.connect)), lambda: self.add_parameter_group_to_gui( self.widgets_layouts, self.parameter_groups[-1]) ])) self.gridLayout_buttons.addWidget(get_line(), 2, 0) #Buttons self.save_settings_button = PyQt4.QtGui.QPushButton( ru( QCoreApplication.translate(u'ExportToFieldLogger', u'Save settings'))) self.save_settings_button.setToolTip( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'Saves the current input fields settings.'))) self.gridLayout_buttons.addWidget(self.save_settings_button, 3, 0) self.connect( self.save_settings_button, PyQt4.QtCore.SIGNAL("clicked()"), lambda: map(lambda x: x(), [ lambda: utils.save_stored_settings( self.ms, self.update_stored_settings( self.parameter_groups), self.stored_settingskey), lambda: utils.save_stored_settings( self.ms, self.update_stored_settings([self.parameter_browser]), self .stored_settingskey_parameterbrowser) ])) self.clear_settings_button = PyQt4.QtGui.QPushButton( ru( QCoreApplication.translate(u'ExportToFieldLogger', u'Clear settings'))) self.clear_settings_button.setToolTip( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'Clear all input fields settings.'))) self.gridLayout_buttons.addWidget(self.clear_settings_button, 4, 0) self.connect( self.clear_settings_button, PyQt4.QtCore.SIGNAL("clicked()"), lambda: map(lambda x: x(), [ lambda: utils.save_stored_settings(self.ms, [ ], self.stored_settingskey), lambda: utils.pop_up_info( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'Settings cleared. Restart Export to Fieldlogger dialog to complete,\nor press "Save settings" to save current input fields settings again.' ))) ])) self.settings_strings_button = PyQt4.QtGui.QPushButton( ru( QCoreApplication.translate(u'ExportToFieldLogger', u'Settings strings'))) self.settings_strings_button.setToolTip( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'Access the settings strings ("Create input fields" and input fields) to copy and paste all settings between different qgis projects.\n Usage: Select string and copy to a text editor or directly into Settings strings dialog of another qgis project.' ))) self.gridLayout_buttons.addWidget(self.settings_strings_button, 5, 0) self.connect(self.settings_strings_button, PyQt4.QtCore.SIGNAL("clicked()"), self.settings_strings_dialogs) self.default_settings_button = PyQt4.QtGui.QPushButton( ru( QCoreApplication.translate(u'ExportToFieldLogger', u'Default settings'))) self.default_settings_button.setToolTip( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'Updates "Create input fields" and input fields to default settings.' ))) self.gridLayout_buttons.addWidget(self.default_settings_button, 6, 0) self.connect(self.default_settings_button, PyQt4.QtCore.SIGNAL("clicked()"), self.restore_default_settings) self.gridLayout_buttons.addWidget(get_line(), 7, 0) self.preview_button = PyQt4.QtGui.QPushButton( ru(QCoreApplication.translate(u'ExportToFieldLogger', u'Preview'))) self.preview_button.setToolTip( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'View a preview of the Fieldlogger location file as pop-up info.' ))) self.gridLayout_buttons.addWidget(self.preview_button, 8, 0) # Lambda and map is used to run several functions for every button click self.connect(self.preview_button, PyQt4.QtCore.SIGNAL("clicked()"), self.preview) self.export_button = PyQt4.QtGui.QPushButton( ru(QCoreApplication.translate(u'ExportToFieldLogger', u'Export'))) self.export_button.setToolTip( ru( QCoreApplication.translate( u'ExportToFieldLogger', u'Exports the current combination of locations and input fields to a Fieldlogger location file.' ))) self.gridLayout_buttons.addWidget(self.export_button, 9, 0) # Lambda and map is used to run several functions for every button click self.connect(self.export_button, PyQt4.QtCore.SIGNAL("clicked()"), self.export) self.gridLayout_buttons.setRowStretch(10, 1) self.show()
def __init__(self, parent, midv_settings): self.iface = parent self.tables_columns = db_utils.tables_columns() self.ms = midv_settings qgis.PyQt.QtWidgets.QDialog.__init__(self, parent) self.setAttribute(qgis.PyQt.QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) # Required by Qt4 to initialize the UI self.setWindowTitle( ru( QCoreApplication.translate('CompactWqualReportUi', "Compact water quality report")) ) # Set the title for the dialog self.manual_label.setText( "<a href=\"https://github.com/jkall/qgis-midvatten-plugin/wiki/5.-Plots-and-reports#create-compact-water-quality-report\">%s</a>" % QCoreApplication.translate('CompactWqualReportUi', '(manual)')) self.manual_label.setOpenExternalLinks(True) self.date_time_formats = { 'YYYY-MM': '%Y-%m', 'YYYY-MM-DD': '%Y-%m-%d', 'YYYY-MM-DD hh': '%Y-%m-%d %H', 'YYYY-MM-DD hh:mm': '%Y-%m-%d %H:%M', 'YYYY-MM-DD hh:mm:ss': '%Y-%m-%d %H:%M:%S' } self.methods = { 'concat': lambda x: ', '.join([ru(y) for y in x.values]), 'avg': lambda x: round( sum([float(y) for y in x.values]) / float(len(x.values)), num_decimals(x.values)) if all([floatable(y) for y in x.values]) else ', '.join( [ru(y) for y in x.values]), 'sum': lambda x: round(sum([float(y) for y in x]), num_decimals(x)) if all([floatable(y) for y in x.values]) else ', '.join(x.values), 'min': lambda x: min(x.values), 'max': lambda x: min(x.values) } self.date_time_format.addItems(self.date_time_formats.keys()) self.method.addItems(self.methods.keys()) tables = list(db_utils.tables_columns().keys()) self.sql_table.addItems(sorted(tables)) #Use w_qual_lab as default. gui_utils.set_combobox(self.sql_table, 'w_qual_lab', add_if_not_exists=False) self.save_attrnames = [ 'num_data_cols', 'rowheader_colwidth_percent', 'empty_row_between_tables', 'page_break_between_tables', 'from_active_layer', 'from_sql_table', 'sql_table', 'sort_alphabetically', 'sort_by_obsid', 'date_time_as_columns', 'date_time_format', 'method', 'data_column' ] self.stored_settings_key = 'compactwqualreport' self.pushButton_ok.clicked.connect(lambda x: self.wqualreport()) self.from_active_layer.clicked.connect( lambda x: self.set_columns_from_activelayer()) self.from_sql_table.clicked.connect( lambda x: self.set_columns_from_sql_layer()) self.sql_table.currentIndexChanged.connect( lambda x: self.set_columns_from_sql_layer()) self.pushButton_update_from_string.clicked.connect( lambda x: self.ask_and_update_stored_settings()) self.sql_table.currentIndexChanged.connect( lambda: self.from_sql_table.setChecked(True)) self.empty_row_between_tables.clicked.connect( lambda: self.page_break_between_tables.setChecked(False) if self.empty_row_between_tables.isChecked() else True) self.page_break_between_tables.clicked.connect( lambda: self.empty_row_between_tables.setChecked(False) if self.page_break_between_tables.isChecked() else True) self.stored_settings = utils.get_stored_settings( self.ms, self.stored_settings_key, {}) self.update_from_stored_settings(self.stored_settings) self.show()
def __init__(self, parent, midv_settings): self.iface = parent self.ms = midv_settings qgis.PyQt.QtWidgets.QDialog.__init__(self, parent) self.setAttribute(qgis.PyQt.QtCore.Qt.WA_DeleteOnClose) self.setupUi(self) # Required by Qt4 to initialize the UI self.setWindowTitle(ru(QCoreApplication.translate('ExportToFieldLogger', "Export to Fieldlogger dialog"))) # Set the title for the dialog self.widget.setMinimumWidth(180) tables_columns = db_utils.tables_columns() self.parameter_groups = None self.stored_settingskey = 'fieldlogger_export_pgroups' self.stored_settingskey_parameterbrowser = 'fieldlogger_export_pbrowser' for settingskey in [self.stored_settingskey, self.stored_settingskey_parameterbrowser]: if settingskey not in self.ms.settingsdict: utils.MessagebarAndLog.warning(bar_msg=ru(QCoreApplication.translate('ExportToFieldLogger', '%s did not exist in settingsdict'))%settingskey) self.parameter_groups = self.create_parameter_groups_using_stored_settings(utils.get_stored_settings(self.ms, self.stored_settingskey)) if self.parameter_groups is None or not self.parameter_groups: self.parameter_groups = [ParameterGroup()] self.main_vertical_layout.addWidget(qgis.PyQt.QtWidgets.QLabel(ru(QCoreApplication.translate('ExportToFieldLogger', 'Fieldlogger input fields and locations:')))) self.main_vertical_layout.addWidget(get_line()) self.splitter = SplitterWithHandel(qgis.PyQt.QtCore.Qt.Vertical) self.main_vertical_layout.addWidget(self.splitter) #This is about adding a messagebar to the fieldlogger window. But for some reason qgis crashes or closes #when the timer ends for the regular messagebar #self.lbl = MessageBar(self.splitter) #qgis.utils.iface.optional_bar = self.lbl self.widgets_layouts = self.init_splitters_layouts(self.splitter) if self.parameter_groups: for export_object in self.parameter_groups: self.add_parameter_group_to_gui(self.widgets_layouts, export_object) #Buttons #ParameterUnitBrowser self.parameter_browser = ParameterBrowser(tables_columns, self.widget) self.parameter_browser_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('ExportToFieldLogger', 'Create Input Fields'))) self.gridLayout_buttons.addWidget(self.parameter_browser_button, 0, 0) self.parameter_browser_button.clicked.connect( lambda : self.parameter_browser.show()) self.update_parameter_browser_using_stored_settings(utils.get_stored_settings(self.ms, self.stored_settingskey_parameterbrowser), self.parameter_browser) self.add_parameter_group = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('ExportToFieldLogger', 'More Fields and Locations'))) self.add_parameter_group.setToolTip(ru(QCoreApplication.translate('ExportToFieldLogger', 'Creates an additional empty input field group.'))) self.gridLayout_buttons.addWidget(self.add_parameter_group, 1, 0) #Lambda and map is used to run several functions for every button click self.add_parameter_group.clicked.connect( lambda: [x() for x in [lambda: self.parameter_groups.append(ParameterGroup()), lambda: self.add_parameter_group_to_gui(self.widgets_layouts, self.parameter_groups[-1])]]) self.gridLayout_buttons.addWidget(get_line(), 2, 0) #Buttons self.save_settings_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('ExportToFieldLogger', 'Save settings'))) self.save_settings_button.setToolTip(ru(QCoreApplication.translate('ExportToFieldLogger', 'Saves the current input fields settings.'))) self.gridLayout_buttons.addWidget(self.save_settings_button, 3, 0) self.save_settings_button.clicked.connect( lambda: [x() for x in [lambda: utils.save_stored_settings(self.ms, self.update_stored_settings(self.parameter_groups), self.stored_settingskey), lambda: utils.save_stored_settings(self.ms, self.update_stored_settings([self.parameter_browser]), self.stored_settingskey_parameterbrowser)]]) self.clear_settings_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('ExportToFieldLogger', 'Clear settings'))) self.clear_settings_button.setToolTip(ru(QCoreApplication.translate('ExportToFieldLogger', 'Clear all input fields settings.'))) self.gridLayout_buttons.addWidget(self.clear_settings_button, 4, 0) self.clear_settings_button.clicked.connect( lambda: [x() for x in [lambda: utils.save_stored_settings(self.ms, [], self.stored_settingskey), lambda: utils.pop_up_info(ru(QCoreApplication.translate('ExportToFieldLogger', 'Settings cleared. Restart Export to Fieldlogger dialog to complete,\nor press "Save settings" to save current input fields settings again.')))]]) self.settings_strings_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('ExportToFieldLogger', 'Settings strings'))) self.settings_strings_button.setToolTip(ru(QCoreApplication.translate('ExportToFieldLogger', 'Access the settings strings ("Create input fields" and input fields) to copy and paste all settings between different qgis projects.\n Usage: Select string and copy to a text editor or directly into Settings strings dialog of another qgis project.'))) self.gridLayout_buttons.addWidget(self.settings_strings_button, 5, 0) self.settings_strings_button.clicked.connect(lambda x: self.settings_strings_dialogs()) self.default_settings_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('ExportToFieldLogger', 'Default settings'))) self.default_settings_button.setToolTip(ru(QCoreApplication.translate('ExportToFieldLogger', 'Updates "Create input fields" and input fields to default settings.'))) self.gridLayout_buttons.addWidget(self.default_settings_button, 6, 0) self.default_settings_button.clicked.connect(lambda x: self.restore_default_settings()) self.gridLayout_buttons.addWidget(get_line(), 7, 0) self.preview_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('ExportToFieldLogger', 'Preview'))) self.preview_button.setToolTip(ru(QCoreApplication.translate('ExportToFieldLogger', 'View a preview of the Fieldlogger location file as pop-up info.'))) self.gridLayout_buttons.addWidget(self.preview_button, 8, 0) # Lambda and map is used to run several functions for every button click self.preview_button.clicked.connect(lambda x: self.preview()) self.export_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('ExportToFieldLogger', 'Export'))) self.export_button.setToolTip(ru(QCoreApplication.translate('ExportToFieldLogger', 'Exports the current combination of locations and input fields to a Fieldlogger location file.'))) self.gridLayout_buttons.addWidget(self.export_button, 9, 0) # Lambda and map is used to run several functions for every button click self.export_button.clicked.connect(lambda x: self.export()) self.gridLayout_buttons.setRowStretch(10, 1) self.show()