Danis plugin ;) ;D 0_0
This commit is contained in:
@@ -25,7 +25,8 @@ Item {
|
|||||||
//width: icon.width
|
//width: icon.width
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
flat: true
|
flat: true
|
||||||
onClicked: appLoader.source = "AddCustomer.qml"
|
// onClicked: appLoader.source = "AddCustomer.qml"
|
||||||
|
onClicked: bm.setVisibleColumns(["gecos", "userid"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,18 +12,43 @@ CUSTOMER_COLUMN_NAMES = \
|
|||||||
"gecos": "Information"
|
"gecos": "Information"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CUSTOMER_COLUMN_INDEX = \
|
||||||
|
{
|
||||||
|
"userid": 0,
|
||||||
|
"username": 1,
|
||||||
|
"password": 2,
|
||||||
|
"enabled": 3,
|
||||||
|
"roleid": 4,
|
||||||
|
"gecos": 5
|
||||||
|
}
|
||||||
|
|
||||||
|
CUSTOMER_COLUMN = \
|
||||||
|
{
|
||||||
|
0: "userid",
|
||||||
|
1: "username",
|
||||||
|
2: "password",
|
||||||
|
3: "enabled",
|
||||||
|
4: "roleid",
|
||||||
|
5: "gecos"
|
||||||
|
}
|
||||||
|
|
||||||
class BusinessModel(QAbstractTableModel):
|
class BusinessModel(QAbstractTableModel):
|
||||||
|
__visible_index = {}
|
||||||
|
__col_name = ""
|
||||||
|
|
||||||
def __init__(self, con, cols):
|
def __init__(self, con, cols):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.__con = con
|
self.__con = con
|
||||||
self.__visible_columns = cols
|
self.__visible_columns = cols
|
||||||
self.__data = self.__getData()
|
self.__data = self.__getData()
|
||||||
|
for col in cols:
|
||||||
|
self.__visible_index[col] = CUSTOMER_COLUMN_INDEX[col]
|
||||||
|
|
||||||
def __getData(self):
|
def __getData(self):
|
||||||
cursor = self.__con.cursor()
|
cursor = self.__con.cursor()
|
||||||
cursor.execute("SELECT * FROM users")
|
cursor.execute("SELECT * FROM users")
|
||||||
self.__all_cols = [desc[0] for desc in cursor.description]
|
self.__all_cols = [desc[0] for desc in cursor.description]
|
||||||
|
#print(self.__all_cols)
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
@@ -35,21 +60,28 @@ class BusinessModel(QAbstractTableModel):
|
|||||||
|
|
||||||
def data(self, index, role= Qt.DisplayRole):
|
def data(self, index, role= Qt.DisplayRole):
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
# row = index.row()
|
|
||||||
row = self.__data[index.row()]
|
row = self.__data[index.row()]
|
||||||
col_name = self.__visible_columns[index.column()]
|
self.__col_name = self.__visible_columns[index.column()]
|
||||||
col_index = self.__all_cols.index(col_name)
|
col_index = self.__visible_index[self.__col_name]
|
||||||
return row[col_index]
|
return row[col_index]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def headerData(self, section, orientation, role= Qt.DisplayRole):
|
def headerData(self, section, orientation, role= Qt.DisplayRole):
|
||||||
#header= ["ID", "Benutzername", "Passwort", "Information", "Rolle", "Aktiv"]
|
|
||||||
if orientation == Qt.Horizontal and role ==Qt.DisplayRole:
|
if orientation == Qt.Horizontal and role ==Qt.DisplayRole:
|
||||||
#return header[section]
|
self.__col_name = self.__visible_columns[section]
|
||||||
col_name = self.__visible_columns[section]
|
return CUSTOMER_COLUMN_NAMES.get(self.__col_name, self.__col_name)
|
||||||
return CUSTOMER_COLUMN_NAMES.get(col_name, col_name)
|
|
||||||
return super().headerData(section, orientation, role)
|
return super().headerData(section, orientation, role)
|
||||||
#return None
|
|
||||||
|
@Slot(dict)
|
||||||
|
def setVisibleColumns(self, cols):
|
||||||
|
self.__visible_columns.clear()
|
||||||
|
self.__visible_index.clear()
|
||||||
|
for col, val in cols.items():
|
||||||
|
self.__visible_index[val] = CUSTOMER_COLUMN_INDEX[cols[col]]
|
||||||
|
self.__visible_columns.append(cols[col])
|
||||||
|
# self.headerDataChanged.emit()
|
||||||
|
# self.dataChanged.emit()
|
||||||
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
def onRowClicked(self, row):
|
def onRowClicked(self, row):
|
||||||
|
|||||||
Reference in New Issue
Block a user