COPASI API  4.16.103
CQArrayAnnotationsWidget.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 // Copyright (C) 2008 - 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 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifdef SunOS
16 #include <ieeefp.h>
17 #else
18 #include <cmath>
19 #endif
20 
21 #include "copasi.h"
22 
24 #include "qtUtilities.h"
25 #include "CQComboDelegate.h"
26 
27 #include <iostream>
28 
29 #include "barChart/qwt3dPlot.h"
30 
31 #include "resourcesUI/CQIconResource.h" //icons for bars and table toggle button
32 
33 #ifdef DEBUG_UI
34 #include <QtCore/QtDebug>
35 #endif
36 
38  QWidget(parent),
39  mWithBarChart(false),
40  mUseSliders(slider),
41  data(NULL),
42  mColors(),
43  mpArray(NULL),
44  mpColorScale(NULL),
45  mAutomaticColorScaling(false),
46  mRowIndex(C_INVALID_INDEX),
47  mColIndex(C_INVALID_INDEX),
48  mSelectedCell(),
49  mBarChartFilled(false),
50  mOneDimensional(false),
51  mComboEntries(),
52  mpComboDelegate(NULL)
53 {
54 #ifdef DEBUG_UI
55  qDebug() << "-- in constructor -- \n";
56 #endif
57 
58  setupUi(this);
59 
60  //Setting values for Combo Box
61  mpComboDelegate = new CQComboDelegate(NULL, this);
62  mpSelectionTable->setItemDelegateForColumn(1, mpComboDelegate);
63 
64  // The bar charts are temporary disabled
65  // mWithBarChart = false;
66  mWithBarChart = true;
67  mUseSliders = slider;
68  mBarChartFilled = false;
69  // mBarChartFilled = true;
70 
71  // if the 3D bar chart is activated, it needs a button to switch between table and bar chart
72  if (mWithBarChart)
73  {
74  if (mUseSliders)
75  {
76  mpPlot3d->setSliderActive(true);
77  }
78 
79  mBarChartFilled = false;
80 
81  connect(mpButton, SIGNAL(clicked()), this, SLOT(changeContents()));
82  }
83 
84  connect(mpContentTable, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(slotContentDoubleClicked()));
85  connect(mpContentTable, SIGNAL(cellClicked(int, int)), this, SLOT(slotContentCellClicked(int, int)));
86  connect(mpContentTable->horizontalHeader(), SIGNAL(sectionResized(int, int, int)), this, SLOT(setColumnSize(int, int, int)));
87 
88  connect(mpComboDelegate, SIGNAL(currentIndexChanged(int, int)), this, SLOT(slotCurrentSelectionIndexChanged(int, int)));
89 }
90 
92 {
93 #ifdef DEBUG_UI
94  qDebug() << "-- in destructor -- \n";
95 #endif
96 
97  if (mpColorScale)
98  delete mpColorScale;
99 }
100 
102 {
103 #ifdef DEBUG_UI
104  qDebug() << "-- in setColorCoding -- \n";
105 #endif
106 
107  if (cs && cs->isUsed())
108  {
109  cs = NULL; //donĀ“t accept a scaler that is already used
110  }
111 
112  if (mpColorScale)
113  delete mpColorScale;
114 
115  mpColorScale = cs;
116 
117  if (cs) cs->setIsUsed(true);
118 }
119 
121 {
122 #ifdef DEBUG_UI
123  qDebug() << "-- in setArrayAnnotation -- \n";
124 #endif
125 
126  mpArray = pArray;
127 
128  if (!mpArray)
129  {
130  mSelectedCell.clear();
131  clearWidget();
132  return;
133  }
134 
135  QStringList Items;
136  size_t i = 0, imax = mpArray->dimensionality();
137 
138  for (; i != imax; i++)
139  {
140  Items.append(FROM_UTF8(mpArray->getDimensionDescription(i)));
141  }
142 
143  mpComboRows->blockSignals(true);
144  mpComboRows->clear();
145  mpComboRows->addItems(Items);
146  mpComboRows->blockSignals(false);
147 
148  mpComboColumns->blockSignals(true);
149  mpComboColumns->clear();
150  mpComboColumns->addItems(Items);
151  mpComboColumns->blockSignals(false);
152 
153  // No practical use in allowing
154  // axes swap when 2 or 1 . . .
155  if(Items.size() < 3)
156  {
157  mpComboRows->setEnabled(false);
158  mpComboColumns->setEnabled(false);
159  }
160 
161  mSelectionIndex.resize(imax);
162  CCopasiAbstractArray::index_type::iterator it = mSelectionIndex.begin();
163  CCopasiAbstractArray::index_type::iterator end = mSelectionIndex.end();
164 
165  mSelectedCell.resize(imax);
166  CCopasiAbstractArray::index_type::iterator itCell = mSelectedCell.begin();
167 
168  for (; it != end; ++it)
169  {
170  *it = 0;
171  *itCell = 0;
172  }
173 
174  switch (imax)
175  {
176  case 0:
177  mpLblRows->hide();
178  mpComboRows->hide();
179  mpLblColumns->hide();
180  mpComboColumns->hide();
181  mpLblOther->hide();
182  mpSelectionTable->hide();
183 
186 
187  fillTable0();
188  break;
189 
190  case 1:
191  mpLblRows->show();
192  mpComboRows->show();
193  mpLblColumns->hide();
194  mpComboColumns->hide();
195  mpLblOther->hide();
196  mpSelectionTable->hide();
197 
199  break;
200 
201  case 2:
202  mpLblRows->show();
203  mpComboRows->show();
204  mpLblColumns->show();
205  mpComboColumns->show();
206  mpLblOther->hide();
207  mpSelectionTable->hide();
208 
210  break;
211 
212  default:
213  mpLblRows->show();
214  mpComboRows->show();
215  mpLblColumns->show();
216  mpComboColumns->show();
217  mpLblOther->hide();
218  mpSelectionTable->hide();
219 
220  // TODO CRITICAL We need to fill the selection table.
222  break;
223  }
224 }
225 
227 {
228 #ifdef DEBUG_UI
229  qDebug() << "-- in initSelectionTable -- \n";
230 #endif
231 
232  size_t i, imax = mpArray->dimensionality();
233 
234  mpSelectionTable->setRowCount((int) imax);
235  mpSelectionTable->setColumnCount(2);
236 
237  for (i = 0; i < imax; ++i)
238  {
239 
240  QTableWidgetItem *pItem = new QTableWidgetItem(FROM_UTF8(mpArray->getDimensionDescription(i)));
241  mpSelectionTable->setItem((int) i, 0, pItem);
242 
243  //combo box
244  QStringList ComboEntries;
246 
247  pItem = new QTableWidgetItem(ComboEntries[mSelectionIndex[i]]);
248  pItem->setData(Qt::EditRole, ComboEntries);
249  mpSelectionTable->setItem((int) i, 1, pItem);
250  }
251 
252  mpSelectionTable->resizeColumnsToContents();
253 
254  mpSelectionTable->show();
255 
256  mpSelectionTable->resizeColumnsToContents();
257  mpSelectionTable->resizeRowsToContents();
258 
259  mpSelectionTable->setMaximumHeight(mpSelectionTable->verticalHeader()->sectionSize(0) * (mpArray->dimensionality() + 1));
260 }
261 
263 {
264 #ifdef DEBUG_UI
265  qDebug() << "-- in clearWidget -- \n";
266 #endif
267 
268  //mpSelectionTable->setColumnCount(2);
269  mpSelectionTable->setRowCount(0);
270  mpContentTable->setColumnCount(0);
271  mpContentTable->setRowCount(0);
272 
274  {
275  if (mpPlot3d)
276  mpPlot3d->emptyPlot();
277 
278  mBarChartFilled = false;
279  }
280 }
281 
283 {
284 #ifdef DEBUG_UI
285  qDebug() << "-- in setLegendEnabled -- \n";
286 #endif
287 
288  if (b)
289  mpSelectionTable->show();
290  else
291  mpSelectionTable->hide();
292 }
293 
295 {
296  // Assure that row and column dimension are not the same
297  if (mpComboColumns->currentIndex() == row)
298  {
299  mpComboColumns->blockSignals(true);
300  mpComboColumns->setCurrentIndex(row == 0 ? 1 : 0);
301  mpComboColumns->blockSignals(false);
302 
303  mpSelectionTable->showRow(mColIndex);
304  mColIndex = mpComboColumns->currentIndex();
305  mpSelectionTable->hideRow(mColIndex);
306  }
307 
308  mpSelectionTable->showRow(mRowIndex);
309  mRowIndex = row;
310  mpSelectionTable->hideRow(mRowIndex);
311 
312  fillTable();
313 }
314 
316 {
317  // Assure that row and column dimension are not the same
318  if (mpComboRows->currentIndex() == col)
319  {
320  mpComboRows->blockSignals(true);
321  mpComboRows->setCurrentIndex(col == 0 ? 1 : 0);
322  mpComboRows->blockSignals(false);
323 
324  mpSelectionTable->showRow(mRowIndex);
325  mRowIndex = mpComboRows->currentIndex();
326  mpSelectionTable->hideRow(mRowIndex);
327  }
328 
329  mpSelectionTable->showRow(mColIndex);
330  mColIndex = col;
331  mpSelectionTable->hideRow(mColIndex);
332 
333  fillTable();
334 }
335 
337 {
338  mSelectionIndex[row] = index;
339  fillTable();
340 }
341 
343 {
344  if (!mpArray) return;
345 
346  switch (mpArray->dimensionality())
347  {
348  case 0:
349  fillTable0();
350  break;
351 
352  case 1:
354  break;
355 
356  default:
358  break;
359  }
360 
361  return;
362 }
363 
364 void CQArrayAnnotationsWidget::fillTableN(size_t rowIndex, size_t colIndex,
365  const CCopasiAbstractArray::index_type & index)
366 {
367 #ifdef DEBUG_UI
368  qDebug() << "-- in fillTable0 A -- \n";
369 #endif
370 
371  if (!mpArray) return;
372 
373  assert(rowIndex < index.size());
374  assert(colIndex < index.size());
375 
376  mpContentTable->setColumnCount((int) mpArray->size()[colIndex]);
377  mpContentTable->setRowCount((int) mpArray->size()[rowIndex]);
378 
379  std::vector<std::string> rowdescr = mpArray->getAnnotationsString(rowIndex);
380  std::vector<std::string> coldescr = mpArray->getAnnotationsString(colIndex);
381 
382  size_t i, imax = mpArray->size()[rowIndex];
383  size_t j, jmax = mpArray->size()[colIndex];
384 
385  if (jmax == 0) return;
386 
387  int TableWidth = mpContentTable->size().width();
388  mpContentTable->verticalHeader()->setMaximumWidth(TableWidth / std::min< size_t >(jmax, 5));
389  mpContentTable->verticalHeader()->setTextElideMode(Qt::ElideRight);
390  mpContentTable->horizontalHeader()->setTextElideMode(Qt::ElideRight);
391 
392  QString DisplayName;
393 
394  //annotations
395  for (i = 0; i < imax; ++i)
396  {
397  DisplayName = FROM_UTF8(rowdescr[i]);
398  QTableWidgetItem * pItem = new QTableWidgetItem(DisplayName);
399  pItem->setToolTip(DisplayName);
400  mpContentTable->setVerticalHeaderItem(i, pItem);
401  }
402 
403  for (j = 0; j < jmax; ++j)
404  {
405  // :TODO: This is a hack we need a smarter way possibly using getObjectDisplayName.
406  DisplayName = FROM_UTF8(coldescr[j]).replace("; {", "\n{");
407  QTableWidgetItem * pItem = new QTableWidgetItem(DisplayName);
408  pItem->setToolTip(DisplayName);
409  mpContentTable->setHorizontalHeaderItem((int) j, pItem);;
410 
411 #ifdef DEBUG_UI
412  qDebug() << "text on col " << j << " = " << FROM_UTF8(coldescr[j]).replace("; {", "\n{");
413 #endif
414  }
415 
416  CCopasiAbstractArray::index_type Index = index;
417 
418  //automatic color scaling
420  {
422 
423  for (i = 0; i < imax; ++i)
424  for (j = 0; j < jmax; ++j)
425  {
426  Index[rowIndex] = i;
427  Index[colIndex] = j;
428  mpColorScale->passValue((*mpArray->array())[Index]);
429  }
430 
432  }
433 
434  //table contents
435  for (i = 0; i < imax; ++i)
436  for (j = 0; j < jmax; ++j)
437  {
438  Index[rowIndex] = i;
439  Index[colIndex] = j;
440 
441  QTableWidgetItem * pItem = new QTableWidgetItem(QString::number((*mpArray->array())[Index]));
442  mpContentTable->setItem((int) i, (int) j, pItem);
443 
444  if (mpColorScale != NULL)
445  {
446  pItem->setBackground(QBrush(mpColorScale->getColor((*mpArray->array())[Index])));
447  }
448  }
449 
450  mOneDimensional = false;
451 
452  mpContentTable->resizeRowsToContents();
453  mpContentTable->resizeColumnsToContents();
454 
455 // if (mpStack->id(mpStack->visibleWidget()) == 1)
456  if (mpStack->currentIndex() == 1)
457  fillBarChart();
458 }
459 
461  const CCopasiAbstractArray::index_type & index)
462 {
463 #ifdef DEBUG_UI
464  qDebug() << "-- in fillTable0 B -- \n";
465 #endif
466 
467  if (!mpArray) return;
468 
469  assert(rowIndex < index.size());
470 
471  mpContentTable->setColumnCount(1);
472  mpContentTable->setRowCount((int) mpArray->size()[rowIndex]);
473 
474  mpContentTable->setHorizontalHeaderItem(0, new QTableWidgetItem(""));
475 
476  size_t i, imax = mpArray->size()[rowIndex];
477 
478  CCopasiAbstractArray::index_type Index = index;
479 
480  //automatic color scaling
482  {
484 
485  for (i = 0; i < imax; ++i)
486  {
487  Index[rowIndex] = i;
488  mpColorScale->passValue((*mpArray->array())[Index]);
489  }
490 
492  }
493 
494  //table contents and annotations
495  const std::vector<std::string> & rowdescr = mpArray->getAnnotationsString(rowIndex);
496 
497  for (i = 0; i < imax; ++i)
498  {
499  Index[rowIndex] = i;
500  QTableWidgetItem * pItem = new QTableWidgetItem(FROM_UTF8(rowdescr[i]));
501  mpContentTable->setVerticalHeaderItem((int) i, pItem);
502 
503  pItem = new QTableWidgetItem(QString::number((*mpArray->array())[Index]));
504  mpContentTable->setItem((int) i, 0, pItem);
505 
506  if (mpColorScale != NULL)
507  {
508  pItem->setBackground(QBrush(mpColorScale->getColor((*mpArray->array())[Index])));
509  }
510  }
511 
512  mOneDimensional = true;
513 
514  mpContentTable->resizeRowsToContents();
515  mpContentTable->resizeColumnsToContents();
516 
517  if (mpStack->currentIndex() == 1)
518  fillBarChart();
519 }
520 
522 {
523 #ifdef DEBUG_UI
524  qDebug() << "-- in fillTable0 C -- \n";
525 #endif
526 
527  if (!mpArray) return;
528 
529  mpContentTable->setColumnCount(0);
530  mpContentTable->setRowCount(0);
531  mpContentTable->setColumnCount(1);
532  mpContentTable->setRowCount(1);
533 
534  mpContentTable->setHorizontalHeaderItem(0, new QTableWidgetItem(""));
535  mpContentTable->setVerticalHeaderItem(0, new QTableWidgetItem(""));
536 
537  CCopasiAbstractArray::index_type index; index.resize(0);
538  //mpContentTable->verticalHeader()->setLabel(i, FROM_UTF8(rowdescr[i]));
539  mpContentTable->setItem(0, 0, new QTableWidgetItem(QString::number((*mpArray->array())[index])));
540 }
541 
543 {
544 #ifdef DEBUG_UI
545  qDebug() << "-- in changeContents -- \n";
546 #endif
547 
548 // if (mpStack->id(mpStack->visibleWidget()) == 0)
549  if (mpStack->currentIndex() == 0)
551  else
552  switchToTable();
553 }
554 
556 {
557 #ifdef DEBUG_UI
558  qDebug() << "-- in enableBarChart -- \n";
559 #endif
560 
561  if (mWithBarChart)
562  {
563  if (enable)
564  {
565  mpButton->setEnabled(true);
566  }
567  else
568  {
569 // if (mpStack->id(mpStack->visibleWidget()) == 1)
570  if (mpStack->currentIndex() == 1)
571  switchToTable();
572 
573  //mpStack->raiseWidget(0);
574  mpButton->setEnabled(false);
575  }
576  }
577 }
578 
579 /*!
580  Function to switch the appearance to table
581  */
583 {
584 #ifdef DEBUG_UI
585  qDebug() << "-- in switchToTable -- \n";
586 
587  qDebug() << "A mpStack->currentIndex() = " << mpStack->currentIndex();
588 #endif
589 
590 // mpStack->raiseWidget(0);
591  mpStack->setCurrentWidget(mpContentTable);
592 
593 #ifdef DEBUG_UI
594  qDebug() << "B mpStack->currentIndex() = " << mpStack->currentIndex();
595 #endif
596 
597  if (mWithBarChart)
598  {
599  mpButton->setIcon(CQIconResource::icon(CQIconResource::bars));
600  setFocusOnTable();
601  }
602 }
603 
604 /*!
605  Function to switch the appearance to bar chart
606  */
608 {
609 #ifdef DEBUG_UI
610  qDebug() << "-- in switchToBarChart -- \n";
611 #endif
612 
613  if (mWithBarChart)
614  {
615  if (!mpPlot3d)
616  createBarChart();
617 
618 // setFocusOnBars();
619 
620  if (!mBarChartFilled)
621  fillBarChart();
622 
623 // setFocusOnBars();
624  setFocusOnBars();
625 
626 // mpStack->raiseWidget(1);
627  mpStack->setCurrentWidget(mpPlot3d);
628  mpPlot3d->show();
629 
630  mpButton->setIcon(CQIconResource::icon(CQIconResource::table));
631  }
632 }
633 
635 {
636 #ifdef DEBUG_UI
637  qDebug() << "-- in disableBarChart -- \n";
638 #endif
639 
640  switchToTable();
641  mpButton->hide();
642 }
643 
645 {
646 #ifdef DEBUG_UI
647  qDebug() << "-- in disableSlider -- \n";
648 #endif
649 
650  if (mpPlot3d && mpPlot3d->isSliderActive())
651  {
652  mpPlot3d->setSliderActive(false);
653  }
654 }
655 
656 /*!
657  Function to set the appearance focus on table
658  */
660 {
661 #ifdef DEBUG_UI
662  qDebug() << "-- in setFocusOnTable -- \n";
663 
664  qDebug() << "boolean mWithBarChart = " << mWithBarChart;
665  qDebug() << "boolean mpPlot3d = " << mpPlot3d;
666  qDebug() << "boolean mpPlot3d->sliderActive() = " << mpPlot3d->sliderActive();
667 #endif
668 
669  if (mWithBarChart && mpPlot3d && mpPlot3d->isSliderActive())
670  {
671  int col = mpPlot3d->mpSliderColumn->value() / mpPlot3d->scaleFactor();
672  int row = mpPlot3d->mpSliderRow->value() / mpPlot3d->scaleFactor();
673 
674 #ifdef DEBUG_UI
675  qDebug() << "col = " << col << " - row = " << row;
676 #endif
677 
678  mpContentTable->clearSelection();
679 
680  if (col < mpContentTable->columnCount())
681  {
682  if (row < mpContentTable->rowCount())
683  {
684  mpContentTable->setCurrentCell(row, col);
685  mpContentTable->scrollToItem(mpContentTable->item(mpContentTable->currentRow(), mpContentTable->currentColumn()));
686  mpContentTable->setFocus();
687  }
688  else
689  {
690  mpContentTable->selectColumn(col);
691  mpContentTable->setFocus();
692  }
693  }
694  else
695  {
696  if (row < mpContentTable->rowCount())
697  {
698  mpContentTable->selectRow(row);
699  mpContentTable->setFocus();
700  }
701  else
702  {
703  mpContentTable->setCurrentCell(-1, -1);
704  }
705  }
706 
707 #ifdef DEBUG_UI
708  qDebug() << "label at col = " << mpContentTable->horizontalHeader()->label(col);
709 #endif
710  /*
711  if (mpContentTable->horizontalHeader()->label(col).isEmpty())
712  mpContentTable->horizontalHeader()->setLabel(col, FROM_UTF8((mpArray->getAnnotationsString(1))[col]).replace("; {", "\n{"));
713  */
714  }
715 
716 // mpContentTable->horizontalHeader()->repaint();
717 // mpContentTable->update();
718 #ifdef DEBUG_UI
719  qDebug() << "at the end of setFocusOnTable";
720 #endif
721 }
722 
723 /*!
724  Function to set the appearance focus on bars
725  */
727 {
728  if (mWithBarChart && mpPlot3d && mpPlot3d->isSliderActive())
729  {
730  QList<QTableWidgetSelectionRange> Ranges = mpContentTable->selectedRanges();
731 
732  if (Ranges.size() == 1)
733  {
734  int SliderColumn = Ranges[0].leftColumn() * mpPlot3d->scaleFactor();
735  int SliderRow = Ranges[0].topRow() * mpPlot3d->scaleFactor();
736 
737  if (Ranges[0].leftColumn() == Ranges[0].rightColumn() &&
738  Ranges[0].topRow() == Ranges[0].bottomRow())
739  {
740  mpPlot3d->mpSliderColumn->setValue(SliderColumn);
741  mpPlot3d->mpSliderRow->setValue(SliderRow);
742  mpPlot3d->sliderMoved(Ranges[0].leftColumn(), Ranges[0].topRow());
743  mpPlot3d->setSlider();
744 
745  return;
746  }
747  else if (Ranges[0].leftColumn() == Ranges[0].rightColumn())
748  {
749  mpPlot3d->mpSliderColumn->setValue(SliderColumn);
750  mpPlot3d->mpSliderRow->setValue(-1);
751  mpPlot3d->sliderMoved(Ranges[0].leftColumn(), mpContentTable->rowCount());
752  mpPlot3d->setSlider();
753 
754  return;
755  }
756  else if (Ranges[0].topRow() == Ranges[0].bottomRow())
757  {
758  mpPlot3d->mpSliderColumn->setValue(-1);
759  mpPlot3d->mpSliderRow->setValue(SliderRow);
760  mpPlot3d->sliderMoved(mpContentTable->columnCount(), Ranges[0].topRow());
761  mpPlot3d->setSlider();
762 
763  return;
764  }
765  }
766 
767  mpPlot3d->mpSliderColumn->setValue(-1);
768  mpPlot3d->mpSliderRow->setValue(-1);
769  mpPlot3d->sliderMoved(mpContentTable->columnCount(), mpContentTable->rowCount());
770  mpPlot3d->setSlider();
771  }
772 
773  return;
774 }
775 
777 {
778  switch (mSelectedCell.size())
779  {
780  case 0:
781  break;
782 
783  case 1:
784  mSelectedCell[mRowIndex] = row;
785  break;
786 
787  default:
788  mSelectedCell[mRowIndex] = row;
789  mSelectedCell[mColIndex] = col;
790  break;
791  }
792 
793  return;
794 }
795 
797 {
798 #ifdef DEBUG_UI
799  qDebug() << "-- in slotContentDoubleClicked -- \n";
800 #endif
801 
802  if (mpPlot3d && mpPlot3d->isSliderActive())
804 }
805 
806 void CQArrayAnnotationsWidget::setColumnSize(int col, int /*size0*/, int /*size*/)
807 {
808  disconnect(mpContentTable->horizontalHeader(), SIGNAL(sectionResized(int, int, int)), this, SLOT(setColumnSize(int, int, int)));
809 
810 #ifdef DEBUG_UI
811  qDebug() << "-- in setColumnSize -- \n";
812 #endif
813 
814  C_INT32 i;
815  C_FLOAT64 sum = 0;
816 
817  for (i = 0; i <= col; ++i)
818  sum += mpContentTable->horizontalHeader()->sectionSize(i);
819 
820  C_FLOAT64 newSize = sum / (col + 1);
821 
822  if (newSize < 5) newSize = 5;
823 
824  for (i = 0; i < mpContentTable->columnCount(); i++)
825  mpContentTable->setColumnWidth(i, ((int)(newSize * (i + 1))) - ((int)(newSize * i)));
826 
827  mpContentTable->horizontalHeader()->repaint();
828 
829  connect(mpContentTable->horizontalHeader(), SIGNAL(sectionResized(int, int, int)), this, SLOT(setColumnSize(int, int, int)));
830 }
831 
833 {
834 #ifdef DEBUG_UI
835  qDebug() << "-- in fillBarChart -- \n";
836 #endif
837 
838  if (!mWithBarChart)
839  return;
840 
841  if (!mpPlot3d)
842  createBarChart();
843 
844 // mBarChartFilled = true;
845 
846  if (!mpArray) return;
847 
848  mBarChartFilled = true;
849 
850 #ifdef DEBUG_UI
851  qDebug() << "mRowIndex = " << mRowIndex << " - mIndex.size() = " << mSelectedCell.size();
852 #endif
853 
854  std::vector<size_t> types = mpArray->size();
855  size_t imax = types.size() > mRowIndex ? types[mRowIndex] : 0;
856  size_t jmax = mOneDimensional ? 1 : types.size() > mColIndex ? types[mColIndex] : 0;
857 
858  if (imax == 0 || jmax == 0)
859  {
860  mpPlot3d->emptyPlot();
861  mBarChartFilled = false;
862  return;
863  }
864 
865  mpContentTable->setRowCount((int) imax);
866 
867  if (mOneDimensional)
868  mpContentTable->setColumnCount(1);
869  else
870  mpContentTable->setColumnCount((int) jmax);
871 
872 // mpContentTable->horizontalHeader()->setLabel(0, ""); --> ???
873 
874  std::vector<std::string> rowdescr = mpArray->getAnnotationsString(mRowIndex);
875 
876  if (!mOneDimensional)
877  std::vector<std::string> coldescr = mpArray->getAnnotationsString(mColIndex);
878 
879  size_t i;
880  size_t j;
881 
882  if (jmax > 0 && imax > 0)
883  {
884  //create a new array data, witch holds the hole numeric data
885  size_t columns = jmax;
886  size_t rows = imax;
887  data = new double * [columns];
888 
889  for (i = 0; i < columns; ++i)
890  data[i] = new double[rows];
891 
892  //minValue and maxValue help to figure out the min and max value
894 
895  if (!mOneDimensional)
897 
898  double maxValue = (double)(*mpArray->array())[mSelectedCell];
899  double minValue = (double)(*mpArray->array())[mSelectedCell];
900 
901  //fill array data with values and figure out min/max value
902  for (i = 0; i < imax; ++i)
903  for (j = 0; j < jmax; ++j)
904  {
906 
907  if (!mOneDimensional)
909 
910  if (isnan((double)(*mpArray->array())[mSelectedCell]) ||
911  !finite((double)(*mpArray->array())[mSelectedCell]))
912  {
913  data[j][i] = 0;
914 
915  if (0 > maxValue) maxValue = 0;
916 
917  if (0 < minValue) minValue = 0;
918  }
919  else
920  {
921  data[j][i] = (double)(*mpArray->array())[mSelectedCell];
922 
923  if ((double)(*mpArray->array())[mSelectedCell] > maxValue)
924  maxValue = (double)(*mpArray->array())[mSelectedCell];
925 
926  if ((double)(*mpArray->array())[mSelectedCell] < minValue)
927  minValue = (double)(*mpArray->array())[mSelectedCell];
928  }
929  }
930 
931  //figure out the min/max print section
932  double minZ, maxZ;
933 
934  if ((minValue < 0) && (maxValue < 0))
935  {
936  //(all values < 0)
937  minZ = minValue;
938  maxZ = 0;
939  }
940  else
941  {
942  if ((minValue > 0) && (maxValue > 0))
943  {
944  //(all values > 0)
945  minZ = 0;
946  maxZ = maxValue;
947  }
948  else
949  {
950  //(values <> 0)
951  minZ = minValue;
952  maxZ = maxValue;
953  }
954  }
955 
956  //fill vector mColor with 100 colors, evenly distributed over relevant print section
957  double holeSection = maxZ - minZ;
958  double step = holeSection / 99;
959 
960  for (i = 0; i < 100; i++)
961  {
962  mColors.push_back((int) i);
963  mColors[i] = mpColorScale->getColor(minZ + i * step);
964  }
965 
966  //deliver plot3D contents, colors and annotations
967  if ((maxValue == 0) && (minValue == 0))
968  {
969  mpPlot3d->emptyPlot();
970  mBarChartFilled = false;
971  return;
972  }
973  else
974  {
975 
976  mpPlot3d->setPlotTitle(QString(""));
977  mpPlot3d->setColors(mColors, minZ, maxZ);
978  mColors.erase(mColors.begin(), mColors.end());
979  mpPlot3d->showColorLegend(true);
980 
981  if (mOneDimensional)
982  mpPlot3d->setDescriptions(NULL, &mpArray->getAnnotationsString(mRowIndex));
983  else
985 
986  mpPlot3d->setData(data, (int) columns, (int) rows, holeSection);
987  enableBarChart(true);
988  }
989  }
990  else
991  {
992  mpPlot3d->emptyPlot();
993  mBarChartFilled = false;
994  return;
995  }
996 }
997 
998 /*!
999  Function to create the 3D bar chart
1000  */
1002 {
1003 #ifdef DEBUG_UI
1004  qDebug() << "-- in createBarChart -- \n";
1005 #endif
1006 
1007  mpPlot3d = new CQBarChart();
1008  mpPlot3d->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
1009 
1010  if (mUseSliders) mpPlot3d->setSliderActive(true);
1011 
1012 // mpStack->addWidget(mpPlot3d, 1);
1013  mpStack->addWidget(mpPlot3d);
1014  mpButton->setIcon(CQIconResource::icon(CQIconResource::bars));
1015  mBarChartFilled = false;
1016 }
void setColumnSize(int col, int size0, int size)
void slotContentCellClicked(int row, int col)
const std::string & getDimensionDescription(size_t d) const
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::vector< std::string > & getAnnotationsString(size_t d, bool display=true) const
void setColorCoding(CColorScale *cs)
CCopasiAbstractArray * array()
#define C_INVALID_INDEX
Definition: copasi.h:222
std::vector< size_t > index_type
Definition: CCopasiArray.h:34
#define C_INT32
Definition: copasi.h:90
const CArrayAnnotation * mpArray
CCopasiAbstractArray::index_type mSelectionIndex
virtual void startAutomaticParameterCalculation()
Definition: CColorScale.h:47
void setArrayAnnotation(const CArrayAnnotation *pArray)
virtual void finishAutomaticParameterCalculation()
Definition: CColorScale.h:57
void vectorOfStrings2QStringList(std::vector< std::string > vs, QStringList &qsl)
virtual QColor getColor(const C_FLOAT64 &number)=0
static const QIcon & icon(const IconID &id)
CCopasiAbstractArray::index_type mSelectedCell
virtual void passValue(const C_FLOAT64 &)
Definition: CColorScale.h:52
void slotCurrentSelectionIndexChanged(int row, int index)
void fillTableN(size_t rowIndex, size_t colIndex, const CCopasiAbstractArray::index_type &index)
#define C_FLOAT64
Definition: copasi.h:92
bool isUsed() const
Definition: CColorScale.h:68
void setIsUsed(bool f)
Definition: CColorScale.h:62
CCopasiAbstractArray::index_type size() const
size_t dimensionality() const
void fillTable1(size_t rowIndex, const CCopasiAbstractArray::index_type &index)
CQArrayAnnotationsWidget(QWidget *parent=0, bool slider=true)