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

#include <CQGlobalQuantitiesWidget.h>

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

Public Member Functions

 CQGlobalQuantitiesWidget (QWidget *parent=0, const char *name=0)
 
virtual bool leave ()
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 
 ~CQGlobalQuantitiesWidget ()
 
- 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 ()
 
virtual void setFramework (int framework)
 
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 deleteSelectedGlobalQuantities ()
 
void updateDeleteBtns ()
 

Private Attributes

CQGlobalQuantityDMmpGlobalQuantityDM
 
CQSortFilterProxyModelmpProxyModel
 
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 CQGlobalQuantitiesWidget.h.

Constructor & Destructor Documentation

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

Definition at line 30 of file CQGlobalQuantitiesWidget.cpp.

References COL_ROW_NUMBER, COL_TYPE_GQ, dataChanged(), CQGlobalQuantityDM::getTypes(), mpGlobalQuantityDM, mpProxyModel, mpTypeDelegate, CopasiWidget::protectedNotify(), and slotFilterChanged().

31  : CopasiWidget(parent, name)
32 {
33  setupUi(this);
34 
35  //Create Source Data Model.
37 
38  //Create the Proxy Model for sorting/filtering and set its properties.
40  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
41  mpProxyModel->setFilterKeyColumn(-1);
42 
43  //Setting values for Types comboBox
45  mpTblGlobalQuantities->setItemDelegateForColumn(COL_TYPE_GQ, mpTypeDelegate);
46 
47  mpTblGlobalQuantities->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
48  mpTblGlobalQuantities->verticalHeader()->hide();
49  mpTblGlobalQuantities->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
50 
51  // Connect the table widget
52  connect(mpGlobalQuantityDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
53  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
54  connect(mpGlobalQuantityDM, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
55  this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)));
56  connect(mpLEFilter, SIGNAL(textChanged(const QString &)),
57  this, SLOT(slotFilterChanged()));
58 }
const QStringList & getTypes()
CQIndexComboDelegate * mpTypeDelegate
CQSortFilterProxyModel * mpProxyModel
CQGlobalQuantityDM * mpGlobalQuantityDM
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="")
#define COL_TYPE_GQ
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
#define COL_ROW_NUMBER
CQGlobalQuantitiesWidget::~CQGlobalQuantitiesWidget ( )

Definition at line 63 of file CQGlobalQuantitiesWidget.cpp.

References mpGlobalQuantityDM, mpProxyModel, mpTypeDelegate, and pdelete.

64 {
68  // no need to delete child widgets, Qt does it all for us
69 }
#define pdelete(p)
Definition: copasi.h:215
CQIndexComboDelegate * mpTypeDelegate
CQSortFilterProxyModel * mpProxyModel
CQGlobalQuantityDM * mpGlobalQuantityDM

Member Function Documentation

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

Definition at line 190 of file CQGlobalQuantitiesWidget.cpp.

References updateDeleteBtns().

Referenced by CQGlobalQuantitiesWidget().

192 {
193  mpTblGlobalQuantities->resizeColumnsToContents();
195 }
void CQGlobalQuantitiesWidget::deleteSelectedGlobalQuantities ( )
private

Definition at line 85 of file CQGlobalQuantitiesWidget.cpp.

References mpGlobalQuantityDM, mpProxyModel, CQGlobalQuantityDM::removeRows(), and CQGlobalQuantityDM::rowCount().

Referenced by slotBtnDeleteClicked().

86 {
87  const QItemSelectionModel * pSelectionModel = mpTblGlobalQuantities->selectionModel();
88 
89  QModelIndexList mappedSelRows;
90  size_t i, imax = mpGlobalQuantityDM->rowCount();
91 
92  for (i = 0; i < imax; i++)
93  {
94  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
95  {
96  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
97  }
98  }
99 
100  if (mappedSelRows.empty())
101  {return;}
102 
103  mpGlobalQuantityDM->removeRows(mappedSelRows);
104 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
CQSortFilterProxyModel * mpProxyModel
CQGlobalQuantityDM * mpGlobalQuantityDM
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
bool CQGlobalQuantitiesWidget::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 135 of file CQGlobalQuantitiesWidget.cpp.

References mpGlobalQuantityDM, mpProxyModel, slotSelectionChanged(), and updateDeleteBtns().

Referenced by update().

136 {
137  if (mpTblGlobalQuantities->selectionModel() != NULL)
138  {
139  disconnect(mpTblGlobalQuantities->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
140  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
141  }
142 
143  mpProxyModel->setSourceModel(mpGlobalQuantityDM);
144  //Set Model for the TableView
145  mpTblGlobalQuantities->setModel(NULL);
146  mpTblGlobalQuantities->setModel(mpProxyModel);
147  connect(mpTblGlobalQuantities->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
148  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
150  mpTblGlobalQuantities->resizeColumnsToContents();
151 
152  return true;
153 }
CQSortFilterProxyModel * mpProxyModel
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
CQGlobalQuantityDM * mpGlobalQuantityDM
void CQGlobalQuantitiesWidget::keyPressEvent ( QKeyEvent *  ev)
protectedvirtual

Definition at line 223 of file CQGlobalQuantitiesWidget.cpp.

References CQGlobalQuantityDM::columnCount(), mpGlobalQuantityDM, mpProxyModel, and slotBtnDeleteClicked().

224 {
225  if (ev->key() == Qt::Key_Delete)
227  else if (ev->key() == Qt::Key_C && (ev->modifiers() & Qt::ControlModifier))
228  {
229  QModelIndexList selRows = mpTblGlobalQuantities->selectionModel()->selectedRows(0);
230 
231  if (selRows.empty())
232  {return;}
233 
234  QString str;
235  QModelIndexList::const_iterator i;
236 
237  for (i = selRows.begin(); i != selRows.end(); ++i)
238  {
239  for (int x = 0; x < mpGlobalQuantityDM->columnCount(); ++x)
240  {
241  if (!mpTblGlobalQuantities->isColumnHidden(x))
242  {
243  if (!str.isEmpty())
244  str += "\t";
245 
246  str += mpGlobalQuantityDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
247  }
248  }
249 
250  str += "\n";
251  }
252 
253  QApplication::clipboard()->setText(str);
254  }
255 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
CQSortFilterProxyModel * mpProxyModel
CQGlobalQuantityDM * mpGlobalQuantityDM
bool CQGlobalQuantitiesWidget::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 130 of file CQGlobalQuantitiesWidget.cpp.

131 {
132  return true;
133 }
void CQGlobalQuantitiesWidget::slotBtnClearClicked ( )
protectedvirtualslot

Definition at line 106 of file CQGlobalQuantitiesWidget.cpp.

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

107 {
108 
109  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Quantities?",
110  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
111 
112  if (ret == QMessageBox::Yes)
113  {
115  }
116 
118 }
virtual bool clear()
CQGlobalQuantityDM * mpGlobalQuantityDM
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void CQGlobalQuantitiesWidget::slotBtnDeleteClicked ( )
protectedvirtualslot

Definition at line 77 of file CQGlobalQuantitiesWidget.cpp.

References deleteSelectedGlobalQuantities(), and updateDeleteBtns().

Referenced by keyPressEvent().

78 {
79  if (mpTblGlobalQuantities->hasFocus())
81 
83 }
void CQGlobalQuantitiesWidget::slotBtnNewClicked ( )
protectedvirtualslot
void CQGlobalQuantitiesWidget::slotDoubleClicked ( const QModelIndex  proxyIndex)
protectedvirtualslot

Definition at line 197 of file CQGlobalQuantitiesWidget.cpp.

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

198 {
199  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
200 
201  if (index.row() < 0)
202  return;
203 
204  if (mpGlobalQuantityDM->isDefaultRow(index))
205  {
207  }
208 
209  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
211  assert(pDataModel != NULL);
212  CModel * pModel = pDataModel->getModel();
213 
214  if (pModel == NULL)
215  return;
216 
217  std::string key = pModel->getModelValues()[index.row()]->getKey();
218 
219  if (CCopasiRootContainer::getKeyFactory()->get(key))
221 }
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
#define C_INVALID_INDEX
Definition: copasi.h:222
CQSortFilterProxyModel * mpProxyModel
virtual const std::string & getKey() const
CQGlobalQuantityDM * mpGlobalQuantityDM
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 CQGlobalQuantitiesWidget::slotFilterChanged ( )
protectedvirtualslot

Definition at line 257 of file CQGlobalQuantitiesWidget.cpp.

References mpProxyModel.

Referenced by CQGlobalQuantitiesWidget().

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

Definition at line 184 of file CQGlobalQuantitiesWidget.cpp.

References updateDeleteBtns().

Referenced by enterProtected().

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

Reimplemented from CopasiWidget.

Definition at line 120 of file CQGlobalQuantitiesWidget.cpp.

References enterProtected(), and CopasiWidget::mIgnoreUpdates.

121 {
122  if (!mIgnoreUpdates)
123  {
124  enterProtected();
125  }
126 
127  return true;
128 }
bool mIgnoreUpdates
Definition: copasiWidget.h:67
void CQGlobalQuantitiesWidget::updateDeleteBtns ( )
private

Definition at line 155 of file CQGlobalQuantitiesWidget.cpp.

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

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

156 {
157  bool selected = false;
158 
159  QModelIndexList selRows = mpTblGlobalQuantities->selectionModel()->selectedRows();
160 
161  if (selRows.size() == 0)
162  selected = false;
163  else
164  {
165  if (selRows.size() == 1)
166  {
167  if (mpGlobalQuantityDM->isDefaultRow(mpProxyModel->mapToSource(selRows[0])))
168  selected = false;
169  else
170  selected = true;
171  }
172  else
173  selected = true;
174  }
175 
176  mpBtnDelete->setEnabled(selected);
177 
178  if (mpProxyModel->rowCount() - 1)
179  mpBtnClear->setEnabled(true);
180  else
181  mpBtnClear->setEnabled(false);
182 }
CQSortFilterProxyModel * mpProxyModel
CQGlobalQuantityDM * mpGlobalQuantityDM
virtual bool isDefaultRow(const QModelIndex &i) const

Member Data Documentation

CQGlobalQuantityDM* CQGlobalQuantitiesWidget::mpGlobalQuantityDM
private
CQSortFilterProxyModel* CQGlobalQuantitiesWidget::mpProxyModel
private
CQIndexComboDelegate* CQGlobalQuantitiesWidget::mpTypeDelegate
private

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