| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <App/Range.h> |
| | #include <Base/Reader.h> |
| | #include <Base/Writer.h> |
| |
|
| | #include "PropertyColumnWidths.h" |
| | #include "PropertyColumnWidthsPy.h" |
| | #include "Utils.h" |
| |
|
| |
|
| | using namespace Spreadsheet; |
| |
|
| | const int PropertyColumnWidths::defaultWidth = 100; |
| | const int PropertyColumnWidths::defaultHeaderWidth = 50; |
| |
|
| | TYPESYSTEM_SOURCE(Spreadsheet::PropertyColumnWidths, App::Property) |
| |
|
| | PropertyColumnWidths::PropertyColumnWidths() = default; |
| |
|
| | PropertyColumnWidths::PropertyColumnWidths(const PropertyColumnWidths& other) |
| | : Property() |
| | , std::map<int, int>(other) |
| | { |
| | std::map<int, int>::const_iterator i = other.begin(); |
| |
|
| | while (i != other.end()) { |
| | insert(*i); |
| | ++i; |
| | } |
| | } |
| |
|
| | App::Property* PropertyColumnWidths::Copy() const |
| | { |
| | PropertyColumnWidths* prop = new PropertyColumnWidths(*this); |
| |
|
| | return prop; |
| | } |
| |
|
| | void PropertyColumnWidths::Paste(const App::Property& from) |
| | { |
| | setValues(dynamic_cast<const PropertyColumnWidths&>(from).getValues()); |
| | } |
| |
|
| | void PropertyColumnWidths::setValues(const std::map<int, int>& values) |
| | { |
| | aboutToSetValue(); |
| |
|
| | std::map<int, int>::const_iterator i; |
| |
|
| | |
| | i = begin(); |
| | while (i != end()) { |
| | dirty.insert(i->first); |
| | ++i; |
| | } |
| |
|
| | |
| | clear(); |
| |
|
| | |
| | i = values.begin(); |
| | while (i != values.end()) { |
| | insert(*i); |
| | dirty.insert(i->first); |
| | ++i; |
| | } |
| | hasSetValue(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | void PropertyColumnWidths::setValue(int col, int width) |
| | { |
| | if (width >= 0) { |
| | aboutToSetValue(); |
| | operator[](col) = width; |
| | dirty.insert(col); |
| | hasSetValue(); |
| | } |
| | } |
| |
|
| | void PropertyColumnWidths::Save(Base::Writer& writer) const |
| | { |
| | |
| | writer.Stream() << writer.ind() << "<ColumnInfo Count=\"" << size() << "\">" << std::endl; |
| | writer.incInd(); |
| | 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; |
| | ++coli; |
| | } |
| | writer.decInd(); |
| | writer.Stream() << writer.ind() << "</ColumnInfo>" << std::endl; |
| | } |
| |
|
| | void PropertyColumnWidths::Restore(Base::XMLReader& reader) |
| | { |
| | int Cnt; |
| |
|
| | |
| | reader.readElement("ColumnInfo"); |
| | Cnt = reader.hasAttribute("Count") ? reader.getAttribute<long>("Count") : 0; |
| | for (int i = 0; i < Cnt; i++) { |
| | reader.readElement("Column"); |
| | const char* name = reader.hasAttribute("name") ? reader.getAttribute<const char*>("name") |
| | : nullptr; |
| | const char* width = reader.hasAttribute("width") ? reader.getAttribute<const char*>("width") |
| | : nullptr; |
| |
|
| | try { |
| | if (name && width) { |
| | int col = App::decodeColumn(name); |
| | int colWidth = atoi(width); |
| |
|
| | setValue(col, colWidth); |
| | } |
| | } |
| | catch (...) { |
| | |
| | } |
| | } |
| | reader.readEndElement("ColumnInfo"); |
| | } |
| |
|
| | PyObject* PropertyColumnWidths::getPyObject() |
| | { |
| | if (PythonObject.is(Py::_None())) { |
| | |
| | PythonObject = Py::Object(new PropertyColumnWidthsPy(this), true); |
| | } |
| | 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(); |
| | } |
| |
|