COPASI API  4.16.103
CQReactionsWidget.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) 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 #include "CQReactionsWidget.h"
12 
13 #include <QtGui/QHeaderView>
14 #include <QtGui/QClipboard>
15 #include <QtGui/QKeyEvent>
16 
17 #include "copasi.h"
18 
19 #include "qtUtilities.h"
20 #include "CQMessageBox.h"
21 
22 #include "model/CModel.h"
25 
26 /*
27  * Constructs a CQReactionsWidget which is a child of 'parent', with the
28  * name 'name'.'
29  */
30 CQReactionsWidget::CQReactionsWidget(QWidget* parent, const char* name)
31  : CopasiWidget(parent, name)
32 {
33  setupUi(this);
34 
35  //Create Source Data Model.
36  mpReactionDM = new CQReactionDM(this);
37 
38  //Create the Proxy Model for sorting/filtering and set its properties.
40  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
41  mpProxyModel->setFilterKeyColumn(-1);
42 
43  mpTblReactions->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
44  mpTblReactions->verticalHeader()->hide();
45  mpTblReactions->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
46 
48 
49  // Connect the table widget
50  connect(mpReactionDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
51  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
52  connect(mpReactionDM, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
53  this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)));
54  connect(mpLEFilter, SIGNAL(textChanged(const QString &)),
55  this, SLOT(slotFilterChanged()));
56 }
57 
58 /*
59  * Destroys the object and frees any allocated resources
60  */
62 {
65  // no need to delete child widgets, Qt does it all for us
66 }
67 
69 {
72 }
73 
75 {
76  if (mpTblReactions->hasFocus())
78 
80 }
81 
83 {
84  const QItemSelectionModel * pSelectionModel = mpTblReactions->selectionModel();
85 
86  QModelIndexList mappedSelRows;
87  size_t i, imax = mpReactionDM->rowCount();
88 
89  for (i = 0; i < imax; i++)
90  {
91  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
92  {
93  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
94  }
95  }
96 
97  if (mappedSelRows.empty())
98  {return;}
99 
100  mpReactionDM->removeRows(mappedSelRows);
101 }
102 
104 {
105 
106  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Reactions?",
107  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
108 
109  if (ret == QMessageBox::Yes)
110  {
111  mpReactionDM->clear();
112  }
113 
115 }
116 
118 {
119  if (!mIgnoreUpdates)
120  {
121  enterProtected();
122  }
123 
124  return true;
125 }
126 
128 {
129  return true;
130 }
131 
133 {
134  if (mpTblReactions->selectionModel() != NULL)
135  {
136  disconnect(mpTblReactions->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
137  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
138  }
139 
140  mpProxyModel->setSourceModel(mpReactionDM);
141  //Set Model for the TableView
142  mpTblReactions->setModel(NULL);
143  mpTblReactions->setModel(mpProxyModel);
144  connect(mpTblReactions->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
145  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
147  mpTblReactions->resizeColumnsToContents();
149 
150  return true;
151 }
152 
154 {
155  bool selected = false;
156 
157  QModelIndexList selRows = mpTblReactions->selectionModel()->selectedRows();
158 
159  if (selRows.size() == 0)
160  selected = false;
161  else
162  {
163  if (selRows.size() == 1)
164  {
165  if (mpReactionDM->isDefaultRow(mpProxyModel->mapToSource(selRows[0])))
166  selected = false;
167  else
168  selected = true;
169  }
170  else
171  selected = true;
172  }
173 
174  mpBtnDelete->setEnabled(selected);
175 
176  if (mpProxyModel->rowCount() - 1)
177  mpBtnClear->setEnabled(true);
178  else
179  mpBtnClear->setEnabled(false);
180 }
181 
182 void CQReactionsWidget::slotSelectionChanged(const QItemSelection& C_UNUSED(selected),
183  const QItemSelection& C_UNUSED(deselected))
184 {
186 }
187 
188 void CQReactionsWidget::dataChanged(const QModelIndex& C_UNUSED(topLeft),
189  const QModelIndex& C_UNUSED(bottomRight))
190 {
191  mpTblReactions->resizeColumnsToContents();
194 }
195 
196 void CQReactionsWidget::slotDoubleClicked(const QModelIndex proxyIndex)
197 {
198  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
199 
200  if (index.row() < 0)
201  return;
202 
203  if (mpReactionDM->isDefaultRow(index))
204  {
206  }
207 
208  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
210  assert(pDataModel != NULL);
211  CModel * pModel = pDataModel->getModel();
212 
213  if (pModel == NULL)
214  return;
215 
216  std::string key = pModel->getReactions()[index.row()]->getKey();
217 
218  if (CCopasiRootContainer::getKeyFactory()->get(key))
220 }
221 
223 {
224  if (ev->key() == Qt::Key_Delete)
226  else if (ev->key() == Qt::Key_C && (ev->modifiers() & Qt::ControlModifier))
227  {
228  QModelIndexList selRows = mpTblReactions->selectionModel()->selectedRows(0);
229 
230  if (selRows.empty())
231  {return;}
232 
233  QString str;
234  QModelIndexList::const_iterator i;
235 
236  for (i = selRows.begin(); i != selRows.end(); ++i)
237  {
238  for (int x = 0; x < mpReactionDM->columnCount(); ++x)
239  {
240  if (!mpTblReactions->isColumnHidden(x))
241  {
242  if (!str.isEmpty())
243  str += "\t";
244 
245  str += mpReactionDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
246  }
247  }
248 
249  str += "\n";
250  }
251 
252  QApplication::clipboard()->setText(str);
253  }
254 }
255 
257 {
258  QRegExp regExp(mpLEFilter->text() + "|New Reaction", Qt::CaseInsensitive, QRegExp::RegExp);
259  mpProxyModel->setFilterRegExp(regExp);
260 }
261 
263 {
264  CopasiWidget::setFramework(framework);
265 
266  switch (mFramework)
267  {
268  case 0:
269  mpTblReactions->showColumn(COL_FLUX);
270  mpTblReactions->hideColumn(COL_PARTICLE_FLUX);
271  break;
272 
273  case 1:
274  mpTblReactions->hideColumn(COL_FLUX);
275  mpTblReactions->showColumn(COL_PARTICLE_FLUX);
276  break;
277  }
278 }
#define pdelete(p)
Definition: copasi.h:215
#define COL_FLUX
Definition: CQReactionDM.h:28
objectType
virtual void slotBtnNewClicked()
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
virtual bool clear()
virtual void setFramework(int framework)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
virtual void slotDoubleClicked(const QModelIndex proxyIndex)
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_UNUSED(p)
Definition: copasi.h:220
bool mIgnoreUpdates
Definition: copasiWidget.h:67
CQReactionDM * mpReactionDM
virtual const std::string & getKey() const
#define COL_PARTICLE_FLUX
Definition: CQReactionDM.h:29
ListViews * mpListView
Definition: copasiWidget.h:62
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
virtual void slotBtnClearClicked()
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool enterProtected()
CQSortFilterProxyModel * mpProxyModel
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
static CKeyFactory * getKeyFactory()
virtual void slotBtnDeleteClicked()
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
virtual void slotFilterChanged()
Definition: CModel.h:50
CQReactionsWidget(QWidget *parent=0, const char *name=0)
virtual bool isDefaultRow(const QModelIndex &i) const
virtual void setFramework(int framework)
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
virtual void keyPressEvent(QKeyEvent *ev)
#define COL_ROW_NUMBER