Spreadsheet: Issue #2402: Added functionality to get cell address given an alias.
This commit is contained in:
parent
a583697e5a
commit
d45a95bf3a
|
@ -157,6 +157,27 @@ Cell *PropertySheet::getValue(CellAddress key)
|
|||
return i->second;
|
||||
}
|
||||
|
||||
const Cell *PropertySheet::getValue(CellAddress key) const
|
||||
{
|
||||
std::map<CellAddress, Cell*>::const_iterator i = data.find(key);
|
||||
|
||||
if (i == data.end())
|
||||
return 0;
|
||||
else
|
||||
return i->second;
|
||||
}
|
||||
|
||||
|
||||
const Cell * PropertySheet::getValueFromAlias(const std::string &alias) const
|
||||
{
|
||||
std::map<std::string, CellAddress>::const_iterator it = revAliasProp.find(alias);
|
||||
|
||||
if (it != revAliasProp.end())
|
||||
return getValue(it->second);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::set<CellAddress> PropertySheet::getUsedCells() const
|
||||
{
|
||||
std::set<CellAddress> usedSet;
|
||||
|
|
|
@ -81,6 +81,10 @@ public:
|
|||
|
||||
Cell * getValue(CellAddress key);
|
||||
|
||||
const Cell * getValue(CellAddress key) const;
|
||||
|
||||
const Cell * getValueFromAlias(const std::string &alias) const;
|
||||
|
||||
std::set<CellAddress> getUsedCells() const;
|
||||
|
||||
Sheet * sheet() const { return owner; }
|
||||
|
|
|
@ -1131,6 +1131,21 @@ void Sheet::setComputedUnit(CellAddress address, const Base::Unit &unit)
|
|||
void Sheet::setAlias(CellAddress address, const std::string &alias)
|
||||
{
|
||||
cells.setAlias(address, alias);
|
||||
/**
|
||||
* @brief Get cell given an alias string
|
||||
* @param alias Alias for cell
|
||||
*
|
||||
* @returns Name of cell, or empty string if not defined
|
||||
*/
|
||||
|
||||
std::string Sheet::getAddressFromAlias(const std::string &alias) const
|
||||
{
|
||||
const Cell * cell = cells.getValueFromAlias(alias);
|
||||
|
||||
if (cell)
|
||||
return cell->getAddress().toString();
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -140,6 +140,8 @@ public:
|
|||
|
||||
void setAlias(CellAddress address, const std::string & alias);
|
||||
|
||||
std::string getAddressFromAlias(const std::string & alias) const;
|
||||
|
||||
void setSpans(CellAddress address, int rows, int columns);
|
||||
|
||||
std::set<std::string> dependsOn(CellAddress address) const;
|
||||
|
|
|
@ -110,6 +110,11 @@
|
|||
<UserDocu>Set alias for cell address</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getCellFromAlias">
|
||||
<Documentation>
|
||||
<UserDocu>Get cell address given an alias</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getDisplayUnit">
|
||||
<Documentation>
|
||||
<UserDocu>Get display unit for cell</UserDocu>
|
||||
|
|
|
@ -457,6 +457,29 @@ PyObject* SheetPy::setAlias(PyObject *args)
|
|||
}
|
||||
}
|
||||
|
||||
PyObject* SheetPy::getCellFromAlias(PyObject *args)
|
||||
{
|
||||
const char * alias;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:getAlias", &alias))
|
||||
return 0;
|
||||
|
||||
try {
|
||||
std::string address = getSheetPtr()->getAddressFromAlias(alias);
|
||||
|
||||
if (address.size() > 0)
|
||||
return Py::new_reference_to( Py::String( address ) );
|
||||
else {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
}
|
||||
catch (const Base::Exception & e) {
|
||||
PyErr_SetString(PyExc_ValueError, e.what());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* SheetPy::getDisplayUnit(PyObject *args)
|
||||
{
|
||||
const char * strAddress;
|
||||
|
|
Loading…
Reference in New Issue
Block a user