add additional input validation

This commit is contained in:
Roland W-H 2025-04-27 11:52:14 +01:00
parent 71d9590205
commit 9e79d986e4
3 changed files with 29 additions and 10 deletions

View File

@ -78,6 +78,7 @@ class SIPPCompare(QMainWindow):
fund_trades_num = int(self.fund_trades_combo.currentText())
share_trades_num = int(self.share_trades_combo.currentText())
shares_value = (1 - (slider_val / 100)) * value_num
index = 0
for platform in self.platform_list_win.plat_list:
if not platform.enabled:
@ -88,6 +89,8 @@ class SIPPCompare(QMainWindow):
share_plat_fees = 0.0
share_deal_fees = 0.0
plat_name = platform.plat_name
if plat_name is None or plat_name == "":
plat_name = f"Unnamed [ID: {index}]"
if platform.fund_deal_fee is not None:
fund_deal_fees = fund_trades_num * platform.fund_deal_fee
@ -119,6 +122,7 @@ class SIPPCompare(QMainWindow):
share_deal_fees = platform.share_deal_fee * share_trades_num
self.results.append([fund_plat_fees, fund_deal_fees, share_plat_fees, share_deal_fees, plat_name])
index += 1
# Save details entered by user for next session
self.db.write_user_details(value_num, slider_val, share_trades_num, fund_trades_num)

View File

@ -1,7 +1,7 @@
from PyQt6 import uic
from PyQt6.QtCore import QRegularExpression, QRect
from PyQt6.QtGui import QRegularExpressionValidator, QFont, QIcon
from PyQt6.QtWidgets import QWidget, QLabel
from PyQt6.QtWidgets import QLabel, QDialog
import resource_finder
from db_handler import DBHandler
@ -9,7 +9,7 @@ from data_struct import Platform
from widgets.fastedit_spinbox import FastEditQDoubleSpinBox
class PlatformEdit(QWidget):
class PlatformEdit(QDialog):
def __init__(self, plat: Platform):
super().__init__()
# Import Qt Designer UI XML file
@ -178,6 +178,8 @@ class PlatformEdit(QWidget):
else:
self.plat.share_deal_reduce_amount = None
self.accept()
# This method does multiple things in order to validate the user's inputs:
# 1) Check all required fields have a non-zero value
# 2) If an optional checkbox is toggled: toggle editing of the corresponding field
@ -347,3 +349,7 @@ class PlatformEdit(QWidget):
self.check_valid()
self.update_tier_labels()
def closeEvent(self, event):
event.ignore()
self.reject()

View File

@ -63,7 +63,7 @@ class PlatformList(QWidget):
# Initialise class variables
self.db = db
self.plat_edit_win = None
self.plat_list_dialog = PlatformRename()
self.plat_list_dialog = None
self.del_plat_dialog = RemoveConfirm()
self.plat_list = []
self.plat_name_list = []
@ -95,6 +95,7 @@ class PlatformList(QWidget):
self.platListWidget.addItem(item)
def add_platform(self):
self.plat_list_dialog = PlatformRename()
name_dialog_res = self.plat_list_dialog.exec()
if name_dialog_res == QDialog.DialogCode.Accepted:
name = self.plat_list_dialog.new_name
@ -110,15 +111,21 @@ class PlatformList(QWidget):
index, [[0], [0]], name_param, True, 0, 0, None, 0, None, None)
)
self.plat_edit_win = PlatformEdit(self.plat_list[index])
self.plat_edit_win.show()
plat_edit_res = self.plat_edit_win.exec()
if plat_edit_res == QDialog.DialogCode.Rejected:
self.plat_list.pop()
self.platListWidget.takeItem(self.platListWidget.count() - 1)
def get_enabled_state(self):
index = self.platListWidget.currentRow()
if len(self.plat_list) > 0:
is_enabled = self.plat_list[index].enabled
if is_enabled:
self.plat_enabled_check.setChecked(True)
else:
self.plat_enabled_check.setChecked(False)
else:
self.plat_enabled_check.setChecked(False)
if index in self.db_indices:
self.del_plat_but.setEnabled(True)
@ -127,8 +134,9 @@ class PlatformList(QWidget):
def edit_platform(self):
index = self.platListWidget.currentRow()
if len(self.plat_list) > 0:
self.plat_edit_win = PlatformEdit(self.plat_list[index])
self.plat_edit_win.show()
self.plat_edit_win.exec()
def save_platforms(self):
self.db.write_platforms(self.plat_list)
@ -138,6 +146,7 @@ class PlatformList(QWidget):
def toggle_platform_state(self):
index = self.platListWidget.currentRow()
state = self.plat_enabled_check.isChecked()
if len(self.plat_list) > 0 and index >= 0:
self.plat_list[index].enabled = state
def remove_platform(self):