diff --git a/QXlsx/header/xlsxdocument.h b/QXlsx/header/xlsxdocument.h index 99004e64..492f1a6b 100644 --- a/QXlsx/header/xlsxdocument.h +++ b/QXlsx/header/xlsxdocument.h @@ -81,8 +81,8 @@ class QXLSX_EXPORT Document : public QObject bool addDataValidation(const DataValidation &validation); bool addConditionalFormatting(const ConditionalFormatting &cf); - Cell *cellAt(const CellReference &cell) const; - Cell *cellAt(int row, int col) const; + std::shared_ptr cellAt(const CellReference &cell) const; + std::shared_ptr cellAt(int row, int col) const; bool defineName(const QString &name, const QString &formula, diff --git a/QXlsx/header/xlsxdocument_p.h b/QXlsx/header/xlsxdocument_p.h index 9f6a647b..ca00aaa5 100644 --- a/QXlsx/header/xlsxdocument_p.h +++ b/QXlsx/header/xlsxdocument_p.h @@ -32,7 +32,7 @@ class DocumentPrivate QString packageName; // name of the .xlsx file QMap documentProperties; // core, app and custom properties - QSharedPointer workbook; + std::shared_ptr workbook; std::shared_ptr contentTypes; bool isLoad; }; diff --git a/QXlsx/header/xlsxdrawinganchor_p.h b/QXlsx/header/xlsxdrawinganchor_p.h index a876da54..3b933caf 100644 --- a/QXlsx/header/xlsxdrawinganchor_p.h +++ b/QXlsx/header/xlsxdrawinganchor_p.h @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -49,7 +48,7 @@ class DrawingAnchor void setObjectPicture(const QImage &img); bool getObjectPicture(QImage &img); - void setObjectGraphicFrame(QSharedPointer chart); + void setObjectGraphicFrame(std::shared_ptr chart); virtual bool loadFromXml(QXmlStreamReader &reader) = 0; virtual void saveToXml(QXmlStreamWriter &writer) const = 0; @@ -83,7 +82,7 @@ class DrawingAnchor Drawing *m_drawing; ObjectType m_objectType; std::shared_ptr m_pictureFile; - QSharedPointer m_chartFile; + std::shared_ptr m_chartFile; int m_id; diff --git a/QXlsx/header/xlsxstyles_p.h b/QXlsx/header/xlsxstyles_p.h index 77c68abb..7c1c0ba8 100644 --- a/QXlsx/header/xlsxstyles_p.h +++ b/QXlsx/header/xlsxstyles_p.h @@ -36,11 +36,12 @@ // We mean it. // +#include + #include #include #include #include -#include #include #include #include @@ -124,8 +125,8 @@ class Styles : public AbstractOOXmlFile bool readCellStyleXfs(QXmlStreamReader &reader); QHash m_builtinNumFmtsHash; - QMap> m_customNumFmtIdMap; - QHash> m_customNumFmtsHash; + QMap> m_customNumFmtIdMap; + QHash> m_customNumFmtsHash; int m_nextCustomNumFmtId; QList m_fontsList; QList m_fillsList; diff --git a/QXlsx/header/xlsxworkbook.h b/QXlsx/header/xlsxworkbook.h index 22e8e8bc..9ad3641c 100644 --- a/QXlsx/header/xlsxworkbook.h +++ b/QXlsx/header/xlsxworkbook.h @@ -12,7 +12,6 @@ #include #include #include -#include QT_BEGIN_NAMESPACE_XLSX @@ -70,8 +69,8 @@ class QXLSX_EXPORT Workbook : public AbstractOOXmlFile // internal used member void addMediaFile(std::shared_ptr media, bool force = false); QList> mediaFiles() const; - void addChartFile(QSharedPointer chartFile); - QList> chartFiles() const; + void addChartFile(std::shared_ptr chartFile); + QList> chartFiles() const; private: friend class Worksheet; @@ -90,7 +89,7 @@ class QXLSX_EXPORT Workbook : public AbstractOOXmlFile Theme *theme(); QList images(); QList drawings(); - QList> getSheetsByTypes(AbstractSheet::SheetType type) const; + QList> getSheetsByTypes(AbstractSheet::SheetType type) const; QStringList worksheetNames() const; AbstractSheet *addSheet(const QString &name, int sheetId, diff --git a/QXlsx/header/xlsxworkbook_p.h b/QXlsx/header/xlsxworkbook_p.h index 32abcbf9..19ae8584 100644 --- a/QXlsx/header/xlsxworkbook_p.h +++ b/QXlsx/header/xlsxworkbook_p.h @@ -9,7 +9,6 @@ #include "xlsxtheme_p.h" #include "xlsxworkbook.h" -#include #include QT_BEGIN_NAMESPACE_XLSX @@ -42,14 +41,14 @@ class WorkbookPrivate : public AbstractOOXmlFilePrivate public: WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag); - QSharedPointer sharedStrings; - QList> sheets; - QList> externalLinks; + std::shared_ptr sharedStrings; + QList> sheets; + QList> externalLinks; QStringList sheetNames; - QSharedPointer styles; - QSharedPointer theme; + std::shared_ptr styles; + std::shared_ptr theme; QList> mediaFiles; - QList> chartFiles; + QList> chartFiles; QList definedNamesList; bool strings_to_numbers_enabled; diff --git a/QXlsx/header/xlsxworksheet.h b/QXlsx/header/xlsxworksheet.h index 13774eef..cdeb0f1b 100644 --- a/QXlsx/header/xlsxworksheet.h +++ b/QXlsx/header/xlsxworksheet.h @@ -126,8 +126,8 @@ class QXLSX_EXPORT Worksheet : public AbstractSheet bool addDataValidation(const DataValidation &validation); bool addConditionalFormatting(const ConditionalFormatting &cf); - Cell *cellAt(const CellReference &row_column) const; - Cell *cellAt(int row, int column) const; + std::shared_ptr cellAt(const CellReference &row_column) const; + std::shared_ptr cellAt(int row, int column) const; int insertImage(int row, int column, const QImage &image); bool getImage(int imageIndex, QImage &img); diff --git a/QXlsx/header/xlsxworksheet_p.h b/QXlsx/header/xlsxworksheet_p.h index 7e32df90..ee784da7 100644 --- a/QXlsx/header/xlsxworksheet_p.h +++ b/QXlsx/header/xlsxworksheet_p.h @@ -10,13 +10,12 @@ #include "xlsxdatavalidation.h" #include "xlsxworksheet.h" +#include #include #include #include -#include #include #include -#include class QXmlStreamWriter; class QXmlStreamReader; @@ -136,30 +135,35 @@ struct XlsxColumnInfo { class CellTable { public: - static QList sorteIntList(QList &&keys) { + static QList sorteIntList(QList &&keys) + { std::sort(keys.begin(), keys.end()); return keys; } - inline QList sortedRows() const { + inline QList sortedRows() const + { QList keys = cells.keys(); std::sort(keys.begin(), keys.end()); return keys; } - void setValue(int row, int column, const std::shared_ptr &cell) { + void setValue(int row, int column, const std::shared_ptr &cell) + { cells[row].insert(column, cell); - firstRow = qMin(firstRow, row); + firstRow = qMin(firstRow, row); firstColumn = qMin(firstColumn, column); - lastRow = qMin(lastRow, row); - lastColumn = qMin(lastColumn, column); + lastRow = qMin(lastRow, row); + lastColumn = qMin(lastColumn, column); } - std::shared_ptr cellAt(int row, int column) const{ + std::shared_ptr cellAt(int row, int column) const + { return cells.value(row).value(column); } - bool contains(int row, int column) const{ + bool contains(int row, int column) const + { auto it = cells.find(row); if (it != cells.end()) { return it->contains(column); @@ -167,17 +171,15 @@ class CellTable return false; } - bool isEmpty() const { - return cells.isEmpty(); - } + bool isEmpty() const { return cells.isEmpty(); } // It's faster with a single QHash, but in Qt5 it's capacity limits // how much cells we can hold QHash>> cells; - int firstRow = -1; + int firstRow = -1; int firstColumn = -1; - int lastRow = -1; - int lastColumn = -1; + int lastRow = -1; + int lastColumn = -1; }; class WorksheetPrivate : public AbstractSheetPrivate @@ -217,8 +219,8 @@ class WorksheetPrivate : public AbstractSheetPrivate void loadXmlSheetViews(QXmlStreamReader &reader); void loadXmlHyperlinks(QXmlStreamReader &reader); - QList> getRowInfoList(int rowFirst, int rowLast); - QList> getColumnInfoList(int colFirst, int colLast); + QList> getRowInfoList(int rowFirst, int rowLast); + QList> getColumnInfoList(int colFirst, int colLast); QList getColumnIndexes(int colFirst, int colLast); bool isColumnRangeValid(int colFirst, int colLast); @@ -228,11 +230,11 @@ class WorksheetPrivate : public AbstractSheetPrivate CellTable cellTable; QHash> comments; - QHash>> urlTable; + QHash>> urlTable; QList merges; - QHash> rowsInfo; - QHash> colsInfo; - QHash> colsInfoHelper; + QHash> rowsInfo; + QHash> colsInfo; + QHash> colsInfoHelper; QList dataValidationsList; QList conditionalFormattingList; diff --git a/QXlsx/source/xlsxchartsheet.cpp b/QXlsx/source/xlsxchartsheet.cpp index 733d5aae..ea743d0e 100644 --- a/QXlsx/source/xlsxchartsheet.cpp +++ b/QXlsx/source/xlsxchartsheet.cpp @@ -48,11 +48,11 @@ Chartsheet::Chartsheet(const QString &name, int id, Workbook *workbook, CreateFl anchor->pos = QPoint(0, 0); anchor->ext = QSize(9293679, 6068786); - QSharedPointer chart = QSharedPointer(new Chart(this, flag)); + auto chart = std::shared_ptr(new Chart(this, flag)); chart->setChartType(Chart::CT_BarChart); anchor->setObjectGraphicFrame(chart); - d_func()->chart = chart.data(); + d_func()->chart = chart.get(); } } diff --git a/QXlsx/source/xlsxdocument.cpp b/QXlsx/source/xlsxdocument.cpp index f0cef3f9..f5987f1a 100644 --- a/QXlsx/source/xlsxdocument.cpp +++ b/QXlsx/source/xlsxdocument.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include /* @@ -163,8 +162,8 @@ void DocumentPrivate::init() if (!contentTypes) contentTypes = std::make_shared(ContentTypes::F_NewFromScratch); - if (workbook.isNull()) - workbook = QSharedPointer(new Workbook(Workbook::F_NewFromScratch)); + if (!workbook) + workbook = std::shared_ptr(new Workbook(Workbook::F_NewFromScratch)); } bool DocumentPrivate::loadPackage(QIODevice *device) @@ -217,7 +216,7 @@ bool DocumentPrivate::loadPackage(QIODevice *device) // load workbook now, Get the workbook file path from the root rels file // In normal case, this should be "xl/workbook.xml" - workbook = QSharedPointer(new Workbook(Workbook::F_LoadFromExists)); + workbook = std::shared_ptr(new Workbook(Workbook::F_LoadFromExists)); QList rels_xl = rootRels.documentRelationships(QStringLiteral("/officeDocument")); if (rels_xl.isEmpty()) @@ -247,7 +246,7 @@ bool DocumentPrivate::loadPackage(QIODevice *device) path = xlworkbook_Dir + QLatin1String("/") + name; } - QSharedPointer styles(new Styles(Styles::F_LoadFromExists)); + std::shared_ptr styles(new Styles(Styles::F_LoadFromExists)); styles->loadFromXmlData(zipReader.fileData(path)); workbook->d_func()->styles = styles; } @@ -285,7 +284,7 @@ bool DocumentPrivate::loadPackage(QIODevice *device) // load external links for (int i = 0; i < workbook->d_func()->externalLinks.count(); ++i) { - SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data(); + SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].get(); QString rel_path = getRelFilePath(link->filePath()); // If the .rel file exists, load it. if (zipReader.filePaths().contains(rel_path)) @@ -303,9 +302,9 @@ bool DocumentPrivate::loadPackage(QIODevice *device) } // load charts - QList> chartFileToLoad = workbook->chartFiles(); + QList> chartFileToLoad = workbook->chartFiles(); for (int i = 0; i < chartFileToLoad.size(); ++i) { - QSharedPointer cf = chartFileToLoad[i]; + std::shared_ptr cf = chartFileToLoad[i]; cf->loadFromXmlData(zipReader.fileData(cf->filePath())); } @@ -335,13 +334,13 @@ bool DocumentPrivate::savePackage(QIODevice *device) const DocPropsCore docPropsCore(DocPropsCore::F_NewFromScratch); // save worksheet xml files - QList> worksheets = + QList> worksheets = workbook->getSheetsByTypes(AbstractSheet::ST_WorkSheet); if (!worksheets.isEmpty()) docPropsApp.addHeadingPair(QStringLiteral("Worksheets"), worksheets.size()); for (int i = 0; i < worksheets.size(); ++i) { - QSharedPointer sheet = worksheets[i]; + std::shared_ptr sheet = worksheets[i]; contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i + 1)); docPropsApp.addPartTitle(sheet->sheetName()); @@ -355,12 +354,12 @@ bool DocumentPrivate::savePackage(QIODevice *device) const } // save chartsheet xml files - QList> chartsheets = + QList> chartsheets = workbook->getSheetsByTypes(AbstractSheet::ST_ChartSheet); if (!chartsheets.isEmpty()) docPropsApp.addHeadingPair(QStringLiteral("Chartsheets"), chartsheets.size()); for (int i = 0; i < chartsheets.size(); ++i) { - QSharedPointer sheet = chartsheets[i]; + std::shared_ptr sheet = chartsheets[i]; contentTypes->addWorksheetName(QStringLiteral("sheet%1").arg(i + 1)); docPropsApp.addPartTitle(sheet->sheetName()); @@ -374,7 +373,7 @@ bool DocumentPrivate::savePackage(QIODevice *device) const // save external links xml files for (int i = 0; i < workbook->d_func()->externalLinks.count(); ++i) { - SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].data(); + SimpleOOXmlFile *link = workbook->d_func()->externalLinks[i].get(); contentTypes->addExternalLinkName(QStringLiteral("externalLink%1").arg(i + 1)); zipWriter.addFile(QStringLiteral("xl/externalLinks/externalLink%1.xml").arg(i + 1), @@ -437,7 +436,7 @@ bool DocumentPrivate::savePackage(QIODevice *device) const // save chart xml files for (int i = 0; i < workbook->chartFiles().size(); ++i) { contentTypes->addChartName(QStringLiteral("chart%1").arg(i + 1)); - QSharedPointer cf = workbook->chartFiles()[i]; + std::shared_ptr cf = workbook->chartFiles()[i]; zipWriter.addFile(QStringLiteral("xl/charts/chart%1.xml").arg(i + 1), cf->saveToXmlData()); } @@ -573,7 +572,7 @@ bool DocumentPrivate::copyStyle(const QString &from, const QString &to) ZipReader zipReader(from); QStringList filePaths = zipReader.filePaths(); - QSharedPointer toReader = QSharedPointer(new ZipReader(to)); + std::shared_ptr toReader = std::shared_ptr(new ZipReader(to)); QStringList toFilePaths = toReader->filePaths(); @@ -628,7 +627,7 @@ bool DocumentPrivate::copyStyle(const QString &from, const QString &to) temporalZip.close(); - toReader.clear(); + toReader.reset(); tempFile.close(); @@ -1098,7 +1097,7 @@ bool Document::addConditionalFormatting(const ConditionalFormatting &cf) * * \sa read() */ -Cell *Document::cellAt(const CellReference &pos) const +std::shared_ptr Document::cellAt(const CellReference &pos) const { if (Worksheet *sheet = currentWorksheet()) return sheet->cellAt(pos); @@ -1111,11 +1110,11 @@ Cell *Document::cellAt(const CellReference &pos) const * * \sa read() */ -Cell *Document::cellAt(int row, int col) const +std::shared_ptr Document::cellAt(int row, int col) const { if (Worksheet *sheet = currentWorksheet()) return sheet->cellAt(row, col); - return nullptr; + return {}; } /*! @@ -1203,7 +1202,7 @@ QStringList Document::documentPropertyNames() const Workbook *Document::workbook() const { Q_D(const Document); - return d->workbook.data(); + return d->workbook.get(); } /*! diff --git a/QXlsx/source/xlsxdrawinganchor.cpp b/QXlsx/source/xlsxdrawinganchor.cpp index 14e71792..30f294da 100644 --- a/QXlsx/source/xlsxdrawinganchor.cpp +++ b/QXlsx/source/xlsxdrawinganchor.cpp @@ -99,7 +99,7 @@ void DrawingAnchor::setObjectShape(const QImage &img) } //}} -void DrawingAnchor::setObjectGraphicFrame(QSharedPointer chart) +void DrawingAnchor::setObjectGraphicFrame(std::shared_ptr chart) { m_chartFile = chart; m_drawing->workbook->addChartFile(chart); @@ -341,8 +341,8 @@ void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader) const auto parts = splitPath(m_drawing->filePath()); QString path = QDir::cleanPath(parts.first() + QLatin1String("/") + name); - bool exist = false; - QList> cfs = m_drawing->workbook->chartFiles(); + bool exist = false; + QList> cfs = m_drawing->workbook->chartFiles(); for (int i = 0; i < cfs.size(); ++i) { if (cfs[i]->filePath() == path) { // already exist @@ -351,8 +351,8 @@ void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader) } } if (!exist) { - m_chartFile = - QSharedPointer(new Chart(m_drawing->sheet, Chart::F_LoadFromExists)); + m_chartFile = std::shared_ptr( + new Chart(m_drawing->sheet, Chart::F_LoadFromExists)); m_chartFile->setFilePath(path); m_drawing->workbook->addChartFile(m_chartFile); } @@ -475,7 +475,7 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) rId=sp_blip_rembed; QString name = m_drawing->relationships()->getRelationshipById(rId).target; QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + - QLatin1String("/") + name); bool exist = false; QList > mfs = + QLatin1String("/") + name); bool exist = false; QList > mfs = m_drawing->workbook->mediaFiles(); for (int i=0; ifileName() == path) @@ -486,7 +486,7 @@ void DrawingAnchor::loadXmlObjectShape(QXmlStreamReader &reader) } } if (!exist) { - m_pictureFile = QSharedPointer (new MediaFile(path)); + m_pictureFile = std::shared_ptr (new MediaFile(path)); m_drawing->workbook->addMediaFile(m_pictureFile, true); } } diff --git a/QXlsx/source/xlsxstyles.cpp b/QXlsx/source/xlsxstyles.cpp index 2695e8b9..e4247f7a 100644 --- a/QXlsx/source/xlsxstyles.cpp +++ b/QXlsx/source/xlsxstyles.cpp @@ -148,7 +148,7 @@ void Styles::fixNumFmt(const Format &format) const auto &str = format.numberFormat(); if (!str.isEmpty()) { - QHash>::ConstIterator cIt; + QHash>::ConstIterator cIt; // Assign proper number format index const auto &it = m_builtinNumFmtsHash.constFind(str); if (it != m_builtinNumFmtsHash.constEnd()) { @@ -159,7 +159,7 @@ void Styles::fixNumFmt(const Format &format) // Assign a new fmt Id. const_cast(&format)->fixNumberFormat(m_nextCustomNumFmtId, str); - QSharedPointer fmt(new XlsxFormatNumberData); + auto fmt = std::make_shared(); fmt->formatIndex = m_nextCustomNumFmtId; fmt->formatString = str; m_customNumFmtIdMap.insert(m_nextCustomNumFmtId, fmt); @@ -356,7 +356,7 @@ void Styles::writeNumFmts(QXmlStreamWriter &writer) const writer.writeStartElement(QStringLiteral("numFmts")); writer.writeAttribute(QStringLiteral("count"), QString::number(m_customNumFmtIdMap.count())); - QMapIterator> it(m_customNumFmtIdMap); + QMapIterator> it(m_customNumFmtIdMap); while (it.hasNext()) { it.next(); writer.writeEmptyElement(QStringLiteral("numFmt")); @@ -779,9 +779,9 @@ bool Styles::readNumFmts(QXmlStreamReader &reader) if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("numFmt")) { const auto &attributes = reader.attributes(); - QSharedPointer fmt(new XlsxFormatNumberData); - fmt->formatIndex = attributes.value(QLatin1String("numFmtId")).toInt(); - fmt->formatString = attributes.value(QLatin1String("formatCode")).toString(); + auto fmt = std::make_shared(); + fmt->formatIndex = attributes.value(QLatin1String("numFmtId")).toInt(); + fmt->formatString = attributes.value(QLatin1String("formatCode")).toString(); if (fmt->formatIndex >= m_nextCustomNumFmtId) m_nextCustomNumFmtId = fmt->formatIndex + 1; m_customNumFmtIdMap.insert(fmt->formatIndex, fmt); diff --git a/QXlsx/source/xlsxworkbook.cpp b/QXlsx/source/xlsxworkbook.cpp index 650dc298..39a0981f 100644 --- a/QXlsx/source/xlsxworkbook.cpp +++ b/QXlsx/source/xlsxworkbook.cpp @@ -26,9 +26,9 @@ QT_BEGIN_NAMESPACE_XLSX WorkbookPrivate::WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag) : AbstractOOXmlFilePrivate(q, flag) { - sharedStrings = QSharedPointer(new SharedStrings(flag)); - styles = QSharedPointer(new Styles(flag)); - theme = QSharedPointer(new Theme(flag)); + sharedStrings = std::make_shared(flag); + styles = std::make_shared(flag); + theme = std::make_shared(flag); x_window = 240; y_window = 15; @@ -206,7 +206,7 @@ AbstractSheet *Workbook::addSheet(const QString &name, int sheetId, AbstractShee Q_ASSERT(false); } - d->sheets.append(QSharedPointer(sheet)); + d->sheets.append(std::shared_ptr(sheet)); d->sheetNames.append(name); return sheet; @@ -253,7 +253,7 @@ AbstractSheet *Workbook::insertSheet(int index, const QString &name, AbstractShe Q_ASSERT(false); } - d->sheets.insert(index, QSharedPointer(sheet)); + d->sheets.insert(index, std::shared_ptr(sheet)); d->sheetNames.insert(index, sheetName); d->activesheetIndex = index; @@ -268,7 +268,7 @@ AbstractSheet *Workbook::activeSheet() const Q_D(const Workbook); if (d->sheets.isEmpty()) const_cast(this)->addSheet(); - return d->sheets[d->activesheetIndex].data(); + return d->sheets[d->activesheetIndex].get(); } bool Workbook::setActiveSheet(int index) @@ -330,7 +330,7 @@ bool Workbook::moveSheet(int srcIndex, int distIndex) if (srcIndex < 0 || srcIndex >= d->sheets.size()) return false; - QSharedPointer sheet = d->sheets.takeAt(srcIndex); + std::shared_ptr sheet = d->sheets.takeAt(srcIndex); d->sheetNames.takeAt(srcIndex); if (distIndex >= 0 || distIndex <= d->sheets.size()) { d->sheets.insert(distIndex, sheet); @@ -364,7 +364,7 @@ bool Workbook::copySheet(int index, const QString &newName) ++d->last_sheet_id; AbstractSheet *sheet = d->sheets[index]->copy(worksheetName, d->last_sheet_id); - d->sheets.append(QSharedPointer(sheet)); + d->sheets.append(std::shared_ptr(sheet)); d->sheetNames.append(sheet->sheetName()); return true; // #162 @@ -387,25 +387,25 @@ AbstractSheet *Workbook::sheet(int index) const Q_D(const Workbook); if (index < 0 || index >= d->sheets.size()) return nullptr; - return d->sheets.at(index).data(); + return d->sheets.at(index).get(); } SharedStrings *Workbook::sharedStrings() const { Q_D(const Workbook); - return d->sharedStrings.data(); + return d->sharedStrings.get(); } Styles *Workbook::styles() { Q_D(Workbook); - return d->styles.data(); + return d->styles.get(); } Theme *Workbook::theme() { Q_D(Workbook); - return d->theme.data(); + return d->theme.get(); } /*! @@ -418,7 +418,7 @@ QList Workbook::drawings() Q_D(Workbook); QList ds; for (int i = 0; i < d->sheets.size(); ++i) { - QSharedPointer sheet = d->sheets[i]; + std::shared_ptr sheet = d->sheets[i]; if (sheet->drawing()) ds.append(sheet->drawing()); } @@ -429,10 +429,11 @@ QList Workbook::drawings() /*! * \internal */ -QList> Workbook::getSheetsByTypes(AbstractSheet::SheetType type) const +QList> + Workbook::getSheetsByTypes(AbstractSheet::SheetType type) const { Q_D(const Workbook); - QList> list; + QList> list; for (int i = 0; i < d->sheets.size(); ++i) { if (d->sheets[i]->sheetType() == type) list.append(d->sheets[i]); @@ -490,7 +491,7 @@ void Workbook::saveToXmlFile(QIODevice *device) const int worksheetIndex = 0; int chartsheetIndex = 0; for (int i = 0; i < d->sheets.size(); ++i) { - QSharedPointer sheet = d->sheets[i]; + std::shared_ptr sheet = d->sheets[i]; writer.writeEmptyElement(QStringLiteral("sheet")); writer.writeAttribute(QStringLiteral("name"), sheet->sheetName()); writer.writeAttribute(QStringLiteral("sheetId"), QString::number(sheet->sheetId())); @@ -653,7 +654,7 @@ bool Workbook::loadFromXmlFile(QIODevice *device) const QString rId = attributes.value(QLatin1String("r:id")).toString(); XlsxRelationship relationship = d->relationships->getRelationshipById(rId); - QSharedPointer link(new SimpleOOXmlFile(F_LoadFromExists)); + std::shared_ptr link(new SimpleOOXmlFile(F_LoadFromExists)); const auto parts = splitPath(filePath()); QString fullPath = @@ -714,7 +715,7 @@ void Workbook::addMediaFile(std::shared_ptr media, bool force) /*! * \internal */ -QList> Workbook::chartFiles() const +QList> Workbook::chartFiles() const { Q_D(const Workbook); @@ -724,7 +725,7 @@ QList> Workbook::chartFiles() const /*! * \internal */ -void Workbook::addChartFile(QSharedPointer chart) +void Workbook::addChartFile(std::shared_ptr chart) { Q_D(Workbook); diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index 804a4015..cebeb18b 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -75,8 +75,7 @@ void WorksheetPrivate::calculateSpans() const int span_max = -1; for (int row_num = dimension.firstRow(); row_num <= dimension.lastRow(); row_num++) { - for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn(); - col_num++) { + for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn(); col_num++) { if (cellTable.contains(row_num, col_num)) { if (span_max == -1) { span_min = col_num; @@ -511,7 +510,7 @@ QVariant Worksheet::read(int row, int column) const { Q_D(const Worksheet); - Cell *cell = cellAt(row, column); + auto cell = cellAt(row, column); if (!cell) return QVariant(); @@ -545,10 +544,10 @@ QVariant Worksheet::read(int row, int column) const * Returns the cell at the given \a row_column. If there * is no cell at the specified position, the function returns 0. */ -Cell *Worksheet::cellAt(const CellReference &row_column) const +std::shared_ptr Worksheet::cellAt(const CellReference &row_column) const { if (!row_column.isValid()) - return nullptr; + return {}; return cellAt(row_column.row(), row_column.column()); } @@ -557,10 +556,10 @@ Cell *Worksheet::cellAt(const CellReference &row_column) const * Returns the cell at the given \a row and \a column. If there * is no cell at the specified position, the function returns 0. */ -Cell *Worksheet::cellAt(int row, int col) const +std::shared_ptr Worksheet::cellAt(int row, int col) const { Q_D(const Worksheet); - return d->cellTable.cellAt(row, col).get(); + return d->cellTable.cellAt(row, col); } Format WorksheetPrivate::cellFormat(int row, int col) const @@ -611,7 +610,7 @@ bool Worksheet::writeString(int row, int column, const RichString &value, const fmt.mergeFormat(value.fragmentFormat(0)); d->workbook->styles()->addXfFormat(fmt); auto cell = std::make_shared(value.toPlainString(), Cell::SharedStringType, fmt, this); - cell->d_ptr->richString = value; + cell->d_ptr->richString = value; d->cellTable.setValue(row, column, cell); return true; } @@ -767,8 +766,8 @@ bool Worksheet::writeFormula(int row, d->sharedFormulaMap[si] = formula; } - auto data = std::make_shared(result, Cell::NumberType, fmt, this); - data->d_ptr->formula = formula; + auto data = std::make_shared(result, Cell::NumberType, fmt, this); + data->d_ptr->formula = formula; d->cellTable.setValue(row, column, data); CellRange range = formula.reference(); @@ -778,7 +777,7 @@ bool Worksheet::writeFormula(int row, for (int r = range.firstRow(); r <= range.lastRow(); ++r) { for (int c = range.firstColumn(); c <= range.lastColumn(); ++c) { if (!(r == row && c == column)) { - if (Cell *cell = cellAt(r, c)) { + if (auto cell = cellAt(r, c)) { cell->d_ptr->formula = sf; } else { auto newCell = std::make_shared(result, Cell::NumberType, fmt, this); @@ -1032,7 +1031,7 @@ bool Worksheet::writeHyperlink(int row, d->cellTable.setValue(row, column, cell); // Store the hyperlink data in a separate table - d->urlTable[row][column] = QSharedPointer(new XlsxHyperlinkData( + d->urlTable[row][column] = std::shared_ptr(new XlsxHyperlinkData( XlsxHyperlinkData::External, urlString, locationString, QString(), tip)); return true; @@ -1123,7 +1122,7 @@ bool Worksheet::getImage(int imageIndex, QImage &img) int realImageIndex = imageIndex - 1; // minus one DrawingAnchor *danchor = d->drawing->anchors.at(realImageIndex); - // QSharedPointer // for multithread + // std::shared_ptr // for multithread if (danchor == nullptr) { return false; } @@ -1190,10 +1189,10 @@ Chart *Worksheet::insertChart(int row, int column, const QSize &size) anchor->from = XlsxMarker(row, column, 0, 0); anchor->ext = size * 9525; - QSharedPointer chart = QSharedPointer(new Chart(this, F_NewFromScratch)); + auto chart = std::shared_ptr(new Chart(this, F_NewFromScratch)); anchor->setObjectGraphicFrame(chart); - return chart.data(); + return chart.get(); } /*! @@ -1219,7 +1218,7 @@ bool Worksheet::mergeCells(const CellRange &range, const Format &format) for (int row = range.firstRow(); row <= range.lastRow(); ++row) { for (int col = range.firstColumn(); col <= range.lastColumn(); ++col) { if (row == range.firstRow() && col == range.firstColumn()) { - Cell *cell = cellAt(row, col); + auto cell = cellAt(row, col); if (cell) { if (format.isValid()) cell->d_ptr->format = format; @@ -1342,7 +1341,7 @@ void Worksheet::saveToXmlFile(QIODevice *device) const writer.writeStartElement(QStringLiteral("cols")); for (auto it = d->colsInfo.begin(); it != d->colsInfo.end(); ++it) { - QSharedPointer col_info = it.value(); + std::shared_ptr col_info = it.value(); writer.writeStartElement(QStringLiteral("col")); writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->firstColumn)); writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->lastColumn)); @@ -1504,7 +1503,7 @@ void WorksheetPrivate::saveXmlSheetData(QXmlStreamWriter &writer) const writer.writeAttribute(QStringLiteral("spans"), span); if (riIt != rowsInfo.constEnd()) { - QSharedPointer rowInfo = riIt.value(); + std::shared_ptr rowInfo = riIt.value(); if (!rowInfo->format.isEmpty()) { writer.writeAttribute(QStringLiteral("s"), QString::number(rowInfo->format.xfIndex())); @@ -1566,7 +1565,8 @@ void WorksheetPrivate::saveXmlCellData(QXmlStreamWriter &writer, } else { auto cIt = colsInfoHelper.constFind(col); if (cIt != colsInfoHelper.constEnd() && !(*cIt)->format.isEmpty()) { - writer.writeAttribute(QStringLiteral("s"), QString::number((*cIt)->format.xfIndex())); + writer.writeAttribute(QStringLiteral("s"), + QString::number((*cIt)->format.xfIndex())); } } } @@ -1724,9 +1724,9 @@ void WorksheetPrivate::saveXmlHyperlinks(QXmlStreamWriter &writer) const int row = it.key(); for (auto it2 = it.value().begin(); it2 != it.value().end(); ++it2) { - int col = it2.key(); - QSharedPointer data = it2.value(); - QString ref = CellReference(row, col).toString(); + int col = it2.key(); + std::shared_ptr data = it2.value(); + QString ref = CellReference(row, col).toString(); // dev57 // writer.writeEmptyElement(QStringLiteral("hyperlink")); @@ -1784,10 +1784,10 @@ void WorksheetPrivate::splitColsInfo(int colFirst, int colLast) // This will be more complex if we try to set "C:F" after "B:D". { for (auto it = colsInfo.begin(); it != colsInfo.end(); ++it) { - QSharedPointer info = it.value(); + std::shared_ptr info = it.value(); if (colFirst > info->firstColumn && colFirst <= info->lastColumn) { // split the range, - QSharedPointer info2(new XlsxColumnInfo(*info)); + std::shared_ptr info2(new XlsxColumnInfo(*info)); info->lastColumn = colFirst - 1; info2->firstColumn = colFirst; colsInfo.insert(colFirst, info2); @@ -1800,9 +1800,9 @@ void WorksheetPrivate::splitColsInfo(int colFirst, int colLast) } { for (auto it = colsInfo.begin(); it != colsInfo.end(); ++it) { - QSharedPointer info = it.value(); + std::shared_ptr info = it.value(); if (colLast >= info->firstColumn && colLast < info->lastColumn) { - QSharedPointer info2(new XlsxColumnInfo(*info)); + std::shared_ptr info2(new XlsxColumnInfo(*info)); info->lastColumn = colLast; info2->firstColumn = colLast + 1; colsInfo.insert(colLast + 1, info2); @@ -1898,9 +1898,9 @@ bool Worksheet::setColumnWidth(int colFirst, int colLast, double width) { Q_D(Worksheet); - const QList> columnInfoList = + const QList> columnInfoList = d->getColumnInfoList(colFirst, colLast); - for (const QSharedPointer &columnInfo : columnInfoList) { + for (const std::shared_ptr &columnInfo : columnInfoList) { columnInfo->width = width; } @@ -1916,9 +1916,9 @@ bool Worksheet::setColumnFormat(int colFirst, int colLast, const Format &format) { Q_D(Worksheet); - const QList> columnInfoList = + const QList> columnInfoList = d->getColumnInfoList(colFirst, colLast); - for (const QSharedPointer &columnInfo : columnInfoList) + for (const std::shared_ptr &columnInfo : columnInfoList) columnInfo->format = format; if (columnInfoList.count() > 0) { @@ -1937,9 +1937,9 @@ bool Worksheet::setColumnHidden(int colFirst, int colLast, bool hidden) { Q_D(Worksheet); - const QList> columnInfoList = + const QList> columnInfoList = d->getColumnInfoList(colFirst, colLast); - for (const QSharedPointer &columnInfo : columnInfoList) + for (const std::shared_ptr &columnInfo : columnInfoList) columnInfo->hidden = hidden; return (columnInfoList.count() > 0); @@ -1952,7 +1952,7 @@ double Worksheet::columnWidth(int column) { Q_D(Worksheet); - QList> columnInfoList = d->getColumnInfoList(column, column); + QList> columnInfoList = d->getColumnInfoList(column, column); // [dev54] if (columnInfoList.size() == 0) { @@ -1983,7 +1983,7 @@ Format Worksheet::columnFormat(int column) { Q_D(Worksheet); - QList> columnInfoList = d->getColumnInfoList(column, column); + QList> columnInfoList = d->getColumnInfoList(column, column); if (columnInfoList.count() == 1) return columnInfoList.at(0)->format; @@ -1997,7 +1997,7 @@ bool Worksheet::isColumnHidden(int column) { Q_D(Worksheet); - QList> columnInfoList = d->getColumnInfoList(column, column); + QList> columnInfoList = d->getColumnInfoList(column, column); if (columnInfoList.count() == 1) return columnInfoList.at(0)->hidden; @@ -2015,8 +2015,8 @@ bool Worksheet::setRowHeight(int rowFirst, int rowLast, double height) { Q_D(Worksheet); - const QList> rowInfoList = d->getRowInfoList(rowFirst, rowLast); - for (const QSharedPointer &rowInfo : rowInfoList) { + const QList> rowInfoList = d->getRowInfoList(rowFirst, rowLast); + for (const std::shared_ptr &rowInfo : rowInfoList) { rowInfo->height = height; rowInfo->customHeight = true; } @@ -2034,8 +2034,8 @@ bool Worksheet::setRowFormat(int rowFirst, int rowLast, const Format &format) { Q_D(Worksheet); - const QList> rowInfoList = d->getRowInfoList(rowFirst, rowLast); - for (const QSharedPointer &rowInfo : rowInfoList) + const QList> rowInfoList = d->getRowInfoList(rowFirst, rowLast); + for (const std::shared_ptr &rowInfo : rowInfoList) rowInfo->format = format; d->workbook->styles()->addXfFormat(format); @@ -2052,8 +2052,8 @@ bool Worksheet::setRowHidden(int rowFirst, int rowLast, bool hidden) { Q_D(Worksheet); - const QList> rowInfoList = d->getRowInfoList(rowFirst, rowLast); - for (const QSharedPointer &rowInfo : rowInfoList) + const QList> rowInfoList = d->getRowInfoList(rowFirst, rowLast); + for (const std::shared_ptr &rowInfo : rowInfoList) rowInfo->hidden = hidden; return rowInfoList.count() > 0; @@ -2117,7 +2117,7 @@ bool Worksheet::groupRows(int rowFirst, int rowLast, bool collapsed) if (it != d->rowsInfo.end()) { (*it)->outlineLevel += 1; } else { - QSharedPointer info(new XlsxRowInfo); + std::shared_ptr info(new XlsxRowInfo); info->outlineLevel += 1; it = d->rowsInfo.insert(row, info); } @@ -2127,7 +2127,7 @@ bool Worksheet::groupRows(int rowFirst, int rowLast, bool collapsed) if (collapsed) { auto it = d->rowsInfo.find(rowLast + 1); if (it == d->rowsInfo.end()) - it = d->rowsInfo.insert(rowLast + 1, QSharedPointer(new XlsxRowInfo)); + it = d->rowsInfo.insert(rowLast + 1, std::shared_ptr(new XlsxRowInfo)); (*it)->collapsed = true; } return true; @@ -2178,7 +2178,7 @@ bool Worksheet::groupColumns(int colFirst, int colLast, bool collapsed) (*it)->hidden = true; } else { int colEnd = (idx == nodes.size() - 1) ? colLast : nodes[idx + 1] - 1; - QSharedPointer info(new XlsxColumnInfo(colStart, colEnd, false)); + std::shared_ptr info(new XlsxColumnInfo(colStart, colEnd, false)); info->outlineLevel += 1; d->colsInfo.insert(colFirst, info); if (collapsed) @@ -2195,7 +2195,7 @@ bool Worksheet::groupColumns(int colFirst, int colLast, bool collapsed) if (it != d->colsInfo.constEnd()) (*it)->collapsed = true; else { - QSharedPointer info(new XlsxColumnInfo(col, col, false)); + std::shared_ptr info(new XlsxColumnInfo(col, col, false)); info->collapsed = true; d->colsInfo.insert(col, info); d->colsInfoHelper[col] = info; @@ -2276,7 +2276,7 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) attributes.hasAttribute(QLatin1String("outlineLevel")) || attributes.hasAttribute(QLatin1String("collapsed"))) { - QSharedPointer info(new XlsxRowInfo); + std::shared_ptr info(new XlsxRowInfo); if (attributes.hasAttribute(QLatin1String("customFormat")) && attributes.hasAttribute(QLatin1String("s"))) { int idx = attributes.value(QLatin1String("s")).toInt(); @@ -2321,8 +2321,7 @@ void WorksheetPrivate::loadXmlSheetData(QXmlStreamReader &reader) QXmlStreamAttributes attributes = reader.attributes(); QString r = attributes.value(QLatin1String("r")).toString(); CellReference pos(r); - if (r.isEmpty()) - { + if (r.isEmpty()) { pos.setRow(row_num); pos.setColumn(++col_num); } @@ -2464,7 +2463,7 @@ void WorksheetPrivate::loadXmlColumnsInfo(QXmlStreamReader &reader) reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("col")) { - QSharedPointer info(new XlsxColumnInfo(0, 1, false)); + std::shared_ptr info(new XlsxColumnInfo(0, 1, false)); QXmlStreamAttributes colAttrs = reader.attributes(); int min = colAttrs.value(QLatin1String("min")).toInt(); @@ -2658,7 +2657,7 @@ void WorksheetPrivate::loadXmlHyperlinks(QXmlStreamReader &reader) QXmlStreamAttributes attrs = reader.attributes(); CellReference pos(attrs.value(QLatin1String("ref")).toString()); if (pos.isValid()) { // Valid - QSharedPointer link(new XlsxHyperlinkData); + std::shared_ptr link(new XlsxHyperlinkData); link->display = attrs.value(QLatin1String("display")).toString(); link->tooltip = attrs.value(QLatin1String("tooltip")).toString(); link->location = attrs.value(QLatin1String("location")).toString(); @@ -2678,9 +2677,10 @@ void WorksheetPrivate::loadXmlHyperlinks(QXmlStreamReader &reader) } } -QList> WorksheetPrivate::getColumnInfoList(int colFirst, int colLast) +QList> WorksheetPrivate::getColumnInfoList(int colFirst, + int colLast) { - QList> columnsInfoList; + QList> columnsInfoList; if (isColumnRangeValid(colFirst, colLast)) { QList nodes = getColumnIndexes(colFirst, colLast); @@ -2691,7 +2691,7 @@ QList> WorksheetPrivate::getColumnInfoList(int co columnsInfoList.append(*it); } else { int colEnd = (idx == nodes.size() - 1) ? colLast : nodes[idx + 1] - 1; - QSharedPointer info(new XlsxColumnInfo(colStart, colEnd, false)); + std::shared_ptr info(new XlsxColumnInfo(colStart, colEnd, false)); colsInfo.insert(colFirst, info); columnsInfoList.append(info); for (int c = colStart; c <= colEnd; ++c) { @@ -2704,9 +2704,9 @@ QList> WorksheetPrivate::getColumnInfoList(int co return columnsInfoList; } -QList> WorksheetPrivate::getRowInfoList(int rowFirst, int rowLast) +QList> WorksheetPrivate::getRowInfoList(int rowFirst, int rowLast) { - QList> rowInfoList; + QList> rowInfoList; int min_col = dimension.firstColumn() < 1 ? 1 : dimension.firstColumn(); @@ -2714,9 +2714,9 @@ QList> WorksheetPrivate::getRowInfoList(int rowFirst if (checkDimensions(row, min_col, false, true)) continue; - QSharedPointer rowInfo; - if ((rowsInfo[row]).isNull()) { - rowsInfo[row] = QSharedPointer(new XlsxRowInfo()); + std::shared_ptr rowInfo; + if (!(rowsInfo[row])) { + rowsInfo[row] = std::make_shared(); } rowInfoList.append(rowsInfo[row]); } @@ -2820,7 +2820,8 @@ void WorksheetPrivate::validateDimension() if (dimension.isValid() || cellTable.isEmpty()) return; - CellRange cr(cellTable.firstRow, cellTable.firstColumn, cellTable.lastRow, cellTable.lastColumn); + CellRange cr( + cellTable.firstRow, cellTable.firstColumn, cellTable.lastRow, cellTable.lastColumn); if (cr.isValid()) dimension = cr; @@ -2858,11 +2859,11 @@ QVector Worksheet::getFullCells(int *maxRow, int *maxCol) } for (const auto row : d->cellTable.sortedRows()) { - auto &columns = d->cellTable.cells[row]; + auto &columns = d->cellTable.cells[row]; auto columnsSorted = CellTable::sorteIntList(columns.keys()); for (const auto col : columnsSorted) { - // It's faster to iterate but cellTable is unordered which might not - // be what callers want? + // It's faster to iterate but cellTable is unordered which might not + // be what callers want? auto cell = std::make_shared(columns.value(col).get()); CellLocation cl; diff --git a/TestExcel/extractdata.cpp b/TestExcel/extractdata.cpp index 7694e718..b70d48e4 100644 --- a/TestExcel/extractdata.cpp +++ b/TestExcel/extractdata.cpp @@ -39,7 +39,7 @@ int extractdata() //![2] qDebug() << "extractdata.xlsx - QXlsx::Cell.value()"; for (int row = 1; row < 10; ++row) { - if (QXlsx::Cell *cell = xlsx.cellAt(row, 1)) { + if (auto cell = xlsx.cellAt(row, 1)) { qDebug() << cell->value(); } } diff --git a/TestExcel/hello.cpp b/TestExcel/hello.cpp index b73f8521..cf7bdbdb 100644 --- a/TestExcel/hello.cpp +++ b/TestExcel/hello.cpp @@ -126,7 +126,7 @@ int ReadExcel(bool isTest) //![2] qDebug() << " QXlsx::Cell.cellAt()"; for (int row = 1; row < 20; ++row) { - Cell *cell = xlsx.cellAt(row, 1); + auto cell = xlsx.cellAt(row, 1); if (cell == NULL) continue; QVariant var = cell->readValue(); diff --git a/TestExcel/readStyle.cpp b/TestExcel/readStyle.cpp index 820df783..593894fd 100644 --- a/TestExcel/readStyle.cpp +++ b/TestExcel/readStyle.cpp @@ -41,7 +41,7 @@ int readGoogleSpreadsheet() // current sheet is default sheet. (Sheet1) for (int row = 1; row < 20; ++row) { - Cell *cell = xlsx.cellAt(row, 1); + auto cell = xlsx.cellAt(row, 1); if (cell == NULL) continue; QVariant var = cell->readValue(); @@ -145,7 +145,7 @@ int readMSExcel201xNumber(QXlsx::Document *pXlsx) return (-1); for (int row = 1; row < 10; ++row) { - Cell *cell = pXlsx->cellAt(row, 1); + auto cell = pXlsx->cellAt(row, 1); if (cell == NULL) continue;