COPASI API  4.16.103
HistoWidget.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 #include <QtCore/QVariant>
7 
8 #include "HistoWidget.h"
9 #include "CQPlotEditWidget.h"
10 
11 #include "CQPlotSubwidget.h"
12 
14 #include "UI/qtUtilities.h"
15 
16 #include "plot/CPlotItem.h"
19 
20 HistoWidget::HistoWidget(QWidget* parent, Qt::WindowFlags fl):
21  CQPlotEditWidget(parent, fl),
22  mpObjectX(NULL)
23 {
24  setupUi(this);
25 
26  mpBtnVariable->setIcon(CQIconResource::icon(CQIconResource::copasi));
27 }
28 
30 {
31  // no need to delete child widgets, Qt does it all for us
32 }
33 
35 {
36  if (!mpModel) return;
37 
38  // mpObjectX = CCopasiSelectionDialog::getObjectSingle(this, CQSimpleSelectionTree::NUMERIC, mpObjectX);
39  //mpObjectX = CCopasiSelectionDialog::getObjectSingle(this, CQSimpleSelectionTree::PLOT_OBJECT, mpObjectX);
40 
41  std::vector< const CCopasiObject * > oldSelection;
42 
43  if (mpObjectX)
44  oldSelection.push_back(mpObjectX);
45 
46  std::vector< const CCopasiObject * > objects =
49  &oldSelection);
50 
51  if (objects.size() && objects[0])
52  {
53  mpObjectX = objects[0];
54  mpEditVariable->setText(FROM_UTF8(mpObjectX->getObjectDisplayName()));
55  mpEditTitle->setText("Histogram: " + FROM_UTF8(mpObjectX->getObjectDisplayName()));
56  }
57  else
58  {
59  mpObjectX = NULL;
60  mpEditVariable->setText("");
61  mpEditTitle->setText("Histogram");
62  }
63 
64  //check if more than one object was selected...
65  if (objects.size() > 1)
66  {
67  CQPlotSubwidget * pParent;
68  QObject* tmp = this;
69 
70  while (!(pParent = dynamic_cast< CQPlotSubwidget * >(tmp)) && this)
71  tmp = tmp->parent();
72 
73  if (pParent) //tell the parent to create the remaining histogram descriptions.
74  pParent->createHistograms(objects, mpEditIncrement->text().toDouble());
75  }
76 }
77 
79 {
80  if (!curve)
81  {
82  // We need to reset the widget to defaults
83  mpEditTitle->setText("");
84 
85  mpObjectX = NULL;
86  mpEditVariable->setText("");
87 
88  mpEditIncrement->setText("");
89 
90  mpCheckBefore->setChecked(false);
91  mpCheckDuring->setChecked(true);
92  mpCheckAfter->setChecked(false);
93 
94  return true;
95  }
96 
97  if (curve->getType() != CPlotItem::histoItem1d) return false;
98 
99  if (curve->getChannels().size() != 1) return false;
100 
101  //title
102  mpEditTitle->setText(FROM_UTF8(curve->getTitle()));
103 
104  //variable
105  mpObjectX = NULL;
106  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
108  assert(pDataModel != NULL);
109 
110  if (curve->getChannels().size() >= 1)
111  mpObjectX = pDataModel->getDataObject(curve->getChannels()[0]);
112 
113  if (mpObjectX == pDataModel)
114  {
115  mpObjectX = NULL;
116  }
117 
118  if (mpObjectX != NULL)
119  mpEditVariable->setText(FROM_UTF8(mpObjectX->getObjectDisplayName()));
120  else
121  mpEditVariable->setText("");
122 
123  //other parameters:
124  const void* tmp;
125 
126  if (!(tmp = curve->getValue("increment").pVOID)) return false;
127 
128  mpEditIncrement->setText(QString::number(*(const C_FLOAT64*)tmp));
129 
130  mpCheckBefore->setChecked(curve->getActivity() & COutputInterface::BEFORE);
131  mpCheckDuring->setChecked(curve->getActivity() & COutputInterface::DURING);
132  mpCheckAfter->setChecked(curve->getActivity() & COutputInterface::AFTER);
133 
134  return true; //TODO
135 }
136 
137 bool HistoWidget::SaveToCurveSpec(CPlotItem * curve, const CPlotItem *original /*= NULL*/) const
138 {
139 
140  C_INT32 Activity = 0;
141 
142  if (mpCheckBefore->isChecked()) Activity += COutputInterface::BEFORE;
143 
144  if (mpCheckDuring->isChecked()) Activity += COutputInterface::DURING;
145 
146  if (mpCheckAfter->isChecked()) Activity += COutputInterface::AFTER;
147 
148  std::string title = TO_UTF8(mpEditTitle->text());
150  C_FLOAT64 increment = mpEditIncrement->text().toDouble();
151 
152  bool thingsChanged = false;
153 
154  if (original != NULL)
155  {
156  if (original->getType() != CPlotItem::histoItem1d)
157  thingsChanged = true;
158 
159  if (thingsChanged || original->getTitle() != title)
160  thingsChanged = true;
161 
162  if (thingsChanged || *original->getValue("increment").pDOUBLE != increment)
163  thingsChanged = true;
164 
165  if (thingsChanged || original->getActivity() != Activity)
166  thingsChanged = true;
167 
168  if (thingsChanged || original->getChannels().size() != 1)
169  thingsChanged = true;
170 
171  if (thingsChanged || original->getChannels()[0] != name)
172  thingsChanged = true;
173  }
174  else thingsChanged = true;
175 
176  if (!thingsChanged)
177  return false;
178 
179  //title
180  curve->setTitle(title);
181 
182  //channels
183  curve->getChannels().clear();
184  curve->getChannels().push_back(CPlotDataChannelSpec(name));
185 
186  //other parameters: TODO
187  curve->setValue("increment", increment);
188 
189  curve->setActivity((COutputInterface::Activity) Activity);
190 
191  return true;
192 }
193 
194 /**
195  * In multiple edit mode, we don't want to edit name & channels
196  */
198 {
199  mpEditTitle->setEnabled(!mode);
200  mpEditVariable->setEnabled(!mode);
201  mpBtnVariable->setEnabled(!mode);
202 }
CCopasiObject * getDataObject(const CCopasiObjectName &CN) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
const CModel * mpModel
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
virtual CCopasiObjectName getCN() const
static std::vector< const CCopasiObject * > getObjectVector(QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const std::vector< const CCopasiObject * > *pCurrentSelection=NULL)
std::vector< CPlotDataChannelSpec > & getChannels()
Definition: CPlotItem.cpp:214
void setActivity(const COutputInterface::Activity &activity)
Definition: CPlotItem.cpp:161
const CCopasiObject * mpObjectX
Definition: HistoWidget.h:35
#define C_INT32
Definition: copasi.h:90
virtual bool SaveToCurveSpec(CPlotItem *curve, const CPlotItem *original=NULL) const
static const QIcon & icon(const IconID &id)
const CPlotItem::Type & getType() const
Definition: CPlotItem.cpp:158
bool setValue(const std::string &name, const CType &value)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
virtual void setMultipleEditMode(bool mode)
virtual void buttonPressedX()
Definition: HistoWidget.cpp:34
const COutputInterface::Activity & getActivity() const
Definition: CPlotItem.cpp:179
HistoWidget(QWidget *parent=0, Qt::WindowFlags fl=0)
Definition: HistoWidget.cpp:20
#define C_FLOAT64
Definition: copasi.h:92
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
const CCopasiParameter::Value & getValue(const std::string &name) const
virtual bool LoadFromCurveSpec(const CPlotItem *curve)
Definition: HistoWidget.cpp:78
const std::string & getTitle() const
Definition: CPlotItem.cpp:228
void setTitle(const std::string &title)
Definition: CPlotItem.cpp:233
void createHistograms(std::vector< const CCopasiObject * >objects, const C_FLOAT64 &incr)