From 17bfff23464efad94a712a603842709bc78073c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Sun, 14 Apr 2024 23:58:15 +0800 Subject: [PATCH] update --- example/example_en_US.ts | 8 ++++---- example/example_zh_CN.ts | 8 ++++---- example/qml/page/T_TreeView.qml | 5 +++-- src/FluTreeModel.cpp | 20 ++++++++++--------- src/FluTreeModel.h | 3 ++- .../imports/FluentUI/Controls/FluTreeView.qml | 4 +++- .../imports/FluentUI/Controls/FluTreeView.qml | 4 +++- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/example/example_en_US.ts b/example/example_en_US.ts index f67acf47..72fff7c3 100644 --- a/example/example_en_US.ts +++ b/example/example_en_US.ts @@ -2394,22 +2394,22 @@ Some contents... - + Title - + Name - + Avatar - + Address diff --git a/example/example_zh_CN.ts b/example/example_zh_CN.ts index 568ee1fe..8ec55285 100644 --- a/example/example_zh_CN.ts +++ b/example/example_zh_CN.ts @@ -2504,22 +2504,22 @@ Some contents... 共计选中%1条数据 - + Title 标题 - + Address 地址 - + Avatar 头像 - + Name 名称 diff --git a/example/qml/page/T_TreeView.qml b/example/qml/page/T_TreeView.qml index c98f68b2..a42010f1 100644 --- a/example/qml/page/T_TreeView.qml +++ b/example/qml/page/T_TreeView.qml @@ -28,7 +28,7 @@ FluContentPage { } const dig = (path = '0', level = 5) => { const list = []; - for (let i = 0; i < 5; i += 1) { + for (let i = 0; i < 4; i += 1) { const key = `${path}-${i}`; const treeNode = { title: key, @@ -148,7 +148,8 @@ FluContentPage { text: "print selection model" onClicked: { var printData = [] - var data = tree_view.selectionModel + var data = tree_view.selectionModel(); + console.debug(data.length) for(var i = 0; i <= data.length-1 ; i++){ const newObj = Object.assign({}, data[i].data); delete newObj["__parent"]; diff --git a/src/FluTreeModel.cpp b/src/FluTreeModel.cpp index aada5733..020e8af8 100644 --- a/src/FluTreeModel.cpp +++ b/src/FluTreeModel.cpp @@ -113,15 +113,7 @@ void FluTreeModel::checkRow(int row, bool checked) { itemData->_checked = checked; } Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0)); - QList data; - foreach (auto item, _dataSource) { - if (!item->hasChildren()) { - if (item->_checked) { - data.append(item); - } - } - } - selectionModel(data); + } void FluTreeModel::setDataSource(QList> data) { @@ -272,3 +264,13 @@ void FluTreeModel::allCollapse() { _rows = _root->_children; endResetModel(); } + +QVariant FluTreeModel::selectionModel(){ + QList data; + foreach (auto item, _dataSource) { + if (item->checked()) { + data.append(item); + } + } + return QVariant::fromValue(data); +} diff --git a/src/FluTreeModel.h b/src/FluTreeModel.h index 07eb6ed6..d8eda4f5 100644 --- a/src/FluTreeModel.h +++ b/src/FluTreeModel.h @@ -89,7 +89,6 @@ public: class FluTreeModel : public QAbstractItemModel { Q_OBJECT Q_PROPERTY_AUTO(int, dataSourceSize) -Q_PROPERTY_AUTO(QList, selectionModel) Q_PROPERTY_AUTO(QList, columnSource) QML_NAMED_ELEMENT(FluTreeModel) QML_ADDED_IN_MINOR_VERSION(1) @@ -141,6 +140,8 @@ public: Q_INVOKABLE void allCollapse(); + Q_INVOKABLE QVariant selectionModel(); + private: QList _rows; QList _dataSource; diff --git a/src/Qt5/imports/FluentUI/Controls/FluTreeView.qml b/src/Qt5/imports/FluentUI/Controls/FluTreeView.qml index 765d3793..c74872a9 100644 --- a/src/Qt5/imports/FluentUI/Controls/FluTreeView.qml +++ b/src/Qt5/imports/FluentUI/Controls/FluTreeView.qml @@ -12,7 +12,6 @@ Rectangle { property int cellHeight: 30 property int depthPadding: 15 property bool checkable: false - property alias selectionModel: tree_model.selectionModel property color lineColor: FluTheme.dividerColor property color borderColor: FluTheme.dark ? Qt.rgba(37/255,37/255,37/255,1) : Qt.rgba(228/255,228/255,228/255,1) property color selectedBorderColor: FluTheme.primaryColor @@ -739,4 +738,7 @@ Rectangle { d.editPosition = undefined d.editDelegate = undefined } + function selectionModel(){ + return tree_model.selectionModel() + } } diff --git a/src/Qt6/imports/FluentUI/Controls/FluTreeView.qml b/src/Qt6/imports/FluentUI/Controls/FluTreeView.qml index c504b25e..47fbb0a1 100644 --- a/src/Qt6/imports/FluentUI/Controls/FluTreeView.qml +++ b/src/Qt6/imports/FluentUI/Controls/FluTreeView.qml @@ -12,7 +12,6 @@ Rectangle { property int cellHeight: 30 property int depthPadding: 15 property bool checkable: false - property alias selectionModel: tree_model.selectionModel property color lineColor: FluTheme.dividerColor property color borderColor: FluTheme.dark ? Qt.rgba(37/255,37/255,37/255,1) : Qt.rgba(228/255,228/255,228/255,1) property color selectedBorderColor: FluTheme.primaryColor @@ -739,4 +738,7 @@ Rectangle { d.editPosition = undefined d.editDelegate = undefined } + function selectionModel(){ + return tree_model.selectionModel() + } }