COPASI API  4.16.103
CQParameterSetsWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
7 
8 #include <QtGui/QHeaderView>
9 #include <QtGui/QClipboard>
10 #include <QtGui/QKeyEvent>
11 
12 #include "copasi.h"
13 
14 #include "qtUtilities.h"
15 #include "CQMessageBox.h"
16 
17 #include "model/CModel.h"
21 
22 /*
23  * Constructs a CQParameterSetsWidget which is a child of 'parent', with the
24  * name 'name'.'
25  */
26 CQParameterSetsWidget::CQParameterSetsWidget(QWidget* parent, const char* name)
27  : CopasiWidget(parent, name)
28 {
29  setupUi(this);
30 
31  //Create Source Data Model.
33 
34  //Create the Proxy Model for sorting/filtering and set its properties.
36  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
37  mpProxyModel->setFilterKeyColumn(-1);
38 
39  mpTblParameterSets->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
40  mpTblParameterSets->verticalHeader()->hide();
41  mpTblParameterSets->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
42 
44 
45  // Connect the table widget
46  connect(mpParameterSetsDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
47  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
48  connect(mpParameterSetsDM, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
49  this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)));
50  connect(mpLEFilter, SIGNAL(textChanged(const QString &)),
51  this, SLOT(slotFilterChanged()));
52 }
53 
54 /*
55  * Destroys the object and frees any allocated resources
56  */
58 {
61  // no need to delete child widgets, Qt does it all for us
62 }
63 
65 {
68 }
69 
71 {
72  if (mpTblParameterSets->hasFocus())
73  {deleteSelected();}
74 
76 }
77 
79 {
80  const QItemSelectionModel * pSelectionModel = mpTblParameterSets->selectionModel();
81 
82  QModelIndexList mappedSelRows;
83  size_t i, imax = mpParameterSetsDM->rowCount();
84 
85  for (i = 0; i < imax; i++)
86  {
87  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
88  {
89  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
90  }
91  }
92 
93  if (mappedSelRows.empty())
94  {return;}
95 
96  mpParameterSetsDM->removeRows(mappedSelRows);
97 }
98 
100 {
101 
102  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Reports?",
103  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
104 
105  if (ret == QMessageBox::Yes)
106  {
108  }
109 
111 }
112 
113 bool CQParameterSetsWidget::update(ListViews::ObjectType objectType, ListViews::Action action, const std::string & C_UNUSED(key))
114 {
115  if (mIgnoreUpdates)
116  {
117  return true;
118  }
119 
120  if (objectType == ListViews::MODEL &&
121  (action == ListViews::DELETE ||
122  action == ListViews::ADD))
123  {
124  mpDataModel = NULL;
125  mpObject = NULL;
126  mKey = "";
127  }
128 
129  return true;
130 }
131 
133 {
134  return true;
135 }
136 
138 {
139  if (mpObject == NULL)
140  {
141  return false;
142  }
143 
144  if (mpTblParameterSets->selectionModel() != NULL)
145  {
146  disconnect(mpTblParameterSets->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
147  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
148  }
149 
150  mpParameterSetsDM->setListOfModelParameterSets(&static_cast< CModel * >(mpObject)->getModelParameterSets());
151  mpProxyModel->setSourceModel(mpParameterSetsDM);
152 
153  //Set Model for the TableView
154  mpTblParameterSets->setModel(NULL);
155  mpTblParameterSets->setModel(mpProxyModel);
156  connect(mpTblParameterSets->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
157  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
159  mpTblParameterSets->resizeColumnsToContents();
161 
162  mpBtnNew->hide();
163 
164  return true;
165 }
166 
168 {
169  bool selected = false;
170 
171  QModelIndexList selRows = mpTblParameterSets->selectionModel()->selectedRows();
172 
173  if (selRows.size() == 0)
174  selected = false;
175  else
176  {
177  if (selRows.size() == 1)
178  {
179  if (mpParameterSetsDM->isDefaultRow(mpProxyModel->mapToSource(selRows[0])))
180  selected = false;
181  else
182  selected = true;
183  }
184  else
185  selected = true;
186  }
187 
188  mpBtnDelete->setEnabled(selected);
189 
190  if (mpProxyModel->rowCount() - 1)
191  mpBtnClear->setEnabled(true);
192  else
193  mpBtnClear->setEnabled(false);
194 }
195 
196 void CQParameterSetsWidget::slotSelectionChanged(const QItemSelection& C_UNUSED(selected),
197  const QItemSelection& C_UNUSED(deselected))
198 {
200 }
201 
202 void CQParameterSetsWidget::dataChanged(const QModelIndex& C_UNUSED(topLeft),
203  const QModelIndex& C_UNUSED(bottomRight))
204 {
205  mpTblParameterSets->resizeColumnsToContents();
208 }
209 
210 void CQParameterSetsWidget::slotDoubleClicked(const QModelIndex proxyIndex)
211 {
212  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
213 
214  if (index.row() < 0)
215  return;
216 
217  if (mpParameterSetsDM->isDefaultRow(index))
218  {
220  }
221 
222  if (mpObject == NULL)
223  {
224  return;
225  }
226 
227  std::string key = static_cast< CModel * >(mpObject)->getModelParameterSets()[index.row()]->getKey();
228 
229  if (CCopasiRootContainer::getKeyFactory()->get(key))
231 }
232 
234 {
235  if (ev->key() == Qt::Key_Delete)
237  else if (ev->key() == Qt::Key_C && (ev->modifiers() & Qt::ControlModifier))
238  {
239  QModelIndexList selRows = mpTblParameterSets->selectionModel()->selectedRows(0);
240 
241  if (selRows.empty())
242  {return;}
243 
244  QString str;
245  QModelIndexList::const_iterator i;
246 
247  for (i = selRows.begin(); i != selRows.end(); ++i)
248  {
249  for (int x = 0; x < mpParameterSetsDM->columnCount(); ++x)
250  {
251  if (!mpTblParameterSets->isColumnHidden(x))
252  {
253  if (!str.isEmpty())
254  str += "\t";
255 
256  str += mpParameterSetsDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
257  }
258  }
259 
260  str += "\n";
261  }
262 
263  QApplication::clipboard()->setText(str);
264  }
265 }
266 
268 {
269  QRegExp regExp(mpLEFilter->text() + "|New Report", Qt::CaseInsensitive, QRegExp::RegExp);
270  mpProxyModel->setFilterRegExp(regExp);
271 }
272 
274 {
275  CopasiWidget::setFramework(framework);
276 }
#define pdelete(p)
Definition: copasi.h:215
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
virtual bool isDefaultRow(const QModelIndex &i) const
void setListOfModelParameterSets(CCopasiVectorN< CModelParameterSet > *pListOfModelParameterSets)
virtual void setFramework(int framework)
CQParameterSetsWidget(QWidget *parent=0, const char *name=0)
virtual bool clear()
CCopasiObject * mpObject
Definition: copasiWidget.h:64
virtual void slotDoubleClicked(const QModelIndex proxyIndex)
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
#define C_UNUSED(p)
Definition: copasi.h:220
virtual void keyPressEvent(QKeyEvent *ev)
CQSortFilterProxyModel * mpProxyModel
bool mIgnoreUpdates
Definition: copasiWidget.h:67
ListViews * mpListView
Definition: copasiWidget.h:62
const std::string & getKey() const
Definition: CModel.cpp:1142
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CQParameterSetsDM * mpParameterSetsDM
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
static CKeyFactory * getKeyFactory()
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CModel.h:50
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
virtual void setFramework(int framework)
std::string mKey
Definition: copasiWidget.h:63
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
#define COL_ROW_NUMBER