2024-11-18 14:59:45 +00:00
|
|
|
#include "validate_depict.h"
|
|
|
|
|
|
|
|
using namespace datas;
|
|
|
|
using namespace depict;
|
|
|
|
|
|
|
|
depict::ValidateDocObject::ValidateDocObject(QJsonObject obj) : _object_bind(obj) { }
|
|
|
|
|
|
|
|
depict::ValidateDocObject::ValidateDocObject() { }
|
|
|
|
|
|
|
|
bool ValidateDocObject::isEmpty() const {
|
|
|
|
return _object_bind.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValidateDocObject::isArray() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValidateDocObject::isObject() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<IDataArray> ValidateDocObject::newArray() const {
|
2024-11-18 15:33:51 +00:00
|
|
|
return std::make_shared<ValidateDocArray>();
|
2024-11-18 14:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<IDataObject> ValidateDocObject::newObject() const {
|
2024-11-18 15:33:51 +00:00
|
|
|
return std::make_shared<ValidateDocObject>();
|
2024-11-18 14:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<IDataComplex> ValidateDocObject::getChild(const QString& key) const {
|
|
|
|
auto t_obj = _object_bind.value(key);
|
|
|
|
if (t_obj.isArray())
|
|
|
|
return std::make_shared<ValidateDocArray>(t_obj.toArray());
|
|
|
|
if (t_obj.isObject())
|
|
|
|
return std::make_shared<ValidateDocObject>(t_obj.toObject());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidateDocObject::setChild(const QString& key, std::shared_ptr<IDataComplex> obj) {
|
|
|
|
if (obj->isArray()) {
|
|
|
|
this->_object_bind[key] = std::dynamic_pointer_cast<ValidateDocArray>(obj)->_array_bind;
|
|
|
|
}
|
|
|
|
else if (obj->isObject()) {
|
|
|
|
this->_object_bind[key] = std::dynamic_pointer_cast<ValidateDocObject>(obj)->_object_bind;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValidateDocObject::isValueField(const QString& key) const {
|
|
|
|
auto val = _object_bind.value(key);
|
|
|
|
if (val.isArray() || val.isObject())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValidateDocObject::getBool(const QString& key) const {
|
|
|
|
return _object_bind.value(key).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
double ValidateDocObject::getDouble(const QString& key) const {
|
|
|
|
return _object_bind.value(key).toDouble();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ValidateDocObject::getInt32(const QString& key) const {
|
|
|
|
return _object_bind.value(key).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <QVariant>
|
|
|
|
int64_t ValidateDocObject::getInt64(const QString& key) const {
|
|
|
|
return _object_bind.value(key).toVariant().toLongLong();
|
|
|
|
}
|
|
|
|
|
2024-11-20 12:03:31 +00:00
|
|
|
uint64_t depict::ValidateDocObject::getUInt64(const QString& key) const {
|
|
|
|
return _object_bind.value(key).toVariant().toULongLong();
|
|
|
|
}
|
|
|
|
|
2024-11-18 14:59:45 +00:00
|
|
|
QString ValidateDocObject::getString(const QString& key) const {
|
|
|
|
return _object_bind.value(key).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidateDocObject::setBool(const QString& key, bool value) {
|
|
|
|
_object_bind[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidateDocObject::setDouble(const QString& key, double value) {
|
|
|
|
_object_bind[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidateDocObject::setInt32(const QString& key, int32_t value) {
|
|
|
|
_object_bind[key] = value;
|
|
|
|
}
|
|
|
|
|
2024-11-20 12:03:31 +00:00
|
|
|
void depict::ValidateDocObject::setUInt64(const QString& key, uint64_t value) {
|
|
|
|
_object_bind[key] = QJsonValue::fromVariant(QVariant(value));
|
|
|
|
}
|
|
|
|
|
2024-11-18 14:59:45 +00:00
|
|
|
void ValidateDocObject::setInt64(const QString& key, int64_t value) {
|
|
|
|
_object_bind[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidateDocObject::setString(const QString& key, const QString& value) {
|
|
|
|
_object_bind[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
QString ValidateDocObject::toText() const {
|
|
|
|
return QString::fromUtf8(QJsonDocument(_object_bind).toJson(QJsonDocument::JsonFormat::Compact));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidateDocObject::loadFrom(const QString& text) {
|
|
|
|
auto doc = QJsonDocument::fromJson(text.toUtf8());
|
|
|
|
_object_bind = doc.object();
|
|
|
|
}
|
|
|
|
|
|
|
|
depict::ValidateDocArray::ValidateDocArray(QJsonArray array) : _array_bind(array) { }
|
|
|
|
|
|
|
|
depict::ValidateDocArray::ValidateDocArray() { }
|
|
|
|
|
|
|
|
bool depict::ValidateDocArray::isEmpty() const {
|
|
|
|
return !_array_bind.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool depict::ValidateDocArray::isArray() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool depict::ValidateDocArray::isObject() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t depict::ValidateDocArray::size() const {
|
|
|
|
return _array_bind.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<IDataComplex> depict::ValidateDocArray::get(int index) const {
|
|
|
|
auto val = _array_bind.at(index);
|
|
|
|
if (val.isArray())
|
|
|
|
return std::make_shared<ValidateDocArray>(val.toArray());
|
|
|
|
|
|
|
|
if (val.isObject())
|
|
|
|
return std::make_shared<ValidateDocObject>(val.toObject());
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void depict::ValidateDocArray::insert(int index, std::shared_ptr<IDataComplex> value) {
|
|
|
|
if (value->isArray())
|
|
|
|
_array_bind.insert(index, std::dynamic_pointer_cast<ValidateDocArray>(value)->_array_bind);
|
|
|
|
if (value->isObject())
|
|
|
|
_array_bind.insert(index, std::dynamic_pointer_cast<ValidateDocObject>(value)->_object_bind);
|
|
|
|
}
|
|
|
|
|
|
|
|
void depict::ValidateDocArray::append(std::shared_ptr<IDataComplex> value) {
|
|
|
|
if (value->isArray())
|
|
|
|
_array_bind.append(std::dynamic_pointer_cast<ValidateDocArray>(value)->_array_bind);
|
|
|
|
if (value->isObject())
|
|
|
|
_array_bind.append(std::dynamic_pointer_cast<ValidateDocObject>(value)->_object_bind);
|
|
|
|
}
|