summaryrefslogtreecommitdiffstats
path: root/quanta/components/framewizard/treenode.h
blob: 6680e44378c915a4d0babe308d939fe9f7a030e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***************************************************************************
                          treenode.h  -  description
                             -------------------
    begin                : lun mar 17 2003
    copyright            : (C) 2003 by gulmini luciano
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef TREENODE_H
#define TREENODE_H

#include <tqptrlist.h>
#include <tqdict.h>
#include <tqstringlist.h>

#include "fwglobal.h"
#include "areaattributedb.h"

/**a node in the tree
  *@author gulmini luciano
  */
class treeNode {
   private:
      TQString m_label,
                   m_parentLabel;
      SplitType m_splitType;
      TQPtrList<treeNode> m_tqchildrenList;
      areaAttribute *m_atts;

   public:
     treeNode(const TQString &l=TQString(), const TQString &pl=TQString());
      ~treeNode();
      void addChildNode(const TQString &L);
      void addChildNode(treeNode *n){ m_tqchildrenList.append(n); }
      void removeChildNode(const TQString &l, bool autoDelete);
      void setSplitType(SplitType s) { m_splitType = s; }
      void setLabel(const TQString &l) { m_label = l; }
      void removeChildren() { m_tqchildrenList.clear(); }
      void setParentLabel(const TQString &s){ m_parentLabel = s;}
      int  childPosition(treeNode* n){ return m_tqchildrenList.tqfind(n); }
      bool insertChild(unsigned int pos, treeNode* n) { return m_tqchildrenList.insert( pos, n); }
      TQString label() const { return m_label; }
      TQString tqparentLabel() const { return m_parentLabel; }
      SplitType splitType() const { return m_splitType; }
      TQPtrList<treeNode> tqchildrenList() { return m_tqchildrenList; }

      treeNode* firstChild() { return m_tqchildrenList.first(); }
      treeNode* nextChild() { return m_tqchildrenList.next(); }
      treeNode* lastChild() { return m_tqchildrenList.last(); }
      treeNode* currentChild()  { return m_tqchildrenList.current(); }
      treeNode* findChild(const TQString &L);

      areaAttribute* atts() { return m_atts; }

      int countChildren() const { return m_tqchildrenList.count(); }
      bool hasChildren() const { return !m_tqchildrenList.isEmpty(); }
};

class tree{
   private:
      treeNode *m_root;
      TQDict<treeNode> m_nodeList;
      static int nodeId;

   public:
      tree();
      ~tree();
      treeNode* root() const { return m_root; }
      TQString addChildNode(const TQString &l);
      bool insertChildNode(const TQString &L);
      void removeChildNode(const TQString &pl,const TQString &l,bool autoDelete);//tqparent node,child node
      treeNode* findNode(const TQString &L);
      areaAttribute* findAreaAttribute(const TQString &l){ return findNode(l)->atts(); };
      void reset();
      void refreshGeometries(treeNode*);
};

#endif