Browse Source

Fixed review comments. setRow/Column to WorksheetPrivate. Added deprecated methods warnings.

master
Edwin van der Horst 11 years ago
parent
commit
7ee11a6c02
  1. 6
      src/xlsx/xlsxdocument.cpp
  2. 5
      src/xlsx/xlsxdocument.h
  3. 158
      src/xlsx/xlsxworksheet.cpp
  4. 15
      src/xlsx/xlsxworksheet.h
  5. 5
      src/xlsx/xlsxworksheet_p.h

6
src/xlsx/xlsxdocument.cpp

@ -733,7 +733,7 @@ double Document::rowHeight(int row)
{
if (Worksheet *sheet = currentWorksheet())
return sheet->rowHeight(row);
return 0.0; // ?
return 0.0;
}
/*!
@ -743,7 +743,7 @@ Format Document::rowFormat(int row)
{
if (Worksheet *sheet = currentWorksheet())
return sheet->rowFormat(row);
return Format(); // ?
return Format();
}
/*!
@ -753,7 +753,7 @@ bool Document::isRowHidden(int row)
{
if (Worksheet *sheet = currentWorksheet())
return sheet->isRowHidden(row);
return false; // ?
return false;
}
/*!

5
src/xlsx/xlsxdocument.h

@ -65,9 +65,10 @@ public:
bool mergeCells(const QString &range, const Format &format=Format());
bool unmergeCells(const CellRange &range);
bool unmergeCells(const QString &range);
bool setRow(int row, double height, const Format &format=Format(), bool hidden=false);
Q_DECL_DEPRECATED
bool setColumn(int colFirst, int colLast, double width, const Format &format=Format(), bool hidden=false);
Q_DECL_DEPRECATED
bool setColumn(const QString &colFirst, const QString &colLast, double width, const Format &format=Format(), bool hidden=false);
bool setColumnWidth(const QString &column, double width);
bool setColumnFormat(const QString &column, const Format &format);
@ -85,6 +86,8 @@ public:
Format columnFormat(int column);
bool isColumnHidden(int column);
Q_DECL_DEPRECATED
bool setRow(int row, double height, const Format &format=Format(), bool hidden=false);
bool setRowHeight(int row, double height);
bool setRowFormat(int row, const Format &format);
bool setRowHidden(int row, bool hidden);

158
src/xlsx/xlsxworksheet.cpp

@ -1528,36 +1528,33 @@ void WorksheetPrivate::splitColsInfo(int colFirst, int colLast)
}
}
bool Worksheet::isColumnRangeValid(int colFirst, int colLast)
bool WorksheetPrivate::isColumnRangeValid(int colFirst, int colLast)
{
Q_D(Worksheet);
bool ignore_row = true;
bool ignore_col = false;
if (colFirst > colLast)
return false;
if (d->checkDimensions(0, colLast, ignore_row, ignore_col))
if (checkDimensions(0, colLast, ignore_row, ignore_col))
return false;
if (d->checkDimensions(0, colFirst, ignore_row, ignore_col))
if (checkDimensions(0, colFirst, ignore_row, ignore_col))
return false;
return true;
}
QList<int> Worksheet::getColumnIndexes(int colFirst, int colLast)
QList<int> WorksheetPrivate ::getColumnIndexes(int colFirst, int colLast)
{
Q_D(Worksheet);
d->splitColsInfo(colFirst, colLast);
splitColsInfo(colFirst, colLast);
QList<int> nodes;
nodes.append(colFirst);
for (int col = colFirst; col <= colLast; ++col) {
if (d->colsInfo.contains(col)) {
if (colsInfo.contains(col)) {
if (nodes.last() != col)
nodes.append(col);
int nextCol = d->colsInfo[col]->lastColumn + 1;
int nextCol = colsInfo[col]->lastColumn + 1;
if (nextCol <= colLast)
nodes.append(nextCol);
}
@ -1579,7 +1576,7 @@ bool Worksheet::setColumn(int colFirst, int colLast, double width, const Format
{
Q_D(Worksheet);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = getColumnInfoList(colFirst, colLast);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = d->getColumnInfoList(colFirst, colLast);
foreach(QSharedPointer<XlsxColumnInfo> columnInfo, columnInfoList) {
columnInfo->width = width;
columnInfo->format = format;
@ -1660,7 +1657,9 @@ bool Worksheet::setColumnHidden(const QString &colFirst, const QString &colLast,
*/
bool Worksheet::setColumnWidth(int colFirst, int colLast, double width)
{
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = getColumnInfoList(colFirst, colLast);
Q_D(Worksheet);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = d->getColumnInfoList(colFirst, colLast);
foreach(QSharedPointer<XlsxColumnInfo> columnInfo, columnInfoList) {
columnInfo->width = width;
}
@ -1675,7 +1674,7 @@ bool Worksheet::setColumnFormat(int colFirst, int colLast, const Format &format)
{
Q_D(Worksheet);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = getColumnInfoList(colFirst, colLast);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = d->getColumnInfoList(colFirst, colLast);
foreach(QSharedPointer<XlsxColumnInfo> columnInfo, columnInfoList) {
columnInfo->format = format;
}
@ -1693,7 +1692,9 @@ bool Worksheet::setColumnFormat(int colFirst, int colLast, const Format &format)
*/
bool Worksheet::setColumnHidden(int colFirst, int colLast, bool hidden)
{
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = getColumnInfoList(colFirst, colLast);
Q_D(Worksheet);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = d->getColumnInfoList(colFirst, colLast);
foreach(QSharedPointer<XlsxColumnInfo> columnInfo, columnInfoList) {
columnInfo->hidden = hidden;
}
@ -1708,7 +1709,7 @@ double Worksheet::columnWidth(int column)
{
Q_D(Worksheet);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = getColumnInfoList(column, column);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = d->getColumnInfoList(column, column);
if (columnInfoList.count() == 1) {
return columnInfoList.at(0)->width ;
}
@ -1721,7 +1722,9 @@ double Worksheet::columnWidth(int column)
*/
Format Worksheet::columnFormat(int column)
{
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = getColumnInfoList(column, column);
Q_D(Worksheet);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = d->getColumnInfoList(column, column);
if (columnInfoList.count() == 1) {
return columnInfoList.at(0)->format;
}
@ -1734,7 +1737,9 @@ Format Worksheet::columnFormat(int column)
*/
bool Worksheet::isColumnHidden(int column)
{
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = getColumnInfoList(column, column);
Q_D(Worksheet);
QList <QSharedPointer<XlsxColumnInfo> > columnInfoList = d->getColumnInfoList(column, column);
if (columnInfoList.count() == 1) {
return columnInfoList.at(0)->hidden;
}
@ -1752,7 +1757,8 @@ bool Worksheet::isColumnHidden(int column)
bool Worksheet::setRow(int rowFirst,int rowLast, double height, const Format &format, bool hidden)
{
Q_D(Worksheet);
QList <QSharedPointer<XlsxRowInfo> > rowInfoList = getRowInfoList(rowFirst,rowLast);
QList <QSharedPointer<XlsxRowInfo> > rowInfoList = d->getRowInfoList(rowFirst,rowLast);
foreach(QSharedPointer<XlsxRowInfo> rowInfo, rowInfoList) {
rowInfo->height = height;
@ -1772,8 +1778,10 @@ bool Worksheet::setRow(int rowFirst,int rowLast, double height, const Format &fo
Returns true if success.
*/
bool Worksheet::setRowHeight(int rowFirst,int rowLast, double height)
{
QList <QSharedPointer<XlsxRowInfo> > rowInfoList = getRowInfoList(rowFirst,rowLast);
{
Q_D(Worksheet);
QList <QSharedPointer<XlsxRowInfo> > rowInfoList = d->getRowInfoList(rowFirst,rowLast);
foreach(QSharedPointer<XlsxRowInfo> rowInfo, rowInfoList) {
rowInfo->height = height;
@ -1793,7 +1801,7 @@ bool Worksheet::setRowFormat(int rowFirst,int rowLast, const Format &format)
{
Q_D(Worksheet);
QList <QSharedPointer<XlsxRowInfo> > rowInfoList = getRowInfoList(rowFirst,rowLast);
QList <QSharedPointer<XlsxRowInfo> > rowInfoList = d->getRowInfoList(rowFirst,rowLast);
foreach(QSharedPointer<XlsxRowInfo> rowInfo, rowInfoList) {
rowInfo->format = format;
@ -1811,7 +1819,9 @@ bool Worksheet::setRowFormat(int rowFirst,int rowLast, const Format &format)
*/
bool Worksheet::setRowHidden(int rowFirst,int rowLast, bool hidden)
{
QList <QSharedPointer<XlsxRowInfo> > rowInfoList = getRowInfoList(rowFirst,rowLast);
Q_D(Worksheet);
QList <QSharedPointer<XlsxRowInfo> > rowInfoList = d->getRowInfoList(rowFirst,rowLast);
foreach(QSharedPointer<XlsxRowInfo> rowInfo, rowInfoList) {
rowInfo->hidden = hidden;
@ -1862,54 +1872,6 @@ bool Worksheet::isRowHidden(int row)
return d->rowsInfo[row]->hidden;
}
QList <QSharedPointer<XlsxColumnInfo> > Worksheet::getColumnInfoList(int colFirst, int colLast)
{
Q_D(Worksheet);
QList <QSharedPointer<XlsxColumnInfo> > columnsInfoList;
if(isColumnRangeValid(colFirst,colLast))
{
QList<int> nodes = getColumnIndexes(colFirst, colLast);
for (int idx = 0; idx < nodes.size(); ++idx) {
int colStart = nodes[idx];
if (d->colsInfo.contains(colStart)) {
QSharedPointer<XlsxColumnInfo> info = d->colsInfo[colStart];
columnsInfoList.append(info);
} else {
int colEnd = (idx == nodes.size() - 1) ? colLast : nodes[idx+1] - 1;
QSharedPointer<XlsxColumnInfo> info(new XlsxColumnInfo(colStart, colEnd));
d->colsInfo.insert(colFirst, info);
columnsInfoList.append(info);
for (int c = colStart; c <= colEnd; ++c)
d->colsInfoHelper[c] = info;
}
}
}
return columnsInfoList;
}
QList <QSharedPointer<XlsxRowInfo> > Worksheet::getRowInfoList(int rowFirst, int rowLast)
{
Q_D(Worksheet);
QList <QSharedPointer<XlsxRowInfo> > rowInfoList;
int min_col = d->dimension.firstColumn() < 0 ? 0 : d->dimension.firstColumn();
for(int row = rowFirst; row <= rowLast; ++row) {
if (d->checkDimensions(row, min_col, false, true))
continue;
QSharedPointer<XlsxRowInfo> rowInfo;
if ((d->rowsInfo[row]).isNull()){
d->rowsInfo[row] = QSharedPointer<XlsxRowInfo>(new XlsxRowInfo());
}
rowInfoList.append(d->rowsInfo[row]);
}
return rowInfoList;
}
/*!
Groups rows from \a rowFirst to \a rowLast with the given \a collapsed.
@ -2362,17 +2324,17 @@ void WorksheetPrivate::loadXmlSheetFormatProps(QXmlStreamReader &reader)
//Retain default values
foreach (QXmlStreamAttribute attrib, attributes) {
if(attrib.name() == QLatin1String("baseColWidth") ) {
formatProps.baseColWidth = attrib.value().toInt();
formatProps.baseColWidth = attrib.value().toString().toInt();
} else if(attrib.name() == QLatin1String("customHeight")) {
formatProps.customHeight = attrib.value() == QLatin1String("1");
} else if(attrib.name() == QLatin1String("defaultColWidth")) {
formatProps.defaultColWidth = attrib.value().toDouble();
formatProps.defaultColWidth = attrib.value().toString().toDouble();
} else if(attrib.name() == QLatin1String("defaultRowHeight")) {
formatProps.defaultRowHeight = attrib.value().toDouble();
formatProps.defaultRowHeight = attrib.value().toString().toDouble();
} else if(attrib.name() == QLatin1String("outlineLevelCol")) {
formatProps.outlineLevelCol = attrib.value().toInt();
formatProps.outlineLevelCol = attrib.value().toString().toInt();
} else if(attrib.name() == QLatin1String("outlineLevelRow")) {
formatProps.outlineLevelRow = attrib.value().toInt();
formatProps.outlineLevelRow = attrib.value().toString().toInt();
} else if(attrib.name() == QLatin1String("thickBottom")) {
formatProps.thickBottom = attrib.value() == QLatin1String("1");
} else if(attrib.name() == QLatin1String("thickTop")) {
@ -2424,6 +2386,52 @@ void WorksheetPrivate::loadXmlHyperlinks(QXmlStreamReader &reader)
}
}
QList <QSharedPointer<XlsxColumnInfo> > WorksheetPrivate::getColumnInfoList(int colFirst, int colLast)
{
QList <QSharedPointer<XlsxColumnInfo> > columnsInfoList;
if(isColumnRangeValid(colFirst,colLast))
{
QList<int> nodes = getColumnIndexes(colFirst, colLast);
for (int idx = 0; idx < nodes.size(); ++idx) {
int colStart = nodes[idx];
if (colsInfo.contains(colStart)) {
QSharedPointer<XlsxColumnInfo> info = colsInfo[colStart];
columnsInfoList.append(info);
} else {
int colEnd = (idx == nodes.size() - 1) ? colLast : nodes[idx+1] - 1;
QSharedPointer<XlsxColumnInfo> info(new XlsxColumnInfo(colStart, colEnd));
colsInfo.insert(colFirst, info);
columnsInfoList.append(info);
for (int c = colStart; c <= colEnd; ++c)
colsInfoHelper[c] = info;
}
}
}
return columnsInfoList;
}
QList <QSharedPointer<XlsxRowInfo> > WorksheetPrivate::getRowInfoList(int rowFirst, int rowLast)
{
QList <QSharedPointer<XlsxRowInfo> > rowInfoList;
int min_col = dimension.firstColumn() < 0 ? 0 : dimension.firstColumn();
for(int row = rowFirst; row <= rowLast; ++row) {
if (checkDimensions(row, min_col, false, true))
continue;
QSharedPointer<XlsxRowInfo> rowInfo;
if ((rowsInfo[row]).isNull()){
rowsInfo[row] = QSharedPointer<XlsxRowInfo>(new XlsxRowInfo());
}
rowInfoList.append(rowsInfo[row]);
}
return rowInfoList;
}
bool Worksheet::loadFromXmlFile(QIODevice *device)
{
Q_D(Worksheet);

15
src/xlsx/xlsxworksheet.h

@ -101,9 +101,10 @@ public:
bool unmergeCells(const CellRange &range);
QList<CellRange> mergedCells() const;
bool setColumn(int colFirst, int colLast, double width, const Format &format, bool hidden);
bool setColumn(const QString &colFirst, const QString &colLast, double width, const Format &format, bool hidden);
Q_DECL_DEPRECATED
bool setColumn(int colFirst, int colLast, double width, const Format &format=Format(), bool hidden=false);
Q_DECL_DEPRECATED
bool setColumn(const QString &colFirst, const QString &colLast, double width, const Format &format=Format(), bool hidden=false);
bool setColumnWidth(const QString &colFirst, const QString &colLast, double width);
bool setColumnFormat(const QString &colFirst, const QString &colLast, const Format &format);
bool setColumnHidden(const QString &colFirst, const QString &colLast, bool hidden);
@ -114,7 +115,8 @@ public:
Format columnFormat(int column);
bool isColumnHidden(int column);
bool setRow(int rowFirst, int rowLast, double height, const Format &format, bool hidden);
Q_DECL_DEPRECATED
bool setRow(int rowFirst, int rowLast, double height, const Format &format=Format(), bool hidden=false);
bool setRowHeight(int rowFirst,int rowLast, double height);
bool setRowFormat(int rowFirst,int rowLast, const Format &format);
bool setRowHidden(int rowFirst,int rowLast, bool hidden);
@ -161,11 +163,6 @@ private:
void saveToXmlFile(QIODevice *device) const;
bool loadFromXmlFile(QIODevice *device);
QList<QSharedPointer<XlsxRowInfo> > getRowInfoList(int rowFirst, int rowLast);
QList <QSharedPointer<XlsxColumnInfo> > getColumnInfoList(int colFirst, int colLast);
QList<int> getColumnIndexes(int colFirst, int colLast);
bool isColumnRangeValid(int colFirst, int colLast);
};
QT_END_NAMESPACE_XLSX

5
src/xlsx/xlsxworksheet_p.h

@ -177,6 +177,11 @@ public:
void loadXmlSheetViews(QXmlStreamReader &reader);
void loadXmlHyperlinks(QXmlStreamReader &reader);
QList<QSharedPointer<XlsxRowInfo> > getRowInfoList(int rowFirst, int rowLast);
QList <QSharedPointer<XlsxColumnInfo> > getColumnInfoList(int colFirst, int colLast);
QList<int> getColumnIndexes(int colFirst, int colLast);
bool isColumnRangeValid(int colFirst, int colLast);
SharedStrings *sharedStrings() const;
QMap<int, QMap<int, QSharedPointer<Cell> > > cellTable;

Loading…
Cancel
Save