Sheet: Apply clang format

This commit is contained in:
wmayer
2023-09-10 13:07:23 +02:00
committed by wwmayer
parent 4d3c9ce1c5
commit 50bb81e6fc
25 changed files with 2733 additions and 2054 deletions

View File

@@ -30,13 +30,15 @@
#include "Sheet.h"
namespace Spreadsheet {
class Module : public Py::ExtensionModule<Module>
namespace Spreadsheet
{
class Module: public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("Spreadsheet")
Module()
: Py::ExtensionModule<Module>("Spreadsheet")
{
initialize("This module is the Spreadsheet module."); // register with Python
initialize("This module is the Spreadsheet module.");// register with Python
}
private:
@@ -46,7 +48,7 @@ PyObject* initModule()
{
return Base::Interpreter().addModule(new Module);
}
} // namespace Spreadsheet
}// namespace Spreadsheet
/* Python entry */
PyMOD_INIT_FUNC(Spreadsheet)

File diff suppressed because it is too large Load Diff

View File

@@ -23,8 +23,8 @@
#ifndef CELL_H
#define CELL_H
#include <string>
#include <set>
#include <string>
#include <App/Expression.h>
#include <App/Material.h>
@@ -33,61 +33,64 @@
#include "Utils.h"
namespace Base {
namespace Base
{
class Unit;
class XMLReader;
class Writer;
}
}// namespace Base
namespace Spreadsheet {
namespace Spreadsheet
{
class PropertySheet;
class DisplayUnit;
class SpreadsheetExport Cell {
class SpreadsheetExport Cell
{
private:
Cell(const Cell & other);
Cell(const Cell& other);
public:
Cell(const App::CellAddress& _address, PropertySheet* _owner);
Cell(const App::CellAddress & _address, PropertySheet * _owner);
Cell(PropertySheet* _owner, const Cell& other);
Cell(PropertySheet * _owner, const Cell & other);
Cell& operator=( const Cell& rhs );
Cell& operator=(const Cell& rhs);
~Cell();
const App::Expression * getExpression(bool withFormat=false) const;
const App::Expression* getExpression(bool withFormat = false) const;
bool getStringContent(std::string & s, bool persistent=false) const;
bool getStringContent(std::string& s, bool persistent = false) const;
void setContent(const char * value);
void setContent(const char* value);
void setAlignment(int _alignment);
bool getAlignment(int & _alignment) const;
bool getAlignment(int& _alignment) const;
void setStyle(const std::set<std::string> & _style);
bool getStyle(std::set<std::string> & style) const;
void setStyle(const std::set<std::string>& _style);
bool getStyle(std::set<std::string>& style) const;
void setForeground(const App::Color &color);
bool getForeground(App::Color &color) const;
void setForeground(const App::Color& color);
bool getForeground(App::Color& color) const;
void setBackground(const App::Color &color);
bool getBackground(App::Color &color) const;
void setBackground(const App::Color& color);
bool getBackground(App::Color& color) const;
void setDisplayUnit(const std::string & unit);
bool getDisplayUnit(DisplayUnit &unit) const;
void setDisplayUnit(const std::string& unit);
bool getDisplayUnit(DisplayUnit& unit) const;
void setAlias(const std::string & n);
bool getAlias(std::string & n ) const;
void setAlias(const std::string& n);
bool getAlias(std::string& n) const;
void setComputedUnit(const Base::Unit & unit);
bool getComputedUnit(Base::Unit & unit) const;
void setComputedUnit(const Base::Unit& unit);
bool getComputedUnit(Base::Unit& unit) const;
void setSpans(int rows, int columns);
bool getSpans(int & rows, int & columns) const;
bool getSpans(int& rows, int& columns) const;
void setException(const std::string & e, bool silent=false);
void setException(const std::string& e, bool silent = false);
void clearException();
@@ -95,32 +98,48 @@ public:
void setDirty();
void setResolveException(const std::string &e);
void setResolveException(const std::string& e);
void clearResolveException();
const std::string &getException() const { return exceptionStr; }
const std::string& getException() const
{
return exceptionStr;
}
bool hasException() const { return isUsed(EXCEPTION_SET) || isUsed(PARSE_EXCEPTION_SET) || isUsed(RESOLVE_EXCEPTION_SET); }
bool hasException() const
{
return isUsed(EXCEPTION_SET) || isUsed(PARSE_EXCEPTION_SET)
|| isUsed(RESOLVE_EXCEPTION_SET);
}
void moveAbsolute(App::CellAddress newAddress);
void restore(Base::XMLReader &reader, bool checkAlias=false);
void restore(Base::XMLReader& reader, bool checkAlias = false);
void afterRestore();
void save(Base::Writer &writer) const;
void save(std::ostream &os, const char *indent, bool noContent) const;
void save(Base::Writer& writer) const;
void save(std::ostream& os, const char* indent, bool noContent) const;
bool isUsed() const;
void mark() { setUsed(MARK_SET); }
void mark()
{
setUsed(MARK_SET);
}
bool isMarked() const { return isUsed(MARK_SET); }
bool isMarked() const
{
return isUsed(MARK_SET);
}
void visit(App::ExpressionVisitor & v);
void visit(App::ExpressionVisitor& v);
App::CellAddress getAddress() const { return address; }
App::CellAddress getAddress() const
{
return address;
}
std::string getFormattedQuantity();
@@ -137,19 +156,18 @@ public:
static const int ALIGNMENT_VIMPLIED;
/* Static functions */
static int decodeAlignment(const std::string &itemStr, int alignment);
static int decodeAlignment(const std::string& itemStr, int alignment);
static std::string encodeAlignment(int alignment);
static std::string encodeStyle(const std::set<std::string> &style);
static std::string encodeStyle(const std::set<std::string>& style);
static std::string encodeColor(const App::Color &color);
static App::Color decodeColor(const std::string &color, const App::Color &defaultColor);
static std::string encodeColor(const App::Color& color);
static App::Color decodeColor(const std::string& color, const App::Color& defaultColor);
private:
void setParseException(const std::string& e);
void setParseException(const std::string & e);
void setExpression(App::ExpressionPtr &&expr);
void setExpression(App::ExpressionPtr&& expr);
void setUsed(int mask, bool state = true);
@@ -175,7 +193,7 @@ private:
static const int RESOLVE_EXCEPTION_SET;
App::CellAddress address;
PropertySheet * owner;
PropertySheet* owner;
int used;
mutable App::ExpressionPtr expression;
@@ -193,6 +211,6 @@ private:
friend class PropertySheet;
};
}
}// namespace Spreadsheet
#endif // CELL_H
#endif// CELL_H

View File

@@ -23,24 +23,26 @@
#ifndef DISPLAYUNIT_H
#define DISPLAYUNIT_H
#include <string>
#include <Base/Unit.h>
#include <string>
namespace Spreadsheet {
namespace Spreadsheet
{
class DisplayUnit {
class DisplayUnit
{
public:
std::string stringRep;
Base::Unit unit;
double scaler;
explicit DisplayUnit(const std::string _stringRep = "", const Base::Unit _unit = Base::Unit(), double _scaler = 0.0)
explicit DisplayUnit(const std::string _stringRep = "",
const Base::Unit _unit = Base::Unit(),
double _scaler = 0.0)
: stringRep(_stringRep)
, unit(_unit)
, scaler(_scaler)
{
}
{}
bool operator==(const DisplayUnit& c) const
{
@@ -52,10 +54,12 @@ public:
return !operator==(c);
}
bool isEmpty() const { return stringRep.empty(); }
bool isEmpty() const
{
return stringRep.empty();
}
};
}
}// namespace Spreadsheet
#endif // DISPLAYUNIT_H
#endif// DISPLAYUNIT_H

View File

@@ -28,10 +28,10 @@
// point at which warnings of overly long specifiers disabled (needed for VC6)
#ifdef _MSC_VER
# pragma warning( disable : 4251 )
# pragma warning( disable : 4275 )
# pragma warning( disable : 4503 )
# pragma warning( disable : 4786 ) // specifier longer then 255 chars
#pragma warning(disable : 4251)
#pragma warning(disable : 4275)
#pragma warning(disable : 4503)
#pragma warning(disable : 4786)// specifier longer then 255 chars
#endif
#ifdef _PreComp_
@@ -47,15 +47,15 @@
#include <string>
// boost
#include <boost/regex.hpp>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <boost/regex.hpp>
#include <boost/tokenizer.hpp>
// Qt
#include <QLocale>
#endif//_PreComp_
#endif // SPREADSHEET_PRECOMPILED_H
#endif// SPREADSHEET_PRECOMPILED_H

View File

@@ -36,12 +36,13 @@ using namespace Spreadsheet;
const int PropertyColumnWidths::defaultWidth = 100;
const int PropertyColumnWidths::defaultHeaderWidth = 50;
TYPESYSTEM_SOURCE(Spreadsheet::PropertyColumnWidths , App::Property)
TYPESYSTEM_SOURCE(Spreadsheet::PropertyColumnWidths, App::Property)
PropertyColumnWidths::PropertyColumnWidths() = default;
PropertyColumnWidths::PropertyColumnWidths(const PropertyColumnWidths &other)
: Property(), std::map<int, int>(other)
PropertyColumnWidths::PropertyColumnWidths(const PropertyColumnWidths& other)
: Property()
, std::map<int, int>(other)
{
std::map<int, int>::const_iterator i = other.begin();
@@ -51,19 +52,20 @@ PropertyColumnWidths::PropertyColumnWidths(const PropertyColumnWidths &other)
}
}
App::Property *PropertyColumnWidths::Copy() const
App::Property* PropertyColumnWidths::Copy() const
{
PropertyColumnWidths * prop = new PropertyColumnWidths(*this);
PropertyColumnWidths* prop = new PropertyColumnWidths(*this);
return prop;
}
void PropertyColumnWidths::Paste(const App::Property &from)
void PropertyColumnWidths::Paste(const App::Property& from)
{
setValues(dynamic_cast<const PropertyColumnWidths&>(from).getValues());
}
void PropertyColumnWidths::setValues(const std::map<int,int> &values) {
void PropertyColumnWidths::setValues(const std::map<int, int>& values)
{
aboutToSetValue();
std::map<int, int>::const_iterator i;
@@ -89,12 +91,12 @@ void PropertyColumnWidths::setValues(const std::map<int,int> &values) {
}
/**
* Set the width (in pixels) of column \a col to \a width.
*
* @param col Column to set
* @param width Width in pixels
*
*/
* Set the width (in pixels) of column \a col to \a width.
*
* @param col Column to set
* @param width Width in pixels
*
*/
void PropertyColumnWidths::setValue(int col, int width)
{
@@ -106,21 +108,22 @@ void PropertyColumnWidths::setValue(int col, int width)
}
}
void PropertyColumnWidths::Save(Base::Writer &writer) const
void PropertyColumnWidths::Save(Base::Writer& writer) const
{
// Save column information
// Save column information
writer.Stream() << writer.ind() << "<ColumnInfo Count=\"" << size() << "\">" << std::endl;
writer.incInd(); // indentation for 'ColumnInfo'
writer.incInd();// indentation for 'ColumnInfo'
std::map<int, int>::const_iterator coli = begin();
while (coli != end()) {
writer.Stream() << writer.ind() << "<Column name=\"" << columnName(coli->first) << "\" width=\"" << coli->second << "\" />" << std::endl;
writer.Stream() << writer.ind() << "<Column name=\"" << columnName(coli->first)
<< "\" width=\"" << coli->second << "\" />" << std::endl;
++coli;
}
writer.decInd(); // indentation for 'ColumnInfo'
writer.decInd();// indentation for 'ColumnInfo'
writer.Stream() << writer.ind() << "</ColumnInfo>" << std::endl;
}
void PropertyColumnWidths::Restore(Base::XMLReader &reader)
void PropertyColumnWidths::Restore(Base::XMLReader& reader)
{
int Cnt;
@@ -130,7 +133,7 @@ void PropertyColumnWidths::Restore(Base::XMLReader &reader)
for (int i = 0; i < Cnt; i++) {
reader.readElement("Column");
const char* name = reader.hasAttribute("name") ? reader.getAttribute("name") : nullptr;
const char * width = reader.hasAttribute("width") ? reader.getAttribute("width") : nullptr;
const char* width = reader.hasAttribute("width") ? reader.getAttribute("width") : nullptr;
try {
if (name && width) {
@@ -143,16 +146,15 @@ void PropertyColumnWidths::Restore(Base::XMLReader &reader)
catch (...) {
// Something is wrong, skip this column
}
}
reader.readEndElement("ColumnInfo");
}
PyObject *PropertyColumnWidths::getPyObject()
PyObject* PropertyColumnWidths::getPyObject()
{
if (PythonObject.is(Py::_None())){
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new PropertyColumnWidthsPy(this),true);
PythonObject = Py::Object(new PropertyColumnWidthsPy(this), true);
}
return Py::new_reference_to(PythonObject);
}
@@ -165,5 +167,5 @@ void PropertyColumnWidths::clear()
dirty.insert(i->first);
++i;
}
std::map<int,int>::clear();
std::map<int, int>::clear();
}

View File

@@ -23,49 +23,63 @@
#ifndef PROPERTYCOLUMNWIDTHS_H
#define PROPERTYCOLUMNWIDTHS_H
#include <map>
#include <App/Property.h>
#include <CXX/Objects.hxx>
#include <Mod/Spreadsheet/SpreadsheetGlobal.h>
#include <map>
namespace Spreadsheet {
namespace Spreadsheet
{
class SpreadsheetExport PropertyColumnWidths : public App::Property, std::map<int, int>
class SpreadsheetExport PropertyColumnWidths: public App::Property, std::map<int, int>
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
PropertyColumnWidths();
void setValue() { }
void setValue()
{}
void setValue(int col, int width);
void setValues(const std::map<int,int> &);
void setValues(const std::map<int, int>&);
std::map<int, int> getValues() const {
std::map<int, int> getValues() const
{
return *this;
}
int getValue(int column) const {
int getValue(int column) const
{
std::map<int, int>::const_iterator i = find(column);
return i != end() ? i->second : defaultWidth;
}
Property *Copy() const override;
Property* Copy() const override;
void Paste(const Property &from) override;
void Paste(const Property& from) override;
void Save (Base::Writer & writer) const override;
void Save(Base::Writer& writer) const override;
void Restore(Base::XMLReader & reader) override;
void Restore(Base::XMLReader& reader) override;
bool isDirty() const { return !dirty.empty(); }
bool isDirty() const
{
return !dirty.empty();
}
void clearDirty() { dirty.clear(); }
void clearDirty()
{
dirty.clear();
}
const std::set<int> & getDirty() const { return dirty; }
const std::set<int>& getDirty() const
{
return dirty;
}
PyObject *getPyObject() override;
PyObject* getPyObject() override;
void clear();
@@ -73,14 +87,13 @@ public:
static const int defaultHeaderWidth;
private:
PropertyColumnWidths(const PropertyColumnWidths & other);
PropertyColumnWidths(const PropertyColumnWidths& other);
std::set<int> dirty;
Py::Object PythonObject;
};
}
}// namespace Spreadsheet
#endif // PROPERTYCOLUMNWIDTHS_H
#endif// PROPERTYCOLUMNWIDTHS_H

View File

@@ -10,7 +10,6 @@
FatherInclude="Base/PersistencePy.h"
FatherNamespace="Base"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Eivind Kvedalen" EMail="eivind@kvedalen.name" />
<UserDocu>Internal spreadsheet object</UserDocu>

View File

@@ -24,8 +24,10 @@
#include "PropertyColumnWidths.h"
// inclusion of the generated files (generated out of PropertyColumnWidthsPy.xml)
// clang-format off
#include "PropertyColumnWidthsPy.h"
#include "PropertyColumnWidthsPy.cpp"
// clang-format on
using namespace Spreadsheet;
@@ -36,7 +38,7 @@ std::string PropertyColumnWidthsPy::representation() const
return {"<PropertyColumnWidths object>"};
}
PyObject *PropertyColumnWidthsPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
PyObject* PropertyColumnWidthsPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper
{
// create a new instance of PropertyColumnWidthsPy and the Twin object
return new PropertyColumnWidthsPy(new PropertyColumnWidths);
@@ -48,7 +50,7 @@ int PropertyColumnWidthsPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
return 0;
}
PyObject *PropertyColumnWidthsPy::getCustomAttributes(const char* /*attr*/) const
PyObject* PropertyColumnWidthsPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}

View File

@@ -35,28 +35,29 @@ using namespace Spreadsheet;
const int PropertyRowHeights::defaultHeight = 30;
TYPESYSTEM_SOURCE(Spreadsheet::PropertyRowHeights , App::Property)
TYPESYSTEM_SOURCE(Spreadsheet::PropertyRowHeights, App::Property)
PropertyRowHeights::PropertyRowHeights() = default;
PropertyRowHeights::PropertyRowHeights(const PropertyRowHeights &other)
: Property(), std::map<int, int>(other)
{
}
PropertyRowHeights::PropertyRowHeights(const PropertyRowHeights& other)
: Property()
, std::map<int, int>(other)
{}
App::Property *PropertyRowHeights::Copy() const
App::Property* PropertyRowHeights::Copy() const
{
PropertyRowHeights * prop = new PropertyRowHeights(*this);
PropertyRowHeights* prop = new PropertyRowHeights(*this);
return prop;
}
void PropertyRowHeights::Paste(const Property &from)
void PropertyRowHeights::Paste(const Property& from)
{
setValues(dynamic_cast<const PropertyRowHeights&>(from).getValues());
}
void PropertyRowHeights::setValues(const std::map<int,int> &values) {
void PropertyRowHeights::setValues(const std::map<int, int>& values)
{
aboutToSetValue();
std::map<int, int>::const_iterator i;
@@ -81,28 +82,29 @@ void PropertyRowHeights::setValues(const std::map<int,int> &values) {
hasSetValue();
}
void PropertyRowHeights::Save(Base::Writer &writer) const
void PropertyRowHeights::Save(Base::Writer& writer) const
{
// Save row information
writer.Stream() << writer.ind() << "<RowInfo Count=\"" << size() << "\">" << std::endl;
writer.incInd(); // indentation for 'RowInfo'
writer.incInd();// indentation for 'RowInfo'
std::map<int, int>::const_iterator ri = begin();
while (ri != end()) {
writer.Stream() << writer.ind() << "<Row name=\"" << rowName(ri->first) << "\" height=\"" << ri->second << "\" />" << std::endl;
writer.Stream() << writer.ind() << "<Row name=\"" << rowName(ri->first) << "\" height=\""
<< ri->second << "\" />" << std::endl;
++ri;
}
writer.decInd(); // indentation for 'RowInfo'
writer.decInd();// indentation for 'RowInfo'
writer.Stream() << writer.ind() << "</RowInfo>" << std::endl;
}
/**
* Set height of row given by \a row to \a height in pixels.
*
* @param row Address of row
* @param height Height in pixels
*
*/
* Set height of row given by \a row to \a height in pixels.
*
* @param row Address of row
* @param height Height in pixels
*
*/
void PropertyRowHeights::setValue(int row, int height)
{
@@ -114,7 +116,7 @@ void PropertyRowHeights::setValue(int row, int height)
}
}
void PropertyRowHeights::Restore(Base::XMLReader &reader)
void PropertyRowHeights::Restore(Base::XMLReader& reader)
{
int Cnt;
@@ -124,7 +126,8 @@ void PropertyRowHeights::Restore(Base::XMLReader &reader)
for (int i = 0; i < Cnt; i++) {
reader.readElement("Row");
const char* name = reader.hasAttribute("name") ? reader.getAttribute("name") : nullptr;
const char * height = reader.hasAttribute("height") ? reader.getAttribute("height") : nullptr;
const char* height =
reader.hasAttribute("height") ? reader.getAttribute("height") : nullptr;
try {
if (name && height) {
@@ -141,11 +144,11 @@ void PropertyRowHeights::Restore(Base::XMLReader &reader)
reader.readEndElement("RowInfo");
}
PyObject *PropertyRowHeights::getPyObject()
PyObject* PropertyRowHeights::getPyObject()
{
if (PythonObject.is(Py::_None())){
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new PropertyRowHeightsPy(this),true);
PythonObject = Py::Object(new PropertyRowHeightsPy(this), true);
}
return Py::new_reference_to(PythonObject);
}
@@ -158,5 +161,5 @@ void PropertyRowHeights::clear()
dirty.insert(i->first);
++i;
}
std::map<int,int>::clear();
std::map<int, int>::clear();
}

View File

@@ -23,63 +23,76 @@
#ifndef PROPERTYROWHEIGHTS_H
#define PROPERTYROWHEIGHTS_H
#include <map>
#include <App/Property.h>
#include <CXX/Objects.hxx>
#include <Mod/Spreadsheet/SpreadsheetGlobal.h>
#include <map>
namespace Spreadsheet {
namespace Spreadsheet
{
class SpreadsheetExport PropertyRowHeights : public App::Property, std::map<int, int>
class SpreadsheetExport PropertyRowHeights: public App::Property, std::map<int, int>
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
PropertyRowHeights();
void setValue() { }
void setValue()
{}
void setValue(int row, int height);
void setValues(const std::map<int,int> &);
void setValues(const std::map<int, int>&);
int getValue(int row) const {
int getValue(int row) const
{
std::map<int, int>::const_iterator i = find(row);
return i != end() ? i->second : defaultHeight;
}
std::map<int, int> getValues() const {
std::map<int, int> getValues() const
{
return *this;
}
App::Property *Copy() const override;
App::Property* Copy() const override;
void Paste(const App::Property &from) override;
void Paste(const App::Property& from) override;
void Save (Base::Writer & writer) const override;
void Save(Base::Writer& writer) const override;
void Restore(Base::XMLReader & reader) override;
void Restore(Base::XMLReader& reader) override;
bool isDirty() const { return dirty.size() > 0; }
bool isDirty() const
{
return dirty.size() > 0;
}
void clearDirty() { dirty.clear(); }
void clearDirty()
{
dirty.clear();
}
const std::set<int> & getDirty() const { return dirty; }
const std::set<int>& getDirty() const
{
return dirty;
}
PyObject *getPyObject() override;
PyObject* getPyObject() override;
static const int defaultHeight;
void clear();
private:
PropertyRowHeights(const PropertyRowHeights & other);
PropertyRowHeights(const PropertyRowHeights& other);
std::set<int> dirty;
Py::Object PythonObject;
};
}
}// namespace Spreadsheet
#endif // PROPERTYROWHEIGHTS_H
#endif// PROPERTYROWHEIGHTS_H

View File

@@ -10,7 +10,6 @@
FatherInclude="Base/PersistencePy.h"
FatherNamespace="Base"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Eivind Kvedalen" EMail="eivind@kvedalen.name" />
<UserDocu>Internal spreadsheet object</UserDocu>

View File

@@ -24,8 +24,10 @@
#include "PropertyRowHeights.h"
// inclusion of the generated files (generated out of PropertyRowHeightsPy.xml)
// clang-format off
#include "PropertyRowHeightsPy.h"
#include "PropertyRowHeightsPy.cpp"
// clang-format on
using namespace Spreadsheet;
@@ -36,7 +38,7 @@ std::string PropertyRowHeightsPy::representation() const
return {"<PropertyRowHeights object>"};
}
PyObject *PropertyRowHeightsPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
PyObject* PropertyRowHeightsPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper
{
// create a new instance of PropertyRowHeightsPy and the Twin object
return new PropertyRowHeightsPy(new PropertyRowHeights);
@@ -48,7 +50,7 @@ int PropertyRowHeightsPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
return 0;
}
PyObject *PropertyRowHeightsPy::getCustomAttributes(const char* /*attr*/) const
PyObject* PropertyRowHeightsPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}

File diff suppressed because it is too large Load Diff

View File

@@ -38,80 +38,86 @@ class Sheet;
class PropertySheet;
class SheetObserver;
class SpreadsheetExport PropertySheet : public App::PropertyExpressionContainer
, private App::AtomicPropertyChangeInterface<PropertySheet> {
class SpreadsheetExport PropertySheet: public App::PropertyExpressionContainer,
private App::AtomicPropertyChangeInterface<PropertySheet>
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
explicit PropertySheet(Sheet * _owner = nullptr);
public:
explicit PropertySheet(Sheet* _owner = nullptr);
~PropertySheet() override;
std::map<App::ObjectIdentifier, const App::Expression*> getExpressions() const override;
void setExpressions(std::map<App::ObjectIdentifier, App::ExpressionPtr> &&exprs) override;
void onRelabeledDocument(const App::Document &doc) override;
void setExpressions(std::map<App::ObjectIdentifier, App::ExpressionPtr>&& exprs) override;
void onRelabeledDocument(const App::Document& doc) override;
void updateElementReference(
App::DocumentObject *feature,bool reverse=false,bool notify=false) override;
void updateElementReference(App::DocumentObject* feature,
bool reverse = false,
bool notify = false) override;
bool referenceChanged() const override;
bool adjustLink(const std::set<App::DocumentObject *> &inList) override;
Property *CopyOnImportExternal(const std::map<std::string,std::string> &nameMap) const override;
Property *CopyOnLabelChange(App::DocumentObject *obj,
const std::string &ref, const char *newLabel) const override;
Property *CopyOnLinkReplace(const App::DocumentObject *parent,
App::DocumentObject *oldObj, App::DocumentObject *newObj) const override;
void breakLink(App::DocumentObject *obj, bool clear) override;
bool adjustLink(const std::set<App::DocumentObject*>& inList) override;
Property*
CopyOnImportExternal(const std::map<std::string, std::string>& nameMap) const override;
Property* CopyOnLabelChange(App::DocumentObject* obj,
const std::string& ref,
const char* newLabel) const override;
Property* CopyOnLinkReplace(const App::DocumentObject* parent,
App::DocumentObject* oldObj,
App::DocumentObject* newObj) const override;
void breakLink(App::DocumentObject* obj, bool clear) override;
void afterRestore() override;
void onContainerRestored() override;
Property *Copy() const override;
Property* Copy() const override;
void Paste(const Property &from) override;
void Paste(const Property& from) override;
void Save (Base::Writer & writer) const override;
void Save(Base::Writer& writer) const override;
void Restore(Base::XMLReader & reader) override;
void Restore(Base::XMLReader& reader) override;
void copyCells(Base::Writer &writer, const std::vector<App::Range> &ranges) const;
void copyCells(Base::Writer& writer, const std::vector<App::Range>& ranges) const;
void pasteCells(Base::XMLReader &reader, App::Range dstRange);
void pasteCells(Base::XMLReader& reader, App::Range dstRange);
Cell *createCell(App::CellAddress address);
Cell* createCell(App::CellAddress address);
void setValue() { }
void setValue()
{}
void setContent(App::CellAddress address, const char * value);
void setContent(App::CellAddress address, const char* value);
void setAlignment(App::CellAddress address, int _alignment);
void setStyle(App::CellAddress address, const std::set<std::string> & _style);
void setStyle(App::CellAddress address, const std::set<std::string>& _style);
void setForeground(App::CellAddress address, const App::Color &color);
void setForeground(App::CellAddress address, const App::Color& color);
void setBackground(App::CellAddress address, const App::Color &color);
void setBackground(App::CellAddress address, const App::Color& color);
void setDisplayUnit(App::CellAddress address, const std::string & unit);
void setDisplayUnit(App::CellAddress address, const std::string& unit);
void setAlias(App::CellAddress address, const std::string &alias);
void setAlias(App::CellAddress address, const std::string& alias);
void setComputedUnit(App::CellAddress address, const Base::Unit & unit);
void setComputedUnit(App::CellAddress address, const Base::Unit& unit);
void setSpans(App::CellAddress address, int rows, int columns);
void clear(App::CellAddress address, bool toClearAlias=true);
void clear(App::CellAddress address, bool toClearAlias = true);
void clear();
Cell * getValue(App::CellAddress key);
Cell* getValue(App::CellAddress key);
const Cell * getValue(App::CellAddress key) const;
const Cell* getValue(App::CellAddress key) const;
Cell * getValueFromAlias(const std::string &alias);
Cell* getValueFromAlias(const std::string& alias);
const Cell * getValueFromAlias(const std::string &alias) const;
const Cell* getValueFromAlias(const std::string& alias) const;
bool isValidAlias(const std::string &candidate);
bool isValidAlias(const std::string& candidate);
std::vector<App::CellAddress> getUsedCells() const;
@@ -121,21 +127,38 @@ public:
std::tuple<App::CellAddress, App::CellAddress> getNonEmptyRange() const;
Sheet * sheet() const { return owner; }
Sheet* sheet() const
{
return owner;
}
const std::set<App::CellAddress> & getDirty() { return dirty; }
const std::set<App::CellAddress>& getDirty()
{
return dirty;
}
void setDirty(App::CellAddress address);
void setDirty();
void clearDirty(App::CellAddress key) { dirty.erase(key); }
void clearDirty(App::CellAddress key)
{
dirty.erase(key);
}
void clearDirty() { dirty.clear(); purgeTouched(); }
void clearDirty()
{
dirty.clear();
purgeTouched();
}
bool isDirty() const { return dirty.size() > 0; }
bool isDirty() const
{
return dirty.size() > 0;
}
void pasteCells(const std::map<App::CellAddress, std::string> &cells, int rowOffset, int colOffset);
void
pasteCells(const std::map<App::CellAddress, std::string>& cells, int rowOffset, int colOffset);
void insertRows(int row, int count);
@@ -149,13 +172,13 @@ public:
void removeColumns(int col, int count);
unsigned int getMemSize () const override;
unsigned int getMemSize() const override;
bool mergeCells(App::CellAddress from, App::CellAddress to);
void splitCell(App::CellAddress address);
void getSpans(App::CellAddress address, int &rows, int &cols) const;
void getSpans(App::CellAddress address, int& rows, int& cols) const;
bool hasSpan() const;
@@ -165,62 +188,65 @@ public:
bool isHidden(App::CellAddress address) const;
const std::set< App::CellAddress > & getDeps(const std::string & name) const;
const std::set<App::CellAddress>& getDeps(const std::string& name) const;
const std::set<std::string> &getDeps(App::CellAddress pos) const;
const std::set<std::string>& getDeps(App::CellAddress pos) const;
void recomputeDependencies(App::CellAddress key);
PyObject *getPyObject() override;
void setPyObject(PyObject *) override;
PyObject* getPyObject() override;
void setPyObject(PyObject*) override;
PyObject *getPyValue(PyObject *key);
PyObject* getPyValue(PyObject* key);
void invalidateDependants(const App::DocumentObject *docObj);
void invalidateDependants(const App::DocumentObject* docObj);
void renamedDocumentObject(const App::DocumentObject *docObj);
void renameObjectIdentifiers(const std::map<App::ObjectIdentifier, App::ObjectIdentifier> &paths);
void renamedDocumentObject(const App::DocumentObject* docObj);
void
renameObjectIdentifiers(const std::map<App::ObjectIdentifier, App::ObjectIdentifier>& paths);
void deletedDocumentObject(const App::DocumentObject *docObj);
void deletedDocumentObject(const App::DocumentObject* docObj);
void documentSet();
App::CellAddress getCellAddress(const char *addr, bool silent=false) const;
App::Range getRange(const char *range, bool silent=false) const;
App::CellAddress getCellAddress(const char* addr, bool silent = false) const;
App::Range getRange(const char* range, bool silent = false) const;
std::string getRow(int offset=0) const;
std::string getRow(int offset = 0) const;
std::string getColumn(int offset=0) const;
std::string getColumn(int offset = 0) const;
void setPathValue(const App::ObjectIdentifier & path, const boost::any & value) override;
const boost::any getPathValue(const App::ObjectIdentifier & path) const override;
void setPathValue(const App::ObjectIdentifier& path, const boost::any& value) override;
const boost::any getPathValue(const App::ObjectIdentifier& path) const override;
unsigned getBindingBorder(App::CellAddress address) const;
bool isBindingPath(const App::ObjectIdentifier &path,
App::CellAddress *from=nullptr, App::CellAddress *to=nullptr, bool *href=nullptr) const;
bool isBindingPath(const App::ObjectIdentifier& path,
App::CellAddress* from = nullptr,
App::CellAddress* to = nullptr,
bool* href = nullptr) const;
enum BindingType {
enum BindingType
{
BindingNone,
BindingNormal,
BindingHiddenRef,
};
BindingType getBinding(const App::Range &range,
App::ExpressionPtr *pStart=nullptr,
App::ExpressionPtr *pEnd=nullptr,
App::ObjectIdentifier *pTarget=nullptr) const;
BindingType getBinding(const App::Range& range,
App::ExpressionPtr* pStart = nullptr,
App::ExpressionPtr* pEnd = nullptr,
App::ObjectIdentifier* pTarget = nullptr) const;
protected:
void hasSetValue() override;
void hasSetChildValue(App::Property &prop) override;
void onBreakLink(App::DocumentObject *obj) override;
void onAddDep(App::DocumentObject *obj) override;
void onRemoveDep(App::DocumentObject *obj) override;
void hasSetChildValue(App::Property& prop) override;
void onBreakLink(App::DocumentObject* obj) override;
void onAddDep(App::DocumentObject* obj) override;
void onRemoveDep(App::DocumentObject* obj) override;
private:
PropertySheet(const PropertySheet & other);
PropertySheet& operator= (const PropertySheet&);
PropertySheet(const PropertySheet& other);
PropertySheet& operator=(const PropertySheet&);
/* friends */
@@ -232,15 +258,15 @@ private:
friend class Sheet;
Cell *cellAt(App::CellAddress address);
Cell* cellAt(App::CellAddress address);
Cell *nonNullCellAt(App::CellAddress address);
Cell* nonNullCellAt(App::CellAddress address);
const Cell *cellAt(App::CellAddress address) const;
const Cell* cellAt(App::CellAddress address) const;
bool colSortFunc(const App::CellAddress &a, const App::CellAddress &b);
bool colSortFunc(const App::CellAddress& a, const App::CellAddress& b);
bool rowSortFunc(const App::CellAddress &a, const App::CellAddress &b);
bool rowSortFunc(const App::CellAddress& a, const App::CellAddress& b);
/*! Set of cells that have been marked dirty */
std::set<App::CellAddress> dirty;
@@ -252,13 +278,15 @@ private:
std::map<App::CellAddress, App::CellAddress> mergedCells;
/*! Owner of this property */
Sheet * owner;
Sheet* owner;
void clearAlias(App::CellAddress address);
void moveAlias(App::CellAddress currPos, App::CellAddress newPos);
void moveCell(App::CellAddress currPos, App::CellAddress newPos, std::map<App::ObjectIdentifier, App::ObjectIdentifier> &renames);
void moveCell(App::CellAddress currPos,
App::CellAddress newPos,
std::map<App::ObjectIdentifier, App::ObjectIdentifier>& renames);
/*
* Cell dependency tracking
@@ -268,24 +296,24 @@ private:
void removeDependencies(App::CellAddress key);
void slotChangedObject(const App::DocumentObject &obj, const App::Property &prop);
void recomputeDependants(const App::DocumentObject *obj, const char *propName);
void slotChangedObject(const App::DocumentObject& obj, const App::Property& prop);
void recomputeDependants(const App::DocumentObject* obj, const char* propName);
/*! Cell dependencies, i.e when a change occurs to property given in key,
the set of addresses needs to be recomputed.
*/
std::map<std::string, std::set< App::CellAddress > > propertyNameToCellMap;
std::map<std::string, std::set<App::CellAddress>> propertyNameToCellMap;
/*! Properties this cell depends on */
std::map<App::CellAddress, std::set< std::string > > cellToPropertyNameMap;
std::map<App::CellAddress, std::set<std::string>> cellToPropertyNameMap;
/*! Cell dependencies, i.e when a change occurs to documentObject given in key,
the set of addresses needs to be recomputed.
*/
std::map<std::string, std::set< App::CellAddress > > documentObjectToCellMap;
std::map<std::string, std::set<App::CellAddress>> documentObjectToCellMap;
/*! DocumentObject this cell depends on */
std::map<App::CellAddress, std::set< std::string > > cellToDocumentObjectMap;
std::map<App::CellAddress, std::set<std::string>> cellToDocumentObjectMap;
/*! Mapping of cell position to alias property */
std::map<App::CellAddress, std::string> aliasProp;
@@ -302,5 +330,5 @@ private:
bool restoring = false;
};
}
#endif // PROPERTYSHEET_H
}// namespace Spreadsheet
#endif// PROPERTYSHEET_H

View File

@@ -10,7 +10,6 @@
FatherInclude="Base/PersistencePy.h"
FatherNamespace="Base"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Eivind Kvedalen" EMail="eivind@kvedalen.name" />
<UserDocu>Internal spreadsheet object</UserDocu>

View File

@@ -24,8 +24,10 @@
#include "PropertySheet.h"
// inclusion of the generated files (generated out of PropertySheetPy.xml)
// clang-format off
#include "PropertySheetPy.h"
#include "PropertySheetPy.cpp"
// clang-format on
using namespace Spreadsheet;
@@ -36,7 +38,7 @@ std::string PropertySheetPy::representation() const
return {"<PropertySheet object>"};
}
PyObject *PropertySheetPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
PyObject* PropertySheetPy::PyMake(struct _typeobject*, PyObject*, PyObject*)// Python wrapper
{
// create a new instance of PropertySheetPy and the Twin object
return new PropertySheetPy(new PropertySheet);
@@ -48,12 +50,12 @@ int PropertySheetPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
return 0;
}
PyObject * PropertySheetPy::mapping_subscript(PyObject * o, PyObject *key)
PyObject* PropertySheetPy::mapping_subscript(PyObject* o, PyObject* key)
{
return static_cast<PropertySheetPy*>(o)->getPropertySheetPtr()->getPyValue(key);
}
PyObject *PropertySheetPy::getCustomAttributes(const char* /*attr*/) const
PyObject* PropertySheetPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}

File diff suppressed because it is too large Load Diff

View File

@@ -24,8 +24,8 @@
#define Spreadsheet_Spreadsheet_H
#ifdef signals
# undef signals
# define signals signals
#undef signals
#define signals signals
#endif
#include <map>
@@ -54,47 +54,55 @@ class SheetObserver;
* Copy() and Paste() methods. It is used by the spreadsheet to
* create aliases in a generic way.
*/
class SpreadsheetExport PropertySpreadsheetQuantity : public App::PropertyQuantity
class SpreadsheetExport PropertySpreadsheetQuantity: public App::PropertyQuantity
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
PropertySpreadsheetQuantity() = default;
~PropertySpreadsheetQuantity() override = default;
Property *Copy() const override;
void Paste(const Property &from) override;
Property* Copy() const override;
void Paste(const Property& from) override;
};
class SpreadsheetExport Sheet : public App::DocumentObject
class SpreadsheetExport Sheet: public App::DocumentObject
{
PROPERTY_HEADER_WITH_OVERRIDE(Spreadsheet::Sheet);
public:
/// Constructor
Sheet();
~Sheet() override;
/// returns the type name of the ViewProvider
const char* getViewProviderName() const override {
const char* getViewProviderName() const override
{
return "SpreadsheetGui::ViewProviderSheet";
}
bool importFromFile(const std::string & filename, char delimiter = '\t', char quoteChar = '\0', char escapeChar = '\\');
bool importFromFile(const std::string& filename,
char delimiter = '\t',
char quoteChar = '\0',
char escapeChar = '\\');
bool getCharsFromPrefs(char &delimiter, char &quote, char &escape, std::string &errMsg);
bool getCharsFromPrefs(char& delimiter, char& quote, char& escape, std::string& errMsg);
bool exportToFile(const std::string & filename, char delimiter = '\t', char quoteChar = '\0', char escapeChar = '\\') const;
bool exportToFile(const std::string& filename,
char delimiter = '\t',
char quoteChar = '\0',
char escapeChar = '\\') const;
bool mergeCells(const App::Range &range);
bool mergeCells(const App::Range& range);
void splitCell(App::CellAddress address);
Cell * getCell(App::CellAddress address);
Cell* getCell(App::CellAddress address);
Cell *getNewCell(App::CellAddress address);
Cell* getNewCell(App::CellAddress address);
enum Border {
enum Border
{
BorderTop = 1,
BorderLeft = 2,
BorderBottom = 4,
@@ -103,20 +111,20 @@ public:
};
unsigned getCellBindingBorder(App::CellAddress address) const;
PropertySheet::BindingType getCellBinding(App::Range &range,
App::ExpressionPtr *pStart=nullptr,
App::ExpressionPtr *pEnd=nullptr,
App::ObjectIdentifier *pTarget=nullptr) const;
PropertySheet::BindingType getCellBinding(App::Range& range,
App::ExpressionPtr* pStart = nullptr,
App::ExpressionPtr* pEnd = nullptr,
App::ObjectIdentifier* pTarget = nullptr) const;
void setCell(const char *address, const char *value);
void setCell(const char* address, const char* value);
void setCell(App::CellAddress address, const char *value);
void setCell(App::CellAddress address, const char* value);
void clearAll();
void clear(App::CellAddress address, bool all = true);
void getSpans(App::CellAddress address, int & rows, int & cols) const;
void getSpans(App::CellAddress address, int& rows, int& cols) const;
bool isMergedCell(App::CellAddress address) const;
@@ -140,60 +148,64 @@ public:
void removeRows(int row, int count);
void setContent(App::CellAddress address, const char * value);
void setContent(App::CellAddress address, const char* value);
void setAlignment(App::CellAddress address, int alignment);
void setStyle(App::CellAddress address, const std::set<std::string> & style);
void setStyle(App::CellAddress address, const std::set<std::string>& style);
void setForeground(App::CellAddress address, const App::Color &color);
void setForeground(App::CellAddress address, const App::Color& color);
void setBackground(App::CellAddress address, const App::Color &color);
void setBackground(App::CellAddress address, const App::Color& color);
void setDisplayUnit(App::CellAddress address, const std::string & unit);
void setDisplayUnit(App::CellAddress address, const std::string& unit);
void setComputedUnit(App::CellAddress address, const Base::Unit & unit);
void setComputedUnit(App::CellAddress address, const Base::Unit& unit);
void setAlias(App::CellAddress address, const std::string & alias);
void setAlias(App::CellAddress address, const std::string& alias);
std::string getAddressFromAlias(const std::string & alias) const;
std::string getAddressFromAlias(const std::string& alias) const;
bool isValidAlias(const std::string &candidate);
bool isValidAlias(const std::string& candidate);
void setSpans(App::CellAddress address, int rows, int columns);
std::set<std::string> dependsOn(App::CellAddress address) const;
void providesTo(App::CellAddress address, std::set<std::string> & result) const;
void providesTo(App::CellAddress address, std::set<std::string>& result) const;
bool hasCell(const std::vector<App::Range> &ranges) const;
PyObject *getPyObject() override;
bool hasCell(const std::vector<App::Range>& ranges) const;
PyObject* getPyObject() override;
PropertySheet *getCells() { return &cells; }
PropertySheet* getCells()
{
return &cells;
}
App::Property *getPropertyByName(const char *name) const override;
App::Property* getPropertyByName(const char* name) const override;
App::Property *getDynamicPropertyByName(const char* name) const override;
App::Property* getDynamicPropertyByName(const char* name) const override;
void getPropertyNamedList(std::vector<std::pair<const char*,App::Property*> > &List) const override;
void
getPropertyNamedList(std::vector<std::pair<const char*, App::Property*>>& List) const override;
short mustExecute() const override;
App::DocumentObjectExecReturn *execute() override;
App::DocumentObjectExecReturn* execute() override;
bool getCellAddress(const App::Property *prop, App::CellAddress &address);
bool getCellAddress(const App::Property* prop, App::CellAddress& address);
App::CellAddress getCellAddress(const char *name, bool silent=false) const;
App::CellAddress getCellAddress(const char* name, bool silent = false) const;
App::Range getRange(const char *name, bool silent=false) const;
App::Range getRange(const char* name, bool silent = false) const;
std::map<int, int> getColumnWidths() const;
std::map<int, int> getRowHeights() const;
std::string getRow(int offset=0) const;
std::string getRow(int offset = 0) const;
std::string getColumn(int offset=0) const;
std::string getColumn(int offset = 0) const;
void touchCells(App::Range range);
@@ -201,29 +213,29 @@ public:
// Signals
boost::signals2::signal<void (App::CellAddress)> cellUpdated;
boost::signals2::signal<void(App::CellAddress)> cellUpdated;
boost::signals2::signal<void (App::Range)> rangeUpdated;
boost::signals2::signal<void(App::Range)> rangeUpdated;
boost::signals2::signal<void (App::CellAddress)> cellSpanChanged;
boost::signals2::signal<void(App::CellAddress)> cellSpanChanged;
boost::signals2::signal<void (int, int)> columnWidthChanged;
boost::signals2::signal<void(int, int)> columnWidthChanged;
boost::signals2::signal<void (int, int)> rowHeightChanged;
boost::signals2::signal<void(int, int)> rowHeightChanged;
void observeDocument(App::Document *document);
void observeDocument(App::Document* document);
void renameObjectIdentifiers(const std::map<App::ObjectIdentifier, App::ObjectIdentifier> & paths) override;
void renameObjectIdentifiers(
const std::map<App::ObjectIdentifier, App::ObjectIdentifier>& paths) override;
void setCopyOrCutRanges(const std::vector<App::Range> &ranges, bool copy=true);
const std::vector<App::Range> &getCopyOrCutRange(bool copy=true) const;
unsigned getCopyOrCutBorder(App::CellAddress address, bool copy=true) const;
void setCopyOrCutRanges(const std::vector<App::Range>& ranges, bool copy = true);
const std::vector<App::Range>& getCopyOrCutRange(bool copy = true) const;
unsigned getCopyOrCutBorder(App::CellAddress address, bool copy = true) const;
protected:
void onChanged(const App::Property* prop) override;
void onChanged(const App::Property *prop) override;
void updateColumnsOrRows(bool horizontal, int section, int count) ;
void updateColumnsOrRows(bool horizontal, int section, int count);
std::set<App::CellAddress> providesTo(App::CellAddress address) const;
@@ -231,31 +243,31 @@ protected:
void recomputeCell(App::CellAddress p);
App::Property *getProperty(App::CellAddress key) const;
App::Property* getProperty(App::CellAddress key) const;
App::Property *getProperty(const char * addr) const;
App::Property* getProperty(const char* addr) const;
void updateProperty(App::CellAddress key);
App::Property *setStringProperty(App::CellAddress key, const std::string & value) ;
App::Property* setStringProperty(App::CellAddress key, const std::string& value);
App::Property *setObjectProperty(App::CellAddress key, Py::Object obj) ;
App::Property* setObjectProperty(App::CellAddress key, Py::Object obj);
App::Property *setFloatProperty(App::CellAddress key, double value);
App::Property* setFloatProperty(App::CellAddress key, double value);
App::Property *setIntegerProperty(App::CellAddress key, long value);
App::Property* setIntegerProperty(App::CellAddress key, long value);
App::Property *setQuantityProperty(App::CellAddress key, double value, const Base::Unit &unit);
App::Property* setQuantityProperty(App::CellAddress key, double value, const Base::Unit& unit);
void onSettingDocument() override;
void updateBindings();
/* Properties for used cells */
App::DynamicProperty &props;
App::DynamicProperty& props;
/* Mapping of properties to cell position */
std::map<const App::Property*, App::CellAddress > propAddress;
std::map<const App::Property*, App::CellAddress> propAddress;
/* Set of cells with errors */
std::set<App::CellAddress> cellErrors;
@@ -272,7 +284,7 @@ protected:
PropertyRowHeights rowHeights;
/* Document observers to track changes to external properties */
using ObserverMap = std::map<std::string, SheetObserver* >;
using ObserverMap = std::map<std::string, SheetObserver*>;
ObserverMap observers;
int currentRow = -1;
@@ -290,7 +302,7 @@ protected:
using SheetPython = App::FeaturePythonT<Sheet>;
} //namespace Spreadsheet
}// namespace Spreadsheet
#endif // Spreadsheet_Spreadsheet_H
#endif// Spreadsheet_Spreadsheet_H

View File

@@ -22,76 +22,78 @@
#include "PreCompiled.h"
#include "SheetObserver.h"
#include "PropertySheet.h"
#include "SheetObserver.h"
using namespace Spreadsheet;
using namespace App;
/**
* The SheetObserver constructor.
*
* @param document The Document we are observing
* @param _sheet The sheet owning this observer.
*
*/
* The SheetObserver constructor.
*
* @param document The Document we are observing
* @param _sheet The sheet owning this observer.
*
*/
SheetObserver::SheetObserver(App::Document * document, PropertySheet *_sheet)
SheetObserver::SheetObserver(App::Document* document, PropertySheet* _sheet)
: DocumentObserver(document)
, sheet(_sheet)
{
}
{}
/**
* Invalidate cells that depend on this document object.
*
*/
* Invalidate cells that depend on this document object.
*
*/
void SheetObserver::slotCreatedObject(const DocumentObject &Obj)
void SheetObserver::slotCreatedObject(const DocumentObject& Obj)
{
sheet->invalidateDependants(&Obj);
}
/**
* Invalidate cells that depend on this document object.
*
*/
* Invalidate cells that depend on this document object.
*
*/
void SheetObserver::slotDeletedObject(const DocumentObject &Obj)
void SheetObserver::slotDeletedObject(const DocumentObject& Obj)
{
sheet->invalidateDependants(&Obj);
sheet->deletedDocumentObject(&Obj);
}
/**
* Invoke the sheets recomputeDependants when a change to a Property occurs.
*
*/
* Invoke the sheets recomputeDependants when a change to a Property occurs.
*
*/
void SheetObserver::slotChangedObject(const DocumentObject &Obj, const Property &Prop)
void SheetObserver::slotChangedObject(const DocumentObject& Obj, const Property& Prop)
{
if (&Prop == &Obj.Label)
if (&Prop == &Obj.Label) {
sheet->renamedDocumentObject(&Obj);
}
else {
const char * name = Obj.getPropertyName(&Prop);
const char* name = Obj.getPropertyName(&Prop);
if (!name)
if (!name) {
return;
}
if (isUpdating.find(name) != isUpdating.end())
if (isUpdating.find(name) != isUpdating.end()) {
return;
}
isUpdating.insert(name);
sheet->recomputeDependants(&Obj,Prop.getName());
sheet->recomputeDependants(&Obj, Prop.getName());
isUpdating.erase(name);
}
}
/**
* Increase reference count.
*
*/
* Increase reference count.
*
*/
void SheetObserver::ref()
{
@@ -99,13 +101,12 @@ void SheetObserver::ref()
}
/**
* Decrease reference count.
*
*/
* Decrease reference count.
*
*/
bool SheetObserver::unref()
{
refCount--;
return refCount;
}

View File

@@ -25,27 +25,33 @@
#include <App/DocumentObserver.h>
namespace Spreadsheet {
namespace Spreadsheet
{
class PropertySheet;
// SheetObserver is obsolete as PropertySheet is now derived from PropertyLinkBase
class SheetObserver : public App::DocumentObserver {
class SheetObserver: public App::DocumentObserver
{
public:
SheetObserver(App::Document* document, PropertySheet *_sheet);
SheetObserver(App::Document* document, PropertySheet* _sheet);
~SheetObserver() override = default;
void slotCreatedObject(const App::DocumentObject& Obj) override;
void slotDeletedObject(const App::DocumentObject& Obj) override;
void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) override;
void ref();
bool unref();
App::Document* getDocument() const { return App::DocumentObserver::getDocument(); }
App::Document* getDocument() const
{
return App::DocumentObserver::getDocument();
}
private:
std::set<std::string> isUpdating;
unsigned int refCount{1};
PropertySheet * sheet;
unsigned int refCount {1};
PropertySheet* sheet;
};
}
}// namespace Spreadsheet
#endif // SHEETOBSERVER_H
#endif// SHEETOBSERVER_H

View File

@@ -10,7 +10,6 @@
FatherInclude="App/DocumentObjectPy.h"
FatherNamespace="App"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Eivind Kvedalen" EMail="eivind@kvedalen.name" />
<UserDocu>With this object you can manipulate spreadsheets</UserDocu>
@@ -180,7 +179,7 @@ following dependency order.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getUsedCells">
<Documentation>
<UserDocu>
@@ -191,7 +190,7 @@ or may not have a non-empty string content.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getNonEmptyCells">
<Documentation>
<UserDocu>
@@ -201,7 +200,7 @@ Get a list of the names of all cells with data in them.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getUsedRange">
<Documentation>
<UserDocu>
@@ -214,7 +213,7 @@ of the block are not necessarily used.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getNonEmptyRange">
<Documentation>
<UserDocu>
@@ -227,6 +226,6 @@ of the block do not necessarily contain anything.
</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

File diff suppressed because it is too large Load Diff

View File

@@ -23,42 +23,45 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
#include <sstream>
#endif
#include "Utils.h"
#include "Sheet.h"
#include "Utils.h"
/**
* Encode \a col as a string.
*
* @param col Column given as a 0-based column position.
*
* @returns String with column position, with "A" being the first column, "B" being the second and so on.
*
*/
* Encode \a col as a string.
*
* @param col Column given as a 0-based column position.
*
* @returns String with column position, with "A" being the first column, "B" being the second and
* so on.
*
*/
std::string Spreadsheet::columnName(int col)
{
std::stringstream s;
if (col < 26)
if (col < 26) {
s << ((char)('A' + col));
else
s << ((char)('A' + (col - 26) / 26 )) << ((char)('A' + (col - 26) % 26));
}
else {
s << ((char)('A' + (col - 26) / 26)) << ((char)('A' + (col - 26) % 26));
}
return s.str();
}
/**
* Encode \a row as a string.
*
* @param row Row given as a 0-based row position.
*
* @returns String with row position, with "1" being the first row.
*
*/
* Encode \a row as a string.
*
* @param row Row given as a 0-based row position.
*
* @returns String with row position, with "1" being the first row.
*
*/
std::string Spreadsheet::rowName(int row)
{
@@ -70,7 +73,8 @@ std::string Spreadsheet::rowName(int row)
}
void Spreadsheet::createRectangles(std::set<std::pair<int, int> > & cells, std::map<std::pair<int, int>, std::pair<int, int> > & rectangles)
void Spreadsheet::createRectangles(std::set<std::pair<int, int>>& cells,
std::map<std::pair<int, int>, std::pair<int, int>>& rectangles)
{
while (!cells.empty()) {
int row, col;
@@ -82,8 +86,9 @@ void Spreadsheet::createRectangles(std::set<std::pair<int, int> > & cells, std::
col = (*cells.begin()).second;
// Expand right first
while (cells.find(std::make_pair(row, col + cols)) != cells.end())
while (cells.find(std::make_pair(row, col + cols)) != cells.end()) {
++cols;
}
// Expand left
while (cells.find(std::make_pair(row, col + cols)) != cells.end()) {
@@ -91,11 +96,12 @@ void Spreadsheet::createRectangles(std::set<std::pair<int, int> > & cells, std::
++cols;
}
// Try to expand cell up (the complete row above from [col,col + cols> needs to be in the cells variable)
// Try to expand cell up (the complete row above from [col,col + cols> needs to be in the
// cells variable)
bool ok = true;
while (ok) {
for (int i = col; i < col + cols; ++i) {
if ( cells.find(std::make_pair(row - 1, i)) == cells.end()) {
if (cells.find(std::make_pair(row - 1, i)) == cells.end()) {
ok = false;
break;
}
@@ -105,17 +111,19 @@ void Spreadsheet::createRectangles(std::set<std::pair<int, int> > & cells, std::
row--;
rows++;
}
else
else {
break;
}
}
// Try to expand down (the complete row below from [col,col + cols> needs to be in the cells variable)
// Try to expand down (the complete row below from [col,col + cols> needs to be in the cells
// variable)
ok = true;
while (ok) {
for (int i = col; i < col + cols; ++i) {
if ( cells.find(std::make_pair(orgRow + 1, i)) == cells.end()) {
ok = false;
break;
if (cells.find(std::make_pair(orgRow + 1, i)) == cells.end()) {
ok = false;
break;
}
}
if (ok) {
@@ -123,21 +131,24 @@ void Spreadsheet::createRectangles(std::set<std::pair<int, int> > & cells, std::
orgRow++;
rows++;
}
else
else {
break;
}
}
// Remove entries from cell set for this rectangle
for (int r = row; r < row + rows; ++r)
for (int c = col; c < col + cols; ++c)
for (int r = row; r < row + rows; ++r) {
for (int c = col; c < col + cols; ++c) {
cells.erase(std::make_pair(r, c));
}
}
// Insert into output variable
rectangles[std::make_pair(row, col)] = std::make_pair(rows, cols);
}
}
std::string Spreadsheet::quote(const std::string &input)
std::string Spreadsheet::quote(const std::string& input)
{
std::stringstream output;
@@ -147,29 +158,29 @@ std::string Spreadsheet::quote(const std::string &input)
output << "<<";
while (cur != end) {
switch (*cur) {
case '\t':
output << "\\t";
break;
case '\n':
output << "\\n";
break;
case '\r':
output << "\\r";
break;
case '\\':
output << "\\\\";
break;
case '\'':
output << "\\'";
break;
case '"':
output << "\\\"";
break;
case '>':
output << "\\>";
break;
default:
output << *cur;
case '\t':
output << "\\t";
break;
case '\n':
output << "\\n";
break;
case '\r':
output << "\\r";
break;
case '\\':
output << "\\\\";
break;
case '\'':
output << "\\'";
break;
case '"':
output << "\\\"";
break;
case '>':
output << "\\>";
break;
default:
output << *cur;
}
++cur;
}
@@ -178,7 +189,7 @@ std::string Spreadsheet::quote(const std::string &input)
return output.str();
}
std::string Spreadsheet::unquote(const std::string & input)
std::string Spreadsheet::unquote(const std::string& input)
{
assert(input.size() >= 4);
@@ -192,32 +203,34 @@ std::string Spreadsheet::unquote(const std::string & input)
while (cur != end) {
if (escaped) {
switch (*cur) {
case 't':
output += '\t';
break;
case 'n':
output += '\n';
break;
case 'r':
output += '\r';
break;
case '\\':
output += '\\';
break;
case '\'':
output += '\'';
break;
case '"':
output += '"';
break;
case 't':
output += '\t';
break;
case 'n':
output += '\n';
break;
case 'r':
output += '\r';
break;
case '\\':
output += '\\';
break;
case '\'':
output += '\'';
break;
case '"':
output += '"';
break;
}
escaped = false;
}
else {
if (*cur == '\\')
if (*cur == '\\') {
escaped = true;
else
}
else {
output += *cur;
}
}
++cur;
}

View File

@@ -31,15 +31,18 @@
#include <Mod/Spreadsheet/SpreadsheetGlobal.h>
namespace Spreadsheet {
namespace Spreadsheet
{
SpreadsheetExport std::string columnName(int col);
SpreadsheetExport std::string rowName(int row);
SpreadsheetExport void createRectangles(std::set<std::pair<int, int> > & cells, std::map<std::pair<int, int>, std::pair<int, int> > & rectangles);
SpreadsheetExport std::string quote(const std::string &input);
SpreadsheetExport std::string unquote(const std::string & input);
SpreadsheetExport void
createRectangles(std::set<std::pair<int, int>>& cells,
std::map<std::pair<int, int>, std::pair<int, int>>& rectangles);
SpreadsheetExport std::string quote(const std::string& input);
SpreadsheetExport std::string unquote(const std::string& input);
}
}// namespace Spreadsheet
#endif // UTILS_H
#endif// UTILS_H