Skip to content

Commit

Permalink
- Self-reference bug
Browse files Browse the repository at this point in the history
- Refactoring/clean-up of code
- Dependency tracking of aliased cells
- Various resolution errors
- Rewriting of ranges when columns/rows are inserted/removed
- References to aliases keep their units.
  • Loading branch information
eivindkv authored and wwmayer committed Mar 4, 2015
1 parent 1b7c0e2 commit 3743008
Show file tree
Hide file tree
Showing 20 changed files with 382 additions and 178 deletions.
1 change: 1 addition & 0 deletions src/Mod/Spreadsheet/App/AppSpreadsheet.cpp
Expand Up @@ -31,6 +31,7 @@ void SpreadsheetExport initSpreadsheet() {
(void) Py_InitModule("Spreadsheet", Spreadsheet_methods); /* mod name, table ptr */
Base::Console().Log("Loading Spreadsheet module... done\n");

Spreadsheet::PropertySpreadsheetQuantity::init();
Spreadsheet::PropertyColumnWidths::init();
Spreadsheet::PropertyRowHeights::init();
Spreadsheet::PropertySheet::init();
Expand Down
16 changes: 14 additions & 2 deletions src/Mod/Spreadsheet/App/Cell.cpp
Expand Up @@ -395,8 +395,20 @@ void Cell::setAlias(const std::string &n)
if (alias != n) {
PropertySheet::Signaller signaller(*owner);

owner->revAliasProp.erase(alias);

alias = n;

// Update owner
if (alias != "") {
owner->aliasProp[address] = n;
owner->revAliasProp[n] = address;
}
else
owner->aliasProp.erase(address);

setUsed(ALIAS_SET, !alias.empty());

}
}

Expand Down Expand Up @@ -590,7 +602,7 @@ void Cell::save(Base::Writer &writer) const

writer.Stream() << writer.ind() << "<Cell ";

writer.Stream() << "address=\"" << addressToString(address) << "\" ";
writer.Stream() << "address=\"" << address.toString() << "\" ";

if (isUsed(EXPRESSION_SET)) {
std::string content;
Expand Down Expand Up @@ -663,7 +675,7 @@ bool Cell::isUsed() const
void Cell::visit(ExpressionVisitor &v)
{
if (expression)
v.visit(expression);
expression->visit(v);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Spreadsheet/App/Cell.h
Expand Up @@ -116,6 +116,8 @@ class SpreadsheetExport Cell {

void visit(ExpressionVisitor & v);

CellAddress getAddress() const { return address; }

/* Alignment */
static const int ALIGNMENT_LEFT;
static const int ALIGNMENT_HCENTER;
Expand Down
19 changes: 17 additions & 2 deletions src/Mod/Spreadsheet/App/Expression.cpp
Expand Up @@ -176,7 +176,7 @@ std::string Path::getPythonAccessor() const
const Property * prop = getProperty();

if (!prop)
throw Exception("Property not found");
throw Exception(std::string("Property '") + getPropertyName() + std::string("' not found."));

const DocumentObject * docObj = freecad_dynamic_cast<DocumentObject>(prop->getContainer());

Expand Down Expand Up @@ -1309,6 +1309,16 @@ Document * Path::getDocument() const
return doc;
}

const DocumentObject *Path::getDocumentObject() const
{
const App::Document * doc = getDocument();

if (!doc)
return 0;

return getDocumentObject(doc, documentObjectName);
}

const Property *Path::getProperty() const
{
const App::Document * doc = getDocument();
Expand Down Expand Up @@ -1346,7 +1356,7 @@ const Property * VariableExpression::getProperty() const
if (prop)
return prop;
else
throw Base::Exception("Property not found.");
throw Base::Exception(std::string("Property '") + var.getPropertyName() + std::string("' not found."));
}

/**
Expand Down Expand Up @@ -1785,6 +1795,11 @@ Expression *RangeExpression::simplify() const
return copy();
}

void RangeExpression::setRange(const Range &r)
{
range = r;
}

}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Spreadsheet/App/Expression.h
Expand Up @@ -158,6 +158,8 @@ class SpreadsheetExport Path {

App::Document *getDocument() const;

const App::DocumentObject *getDocumentObject() const;

protected:

const App::DocumentObject *getDocumentObject(const App::Document *doc, const std::string &name) const;
Expand Down Expand Up @@ -367,6 +369,8 @@ class SpreadsheetExport RangeExpression : public Expression {

Range getRange() const { return range; }

void setRange(const Range & r);

protected:
Range range;
};
Expand Down
11 changes: 11 additions & 0 deletions src/Mod/Spreadsheet/App/PropertyColumnWidths.cpp
Expand Up @@ -155,3 +155,14 @@ PyObject *PropertyColumnWidths::getPyObject()
}
return Py::new_reference_to(PythonObject);
}

void PropertyColumnWidths::clear()
{
std::map<int, int>::const_iterator i = begin();

while (i != end()) {
dirty.insert(i->first);
++i;
}
std::map<int,int>::clear();
}
6 changes: 4 additions & 2 deletions src/Mod/Spreadsheet/App/PropertyColumnWidths.h
Expand Up @@ -35,8 +35,6 @@ class SpreadsheetExport PropertyColumnWidths : public App::Property, std::map<in
public:
PropertyColumnWidths();

PropertyColumnWidths(const PropertyColumnWidths & other);

void setValue() { }

void setValue(int col, int width);
Expand Down Expand Up @@ -66,11 +64,15 @@ class SpreadsheetExport PropertyColumnWidths : public App::Property, std::map<in

PyObject *getPyObject(void);

void clear();

static const int defaultWidth;
static const int defaultHeaderWidth;

private:

PropertyColumnWidths(const PropertyColumnWidths & other);

std::set<int> dirty;

Py::Object PythonObject;
Expand Down
11 changes: 11 additions & 0 deletions src/Mod/Spreadsheet/App/PropertyRowHeights.cpp
Expand Up @@ -148,3 +148,14 @@ PyObject *PropertyRowHeights::getPyObject()
}
return Py::new_reference_to(PythonObject);
}

void PropertyRowHeights::clear()
{
std::map<int, int>::const_iterator i = begin();

while (i != end()) {
dirty.insert(i->first);
++i;
}
std::map<int,int>::clear();
}
6 changes: 4 additions & 2 deletions src/Mod/Spreadsheet/App/PropertyRowHeights.h
Expand Up @@ -35,8 +35,6 @@ class SpreadsheetExport PropertyRowHeights : public App::Property, std::map<int,
public:
PropertyRowHeights();

PropertyRowHeights(const PropertyRowHeights & other);

void setValue() { }

void setValue(int row, int height);
Expand Down Expand Up @@ -68,8 +66,12 @@ class SpreadsheetExport PropertyRowHeights : public App::Property, std::map<int,

static const int defaultHeight;

void clear();

private:

PropertyRowHeights(const PropertyRowHeights & other);

std::set<int> dirty;

Py::Object PythonObject;
Expand Down

0 comments on commit 3743008

Please sign in to comment.