diff --git a/src/xlsx/xlsxdocument.cpp b/src/xlsx/xlsxdocument.cpp index 03cc687..eb07fce 100644 --- a/src/xlsx/xlsxdocument.cpp +++ b/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; } /*! diff --git a/src/xlsx/xlsxdocument.h b/src/xlsx/xlsxdocument.h index fa5d7d0..1e2bad3 100644 --- a/src/xlsx/xlsxdocument.h +++ b/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); diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index 95d769d..6001199 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/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 Worksheet::getColumnIndexes(int colFirst, int colLast) +QList WorksheetPrivate ::getColumnIndexes(int colFirst, int colLast) { - Q_D(Worksheet); - - d->splitColsInfo(colFirst, colLast); + splitColsInfo(colFirst, colLast); QList 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 > columnInfoList = getColumnInfoList(colFirst, colLast); + QList > columnInfoList = d->getColumnInfoList(colFirst, colLast); foreach(QSharedPointer 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 > columnInfoList = getColumnInfoList(colFirst, colLast); + Q_D(Worksheet); + + QList > columnInfoList = d->getColumnInfoList(colFirst, colLast); foreach(QSharedPointer columnInfo, columnInfoList) { columnInfo->width = width; } @@ -1675,7 +1674,7 @@ bool Worksheet::setColumnFormat(int colFirst, int colLast, const Format &format) { Q_D(Worksheet); - QList > columnInfoList = getColumnInfoList(colFirst, colLast); + QList > columnInfoList = d->getColumnInfoList(colFirst, colLast); foreach(QSharedPointer 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 > columnInfoList = getColumnInfoList(colFirst, colLast); + Q_D(Worksheet); + + QList > columnInfoList = d->getColumnInfoList(colFirst, colLast); foreach(QSharedPointer columnInfo, columnInfoList) { columnInfo->hidden = hidden; } @@ -1708,7 +1709,7 @@ double Worksheet::columnWidth(int column) { Q_D(Worksheet); - QList > columnInfoList = getColumnInfoList(column, column); + QList > 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 > columnInfoList = getColumnInfoList(column, column); + Q_D(Worksheet); + + QList > 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 > columnInfoList = getColumnInfoList(column, column); + Q_D(Worksheet); + + QList > 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 > rowInfoList = getRowInfoList(rowFirst,rowLast); + + QList > rowInfoList = d->getRowInfoList(rowFirst,rowLast); foreach(QSharedPointer 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 > rowInfoList = getRowInfoList(rowFirst,rowLast); +{ + Q_D(Worksheet); + + QList > rowInfoList = d->getRowInfoList(rowFirst,rowLast); foreach(QSharedPointer rowInfo, rowInfoList) { rowInfo->height = height; @@ -1793,7 +1801,7 @@ bool Worksheet::setRowFormat(int rowFirst,int rowLast, const Format &format) { Q_D(Worksheet); - QList > rowInfoList = getRowInfoList(rowFirst,rowLast); + QList > rowInfoList = d->getRowInfoList(rowFirst,rowLast); foreach(QSharedPointer 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 > rowInfoList = getRowInfoList(rowFirst,rowLast); + Q_D(Worksheet); + + QList > rowInfoList = d->getRowInfoList(rowFirst,rowLast); foreach(QSharedPointer rowInfo, rowInfoList) { rowInfo->hidden = hidden; @@ -1862,54 +1872,6 @@ 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. @@ -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 > WorksheetPrivate::getColumnInfoList(int colFirst, int colLast) +{ + QList > columnsInfoList; + if(isColumnRangeValid(colFirst,colLast)) + { + QList nodes = getColumnIndexes(colFirst, colLast); + + for (int idx = 0; idx < nodes.size(); ++idx) { + int colStart = nodes[idx]; + if (colsInfo.contains(colStart)) { + QSharedPointer info = colsInfo[colStart]; + columnsInfoList.append(info); + } else { + int colEnd = (idx == nodes.size() - 1) ? colLast : nodes[idx+1] - 1; + QSharedPointer 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 > WorksheetPrivate::getRowInfoList(int rowFirst, int rowLast) +{ + QList > 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 rowInfo; + if ((rowsInfo[row]).isNull()){ + rowsInfo[row] = QSharedPointer(new XlsxRowInfo()); + } + rowInfoList.append(rowsInfo[row]); + } + + return rowInfoList; +} + bool Worksheet::loadFromXmlFile(QIODevice *device) { Q_D(Worksheet); diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index 7c91e05..17214cb 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -101,9 +101,10 @@ public: bool unmergeCells(const CellRange &range); QList 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 > getRowInfoList(int rowFirst, int rowLast); - QList > getColumnInfoList(int colFirst, int colLast); - QList getColumnIndexes(int colFirst, int colLast); - bool isColumnRangeValid(int colFirst, int colLast); }; QT_END_NAMESPACE_XLSX diff --git a/src/xlsx/xlsxworksheet_p.h b/src/xlsx/xlsxworksheet_p.h index 870003d..0599167 100644 --- a/src/xlsx/xlsxworksheet_p.h +++ b/src/xlsx/xlsxworksheet_p.h @@ -177,6 +177,11 @@ public: void loadXmlSheetViews(QXmlStreamReader &reader); void loadXmlHyperlinks(QXmlStreamReader &reader); + QList > getRowInfoList(int rowFirst, int rowLast); + QList > getColumnInfoList(int colFirst, int colLast); + QList getColumnIndexes(int colFirst, int colLast); + bool isColumnRangeValid(int colFirst, int colLast); + SharedStrings *sharedStrings() const; QMap > > cellTable;