From 086020857540be58559edc319a5a8a154a51dd90 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Tue, 18 Mar 2014 00:30:54 +0800 Subject: [PATCH] Code refactoring: add new constructor CellRange(const char *) --- src/xlsx/xlsxcellrange.cpp | 14 +++++++++++++ src/xlsx/xlsxcellrange.h | 2 ++ src/xlsx/xlsxdocument.cpp | 24 ----------------------- src/xlsx/xlsxdocument.h | 2 -- src/xlsx/xlsxworksheet.cpp | 40 -------------------------------------- src/xlsx/xlsxworksheet.h | 2 -- 6 files changed, 16 insertions(+), 68 deletions(-) diff --git a/src/xlsx/xlsxcellrange.cpp b/src/xlsx/xlsxcellrange.cpp index 93fc282..dc72baf 100644 --- a/src/xlsx/xlsxcellrange.cpp +++ b/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. */ 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(':')); if (rs.size() == 2) { diff --git a/src/xlsx/xlsxcellrange.h b/src/xlsx/xlsxcellrange.h index 8773496..1ef2f0a 100644 --- a/src/xlsx/xlsxcellrange.h +++ b/src/xlsx/xlsxcellrange.h @@ -34,6 +34,7 @@ public: CellRange(); CellRange(int firstRow, int firstColumn, int lastRow, int lastColumn); CellRange(const QString &range); + CellRange(const char *range); CellRange(const CellRange &other); ~CellRange(); @@ -61,6 +62,7 @@ public: || left != other.left || right != other.right; } private: + void init(const QString &range); int top, left, bottom, right; }; diff --git a/src/xlsx/xlsxdocument.cpp b/src/xlsx/xlsxdocument.cpp index b2a5cdb..b765188 100644 --- a/src/xlsx/xlsxdocument.cpp +++ b/src/xlsx/xlsxdocument.cpp @@ -480,30 +480,6 @@ bool Document::mergeCells(const CellRange &range, const Format &format) 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. */ diff --git a/src/xlsx/xlsxdocument.h b/src/xlsx/xlsxdocument.h index 7770870..2d89684 100644 --- a/src/xlsx/xlsxdocument.h +++ b/src/xlsx/xlsxdocument.h @@ -62,9 +62,7 @@ public: bool insertImage(int row, int col, const QImage &image); Chart *insertChart(int row, int col, const QSize &size); 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 QString &range); bool setColumnWidth(const CellRange &range, double width); bool setColumnFormat(const CellRange &range, const Format &format); diff --git a/src/xlsx/xlsxworksheet.cpp b/src/xlsx/xlsxworksheet.cpp index dcab830..6718fb2 100755 --- a/src/xlsx/xlsxworksheet.cpp +++ b/src/xlsx/xlsxworksheet.cpp @@ -1112,27 +1112,6 @@ bool Worksheet::mergeCells(const CellRange &range, const Format &format) 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. */ @@ -1146,25 +1125,6 @@ bool Worksheet::unmergeCells(const CellRange &range) 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 */ diff --git a/src/xlsx/xlsxworksheet.h b/src/xlsx/xlsxworksheet.h index 8f92a5b..d6c248d 100755 --- a/src/xlsx/xlsxworksheet.h +++ b/src/xlsx/xlsxworksheet.h @@ -93,9 +93,7 @@ public: bool insertImage(int row, int column, const QImage &image); 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 unmergeCells(const QString &range); bool unmergeCells(const CellRange &range); QList mergedCells() const;