import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQmlTricks 1.0
import "qrc:/import/QtQmlTricks/" as QmlTricks
TableView {
// model: must be bound to an external model, which has to be properly filled before TableView is created
model: mainWindow.mainWindowTableModel
id: dynamicTableViewBasis
property var tableModel: dynamicTableViewBasis.model
signal clickedEntry(var id, string role, var value)
width: parent ? parent.width : 0
resources:
{
var roleList = dynamicTableViewBasis.tableModel.userRoleNames
var temp = []
for(var i=0; i<roleList.length; i++)
{
var role = roleList[i]
if (!dynamicTableViewBasis.tableModel.isColumnHidden(role)) {
var columnHeaderName = dynamicTableViewBasis.tableModel.columnHeaderName(role)
if (columnHeaderName === "") {
columnHeaderName = role
}
if (dynamicTableViewBasis.tableModel.columnTypeName(role) == "bool") {
temp.push(columnComponentBool.createObject(dynamicTableViewBasis, { "role": role, "title": columnHeaderName, "width": dynamicTableViewBasis.tableModel.columnInitialWidth(role)}))
} else {
temp.push(columnComponentText.createObject(dynamicTableViewBasis, { "role": role, "title": columnHeaderName, "width": dynamicTableViewBasis.tableModel.columnInitialWidth(role)}))
}
}
}
return temp
}
Component {
id: columnComponentText
TableViewColumn {
delegate: Text {
id: textDelegate
text: styleData.value ? styleData.value : ""
color: styleData.textColor ? styleData.textColor : ""
elide: styleData.elideMode ? styleData.elideMode : ""
MouseArea {
anchors.fill: parent
onClicked: {
var id = dynamicTableViewBasis.tableModel.data(dynamicTableViewBasis.tableModel.index(styleData.row,0),dynamicTableViewBasis.tableModel.roleForName("myId"))
var role = dynamicTableViewBasis.getColumn(styleData.column).role
var value = styleData.value
dynamicTableViewBasis.clickedEntry(id, role, value)
}
}
}
}
}
Component {
id: columnComponentBool
TableViewColumn {
delegate: CheckBox {
id: checkBoxDelegate
text: ""
checked: styleData.value ? styleData.value : undefined
onClicked: {
var id = dynamicTableViewBasis.tableModel.data(dynamicTableViewBasis.tableModel.index(styleData.row,0),dynamicTableViewBasis.tableModel.roleForName("myId"))
var role = dynamicTableViewBasis.getColumn(styleData.column).role
var value = checkBoxDelegate.checked
dynamicTableViewBasis.clickedEntry(id, role, value)
}
}
}
}
}
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQmlTricks 1.0
import "qrc:/import/QtQmlTricks/" as QmlTricks
TableView {
// model: must be bound to an external model, which has to be properly filled before TableView is created
model: mainWindow.mainWindowTableModel
id: dynamicTableViewBasis
property var tableModel: dynamicTableViewBasis.model
signal clickedEntry(var id, string role, var value)
width: parent ? parent.width : 0
resources:
{
var roleList = dynamicTableViewBasis.tableModel.userRoleNames
var temp = []
for(var i=0; i<roleList.length; i++)
{
var role = roleList[i]
if (!dynamicTableViewBasis.tableModel.isColumnHidden(role)) {
var columnHeaderName = dynamicTableViewBasis.tableModel.columnHeaderName(role)
if (columnHeaderName === "") {
columnHeaderName = role
}
if (dynamicTableViewBasis.tableModel.columnTypeName(role) == "bool") {
temp.push(columnComponentBool.createObject(dynamicTableViewBasis, { "role": role, "title": columnHeaderName, "width": dynamicTableViewBasis.tableModel.columnInitialWidth(role)}))
} else {
temp.push(columnComponentText.createObject(dynamicTableViewBasis, { "role": role, "title": columnHeaderName, "width": dynamicTableViewBasis.tableModel.columnInitialWidth(role)}))
}
}
}
return temp
}
Component {
id: columnComponentText
TableViewColumn {
delegate: Text {
id: textDelegate
text: styleData.value ? styleData.value : ""
color: styleData.textColor ? styleData.textColor : ""
elide: styleData.elideMode ? styleData.elideMode : ""
MouseArea {
anchors.fill: parent
onClicked: {
var id = dynamicTableViewBasis.tableModel.data(dynamicTableViewBasis.tableModel.index(styleData.row,0),dynamicTableViewBasis.tableModel.roleForName("myId"))
var role = dynamicTableViewBasis.getColumn(styleData.column).role
var value = styleData.value
dynamicTableViewBasis.clickedEntry(id, role, value)
}
}
}
}
}
Component {
id: columnComponentBool
TableViewColumn {
delegate: CheckBox {
id: checkBoxDelegate
text: ""
checked: styleData.value ? styleData.value : undefined
onClicked: {
var id = dynamicTableViewBasis.tableModel.data(dynamicTableViewBasis.tableModel.index(styleData.row,0),dynamicTableViewBasis.tableModel.roleForName("myId"))
var role = dynamicTableViewBasis.getColumn(styleData.column).role
var value = checkBoxDelegate.checked
dynamicTableViewBasis.clickedEntry(id, role, value)
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks