Commit 3b9d0b17 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

BC: Add date custom editor.

Showing with 32 additions and 8 deletions
+32 -8
......@@ -10,12 +10,12 @@ from View.ListedSubWindow import ListedSubWindow
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
QCoreApplication, QModelIndex, pyqtSlot,
QRect, QTime,
QRect, QTime, QDateTime,
)
from PyQt5.QtWidgets import (
QTableView, QAbstractItemView, QSpinBox,
QTimeEdit, QItemDelegate,
QTimeEdit, QDateTimeEdit, QItemDelegate,
)
from Model.BoundaryCondition.BoundaryConditionTypes import (
......@@ -73,6 +73,26 @@ class ExtendedTimeEdit(AWidget):
return timedelta(days=days, seconds=secs)
class ExtendedDateTimeEdit(AWidget):
def __init__(self, parent=None):
super(ExtendedDateTimeEdit, self).__init__(
ui="extendedDateTimeEdit",
parent=parent
)
self.parent = parent
self.dateTimeEdit = self.find(QDateTimeEdit, "dateTimeEdit")
def set_time(self, time):
qdatetime = QDateTime.fromString(
time,
"yyyy-MM-dd hh:mm:ss"
)
self.dateTimeEdit.setDateTime(qdatetime)
def get_time(self):
time = self.dateTimeEdit.dateTime().toPyDateTime()
return time
class ExTimeDelegate(QItemDelegate):
def __init__(self, data=None, mode="time", parent=None):
......@@ -82,18 +102,22 @@ class ExTimeDelegate(QItemDelegate):
self._mode = mode
def createEditor(self, parent, option, index):
self.editor = ExtendedTimeEdit(parent=parent)
if self._mode == "time":
self.editor = ExtendedTimeEdit(parent=parent)
else:
self.editor = ExtendedDateTimeEdit(parent=parent)
value = index.data(Qt.DisplayRole)
self.editor.set_time(value)
print(value)
return self.editor
def setEditorData(self, editor, index):
value = index.data(Qt.DisplayRole)
self.editor.currentTextChanged.connect(self.currentItemChanged)
def setModelData(self, editor, model, index):
time = editor.get_time()
model.setData(index, int(time.total_seconds()))
if self._mode == "time":
model.setData(index, int(time.total_seconds()))
else:
print(time.timestamp())
model.setData(index, int(time.timestamp()))
editor.close()
editor.deleteLater()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment