xlsxcellrange.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /****************************************************************************
  2. ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
  3. ** All right reserved.
  4. **
  5. ** Permission is hereby granted, free of charge, to any person obtaining
  6. ** a copy of this software and associated documentation files (the
  7. ** "Software"), to deal in the Software without restriction, including
  8. ** without limitation the rights to use, copy, modify, merge, publish,
  9. ** distribute, sublicense, and/or sell copies of the Software, and to
  10. ** permit persons to whom the Software is furnished to do so, subject to
  11. ** the following conditions:
  12. **
  13. ** The above copyright notice and this permission notice shall be
  14. ** included in all copies or substantial portions of the Software.
  15. **
  16. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. **
  24. ****************************************************************************/
  25. #ifndef QXLSX_XLSXCELLRANGE_H
  26. #define QXLSX_XLSXCELLRANGE_H
  27. #include "xlsxglobal.h"
  28. #include "xlsxcellreference.h"
  29. QT_BEGIN_NAMESPACE_XLSX
  30. class Q_XLSX_EXPORT CellRange
  31. {
  32. public:
  33. CellRange();
  34. CellRange(int firstRow, int firstColumn, int lastRow, int lastColumn);
  35. CellRange(const CellReference &topLeft, const CellReference &bottomRight);
  36. CellRange(const QString &range);
  37. CellRange(const char *range);
  38. CellRange(const CellRange &other);
  39. ~CellRange();
  40. QString toString(bool row_abs=false, bool col_abs=false) const;
  41. bool isValid() const;
  42. inline void setFirstRow(int row) { top = row; }
  43. inline void setLastRow(int row) { bottom = row; }
  44. inline void setFirstColumn(int col) { left = col; }
  45. inline void setLastColumn(int col) { right = col; }
  46. inline int firstRow() const { return top; }
  47. inline int lastRow() const { return bottom; }
  48. inline int firstColumn() const { return left; }
  49. inline int lastColumn() const { return right; }
  50. inline int rowCount() const { return bottom - top + 1; }
  51. inline int columnCount() const { return right - left + 1; }
  52. inline CellReference topLeft() const { return CellReference(top, left); }
  53. inline CellReference topRight() const { return CellReference(top, right); }
  54. inline CellReference bottomLeft() const { return CellReference(bottom, left); }
  55. inline CellReference bottomRight() const { return CellReference(bottom, right); }
  56. inline bool operator ==(const CellRange &other) const
  57. {
  58. return top==other.top && bottom==other.bottom
  59. && left == other.left && right == other.right;
  60. }
  61. inline bool operator !=(const CellRange &other) const
  62. {
  63. return top!=other.top || bottom!=other.bottom
  64. || left != other.left || right != other.right;
  65. }
  66. private:
  67. void init(const QString &range);
  68. int top, left, bottom, right;
  69. };
  70. QT_END_NAMESPACE_XLSX
  71. Q_DECLARE_TYPEINFO(QXlsx::CellRange, Q_MOVABLE_TYPE);
  72. #endif // QXLSX_XLSXCELLRANGE_H