COPASI API  4.16.103
CScanContainerWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include "copasi.h"
16 #include <iostream>
17 
18 #include <QtGui/QApplication>
19 #include <QtGui/QResizeEvent>
20 
21 #include "CScanContainerWidget.h"
22 #include "CScanWidgetScan.h"
23 #include "CScanWidgetRepeat.h"
24 #include "CScanWidgetRandom.h"
25 #include "CUpDownSubwidget.h"
26 
27 CScanContainerWidget::CScanContainerWidget(QWidget * parent, const char * name) :
28  QTableWidget(parent)
29 {
30  if (!name)
31  setObjectName("CScanContainerWidget");
32 
33  horizontalHeader()->setStretchLastSection(true);
34 
35  horizontalHeader()->hide();
36  verticalHeader()->hide();
37 
38  setShowGrid(false);
39 
40  setColumnCount(2);
41  setAutoScroll(true);
42 
43  setSelectionMode(QAbstractItemView::NoSelection);
44 
45  mCopyEnabled = false;
46  //TODO maybe reimplement paintFocus() to make the focus completely invisible
47  // (it is already invisible most of the time)
48 }
49 
51 {}
52 
53 std::vector<QWidget*> CScanContainerWidget::getWidgetList() const
54 {
55  std::vector< QWidget * > ret;
56  QWidget* tmpWidget;
57 
58  int i, imax = rowCount();
59 
60  for (i = 0; i < imax; ++i)
61  {
62  tmpWidget = cellWidget(i, 1);
63 
64  if (tmpWidget)
65  ret.push_back(tmpWidget);
66  }
67 
68  return ret;
69 }
70 
72 {
73  setRowCount(0);
74 }
75 
76 void CScanContainerWidget::addWidget(QWidget * widget, bool controls)
77 {
78  setRowCount(rowCount() + 1);
79 
80  int i = rowCount() - 1;
81 
82  if (controls) //add control widget
83  {
84  CUpDownSubwidget * tmpUD = new CUpDownSubwidget(this);
85  tmpUD->setIndex(i, false, true); //assumes...
86  tmpUD->enableCopy(mCopyEnabled);
87  connect(tmpUD, SIGNAL(del(int)), this, SLOT(slotDel(int)));
88  connect(tmpUD, SIGNAL(up(int)), this, SLOT(slotUp(int)));
89  connect(tmpUD, SIGNAL(down(int)), this, SLOT(slotDown(int)));
90  connect(tmpUD, SIGNAL(copy(int)), this, SLOT(slotCopy(int)));
91  setCellWidget(i, 0, tmpUD);
92 
93  //tell the widget above that it is not the last anymore
94  if (i > 0)
95  {
96  CUpDownSubwidget* tmpWidget = dynamic_cast<CUpDownSubwidget*>(cellWidget(i - 1, 0));
97 
98  if (tmpWidget)
99  tmpWidget->setIndex(i - 1, false, false); //assumes...
100  }
101  }
102 
103  setCellWidget(i, 1, widget);
104 
105  updateIndices();
106  updateTable();
107 }
108 
109 void CScanContainerWidget::insertWidget(QWidget* widget, int row)
110 {
111  if (row == -1)
112  {
113  if (rowCount() == 0)
114  row = 0;
115  else
116  row = rowCount() - 1;
117  }
118 
119  insertRow(row);
120 
121  unsigned C_INT32 i = row;
122 
123  if (true) //add control widget
124  {
125  CUpDownSubwidget * tmpUD = new CUpDownSubwidget(this);
126  tmpUD->enableCopy(mCopyEnabled);
127 
128  connect(tmpUD, SIGNAL(del(int)), this, SLOT(slotDel(int)));
129  connect(tmpUD, SIGNAL(up(int)), this, SLOT(slotUp(int)));
130  connect(tmpUD, SIGNAL(down(int)), this, SLOT(slotDown(int)));
131  connect(tmpUD, SIGNAL(copy(int)), this, SLOT(slotCopy(int)));
132 
133  setCellWidget(i, 0, tmpUD);
134  }
135 
136  setCellWidget(i, 1, widget);
137 
138  updateIndices();
139  updateTable();
140 }
141 
143 {
144  if (index <= 0) return; //do nothing
145 
146  slotDown(index - 1);
147 }
148 
150 {
151  if (index >= rowCount() - 1) return; //do nothing
152 
153  QWidget * pWidget = cellWidget(index, 1);
154  QWidget * pNewWidget = NULL;
155 
156  if (pWidget->objectName() == "CScanWidgetScan")
157  {
158  static_cast< CScanWidgetScan * >(pWidget)->save(NULL);
159  pNewWidget = new CScanWidgetScan(*static_cast< CScanWidgetScan * >(pWidget), this);
160  }
161  else if (pWidget->objectName() == "CScanWidgetRandom")
162  {
163  static_cast< CScanWidgetRandom * >(pWidget)->save(NULL);
164  pNewWidget = new CScanWidgetRandom(*static_cast< CScanWidgetRandom * >(pWidget), this);
165  }
166  else if (pWidget->objectName() == "CScanWidgetRepeat")
167  {
168  static_cast< CScanWidgetRepeat * >(pWidget)->save(NULL);
169  pNewWidget = new CScanWidgetRepeat(*static_cast< CScanWidgetRepeat * >(pWidget), this);
170  }
171 
172  if (pNewWidget != NULL)
173  {
174  removeRow(index);
175  insertWidget(pNewWidget, index + 1);
176  }
177 }
178 
180 {
181  removeRow(index);
182 
183  updateIndices();
184  updateTable();
185 }
186 
188 {emit copyWidget(index);}
189 
191 {
192  //update the indices of the updown widgets
193  CUpDownSubwidget* tmp, *tmp_last, *tmp_next;
194 
195  C_INT32 i, imax = rowCount();
196 
197  for (i = 0; i < imax; ++i)
198  {
199  tmp_last = dynamic_cast<CUpDownSubwidget*>(cellWidget(i - 1, 0));
200  tmp = dynamic_cast<CUpDownSubwidget*>(cellWidget(i, 0));
201  tmp_next = dynamic_cast<CUpDownSubwidget*>(cellWidget(i + 1, 0));
202 
203  if (tmp)
204  {
205  tmp->setIndex(i, (tmp_last == NULL), (tmp_next == NULL));
206  }
207  }
208 }
209 
210 // repaints the whole table
212 {
213  qApp->processEvents();
214 
215  resizeRowsToContents();
216  resizeColumnsToContents();
217 }
218 
219 void CScanContainerWidget::enableCopy(const bool & enable)
220 {mCopyEnabled = enable;}
221 
223 {
224  QTableWidget::resizeEvent(e);
225 
226  resizeRowsToContents();
227  resizeColumnsToContents();
228 }
virtual void setIndex(int, bool, bool)
#define C_INT32
Definition: copasi.h:90
void resizeEvent(QResizeEvent *event)
std::vector< QWidget * > getWidgetList() const
void enableCopy(const bool &enable)
CScanContainerWidget(QWidget *parent=0, const char *name=0)
void enableCopy(const bool &)
void addWidget(QWidget *widget, bool controls=true)
void insertWidget(QWidget *widget, int row=-1)