This commit is contained in:
朱子楚\zhuzi 2024-03-01 00:19:12 +08:00
parent 38612f0ebc
commit e2d52f55b9
7 changed files with 554 additions and 226 deletions

View File

@ -13,19 +13,44 @@ FluContentPage{
property var dataSource : [] property var dataSource : []
property int sortType: 0 property int sortType: 0
property bool seletedAll: true
Component.onCompleted: { Component.onCompleted: {
loadData(1,1000) loadData(1,1000)
} }
onCheckBoxChanged: {
for(var i =0;i< table_view.rows ;i++){
if(false === table_view.getRow(i).checkbox.options.checked){
root.seletedAll = false
return
}
}
root.seletedAll = true
}
onSortTypeChanged: { onSortTypeChanged: {
table_view.closeEditor() table_view.closeEditor()
if(sortType === 0){ if(sortType === 0){
table_view.sort() table_view.sort()
}else if(sortType === 1){ }else if(sortType === 1){
table_view.sort((a, b) => a.age - b.age); table_view.sort((l, r) =>{
var lage = Number(l.age)
var rage = Number(r.age)
if(lage === rage){
return l._key>r._key
}
return lage>rage
});
}else if(sortType === 2){ }else if(sortType === 2){
table_view.sort((a, b) => b.age - a.age); table_view.sort((l, r) => {
var lage = Number(l.age)
var rage = Number(r.age)
if(lage === rage){
return l._key>r._key
}
return lage<rage
});
} }
} }
@ -73,9 +98,9 @@ FluContentPage{
checked: true === options.checked checked: true === options.checked
enableAnimation: false enableAnimation: false
clickListener: function(){ clickListener: function(){
var obj = tableModel.getRow(row) var obj = table_view.getRow(row)
obj.checkbox = table_view.customItem(com_checbox,{checked:!options.checked}) obj.checkbox = table_view.customItem(com_checbox,{checked:!options.checked})
tableModel.setRow(row,obj) table_view.setRow(row,obj)
checkBoxChanged() checkBoxChanged()
} }
} }
@ -91,17 +116,16 @@ FluContentPage{
text:"删除" text:"删除"
onClicked: { onClicked: {
table_view.closeEditor() table_view.closeEditor()
tableModel.removeRow(row) table_view.removeRow(row)
checkBoxChanged()
} }
} }
FluFilledButton{ FluFilledButton{
text:"编辑" text:"编辑"
onClicked: { onClicked: {
var obj = tableModel.getRow(row) var obj = table_view.getRow(row)
obj.name = "12345" obj.name = "12345"
tableModel.setRow(row,obj) table_view.setRow(row,obj)
showSuccess(JSON.stringify(tableModel.getRow(row))) showSuccess(JSON.stringify(obj))
} }
} }
} }
@ -119,31 +143,20 @@ FluContentPage{
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
} }
FluCheckBox{ FluCheckBox{
checked: true === options.checked checked: true === root.seletedAll
enableAnimation: false enableAnimation: false
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
clickListener: function(){ clickListener: function(){
var checked = !options.checked root.seletedAll = !root.seletedAll
var checked = root.seletedAll
itemModel.display = table_view.customItem(com_column_checbox,{"checked":checked}) itemModel.display = table_view.customItem(com_column_checbox,{"checked":checked})
for(var i =0;i< tableModel.rowCount ;i++){ for(var i =0;i< table_view.rows ;i++){
var rowData = tableModel.getRow(i) var rowData = table_view.getRow(i)
rowData.checkbox = table_view.customItem(com_checbox,{"checked":checked}) rowData.checkbox = table_view.customItem(com_checbox,{"checked":checked})
tableModel.setRow(i,rowData) table_view.setRow(i,rowData)
} }
} }
} }
Connections{
target: root
function onCheckBoxChanged(){
for(var i =0;i< tableModel.rowCount ;i++){
if(false === tableModel.getRow(i).checkbox.options.checked){
itemModel.display = table_view.customItem(com_column_checbox,{"checked":false})
return
}
}
itemModel.display = table_view.customItem(com_column_checbox,{"checked":true})
}
}
} }
} }
} }
@ -166,7 +179,7 @@ FluContentPage{
selectAll() selectAll()
} }
onCommit: { onCommit: {
display = editText editTextChaged(editText)
tableView.closeEditor() tableView.closeEditor()
} }
} }
@ -282,15 +295,67 @@ FluContentPage{
} }
} }
FluArea{
id:layout_controls
anchors{
left: parent.left
right: parent.right
top: parent.top
topMargin: 20
}
height: 60
Row{
spacing: 5
anchors{
left: parent.left
leftMargin: 10
verticalCenter: parent.verticalCenter
}
FluButton{
text:"清空"
onClicked: {
table_view.dataSource = []
}
}
FluButton{
text:"删除选中"
onClicked: {
var data = []
for(var i =0;i< table_view.rows ;i++){
var item = table_view.getRow(i)
if(false === item.checkbox.options.checked){
data.push(item)
}
}
table_view.dataSource = data
}
}
FluButton{
text:"添加一行数据"
onClicked: {
table_view.appendRow(genTestObject())
}
}
}
}
FluTableView{ FluTableView{
id:table_view id:table_view
anchors{ anchors{
left: parent.left left: parent.left
right: parent.right right: parent.right
top: parent.top top: layout_controls.bottom
bottom: gagination.top bottom: gagination.top
} }
anchors.topMargin: 20 anchors.topMargin: 5
onRowsChanged: {
root.checkBoxChanged()
}
columnSource:[ columnSource:[
{ {
title: table_view.customItem(com_column_checbox,{checked:true}), title: table_view.customItem(com_column_checbox,{checked:true}),
@ -366,11 +431,11 @@ FluContentPage{
} }
} }
function loadData(page,count){ function genTestObject(){
var numbers = [100, 300, 500, 1000]; var ages = ["100", "300", "500", "1000"];
function getRandomAge() { function getRandomAge() {
var randomIndex = Math.floor(Math.random() * numbers.length); var randomIndex = Math.floor(Math.random() * ages.length);
return numbers[randomIndex]; return ages[randomIndex];
} }
var names = ["孙悟空", "猪八戒", "沙和尚", "唐僧","白骨夫人","金角大王","熊山君","黄风怪","银角大王"]; var names = ["孙悟空", "猪八戒", "沙和尚", "唐僧","白骨夫人","金角大王","熊山君","黄风怪","银角大王"];
function getRandomName(){ function getRandomName(){
@ -387,26 +452,29 @@ FluContentPage{
var randomIndex = Math.floor(Math.random() * addresses.length); var randomIndex = Math.floor(Math.random() * addresses.length);
return addresses[randomIndex]; return addresses[randomIndex];
} }
var avatars = ["qrc:/example/res/svg/avatar_1.svg", "qrc:/example/res/svg/avatar_2.svg", "qrc:/example/res/svg/avatar_3.svg", "qrc:/example/res/svg/avatar_4.svg","qrc:/example/res/svg/avatar_5.svg","qrc:/example/res/svg/avatar_6.svg","qrc:/example/res/svg/avatar_7.svg","qrc:/example/res/svg/avatar_8.svg","qrc:/example/res/svg/avatar_9.svg","qrc:/example/res/svg/avatar_10.svg","qrc:/example/res/svg/avatar_11.svg","qrc:/example/res/svg/avatar_12.svg"]; var avatars = ["qrc:/example/res/svg/avatar_1.svg", "qrc:/example/res/svg/avatar_2.svg", "qrc:/example/res/svg/avatar_3.svg", "qrc:/example/res/svg/avatar_4.svg","qrc:/example/res/svg/avatar_5.svg","qrc:/example/res/svg/avatar_6.svg","qrc:/example/res/svg/avatar_7.svg","qrc:/example/res/svg/avatar_8.svg","qrc:/example/res/svg/avatar_9.svg","qrc:/example/res/svg/avatar_10.svg","qrc:/example/res/svg/avatar_11.svg","qrc:/example/res/svg/avatar_12.svg"];
function getAvatar(){ function getAvatar(){
var randomIndex = Math.floor(Math.random() * avatars.length); var randomIndex = Math.floor(Math.random() * avatars.length);
return avatars[randomIndex]; return avatars[randomIndex];
} }
return {
checkbox: table_view.customItem(com_checbox,{checked:root.seletedAll}),
avatar:table_view.customItem(com_avatar,{avatar:getAvatar()}),
name: getRandomName(),
age:getRandomAge(),
address: getRandomAddresses(),
nickname: getRandomNickname(),
longstring:"你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好",
action: table_view.customItem(com_action),
_minimumHeight:50,
_key:FluTools.uuid()
}
}
function loadData(page,count){
root.seletedAll = true
const dataSource = [] const dataSource = []
for(var i=0;i<count;i++){ for(var i=0;i<count;i++){
dataSource.push({ dataSource.push(genTestObject())
checkbox: table_view.customItem(com_checbox,{checked:true}),
avatar:table_view.customItem(com_avatar,{avatar:getAvatar()}),
name: getRandomName(),
age:getRandomAge(),
address: getRandomAddresses(),
nickname: getRandomNickname(),
longstring:"你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好",
action: table_view.customItem(com_action),
minimumHeight:50
})
} }
root.dataSource = dataSource root.dataSource = dataSource
table_view.dataSource = root.dataSource table_view.dataSource = root.dataSource

View File

@ -13,19 +13,44 @@ FluContentPage{
property var dataSource : [] property var dataSource : []
property int sortType: 0 property int sortType: 0
property bool seletedAll: true
Component.onCompleted: { Component.onCompleted: {
loadData(1,1000) loadData(1,1000)
} }
onCheckBoxChanged: {
for(var i =0;i< table_view.rows ;i++){
if(false === table_view.getRow(i).checkbox.options.checked){
root.seletedAll = false
return
}
}
root.seletedAll = true
}
onSortTypeChanged: { onSortTypeChanged: {
table_view.closeEditor() table_view.closeEditor()
if(sortType === 0){ if(sortType === 0){
table_view.sort() table_view.sort()
}else if(sortType === 1){ }else if(sortType === 1){
table_view.sort((a, b) => a.age - b.age); table_view.sort((l, r) =>{
var lage = Number(l.age)
var rage = Number(r.age)
if(lage === rage){
return l._key>r._key
}
return lage>rage
});
}else if(sortType === 2){ }else if(sortType === 2){
table_view.sort((a, b) => b.age - a.age); table_view.sort((l, r) => {
var lage = Number(l.age)
var rage = Number(r.age)
if(lage === rage){
return l._key>r._key
}
return lage<rage
});
} }
} }
@ -73,9 +98,9 @@ FluContentPage{
checked: true === options.checked checked: true === options.checked
enableAnimation: false enableAnimation: false
clickListener: function(){ clickListener: function(){
var obj = tableModel.getRow(row) var obj = table_view.getRow(row)
obj.checkbox = table_view.customItem(com_checbox,{checked:!options.checked}) obj.checkbox = table_view.customItem(com_checbox,{checked:!options.checked})
tableModel.setRow(row,obj) table_view.setRow(row,obj)
checkBoxChanged() checkBoxChanged()
} }
} }
@ -91,17 +116,16 @@ FluContentPage{
text:"删除" text:"删除"
onClicked: { onClicked: {
table_view.closeEditor() table_view.closeEditor()
tableModel.removeRow(row) table_view.removeRow(row)
checkBoxChanged()
} }
} }
FluFilledButton{ FluFilledButton{
text:"编辑" text:"编辑"
onClicked: { onClicked: {
var obj = tableModel.getRow(row) var obj = table_view.getRow(row)
obj.name = "12345" obj.name = "12345"
tableModel.setRow(row,obj) table_view.setRow(row,obj)
showSuccess(JSON.stringify(tableModel.getRow(row))) showSuccess(JSON.stringify(obj))
} }
} }
} }
@ -119,31 +143,20 @@ FluContentPage{
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
} }
FluCheckBox{ FluCheckBox{
checked: true === options.checked checked: true === root.seletedAll
enableAnimation: false enableAnimation: false
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
clickListener: function(){ clickListener: function(){
var checked = !options.checked root.seletedAll = !root.seletedAll
var checked = root.seletedAll
itemModel.display = table_view.customItem(com_column_checbox,{"checked":checked}) itemModel.display = table_view.customItem(com_column_checbox,{"checked":checked})
for(var i =0;i< tableModel.rowCount ;i++){ for(var i =0;i< table_view.rows ;i++){
var rowData = tableModel.getRow(i) var rowData = table_view.getRow(i)
rowData.checkbox = table_view.customItem(com_checbox,{"checked":checked}) rowData.checkbox = table_view.customItem(com_checbox,{"checked":checked})
tableModel.setRow(i,rowData) table_view.setRow(i,rowData)
} }
} }
} }
Connections{
target: root
function onCheckBoxChanged(){
for(var i =0;i< tableModel.rowCount ;i++){
if(false === tableModel.getRow(i).checkbox.options.checked){
itemModel.display = table_view.customItem(com_column_checbox,{"checked":false})
return
}
}
itemModel.display = table_view.customItem(com_column_checbox,{"checked":true})
}
}
} }
} }
} }
@ -166,7 +179,7 @@ FluContentPage{
selectAll() selectAll()
} }
onCommit: { onCommit: {
display = editText editTextChaged(editText)
tableView.closeEditor() tableView.closeEditor()
} }
} }
@ -282,15 +295,67 @@ FluContentPage{
} }
} }
FluArea{
id:layout_controls
anchors{
left: parent.left
right: parent.right
top: parent.top
topMargin: 20
}
height: 60
Row{
spacing: 5
anchors{
left: parent.left
leftMargin: 10
verticalCenter: parent.verticalCenter
}
FluButton{
text:"清空"
onClicked: {
table_view.dataSource = []
}
}
FluButton{
text:"删除选中"
onClicked: {
var data = []
for(var i =0;i< table_view.rows ;i++){
var item = table_view.getRow(i)
if(false === item.checkbox.options.checked){
data.push(item)
}
}
table_view.dataSource = data
}
}
FluButton{
text:"添加一行数据"
onClicked: {
table_view.appendRow(genTestObject())
}
}
}
}
FluTableView{ FluTableView{
id:table_view id:table_view
anchors{ anchors{
left: parent.left left: parent.left
right: parent.right right: parent.right
top: parent.top top: layout_controls.bottom
bottom: gagination.top bottom: gagination.top
} }
anchors.topMargin: 20 anchors.topMargin: 5
onRowsChanged: {
root.checkBoxChanged()
}
columnSource:[ columnSource:[
{ {
title: table_view.customItem(com_column_checbox,{checked:true}), title: table_view.customItem(com_column_checbox,{checked:true}),
@ -366,11 +431,11 @@ FluContentPage{
} }
} }
function loadData(page,count){ function genTestObject(){
var numbers = [100, 300, 500, 1000]; var ages = ["100", "300", "500", "1000"];
function getRandomAge() { function getRandomAge() {
var randomIndex = Math.floor(Math.random() * numbers.length); var randomIndex = Math.floor(Math.random() * ages.length);
return numbers[randomIndex]; return ages[randomIndex];
} }
var names = ["孙悟空", "猪八戒", "沙和尚", "唐僧","白骨夫人","金角大王","熊山君","黄风怪","银角大王"]; var names = ["孙悟空", "猪八戒", "沙和尚", "唐僧","白骨夫人","金角大王","熊山君","黄风怪","银角大王"];
function getRandomName(){ function getRandomName(){
@ -387,26 +452,29 @@ FluContentPage{
var randomIndex = Math.floor(Math.random() * addresses.length); var randomIndex = Math.floor(Math.random() * addresses.length);
return addresses[randomIndex]; return addresses[randomIndex];
} }
var avatars = ["qrc:/example/res/svg/avatar_1.svg", "qrc:/example/res/svg/avatar_2.svg", "qrc:/example/res/svg/avatar_3.svg", "qrc:/example/res/svg/avatar_4.svg","qrc:/example/res/svg/avatar_5.svg","qrc:/example/res/svg/avatar_6.svg","qrc:/example/res/svg/avatar_7.svg","qrc:/example/res/svg/avatar_8.svg","qrc:/example/res/svg/avatar_9.svg","qrc:/example/res/svg/avatar_10.svg","qrc:/example/res/svg/avatar_11.svg","qrc:/example/res/svg/avatar_12.svg"]; var avatars = ["qrc:/example/res/svg/avatar_1.svg", "qrc:/example/res/svg/avatar_2.svg", "qrc:/example/res/svg/avatar_3.svg", "qrc:/example/res/svg/avatar_4.svg","qrc:/example/res/svg/avatar_5.svg","qrc:/example/res/svg/avatar_6.svg","qrc:/example/res/svg/avatar_7.svg","qrc:/example/res/svg/avatar_8.svg","qrc:/example/res/svg/avatar_9.svg","qrc:/example/res/svg/avatar_10.svg","qrc:/example/res/svg/avatar_11.svg","qrc:/example/res/svg/avatar_12.svg"];
function getAvatar(){ function getAvatar(){
var randomIndex = Math.floor(Math.random() * avatars.length); var randomIndex = Math.floor(Math.random() * avatars.length);
return avatars[randomIndex]; return avatars[randomIndex];
} }
return {
checkbox: table_view.customItem(com_checbox,{checked:root.seletedAll}),
avatar:table_view.customItem(com_avatar,{avatar:getAvatar()}),
name: getRandomName(),
age:getRandomAge(),
address: getRandomAddresses(),
nickname: getRandomNickname(),
longstring:"你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好",
action: table_view.customItem(com_action),
_minimumHeight:50,
_key:FluTools.uuid()
}
}
function loadData(page,count){
root.seletedAll = true
const dataSource = [] const dataSource = []
for(var i=0;i<count;i++){ for(var i=0;i<count;i++){
dataSource.push({ dataSource.push(genTestObject())
checkbox: table_view.customItem(com_checbox,{checked:true}),
avatar:table_view.customItem(com_avatar,{avatar:getAvatar()}),
name: getRandomName(),
age:getRandomAge(),
address: getRandomAddresses(),
nickname: getRandomNickname(),
longstring:"你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好",
action: table_view.customItem(com_action),
minimumHeight:50
})
} }
root.dataSource = dataSource root.dataSource = dataSource
table_view.dataSource = root.dataSource table_view.dataSource = root.dataSource

View File

@ -25,7 +25,7 @@ void FluTools::clipText(const QString& text){
} }
QString FluTools::uuid(){ QString FluTools::uuid(){
return QUuid::createUuid().toString(); return QUuid::createUuid().toString().remove('-').remove('{').remove('}');
} }
QString FluTools::readFile(const QString &fileName){ QString FluTools::readFile(const QString &fileName){

View File

@ -17,6 +17,7 @@
#include "FluNetwork.h" #include "FluNetwork.h"
#include "FluFramelessHelper.h" #include "FluFramelessHelper.h"
#include "FluQrCodeItem.h" #include "FluQrCodeItem.h"
#include "FluTableSortProxyModel.h"
void FluentUI::registerTypes(QQmlEngine *engine){ void FluentUI::registerTypes(QQmlEngine *engine){
initializeEngine(engine,uri); initializeEngine(engine,uri);
@ -39,6 +40,7 @@ void FluentUI::registerTypes(const char *uri){
qmlRegisterType<FluNetworkCallable>(uri,major,minor,"FluNetworkCallable"); qmlRegisterType<FluNetworkCallable>(uri,major,minor,"FluNetworkCallable");
qmlRegisterType<FluNetworkParams>(uri,major,minor,"FluNetworkParams"); qmlRegisterType<FluNetworkParams>(uri,major,minor,"FluNetworkParams");
qmlRegisterType<FluFramelessHelper>(uri,major,minor,"FluFramelessHelper"); qmlRegisterType<FluFramelessHelper>(uri,major,minor,"FluFramelessHelper");
qmlRegisterType<FluTableSortProxyModel>(uri,major,minor,"FluTableSortProxyModel");
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/ColorPicker.qml"),uri,major,minor,"ColorPicker"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/ColorPicker.qml"),uri,major,minor,"ColorPicker");
qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/Checkerboard.qml"),uri,major,minor,"Checkerboard"); qmlRegisterType(QUrl("qrc:/qt/qml/FluentUI/Controls/ColorPicker/Content/Checkerboard.qml"),uri,major,minor,"Checkerboard");

View File

@ -8,8 +8,8 @@ Rectangle {
property var columnSource property var columnSource
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 rows: table_view.rows
property alias tableView: table_view property alias columns: table_view.columns
property bool horizonalHeaderVisible: true property bool horizonalHeaderVisible: true
property bool verticalHeaderVisible: true property bool verticalHeaderVisible: true
id:control id:control
@ -31,13 +31,13 @@ Rectangle {
} }
QtObject{ QtObject{
id:d id:d
property var currentIndex property var current
property int rowHoverIndex: -1 property int rowHoverIndex: -1
property int defaultItemWidth: 100 property int defaultItemWidth: 100
property int defaultItemHeight: 42 property int defaultItemHeight: 42
property var header_rows:[] property var header_rows:[]
function obtEditDelegate(column,row,cellItem){ function obtEditDelegate(column,row,display,cellItem){
var display = table_model.data(table_model.index(row,column),"display") var tableModel = table_view.model
var cellPosition = cellItem.mapToItem(scroll_table, 0, 0) var cellPosition = cellItem.mapToItem(scroll_table, 0, 0)
item_loader.column = column item_loader.column = column
item_loader.row = row item_loader.row = row
@ -59,17 +59,15 @@ Rectangle {
} }
onDataSourceChanged: { onDataSourceChanged: {
table_model.clear() table_model.clear()
var rows = [] table_model.rows = dataSource
for(var i =0;i<dataSource.length;i++){
var row = dataSource[i]
row.__index= i
rows.push(row)
}
table_model.rows = rows
} }
TableModel { TableModel {
id:table_model id:table_model
} }
FluTableSortProxyModel{
id:table_sort_model
model: table_model
}
Component{ Component{
id:com_edit id:com_edit
FluTextBox{ FluTextBox{
@ -82,7 +80,7 @@ Rectangle {
} }
onCommit: { onCommit: {
if(!readOnly){ if(!readOnly){
display = text_box.text editTextChaged(text_box.text)
} }
tableView.closeEditor() tableView.closeEditor()
} }
@ -115,7 +113,7 @@ Rectangle {
rightPadding: 24 rightPadding: 24
onCommit: { onCommit: {
if(!readOnly){ if(!readOnly){
display = text editTextChaged(text_box.text)
} }
tableView.closeEditor() tableView.closeEditor()
} }
@ -146,7 +144,7 @@ Rectangle {
id:com_text id:com_text
FluText { FluText {
id:item_text id:item_text
text: modelData text: String(display)
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.WrapAnywhere wrapMode: Text.WrapAnywhere
anchors{ anchors{
@ -220,12 +218,13 @@ Rectangle {
return w return w
} }
rowHeightProvider: function(row) { rowHeightProvider: function(row) {
if(row>=table_model.rowCount){ if(row>=table_view.rows){
return 0 return 0
} }
var h = table_model.getRow(row).height var rowObject = control.getRow(row)
var h = rowObject.height
if(!h){ if(!h){
h = table_model.getRow(row).minimumHeight h = rowObject._minimumHeight
} }
if(!h){ if(!h){
h = d.defaultItemHeight h = d.defaultItemHeight
@ -243,8 +242,12 @@ Rectangle {
} }
model: table_model model: table_model
clip: true clip: true
onRowsChanged: {
closeEditor()
}
delegate: MouseArea{ delegate: MouseArea{
property var rowObject : table_model.getRow(row) property var rowObject : control.getRow(row)
property var itemModel: model
hoverEnabled: true hoverEnabled: true
implicitHeight: 40 implicitHeight: 40
implicitWidth: { implicitWidth: {
@ -264,7 +267,14 @@ 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 === rowObject.__index property bool isRowSelected: {
if(rowObject === null)
return false
if(d.current){
return rowObject._key === d.current._key
}
return false
}
color:{ color:{
if(d.rowHoverIndex === row || item_table.isRowSelected){ 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)
@ -297,23 +307,20 @@ Rectangle {
if(typeof(display) == "object"){ if(typeof(display) == "object"){
return return
} }
item_loader.sourceComponent = d.obtEditDelegate(column,row,item_table) item_loader.sourceComponent = d.obtEditDelegate(column,row,display,item_table)
} }
onClicked: onClicked:
(event)=>{ (event)=>{
d.currentIndex = rowObject.__index d.current = rowObject
item_loader.sourceComponent = undefined item_loader.sourceComponent = undefined
event.accepted = true event.accepted = true
} }
} }
FluLoader{ FluLoader{
property var itemModel: model property var model: itemModel
property var modelData: display property var display: itemModel.display
property var tableView: table_view property int row: item_table.position.y
property var tableModel: table_model property int column: item_table.position.x
property var position: item_table.position
property int row: position.y
property int column: position.x
property var options: { property var options: {
if(typeof(modelData) == "object"){ if(typeof(modelData) == "object"){
return modelData.options return modelData.options
@ -352,13 +359,15 @@ Rectangle {
property int column property int column
property int row property int row
property var tableView: control property var tableView: control
signal editTextChaged(string text)
sourceComponent: undefined sourceComponent: undefined
anchors.fill: parent anchors.fill: parent
onDisplayChanged: { onEditTextChaged:
var obj = table_model.getRow(row) (text)=>{
obj[columnSource[column].dataIndex] = display var obj = control.getRow(row)
table_model.setRow(row,obj) obj[columnSource[column].dataIndex] = text
} control.setRow(row,obj)
}
} }
} }
} }
@ -431,7 +440,7 @@ Rectangle {
height: parent.height height: parent.height
anchors.right: parent.right anchors.right: parent.right
color:"#00000000" color:"#00000000"
visible: column === tableModel.columnCount - 1 visible: column === table_view.columns - 1
} }
MouseArea{ MouseArea{
id:column_item_control_mouse id:column_item_control_mouse
@ -538,7 +547,7 @@ Rectangle {
Connections{ Connections{
target: table_model target: table_model
function onRowCountChanged(){ function onRowCountChanged(){
model_rows.rows = Array.from({length: table_model.rows.length}, (_, i) => ({rowIndex:i+1})); model_rows.rows = Array.from({length: table_model.rows.length}, (_, i) => ({rowIndex:i+1}));
} }
} }
onContentYChanged:{ onContentYChanged:{
@ -555,7 +564,7 @@ Rectangle {
id:item_control id:item_control
readonly property real cellPadding: 8 readonly property real cellPadding: 8
property bool canceled: false property bool canceled: false
property var rowObject: table_model.getRow(row) property var rowObject: control.getRow(row)
implicitWidth: Math.max(30, row_text.implicitWidth + (cellPadding * 2)) implicitWidth: Math.max(30, row_text.implicitWidth + (cellPadding * 2))
implicitHeight: row_text.implicitHeight + (cellPadding * 2) implicitHeight: row_text.implicitHeight + (cellPadding * 2)
width: implicitWidth width: implicitWidth
@ -573,7 +582,7 @@ Rectangle {
width: parent.width width: parent.width
height: 1 height: 1
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
visible: row === tableModel.rowCount - 1 visible: row === table_view.rows - 1
color:"#00000000" color:"#00000000"
} }
Rectangle{ Rectangle{
@ -620,7 +629,11 @@ Rectangle {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
cursorShape: Qt.SplitVCursor cursorShape: Qt.SplitVCursor
visible: !(rowObject.height === rowObject.minimumHeight && rowObject.height === rowObject.maximumHeight && rowObject.height) visible: {
if(rowObject === null)
return false
return !(rowObject.height === rowObject._minimumHeight && rowObject.height === rowObject._maximumHeight && rowObject.height)
}
onPressed : onPressed :
(mouse)=>{ (mouse)=>{
header_vertical.interactive = false header_vertical.interactive = false
@ -640,9 +653,10 @@ Rectangle {
if(!pressed){ if(!pressed){
return return
} }
var rowObject = control.getRow(row)
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y) var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
var minimumHeight = rowObject.minimumHeight var minimumHeight = rowObject._minimumHeight
var maximumHeight = rowObject.maximumHeight var maximumHeight = rowObject._maximumHeight
var h = rowObject.height var h = rowObject.height
if(!h){ if(!h){
h = d.defaultItemHeight h = d.defaultItemHeight
@ -654,7 +668,7 @@ Rectangle {
maximumHeight = 65535 maximumHeight = 65535
} }
rowObject.height = Math.min(Math.max(minimumHeight, h + delta.y),maximumHeight) rowObject.height = Math.min(Math.max(minimumHeight, h + delta.y),maximumHeight)
table_model.setRow(row,rowObject) control.setRow(row,rowObject)
table_view.forceLayout() table_view.forceLayout()
} }
} }
@ -673,21 +687,33 @@ Rectangle {
o.options = options o.options = options
return o return o
} }
function updateRow(row,obj){
table_model.setRow(row,obj)
}
function sort(order){ function sort(order){
let sortedArray = []
for(var i =0;i<table_model.rowCount;i++){
let row = table_model.getRow(i)
sortedArray.push(row)
}
if(order === undefined){ if(order === undefined){
sortedArray.sort((a, b) => a.__index - b.__index) table_view.model = table_model
}else{ }else{
sortedArray.sort(order) table_view.model = table_sort_model
table_sort_model.setSortComparator(function(left,right){
return order(table_model.getRow(left),table_model.getRow(right))
})
} }
table_model.clear() }
table_model.rows = sortedArray function setRow(rowIndex,obj){
if(rowIndex>=0 && rowIndex<table_view.rows){
table_view.model.setRow(rowIndex,obj)
}
}
function getRow(rowIndex){
if(rowIndex>=0 && rowIndex<table_view.rows){
return table_view.model.getRow(rowIndex)
}
return null
}
function removeRow(rowIndex,rows=1){
if(rowIndex>=0 && rowIndex<table_view.rows){
table_view.model.removeRow(rowIndex,rows)
}
}
function appendRow(obj){
table_model.appendRow(obj)
} }
} }

View File

@ -81,7 +81,10 @@ Module {
exports: ["FluentUI/FluFramelessHelper 1.0"] exports: ["FluentUI/FluFramelessHelper 1.0"]
exportMetaObjectRevisions: [0] exportMetaObjectRevisions: [0]
Signal { name: "loadCompleted" } Signal { name: "loadCompleted" }
Method { name: "showSystemMenu" } Method {
name: "showSystemMenu"
Parameter { name: "point"; type: "QPoint" }
}
} }
Component { Component {
name: "FluNavigationViewType" name: "FluNavigationViewType"
@ -299,6 +302,32 @@ Module {
} }
} }
} }
Component {
name: "FluTableSortProxyModel"
prototype: "QSortFilterProxyModel"
exports: ["FluentUI/FluTableSortProxyModel 1.0"]
exportMetaObjectRevisions: [0]
Property { name: "model"; type: "QAbstractTableModel"; isPointer: true }
Method {
name: "setSortComparator"
Parameter { name: "comparator"; type: "QJSValue" }
}
Method {
name: "getRow"
type: "QVariant"
Parameter { name: "rowIndex"; type: "int" }
}
Method {
name: "setRow"
Parameter { name: "rowIndex"; type: "int" }
Parameter { name: "val"; type: "QVariant" }
}
Method {
name: "removeRow"
Parameter { name: "rowIndex"; type: "int" }
Parameter { name: "rows"; type: "int" }
}
}
Component { Component {
name: "FluThemeType" name: "FluThemeType"
exports: ["FluentUI/FluThemeType 1.0"] exports: ["FluentUI/FluThemeType 1.0"]
@ -346,7 +375,7 @@ Module {
exports: ["FluentUI/FluTreeModel 1.0"] exports: ["FluentUI/FluTreeModel 1.0"]
exportMetaObjectRevisions: [0] exportMetaObjectRevisions: [0]
Property { name: "dataSourceSize"; type: "int" } Property { name: "dataSourceSize"; type: "int" }
Property { name: "selectionModel"; type: "QList<Node*>" } Property { name: "selectionModel"; type: "QList<FluNode*>" }
Method { Method {
name: "removeRows" name: "removeRows"
Parameter { name: "row"; type: "int" } Parameter { name: "row"; type: "int" }
@ -355,7 +384,7 @@ Module {
Method { Method {
name: "insertRows" name: "insertRows"
Parameter { name: "row"; type: "int" } Parameter { name: "row"; type: "int" }
Parameter { name: "data"; type: "QList<Node*>" } Parameter { name: "data"; type: "QList<FluNode*>" }
} }
Method { Method {
name: "getRow" name: "getRow"
@ -364,7 +393,7 @@ Module {
} }
Method { Method {
name: "setData" name: "setData"
Parameter { name: "data"; type: "QList<Node*>" } Parameter { name: "data"; type: "QList<FluNode*>" }
} }
Method { Method {
name: "setDataSource" name: "setDataSource"
@ -386,7 +415,7 @@ Module {
} }
Method { Method {
name: "getNode" name: "getNode"
type: "Node*" type: "FluNode*"
Parameter { name: "row"; type: "int" } Parameter { name: "row"; type: "int" }
} }
Method { Method {
@ -2177,6 +2206,99 @@ Module {
Parameter { name: "value"; type: "QVariant" } Parameter { name: "value"; type: "QVariant" }
} }
} }
Component {
name: "QAbstractProxyModel"
prototype: "QAbstractItemModel"
Property { name: "sourceModel"; type: "QAbstractItemModel"; isPointer: true }
Method {
name: "mapToSource"
type: "QModelIndex"
Parameter { name: "proxyIndex"; type: "QModelIndex" }
}
Method {
name: "mapFromSource"
type: "QModelIndex"
Parameter { name: "sourceIndex"; type: "QModelIndex" }
}
Method {
name: "mapSelectionToSource"
type: "QItemSelection"
Parameter { name: "selection"; type: "QItemSelection" }
}
Method {
name: "mapSelectionFromSource"
type: "QItemSelection"
Parameter { name: "selection"; type: "QItemSelection" }
}
}
Component {
name: "QSortFilterProxyModel"
prototype: "QAbstractProxyModel"
Property { name: "filterRegExp"; type: "QRegExp" }
Property { name: "filterRegularExpression"; type: "QRegularExpression" }
Property { name: "filterKeyColumn"; type: "int" }
Property { name: "dynamicSortFilter"; type: "bool" }
Property { name: "filterCaseSensitivity"; type: "Qt::CaseSensitivity" }
Property { name: "sortCaseSensitivity"; type: "Qt::CaseSensitivity" }
Property { name: "isSortLocaleAware"; type: "bool" }
Property { name: "sortRole"; type: "int" }
Property { name: "filterRole"; type: "int" }
Property { name: "recursiveFilteringEnabled"; type: "bool" }
Signal {
name: "dynamicSortFilterChanged"
Parameter { name: "dynamicSortFilter"; type: "bool" }
}
Signal {
name: "filterCaseSensitivityChanged"
Parameter { name: "filterCaseSensitivity"; type: "Qt::CaseSensitivity" }
}
Signal {
name: "sortCaseSensitivityChanged"
Parameter { name: "sortCaseSensitivity"; type: "Qt::CaseSensitivity" }
}
Signal {
name: "sortLocaleAwareChanged"
Parameter { name: "sortLocaleAware"; type: "bool" }
}
Signal {
name: "sortRoleChanged"
Parameter { name: "sortRole"; type: "int" }
}
Signal {
name: "filterRoleChanged"
Parameter { name: "filterRole"; type: "int" }
}
Signal {
name: "recursiveFilteringEnabledChanged"
Parameter { name: "recursiveFilteringEnabled"; type: "bool" }
}
Method {
name: "setFilterRegExp"
Parameter { name: "pattern"; type: "string" }
}
Method {
name: "setFilterRegExp"
Parameter { name: "regExp"; type: "QRegExp" }
}
Method {
name: "setFilterRegularExpression"
Parameter { name: "pattern"; type: "string" }
}
Method {
name: "setFilterRegularExpression"
Parameter { name: "regularExpression"; type: "QRegularExpression" }
}
Method {
name: "setFilterWildcard"
Parameter { name: "pattern"; type: "string" }
}
Method {
name: "setFilterFixedString"
Parameter { name: "pattern"; type: "string" }
}
Method { name: "clear" }
Method { name: "invalidate" }
}
Component { Component {
prototype: "QQuickGrid" prototype: "QQuickGrid"
name: "FluentUI/Checkerboard 1.0" name: "FluentUI/Checkerboard 1.0"
@ -2302,31 +2424,31 @@ Module {
Property { name: "systemMenuListener"; type: "QVariant" } Property { name: "systemMenuListener"; type: "QVariant" }
Property { Property {
name: "buttonStayTop" name: "buttonStayTop"
type: "FluIconButton_QMLTYPE_26" type: "FluIconButton_QMLTYPE_28"
isReadonly: true isReadonly: true
isPointer: true isPointer: true
} }
Property { Property {
name: "buttonMinimize" name: "buttonMinimize"
type: "FluIconButton_QMLTYPE_26" type: "FluIconButton_QMLTYPE_28"
isReadonly: true isReadonly: true
isPointer: true isPointer: true
} }
Property { Property {
name: "buttonMaximize" name: "buttonMaximize"
type: "FluIconButton_QMLTYPE_26" type: "FluIconButton_QMLTYPE_28"
isReadonly: true isReadonly: true
isPointer: true isPointer: true
} }
Property { Property {
name: "buttonClose" name: "buttonClose"
type: "FluIconButton_QMLTYPE_26" type: "FluIconButton_QMLTYPE_28"
isReadonly: true isReadonly: true
isPointer: true isPointer: true
} }
Property { Property {
name: "buttonDark" name: "buttonDark"
type: "FluToggleSwitch_QMLTYPE_31" type: "FluToggleSwitch_QMLTYPE_22"
isReadonly: true isReadonly: true
isPointer: true isPointer: true
} }
@ -3004,15 +3126,15 @@ Module {
defaultProperty: "data" defaultProperty: "data"
Property { name: "logo"; type: "QUrl" } Property { name: "logo"; type: "QUrl" }
Property { name: "title"; type: "string" } Property { name: "title"; type: "string" }
Property { name: "items"; type: "FluObject_QMLTYPE_163"; isPointer: true } Property { name: "items"; type: "FluObject_QMLTYPE_162"; isPointer: true }
Property { name: "footerItems"; type: "FluObject_QMLTYPE_163"; isPointer: true } Property { name: "footerItems"; type: "FluObject_QMLTYPE_162"; isPointer: true }
Property { name: "displayMode"; type: "int" } Property { name: "displayMode"; type: "int" }
Property { name: "autoSuggestBox"; type: "QQmlComponent"; isPointer: true } Property { name: "autoSuggestBox"; type: "QQmlComponent"; isPointer: true }
Property { name: "actionItem"; type: "QQmlComponent"; isPointer: true } Property { name: "actionItem"; type: "QQmlComponent"; isPointer: true }
Property { name: "topPadding"; type: "int" } Property { name: "topPadding"; type: "int" }
Property { name: "pageMode"; type: "int" } Property { name: "pageMode"; type: "int" }
Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_51"; isPointer: true } Property { name: "navItemRightMenu"; type: "FluMenu_QMLTYPE_41"; isPointer: true }
Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_51"; isPointer: true } Property { name: "navItemExpanderRightMenu"; type: "FluMenu_QMLTYPE_41"; isPointer: true }
Property { name: "navCompactWidth"; type: "int" } Property { name: "navCompactWidth"; type: "int" }
Property { name: "navTopMargin"; type: "int" } Property { name: "navTopMargin"; type: "int" }
Property { name: "cellHeight"; type: "int" } Property { name: "cellHeight"; type: "int" }
@ -3020,13 +3142,13 @@ Module {
Property { name: "hideNavAppBar"; type: "bool" } Property { name: "hideNavAppBar"; type: "bool" }
Property { Property {
name: "buttonMenu" name: "buttonMenu"
type: "FluIconButton_QMLTYPE_26" type: "FluIconButton_QMLTYPE_28"
isReadonly: true isReadonly: true
isPointer: true isPointer: true
} }
Property { Property {
name: "buttonBack" name: "buttonBack"
type: "FluIconButton_QMLTYPE_26" type: "FluIconButton_QMLTYPE_28"
isReadonly: true isReadonly: true
isPointer: true isPointer: true
} }
@ -3569,8 +3691,8 @@ Module {
Property { name: "borderColor"; type: "QColor" } Property { name: "borderColor"; type: "QColor" }
Property { name: "horizonalHeaderVisible"; type: "bool" } Property { name: "horizonalHeaderVisible"; type: "bool" }
Property { name: "verticalHeaderVisible"; type: "bool" } Property { name: "verticalHeaderVisible"; type: "bool" }
Property { name: "tableModel"; type: "QQmlTableModel"; isReadonly: true; isPointer: true } Property { name: "rows"; type: "int"; isReadonly: true }
Property { name: "tableView"; type: "QQuickTableView"; isReadonly: true; isPointer: true } Property { name: "columns"; type: "int"; isReadonly: true }
Method { name: "closeEditor"; type: "QVariant" } Method { name: "closeEditor"; type: "QVariant" }
Method { name: "resetPosition"; type: "QVariant" } Method { name: "resetPosition"; type: "QVariant" }
Method { Method {
@ -3579,17 +3701,33 @@ Module {
Parameter { name: "comId"; type: "QVariant" } Parameter { name: "comId"; type: "QVariant" }
Parameter { name: "options"; type: "QVariant" } Parameter { name: "options"; type: "QVariant" }
} }
Method {
name: "updateRow"
type: "QVariant"
Parameter { name: "row"; type: "QVariant" }
Parameter { name: "obj"; type: "QVariant" }
}
Method { Method {
name: "sort" name: "sort"
type: "QVariant" type: "QVariant"
Parameter { name: "order"; type: "QVariant" } Parameter { name: "order"; type: "QVariant" }
} }
Method {
name: "setRow"
type: "QVariant"
Parameter { name: "rowIndex"; type: "QVariant" }
Parameter { name: "obj"; type: "QVariant" }
}
Method {
name: "getRow"
type: "QVariant"
Parameter { name: "rowIndex"; type: "QVariant" }
}
Method {
name: "removeRow"
type: "QVariant"
Parameter { name: "rowIndex"; type: "QVariant" }
Parameter { name: "rows"; type: "QVariant" }
}
Method {
name: "appendRow"
type: "QVariant"
Parameter { name: "obj"; type: "QVariant" }
}
} }
Component { Component {
prototype: "QQuickText" prototype: "QQuickText"
@ -3814,13 +3952,13 @@ Module {
Property { name: "showStayTop"; type: "bool" } Property { name: "showStayTop"; type: "bool" }
Property { name: "autoMaximize"; type: "bool" } Property { name: "autoMaximize"; type: "bool" }
Property { name: "autoVisible"; type: "bool" } Property { name: "autoVisible"; type: "bool" }
Property { name: "autoCenter"; type: "bool" }
Property { name: "useSystemAppBar"; type: "bool" } Property { name: "useSystemAppBar"; type: "bool" }
Property { name: "resizeBorderColor"; type: "QColor" } Property { name: "resizeBorderColor"; type: "QColor" }
Property { name: "resizeBorderWidth"; type: "int" } Property { name: "resizeBorderWidth"; type: "int" }
Property { name: "closeListener"; type: "QVariant" } Property { name: "closeListener"; type: "QVariant" }
Property { name: "_offsetXY"; type: "QPointF" } Property { name: "_offsetXY"; type: "QPointF" }
Property { name: "_originalPos"; type: "QVariant" } Property { name: "_originalPos"; type: "QVariant" }
Property { name: "_accentColor"; type: "QColor" }
Property { name: "_realHeight"; type: "int" } Property { name: "_realHeight"; type: "int" }
Property { name: "_realWidth"; type: "int" } Property { name: "_realWidth"; type: "int" }
Property { name: "_appBarHeight"; type: "int" } Property { name: "_appBarHeight"; type: "int" }

View File

@ -9,8 +9,8 @@ Rectangle {
property var columnSource property var columnSource
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 rows: table_view.rows
property alias tableView: table_view property alias columns: table_view.columns
property bool horizonalHeaderVisible: true property bool horizonalHeaderVisible: true
property bool verticalHeaderVisible: true property bool verticalHeaderVisible: true
id:control id:control
@ -32,13 +32,13 @@ Rectangle {
} }
QtObject{ QtObject{
id:d id:d
property var currentIndex property var current
property int rowHoverIndex: -1 property int rowHoverIndex: -1
property int defaultItemWidth: 100 property int defaultItemWidth: 100
property int defaultItemHeight: 42 property int defaultItemHeight: 42
property var header_rows:[] property var header_rows:[]
function obtEditDelegate(column,row,cellItem){ function obtEditDelegate(column,row,display,cellItem){
var display = table_model.data(table_model.index(row,column),"display") var tableModel = table_view.model
var cellPosition = cellItem.mapToItem(scroll_table, 0, 0) var cellPosition = cellItem.mapToItem(scroll_table, 0, 0)
item_loader.column = column item_loader.column = column
item_loader.row = row item_loader.row = row
@ -60,17 +60,15 @@ Rectangle {
} }
onDataSourceChanged: { onDataSourceChanged: {
table_model.clear() table_model.clear()
var rows = [] table_model.rows = dataSource
for(var i =0;i<dataSource.length;i++){
var row = dataSource[i]
row.__index= i
rows.push(row)
}
table_model.rows = rows
} }
TableModel { TableModel {
id:table_model id:table_model
} }
FluTableSortProxyModel{
id:table_sort_model
model: table_model
}
Component{ Component{
id:com_edit id:com_edit
FluTextBox{ FluTextBox{
@ -83,7 +81,7 @@ Rectangle {
} }
onCommit: { onCommit: {
if(!readOnly){ if(!readOnly){
display = text_box.text editTextChaged(text_box.text)
} }
tableView.closeEditor() tableView.closeEditor()
} }
@ -116,7 +114,7 @@ Rectangle {
rightPadding: 24 rightPadding: 24
onCommit: { onCommit: {
if(!readOnly){ if(!readOnly){
display = text editTextChaged(text_box.text)
} }
tableView.closeEditor() tableView.closeEditor()
} }
@ -147,7 +145,7 @@ Rectangle {
id:com_text id:com_text
FluText { FluText {
id:item_text id:item_text
text: modelData text: String(display)
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.WrapAnywhere wrapMode: Text.WrapAnywhere
anchors{ anchors{
@ -221,12 +219,13 @@ Rectangle {
return w return w
} }
rowHeightProvider: function(row) { rowHeightProvider: function(row) {
if(row>=table_model.rowCount){ if(row>=table_view.rows){
return 0 return 0
} }
var h = table_model.getRow(row).height var rowObject = control.getRow(row)
var h = rowObject.height
if(!h){ if(!h){
h = table_model.getRow(row).minimumHeight h = rowObject._minimumHeight
} }
if(!h){ if(!h){
h = d.defaultItemHeight h = d.defaultItemHeight
@ -244,8 +243,12 @@ Rectangle {
} }
model: table_model model: table_model
clip: true clip: true
onRowsChanged: {
closeEditor()
}
delegate: MouseArea{ delegate: MouseArea{
property var rowObject : table_model.getRow(row) property var rowObject : control.getRow(row)
property var itemModel: model
hoverEnabled: true hoverEnabled: true
implicitHeight: 40 implicitHeight: 40
implicitWidth: { implicitWidth: {
@ -265,7 +268,14 @@ 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 === rowObject.__index property bool isRowSelected: {
if(rowObject === null)
return false
if(d.current){
return rowObject._key === d.current._key
}
return false
}
color:{ color:{
if(d.rowHoverIndex === row || item_table.isRowSelected){ 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)
@ -298,23 +308,20 @@ Rectangle {
if(typeof(display) == "object"){ if(typeof(display) == "object"){
return return
} }
item_loader.sourceComponent = d.obtEditDelegate(column,row,item_table) item_loader.sourceComponent = d.obtEditDelegate(column,row,display,item_table)
} }
onClicked: onClicked:
(event)=>{ (event)=>{
d.currentIndex = rowObject.__index d.current = rowObject
item_loader.sourceComponent = undefined item_loader.sourceComponent = undefined
event.accepted = true event.accepted = true
} }
} }
FluLoader{ FluLoader{
property var itemModel: model property var model: itemModel
property var modelData: display property var display: itemModel.display
property var tableView: table_view property int row: item_table.position.y
property var tableModel: table_model property int column: item_table.position.x
property var position: item_table.position
property int row: position.y
property int column: position.x
property var options: { property var options: {
if(typeof(modelData) == "object"){ if(typeof(modelData) == "object"){
return modelData.options return modelData.options
@ -353,13 +360,15 @@ Rectangle {
property int column property int column
property int row property int row
property var tableView: control property var tableView: control
signal editTextChaged(string text)
sourceComponent: undefined sourceComponent: undefined
anchors.fill: parent anchors.fill: parent
onDisplayChanged: { onEditTextChaged:
var obj = table_model.getRow(row) (text)=>{
obj[columnSource[column].dataIndex] = display var obj = control.getRow(row)
table_model.setRow(row,obj) obj[columnSource[column].dataIndex] = text
} control.setRow(row,obj)
}
} }
} }
} }
@ -432,7 +441,7 @@ Rectangle {
height: parent.height height: parent.height
anchors.right: parent.right anchors.right: parent.right
color:"#00000000" color:"#00000000"
visible: column === tableModel.columnCount - 1 visible: column === table_view.columns - 1
} }
MouseArea{ MouseArea{
id:column_item_control_mouse id:column_item_control_mouse
@ -539,7 +548,7 @@ Rectangle {
Connections{ Connections{
target: table_model target: table_model
function onRowCountChanged(){ function onRowCountChanged(){
model_rows.rows = Array.from({length: table_model.rows.length}, (_, i) => ({rowIndex:i+1})); model_rows.rows = Array.from({length: table_model.rows.length}, (_, i) => ({rowIndex:i+1}));
} }
} }
onContentYChanged:{ onContentYChanged:{
@ -556,7 +565,7 @@ Rectangle {
id:item_control id:item_control
readonly property real cellPadding: 8 readonly property real cellPadding: 8
property bool canceled: false property bool canceled: false
property var rowObject: table_model.getRow(row) property var rowObject: control.getRow(row)
implicitWidth: Math.max(30, row_text.implicitWidth + (cellPadding * 2)) implicitWidth: Math.max(30, row_text.implicitWidth + (cellPadding * 2))
implicitHeight: row_text.implicitHeight + (cellPadding * 2) implicitHeight: row_text.implicitHeight + (cellPadding * 2)
width: implicitWidth width: implicitWidth
@ -574,7 +583,7 @@ Rectangle {
width: parent.width width: parent.width
height: 1 height: 1
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
visible: row === tableModel.rowCount - 1 visible: row === table_view.rows - 1
color:"#00000000" color:"#00000000"
} }
Rectangle{ Rectangle{
@ -621,7 +630,11 @@ Rectangle {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
cursorShape: Qt.SplitVCursor cursorShape: Qt.SplitVCursor
visible: !(rowObject.height === rowObject.minimumHeight && rowObject.height === rowObject.maximumHeight && rowObject.height) visible: {
if(rowObject === null)
return false
return !(rowObject.height === rowObject._minimumHeight && rowObject.height === rowObject._maximumHeight && rowObject.height)
}
onPressed : onPressed :
(mouse)=>{ (mouse)=>{
header_vertical.interactive = false header_vertical.interactive = false
@ -641,9 +654,10 @@ Rectangle {
if(!pressed){ if(!pressed){
return return
} }
var rowObject = control.getRow(row)
var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y) var delta = Qt.point(mouse.x - clickPos.x, mouse.y - clickPos.y)
var minimumHeight = rowObject.minimumHeight var minimumHeight = rowObject._minimumHeight
var maximumHeight = rowObject.maximumHeight var maximumHeight = rowObject._maximumHeight
var h = rowObject.height var h = rowObject.height
if(!h){ if(!h){
h = d.defaultItemHeight h = d.defaultItemHeight
@ -655,7 +669,7 @@ Rectangle {
maximumHeight = 65535 maximumHeight = 65535
} }
rowObject.height = Math.min(Math.max(minimumHeight, h + delta.y),maximumHeight) rowObject.height = Math.min(Math.max(minimumHeight, h + delta.y),maximumHeight)
table_model.setRow(row,rowObject) control.setRow(row,rowObject)
table_view.forceLayout() table_view.forceLayout()
} }
} }
@ -674,21 +688,33 @@ Rectangle {
o.options = options o.options = options
return o return o
} }
function updateRow(row,obj){
table_model.setRow(row,obj)
}
function sort(order){ function sort(order){
let sortedArray = []
for(var i =0;i<table_model.rowCount;i++){
let row = table_model.getRow(i)
sortedArray.push(row)
}
if(order === undefined){ if(order === undefined){
sortedArray.sort((a, b) => a.__index - b.__index) table_view.model = table_model
}else{ }else{
sortedArray.sort(order) table_view.model = table_sort_model
table_sort_model.setSortComparator(function(left,right){
return order(table_model.getRow(left),table_model.getRow(right))
})
} }
table_model.clear() }
table_model.rows = sortedArray function setRow(rowIndex,obj){
if(rowIndex>=0 && rowIndex<table_view.rows){
table_view.model.setRow(rowIndex,obj)
}
}
function getRow(rowIndex){
if(rowIndex>=0 && rowIndex<table_view.rows){
return table_view.model.getRow(rowIndex)
}
return null
}
function removeRow(rowIndex,rows=1){
if(rowIndex>=0 && rowIndex<table_view.rows){
table_view.model.removeRow(rowIndex,rows)
}
}
function appendRow(obj){
table_model.appendRow(obj)
} }
} }