]> git.llucax.com Git - z.facultad/75.52/treemulator.git/blob - viewer/view_node.cpp
Agrega ABB (Altas, Bajas y Búsqueda ;) de claves al viewer.
[z.facultad/75.52/treemulator.git] / viewer / view_node.cpp
1
2 #include "view_node.h"
3
4 ViewNode::ViewNode (Canvas::Group *parent, uint num, uint padre, BTreeNodeHeader &header, std::list<BTreeData *> &keys)
5         : Canvas::Group (*parent)
6 {
7         last_selected = NULL;
8         double header_w = ViewBTree::byte_to_pixels * sizeof (BTreeNodeHeader);
9         this->num = num;
10         this->padre = padre;
11
12         /* Fondo */
13         fondo = new Canvas::Rect (*this, 0, 0, ViewBTree::node_width, ViewBTree::node_height);
14         fondo->property_fill_color() = "gray";
15         fondo->property_outline_color() = "black";
16
17         /* Header */
18         Canvas::Rect *h = new Canvas::Rect (*this, 0, 0, header_w, ViewBTree::node_height);
19         h->property_fill_color() = "blue";
20         h->property_outline_color() = "black";
21
22         /* Numero de nodo */
23         std::string node_num;
24         std::stringstream ss;
25         ss << num;
26         ss >> node_num;
27         new Canvas::Text (*this, header_w/2, ViewBTree::node_height/2, node_num);
28
29         double x = header_w;
30
31         std::list<BTreeData *>::iterator it = keys.begin ();
32         while (it != keys.end ()) {
33                 BTreeData *data = (*it);
34                 double w = ViewBTree::byte_to_pixels * data->Size ();
35
36                 ViewBTreeData *v = ViewBTreeData::Create (data, this, x, 0, w+x, ViewBTree::node_height);
37                 v->signal_clicked ().connect ( sigc::mem_fun (this , &ViewNode::on_item_clicked ));
38                 v->signal_double_clicked ().connect ( sigc::mem_fun (this , &ViewNode::on_item_activated ));
39                 x += w;
40                 it++;
41
42                 if (!dynamic_cast<BTreeLeafData *>(data)) {
43                         /* Si no es un dato de una hoja, tiene hijos */
44                         hijos.push_back (data->GetChild ());
45                 }
46         }
47 }
48
49 void ViewNode::on_item_clicked (BTreeData *data, ViewBTreeData *s)
50 {
51         if (last_selected)
52                 if (s != last_selected)
53                         last_selected->SetSelected (false);
54         last_selected = s;
55         m_signal_selected (data, num, this);
56 }
57
58 void ViewNode::on_item_activated (BTreeData *data, ViewBTreeData *s)
59 {
60         /* Solo activo los que tienen hijos */
61         if (dynamic_cast<BTreeLeafData *> (data) == NULL)
62                 m_signal_activated (data, num, this);
63 }
64
65 ViewNode::type_signal_selected ViewNode::signal_selected ()
66 {
67         return m_signal_selected;
68 }
69
70 ViewNode::type_signal_activated ViewNode::signal_activated ()
71 {
72         return m_signal_activated;
73 }
74
75 void ViewNode::SetSelected (bool b)
76 {
77         if (last_selected) {
78                 last_selected->SetSelected (b);
79         }
80 }
81