bool RDocumentVariables::setProperty(RPropertyTypeId propertyTypeId, const QVariant& value, RTransaction* transaction) { bool ret = false; ret = ret || RObject::setMember(currentLayerId, value, PropertyCurrentLayerId == propertyTypeId); ret = ret || RObject::setMember((int&)unit, value, PropertyUnit == propertyTypeId); ret = ret || RObject::setMember(linetypeScale, value, PropertyLinetypeScale == propertyTypeId); ret = ret || RObject::setMember(dimensionFont, value, PropertyDimensionFont == propertyTypeId); // custom property that is a known variable: if (propertyTypeId.isCustom()) { QString appId = propertyTypeId.getCustomPropertyTitle(); QString name = propertyTypeId.getCustomPropertyName(); RS::KnownVariable v = RDxfServices::stringToVariable(name); if (appId=="QCAD" && v!=RS::INVALID) { setKnownVariable(v, value); ret = true; } } ret = ret || RObject::setProperty(propertyTypeId, value, transaction); return ret; }
QPair<QVariant, RPropertyAttributes> RDocumentVariables::getProperty(RPropertyTypeId& propertyTypeId, bool humanReadable, bool noAttributes) { if (propertyTypeId == PropertyCurrentLayerId) { return qMakePair(QVariant(currentLayerId), RPropertyAttributes()); } if (propertyTypeId == PropertyUnit) { return qMakePair(QVariant(unit), RPropertyAttributes()); } if (propertyTypeId == PropertyLinetypeScale) { return qMakePair(QVariant(linetypeScale), RPropertyAttributes()); } if (propertyTypeId == PropertyDimensionFont) { return qMakePair(QVariant(dimensionFont), RPropertyAttributes()); } if (propertyTypeId.isCustom()) { QString appId = propertyTypeId.getCustomPropertyTitle(); QString name = propertyTypeId.getCustomPropertyName(); RS::KnownVariable v = RDxfServices::stringToVariable(name); if (appId=="QCAD" && v!=RS::INVALID) { return qMakePair(getKnownVariable(v), RPropertyAttributes(RPropertyAttributes::KnownVariable)); } } return RObject::getProperty(propertyTypeId, humanReadable, noAttributes); }
uint qHash(RPropertyTypeId propertyTypeId) { if (propertyTypeId.getId()!=RPropertyTypeId::INVALID_ID) { return qHash(propertyTypeId.getId()); } else { return qHash(propertyTypeId.getCustomPropertyTitle() + "///" + propertyTypeId.getCustomPropertyName()); } }
QDebug operator<<(QDebug dbg, const RPropertyTypeId& p) { dbg.nospace() << "RPropertyTypeId(" << p.getId() << ", " << p.getCustomPropertyName() << ", " << p.getPropertyGroupTitle() << ", " << p.getPropertyTitle() << ")"; return dbg.space(); }
QPair<QVariant, RPropertyAttributes> RBlockReferenceEntity::getProperty( RPropertyTypeId& propertyTypeId, bool humanReadable, bool noAttributes) { if (propertyTypeId == PropertyPositionX) { return qMakePair(QVariant(data.position.x), RPropertyAttributes()); } else if (propertyTypeId == PropertyPositionY) { return qMakePair(QVariant(data.position.y), RPropertyAttributes()); } else if (propertyTypeId == PropertyPositionZ) { return qMakePair(QVariant(data.position.z), RPropertyAttributes()); } else if (propertyTypeId == PropertyScaleX) { return qMakePair(QVariant(data.scaleFactors.x), RPropertyAttributes()); } else if (propertyTypeId == PropertyScaleY) { return qMakePair(QVariant(data.scaleFactors.y), RPropertyAttributes()); } else if (propertyTypeId == PropertyScaleZ) { return qMakePair(QVariant(data.scaleFactors.z), RPropertyAttributes()); } else if (propertyTypeId == PropertyRotation) { return qMakePair(QVariant(data.rotation), RPropertyAttributes(RPropertyAttributes::Angle)); } else if (propertyTypeId == PropertyReferencedBlock) { if (humanReadable) { RDocument* document = getData().getDocument(); if (document != NULL) { RPropertyAttributes attr; // TODO if (!noAttributes) { QSet<QString> blockNames = document->getBlockNames(); QSet<QString> filtered; QSet<QString>::iterator it; for (it=blockNames.begin(); it!=blockNames.end(); it++) { if (!(*it).startsWith("*")) { filtered.insert(*it); } } attr.setChoices(filtered); } return qMakePair(QVariant(document->getBlockName( getData().getReferencedBlockId())), attr); } } else { return qMakePair(QVariant(getData().getReferencedBlockId()), RPropertyAttributes()); } } else if (propertyTypeId.isCustom()) { if (propertyTypeId.getCustomPropertyTitle()=="Attributes") { QString tag = propertyTypeId.getCustomPropertyName(); const RDocument* doc = getDocument(); if (doc!=NULL) { QSet<REntity::Id> childIds = doc->queryChildEntities(getId(), RS::EntityAttribute); QSet<REntity::Id>::iterator it; for (it=childIds.begin(); it!=childIds.end(); it++) { REntity::Id childId = *it; QSharedPointer<REntity> child = doc->queryEntityDirect(childId); if (child.isNull()) { continue; } QSet<RPropertyTypeId> childProperties = child->getPropertyTypeIds(); QSet<RPropertyTypeId>::iterator it2; for (it2=childProperties.begin(); it2!=childProperties.end(); it2++) { RPropertyTypeId pid = *it2; QPair<QVariant, RPropertyAttributes> p = child->getProperty(pid); if (p.second.isVisibleToParent() && pid.getCustomPropertyName()==tag) { //ret.insert(RPropertyTypeId(QT_TRANSLATE_NOOP("REntity", "Attributes"), p.first.toString())); return qMakePair(QVariant(p.first), RPropertyAttributes()); } } } } //document->queryChildEntities(getId()); //return qMakePair(QVariant("Dummy"), RPropertyAttributes()); } } return REntity::getProperty(propertyTypeId, humanReadable, noAttributes); }
bool RBlockReferenceEntity::setProperty(RPropertyTypeId propertyTypeId, const QVariant& value, RTransaction* transaction) { bool ret = REntity::setProperty(propertyTypeId, value, transaction); // if (propertyTypeId==PropertyPositionX) { // double d = value - data.position.x; // RObject::setMember(data.position.x, value); // const RDocument* doc = getDocument(); // if (doc!=NULL) { // QSet<REntity::Id> childIds = doc->queryChildEntities(getId(), RS::EntityAttribute); // QSet<REntity::Id>::iterator it; // for (it=childIds.begin(); it!=childIds.end(); it++) { // REntity::Id childId = *it; // QSharedPointer<REntity> child = doc->queryEntity(childId); // if (child.isNull()) { // continue; // } // QSet<RPropertyTypeId> childProperties = child->getPropertyTypeIds(); // QSet<RPropertyTypeId>::iterator it2; // for (it2=childProperties.begin(); it2!=childProperties.end(); it2++) { // RPropertyTypeId pid = *it2; // QPair<QVariant, RPropertyAttributes> p = child->getProperty(pid); // if (p.second.isVisibleToParent() && pid.getCustomPropertyName()==tag) { // //ret.insert(RPropertyTypeId(QT_TRANSLATE_NOOP("REntity", "Attributes"), p.first.toString())); // //return qMakePair(QVariant(p.first), RPropertyAttributes()); // child->setProperty(pid, value.toString(), transaction); // transaction->addObject(child); // } // } // } // } // } ret = ret || RObject::setMember(data.position.x, value, PropertyPositionX == propertyTypeId); ret = ret || RObject::setMember(data.position.y, value, PropertyPositionY == propertyTypeId); ret = ret || RObject::setMember(data.position.z, value, PropertyPositionZ == propertyTypeId); ret = ret || RObject::setMember(data.scaleFactors.x, value, PropertyScaleX == propertyTypeId && fabs(value.toDouble())>RS::PointTolerance); ret = ret || RObject::setMember(data.scaleFactors.y, value, PropertyScaleY == propertyTypeId && fabs(value.toDouble())>RS::PointTolerance); ret = ret || RObject::setMember(data.scaleFactors.z, value, PropertyScaleZ == propertyTypeId && fabs(value.toDouble())>RS::PointTolerance); ret = ret || RObject::setMember(data.rotation, value, PropertyRotation == propertyTypeId); if (propertyTypeId == PropertyReferencedBlock) { if (value.type() == QVariant::Int || value.type() == QVariant::LongLong) { ret = ret || RObject::setMember( getData().referencedBlockId, value.toInt(), true); } else if (value.type() == QVariant::String) { RDocument* document = getData().getDocument(); if (document != NULL) { ret = ret || RObject::setMember(getData().referencedBlockId, document->getBlockId(value.toString()), true); } } } // allow editing of attributes in the context of a block reference: if (transaction && propertyTypeId.isCustom()) { if (propertyTypeId.getCustomPropertyTitle()=="Attributes") { QString tag = propertyTypeId.getCustomPropertyName(); const RDocument* doc = getDocument(); if (doc!=NULL) { QSet<REntity::Id> childIds = doc->queryChildEntities(getId(), RS::EntityAttribute); QSet<REntity::Id>::iterator it; for (it=childIds.begin(); it!=childIds.end(); it++) { REntity::Id childId = *it; QSharedPointer<REntity> child = doc->queryEntity(childId); if (child.isNull()) { continue; } QSet<RPropertyTypeId> childProperties = child->getPropertyTypeIds(); QSet<RPropertyTypeId>::iterator it2; for (it2=childProperties.begin(); it2!=childProperties.end(); it2++) { RPropertyTypeId pid = *it2; QPair<QVariant, RPropertyAttributes> p = child->getProperty(pid); if (p.second.isVisibleToParent() && pid.getCustomPropertyName()==tag) { //ret.insert(RPropertyTypeId(QT_TRANSLATE_NOOP("REntity", "Attributes"), p.first.toString())); //return qMakePair(QVariant(p.first), RPropertyAttributes()); child->setProperty(pid, value.toString(), transaction); transaction->addObject(child); } } } } } } if (ret) { data.update(); } return ret; }