COPASI API  4.16.103
CQReportDefinitionSelect.cpp
Go to the documentation of this file.
1 // Copyright (C) 2012 - 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 "copasi.h"
9 
10 #include "qtUtilities.h"
11 #include "listviews.h"
12 #include "DataModelGUI.h"
13 #include "CQMessageBox.h"
14 #include "CopasiFileDialog.h"
15 
17 
21 
22 CQReportDefinitionSelect::CQReportDefinitionSelect(QWidget * parent, Qt::WindowFlags f) :
23  QDialog(parent, f),
24  mpListView(static_cast< ListViews * >(parent)),
25  mpReport(NULL),
26  mShow(true)
27 {
28  setupUi(this);
29 
30  mpBtnEdit->setIcon(CQIconResource::icon(CQIconResource::edit));
31  mpBtnBrowse->setIcon(CQIconResource::icon(CQIconResource::fileOpen));
32 
33 }
34 
36 {
37  cleanup();
38 }
39 
41 {
42  mpReport = NULL;
43 }
44 
46 {
47  mpReport = newReport;
48 }
49 
51 {
52  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
53  CReportDefinitionVector* pReportDefinitionVector = (*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList();
54  unsigned C_INT32 i;
55 
56  for (i = 0; i < pReportDefinitionVector->size(); i++)
57  mpComboDefinition->
58  insertItem(mpComboDefinition->count(), FROM_UTF8((*(pReportDefinitionVector))[i]->getObjectName()));
59 
60  // if it is an empty list
61  if (mpComboDefinition->count() == 0)
62  {
63  std::string name = "ReportDefinition_0";
64  (*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList()->createReportDefinition(name, "");
65  mpComboDefinition->insertItem(mpComboDefinition->count(), FROM_UTF8(name));
66  mpComboDefinition->setCurrentIndex(1);
67  mpReport->setReportDefinition((*(*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList())[0]); //first one report definition
68  mpReport->setAppend(mpCheckAppend->isChecked());
69  mpReport->setConfirmOverwrite(mpCheckConfirmOverwrite->isChecked());
70  mpReport->setTarget(TO_UTF8(mpEditTarget->text()));
71  mpListView->getDataModel()->notify(ListViews::REPORT, ListViews::CHANGE, ""); //notify Table Definition to
72 
73  if (CQMessageBox::question(NULL, "No Report Template Defined",
74  "No report definition defined, COPASI has already created a new one for you.\n Do you want to switch to the GUI to edit it?",
75  QMessageBox::Ok | QMessageBox::No, QMessageBox::Ok) == QMessageBox::Ok)
76  slotEdit();
77 
78  return;
79  }
80 
82  {
83  C_INT32 row;
84  row = mpComboDefinition->currentIndex();
85  mpReport->setReportDefinition((*(pReportDefinitionVector))[row]);
86  mpReport->setAppend(mpCheckAppend->isChecked());
87  mpReport->setConfirmOverwrite(mpCheckConfirmOverwrite->isChecked());
88  mpReport->setTarget(TO_UTF8(mpEditTarget->text()));
89  return;
90  }
91  else
92  {
93  C_INT32 i;
94 
95  // no use to compare the last one
96  for (i = mpComboDefinition->count() - 1; i >= 1; i--)
97  if (mpComboDefinition->itemText(i) == FROM_UTF8(mpReport->getReportDefinition()->getObjectName()))
98  break;
99 
100  mpComboDefinition->setCurrentIndex(i);
101  mpCheckAppend->setChecked(mpReport->append());
102  mpCheckConfirmOverwrite->setChecked(mpReport->confirmOverwrite());
103  mpEditTarget->setText(FROM_UTF8(mpReport->getTarget()));
104  }
105 }
106 
108 {
109  if (mShow)
110  return QDialog::exec();
111  else
112  return QDialog::Accepted;
113 }
114 
116 {
117  if (!mpReport)
118  //exception made here
119  return;
120 
121  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
122  CReportDefinitionVector* pReportDefinitionVector = (*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList();
123  C_INT32 row;
124  row = mpComboDefinition->currentIndex();
125  mpReport->setReportDefinition((*(pReportDefinitionVector))[row]);
126  mpReport->setAppend(mpCheckAppend->isChecked());
127  mpReport->setConfirmOverwrite(mpCheckConfirmOverwrite->isChecked());
128  mpReport->setTarget(TO_UTF8(mpEditTarget->text()));
129  cleanup();
130  QDialog::done(QDialog::Accepted);
131 }
132 
134 {
135  cleanup();
136  QDialog::done(QDialog::Rejected);
137 }
138 
140 {
141  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
142  CReportDefinitionVector* pReportDefinitionVector = (*CCopasiRootContainer::getDatamodelList())[0]->getReportDefinitionList();
143  C_INT32 row;
144  row = mpComboDefinition->currentIndex();
145  mpListView->switchToOtherWidget(C_INVALID_INDEX, (*pReportDefinitionVector)[row]->getKey());
146  accept(); // if shown then close
147  mShow = false; // if not shown then close
148 }
149 
151 {
152  QString reportFile =
153  CopasiFileDialog::getSaveFileName(this, "Save File Dialog", "untitled.txt", "TEXT Files (*.txt)",
154  "Choose to create a new a file");
155 
156  if (!reportFile.isNull())
157  {
158  mpEditTarget->setText(reportFile);
159  }
160 }
161 
void setReport(CReport *newReport)
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const bool & confirmOverwrite() const
Definition: CReport.cpp:101
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
bool notify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
const std::string & getObjectName() const
virtual size_t size() const
const std::string & getTarget() const
Definition: CReport.cpp:89
#define C_INVALID_INDEX
Definition: copasi.h:222
void setAppend(const bool &append)
Definition: CReport.cpp:98
void setConfirmOverwrite(const bool &confirmOverwrite)
Definition: CReport.cpp:104
#define C_INT32
Definition: copasi.h:90
const bool & append() const
Definition: CReport.cpp:95
CQReportDefinitionSelect(QWidget *parent=0, Qt::WindowFlags f=0)
static const QIcon & icon(const IconID &id)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void setTarget(const std::string &target)
Definition: CReport.cpp:92
DataModelGUI * getDataModel()
Definition: listviews.h:134
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
CReportDefinition * getReportDefinition()
Definition: CReport.cpp:83
void setReportDefinition(CReportDefinition *reportDef)
Definition: CReport.cpp:86
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
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)