working color, but update from proxy does not change in database

This commit is contained in:
ccppi 2024-07-26 14:19:17 +02:00
parent 41f356e5bb
commit 2901badfe5

View File

@ -1,6 +1,6 @@
from PySide6.QtWidgets import QApplication, QWidget, QMainWindow, QTableWidget, QVBoxLayout, QTableWidgetItem, QPushButton, QHBoxLayout, QTableView, QLineEdit, QDialog, QLabel, QTextEdit, QCheckBox, QComboBox from PySide6.QtWidgets import QApplication, QWidget, QMainWindow, QTableWidget, QVBoxLayout, QTableWidgetItem, QPushButton, QHBoxLayout, QTableView, QLineEdit, QDialog, QLabel, QTextEdit, QCheckBox, QComboBox, QStyledItemDelegate
from PySide6.QtWebEngineWidgets import QWebEngineView from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QUrl,Qt,QSortFilterProxyModel, qDebug, QSize,QObject,QThread,Signal from PySide6.QtCore import QUrl,Qt,QSortFilterProxyModel, qDebug, QSize,QObject,QThread,Signal,QAbstractTableModel
from PySide6.QtSql import QSqlDatabase, QSqlTableModel, QSqlQueryModel, QSqlQuery from PySide6.QtSql import QSqlDatabase, QSqlTableModel, QSqlQueryModel, QSqlQuery
from PySide6 import QtGui from PySide6 import QtGui
from db import addFineFilter from db import addFineFilter
@ -12,13 +12,33 @@ DBFILE = "../db/sqlite3.db"
Cantons = ["AG","ZH","BE","SG","SO"] Cantons = ["AG","ZH","BE","SG","SO"]
class TableModel(QAbstractTableModel): class ColorDelegate(QStyledItemDelegate):
def __init__(self, data): currentRow = 0
super(TableModel, self).__init__() starred = 0
self._data = data def initStyleOption(self,option,index):
def data(self, index, role): super().initStyleOption(option,index)
if role == Qt.BackgroundRole: data = index.data()
return QtGui.QColor('#9C0006')
try:
value = float(data)
except:
print("error not an integer")
else:
print("data:",data)
self.currentRow = index.row()
print("row: ",self.currentRow)
if value == 1:
self.starred = 1
#option.backgroundBrush = QtGui.QColor("green")
else:
self.starred = 0
#option.backgroundBrush = QtGui.QColor("grey")
if self.starred == 1:
option.backgroundBrush = QtGui.QColor("red")
else:
option.backgroundBrush = QtGui.QColor("white")
class ValidationWorker(QObject): class ValidationWorker(QObject):
finished = Signal() finished = Signal()
@ -70,6 +90,10 @@ class MainWindow(QMainWindow):
self.view = QTableView() self.view = QTableView()
self.view.setModel(self.model) self.view.setModel(self.model)
delegate = ColorDelegate(self.view)
self.view.setItemDelegate(delegate)
self.setProxyViewSettings() self.setProxyViewSettings()
self.view.clicked.connect(self.cell_clicked) self.view.clicked.connect(self.cell_clicked)
@ -193,8 +217,8 @@ class MainWindow(QMainWindow):
self.model.setTable("") self.model.setTable("")
self.model.setQuery(cmd +" ;") self.model.setQuery(cmd +" ;")
self.proxymodel2 = QSortFilterProxyModel(self) #self.proxymodel2 = QSortFilterProxyModel(self)
self.proxymodel2.setSourceModel(self.model) #self.proxymodel2.setSourceModel(self.model)
self.view.setModel(self.proxymodel2) self.view.setModel(self.proxymodel2)
self.setProxyViewSettings() self.setProxyViewSettings()
class PWPrompt(QDialog): class PWPrompt(QDialog):