mirror of https://gitlab.com/pamhyr/pamhyr2
Stricklers: Switch stricklers table to PamhyrTableModel and fix translate.
parent
4f471d4d6f
commit
ffebfbdddc
|
|
@ -34,37 +34,19 @@ from PyQt5.QtWidgets import (
|
||||||
QComboBox,
|
QComboBox,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||||
|
|
||||||
from View.Stricklers.UndoCommand import (
|
from View.Stricklers.UndoCommand import (
|
||||||
SetNameCommand, SetCommentCommand,
|
SetNameCommand, SetCommentCommand,
|
||||||
SetMinorCommand, SetMediumCommand,
|
SetMinorCommand, SetMediumCommand,
|
||||||
AddCommand, DelCommand, SortCommand,
|
AddCommand, DelCommand, SortCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.Stricklers.translate import *
|
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
class TableModel(QAbstractTableModel):
|
class TableModel(PamhyrTableModel):
|
||||||
def __init__(self, data=None, undo=None, tab=""):
|
|
||||||
super(QAbstractTableModel, self).__init__()
|
|
||||||
self._headers = list(table_headers.keys())
|
|
||||||
self._data = data
|
|
||||||
self._undo = undo
|
|
||||||
|
|
||||||
def flags(self, index):
|
|
||||||
options = Qt.ItemIsEnabled | Qt.ItemIsSelectable
|
|
||||||
options |= Qt.ItemIsEditable
|
|
||||||
|
|
||||||
return options
|
|
||||||
|
|
||||||
def rowCount(self, parent):
|
|
||||||
return len(self._data)
|
|
||||||
|
|
||||||
def columnCount(self, parent):
|
|
||||||
return len(self._headers)
|
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role != Qt.ItemDataRole.DisplayRole:
|
if role != Qt.ItemDataRole.DisplayRole:
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
@ -83,12 +65,7 @@ class TableModel(QAbstractTableModel):
|
||||||
|
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
def headerData(self, section, orientation, role):
|
@pyqtSlot()
|
||||||
if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal:
|
|
||||||
return table_headers[self._headers[section]]
|
|
||||||
|
|
||||||
return QVariant()
|
|
||||||
|
|
||||||
def setData(self, index, value, role=Qt.EditRole):
|
def setData(self, index, value, role=Qt.EditRole):
|
||||||
if not index.isValid() or role != Qt.EditRole:
|
if not index.isValid() or role != Qt.EditRole:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ from Model.Stricklers.Stricklers import Stricklers
|
||||||
|
|
||||||
from View.Stricklers.UndoCommand import PasteCommand
|
from View.Stricklers.UndoCommand import PasteCommand
|
||||||
from View.Stricklers.Table import TableModel
|
from View.Stricklers.Table import TableModel
|
||||||
|
from View.Stricklers.translate import table_headers, retranslate
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
@ -74,7 +75,9 @@ class StricklersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
self.copy_sc = QShortcut(QKeySequence.Copy, self)
|
self.copy_sc = QShortcut(QKeySequence.Copy, self)
|
||||||
self.paste_sc = QShortcut(QKeySequence.Paste, self)
|
self.paste_sc = QShortcut(QKeySequence.Paste, self)
|
||||||
|
|
||||||
|
|
||||||
def setup_table(self):
|
def setup_table(self):
|
||||||
|
retranslate()
|
||||||
self._table = {}
|
self._table = {}
|
||||||
|
|
||||||
for t in ["app", "study"]:
|
for t in ["app", "study"]:
|
||||||
|
|
@ -85,6 +88,9 @@ class StricklersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
data = self._config.stricklers
|
data = self._config.stricklers
|
||||||
|
|
||||||
self._table[t] = TableModel(
|
self._table[t] = TableModel(
|
||||||
|
table_view = table,
|
||||||
|
table_headers = table_headers,
|
||||||
|
editable_headers = ["name", "comment", "minor", "medium"],
|
||||||
data = data,
|
data = data,
|
||||||
undo = self._undo_stack,
|
undo = self._undo_stack,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -30,3 +30,9 @@ table_headers = {
|
||||||
"medium": _translate("LateralContribution", "Medium bed"),
|
"medium": _translate("LateralContribution", "Medium bed"),
|
||||||
"comment": _translate("LateralContribution", "Comment"),
|
"comment": _translate("LateralContribution", "Comment"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def retranslate():
|
||||||
|
table_headers["name"] = _translate("LateralContribution", "Name")
|
||||||
|
table_headers["minor"] = _translate("LateralContribution", "Minor bed")
|
||||||
|
table_headers["medium"] = _translate("LateralContribution", "Medium bed")
|
||||||
|
table_headers["comment"] = _translate("LateralContribution", "Comment")
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,6 @@ class PamhyrTableModel(QAbstractTableModel):
|
||||||
|
|
||||||
def headerData(self, section, orientation, role):
|
def headerData(self, section, orientation, role):
|
||||||
if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal:
|
if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal:
|
||||||
logger.info(self._table_headers[self._headers[section]])
|
|
||||||
return self._table_headers[self._headers[section]]
|
return self._table_headers[self._headers[section]]
|
||||||
|
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue