Skip to content

Commit

Permalink
Add New, Add and Open to the db editor toolbar (#2819)
Browse files Browse the repository at this point in the history
  • Loading branch information
PiispaH authored Jun 5, 2024
1 parent a1ea7cb commit 81dd5d2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
15 changes: 8 additions & 7 deletions docs/source/spine_db_editor/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,14 @@ Contains a link to the index page of the Spine Database Editor documentation.
Toolbar
=======

The **Toolbar** houses many useful features that come in handy when working with a database. Starting from the left, there
are the **Undo** and **Redo** -buttons. These can be used to undo and redo the actions that have been made in the
editor (**CTR+Z** and **CTR+Y** also work). **Commit** saves the changes made in the editor into the database. More
information about committing can be found in here :ref:`committing_and_history`. The **Purge...** button is quite
useful when there is a need to get rid of a lot of data quickly. Clicking it will open a new window where
options for the purging are given. Find out more about purging in the section :ref:`Removing data`. **reload**
(|reload|) button can be used to reload the data of the database.
The **Toolbar** houses many useful features that come in handy when working with a database. Starting from the left,
there **New**, **Add** and **Open** -buttons. With these you can create a new Spine db in sqlite form, add an
existing one to the tab or open an existing one instead. Next are the **Undo** and **Redo** -buttons. These can be
used to undo and redo the actions that have been made in the editor (**CTR+Z** and **CTR+Y** also work). **Commit**
saves the changes made in the editor into the database. More information about committing can be found in here
:ref:`committing_and_history`. The **Purge...** button is quite useful when there is a need to get rid of a lot of
data quickly. Clicking it will open a new window where options for the purging are given. Find out more about purging
in the section :ref:`Removing data`. **reload** (|reload|) button can be used to reload the data of the database.

The following six buttons are used to switch between the different views in the editor. Short introductions to the
different views can be found on the bottom of this page and more indepth explanations from here: :ref:`viewing data`.
Expand Down
Binary file modified docs/source/spine_db_editor/img/dirty_db.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/spine_db_editor/img/plain_db_editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 30 additions & 15 deletions spinetoolbox/spine_db_editor/widgets/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,31 @@ def __init__(self, db_editor):
super().__init__(db_editor)
self.setObjectName("spine_db_editor_toolbar")
self._db_editor = db_editor
self.reload_action = QAction(QIcon(CharIconEngine("\uf021")), "Reload")
self.reload_action.setShortcut(QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_R))
self.reload_action.setEnabled(False)
self.reset_docs_action = QAction(QIcon(CharIconEngine("\uf2d2")), "Reset docs")
self.show_toolbox_action = QAction(QIcon(":/symbols/Spine_symbol.png"), "Show Toolbox")
self.show_toolbox_action.setShortcut(QKeySequence(Qt.Modifier.CTRL | Qt.Key.Key_Escape))
self.show_toolbox_action.setToolTip("Show Spine Toolbox (Ctrl+ESC)")
self._filter_action = QAction(QIcon(CharIconEngine("\uf0b0")), "Filter")
self.show_url_action = QAction(QIcon(CharIconEngine("\uf550")), "Show URLs")
self._add_actions()
self._connect_signals()
self.setMovable(False)
self.setIconSize(QSize(20, 20))

def _add_actions(self):
"""Creates buttons for the actions and adds them to the toolbar"""
self.create_button_for_action(self._db_editor.ui.actionNew_db_file)
self.create_button_for_action(self._db_editor.ui.actionAdd_db_file)
self.create_button_for_action(self._db_editor.ui.actionOpen_db_file)
self.addSeparator()
self.create_button_for_action(self._db_editor.ui.actionUndo)
self.create_button_for_action(self._db_editor.ui.actionRedo)
self.addSeparator()
self.create_button_for_action(self._db_editor.ui.actionCommit)
self.create_button_for_action(self._db_editor.ui.actionMass_remove_items)
self.reload_action = QAction(QIcon(CharIconEngine("\uf021")), "Reload")
self.reload_action.setShortcut(QKeySequence(Qt.Modifier.CTRL.value | Qt.Key.Key_R.value))
self.reload_action.setEnabled(False)
self.reload_action.triggered.connect(db_editor.refresh_session)
self.create_button_for_action(self.reload_action)
self.addSeparator()
self.create_button_for_action(self._db_editor.ui.actionStacked_style)
Expand All @@ -62,41 +78,40 @@ def __init__(self, db_editor):
self.create_button_for_action(self._db_editor.ui.actionElement)
self.create_button_for_action(self._db_editor.ui.actionScenario)
self.addSeparator()
self.reset_docs_action = QAction(QIcon(CharIconEngine("\uf2d2")), "Reset docs")
self.reset_docs_action.triggered.connect(self._db_editor.reset_docs)
self.create_button_for_action(self.reset_docs_action)
self.addSeparator()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self.addWidget(spacer)
self.addSeparator()
self.show_url_action = QAction(QIcon(CharIconEngine("\uf550")), "Show URLs")
self.show_url_action.triggered.connect(self._show_url_codename_widget)
self.create_button_for_action(self.show_url_action)
self._filter_action = QAction(QIcon(CharIconEngine("\uf0b0")), "Filter")
self._filter_action.triggered.connect(self._show_filter_menu)
self.create_button_for_action(self._filter_action)
self.addSeparator()
self.show_toolbox_action = QAction(QIcon(":/symbols/Spine_symbol.png"), "Show Toolbox")
self.show_toolbox_action.setShortcut(QKeySequence(Qt.Modifier.CTRL.value | Qt.Key.Key_Escape.value))
self.show_toolbox_action.setToolTip("Show Spine Toolbox (Ctrl+ESC)")
self.create_button_for_action(self.show_toolbox_action)
self.setMovable(False)
self.setIconSize(QSize(20, 20))

def _connect_signals(self):
"""Connects signals"""
self.reload_action.triggered.connect(self._db_editor.refresh_session)
self.reset_docs_action.triggered.connect(self._db_editor.reset_docs)
self.show_url_action.triggered.connect(self._show_url_codename_widget)
self._filter_action.triggered.connect(self._show_filter_menu)

def create_button_for_action(self, action):
"""Creates a button for the given action and adds it to the widget"""
tool_button = QToolButton()
tool_button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
tool_button.setPopupMode(QToolButton.InstantPopup)
tool_button.setDefaultAction(action)
self.addWidget(tool_button)

def _show_url_codename_widget(self):
"""Shows the url codename widget"""
dialog = _URLDialog(self._db_editor.db_url_codenames, parent=self)
dialog.show()

@Slot(bool)
def _show_filter_menu(self, _checked=False):
"""Shows the filter menu"""
dialog = _UrlFilterDialog(self._db_editor.db_mngr, self._db_editor.db_maps, parent=self)
dialog.show()
dialog.filter_accepted.connect(self._db_editor.load_db_urls)
Expand Down

0 comments on commit 81dd5d2

Please sign in to comment.