I dunno something with colors
This commit is contained in:
parent
2901badfe5
commit
5c580adf7f
13
lib/gui.py
13
lib/gui.py
@ -22,11 +22,12 @@ class ColorDelegate(QStyledItemDelegate):
|
|||||||
try:
|
try:
|
||||||
value = float(data)
|
value = float(data)
|
||||||
except:
|
except:
|
||||||
print("error not an integer")
|
pass
|
||||||
|
#print("error not an integer")
|
||||||
else:
|
else:
|
||||||
print("data:",data)
|
#print("data:",data)
|
||||||
self.currentRow = index.row()
|
self.currentRow = index.row()
|
||||||
print("row: ",self.currentRow)
|
#print("row: ",self.currentRow)
|
||||||
if value == 1:
|
if value == 1:
|
||||||
self.starred = 1
|
self.starred = 1
|
||||||
#option.backgroundBrush = QtGui.QColor("green")
|
#option.backgroundBrush = QtGui.QColor("green")
|
||||||
@ -86,6 +87,7 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
self.model = QSqlTableModel(self)
|
self.model = QSqlTableModel(self)
|
||||||
self.model.setTable("jobs")
|
self.model.setTable("jobs")
|
||||||
|
self.model.setEditStrategy(QSqlTableModel.OnFieldChange)
|
||||||
self.model.select()
|
self.model.select()
|
||||||
|
|
||||||
self.view = QTableView()
|
self.view = QTableView()
|
||||||
@ -121,7 +123,7 @@ class MainWindow(QMainWindow):
|
|||||||
self.view.setColumnWidth(5,10)
|
self.view.setColumnWidth(5,10)
|
||||||
self.view.hideColumn(7)
|
self.view.hideColumn(7)
|
||||||
self.view.setSortingEnabled(True)
|
self.view.setSortingEnabled(True)
|
||||||
self.view.clicked.connect(self.cell_clicked)
|
|
||||||
def runWorker(self):
|
def runWorker(self):
|
||||||
self.thread = QThread()
|
self.thread = QThread()
|
||||||
self.worker = Worker()
|
self.worker = Worker()
|
||||||
@ -216,10 +218,11 @@ class MainWindow(QMainWindow):
|
|||||||
print("Run SQL Query",cmd)
|
print("Run SQL Query",cmd)
|
||||||
self.model.setTable("")
|
self.model.setTable("")
|
||||||
self.model.setQuery(cmd +" ;")
|
self.model.setQuery(cmd +" ;")
|
||||||
|
#self.model.setTable("jobs")
|
||||||
|
|
||||||
#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.model)
|
||||||
self.setProxyViewSettings()
|
self.setProxyViewSettings()
|
||||||
class PWPrompt(QDialog):
|
class PWPrompt(QDialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
38
lib/qsqlmod.py
Normal file
38
lib/qsqlmod.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#modifie the QSqlQueryModel to be editable and sets them to the database
|
||||||
|
|
||||||
|
#credits to :
|
||||||
|
#https://stackoverflow.com/questions/49752388/editable-qtableview-of-complex-sql-query
|
||||||
|
|
||||||
|
|
||||||
|
class SqlQueryModel_editable(QSqlQueryModel):
|
||||||
|
"""a subclass of QSqlQueryModel where individual columns can be defined as editable
|
||||||
|
"""
|
||||||
|
def __init__(self, editables):
|
||||||
|
"""editables should be a dict of format:
|
||||||
|
{INT editable_column_nr : (STR update query to be performed when changes are made on this column
|
||||||
|
INT model's column number for the filter-column (used in the where-clause),
|
||||||
|
)}
|
||||||
|
"""
|
||||||
|
super().__init__()
|
||||||
|
self.editables = editables
|
||||||
|
|
||||||
|
def flags(self, index):
|
||||||
|
fl = QSqlQueryModel.flags(self, index)
|
||||||
|
if index.column() in self.editables:
|
||||||
|
fl |= Qt.ItemIsEditable
|
||||||
|
return fl
|
||||||
|
|
||||||
|
def setData(self, index, value, role=Qt.EditRole):
|
||||||
|
if role == Qt.EditRole:
|
||||||
|
mycolumn = index.column()
|
||||||
|
if mycolumn in self.editables:
|
||||||
|
(query, filter_col) = self.editables[mycolumn]
|
||||||
|
filter_value = self.index(index.row(), filter_col).data()
|
||||||
|
q = QSqlQuery(query.format(value, filter_value))
|
||||||
|
result = q.exec_()
|
||||||
|
if result:
|
||||||
|
self.query().exec_()
|
||||||
|
else:
|
||||||
|
print(self.query().lastError().text())
|
||||||
|
return result
|
||||||
|
return QSqlQueryModel.setData(self, index, value, role)
|
Loading…
Reference in New Issue
Block a user