Add format param to the mergeCells() API

This commit is contained in:
Debao Zhang
2013-11-01 10:37:41 +08:00
parent 1c1e0a771e
commit 5a035ede93
8 changed files with 125 additions and 41 deletions
+27 -4
View File
@@ -142,21 +142,44 @@ int Document::insertImage(int row, int column, const QImage &image, double xOffs
}
/*!
* Merge cell \a range.
Merge a \a range of cells. The first cell should contain the data and the others should
be blank. All cells will be applied the same style if a valid \a format is given.
\note All cells except the top-left one will be cleared.
*/
int Document::mergeCells(const QString &range)
int Document::mergeCells(const CellRange &range, Format *format)
{
return currentWorksheet()->mergeCells(range);
return currentWorksheet()->mergeCells(range, format);
}
/*!
* Unmerge cell \a range.
\overload
Merge a \a range of cells. The first cell should contain the data and the others should
be blank. All cells will be applied the same style if a valid \a format is given.
\note All cells except the top-left one will be cleared.
*/
int Document::mergeCells(const QString &range, Format *format)
{
return currentWorksheet()->mergeCells(range, format);
}
/*!
Unmerge the cells in the \a range.
*/
int Document::unmergeCells(const QString &range)
{
return currentWorksheet()->unmergeCells(range);
}
/*!
Unmerge the cells in the \a range.
*/
int Document::unmergeCells(const CellRange &range)
{
return currentWorksheet()->unmergeCells(range);
}
/*!
* \brief Set properties for a row of cells.
* \param row The worksheet row (zero indexed).
+3 -1
View File
@@ -58,7 +58,9 @@ public:
int write(const QString &cell, const QVariant &value, Format *format=0);
int write(int row, int col, const QVariant &value, Format *format=0);
int insertImage(int row, int column, const QImage &image, double xOffset=0, double yOffset=0, double xScale=1, double yScale=1);
int mergeCells(const QString &range);
int mergeCells(const CellRange &range, Format *format=0);
int mergeCells(const QString &range, Format *format=0);
int unmergeCells(const CellRange &range);
int unmergeCells(const QString &range);
bool setRow(int row, double height, Format* format=0, bool hidden=false);
bool setRow(const QString &row, double height, Format* format=0, bool hidden=false);
+42 -13
View File
@@ -679,7 +679,13 @@ int Worksheet::insertImage(int row, int column, const QImage &image, const QPoin
return 0;
}
int Worksheet::mergeCells(const CellRange &range)
/*!
Merge a \a range of cells. The first cell should contain the data and the others should
be blank. All cells will be applied the same style if a valid \a format is given.
\note All cells except the top-left one will be cleared.
*/
int Worksheet::mergeCells(const CellRange &range, Format *format)
{
Q_D(Worksheet);
if (range.rowCount() < 2 && range.columnCount() < 2)
@@ -688,11 +694,37 @@ int Worksheet::mergeCells(const CellRange &range)
if (d->checkDimensions(range.firstRow(), range.firstColumn()))
return -1;
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);
if (cell) {
if (format)
cell->d_ptr->format = format;
} else {
writeBlank(row, col, format);
}
} else {
writeBlank(row, col, format);
}
}
}
if (format)
d->workbook->styles()->addFormat(format);
d->merges.append(range);
return 0;
}
int Worksheet::mergeCells(const QString &range)
/*!
\overload
Merge a \a range of cells. The first cell should contain the data and the others should
be blank. All cells will be applied the same style if a valid \a format is given.
\note All cells except the top-left one will be cleared.
*/
int Worksheet::mergeCells(const QString &range, Format *format)
{
QStringList cells = range.split(QLatin1Char(':'));
if (cells.size() != 2)
@@ -703,14 +735,12 @@ int Worksheet::mergeCells(const QString &range)
if (cell1 == QPoint(-1,-1) || cell2 == QPoint(-1, -1))
return -1;
return mergeCells(CellRange(cell1.x(), cell1.y(), cell2.x(), cell2.y()));
}
int Worksheet::mergeCells(int row_begin, int column_begin, int row_end, int column_end)
{
return mergeCells(CellRange(row_begin, column_begin, row_end, column_end));
return mergeCells(CellRange(cell1.x(), cell1.y(), cell2.x(), cell2.y()), format);
}
/*!
Unmerge the cells in the \a range.
*/
int Worksheet::unmergeCells(const CellRange &range)
{
Q_D(Worksheet);
@@ -721,6 +751,10 @@ int Worksheet::unmergeCells(const CellRange &range)
return 0;
}
/*!
\overload
Unmerge the cells in the \a range.
*/
int Worksheet::unmergeCells(const QString &range)
{
QStringList cells = range.split(QLatin1Char(':'));
@@ -735,11 +769,6 @@ int Worksheet::unmergeCells(const QString &range)
return unmergeCells(CellRange(cell1.x(), cell1.y(), cell2.x(), cell2.y()));
}
int Worksheet::unmergeCells(int row_begin, int column_begin, int row_end, int column_end)
{
return unmergeCells(CellRange(row_begin, column_begin, row_end, column_end));
}
void Worksheet::saveToXmlFile(QIODevice *device)
{
Q_D(Worksheet);
+2 -4
View File
@@ -71,10 +71,8 @@ public:
int insertImage(int row, int column, const QImage &image, const QPointF &offset=QPointF(), double xScale=1, double yScale=1);
int mergeCells(int row_begin, int column_begin, int row_end, int column_end);
int mergeCells(const QString &range);
int mergeCells(const CellRange &range);
int unmergeCells(int row_begin, int column_begin, int row_end, int column_end);
int mergeCells(const QString &range, Format *format=0);
int mergeCells(const CellRange &range, Format *format=0);
int unmergeCells(const QString &range);
int unmergeCells(const CellRange &range);