Spreadsheet: support mapping protocol in PropertySheetPy

Read only mapping protocol support to retrieve a range of cell values.
Expects the key to be a string of either a single cell address or a
range.
This commit is contained in:
Zheng, Lei
2019-12-26 20:56:45 +08:00
committed by Chris Hennes
parent a5ca0b7d15
commit 830bd52af0

View File

@@ -23,7 +23,7 @@
#include "PreCompiled.h"
#include "PropertySheet.h"
#include "Mod/Spreadsheet/App/PropertySheet.h"
// inclusion of the generated files (generated out of PropertySheetPy.xml)
#include "PropertySheetPy.h"
@@ -31,6 +31,23 @@
using namespace Spreadsheet;
struct PropertySheetPyInit {
PyMappingMethods methods;
PropertySheetPyInit() {
methods.mp_length = 0;
methods.mp_ass_subscript = 0;
methods.mp_subscript = [](PyObject *o, PyObject *key) {
return static_cast<PropertySheetPy*>(o)->getPropertySheetPtr()->getPyValue(key);
};
PropertySheetPy::Type.tp_as_mapping = &methods;
}
};
static PropertySheetPyInit _PropertySheetPyInit;
// returns a string which represents the object e.g. when printed in python
std::string PropertySheetPy::representation(void) const
{