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); }
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; }
QSet<RPropertyTypeId> RBlockReferenceEntity::getPropertyTypeIds() const { QSet<RPropertyTypeId> ret; // TODO: move to RObject? // add attribute tag / values as properties of the block reference: 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.setId(RPropertyTypeId::INVALID_ID); ret.insert(pid); //qDebug() << pid.getCustomPropertyTitle() << " / " << pid.getCustomPropertyName(); //qDebug() << p.first.toString(); } } } } ret.unite(REntity::getPropertyTypeIds()); return ret; }
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(); }
/** * Sets the property with the given name to the given value or to 'mixed' * if that property exists already with a different value. * * \param propertyTypeId: Id of the property in the format "Group|Property". * \param property: Value and attributes of the property. */ void RPropertyEditor::updateProperty(const RPropertyTypeId& propertyTypeId, RObject& object, RDocument* document) { RPropertyTypeId pid = propertyTypeId; QString propertyGroupTitle = propertyTypeId.getPropertyGroupTitle(); QString propertyTitle = propertyTypeId.getPropertyTitle(); if (guiUpToDate) { combinedProperties.clear(); guiUpToDate = false; } // existing group: if (combinedProperties.count(propertyGroupTitle) > 0) { RPropertyMap& propertyMap = combinedProperties[propertyGroupTitle]; // existing property in existing group: if (propertyMap.count(propertyTitle) > 0) { QPair<QVariant, RPropertyAttributes> property = object.getProperty(pid, true, true); // mixed value: if (!RS::compare(propertyMap[propertyTitle], property)) { propertyMap[propertyTitle].first = property.first; propertyMap[propertyTitle].second.setMixed(true); } } else { // new property in existing group: QPair<QVariant, RPropertyAttributes> property = object.getProperty(pid, true); if (property.second.isInvisible()) { return; } property.second.setPropertyTypeId(propertyTypeId); propertyMap[propertyTitle] = property; propertyOrder[propertyGroupTitle].push_back(propertyTitle); } } else { // new property in new group: QPair<QVariant, RPropertyAttributes> property = object.getProperty(pid, document, true); if (property.second.isInvisible()) { return; } property.second.setPropertyTypeId(propertyTypeId); RPropertyMap propertyMap; propertyMap[propertyTitle] = property; combinedProperties[propertyGroupTitle] = propertyMap; groupOrder.push_back(propertyGroupTitle); propertyOrder[propertyGroupTitle].push_back(propertyTitle); } }
QPair<QVariant, RPropertyAttributes> RAttributeEntity::getProperty( RPropertyTypeId& propertyTypeId, bool humanReadable, bool noAttributes) { if (propertyTypeId == PropertyTag) { return qMakePair(QVariant(data.tag), RPropertyAttributes()); } if (propertyTypeId == PropertyText || propertyTypeId == PropertyPlainText) { // add custom property title for use by parent (block reference): propertyTypeId.setCustomPropertyTitle("Attributes"); propertyTypeId.setCustomPropertyName(getTag()); return qMakePair( QVariant(data.text), RPropertyAttributes( RPropertyAttributes::VisibleToParent | (propertyTypeId==PropertyPlainText ? RPropertyAttributes::ReadOnly : RPropertyAttributes::NoOptions)) ); } return RTextBasedEntity::getProperty(propertyTypeId, humanReadable, noAttributes); }
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; }
/** * \return Property attributes of given propery. */ RPropertyAttributes RPropertyEditor::getPropertyAttributes(const RPropertyTypeId& propertyTypeId) { return getPropertyAttributes(propertyTypeId.getPropertyGroupTitle(), propertyTypeId.getPropertyTitle()); }
/** * \return Property value of given propery. */ QVariant RPropertyEditor::getPropertyValue(const RPropertyTypeId& propertyTypeId) { return getPropertyValue(propertyTypeId.getPropertyGroupTitle(), propertyTypeId.getPropertyTitle()); }