1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| #include "../include/precompiled.h"
#include "../include/CPerson.h"
#include <QxMemLeak.h>
void myGlobalValidator_1(const QVariant & value, const qx::IxValidator * validator, qx::QxInvalidValueX & invalidValues);
void myGlobalValidator_2(const QString & value, const qx::IxValidator * validator, qx::QxInvalidValueX & invalidValues);
QX_REGISTER_COMPLEX_CLASS_NAME_CPP_QX_DLL1(qx::test::CPerson, qx_test_CPerson)
namespace qx {
template <> void register_class(QxClass<qx::test::CPerson> & t)
{
IxDataMember * pData = NULL;
IxFunction * pFct = NULL;
IxValidator * pValidator = NULL;
t.setName("CPerson");
pData = t.id(& qx::test::CPerson::m_lPersonId, "idPerson", 0);
pData = t.data(& qx::test::CPerson::m_sFirstName, "firstName", 0);
pData = t.data(& qx::test::CPerson::m_sLastName, "lastName", 0);
pData = t.data(& qx::test::CPerson::m_dDouble, "double", 0);
pData = t.data(& qx::test::CPerson::m_eSex, "sex", 0);
pFct = t.fct_0<long>(& qx::test::CPerson::getPersonId, "fct_getPersonId");
pFct = t.fct_0<QString>(& qx::test::CPerson::getFirstName, "fct_getFirstName");
pFct = t.fct_1<void, long>(& qx::test::CPerson::setPersonId, "fct_setPersonId");
QxValidatorX<qx::test::CPerson> * pAllValidator = t.getAllValidator();
if (! pAllValidator) { qAssert(false); return; }
pValidator = pAllValidator->add_NotEmpty("firstName", "a person must have a firstname");
pValidator = pAllValidator->add_NotEmpty("lastName");
pValidator = pAllValidator->add_MinDecimal("double", 0.5, "'double' field must be greater than or equal to '0.5'");
pValidator = pAllValidator->add_MaxDecimal("double", 103.19);
pValidator = pAllValidator->add_CustomValidator(& qx::test::CPerson::isValid);
pValidator = pAllValidator->add_CustomValidator_QVariant(& myGlobalValidator_1, "firstName");
pValidator = pAllValidator->add_CustomValidator_DataType<QString>(& myGlobalValidator_2, "lastName");
}}
namespace qx {
namespace test {
void CPerson::isValid(qx::QxInvalidValueX & invalidValues)
{
// This method is called automatically by 'QxValidator' module (validator engine of QxOrm library) :
// - when you try to insert or update using 'qx::dao::xxx' functions
// - when you call 'qx::validate()' function
// For registration, see 'pAllValidator->add_CustomValidator(& qx::test::CPerson::isValid);' into 'qx::register_class<T>()' function
// Here, you can verify some values of your instance
// If a value is not valid, you must add an invalid value into the collection 'invalidValues'
if ((m_sFirstName == "admin") || (m_sLastName == "admin"))
{ invalidValues.insert("you cannot set 'admin' for the name of a person"); }
}
} // namespace test
} // namespace qx
// ********************************************************************************************************
// ********************************************************************************************************
// Example of global functions 'myGlobalValidator_1' and 'myGlobalValidator_2' used by 'QxValidator' module
// Those functions will be called automatically by validator engine of QxOrm library :
// - when you try to insert or update using 'qx::dao::xxx' functions
// - when you call 'qx::validate()' function
void myGlobalValidator_1(const QVariant & value, const qx::IxValidator * validator, qx::QxInvalidValueX & invalidValues)
{
// Here you can test the value (converted to QVariant type)
// If an invalid value is detected, just add a message into 'invalidValues' collection
Q_UNUSED(value); Q_UNUSED(validator); Q_UNUSED(invalidValues);
}
void myGlobalValidator_2(const QString & value, const qx::IxValidator * validator, qx::QxInvalidValueX & invalidValues)
{
// Here you can test the value (with its real type, in this example, the data-member is a 'QString' type)
// If an invalid value is detected, just add a message into 'invalidValues' collection
Q_UNUSED(value); Q_UNUSED(validator); Q_UNUSED(invalidValues);
}
// ********************************************************************************************************
// ******************************************************************************************************** |
Partager