QxModel::setModelValue can't set smartpointer to null
Posted: Fri Apr 03, 2020 10:14 am
Hello,
I'm using QxModel to visualise my data but I have some troubles.
I have class which looks like this:
Setting parent_location using setModelValue with desired id works fine. But when I try bring it to NULL (resting smart pointer) with setModelValue(0, "parent_location", null) I end up in function QxConvert_FromVariant< Uuid >::fromVariant which tries set current value of parent_location-id to null (for uuid its zeros). It messes with following database manipulation because table field parent_location isnt set to null (which it would be if smartpointer would be set to null) but instead filed contains invalid uuid. Writing this post I see some solution cheacking before insert/update which will be clearing relations smartpointers if they contain invalid uuid but I thought that function setModelValue with null value will be able to clear smartpointer by it self. Is there any other better solution or em I missing something?
I'm using QxModel to visualise my data but I have some troubles.
I have class which looks like this:
- Code: Select all
#include "DbTablesBase.h"
namespace Db {
namespace Tables {
class WarehouseLocation;
using WarehouseLocation_ptr = std::shared_ptr<WarehouseLocation>;
using WarehouseLocation_list = qx::QxCollection<Uuid, WarehouseLocation_ptr>;
class WarehouseLocation : public Base {
friend struct qx::dao::detail::QxDao_Trigger<Db::Tables::WarehouseLocation>;
public:
enum Type {
/* Grupa lokacji.*/
view = 0,
/* lokalizacje fizyczne.*/
internal,
/* Korekty stanu magazynowego.*/
inventory,
/* Dostawy.*/
procurement,
/* dostawcy.*/
supplier,
/* Klienci.*/
customer
};
public:
QString name;
Type type;
WarehouseLocation_ptr parent_location;
std::optional<QString> description;
QString path;
WarehouseLocation_list children_location;
public:
WarehouseLocation();
~WarehouseLocation() override;
QSqlError fetch_path(QSqlDatabase *pDatabase = nullptr);
void createPath();
static QSqlError fetch_all_with_children(WarehouseLocation_list &collection,
QSqlDatabase *pDatabase = nullptr);
private:
void onBeforeInsert(qx::dao::detail::IxDao_Helper *dao) override;
void onBeforeUpdate(qx::dao::detail::IxDao_Helper * dao) override;
};
} // namespace Tables
} // namespace Db
QX_REGISTER_PRIMARY_KEY(Db::Tables::WarehouseLocation, Uuid)
QX_REGISTER_COMPLEX_CLASS_NAME_HPP_EXPORT_DLL(Db::Tables::WarehouseLocation,
Db::Tables::Base, 0, Db_Tables_WarehouseLocation)
#endif // DBTABLESWAREHOUSELOCATION_H
Setting parent_location using setModelValue with desired id works fine. But when I try bring it to NULL (resting smart pointer) with setModelValue(0, "parent_location", null) I end up in function QxConvert_FromVariant< Uuid >::fromVariant which tries set current value of parent_location-id to null (for uuid its zeros). It messes with following database manipulation because table field parent_location isnt set to null (which it would be if smartpointer would be set to null) but instead filed contains invalid uuid. Writing this post I see some solution cheacking before insert/update which will be clearing relations smartpointers if they contain invalid uuid but I thought that function setModelValue with null value will be able to clear smartpointer by it self. Is there any other better solution or em I missing something?