/*
 * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 * 
**/
#ifndef TREEITEM_H
#define TREEITEM_H

#include <QList>
#include <QVariant>

class TreeItem
{
public:
    TreeItem(const QList<QVariant> &data, TreeItem *parent=nullptr,
             int uid = -1, int index = 0);
    ~TreeItem();

    void appendChild(TreeItem *child);
    void insertChild(int pos,TreeItem *child);
    TreeItem *child(int row);
    int childCount() const;
    int columnCount() const;
    int row() const;
    TreeItem *parent();
    void setParent(TreeItem *parent);
    QVariant data(int column) const;
    void setData(int column, const QVariant &data);
    int getIndex();
    void setIndex(int index);
    bool removeChild(int row, bool recursive = false);
    bool removeChildren(int row, int count, bool recursive = false);
    void removeChildrenNoDelete();
    void cleanChildren();
    void setUid(int uid);
    int getUid();
    static bool lessThan_L(const TreeItem * item1, const TreeItem * item2);
    void sort();

private:
    QList<QVariant> itemData;
    TreeItem *parentItem;
    QList<TreeItem*> childItems;
    int index;
    int uid;
};

#endif // TREEITEM_H
