add possibility to set save status for the whole tree
add method: void Model::set_save_mode2(SaveMode save_mode, bool update_whole_tree = true) in the future it may be renamed to set_save_mode()
This commit is contained in:
parent
df44296c04
commit
3bde64e033
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2021, Tomasz Sowa
|
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2021, Tomasz Sowa
|
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -74,6 +74,21 @@ Model::SaveMode Model::get_save_mode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Model::set_save_mode2(SaveMode save_mode, bool update_whole_tree)
|
||||||
|
{
|
||||||
|
this->save_mode = save_mode;
|
||||||
|
|
||||||
|
if( update_whole_tree )
|
||||||
|
{
|
||||||
|
ModelEnv model_env_local;
|
||||||
|
model_env = &model_env_local;
|
||||||
|
model_env->model_work_mode = MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS;
|
||||||
|
fields();
|
||||||
|
model_env = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Model::set_has_primary_key_set(bool has_primary_key)
|
void Model::set_has_primary_key_set(bool has_primary_key)
|
||||||
{
|
{
|
||||||
this->has_primary_key_set = has_primary_key;
|
this->has_primary_key_set = has_primary_key;
|
||||||
|
@ -1578,6 +1593,11 @@ void Model::field_model(const wchar_t * db_field_name, const wchar_t * flat_fiel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS )
|
||||||
|
{
|
||||||
|
field_model.set_save_mode2(save_mode, true);
|
||||||
|
}
|
||||||
|
|
||||||
field_model.model_env = nullptr;
|
field_model.model_env = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
49
src/model.h
49
src/model.h
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2021, Tomasz Sowa
|
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -153,6 +153,9 @@ public:
|
||||||
virtual void set_save_mode(SaveMode save_mode);
|
virtual void set_save_mode(SaveMode save_mode);
|
||||||
virtual SaveMode get_save_mode();
|
virtual SaveMode get_save_mode();
|
||||||
|
|
||||||
|
// set_save_mode() will be changed to set_save_mode2() in the future
|
||||||
|
virtual void set_save_mode2(SaveMode save_mode, bool update_whole_tree = true);
|
||||||
|
|
||||||
virtual void set_has_primary_key_set(bool has_primary_key);
|
virtual void set_has_primary_key_set(bool has_primary_key);
|
||||||
virtual bool get_has_primary_key_set();
|
virtual bool get_has_primary_key_set();
|
||||||
|
|
||||||
|
@ -1188,6 +1191,45 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename ModelContainer, typename ModelContainerType, typename IsContainerByValueRenameMe>
|
||||||
|
void field_list_propagate_save_status(ModelContainer & field_container, ModelContainerType * model_container_type, IsContainerByValueRenameMe * foo)
|
||||||
|
{
|
||||||
|
if constexpr (std::is_base_of<Model, ModelContainerType>())
|
||||||
|
{
|
||||||
|
if constexpr (std::is_base_of<Model, IsContainerByValueRenameMe>())
|
||||||
|
{
|
||||||
|
field_list_propagate_save_status_in_container_by_value(field_container, model_container_type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
field_list_propagate_save_status_in_container_by_pointer(field_container, model_container_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename ModelContainer, typename ModelContainerType>
|
||||||
|
void field_list_propagate_save_status_in_container_by_value(ModelContainer & field_container, ModelContainerType * model_container_type)
|
||||||
|
{
|
||||||
|
for(ModelContainerType & item : field_container)
|
||||||
|
{
|
||||||
|
item.set_connector(model_connector);
|
||||||
|
item.set_save_mode2(save_mode, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename ModelContainer, typename ModelContainerType>
|
||||||
|
void field_list_propagate_save_status_in_container_by_pointer(ModelContainer & field_container, ModelContainerType * model_container_type)
|
||||||
|
{
|
||||||
|
for(ModelContainerType * item : field_container)
|
||||||
|
{
|
||||||
|
item->set_connector(model_connector);
|
||||||
|
item->set_save_mode2(save_mode, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename ContainerItemType>
|
template<typename ContainerItemType>
|
||||||
void field_vector(const wchar_t * db_field_name, const wchar_t * flat_field_name, std::vector<ContainerItemType> & field_value, const FT & field_type)
|
void field_vector(const wchar_t * db_field_name, const wchar_t * flat_field_name, std::vector<ContainerItemType> & field_value, const FT & field_type)
|
||||||
{
|
{
|
||||||
|
@ -1372,6 +1414,11 @@ protected:
|
||||||
{
|
{
|
||||||
field_list_clearing_values(field_container, model_container_type, foo);
|
field_list_clearing_values(field_container, model_container_type, foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS )
|
||||||
|
{
|
||||||
|
field_list_propagate_save_status(field_container, model_container_type, foo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2021, Tomasz Sowa
|
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
#define MORM_MODEL_WORK_MODE_GET_FIELD_MODEL 10
|
#define MORM_MODEL_WORK_MODE_GET_FIELD_MODEL 10
|
||||||
#define MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER 11
|
#define MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER 11
|
||||||
#define MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM 12
|
#define MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM 12
|
||||||
|
#define MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS 13
|
||||||
|
|
||||||
|
|
||||||
// submodes used in some cases
|
// submodes used in some cases
|
||||||
|
|
Loading…
Reference in New Issue