CFEL - ASG Software Suite  2.5.0
CASS
data_source_manager.h
Go to the documentation of this file.
1 // Copyright (C) 2013, 2014 Lutz Foucar
2 
3 /**
4  * @file data_source_manager.h contains singleton class to manage the data sources
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _DATASOURCEMANAGER_
10 #define _DATASOURCEMANAGER_
11 
12 #include <QtCore/QObject>
13 #include <QtCore/QMap>
14 #include <QtCore/QString>
15 
16 class QMenu;
17 class QActionGroup;
18 class QSignalMapper;
19 
20 namespace jocassview
21 {
22 class DataSource;
23 
24 /** singleton class to manage the available data sources
25  *
26  * @author Lutz Foucar
27  */
28 class DataSourceManager : public QObject
29 {
30  Q_OBJECT
31 
32 public:
33  /** generate an instance of this, if not already existent
34  *
35  * @return the singleton instance of this
36  */
37  static DataSourceManager* instance();
38 
39  /** retrieve an available source
40  *
41  * if no name of the source is given the current active one will be returned
42  * If no are available or the requested doesn't exist a 0 pointer will be
43  * returned
44  *
45  * @return pointer to the requested source
46  * @param sourcename the name of the requested source
47  */
48  static DataSource* source(const QString & sourcename=QString());
49 
50  /** return the current source name
51  *
52  * @return name of current active source
53  */
54  static QString currentSourceName();
55 
56  /** retrieve the names of all current active sources
57  *
58  * @return list of names of the sources
59  */
60  static QStringList sourceNames();
61 
62  /** set the Menu where the data sources will be displayed in
63  *
64  * @param menu the menu that displays the available data sources
65  */
66  static void setMenu(QMenu* menu);
67 
68  /** add a data source
69  *
70  * the added source will be set as the current active source
71  *
72  * @param sourcename the name of the data source that should be added
73  * @param source the data source that should be added
74  * @param setActive Set added source as the current active one and emit the
75  * signal that a new source has been
76  */
77  static void addSource(const QString &sourcename, DataSource * source, bool setActive=true);
78 
79 signals:
80  /** signal when a new source was chosen
81  *
82  * @param newSource the name of the new source
83  */
84  void sourceChanged(QString newSource);
85 
86 private:
87  /** constructor */
89 
90  /** copy constructor */
92 
93  /** self assignment */
95 
96 private:
97  /** an instane of this */
99 
100  /** container for all data sources */
102 
103  /** the source menu */
105 
106  /** the action group where the menue items will be grouped */
108 
109  /** mapper for the signals of the signal group */
111 };
112 }//end namespace jocassview
113 
114 #endif
static void addSource(const QString &sourcename, DataSource *source, bool setActive=true)
add a data source
DataSourceManager & operator=(const DataSourceManager &)
self assignment
QMap< QString, DataSource * > _sources
container for all data sources
QSignalMapper * _mapper
mapper for the signals of the signal group
static DataSourceManager * _instance
an instane of this
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
QMenu * _sourceMenu
the source menu