-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix empty database missing 'modified' time causing table to not show #1182
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ def data(self, index, role=Qt.DisplayRole): | |
|
||
# instantiate value only in case of DisplayRole or ToolTipRole | ||
value = None | ||
tt_date_flag = False # flag to indicate if value is datetime object and role is ToolTipRole | ||
if role == Qt.DisplayRole or role == Qt.ToolTipRole or role == 'sorting': | ||
value = self._dataframe.iat[index.row(), index.column()] | ||
if isinstance(value, np.float64): | ||
|
@@ -64,14 +65,23 @@ def data(self, index, role=Qt.DisplayRole): | |
value = value.item() | ||
elif isinstance(value, tuple): | ||
value = str(value) | ||
elif isinstance(value, datetime.datetime) and role != 'sorting': | ||
elif isinstance(value, datetime.datetime) and (Qt.DisplayRole or Qt.ToolTipRole): | ||
tz = datetime.datetime.now(datetime.timezone.utc).astimezone() | ||
time_shift = - tz.utcoffset().total_seconds() | ||
value = arrow.get(value).shift(seconds=time_shift).humanize() | ||
if role == Qt.ToolTipRole: | ||
value = arrow.get(value).shift(seconds=time_shift).format('YYYY-MM-DD HH:mm:ss') | ||
tt_date_flag = True | ||
elif role == Qt.DisplayRole: | ||
value = arrow.get(value).shift(seconds=time_shift).humanize() | ||
|
||
# immediately return value in case of DisplayRole or sorting | ||
if role == Qt.DisplayRole or role == 'sorting': | ||
return value | ||
|
||
# in case of ToolTipRole and date, always show the full date | ||
if tt_date_flag and role == Qt.ToolTipRole: | ||
return value | ||
Comment on lines
+82
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't you just return the value where you've set the flag? That would clear the code up nicely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case you wouldn't need the flag to begin with. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's what I had earlier, but thought this may be more consistent as there's no returns in other places |
||
|
||
# immediately return value in case of DisplayRole | ||
if role == Qt.DisplayRole or role == 'sorting': return value | ||
|
||
# in case of ToolTipRole, check whether content fits the cell | ||
if role == Qt.ToolTipRole: | ||
parent = self.parent() | ||
|
@@ -83,7 +93,8 @@ def data(self, index, role=Qt.DisplayRole): | |
margin = 10 | ||
|
||
# only show tooltip if the text is wider then the cell minus the margin | ||
if text_width > column_width - margin: return value | ||
if text_width > column_width - margin: | ||
return value | ||
|
||
if role == Qt.ForegroundRole: | ||
col_name = self._dataframe.columns[index.column()] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method has become very unclear over the last commits. Maybe we should chop it up into different functions/methods. e.g. a value function that returns the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A switch case block also comes to mind. Those are awfully quick, meant for enums like these, and easy to read. Just spitballing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the whole date thing could go in a child class for the DB table as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, it's a bit messy atm
switch
only exists frompy=3.10
, so we can't implement this until we drop support for3.9
. Thoughelif
is essentially a switch, and I don't think the speed matters in this case.Also agree