COPASI API  4.16.103
CQMiriamWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 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 "CQMiriamWidget.h"
12 
13 #include <QtGui/QHeaderView>
14 #include <QtGui/QClipboard>
15 #include <QtGui/QKeyEvent>
16 #include <QtGui/QDesktopServices>
17 #include <QtCore/QUrl>
18 
19 #include "copasi.h"
20 
21 #include "UI/qtUtilities.h"
22 #include "UI/CQMessageBox.h"
23 
25 #include "function/CFunction.h"
26 #include "report/CKeyFactory.h"
29 
30 /*
31  * Constructs a CQMiriamWidget which is a child of 'parent', with the
32  * name 'name'.'
33  */
34 CQMiriamWidget::CQMiriamWidget(QWidget* parent, const char* name)
35  : CopasiWidget(parent, name),
36  mKeyToCopy("")
37 {
38  setupUi(this);
39 
40  // Create the MIRIAM Info
41  mpMIRIAMInfo = new CMIRIAMInfo();
42 
43  //Create Data Models for the 4 tables
48 
49  //Create Proxy Data Models for the 4 tables
54 
55  //Create Required Delegates
56  mpResourceDelegate1 = new CQComboDelegate(&mResources, this, false);
57  mpTblReferences->setItemDelegateForColumn(COL_RESOURCE_REFERENCE, mpResourceDelegate1);
58 
59  mpResourceDelegate2 = new CQComboDelegate(&mReferences, this, false);
60  mpTblDescription->setItemDelegateForColumn(COL_RESOURCE_BD, mpResourceDelegate2);
61 
62  mpPredicateDelegate = new CQComboDelegate(&mPredicates, this, false);
63  mpTblDescription->setItemDelegateForColumn(COL_RELATIONSHIP, mpPredicateDelegate);
64 
65  mWidgets.push_back(mpTblAuthors); mDMs.push_back(mpCreatorDM); mProxyDMs.push_back(mpCreatorPDM);
66  mWidgets.push_back(mpTblReferences); mDMs.push_back(mpReferenceDM); mProxyDMs.push_back(mpReferencePDM);
67  mWidgets.push_back(mpTblDescription); mDMs.push_back(mpBiologicalDescriptionDM); mProxyDMs.push_back(mpBiologicalDescriptionPDM);
68  mWidgets.push_back(mpTblModified); mDMs.push_back(mpModifiedDM); mProxyDMs.push_back(mpModifiedPDM);
69 
70  // Build the list of supported predicates
71  mPredicates.push_back("-- select --");
80 
81  std::vector<CQTableView*>::const_iterator it = mWidgets.begin();
82  std::vector<CQTableView*>::const_iterator end = mWidgets.end();
83 
84  std::vector<CQBaseDataModel*>::const_iterator itDM = mDMs.begin();
85  std::vector<CQBaseDataModel*>::const_iterator endDM = mDMs.end();
86 
87  std::vector<CQSortFilterProxyModel*>::const_iterator itPDM = mProxyDMs.begin();
88  std::vector<CQSortFilterProxyModel*>::const_iterator endPDM = mProxyDMs.end();
89 
90  for (; it != end && itDM != endDM && itPDM != endPDM; it++, itDM++, itPDM++)
91  {
92  //Set Proxy Data Model properties
93  (*itPDM)->setDynamicSortFilter(true);
94  (*itPDM)->setSortCaseSensitivity(Qt::CaseInsensitive);
95 
96  (*it)->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
97  (*it)->verticalHeader()->hide();
98  (*it)->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
99 
100  connect((*itDM), SIGNAL(notifyGUI(ListViews::ObjectType, ListViews::Action, const std::string)),
101  this, SLOT(protectedNotify(ListViews::ObjectType, ListViews::Action, const std::string)));
102  connect((*itDM), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
103  this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&)));
104  }
105 
106  connect(mpTblDescription, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(slotBtnBrowseDescription(const QModelIndex&)));
107  connect(mpTblReferences, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(slotBtnBrowseReference(const QModelIndex&)));
108 
109  // Build the list of known resources
111 }
112 
113 /*
114  * Destroys the object and frees any allocated resources
115  */
117 {
118  // no need to delete child widgets or objects, Qt does it all for us
124 }
125 
127 {
128  if (mpTblAuthors->hasFocus())
130  else if (mpTblReferences->hasFocus())
132  else if (mpTblModified->hasFocus())
134  else if (mpTblDescription->hasFocus())
136 }
137 
139 {
140  QModelIndexList selRows = mpTblAuthors->selectionModel()->selectedRows(0);
141 
142  if (selRows.empty())
143  {return;}
144 
145  QModelIndexList mappedSelRows;
146  QModelIndexList::const_iterator i;
147 
148  for (i = selRows.begin(); i != selRows.end(); ++i)
149  {mappedSelRows.append(mpCreatorPDM->mapToSource(*i));}
150 
151  mpCreatorDM->removeRows(mappedSelRows);
152 }
153 
155 {
156  QModelIndexList selRows = mpTblReferences->selectionModel()->selectedRows(0);
157 
158  if (selRows.empty())
159  {return;}
160 
161  QModelIndexList mappedSelRows;
162  QModelIndexList::const_iterator i;
163 
164  for (i = selRows.begin(); i != selRows.end(); ++i)
165  {mappedSelRows.append(mpReferencePDM->mapToSource(*i));}
166 
167  mpReferenceDM->removeRows(mappedSelRows);
168 }
169 
171 {
172 
173  QModelIndexList selRows = mpTblDescription->selectionModel()->selectedRows(0);
174 
175  if (selRows.empty())
176  {return;}
177 
178  QModelIndexList mappedSelRows;
179  QModelIndexList::const_iterator i;
180 
181  for (i = selRows.begin(); i != selRows.end(); ++i)
182  {mappedSelRows.append(mpBiologicalDescriptionPDM->mapToSource(*i));}
183 
184  mpBiologicalDescriptionDM->removeRows(mappedSelRows);
185 }
186 
188 {
189 
190  QModelIndexList selRows = mpTblModified->selectionModel()->selectedRows(0);
191 
192  if (selRows.empty())
193  {return;}
194 
195  QModelIndexList mappedSelRows;
196  QModelIndexList::const_iterator i;
197 
198  for (i = selRows.begin(); i != selRows.end(); ++i)
199  {mappedSelRows.append(mpModifiedPDM->mapToSource(*i));}
200 
201  mpModifiedDM->removeRows(mappedSelRows);
202 }
203 
204 void openMiriamReference(const std::string &reference)
205 {
206  if (reference == "" || reference.length() < 7)
207  return;
208 
209  QDesktopServices::openUrl(QUrl(reference.c_str()));
210 }
211 
212 void CQMiriamWidget::slotBtnBrowseReference(const QModelIndex& index)
213 {
214  if (mpMIRIAMInfo == NULL ||
215  index.column() > 1 ||
216  index.row() < 0 ||
217  index.row() >= (int)mpMIRIAMInfo->getReferences().size())
218  return;
219 
220  const CReference *pRef = mpMIRIAMInfo->getReferences()[index.row()];
221 
222  openMiriamReference(pRef->getMIRIAMResourceObject().getIdentifiersOrgURL() + "?profile=most_reliable");
223 }
224 
225 void CQMiriamWidget::slotBtnBrowseDescription(const QModelIndex& index)
226 {
227  if (mpMIRIAMInfo == NULL ||
228  index.column() > 1 ||
229  index.row() < 0 ||
230  index.row() >= (int)mpMIRIAMInfo->getBiologicalDescriptions().size())
231  return;
232 
233  const CBiologicalDescription *pRef = mpMIRIAMInfo->getBiologicalDescriptions()[index.row()];
234 
235  openMiriamReference(pRef->getMIRIAMResourceObject().getIdentifiersOrgURL() + "?profile=most_reliable");
236 }
237 
239 {
240  if (mpDTCreated->hasFocus())
241  {
242  mpDTCreated->setDateTime(QDateTime::currentDateTime());
243  return;
244  }
245 
246  if (mpTblAuthors->hasFocus())
247  {
248  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Creators?",
249  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
250 
251  if (ret == QMessageBox::Yes)
252  {
253  mpCreatorDM->clear();
254  }
255  }
256  else if (mpTblReferences->hasFocus())
257  {
258  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all References?",
259  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
260 
261  if (ret == QMessageBox::Yes)
262  {
263  mpReferenceDM->clear();
264  }
265  }
266  else if (mpTblDescription->hasFocus())
267  {
268  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Descriptions?",
269  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
270 
271  if (ret == QMessageBox::Yes)
272  {
274  }
275  }
276  else if (mpTblModified->hasFocus())
277  {
278  int ret = CQMessageBox::question(this, tr("Confirm Delete"), "Delete all Date/Time Modifieds?",
279  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
280 
281  if (ret == QMessageBox::Yes)
282  {
283  mpModifiedDM->clear();
284  }
285  }
286 }
287 
288 bool CQMiriamWidget::update(ListViews::ObjectType objectType, ListViews::Action C_UNUSED(action), const std::string & key)
289 {
290  if (getIgnoreUpdates())
291  return true;
292 
293  if (objectType != ListViews::MIRIAM)
294  return true;
295 
296  if (key == "" || key != mpMIRIAMInfo->getKey())
297  return true;
298 
299  bool success = true;
300  mpMIRIAMInfo->load(key);
301 
302  if (mpMIRIAMInfo->getCreatedDT() != "")
303  mpDTCreated->setDateTime(QDateTime::fromString(FROM_UTF8(mpMIRIAMInfo->getCreatedDT()), Qt::ISODate));
304 
305  return success;
306 }
307 
309 {
310  //Now update.
311  // Created at
312  std::string DT = "";
313 
314  if (newDT.isValid())
315  {
316  DT = TO_UTF8(newDT.toString(Qt::ISODate));
317  DT += "Z";
318 
319  if (DT != mpMIRIAMInfo->getCreatedDT())
320  {
322  }
323  }
324 }
325 
326 void
327 CQMiriamWidget::showEvent(QShowEvent * event)
328 {
329  if (!isVisible() || mKey.empty()) return;
330 
332 
333  if (mKeyToCopy != "")
334  {
335  CAnnotation * pAnnotation = CAnnotation::castObject(dynamic_cast< CCopasiObject * >(CCopasiRootContainer::getKeyFactory()->get(mKeyToCopy)));
336 
337  std::string pMiriamAnnotation = pAnnotation->getMiriamAnnotation();
338 
339  pAnnotation = CAnnotation::castObject(mpObject);
340 
341  pAnnotation->setMiriamAnnotation(pMiriamAnnotation, mKey, mKeyToCopy);
342 
343  mKeyToCopy = "";
344  }
345 
347 
348  //Set Models for the 4 TableViews
349  std::vector<CQTableView*>::const_iterator it = mWidgets.begin();
350  std::vector<CQTableView*>::const_iterator end = mWidgets.end();
351 
352  std::vector<CQBaseDataModel*>::const_iterator itDM = mDMs.begin();
353  std::vector<CQBaseDataModel*>::const_iterator endDM = mDMs.end();
354 
355  std::vector<CQSortFilterProxyModel*>::const_iterator itPDM = mProxyDMs.begin();
356  std::vector<CQSortFilterProxyModel*>::const_iterator endPDM = mProxyDMs.end();
357 
358  for (; it != end && itDM != endDM && itPDM != endPDM; it++, itDM++, itPDM++)
359  {
360  (*itPDM)->setSourceModel(*itDM);
361  (*it)->setModel(NULL);
362  (*it)->setModel(*itPDM);
363  (*it)->resizeColumnsToContents();
364  }
365 
366  QDateTime DTCreated;
367 
368  if (mpMIRIAMInfo->getCreatedDT() != "")
369  DTCreated = QDateTime::fromString(FROM_UTF8(mpMIRIAMInfo->getCreatedDT()), Qt::ISODate);
370 
371  if (DTCreated.isValid())
372  mpDTCreated->setDateTime(DTCreated);
373  else
374  {
375  mpDTCreated->setDateTime(QDateTime::currentDateTime());
376  }
377 
378  if (CCopasiMessage::size() > 0)
379  {
381  {
382  // we decided to not display the warning about not recognized terms
383  // at the last meeting
384  // case CCopasiMessage::WARNING:
385  // CQMessageBox::information(this, "Information", FROM_UTF8(CCopasiMessage::getAllMessageText()));
386  // break;
387 
391  break;
392 
393  default:
394  break;
395  }
396 
398  }
399 }
400 
402 {
403  // loading is now deferred until the window is made visible
404  return true;
405 }
406 
408 {
409  mpMIRIAMInfo->save();
410  return true;
411 }
412 
414 {return *mpMIRIAMInfo;}
415 
417 {
418  mResources.clear();
419  mReferences.clear();
420  // Build the list of known resources
421  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
423  mResources.push_back("-- select --");
424  mReferences.push_back("-- select --");
425 
426  size_t i, imax = pResource->getResourceList().size();
427 
428  for (i = 0; i < imax; i++)
429  if (pResource->getMIRIAMResource(i).getMIRIAMCitation())
430  mResources.push_back(FROM_UTF8(pResource->getMIRIAMResource(i).getMIRIAMDisplayName()));
431  else
432  mReferences.push_back(FROM_UTF8(pResource->getMIRIAMResource(i).getMIRIAMDisplayName()));
433 }
434 
435 void CQMiriamWidget::keyPressEvent(QKeyEvent* ev)
436 {
437  if (ev->key() == Qt::Key_Delete)
439  else if (ev->key() == Qt::Key_C &&
440  (ev->modifiers() & Qt::ControlModifier))
441  slotCopyEvent();
442 }
443 
444 void CQMiriamWidget::dataChanged(const QModelIndex& C_UNUSED(topLeft), const QModelIndex& C_UNUSED(bottomRight))
445 {
446  std::vector<CQTableView*>::const_iterator it = mWidgets.begin();
447  std::vector<CQTableView*>::const_iterator end = mWidgets.end();
448 
449  for (; it != end; it++)
450  (*it)->resizeColumnsToContents();
451 }
452 
454 {
455  CQSortFilterProxyModel* pProxyModel = NULL;
456  CQBaseDataModel* pBaseDM = NULL;
457  CQTableView* pTbl = NULL;
458 
459  if (mpTblAuthors->hasFocus())
460  {
461  pProxyModel = mpCreatorPDM;
462  pBaseDM = mpCreatorDM;
463  pTbl = mpTblAuthors;
464  }
465  else if (mpTblReferences->hasFocus())
466  {
467  pProxyModel = mpReferencePDM;
468  pBaseDM = mpReferenceDM;
469  pTbl = mpTblReferences;
470  }
471  else if (mpTblModified->hasFocus())
472  {
473  pProxyModel = mpModifiedPDM;
474  pBaseDM = mpModifiedDM;
475  pTbl = mpTblModified;
476  }
477  else if (mpTblDescription->hasFocus())
478  {
479  pProxyModel = mpBiologicalDescriptionPDM;
480  pBaseDM = mpBiologicalDescriptionDM;
481  pTbl = mpTblDescription;
482  }
483 
484  QModelIndexList selRows = pTbl->selectionModel()->selectedRows(0);
485 
486  if (selRows.empty())
487  {return;}
488 
489  QString str;
490  QModelIndexList::const_iterator i;
491 
492  for (i = selRows.begin(); i != selRows.end(); ++i)
493  {
494  for (int x = 0; x < pBaseDM->columnCount(); ++x)
495  {
496  if (!pTbl->isColumnHidden(x))
497  {
498  if (!str.isEmpty())
499  str += "\t";
500 
501  str += pBaseDM->index(pProxyModel->mapToSource(*i).row(), x).data().toString();
502  }
503  }
504 
505  str += "\n";
506  }
507 
508  QApplication::clipboard()->setText(str);
509 }
510 
512 {
513  mKeyToCopy = mKey;
514 }
void keyPressEvent(QKeyEvent *ev)
#define COL_RESOURCE_BD
void deleteSelectedModifieds()
#define pdelete(p)
Definition: copasi.h:215
virtual void slotCreatedDTChanged(QDateTime newDT)
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const CMIRIAMResource & getMIRIAMResource(const size_t index) const
void load(const std::string &key="")
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
CQSortFilterProxyModel * mpCreatorPDM
std::vector< CQSortFilterProxyModel * > mProxyDMs
CMIRIAMInfo * mpMIRIAMInfo
void openMiriamReference(const std::string &reference)
CQSortFilterProxyModel * mpModifiedPDM
const CCopasiParameterGroup & getResourceList() const
const CCopasiVector< CBiologicalDescription > & getBiologicalDescriptions() const
virtual size_t size() const
CQMiriamWidget(QWidget *parent=0, const char *name=0)
const CMIRIAMResourceObject & getMIRIAMResourceObject() const
Definition: CReference.cpp:90
virtual bool clear()
const CMIRIAMInfo & getMIRIAMInfo() const
virtual void slotBtnClearClicked()
CQSortFilterProxyModel * mpBiologicalDescriptionPDM
QStringList mResources
static std::string getAllMessageText(const bool &chronological=true)
CCopasiObject * mpObject
Definition: copasiWidget.h:64
void deleteSelectedAuthors()
CQModifiedDM * mpModifiedDM
void setMiriamAnnotation(const std::string &miriamAnnotation, const std::string &newId, const std::string &oldId)
#define C_UNUSED(p)
Definition: copasi.h:220
std::vector< CQTableView * > mWidgets
void deleteSelectedReferences()
const std::string & getMiriamAnnotation() const
CQReferenceDM * mpReferenceDM
static void clearDeque()
const std::string & getMIRIAMDisplayName() const
virtual void slotBtnDeleteClicked()
static CConfigurationFile * getConfiguration()
virtual const std::string & getKey() const
static const std::string & getDisplayName(const CRDFPredicate &predicate)
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
static CAnnotation * castObject(CCopasiObject *pObject)
Definition: CAnnotation.cpp:32
CMIRIAMResources & getRecentMIRIAMResources()
virtual void showEvent(QShowEvent *event)
std::string mKeyToCopy
virtual bool enterProtected()
const std::string getCreatedDT() const
static size_t size()
QStringList mReferences
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
#define COL_RESOURCE_REFERENCE
Definition: CQReferenceDM.h:26
std::string getIdentifiersOrgURL() const
Definition: CConstants.cpp:138
const CCopasiVector< CReference > & getReferences() const
virtual void slotBtnBrowseReference(const QModelIndex &index)
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
void deleteSelectedBiologicalDescriptions()
virtual void slotBtnCopy()
std::vector< CQBaseDataModel * > mDMs
virtual void slotCopyEvent()
CQCreatorDM * mpCreatorDM
static CKeyFactory * getKeyFactory()
CQComboDelegate * mpResourceDelegate2
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
CQComboDelegate * mpPredicateDelegate
#define COL_RELATIONSHIP
QStringList mPredicates
void updateResourcesList()
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
CQComboDelegate * mpResourceDelegate1
const CMIRIAMResourceObject & getMIRIAMResourceObject() const
void setCreatedDT(const std::string &dt)
virtual void slotBtnBrowseDescription(const QModelIndex &index)
CQSortFilterProxyModel * mpReferencePDM
std::string mKey
Definition: copasiWidget.h:63
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())
virtual bool leave()
bool getIgnoreUpdates()
CQBiologicalDescriptionDM * mpBiologicalDescriptionDM
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
static CCopasiMessage::Type getHighestSeverity()
#define COL_ROW_NUMBER
const bool & getMIRIAMCitation() const
bool removeRows(QModelIndexList rows, const QModelIndex &index=QModelIndex())