COPASI API  4.16.103
CQGlobalQuantitiesWidget.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 
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 CQGlobalQuantitiesWidget which is a child of 'parent', with the
28  * name 'name'.'
29  */
30 CQGlobalQuantitiesWidget::CQGlobalQuantitiesWidget(QWidget* parent, const char* name)
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 }
59 
60 /*
61  * Destroys the object and frees any allocated resources
62  */
64 {
68  // no need to delete child widgets, Qt does it all for us
69 }
70 
72 {
75 }
76 
78 {
79  if (mpTblGlobalQuantities->hasFocus())
81 
83 }
84 
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 }
105 
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 }
119 
121 {
122  if (!mIgnoreUpdates)
123  {
124  enterProtected();
125  }
126 
127  return true;
128 }
129 
131 {
132  return true;
133 }
134 
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 }
154 
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 }
183 
184 void CQGlobalQuantitiesWidget::slotSelectionChanged(const QItemSelection& C_UNUSED(selected),
185  const QItemSelection& C_UNUSED(deselected))
186 {
188 }
189 
190 void CQGlobalQuantitiesWidget::dataChanged(const QModelIndex& C_UNUSED(topLeft),
191  const QModelIndex& C_UNUSED(bottomRight))
192 {
193  mpTblGlobalQuantities->resizeColumnsToContents();
195 }
196 
197 void CQGlobalQuantitiesWidget::slotDoubleClicked(const QModelIndex proxyIndex)
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 }
222 
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 }
256 
258 {
259  QRegExp regExp(mpLEFilter->text() + "|New Quantity", Qt::CaseInsensitive, QRegExp::RegExp);
260  mpProxyModel->setFilterRegExp(regExp);
261 }
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
const QStringList & getTypes()
#define pdelete(p)
Definition: copasi.h:215
objectType
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
const CCopasiVectorN< CModelValue > & getModelValues() const
Definition: CModel.cpp:1060
virtual bool clear()
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_UNUSED(p)
Definition: copasi.h:220
CQIndexComboDelegate * mpTypeDelegate
CQSortFilterProxyModel * mpProxyModel
bool mIgnoreUpdates
Definition: copasiWidget.h:67
virtual const std::string & getKey() const
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
virtual void keyPressEvent(QKeyEvent *ev)
CQGlobalQuantityDM * mpGlobalQuantityDM
ListViews * mpListView
Definition: copasiWidget.h:62
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual void slotDoubleClicked(const QModelIndex proxyIndex)
#define COL_TYPE_GQ
static CKeyFactory * getKeyFactory()
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
Definition: CModel.h:50
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
virtual bool isDefaultRow(const QModelIndex &i) const
CQGlobalQuantitiesWidget(QWidget *parent=0, const char *name=0)
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
#define COL_ROW_NUMBER