| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- import QtQuick
- import QtQuick.Controls
- import QtQuick.Layouts
- import FluentUI
- Item {
- property var columns : []
- property var dataSource : []
- property int pageCurrent: 1
- property int itemCount: 1000
- property int pageCount: 10
- property int itemHeight: 56
- signal requestPage(int page,int count)
- id:control
- implicitHeight: layout_table.height
- QtObject{
- id:d
- property int coumnsWidth: parent.width
- }
- MouseArea{
- anchors.fill: parent
- preventStealing: true
- }
- ListModel{
- id:model_coumns
- }
- ListModel{
- id:model_data_source
- }
- onColumnsChanged: {
- model_coumns.clear()
- model_coumns.append(columns)
- var w = 0
- for(var i=0;i<model_coumns.count;i++){
- var item = model_coumns.get(i)
- w=w+item.width
- }
- d.coumnsWidth = w
- }
- onDataSourceChanged: {
- model_data_source.clear()
- model_data_source.append(dataSource)
- }
- Flickable{
- id:layout_flickable
- height: layout_table.height
- anchors{
- top: parent.top
- left: parent.left
- right: parent.right
- }
- contentWidth: layout_table.width
- ScrollBar.horizontal: FluScrollBar {
- }
- Rectangle{
- anchors.fill: layout_table
- radius: 5
- color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1)
- }
- ListView{
- id:layout_table
- height: contentHeight
- width: Math.max(layout_flickable.width,d.coumnsWidth)
- clip:true
- interactive: false
- header: FluRectangle{
- id:layout_coumns
- height: control.itemHeight
- width: parent.width
- color:FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1)
- radius: [5,5,0,0]
- Row{
- id:list_coumns
- spacing: 0
- anchors.fill: parent
- Repeater{
- model: model_coumns
- delegate: Item{
- height: list_coumns.height
- width: model.width
- FluText{
- text:model.title
- wrapMode: Text.WordWrap
- anchors{
- verticalCenter: parent.verticalCenter
- left: parent.left
- leftMargin: 14
- }
- fontStyle: FluText.BodyStrong
- }
- FluDivider{
- width: 1
- height: 40
- anchors.right: parent.right
- anchors.verticalCenter: parent.verticalCenter
- visible: index !== list_coumns.count-1
- }
- }
- }
- }
- }
- footer: Item{
- height: 50
- width: layout_table.width
- FluPagination{
- id:pagination
- height: 40
- pageCurrent: control.pageCurrent
- itemCount: control.itemCount
- pageCount: control.pageCount
- onRequestPage:
- (page,count)=> {
- control.requestPage(page,count)
- }
- anchors{
- top: parent.top
- right: parent.right
- }
- }
- }
- model:model_data_source
- delegate: Item{
- height: table_row.maxHeight
- width: layout_table.width
- property var model_values : getObjectValues(index)
- property var itemObject: getObject(index)
- property var listModel: model
- Row{
- id: table_row
- spacing: 0
- anchors.fill: parent
- property int maxHeight: itemHeight
- Repeater{
- model: model_values
- delegate:Item{
- height: table_row.maxHeight
- width: modelData.width
- Loader{
- property var model : modelData
- property var dataModel : listModel
- property var dataObject : itemObject
- anchors.fill: parent
- sourceComponent: {
- if(model.itemData instanceof Component){
- return model.itemData
- }
- return com_text
- }
- onHeightChanged:
- {
- table_row.maxHeight = Math.max(table_row.maxHeight,height,itemHeight)
- parent.height = table_row.maxHeight
- table_row.parent.height = table_row.maxHeight
- }
- }
- }
- }
- }
- FluDivider{
- width: parent.width
- height: 1
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- }
- }
- }
- }
- Component{
- id:com_text
- Item{
- MouseArea{
- id:item_mouse
- hoverEnabled: true
- anchors.fill: parent
- }
- FluText{
- id:table_value
- text:String(model.itemData)
- width: parent.width - 14
- wrapMode: Text.WordWrap
- onImplicitHeightChanged: parent.parent.parent.height = Math.max(implicitHeight + 20,itemHeight)
- anchors{
- verticalCenter: parent.verticalCenter
- left: parent.left
- leftMargin: 14
- }
- FluTooltip{
- visible: item_mouse.containsMouse
- text:parent.text
- delay: 1000
- }
- }
- }
- }
- function getObject(index){
- return model_data_source.get(index)
- }
- function getObjectValues(index) {
- var obj = model_data_source.get(index)
- if(!obj)
- return
- var data = []
- for(var i=0;i<model_coumns.count;i++){
- var item = model_coumns.get(i)
- data.push({itemData:obj[item.dataIndex],width:item.width})
- }
- return data;
- }
- }
|