COPASI API  4.16.103
CQReportsWidget.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 "CQReportsWidget.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"
26 
27 /*
28  * Constructs a CQReportsWidget which is a child of 'parent', with the
29  * name 'name'.'
30  */
31 CQReportsWidget::CQReportsWidget(QWidget* parent, const char* name)
32  : CopasiWidget(parent, name)
33 {
34  setupUi(this);
35 
36  //Create Source Data Model.
37  mpReportDM = new CQReportDM(this);
38 
39  //Create the Proxy Model for sorting/filtering and set its properties.
41  mpProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
42  mpProxyModel->setFilterKeyColumn(-1);
43 
44  mpTblReports->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
45  mpTblReports->verticalHeader()->hide();
46  mpTblReports->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
47 
49 
50  // Connect the table widget
51  connect(mpReportDM, SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
52  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
53  connect(mpReportDM, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
54  this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)));
55  connect(mpLEFilter, SIGNAL(textChanged(const QString &)),
56  this, SLOT(slotFilterChanged()));
57 }
58 
59 /*
60  * Destroys the object and frees any allocated resources
61  */
63 {
66  // no need to delete child widgets, Qt does it all for us
67 }
68 
70 {
73 }
74 
76 {
77  if (mpTblReports->hasFocus())
79 
81 }
82 
84 {
85  const QItemSelectionModel * pSelectionModel = mpTblReports->selectionModel();
86 
87  QModelIndexList mappedSelRows;
88  size_t i, imax = mpReportDM->rowCount();
89 
90  for (i = 0; i < imax; i++)
91  {
92  if (pSelectionModel->isRowSelected((int) i, QModelIndex()))
93  {
94  mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0)));
95  }
96  }
97 
98  if (mappedSelRows.empty())
99  {return;}
100 
101  mpReportDM->removeRows(mappedSelRows);
102 }
103 
105 {
106 
107  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Reports?",
108  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
109 
110  if (ret == QMessageBox::Yes)
111  {
112  mpReportDM->clear();
113  }
114 
116 }
117 
119 {
120  if (!mIgnoreUpdates)
121  {
122  enterProtected();
123  }
124 
125  return true;
126 }
127 
129 {
130  return true;
131 }
132 
134 {
135  if (mpTblReports->selectionModel() != NULL)
136  {
137  disconnect(mpTblReports->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
138  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
139  }
140 
141  mpProxyModel->setSourceModel(mpReportDM);
142  //Set Model for the TableView
143  mpTblReports->setModel(NULL);
144  mpTblReports->setModel(mpProxyModel);
145  connect(mpTblReports->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
146  this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection&)));
148  mpTblReports->resizeColumnsToContents();
150 
151  return true;
152 }
153 
155 {
156  bool selected = false;
157 
158  QModelIndexList selRows = mpTblReports->selectionModel()->selectedRows();
159 
160  if (selRows.size() == 0)
161  selected = false;
162  else
163  {
164  if (selRows.size() == 1)
165  {
166  if (mpReportDM->isDefaultRow(mpProxyModel->mapToSource(selRows[0])))
167  selected = false;
168  else
169  selected = true;
170  }
171  else
172  selected = true;
173  }
174 
175  mpBtnDelete->setEnabled(selected);
176 
177  if (mpProxyModel->rowCount() - 1)
178  mpBtnClear->setEnabled(true);
179  else
180  mpBtnClear->setEnabled(false);
181 }
182 
183 void CQReportsWidget::slotSelectionChanged(const QItemSelection& C_UNUSED(selected),
184  const QItemSelection& C_UNUSED(deselected))
185 {
187 }
188 
189 void CQReportsWidget::dataChanged(const QModelIndex& C_UNUSED(topLeft),
190  const QModelIndex& C_UNUSED(bottomRight))
191 {
192  mpTblReports->resizeColumnsToContents();
195 }
196 
197 void CQReportsWidget::slotDoubleClicked(const QModelIndex proxyIndex)
198 {
199  QModelIndex index = mpProxyModel->mapToSource(proxyIndex);
200 
201  if (index.row() < 0)
202  return;
203 
204  if (mpReportDM->isDefaultRow(index))
205  {
207  }
208 
209  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
211  assert(pDataModel != NULL);
212 
213  if (!pDataModel->getModel())
214  return;
215 
216  std::string key = pDataModel->getReportDefinitionList()->operator[](index.row())->getKey();
217 
220 }
221 
223 {
224  if (ev->key() == Qt::Key_Delete)
226  else if (ev->key() == Qt::Key_C && (ev->modifiers() & Qt::ControlModifier))
227  {
228  QModelIndexList selRows = mpTblReports->selectionModel()->selectedRows(0);
229 
230  if (selRows.empty())
231  {return;}
232 
233  QString str;
234  QModelIndexList::const_iterator i;
235 
236  for (i = selRows.begin(); i != selRows.end(); ++i)
237  {
238  for (int x = 0; x < mpReportDM->columnCount(); ++x)
239  {
240  if (!mpTblReports->isColumnHidden(x))
241  {
242  if (!str.isEmpty())
243  str += "\t";
244 
245  str += mpReportDM->index(mpProxyModel->mapToSource(*i).row(), x).data().toString();
246  }
247  }
248 
249  str += "\n";
250  }
251 
252  QApplication::clipboard()->setText(str);
253  }
254 }
255 
257 {
258  QRegExp regExp(mpLEFilter->text() + "|New Report", Qt::CaseInsensitive, QRegExp::RegExp);
259  mpProxyModel->setFilterRegExp(regExp);
260 }
261 
262 void CQReportsWidget::setFramework(int framework)
263 {
264  CopasiWidget::setFramework(framework);
265 }
CQSortFilterProxyModel * mpProxyModel
#define pdelete(p)
Definition: copasi.h:215
objectType
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
virtual bool clear()
CCopasiObject * get(const std::string &key)
virtual bool enterProtected()
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_UNUSED(p)
Definition: copasi.h:220
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQReportDM.cpp:29
bool mIgnoreUpdates
Definition: copasiWidget.h:67
virtual void keyPressEvent(QKeyEvent *ev)
const CReportDefinitionVector * getReportDefinitionList() const
CQReportsWidget(QWidget *parent=0, const char *name=0)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: CQReportDM.cpp:33
virtual void slotBtnDeleteClicked()
ListViews * mpListView
Definition: copasiWidget.h:62
virtual void slotDoubleClicked(const QModelIndex proxyIndex)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual bool leave()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
virtual void slotBtnNewClicked()
CQReportDM * mpReportDM
virtual void slotBtnClearClicked()
static CKeyFactory * getKeyFactory()
void deleteSelectedReports()
virtual void slotFilterChanged()
virtual bool isDefaultRow(const QModelIndex &i) const
virtual void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
virtual void setFramework(int framework)
virtual void setFramework(int framework)
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
Definition: CQReportDM.cpp:210
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
#define COL_ROW_NUMBER