Add a private sheetId() member for Worksheet
This commit is contained in:
@@ -55,6 +55,9 @@ WorkbookPrivate::WorkbookPrivate(Workbook *q) :
|
||||
activesheet = 0;
|
||||
firstsheet = 0;
|
||||
table_count = 0;
|
||||
|
||||
last_sheet_index = 0;
|
||||
last_sheet_id = 0;
|
||||
}
|
||||
|
||||
Workbook::Workbook() :
|
||||
@@ -135,10 +138,9 @@ Worksheet *Workbook::addWorksheet(const QString &name)
|
||||
Worksheet *Workbook::insertWorkSheet(int index, const QString &name)
|
||||
{
|
||||
Q_D(Workbook);
|
||||
static int lastIndex = -1;
|
||||
QString worksheetName = name;
|
||||
if (!name.isEmpty()) {
|
||||
//If user given an already in-use name, we should not continue any more!
|
||||
//If user given an already in-used name, we should not continue any more!
|
||||
for (int i=0; i<d->worksheets.size(); ++i) {
|
||||
if (d->worksheets[i]->sheetName() == name) {
|
||||
return 0;
|
||||
@@ -147,9 +149,9 @@ Worksheet *Workbook::insertWorkSheet(int index, const QString &name)
|
||||
} else {
|
||||
bool exists;
|
||||
do {
|
||||
++lastIndex;
|
||||
++d->last_sheet_index;
|
||||
exists = false;
|
||||
worksheetName = QStringLiteral("Sheet%1").arg(lastIndex+1);
|
||||
worksheetName = QStringLiteral("Sheet%1").arg(d->last_sheet_index);
|
||||
for (int i=0; i<d->worksheets.size(); ++i) {
|
||||
if (d->worksheets[i]->sheetName() == worksheetName)
|
||||
exists = true;
|
||||
@@ -157,7 +159,8 @@ Worksheet *Workbook::insertWorkSheet(int index, const QString &name)
|
||||
} while (exists);
|
||||
}
|
||||
|
||||
Worksheet *sheet = new Worksheet(worksheetName, this);
|
||||
++d->last_sheet_id;
|
||||
Worksheet *sheet = new Worksheet(worksheetName, d->last_sheet_id, this);
|
||||
d->worksheets.insert(index, QSharedPointer<Worksheet>(sheet));
|
||||
d->activesheet = index;
|
||||
return sheet;
|
||||
@@ -284,7 +287,7 @@ void Workbook::saveToXmlFile(QIODevice *device)
|
||||
QSharedPointer<Worksheet> sheet = d->worksheets[i];
|
||||
writer.writeEmptyElement(QStringLiteral("sheet"));
|
||||
writer.writeAttribute(QStringLiteral("name"), sheet->sheetName());
|
||||
writer.writeAttribute(QStringLiteral("sheetId"), QString::number(i+1));
|
||||
writer.writeAttribute(QStringLiteral("sheetId"), QString::number(sheet->sheetId()));
|
||||
if (sheet->isHidden())
|
||||
writer.writeAttribute(QStringLiteral("state"), QStringLiteral("hidden"));
|
||||
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(i+1));
|
||||
|
||||
@@ -58,6 +58,10 @@ public:
|
||||
int activesheet;
|
||||
int firstsheet;
|
||||
int table_count;
|
||||
|
||||
//Used to generate new sheet name and id
|
||||
int last_sheet_index;
|
||||
int last_sheet_id;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -195,13 +195,15 @@ int WorksheetPrivate::checkDimensions(int row, int col, bool ignore_row, bool ig
|
||||
/*!
|
||||
* \brief Worksheet::Worksheet
|
||||
* \param name Name of the worksheet
|
||||
* \param index Index of the worksheet in the workbook
|
||||
* \param parent
|
||||
* \param id : An integer representing the internal id of the
|
||||
* sheet which is used by .xlsx revision part.
|
||||
* (Note: id is not the index of the sheet in workbook)
|
||||
*/
|
||||
Worksheet::Worksheet(const QString &name, Workbook *workbook) :
|
||||
Worksheet::Worksheet(const QString &name, int id, Workbook *workbook) :
|
||||
d_ptr(new WorksheetPrivate(this))
|
||||
{
|
||||
d_ptr->name = name;
|
||||
d_ptr->id = id;
|
||||
if (!workbook) //For unit test propose only. Ignore the memery leak.
|
||||
workbook = new Workbook;
|
||||
d_ptr->workbook = workbook;
|
||||
@@ -253,6 +255,12 @@ void Worksheet::setSelected(bool select)
|
||||
d->selected = select;
|
||||
}
|
||||
|
||||
int Worksheet::sheetId() const
|
||||
{
|
||||
Q_D(const Worksheet);
|
||||
return d->id;
|
||||
}
|
||||
|
||||
void Worksheet::setRightToLeft(bool enable)
|
||||
{
|
||||
Q_D(Worksheet);
|
||||
|
||||
@@ -85,7 +85,7 @@ private:
|
||||
friend class Package;
|
||||
friend class Workbook;
|
||||
friend class ::WorksheetTest;
|
||||
Worksheet(const QString &sheetName, Workbook *book);
|
||||
Worksheet(const QString &sheetName, int sheetId, Workbook *book);
|
||||
|
||||
void saveToXmlFile(QIODevice *device);
|
||||
QByteArray saveToXmlData();
|
||||
@@ -97,6 +97,7 @@ private:
|
||||
bool isSelected() const;
|
||||
void setHidden(bool hidden);
|
||||
void setSelected(bool select);
|
||||
int sheetId() const;
|
||||
QStringList externUrlList() const;
|
||||
QStringList externDrawingList() const;
|
||||
QList<QPair<QString, QString> > drawingLinks() const;
|
||||
|
||||
@@ -223,6 +223,7 @@ public:
|
||||
bool default_row_zeroed;
|
||||
|
||||
QString name;
|
||||
int id;
|
||||
bool hidden;
|
||||
bool selected;
|
||||
bool right_to_left;
|
||||
|
||||
Reference in New Issue
Block a user