From 830bd52af0edcb2eea7327618e6f67dcacd3799a Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Thu, 26 Dec 2019 20:56:45 +0800 Subject: [PATCH] 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. --- .../Spreadsheet/App/PropertySheetPyImp.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Mod/Spreadsheet/App/PropertySheetPyImp.cpp b/src/Mod/Spreadsheet/App/PropertySheetPyImp.cpp index 9dd2fa1a65..1313ed80b4 100644 --- a/src/Mod/Spreadsheet/App/PropertySheetPyImp.cpp +++ b/src/Mod/Spreadsheet/App/PropertySheetPyImp.cpp @@ -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(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 {