This commit is contained in:
朱子楚\zhuzi
2024-04-14 23:58:15 +08:00
parent 295dcf02c4
commit 17bfff2346
7 changed files with 30 additions and 22 deletions

View File

@ -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<FluTreeNode *> data;
foreach (auto item, _dataSource) {
if (!item->hasChildren()) {
if (item->_checked) {
data.append(item);
}
}
}
selectionModel(data);
}
void FluTreeModel::setDataSource(QList<QMap<QString, QVariant>> data) {
@ -272,3 +264,13 @@ void FluTreeModel::allCollapse() {
_rows = _root->_children;
endResetModel();
}
QVariant FluTreeModel::selectionModel(){
QList<FluTreeNode *> data;
foreach (auto item, _dataSource) {
if (item->checked()) {
data.append(item);
}
}
return QVariant::fromValue(data);
}

View File

@ -89,7 +89,6 @@ public:
class FluTreeModel : public QAbstractItemModel {
Q_OBJECT
Q_PROPERTY_AUTO(int, dataSourceSize)
Q_PROPERTY_AUTO(QList<FluTreeNode *>, selectionModel)
Q_PROPERTY_AUTO(QList<QVariantMap>, 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<FluTreeNode *> _rows;
QList<FluTreeNode *> _dataSource;

View File

@ -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()
}
}

View File

@ -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()
}
}