Browse Source

Add const to the saveAs* members, step 1

master
Debao Zhang 11 years ago
parent
commit
1ca891cf8a
  1. 2
      src/xlsx/xlsxcontenttypes.cpp
  2. 2
      src/xlsx/xlsxcontenttypes_p.h
  3. 4
      src/xlsx/xlsxdocpropsapp.cpp
  4. 4
      src/xlsx/xlsxdocpropsapp_p.h
  5. 4
      src/xlsx/xlsxdocpropscore.cpp
  6. 4
      src/xlsx/xlsxdocpropscore_p.h
  7. 14
      src/xlsx/xlsxdrawing.cpp
  8. 14
      src/xlsx/xlsxdrawing_p.h
  9. 4
      src/xlsx/xlsxrelationships.cpp
  10. 4
      src/xlsx/xlsxrelationships_p.h
  11. 2
      src/xlsx/xlsxtheme.cpp
  12. 2
      src/xlsx/xlsxtheme_p.h
  13. 6
      src/xlsx/xlsxworkbook.cpp
  14. 4
      src/xlsx/xlsxworkbook.h
  15. 40
      src/xlsx/xlsxworksheet.cpp
  16. 4
      src/xlsx/xlsxworksheet.h
  17. 32
      src/xlsx/xlsxworksheet_p.h

2
src/xlsx/xlsxcontenttypes.cpp

@ -111,7 +111,7 @@ void ContentTypes::addVbaProject()
addOverride(QStringLiteral("bin"), QStringLiteral("application/vnd.ms-office.vbaProject"));
}
void ContentTypes::saveToXmlFile(QIODevice *device)
void ContentTypes::saveToXmlFile(QIODevice *device) const
{
QXmlStreamWriter writer(device);

2
src/xlsx/xlsxcontenttypes_p.h

@ -65,7 +65,7 @@ public:
void addCalcChain();
void addVbaProject();
void saveToXmlFile(QIODevice *device);
void saveToXmlFile(QIODevice *device) const;
private:
QMap<QString, QString> m_defaults;

4
src/xlsx/xlsxdocpropsapp.cpp

@ -79,7 +79,7 @@ QStringList DocPropsApp::propertyNames() const
return m_properties.keys();
}
void DocPropsApp::saveToXmlFile(QIODevice *device)
void DocPropsApp::saveToXmlFile(QIODevice *device) const
{
QXmlStreamWriter writer(device);
QString vt = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
@ -130,7 +130,7 @@ void DocPropsApp::saveToXmlFile(QIODevice *device)
writer.writeEndDocument();
}
QByteArray DocPropsApp::saveToXmlData()
QByteArray DocPropsApp::saveToXmlData() const
{
QByteArray data;
QBuffer buffer(&data);

4
src/xlsx/xlsxdocpropsapp_p.h

@ -58,8 +58,8 @@ public:
QString property(const QString &name) const;
QStringList propertyNames() const;
QByteArray saveToXmlData();
void saveToXmlFile(QIODevice *device);
QByteArray saveToXmlData() const;
void saveToXmlFile(QIODevice *device) const;
static DocPropsApp loadFromXmlFile(QIODevice *device);
static DocPropsApp loadFromXmlData(const QByteArray &data);

4
src/xlsx/xlsxdocpropscore.cpp

@ -72,7 +72,7 @@ QStringList DocPropsCore::propertyNames() const
return m_properties.keys();
}
void DocPropsCore::saveToXmlFile(QIODevice *device)
void DocPropsCore::saveToXmlFile(QIODevice *device) const
{
QXmlStreamWriter writer(device);
const QString cp = QStringLiteral("http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
@ -124,7 +124,7 @@ void DocPropsCore::saveToXmlFile(QIODevice *device)
writer.writeEndDocument();
}
QByteArray DocPropsCore::saveToXmlData()
QByteArray DocPropsCore::saveToXmlData() const
{
QByteArray data;
QBuffer buffer(&data);

4
src/xlsx/xlsxdocpropscore_p.h

@ -53,8 +53,8 @@ public:
QString property(const QString &name) const;
QStringList propertyNames() const;
void saveToXmlFile(QIODevice *device);
QByteArray saveToXmlData();
void saveToXmlFile(QIODevice *device) const;
QByteArray saveToXmlData() const;
static DocPropsCore loadFromXmlFile(QIODevice *device);
static DocPropsCore loadFromXmlData(const QByteArray &data);

14
src/xlsx/xlsxdrawing.cpp

@ -36,7 +36,7 @@ Drawing::Drawing()
orientation = 0;
}
void Drawing::saveToXmlFile(QIODevice *device)
void Drawing::saveToXmlFile(QIODevice *device) const
{
QXmlStreamWriter writer(device);
@ -60,7 +60,7 @@ void Drawing::saveToXmlFile(QIODevice *device)
writer.writeEndDocument();
}
void Drawing::writeTwoCellAnchor(QXmlStreamWriter &writer, int index, XlsxDrawingDimensionData *data)
void Drawing::writeTwoCellAnchor(QXmlStreamWriter &writer, int index, XlsxDrawingDimensionData *data) const
{
writer.writeStartElement(QStringLiteral("xdr:twoCellAnchor"));
if (data->drawing_type == 2)
@ -96,7 +96,7 @@ void Drawing::writeTwoCellAnchor(QXmlStreamWriter &writer, int index, XlsxDrawin
writer.writeEndElement(); //xdr:twoCellAnchor
}
void Drawing::writeAbsoluteAnchor(QXmlStreamWriter &writer, int index)
void Drawing::writeAbsoluteAnchor(QXmlStreamWriter &writer, int index) const
{
writer.writeStartElement(QStringLiteral("xdr:absoluteAnchor"));
if (orientation == 0) {
@ -113,21 +113,21 @@ void Drawing::writeAbsoluteAnchor(QXmlStreamWriter &writer, int index)
writer.writeEndElement(); //xdr:absoluteAnchor
}
void Drawing::writePos(QXmlStreamWriter &writer, int x, int y)
void Drawing::writePos(QXmlStreamWriter &writer, int x, int y) const
{
writer.writeEmptyElement(QStringLiteral("xdr:pos"));
writer.writeAttribute(QStringLiteral("x"), QString::number(x));
writer.writeAttribute(QStringLiteral("y"), QString::number(y));
}
void Drawing::writeExt(QXmlStreamWriter &writer, int cx, int cy)
void Drawing::writeExt(QXmlStreamWriter &writer, int cx, int cy) const
{
writer.writeStartElement(QStringLiteral("xdr:ext"));
writer.writeAttribute(QStringLiteral("cx"), QString::number(cx));
writer.writeAttribute(QStringLiteral("cy"), QString::number(cy));
}
void Drawing::writeGraphicFrame(QXmlStreamWriter &writer, int index, const QString &name)
void Drawing::writeGraphicFrame(QXmlStreamWriter &writer, int index, const QString &name) const
{
writer.writeStartElement(QStringLiteral("xdr:graphicFrame"));
writer.writeAttribute(QStringLiteral("macro"), QString());
@ -149,7 +149,7 @@ void Drawing::writeGraphicFrame(QXmlStreamWriter &writer, int index, const QStri
writer.writeEndElement(); //xdr:graphicFrame
}
void Drawing::writePicture(QXmlStreamWriter &writer, int index, double col_abs, double row_abs, int width, int height, const QString &description)
void Drawing::writePicture(QXmlStreamWriter &writer, int index, double col_abs, double row_abs, int width, int height, const QString &description) const
{
writer.writeStartElement(QStringLiteral("xdr:pic"));

14
src/xlsx/xlsxdrawing_p.h

@ -68,19 +68,19 @@ class Drawing
{
public:
Drawing();
void saveToXmlFile(QIODevice *device);
void saveToXmlFile(QIODevice *device) const;
bool embedded;
int orientation;
QList <XlsxDrawingDimensionData *> dimensionList;
private:
void writeTwoCellAnchor(QXmlStreamWriter &writer, int index, XlsxDrawingDimensionData *data);
void writeAbsoluteAnchor(QXmlStreamWriter &writer, int index);
void writePos(QXmlStreamWriter &writer, int x, int y);
void writeExt(QXmlStreamWriter &writer, int cx, int cy);
void writeGraphicFrame(QXmlStreamWriter &writer, int index, const QString &name=QString());
void writePicture(QXmlStreamWriter &writer, int index, double col_abs, double row_abs, int width, int height, const QString &description);
void writeTwoCellAnchor(QXmlStreamWriter &writer, int index, XlsxDrawingDimensionData *data) const;
void writeAbsoluteAnchor(QXmlStreamWriter &writer, int index) const;
void writePos(QXmlStreamWriter &writer, int x, int y) const;
void writeExt(QXmlStreamWriter &writer, int cx, int cy) const;
void writeGraphicFrame(QXmlStreamWriter &writer, int index, const QString &name=QString()) const;
void writePicture(QXmlStreamWriter &writer, int index, double col_abs, double row_abs, int width, int height, const QString &description) const;
};
} // namespace QXlsx

4
src/xlsx/xlsxrelationships.cpp

@ -100,7 +100,7 @@ void Relationships::addRelationship(const QString &type, const QString &target,
m_relationships.append(relation);
}
void Relationships::saveToXmlFile(QIODevice *device)
void Relationships::saveToXmlFile(QIODevice *device) const
{
QXmlStreamWriter writer(device);
@ -120,7 +120,7 @@ void Relationships::saveToXmlFile(QIODevice *device)
writer.writeEndDocument();
}
QByteArray Relationships::saveToXmlData()
QByteArray Relationships::saveToXmlData() const
{
QByteArray data;
QBuffer buffer(&data);

4
src/xlsx/xlsxrelationships_p.h

@ -66,8 +66,8 @@ public:
void addMsPackageRelationship(const QString &relativeType, const QString &target);
void addWorksheetRelationship(const QString &relativeType, const QString &target, const QString &targetMode=QString());
void saveToXmlFile(QIODevice *device);
QByteArray saveToXmlData();
void saveToXmlFile(QIODevice *device) const;
QByteArray saveToXmlData() const;
bool loadFromXmlFile(QIODevice *device);
bool loadFromXmlData(const QByteArray &data);
XlsxRelationship getRelationshipById(const QString &id) const;

2
src/xlsx/xlsxtheme.cpp

@ -205,7 +205,7 @@ Theme::Theme()
{
}
void Theme::saveToXmlFile(QIODevice *device)
void Theme::saveToXmlFile(QIODevice *device) const
{
if (xmlData.isEmpty())
device->write(defaultXmlData);

2
src/xlsx/xlsxtheme_p.h

@ -46,7 +46,7 @@ class Theme
public:
Theme();
void saveToXmlFile(QIODevice *device);
void saveToXmlFile(QIODevice *device) const;
QByteArray saveToXmlData() const;
void loadFromXmlData(const QByteArray &data);

6
src/xlsx/xlsxworkbook.cpp

@ -395,9 +395,9 @@ void Workbook::prepareDrawings()
}
}
void Workbook::saveToXmlFile(QIODevice *device)
void Workbook::saveToXmlFile(QIODevice *device) const
{
Q_D(Workbook);
Q_D(const Workbook);
QXmlStreamWriter writer(device);
writer.writeStartDocument(QStringLiteral("1.0"), true);
@ -474,7 +474,7 @@ void Workbook::saveToXmlFile(QIODevice *device)
writer.writeEndDocument();
}
QByteArray Workbook::saveToXmlData()
QByteArray Workbook::saveToXmlData() const
{
QByteArray data;
QBuffer buffer(&data);

4
src/xlsx/xlsxworkbook.h

@ -82,8 +82,8 @@ private:
Workbook();
void saveToXmlFile(QIODevice *device);
QByteArray saveToXmlData();
void saveToXmlFile(QIODevice *device) const;
QByteArray saveToXmlData() const;
bool loadFromXmlFile(QIODevice *device);
bool loadFromXmlData(const QByteArray &data);

40
src/xlsx/xlsxworksheet.cpp

@ -83,7 +83,7 @@ WorksheetPrivate::~WorksheetPrivate()
makes comparing files easier. The span is the same for each
block of 16 rows.
*/
void WorksheetPrivate::calculateSpans()
void WorksheetPrivate::calculateSpans() const
{
row_spans.clear();
int span_min = XLSX_COLUMN_MAX+1;
@ -132,7 +132,7 @@ void WorksheetPrivate::calculateSpans()
}
QString WorksheetPrivate::generateDimensionString()
QString WorksheetPrivate::generateDimensionString() const
{
if (!dimension.isValid())
return QStringLiteral("A1");
@ -990,7 +990,7 @@ int Worksheet::writeHyperlink(int row, int column, const QUrl &url, const Format
d->cellTable[row][column] = QSharedPointer<Cell>(new Cell(displayString, Cell::String, fmt, this));
//Store the hyperlink data in a separate table
d->urlTable[row][column] = new XlsxUrlData(XlsxUrlData::External, urlString, locationString, tip);
d->urlTable[row][column] = new XlsxHyperlinkData(XlsxHyperlinkData::External, urlString, locationString, tip);
return error;
}
@ -1119,9 +1119,9 @@ int Worksheet::unmergeCells(const QString &range)
return unmergeCells(CellRange(cell1.x(), cell1.y(), cell2.x(), cell2.y()));
}
void Worksheet::saveToXmlFile(QIODevice *device)
void Worksheet::saveToXmlFile(QIODevice *device) const
{
Q_D(Worksheet);
Q_D(const Worksheet);
d->relationships.clear();
QXmlStreamWriter writer(device);
@ -1222,7 +1222,7 @@ void Worksheet::saveToXmlFile(QIODevice *device)
writer.writeEndDocument();
}
void WorksheetPrivate::writeSheetData(QXmlStreamWriter &writer)
void WorksheetPrivate::writeSheetData(QXmlStreamWriter &writer) const
{
calculateSpans();
for (int row_num = dimension.firstRow(); row_num <= dimension.lastRow(); row_num++) {
@ -1275,7 +1275,7 @@ void WorksheetPrivate::writeSheetData(QXmlStreamWriter &writer)
}
}
void WorksheetPrivate::writeCellData(QXmlStreamWriter &writer, int row, int col, QSharedPointer<Cell> cell)
void WorksheetPrivate::writeCellData(QXmlStreamWriter &writer, int row, int col, QSharedPointer<Cell> cell) const
{
//This is the innermost loop so efficiency is important.
QString cell_pos = xl_rowcol_to_cell_fast(row, col);
@ -1349,7 +1349,7 @@ void WorksheetPrivate::writeCellData(QXmlStreamWriter &writer, int row, int col,
writer.writeEndElement(); //c
}
void WorksheetPrivate::writeMergeCells(QXmlStreamWriter &writer)
void WorksheetPrivate::writeMergeCells(QXmlStreamWriter &writer) const
{
if (merges.isEmpty())
return;
@ -1367,7 +1367,7 @@ void WorksheetPrivate::writeMergeCells(QXmlStreamWriter &writer)
writer.writeEndElement(); //mergeCells
}
void WorksheetPrivate::writeDataValidations(QXmlStreamWriter &writer)
void WorksheetPrivate::writeDataValidations(QXmlStreamWriter &writer) const
{
if (dataValidationsList.isEmpty())
return;
@ -1381,25 +1381,25 @@ void WorksheetPrivate::writeDataValidations(QXmlStreamWriter &writer)
writer.writeEndElement(); //dataValidations
}
void WorksheetPrivate::writeHyperlinks(QXmlStreamWriter &writer)
void WorksheetPrivate::writeHyperlinks(QXmlStreamWriter &writer) const
{
if (urlTable.isEmpty())
return;
writer.writeStartElement(QStringLiteral("hyperlinks"));
QMapIterator<int, QMap<int, XlsxUrlData *> > it(urlTable);
QMapIterator<int, QMap<int, XlsxHyperlinkData *> > it(urlTable);
while (it.hasNext()) {
it.next();
int row = it.key();
QMapIterator <int, XlsxUrlData *> it2(it.value());
QMapIterator <int, XlsxHyperlinkData *> it2(it.value());
while (it2.hasNext()) {
it2.next();
int col = it2.key();
XlsxUrlData *data = it2.value();
XlsxHyperlinkData *data = it2.value();
QString ref = xl_rowcol_to_cell(row, col);
writer.writeEmptyElement(QStringLiteral("hyperlink"));
writer.writeAttribute(QStringLiteral("ref"), ref);
if (data->linkType == XlsxUrlData::External) {
if (data->linkType == XlsxHyperlinkData::External) {
//Update relationships
relationships.addWorksheetRelationship(QStringLiteral("/hyperlink"), data->url, QStringLiteral("External"));
@ -1423,7 +1423,7 @@ void WorksheetPrivate::writeHyperlinks(QXmlStreamWriter &writer)
writer.writeEndElement();//hyperlinks
}
void WorksheetPrivate::writeDrawings(QXmlStreamWriter &writer)
void WorksheetPrivate::writeDrawings(QXmlStreamWriter &writer) const
{
if (!drawing)
return;
@ -1732,7 +1732,7 @@ void Worksheet::prepareImage(int index, int image_id)
height hasn't been set by the user we use the default value. If
the row is hidden it has a value of zero.
*/
int WorksheetPrivate::rowPixelsSize(int row)
int WorksheetPrivate::rowPixelsSize(int row) const
{
double height;
if (row_sizes.contains(row))
@ -1748,7 +1748,7 @@ int WorksheetPrivate::rowPixelsSize(int row)
by the user we use the default value. If the column is hidden it
has a value of zero.
*/
int WorksheetPrivate::colPixelsSize(int col)
int WorksheetPrivate::colPixelsSize(int col) const
{
double max_digit_width = 7.0; //For Calabri 11
double padding = 5.0;
@ -1780,7 +1780,7 @@ int WorksheetPrivate::colPixelsSize(int col)
x_abs Absolute distance to left side of object.
y_abs Absolute distance to top side of object.
*/
XlsxObjectPositionData WorksheetPrivate::objectPixelsPosition(int col_start, int row_start, double x1, double y1, double width, double height)
XlsxObjectPositionData WorksheetPrivate::objectPixelsPosition(int col_start, int row_start, double x1, double y1, double width, double height) const
{
double x_abs = 0;
double y_abs = 0;
@ -1841,7 +1841,7 @@ XlsxObjectPositionData WorksheetPrivate::objectPixelsPosition(int col_start, int
12,700 EMUs per point. Therefore, 12,700 * 3 /4 = 9,525 EMUs per
pixel
*/
XlsxObjectPositionData WorksheetPrivate::pixelsToEMUs(const XlsxObjectPositionData &data)
XlsxObjectPositionData WorksheetPrivate::pixelsToEMUs(const XlsxObjectPositionData &data) const
{
XlsxObjectPositionData result = data;
result.x1 = static_cast<int>(data.x1 * 9525 + 0.5);
@ -1856,7 +1856,7 @@ XlsxObjectPositionData WorksheetPrivate::pixelsToEMUs(const XlsxObjectPositionDa
return result;
}
QByteArray Worksheet::saveToXmlData()
QByteArray Worksheet::saveToXmlData() const
{
QByteArray data;
QBuffer buffer(&data);

4
src/xlsx/xlsxworksheet.h

@ -139,8 +139,8 @@ private:
void setSheetName(const QString &sheetName);
Relationships &relationships();
void saveToXmlFile(QIODevice *device);
QByteArray saveToXmlData();
void saveToXmlFile(QIODevice *device) const;
QByteArray saveToXmlData() const;
bool loadFromXmlFile(QIODevice *device);
bool loadFromXmlData(const QByteArray &data);

32
src/xlsx/xlsxworksheet_p.h

@ -57,7 +57,7 @@ const int XLSX_STRING_MAX = 32767;
class SharedStrings;
struct XlsxUrlData
struct XlsxHyperlinkData
{
enum LinkType
{
@ -65,7 +65,7 @@ struct XlsxUrlData
Internal
};
XlsxUrlData(LinkType linkType=External, const QString &url=QString(), const QString &location=QString(), const QString &tip=QString()) :
XlsxHyperlinkData(LinkType linkType=External, const QString &url=QString(), const QString &location=QString(), const QString &tip=QString()) :
linkType(linkType), url(url), location(location), tip(tip)
{
@ -180,20 +180,20 @@ public:
~WorksheetPrivate();
int checkDimensions(int row, int col, bool ignore_row=false, bool ignore_col=false);
Format cellFormat(int row, int col) const;
QString generateDimensionString();
void calculateSpans();
QString generateDimensionString() const;
void calculateSpans() const;
void splitColsInfo(int colFirst, int colLast);
void writeSheetData(QXmlStreamWriter &writer);
void writeCellData(QXmlStreamWriter &writer, int row, int col, QSharedPointer<Cell> cell);
void writeMergeCells(QXmlStreamWriter &writer);
void writeHyperlinks(QXmlStreamWriter &writer);
void writeDrawings(QXmlStreamWriter &writer);
void writeDataValidations(QXmlStreamWriter &writer);
int rowPixelsSize(int row);
int colPixelsSize(int col);
XlsxObjectPositionData objectPixelsPosition(int col_start, int row_start, double x1, double y1, double width, double height);
XlsxObjectPositionData pixelsToEMUs(const XlsxObjectPositionData &data);
void writeSheetData(QXmlStreamWriter &writer) const;
void writeCellData(QXmlStreamWriter &writer, int row, int col, QSharedPointer<Cell> cell) const;
void writeMergeCells(QXmlStreamWriter &writer) const;
void writeHyperlinks(QXmlStreamWriter &writer) const;
void writeDrawings(QXmlStreamWriter &writer) const;
void writeDataValidations(QXmlStreamWriter &writer) const;
int rowPixelsSize(int row) const;
int colPixelsSize(int col) const;
XlsxObjectPositionData objectPixelsPosition(int col_start, int row_start, double x1, double y1, double width, double height) const;
XlsxObjectPositionData pixelsToEMUs(const XlsxObjectPositionData &data) const;
QSharedPointer<Cell> readNumericCellData(QXmlStreamReader &reader);
void readSheetData(QXmlStreamReader &reader);
@ -210,7 +210,7 @@ public:
Drawing *drawing;
QMap<int, QMap<int, QSharedPointer<Cell> > > cellTable;
QMap<int, QMap<int, QString> > comments;
QMap<int, QMap<int, XlsxUrlData *> > urlTable;
QMap<int, QMap<int, XlsxHyperlinkData *> > urlTable;
QList<CellRange> merges;
QList<XlsxImageData *> imageList;
QMap<int, QSharedPointer<XlsxRowInfo> > rowsInfo;
@ -224,7 +224,7 @@ public:
CellRange dimension;
int previous_row;
QMap<int, QString> row_spans;
mutable QMap<int, QString> row_spans;
QMap<int, double> row_sizes;
QMap<int, double> col_sizes;

Loading…
Cancel
Save