CFEL - ASG Software Suite  2.5.0
CASS
jocassviewer.cpp
Go to the documentation of this file.
1 // Copyright (C) 2013 Lutz Foucar
2 
3 /**
4  * @file jocassviewer.cpp contains the jocassviewer
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <QtCore/QFileInfo>
10 #include <QtCore/QDebug>
11 #include <QtCore/QSettings>
12 #include <QtCore/QDir>
13 #include <QtCore/QDateTime>
14 
15 #if QT_VERSION >= 0x050000
16 #include <QtWidgets/QMessageBox>
17 #include <QtWidgets/QInputDialog>
18 #include <QtWidgets/QMenuBar>
19 #include <QtWidgets/QMenu>
20 #include <QtWidgets/QToolBar>
21 #include <QtWidgets/QLineEdit>
22 #include <QtWidgets/QSpinBox>
23 #include <QtWidgets/QDoubleSpinBox>
24 #include <QtWidgets/QLabel>
25 #include <QtWidgets/QStatusBar>
26 #include <QtWidgets/QListWidget>
27 #include <QtWidgets/QFileDialog>
28 #include <QtWidgets/QApplication>
29 #else
30 #include <QtGui/QMessageBox>
31 #include <QtGui/QInputDialog>
32 #include <QtGui/QMenuBar>
33 #include <QtGui/QMenu>
34 #include <QtGui/QToolBar>
35 #include <QtGui/QLineEdit>
36 #include <QtGui/QSpinBox>
37 #include <QtGui/QDoubleSpinBox>
38 #include <QtGui/QLabel>
39 #include <QtGui/QStatusBar>
40 #include <QtGui/QListWidget>
41 #include <QtGui/QFileDialog>
42 #include <QtGui/QApplication>
43 #endif
44 #include <QtGui/QMoveEvent>
45 #include <QtGui/QResizeEvent>
46 
47 #include "jocassviewer.h"
48 
49 #include "result.hpp"
50 #include "file_handler.h"
51 #include "zero_d_viewer.h"
52 #include "one_d_viewer.h"
53 #include "two_d_viewer.h"
54 #include "status_led.h"
55 #include "data_source.h"
56 #include "data.h"
57 #include "tcpclient.h"
58 #include "data_source_manager.h"
59 
60 using namespace jocassview;
61 using namespace cass;
62 using namespace std;
63 
64 
65 JoCASSViewer::JoCASSViewer(QWidget *parent, Qt::WindowFlags flags)
66  : QMainWindow(parent,flags),
67  _updateInProgress(false)
68 {
69  QSettings settings;
70  TCPClient *client(new TCPClient);
71 
72  /** set up the window */
73  // Add a menu to the window
74  QMenuBar *menu = menuBar();
75 
76  // Add file menu
77  QMenu *fmenu = menu->addMenu(tr("&File"));
78  fmenu->addAction(QIcon::fromTheme("document-open"),tr("Load Data"),this,
79  SLOT(openFile()),QKeySequence(QKeySequence::Open))->setShortcutContext(Qt::ApplicationShortcut);
80  fmenu->addAction(QIcon::fromTheme("document-save"),tr("Save"),this,
81  SLOT(autoSave()),QKeySequence(tr("F10")))->setShortcutContext(Qt::ApplicationShortcut);
82  fmenu->addAction(QIcon::fromTheme("document-save"),tr("Save Images"),this,
83  SLOT(autoSaveImages()),QKeySequence(tr("F9")))->setShortcutContext(Qt::ApplicationShortcut);
84  fmenu->addAction(QIcon::fromTheme("document-save-as"),tr("Save as..."),this,
85  SLOT(saveFile()),QKeySequence(QKeySequence::SaveAs))->setShortcutContext(Qt::ApplicationShortcut);
86  fmenu->addAction(QIcon::fromTheme("document-print"),tr("Print"),this,
87  SLOT(print()),QKeySequence(QKeySequence::Print))->setShortcutContext(Qt::ApplicationShortcut);
88  fmenu->addSeparator();
89  fmenu->addAction(QIcon::fromTheme("application-exit"),tr("Quit"),qApp,
90  SLOT(closeAllWindows()),QKeySequence("Ctrl+q"))->setShortcutContext(Qt::ApplicationShortcut);
91 
92  // Add control menu
93  QMenu *cmenu = menu->addMenu(tr("&Control"));
94  cmenu->addAction(tr("Refresh List"),this,
95  SLOT(refreshDisplayableItemsList()),QKeySequence(tr("F5")))->setShortcutContext(Qt::ApplicationShortcut);
96  cmenu->addAction(tr("Get Data"),this,
97  SLOT(updateViewers()),QKeySequence(tr("Ctrl+i")))->setShortcutContext(Qt::ApplicationShortcut);
98  cmenu->addAction(tr("Clear Histogram"),this,
99  SLOT(clearHistogram()));
100  cmenu->addAction(tr("Send custom Command"),this,
101  SLOT(sendCustomCommand()));
102  cmenu->addAction(tr("Broadcast darkcal command"),this,
103  SLOT(broadcastDarkcalCommand()),QKeySequence(tr("Ctrl+d")))->setShortcutContext(Qt::ApplicationShortcut);
104  cmenu->addAction(tr("Broadcast gaincal command"),this,
105  SLOT(broadcastGaincalCommand()),QKeySequence(tr("Ctrl+g")))->setShortcutContext(Qt::ApplicationShortcut);
106  cmenu->addSeparator()->setText("Server Control");
107  cmenu->addAction(tr("Reload ini File"),client,
108  SLOT(reloadIni()),QKeySequence(tr("Ctrl+r")))->setShortcutContext(Qt::ApplicationShortcut);
109  cmenu->addAction(tr("Quit Server"),client,SLOT(quitServer()));
110 
111  // Add the source menu
112  DataSourceManager::setMenu(menu->addMenu(tr("&Sources")));
113 
114  // Add help menu
115  QMenu *hmenu = menu->addMenu(tr("&Help"));
116  hmenu->addAction(tr("About"),this,SLOT(about()));
117  hmenu->addAction(tr("About Qt"),qApp,SLOT(aboutQt()));
118 
119  // Add a toolbar where we can add the general tools
120  _serverToolBar = addToolBar(tr("Display control"));
121  _serverToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
122 
123  // Add servername and port to toolbar.
124  _servername = new QLineEdit(settings.value("Servername", "localhost").toString());
125  _servername->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
126  _servername->setToolTip(tr("Name of the server to connect to."));
127  connect(_servername,SIGNAL(textEdited(QString)),this,SLOT(changeServerAddress()));
129 
130  _serverport = new QSpinBox();
131  _serverport->setKeyboardTracking(false);
132  _serverport->setRange(1000, 50000);
133  _serverport->setValue(settings.value("Serverport", 12321).toInt());
134  _serverport->setToolTip(tr("Port of the server to connect to."));
135  connect(_serverport,SIGNAL(valueChanged(int)),this,SLOT(changeServerAddress()));
137 
138  // Add spacer to toolbar.
139  QWidget *spacer1(new QWidget());
140  spacer1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
141  _serverToolBar->addWidget(spacer1);
142 
143  // Add a separator
145 
146  // Add spacer to toolbar.
147  QWidget *spacer2(new QWidget());
148  spacer2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
149  _serverToolBar->addWidget(spacer2);
150 
151  // Add run control to toolbar.
152  _autoUpdate = new QAction(QIcon(":images/auto_update.png"),tr("Toggle auto update"),_serverToolBar);
153  _autoUpdate->setCheckable(true);
154  _autoUpdate->setChecked(settings.value("AutoUpdateOn",false).toBool());
155  _autoUpdate->setToolTip(tr("If checked, continuously retrieve and display images."));
156  connect(_autoUpdate,SIGNAL(triggered()),
157  this,SLOT(changeAutoUpdate()));
159 
160  // Add status LED to toolbar.
161  _statusLED = new StatusLED();
162  _statusLED->setToolTip("Status indicator (green = Data retrieved ok, red = communciation Problems, yellow = busy).");
165 
166  // Add rate to toolbar.
167  _rate = new QDoubleSpinBox();
168  _rate->setRange(0.01, 100.);
169  _rate->setValue(settings.value("Rate", 10.).toDouble());
170  _rate->setToolTip(tr("Image update frequency."));
171  connect(_rate,SIGNAL(valueChanged(double)),
172  this,SLOT(changeAutoUpdate()));
174  QLabel *punit = new QLabel;
175  punit->setText("Hz");
176  _serverToolBar->addWidget(punit);
177 
178  // set up status bar
179  statusBar()->setToolTip(tr("Actual frequency to get and display "
180  "images averaged over (n) times."));
181 
182  // Set a list item as central widget
183  QListWidget *listview(new QListWidget(this));
184  listview->setSelectionMode(QAbstractItemView::MultiSelection);
185  connect(listview,SIGNAL(itemClicked(QListWidgetItem*)),
186  this,SLOT(changeViewers(QListWidgetItem*)));
187  setCentralWidget(listview);
188 
189  /** use the timer as single shot */
190  _updateTimer.setSingleShot(true);
191  connect(&_updateTimer,SIGNAL(timeout()),this,SLOT(updateViewers()));
192 
193  /** initialize the server data source and add them to the manager */
194  DataSourceManager::addSource("Server",client);
196  connect(DataSourceManager::instance(),SIGNAL(sourceChanged(QString)),
197  this,SLOT(on_source_changed(QString)));
198 
199  // Set the size and position of the window
200  resize(settings.value("MainWindowSize",size()).toSize());
201  move(settings.value("MainWindowPosition",pos()).toPoint());
202 
203  show();
204 }
205 
207 {
208 
209 }
210 
212 {
213  /** if no filename is given ask for a file */
214  if (filename.isEmpty())
215  {
216  QString filter("Data Files (*.csv *.hst *.h5 *.hdf5 *.cbf)");
217  filename = QFileDialog::getOpenFileName(this, tr("Open File"),
218  QDir::currentPath(), filter);
219  if(filename.isEmpty())
220  return;
221  }
222 
223  /** if the file doesn't exist exit here */
224  if (!QFileInfo(filename).exists())
225  return;
226 
227  /** add a source with the requested file and set the window title to the
228  * filename
229  */
230  DataSourceManager::addSource(filename,new FileHandler(filename));
231  setWindowTitle(QFileInfo(filename).baseName());
232 
233  /** in case the key is on the list of displayable items, display it */
234  if (displayableItems().contains(key))
235  setDisplayedItem(key,true);
236 }
237 
239 {
240  autoSave(true);
241 }
242 
243 void JoCASSViewer::autoSave(bool onlyPNG) const
244 {
245  if (_viewers.isEmpty())
246  return;
247  /** generate the general automatic filename */
248  QString fileNameBase(QDir::currentPath() + "/" +
249  QDateTime::currentDateTime().toString("yyyyMMdd-HHmmss") +
250  "_");
251 
252  /** save all open windows data to a single container file, if not only png */
253  if (!onlyPNG)
254  saveFile(QString(fileNameBase + "autoSave.h5"),displayedItems());
255 
256  /** save the individual viewers to their specific savable file types
257  * (exclude the container files type
258  */
260  while( view != _viewers.constEnd())
261  {
262  if (view.value())
263  {
264 
265  QStringList filetypes(view.value()->dataFileSuffixes());
266  /** if only png files should be saved, check if view can be saved as png
267  * remove all other options from the file list
268  */
269  if (onlyPNG)
270  filetypes = filetypes.filter("png",Qt::CaseInsensitive);
271  QStringList::const_iterator cIt;
272  for (cIt = filetypes.constBegin(); cIt != filetypes.constEnd(); ++cIt)
273  {
274  QString fname(fileNameBase + view.key() + "." + *cIt);
275  if (!FileHandler::isContainerFile(fname))
276  saveFile(fname,QStringList(view.key()));
277  }
278  }
279  ++view;
280  }
281 }
282 
283 void JoCASSViewer::saveFile(QString filename, QStringList keys) const
284 {
285  if (_viewers.isEmpty())
286  return;
287 
288  /** if not filename was given ask for one */
289  if (filename.isEmpty())
290  {
291  QString filter("Data Files (*.png *.csv *.hst *.h5 *.hdf5 *.cbf)");
292  filename = QFileDialog::getSaveFileName(0, tr("Save Data to File"),
293  QDir::currentPath(), filter);
294  if(filename.isEmpty())
295  return;
296  }
297 
298  /** if no keys are given, request at least one using the iteminput dialog
299  * The preselected item in the dialog should be the currently highlighted
300  * window or, in case of a container file, "all"
301  */
302  if (keys.isEmpty())
303  {
304  QStringList items(displayedItems());
305  items.prepend("**ALL**");
306  QWidget *focusWiget(QApplication::focusWidget());
307  int preselectItemId(items.indexOf("**ALL**"));
308  if (!FileHandler::isContainerFile(filename) && (focusWiget))
309  preselectItemId = items.indexOf(focusWiget->windowTitle());
310  bool ok(false);
311  QString item(QInputDialog::getItem(0, QObject::tr("Select Key"),
312  QObject::tr("Key:"), items,
313  preselectItemId, false, &ok));
314  if (!ok || item.isEmpty())
315  return;
316  if (item.contains("***ALL***"))
317  keys = displayedItems();
318  else
319  keys.append(item);
320  }
321 
322  /** if the file is a container file, create the container first before adding
323  * data to it.
324  */
325  if (FileHandler::isContainerFile(filename))
327 
328  /** go through the list and tell the viewer to save the data
329  * Append the name of the viewer to the filaname in case this is not a
330  * container file and more that one file should be saved with data so that
331  * the files are not overwritten.
332  */
333  QStringList::const_iterator cIt;
334  for (cIt = keys.constBegin(); cIt != keys.constEnd(); ++cIt)
335  {
336  if (_viewers.value(*cIt))
337  {
338  QString fname(filename);
339  if(!FileHandler::isContainerFile(filename) && keys.size() > 1)
340  fname.insert(fname.lastIndexOf("."),"_" + *cIt);
341  _viewers.value(*cIt)->saveData(fname);
342  }
343  }
344 }
345 
347 {
349 }
350 
352 {
353  QMessageBox::about(this, tr("About jocassview"),
354  tr("<p>The <b>JoCASSviewer</b> is a display client for the CASS software.</p>"));
355 }
356 
358 {
359  return (1000./rate());
360 }
361 
362 double JoCASSViewer::rate() const
363 {
364  return _rate->value();
365 }
366 
368 {
369  //qDebug()<<"changeAutoUpdate: "<<interval()<<_autoUpdate->isChecked();
370  _updateTimer.setInterval(interval());
371  if(_autoUpdate->isChecked())
373  else
374  _updateTimer.stop();
375  QSettings settings;
376  settings.setValue("Rate",rate());
377  settings.setValue("AutoUpdateOn",_autoUpdate->isChecked());
378 }
379 
381 {
382  /** if another process is still updating return here
383  * @note this can happen, because while retrieving data from the server all
384  * pending processes on the eventloop will be processed. One of them
385  * could be the user trying to retrieve data another time (while another
386  * retrieval process is still ongoing, thus resulting this function will
387  * be reentered, even though it is still working.
388  */
389  if (_updateInProgress)
390  return;
391 
392  if (_viewers.isEmpty())
393  return;
394 
395  //qDebug()<<"update viewers";
396  _updateInProgress = true;
398  bool sucess(true);
399 
400  /** get an iterator to go through the map and retrieve the first item where
401  * we get the id from. Then check whether all the other histograms should have
402  * the same id (if not then set the id to 0).
403  * Remember how big the container is for validating whether nothing has changed
404  * while the data was retrieved from the source.
405  */
407 // cass::HistogramBackend *hist(_client.getData(view.key()));
408 // const quint64 eventID = hist && false ? hist->id() : 0;
409  const quint64 eventID(0);
410  const int nbrWindows(_viewers.size());
411  while( view != _viewers.end())
412  {
413  if (!view.value())
414  {
415  /** check if current source is available, if remove the viewer from the
416  * list and quit updating
417  */
420  if (!source)
421  {
422  setDisplayedItem(view.key(),false,false);
423  _viewers.remove(view.key());
424  sucess = false;
425  break;
426  }
427  /** if the viewer hasn't been initalized, initialize it with new result
428  * from the current active source.
429  */
430  DataSource::result_t::shared_pointer result(source->result(view.key(),eventID));
431  /** validate container consistency */
432  if(_viewers.size() != nbrWindows)
433  {
434  sucess = false;
435  break;
436  }
437  /** validate result.
438  * If the viewer can't be initialzed, remove it from the list
439  */
440  if (!result)
441  {
442  //qDebug()<<"result is empty "<<view.key();
443  setDisplayedItem(view.key(),false,false);
444  _viewers.remove(view.key());
445  break;
446  }
447  /** Set the result to the data of the viewer and let the data now what
448  * source type it has been filled with
449  */
450  createViewerForType(view,result);
451  /** validate data */
452  if (!view.value()->data().isEmpty())
453  {
454  //qDebug()<<"set result to viewer:" <<QString::fromStdString(result->name());
455  view.value()->data().front()->setResult(result);
456  //qDebug()<<"done set result to viewer:" <<QString::fromStdString(result->name());
457  view.value()->data().front()->setSourceName(sourceName);
458  }
459  }
460  else
461  {
462  /** otherwise retrieve all the data containers from a viewer and update
463  * them with the latest data
464  */
465  //qDebug()<<"update existing viewer"<<view.key();
466  QList<Data*> data(view.value()->data());
467  const int nbrData(data.size());
468  QList<Data*>::iterator dataIt(data.begin());
469  while (dataIt != data.end())
470  {
471  /** validate source */
472  QString sourceName((*dataIt)->sourceName());
473  DataSource *source(DataSourceManager::source(sourceName));
474  if(!source)
475  {
476  //qDebug()<<"source doesnt exist"<<sourceName;
477  continue;
478  }
479  /** validate result to update */
480  if (!(*dataIt)->result())
481  {
482  //qDebug()<<"result is empty"<<sourceName;
483  continue;
484  }
485  const QString key(QString::fromStdString((*dataIt)->result()->name()));
486  DataSource::result_t::shared_pointer result(source->result(key,eventID));
487  /** validate container consistency */
488  //qDebug()<<"validate viewer conistency"<<nbrWindows<<_viewers.size();
489  if(_viewers.size() != nbrWindows || data.size() != nbrData)
490  {
491  sucess = false;
492  break;
493  }
494  (*dataIt)->setResult(result);
495  ++dataIt;
496  }
497  if (sucess == false)
498  break;
499  }
500  /** tell the viewer the data has changed */
501  view.value()->dataChanged();
502  ++view;
503  }
504  /** set the report to sucess or failure */
505  sucess ? _statusLED->setStatus(StatusLED::ok) :
507 
508  /** remember which viewers are active */
509  QSettings settings;
510  settings.setValue("OpenedViewers",displayedItems());
511 
512 
513  /** restart the updatetimer when requested and reset the in progress flag */
515  _updateInProgress = false;
516 }
517 
519 {
520  bool state(item->isSelected());
521  QString name(item->text());
522 
523  if (state)
524  {
525  /** if the container already has a viewer with the requested name, exit here */
526  if (_viewers.contains(name))
527  return;
528  /** create an entry in the viewers container with a 0 pointer and initialize
529  * the viewer based upon the type of data using update_viewers();
530  */
531  _viewers[name] = 0;
532  updateViewers();
533  }
534  else
535  {
536  /** if the key is on the list of viewers and the viewer has been created
537  * close it (which will delete the window, because all dataviewer windows
538  * have the delete on close flag set)
539  */
540  if (_viewers.contains(name) && _viewers[name])
541  _viewers[name]->close();
542  }
543 }
544 
546 {
547  /** retrieve the window title from the dataviewer that is beeing destroyed
548  * (because its the key in the list of viewers) and remove the key from the
549  * list. Then set the entry in the list as not highlighted.
550  */
551  QString key(obj->windowTitle());
552  _viewers.remove(key);
553  setDisplayedItem(key,false);
554 }
555 
557 {
558  //qDebug()<<"on_refresh_list_triggered";
560  if (!source)
561  return;
562  QListWidget *listwidget(dynamic_cast<QListWidget*>(centralWidget()));
563  QStringList selectedItems(displayedItems());
564  listwidget->clear();
565  listwidget->addItems(source->resultNames());
566  listwidget->sortItems();
567  for (int i=0; i < selectedItems.size(); ++i)
568  setDisplayedItem(selectedItems[i],true,false);
569 }
570 
571 void JoCASSViewer::setDisplayedItem(QString item,bool state, bool simulateClickedSignal)
572 {
573  QListWidget *listwidget(dynamic_cast<QListWidget*>(centralWidget()));
574  QList<QListWidgetItem*> listwidgetitems(listwidget->findItems(item,Qt::MatchExactly));
575  if (listwidgetitems.empty() || listwidgetitems.size() > 1)
576  return;
577  QListWidgetItem *listwidgetitem(listwidgetitems.front());
578  listwidgetitem->setSelected(state);
579  if(simulateClickedSignal)
580  changeViewers(listwidgetitem);
581 }
582 
584 {
585  QStringList items;
586  QListWidget *listwidget(dynamic_cast<QListWidget*>(centralWidget()));
587  for (int i=0; i < listwidget->count(); ++i)
588  items.append(listwidget->item(i)->text());
589  return items;
590 }
591 
593 {
594  QStringList items;
595  QListWidget *listwidget(dynamic_cast<QListWidget*>(centralWidget()));
596  QList<QListWidgetItem*> selected(listwidget->selectedItems());
597  for (int i=0; i < selected.size(); ++i)
598  items.append(selected[i]->text());
599  return items;
600 }
601 
603 {
604  QStringList items(displayedItems());
605  QWidget *focusWiget(QApplication::focusWidget());
606  QString preselectItem;
607  if (focusWiget)
608  preselectItem=focusWiget->windowTitle();
609  bool ok(false);
610  QString item(QInputDialog::getItem(this, QObject::tr("Select Key"),
611  QObject::tr("Print Key:"), items,
612  items.indexOf(preselectItem), false, &ok));
613  if (!ok)
614  return;
615 
616  if(!_viewers.contains(item))
617  return;
618 
619  _viewers.value(item)->print();
620 }
621 
623 {
624  //qDebug()<<"new source"<<newSource;
625  _serverToolBar->setVisible(newSource == "Server");
627  QString sourceDisplayName(newSource == "Server" ?
628  newSource : QFileInfo(newSource).baseName());
629  setWindowTitle(sourceDisplayName);
630 }
631 
633 {
634  QString servername(_servername->text());
635  QString serverport(QString::number(_serverport->value()));
636  QSettings settings;
637  settings.setValue("Servername",servername);
638  settings.setValue("Serverport",serverport);
639  QString serveraddress(servername + ":" + serverport);
640  DataSource *source(DataSourceManager::source("Server"));
641  if (source)
642  dynamic_cast<TCPClient*>(source)->setServer(serveraddress);
643 }
644 
646 {
647  DataSource *source(DataSourceManager::source("Server"));
648  if (source)
649  dynamic_cast<TCPClient*>(source)->broadcastCommand("startDarkcal");
650 }
651 
653 {
654  DataSource *source(DataSourceManager::source("Server"));
655  if (source)
656  dynamic_cast<TCPClient*>(source)->broadcastCommand("startGaincal");
657 }
658 
660 {
661  DataSource *source(DataSourceManager::source("Server"));
662  if (!source)
663  return;
664  QStringList items(displayableItems());
665  if (items.empty())
666  return;
667  bool ok(false);
668  QString key(QInputDialog::getItem(0, QObject::tr("Select Key"),
669  QObject::tr("Key:"), items, 0, false, &ok));
670  if (!ok)
671  return;
672  QString command = QInputDialog::getText(0,tr("Command"),tr("Type command:"),
673  QLineEdit::Normal,tr("Type command here"),&ok);
674  if (!ok)
675  return;
676  dynamic_cast<TCPClient*>(source)->sendCommandTo(key,command);
677 }
678 
680 {
681  DataSource *source(DataSourceManager::source("Server"));
682  if (!source)
683  return;
684  QStringList items(displayableItems());
685  if (items.empty())
686  return;
687  bool ok(false);
688  QString key(QInputDialog::getItem(0, QObject::tr("Select Key"),
689  QObject::tr("Key:"), items, 0, false, &ok));
690  if (!ok)
691  return;
692  dynamic_cast<TCPClient*>(source)->clearHistogram(key);
693 }
694 
697 {
698  //qDebug()<<"create viewer"<<view.key()<<result->dim();
699  switch (result->dim())
700  {
701  case 0:
702  view.value() = new ZeroDViewer(view.key(),this);
703  break;
704  case 1:
705  view.value() = new OneDViewer(view.key(),this);
706  break;
707  case 2:
708  view.value() = new TwoDViewer(view.key(),this);
709  break;
710  }
711  view.value()->show();
712  connect(view.value(),SIGNAL(viewerClosed(DataViewer*)),
713  this,SLOT(removeViewer(DataViewer*)));
714  //qDebug()<<"created viewer"<<view.key()<<result->dim();
715 }
716 
718 {
719  QMainWindow::moveEvent(event);
720  QSettings settings;
721  settings.setValue("MainWindowPosition",frameGeometry().topLeft());
722 // qDebug() << "Main pos "<<event->pos() << "; geom " << geometry()
723 // <<"; framegeom "<<frameGeometry()
724 // <<"; framegeom.left "<<frameGeometry().topLeft()
725 // <<"; framegeom.right "<<frameGeometry().topRight()
726 // <<"; framegeom.size "<<frameGeometry().size();
727 }
728 
730 {
731  QSettings settings;
732  settings.setValue("MainWindowSize",event->size());
733 }
void autoSaveImages() const
save the data displayed by all windows as png images
contains the jocassviewer class
void clearHistogram() const
send clear histograms
size_t dim() const
what is the dimension of the result
Definition: result.hpp:503
void autoSave(bool onlyPNG=false) const
save the data displayed by all windows in the possible files
addToolBar(Qt::ToolBarArea area, QToolBar *toolbar)
void startViewer()
start the viewer
base class for viewers
Definition: data_viewer.h:37
QStringList displayableItems() const
retrieve a list with all items
void on_source_changed(QString newSource)
react on when the source has been changed
getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, int current=0, bool editable=true, bool *ok=0, Qt::WindowFlags flags=0)
a LED that should display the status
Definition: status_led.h:22
QSpinBox * _serverport
the server port input widget
Definition: jocassviewer.h:252
QToolBar * _serverToolBar
the toolbar with the server options
Definition: jocassviewer.h:261
void print()
react when print has been triggered
static void addSource(const QString &sourcename, DataSource *source, bool setActive=true)
add a data source
about(QWidget *parent, const QString &title, const QString &text)
std::tr1::shared_ptr< self_type > shared_pointer
a shared pointer of this class
Definition: result.hpp:323
contains the base class data sources
read and write data to files
Definition: file_handler.h:30
contains the base class for add viewer data
contains singleton class to manage the data sources
addWidget(QWidget *widget)
file contains the classes connect to cass
STL namespace.
QTimer _updateTimer
timer for the auto update function it is used as singleshot timer
Definition: jocassviewer.h:267
StatusLED * _statusLED
the status LED
Definition: jocassviewer.h:246
setRange(double minimum, double maximum)
things written only at end of run H5Dump ProcessorSummary size
currentPath()
QMap< QString, DataViewer * > _viewers
the container for all opened viewers
Definition: jocassviewer.h:264
sortItems(Qt::SortOrder order=Qt::AscendingOrder)
result classes
QLineEdit * _servername
the servername input widget
Definition: jocassviewer.h:249
tr(const char *sourceText, const char *disambiguation=0, int n=-1)
contains the viewer for 1d data
a viewer that displays 1d data
Definition: one_d_viewer.h:37
addAction(const QString &text)
setRange(int minimum, int maximum)
setValue(const QString &key, const QVariant &value)
void changeAutoUpdate()
change the autoupdate based upon what the user set
number(long n, int base=10)
QAction * _autoUpdate
the auto update input
Definition: jocassviewer.h:258
void removeViewer(DataViewer *obj)
remove the viewer from the container when it has been destroyed
fromStdString(const std::string &str)
base class for data sources
Definition: data_source.h:26
static bool isContainerFile(const QString &filename)
return whether the file is a container file
QDoubleSpinBox * _rate
the rate input
Definition: jocassviewer.h:255
a viewer that displays 0d data
Definition: zero_d_viewer.h:25
contains the status led class
virtual result_t::shared_pointer result(const QString &key, quint64 id=0)=0
retrieve a result from the source
void setStatus(int status)
set the status
Definition: status_led.cpp:41
void sendCustomCommand() const
send a custom command
contains a file handler
void openFile(QString filename=QString(), QString key=QString())
load data from a file
A result of a processor.
Definition: result.hpp:30
void setDisplayedItem(QString itemName, bool state, bool simulateClickedSignal=true)
check an item in the list
setCentralWidget(QWidget *widget)
addSeparator()
item(int row)
void refreshDisplayableItemsList()
refresh the items on the displayable list
getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode=QLineEdit::Normal, const QString &text=QString()
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
std::string toString(const Type &t)
convert any type to a string
Definition: cass.h:63
static DataSource * source(const QString &sourcename=QString())
retrieve an available source
JoCASSViewer(QWidget *parent=0, Qt::WindowFlags flags=0)
constructor
QStringList displayedItems() const
retrieve a list with the selected items
static DataSourceManager * instance()
generate an instance of this, if not already existent
key(const T &value)
void saveFile(QString filename=QString(), QStringList keys=QStringList()) const
save a data from specific viewer or all viewers to the given filename
void changeServerAddress() const
retrieve the server address
value(const QString &key, const QVariant &defaultValue=QVariant()
void resizeEvent(QResizeEvent *event)
receive resize events to store the current size to the settings
contains the viewer for 0d data
double interval() const
retrieve the rate as interval in ms
addMenu(QMenu *menu)
void about()
display about this box
void changeViewers(QListWidgetItem *item)
react on when an item in the list has been checked
bool _updateInProgress
flag to tell whether an update is in progess
Definition: jocassviewer.h:270
addItems(const QStringList &labels)
a viewer that displays 2d data
Definition: two_d_viewer.h:35
getSaveFileName(QWidget *parent=0, const QString &caption=QString()
the tcp client that connects to the cass server
double rate() const
retrieve the user set rate in Hz
start(int msec)
findItems(const QString &text, Qt::MatchFlags flags)
indexOf(const QRegExp &rx, int from=0)
fromTheme(const QString &name, const QIcon &fallback=QIcon()
void broadcastGaincalCommand() const
broadcast the gaincal command
void broadcastDarkcalCommand() const
broadcast the darkcal command
getOpenFileName(QWidget *parent=0, const QString &caption=QString()
void createViewerForType(QMap< QString, DataViewer * >::iterator view, cass::Result< float >::shared_pointer result)
convenience function to create a viewer thats appropriate for a given type of data ...
filter(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
static void setMenu(QMenu *menu)
set the Menu where the data sources will be displayed in
insert(int position, const QString &str)
static QString currentSourceName()
return the current source name
void updateViewers()
update the contents within the viewers in the map
void moveEvent(QMoveEvent *event)
receive move events to store the current position to the settings
addAction(QAction *action)
setSelected(bool select)
static void createContainer(const QString &filename)
create the container file
contains the viewer for 2d data
lastIndexOf(const QString &str, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive)
virtual QStringList resultNames()=0
retrieve the list items that can be displayed
value(const Key &key)