Browse Source

Code refactoring: add new constructor CellRange(const char *)

master
Debao Zhang 11 years ago
parent
commit
0860208575
  1. 14
      src/xlsx/xlsxcellrange.cpp
  2. 2
      src/xlsx/xlsxcellrange.h
  3. 24
      src/xlsx/xlsxdocument.cpp
  4. 2
      src/xlsx/xlsxdocument.h
  5. 40
      src/xlsx/xlsxworksheet.cpp
  6. 2
      src/xlsx/xlsxworksheet.h

14
src/xlsx/xlsxcellrange.cpp

@ -64,6 +64,20 @@ CellRange::CellRange(int top, int left, int bottom, int right)
Constructs the range form the given \a range string. Constructs the range form the given \a range string.
*/ */
CellRange::CellRange(const QString &range) CellRange::CellRange(const QString &range)
{
init(range);
}
/*!
\overload
Constructs the range form the given \a range string.
*/
CellRange::CellRange(const char *range)
{
init(QString::fromLatin1(range));
}
void CellRange::init(const QString &range)
{ {
QStringList rs = range.split(QLatin1Char(':')); QStringList rs = range.split(QLatin1Char(':'));
if (rs.size() == 2) { if (rs.size() == 2) {

2
src/xlsx/xlsxcellrange.h

@ -34,6 +34,7 @@ public:
CellRange(); CellRange();
CellRange(int firstRow, int firstColumn, int lastRow, int lastColumn); CellRange(int firstRow, int firstColumn, int lastRow, int lastColumn);
CellRange(const QString &range); CellRange(const QString &range);
CellRange(const char *range);
CellRange(const CellRange &other); CellRange(const CellRange &other);
~CellRange(); ~CellRange();
@ -61,6 +62,7 @@ public:
|| left != other.left || right != other.right; || left != other.left || right != other.right;
} }
private: private:
void init(const QString &range);
int top, left, bottom, right; int top, left, bottom, right;
}; };

24
src/xlsx/xlsxdocument.cpp

@ -480,30 +480,6 @@ bool Document::mergeCells(const CellRange &range, const Format &format)
return false; return false;
} }
/*!
\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.
*/
bool Document::mergeCells(const QString &range, const Format &format)
{
if (Worksheet *sheet = currentWorksheet())
return sheet->mergeCells(range, format);
return false;
}
/*!
Unmerge the cells in the \a range.
*/
bool Document::unmergeCells(const QString &range)
{
if (Worksheet *sheet = currentWorksheet())
return sheet->unmergeCells(range);
return false;
}
/*! /*!
Unmerge the cells in the \a range. Unmerge the cells in the \a range.
*/ */

2
src/xlsx/xlsxdocument.h

@ -62,9 +62,7 @@ public:
bool insertImage(int row, int col, const QImage &image); bool insertImage(int row, int col, const QImage &image);
Chart *insertChart(int row, int col, const QSize &size); Chart *insertChart(int row, int col, const QSize &size);
bool mergeCells(const CellRange &range, const Format &format=Format()); bool mergeCells(const CellRange &range, const Format &format=Format());
bool mergeCells(const QString &range, const Format &format=Format());
bool unmergeCells(const CellRange &range); bool unmergeCells(const CellRange &range);
bool unmergeCells(const QString &range);
bool setColumnWidth(const CellRange &range, double width); bool setColumnWidth(const CellRange &range, double width);
bool setColumnFormat(const CellRange &range, const Format &format); bool setColumnFormat(const CellRange &range, const Format &format);

40
src/xlsx/xlsxworksheet.cpp

@ -1112,27 +1112,6 @@ bool Worksheet::mergeCells(const CellRange &range, const Format &format)
return true; return true;
} }
/*!
\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.
*/
bool Worksheet::mergeCells(const QString &range, const Format &format)
{
QStringList cells = range.split(QLatin1Char(':'));
if (cells.size() != 2)
return false;
QPoint cell1 = xl_cell_to_rowcol(cells[0]);
QPoint cell2 = xl_cell_to_rowcol(cells[1]);
if (cell1 == QPoint(-1,-1) || cell2 == QPoint(-1, -1))
return false;
return mergeCells(CellRange(cell1.x(), cell1.y(), cell2.x(), cell2.y()), format);
}
/*! /*!
Unmerge the cells in the \a range. Unmerge the cells in the \a range.
*/ */
@ -1146,25 +1125,6 @@ bool Worksheet::unmergeCells(const CellRange &range)
return true; return true;
} }
/*!
\overload
Unmerge the cells in the \a range.
*/
bool Worksheet::unmergeCells(const QString &range)
{
QStringList cells = range.split(QLatin1Char(':'));
if (cells.size() != 2)
return false;
QPoint cell1 = xl_cell_to_rowcol(cells[0]);
QPoint cell2 = xl_cell_to_rowcol(cells[1]);
if (cell1 == QPoint(-1,-1) || cell2 == QPoint(-1, -1))
return false;
return unmergeCells(CellRange(cell1.x(), cell1.y(), cell2.x(), cell2.y()));
}
/*! /*!
Returns all the merged cells Returns all the merged cells
*/ */

2
src/xlsx/xlsxworksheet.h

@ -93,9 +93,7 @@ public:
bool insertImage(int row, int column, const QImage &image); bool insertImage(int row, int column, const QImage &image);
Chart *insertChart(int row, int column, const QSize &size); Chart *insertChart(int row, int column, const QSize &size);
bool mergeCells(const QString &range, const Format &format=Format());
bool mergeCells(const CellRange &range, const Format &format=Format()); bool mergeCells(const CellRange &range, const Format &format=Format());
bool unmergeCells(const QString &range);
bool unmergeCells(const CellRange &range); bool unmergeCells(const CellRange &range);
QList<CellRange> mergedCells() const; QList<CellRange> mergedCells() const;

Loading…
Cancel
Save