mirror of https://gitlab.com/pamhyr/pamhyr2
Application strickler: check that the name is not already in use before committing the change to the talbe, as the name is used as database identifier
parent
129dde1c57
commit
b9ab202e3f
|
|
@ -120,7 +120,9 @@ class ConfigureWindow(PamhyrDialog):
|
||||||
editable_headers=["name", "comment", "minor", "medium"],
|
editable_headers=["name", "comment", "minor", "medium"],
|
||||||
data=self._stricklers,
|
data=self._stricklers,
|
||||||
undo=self._undo_stack,
|
undo=self._undo_stack,
|
||||||
|
trad=self._trad_stricklers,
|
||||||
display_manning=self._config.display_manning,
|
display_manning=self._config.display_manning,
|
||||||
|
unique_names=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setup_data(self):
|
def setup_data(self):
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ from PyQt5.QtWidgets import (
|
||||||
QDialogButtonBox, QPushButton, QLineEdit,
|
QDialogButtonBox, QPushButton, QLineEdit,
|
||||||
QFileDialog, QTableView, QAbstractItemView,
|
QFileDialog, QTableView, QAbstractItemView,
|
||||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||||
QComboBox,
|
QComboBox, QMessageBox,
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||||
|
|
@ -51,10 +51,19 @@ _translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
||||||
class TableModel(PamhyrTableModel):
|
class TableModel(PamhyrTableModel):
|
||||||
def __init__(self, *args, display_manning=False, **kwargs):
|
def __init__(self, *args, display_manning=False, unique_names=False,
|
||||||
|
**kwargs):
|
||||||
self.display_manning = display_manning
|
self.display_manning = display_manning
|
||||||
|
self.unique_names = unique_names
|
||||||
super(TableModel, self).__init__(*args, **kwargs)
|
super(TableModel, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def name_is_already_used(self, row, name):
|
||||||
|
current = self._data.get(row)
|
||||||
|
return any(
|
||||||
|
strickler is not current and strickler.name == name
|
||||||
|
for strickler in self._data.stricklers
|
||||||
|
)
|
||||||
|
|
||||||
def get_true_data_row(self, row):
|
def get_true_data_row(self, row):
|
||||||
el = self._data.get(row)
|
el = self._data.get(row)
|
||||||
|
|
||||||
|
|
@ -101,6 +110,18 @@ class TableModel(PamhyrTableModel):
|
||||||
row = index.row()
|
row = index.row()
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
|
||||||
|
if (
|
||||||
|
self._headers[column] == "name"
|
||||||
|
and self.unique_names
|
||||||
|
and self.name_is_already_used(row, str(value))
|
||||||
|
):
|
||||||
|
QMessageBox.warning(
|
||||||
|
self._table_view,
|
||||||
|
self._trad["duplicate_name_title"],
|
||||||
|
self._trad["duplicate_name_message"]
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self._headers[column] == "name":
|
if self._headers[column] == "name":
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,13 @@ class StricklersTranslate(MainTranslate):
|
||||||
self._dict["application_mannings"] = _translate(
|
self._dict["application_mannings"] = _translate(
|
||||||
"Stricklers", "Manning coefficients of the application"
|
"Stricklers", "Manning coefficients of the application"
|
||||||
)
|
)
|
||||||
|
self._dict["duplicate_name_title"] = _translate(
|
||||||
|
"Stricklers", "Name already used"
|
||||||
|
)
|
||||||
|
self._dict["duplicate_name_message"] = _translate(
|
||||||
|
"Stricklers",
|
||||||
|
"This name is already used by another coefficient."
|
||||||
|
)
|
||||||
|
|
||||||
self._sub_dict["table_headers"] = {
|
self._sub_dict["table_headers"] = {
|
||||||
"name": self._dict["name"],
|
"name": self._dict["name"],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue