COPASI API  4.16.103
CQTimeSeriesWidget.cpp
Go to the documentation of this file.
1 // Copyright (C) 2011 - 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 #include "CQTimeSeriesWidget.h"
7 #include "CQTimeSeriesDM.h"
8 #include "CopasiFileDialog.h"
9 #include "CQMessageBox.h"
10 #include "qtUtilities.h"
11 
14 
16  CopasiWidget(parent),
17  mpTimeSeries(NULL),
18  mpDataModel(NULL)
19 {
20  setupUi(this);
21 
22  mpDataModel = new CQTimeSeriesDM(this);
23  mpTableView->setModel(mpDataModel);
24 }
25 
27 {
28  // TODO Auto-generated destructor stub
29 }
30 
31 // virtual
33  ListViews::Action action,
34  const std::string & /* key */)
35 {
36  // We need to update the task when a new model is loaded.
37  switch (objectType)
38  {
39  case ListViews::MODEL:
40 
41  switch (action)
42  {
43  case ListViews::ADD:
44  case ListViews::DELETE:
45  loadResult(NULL);
46  break;
47 
48  default:
49  break;
50  }
51 
52  break;
53 
54  default:
55  break;
56  }
57 
58  return true;
59 }
60 
61 // virtual
63 {
64  return true;
65 }
66 
67 void CQTimeSeriesWidget::setTitle(const QString &title)
68 {
69  mpLblResult->setText(title);
70 }
71 
73 {
74  const CTrajectoryTask *traj = dynamic_cast<const CTrajectoryTask *>(pTask);
75 
76  if (traj != NULL)
77  return &traj->getTimeSeries();
78 
79  const CCrossSectionTask* cross = dynamic_cast<const CCrossSectionTask *>(pTask);
80 
81  if (cross != NULL)
82  return &cross->getTimeSeries();
83 
84  return NULL;
85 }
86 
87 // virtual
89 {
92 
93  // mpTableView->resizeRowsToContents(); This is to slow
94  int RowCount = mpDataModel->rowCount();
95 
96  if (RowCount > 0)
97  {
98  mpTableView->resizeRowToContents(0);
99  int RowHeight = mpTableView->rowHeight(0);
100 
101  mpTableView->verticalHeader()->setDefaultSectionSize(RowHeight);
102  }
103 
104  // mpTableView->resizeColumnsToContents(); This is to slow
105 
106  return true;
107 }
108 
109 // virtual
111 {
112  CopasiWidget::setFramework(framework);
113  mpDataModel->setFramework(framework);
114 }
115 
116 // virtual
118 {
119  return true;
120 }
121 
123 {
124  if (mpTimeSeries == NULL) return;
125 
126  C_INT32 Answer = QMessageBox::No;
127  QString fileName;
128 
129  while (Answer == QMessageBox::No)
130  {
131  fileName =
132  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
133  "untitled.txt", "TEXT Files (*.txt)", "Save to");
134 
135  if (fileName.isEmpty()) return;
136 
137  // Checks whether the file exists
138  Answer = checkSelection(fileName);
139 
140  if (Answer == QMessageBox::Cancel) return;
141  }
142 
143  int failed = 0;
144 
145  QCursor oldCursor = cursor();
146  setCursor(Qt::WaitCursor);
147  failed = mpTimeSeries->save(TO_UTF8(fileName), (mFramework == 1), "\t");
148  setCursor(oldCursor);
149 
150  if (failed)
151  {
152  std::string s = "Could not save data to ";
153  s += TO_UTF8(fileName);
154  CQMessageBox::critical(this, "Save Error", FROM_UTF8(s), QMessageBox::Ok, QMessageBox::Cancel);
155  }
156 }
CQTimeSeriesDM * mpDataModel
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
objectType
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
int save(const std::string &fileName, bool writeConcentrations=false, const std::string &separator="\t") const
#define C_INT32
Definition: copasi.h:90
void setFramework(int framework)
virtual bool loadResult(const CCopasiTask *pTask)
void setTimeSeries(const CTimeSeries *pTimeSeries)
CTSSATask * pTask
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual void setTitle(const QString &title)
const CTimeSeries * getTimeSeriesFromTask(const CCopasiTask *pTask)
C_INT32 checkSelection(const QString &file)
virtual bool enterProtected()
const CTimeSeries & getTimeSeries() const
virtual void setFramework(int framework)
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
const CTimeSeries & getTimeSeries() const
virtual void setFramework(int framework)
const CTimeSeries * mpTimeSeries
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
CQTimeSeriesWidget(QWidget *parent=0)