Пример #1
0
    def __init__(self, tables_columns, file_header=None):
        super(ImportTableChooser, self).__init__()
        self.tables_columns = tables_columns
        self.file_header = file_header
        self.columns = []
        self.numeric_datatypes = db_utils.numeric_datatypes()

        chooser = RowEntry()

        self.label = qgis.PyQt.QtWidgets.QLabel(ru(QCoreApplication.translate('ImportTableChooser', 'Import to table')))
        self.__import_method = qgis.PyQt.QtWidgets.QComboBox()
        self.__import_method.addItem('')
        self.__import_method.addItems(sorted(list(tables_columns.keys()), key=lambda s: s.lower()))

        self.__import_method.currentIndexChanged.connect( self.choose_method)

        for widget in [self.label, self.__import_method]:
            chooser.layout.addWidget(widget)
        chooser.layout.insertStretch(-1, 5)

        self.layout.addWidget(chooser.widget)

        self.specific_info_widget = VRowEntry()
        self.specific_info_widget.layout.addWidget(get_line())
        self.specific_table_info = qgis.PyQt.QtWidgets.QLabel()
        self.specific_info_widget.layout.addWidget(self.specific_table_info)
        self.specific_info_widget.layout.addWidget(get_line())

        self.layout.addWidget(self.specific_info_widget.widget)
    def __init__(self, tables_columns, file_header=None):
        super(ImportTableChooser, self).__init__()
        self.tables_columns = tables_columns
        self.file_header = file_header
        self.columns = []
        self.numeric_datatypes = db_utils.numeric_datatypes()

        chooser = RowEntry()

        self.label = qgis.PyQt.QtWidgets.QLabel(ru(QCoreApplication.translate('ImportTableChooser', 'Import to table')))
        self.__import_method = qgis.PyQt.QtWidgets.QComboBox()
        self.__import_method.addItem('')
        self.__import_method.addItems(sorted(list(tables_columns.keys()), key=lambda s: s.lower()))

        self.__import_method.currentIndexChanged.connect( self.choose_method)

        for widget in [self.label, self.__import_method]:
            chooser.layout.addWidget(widget)

        self.layout.addWidget(chooser.widget)

        self.specific_info_widget = VRowEntry()
        self.specific_info_widget.layout.addWidget(get_line())
        self.specific_table_info = qgis.PyQt.QtWidgets.QLabel()
        self.specific_info_widget.layout.addWidget(self.specific_table_info)
        self.specific_info_widget.layout.addWidget(get_line())

        self.layout.addWidget(self.specific_info_widget.widget)

        self.layout.insertStretch(-1, 4)
    def select_files_and_load_gui(self):
        self.files = self.select_files()
        if not self.files:
            raise utils.UserInterruptError()

        self.date_time_filter = DateTimeFilter(calendar=True)
        self.add_row(self.date_time_filter.widget)

        self.add_row(get_line())

        self.skip_rows = CheckboxAndExplanation(QCoreApplication.translate('DiverofficeImport', 'Skip rows without water level'),
                                                QCoreApplication.translate('DiverofficeImport', 'Checked = Rows without a value for columns Water head[cm] or Level[cm] will be skipped.'))
        if self.use_skiprows:
            self.skip_rows.checked = True
            self.add_row(self.skip_rows.widget)
            self.add_row(get_line())
        else:
            self.skip_rows.checked = False

        self.confirm_names = CheckboxAndExplanation(QCoreApplication.translate('DiverofficeImport', 'Confirm each logger obsid before import'),
                                                    QCoreApplication.translate('DiverofficeImport', 'Checked = The obsid will be requested of the user for every file.\n\n') +
                                                    QCoreApplication.translate('DiverofficeImport', 'Unchecked = the location attribute, both as is and capitalized, in the\n') +
                                                    QCoreApplication.translate('DiverofficeImport', 'file will be matched against obsids in the database.\n\n') +
                                                    QCoreApplication.translate('DiverofficeImport', 'In both case, obsid will be requested of the user if no match in the database is found.'))
        self.confirm_names.checked = True
        self.add_row(self.confirm_names.widget)
        self.add_row(get_line())
        self.import_all_data = CheckboxAndExplanation(QCoreApplication.translate('DiverofficeImport', 'Import all data'),
                                                      QCoreApplication.translate('DiverofficeImport', 'Checked = any data not matching an exact datetime in the database\n') +
                                                      QCoreApplication.translate('DiverofficeImport', 'for the corresponding obsid will be imported.\n\n') +
                                                      QCoreApplication.translate('DiverofficeImport', 'Unchecked = only new data after the latest date in the database,\n') +
                                                      QCoreApplication.translate('DiverofficeImport', 'for each observation point, will be imported.'))
        self.import_all_data.checked = False
        self.add_row(self.import_all_data.widget)

        self.close_after_import = qgis.PyQt.QtWidgets.QCheckBox(ru(QCoreApplication.translate('DiverofficeImport', 'Close dialog after import')))
        self.close_after_import.setChecked(True)
        self.gridLayout_buttons.addWidget(self.close_after_import, 0, 0)

        self.start_import_button = qgis.PyQt.QtWidgets.QPushButton(QCoreApplication.translate('DiverofficeImport', 'Start import'))
        self.gridLayout_buttons.addWidget(self.start_import_button, 1, 0)
        self.start_import_button.clicked.connect(lambda : self.start_import(files=self.files, skip_rows_without_water_level=self.skip_rows.checked, confirm_names=self.confirm_names.checked, import_all_data=self.import_all_data.checked, from_date=self.date_time_filter.from_date, to_date=self.date_time_filter.to_date))

        self.gridLayout_buttons.setRowStretch(2, 1)

        self.show()
Пример #4
0
    def select_files_and_load_gui(self):
        self.files = self.select_files()
        if not self.files:
            raise utils.UserInterruptError()

        self.date_time_filter = DateTimeFilter(calendar=True)
        self.add_row(self.date_time_filter.widget)

        self.add_row(get_line())

        self.skip_rows = CheckboxAndExplanation(QCoreApplication.translate('DiverofficeImport', u'Skip rows without water level'),
                                                QCoreApplication.translate('DiverofficeImport', u'Checked = Rows without a value for columns Water head[cm] or Level[cm] will be skipped.'))
        self.skip_rows.checked = True
        self.add_row(self.skip_rows.widget)
        self.add_row(get_line())
        self.confirm_names = CheckboxAndExplanation(QCoreApplication.translate('DiverofficeImport', u'Confirm each logger obsid before import'),
                                                    QCoreApplication.translate('DiverofficeImport', u'Checked = The obsid will be requested of the user for every file.\n\n') +
                                                    QCoreApplication.translate('DiverofficeImport', u'Unchecked = the location attribute, both as is and capitalized, in the\n') +
                                                    QCoreApplication.translate('DiverofficeImport', u'file will be matched against obsids in the database.\n\n') +
                                                    QCoreApplication.translate('DiverofficeImport', u'In both case, obsid will be requested of the user if no match in the database is found.'))
        self.confirm_names.checked = True
        self.add_row(self.confirm_names.widget)
        self.add_row(get_line())
        self.import_all_data = CheckboxAndExplanation(QCoreApplication.translate('DiverofficeImport', u'Import all data'),
                                                      QCoreApplication.translate('DiverofficeImport', u'Checked = any data not matching an exact datetime in the database\n') +
                                                      QCoreApplication.translate('DiverofficeImport', u'for the corresponding obsid will be imported.\n\n') +
                                                      QCoreApplication.translate('DiverofficeImport', u'Unchecked = only new data after the latest date in the database,\n') +
                                                      QCoreApplication.translate('DiverofficeImport', u'for each observation point, will be imported.'))
        self.import_all_data.checked = False
        self.add_row(self.import_all_data.widget)

        self.close_after_import = PyQt4.QtGui.QCheckBox(ru(QCoreApplication.translate(u'DiverofficeImport', u'Close dialog after import')))
        self.close_after_import.setChecked(True)
        self.gridLayout_buttons.addWidget(self.close_after_import, 0, 0)

        self.start_import_button = PyQt4.QtGui.QPushButton(QCoreApplication.translate('DiverofficeImport', u'Start import'))
        self.gridLayout_buttons.addWidget(self.start_import_button, 1, 0)
        self.connect(self.start_import_button, PyQt4.QtCore.SIGNAL("clicked()"), lambda : self.start_import(files=self.files, skip_rows_without_water_level=self.skip_rows.checked, confirm_names=self.confirm_names.checked, import_all_data=self.import_all_data.checked, from_date=self.date_time_filter.from_date, to_date=self.date_time_filter.to_date))

        self.gridLayout_buttons.setRowStretch(2, 1)

        self.show()
Пример #5
0
    def load_gui(self):
        self.tables_columns_info = {k: v for (k, v) in db_utils.db_tables_columns_info().items() if not k.endswith('_geom')}
        self.table_chooser = ImportTableChooser(self.tables_columns_info, file_header=None)
        self.main_vertical_layout.addWidget(self.table_chooser.widget)
        self.main_vertical_layout.addStretch()
        #General buttons
        self.select_file_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Load data from file')))
        self.gridLayout_buttons.addWidget(self.select_file_button, 0, 0)
        self.select_file_button.clicked.connect(lambda x: self.select_file())


        self.import_all_features_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Load data from all features\nfrom active layer')))
        self.gridLayout_buttons.addWidget(self.import_all_features_button, 1, 0)
        self.import_all_features_button.clicked.connect(lambda x: self.import_all_features())

        self.import_selected_features_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Load data from selected features\nfrom active layer')))
        self.gridLayout_buttons.addWidget(self.import_selected_features_button, 2, 0)
        self.import_selected_features_button.clicked.connect(lambda x: self.import_selected_features())

        self.gridLayout_buttons.addWidget(get_line(), 3, 0)

        tables_columns = db_utils.tables_columns()
        self.distinct_value_browser = DistinctValuesBrowser(tables_columns)
        self.gridLayout_buttons.addWidget(self.distinct_value_browser.widget, 4, 0)

        self.gridLayout_buttons.addWidget(get_line(), 5, 0)

        self.close_after_import = qgis.PyQt.QtWidgets.QCheckBox(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Close dialog after import')))
        self.close_after_import.setChecked(True)
        self.gridLayout_buttons.addWidget(self.close_after_import, 6, 0)

        self.start_import_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Start import')))
        self.gridLayout_buttons.addWidget(self.start_import_button, 7, 0)
        self.start_import_button.clicked.connect(lambda x: self.start_import())

        self.gridLayout_buttons.setRowStretch(8, 1)

        self.show()
Пример #6
0
    def __init__(self, tables_columns, connect, file_header=None):
        super(ImportTableChooser, self).__init__()
        self.connect = connect
        self.tables_columns = tables_columns
        self.file_header = file_header
        self.columns = []
        self.numeric_datatypes = db_utils.numeric_datatypes()

        chooser = RowEntry()

        self.label = PyQt4.QtGui.QLabel(
            ru(
                QCoreApplication.translate(u'ImportTableChooser',
                                           'Import to table')))
        self.__import_method = PyQt4.QtGui.QComboBox()
        self.__import_method.addItem(u'')
        self.__import_method.addItems(
            sorted(tables_columns.keys(), key=lambda s: s.lower()))

        self.connect(
            self.__import_method,
            PyQt4.QtCore.SIGNAL("currentIndexChanged(const QString&)"),
            self.choose_method)

        for widget in [self.label, self.__import_method]:
            chooser.layout.addWidget(widget)

        self.layout.addWidget(chooser.widget)

        self.specific_info_widget = VRowEntry()
        self.specific_info_widget.layout.addWidget(get_line())
        self.specific_table_info = PyQt4.QtGui.QLabel()
        self.specific_info_widget.layout.addWidget(self.specific_table_info)
        self.specific_info_widget.layout.addWidget(get_line())

        self.layout.addWidget(self.specific_info_widget.widget)

        self.layout.insertStretch(-1, 4)
    def load_gui(self):
        self.tables_columns_info = {k: v for (k, v) in db_utils.db_tables_columns_info().items() if not k.endswith('_geom')}
        self.table_chooser = ImportTableChooser(self.tables_columns_info, file_header=None)
        self.main_vertical_layout.addWidget(self.table_chooser.widget)
        self.main_vertical_layout.addStretch()
        #General buttons
        self.select_file_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Load data from file')))
        self.gridLayout_buttons.addWidget(self.select_file_button, 0, 0)
        self.select_file_button.clicked.connect(lambda x: self.select_file())


        self.import_all_features_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Load data from all features\nfrom active layer')))
        self.gridLayout_buttons.addWidget(self.import_all_features_button, 1, 0)
        self.import_all_features_button.clicked.connect(lambda x: self.import_all_features())

        self.import_selected_features_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Load data from selected features\nfrom active layer')))
        self.gridLayout_buttons.addWidget(self.import_selected_features_button, 2, 0)
        self.import_selected_features_button.clicked.connect(lambda x: self.import_selected_features())

        self.gridLayout_buttons.addWidget(get_line(), 3, 0)

        tables_columns = db_utils.tables_columns()
        self.distinct_value_browser = DistinctValuesBrowser(tables_columns)
        self.gridLayout_buttons.addWidget(self.distinct_value_browser.widget, 4, 0)

        self.gridLayout_buttons.addWidget(get_line(), 5, 0)

        self.close_after_import = qgis.PyQt.QtWidgets.QCheckBox(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Close dialog after import')))
        self.close_after_import.setChecked(True)
        self.gridLayout_buttons.addWidget(self.close_after_import, 6, 0)

        self.start_import_button = qgis.PyQt.QtWidgets.QPushButton(ru(QCoreApplication.translate('GeneralCsvImportGui', 'Start import')))
        self.gridLayout_buttons.addWidget(self.start_import_button, 7, 0)
        self.start_import_button.clicked.connect(lambda x: self.start_import())

        self.gridLayout_buttons.setRowStretch(8, 1)

        self.show()
Пример #8
0
    def load_gui(self):
        self.tables_columns_info = {
            k: v
            for (k, v) in db_utils.db_tables_columns_info().iteritems()
            if not k.endswith(u'_geom')
        }
        self.table_chooser = ImportTableChooser(self.tables_columns_info,
                                                self.connect,
                                                file_header=None)
        self.main_vertical_layout.addWidget(self.table_chooser.widget)
        self.main_vertical_layout.addStretch()
        #General buttons
        self.select_file_button = PyQt4.QtGui.QPushButton(
            ru(
                QCoreApplication.translate(u'GeneralCsvImportGui',
                                           u'Load data from file')))
        self.gridLayout_buttons.addWidget(self.select_file_button, 0, 0)
        self.connect(
            self.select_file_button, PyQt4.QtCore.SIGNAL("clicked()"),
            lambda: map(lambda x: x(), [
                lambda: self.load_files(), lambda: self.table_chooser.reload(),
                lambda: self.file_data_loaded_popup()
            ]))

        self.import_all_features_button = PyQt4.QtGui.QPushButton(
            ru(
                QCoreApplication.translate(
                    u'GeneralCsvImportGui',
                    u'Load data from all features\nfrom active layer')))
        self.gridLayout_buttons.addWidget(self.import_all_features_button, 1,
                                          0)
        self.connect(
            self.import_all_features_button, PyQt4.QtCore.SIGNAL("clicked()"),
            lambda: map(lambda x: x(), [
                lambda: self.load_from_active_layer(
                    only_selected=False), lambda: self.table_chooser.reload(),
                lambda: self.file_data_loaded_popup()
            ]))

        self.import_selected_features_button = PyQt4.QtGui.QPushButton(
            ru(
                QCoreApplication.translate(
                    u'GeneralCsvImportGui',
                    u'Load data from selected features\nfrom active layer')))
        self.gridLayout_buttons.addWidget(self.import_selected_features_button,
                                          2, 0)
        self.connect(
            self.import_selected_features_button,
            PyQt4.QtCore.SIGNAL("clicked()"),
            lambda: map(lambda x: x(), [
                lambda: self.load_from_active_layer(
                    only_selected=True), lambda: self.table_chooser.reload(),
                lambda: self.file_data_loaded_popup()
            ]))

        self.gridLayout_buttons.addWidget(get_line(), 3, 0)

        tables_columns = db_utils.tables_columns()
        self.distinct_value_browser = DistinctValuesBrowser(
            tables_columns, self.connect)
        self.gridLayout_buttons.addWidget(self.distinct_value_browser.widget,
                                          4, 0)

        self.gridLayout_buttons.addWidget(get_line(), 5, 0)

        self.close_after_import = PyQt4.QtGui.QCheckBox(
            ru(
                QCoreApplication.translate(u'GeneralCsvImportGui',
                                           u'Close dialog after import')))
        self.close_after_import.setChecked(True)
        self.gridLayout_buttons.addWidget(self.close_after_import, 6, 0)

        self.start_import_button = PyQt4.QtGui.QPushButton(
            ru(
                QCoreApplication.translate(u'GeneralCsvImportGui',
                                           u'Start import')))
        self.gridLayout_buttons.addWidget(self.start_import_button, 7, 0)
        self.connect(self.start_import_button,
                     PyQt4.QtCore.SIGNAL("clicked()"), self.start_import)

        self.gridLayout_buttons.setRowStretch(8, 1)

        self.show()
Пример #9
0
    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.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()