Compare commits

..

No commits in common. "2367c6978a53e372277487b160c558390e87a93f" and "4997b991db3238376121af5aa9e9cbe3a52c4616" have entirely different histories.

8 changed files with 125 additions and 142 deletions

View File

@ -375,7 +375,7 @@ void FluFrameless::_showSystemMenu(QPoint point) {
} }
const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), nativePos.x(), const int result = ::TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), nativePos.x(),
nativePos.y(), 0, hwnd, nullptr); nativePos.y(), 0, hwnd, nullptr);
if (result) { if (result != FALSE) {
::PostMessageW(hwnd, WM_SYSCOMMAND, result, 0); ::PostMessageW(hwnd, WM_SYSCOMMAND, result, 0);
} }
#endif #endif

View File

@ -31,6 +31,16 @@ QHash<int, QByteArray> FluTableModel::roleNames() const {
}; };
} }
QModelIndex FluTableModel::parent(const QModelIndex &child) const {
return {};
}
QModelIndex FluTableModel::index(int row, int column, const QModelIndex &parent) const {
if (!hasIndex(row, column, parent) || parent.isValid())
return {};
return createIndex(row, column);
}
void FluTableModel::clear() { void FluTableModel::clear() {
beginResetModel(); beginResetModel();
this->_rows.clear(); this->_rows.clear();

View File

@ -28,6 +28,10 @@ public:
[[nodiscard]] QHash<int, QByteArray> roleNames() const override; [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] QModelIndex parent(const QModelIndex &child) const override;
[[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
Q_INVOKABLE void clear(); Q_INVOKABLE void clear();
Q_INVOKABLE QVariant getRow(int rowIndex); Q_INVOKABLE QVariant getRow(int rowIndex);

View File

@ -9,6 +9,16 @@ FluTreeModel::FluTreeModel(QObject *parent) : QAbstractTableModel{parent} {
_dataSourceSize = 0; _dataSourceSize = 0;
} }
QModelIndex FluTreeModel::parent(const QModelIndex &child) const {
return {};
}
QModelIndex FluTreeModel::index(int row, int column, const QModelIndex &parent) const {
if (!hasIndex(row, column, parent) || parent.isValid())
return {};
return createIndex(row, column);
}
int FluTreeModel::rowCount(const QModelIndex &parent) const { int FluTreeModel::rowCount(const QModelIndex &parent) const {
return _rows.count(); return _rows.count();
} }

View File

@ -107,6 +107,10 @@ public:
[[nodiscard]] QHash<int, QByteArray> roleNames() const override; [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] QModelIndex parent(const QModelIndex &child) const override;
[[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
Q_INVOKABLE void removeRows(int row, int count); Q_INVOKABLE void removeRows(int row, int count);
Q_INVOKABLE void insertRows(int row, const QList<FluTreeNode *> &data); Q_INVOKABLE void insertRows(int row, const QList<FluTreeNode *> &data);

View File

@ -225,21 +225,22 @@ Rectangle {
id:com_table_delegate id:com_table_delegate
MouseArea{ MouseArea{
id:item_table_mouse id:item_table_mouse
implicitWidth: TableView.view.width
property var _model: model property var _model: model
property bool isMainTable: TableView.view == table_view property bool isMainTable: TableView.view == table_view
property var currentTableView: TableView.view property var currentTableView: TableView.view
property bool isHide: { visible: {
if(isMainTable && columnModel.frozen){ if(isMainTable && columnModel.frozen){
return true return false
} }
if(!isMainTable){ if(!isMainTable){
if(currentTableView.dataIndex !== columnModel.dataIndex) if(currentTableView.dataIndex !== columnModel.dataIndex)
return true return false
} }
return false return true
} }
property bool isRowSelected: { property bool isRowSelected: {
if(!rowModel) if(rowModel === null)
return false return false
if(d.current){ if(d.current){
return rowModel._key === d.current._key return rowModel._key === d.current._key
@ -247,15 +248,11 @@ Rectangle {
return false return false
} }
property bool editVisible: { property bool editVisible: {
if(!rowModel)
return false
if(d.editPosition && d.editPosition._key === rowModel._key && d.editPosition.column === column){ if(d.editPosition && d.editPosition._key === rowModel._key && d.editPosition.column === column){
return true return true
} }
return false return false
} }
implicitWidth: isHide ? Number.MIN_VALUE : TableView.view.width
visible: !isHide
TableView.onPooled: { TableView.onPooled: {
if(d.editPosition && d.editPosition.row === row && d.editPosition.column === column){ if(d.editPosition && d.editPosition.row === row && d.editPosition.column === column){
control.closeEditor() control.closeEditor()
@ -444,11 +441,6 @@ Rectangle {
} }
} }
} }
onWidthChanged:{
table_view.forceLayout()
}
MouseArea{ MouseArea{
id:layout_mouse_table id:layout_mouse_table
hoverEnabled: true hoverEnabled: true
@ -483,7 +475,7 @@ Rectangle {
} }
Component{ Component{
id: com_column_header_delegate id:com_column_header_delegate
Rectangle{ Rectangle{
id: column_item_control id: column_item_control
property var currentTableView : TableView.view property var currentTableView : TableView.view
@ -498,31 +490,17 @@ Rectangle {
return control.columnSource.findIndex(isDataIndex) return control.columnSource.findIndex(isDataIndex)
} }
readonly property bool isHeaderHorizontal: TableView.view == header_horizontal readonly property bool isHeaderHorizontal: TableView.view == header_horizontal
readonly property bool isHide: {
if(isHeaderHorizontal && columnModel.frozen){
return true
}
if(!isHeaderHorizontal){
if(currentTableView.dataIndex !== columnModel.dataIndex)
return true
}
return false
}
visible: !isHide
implicitWidth: { implicitWidth: {
if(isHide){
return Number.MIN_VALUE
}
if(column_item_control.isHeaderHorizontal){ if(column_item_control.isHeaderHorizontal){
return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2) return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2)
} }
return Math.max(TableView.view.width,Number.MIN_VALUE) return TableView.view.width
} }
implicitHeight: { implicitHeight: {
if(column_item_control.isHeaderHorizontal){ if(column_item_control.isHeaderHorizontal){
return Math.max(36, (item_column_loader.item&&item_column_loader.item.implicitHeight) + (cellPadding * 2)) return Math.max(36, (item_column_loader.item&&item_column_loader.item.implicitHeight) + (cellPadding * 2))
} }
return Math.max(TableView.view.height,Number.MIN_VALUE) return TableView.view.height
} }
color: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1) color: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1)
Rectangle{ Rectangle{
@ -638,6 +616,7 @@ Rectangle {
columnModel.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth) columnModel.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth)
table_view.forceLayout() table_view.forceLayout()
header_horizontal.forceLayout() header_horizontal.forceLayout()
// column_item_control.currentTableView.forceLayout()
} }
} }
} }
@ -891,32 +870,12 @@ Rectangle {
} }
color: "#00000000" color: "#00000000"
} }
TableView{
property string dataIndex: columnModel.dataIndex
id: item_table_frozen
interactive: false
clip: true
anchors{
left: parent.left
right: parent.right
}
contentWidth: width
height: table_view.height
y: header_horizontal.height
boundsBehavior: TableView.StopAtBounds
model: table_view.model
delegate: table_view.delegate
syncDirection: Qt.Vertical
syncView: table_view
}
TableView { TableView {
property string dataIndex: columnModel.dataIndex
id:item_table_frozen_header id:item_table_frozen_header
model: header_column_model model: header_column_model
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
interactive: false
clip: true clip: true
contentWidth: width interactive: false
anchors{ anchors{
left: parent.left left: parent.left
right: parent.right right: parent.right
@ -924,14 +883,24 @@ Rectangle {
bottom: item_table_frozen.top bottom: item_table_frozen.top
} }
delegate: com_column_header_delegate delegate: com_column_header_delegate
Component.onCompleted: {
item_table_frozen_header.forceLayout()
}
} }
Connections{ TableView{
target: table_view property string dataIndex: columnModel.dataIndex
function onWidthChanged() { id: item_table_frozen
item_table_frozen_header.forceLayout() clip: true
interactive: false
anchors{
fill: parent
topMargin: header_horizontal.height
}
boundsBehavior: TableView.StopAtBounds
model: table_sort_model
delegate: com_table_delegate
syncDirection: Qt.Vertical
syncView: table_view
Component.onCompleted: {
item_table_frozen_header.contentX = columnModel.width * _index
item_table_frozen.contentX = columnModel.width * _index
} }
} }
@ -945,12 +914,6 @@ Rectangle {
id: item_layout_frozen id: item_layout_frozen
readonly property int _index : model.index readonly property int _index : model.index
readonly property var columnModel : control.columnSource[_index] readonly property var columnModel : control.columnSource[_index]
readonly property bool isHide:{
if(columnModel.frozen){
return false
}
return true
}
Connections{ Connections{
target: d target: d
function onTableItemLayout(column){ function onTableItemLayout(column){
@ -969,17 +932,17 @@ Rectangle {
width = table_view.columnWidthProvider(_index) width = table_view.columnWidthProvider(_index)
x = Qt.binding(function(){ x = Qt.binding(function(){
var minX = 0 var minX = 0
var maxX = table_view.width-width var maxX = table_view.width-item_layout_frozen.width
for(var i=0;i<_index;i++){ for(var i=0;i<_index;i++){
var item = control.columnSource[i] var item = control.columnSource[i]
if(item.frozen){ if(item.frozen){
minX = minX + table_view.columnWidthProvider(i) minX = minX + item.width
} }
} }
for(i=_index+1;i<control.columnSource.length;i++){ for(i=_index+1;i<control.columnSource.length;i++){
item = control.columnSource[i] item = control.columnSource[i]
if(item.frozen){ if(item.frozen){
maxX = maxX - table_view.columnWidthProvider(i) maxX = maxX- item.width
} }
} }
return Math.min(Math.max(columnModel.x - table_view.contentX,minX),maxX)} return Math.min(Math.max(columnModel.x - table_view.contentX,minX),maxX)}
@ -989,8 +952,23 @@ Rectangle {
updateLayout() updateLayout()
} }
height: control.height height: control.height
visible: !item_layout_frozen.isHide visible: {
sourceComponent: item_layout_frozen.isHide ? undefined : com_table_frozen if(modelData.frozen){
return true
}
return false
}
sourceComponent: visible ? com_table_frozen : undefined
onStatusChanged: {
if(status === Loader.Ready){
sourceComponent = Qt.binding(function(){
if(modelData.frozen){
return com_table_frozen
}
return undefined
})
}
}
} }
} }
} }

View File

@ -1,6 +1,5 @@
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Window import QtQuick.Window
import FluentUI import FluentUI

View File

@ -225,21 +225,22 @@ Rectangle {
id:com_table_delegate id:com_table_delegate
MouseArea{ MouseArea{
id:item_table_mouse id:item_table_mouse
implicitWidth: TableView.view.width
property var _model: model property var _model: model
property bool isMainTable: TableView.view == table_view property bool isMainTable: TableView.view == table_view
property var currentTableView: TableView.view property var currentTableView: TableView.view
property bool isHide: { visible: {
if(isMainTable && columnModel.frozen){ if(isMainTable && columnModel.frozen){
return true return false
} }
if(!isMainTable){ if(!isMainTable){
if(currentTableView.dataIndex !== columnModel.dataIndex) if(currentTableView.dataIndex !== columnModel.dataIndex)
return true return false
} }
return false return true
} }
property bool isRowSelected: { property bool isRowSelected: {
if(!rowModel) if(rowModel === null)
return false return false
if(d.current){ if(d.current){
return rowModel._key === d.current._key return rowModel._key === d.current._key
@ -247,15 +248,11 @@ Rectangle {
return false return false
} }
property bool editVisible: { property bool editVisible: {
if(!rowModel)
return false
if(d.editPosition && d.editPosition._key === rowModel._key && d.editPosition.column === column){ if(d.editPosition && d.editPosition._key === rowModel._key && d.editPosition.column === column){
return true return true
} }
return false return false
} }
implicitWidth: isHide ? Number.MIN_VALUE : TableView.view.width
visible: !isHide
TableView.onPooled: { TableView.onPooled: {
if(d.editPosition && d.editPosition.row === row && d.editPosition.column === column){ if(d.editPosition && d.editPosition.row === row && d.editPosition.column === column){
control.closeEditor() control.closeEditor()
@ -444,11 +441,6 @@ Rectangle {
} }
} }
} }
onWidthChanged:{
table_view.forceLayout()
}
MouseArea{ MouseArea{
id:layout_mouse_table id:layout_mouse_table
hoverEnabled: true hoverEnabled: true
@ -483,7 +475,7 @@ Rectangle {
} }
Component{ Component{
id: com_column_header_delegate id:com_column_header_delegate
Rectangle{ Rectangle{
id: column_item_control id: column_item_control
property var currentTableView : TableView.view property var currentTableView : TableView.view
@ -498,31 +490,17 @@ Rectangle {
return control.columnSource.findIndex(isDataIndex) return control.columnSource.findIndex(isDataIndex)
} }
readonly property bool isHeaderHorizontal: TableView.view == header_horizontal readonly property bool isHeaderHorizontal: TableView.view == header_horizontal
readonly property bool isHide: {
if(isHeaderHorizontal && columnModel.frozen){
return true
}
if(!isHeaderHorizontal){
if(currentTableView.dataIndex !== columnModel.dataIndex)
return true
}
return false
}
visible: !isHide
implicitWidth: { implicitWidth: {
if(isHide){
return Number.MIN_VALUE
}
if(column_item_control.isHeaderHorizontal){ if(column_item_control.isHeaderHorizontal){
return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2) return (item_column_loader.item && item_column_loader.item.implicitWidth) + (cellPadding * 2)
} }
return Math.max(TableView.view.width,Number.MIN_VALUE) return TableView.view.width
} }
implicitHeight: { implicitHeight: {
if(column_item_control.isHeaderHorizontal){ if(column_item_control.isHeaderHorizontal){
return Math.max(36, (item_column_loader.item&&item_column_loader.item.implicitHeight) + (cellPadding * 2)) return Math.max(36, (item_column_loader.item&&item_column_loader.item.implicitHeight) + (cellPadding * 2))
} }
return Math.max(TableView.view.height,Number.MIN_VALUE) return TableView.view.height
} }
color: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1) color: FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1)
Rectangle{ Rectangle{
@ -638,6 +616,7 @@ Rectangle {
columnModel.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth) columnModel.width = Math.min(Math.max(minimumWidth, w + delta.x),maximumWidth)
table_view.forceLayout() table_view.forceLayout()
header_horizontal.forceLayout() header_horizontal.forceLayout()
// column_item_control.currentTableView.forceLayout()
} }
} }
} }
@ -891,32 +870,12 @@ Rectangle {
} }
color: "#00000000" color: "#00000000"
} }
TableView{
property string dataIndex: columnModel.dataIndex
id: item_table_frozen
interactive: false
clip: true
anchors{
left: parent.left
right: parent.right
}
contentWidth: width
height: table_view.height
y: header_horizontal.height
boundsBehavior: TableView.StopAtBounds
model: table_view.model
delegate: table_view.delegate
syncDirection: Qt.Vertical
syncView: table_view
}
TableView { TableView {
property string dataIndex: columnModel.dataIndex
id:item_table_frozen_header id:item_table_frozen_header
model: header_column_model model: header_column_model
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
interactive: false
clip: true clip: true
contentWidth: width interactive: false
anchors{ anchors{
left: parent.left left: parent.left
right: parent.right right: parent.right
@ -924,14 +883,24 @@ Rectangle {
bottom: item_table_frozen.top bottom: item_table_frozen.top
} }
delegate: com_column_header_delegate delegate: com_column_header_delegate
Component.onCompleted: {
item_table_frozen_header.forceLayout()
}
} }
Connections{ TableView{
target: table_view property string dataIndex: columnModel.dataIndex
function onWidthChanged() { id: item_table_frozen
item_table_frozen_header.forceLayout() clip: true
interactive: false
anchors{
fill: parent
topMargin: header_horizontal.height
}
boundsBehavior: TableView.StopAtBounds
model: table_sort_model
delegate: com_table_delegate
syncDirection: Qt.Vertical
syncView: table_view
Component.onCompleted: {
item_table_frozen_header.contentX = columnModel.width * _index
item_table_frozen.contentX = columnModel.width * _index
} }
} }
@ -945,12 +914,6 @@ Rectangle {
id: item_layout_frozen id: item_layout_frozen
readonly property int _index : model.index readonly property int _index : model.index
readonly property var columnModel : control.columnSource[_index] readonly property var columnModel : control.columnSource[_index]
readonly property bool isHide:{
if(columnModel.frozen){
return false
}
return true
}
Connections{ Connections{
target: d target: d
function onTableItemLayout(column){ function onTableItemLayout(column){
@ -969,17 +932,17 @@ Rectangle {
width = table_view.columnWidthProvider(_index) width = table_view.columnWidthProvider(_index)
x = Qt.binding(function(){ x = Qt.binding(function(){
var minX = 0 var minX = 0
var maxX = table_view.width-width var maxX = table_view.width-item_layout_frozen.width
for(var i=0;i<_index;i++){ for(var i=0;i<_index;i++){
var item = control.columnSource[i] var item = control.columnSource[i]
if(item.frozen){ if(item.frozen){
minX = minX + table_view.columnWidthProvider(i) minX = minX + item.width
} }
} }
for(i=_index+1;i<control.columnSource.length;i++){ for(i=_index+1;i<control.columnSource.length;i++){
item = control.columnSource[i] item = control.columnSource[i]
if(item.frozen){ if(item.frozen){
maxX = maxX - table_view.columnWidthProvider(i) maxX = maxX- item.width
} }
} }
return Math.min(Math.max(columnModel.x - table_view.contentX,minX),maxX)} return Math.min(Math.max(columnModel.x - table_view.contentX,minX),maxX)}
@ -989,8 +952,23 @@ Rectangle {
updateLayout() updateLayout()
} }
height: control.height height: control.height
visible: !item_layout_frozen.isHide visible: {
sourceComponent: item_layout_frozen.isHide ? undefined : com_table_frozen if(modelData.frozen){
return true
}
return false
}
sourceComponent: visible ? com_table_frozen : undefined
onStatusChanged: {
if(status === Loader.Ready){
sourceComponent = Qt.binding(function(){
if(modelData.frozen){
return com_table_frozen
}
return undefined
})
}
}
} }
} }
} }