diff --git a/src/Mod/Spreadsheet/App/PropertySheet.cpp b/src/Mod/Spreadsheet/App/PropertySheet.cpp index d851ff14f..732a1305d 100644 --- a/src/Mod/Spreadsheet/App/PropertySheet.cpp +++ b/src/Mod/Spreadsheet/App/PropertySheet.cpp @@ -157,6 +157,27 @@ Cell *PropertySheet::getValue(CellAddress key) return i->second; } +const Cell *PropertySheet::getValue(CellAddress key) const +{ + std::map::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::const_iterator it = revAliasProp.find(alias); + + if (it != revAliasProp.end()) + return getValue(it->second); + else + return 0; +} + std::set PropertySheet::getUsedCells() const { std::set usedSet; diff --git a/src/Mod/Spreadsheet/App/PropertySheet.h b/src/Mod/Spreadsheet/App/PropertySheet.h index 0e2e78f90..8ba5169f1 100644 --- a/src/Mod/Spreadsheet/App/PropertySheet.h +++ b/src/Mod/Spreadsheet/App/PropertySheet.h @@ -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 getUsedCells() const; Sheet * sheet() const { return owner; } diff --git a/src/Mod/Spreadsheet/App/Sheet.cpp b/src/Mod/Spreadsheet/App/Sheet.cpp index 7f3466ab0..b9b3931dd 100644 --- a/src/Mod/Spreadsheet/App/Sheet.cpp +++ b/src/Mod/Spreadsheet/App/Sheet.cpp @@ -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(); } /** diff --git a/src/Mod/Spreadsheet/App/Sheet.h b/src/Mod/Spreadsheet/App/Sheet.h index bd329bfa0..65f7b9e96 100644 --- a/src/Mod/Spreadsheet/App/Sheet.h +++ b/src/Mod/Spreadsheet/App/Sheet.h @@ -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 dependsOn(CellAddress address) const; diff --git a/src/Mod/Spreadsheet/App/SheetPy.xml b/src/Mod/Spreadsheet/App/SheetPy.xml index 731e4f699..e9bfaff9c 100644 --- a/src/Mod/Spreadsheet/App/SheetPy.xml +++ b/src/Mod/Spreadsheet/App/SheetPy.xml @@ -110,6 +110,11 @@ Set alias for cell address + + + Get cell address given an alias + + Get display unit for cell diff --git a/src/Mod/Spreadsheet/App/SheetPyImp.cpp b/src/Mod/Spreadsheet/App/SheetPyImp.cpp index de63a8d94..aad6887be 100644 --- a/src/Mod/Spreadsheet/App/SheetPyImp.cpp +++ b/src/Mod/Spreadsheet/App/SheetPyImp.cpp @@ -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;