COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | Protected Slots | Protected Attributes | List of all members
CCopasiSelectionDialog Class Reference

#include <CCopasiSelectionDialog.h>

Inheritance diagram for CCopasiSelectionDialog:
Inheritance graph
[legend]
Collaboration diagram for CCopasiSelectionDialog:
Collaboration graph
[legend]

Public Member Functions

 CCopasiSelectionDialog (QWidget *parent=0, const char *name=0, bool modal=false)
 
void enableExpertMode (bool enable)
 
void setModel (const CModel *model, const CQSimpleSelectionTree::ObjectClasses &classes)
 
void setOutputVector (std::vector< const CCopasiObject * > *outputVector)
 
void setSingleSelection (bool singleSelectionMode)
 
 ~CCopasiSelectionDialog ()
 

Static Public Member Functions

static std::vector< const
CCopasiObject * > 
chooseCellMatrix (const CArrayAnnotation *pArrayAnnotation, bool single, bool value, std::string caption="")
 
static const CCopasiObjectgetObjectSingle (QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const CCopasiObject *pCurrentObject=NULL)
 
static std::vector< const
CCopasiObject * > 
getObjectVector (QWidget *pParent, const CQSimpleSelectionTree::ObjectClasses &classes, const std::vector< const CCopasiObject * > *pCurrentSelection=NULL)
 

Protected Slots

void cancelButton_clicked ()
 
void modeButton_toggled (bool checked)
 
void okButton_clicked ()
 

Protected Attributes

bool mExpertMode
 
bool mExpertModeEnabled
 
QHBoxLayout * mpButtonBox
 
QVBoxLayout * mpMainLayout
 
QWidget * mpMainWidget
 
QCheckBox * mpModeCheckBox
 
std::vector< const
CCopasiObject * > * 
mpOutputVector
 
CCopasiSelectionWidgetmpSelectionWidget
 
std::vector< const
CCopasiObject * > * 
mpTmpVector
 

Detailed Description

Definition at line 33 of file CCopasiSelectionDialog.h.

Constructor & Destructor Documentation

CCopasiSelectionDialog::CCopasiSelectionDialog ( QWidget *  parent = 0,
const char *  name = 0,
bool  modal = false 
)

Definition at line 38 of file CCopasiSelectionDialog.cpp.

References cancelButton_clicked(), modeButton_toggled(), mpButtonBox, mpMainLayout, mpMainWidget, mpModeCheckBox, mpSelectionWidget, okButton_clicked(), and CCopasiSelectionWidget::setOutputVector().

Referenced by getObjectSingle(), and getObjectVector().

38  :
39  QDialog(parent),
40  mpModeCheckBox(NULL),
41  mpButtonBox(NULL),
42  mpMainWidget(NULL),
43  mpMainLayout(NULL),
44  mpTmpVector(new std::vector< const CCopasiObject * >()),
45  mpOutputVector(NULL),
46  mExpertMode(false),
47  mExpertModeEnabled(true)
48 {
49  setObjectName(QString::fromUtf8(name));
50  setModal(modal);
51  setAttribute(Qt::WA_DeleteOnClose);
52  mpMainLayout = new QVBoxLayout(this);
53 
55  mpMainLayout->addWidget(mpSelectionWidget);
56 
57  mpButtonBox = new QHBoxLayout();
58  mpMainLayout->addLayout(mpButtonBox);
59 
60  QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
61  mpButtonBox->addWidget(box);
62 
63  mpModeCheckBox = new QCheckBox("expert mode", this);
64  mpModeCheckBox->setObjectName("expertMode");
65  mpModeCheckBox->setChecked(false);
66  mpButtonBox->addWidget(mpModeCheckBox);
67 
68  // this->mpButtonBox->addSpacing(20);
69  // this->mpButtonBox->addStretch();
70 
71  connect(box, SIGNAL(accepted()), this, SLOT(okButton_clicked()));
72  connect(box, SIGNAL(rejected()), this, SLOT(cancelButton_clicked()));
73  connect(this->mpModeCheckBox, SIGNAL(toggled(bool)), this, SLOT(modeButton_toggled(bool)));
74 
76 
77  this->setTabOrder(this->mpModeCheckBox, this->mpMainWidget);
78 }
CCopasiSelectionWidget * mpSelectionWidget
std::vector< const CCopasiObject * > * mpOutputVector
void setOutputVector(std::vector< const CCopasiObject * > *outputVector)
void modeButton_toggled(bool checked)
std::vector< const CCopasiObject * > * mpTmpVector
CCopasiSelectionDialog::~CCopasiSelectionDialog ( )

Definition at line 80 of file CCopasiSelectionDialog.cpp.

References mpTmpVector.

81 {
82  delete mpTmpVector;
83 }
std::vector< const CCopasiObject * > * mpTmpVector

Member Function Documentation

void CCopasiSelectionDialog::cancelButton_clicked ( )
protectedslot

Definition at line 103 of file CCopasiSelectionDialog.cpp.

Referenced by CCopasiSelectionDialog().

104 {
105  done(QDialog::Rejected);
106 }
std::vector< const CCopasiObject * > CCopasiSelectionDialog::chooseCellMatrix ( const CArrayAnnotation pArrayAnnotation,
bool  single,
bool  value,
std::string  caption = "" 
)
static

single=true means only one object can be returned (in the first element of the return vector) when single=true and the dialog is canceled the return vector will have size=1 and contain the NULL pointer. when single=false and the dialog is canceled the return vector will be empty. value=true means only objects that have a value (i.e. arrayElementReferences) are allowed. otherwise also the whole array annotation may be returned.

Definition at line 230 of file CCopasiSelectionDialog.cpp.

References CArrayAnnotation::addElementReference(), CArrayAnnotation::dimensionality(), FROM_UTF8, CCopasiObject::getObjectName(), CQMatrixDialog::setArray(), CArrayAnnotation::size(), TO_UTF8, and CQMessageBox::warning().

Referenced by CQPlotSubwidget::addCurve2D(), getObjectSingle(), and getObjectVector().

231 {
232  std::vector< const CCopasiObject* > returnVector;
233 
234  if (single)
235  {returnVector.resize(1); returnVector[0] = NULL;}
236  else
237  returnVector.resize(0);
238 
239  if (!pArrayAnnotation) return returnVector;
240 
241  //handle zero-dimensional array
242  if (pArrayAnnotation->size().size() == 0)
243  {
245  index.resize(0);
246  returnVector.resize(1);
247  returnVector[0] = static_cast< const CCopasiObject * >(pArrayAnnotation->addElementReference(index));
248  return returnVector;
249  }
250 
251  CQMatrixDialog * pDialog = new CQMatrixDialog();
252 
253  pDialog->setWindowTitle(tr(TO_UTF8(FROM_UTF8(caption) + "Cell Selection of " + FROM_UTF8(pArrayAnnotation->getObjectName()))));
254  pDialog->setArray(pArrayAnnotation, single);
255 
256  int Result = pDialog->exec();
257 
258  if (Result == QDialog::Accepted)
259  {
261  index.resize(pArrayAnnotation->dimensionality());
262 
263  if (index.size() > 2)
264  CQMessageBox::warning(0, "Dimensionality Problem", "Need more handle for high dimension of array",
265  QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton);
266 
267  if (single)
268  {
269  // single cell selection
270  if (value)
271  {
272  index[0] = pDialog->mpCBRow->currentIndex();
273 
274  if (index.size() > 1)
275  index[1] = pDialog->mpCBColumn->currentIndex();
276 
277  returnVector[0] = static_cast< const CCopasiObject * >(pArrayAnnotation->addElementReference(index));
278  }
279 
280  return returnVector;
281  }
282 
283  // multi cell selection
284 
285  //if "All" is selected for both rows and columns, and an object with numerical value
286  //is not requested, return the array annotation as such
287  if (pDialog->mpCBRow->currentIndex() == 0 && pDialog->mpCBColumn->currentIndex() == 0
288  && !value)
289  {
290  // whole matrix should be chosen -> the object itself will be returned
291  returnVector.resize(1);
292  returnVector[0] = (CCopasiObject *) pArrayAnnotation;
293  return returnVector;
294  }
295 
296  size_t minRows, maxRows, minCols, maxCols;
297  size_t i, j;
298 
299  if (pDialog->mpCBRow->currentIndex())
300  {
301  // not ALL option
302  minRows = pDialog->mpCBRow->currentIndex() - 1;
303  maxRows = minRows + 1;
304  }
305  else
306  {
307  // ALL option
308  minRows = 0;
309  maxRows = pArrayAnnotation->size()[0];
310  }
311 
312  if (index.size() == 2)
313  {
314  if (pDialog->mpCBColumn->currentIndex())
315  {
316  // not ALL option
317  minCols = pDialog->mpCBColumn->currentIndex() - 1;
318  maxCols = minCols + 1;
319  }
320  else
321  {
322  // ALL option
323  minCols = 0;
324  maxCols = pArrayAnnotation->size()[1];
325  }
326 
327  for (i = minRows; i < maxRows; ++i)
328  {
329  for (j = minCols; j < maxCols; ++j)
330  {
331  returnVector.push_back(static_cast< const CCopasiObject * >(pArrayAnnotation->addElementReference((int) i, (int) j)));
332  }
333  }
334  }
335 
336  if (index.size() == 1)
337  {
338  for (i = minRows; i < maxRows; ++i)
339  {
340  returnVector.push_back(static_cast< const CCopasiObject * >(pArrayAnnotation->addElementReference((int) i)));
341  }
342  }
343 
344  return returnVector;
345  }
346 
347  else
348  {
349  // Rejected case
350  if (single)
351  returnVector[0] = NULL;
352 
353  return returnVector;
354  }
355 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
std::vector< size_t > index_type
Definition: CCopasiArray.h:34
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
const CObjectInterface * addElementReference(CCopasiAbstractArray::index_type index) const
virtual void setArray(const CArrayAnnotation *tmp, bool single)
CCopasiAbstractArray::index_type size() const
size_t dimensionality() const
void CCopasiSelectionDialog::enableExpertMode ( bool  enable)

Definition at line 118 of file CCopasiSelectionDialog.cpp.

References mExpertModeEnabled, and mpModeCheckBox.

119 {
120  if (enable == this->mExpertModeEnabled) return;
121 
122  this->mExpertModeEnabled = enable;
123 
124  if (!this->mExpertModeEnabled)
125  {
126  this->mpModeCheckBox->setChecked(false);
127  this->mpModeCheckBox->hide();
128  }
129  else
130  {
131  this->mpModeCheckBox->show();
132  }
133 }
const CCopasiObject * CCopasiSelectionDialog::getObjectSingle ( QWidget *  pParent,
const CQSimpleSelectionTree::ObjectClasses classes,
const CCopasiObject pCurrentObject = NULL 
)
static

Definition at line 136 of file CCopasiSelectionDialog.cpp.

References CCopasiSelectionDialog(), chooseCellMatrix(), CCopasiRootContainer::getDatamodelList(), setModel(), setOutputVector(), and setSingleSelection().

Referenced by SliderSettingsDialog::browseButtonPressed(), Curve2DWidget::buttonPressedX(), BandedGraphWidget::buttonPressedX(), Curve2DWidget::buttonPressedY(), BandedGraphWidget::buttonPressedYone(), BandedGraphWidget::buttonPressedYtwo(), CQExperimentData::selectModelObject(), CQEventWidget1::slotAddTarget(), CScanWidgetRandom::slotChooseObject(), CScanWidgetScan::slotChooseObject(), SensitivitiesWidget::slotChooseSingleFunction(), SensitivitiesWidget::slotChooseSingleVariable(), SensitivitiesWidget::slotChooseSingleVariable2(), CQCrossSectionTaskWidget::slotChooseVariable(), CQFittingItemWidget::slotLowerEdit(), CQFittingItemWidget::slotParamEdit(), CQEventWidget1::slotSelectObject(), CQExpressionWidget::slotSelectObject(), and CQFittingItemWidget::slotUpperEdit().

139 {
140  std::vector< const CCopasiObject * > Selection;
141 
142  if (pCurrentObject != NULL)
143  Selection.push_back(pCurrentObject);
144 
145  CCopasiSelectionDialog * pDialog = new CCopasiSelectionDialog(parent);
146  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
147  pDialog->setWindowTitle("Select Item");
148  pDialog->setModel((*CCopasiRootContainer::getDatamodelList())[0]->getModel(), classes);
149  pDialog->setSingleSelection(true);
150  pDialog->setOutputVector(&Selection);
151 
152  int Result = pDialog->exec();
153 
154  if (Result == QDialog::Accepted && Selection.size() != 0)
155  {
156  const CCopasiObject *pObject = Selection[0];
157  const CArrayAnnotation * pArray;
158 
159  // if the selected object is an array then select firstly one cell of it
160  if ((pArray = dynamic_cast< const CArrayAnnotation * >(pObject)))
161  {
162  pObject = chooseCellMatrix(pArray, true, true)[0];
163 
164  if (!pObject) return NULL;
165  }
166 
167  return pObject;
168  }
169 
170  if (Result == QDialog::Rejected && pCurrentObject != NULL)
171  return pCurrentObject;
172 
173  return NULL;
174 }
void setSingleSelection(bool singleSelectionMode)
CCopasiSelectionDialog(QWidget *parent=0, const char *name=0, bool modal=false)
static std::vector< const CCopasiObject * > chooseCellMatrix(const CArrayAnnotation *pArrayAnnotation, bool single, bool value, std::string caption="")
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void setOutputVector(std::vector< const CCopasiObject * > *outputVector)
void setModel(const CModel *model, const CQSimpleSelectionTree::ObjectClasses &classes)
std::vector< const CCopasiObject * > CCopasiSelectionDialog::getObjectVector ( QWidget *  pParent,
const CQSimpleSelectionTree::ObjectClasses classes,
const std::vector< const CCopasiObject * > *  pCurrentSelection = NULL 
)
static

Definition at line 176 of file CCopasiSelectionDialog.cpp.

References CCopasiSelectionDialog(), chooseCellMatrix(), CCopasiRootContainer::getDatamodelList(), setModel(), setOutputVector(), and setSingleSelection().

Referenced by CQReportDefinition::btnItemClicked(), HistoWidget::buttonPressedX(), SliderDialog::createNewSlider(), ScanWidget::slotAddItem(), and CQFittingItemWidget::slotParamEdit().

179 {
180  std::vector< const CCopasiObject * > Selection;
181 
182  if (pCurrentSelection)
183  Selection = *pCurrentSelection;
184 
185  CCopasiSelectionDialog * pDialog = new CCopasiSelectionDialog(parent);
186  pDialog->setWindowTitle("Select Items");
187  pDialog->setToolTip("Select multiple items by holding down the Ctrl or Shift (or equivalent) key.");
188  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
189  pDialog->setModel((*CCopasiRootContainer::getDatamodelList())[0]->getModel(), classes);
190  pDialog->setSingleSelection(false);
191  pDialog->setOutputVector(&Selection);
192 
193  if (pDialog->exec() == QDialog::Rejected && pCurrentSelection)
194  return *pCurrentSelection;
195  else
196  // return Selection;
197  {
198  std::vector<const CCopasiObject *> newSelection;
199 
200  std::vector< const CCopasiObject * >::iterator itSelection = Selection.begin();
201 
202  for (; itSelection != Selection.end(); ++itSelection)
203  {
204  // if the current object is an array then select firstly one cell of it
205  const CArrayAnnotation * pArray;
206 
207  if ((pArray = dynamic_cast< const CArrayAnnotation * >(*itSelection)))
208  {
209  // second parameter is false in order 'ALL' options on the matrix dialog to appear
210  std::vector<const CCopasiObject *> tmp = chooseCellMatrix(pArray, false, true); //TODO value flag
211  std::vector<const CCopasiObject *>::const_iterator tmpit, tmpitEnd = tmp.end();
212 
213  for (tmpit = tmp.begin(); tmpit != tmpitEnd; ++tmpit)
214  newSelection.push_back(*tmpit);
215  }
216  // otherwise, just put it into newSelection
217  else
218  {
219  newSelection.push_back(*itSelection);
220  }
221  }
222 
223  return newSelection;
224  }
225 
226  // return Selection;
227 }
void setSingleSelection(bool singleSelectionMode)
CCopasiSelectionDialog(QWidget *parent=0, const char *name=0, bool modal=false)
static std::vector< const CCopasiObject * > chooseCellMatrix(const CArrayAnnotation *pArrayAnnotation, bool single, bool value, std::string caption="")
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
void setOutputVector(std::vector< const CCopasiObject * > *outputVector)
void setModel(const CModel *model, const CQSimpleSelectionTree::ObjectClasses &classes)
void CCopasiSelectionDialog::modeButton_toggled ( bool  checked)
protectedslot

Definition at line 108 of file CCopasiSelectionDialog.cpp.

References mpSelectionWidget, and CCopasiSelectionWidget::setExpertMode().

Referenced by CCopasiSelectionDialog().

109 {
110  this->mpSelectionWidget->setExpertMode(checked);
111 }
void setExpertMode(bool expertMode)
CCopasiSelectionWidget * mpSelectionWidget
void CCopasiSelectionDialog::okButton_clicked ( )
protectedslot

Definition at line 96 of file CCopasiSelectionDialog.cpp.

References CCopasiSelectionWidget::commit(), and mpSelectionWidget.

Referenced by CCopasiSelectionDialog().

97 {
98  // fill outputVector
99  this->mpSelectionWidget->commit();
100  done(QDialog::Accepted);
101 }
CCopasiSelectionWidget * mpSelectionWidget
void CCopasiSelectionDialog::setModel ( const CModel model,
const CQSimpleSelectionTree::ObjectClasses classes 
)

Definition at line 85 of file CCopasiSelectionDialog.cpp.

References mpSelectionWidget, and CCopasiSelectionWidget::populateTree().

Referenced by getObjectSingle(), and getObjectVector().

87 {
88  this->mpSelectionWidget->populateTree(pModel, classes);
89 }
CCopasiSelectionWidget * mpSelectionWidget
void populateTree(const CModel *model, const CQSimpleSelectionTree::ObjectClasses &classes)
void CCopasiSelectionDialog::setOutputVector ( std::vector< const CCopasiObject * > *  outputVector)

Definition at line 91 of file CCopasiSelectionDialog.cpp.

References mpSelectionWidget, and CCopasiSelectionWidget::setOutputVector().

Referenced by getObjectSingle(), and getObjectVector().

92 {
93  this->mpSelectionWidget->setOutputVector(outputVector);
94 }
CCopasiSelectionWidget * mpSelectionWidget
void setOutputVector(std::vector< const CCopasiObject * > *outputVector)
void CCopasiSelectionDialog::setSingleSelection ( bool  singleSelectionMode)

Definition at line 113 of file CCopasiSelectionDialog.cpp.

References mpSelectionWidget, and CCopasiSelectionWidget::setSingleSelection().

Referenced by getObjectSingle(), and getObjectVector().

114 {
115  this->mpSelectionWidget->setSingleSelection(singleSelectionMode);
116 }
void setSingleSelection(bool singleSelection)
CCopasiSelectionWidget * mpSelectionWidget

Member Data Documentation

bool CCopasiSelectionDialog::mExpertMode
protected

Definition at line 45 of file CCopasiSelectionDialog.h.

bool CCopasiSelectionDialog::mExpertModeEnabled
protected

Definition at line 46 of file CCopasiSelectionDialog.h.

Referenced by enableExpertMode().

QHBoxLayout* CCopasiSelectionDialog::mpButtonBox
protected

Definition at line 39 of file CCopasiSelectionDialog.h.

Referenced by CCopasiSelectionDialog().

QVBoxLayout* CCopasiSelectionDialog::mpMainLayout
protected

Definition at line 42 of file CCopasiSelectionDialog.h.

Referenced by CCopasiSelectionDialog().

QWidget* CCopasiSelectionDialog::mpMainWidget
protected

Definition at line 40 of file CCopasiSelectionDialog.h.

Referenced by CCopasiSelectionDialog().

QCheckBox* CCopasiSelectionDialog::mpModeCheckBox
protected

Definition at line 38 of file CCopasiSelectionDialog.h.

Referenced by CCopasiSelectionDialog(), and enableExpertMode().

std::vector<const CCopasiObject * >* CCopasiSelectionDialog::mpOutputVector
protected

Definition at line 44 of file CCopasiSelectionDialog.h.

CCopasiSelectionWidget* CCopasiSelectionDialog::mpSelectionWidget
protected
std::vector<const CCopasiObject * >* CCopasiSelectionDialog::mpTmpVector
protected

Definition at line 43 of file CCopasiSelectionDialog.h.

Referenced by ~CCopasiSelectionDialog().


The documentation for this class was generated from the following files: