bool Type::isNativeMemberPure(bool ignoreStaticMembers) { //if (!attr.isNative) // return false; for (UTsize i = 0; i < members.size(); i++) { MemberInfo *memberInfo = members.at(i); if (ignoreStaticMembers && memberInfo->isStatic()) { continue; } if (memberInfo->isConstructor()) { ConstructorInfo *cinfo = (ConstructorInfo *)memberInfo; if (cinfo->defaultConstructor) { continue; } } if (memberInfo->isConstructor() || memberInfo->isMethod()) { if (!((MethodBase *)memberInfo)->isNative()) { return false; } } if (memberInfo->isProperty()) { PropertyInfo *pinfo = (PropertyInfo *)memberInfo; if (pinfo->getGetMethod() && !pinfo->getGetMethod()->isNative()) { return false; } if (pinfo->getSetMethod() && !pinfo->getSetMethod()->isNative()) { return false; } } if (memberInfo->isField()) { if (!memberInfo->getOrdinal()) { return false; } } } if (baseType) { return baseType->isNativeMemberPure(); } return true; }
bool DataBus::GetClientPropertyInfoResponsePacket::create(const quint8 source, const quint8 destination, const quint8 packetId, const PropertyInfo &propertyInfo, Packet *packet) { // Check parameters if ((source == 0) || (propertyInfo.isValid() == false) || (packet == 0)) { // Error, invalid parameters return false; } // Create Header packet->setSource(source); packet->setDestination(destination); packet->setPacketType(PacketType_GetClientPropertyInfoResponse); packet->setPacketId(packetId); // Create Payload QByteArray data; data.append(propertyInfo.toBinary()); packet->setData(data); // Success return true; }
void Type::findMembers(const MemberTypes& memberTypes, utArray<MemberInfo *>& membersOut, bool includeBases, bool includePropertyGetterSetters) { if (!includeBases) { membersOut.clear(); } for (size_t i = 0; i < members.size(); i++) { MemberInfo *m = members.at((int)i); if (m->isConstructor() && memberTypes.constructor) { membersOut.push_back(m); } if (m->isMethod() && memberTypes.method) { membersOut.push_back(m); } if (m->isField() && memberTypes.field) { membersOut.push_back(m); } if (m->isProperty() && memberTypes.property) { membersOut.push_back(m); if (includePropertyGetterSetters) { PropertyInfo *p = (PropertyInfo *)m; if (p->getter && (p->getter->getDeclaringType() == p->getDeclaringType())) { membersOut.push_back(p->getter); } if (p->setter && (p->setter->getDeclaringType() == p->getDeclaringType())) { membersOut.push_back(p->setter); } } } } if (baseType && includeBases) { baseType->findMembers(memberTypes, membersOut, true, includePropertyGetterSetters); } }
void SettingsPropertyMapper::initilizeEditorValue(PropertyInfo& propertyInfo) { QVariant propertyValue = propertyInfo.valueGetter(propertyInfo.group, propertyInfo.propertyName, propertyInfo.defaultValue); if (propertyInfo.uiSetter != NULL) { propertyInfo.uiSetter(propertyInfo.editor, propertyInfo.editorType, propertyInfo.propertyType, propertyValue); } else { qCritical() << "Setter not set for " << propertyInfo.group << propertyInfo.propertyName; } }
void SettingsPropertyMapper::ResetToCurrentValues() { for (int i = 0; i < m_propertyInfos.size(); i++) { PropertyInfo propertyInfo = m_propertyInfos[i]; QVariant propertyValue = propertyInfo.valueGetter(propertyInfo.group, propertyInfo.propertyName, propertyInfo.defaultValue); if (propertyInfo.uiSetter != NULL) { propertyInfo.uiSetter(propertyInfo.editor, propertyInfo.editorType, propertyInfo.propertyType, propertyValue); } else { qCritical() << "Setter not set for " << propertyInfo.group << propertyInfo.propertyName; } } }
// Properly working breakpoints on windows with msvc10 and cdb inside static-function-inside-class-inside-function? // Qt-Creator: "No, not heard." static void* Helper(rapidjson::Document::ValueType* document, char *nextName) { bool isObject = document->IsObject(); TypeInfo *typeInfo = TypeInfo::GetTypeInfo(nextName); void *next = typeInfo->New(); for (rapidjson::Document::ValueType::MemberIterator i = document->MemberBegin(); i != document->MemberEnd(); ++i) { std::string propertyName = i->name.GetString(); PropertyInfo *prop = typeInfo->FindProperty(propertyName); if (i->value.IsObject()) { prop->SetValue(next, Helper(&(i->value), prop->TypeName())); } else if( i->value.IsArray()) { for (int j = 0; j < i->value.Size(); j++) { TypeInfo *tempTypeInfo = TypeInfo::GetTypeInfo(prop->TypeName()); void *temp = tempTypeInfo->New(); tempTypeInfo->SetString(temp, i->value[j].GetString()); prop->PushValue(next, temp); delete temp; } } else { TypeInfo *tempTypeInfo = TypeInfo::GetTypeInfo(prop->TypeName()); void *temp = tempTypeInfo->New(); tempTypeInfo->SetString(temp, i->value.GetString()); prop->SetValue(next, temp); delete temp; } } return next; }
PropertyInfo *PropertyInfoReader::deserializePropertyInfo(Type *declaringType, json_t *json) { PropertyInfo *pi = new PropertyInfo(); MemberInfoReader::deserialize(pi, json); // handle attr json_t *marray = json_object_get(json, "propertyattributes"); for (size_t i = 0; i < json_array_size(marray); i++) { utString modifier = json_string_value(json_array_get(marray, i)); if (modifier == "static") { pi->attr.isStatic = true; } else if (modifier == "public") { pi->attr.isPublic = true; } else if (modifier == "private") { pi->attr.isPrivate = true; } else if (modifier == "protected") { pi->attr.isProtected = true; } else if (modifier == "native") { pi->attr.isNative = true; } } utString stype = json_string_value(json_object_get(json, "type")); if (stype.size() > 0) { // a shortcut? pi->type = declaringType->getModule()->getAssembly()->getLuaState()->getType( stype.c_str()); assert(pi->type); } json_t *getter = json_object_get(json, "getter"); json_t *setter = json_object_get(json, "setter"); if (getter) { MethodBase *m = NULL; m = MethodReader::deserializeMethodInfo(declaringType, getter); assert(m->isMethod()); pi->getter = (MethodInfo *)m; m->setPropertyInfo(pi); } if (setter) { MethodBase *m = NULL; m = MethodReader::deserializeMethodInfo(declaringType, setter); assert(m->isMethod()); pi->setter = (MethodInfo *)m; m->setPropertyInfo(pi); } json_t *ttypes = json_object_get(json, "templatetypes"); if (ttypes && json_is_object(ttypes)) { TemplateInfo *info = MemberInfoReader::readTemplateTypeInfo(ttypes); assert(info); info->resolveTypes(Assembly::getAssembly(declaringType)->getLuaState()); pi->setTemplateInfo(info); } return pi; }
void ExternalExtractor::extract(ExtractionResult* result) { Q_D(ExternalExtractor); QJsonDocument writeData; QJsonObject writeRootObject; QByteArray output; QByteArray errorOutput; writeRootObject[QStringLiteral("path")] = QJsonValue(result->inputUrl()); writeRootObject[QStringLiteral("mimetype")] = result->inputMimetype(); writeData.setObject(writeRootObject); QProcess extractorProcess; extractorProcess.start(d->mainPath, QIODevice::ReadWrite); extractorProcess.write(writeData.toJson()); extractorProcess.closeWriteChannel(); extractorProcess.waitForFinished(EXTRACTOR_TIMEOUT_MS); output = extractorProcess.readAll(); errorOutput = extractorProcess.readAllStandardError(); if (extractorProcess.exitStatus()) { qDebug() << errorOutput; return; } // now we read in the output (which is a standard json format) into the // ExtractionResult QJsonDocument extractorData = QJsonDocument::fromJson(output); if (!extractorData.isObject()) { return; } QJsonObject rootObject = extractorData.object(); QJsonObject propertiesObject = rootObject[QStringLiteral("properties")].toObject(); Q_FOREACH(auto key, propertiesObject.keys()) { if (key == QStringLiteral("typeInfo")) { TypeInfo info = TypeInfo::fromName(propertiesObject.value(key).toString()); result->addType(info.type()); continue; } // for plaintext extraction if (key == QStringLiteral("text")) { result->append(propertiesObject.value(key).toString(QStringLiteral(""))); continue; } PropertyInfo info = PropertyInfo::fromName(key); if (info.name() != key) { continue; } result->add(info.property(), propertiesObject.value(key).toVariant()); } if (rootObject[QStringLiteral("status")].toString() != QStringLiteral("OK")) { qDebug() << rootObject[QStringLiteral("error")].toString(); } }
void DynamicObjectsTest::allTests() { QString dbname = "testdynamic"; Classes::setup(); Classes::addClass( "Test", DynamicObject::createInstance, 0 ); ClassInfo *ci = Classes::classInfo( "Test" ); ci->addObject( "Customer", "Customer_Test", &Customer::createInstance ); ci->addCollection( "Article", "Article_Test" ); PropertyInfo *p; p = new PropertyInfo(); p->setName( "Property1" ); p->setType( QVariant::String ); ci->addProperty( p ); p = new PropertyInfo(); p->setName( "Property2" ); p->setType( QVariant::ULongLong ); ci->addProperty( p ); Classes::setupRelations(); // Drop the database if already exists KProcess *proc = new KProcess; *proc << "dropdb"; *proc << dbname; proc->start(); proc->wait(); delete proc; // Create the database proc = new KProcess; *proc << "createdb"; *proc << dbname; CHECK( proc->start(), true ); proc->wait(); if ( ! proc->normalExit() || proc->exitStatus() != 0 ) { CHECK( true, false ); delete proc; return; } delete proc; QSqlDatabase *db = QSqlDatabase::addDatabase( "QPSQL7" ); db->setDatabaseName( dbname ); db->setUserName( "ak213" ); db->setPassword( "ak" ); db->setHostName( "localhost" ); if ( ! db->open() ) { kdDebug() << "Failed to open database: " << db->lastError().text() << endl; return; } DbBackendIface *backend = new SqlDbBackend( db ); m_manager = new Manager( backend ); m_manager->setMaxObjects( 1 ); m_manager->createSchema(); ObjectRef<Customer> customer = Customer::create(); customer->setCustomerName( "Name of the customer" ); ObjectRef<Article> a1 = Article::create(); a1->setCode( "00001" ); ObjectRef<Article> a2 = Article::create(); a2->setCode( "00002" ); ObjectRef<Object> obj = Classes::classInfo( "Test" )->create(); CHECK( obj->property( "Property1" ).type(), QVariant::String ); CHECK( obj->property( "Property2" ).type(), QVariant::ULongLong ); CHECK( obj->containsObject( "Customer_Test" ), true ); CHECK( obj->containsCollection( "Article_Test" ), true ); obj->setProperty( "Property1", "Property number one" ); obj->setProperty( "Property2", 2 ); CHECK( obj->property( QString( "Property1" ) ).value().toString(), QString( "Property number one" ) ); CHECK( obj->property( QString( "Property2" ) ).value().toULongLong(), 2 ); obj->setObject( "Customer_Test", customer ); obj->collection( "Article_Test" )->add( a1 ); obj->collection( "Article_Test" )->add( a2 ); m_manager->commit(); CHECK( obj->property( "Property1" ).value().toString(), QString( "Property number one" ) ); delete m_manager; }
bool SqlDbBackend::createSchema() { QStringList tables; QStringList constraints; QString exec; PropertyInfo *prop; uint i; // This sequence is incremented every time a new object is created m_db->exec( "CREATE SEQUENCE seq_dboid;" ); // This sequence is incremented every time a record is created or modified and is used in the dbseq field that will be created in each table. m_db->exec( "CREATE SEQUENCE seq_dbseq;" ); // Create the tables. Iterate creating the classes that // have inheritance first. QStringList classList( Classes::parentsFirst() ); QStringList::const_iterator it( classList.constBegin() ); QStringList::const_iterator end( classList.constEnd() ); ClassInfo *currentClass; for ( ; it != end; ++it ) { currentClass = Classes::classInfo( *it ); exec = "CREATE TABLE " + currentClass->name().lower() + " ( " + oidFieldName() + " BIGINT PRIMARY KEY, " + sequenceFieldName() + " BIGINT NOT NULL, "; // Create properties fields PropertiesInfoConstIterator pIt( currentClass->propertiesBegin() ); PropertiesInfoConstIterator pEnd( currentClass->propertiesEnd() ); for ( ; pIt != pEnd; ++pIt ) { prop = *pIt; if ( prop->readOnly() == false ) exec += prop->name() + " " + sqlType( prop ) + ", "; } // Create related objects fields // For 1-1 relations only create the field in one of the two tables. // We assume that both classes have relation to each other. RelationInfosConstIterator oIt( currentClass->relationsBegin() ); RelationInfosConstIterator oEnd( currentClass->relationsEnd() ); RelationInfo *rObj; for ( ; oIt != oEnd; ++oIt ) { rObj = *oIt; // needs to be >= to consider cases where the parent and related class(table) are the same if ( ! rObj->isOneToOne() || rObj->relatedClassInfo()->name() >= rObj->parentClassInfo()->name() ) { exec += rObj->name().lower() + " BIGINT DEFAULT NULL, "; constraints << currentClass->name() + "-" + rObj->name() + "-" + rObj->relatedClassInfo()->name(); } } // Search in all the classes if they have N - 1 relations with the current class ClassInfoIterator cIt( Classes::begin() ); ClassInfoIterator cEnd( Classes::end() ); ClassInfo *cInfo; for ( ; cIt != cEnd; ++cIt ) { cInfo = *cIt; CollectionInfosIterator colIt( cInfo->collectionsBegin() ); CollectionInfosIterator colEnd( cInfo->collectionsEnd() ); CollectionInfo *rCol; for ( ; colIt != colEnd; ++colIt ) { rCol = *colIt; if ( rCol->childrenClassInfo()->name() == currentClass->name() && rCol->isNToOne() && constraints.grep( rCol->name() ).count() == 0 ) { exec += rCol->name().lower() + " BIGINT DEFAULT NULL, "; constraints << currentClass->name() + "-" + rCol->name() + "-" + rCol->parentClassInfo()->name(); } } } CollectionInfosIterator colIt( currentClass->collectionsBegin() ); CollectionInfosIterator colEnd( currentClass->collectionsEnd() ); CollectionInfo *col; for ( ; colIt != colEnd; ++colIt ) { col = *colIt; if ( ! tables.grep( col->name() ).count() > 0 && ! col->isNToOne() ) { tables << col->name() + "-" + filterFieldName( col ) + "-" + idFieldName( col ); } } // Take off the colon and space exec = exec.left( exec.length() - 2 ); exec += ")"; if ( currentClass->parent() != 0 ) exec += " INHERITS ( " + currentClass->parent()->name() + ")"; m_db->exec( exec ); if ( m_db->lastError().type() != QSqlError::None ) { kdDebug() << k_funcinfo << exec << endl; kdDebug() << k_funcinfo << m_db->lastError().text() << endl; } } /* As PostgreSQL doesn't properly support foreign keys to inherited tables we will create foreign keys (references) only when the refered class hasn't any inherited classes. */ // Create relation tables (for N-M relations) QStringList list; for ( i = 0; i < tables.count(); ++i ) { list = QStringList::split( QString( "-" ), tables[ i ] ); exec = "CREATE TABLE " + list[ 0 ].lower() + " ( " + list[ 1 ].lower() + " BIGINT NOT NULL "; if ( Classes::classInfo( list[ 1 ] )->children().count() == 0 ) exec += " REFERENCES " + list[ 1 ].lower() + " DEFERRABLE INITIALLY DEFERRED"; exec += ", " + list[ 2 ].lower() + " BIGINT NOT NULL "; if ( Classes::classInfo( list[2] )->children().count() == 0 ) exec += " REFERENCES " + list[ 2 ].lower() + " DEFERRABLE INITIALLY DEFERRED"; exec += ", " + sequenceFieldName() + " BIGINT NOT NULL , PRIMARY KEY( " + list[1].lower() + " , " + list[2].lower() + " ) );"; m_db->exec( exec ); if ( m_db->lastError().type() != QSqlError::None ) { kdDebug() << k_funcinfo << " -> " << exec << endl; kdDebug() << k_funcinfo << " -> " << m_db->lastError().text() << endl; } } // Create foreign keys in class tables for ( i = 0; i < constraints.count(); ++i ) { list = QStringList::split( QString( "-" ), constraints[ i ] ); // If the related class doesn't have children we can use a normal // foreign key in PostgreSQL. Otherwise we have to use our own trigger. kdDebug() << k_funcinfo << "'" << list[ 2 ] << "'" << endl; if ( Classes::classInfo( list[ 2 ] )->children().count() == 0 ) exec = "ALTER TABLE " + list[ 0 ].lower() + " ADD FOREIGN KEY (" + list[ 1 ].lower() + ") REFERENCES " + list[ 2 ].lower() + "( " + oidFieldName() + " ) DEFERRABLE INITIALLY DEFERRED"; //else // exec = "CREATE DDL!!!"; m_db->exec( exec ); if ( m_db->lastError().type() != QSqlError::None ) { kdDebug() << k_funcinfo << " -> " << exec << endl; kdDebug() << k_funcinfo << " -> " << m_db->lastError().text() << endl; } } return true; }