Commits

Ivan Andrianov committed b39cc04

Used QDataWidgetMapper to map tag block widgets and TranscodeModel.

  • Participants
  • Parent commits 2209ce9

Comments (0)

Files changed (1)

File pysrc/fftranscoder/ui/mainwindow.py

         self._prepareView()
 
         self._prepareTagBlock()
+        
+        self._prepareWidgetMapper()
 
     def _addFiles(self):
         if len(codecs.PluginLoader.instance().decoderPlugins()) == 0:
         self._tagBlockLayout.addWidget(self._yearLabel, 0, 2)
 
         self._yearSpinBox = QtGui.QSpinBox()
+        self._yearSpinBox.setMaximum(9999)
         self._tagBlockLayout.addWidget(self._yearSpinBox, 0, 3)
 
         self._trackNameLabel = QtGui.QLabel(self.tr('Track number'))
         self._tagBlockLayout.addWidget(self._trackNameLabel, 1, 2)
 
-        self._trackNameSpinBox = QtGui.QSpinBox()
-        self._tagBlockLayout.addWidget(self._trackNameSpinBox, 1, 3)
+        self._trackNumberSpinBox = QtGui.QSpinBox()
+        self._tagBlockLayout.addWidget(self._trackNumberSpinBox, 1, 3)
 
         self._submitTagBlock = QtGui.QPushButton(self.tr('Submit tags'))
         self._tagBlockLayout.addWidget(self._submitTagBlock, 2, 2, 1, -1)
 
         self._mainLayout.addWidget(self._tagBlockWidget)
+
+    def _prepareWidgetMapper(self):
+        self._tagBlockWidgetMapper = QtGui.QDataWidgetMapper()
+        self._tagBlockWidgetMapper.setSubmitPolicy(
+                QtGui.QDataWidgetMapper.ManualSubmit)
+
+        self._tagBlockWidgetMapper.setModel(self._transcodeModel)
+        self._tagBlockWidgetMapper.addMapping(self._artistNameLineEdit,
+                TranscodeModel.ARTIST_NAME)
+        self._tagBlockWidgetMapper.addMapping(self._albumNameLineEdit,
+                TranscodeModel.ALBUM_NAME)
+        self._tagBlockWidgetMapper.addMapping(self._trackNameLineEdit,
+                TranscodeModel.TRACK_NAME)
+        self._tagBlockWidgetMapper.addMapping(self._yearSpinBox,
+                TranscodeModel.YEAR)
+        self._tagBlockWidgetMapper.addMapping(self._trackNumberSpinBox,
+                TranscodeModel.TRACK_NUMBER)
+
+        self._submitTagBlock.clicked.connect(
+                self._tagBlockWidgetMapper.submit)
+        self._view.selectionModel().currentRowChanged.connect(
+                lambda i, x: self._tagBlockWidgetMapper.setCurrentModelIndex(i))