[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/filters/kspread/excel
From: Marijn Kruisselbrink <m.kruisselbrink () student ! tue ! nl>
Date: 2010-07-25 6:41:13
Message-ID: 20100725064113.0A590AC7E2 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1154315 by mkruisselbrink:
change a bit the way some things are stored in memory, this improves memory usage for \
loading a certain file from 300MB to 200MB on a 64-bit system.
M +8 -2 import/CMakeLists.txt
M +5 -4 import/excelimport.cc
M +1 -0 sidewinder/CMakeLists.txt
M +14 -46 sidewinder/cell.cpp
M +27 -8 sidewinder/cell.h
M +1 -0 sidewinder/excel.cpp
M +86 -0 sidewinder/sheet.cpp
M +15 -0 sidewinder/sheet.h
M +2 -0 sidewinder/value.cpp
M +10 -0 sidewinder/workbook.cpp
M +3 -0 sidewinder/workbook.h
M +1 -1 sidewinder/worksheetsubstreamhandler.cpp
--- trunk/koffice/filters/kspread/excel/import/CMakeLists.txt #1154314:1154315
@@ -1,5 +1,11 @@
-include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../sidewinder \
${CMAKE_BINARY_DIR}/filters/ ${KOMAIN_INCLUDES})
-include_directories( ${CMAKE_SOURCE_DIR}/filters/kspread/xlsx \
${CMAKE_SOURCE_DIR}/filters/libmsooxml ) +include_directories(
+ ${CMAKE_CURRENT_SOURCE_DIR}/../sidewinder
+ ${CMAKE_BINARY_DIR}/filters/
+ ${KOMAIN_INCLUDES}
+ ${CMAKE_SOURCE_DIR}/filters/kspread/xlsx
+ ${CMAKE_SOURCE_DIR}/filters/libmsooxml
+ ${CMAKE_SOURCE_DIR}/kspread # for PointStorage
+)
add_custom_command(
OUTPUT records.cpp
--- trunk/koffice/filters/kspread/excel/import/excelimport.cc #1154314:1154315
@@ -1336,10 +1336,11 @@
QString str = string(value.asString());
QString linkName, linkLocation;
- if (cell->hasHyperlink()) {
- linkLocation = string(cell->hyperlinkLocation());
+ Hyperlink link = cell->hyperlink();
+ if (link.isValid) {
+ linkLocation = string(link.location);
if(!linkLocation.isEmpty()) {
- linkName = string(cell->hyperlinkDisplayName()).trimmed();
+ linkName = string(link.displayName).trimmed();
if(linkName.isEmpty())
linkName = str;
str.clear(); // at Excel cells with links don't have additional text \
content @@ -1401,7 +1402,7 @@
if (!linkName.isEmpty()) {
xmlWriter->startElement("text:a");
xmlWriter->addAttribute("xlink:href", linkLocation);
- const QString targetFrameName = \
string(cell->hyperlinkTargetFrameName()); + const QString targetFrameName \
= string(link.targetFrameName); if (! targetFrameName.isEmpty())
xmlWriter->addAttribute("office:target-frame-name", \
targetFrameName); xmlWriter->addTextNode(linkName);
--- trunk/koffice/filters/kspread/excel/sidewinder/CMakeLists.txt #1154314:1154315
@@ -1,6 +1,7 @@
include_directories(
${CMAKE_BINARY_DIR}/filters/
${CMAKE_SOURCE_DIR}/filters/kspread/xlsx # for Charting.h
+ ${CMAKE_SOURCE_DIR}/kspread # for PointStorage.h
)
kde4_add_executable(recordsxml2cpp recordsxml2cpp.cpp)
--- trunk/koffice/filters/kspread/excel/sidewinder/cell.cpp #1154314:1154315
@@ -42,13 +42,7 @@
unsigned rowSpan;
bool covered;
int columnRepeat;
- bool hasHyperlink;
- UString hyperlinkDisplayName;
- UString hyperlinkLocation;
- UString hyperlinkTargetFrameName;
UString note;
- std::vector<Picture*> pictures;
- std::vector<ChartObject*> charts;
};
}
@@ -66,14 +60,11 @@
d->rowSpan = 1;
d->covered = false;
d->columnRepeat = 1;
- d->hasHyperlink = false;
d->format = 0;
}
Cell::~Cell()
{
- qDeleteAll(d->pictures);
- qDeleteAll(d->charts);
delete d;
}
@@ -217,40 +208,19 @@
bool Cell::hasHyperlink() const
{
- return d->hasHyperlink;
+ return d->sheet->hyperlink(d->column, d->row).isValid;
}
-UString Cell::hyperlinkDisplayName() const
+Hyperlink Cell::hyperlink() const
{
- return d->hyperlinkDisplayName;
+ return d->sheet->hyperlink(d->column, d->row);
}
-UString Cell::hyperlinkLocation() const
+void Cell::setHyperlink(const Hyperlink& link)
{
- return d->hyperlinkLocation;
+ d->sheet->setHyperlink(d->column, d->row, link);
}
-UString Cell::hyperlinkTargetFrameName() const
-{
- return d->hyperlinkTargetFrameName;
-}
-
-void Cell::removeHyperlink()
-{
- d->hyperlinkDisplayName = UString();
- d->hyperlinkLocation = UString();
- d->hyperlinkTargetFrameName = UString();
- d->hasHyperlink = false;
-}
-
-void Cell::setHyperlink(const UString& displayName, const UString& location, const \
UString& targetFrameName)
-{
- d->hyperlinkDisplayName = displayName;
- d->hyperlinkLocation = location;
- d->hyperlinkTargetFrameName = targetFrameName;
- d->hasHyperlink = true;
-}
-
UString Cell::note() const
{
return d->note;
@@ -261,29 +231,29 @@
d->note = n;
}
-std::vector<Picture*> Cell::pictures() const
+QList<Picture*> Cell::pictures() const
{
- return d->pictures;
+ return d->sheet->pictures(d->column, d->row);
}
-void Cell::setPictures(std::vector<Picture*> pics)
+void Cell::setPictures(const QList<Picture*>& pics)
{
- d->pictures = pics;
+ d->sheet->setPictures(d->column, d->row, pics);
}
void Cell::addPicture(Picture* picture)
{
- d->pictures.push_back(picture);
+ d->sheet->addPicture(d->column, d->row, picture);
}
-std::vector<ChartObject*> Cell::charts() const
+QList<ChartObject*> Cell::charts() const
{
- return d->charts;
+ return d->sheet->charts(d->column, d->row);
}
void Cell::addChart(ChartObject* chart)
{
- d->charts.push_back(chart);
+ d->sheet->addChart(d->column, d->row, chart);
}
bool Cell::operator==(const Cell &other) const
@@ -297,9 +267,7 @@
if (columnRepeat() != other.columnRepeat()) return false;
if (hasHyperlink() != other.hasHyperlink()) return false;
- if (hasHyperlink() && ( hyperlinkDisplayName() != other.hyperlinkDisplayName() \
||
- hyperlinkLocation() != other.hyperlinkLocation() ||
- hyperlinkTargetFrameName() != \
other.hyperlinkTargetFrameName() ) ) return false; + if (hasHyperlink() && \
hyperlink() != other.hyperlink()) return false;
if (note() != other.note()) return false;
--- trunk/koffice/filters/kspread/excel/sidewinder/cell.h #1154314:1154315
@@ -25,6 +25,8 @@
#include "value.h"
#include <vector>
+#include <QtGlobal>
+#include <QList>
namespace Swinder
{
@@ -34,6 +36,26 @@
class Picture;
class ChartObject;
+struct Hyperlink
+{
+ Hyperlink() : isValid(false) {}
+ Hyperlink(const UString& displayName, const UString& location, const UString& \
targetFrameName) : isValid(true), displayName(displayName), location(location), \
targetFrameName(targetFrameName) {} + bool operator==(const Hyperlink& b) {
+ if (!isValid && !b.isValid) return true;
+ if (!isValid || !b.isValid) return false;
+ return displayName == b.displayName && location == b.location && \
targetFrameName == b.targetFrameName; + }
+ bool operator!=(const Hyperlink& b) { return !operator==(b); }
+
+ bool isValid;
+ UString displayName;
+ UString location;
+ UString targetFrameName;
+};
+}
+Q_DECLARE_TYPEINFO(Swinder::Hyperlink, Q_MOVABLE_TYPE);
+namespace Swinder
+{
class Cell
{
public:
@@ -90,23 +112,20 @@
// Defines if this cell has a hyperlink.
bool hasHyperlink() const;
- UString hyperlinkDisplayName() const;
- UString hyperlinkLocation() const;
- UString hyperlinkTargetFrameName() const;
- void removeHyperlink();
- void setHyperlink(const UString& displayName, const UString& location, const \
UString& targetFrameName); + Hyperlink hyperlink() const;
+ void setHyperlink(const Hyperlink& link);
// Returns the optional note/comment/annotation of this cell.
UString note() const;
void setNote(const UString &n);
// Defines a list of pictures anchored to this cell.
- std::vector<Picture*> pictures() const;
- void setPictures(std::vector<Picture*>);
+ QList<Picture*> pictures() const;
+ void setPictures(const QList<Picture*>&);
void addPicture(Picture*);
// Defines a list of charts anchored to this cell.
- std::vector<ChartObject*> charts() const;
+ QList<ChartObject*> charts() const;
void addChart(ChartObject* chart);
bool operator==(const Cell &other) const;
--- trunk/koffice/filters/kspread/excel/sidewinder/excel.cpp #1154314:1154315
@@ -3220,6 +3220,7 @@
Workbook* workbook = new Workbook();
ExcelReader* reader = new ExcelReader();
reader->load(workbook, filename);
+ workbook->dumpStats();
delete reader;
delete workbook;
--- trunk/koffice/filters/kspread/excel/sidewinder/sheet.cpp #1154314:1154315
@@ -24,6 +24,8 @@
#include "ustring.h"
#include "utils.h"
+#include <PointStorage.h>
+
#include <iostream>
#include <map>
#include <QPoint>
@@ -49,6 +51,9 @@
QHash<unsigned, unsigned> maxCellsInRow;
QHash<unsigned, Column*> columns;
QHash<unsigned, Row*> rows;
+ KSpread::PointStorage<Hyperlink> hyperlinks;
+ KSpread::PointStorage<QList<Picture*> > pictures;
+ KSpread::PointStorage<QList<ChartObject*> > charts;
bool visible;
bool protect;
@@ -116,6 +121,13 @@
void Sheet::clear()
{
+ // delete all cell data
+ for (int i = 0; i < d->pictures.count(); i++) {
+ qDeleteAll(d->pictures.data(i));
+ }
+ for (int i = 0; i < d->charts.count(); i++) {
+ qDeleteAll(d->charts.data(i));
+ }
// delete all cells
qDeleteAll(d->cells);
d->cells.clear();
@@ -468,7 +480,81 @@
return d->horizontalPageBreaks;
}
+Hyperlink Sheet::hyperlink(unsigned column, unsigned row) const
+{
+ return d->hyperlinks.lookup(column, row);
+}
+void Sheet::setHyperlink(unsigned column, unsigned row, const Hyperlink& link)
+{
+ if (link.isValid)
+ d->hyperlinks.insert(column, row, link);
+ else
+ d->hyperlinks.take(column, row);
+}
+
+QList<Picture*> Sheet::pictures(unsigned column, unsigned row) const
+{
+ return d->pictures.lookup(column, row);
+}
+
+void Sheet::setPictures(unsigned column, unsigned row, const QList<Picture*>& \
pictures) +{
+ if (pictures.isEmpty())
+ d->pictures.take(column, row);
+ else
+ d->pictures.insert(column, row, pictures);
+}
+
+void Sheet::addPicture(unsigned column, unsigned row, Picture* picture)
+{
+ QList<Picture*> pics = pictures(column, row);
+ pics.append(picture);
+ setPictures(column, row, pics);
+}
+
+QList<ChartObject*> Sheet::charts(unsigned column, unsigned row) const
+{
+ return d->charts.lookup(column, row);
+}
+
+void Sheet::setCharts(unsigned column, unsigned row, const QList<ChartObject*>& \
charts) +{
+ if (charts.isEmpty())
+ d->charts.take(column, row);
+ else
+ d->charts.insert(column, row, charts);
+}
+
+void Sheet::addChart(unsigned column, unsigned row, ChartObject* chart)
+{
+ QList<ChartObject*> chrts = charts(column, row);
+ chrts.append(chart);
+ setCharts(column, row, chrts);
+}
+
+#ifdef SWINDER_XLS2RAW
+void Sheet::dumpStats()
+{
+ int ndValue = 0, ndFormula = 0, ndFormat = 0, ndColumnSpan = 0, ndRowSpan = 0, \
ndCovered = 0, ndColumnRepeat = 0, ndHyperlink = 0, ndNote = 0, ndPictures = 0, \
ndCharts = 0; + foreach (Cell* c, d->cells) {
+ if (c->value() != Value()) ndValue++;
+ if (!c->formula().isEmpty()) ndFormula++;
+ if (c->format() != Format()) ndFormat++;
+ if (c->columnSpan() != 1) ndColumnSpan++;
+ if (c->rowSpan() != 1) ndRowSpan++;
+ if (c->isCovered()) ndCovered++;
+ if (c->columnRepeat() != 1) ndColumnRepeat++;
+ if (c->hasHyperlink()) ndHyperlink++;
+ if (!c->note().isEmpty()) ndNote++;
+ if (c->pictures().size()) ndPictures++;
+ if (c->charts().size()) ndCharts++;
+ }
+ printf(" rows: %d\n cols: %d\n cells: %d\n", d->rows.size(), \
d->columns.size(), d->cells.size()); + printf(" values: %d\n formulas: \
%d\n formats: %d\n colspans: %d\n rowspans: %d\n covered: \
%d\n colrepeat: %d\n hyperlink: %d\n note: %d\n pics: %d\n \
charts: %d\n", ndValue, ndFormula, ndFormat, ndColumnSpan, ndRowSpan, ndCovered, \
ndColumnRepeat, ndHyperlink, ndNote, ndPictures, ndCharts); +}
+#endif
+
class Column::Private
{
public:
--- trunk/koffice/filters/kspread/excel/sidewinder/sheet.h #1154314:1154315
@@ -22,6 +22,7 @@
#include "ustring.h"
#include "format.h"
+#include "cell.h"
#include <QImage>
class QPoint;
@@ -174,6 +175,9 @@
void addHorizontalPageBreak(const HorizontalPageBreak& pageBreak);
QList<HorizontalPageBreak> horizontalPageBreaks();
+#ifdef SWINDER_XLS2RAW
+ void dumpStats();
+#endif
private:
// no copy or assign
Sheet(const Sheet&);
@@ -181,6 +185,17 @@
class Private;
Private *d;
+
+ friend class Cell;
+
+ Hyperlink hyperlink(unsigned column, unsigned row) const;
+ void setHyperlink(unsigned column, unsigned row, const Hyperlink& link);
+ QList<Picture*> pictures(unsigned column, unsigned row) const;
+ void setPictures(unsigned column, unsigned row, const QList<Picture*>& \
pictures); + void addPicture(unsigned column, unsigned row, Picture* picture);
+ QList<ChartObject*> charts(unsigned column, unsigned row) const;
+ void setCharts(unsigned column, unsigned row, const QList<ChartObject*>& \
charts); + void addChart(unsigned column, unsigned row, ChartObject* chart);
};
struct VerticalPageBreak {
--- trunk/koffice/filters/kspread/excel/sidewinder/value.cpp #1154314:1154315
@@ -34,9 +34,11 @@
Value::Type type;
// someday move to use union to reduce memory consumption
+ union {
bool b;
int i;
double f;
+ };
UString s;
std::map<unsigned, FormatFont> formatRuns;
--- trunk/koffice/filters/kspread/excel/sidewinder/workbook.cpp #1154314:1154315
@@ -178,3 +178,13 @@
{
return d->formats[index];
}
+
+#ifdef SWINDER_XLS2RAW
+void Workbook::dumpStats()
+{
+ for (unsigned i = 0; i < d->sheets.size(); i++) {
+ printf("Sheet %u\n", i+1);
+ d->sheets[i]->dumpStats();
+ }
+}
+#endif
--- trunk/koffice/filters/kspread/excel/sidewinder/workbook.h #1154314:1154315
@@ -136,6 +136,9 @@
void emitProgress(int value);
+#ifdef SWINDER_XLS2RAW
+ void dumpStats();
+#endif
signals:
void sigProgress(int value);
--- trunk/koffice/filters/kspread/excel/sidewinder/worksheetsubstreamhandler.cpp \
#1154314:1154315 @@ -726,7 +726,7 @@
Cell *cell = d->sheet->cell(record->firstColumn(), record->firstRow());
if (cell) {
UString url = record->urlMonikerUrl() + UString('#') + record->location();
- cell->setHyperlink(record->displayName(), url, record->frameName());
+ cell->setHyperlink(Hyperlink(record->displayName(), url, \
record->frameName())); }
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic