Spreadsheet: Expose currentIndex to Python

This commit is contained in:
Chris Hennes
2021-11-12 22:53:42 -06:00
parent 4a4db353a5
commit 093f15dce5
5 changed files with 42 additions and 4 deletions

View File

@@ -439,6 +439,11 @@ QModelIndex SheetView::currentIndex() const
return ui->cells->currentIndex();
}
void SpreadsheetGui::SheetView::setCurrentIndex(App::CellAddress cell) const
{
ui->cells->setCurrentIndex(model->index(cell.row(), cell.col()));
}
PyObject *SheetView::getPyObject()
{
if (!pythonObject)

View File

@@ -79,6 +79,8 @@ public:
QModelIndex currentIndex() const;
void setCurrentIndex(App::CellAddress cell) const;
void deleteSelection();
PyObject *getPyObject(void);

View File

@@ -2,6 +2,7 @@
#include "SpreadsheetViewPy.h"
#include "SpreadsheetViewPy.cpp"
#include "ui_Sheet.h"
#include <Mod/Spreadsheet/App/SheetPy.h>

View File

@@ -27,10 +27,19 @@
</Methode>
<Methode Name="select">
<Documentation>
<UserDocu>
select(index, flags): Select the specified cell using the given QItemSelectionModel.SelectionFlag set
<UserDocu>select(index, flags): Select the specified cell using the given QItemSelectionModel.SelectionFlag set
select(topLeft, bottomRight, flags): Select the specified range using the given QItemSelectionModel.SelectionFlag set</UserDocu>
</Documentation>
</Methode>
<Methode Name="currentIndex">
<Documentation>
<UserDocu>Get the current active cell</UserDocu>
</Documentation>
</Methode>
<Methode Name="setCurrentIndex">
<Documentation>
<UserDocu>Set the current active cell</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>
</GenerateModel>

View File

@@ -48,7 +48,6 @@ PyObject* ViewProviderSpreadsheetPy::select(PyObject* _args)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView* sheetView = vp->getView();
Spreadsheet::Sheet* sheet = sheetView->getSheet();
Py::Sequence args(_args);
@@ -73,6 +72,28 @@ PyObject* ViewProviderSpreadsheetPy::select(PyObject* _args)
return Py_None;
}
PyObject* ViewProviderSpreadsheetPy::currentIndex(PyObject* _args)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView* sheetView = vp->getView();
auto index = sheetView->currentIndex();
PyObject* py_str = PyUnicode_FromString(
App::CellAddress(index.row(), index.column()).toString().c_str());
return py_str;
}
PyObject* ViewProviderSpreadsheetPy::setCurrentIndex(PyObject* args)
{
ViewProviderSheet* vp = this->getViewProviderSheetPtr();
SheetView* sheetView = vp->getView();
const char* cell;
if (PyArg_ParseTuple(args, "s", &cell)) {
sheetView->setCurrentIndex(App::CellAddress(cell));
}
return Py_None;
}
PyObject *ViewProviderSpreadsheetPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;