19 #ifndef OMNI_UI_MIXIN_DATAMODEL_H_
20 #define OMNI_UI_MIXIN_DATAMODEL_H_
32 template<
typename T,
bool SHARED>
39 typedef std::shared_ptr<T>
type;
86 template<
typename DATAMODEL,
bool SHARED>
170 template<
typename WIDGET,
typename DATAMODEL,
typename ... ARGS>
171 static WIDGET*
makeWidget(DATAMODEL *_dataModel, ARGS&& ... _args) {
172 auto *_widget =
new WIDGET(_args ...);
174 _widget->setDataModel(_dataModel);
181 template<
typename WIDGET,
typename DATAMODEL,
typename ... ARGS>
182 static WIDGET*
makeWidget(std::shared_ptr<DATAMODEL>_dataModel,
184 auto *_widget =
new WIDGET(_args ...);
186 _widget->setDataModel(_dataModel);
191 using mixin::DataModel;
199 #define OMNI_UI_DATAMODEL(MODEL, SHARED) \
201 typedef omni::ui::mixin::DataModel<MODEL, SHARED>mixin_data_model_type; \
202 inline void updateDataModel() { \
203 mixin_data_model_type::updateDataModel(); \
205 inline void updateFrontend() { \
206 this->locked([&]() { \
207 mixin_data_model_type::updateFrontend(); \
212 void emitDataModelChangedSignal() { \
213 emit dataModelChanged(); \
216 #define OMNI_UI_SHARED_DATAMODEL(MODEL) \
217 OMNI_UI_DATAMODEL(MODEL, true)
219 #define OMNI_UI_UNSHARED_DATAMODEL(MODEL) \
220 OMNI_UI_DATAMODEL(MODEL, false)
T data_type
Definition: DataModel.h:38
DataModel< T, true > SharedDataModel
Template alias for shared data model.
Definition: DataModel.h:161
DataModel< T, false > UnsharedDataModel
Template alias for unshared data model.
Definition: DataModel.h:165
pointer_type dataModel()
Return pointer to data model.
Definition: DataModel.h:118
static T * raw_pointer(type _t)
Definition: DataModel.h:62
static WIDGET * makeWidget(DATAMODEL *_dataModel, ARGS &&..._args)
Instantiate a new widget and set data model Uses raw pointer (unshared data model) ...
Definition: DataModel.h:171
Mixin with a function to lock the widget temporarily.
Definition: Locked.h:26
T * type
Definition: DataModel.h:56
pointer_type dataModel_
Definition: DataModel.h:156
pointer_type_handler::type pointer_type
Derived pointer type.
Definition: DataModel.h:103
static T const * raw_pointer_const(type _t)
Definition: DataModel.h:48
virtual void updateFrontend()=0
static T const * raw_pointer_const(const type _t)
Definition: DataModel.h:66
DataModel< data_model_type, SHARED > type
This type.
Definition: DataModel.h:96
void locked(F f)
Lock widget and execute given functor.
Definition: Locked.h:30
Data model interface.
Definition: DataModel.h:73
const pointer_type dataModel() const
Return pointer to data model (const version)
Definition: DataModel.h:123
static void initialize(type &_t)
Definition: DataModel.h:41
detail::PointerType< data_model_type, SHARED > pointer_type_handler
Pointer type handler.
Definition: DataModel.h:100
virtual void updateDataModel()=0
Update the data model interface.
static void initialize(type &_t)
Definition: DataModel.h:58
bool isLocked() const
Return true if widget is locked.
Definition: Locked.h:40
Pointer type handler.
Definition: DataModel.h:33
void setDataModel(pointer_type _dataModel)
Set new data model.
Definition: DataModel.h:110
Holds a specific data model with frontend update mechanism.
Definition: DataModel.h:87
static T * raw_pointer(type _t)
Definition: DataModel.h:44
virtual bool frontendToData()=0
Return true if data has changed by front end.
virtual void dataToFrontend()=0
Pure virtual method which determines how data model is represented in frontend.
virtual void updateDataModel()
Update the data model interface.
Definition: DataModel.h:134
DATAMODEL data_model_type
Data type.
Definition: DataModel.h:93
DataModel()
Definition: DataModel.h:105
virtual void updateFrontend()
Push data to frontend widgets and all child widgets.
Definition: DataModel.h:128
std::shared_ptr< T > type
Definition: DataModel.h:39
virtual void emitDataModelChangedSignal()
Internal method used to emit dataModelChanged signal.
Definition: DataModel.h:154