This commit is contained in:
朱子楚\zhuzi
2024-04-09 20:53:52 +08:00
parent 6ebd659e13
commit 6a31e86505
15 changed files with 1711 additions and 815 deletions

View File

@ -4,6 +4,7 @@
#include <QObject>
#include <QAbstractTableModel>
#include <QJsonArray>
#include <QVariant>
#include <QtQml/qqml.h>
#include "stdafx.h"
@ -12,17 +13,15 @@
*/
class FluTreeNode : public QObject{
Q_OBJECT
Q_PROPERTY(QString key READ key CONSTANT)
Q_PROPERTY(QString title READ title CONSTANT)
Q_PROPERTY(QVariantMap data READ data CONSTANT)
Q_PROPERTY(int depth READ depth CONSTANT)
Q_PROPERTY(bool isExpanded READ isExpanded CONSTANT)
Q_PROPERTY(bool checked READ checked CONSTANT)
public:
explicit FluTreeNode(QObject *parent = nullptr);
Q_INVOKABLE QString key(){return _key;};
Q_INVOKABLE QString title(){return _title;};
Q_INVOKABLE int depth(){return _depth;};
Q_INVOKABLE bool isExpanded(){return _isExpanded;};
Q_INVOKABLE QVariantMap data(){return _data;};
Q_INVOKABLE bool hasChildren(){ return !_children.isEmpty();};
Q_INVOKABLE bool hasNextNodeByIndex(int index){
FluTreeNode* p = this;
@ -70,11 +69,11 @@ public:
return true;
}
public:
QString _key="";
QString _title="";
int _depth=0;
bool _checked = false;
bool _isExpanded=true;
QVariantMap _data;
QList<FluTreeNode*> _children;
FluTreeNode* _parent = nullptr;
};
@ -84,9 +83,14 @@ 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)
public:
enum TreeModelRoles {
RowModel = 0x0101,
ColumnModel = 0x0102
};
explicit FluTreeModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
@ -98,11 +102,11 @@ public:
Q_INVOKABLE void removeRows(int row,int count);
Q_INVOKABLE void insertRows(int row,QList<FluTreeNode*> data);
Q_INVOKABLE QObject* getRow(int row);
Q_INVOKABLE void setRow(int row,QVariantMap data);
Q_INVOKABLE void setData(QList<FluTreeNode*> data);
Q_INVOKABLE void setDataSource(QList<QMap<QString,QVariant>> data);
Q_INVOKABLE void collapse(int row);
Q_INVOKABLE void expand(int row);
Q_INVOKABLE void dragAndDrop(int dragIndex,int dropIndex,bool isDropTopArea);
Q_INVOKABLE FluTreeNode* getNode(int row);
Q_INVOKABLE void refreshNode(int row);
Q_INVOKABLE void checkRow(int row,bool checked);