itom
Loading...
Searching...
No Matches
modesManager.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21
22 Further hints:
23 ------------------------
24
25 This file belongs to the code editor of itom. The code editor is
26 in major parts a fork / rewritten version of the python-based source
27 code editor PyQode from Colin Duquesnoy and others
28 (see https://github.com/pyQode). PyQode itself is licensed under
29 the MIT License (MIT).
30
31 Some parts of the code editor of itom are also inspired by the
32 source code editor of the Spyder IDE (https://github.com/spyder-ide),
33 also licensed under the MIT License and developed by the Spyder Project
34 Contributors.
35
36*********************************************************************** */
37
38#ifndef MODESMANAGER_H
39#define MODESMANAGER_H
40
41/*
42This module contains the modes controller.
43*/
44
45#include "manager.h"
46
47#include <qmap.h>
48#include "../mode.h"
49
50namespace ito {
51
52/*
53Manages the list of modes of the code edit widget.
54*/
55class ModesManager : public Manager
56{
57 Q_OBJECT
58
59public:
60 ModesManager(CodeEditor *editor, QObject *parent = NULL);
61 virtual ~ModesManager();
62
63 typedef QMap<QString, Mode::Ptr>::const_iterator const_iterator;
64 typedef QMap<QString, Mode::Ptr>::iterator iterator;
65
66 Mode::Ptr append(Mode::Ptr mode);
67 Mode::Ptr remove(Mode::Ptr mode);
68 void clear();
69
70 Mode::Ptr get(const QString &name) const
71 {
72 if (m_modes.contains(name))
73 {
74 return m_modes[name];
75 }
76 return Mode::Ptr();
77 }
78
79 template <typename _Tp> _Tp* getT(const QString &name) const
80 {
81 _Tp* ptr = NULL;
82 if (m_modes.contains(name))
83 {
84 Mode::Ptr p = m_modes[name];
85 if (p)
86 {
87 ptr = dynamic_cast<_Tp*>(p.data());
88 }
89 }
90
91 return ptr;
92 }
93
94 const_iterator constBegin() const
95 {
96 return m_modes.constBegin();
97 }
98 const_iterator constEnd() const
99 {
100 return m_modes.constEnd();
101 }
102
103 iterator begin()
104 {
105 return m_modes.begin();
106 }
107 iterator end()
108 {
109 return m_modes.end();
110 }
111
112private:
113
114 QMap<QString, Mode::Ptr> m_modes;
115};
116
117} //end namespace ito
118
119#endif
Definition codeEditor.h:110
Definition manager.h:72
Definition modesManager.h:56
Definition apiFunctionsGraph.cpp:40