Change the layout of the editor and menu points in editor menu

Remove the buttons for exporting the result of a query to a csv file and
explaining the current query. Add those points together with the
submit/stop query functions to the editor menu in the main window.
This commit is contained in:
Lea Laux 2021-03-08 13:21:25 +01:00 committed by KDV Admin
parent a8d3ca1ab6
commit 3af98454d8
2 changed files with 83 additions and 28 deletions

View File

@ -101,13 +101,9 @@ class EditorWidget(QWidget, SearchReplaceParent, metaclass=MetaEditor):
# shows an error to the user. # shows an error to the user.
self.submit_query_shortcut.activated.connect(self.check_for_valid_connection_and_execute_query_with_shortcut) self.submit_query_shortcut.activated.connect(self.check_for_valid_connection_and_execute_query_with_shortcut)
# Create a button for explaining the current query (plan).
self.explain_query_button = QPushButton("Explain Query Plan")
# Connect the function for executing the explaining process with the button.
self.explain_query_button.clicked.connect(self.execute_explain_analyze_query)
# Check for enabling and disabling of the button for submitting or explaining a query. # Check for enabling and disabling of the button for submitting or explaining a query.
self.check_enabling_of_submit_and_explain_button() self.check_enabling_of_submit_button()
# Create a button for stopping a query. # Create a button for stopping a query.
self.stop_query_button = QPushButton("Stop Query") self.stop_query_button = QPushButton("Stop Query")
@ -155,12 +151,8 @@ class EditorWidget(QWidget, SearchReplaceParent, metaclass=MetaEditor):
self.replace_usages_shortcut = QShortcut(QKeySequence("Ctrl+R"), self) self.replace_usages_shortcut = QShortcut(QKeySequence("Ctrl+R"), self)
self.replace_usages_shortcut.activated.connect(self.open_replace_dialog) self.replace_usages_shortcut.activated.connect(self.open_replace_dialog)
# Create a button for exporting the result to a csv. # Set the csv export to not possible at the moment.
self.export_csv_button = QPushButton("Export result to .csv") self.csv_export_possible = False
# Connect the button with the function for exporting and saving the csv data.
self.export_csv_button.clicked.connect(self.export_and_save_csv_data)
# Set the button as invisible as default, because at the beginning, an export is not necessary.
self.export_csv_button.setVisible(False)
self.setGeometry(600, 600, 500, 300) self.setGeometry(600, 600, 500, 300)
@ -188,17 +180,10 @@ class EditorWidget(QWidget, SearchReplaceParent, metaclass=MetaEditor):
splitter.addWidget(self.table_view) splitter.addWidget(self.table_view)
# Add the splitter to the grid layout. # Add the splitter to the grid layout.
grid_layout.addWidget(splitter, 3, 0, 1, 4) grid_layout.addWidget(splitter, 3, 0, 1, 4)
# Set the submit button for the SQL queries under the table.
# Set the export button on the top of the buttons. The export button is only visible, if results are available grid_layout.addWidget(self.submit_query_button, 4, 0, 1, 4)
# in the table view.
grid_layout.addWidget(self.export_csv_button, 4, 0, 1, 4)
# Set the submit button for the SQL queries as element at the bottom.
grid_layout.addWidget(self.submit_query_button, 6, 0, 1, 4)
# Place the stop button below the submit button. # Place the stop button below the submit button.
grid_layout.addWidget(self.stop_query_button, 7, 0, 1, 4) grid_layout.addWidget(self.stop_query_button, 5, 0, 1, 4)
# Place the explain button below the stop button.
grid_layout.addWidget(self.explain_query_button, 8, 0, 1, 4)
grid_layout.setSpacing(10) grid_layout.setSpacing(10)
@ -262,7 +247,7 @@ class EditorWidget(QWidget, SearchReplaceParent, metaclass=MetaEditor):
# Check for enabling or disabling the button and the shortcut for submitting a query based on the new result of # Check for enabling or disabling the button and the shortcut for submitting a query based on the new result of
# the established connection. # the established connection.
self.check_enabling_of_submit_and_explain_button() self.check_enabling_of_submit_button()
# Update the window title to the current status of the database connection. # Update the window title to the current status of the database connection.
self.update_window_title_and_description() self.update_window_title_and_description()
@ -283,8 +268,8 @@ class EditorWidget(QWidget, SearchReplaceParent, metaclass=MetaEditor):
# Activate the button and the shortcut for stopping the current query. # Activate the button and the shortcut for stopping the current query.
self.set_stop_query_element_activate(True) self.set_stop_query_element_activate(True)
# Set the button invisible during a query. # Set the csv export to not possible during a query.
self.export_csv_button.setVisible(False) self.csv_export_possible = False
# If the query is None, the default parameter is used, so it is necessary to get the current query in the input # If the query is None, the default parameter is used, so it is necessary to get the current query in the input
# editor. # editor.
@ -377,8 +362,8 @@ class EditorWidget(QWidget, SearchReplaceParent, metaclass=MetaEditor):
# Disable the button and the short cut for stopping a query, because a query is currently not executed. # Disable the button and the short cut for stopping a query, because a query is currently not executed.
self.set_stop_query_element_activate(False) self.set_stop_query_element_activate(False)
# Set the export button visible after a result. # Enable the csv export.
self.export_csv_button.setVisible(True) self.csv_export_possible = True
# Check, if the command should be saved. # Check, if the command should be saved.
if save_command: if save_command:
@ -407,7 +392,7 @@ class EditorWidget(QWidget, SearchReplaceParent, metaclass=MetaEditor):
# Show the error in the table model and do not save the command, which caused the error. # Show the error in the table model and do not save the command, which caused the error.
self.refresh_table_model(error_result_list, save_command=False) self.refresh_table_model(error_result_list, save_command=False)
def check_enabling_of_submit_and_explain_button(self): def check_enabling_of_submit_button(self):
""" """
Check for enabling or disabling the button and the shortcut for submitting a query. There is a check for a valid Check for enabling or disabling the button and the shortcut for submitting a query. There is a check for a valid
connection with a specified function. connection with a specified function.
@ -418,7 +403,6 @@ class EditorWidget(QWidget, SearchReplaceParent, metaclass=MetaEditor):
# If the connection is valid, the button is enabled. If the connection is invalid, the button is disabled. # If the connection is valid, the button is enabled. If the connection is invalid, the button is disabled.
self.submit_query_button.setEnabled(is_connection_valid) self.submit_query_button.setEnabled(is_connection_valid)
self.explain_query_button.setEnabled(is_connection_valid)
def check_query_status_message(self, status_message): def check_query_status_message(self, status_message):
""" """

View File

@ -164,6 +164,21 @@ class MainWindow(QMainWindow):
# Create a new menu bar point: An editor menu. # Create a new menu bar point: An editor menu.
editor_menu = self.menu_bar.addMenu("Editor") editor_menu = self.menu_bar.addMenu("Editor")
# Add an action for submitting the query in the current editor.
self.add_action_to_menu_bar("Submit Query", self.submit_current_query_to_editor, alternate_menu=editor_menu)
# Add an action for stopping the query in the current editor.
self.add_action_to_menu_bar("Stop Query", self.stop_current_query_in_editor, alternate_menu=editor_menu)
editor_menu.addSeparator()
# Add an action for exporting the current result of the query to a csv file.
self.add_action_to_menu_bar("Export Result To CSV", self.export_current_result_in_editor_to_csv,
alternate_menu=editor_menu)
# Add an action for explaining the current query plan.
self.add_action_to_menu_bar("Explain Query Plan", self.explain_current_query_in_editor,
alternate_menu=editor_menu)
editor_menu.addSeparator()
# Add the search dialog in the editor to the editor menu. # Add the search dialog in the editor to the editor menu.
self.add_action_to_menu_bar("Search", self.search_usage_in_editor, alternate_menu=editor_menu) self.add_action_to_menu_bar("Search", self.search_usage_in_editor, alternate_menu=editor_menu)
@ -554,6 +569,62 @@ class MainWindow(QMainWindow):
# empty editor with this command. # empty editor with this command.
self.command_history_dialog.get_double_click_command.connect(self.load_empty_editor_with_command) self.command_history_dialog.get_double_click_command.connect(self.load_empty_editor_with_command)
def submit_current_query_to_editor(self):
"""
Submit the current query in the editor.
"""
# Get the editor widget.
editor_widget = self.mdi_area.determine_current_editor_widget()
# Check for an existing widget.
if editor_widget is not None:
# Check the button for submitting the query: If the button is enabled, the query will be executed.
if editor_widget.submit_query_button.isEnabled():
editor_widget.execute_current_query(None)
def stop_current_query_in_editor(self):
"""
Stop the query in the current editor widget.
"""
# Get the widget.
editor_widget = self.mdi_area.determine_current_editor_widget()
# Check for the existence of the widget.
if editor_widget is not None:
# If the stop button is enabled, the function can be executed.
if editor_widget.stop_query_button.isEnabled():
editor_widget.stop_current_query()
def export_current_result_in_editor_to_csv(self):
"""
Export the current result in the editor to a csv file.
"""
# Get the widget.
editor_widget = self.mdi_area.determine_current_editor_widget()
# Check for the existence of the widget.
if editor_widget is not None:
# Check if CSV export is currently possible.
if editor_widget.csv_export_possible:
editor_widget.export_and_save_csv_data()
def explain_current_query_in_editor(self):
"""
Explain the current query in the editor.
"""
# Get the editor widget.
editor_widget = self.mdi_area.determine_current_editor_widget()
# Check for the existence of the widget.
if editor_widget is not None:
# Check for the enabling of the submit button, because in this case, explaining the query is possible too.
if editor_widget.submit_query_button.isEnabled():
editor_widget.execute_explain_analyze_query()
def closeEvent(self, a0: QtGui.QCloseEvent) -> None: def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
""" """
Reimplement the close event of the main window and as a consequence, the close event of the whole application. Reimplement the close event of the main window and as a consequence, the close event of the whole application.