Commits

Ivan Andrianov committed 2209ce9

Made TranscodeModel editable.

  • Participants
  • Parent commits a771a2e

Comments (0)

Files changed (1)

pysrc/fftranscoder/ui/transcodemodel.py

             return 0
 
     def data(self, index, role = QtCore.Qt.DisplayRole):
-        if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.ToolTipRole:
+        if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
             if index.column() == TranscodeModel.FILE_NAME:
                 return self._fileNames[index.row()]
             else:
         else:
             return None
 
+    def flags(self, index):
+        f = QtCore.QAbstractItemModel.flags(self, index)
+
+        if index.column() == TranscodeModel.ARTIST_NAME or \
+                index.column() == TranscodeModel.ALBUM_NAME or \
+                index.column() == TranscodeModel.TRACK_NAME or \
+                index.column() == TranscodeModel.YEAR or \
+                index.column() == TranscodeModel.TRACK_NUMBER:
+            f |= QtCore.Qt.ItemIsEditable
+
+        return f
+
+    def setData(self, index, value, role = QtCore.Qt.EditRole):
+        if role == QtCore.Qt.EditRole:
+            tagBlock = self._tagBlocks[index.row()]
+            
+            if tagBlock is None:
+                return False
+            
+            if index.column() == TranscodeModel.ARTIST_NAME:
+                tagBlock.setArtistName(value)
+            elif index.column() == TranscodeModel.ALBUM_NAME:
+                tagBlock.setAlbumName(value)
+            elif index.column() == TranscodeModel.TRACK_NAME:
+                tagBlock.setTrackName(value)
+            elif index.column() == TranscodeModel.YEAR:
+                tagBlock.setYear(value)
+            elif index.column() == TranscodeModel.TRACK_NUMBER:
+                tagBlock.setTrackNumber(value)
+            else:
+                return False
+            
+            self.dataChanged.emit(
+                  self.index(index.row(), index.column(), QtCore.QModelIndex()),
+                  self.index(index.row(), index.column(), QtCore.QModelIndex()))
+            return True
+        else:
+            return False
+
     def fileName(self, row):
         return self._fileNames[row]