From f841a9b119d5a2530cd24bd759e4baef6e86c3ba Mon Sep 17 00:00:00 2001 From: eho Date: Fri, 14 Mar 2014 11:22:15 +0100 Subject: [PATCH] Cleanup and added comments to new methods. --- src/xlsx/xlsxdocument.cpp | 49 ++++++++++- src/xlsx/xlsxdocument.h | 2 - src/xlsx/xlsxworksheet.cpp | 174 +++++++++++++++++++++++-------------- src/xlsx/xlsxworksheet.h | 3 +- 4 files changed, 159 insertions(+), 69 deletions(-) diff --git a/src/xlsx/xlsxdocument.cpp b/src/xlsx/xlsxdocument.cpp index 0158790..03cc687 100644 --- a/src/xlsx/xlsxdocument.cpp +++ b/src/xlsx/xlsxdocument.cpp @@ -648,15 +648,27 @@ bool Document::isColumnHidden(int column) bool Document::setRow(int row, double height, const Format &format, bool hidden) { if (Worksheet *sheet = currentWorksheet()) - return sheet->setRow(row, height, format, hidden); + return sheet->setRow(row, row, height, format, hidden); return false; } +/*! + Sets the \a format of the row \a row. + Rows are 1-indexed. + + Returns true if success. +*/ bool Document::setRowFormat(int row, const Format &format) { return setRowFormat(row,row, format); } +/*! + Sets the \a format of the rows including and between \a rowFirst and \a rowLast. + Rows are 1-indexed. + + Returns true if success. +*/ bool Document::setRowFormat(int rowFirst, int rowLast, const Format &format) { if (Worksheet *sheet = currentWorksheet()) @@ -664,11 +676,23 @@ bool Document::setRowFormat(int rowFirst, int rowLast, const Format &format) return false; } +/*! + Sets the \a hidden property of the row \a row. + Rows are 1-indexed. If hidden is true rows will not be visible. + + Returns true if success. +*/ bool Document::setRowHidden(int row, bool hidden) { return setRowHidden(row,row,hidden); } +/*! + Sets the \a hidden property of the rows including and between \a rowFirst and \a rowLast. + Rows are 1-indexed. If hidden is true rows will not be visible. + + Returns true if success. +*/ bool Document::setRowHidden(int rowFirst, int rowLast, bool hidden) { if (Worksheet *sheet = currentWorksheet()) @@ -676,11 +700,25 @@ bool Document::setRowHidden(int rowFirst, int rowLast, bool hidden) return false; } +/*! + Sets the \a height of the row \a row. + Row height measured in point size. + Rows are 1-indexed. + + Returns true if success. +*/ bool Document::setRowHeight(int row, double height) { return setRowHeight(row,row,height); } +/*! + Sets the \a height of the rows including and between \a rowFirst and \a rowLast. + Row height measured in point size. + Rows are 1-indexed. + + Returns true if success. +*/ bool Document::setRowHeight(int rowFirst, int rowLast, double height) { if (Worksheet *sheet = currentWorksheet()) @@ -688,6 +726,9 @@ bool Document::setRowHeight(int rowFirst, int rowLast, double height) return false; } +/*! + Returns height of \a row in points. +*/ double Document::rowHeight(int row) { if (Worksheet *sheet = currentWorksheet()) @@ -695,6 +736,9 @@ double Document::rowHeight(int row) return 0.0; // ? } +/*! + Returns format of \a row. +*/ Format Document::rowFormat(int row) { if (Worksheet *sheet = currentWorksheet()) @@ -702,6 +746,9 @@ Format Document::rowFormat(int row) return Format(); // ? } +/*! + Returns true if \a row is hidden. +*/ bool Document::isRowHidden(int row) { if (Worksheet *sheet = currentWorksheet()) diff --git a/src/xlsx/xlsxdocument.h b/src/xlsx/xlsxdocument.h index c3552ea..fa5d7d0 100644 --- a/src/xlsx/xlsxdocument.h +++ b/src/xlsx/xlsxdocument.h @@ -96,8 +96,6 @@ public: Format rowFormat(int row); bool isRowHidden(int row); - - bool groupRows(int rowFirst, int rowLast, bool collapsed = true); bool groupColumns(int colFirst, int colLast, bool collapsed = true); bool addDataValidation(const DataValidation &validation); diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index b8d7a82..95d769d 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -1611,6 +1611,10 @@ bool Worksheet::setColumn(const QString &colFirst, const QString &colLast, doubl return setColumn(col1, col2, width, format, hidden); } +/*! + Sets width in characters of a range of columns. Columns can be specified as "A", "B" ... "Z". + Returns true on success. + */ bool Worksheet::setColumnWidth(const QString &colFirst, const QString &colLast, double width) { int col1 = xl_col_name_to_value(colFirst); @@ -1621,6 +1625,10 @@ bool Worksheet::setColumnWidth(const QString &colFirst, const QString &colLast, return setColumnWidth(col1, col2, width); } +/*! + Sets format property of a range of columns. Columns are 1-indexed. + Returns true on success. + */ bool Worksheet::setColumnFormat(const QString &colFirst, const QString &colLast, const Format &format) { int col1 = xl_col_name_to_value(colFirst); @@ -1631,6 +1639,11 @@ bool Worksheet::setColumnFormat(const QString &colFirst, const QString &colLast, return setColumnFormat(col1, col2, format); } +/*! + Sets hidden property of a range of columns. Columns are 1-indexed. + Hidden columns are not visible. + Returns true on success. + */ bool Worksheet::setColumnHidden(const QString &colFirst, const QString &colLast, bool hidden) { int col1 = xl_col_name_to_value(colFirst); @@ -1641,54 +1654,10 @@ bool Worksheet::setColumnHidden(const QString &colFirst, const QString &colLast, return setColumnHidden(col1, col2, hidden); } -QList > Worksheet::getColumnInfoList(int colFirst, int colLast) -{ - Q_D(Worksheet); - QList > columnsInfoList; - if(isColumnRangeValid(colFirst,colLast)) - { - QList nodes = getColumnIndexes(colFirst, colLast); - - for (int idx = 0; idx < nodes.size(); ++idx) { - int colStart = nodes[idx]; - if (d->colsInfo.contains(colStart)) { - QSharedPointer info = d->colsInfo[colStart]; - columnsInfoList.append(info); - } else { - int colEnd = (idx == nodes.size() - 1) ? colLast : nodes[idx+1] - 1; - QSharedPointer 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 > Worksheet::getRowInfoList(int rowFirst, int rowLast) -{ - Q_D(Worksheet); - QList > 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 rowInfo; - if ((d->rowsInfo[row]).isNull()){ - d->rowsInfo[row] = QSharedPointer(new XlsxRowInfo()); - } - rowInfoList.append(d->rowsInfo[row]); - } - - return rowInfoList; -} - +/*! + Sets width in characters of a range of columns. Columns are 1-indexed. + Returns true on success. + */ bool Worksheet::setColumnWidth(int colFirst, int colLast, double width) { QList > columnInfoList = getColumnInfoList(colFirst, colLast); @@ -1699,6 +1668,9 @@ bool Worksheet::setColumnWidth(int colFirst, int colLast, double width) return (columnInfoList.count() > 0); } +/*! + Sets format property of a range of columns. Columns are 1-indexed. + */ bool Worksheet::setColumnFormat(int colFirst, int colLast, const Format &format) { Q_D(Worksheet); @@ -1716,6 +1688,9 @@ bool Worksheet::setColumnFormat(int colFirst, int colLast, const Format &format) return false; } +/*! + Sets hidden property of a range of columns. Columns are 1-indexed. + */ bool Worksheet::setColumnHidden(int colFirst, int colLast, bool hidden) { QList > columnInfoList = getColumnInfoList(colFirst, colLast); @@ -1726,41 +1701,44 @@ bool Worksheet::setColumnHidden(int colFirst, int colLast, bool hidden) return (columnInfoList.count() > 0); } +/*! + Returns width of the column in characters of the normal font. Columns are 1-indexed. + */ double Worksheet::columnWidth(int column) { Q_D(Worksheet); QList > columnInfoList = getColumnInfoList(column, column); if (columnInfoList.count() == 1) { - qDebug() << "Whoopie Width"; return columnInfoList.at(0)->width ; } - qDebug() << "Default Width"; return d->sheetFormatProps.defaultColWidth; } +/*! + Returns formatting of the column. Columns are 1-indexed. + */ Format Worksheet::columnFormat(int column) { QList > columnInfoList = getColumnInfoList(column, column); if (columnInfoList.count() == 1) { - qDebug() << "Whoopie Format"; return columnInfoList.at(0)->format; } - qDebug() << "Default Format"; return Format(); } +/*! + Returns true if column is hidden. Columns are 1-indexed. + */ bool Worksheet::isColumnHidden(int column) { QList > columnInfoList = getColumnInfoList(column, column); if (columnInfoList.count() == 1) { - qDebug() << "Whoopie Hidden"; return columnInfoList.at(0)->hidden; } - qDebug() << "Default Hidden"; return false; } @@ -1771,11 +1749,6 @@ bool Worksheet::isColumnHidden(int column) Returns true if success. */ -bool Worksheet::setRow(int row, double height, const Format &format, bool hidden) -{ - return setRow(row,row, height, format, hidden); -} - bool Worksheet::setRow(int rowFirst,int rowLast, double height, const Format &format, bool hidden) { Q_D(Worksheet); @@ -1791,6 +1764,13 @@ bool Worksheet::setRow(int rowFirst,int rowLast, double height, const Format &fo return true; } +/*! + Sets the \a height of the rows including and between \a rowFirst and \a rowLast. + Row height measured in point size. + Rows are 1-indexed. + + Returns true if success. +*/ bool Worksheet::setRowHeight(int rowFirst,int rowLast, double height) { QList > rowInfoList = getRowInfoList(rowFirst,rowLast); @@ -1803,6 +1783,12 @@ bool Worksheet::setRowHeight(int rowFirst,int rowLast, double height) return rowInfoList.count() > 0; } +/*! + Sets the \a format of the rows including and between \a rowFirst and \a rowLast. + Rows are 1-indexed. + + Returns true if success. +*/ bool Worksheet::setRowFormat(int rowFirst,int rowLast, const Format &format) { Q_D(Worksheet); @@ -1817,6 +1803,12 @@ bool Worksheet::setRowFormat(int rowFirst,int rowLast, const Format &format) return rowInfoList.count() > 0; } +/*! + Sets the \a hidden proeprty of the rows including and between \a rowFirst and \a rowLast. + Rows are 1-indexed. If hidden is true rows will not be visible. + + Returns true if success. +*/ bool Worksheet::setRowHidden(int rowFirst,int rowLast, bool hidden) { QList > rowInfoList = getRowInfoList(rowFirst,rowLast); @@ -1828,6 +1820,9 @@ bool Worksheet::setRowHidden(int rowFirst,int rowLast, bool hidden) return rowInfoList.count() > 0; } +/*! + Returns height of \a row in points. +*/ double Worksheet::rowHeight(int row) { Q_D(Worksheet); @@ -1839,6 +1834,9 @@ double Worksheet::rowHeight(int row) return d->rowsInfo[row]->height; } +/*! + Returns format of \a row. +*/ Format Worksheet::rowFormat(int row) { Q_D(Worksheet); @@ -1850,6 +1848,9 @@ Format Worksheet::rowFormat(int row) return d->rowsInfo[row]->format; } +/*! + Returns true if \a row is hidden. +*/ bool Worksheet::isRowHidden(int row) { Q_D(Worksheet); @@ -1861,6 +1862,54 @@ bool Worksheet::isRowHidden(int row) return d->rowsInfo[row]->hidden; } +QList > Worksheet::getColumnInfoList(int colFirst, int colLast) +{ + Q_D(Worksheet); + QList > columnsInfoList; + if(isColumnRangeValid(colFirst,colLast)) + { + QList nodes = getColumnIndexes(colFirst, colLast); + + for (int idx = 0; idx < nodes.size(); ++idx) { + int colStart = nodes[idx]; + if (d->colsInfo.contains(colStart)) { + QSharedPointer info = d->colsInfo[colStart]; + columnsInfoList.append(info); + } else { + int colEnd = (idx == nodes.size() - 1) ? colLast : nodes[idx+1] - 1; + QSharedPointer 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 > Worksheet::getRowInfoList(int rowFirst, int rowLast) +{ + Q_D(Worksheet); + QList > 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 rowInfo; + if ((d->rowsInfo[row]).isNull()){ + d->rowsInfo[row] = QSharedPointer(new XlsxRowInfo()); + } + rowInfoList.append(d->rowsInfo[row]); + } + + return rowInfoList; +} + /*! Groups rows from \a rowFirst to \a rowLast with the given \a collapsed. @@ -2204,14 +2253,12 @@ void WorksheetPrivate::loadXmlColumnsInfo(QXmlStreamReader &reader) //Flag indicating that the column width for the affected column(s) is different from the // default or has been manually set if(colAttrs.hasAttribute(QLatin1String("customWidth"))) { - info->customWidth = colAttrs.value(QLatin1String("customWidth")) == QLatin1String("1"); - qDebug() << "Custom width: " << info->customWidth; + info->customWidth = colAttrs.value(QLatin1String("customWidth")) == QLatin1String("1"); } //Note, node may have "width" without "customWidth" if (colAttrs.hasAttribute(QLatin1String("width"))) { double width = colAttrs.value(QLatin1String("width")).toString().toDouble(); info->width = width; - qDebug() << "Width: " << info->width; } info->hidden = colAttrs.value(QLatin1String("hidden")) == QLatin1String("1"); @@ -2384,8 +2431,7 @@ bool Worksheet::loadFromXmlFile(QIODevice *device) QXmlStreamReader reader(device); while (!reader.atEnd()) { reader.readNextStartElement(); - if (reader.tokenType() == QXmlStreamReader::StartElement) { - qDebug() << "TOKEN: " << reader.name(); + if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("dimension")) { QXmlStreamAttributes attributes = reader.attributes(); QString range = attributes.value(QLatin1String("ref")).toString(); diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index 96004f0..7c91e05 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -115,15 +115,14 @@ public: bool isColumnHidden(int column); bool setRow(int rowFirst, int rowLast, double height, const Format &format, bool hidden); - bool setRow(int row, double height, const Format &format, bool hidden); 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); + double rowHeight(int row); Format rowFormat(int row); bool isRowHidden(int row); - bool groupRows(int rowFirst, int rowLast, bool collapsed = true); bool groupColumns(int colFirst, int colLast, bool collapsed = true); bool groupColumns(const QString &colFirst, const QString &colLast, bool collapsed = true);