Beispiel #1
0
 def setEditorData(self, editor, index):
     timestamp = index.model().data(index, Qt.EditRole)
     if timestamp == '':
         QStyledItemDelegate.setEditorData(self, editor, index)
     else:
         editor.setDateTime(datetime.utcfromtimestamp(timestamp))
Beispiel #2
0
 def setEditorData(self, editor, index):
     """ Sets the data to be displayed and edited by our custom editor. """
     if index.column() == 3:
         editor.starRating = StarRating(index.data())
     else:
         QStyledItemDelegate.setEditorData(self, editor, index)
Beispiel #3
0
class KnechtValueDelegate(QStyledItemDelegate):
    def __init__(self, view):
        """ Basic item delegate that returns the views default item delegate or depending
            on the item type column: an appropriate custom render setting item delegate.

        :param modules.itemview.treeview.KnechtTreeView view: View we replace delegates in
        """
        super(KnechtValueDelegate, self).__init__(view)
        self.view = view

        self.default_delegate = QStyledItemDelegate(view)
        self.setting_delegate = None

    def createEditor(self, parent, option, index):
        # ---- Default behaviour ----
        if not self._index_is_custom_setting(index):
            return self.default_delegate.createEditor(parent, option, index)

        # ---- Custom behaviour ----
        return self.setting_delegate.create_editor(parent, option, index)

    def setEditorData(self, editor, index):
        # ---- Default behaviour ----
        if not self._index_is_custom_setting(index):
            return self.default_delegate.setEditorData(editor, index)

        # ---- Custom behaviour ---
        self.setting_delegate.set_editor_data(editor, index)

    def setModelData(self, editor, model, index):
        # ---- Default behaviour ----
        if not self._index_is_custom_setting(index):
            return self.default_delegate.setModelData(editor, model, index)

        # ---- Custom behaviour ---
        self.setting_delegate.set_model_data(editor, model, index)

    def updateEditorGeometry(self, editor, option, index):
        # ---- Default behaviour ----
        if not self._index_is_custom_setting(index):
            return self.default_delegate.updateEditorGeometry(
                editor, option, index)

        # ---- Custom behaviour ---
        editor.setGeometry(option.rect)

    def _index_is_custom_setting(self, index: QModelIndex):
        src_index = index.model().mapToSource(index)
        item: KnechtItem = index.model().sourceModel().get_item(src_index)
        setting_type = item.data(Kg.TYPE)

        if item.userType in [Kg.output_item]:
            self.setting_delegate = OutputDirButton(self.view)
            return True

        if item.userType in [Kg.plmxml_item]:
            self.setting_delegate = InputFileButton(self.view)
            return True

        if item.userType == Kg.render_setting and setting_type in RENDER_SETTING_MAP.keys(
        ):
            self.setting_delegate = RENDER_SETTING_MAP[setting_type](self.view)
            return True
        return False