COPASI API  4.16.103
CQEFMResultWidget.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 "CQEFMResultWidget.h"
12 #include "CQEFMNetReactionDM.h"
13 #include "CQEFMReactionDM.h"
14 #include "CQEFMSpeciesDM.h"
15 #include "CopasiFileDialog.h"
16 #include "CQMessageBox.h"
17 #include "qtUtilities.h"
18 
21 #include "utilities/utility.h"
23 
24 CQEFMResultWidget::CQEFMResultWidget(QWidget* parent, const char* name) :
25  CopasiWidget(parent, name),
26  mpTask(NULL),
27  mpProxyModelReactions(NULL),
28  mpReactionDM(NULL),
29  mpProxyModelSpecies(NULL),
30  mpSpeciesDM(NULL),
31  mpProxyModelNetReactions(NULL),
32  mpNetReactionDM(NULL)
33 {
34  setupUi(this);
35 
36  mpReactionMatrix->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
37  mpReactionMatrix->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
38  mpReactionMatrix->verticalHeader()->hide();
39 
40  //Create Source Data Model.
41  mpReactionDM = new CQEFMReactionDM(this);
42 
43  //Create the Proxy Model for sorting/filtering and set its properties.
45  mpProxyModelReactions->setSortCaseSensitivity(Qt::CaseInsensitive);
46  mpProxyModelReactions->setFilterKeyColumn(COL_REACTION_NAME);
47 
48  mpProxyModelReactions->setSourceModel(mpReactionDM);
49 
50  //Set Model for the TableView
51  mpReactionMatrix->setModel(NULL);
52  mpReactionMatrix->setModel(mpProxyModelReactions);
53  mpReactionMatrix->resizeColumnsToContents();
54 
55  mpSpeciesMatrix->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
56  mpSpeciesMatrix->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
57  mpSpeciesMatrix->verticalHeader()->hide();
58 
59  //Create Source Data Model.
60  mpSpeciesDM = new CQEFMSpeciesDM(this);
61 
62  //Create the Proxy Model for sorting/filtering and set its properties.
64  mpProxyModelSpecies->setSortCaseSensitivity(Qt::CaseInsensitive);
65  mpProxyModelSpecies->setFilterKeyColumn(COL_REACTION_NAME);
66 
67  mpProxyModelSpecies->setSourceModel(mpSpeciesDM);
68 
69  //Set Model for the TableView
70  mpSpeciesMatrix->setModel(NULL);
71  mpSpeciesMatrix->setModel(mpProxyModelSpecies);
72  mpSpeciesMatrix->resizeColumnsToContents();
73 
74  mpNetReactions->sortByColumn(COL_ROW_NUMBER, Qt::AscendingOrder);
75  mpNetReactions->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
76  mpNetReactions->verticalHeader()->hide();
77 
78  //Create Source Data Model.
80 
81  //Create the Proxy Model for sorting/filtering and set its properties.
83  mpProxyModelNetReactions->setSortCaseSensitivity(Qt::CaseInsensitive);
84  mpProxyModelNetReactions->setFilterKeyColumn(COL_REACTION_NAME);
85 
87 
88  //Set Model for the TableView
89  mpNetReactions->setModel(NULL);
90  mpNetReactions->setModel(mpProxyModelNetReactions);
91  mpNetReactions->resizeColumnsToContents();
92 }
93 
95 {
99 }
100 
101 // virtual
103 {
104  return true;
105 }
106 
107 // virtual
109  ListViews::Action action,
110  const std::string & /* key */)
111 {
112  // We need to update the task when a new model is loaded.
113  switch (objectType)
114  {
115  case ListViews::MODEL:
116 
117  switch (action)
118  {
119  case ListViews::ADD:
120  case ListViews::DELETE:
121  loadResult(NULL);
122  break;
123 
124  default:
125  break;
126  }
127 
128  break;
129 
130  default:
131  break;
132  }
133 
134  return true;
135 }
136 
137 // virtual
139 {
140  return true;
141 }
142 
143 // virtual
145 {
146  mpTask = dynamic_cast<const CEFMTask *>(pTask);
147 
148  if (mpTask != NULL)
149  {
150  mpEditFluxModes->setText(QString::number(mpTask->getFluxModes().size()));
151  }
152  else
153  {
154  mpEditFluxModes->setText(QString::number(0));
155  }
156 
157  bool success = true;
158  success &= mpEFMListWidget->loadResult(mpTask);
159 
161 
162  mpProxyModelReactions->setSourceModel(mpReactionDM);
163 
164  //Set Model for the TableView
165  mpReactionMatrix->setModel(NULL);
166  mpReactionMatrix->setModel(mpProxyModelReactions);
167  mpReactionMatrix->resizeColumnsToContents();
168 
170 
171  mpProxyModelSpecies->setSourceModel(mpSpeciesDM);
172 
173  //Set Model for the TableView
174  mpSpeciesMatrix->setModel(NULL);
175  mpSpeciesMatrix->setModel(mpProxyModelSpecies);
176  mpSpeciesMatrix->resizeColumnsToContents();
177 
179 
180  mpProxyModelNetReactions->setSourceModel(mpNetReactionDM);
181 
182  //Set Model for the TableView
183  mpNetReactions->setModel(NULL);
184  mpNetReactions->setModel(mpProxyModelNetReactions);
185  mpNetReactions->resizeColumnsToContents();
186 
187  return success;
188 }
189 
191 {
192  C_INT32 Answer = QMessageBox::No;
193  QString fileName;
194 
195  while (Answer == QMessageBox::No)
196  {
197  fileName =
198  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
199  "untitled.txt", "TEXT Files (*.txt)", "Save to");
200 
201  if (fileName.isEmpty()) return;
202 
203  // Checks whether the file exists
204  Answer = checkSelection(fileName);
205 
206  if (Answer == QMessageBox::Cancel) return;
207  }
208 
209  std::ofstream file(CLocaleString::fromUtf8(TO_UTF8(fileName)).c_str());
210 
211  if (file.fail())
212  return;
213 
214  if (mpTask != NULL)
215  file << mpTask->getResult();
216 
217  return;
218 }
#define pdelete(p)
Definition: copasi.h:215
objectType
void setTask(const CEFMTask *pTask)
void setTask(const CEFMTask *pTask)
const CEFMTask * mpTask
const std::vector< CFluxMode > & getFluxModes() const
Definition: CEFMTask.cpp:183
#define C_INT32
Definition: copasi.h:90
CQEFMSpeciesDM * mpSpeciesDM
CTSSATask * pTask
virtual bool loadResult(const CCopasiTask *pTask)
CQSortFilterProxyModel * mpProxyModelReactions
C_INT32 checkSelection(const QString &file)
CQSortFilterProxyModel * mpProxyModelNetReactions
#define COL_REACTION_NAME
Definition: CQFluxModeDM.h:30
void setTask(const CEFMTask *pTask)
CQEFMResultWidget(QWidget *parent=0, const char *name=0)
const CResult & getResult() const
virtual bool update(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
CQEFMNetReactionDM * mpNetReactionDM
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
virtual bool enterProtected()
CQEFMReactionDM * mpReactionDM
CQSortFilterProxyModel * mpProxyModelSpecies
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)
#define COL_ROW_NUMBER