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