Skip to content

Commit

Permalink
Return std::shared_ptr for Cell
Browse files Browse the repository at this point in the history
  • Loading branch information
dantti committed Sep 2, 2024
1 parent 81284da commit 35c6d27
Show file tree
Hide file tree
Showing 17 changed files with 165 additions and 164 deletions.
4 changes: 2 additions & 2 deletions QXlsx/header/xlsxdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cell> cellAt(const CellReference &cell) const;
std::shared_ptr<Cell> cellAt(int row, int col) const;

bool defineName(const QString &name,
const QString &formula,
Expand Down
2 changes: 1 addition & 1 deletion QXlsx/header/xlsxdocument_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DocumentPrivate
QString packageName; // name of the .xlsx file

QMap<QString, QString> documentProperties; // core, app and custom properties
QSharedPointer<Workbook> workbook;
std::shared_ptr<Workbook> workbook;
std::shared_ptr<ContentTypes> contentTypes;
bool isLoad;
};
Expand Down
5 changes: 2 additions & 3 deletions QXlsx/header/xlsxdrawinganchor_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <memory>

#include <QPoint>
#include <QSharedPointer>
#include <QSize>
#include <QString>
#include <QXmlStreamReader>
Expand Down Expand Up @@ -49,7 +48,7 @@ class DrawingAnchor
void setObjectPicture(const QImage &img);
bool getObjectPicture(QImage &img);

void setObjectGraphicFrame(QSharedPointer<Chart> chart);
void setObjectGraphicFrame(std::shared_ptr<QXlsx::Chart> chart);

virtual bool loadFromXml(QXmlStreamReader &reader) = 0;
virtual void saveToXml(QXmlStreamWriter &writer) const = 0;
Expand Down Expand Up @@ -83,7 +82,7 @@ class DrawingAnchor
Drawing *m_drawing;
ObjectType m_objectType;
std::shared_ptr<MediaFile> m_pictureFile;
QSharedPointer<Chart> m_chartFile;
std::shared_ptr<Chart> m_chartFile;

int m_id;

Expand Down
7 changes: 4 additions & 3 deletions QXlsx/header/xlsxstyles_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
// We mean it.
//

#include <memory>

#include <QHash>
#include <QIODevice>
#include <QList>
#include <QMap>
#include <QSharedPointer>
#include <QStringList>
#include <QVector>
#include <QXmlStreamReader>
Expand Down Expand Up @@ -124,8 +125,8 @@ class Styles : public AbstractOOXmlFile
bool readCellStyleXfs(QXmlStreamReader &reader);

QHash<QString, int> m_builtinNumFmtsHash;
QMap<int, QSharedPointer<XlsxFormatNumberData>> m_customNumFmtIdMap;
QHash<QString, QSharedPointer<XlsxFormatNumberData>> m_customNumFmtsHash;
QMap<int, std::shared_ptr<XlsxFormatNumberData>> m_customNumFmtIdMap;
QHash<QString, std::shared_ptr<XlsxFormatNumberData>> m_customNumFmtsHash;
int m_nextCustomNumFmtId;
QList<Format> m_fontsList;
QList<Format> m_fillsList;
Expand Down
7 changes: 3 additions & 4 deletions QXlsx/header/xlsxworkbook.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <QIODevice>
#include <QImage>
#include <QList>
#include <QSharedPointer>

QT_BEGIN_NAMESPACE_XLSX

Expand Down Expand Up @@ -70,8 +69,8 @@ class QXLSX_EXPORT Workbook : public AbstractOOXmlFile
// internal used member
void addMediaFile(std::shared_ptr<MediaFile> media, bool force = false);
QList<std::shared_ptr<MediaFile>> mediaFiles() const;
void addChartFile(QSharedPointer<Chart> chartFile);
QList<QSharedPointer<Chart>> chartFiles() const;
void addChartFile(std::shared_ptr<Chart> chartFile);
QList<std::shared_ptr<Chart>> chartFiles() const;

private:
friend class Worksheet;
Expand All @@ -90,7 +89,7 @@ class QXLSX_EXPORT Workbook : public AbstractOOXmlFile
Theme *theme();
QList<QImage> images();
QList<Drawing *> drawings();
QList<QSharedPointer<AbstractSheet>> getSheetsByTypes(AbstractSheet::SheetType type) const;
QList<std::shared_ptr<AbstractSheet>> getSheetsByTypes(AbstractSheet::SheetType type) const;
QStringList worksheetNames() const;
AbstractSheet *addSheet(const QString &name,
int sheetId,
Expand Down
13 changes: 6 additions & 7 deletions QXlsx/header/xlsxworkbook_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "xlsxtheme_p.h"
#include "xlsxworkbook.h"

#include <QSharedPointer>
#include <QStringList>

QT_BEGIN_NAMESPACE_XLSX
Expand Down Expand Up @@ -42,14 +41,14 @@ class WorkbookPrivate : public AbstractOOXmlFilePrivate
public:
WorkbookPrivate(Workbook *q, Workbook::CreateFlag flag);

QSharedPointer<SharedStrings> sharedStrings;
QList<QSharedPointer<AbstractSheet>> sheets;
QList<QSharedPointer<SimpleOOXmlFile>> externalLinks;
std::shared_ptr<SharedStrings> sharedStrings;
QList<std::shared_ptr<AbstractSheet>> sheets;
QList<std::shared_ptr<SimpleOOXmlFile>> externalLinks;
QStringList sheetNames;
QSharedPointer<Styles> styles;
QSharedPointer<Theme> theme;
std::shared_ptr<Styles> styles;
std::shared_ptr<Theme> theme;
QList<std::shared_ptr<MediaFile>> mediaFiles;
QList<QSharedPointer<Chart>> chartFiles;
QList<std::shared_ptr<Chart>> chartFiles;
QList<XlsxDefineNameData> definedNamesList;

bool strings_to_numbers_enabled;
Expand Down
4 changes: 2 additions & 2 deletions QXlsx/header/xlsxworksheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cell> cellAt(const CellReference &row_column) const;
std::shared_ptr<Cell> cellAt(int row, int column) const;

int insertImage(int row, int column, const QImage &image);
bool getImage(int imageIndex, QImage &img);
Expand Down
46 changes: 24 additions & 22 deletions QXlsx/header/xlsxworksheet_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
#include "xlsxdatavalidation.h"
#include "xlsxworksheet.h"

#include <QHash>
#include <QImage>
#include <QObject>
#include <QRegularExpression>
#include <QSharedPointer>
#include <QString>
#include <QVector>
#include <QHash>

class QXmlStreamWriter;
class QXmlStreamReader;
Expand Down Expand Up @@ -136,48 +135,51 @@ struct XlsxColumnInfo {
class CellTable
{
public:
static QList<int> sorteIntList(QList<int> &&keys) {
static QList<int> sorteIntList(QList<int> &&keys)
{
std::sort(keys.begin(), keys.end());
return keys;
}

inline QList<int> sortedRows() const {
inline QList<int> sortedRows() const
{
QList<int> keys = cells.keys();
std::sort(keys.begin(), keys.end());
return keys;
}

void setValue(int row, int column, const std::shared_ptr<Cell> &cell) {
void setValue(int row, int column, const std::shared_ptr<Cell> &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<Cell> cellAt(int row, int column) const{
std::shared_ptr<Cell> 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);
}
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<int, QHash<int, std::shared_ptr<Cell>>> 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
Expand Down Expand Up @@ -217,8 +219,8 @@ class WorksheetPrivate : public AbstractSheetPrivate
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<std::shared_ptr<XlsxRowInfo>> getRowInfoList(int rowFirst, int rowLast);
QList<std::shared_ptr<XlsxColumnInfo>> getColumnInfoList(int colFirst, int colLast);
QList<int> getColumnIndexes(int colFirst, int colLast);
bool isColumnRangeValid(int colFirst, int colLast);

Expand All @@ -228,11 +230,11 @@ class WorksheetPrivate : public AbstractSheetPrivate
CellTable cellTable;

QHash<int, QHash<int, QString>> comments;
QHash<int, QHash<int, QSharedPointer<XlsxHyperlinkData>>> urlTable;
QHash<int, QHash<int, std::shared_ptr<XlsxHyperlinkData>>> urlTable;
QList<CellRange> merges;
QHash<int, QSharedPointer<XlsxRowInfo>> rowsInfo;
QHash<int, QSharedPointer<XlsxColumnInfo>> colsInfo;
QHash<int, QSharedPointer<XlsxColumnInfo>> colsInfoHelper;
QHash<int, std::shared_ptr<XlsxRowInfo>> rowsInfo;
QHash<int, std::shared_ptr<XlsxColumnInfo>> colsInfo;
QHash<int, std::shared_ptr<XlsxColumnInfo>> colsInfoHelper;

QList<DataValidation> dataValidationsList;
QList<ConditionalFormatting> conditionalFormattingList;
Expand Down
4 changes: 2 additions & 2 deletions QXlsx/source/xlsxchartsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> chart = QSharedPointer<Chart>(new Chart(this, flag));
auto chart = std::shared_ptr<Chart>(new Chart(this, flag));
chart->setChartType(Chart::CT_BarChart);
anchor->setObjectGraphicFrame(chart);

d_func()->chart = chart.data();
d_func()->chart = chart.get();
}
}

Expand Down
Loading

0 comments on commit 35c6d27

Please sign in to comment.