Skip to content

Commit

Permalink
Merge branch 'master' into issue_2008_entity_tree_manipulation
Browse files Browse the repository at this point in the history
# Conflicts:
#	spinetoolbox/spine_db_editor/widgets/spine_db_editor.py
  • Loading branch information
Henrik Koski committed Jun 17, 2024
2 parents 0f84d76 + 64a369a commit 7d0fe1d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion spinetoolbox/mvcmodels/map_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def _reconstruct_map(tree):
values.append(value)
if len(indexes) > 1:
first_type = type(indexes[0])
if first_type == numpy.float_:
if first_type == numpy.float64:
first_type = float
if any(not isinstance(i, first_type) for i in indexes[1:]):
raise ParameterValueFormatError(f"Index type mismatch.")
Expand Down
2 changes: 1 addition & 1 deletion spinetoolbox/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def plot_data(data_list, plot_widget=None, plot_type=None):
plot_title = " | ".join(map(str, common_indexes))
plot_widget.canvas.axes.set_title(plot_title)
for data in data_list:
if type(data.x[0]) not in (float, np.float_, int):
if type(data.x[0]) not in (float, np.float64, int):
plot_widget.canvas.axes.tick_params(axis="x", labelrotation=30)
if len(squeezed_data) > 1:
plot_widget.add_legend(legend_handles)
Expand Down
11 changes: 11 additions & 0 deletions spinetoolbox/spine_db_editor/mvcmodels/compound_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ def __init__(self, parent, db_mngr, *db_maps):
handle_items_updated=self.handle_items_updated,
owner=self,
)
self.dock = None
self._column_filters = {self.header[column]: False for column in range(self.columnCount())}

def _make_header(self):
raise NotImplementedError()

@property
def column_filters(self):
return self._column_filters

@property
def field_map(self):
return {}
Expand Down Expand Up @@ -233,6 +239,11 @@ def set_auto_filter(self, field, values):
self._set_compound_auto_filter(field, values)
for model in self.accepted_single_models():
self._set_single_auto_filter(model, field)
if values is None or any(bool(i) for i in values.values()):
self._column_filters[field] = True
else:
self._column_filters[field] = False
self._parent.handle_column_filters(self)

def _set_compound_auto_filter(self, field, values):
"""Sets the auto filter for given column in the compound model.
Expand Down
8 changes: 7 additions & 1 deletion spinetoolbox/spine_db_editor/widgets/custom_qtableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,19 @@ def populate_context_menu(self):
self._menu.addAction("Filter by", self.filter_by_selection)
self._menu.addAction("Filter excluding", self.filter_excluding_selection)
self._menu.addSeparator()
self._menu.addAction("Clear all filters", self._spine_db_editor.clear_all_filters)
self._menu.addAction("Clear all filters", self._clear_filters)
self._menu.addSeparator()
# Shortcuts
remove_rows_action.setShortcut(QKeySequence(Qt.Modifier.CTRL.value | Qt.Key.Key_Delete.value))
remove_rows_action.setShortcutContext(Qt.WidgetShortcut)
self.addAction(remove_rows_action)

def _clear_filters(self):
"""Clear all filters"""
self._spine_db_editor.clear_all_filters()
for i in range(self._EXPECTED_COLUMN_COUNT):
self.model().get_auto_filter_menu(i)._clear_filter()

def contextMenuEvent(self, event):
"""Shows context menu.
Expand Down
23 changes: 19 additions & 4 deletions spinetoolbox/spine_db_editor/widgets/spine_db_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
QDialog,
)
from PySide6.QtCore import QModelIndex, Qt, Signal, Slot, QTimer, QCoreApplication
from PySide6.QtGui import QGuiApplication, QKeySequence, QPalette
from PySide6.QtGui import QGuiApplication, QKeySequence, QPalette, QColor
from spinedb_api import export_data, DatabaseMapping, SpineDBAPIError, SpineDBVersionError, Asterisk
from spinedb_api.spine_io.importers.excel_reader import get_mapped_data_from_xlsx
from spinedb_api.helpers import vacuum
Expand All @@ -39,6 +39,7 @@
from .toolbar import DBEditorToolBar
from .metadata_editor import MetadataEditor
from .item_metadata_editor import ItemMetadataEditor
from ..helpers import table_name_from_item_type
from ...widgets.notification import ChangeNotifier, Notification
from ...widgets.parameter_value_editor import ParameterValueEditor
from ...widgets.commit_dialog import CommitDialog
Expand Down Expand Up @@ -874,15 +875,29 @@ def closeEvent(self, event):
def _get_base_dir():
return APPLICATION_PATH

def set_dock_tab_color(self, dock, color):
@staticmethod
def set_dock_tab_color(dock, color):
"""Colors the header of a dock widget"""
palette = QPalette()
if color:
palette.setColor(QPalette.Window, color)
else:
self.rename_dock(dock, None)
dock.setPalette(palette)

def handle_column_filters(self, model):
if not model.dock:
return
if not any(model.column_filters.values()):
# Back to defaults
model.dock.setWindowTitle(table_name_from_item_type(model.item_type))
self.set_dock_tab_color(model.dock, None)
return
self.set_dock_tab_color(model.dock, QColor("paleturquoise"))
table_name = table_name_from_item_type(model.item_type)
table_name += (
f" [COLUMN FILTERS: {', '.join([name for name, active in model.column_filters.items() if active])}]"
)
model.dock.setWindowTitle(table_name)

@staticmethod
def rename_dock(dock, text=None):
name = "Entity tree"
Expand Down
2 changes: 2 additions & 0 deletions spinetoolbox/spine_db_editor/widgets/stacked_view_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(self, *args, **kwargs):
}
for model, view in self._all_stacked_models.items():
view.setModel(model)
dock = view.parent().parent()
model.dock = dock
view.verticalHeader().setDefaultSectionSize(preferred_row_height(self))
horizontal_header = view.horizontalHeader()
horizontal_header.setSectionsMovable(True)
Expand Down

0 comments on commit 7d0fe1d

Please sign in to comment.