COPASI API  4.16.103
CQPlotsWidget.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 "CQPlotsWidget.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"
27 
28 /*
29  * Constructs a CQPlotsWidget which is a child of 'parent', with the
30  * name 'name'.'
31  */
32 CQPlotsWidget::CQPlotsWidget(QWidget* parent, const char* name)
33  : CopasiWidget(parent, name)
34 {
35  setupUi(this);
36 
37  //Create Source Data Model.
38  mpPlotDM = new CQPlotDM(this);
39 
40  //Create the Proxy Model for sorting/filtering and set its properties.
42  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
43  mpProxyModel->setFilterKeyColumn(-1);
44 
45  mpTblPlots->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
46  mpTblPlots->verticalHeader()->hide();
47  mpTblPlots->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
48 
50 
51  // Connect the table widget
52  connect(mpPlotDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
53  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
54  connect(mpPlotDM, 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  connect(mpBtnActivateAll, SIGNAL(pressed()), this, SLOT(slotBtnActivateAllClicked()));
59  connect(mpBtnDeactivateAll, SIGNAL(pressed()), this, SLOT(slotBtnDeactivateAllClicked()));
60 }
61 
62 /*
63  * Destroys the object and frees any allocated resources
64  */
66 {
69  // no need to delete child widgets, Qt does it all for us
70 }
71 
73 {
75  assert(pDataModel != NULL);
76 
77  if (!pDataModel->getModel())
78  return;
79 
80  for (size_t i = 0; i < pDataModel->getPlotDefinitionList()->size(); i++)
81  {
82  CPlotSpecification *pPS = static_cast<CPlotSpecification *>(pDataModel->getPlotDefinitionList()->operator[](i));
83  pPS->setActive(true);
84  }
85 
86  mpTblPlots->doItemsLayout();
87 }
88 
90 {
92  assert(pDataModel != NULL);
93 
94  if (!pDataModel->getModel())
95  return;
96 
97  for (size_t i = 0; i < pDataModel->getPlotDefinitionList()->size(); i++)
98  {
99  CPlotSpecification *pPS = static_cast<CPlotSpecification *>(pDataModel->getPlotDefinitionList()->operator[](i));
100  pPS->setActive(false);
101  }
102 
103  mpTblPlots->doItemsLayout();
104 }
105 
107 {
108  mpPlotDM->insertRow();
110 }
111 
113 {
114  if (mpTblPlots->hasFocus())
116 
118 }
119 
121 {
122  const QItemSelectionModel * pSelectionModel = mpTblPlots->selectionModel();
123 
124  QModelIndexList mappedSelRows;
125  size_t i, imax = mpPlotDM->rowCount();
126 
127  for (i = 0; i < imax; i++)
128  {
129  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
130  {
131  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
132  }
133  }
134 
135  if (mappedSelRows.empty())
136  {return;}
137 
138  mpPlotDM->removeRows(mappedSelRows);
139 }
140 
142 {
143 
144  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Plots?",
145  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
146 
147  if (ret == QMessageBox::Yes)
148  {
149  mpPlotDM->clear();
150  }
151 
153 }
154 
156 {
157  if (!mIgnoreUpdates)
158  {
159  enterProtected();
160  }
161 
162  return true;
163 }
164 
166 {
167  return true;
168 }
169 
171 {
172  if (mpTblPlots->selectionModel() != NULL)
173  {
174  disconnect(mpTblPlots->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
175  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
176  }
177 
178  mpProxyModel->setSourceModel(mpPlotDM);
179  //Set Model for the TableView
180  mpTblPlots->setModel(NULL);
181  mpTblPlots->setModel(mpProxyModel);
182  connect(mpTblPlots->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
183  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
185  mpTblPlots->resizeColumnsToContents();
187 
188  return true;
189 }
190 
192 {
193  bool selected = false;
194 
195  QModelIndexList selRows = mpTblPlots->selectionModel()->selectedRows();
196 
197  if (selRows.size() == 0)
198  selected = false;
199  else
200  {
201  if (selRows.size() == 1)
202  {
203  if (mpPlotDM->isDefaultRow(mpProxyModel->mapToSource(selRows[0])))
204  selected = false;
205  else
206  selected = true;
207  }
208  else
209  selected = true;
210  }
211 
212  mpBtnDelete->setEnabled(selected);
213 
214  if (mpProxyModel->rowCount() - 1)
215  mpBtnClear->setEnabled(true);
216  else
217  mpBtnClear->setEnabled(false);
218 }
219 
220 void CQPlotsWidget::slotSelectionChanged(const QItemSelection& C_UNUSED(selected),
221  const QItemSelection& C_UNUSED(deselected))
222 {
224 }
225 
226 void CQPlotsWidget::dataChanged(const QModelIndex& C_UNUSED(topLeft),
227  const QModelIndex& C_UNUSED(bottomRight))
228 {
229  mpTblPlots->resizeColumnsToContents();
232 }
233 
234 void CQPlotsWidget::slotDoubleClicked(const QModelIndex proxyIndex)
235 {
236  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
237 
238  if (index.row() < 0)
239  return;
240 
241  if (mpPlotDM->isDefaultRow(index))
242  {
244  }
245 
246  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
248  assert(pDataModel != NULL);
249 
250  if (!pDataModel->getModel())
251  return;
252 
253  CPlotSpecification *pPS = static_cast<CPlotSpecification *>(pDataModel->getPlotDefinitionList()->operator[](index.row()));
254  const std::string key = static_cast<CCopasiParameter *>(pPS)->getKey();
255 
258 }
259 
260 void CQPlotsWidget::keyPressEvent(QKeyEvent* ev)
261 {
262  if (ev->key() == Qt::Key_Delete)
264  else if (ev->key() == Qt::Key_C &&
265  (ev->modifiers() & Qt::ControlModifier))
266  {
267  QModelIndexList selRows = mpTblPlots->selectionModel()->selectedRows(0);
268 
269  if (selRows.empty())
270  {return;}
271 
272  QString str;
273  QModelIndexList::const_iterator i;
274 
275  for (i = selRows.begin(); i != selRows.end(); ++i)
276  {
277  for (int x = 0; x < mpPlotDM->columnCount(); ++x)
278  {
279  if (!mpTblPlots->isColumnHidden(x))
280  {
281  if (!str.isEmpty())
282  str += "\t";
283 
284  str += mpPlotDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
285  }
286  }
287 
288  str += "\n";
289  }
290 
291  QApplication::clipboard()->setText(str);
292  }
293 }
294 
296 {
297  QRegExp regExp(mpLEFilter->text() + "|New Plot", Qt::CaseInsensitive, QRegExp::RegExp);
298  mpProxyModel->setFilterRegExp(regExp);
299 }
300 
301 void CQPlotsWidget::setFramework(int framework)
302 {
303  CopasiWidget::setFramework(framework);
304 }
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQPlotDM.cpp:28
#define pdelete(p)
Definition: copasi.h:215
CQSortFilterProxyModel * mpProxyModel
Definition: CQPlotsWidget.h:35
objectType
virtual void slotFilterChanged()
void updateDeleteBtns()
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
virtual size_t size() const
virtual bool clear()
CCopasiObject * get(const std::string &key)
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void setActive(const bool &active)
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_UNUSED(p)
Definition: copasi.h:220
bool mIgnoreUpdates
Definition: copasiWidget.h:67
ListViews * mpListView
Definition: copasiWidget.h:62
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
Definition: CQPlotDM.cpp:242
virtual void slotBtnDeleteClicked()
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQPlotDM.cpp:32
virtual bool leave()
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual void slotBtnActivateAllClicked()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual void slotBtnClearClicked()
virtual void setFramework(int framework)
CQPlotDM * mpPlotDM
Definition: CQPlotsWidget.h:34
virtual bool enterProtected()
static CKeyFactory * getKeyFactory()
const COutputDefinitionVector * getPlotDefinitionList() const
void deleteSelectedPlots()
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
virtual bool isDefaultRow(const QModelIndex &i) const
virtual void slotDoubleClicked(const QModelIndex proxyIndex)
virtual void setFramework(int framework)
virtual void keyPressEvent(QKeyEvent *ev)
virtual void slotBtnDeactivateAllClicked()
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
virtual void slotBtnNewClicked()
CQPlotsWidget(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