def addMenuSeparator(self): """Adds a separator to the specified menu bar""" separator = QAction() separator.setSeparator(True) self.iface.addPluginToMenu(self.menu, separator) self.actions.append(separator)
def registerDatabaseActions(self, mainWindow): Database.registerDatabaseActions(self, mainWindow) # add a separator separator = QAction(self) separator.setSeparator(True) mainWindow.registerAction(separator, self.tr("&Table")) action = QAction(self.tr("Run &Vacuum Analyze"), self) mainWindow.registerAction(action, self.tr("&Table"), self.runVacuumAnalyzeActionSlot)
def registerDatabaseActions(self, mainWindow): Database.registerDatabaseActions(self, mainWindow) # add a separator separator = QAction(self) separator.setSeparator(True) mainWindow.registerAction(separator, self.tr("&Table")) action = QAction(self.tr("Run &Vacuum Analyze"), self) mainWindow.registerAction(action, self.tr("&Table"), self.runVacuumAnalyzeActionSlot) action = QAction(self.tr("Run &Refresh Materialized View"), self) mainWindow.registerAction(action, self.tr("&Table"), self.runRefreshMaterializedViewSlot)
def actions(self, parent): actions = [] # user custom map if 'custom' in self._dataset: add_custom_action = QAction(QIcon(), 'Add Layer', parent) add_custom_action.triggered.connect( lambda: self._add_custom_to_canvas()) actions.append(add_custom_action) edit_action = QAction(QIcon(), 'Edit', parent) edit_action.triggered.connect(self._edit) actions.append(edit_action) delete_action = QAction(QIcon(), 'Delete', parent) delete_action.triggered.connect(self._delete) actions.append(delete_action) # MapTiler map else: add_raster_action = QAction(QIcon(), 'Add as Raster', parent) add_raster_action.triggered.connect( lambda: self._add_raster_to_canvas()) actions.append(add_raster_action) # QGIS version 3.13 or more if utils.is_qgs_vectortile_api_enable(): add_vector_action = QAction(QIcon(), 'Add as Vector', parent) add_vector_action.triggered.connect( lambda: self._add_vector_to_canvas()) actions.append(add_vector_action) remove_action = QAction(QIcon(), 'Remove', parent) remove_action.triggered.connect(self._remove) actions.append(remove_action) if 'customize_url' in self._dataset: separator = QAction(QIcon(), '', parent) separator.setSeparator(True) actions.append(separator) open_customize_url_action = QAction(QIcon(), 'Customize in Cloud ↗', parent) open_customize_url_action.triggered.connect( self._open_customize_url) actions.append(open_customize_url_action) return actions
def add_group_separator(self, add_to_menu=True, add_to_toolbar=True, parent=None): sep_action = QAction(parent) sep_action.setSeparator(True) if add_to_menu: self.iface.addPluginToMenu(self.menu, sep_action) if add_to_toolbar: self.toolbar.addAction(sep_action) self.actions.append(sep_action)
def _getActions(self): """Get actions that are displayed in the context menu""" actions = [] scaleAction = QAction("Scale...", self) scaleAction.triggered.connect(self._scale) scaleAction.setEnabled(True) actions.append(scaleAction) exportAction = QAction("Export as...", self) exportAction.triggered.connect(self._exportToFile) exportAction.setEnabled(True) actions.append(exportAction) sep = QAction("", self) sep.setSeparator(True) actions.append(sep) group = QActionGroup(self) group.addAction(self._nsAction) actions.append(self._nsAction) group.addAction(self._snAction) actions.append(self._snAction) group.addAction(self._weAction) actions.append(self._weAction) group.addAction(self._ewAction) actions.append(self._ewAction) sepAbout = QAction("", self) sepAbout.setSeparator(True) actions.append(sepAbout) manualAction = QAction("Manual...", self) manualAction.triggered.connect(self._openManual) manualAction.setEnabled(True) actions.append(manualAction) aboutAction = QAction("About...", self) aboutAction.triggered.connect(self._aboutPlugin) aboutAction.setEnabled(True) actions.append(aboutAction) return actions
def setAsRepoLayer(layer): removeLayerActions(layer) canConnect = addInfoActions(layer) separatorAction = QAction("", config.iface.legendInterface()) separatorAction.setSeparator(True) config.iface.legendInterface().addLegendLayerAction(separatorAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer(separatorAction, layer) syncAction = QAction(u"Sync layer with branch...", config.iface.legendInterface()) syncAction.triggered.connect(partial(syncLayer, layer)) config.iface.legendInterface().addLegendLayerAction(syncAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer(syncAction, layer) changeVersionAction = QAction(u"Change to a different commit...", config.iface.legendInterface()) changeVersionAction.triggered.connect(partial(changeVersion, layer)) config.iface.legendInterface().addLegendLayerAction(changeVersionAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer(changeVersionAction, layer) revertChangeAction = QAction(u"Revert commit...", config.iface.legendInterface()) revertChangeAction.triggered.connect(partial(revertChange, layer)) config.iface.legendInterface().addLegendLayerAction(revertChangeAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer(revertChangeAction, layer) changesAction = QAction(u"Show local changes...", config.iface.legendInterface()) changesAction.triggered.connect(partial(showLocalChanges, layer)) config.iface.legendInterface().addLegendLayerAction(changesAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer(changesAction, layer) revertAction = QAction(u"Revert local changes", config.iface.legendInterface()) revertAction.triggered.connect(partial(revertLocalChanges, layer)) config.iface.legendInterface().addLegendLayerAction(revertAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer(revertAction, layer) _actions[layer.id()] = [separatorAction, syncAction, changeVersionAction, revertChangeAction, changesAction, revertAction] for action in _actions[layer.id()]: action.setEnabled(canConnect) if not canConnect: refreshAction = QAction(u"Retry connecting...", config.iface.legendInterface()) refreshAction.triggered.connect(lambda: setAsRepoLayer(layer)) config.iface.legendInterface().addLegendLayerAction(refreshAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer(refreshAction, layer) _actions[layer.id()].append(refreshAction) _actions[layer.id()].extend(_infoActions[layer.id()]) repoWatcher.layerUpdated.connect(updateInfoActions)
def _add_spacer_to_menu(self): """Create a spacer to the menu to separate action groups.""" separator = QAction(self.iface.mainWindow()) separator.setSeparator(True) self.iface.addPluginToMenu(self.tr('InaSAFE'), separator)
class QgsProjectGeneratorPlugin(QObject): def __init__(self, iface): QObject.__init__(self) self.iface = iface self.plugin_dir = os.path.dirname(__file__) self.__generate_action = None self.__export_action = None self.__importdata_action = None self.__configure_action = None self.__help_action = None self.__about_action = None self.__separator = None if locale.getlocale() == (None, None): locale.setlocale(locale.LC_ALL, '') # initialize translation qgis_locale_id = str(QSettings().value('locale/userLocale')) qgis_locale = QLocale(qgis_locale_id) locale_path = os.path.join(self.plugin_dir, 'i18n') self.translator = QTranslator() self.translator.load(qgis_locale, 'projectgenerator', '_', locale_path) QCoreApplication.installTranslator(self.translator) self.ili2db_configuration = BaseConfiguration() settings = QSettings() settings.beginGroup('QgsProjectGenerator/ili2db') self.ili2db_configuration.restore(settings) def initGui(self): self.__generate_action = QAction( QIcon( os.path.join(os.path.dirname(__file__), 'images/projectgenerator-icon.svg')), self.tr('Generate'), None) self.__export_action = QAction( QIcon( os.path.join(os.path.dirname(__file__), 'images/projectgenerator-xtf-export-icon.svg')), self.tr('Export Interlis Transfer File (.xtf)'), None) self.__importdata_action = QAction( QIcon( os.path.join(os.path.dirname(__file__), 'images/projectgenerator-xtf-import-icon.svg')), self.tr('Import Interlis Transfer File (.xtf)'), None) self.__configure_action = QAction(self.tr('Settings'), None) self.__help_action = QAction(self.tr('Help'), None) self.__about_action = QAction(self.tr('About'), None) self.__separator = QAction(None) self.__separator.setSeparator(True) self.__generate_action.triggered.connect(self.show_generate_dialog) self.__configure_action.triggered.connect(self.show_options_dialog) self.__importdata_action.triggered.connect(self.show_importdata_dialog) self.__export_action.triggered.connect(self.show_export_dialog) self.__help_action.triggered.connect(self.show_help_documentation) self.__about_action.triggered.connect(self.show_about_dialog) self.iface.addPluginToDatabaseMenu(self.tr('Project Generator'), self.__generate_action) self.iface.addPluginToDatabaseMenu(self.tr('Project Generator'), self.__importdata_action) self.iface.addPluginToDatabaseMenu(self.tr('Project Generator'), self.__export_action) self.iface.addPluginToDatabaseMenu(self.tr('Project Generator'), self.__configure_action) self.iface.addPluginToDatabaseMenu(self.tr('Project Generator'), self.__separator) self.iface.addPluginToDatabaseMenu(self.tr('Project Generator'), self.__help_action) self.iface.addPluginToDatabaseMenu(self.tr('Project Generator'), self.__about_action) self.toolbar = self.iface.addToolBar(self.tr('Project Generator')) self.toolbar.setObjectName("ProjectGeneratorToolbar") self.toolbar.setToolTip(self.tr('Project Generator Toolbar')) self.toolbar.addAction(self.__generate_action) self.toolbar.addAction(self.__importdata_action) self.toolbar.addAction(self.__export_action) def unload(self): self.iface.removePluginDatabaseMenu(self.tr('Project Generator'), self.__generate_action) self.iface.removePluginDatabaseMenu(self.tr('Project Generator'), self.__importdata_action) self.iface.removePluginDatabaseMenu(self.tr('Project Generator'), self.__export_action) self.iface.removePluginDatabaseMenu(self.tr('Project Generator'), self.__configure_action) self.iface.removePluginDatabaseMenu(self.tr('Project Generator'), self.__help_action) self.iface.removePluginDatabaseMenu(self.tr('Project Generator'), self.__about_action) del self.__generate_action del self.__export_action del self.__importdata_action del self.__configure_action del self.__help_action del self.__about_action def show_generate_dialog(self): dlg = GenerateProjectDialog(self.iface, self.ili2db_configuration) dlg.exec_() def show_options_dialog(self): dlg = OptionsDialog(self.ili2db_configuration) if dlg.exec_(): settings = QSettings() settings.beginGroup('QgsProjectGenerator/ili2db') self.ili2db_configuration.save(settings) def show_export_dialog(self): dlg = ExportDialog(self.ili2db_configuration) dlg.exec_() def show_importdata_dialog(self): dlg = ImportDataDialog(self.ili2db_configuration) dlg.exec_() def show_help_documentation(self): os_language = QLocale( QSettings().value('locale/userLocale')).name()[:2] if os_language in ['es', 'de']: webbrowser.open( 'https://opengisch.github.io/projectgenerator/docs/{}/'.format( os_language)) else: webbrowser.open( 'https://opengisch.github.io/projectgenerator/docs/index.html') def show_about_dialog(self): self.msg = QMessageBox() self.msg.setIcon(QMessageBox.Information) self.msg.setTextFormat(Qt.RichText) self.msg.setWindowTitle(self.tr('About Project Generator')) self.msg.setText( self.tr("""<h1>Project Generator</h1> <p align="justify">Configuring QGIS layers and forms manually is a tedious and error prone process. This plugin loads database schemas with various meta information to preconfigure the layer tree, widget configuration, relations and more.</p> <p align="justify">This project is open source under the terms of the GPLv2 or later and the source code can be found on <a href="https://github.com/opengisch/projectgenerator">github</a>.</p> <p align="justify">This plugin is developed by <a href="https://www.opengis.ch/">OPENGIS.ch</a> in collaboration with <a href="https://www.proadmintierra.info/">Agencia de Implementación (BSF-Swissphoto AG / INCIGE S.A.S.)</a>.</p></p>""" )) self.msg.setStandardButtons(QMessageBox.Close) msg_box = self.msg.exec_() def get_generator(self): return Generator def create_project(self, layers, relations, bags_of_enum, legend, auto_transaction=True, evaluate_default_values=True): """ Expose the main functionality from Project Generator to other plugins, namely, create a QGIS project from objects obtained from the Generator class. :param layers: layers object from generator.layers :param relations: relations object obtained from generator.relations :param bags_of_enum: bags_of_enum object from generator.relations :param legend: legend object obtained from generator.legend :param auto_transaction: whether transactions should be enabled or not when editing layers from supported DB like PG :param evaluate_default_values: should default values be evaluated on provider side when requested and not when committed. (from QGIS docs) """ project = Project(auto_transaction, evaluate_default_values) project.layers = layers project.relations = relations project.bags_of_enum = bags_of_enum project.legend = legend project.post_generate() qgis_project = QgsProject.instance() project.create(None, qgis_project)
class DocumentViewManager(QMainWindow): """ MDI area for displaying supporting documents within a given context e.g. supporting documents for a specific household based on the lifetime of the 'SourceDocumentManager' instance. """ def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.setWindowFlags(Qt.Window) self._mdi_area = QMdiArea() self._mdi_area.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded) self._mdi_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.setCentralWidget(self._mdi_area) # set the size of mid_area and DocumentViewManager based on the # screen size. screen = QDesktopWidget().availableGeometry() self._mdi_area.resize(screen.width() - 30, screen.height() - 80) self.resize(self._mdi_area.size()) self._mdi_area.subWindowActivated.connect(self.update_actions) self._viewer_mapper = QSignalMapper(self) self._viewer_mapper.mapped[QWidget].connect(self.set_active_sub_window) win_title = QApplication.translate("DocumentViewManager", "Document Viewer") self.setWindowTitle(win_title) self.setUnifiedTitleAndToolBarOnMac(True) self.statusBar().showMessage( QApplication.translate("DocumentViewManager", "Ready")) self._doc_viewers = {} self._create_menu_actions() self.update_actions() def center(self): """ Move the Document viewer to the center of the screen. """ # Get the current screens' dimensions... screen = QDesktopWidget().availableGeometry() # ... and get this windows' dimensions mdi_area_size = self.frameGeometry() # The horizontal position hpos = (screen.width() - mdi_area_size.width()) / 2 # vertical position vpos = (screen.height() - mdi_area_size.height()) / 2 # repositions the window self.move(hpos, vpos) def _create_menu_actions(self): self._window_menu = self.menuBar().addMenu( QApplication.translate("DocumentViewManager", "&Windows")) self._close_act = QAction( QApplication.translate("DocumentViewManager", "Cl&ose"), self) self._close_act.setStatusTip( QApplication.translate("DocumentViewManager", "Close the active document viewer")) self._close_act.triggered.connect(self._mdi_area.closeActiveSubWindow) self._close_all_act = QAction( QApplication.translate("DocumentViewManager", "Close &All"), self) self._close_all_act.setStatusTip( QApplication.translate("DocumentViewManager", "Close all the document viewers")) self._close_all_act.triggered.connect( self._mdi_area.closeAllSubWindows) self._tile_act = QAction( QApplication.translate("DocumentViewManager", "&Tile"), self) self._tile_act.setStatusTip( QApplication.translate("DocumentViewManager", "Tile the document viewers")) self._tile_act.triggered.connect(self.tile_windows) self._cascade_act = QAction( QApplication.translate("DocumentViewManager", "&Cascade"), self) self._cascade_act.setStatusTip( QApplication.translate("DocumentViewManager", "Cascade the document viewers")) self._cascade_act.triggered.connect(self.cascade_windows) self._next_act = QAction( QApplication.translate("DocumentViewManager", "Ne&xt"), self) self._next_act.setStatusTip( QApplication.translate( "DocumentViewManager", "Move the focus to the next document viewer")) self._next_act.triggered.connect(self._mdi_area.activateNextSubWindow) self._previous_act = QAction( QApplication.translate("DocumentViewManager", "Pre&vious"), self) self._previous_act.setStatusTip( QApplication.translate( "DocumentViewManager", "Move the focus to the previous document viewer")) self._previous_act.triggered.connect( self._mdi_area.activatePreviousSubWindow) self._separator_act = QAction(self) self._separator_act.setSeparator(True) self.update_window_menu() self._window_menu.aboutToShow.connect(self.update_window_menu) def cascade_windows(self): # Cascade document windows self._mdi_area.cascadeSubWindows() def tile_windows(self): # Arrange document windows to occupy the available space in mdi area self._mdi_area.tileSubWindows() def update_actions(self): if self._mdi_area.activeSubWindow(): has_mdi_child = True else: has_mdi_child = False self._close_act.setEnabled(has_mdi_child) self._close_all_act.setEnabled(has_mdi_child) self._tile_act.setEnabled(has_mdi_child) self._cascade_act.setEnabled(has_mdi_child) self._previous_act.setEnabled(has_mdi_child) self._next_act.setEnabled(has_mdi_child) self._separator_act.setVisible(has_mdi_child) def update_window_menu(self): self._window_menu.clear() self._window_menu.addAction(self._close_act) self._window_menu.addAction(self._close_all_act) self._window_menu.addSeparator() self._window_menu.addAction(self._tile_act) self._window_menu.addAction(self._cascade_act) self._window_menu.addSeparator() self._window_menu.addAction(self._next_act) self._window_menu.addAction(self._previous_act) self._window_menu.addAction(self._separator_act) windows = self._mdi_area.subWindowList() self._separator_act.setVisible(len(windows) != 0) for i, window in enumerate(windows): text = "%d. %s" % (i + 1, window.windowTitle()) win_action = self._window_menu.addAction(text) win_action.setCheckable(True) win_action.setChecked(window is self._mdi_area.activeSubWindow()) win_action.triggered.connect(self._viewer_mapper.map) self._viewer_mapper.setMapping(win_action, window) def load_viewer(self, document_widget, visible=True): """ Open a new instance of the viewer or activate an existing one if the document had been previously loaded. :param document_widget: Contains all the necessary information required to load the specific document. :type document_widget: DocumentWidget :param visible: True to show the view manager after the viewer has been loaded, otherwise it will be the responsibility of the caller to enable visibility. :type visible: bool :returns: True if the document was successfully loaded, else False. :rtype: bool """ doc_identifier = document_widget.file_identifier() if doc_identifier in self._doc_viewers: doc_sw = self._doc_viewers[doc_identifier] self._mdi_area.setActiveSubWindow(doc_sw) doc_sw.showNormal() else: abs_doc_path = self.absolute_document_path(document_widget) if not QFile.exists(abs_doc_path): msg = QApplication.translate( "DocumentViewManager", "The selected document does not exist." "\nPlease check the supporting documents' " "repository setting.") QMessageBox.critical( self, QApplication.translate("DocumentViewManager", "Invalid Document"), msg) return False file_info = QFileInfo(abs_doc_path) ext = file_info.suffix().lower() if ext == 'pdf': os.startfile(abs_doc_path) return True doc_viewer = self._create_viewer(document_widget) doc_viewer.load_document(abs_doc_path) self._doc_viewers[doc_identifier] = doc_viewer self._mdi_area.addSubWindow(doc_viewer) doc_viewer.show() if not self.isVisible() and visible: self.setVisible(True) if self.isMinimized(): self.showNormal() self.center() return True def set_active_sub_window(self, viewer): if viewer: self._mdi_area.setActiveSubWindow(viewer) def absolute_document_path(self, document_widget): """ Build the absolute document path using info from the document widget. :param document_widget: Instance of document widget. :return: Absolute path of the supporting document. :rtype: str """ abs_path = '' file_manager = document_widget.fileManager if not file_manager is None: network_repository = file_manager.networkPath file_id = document_widget.file_identifier() source_entity = document_widget.doc_source_entity() profile_name = current_profile().name doc_type = document_widget.doc_type_value().lower().replace( ' ', '_') file_name, file_extension = guess_extension( document_widget.displayName()) abs_path = network_repository + "/" + profile_name + '/' + \ str(source_entity) + "/" + str(doc_type) + "/" + \ str(file_id) + str(file_extension) return abs_path def reset(self): """ Removes all document viewers in the view area. The QCloseEvent sent to each sub-window will decrement the register. """ self._mdi_area.closeAllSubWindows() def _create_viewer(self, document_widget): """ Creates a new instance of a document viewer. :param document_widget: Contains all the necessary information required to load the specific document. :return: Document viewer object :rtype: DocumentViewer """ doc_viewer = DocumentViewer(self._mdi_area, document_widget.file_identifier()) doc_viewer.setAttribute(Qt.WA_DeleteOnClose) doc_viewer.setWindowTitle(document_widget.displayName()) # TODO: Incorporate logic for determining # TODO: viewer based on document type ph_viewer = PhotoViewer() # v_layout = QVBoxLayout() # v_layout.addWidget(ph_viewer) # doc_viewer.setLayout(v_layout) doc_viewer.set_view_widget(ph_viewer) doc_viewer.closed.connect(self._on_viewer_closed) return doc_viewer def remove_viewer(self, viewer_id): """ Close and remove the viewer with the specified viewer ID. """ if viewer_id in self._doc_viewers: viewer = self._doc_viewers[viewer_id] self._mdi_area.setActiveSubWindow(viewer) self._mdi_area.closeActiveSubWindow() self._on_viewer_closed(viewer_id) def _on_viewer_closed(self, file_id): """ Slot raised when a document viewer is closed. """ if file_id in self._doc_viewers: del self._doc_viewers[file_id]
def action(self): separatorAct = QAction(self.composerView()) separatorAct.setSeparator(True) return separatorAct
def createActions(self): ACTIONS = [ ('Split Polylines', lambda: self.onAnalysis( wizards.SplitPolylinesWiz, SplitPolylinesAnalysis), None), ('Create Segment Map', lambda: self.onAnalysis( wizards.CreateSegmentMapWiz, CreateSegmentMapAnalysis), None), ('Create Junctions', lambda: self.onAnalysis( wizards.CreateJunctionsWiz, CreateJunctionsAnalysis), None), None, ('Reach', lambda: self.onAnalysis(wizards.ReachWiz, ReachAnalysis), None), ('Network Integration', lambda: self.onAnalysis( wizards.NetworkIntegrationWiz, NetworkIntegrationAnalysis), None), ('Angular Integration', lambda: self.onAnalysis( wizards.AngularIntegrationWiz, AngularIntegrationAnalysis), None), ('Network Betweenness', lambda: self.onAnalysis( wizards.NetworkBetweennessWiz, NetworkBetweennessAnalysis), None), ('Angular Betweenness', lambda: self.onAnalysis( wizards.AngularBetweennessWiz, AngularBetweennessAnalysis), None), ('Angular Choice', lambda: self.onAnalysis( wizards.AngularChoiceWiz, AngularChoiceAnalysis), None), ('Attraction Distance', lambda: self.onAnalysis( wizards.AttractionDistanceWiz, AttractionDistanceAnalysis), None), ('Attraction Reach', lambda: self.onAnalysis( wizards.AttractionReachWiz, AttractionReachAnalysis), None), ('Attraction Betweenness', lambda: self.onAnalysis(wizards.AttractionBetweennessWiz, AttractionBetweennessAnalysis), None) ] if ENABLE_EXPERIMENTAL_ANALYSES: from .analyses import SegmentGroupingAnalysis, SegmentGroupIntegrationAnalysis ACTIONS += [ None, ('Segment Grouping', lambda: self.onAnalysis( wizards.SegmentGroupingWiz, SegmentGroupingAnalysis), None), ('Segment Group Integration', lambda: self.onAnalysis(wizards.SegmentGroupIntegrationWiz, SegmentGroupIntegrationAnalysis), None), ] actions = [] for a in ACTIONS: act = None if a is None: act = QAction(self.iface.mainWindow()) act.setSeparator(True) else: icon = QIcon(a[2]) if a[2] else None act = QAction( a[0], self.iface.mainWindow()) if icon is None else QAction( icon, a[0], self.iface.mainWindow()) act.triggered.connect(a[1]) actions.append(act) return actions
def setAsRepoLayer(layer): removeLayerActions(layer) canConnect = addInfoActions(layer) separatorAction = QAction("", config.iface.legendInterface()) separatorAction.setSeparator(True) config.iface.legendInterface().addLegendLayerAction( separatorAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer( separatorAction, layer) syncAction = QAction(u"Sync layer with repository branch...", config.iface.legendInterface()) syncAction.triggered.connect(partial(syncLayer, layer)) config.iface.legendInterface().addLegendLayerAction( syncAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer( syncAction, layer) changeVersionAction = QAction(u"Change to a different version...", config.iface.legendInterface()) changeVersionAction.triggered.connect(partial(changeVersion, layer)) config.iface.legendInterface().addLegendLayerAction( changeVersionAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer( changeVersionAction, layer) revertChangeAction = QAction(u"Revert changes introduced by a version...", config.iface.legendInterface()) revertChangeAction.triggered.connect(partial(revertChange, layer)) config.iface.legendInterface().addLegendLayerAction( revertChangeAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer( revertChangeAction, layer) changesAction = QAction(u"Show local changes...", config.iface.legendInterface()) changesAction.triggered.connect(partial(showLocalChanges, layer)) config.iface.legendInterface().addLegendLayerAction( changesAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer( changesAction, layer) revertAction = QAction(u"Revert local changes", config.iface.legendInterface()) revertAction.triggered.connect(partial(revertLocalChanges, layer)) config.iface.legendInterface().addLegendLayerAction( revertAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer( revertAction, layer) layer.geogigActions = [ separatorAction, syncAction, changeVersionAction, revertChangeAction, changesAction, revertAction ] for action in layer.geogigActions: action.setEnabled(canConnect) if not canConnect: refreshAction = QAction(u"Retry connecting...", config.iface.legendInterface()) refreshAction.triggered.connect(lambda: setAsRepoLayer(layer)) config.iface.legendInterface().addLegendLayerAction( refreshAction, u"GeoGig", u"id1", QgsMapLayer.VectorLayer, False) config.iface.legendInterface().addLegendLayerActionForLayer( refreshAction, layer) layer.geogigActions.append(refreshAction) layer.geogigActions.extend(layer.infoActions) repoWatcher.layerUpdated.connect(updateInfoActions)
class QgisModelBakerPlugin(QObject): def __init__(self, iface): QObject.__init__(self) self.iface = iface self.plugin_dir = os.path.dirname(__file__) self.generate_dlg = None self.export_dlg = None self.importdata_dlg = None self.__generate_action = None self.__export_action = None self.__importdata_action = None self.__configure_action = None self.__help_action = None self.__about_action = None self.__separator = None basepath = pathlib.Path(__file__).parent.absolute() metadata = configparser.ConfigParser() metadata.read(os.path.join(basepath, 'metadata.txt')) self.__version__ = metadata['general']['version'] if locale.getlocale() == (None, None): locale.setlocale(locale.LC_ALL, '') # initialize translation qgis_locale_id = str(QSettings().value('locale/userLocale')) qgis_locale = QLocale(qgis_locale_id) locale_path = os.path.join(self.plugin_dir, 'i18n') self.translator = QTranslator() self.translator.load(qgis_locale, 'QgisModelBaker', '_', locale_path) QCoreApplication.installTranslator(self.translator) self.ili2db_configuration = BaseConfiguration() settings = QSettings() settings.beginGroup('QgisModelBaker/ili2db') self.ili2db_configuration.restore(settings) self.event_filter = DropFileFilter(self) def register_event_filter(self): if not self.event_filter: self.event_filter = DropFileFilter(self) self.iface.mainWindow().installEventFilter(self.event_filter) def unregister_event_filter(self): if self.event_filter: self.iface.mainWindow().removeEventFilter(self.event_filter) self.event_filter.deleteLater() def initGui(self): pyplugin_installer.installer.initPluginInstaller() pyplugin_installer.installer_data.plugins.rebuild() if 'projectgenerator' in available_plugins: pyplugin_installer.instance().uninstallPlugin('projectgenerator', quiet=True) self.__generate_action = QAction( QIcon( os.path.join(os.path.dirname(__file__), 'images/QgisModelBaker-icon.svg')), self.tr('Generate'), None) self.__export_action = QAction( QIcon( os.path.join(os.path.dirname(__file__), 'images/QgisModelBaker-xtf-export-icon.svg')), self.tr('Export Interlis Transfer File (.xtf)'), None) self.__importdata_action = QAction( QIcon( os.path.join(os.path.dirname(__file__), 'images/QgisModelBaker-xtf-import-icon.svg')), self.tr('Import Interlis Transfer File (.xtf)'), None) self.__configure_action = QAction(self.tr('Settings'), None) self.__help_action = QAction(self.tr('Help'), None) self.__about_action = QAction(self.tr('About'), None) self.__separator = QAction(None) self.__separator.setSeparator(True) # set these actions checkable to visualize that the dialog is open self.__generate_action.setCheckable(True) self.__export_action.setCheckable(True) self.__importdata_action.setCheckable(True) self.__generate_action.triggered.connect(self.show_generate_dialog) self.__configure_action.triggered.connect(self.show_options_dialog) self.__importdata_action.triggered.connect(self.show_importdata_dialog) self.__export_action.triggered.connect(self.show_export_dialog) self.__help_action.triggered.connect(self.show_help_documentation) self.__about_action.triggered.connect(self.show_about_dialog) self.iface.addPluginToDatabaseMenu(self.tr('Model Baker'), self.__generate_action) self.iface.addPluginToDatabaseMenu(self.tr('Model Baker'), self.__importdata_action) self.iface.addPluginToDatabaseMenu(self.tr('Model Baker'), self.__export_action) self.iface.addPluginToDatabaseMenu(self.tr('Model Baker'), self.__configure_action) self.iface.addPluginToDatabaseMenu(self.tr('Model Baker'), self.__separator) self.iface.addPluginToDatabaseMenu(self.tr('Model Baker'), self.__help_action) self.iface.addPluginToDatabaseMenu(self.tr('Model Baker'), self.__about_action) self.toolbar = self.iface.addToolBar(self.tr('Model Baker')) self.toolbar.setObjectName("ModelBakerToolbar") self.toolbar.setToolTip(self.tr('Model Baker Toolbar')) self.toolbar.addAction(self.__generate_action) self.toolbar.addAction(self.__importdata_action) self.toolbar.addAction(self.__export_action) self.register_event_filter() def unload(self): self.unregister_event_filter() self.iface.removePluginDatabaseMenu(self.tr('Model Baker'), self.__generate_action) self.iface.removePluginDatabaseMenu(self.tr('Model Baker'), self.__importdata_action) self.iface.removePluginDatabaseMenu(self.tr('Model Baker'), self.__export_action) self.iface.removePluginDatabaseMenu(self.tr('Model Baker'), self.__configure_action) self.iface.removePluginDatabaseMenu(self.tr('Model Baker'), self.__help_action) self.iface.removePluginDatabaseMenu(self.tr('Model Baker'), self.__about_action) del self.__generate_action del self.__export_action del self.__importdata_action del self.__configure_action del self.__help_action del self.__about_action def show_generate_dialog(self): if self.generate_dlg: self.generate_dlg.reject() else: self.generate_dlg = GenerateProjectDialog( self.iface, self.ili2db_configuration, self.iface.mainWindow()) self.generate_dlg.setAttribute(Qt.WA_DeleteOnClose) self.generate_dlg.setWindowFlags(self.generate_dlg.windowFlags() | Qt.Tool) self.generate_dlg.show() self.generate_dlg.finished.connect(self.generate_dialog_finished) self.__generate_action.setChecked(True) def generate_dialog_finished(self): self.__generate_action.setChecked(False) self.generate_dlg = None def show_export_dialog(self): if self.export_dlg: self.export_dlg.reject() else: self.export_dlg = ExportDialog(self.ili2db_configuration, self.iface.mainWindow()) self.export_dlg.setAttribute(Qt.WA_DeleteOnClose) self.export_dlg.setWindowFlags(self.export_dlg.windowFlags() | Qt.Tool) self.export_dlg.show() self.export_dlg.finished.connect(self.export_dialog_finished) self.__export_action.setChecked(True) def export_dialog_finished(self): self.__export_action.setChecked(False) self.export_dlg = None def show_importdata_dialog(self): if self.importdata_dlg: self.importdata_dlg.reject() else: self.importdata_dlg = ImportDataDialog(self.iface, self.ili2db_configuration, self.iface.mainWindow()) self.importdata_dlg.setAttribute(Qt.WA_DeleteOnClose) self.importdata_dlg.setWindowFlags( self.importdata_dlg.windowFlags() | Qt.Tool) self.importdata_dlg.show() self.importdata_dlg.finished.connect( self.importdata_dialog_finished) self.__importdata_action.setChecked(True) def importdata_dialog_finished(self): self.__importdata_action.setChecked(False) self.importdata_dlg = None def show_options_dialog(self): dlg = OptionsDialog(self.ili2db_configuration) if dlg.exec_(): settings = QSettings() settings.beginGroup('QgisModelBaker/ili2db') self.ili2db_configuration.save(settings) def show_help_documentation(self): os_language = QLocale( QSettings().value('locale/userLocale')).name()[:2] if os_language in ['es', 'de']: webbrowser.open( 'https://opengisch.github.io/QgisModelBaker/docs/{}/'.format( os_language)) else: webbrowser.open( 'https://opengisch.github.io/QgisModelBaker/docs/index.html') def show_about_dialog(self): self.msg = QMessageBox() self.msg.setIcon(QMessageBox.Information) self.msg.setTextFormat(Qt.RichText) self.msg.setWindowTitle(self.tr('About Model Baker')) self.msg.setText("""<h1>{title}</h1> <p align="justify"><small>{version}</small></p> <p align="justify">{p1}</p> <p align="justify">{p2}</p> <p align="justify">{p3}</p>""".format( title=self.tr('QGIS Model Baker'), version=self.tr('Version {version}').format( version=self.__version__), p1=self. tr('Configuring QGIS layers and forms manually is a tedious and error prone process. This plugin loads database schemas with various meta information to preconfigure the layer tree, widget configuration, relations and more.' ), p2=self. tr('This project is open source under the terms of the GPLv2 or later and the source code can be found on <a href="https://github.com/opengisch/QgisModelBaker">github</a>.' ), p3=self. tr('This plugin is developed by <a href="https://www.opengis.ch/">OPENGIS.ch</a> in collaboration with <a href="https://swisstierrascolombia.com">SwissTierras Colombia</a>' ))) self.msg.setStandardButtons(QMessageBox.Close) msg_box = self.msg.exec_() def get_generator(self): return Generator def create_project(self, layers, relations, bags_of_enum, legend, auto_transaction=True, evaluate_default_values=True): """ Expose the main functionality from Model Baker to other plugins, namely, create a QGIS project from objects obtained from the Generator class. :param layers: layers object from generator.layers :param relations: relations object obtained from generator.relations :param bags_of_enum: bags_of_enum object from generator.relations :param legend: legend object obtained from generator.legend :param auto_transaction: whether transactions should be enabled or not when editing layers from supported DB like PG :param evaluate_default_values: should default values be evaluated on provider side when requested and not when committed. (from QGIS docs) """ project = Project(auto_transaction, evaluate_default_values) project.layers = layers project.relations = relations project.bags_of_enum = bags_of_enum project.legend = legend project.post_generate() qgis_project = QgsProject.instance() project.create(None, qgis_project) def handle_dropped_file(self, file_path): if pathlib.Path(file_path).suffix[1:] in ['xtf', 'XTF', 'itf', 'ITF']: if not self.importdata_dlg: self.set_dropped_file_configuration(file_path) self.show_importdata_dialog() return True return False def set_dropped_file_configuration(self, file_path): settings = QSettings() settings.setValue('QgisModelBaker/ili2pg/xtffile_import', file_path) settings.setValue('QgisModelBaker/importtype', 'gpkg') output_file_name = '{}_{:%Y%m%d%H%M%S%f}.gpkg'.format( os.path.splitext(os.path.basename(file_path))[0], datetime.datetime.now()) settings.setValue( 'QgisModelBaker/ili2gpkg/dbfile', os.path.join( QStandardPaths.writableLocation(QStandardPaths.TempLocation), output_file_name))
class ReportingTool(object): def __init__(self, iface): self.iface = iface try: from reportingtool.tests import testerplugin from qgistester.tests import addTestModule addTestModule(testerplugin, "Support tool") except: pass def initGui(self): icon = QIcon(os.path.dirname(__file__) + "reportingtool.png") self.action = QAction(icon, "Boundless Support Tool", self.iface.mainWindow()) self.action.setObjectName("startreportingtool") self.action.triggered.connect(self.run) self.separator = QAction(self.iface.mainWindow()) self.separator.setObjectName("reportingtoolseparator") self.separator.setSeparator(True) actions = self.iface.mainWindow().menuBar().actions() for action in actions: if action.menu().objectName() == 'mPluginMenu': menuPlugin = action.menu() for a in menuPlugin.actions(): if a.isSeparator(): menuPlugin.insertAction(a, self.action) helpMenu = self.iface.helpMenu() for action in helpMenu.actions(): if action.objectName() == "mActionNeedSupport": helpMenu.insertActions(action, [self.action, self.separator]) try: from lessons import addLessonsFolder folder = os.path.join(os.path.dirname(__file__), "_lessons") addLessonsFolder(folder) except: pass def unload(self): helpMenu = self.iface.helpMenu() helpMenu.removeAction(self.action) helpMenu.removeAction(self.separator) actions = self.iface.mainWindow().menuBar().actions() for action in actions: if action.menu().objectName() == 'mPluginMenu': menuPlugin = action.menu() menuPlugin.removeAction(self.action) try: from reportingtool.tests import testerplugin from qgistester.tests import removeTestModule removeTestModule(testerplugin, "Support tool") except: pass def run(self): if sys.platform == "darwin": # macOS needs this set for modules to work properly on QGIS init os.environ['QGIS_PREFIX_PATH'] = QgsApplication.prefixPath() report, filePath = createReport() dlg = ReportDialog(report, filePath) dlg.exec_() def lastReport(self): reportsPath = os.path.expanduser("~") reports = (fn for fn in glob.glob(os.path.join(reportsPath, "QgisSystemReport*"))) reports = ((os.stat(f), f) for f in reports) reports = ((stat[ST_CTIME], f) for stat, f in reports if S_ISREG(stat[ST_MODE])) reports = sorted(reports) return reports[-1][1]
class QgisModelBakerPlugin(QObject): def __init__(self, iface): QObject.__init__(self) self.iface = iface self.plugin_dir = os.path.dirname(__file__) self.generate_dlg = None self.export_dlg = None self.importdata_dlg = None self.workflow_wizard_dlg = None self.datasetmanager_dlg = None self.__generate_action = None self.__export_action = None self.__importdata_action = None self.__workflow_wizard_action = None self.__datasetmanager_action = None self.__validate_action = None self.__configure_action = None self.__help_action = None self.__about_action = None self.__separator = None self.__dataset_selector_action = None self.__dataset_selector = None self.__validate_dock = None basepath = pathlib.Path(__file__).parent.absolute() metadata = configparser.ConfigParser() metadata.read(os.path.join(basepath, "metadata.txt")) self.__version__ = metadata["general"]["version"] if locale.getlocale() == (None, None): locale.setlocale(locale.LC_ALL, "") # initialize translation qgis_locale_id = str(QSettings().value("locale/userLocale")) qgis_locale = QLocale(qgis_locale_id) locale_path = os.path.join(self.plugin_dir, "i18n") self.translator = QTranslator() self.translator.load(qgis_locale, "QgisModelBaker", "_", locale_path) QCoreApplication.installTranslator(self.translator) self.ili2db_configuration = BaseConfiguration() settings = QSettings() settings.beginGroup("QgisModelBaker/ili2db") self.ili2db_configuration.restore(settings) self.event_filter = DropFileFilter(self) def register_event_filter(self): if not self.event_filter: self.event_filter = DropFileFilter(self) self.iface.mainWindow().installEventFilter(self.event_filter) def unregister_event_filter(self): if self.event_filter: self.iface.mainWindow().removeEventFilter(self.event_filter) self.event_filter.deleteLater() def initGui(self): pyplugin_installer.installer.initPluginInstaller() pyplugin_installer.installer_data.plugins.rebuild() if "projectgenerator" in available_plugins: pyplugin_installer.instance().uninstallPlugin("projectgenerator", quiet=True) self.__generate_action = QAction( QIcon( os.path.join(os.path.dirname(__file__), "images/QgisModelBaker-icon.svg")), self.tr("Generate"), None, ) self.__export_action = QAction( QIcon( os.path.join( os.path.dirname(__file__), "images/QgisModelBaker-xtf-export-icon.svg", )), self.tr("Export Interlis Transfer File (.xtf)"), None, ) self.__importdata_action = QAction( QIcon( os.path.join( os.path.dirname(__file__), "images/QgisModelBaker-xtf-import-icon.svg", )), self.tr("Import Interlis Transfer File (.xtf)"), None, ) self.__datasetmanager_action = QAction( QIcon( os.path.join( os.path.dirname(__file__), "images/QgisModelBaker-datasetmanager-icon.svg", )), self.tr("Dataset Manager"), None, ) self.__validate_action = QAction( QIcon( os.path.join( os.path.dirname(__file__), "images/QgisModelBaker-validator_icon.svg", )), self.tr("Data Validator"), None, ) self.__workflow_wizard_action = QAction( QIcon( os.path.join(os.path.dirname(__file__), "images/QgisModelBaker-wizard.svg")), self.tr("Import/Export Wizard"), None, ) self.__configure_action = QAction(self.tr("Settings"), None) self.__help_action = QAction(self.tr("Help"), None) self.__about_action = QAction(self.tr("About"), None) self.__separator = QAction(None) self.__separator.setSeparator(True) self.__dataset_selector_action = QAction(self.tr("Dataset Selector")) # set these actions checkable to visualize that the dialog is open self.__generate_action.setCheckable(True) self.__export_action.setCheckable(True) self.__importdata_action.setCheckable(True) self.__workflow_wizard_action.setCheckable(True) self.__datasetmanager_action.setCheckable(True) self.__validate_action.setCheckable(True) self.__generate_action.triggered.connect(self.show_generate_dialog) self.__configure_action.triggered.connect(self.show_options_dialog) self.__importdata_action.triggered.connect(self.show_importdata_dialog) self.__datasetmanager_action.triggered.connect( self.show_datasetmanager_dialog) self.__validate_action.triggered.connect(self.show_validate_dock) self.__export_action.triggered.connect(self.show_export_dialog) self.__workflow_wizard_action.triggered.connect( self.show_workflow_wizard_dialog) self.__help_action.triggered.connect(self.show_help_documentation) self.__about_action.triggered.connect(self.show_about_dialog) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__workflow_wizard_action) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__generate_action) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__importdata_action) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__export_action) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__datasetmanager_action) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__validate_action) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__configure_action) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__separator) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__help_action) self.iface.addPluginToDatabaseMenu(self.tr("Model Baker"), self.__about_action) self.toolbar = self.iface.addToolBar(self.tr("Model Baker")) self.toolbar.setObjectName("ModelBakerToolbar") self.toolbar.setToolTip(self.tr("Model Baker Toolbar")) self.toolbar.addAction(self.__workflow_wizard_action) self.toolbar.addAction(self.__generate_action) self.toolbar.addAction(self.__importdata_action) self.toolbar.addAction(self.__export_action) self.__dataset_selector = DatasetSelector() self.__dataset_selector_action = self.toolbar.addWidget( self.__dataset_selector) # connect trigger to refresh model of dataset combobox when layer changed self.iface.layerTreeView().currentLayerChanged.connect( self.__dataset_selector.set_current_layer) self.toolbar.addAction(self.__datasetmanager_action) self.init_validate_dock() self.register_event_filter() def unload(self): self.unregister_event_filter() self.iface.removePluginDatabaseMenu(self.tr("Model Baker"), self.__generate_action) self.iface.removePluginDatabaseMenu(self.tr("Model Baker"), self.__importdata_action) self.iface.removePluginDatabaseMenu(self.tr("Model Baker"), self.__export_action) self.iface.removePluginDatabaseMenu(self.tr("Model Baker"), self.__datasetmanager_action) self.iface.removePluginDatabaseMenu(self.tr("Model Baker"), self.__validate_action) self.iface.removePluginDatabaseMenu(self.tr("Model Baker"), self.__configure_action) self.iface.removePluginDatabaseMenu(self.tr("Model Baker"), self.__help_action) self.iface.removePluginDatabaseMenu(self.tr("Model Baker"), self.__about_action) self.toolbar.removeAction(self.__dataset_selector_action) self.iface.layerTreeView().currentLayerChanged.disconnect( self.__dataset_selector.set_current_layer) del self.__generate_action del self.__export_action del self.__importdata_action del self.__workflow_wizard_action del self.__datasetmanager_action del self.__validate_action del self.__configure_action del self.__help_action del self.__about_action del self.__dataset_selector_action del self.__dataset_selector # remove the toolbar del self.toolbar self.remove_validate_dock() def show_generate_dialog(self): if self.generate_dlg: self.generate_dlg.reject() else: self.generate_dlg = GenerateProjectDialog( self.iface, self.ili2db_configuration, self.iface.mainWindow()) self.generate_dlg.setAttribute(Qt.WA_DeleteOnClose) self.generate_dlg.setWindowFlags(self.generate_dlg.windowFlags() | Qt.Tool) self.generate_dlg.show() self.generate_dlg.finished.connect(self.generate_dialog_finished) self.__generate_action.setChecked(True) def generate_dialog_finished(self): self.__generate_action.setChecked(False) self.generate_dlg = None def show_export_dialog(self): if self.export_dlg: self.export_dlg.reject() else: self.export_dlg = ExportDialog(self.ili2db_configuration, self.iface.mainWindow()) self.export_dlg.setAttribute(Qt.WA_DeleteOnClose) self.export_dlg.setWindowFlags(self.export_dlg.windowFlags() | Qt.Tool) self.export_dlg.show() self.export_dlg.finished.connect(self.export_dialog_finished) self.__export_action.setChecked(True) def export_dialog_finished(self): self.__export_action.setChecked(False) self.export_dlg = None def show_workflow_wizard_dialog(self): if self.workflow_wizard_dlg: self.workflow_wizard_dlg.reject() else: self.workflow_wizard_dlg = WorkflowWizardDialog( self.iface, self.ili2db_configuration, self.iface.mainWindow()) self.workflow_wizard_dlg.show() self.workflow_wizard_dlg.setAttribute(Qt.WA_DeleteOnClose) self.workflow_wizard_dlg.setWindowFlags( self.workflow_wizard_dlg.windowFlags() | Qt.Tool) self.workflow_wizard_dlg.show() self.workflow_wizard_dlg.finished.connect( self.workflow_wizard_dialog_finished) self.__workflow_wizard_action.setChecked(True) def workflow_wizard_dialog_finished(self): self.__workflow_wizard_action.setChecked(False) self.workflow_wizard_dlg = None def show_importdata_dialog(self): if self.importdata_dlg: self.importdata_dlg.reject() else: self.importdata_dlg = ImportDataDialog(self.iface, self.ili2db_configuration, self.iface.mainWindow()) self.importdata_dlg.setAttribute(Qt.WA_DeleteOnClose) self.importdata_dlg.setWindowFlags( self.importdata_dlg.windowFlags() | Qt.Tool) self.importdata_dlg.show() self.importdata_dlg.finished.connect( self.importdata_dialog_finished) self.__importdata_action.setChecked(True) def importdata_dialog_finished(self): self.__importdata_action.setChecked(False) self.importdata_dlg = None def show_datasetmanager_dialog(self): if self.datasetmanager_dlg: self.datasetmanager_dlg.reject() else: self.datasetmanager_dlg = DatasetManagerDialog( self.iface, self.iface.mainWindow()) self.datasetmanager_dlg.setAttribute(Qt.WA_DeleteOnClose) self.datasetmanager_dlg.setWindowFlags( self.datasetmanager_dlg.windowFlags() | Qt.Tool) self.datasetmanager_dlg.show() self.datasetmanager_dlg.finished.connect( self.datasetmanager_dialog_finished) self.__datasetmanager_action.setChecked(True) def datasetmanager_dialog_finished(self): self.__dataset_selector.reset_model( self.iface.layerTreeView().currentLayer()) self.__datasetmanager_action.setChecked(False) self.datasetmanager_dlg = None def show_validate_dock(self): self.__validate_dock.setVisible(not self.__validate_dock.isVisible()) def show_options_dialog(self): dlg = OptionsDialog(self.ili2db_configuration) if dlg.exec_(): settings = QSettings() settings.beginGroup("QgisModelBaker/ili2db") self.ili2db_configuration.save(settings) def show_help_documentation(self): os_language = QLocale( QSettings().value("locale/userLocale")).name()[:2] if os_language in ["es", "de"]: webbrowser.open( "https://opengisch.github.io/QgisModelBaker/docs/{}/".format( os_language)) else: webbrowser.open( "https://opengisch.github.io/QgisModelBaker/docs/index.html") def show_about_dialog(self): self.msg = QMessageBox() self.msg.setIcon(QMessageBox.Information) self.msg.setTextFormat(Qt.RichText) self.msg.setWindowTitle(self.tr("About Model Baker")) self.msg.setText("""<h1>{title}</h1> <p align="justify"><small>{version}</small></p> <p align="justify">{p1}</p> <p align="justify">{p2}</p> <p align="justify">{p3}</p>""".format( title=self.tr("QGIS Model Baker"), version=self.tr("Version {version}").format( version=self.__version__), p1=self. tr("Configuring QGIS layers and forms manually is a tedious and error prone process. This plugin loads database schemas with various meta information to preconfigure the layer tree, widget configuration, relations and more." ), p2=self. tr('This project is open source under the terms of the GPLv2 or later and the source code can be found on <a href="https://github.com/opengisch/QgisModelBaker">github</a>.' ), p3=self. tr('This plugin is developed by <a href="https://www.opengis.ch/">OPENGIS.ch</a> in collaboration with <a href="https://swisstierrascolombia.com">SwissTierras Colombia</a>' ), )) self.msg.setStandardButtons(QMessageBox.Close) self.msg.exec_() def init_validate_dock(self): settings = QSettings() self.__validate_dock = ValidateDock(self.ili2db_configuration, self.iface) self.iface.addDockWidget( settings.value("QgisModelBaker/validate_dock/area", Qt.RightDockWidgetArea, type=int), self.__validate_dock, ) self.__validate_dock.visibilityChanged.connect( self.__validate_action.setChecked) self.__validate_dock.setVisible( settings.value("QgisModelBaker/validate_dock/isVisible", False, type=bool)) self.iface.layerTreeView().currentLayerChanged.connect( self.__validate_dock.set_current_layer) def remove_validate_dock(self): settings = QSettings() settings.setValue( "QgisModelBaker/validate_dock/area", self.iface.mainWindow().dockWidgetArea(self.__validate_dock), ) settings.setValue("QgisModelBaker/validate_dock/isVisible", self.__validate_dock.isVisible()) self.__validate_dock.setVisible(False) self.iface.removeDockWidget(self.__validate_dock) self.iface.layerTreeView().currentLayerChanged.disconnect( self.__validate_dock.set_current_layer) del self.__validate_dock def get_generator(self): return Generator def create_project( self, layers, relations, bags_of_enum, legend, auto_transaction=True, evaluate_default_values=True, ): """ Expose the main functionality from Model Baker to other plugins, namely, create a QGIS project from objects obtained from the Generator class. :param layers: layers object from generator.layers :param relations: relations object obtained from generator.relations :param bags_of_enum: bags_of_enum object from generator.relations :param legend: legend object obtained from generator.legend :param auto_transaction: whether transactions should be enabled or not when editing layers from supported DB like PG :param evaluate_default_values: should default values be evaluated on provider side when requested and not when committed. (from QGIS docs) """ project = Project(auto_transaction, evaluate_default_values) project.layers = layers project.relations = relations project.bags_of_enum = bags_of_enum project.legend = legend project.post_generate() qgis_project = QgsProject.instance() project.create(None, qgis_project) def handle_dropped_files(self, dropped_files): if not self.workflow_wizard_dlg: self._set_dropped_file_configuration() self.show_workflow_wizard_dialog() self.workflow_wizard_dlg.append_dropped_files(dropped_files) return True def _set_dropped_file_configuration(self): settings = QSettings() settings.setValue("QgisModelBaker/importtype", "gpkg") output_file_name = "temp_db_{:%Y%m%d%H%M%S%f}.gpkg".format( datetime.datetime.now()) settings.setValue( "QgisModelBaker/ili2gpkg/dbfile", os.path.join( QStandardPaths.writableLocation(QStandardPaths.TempLocation), output_file_name, ), )