Skip to content

Commit

Permalink
Make some DB editor tooltips rich text
Browse files Browse the repository at this point in the history
This is a quick-n-dirty fix to get the tests work when publishing.
Instead of cutting the text to fixed size, we can make it rich text
which enables Qt to wrap the lines.
  • Loading branch information
soininen committed Mar 28, 2024
1 parent ff6a279 commit b684209
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions spinetoolbox/spine_db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,7 @@ def tool_tip_data_from_parsed(parsed_data):
else:
tool_tip_data = None
if isinstance(tool_tip_data, str):
fm = QFontMetrics(QFont("", 0))
tool_tip_data = fm.elidedText(tool_tip_data, Qt.ElideRight, 800)
tool_tip_data = "<qt>" + tool_tip_data + "</qt>"
return tool_tip_data

def _format_list_value(self, db_map, item_type, value, list_value_id):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_SpineDBManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ def test_time_series_in_tool_tip_role(self):
value = TimeSeriesFixedResolution("2019-07-12T08:00", ["7 hours", "12 hours"], [1.1, 2.2, 3.3], False, False)
self.db_mngr.get_item.side_effect = _make_get_item_side_effect(*to_database(value))
formatted = self.get_value(Qt.ItemDataRole.ToolTipRole)
self.assertEqual(formatted, "Start: 2019-07-12 08:00:00, resolution: [7h, 12h], length: 3")
self.assertEqual(formatted, "<qt>Start: 2019-07-12 08:00:00, resolution: [7h, 12h], length: 3</qt>")
value = TimeSeriesVariableResolution(["2019-07-12T08:00", "2019-07-12T16:00"], [0.0, 100.0], False, False)
self.db_mngr.get_item.side_effect = _make_get_item_side_effect(*to_database(value))
formatted = self.get_value(Qt.ItemDataRole.ToolTipRole)
self.assertEqual(formatted, "Start: 2019-07-12T08:00:00, resolution: variable, length: 2")
self.assertEqual(formatted, "<qt>Start: 2019-07-12T08:00:00, resolution: variable, length: 2</qt>")

def test_broken_value_in_display_role(self):
value = b"dubbidubbidu"
Expand All @@ -179,7 +179,7 @@ def test_broken_value_in_tool_tip_role(self):
value = b"diibadaaba"
self.db_mngr.get_item.side_effect = _make_get_item_side_effect(value, None)
formatted = self.get_value(Qt.ItemDataRole.ToolTipRole)
self.assertTrue(formatted.startswith('Could not decode the value'))
self.assertTrue(formatted.startswith('<qt>Could not decode the value'))


class TestAddItems(unittest.TestCase):
Expand Down

0 comments on commit b684209

Please sign in to comment.