Skip to content

Commit

Permalink
[Spreadsheet] Fix CSV Insert/Import
Browse files Browse the repository at this point in the history
  • Loading branch information
Syres916 authored Oct 7, 2024
1 parent ddbaa1a commit 22345bf
Showing 1 changed file with 67 additions and 32 deletions.
99 changes: 67 additions & 32 deletions src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,51 +52,86 @@ void loadSpreadsheetResource()
Gui::Translator::instance()->refresh();
}

namespace SpreadsheetGui {
class Module : public Py::ExtensionModule<Module>
namespace SpreadsheetGui
{
class Module: public Py::ExtensionModule<Module>

Check warning on line 57 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

class 'Module' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

Check warning on line 57 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

class 'Module' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
{
public:
Module()
: Py::ExtensionModule<Module>("SpreadsheetGui")
{
public:
Module() : Py::ExtensionModule<Module>("SpreadsheetGui")
{
add_varargs_method("open",&Module::open
);
initialize("This module is the SpreadsheetGui module."); // register with Python
add_varargs_method("open", &Module::open);
add_varargs_method("insert", &Module::insert);
initialize("This module is the SpreadsheetGui module.");// register with Python
}

~Module() override

Check warning on line 68 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

use '= default' to define a trivial destructor [modernize-use-equals-default]

Check warning on line 68 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

use '= default' to define a trivial destructor [modernize-use-equals-default]
{}

private:
Py::Object open(const Py::Tuple& args)

Check warning on line 72 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

method 'open' can be made static [readability-convert-member-functions-to-static]

Check warning on line 72 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

method 'open' can be made static [readability-convert-member-functions-to-static]
{
char* Name;

Check warning on line 74 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'Name' is not initialized [cppcoreguidelines-init-variables]

Check warning on line 74 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

variable 'Name' is not initialized [cppcoreguidelines-init-variables]
const char* DocName = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "et|s", "utf-8", &Name, &DocName))

Check warning on line 76 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]

Check warning on line 76 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion 'int' -> bool [readability-implicit-bool-conversion]

Check warning on line 76 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]

Check warning on line 76 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]

Check warning on line 76 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion 'int' -> bool [readability-implicit-bool-conversion]

Check warning on line 76 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]
throw Py::Exception();
std::string EncodedName = std::string(Name);
PyMem_Free(Name);

try {
Base::FileInfo file(EncodedName);
App::Document* pcDoc =
App::GetApplication().newDocument(DocName ? DocName : QT_TR_NOOP("Unnamed"));
Spreadsheet::Sheet* pcSheet = static_cast<Spreadsheet::Sheet*>(

Check warning on line 85 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]

Check warning on line 85 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
pcDoc->addObject("Spreadsheet::Sheet", file.fileNamePure().c_str()));

pcSheet->importFromFile(EncodedName, '\t', '"', '\\');
pcSheet->execute();
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}

~Module() override {}
return Py::None();
}


private:
Py::Object open(const Py::Tuple& args)
{
char* Name;
const char* DocName=nullptr;
if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName))
throw Py::Exception();
std::string EncodedName = std::string(Name);
PyMem_Free(Name);
Py::Object insert(const Py::Tuple& args)

Check warning on line 99 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

method 'insert' can be made static [readability-convert-member-functions-to-static]

Check warning on line 99 in src/Mod/Spreadsheet/Gui/AppSpreadsheetGui.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

method 'insert' can be made static [readability-convert-member-functions-to-static]
{
char* Name;
const char* DocName = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "et|s", "utf-8", &Name, &DocName)) {
throw Py::Exception();
}
std::string EncodedName = std::string(Name);
PyMem_Free(Name);

try {
Base::FileInfo file(EncodedName);
App::Document *pcDoc = App::GetApplication().newDocument(DocName ? DocName : QT_TR_NOOP("Unnamed"));
Spreadsheet::Sheet *pcSheet = static_cast<Spreadsheet::Sheet *>(pcDoc->addObject("Spreadsheet::Sheet", file.fileNamePure().c_str()));
try {
Base::FileInfo file(EncodedName);
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
App::Document* pcDoc = doc->getDocument();
Spreadsheet::Sheet* pcSheet = static_cast<Spreadsheet::Sheet*>(
pcDoc->addObject("Spreadsheet::Sheet", file.fileNamePure().c_str()));

pcSheet->importFromFile(EncodedName, '\t', '"', '\\');
pcSheet->execute();
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}

return Py::None();
}
};
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}

PyObject* initModule()
{
return Base::Interpreter().addModule(new Module);
return Py::None();
}
};

PyObject* initModule()
{
return Base::Interpreter().addModule(new Module);
}

} // namespace SpreadsheetGui
}// namespace SpreadsheetGui

/* Python entry */
PyMOD_INIT_FUNC(SpreadsheetGui)
Expand Down

0 comments on commit 22345bf

Please sign in to comment.