void Sheet::recomputeCell(CellAddress p) { Cell * cell = cells.getValue(p); std::string docName = getDocument()->Label.getValue(); std::string docObjName = std::string(getNameInDocument()); std::string name = docName + "#" + docObjName + "." + p.toString(); try { if (cell) { cell->clearException(); cell->clearResolveException(); } updateProperty(p); cells.clearDirty(p); cellErrors.erase(p); } catch (const Base::Exception & e) { QString msg = QString::fromUtf8("ERR: %1").arg(QString::fromUtf8(e.what())); setStringProperty(p, Base::Tools::toStdString(msg)); if (cell) cell->setException(e.what()); // Mark as erroneous cellErrors.insert(p); } updateAlias(p); if (!cell || cell->spansChanged()) cellSpanChanged(p); }
void Sheet::clear(CellAddress address, bool /*all*/) { Cell * cell = getCell(address); std::string addr = address.toString(); Property * prop = props.getDynamicPropertyByName(addr.c_str()); // Remove alias, if defined std::string aliasStr; if (cell && cell->getAlias(aliasStr)) this->removeDynamicProperty(aliasStr.c_str()); cells.clear(address); // Update dependencies std::set<DocumentObject*> ds(cells.getDocDeps()); // Make sure we don't reference ourselves ds.erase(this); std::vector<DocumentObject*> dv(ds.begin(), ds.end()); docDeps.setValues(dv); propAddress.erase(prop); this->removeDynamicProperty(addr.c_str()); }
void Sheet::updateAlias(CellAddress key) { std::string alias; Property * prop = props.getDynamicPropertyByName(key.toString().c_str()); if (!prop) return; Cell * cell = getCell(key); if (cell && cell->getAlias(alias)) { Property * aliasProp = props.getDynamicPropertyByName(alias.c_str()); /* Update or create alias? */ if (aliasProp) { // Type of alias and property must always be the same if (aliasProp->getTypeId() != prop->getTypeId()) { this->removeDynamicProperty(alias.c_str()); aliasProp = 0; } } if (!aliasProp) aliasProp = props.addDynamicProperty(prop->getTypeId().getName(), alias.c_str(), 0, 0, Prop_ReadOnly | Prop_Transient); aliasProp->Paste(*prop); } }
void Sheet::clear(CellAddress address, bool all) { Cell * cell = getCell(address); std::string addr = address.toString(); Property * prop = props.getDynamicPropertyByName(addr.c_str()); // Remove alias, if defined std::string aliasStr; if (cell && cell->getAlias(aliasStr)) props.removeDynamicProperty(aliasStr.c_str()); cells.clear(address); propAddress.erase(prop); props.removeDynamicProperty(addr.c_str()); }
void Sheet::setAlias(CellAddress address, const std::string &alias) { std::string existingAlias = getAddressFromAlias(alias); if (existingAlias.size() > 0) { if (existingAlias == address.toString()) // Same as old? return; else throw Base::Exception("Alias already defined"); } else if (alias.size() == 0) // Empty? cells.setAlias(address, ""); else if (isValidAlias(alias)) // Valid? cells.setAlias(address, alias); else throw Base::Exception("Invalid alias"); }
void Sheet::providesTo(CellAddress address, std::set<CellAddress> & result) const { const char * docName = getDocument()->Label.getValue(); const char * docObjName = getNameInDocument(); std::string fullName = std::string(docName) + "#" + std::string(docObjName) + "." + address.toString(); result = cells.getDeps(fullName); }
void Sheet::providesTo(CellAddress address, std::set<std::string> & result) const { const char * docName = getDocument()->Label.getValue(); const char * docObjName = getNameInDocument(); std::string fullName = std::string(docName) + "#" + std::string(docObjName) + "." + address.toString(); std::set<CellAddress> tmpResult = cells.getDeps(fullName); for (std::set<CellAddress>::const_iterator i = tmpResult.begin(); i != tmpResult.end(); ++i) result.insert(std::string(docName) + "#" + std::string(docObjName) + "." + i->toString()); }