CFEL - ASG Software Suite  2.5.0
CASS
data_source_manager.cpp
Go to the documentation of this file.
1 // Copyright (C) 2013, 2014 Lutz Foucar
2 
3 /**
4  * @file data_source_manager.cpp contains singleton class to manage the data sources
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <QtCore/QDebug>
10 #include <QtCore/QSignalMapper>
11 
12 #if QT_VERSION >= 0x050000
13 #include <QtWidgets/QMenu>
14 #include <QtWidgets/QActionGroup>
15 #else
16 #include <QtGui/QMenu>
17 #include <QtGui/QActionGroup>
18 #endif
19 
20 #include "data_source_manager.h"
21 
22 #include "data_source.h"
23 
24 using namespace jocassview;
25 
27 
29  : _sourceMenu(0),
30  _actionGroup(0),
31  _mapper(0)
32 {
33 
34 }
35 
37 {
38  if(!_instance)
39  {
40  //qDebug()<<"create instance";
42  }
43  return _instance;
44 }
45 
47 {
48  //qDebug()<<"get source"<<sourcename<<currentSourceName();
49  if (sourcename.isEmpty())
50  return instance()->_sources[currentSourceName()];
51  else if(!instance()->_sources.contains(sourcename))
52  return 0;
53  return instance()->_sources.value(sourcename);
54 }
55 
57 {
58  QString name;
60  name = instance()->_actionGroup->checkedAction()->text();
61  //qDebug()<<"current source name "<<name;
62  return name;
63 }
64 
66 {
67  return instance()->_sources.keys();
68 }
69 
71 {
72  //qDebug()<<"add menu";
73  instance()->_sourceMenu = menu;
74  instance()->_actionGroup = new QActionGroup(menu);
75  instance()->_mapper = new QSignalMapper(menu);
76  connect(instance()->_mapper,SIGNAL(mapped(QString)),instance(),SIGNAL(sourceChanged(QString)));
77 }
78 
79 void DataSourceManager::addSource(const QString &sourcename, DataSource *source,
80  bool setActive)
81 {
82  //qDebug()<<"add Source"<< sourcename<<source;
83  instance()->_sources[sourcename] = source;
84  QAction *act(instance()->_sourceMenu->addAction(sourcename));
85  act->setCheckable(true);
86  connect(act,SIGNAL(triggered()),instance()->_mapper,SLOT(map()));
87  instance()->_mapper->setMapping(act,sourcename);
89  if (setActive)
90  {
91  act->setChecked(true);
92  emit instance()->sourceChanged(sourcename);
93  }
94 }
static void addSource(const QString &sourcename, DataSource *source, bool setActive=true)
add a data source
create the noise and bad pixel map[Processor]
contains the base class data sources
contains singleton class to manage the data sources
QMap< QString, DataSource * > _sources
container for all data sources
QSignalMapper * _mapper
mapper for the signals of the signal group
addAction(QAction *action)
static DataSourceManager * _instance
an instane of this
addAction(const QString &text)
setMapping(QObject *sender, int id)
base class for data sources
Definition: data_source.h:26
void sourceChanged(QString newSource)
signal when a new source was chosen
QActionGroup * _actionGroup
the action group where the menue items will be grouped
singleton class to manage the available data sources
static DataSource * source(const QString &sourcename=QString())
retrieve an available source
static DataSourceManager * instance()
generate an instance of this, if not already existent
static QStringList sourceNames()
retrieve the names of all current active sources
static void setMenu(QMenu *menu)
set the Menu where the data sources will be displayed in
static QString currentSourceName()
return the current source name
connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type=Qt::AutoConnection)
QMenu * _sourceMenu
the source menu