LMMS
Loading...
Searching...
No Matches
LinkedModelGroups.h
Go to the documentation of this file.
1/*
2 * LinkedModelGroups.h - base classes for groups of linked models
3 *
4 * Copyright (c) 2019-2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_LINKED_MODEL_GROUPS_H
26#define LMMS_LINKED_MODEL_GROUPS_H
27
28#include <cstddef>
29
30#include "Model.h"
31
32class QDomDocument;
33class QDomElement;
34
35namespace lmms
36{
37
42
43
53class LinkedModelGroup : public Model
54{
55 Q_OBJECT
56public:
57 /*
58 Initialization
59 */
62
63 /*
64 Linking (initially only)
65 */
66 void linkControls(LinkedModelGroup *other);
67
68 /*
69 Models
70 */
71 struct ModelInfo
72 {
73 QString m_name;
75 ModelInfo() { /* hopefully no one will use this */ } // TODO: remove?
76 ModelInfo(const QString& name, AutomatableModel* model)
77 : m_name(name), m_model(model) {}
78 };
79
80 // TODO: refactor those 2
81 template<class Functor>
82 void foreach_model(const Functor& ftor)
83 {
84 for (auto itr = m_models.begin(); itr != m_models.end(); ++itr)
85 {
86 ftor(itr->first, itr->second);
87 }
88 }
89
90 template<class Functor>
91 void foreach_model(const Functor& ftor) const
92 {
93 for (auto itr = m_models.cbegin(); itr != m_models.cend(); ++itr)
94 {
95 ftor(itr->first, itr->second);
96 }
97 }
98
99 std::size_t modelNum() const { return m_models.size(); }
100 bool containsModel(const QString& name) const;
102
103 /*
104 Load/Save
105 */
106 void saveValues(class QDomDocument& doc, class QDomElement& that);
107 void loadValues(const class QDomElement& that);
108
109signals:
110 // NOTE: when separating core from UI, this will need to be removed
111 // (who would know if the client is Qt, i.e. it may not have slots at all)
112 // In this case you'd e.g. send the UI something like
113 // "/added <model meta info>"
116
117public:
118 AutomatableModel* getModel(const std::string& s)
119 {
120 auto itr = m_models.find(s);
121 return (itr == m_models.end()) ? nullptr : itr->second.m_model;
122 }
123
125 void addModel(class AutomatableModel* model, const QString& name);
127 bool eraseModel(const QString& name);
128
130 void clearModels();
131
132private:
136 std::map<std::string, ModelInfo> m_models;
137};
138
139
156{
157public:
158 virtual ~LinkedModelGroups() = default;
159
160 void linkAllModels();
161
162 /*
163 Load/Save
164 */
165 void saveSettings(class QDomDocument& doc, class QDomElement& that);
166 void loadSettings(const class QDomElement& that);
167
168 /*
169 General
170 */
173 virtual LinkedModelGroup* getGroup(std::size_t idx) = 0;
175 virtual const LinkedModelGroup* getGroup(std::size_t idx) const = 0;
176};
177
178
179} // namespace lmms
180
181#endif // LMMS_LINKED_MODEL_GROUPS_H
#define nullptr
Definition DistrhoDefines.h:75
Definition AutomatableModel.h:77
Definition LinkedModelGroups.h:54
void modelAdded(lmms::AutomatableModel *added)
std::size_t modelNum() const
Definition LinkedModelGroups.h:99
void foreach_model(const Functor &ftor)
Definition LinkedModelGroups.h:82
void linkControls(LinkedModelGroup *other)
Definition LinkedModelGroups.cpp:43
void foreach_model(const Functor &ftor) const
Definition LinkedModelGroups.h:91
void saveValues(class QDomDocument &doc, class QDomElement &that)
Definition LinkedModelGroups.cpp:56
void addModel(class AutomatableModel *model, const QString &name)
Register a further model.
Definition LinkedModelGroups.cpp:79
bool eraseModel(const QString &name)
Unregister a model, return true if a model was erased.
Definition LinkedModelGroups.cpp:113
void removeControl(AutomatableModel *)
Definition LinkedModelGroups.cpp:101
std::map< std::string, ModelInfo > m_models
Definition LinkedModelGroups.h:136
void modelRemoved(lmms::AutomatableModel *removed)
bool containsModel(const QString &name) const
Definition LinkedModelGroups.cpp:129
void clearModels()
Remove all models.
Definition LinkedModelGroups.cpp:121
void loadValues(const class QDomElement &that)
Definition LinkedModelGroups.cpp:67
LinkedModelGroup(Model *parent)
Definition LinkedModelGroups.h:61
AutomatableModel * getModel(const std::string &s)
Definition LinkedModelGroups.h:118
Definition LinkedModelGroups.h:156
virtual ~LinkedModelGroups()=default
void loadSettings(const class QDomElement &that)
Definition LinkedModelGroups.cpp:170
virtual const LinkedModelGroup * getGroup(std::size_t idx) const =0
virtual LinkedModelGroup * getGroup(std::size_t idx)=0
void linkAllModels()
Definition LinkedModelGroups.cpp:143
void saveSettings(class QDomDocument &doc, class QDomElement &that)
Definition LinkedModelGroups.cpp:155
Model(Model *parent, QString displayName=QString(), bool defaultConstructed=false)
Definition Model.cpp:30
unsigned s
Definition inflate.c:1555
static const char * name
Definition pugl.h:1582
static uintptr_t parent
Definition pugl.h:1644
Definition AudioAlsa.cpp:35
ModelInfo()
Definition LinkedModelGroups.h:75
ModelInfo(const QString &name, AutomatableModel *model)
Definition LinkedModelGroups.h:76
QString m_name
Definition LinkedModelGroups.h:73
class AutomatableModel * m_model
Definition LinkedModelGroups.h:74