Skip to content

Commit

Permalink
Improve tool tips
Browse files Browse the repository at this point in the history
Use rich text in tool tips so Qt can wrap the text.

Re spine-tools/Spine-Toolbox#2542
  • Loading branch information
soininen committed Mar 14, 2024
1 parent f1c61c6 commit 4228d6e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions spine_items/exporter/mvcmodels/mapping_editor_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
DefaultValueIndexNameMapping,
ParameterDefaultValueTypeMapping,
)
from spinetoolbox.helpers import color_from_index
from spinetoolbox.helpers import color_from_index, plain_to_rich
from ..commands import SetMappingNullable, SetMappingPositions, SetMappingProperty


Expand Down Expand Up @@ -152,9 +152,9 @@ def data(self, index, role=Qt.ItemDataRole.DisplayRole):
return self._mapping_colors.get(m.position, QColor(Qt.GlobalColor.gray).lighter())
elif role == Qt.ItemDataRole.ToolTipRole:
if column == EditorColumn.FILTER:
return "Regular expression to filter database items."
return plain_to_rich("Regular expression to filter database items.")

Check warning on line 155 in spine_items/exporter/mvcmodels/mapping_editor_table_model.py

View check run for this annotation

Codecov / codecov/patch

spine_items/exporter/mvcmodels/mapping_editor_table_model.py#L155

Added line #L155 was not covered by tests
elif column == EditorColumn.NULLABLE:
return "When checked, ignore this row if it yields nothing to export."
return plain_to_rich("When checked, ignore this row if it yields nothing to export.")

Check warning on line 157 in spine_items/exporter/mvcmodels/mapping_editor_table_model.py

View check run for this annotation

Codecov / codecov/patch

spine_items/exporter/mvcmodels/mapping_editor_table_model.py#L157

Added line #L157 was not covered by tests
if role == self.MAPPING_ITEM_ROLE:
return self._mappings[index.row()]
return None
Expand Down
12 changes: 5 additions & 7 deletions spine_items/importer/mvcmodels/mappings_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import re
from PySide6.QtCore import QAbstractItemModel, QModelIndex, Qt, Signal
from PySide6.QtGui import QColor, QFont
from spinetoolbox.helpers import unique_name
from spinetoolbox.helpers import plain_to_rich, list_to_rich_text, unique_name
from spinedb_api.parameter_value import join_value_and_type, split_value_and_type
from spinedb_api import from_database, ParameterValueFormatError
from spinedb_api.import_mapping.import_mapping import ScenarioBeforeAlternativeMapping
Expand Down Expand Up @@ -214,9 +214,9 @@ def _table_list_data(self, index, role):
list_item = self._mappings[row]
if not list_item.empty:
if not list_item.in_source:
return "Table isn't in source data."
return plain_to_rich("Table isn't in source data.")

Check warning on line 217 in spine_items/importer/mvcmodels/mappings_model.py

View check run for this annotation

Codecov / codecov/patch

spine_items/importer/mvcmodels/mappings_model.py#L217

Added line #L217 was not covered by tests
if not list_item.in_specification:
return "Table's mappings haven't been saved with the specification yet."
return plain_to_rich("Table's mappings haven't been saved with the specification yet.")
return None
if role == Qt.ItemDataRole.FontRole:
return self._add_table_row_font if self._mappings[index.row()].empty else None
Expand Down Expand Up @@ -288,11 +288,9 @@ def _mapping_data(flattened_mappings, index, role):
if role == Qt.ItemDataRole.ToolTipRole:
if column == FlattenedColumn.POSITION:
issues = flattened_mappings.display_row_issues(index.row())
if issues:
return issues
return None
return list_to_rich_text(issues) if issues else None
if column == FlattenedColumn.REGEXP:
return "Enter regular expression to filter importer data."
return plain_to_rich("Enter regular expression to filter importer data.")

Check warning on line 293 in spine_items/importer/mvcmodels/mappings_model.py

View check run for this annotation

Codecov / codecov/patch

spine_items/importer/mvcmodels/mappings_model.py#L293

Added line #L293 was not covered by tests
return None

def headerData(self, section, orientation, role=Qt.ItemDataRole.DisplayRole):
Expand Down
3 changes: 2 additions & 1 deletion tests/importer/mvcmodels/test_mappings_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def test_turn_empty_row_into_non_real_table(self):
self.assertEqual(index.data(Qt.ItemDataRole.CheckStateRole), Qt.CheckState.Checked)
self.assertIsNone(index.data(Qt.ItemDataRole.FontRole))
self.assertEqual(
index.data(Qt.ItemDataRole.ToolTipRole), "Table's mappings haven't been saved with the specification yet."
index.data(Qt.ItemDataRole.ToolTipRole),
"<qt>Table's mappings haven't been saved with the specification yet.</qt>",
)
flags = self._model.flags(index)
self.assertEqual(
Expand Down

0 comments on commit 4228d6e

Please sign in to comment.