File indexing completed on 2024-04-28 17:02:20

0001 /*
0002    This file is part of Massif Visualizer
0003 
0004    Copyright 2010 Milian Wolff <mail@milianw.de>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Lesser General Public
0008    License as published by the Free Software Foundation; either
0009    version 2.1 of the License, or (at your option) version 3, or any
0010    later version accepted by the membership of KDE e.V. (or its
0011    successor approved by the membership of KDE e.V.), which shall
0012    act as a proxy defined in Section 6 of version 3 of the license.
0013 
0014    This library is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017    Lesser General Public License for more details.
0018 
0019    You should have received a copy of the GNU Lesser General Public
0020    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef TREELEAFITEM_H
0024 #define TREELEAFITEM_H
0025 
0026 #include <QtCore/QString>
0027 #include <QtCore/QVector>
0028 #include <QtCore/QMetaType>
0029 
0030 namespace Massif {
0031 
0032 class TreeLeafItem
0033 {
0034 public:
0035     TreeLeafItem();
0036     ~TreeLeafItem();
0037 
0038     /**
0039      * Sets the label for this leaf item.
0040      */
0041     void setLabel(const QByteArray& label);
0042     /**
0043      * @return The label for this leaf item.
0044      */
0045     QByteArray label() const;
0046 
0047     /**
0048      * Sets the cost for this item in bytes.
0049      */
0050     void setCost(quint64 bytes);
0051     /**
0052      * @return The cost for this item in bytes.
0053      */
0054     quint64 cost() const;
0055 
0056     /**
0057      * Adds @p leaf as child of this item.
0058      * This item takes ownership.
0059      */
0060     void addChild(TreeLeafItem* leaf);
0061 
0062     /**
0063      * Sets @p leafs as children of this item and takes ownership.
0064      * No existing children will be deleted and might get leaked
0065      * if you do not do this yourself.
0066      */
0067     void setChildren(const QVector<TreeLeafItem*>& leafs);
0068 
0069     /**
0070      * @return The children of this leaf.
0071      */
0072     QVector<TreeLeafItem*> children() const;
0073 
0074     /**
0075      * @return The parent tree leaf item or zero, if this is the root node.
0076      */
0077     TreeLeafItem* parent() const;
0078 
0079 private:
0080     QByteArray m_label;
0081     quint64 m_cost;
0082     QVector<TreeLeafItem*> m_children;
0083 
0084     TreeLeafItem* m_parent;
0085 };
0086 
0087 }
0088 
0089 Q_DECLARE_METATYPE(Massif::TreeLeafItem*);
0090 Q_DECLARE_METATYPE(const Massif::TreeLeafItem*);
0091 
0092 #endif // TREELEAFITEM_H