Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: effjot/qgis-data-sources-panel
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.2.1
Choose a base ref
...
head repository: effjot/qgis-data-sources-panel
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Jan 29, 2024

  1. Show dock only via View → Panels menu

    * Use QgsDockWidget class.  (Not sure if strictly necessary.)
    * Make add_action() more flexible regarding which menu and
      toolbar to use.  However, for Panel menu no action is required,
      only for help menu and toolbar, if that would be added back in
    effjot committed Jan 29, 2024

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    cb6b801 View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    70d6a64 View commit details
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ in the ESRI ArcGIS Table of Contents.

## Usage

The panel can be opened from the Plugins menu → Data Sources Panel.
The panel can be opened from the View menu → Panels → Data Sources.

You can switch between a table view and a tree view of the layer
sources with the first two buttons of the toolbar.
82 changes: 41 additions & 41 deletions data_sources_panel/data_sources_panel.py
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@

from qgis.PyQt.QtCore import QCoreApplication, QSettings, Qt, QTranslator, QUrl
from qgis.PyQt.QtGui import QDesktopServices, QIcon
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtWidgets import QAction, QMenu

# Import the code for the DockWidget
from .dockwidget import DataSourcesDockWidget
@@ -64,24 +64,22 @@ def __init__(self, iface):

# Declare instance attributes
self.actions = []
self.menu = tr('&Data Sources')
self.menu_item = tr('&Data Sources Panel')
# self.toolbar = self.iface.addToolBar(u'DataSourcesPanel')
# self.toolbar.setObjectName(u'DataSourcesPanel')
self.parent_menu = None
self.toolbar = self.iface.pluginToolBar()
self.pluginIsActive = False
self.dockwidget = None

def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None):
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=None,
add_to_toolbar=False,
status_tip=None,
whats_this=None,
parent=None):
"""Add a toolbar icon to the toolbar.
:param icon_path: Path to the icon for this action. Can be a resource
@@ -98,12 +96,12 @@ def add_action(
by default. Defaults to True.
:type enabled_flag: bool
:param add_to_menu: Flag indicating whether the action should also
be added to the menu. Defaults to True.
:type add_to_menu: bool
:param add_to_menu: Menu to which action should be added. Set to None
if action should not be added to a menu. Defaults to False.
:type add_to_menu: QMenu
:param add_to_toolbar: Flag indicating whether the action should also
be added to the toolbar. Defaults to True.
be added to the toolbar. Defaults to False.
:type add_to_toolbar: bool
:param status_tip: Optional text to show in a popup when mouse pointer
@@ -120,7 +118,6 @@ def add_action(
added to self.actions list.
:rtype: QAction
"""

icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
@@ -133,30 +130,31 @@ def add_action(
action.setWhatsThis(whats_this)

if add_to_toolbar:
# self.toolbar.addAction(action)
pass
self.toolbar.addAction(action)

if add_to_menu:
self.iface.addPluginToMenu(
self.menu,
action)
add_to_menu.addAction(action)

self.actions.append(action)
self.actions.append((action, add_to_menu, add_to_toolbar))
return action

def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
icon_path = ':/icon.svg'
# self.add_action(
# icon_path,
# text=tr('&Data Sources Panel'),
# add_to_menu=self.iface.pluginMenu(),
# callback=self.run,
# parent=self.iface.mainWindow())
self.add_action(
icon_path,
text=self.menu_item,
add_to_toolbar=False,
callback=self.run,
text=tr('&Data Sources Panel'),
add_to_menu=self.iface.pluginHelpMenu(),
callback=self.show_help,
parent=self.iface.mainWindow())
self.act_help = QAction(
QIcon(icon_path), self.menu_item, self.iface.mainWindow())
self.act_help.triggered.connect(self.show_help)
self.iface.pluginHelpMenu().addAction(self.act_help)
# immediately activate the dock, will be automatically added to Panel menu
self.run()

def onClosePlugin(self):
"""Cleanup necessary items here when plugin dockwidget is closed"""
@@ -171,18 +169,20 @@ def onClosePlugin(self):
self.pluginIsActive = False

def unload(self):
"""Removes the plugin menu item and icon from QGIS GUI."""
"""Removes the dock, plugin menu item and icon from QGIS GUI."""
if self.dockwidget:
self.dockwidget.hide()
self.dockwidget.deleteLater()
for action in self.actions:
self.iface.removePluginMenu(self.menu, action)
# self.iface.removeToolBarIcon(action)
# remove actions from menus and toolbar
for action, menu, toolbar in self.actions:
if menu:
menu.removeAction(action)
if toolbar:
self.toolbar.removeToolBarIcon(action)
if self.parent_menu:
self.parent_menu.removeAction(self.menu.menuAction())
# remove the toolbar
# del self.toolbar
if self.act_help:
self.iface.pluginHelpMenu().removeAction(self.act_help)
del self.act_help
del self.toolbar

def run(self):
"""Run method that loads and starts the plugin"""
3 changes: 2 additions & 1 deletion data_sources_panel/dockwidget.py
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
QgsSettings,
QgsVectorFileWriter
)
from qgis.gui import QgsDockWidget
from qgis.PyQt import QtCore, QtWidgets, uic
from qgis.PyQt.QtCore import Qt, pyqtSignal
from qgis.PyQt.QtWidgets import QAction, QFileDialog, QMenu, QToolButton
@@ -399,7 +400,7 @@ def update(self):
self.endResetModel()


class DataSourcesDockWidget(QtWidgets.QDockWidget, FORM_CLASS):
class DataSourcesDockWidget(QgsDockWidget, FORM_CLASS): #QtWidgets.QDockWidget
closingPlugin = pyqtSignal()

def __init__(self, iface, parent=None):
2 changes: 1 addition & 1 deletion data_sources_panel/help/source/index.rst
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ in the ESRI ArcGIS Table of Contents.
Usage
-----

The panel can be opened from the Plugins menu → Data Sources Panel.
The panel can be opened from the View menu → Panels → Data Sources.

You can switch between a table view and a tree view of the layer
sources with the first two buttons of the toolbar.
37 changes: 16 additions & 21 deletions data_sources_panel/i18n/data_sources_panel_de.ts
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@
<context>
<name>@default</name>
<message>
<location filename="../data_sources_panel.py" line="68"/>
<location filename="../data_sources_panel.py" line="150"/>
<source>&amp;Data Sources Panel</source>
<translation>&amp;Datenquellen-Bedienfeld</translation>
</message>
<message>
<location filename="../dockwidget.py" line="53"/>
<location filename="../dockwidget.py" line="54"/>
<source>Layer</source>
<translation>Layer</translation>
</message>
@@ -24,72 +24,72 @@
<translation>Speicherort</translation>
</message>
<message>
<location filename="../dockwidget.py" line="553"/>
<location filename="../dockwidget.py" line="551"/>
<source>Data Sources</source>
<translation>Datenquellen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="426"/>
<location filename="../dockwidget.py" line="424"/>
<source>&amp;Table View</source>
<translation>&amp;Tabellenansicht</translation>
</message>
<message>
<location filename="../dockwidget.py" line="429"/>
<location filename="../dockwidget.py" line="427"/>
<source>T&amp;ree View</source>
<translation>&amp;Baumansicht</translation>
</message>
<message>
<location filename="../dockwidget.py" line="432"/>
<location filename="../dockwidget.py" line="430"/>
<source>&amp;Expand All</source>
<translation>Alle &amp;ausklappen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="435"/>
<location filename="../dockwidget.py" line="433"/>
<source>&amp;Collapse All</source>
<translation>Alle &amp;einklappen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="441"/>
<location filename="../dockwidget.py" line="439"/>
<source>Export</source>
<translation>Export</translation>
</message>
<message>
<location filename="../dockwidget.py" line="444"/>
<location filename="../dockwidget.py" line="442"/>
<source>Export as &amp;Excel file</source>
<translation>Als &amp;Excel-Datei exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="446"/>
<location filename="../dockwidget.py" line="444"/>
<source>Export as &amp;CSV file</source>
<translation>Als &amp;CSV-Datei exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="556"/>
<location filename="../dockwidget.py" line="554"/>
<source>Comma Separated Values (*.csv)</source>
<translation>CSV (Komma-getrennte Werte)</translation>
</message>
<message>
<location filename="../dockwidget.py" line="557"/>
<location filename="../dockwidget.py" line="555"/>
<source>Excel workbook (*.xlsx)</source>
<translation>Excel-Arbeitsmappe (*.xlsx)</translation>
</message>
<message>
<location filename="../dockwidget.py" line="561"/>
<location filename="../dockwidget.py" line="559"/>
<source>Export Data Sources Table</source>
<translation>Datenquellen-Tabelle exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="566"/>
<location filename="../dockwidget.py" line="564"/>
<source>Export cancelled</source>
<translation>Export abgebrochen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="578"/>
<location filename="../dockwidget.py" line="576"/>
<source>Data sources table successfully exported to {output_file}</source>
<translation>Datenquellen-Tabelle erfolgreich nach {output_file} exportiert</translation>
</message>
<message>
<location filename="../dockwidget.py" line="586"/>
<location filename="../dockwidget.py" line="584"/>
<source>Export to {output_file} failed: {error} {message}</source>
<translation>Export nach {output_file} fehlgeschlagen: {error} {message}</translation>
</message>
@@ -148,11 +148,6 @@
<source>Schema</source>
<translation>Schema</translation>
</message>
<message>
<location filename="../data_sources_panel.py" line="67"/>
<source>&amp;Data Sources</source>
<translation>&amp;Datenquellen</translation>
</message>
<message>
<location filename="../layer_sources.py" line="235"/>
<source>Vector Files (OGR)</source>
1 change: 1 addition & 0 deletions data_sources_panel/metadata.txt
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ repository=https://github.com/effjot/qgis-data-sources-panel
hasProcessingProvider=no
# Uncomment the following line and add your changelog:
changelog=
0.2.2 Move to View → Panels menu
0.2.1 Show CRS info, export geometry type, updated documentation
0.2.0 German translation, other small improvements
0.1.0 Initial experimental release