This commit is contained in:
zhuzichu 2024-01-29 11:11:38 +08:00
parent 3933026de3
commit 190b14eed6
2 changed files with 37 additions and 13 deletions

View File

@ -9,6 +9,7 @@ Rectangle {
property var dataSource property var dataSource
property color borderColor: FluTheme.dark ? "#252525" : "#e4e4e4" property color borderColor: FluTheme.dark ? "#252525" : "#e4e4e4"
property alias tableModel: table_model property alias tableModel: table_model
property alias tableView: table_view
property bool horizonalHeaderVisible: true property bool horizonalHeaderVisible: true
property bool verticalHeaderVisible: true property bool verticalHeaderVisible: true
id:control id:control
@ -30,7 +31,7 @@ Rectangle {
} }
QtObject{ QtObject{
id:d id:d
property var currentRow property var currentIndex
property int rowHoverIndex: -1 property int rowHoverIndex: -1
property int defaultItemWidth: 100 property int defaultItemWidth: 100
property int defaultItemHeight: 42 property int defaultItemHeight: 42
@ -66,6 +67,16 @@ Rectangle {
} }
TableModel { TableModel {
id:table_model id:table_model
onRowCountChanged: {
timer_table_force_layout.restart()
}
}
Timer{
id:timer_table_force_layout
interval: 50
onTriggered: {
table_view.flick(0,1)
}
} }
Component{ Component{
id:com_edit id:com_edit
@ -260,8 +271,9 @@ Rectangle {
id:item_table id:item_table
anchors.fill: parent anchors.fill: parent
property point position: Qt.point(column,row) property point position: Qt.point(column,row)
property bool isRowSelected: d.currentIndex === table_model.getRow(row).__index
color:{ color:{
if(d.rowHoverIndex === row || d.currentRow === table_model.getRow(row).__index){ if(d.rowHoverIndex === row || item_table.isRowSelected){
return FluTheme.dark ? Qt.rgba(1,1,1,0.06) : Qt.rgba(0,0,0,0.06) return FluTheme.dark ? Qt.rgba(1,1,1,0.06) : Qt.rgba(0,0,0,0.06)
} }
return (row%2!==0) ? control.color : (FluTheme.dark ? Qt.rgba(1,1,1,0.015) : Qt.rgba(0,0,0,0.015)) return (row%2!==0) ? control.color : (FluTheme.dark ? Qt.rgba(1,1,1,0.015) : Qt.rgba(0,0,0,0.015))
@ -271,7 +283,7 @@ Rectangle {
radius: 1.5 radius: 1.5
color: FluTheme.primaryColor color: FluTheme.primaryColor
width: 3 width: 3
visible: d.currentRow === table_model.getRow(row).__index && column === 0 visible: item_table.isRowSelected && column === 0
anchors{ anchors{
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
left: parent.left left: parent.left
@ -296,7 +308,7 @@ Rectangle {
} }
onClicked: onClicked:
(event)=>{ (event)=>{
d.currentRow = table_model.getRow(row).__index d.currentIndex = table_model.getRow(row).__index
item_loader.sourceComponent = undefined item_loader.sourceComponent = undefined
event.accepted = true event.accepted = true
} }
@ -535,11 +547,11 @@ Rectangle {
} }
} }
onContentYChanged:{ onContentYChanged:{
timer_force_layout.restart() timer_vertical_force_layout.restart()
} }
Timer{ Timer{
id:timer_vertical_force_layout
interval: 50 interval: 50
id:timer_force_layout
onTriggered: { onTriggered: {
header_vertical.forceLayout() header_vertical.forceLayout()
} }

View File

@ -10,6 +10,7 @@ Rectangle {
property var dataSource property var dataSource
property color borderColor: FluTheme.dark ? "#252525" : "#e4e4e4" property color borderColor: FluTheme.dark ? "#252525" : "#e4e4e4"
property alias tableModel: table_model property alias tableModel: table_model
property alias tableView: table_view
property bool horizonalHeaderVisible: true property bool horizonalHeaderVisible: true
property bool verticalHeaderVisible: true property bool verticalHeaderVisible: true
id:control id:control
@ -19,7 +20,7 @@ Rectangle {
var columns= [] var columns= []
var header_rows = {} var header_rows = {}
columnSource.forEach(function(item){ columnSource.forEach(function(item){
var column = Qt.createQmlObject('import Qt.labs.qmlmodels;TableModelColumn{}',table_model); var column = Qt.createQmlObject('import Qt.labs.qmlmodels 1.0;TableModelColumn{}',table_model);
column.display = item.dataIndex column.display = item.dataIndex
columns.push(column) columns.push(column)
header_rows[item.dataIndex] = item.title header_rows[item.dataIndex] = item.title
@ -31,7 +32,7 @@ Rectangle {
} }
QtObject{ QtObject{
id:d id:d
property var currentRow property var currentIndex
property int rowHoverIndex: -1 property int rowHoverIndex: -1
property int defaultItemWidth: 100 property int defaultItemWidth: 100
property int defaultItemHeight: 42 property int defaultItemHeight: 42
@ -67,6 +68,16 @@ Rectangle {
} }
TableModel { TableModel {
id:table_model id:table_model
onRowCountChanged: {
timer_table_force_layout.restart()
}
}
Timer{
id:timer_table_force_layout
interval: 50
onTriggered: {
table_view.flick(0,1)
}
} }
Component{ Component{
id:com_edit id:com_edit
@ -261,8 +272,9 @@ Rectangle {
id:item_table id:item_table
anchors.fill: parent anchors.fill: parent
property point position: Qt.point(column,row) property point position: Qt.point(column,row)
property bool isRowSelected: d.currentIndex === table_model.getRow(row).__index
color:{ color:{
if(d.rowHoverIndex === row || d.currentRow === table_model.getRow(row).__index){ if(d.rowHoverIndex === row || item_table.isRowSelected){
return FluTheme.dark ? Qt.rgba(1,1,1,0.06) : Qt.rgba(0,0,0,0.06) return FluTheme.dark ? Qt.rgba(1,1,1,0.06) : Qt.rgba(0,0,0,0.06)
} }
return (row%2!==0) ? control.color : (FluTheme.dark ? Qt.rgba(1,1,1,0.015) : Qt.rgba(0,0,0,0.015)) return (row%2!==0) ? control.color : (FluTheme.dark ? Qt.rgba(1,1,1,0.015) : Qt.rgba(0,0,0,0.015))
@ -272,7 +284,7 @@ Rectangle {
radius: 1.5 radius: 1.5
color: FluTheme.primaryColor color: FluTheme.primaryColor
width: 3 width: 3
visible: d.currentRow === table_model.getRow(row).__index && column === 0 visible: item_table.isRowSelected && column === 0
anchors{ anchors{
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
left: parent.left left: parent.left
@ -297,7 +309,7 @@ Rectangle {
} }
onClicked: onClicked:
(event)=>{ (event)=>{
d.currentRow = table_model.getRow(row).__index d.currentIndex = table_model.getRow(row).__index
item_loader.sourceComponent = undefined item_loader.sourceComponent = undefined
event.accepted = true event.accepted = true
} }
@ -536,11 +548,11 @@ Rectangle {
} }
} }
onContentYChanged:{ onContentYChanged:{
timer_force_layout.restart() timer_vertical_force_layout.restart()
} }
Timer{ Timer{
id:timer_vertical_force_layout
interval: 50 interval: 50
id:timer_force_layout
onTriggered: { onTriggered: {
header_vertical.forceLayout() header_vertical.forceLayout()
} }