Isis 3 Programmer Reference
TabBar.cpp
1 #include "TabBar.h"
2 
3 #include <cstddef>
4 #include <iostream>
5 
6 #include <QVector>
7 
8 #include "Tab.h"
9 
10 using std::cerr;
11 
12 
13 namespace Isis
14 {
19  {
20  tabs = NULL;
21 
22  tabs = new QVector< Tab * > ();
23  radioStyleTabs = false;
24  }
25 
26 
29  {
30  if (tabs)
31  {
32  delete tabs;
33  tabs = NULL;
34  }
35  }
36 
37 
44  void TabBar::addTab(Tab * newTab)
45  {
46  const int & tabCountBeforeAddition = tabs->size();
47  newTab->setPosition(tabCountBeforeAddition);
48  connect(newTab, SIGNAL(clicked(const int &)), this,
49  SLOT(tabClicked(const int &)));
50  tabs->push_back(newTab);
51 
52  newTab->setSelected(false);
53  addAction(newTab);
54  }
55 
56 
66  void TabBar::setRadioStyle(const bool & radioStyle)
67  {
68  radioStyleTabs = radioStyle;
69  }
70 
71 
76  {
77  return radioStyleTabs;
78  }
79 
80 
84  int TabBar::size() const
85  {
86  return tabs->size();
87  }
88 
89 
98  void TabBar::setSelected(const int & index, const bool & status)
99  {
100  if (index >= 0 && index < tabs->size())
101  (*tabs)[index]->setSelected(status);
102  }
103 
104 
111  bool TabBar::isSelected(const int &index)
112  {
113  if (index >= 0 && index < tabs->size() && (*tabs)[index]->isSelected())
114  return true;
115 
116  return false;
117  }
118 
119 
124  {
125  for (int i = 0; i < tabs->size(); i++)
126  if ((*tabs)[i]->isSelected())
127  return false;
128 
129  return true;
130  }
131 
132 
139  void TabBar::setEnabled(bool newEnabledStatus)
140  {
141  QToolBar::setEnabled(newEnabledStatus);
142 
143  for (int i = 0; i < size(); i++)
144  (*tabs)[i]->setEnabled(newEnabledStatus);
145  }
146 
147 
163  void TabBar::tabClicked(const int & index)
164  {
165  if (!radioStyleTabs || noOthersInGrpSelected(index))
166  {
167  (*tabs)[index]->setSelected(!(*tabs)[index]->isSelected());
168  }
169  else
170  {
171  deselectOthersInGrp(index);
172  (*tabs)[index]->setSelected(true);
173  }
174  }
175 
176 
184  bool TabBar::noOthersInGrpSelected(const int & index) const
185  {
186  const int & thisGrp = tabs->at(index)->getRadioGroup();
187  for (int i = 0; i < tabs->size(); i++)
188  {
189  if (index != i)
190  {
191  const int & otherGrp = tabs->at(i)->getRadioGroup();
192  if (otherGrp == thisGrp && tabs->at(i)->isSelected())
193  return false;
194  }
195  }
196  return true;
197  }
198 
199 
206  void TabBar::deselectOthersInGrp(const int & index)
207  {
208  const int & thisGrp = tabs->at(index)->getRadioGroup();
209  for (int i = 0; i < tabs->size(); i++)
210  {
211  if (index != i)
212  {
213  const int & otherGrp = tabs->at(i)->getRadioGroup();
214  if (otherGrp == thisGrp)
215  (*tabs)[i]->setSelected(false);
216  }
217  }
218  }
219 }
Isis::TabBar::size
int size() const
Definition: TabBar.cpp:84
Isis::TabBar::setRadioStyle
void setRadioStyle(const bool &radioStyle)
If set to true then the effect is that Tabs in the same radio group can only be selected one at a tim...
Definition: TabBar.cpp:66
Isis::TabBar::addTab
virtual void addTab(Tab *newTab)
Adds a Tab to the TabBar.
Definition: TabBar.cpp:44
Isis::TabBar::radioStyle
bool radioStyle()
Definition: TabBar.cpp:75
Isis::TabBar::~TabBar
virtual ~TabBar()
destruct a TabBar
Definition: TabBar.cpp:28
Isis::Tab::setSelected
void setSelected(bool newStatus)
A selected Tab will look visually pressed and have its associatedWidget visible.
Definition: Tab.cpp:86
Isis::Tab::setPosition
void setPosition(const int &newPosition)
set the position of the Tab within a TabBar
Definition: Tab.cpp:42
Isis::TabBar::setSelected
void setSelected(const int &index, const bool &status)
Sets whether the Tab at the specified index is selected or not.
Definition: TabBar.cpp:98
Isis::TabBar::tabClicked
void tabClicked(const int &index)
SLOT which performs actions that need to be done when we get a SIGNAL from a Tab telling us that it h...
Definition: TabBar.cpp:163
Isis::TabBar::TabBar
TabBar()
construct a TabBar
Definition: TabBar.cpp:18
Isis::TabBar::setEnabled
void setEnabled(bool)
Custom setEnabled method that also calls setEnabled for each of our Tabs.
Definition: TabBar.cpp:139
Isis::TabBar::isSelected
bool isSelected(const int &index)
Definition: TabBar.cpp:111
Isis::TabBar::noOthersInGrpSelected
bool noOthersInGrpSelected(const int &index) const
Definition: TabBar.cpp:184
Isis::TabBar::deselectOthersInGrp
void deselectOthersInGrp(const int &index)
Definition: TabBar.cpp:206
QVector
This is free and unencumbered software released into the public domain.
Definition: Calculator.h:18
Isis::TabBar::noneSelected
bool noneSelected()
Definition: TabBar.cpp:123
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::Tab
A Tab is a QAction which shows or hides some other QWidget, which we call associatedWidget.
Definition: Tab.h:42