Isis 3 Programmer Reference
TreeView.cpp
1 #include "IsisDebug.h"
2 
3 #include "TreeView.h"
4 
5 #include <QLabel>
6 #include <QVariant>
7 #include <QVBoxLayout>
8 
9 #include "TreeViewContent.h"
10 #include "TreeViewHeader.h"
11 #include "AbstractTreeModel.h"
12 
13 
14 namespace Isis {
15  TreeView::TreeView(QWidget *parent) : QWidget(parent) {
16  nullify();
17 
18  m_active = false;
19 
20  m_content = new TreeViewContent(this);
21  m_header = new TreeViewHeader(m_content, this);
22  connect(m_header, SIGNAL(activated()), this, SIGNAL(activated()));
23  connect(m_content, SIGNAL(treeSelectionChanged()),
24  this, SIGNAL(selectionChanged()));
25  // m_content->setContextMenuPolicy(Qt::CustomContextMenu);
26 
27  QVBoxLayout *layout = new QVBoxLayout;
28  layout->addWidget(m_header);
29  layout->addWidget(m_content);
30  layout->setContentsMargins(0, 0, 0, 0);
31  layout->setSpacing(0);
32 
33  setLayout(layout);
34  }
35 
36 
37  TreeView::~TreeView() {
38  }
39 
40 
41  QSize TreeView::sizeHint() const {
42  if (parentWidget())
43  return QSize(parentWidget()->width() / 4, parentWidget()->height() / 2);
44 
45  return QSize();
46  }
47 
48 
49  QFont TreeView::getContentFont() const {
50  return m_content->font();
51  }
52 
53 
54  void TreeView::setModel(AbstractTreeModel *someModel) {
55  ASSERT(m_content);
56  m_content->setModel(someModel);
57 
58  connect(someModel, SIGNAL(filterProgressChanged(int)),
59  m_header, SLOT(updateFilterProgress(int)));
60  connect(someModel, SIGNAL(filterProgressRangeChanged(int, int)),
61  m_header, SLOT(updateFilterProgressRange(int, int)));
62  connect(someModel, SIGNAL(rebuildProgressChanged(int)),
63  m_header, SLOT(updateRebuildProgress(int)));
64  connect(someModel, SIGNAL(rebuildProgressRangeChanged(int, int)),
65  m_header, SLOT(updateRebuildProgressRange(int, int)));
66  connect(someModel, SIGNAL(filterCountsChanged(int, int)),
67  m_header, SLOT(handleFilterCountsChanged(int, int)));
68 
69  connect(someModel, SIGNAL(modelModified()),
70  this, SIGNAL(selectionChanged()));
71  }
72 
73 
74  AbstractTreeModel *TreeView::getModel() const {
75  return m_content->getModel();
76  }
77 
78 
79  bool TreeView::isActive() const {
80  return m_active;
81  }
82 
83 
84  QString TreeView::getTitle() const {
85  return m_header->getText();
86  }
87 
88 
89  void TreeView::setTitle(QString someTitle) {
90  m_header->setText(someTitle);
91  }
92 
93 
94  void TreeView::deactivate() {
95  m_active = false;
96 
97  ASSERT(m_header);
98  if (m_header)
99  m_header->setActive(false);
100  update();
101  }
102 
103 
104  void TreeView::activate() {
105  m_active = true;
106 
107  ASSERT(m_header);
108  if (m_header)
109  m_header->setActive(true);
110  update();
111  }
112 
113 
114  void TreeView::handleModelSelectionChanged() {
115  m_content->refresh();
116  }
117 
118 
119  void TreeView::nullify() {
120  m_header = NULL;
121  m_content = NULL;
122  }
123 }
void nullify()
Sets all the member variables to NULL.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31