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

#include <CQSpeciesWidget.h>

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

Public Member Functions

 CQSpeciesWidget (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)
 
 ~CQSpeciesWidget ()
 
- 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)
 
void refreshCompartments ()
 

Private Member Functions

void deleteSelectedSpecies ()
 
void updateDeleteBtns ()
 

Private Attributes

QStringList mCompartments
 
CQComboDelegatempCompartmentDelegate
 
CQSortFilterProxyModelmpProxyModel
 
CQSpecieDMmpSpecieDM
 
CQIndexComboDelegatempTypeDelegate
 

Additional Inherited Members

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

Detailed Description

Definition at line 30 of file CQSpeciesWidget.h.

Constructor & Destructor Documentation

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

Definition at line 30 of file CQSpeciesWidget.cpp.

References COL_COMPARTMENT, COL_ROW_NUMBER, COL_TYPE_SPECIES, dataChanged(), CQSpecieDM::getTypes(), mCompartments, mpCompartmentDelegate, mpProxyModel, mpSpecieDM, mpTypeDelegate, CopasiWidget::protectedNotify(), and slotFilterChanged().

31  : CopasiWidget(parent, name)
32 {
33  setupUi(this);
34 
35  //Create Source Data Model.
36  mpSpecieDM = new CQSpecieDM(this);
37 
38  //Create the Proxy Model for sorting/filtering and set its properties.
40  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
41  mpProxyModel->setFilterKeyColumn(-1);
42  mpProxyModel->setSourceModel(mpSpecieDM);
43 
44  mpTblSpecies->setModel(mpProxyModel);
45 
46  //Setting values for Compartment comboBox
48  mpTblSpecies->setItemDelegateForColumn(COL_COMPARTMENT, mpCompartmentDelegate);
49 
50  //Setting values for Types comboBox
52  mpTblSpecies->setItemDelegateForColumn(COL_TYPE_SPECIES, mpTypeDelegate);
53 
54  mpTblSpecies->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
55  mpTblSpecies->verticalHeader()->hide();
56  mpTblSpecies->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
57 
58  // Connect the table widget
59  connect(mpSpecieDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
60  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
61  connect(mpSpecieDM, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
62  this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)));
63  connect(mpLEFilter, SIGNAL(textChanged(const QString &)),
64  this, SLOT(slotFilterChanged()));
65 }
CQSortFilterProxyModel * mpProxyModel
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
QStringList mCompartments
CQSpecieDM * mpSpecieDM
#define COL_TYPE_SPECIES
Definition: CQSpecieDM.h:28
const QStringList & getTypes()
Definition: CQSpecieDM.cpp:39
virtual void slotFilterChanged()
CQIndexComboDelegate * mpTypeDelegate
#define COL_COMPARTMENT
Definition: CQSpecieDM.h:27
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CQComboDelegate * mpCompartmentDelegate
#define COL_ROW_NUMBER
CQSpeciesWidget::~CQSpeciesWidget ( )

Definition at line 70 of file CQSpeciesWidget.cpp.

References mpCompartmentDelegate, mpProxyModel, mpSpecieDM, mpTypeDelegate, and pdelete.

71 {
76  // no need to delete child widgets, Qt does it all for us
77 }
CQSortFilterProxyModel * mpProxyModel
#define pdelete(p)
Definition: copasi.h:215
CQSpecieDM * mpSpecieDM
CQIndexComboDelegate * mpTypeDelegate
CQComboDelegate * mpCompartmentDelegate

Member Function Documentation

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

Definition at line 201 of file CQSpeciesWidget.cpp.

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

Referenced by CQSpeciesWidget().

203 {
204  mpTblSpecies->resizeColumnsToContents();
208 }
virtual void setFramework(int framework)
void CQSpeciesWidget::deleteSelectedSpecies ( )
private

Definition at line 93 of file CQSpeciesWidget.cpp.

References mpProxyModel, mpSpecieDM, CQSpecieDM::removeRows(), and CQSpecieDM::rowCount().

Referenced by slotBtnDeleteClicked().

94 {
95  const QItemSelectionModel * pSelectionModel = mpTblSpecies->selectionModel();
96 
97  QModelIndexList mappedSelRows;
98  size_t i, imax = mpSpecieDM->rowCount();
99 
100  for (i = 0; i < imax; i++)
101  {
102  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
103  {
104  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
105  }
106  }
107 
108  if (mappedSelRows.empty())
109  {return;}
110 
111  mpSpecieDM->removeRows(mappedSelRows);
112 }
CQSortFilterProxyModel * mpProxyModel
CQSpecieDM * mpSpecieDM
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQSpecieDM.cpp:54
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
Definition: CQSpecieDM.cpp:541
bool CQSpeciesWidget::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 143 of file CQSpeciesWidget.cpp.

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

Referenced by update().

144 {
145  if (mpTblSpecies->selectionModel() != NULL)
146  {
147  disconnect(mpTblSpecies->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
148  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
149  }
150 
151  mpProxyModel->setSourceModel(mpSpecieDM);
152  //Set Model for the TableView
153  mpTblSpecies->setModel(NULL);
154  mpTblSpecies->setModel(mpProxyModel);
155 
156  connect(mpTblSpecies->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
157  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
159  mpTblSpecies->resizeColumnsToContents();
162 
163  return true;
164 }
CQSortFilterProxyModel * mpProxyModel
CQSpecieDM * mpSpecieDM
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
virtual void setFramework(int framework)
void CQSpeciesWidget::keyPressEvent ( QKeyEvent *  ev)
protectedvirtual

Definition at line 236 of file CQSpeciesWidget.cpp.

References CQSpecieDM::columnCount(), mpProxyModel, mpSpecieDM, and slotBtnDeleteClicked().

237 {
238  if (ev->key() == Qt::Key_Delete)
240  else if (ev->key() == Qt::Key_C && (ev->modifiers() & Qt::ControlModifier))
241  {
242  QModelIndexList selRows = mpTblSpecies->selectionModel()->selectedRows(0);
243 
244  if (selRows.empty())
245  {return;}
246 
247  QString str;
248  QModelIndexList::const_iterator i;
249 
250  for (i = selRows.begin(); i != selRows.end(); ++i)
251  {
252  for (int x = 0; x < mpSpecieDM->columnCount(); ++x)
253  {
254  if (!mpTblSpecies->isColumnHidden(x))
255  {
256  if (!str.isEmpty())
257  str += "\t";
258 
259  str += mpSpecieDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
260  }
261  }
262 
263  str += "\n";
264  }
265 
266  QApplication::clipboard()->setText(str);
267  }
268 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQSpecieDM.cpp:59
CQSortFilterProxyModel * mpProxyModel
CQSpecieDM * mpSpecieDM
virtual void slotBtnDeleteClicked()
bool CQSpeciesWidget::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 138 of file CQSpeciesWidget.cpp.

139 {
140  return true;
141 }
void CQSpeciesWidget::refreshCompartments ( )
protected

Definition at line 308 of file CQSpeciesWidget.cpp.

References C_INT32, FROM_UTF8, CCopasiRootContainer::getDatamodelList(), mCompartments, and CCopasiVector< T >::size().

Referenced by dataChanged(), and enterProtected().

309 {
310  const CCopasiVector < CCompartment > & compartments =
311  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getCompartments();
312  mCompartments.clear();
313 
314  for (unsigned C_INT32 jj = 0; jj < compartments.size(); jj++)
315  mCompartments.push_back(FROM_UTF8(compartments[jj]->getObjectName()));
316 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
virtual size_t size() const
QStringList mCompartments
#define C_INT32
Definition: copasi.h:90
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void CQSpeciesWidget::setFramework ( int  framework)
virtual

Reimplemented from CopasiWidget.

Definition at line 276 of file CQSpeciesWidget.cpp.

References COL_CONCENTRATION, COL_CRATE, COL_ICONCENTRATION, COL_INUMBER, COL_NRATE, COL_NUMBER, CopasiWidget::mFramework, mpSpecieDM, CQSpecieDM::setFlagConc(), and CopasiWidget::setFramework().

Referenced by dataChanged(), and enterProtected().

277 {
278  CopasiWidget::setFramework(framework);
279 
280  switch (mFramework)
281  {
282  case 0:
283  mpTblSpecies->showColumn(COL_ICONCENTRATION);
284  mpTblSpecies->showColumn(COL_CONCENTRATION);
285  mpTblSpecies->showColumn(COL_CRATE);
286 
287  mpTblSpecies->hideColumn(COL_INUMBER);
288  mpTblSpecies->hideColumn(COL_NUMBER);
289  mpTblSpecies->hideColumn(COL_NRATE);
290 
291  mpSpecieDM->setFlagConc(true);
292  break;
293 
294  case 1:
295  mpTblSpecies->hideColumn(COL_ICONCENTRATION);
296  mpTblSpecies->hideColumn(COL_CONCENTRATION);
297  mpTblSpecies->hideColumn(COL_CRATE);
298 
299  mpTblSpecies->showColumn(COL_INUMBER);
300  mpTblSpecies->showColumn(COL_NUMBER);
301  mpTblSpecies->showColumn(COL_NRATE);
302 
303  mpSpecieDM->setFlagConc(false);
304  break;
305  }
306 }
void setFlagConc(bool flag)
Definition: CQSpecieDM.cpp:44
CQSpecieDM * mpSpecieDM
#define COL_CONCENTRATION
Definition: CQSpecieDM.h:31
#define COL_NRATE
Definition: CQSpecieDM.h:34
#define COL_INUMBER
Definition: CQSpecieDM.h:30
#define COL_NUMBER
virtual void setFramework(int framework)
#define COL_CRATE
Definition: CQSpecieDM.h:33
#define COL_ICONCENTRATION
Definition: CQSpecieDM.h:29
void CQSpeciesWidget::slotBtnClearClicked ( )
protectedvirtualslot

Definition at line 114 of file CQSpeciesWidget.cpp.

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

115 {
116 
117  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Species?",
118  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
119 
120  if (ret == QMessageBox::Yes)
121  {
122  mpSpecieDM->clear();
123  }
124 
126 }
virtual bool clear()
CQSpecieDM * mpSpecieDM
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void CQSpeciesWidget::slotBtnDeleteClicked ( )
protectedvirtualslot

Definition at line 85 of file CQSpeciesWidget.cpp.

References deleteSelectedSpecies(), and updateDeleteBtns().

Referenced by keyPressEvent().

86 {
87  if (mpTblSpecies->hasFocus())
89 
91 }
void deleteSelectedSpecies()
void CQSpeciesWidget::slotBtnNewClicked ( )
protectedvirtualslot

Definition at line 79 of file CQSpeciesWidget.cpp.

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

Referenced by slotDoubleClicked().

80 {
83 }
CQSpecieDM * mpSpecieDM
void CQSpeciesWidget::slotDoubleClicked ( const QModelIndex  proxyIndex)
protectedvirtualslot

Definition at line 210 of file CQSpeciesWidget.cpp.

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

211 {
212  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
213 
214  if (index.row() < 0)
215  return;
216 
217  if (mpSpecieDM->isDefaultRow(index))
218  {
220  }
221 
222  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
224  assert(pDataModel != NULL);
225  CModel * pModel = pDataModel->getModel();
226 
227  if (pModel == NULL)
228  return;
229 
230  std::string key = pModel->getMetabolites()[index.row()]->getKey();
231 
232  if (CCopasiRootContainer::getKeyFactory()->get(key))
234 }
CQSortFilterProxyModel * mpProxyModel
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
const CCopasiVector< CMetab > & getMetabolites() const
Definition: CModel.cpp:1051
CQSpecieDM * mpSpecieDM
virtual void slotBtnNewClicked()
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual const std::string & getKey() const
ListViews * mpListView
Definition: copasiWidget.h:62
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
static CKeyFactory * getKeyFactory()
Definition: CModel.h:50
virtual bool isDefaultRow(const QModelIndex &i) const
void CQSpeciesWidget::slotFilterChanged ( )
protectedvirtualslot

Definition at line 270 of file CQSpeciesWidget.cpp.

References mpProxyModel.

Referenced by CQSpeciesWidget().

271 {
272  QRegExp regExp(mpLEFilter->text() + "|New Species", Qt::CaseInsensitive, QRegExp::RegExp);
273  mpProxyModel->setFilterRegExp(regExp);
274 }
CQSortFilterProxyModel * mpProxyModel
void CQSpeciesWidget::slotSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &  deselected 
)
protectedvirtualslot

Definition at line 195 of file CQSpeciesWidget.cpp.

References updateDeleteBtns().

Referenced by enterProtected().

197 {
199 }
bool CQSpeciesWidget::update ( ListViews::ObjectType  objectType,
ListViews::Action  action,
const std::string &  key 
)
virtual

Reimplemented from CopasiWidget.

Definition at line 128 of file CQSpeciesWidget.cpp.

References enterProtected(), and CopasiWidget::mIgnoreUpdates.

129 {
130  if (!mIgnoreUpdates)
131  {
132  enterProtected();
133  }
134 
135  return true;
136 }
virtual bool enterProtected()
bool mIgnoreUpdates
Definition: copasiWidget.h:67
void CQSpeciesWidget::updateDeleteBtns ( )
private

Definition at line 166 of file CQSpeciesWidget.cpp.

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

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

167 {
168  bool selected = false;
169 
170  QModelIndexList selRows = mpTblSpecies->selectionModel()->selectedRows();
171 
172  if (selRows.size() == 0)
173  selected = false;
174  else
175  {
176  if (selRows.size() == 1)
177  {
178  if (mpSpecieDM->isDefaultRow(mpProxyModel->mapToSource(selRows[0])))
179  selected = false;
180  else
181  selected = true;
182  }
183  else
184  selected = true;
185  }
186 
187  mpBtnDelete->setEnabled(selected);
188 
189  if (mpProxyModel->rowCount() - 1)
190  mpBtnClear->setEnabled(true);
191  else
192  mpBtnClear->setEnabled(false);
193 }
CQSortFilterProxyModel * mpProxyModel
CQSpecieDM * mpSpecieDM
virtual bool isDefaultRow(const QModelIndex &i) const

Member Data Documentation

QStringList CQSpeciesWidget::mCompartments
private

Definition at line 45 of file CQSpeciesWidget.h.

Referenced by CQSpeciesWidget(), and refreshCompartments().

CQComboDelegate* CQSpeciesWidget::mpCompartmentDelegate
private

Definition at line 46 of file CQSpeciesWidget.h.

Referenced by CQSpeciesWidget(), and ~CQSpeciesWidget().

CQSortFilterProxyModel* CQSpeciesWidget::mpProxyModel
private
CQSpecieDM* CQSpeciesWidget::mpSpecieDM
private
CQIndexComboDelegate* CQSpeciesWidget::mpTypeDelegate
private

Definition at line 47 of file CQSpeciesWidget.h.

Referenced by CQSpeciesWidget(), and ~CQSpeciesWidget().


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