mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2024-11-26 13:27:05 +08:00
update
This commit is contained in:
parent
6749e47c22
commit
19a947ffab
@ -2,7 +2,7 @@
|
||||
|
||||
#include <QMetaEnum>
|
||||
|
||||
Node::Node(QObject *parent): QObject{parent}{
|
||||
FluNode::FluNode(QObject *parent): QObject{parent}{
|
||||
}
|
||||
|
||||
FluTreeModel::FluTreeModel(QObject *parent): QAbstractItemModel{parent}{
|
||||
@ -41,7 +41,7 @@ QHash<int, QByteArray> FluTreeModel::roleNames() const {
|
||||
return { {Qt::DisplayRole, "dataModel"} };
|
||||
};
|
||||
|
||||
void FluTreeModel::setData(QList<Node*> data){
|
||||
void FluTreeModel::setData(QList<FluNode*> data){
|
||||
beginResetModel();
|
||||
_rows = data;
|
||||
endResetModel();
|
||||
@ -51,20 +51,20 @@ void FluTreeModel::removeRows(int row,int count){
|
||||
if (row < 0 || row + count > _rows.size() || count==0)
|
||||
return;
|
||||
beginRemoveRows(QModelIndex(),row, row + count - 1);
|
||||
QList<Node*> firstPart = _rows.mid(0,row);
|
||||
QList<Node*> secondPart = _rows.mid(row + count);
|
||||
QList<FluNode*> firstPart = _rows.mid(0,row);
|
||||
QList<FluNode*> secondPart = _rows.mid(row + count);
|
||||
_rows.clear();
|
||||
_rows.append(firstPart);
|
||||
_rows.append(secondPart);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void FluTreeModel::insertRows(int row,QList<Node*> data){
|
||||
void FluTreeModel::insertRows(int row,QList<FluNode*> data){
|
||||
if (row < 0 || row > _rows.size() || data.size() == 0)
|
||||
return;;
|
||||
beginInsertRows(QModelIndex(), row, row + data.size() - 1);
|
||||
QList<Node*> firstPart = _rows.mid(0, row);
|
||||
QList<Node*> secondPart = _rows.mid(row);
|
||||
QList<FluNode*> firstPart = _rows.mid(0, row);
|
||||
QList<FluNode*> secondPart = _rows.mid(row);
|
||||
_rows.clear();
|
||||
_rows.append(firstPart);
|
||||
_rows.append(data);
|
||||
@ -79,7 +79,7 @@ QObject* FluTreeModel::getRow(int row){
|
||||
void FluTreeModel::checkRow(int row,bool chekced){
|
||||
auto itemData = _rows.at(row);
|
||||
if(itemData->hasChildren()){
|
||||
QList<Node*> stack = itemData->_children;
|
||||
QList<FluNode*> stack = itemData->_children;
|
||||
std::reverse(stack.begin(), stack.end());
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
@ -87,7 +87,7 @@ void FluTreeModel::checkRow(int row,bool chekced){
|
||||
if(!item->hasChildren()){
|
||||
item->_checked = chekced;
|
||||
}
|
||||
QList<Node*> children = item->_children;
|
||||
QList<FluNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
@ -102,7 +102,7 @@ void FluTreeModel::checkRow(int row,bool chekced){
|
||||
itemData->_checked = chekced;
|
||||
}
|
||||
Q_EMIT layoutChanged(QList<QPersistentModelIndex>(),QAbstractItemModel::VerticalSortHint);
|
||||
QList<Node*> data;
|
||||
QList<FluNode*> data;
|
||||
foreach (auto item, _dataSource) {
|
||||
if(!item->hasChildren()){
|
||||
if(item->_checked){
|
||||
@ -119,16 +119,16 @@ void FluTreeModel::setDataSource(QList<QMap<QString,QVariant>> data){
|
||||
delete _root;
|
||||
_root = nullptr;
|
||||
}
|
||||
_root = new Node(this);
|
||||
_root = new FluNode(this);
|
||||
std::reverse(data.begin(), data.end());
|
||||
while (data.count() > 0) {
|
||||
auto item = data.at(data.count()-1);
|
||||
data.pop_back();
|
||||
Node* node = new Node(this);
|
||||
FluNode* node = new FluNode(this);
|
||||
node->_title = item.value("title").toString();
|
||||
node->_key = item.value("key").toString();
|
||||
node->_depth = item.value("__depth").toInt();
|
||||
node->_parent = item.value("__parent").value<Node*>();
|
||||
node->_parent = item.value("__parent").value<FluNode*>();
|
||||
node->_isExpanded = true;
|
||||
if(node->_parent){
|
||||
node->_parent->_children.append(node);
|
||||
@ -181,8 +181,8 @@ void FluTreeModel::expand(int row){
|
||||
_rows.at(row)->_isExpanded = true;
|
||||
Q_EMIT dataChanged(index(row,0),index(row,0));
|
||||
auto modelData = _rows.at(row);
|
||||
QList<Node*> insertData;
|
||||
QList<Node*> stack = modelData->_children;
|
||||
QList<FluNode*> insertData;
|
||||
QList<FluNode*> stack = modelData->_children;
|
||||
std::reverse(stack.begin(), stack.end());
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
@ -190,7 +190,7 @@ void FluTreeModel::expand(int row){
|
||||
if(item->isShown()){
|
||||
insertData.append(item);
|
||||
}
|
||||
QList<Node*> children = item->_children;
|
||||
QList<FluNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
@ -242,7 +242,7 @@ void FluTreeModel::dragAnddrop(int dragIndex,int dropIndex,bool isDropTopArea){
|
||||
|
||||
Q_EMIT layoutAboutToBeChanged();
|
||||
if(dragItem->_parent == dropItem->_parent){
|
||||
QList<Node*>* children = &(dragItem->_parent->_children);
|
||||
QList<FluNode*>* children = &(dragItem->_parent->_children);
|
||||
int srcIndex = children->indexOf(dragItem);
|
||||
int destIndex = children->indexOf(dropItem);
|
||||
if(dropIndex > dragIndex){
|
||||
@ -260,14 +260,14 @@ void FluTreeModel::dragAnddrop(int dragIndex,int dropIndex,bool isDropTopArea){
|
||||
}
|
||||
children->move(srcIndex,targetIndex);
|
||||
}else{
|
||||
QList<Node*>* srcChildren = &(dragItem->_parent->_children);
|
||||
QList<Node*>* destChildren = &(dropItem->_parent->_children);
|
||||
QList<FluNode*>* srcChildren = &(dragItem->_parent->_children);
|
||||
QList<FluNode*>* destChildren = &(dropItem->_parent->_children);
|
||||
int srcIndex = srcChildren->indexOf(dragItem);
|
||||
int destIndex = destChildren->indexOf(dropItem);
|
||||
dragItem->_depth = dropItem->_depth;
|
||||
dragItem->_parent = dropItem->_parent;
|
||||
if(dragItem->hasChildren()){
|
||||
QList<Node*> stack = dragItem->_children;
|
||||
QList<FluNode*> stack = dragItem->_children;
|
||||
foreach (auto node, stack) {
|
||||
node->_depth = dragItem->_depth+1;
|
||||
}
|
||||
@ -275,7 +275,7 @@ void FluTreeModel::dragAnddrop(int dragIndex,int dropIndex,bool isDropTopArea){
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
stack.pop_back();
|
||||
QList<Node*> children = item->_children;
|
||||
QList<FluNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
@ -318,14 +318,14 @@ void FluTreeModel::refreshNode(int row){
|
||||
Q_EMIT dataChanged(index(row,0),index(row,0));
|
||||
};
|
||||
|
||||
Node* FluTreeModel::getNode(int row){
|
||||
FluNode* FluTreeModel::getNode(int row){
|
||||
return _rows.at(row);
|
||||
}
|
||||
|
||||
void FluTreeModel::allExpand(){
|
||||
beginResetModel();
|
||||
QList<Node*> data;
|
||||
QList<Node*> stack = _root->_children;
|
||||
QList<FluNode*> data;
|
||||
QList<FluNode*> stack = _root->_children;
|
||||
std::reverse(stack.begin(), stack.end());
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
@ -334,7 +334,7 @@ void FluTreeModel::allExpand(){
|
||||
item->_isExpanded = true;
|
||||
}
|
||||
data.append(item);
|
||||
QList<Node*> children = item->_children;
|
||||
QList<FluNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
@ -347,7 +347,7 @@ void FluTreeModel::allExpand(){
|
||||
}
|
||||
void FluTreeModel::allCollapse(){
|
||||
beginResetModel();
|
||||
QList<Node*> stack = _root->_children;
|
||||
QList<FluNode*> stack = _root->_children;
|
||||
std::reverse(stack.begin(), stack.end());
|
||||
while (stack.count() > 0) {
|
||||
auto item = stack.at(stack.count()-1);
|
||||
@ -355,7 +355,7 @@ void FluTreeModel::allCollapse(){
|
||||
if(item->hasChildren()){
|
||||
item->_isExpanded = false;
|
||||
}
|
||||
QList<Node*> children = item->_children;
|
||||
QList<FluNode*> children = item->_children;
|
||||
if(!children.isEmpty()){
|
||||
std::reverse(children.begin(), children.end());
|
||||
foreach (auto c, children) {
|
||||
|
@ -8,9 +8,9 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
/**
|
||||
* @brief The Node class
|
||||
* @brief The FluNode class
|
||||
*/
|
||||
class Node : public QObject{
|
||||
class FluNode : public QObject{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString key READ key CONSTANT)
|
||||
Q_PROPERTY(QString title READ title CONSTANT)
|
||||
@ -18,14 +18,14 @@ class Node : public QObject{
|
||||
Q_PROPERTY(bool isExpanded READ isExpanded CONSTANT)
|
||||
Q_PROPERTY(bool checked READ checked CONSTANT)
|
||||
public:
|
||||
explicit Node(QObject *parent = nullptr);
|
||||
explicit FluNode(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 bool hasChildren(){ return !_children.isEmpty();};
|
||||
Q_INVOKABLE bool hasNextNodeByIndex(int index){
|
||||
Node* p = this;
|
||||
FluNode* p = this;
|
||||
for(int i=0;i<(_depth - index -1);i++){
|
||||
p = p->_parent;
|
||||
}
|
||||
@ -75,15 +75,15 @@ public:
|
||||
int _depth=0;
|
||||
bool _checked = false;
|
||||
bool _isExpanded=true;
|
||||
QList<Node*> _children;
|
||||
Node* _parent = nullptr;
|
||||
QList<FluNode*> _children;
|
||||
FluNode* _parent = nullptr;
|
||||
};
|
||||
|
||||
class FluTreeModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int,dataSourceSize)
|
||||
Q_PROPERTY_AUTO(QList<Node*>,selectionModel)
|
||||
Q_PROPERTY_AUTO(QList<FluNode*>,selectionModel)
|
||||
QML_NAMED_ELEMENT(FluTreeModel)
|
||||
QML_ADDED_IN_MINOR_VERSION(1)
|
||||
public:
|
||||
@ -96,23 +96,23 @@ public:
|
||||
QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
Q_INVOKABLE void removeRows(int row,int count);
|
||||
Q_INVOKABLE void insertRows(int row,QList<Node*> data);
|
||||
Q_INVOKABLE void insertRows(int row,QList<FluNode*> data);
|
||||
Q_INVOKABLE QObject* getRow(int row);
|
||||
Q_INVOKABLE void setData(QList<Node*> data);
|
||||
Q_INVOKABLE void setData(QList<FluNode*> 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 Node* getNode(int row);
|
||||
Q_INVOKABLE FluNode* getNode(int row);
|
||||
Q_INVOKABLE void refreshNode(int row);
|
||||
Q_INVOKABLE void checkRow(int row,bool chekced);
|
||||
Q_INVOKABLE bool hitHasChildrenExpanded(int row);
|
||||
Q_INVOKABLE void allExpand();
|
||||
Q_INVOKABLE void allCollapse();
|
||||
private:
|
||||
QList<Node*> _rows;
|
||||
QList<Node*> _dataSource;
|
||||
Node* _root = nullptr;
|
||||
QList<FluNode*> _rows;
|
||||
QList<FluNode*> _dataSource;
|
||||
FluNode* _root = nullptr;
|
||||
};
|
||||
|
||||
#endif // FLUTREEMODEL_H
|
||||
|
Loading…
Reference in New Issue
Block a user