mirror of
https://github.com/RolandWH/SIPPCompare.git
synced 2025-05-10 08:41:49 +01:00
add additional input validation
This commit is contained in:
parent
71d9590205
commit
9e79d986e4
@ -78,6 +78,7 @@ class SIPPCompare(QMainWindow):
|
|||||||
fund_trades_num = int(self.fund_trades_combo.currentText())
|
fund_trades_num = int(self.fund_trades_combo.currentText())
|
||||||
share_trades_num = int(self.share_trades_combo.currentText())
|
share_trades_num = int(self.share_trades_combo.currentText())
|
||||||
shares_value = (1 - (slider_val / 100)) * value_num
|
shares_value = (1 - (slider_val / 100)) * value_num
|
||||||
|
index = 0
|
||||||
|
|
||||||
for platform in self.platform_list_win.plat_list:
|
for platform in self.platform_list_win.plat_list:
|
||||||
if not platform.enabled:
|
if not platform.enabled:
|
||||||
@ -88,6 +89,8 @@ class SIPPCompare(QMainWindow):
|
|||||||
share_plat_fees = 0.0
|
share_plat_fees = 0.0
|
||||||
share_deal_fees = 0.0
|
share_deal_fees = 0.0
|
||||||
plat_name = platform.plat_name
|
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:
|
if platform.fund_deal_fee is not None:
|
||||||
fund_deal_fees = fund_trades_num * platform.fund_deal_fee
|
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
|
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])
|
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
|
# Save details entered by user for next session
|
||||||
self.db.write_user_details(value_num, slider_val, share_trades_num, fund_trades_num)
|
self.db.write_user_details(value_num, slider_val, share_trades_num, fund_trades_num)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from PyQt6 import uic
|
from PyQt6 import uic
|
||||||
from PyQt6.QtCore import QRegularExpression, QRect
|
from PyQt6.QtCore import QRegularExpression, QRect
|
||||||
from PyQt6.QtGui import QRegularExpressionValidator, QFont, QIcon
|
from PyQt6.QtGui import QRegularExpressionValidator, QFont, QIcon
|
||||||
from PyQt6.QtWidgets import QWidget, QLabel
|
from PyQt6.QtWidgets import QLabel, QDialog
|
||||||
|
|
||||||
import resource_finder
|
import resource_finder
|
||||||
from db_handler import DBHandler
|
from db_handler import DBHandler
|
||||||
@ -9,7 +9,7 @@ from data_struct import Platform
|
|||||||
from widgets.fastedit_spinbox import FastEditQDoubleSpinBox
|
from widgets.fastedit_spinbox import FastEditQDoubleSpinBox
|
||||||
|
|
||||||
|
|
||||||
class PlatformEdit(QWidget):
|
class PlatformEdit(QDialog):
|
||||||
def __init__(self, plat: Platform):
|
def __init__(self, plat: Platform):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
# Import Qt Designer UI XML file
|
# Import Qt Designer UI XML file
|
||||||
@ -178,6 +178,8 @@ class PlatformEdit(QWidget):
|
|||||||
else:
|
else:
|
||||||
self.plat.share_deal_reduce_amount = None
|
self.plat.share_deal_reduce_amount = None
|
||||||
|
|
||||||
|
self.accept()
|
||||||
|
|
||||||
# This method does multiple things in order to validate the user's inputs:
|
# This method does multiple things in order to validate the user's inputs:
|
||||||
# 1) Check all required fields have a non-zero value
|
# 1) Check all required fields have a non-zero value
|
||||||
# 2) If an optional checkbox is toggled: toggle editing of the corresponding field
|
# 2) If an optional checkbox is toggled: toggle editing of the corresponding field
|
||||||
@ -347,3 +349,7 @@ class PlatformEdit(QWidget):
|
|||||||
|
|
||||||
self.check_valid()
|
self.check_valid()
|
||||||
self.update_tier_labels()
|
self.update_tier_labels()
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
event.ignore()
|
||||||
|
self.reject()
|
||||||
|
@ -63,7 +63,7 @@ class PlatformList(QWidget):
|
|||||||
# Initialise class variables
|
# Initialise class variables
|
||||||
self.db = db
|
self.db = db
|
||||||
self.plat_edit_win = None
|
self.plat_edit_win = None
|
||||||
self.plat_list_dialog = PlatformRename()
|
self.plat_list_dialog = None
|
||||||
self.del_plat_dialog = RemoveConfirm()
|
self.del_plat_dialog = RemoveConfirm()
|
||||||
self.plat_list = []
|
self.plat_list = []
|
||||||
self.plat_name_list = []
|
self.plat_name_list = []
|
||||||
@ -95,6 +95,7 @@ class PlatformList(QWidget):
|
|||||||
self.platListWidget.addItem(item)
|
self.platListWidget.addItem(item)
|
||||||
|
|
||||||
def add_platform(self):
|
def add_platform(self):
|
||||||
|
self.plat_list_dialog = PlatformRename()
|
||||||
name_dialog_res = self.plat_list_dialog.exec()
|
name_dialog_res = self.plat_list_dialog.exec()
|
||||||
if name_dialog_res == QDialog.DialogCode.Accepted:
|
if name_dialog_res == QDialog.DialogCode.Accepted:
|
||||||
name = self.plat_list_dialog.new_name
|
name = self.plat_list_dialog.new_name
|
||||||
@ -110,13 +111,19 @@ class PlatformList(QWidget):
|
|||||||
index, [[0], [0]], name_param, True, 0, 0, None, 0, None, None)
|
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 = 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):
|
def get_enabled_state(self):
|
||||||
index = self.platListWidget.currentRow()
|
index = self.platListWidget.currentRow()
|
||||||
is_enabled = self.plat_list[index].enabled
|
if len(self.plat_list) > 0:
|
||||||
if is_enabled:
|
is_enabled = self.plat_list[index].enabled
|
||||||
self.plat_enabled_check.setChecked(True)
|
if is_enabled:
|
||||||
|
self.plat_enabled_check.setChecked(True)
|
||||||
|
else:
|
||||||
|
self.plat_enabled_check.setChecked(False)
|
||||||
else:
|
else:
|
||||||
self.plat_enabled_check.setChecked(False)
|
self.plat_enabled_check.setChecked(False)
|
||||||
|
|
||||||
@ -127,8 +134,9 @@ class PlatformList(QWidget):
|
|||||||
|
|
||||||
def edit_platform(self):
|
def edit_platform(self):
|
||||||
index = self.platListWidget.currentRow()
|
index = self.platListWidget.currentRow()
|
||||||
self.plat_edit_win = PlatformEdit(self.plat_list[index])
|
if len(self.plat_list) > 0:
|
||||||
self.plat_edit_win.show()
|
self.plat_edit_win = PlatformEdit(self.plat_list[index])
|
||||||
|
self.plat_edit_win.exec()
|
||||||
|
|
||||||
def save_platforms(self):
|
def save_platforms(self):
|
||||||
self.db.write_platforms(self.plat_list)
|
self.db.write_platforms(self.plat_list)
|
||||||
@ -138,7 +146,8 @@ class PlatformList(QWidget):
|
|||||||
def toggle_platform_state(self):
|
def toggle_platform_state(self):
|
||||||
index = self.platListWidget.currentRow()
|
index = self.platListWidget.currentRow()
|
||||||
state = self.plat_enabled_check.isChecked()
|
state = self.plat_enabled_check.isChecked()
|
||||||
self.plat_list[index].enabled = state
|
if len(self.plat_list) > 0 and index >= 0:
|
||||||
|
self.plat_list[index].enabled = state
|
||||||
|
|
||||||
def remove_platform(self):
|
def remove_platform(self):
|
||||||
index = self.platListWidget.currentRow()
|
index = self.platListWidget.currentRow()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user