QGpCoreTools/TreeContainer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpCoreTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created: 2011-05-16
00022 **  Authors:
00023 **    Marc Wathelet (ISTerre, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef TREECONTAINER_H
00028 #define TREECONTAINER_H
00029 
00030 #include "TreeItem.h"
00031 #include "QGpCoreToolsDLLExport.h"
00032 
00033 namespace QGpCoreTools {
00034 
00035   class QGPCORETOOLS_EXPORT TreeContainer : public TreeItem
00036   {
00037   public:
00038     TreeContainer(TreeContainer * parent=0) : TreeItem(parent) {}
00039     virtual ~TreeContainer();
00040 
00041     TreeItem * childAt(int index) {return _children.at(index);}
00042     const TreeItem * childAt(int index) const {return _children.at(index);}
00043     int childrenCount() const {return _children.count();}
00044     int rank() const {return TreeItem::rank();}
00045     int rank(const TreeItem * item) const {return _children.indexOf(const_cast<TreeItem *>(item));}
00046     virtual void setRank(int r) {TreeItem::setRank(r);}
00047     virtual bool isContainer() const {return true;}
00048 
00049     typedef QList<TreeItem *>::iterator iterator;
00050     typedef QList<TreeItem *>::const_iterator const_iterator;
00051     iterator begin() {return _children.begin();}
00052     iterator end() {return _children.end();}
00053     const_iterator begin() const {return _children.begin();}
00054     const_iterator end() const {return _children.end();}
00055 
00056     int containerCount() const;
00057     TreeContainer * containerAt(int index) const;
00058     int containerIndex() const;
00059 
00060     bool canTakeChildren(const TreeContainer * o) const;
00061     void takeChildren(TreeContainer * o);
00062   protected:
00063     virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const;
00064   private:
00065     friend class TreeItem;
00066 
00067     void setRank(int oldr, int newr);
00068     void addChild(TreeItem * item) {_children.append(item);}
00069     bool takeChild(TreeItem * item);
00070 
00071     QList<TreeItem *> _children;
00072   };
00073 
00074 } // namespace QGpCoreTools
00075 
00076 #endif // TREECONTAINER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines