COPASI API  4.16.103
Public Member Functions | Protected Slots | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
CQReactionsWidget Class Reference

#include <CQReactionsWidget.h>

Inheritance diagram for CQReactionsWidget:
Inheritance graph
[legend]
Collaboration diagram for CQReactionsWidget:
Collaboration graph
[legend]

Public Member Functions

 CQReactionsWidget (QWidget *parent=0, const char *name=0)
 
virtual bool leave ()
 
virtual void setFramework (int framework)
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
 ~CQReactionsWidget ()
 
- Public Member Functions inherited from CopasiWidget
 CopasiWidget (QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
 
bool enter (const std::string &key)
 
CCopasiDataModelgetDataModel ()
 
bool getIgnoreUpdates ()
 
void setIgnoreUpdates (bool v)
 

Protected Slots

virtual void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 
virtual void slotBtnClearClicked ()
 
virtual void slotBtnDeleteClicked ()
 
virtual void slotBtnNewClicked ()
 
virtual void slotDoubleClicked (const QModelIndex proxyIndex)
 
virtual void slotFilterChanged ()
 
virtual void slotSelectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 
- Protected Slots inherited from CopasiWidget
virtual bool protectedNotify (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Protected Member Functions

virtual bool enterProtected ()
 
virtual void keyPressEvent (QKeyEvent *ev)
 

Private Member Functions

void deleteSelectedReactions ()
 
void updateDeleteBtns ()
 

Private Attributes

CQSortFilterProxyModelmpProxyModel
 
CQReactionDMmpReactionDM
 

Additional Inherited Members

- Protected Attributes inherited from CopasiWidget
int mFramework
 
bool mIgnoreUpdates
 
std::string mKey
 
CCopasiDataModelmpDataModel
 
ListViewsmpListView
 
CCopasiObjectmpObject
 

Detailed Description

Definition at line 29 of file CQReactionsWidget.h.

Constructor & Destructor Documentation

CQReactionsWidget::CQReactionsWidget ( QWidget *  parent = 0,
const char *  name = 0 
)

Definition at line 30 of file CQReactionsWidget.cpp.

References COL_ROW_NUMBER, dataChanged(), CopasiWidget::mFramework, mpProxyModel, mpReactionDM, CopasiWidget::protectedNotify(), setFramework(), and slotFilterChanged().

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 }
virtual void setFramework(int framework)
CQReactionDM * mpReactionDM
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
CQSortFilterProxyModel * mpProxyModel
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
virtual void slotFilterChanged()
#define COL_ROW_NUMBER
CQReactionsWidget::~CQReactionsWidget ( )

Definition at line 61 of file CQReactionsWidget.cpp.

References mpProxyModel, mpReactionDM, and pdelete.

62 {
65  // no need to delete child widgets, Qt does it all for us
66 }
#define pdelete(p)
Definition: copasi.h:215
CQReactionDM * mpReactionDM
CQSortFilterProxyModel * mpProxyModel

Member Function Documentation

void CQReactionsWidget::dataChanged ( const QModelIndex &  topLeft,
const QModelIndex &  bottomRight 
)
protectedvirtualslot

Definition at line 188 of file CQReactionsWidget.cpp.

References CopasiWidget::mFramework, setFramework(), and updateDeleteBtns().

Referenced by CQReactionsWidget().

190 {
191  mpTblReactions->resizeColumnsToContents();
194 }
virtual void setFramework(int framework)
void CQReactionsWidget::deleteSelectedReactions ( )
private

Definition at line 82 of file CQReactionsWidget.cpp.

References mpProxyModel, mpReactionDM, CQReactionDM::removeRows(), and CQReactionDM::rowCount().

Referenced by slotBtnDeleteClicked().

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 }
CQReactionDM * mpReactionDM
CQSortFilterProxyModel * mpProxyModel
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
bool CQReactionsWidget::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 132 of file CQReactionsWidget.cpp.

References CopasiWidget::mFramework, mpProxyModel, mpReactionDM, setFramework(), slotSelectionChanged(), and updateDeleteBtns().

Referenced by update().

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 }
virtual void setFramework(int framework)
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
CQReactionDM * mpReactionDM
CQSortFilterProxyModel * mpProxyModel
void CQReactionsWidget::keyPressEvent ( QKeyEvent *  ev)
protectedvirtual

Definition at line 222 of file CQReactionsWidget.cpp.

References CQReactionDM::columnCount(), mpProxyModel, mpReactionDM, and slotBtnDeleteClicked().

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 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
CQReactionDM * mpReactionDM
CQSortFilterProxyModel * mpProxyModel
virtual void slotBtnDeleteClicked()
bool CQReactionsWidget::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 127 of file CQReactionsWidget.cpp.

128 {
129  return true;
130 }
void CQReactionsWidget::setFramework ( int  framework)
virtual

Reimplemented from CopasiWidget.

Definition at line 262 of file CQReactionsWidget.cpp.

References COL_FLUX, COL_PARTICLE_FLUX, CopasiWidget::mFramework, and CopasiWidget::setFramework().

Referenced by CQReactionsWidget(), dataChanged(), and enterProtected().

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 COL_FLUX
Definition: CQReactionDM.h:28
#define COL_PARTICLE_FLUX
Definition: CQReactionDM.h:29
virtual void setFramework(int framework)
void CQReactionsWidget::slotBtnClearClicked ( )
protectedvirtualslot

Definition at line 103 of file CQReactionsWidget.cpp.

References CQBaseDataModel::clear(), mpReactionDM, CQMessageBox::question(), and updateDeleteBtns().

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 }
virtual bool clear()
CQReactionDM * mpReactionDM
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void CQReactionsWidget::slotBtnDeleteClicked ( )
protectedvirtualslot

Definition at line 74 of file CQReactionsWidget.cpp.

References deleteSelectedReactions(), and updateDeleteBtns().

Referenced by keyPressEvent().

75 {
76  if (mpTblReactions->hasFocus())
78 
80 }
void CQReactionsWidget::slotBtnNewClicked ( )
protectedvirtualslot

Definition at line 68 of file CQReactionsWidget.cpp.

References CQBaseDataModel::insertRow(), mpReactionDM, and updateDeleteBtns().

Referenced by slotDoubleClicked().

69 {
72 }
CQReactionDM * mpReactionDM
void CQReactionsWidget::slotDoubleClicked ( const QModelIndex  proxyIndex)
protectedvirtualslot

Definition at line 196 of file CQReactionsWidget.cpp.

References C_INVALID_INDEX, CCopasiRootContainer::getDatamodelList(), CCopasiObject::getKey(), CCopasiRootContainer::getKeyFactory(), CCopasiDataModel::getModel(), CModel::getReactions(), CQBaseDataModel::isDefaultRow(), CopasiWidget::mpListView, mpProxyModel, mpReactionDM, slotBtnNewClicked(), and ListViews::switchToOtherWidget().

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 }
virtual void slotBtnNewClicked()
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
#define C_INVALID_INDEX
Definition: copasi.h:222
CQReactionDM * mpReactionDM
virtual const std::string & getKey() const
ListViews * mpListView
Definition: copasiWidget.h:62
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CQSortFilterProxyModel * mpProxyModel
static CKeyFactory * getKeyFactory()
CCopasiVectorNS< CReaction > & getReactions()
Definition: CModel.cpp:1039
Definition: CModel.h:50
virtual bool isDefaultRow(const QModelIndex &i) const
void CQReactionsWidget::slotFilterChanged ( )
protectedvirtualslot

Definition at line 256 of file CQReactionsWidget.cpp.

References mpProxyModel.

Referenced by CQReactionsWidget().

257 {
258  QRegExp regExp(mpLEFilter->text() + "|New Reaction", Qt::CaseInsensitive, QRegExp::RegExp);
259  mpProxyModel->setFilterRegExp(regExp);
260 }
CQSortFilterProxyModel * mpProxyModel
void CQReactionsWidget::slotSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &  deselected 
)
protectedvirtualslot

Definition at line 182 of file CQReactionsWidget.cpp.

References updateDeleteBtns().

Referenced by enterProtected().

184 {
186 }
bool CQReactionsWidget::update ( ListViews::ObjectType  objectType,
ListViews::Action  action,
const std::string &  key 
)
virtual

Reimplemented from CopasiWidget.

Definition at line 117 of file CQReactionsWidget.cpp.

References enterProtected(), and CopasiWidget::mIgnoreUpdates.

118 {
119  if (!mIgnoreUpdates)
120  {
121  enterProtected();
122  }
123 
124  return true;
125 }
bool mIgnoreUpdates
Definition: copasiWidget.h:67
virtual bool enterProtected()
void CQReactionsWidget::updateDeleteBtns ( )
private

Definition at line 153 of file CQReactionsWidget.cpp.

References CQBaseDataModel::isDefaultRow(), mpProxyModel, and mpReactionDM.

Referenced by dataChanged(), enterProtected(), slotBtnClearClicked(), slotBtnDeleteClicked(), slotBtnNewClicked(), and slotSelectionChanged().

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 }
CQReactionDM * mpReactionDM
CQSortFilterProxyModel * mpProxyModel
virtual bool isDefaultRow(const QModelIndex &i) const

Member Data Documentation

CQSortFilterProxyModel* CQReactionsWidget::mpProxyModel
private
CQReactionDM* CQReactionsWidget::mpReactionDM
private

The documentation for this class was generated from the following files: