GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoTabManager.cxx
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 
35 #include "QGoTabManager.h"
36 
37 #include <QTabWidget>
38 
39 #include "QGoMainWindow.h"
40 #include "QGoTabElementBase.h"
41 
42 //--------------------------------------------------------------------------
43 QGoTabManager::QGoTabManager(QGoMainWindow *iMW, QTabWidget *iTW) : m_MainWindow(iMW),
44  m_TabWidget(iTW), m_PreviousTabIndex(-1)
45 {
46 }
47 
48 //--------------------------------------------------------------------------
49 
50 //--------------------------------------------------------------------------
52 {
53 }
54 
55 //--------------------------------------------------------------------------
56 
57 //--------------------------------------------------------------------------
59 {
60  m_MainWindow = iMW;
61 }
62 
63 //--------------------------------------------------------------------------
64 
65 //--------------------------------------------------------------------------
67 {
68  m_TabWidget = iTW;
69 }
70 
71 //--------------------------------------------------------------------------
72 
73 //--------------------------------------------------------------------------
75 {
76  if ( iE )
77  {
78  // First remove all toolbar related to the previous tab
80  //m_MainWindow->m_ModeToolBar->clear();
81 
82  std::list<QGoToolBarStatus*> ListToolBars = iE->GetToolBarsStatus();
83  std::list<QGoToolBarStatus*>::iterator iter =ListToolBars .begin();
84  while (iter != ListToolBars.end())
85  {
86  QGoToolBarStatus* ToolBar= *iter;
87  ToolBar->ClearToolBar();
88  ++iter;
89  }
90 
91  //this->m_MainWindow->m_TraceSettingsToolBar->toggleViewAction()->disconnect(
92  // this->m_MainWindow->m_TraceSettingsToolBar->findChild<QGoTraceSettingsWidget*>("TraceSettingsWidget") );
93  //m_MainWindow->m_TraceSettingsToolBar->clear();
94 
95  // Then remove all actions related to the previous tab from menuView
96  m_MainWindow->menuView->clear();
97 
98  // Then remove all actions from the segmentation menu
99  m_MainWindow->menuSegmentation->clear();
100 
101  // Then remove all actions from the tools menu
102  m_MainWindow->menuTools->clear();
103 
104  // Then remove all actions from the bookmark menu
105  m_MainWindow->menuBookmarks->clear();
106 
107  //then remove all actions from the mode menu:
108  m_MainWindow->menuMode->clear();
109 
110  std::list< QGoTabElementBase::QGoDockWidgetStatusPair > & dock_list = iE->DockWidget();
111 
112  for ( std::list< QGoTabElementBase::QGoDockWidgetStatusPair >::iterator
113  dck_it = dock_list.begin();
114  dck_it != dock_list.end();
115  ++dck_it )
116  {
117  this->GetMainWindow(*dck_it)->removeDockWidget(dck_it->first->m_DockWidget);
118  }
119 
121 
122  std::map< GoFigure::TabDimensionType, std::list< QAction * > >::iterator
123  map_it = m_MainWindow->m_TabDimPluginActionMap.find(dim);
124 
125  if ( map_it != m_MainWindow->m_TabDimPluginActionMap.end() )
126  {
127  for ( std::list< QAction * >::iterator list_it = ( map_it->second ).begin();
128  list_it != ( map_it->second ).end();
129  ++list_it )
130  {
131  ( *list_it )->setDisabled(true);
132  }
133  }
134  }
135 }
136 
137 //--------------------------------------------------------------------------
138 
139 //--------------------------------------------------------------------------
141 {
142  if ( iE )
143  {
144  // Then add all actions related to the new tab from menuView
145  std::vector< QAction * > action_vector2 = iE->ViewActions();
146 
147  for ( std::vector< QAction * >::iterator it = action_vector2.begin();
148  it != action_vector2.end();
149  ++it )
150  {
151  m_MainWindow->menuView->addAction(*it);
153  }
154 
155  this->UpdateViewMenu(iE->ViewNoToolBarActions() );
156 
157  /*action_vector2 = iE->ModeActions();
158 
159  for ( std::vector< QAction * >::iterator it = action_vector2.begin();
160  it != action_vector2.end();
161  ++it )
162  {
163  m_MainWindow->menuMode->addAction(*it);
164  m_MainWindow->m_ModeToolBar->addAction(*it);
165  }*/
166 
167  action_vector2 = iE->SegmentationActions();
168 
169  for ( std::vector< QAction * >::iterator it = action_vector2.begin();
170  it != action_vector2.end();
171  ++it )
172  {
173  m_MainWindow->menuSegmentation->addAction(*it);
174  }
175 
176  action_vector2 = iE->ToolsActions();
177 
178  for ( std::vector< QAction * >::iterator it = action_vector2.begin();
179  it != action_vector2.end();
180  ++it )
181  {
182  m_MainWindow->menuTools->addAction(*it);
183  }
184 
185  action_vector2 = iE->BookmarkActions();
186 
187  for ( std::vector< QAction * >::iterator it = action_vector2.begin();
188  it != action_vector2.end();
189  ++it )
190  {
191  m_MainWindow->menuBookmarks->addAction(*it);
192  }
193 
194  std::list<QGoToolBarStatus*> ToolBarList = iE->GetToolBarsStatus();
195  std::list<QGoToolBarStatus*>::iterator iter = ToolBarList.begin();
196  while (iter != ToolBarList.end() )
197  {
198  QGoToolBarStatus* ToolBar = *iter;
199  ToolBar->SetUpToolBar();
200  ++iter;
201  }
202 
203  /*QAction* TraceSettingsAction =
204  m_MainWindow->m_TraceSettingsToolBar->addWidget(iE->TraceSettingsWidget() );
205  TraceSettingsAction->setVisible(true);
206  iE->SetTraceSettingsToolBar(m_MainWindow->m_TraceSettingsToolBar);
207  m_MainWindow->m_TraceSettingsToolBar->setVisible(
208  iE->TraceSettingsWidget()->GetIsToolBarVisible());
209 
210  QObject::connect(this->m_MainWindow->m_TraceSettingsToolBar->toggleViewAction(),
211  SIGNAL( toggled (bool) ),
212  this->m_MainWindow->m_TraceSettingsToolBar->findChild<QGoTraceSettingsWidget*>("TraceSettingsWidget"),
213  SLOT(SetVisibilityStatus(bool) ) );*/
214 
215  std::list< QGoTabElementBase::QGoDockWidgetStatusPair > dock_list = iE->DockWidget();
216 
217  for ( std::list< QGoTabElementBase::QGoDockWidgetStatusPair >::iterator
218  dck_it = dock_list.begin();
219  dck_it != dock_list.end();
220  ++dck_it )
221  {
222  if ( dck_it->first->m_Attached )
223  {
224  if ( dck_it->first->m_Area == Qt::NoDockWidgetArea )
225  {
226  dck_it->first->m_Area = dck_it->first->m_DefaultArea;
227  }
228  this->GetMainWindow(*dck_it)->addDockWidget(dck_it->first->m_Area, dck_it->second);
229  }
230  dck_it->second->setVisible(dck_it->first->m_Visibility);
231  }
232 
234 
235  if ( dim == GoFigure::THREE_D_WITH_T )
236  {
238  // import/export in menu
239  //std::cout << "Check if there is a connection with database to update
240  // import/export in menu" << std::endl;
241  }
242 
243  std::map< GoFigure::TabDimensionType, std::list< QAction * > >::iterator
244  map_it = m_MainWindow->m_TabDimPluginActionMap.find(dim);
245 
246  if ( map_it != m_MainWindow->m_TabDimPluginActionMap.end() )
247  {
248  for ( std::list< QAction * >::iterator list_it = ( map_it->second ).begin();
249  list_it != ( map_it->second ).end();
250  ++list_it )
251  {
252  ( *list_it )->setEnabled(true);
253  }
254  }
255  }
256 }
257 
258 //--------------------------------------------------------------------------
259 
260 //--------------------------------------------------------------------------
262 {
263  if ( m_PreviousTabIndex != -1 )
264  {
265  QGoTabElementBase *w =
266  dynamic_cast< QGoTabElementBase * >(
268 
269  ClearTabElement(w);
270  }
271 
272  if ( iIdx != -1 )
273  {
274  QGoTabElementBase *w2 =
275  dynamic_cast< QGoTabElementBase * >(
276  m_TabWidget->widget(iIdx) );
277 
278  SetUpTabElement(w2);
279  }
280 
281  m_PreviousTabIndex = iIdx;
282 }
283 
284 //--------------------------------------------------------------------------
285 
286 //--------------------------------------------------------------------------
287 void QGoTabManager::UpdateBookmarkMenu(std::vector< QAction * > iBookmarkActions)
288 {
289  m_MainWindow->menuBookmarks->clear();
290 
291  for ( std::vector< QAction * >::iterator it = iBookmarkActions.begin();
292  it != iBookmarkActions.end();
293  ++it )
294  {
295  m_MainWindow->menuBookmarks->addAction(*it);
296  }
297 }
298 
299 //--------------------------------------------------------------------------
300 
301 //--------------------------------------------------------------------------
302 void QGoTabManager::UpdateViewMenu(std::vector< QAction* > iViewNoToolBarActions)
303 {
304  for ( std::vector< QAction * >::iterator it = iViewNoToolBarActions.begin();
305  it != iViewNoToolBarActions.end();
306  ++it )
307  {
308  m_MainWindow->menuView->addAction(*it);
309  }
310 }
311 //--------------------------------------------------------------------------
312 
313 //--------------------------------------------------------------------------
315 {
316  if ( idx >= 0 )
317  {
318  QGoTabElementBase *w =
319  dynamic_cast< QGoTabElementBase * >( m_TabWidget->widget(idx) );
320  if ( w )
321  {
322  w->WriteSettings();
323  ClearTabElement(w);
324  delete w;
325  w = 0;
326  }
327  // m_TabWidget->removeTab( idx );
328  }
329 }
330 
331 //--------------------------------------------------------------------------
332 
333 //--------------------------------------------------------------------------
335 {
336  int NumberOfTabs = m_TabWidget->count();
337 
338  for ( int i = 0; i < NumberOfTabs; i++ )
339  {
340  int k = NumberOfTabs - 1 - i;
341  QGoTabElementBase *w =
342  dynamic_cast< QGoTabElementBase * >( m_TabWidget->widget(k) );
343 
344  if ( w )
345  {
346  ClearTabElement(w);
347 
348  w->WriteSettings();
349  delete w;
350  }
351  }
352 
355  m_TabWidget->clear();
356 }
357 
358 //--------------------------------------------------------------------------
359 
360 //--------------------------------------------------------------------------
363 {
364  if (iDockStatus.first->m_MainWindow != 0)
365  {
366  return iDockStatus.first->m_MainWindow;
367  }
368  else
369  {
370  return m_MainWindow;
371  }
372 }
QToolBar * m_ViewToolBar
virtual std::vector< QAction * > ViewActions()
Get all actions belonging to View Menu and Toolbar.
Abstract class for one tab element in GoFigure2.
int m_PreviousTabIndex
Definition: QGoTabManager.h:80
QGoTabManager(QGoMainWindow *iMW=0, QTabWidget *iTW=0)
void addAction(QAction *action)
void removeDockWidget(QDockWidget *dockwidget)
void ClearToolBar()
clear the toolbar and disconnect all the slots inside this class connected to the toolbar ...
QMainWindow * GetMainWindow(QGoDockWidgetStatusPair iDockStatus)
QGoMainWindow * m_MainWindow
Definition: QGoTabManager.h:78
void clear()
QGoTabElementBase::QGoDockWidgetStatusPair QGoDockWidgetStatusPair
Definition: QGoTabManager.h:58
GoFigure2&#39;s main window.
Definition: QGoMainWindow.h:71
std::map< GoFigure::TabDimensionType, std::list< QAction * > > m_TabDimPluginActionMap
virtual std::list< QGoDockWidgetStatusPair > & DockWidget()
Get all actions belonging to Mode Menu and Toolbar.
virtual GoFigure::TabDimensionType GetTabDimensionType() const =0
Get the dimension type of the underlying data set.
virtual void WriteSettings()=0
Write Settings for the tab element.
void SetMainWindow(QGoMainWindow *iMW)
Set the MainWindow if it has not been set by calling the constructor.
void CloseTab(int idx)
virtual std::list< QGoToolBarStatus * > GetToolBarsStatus()
void UpdateBookmarkMenu(std::vector< QAction * > iBookmarkActions)
virtual std::vector< QAction * > ViewNoToolBarActions()
Get all actions belonging to View Menu only.
virtual std::vector< QAction * > BookmarkActions()
Get all actions belonging to Bookmark Menu and Toolbar.
QWidget * widget(int index) const
void SetUpTabElement(QGoTabElementBase *iE)
QTabWidget * m_TabWidget
Definition: QGoTabManager.h:79
void ClearTabElement(QGoTabElementBase *iE)
QToolBar * m_ModeToolBar
void addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget)
void SetUpToolBar()
add all the actions coontained in the m_VectorAction into the toolbar and connect the slots ...
void UpdateViewMenu(std::vector< QAction * > iViewNoToolBarActions)
void ChangeCurrentTab(int iIdx)
void addAction(QAction *action)
virtual std::vector< QAction * > ToolsActions()
Get all actions belonging to Tools Menu and Toolbar.
void SetTabWidget(QTabWidget *iTW)
Set the TabWidget if it has not been set by calling the constructor.
void clear()
virtual std::vector< QAction * > SegmentationActions()
Get all actions belonging to Segmentation Menu and Toolbar.