Mercurial > clickerconvert
annotate src/xlsx/xlsxcellreference.cpp @ 88:d944cc7caf2d
Removed tag 1.3
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 05 Oct 2016 15:43:30 +0200 |
parents | 93d3106bb9a4 |
children |
rev | line source |
---|---|
1
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 /**************************************************************************** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 ** All right reserved. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 ** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 ** Permission is hereby granted, free of charge, to any person obtaining |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 ** a copy of this software and associated documentation files (the |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 ** "Software"), to deal in the Software without restriction, including |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 ** without limitation the rights to use, copy, modify, merge, publish, |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 ** distribute, sublicense, and/or sell copies of the Software, and to |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 ** permit persons to whom the Software is furnished to do so, subject to |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 ** the following conditions: |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 ** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 ** The above copyright notice and this permission notice shall be |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 ** included in all copies or substantial portions of the Software. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 ** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 ** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 ****************************************************************************/ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 #include "xlsxcellreference.h" |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 #include <QStringList> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 #include <QMap> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 #include <QRegularExpression> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 QT_BEGIN_NAMESPACE_XLSX |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 namespace { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 int intPow(int x, int p) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 if (p == 0) return 1; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 if (p == 1) return x; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 int tmp = intPow(x, p/2); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 if (p%2 == 0) return tmp * tmp; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 else return x * tmp * tmp; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 QString col_to_name(int col_num) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 static QMap<int, QString> col_cache; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
48 if (!col_cache.contains(col_num)) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 QString col_str; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 int remainder; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 while (col_num) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 remainder = col_num % 26; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 if (remainder == 0) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 remainder = 26; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 col_str.prepend(QChar('A'+remainder-1)); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 col_num = (col_num - 1) / 26; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 col_cache.insert(col_num, col_str); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 return col_cache[col_num]; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 int col_from_name(const QString &col_str) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
65 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 int col = 0; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
67 int expn = 0; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 for (int i=col_str.size()-1; i>-1; --i) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
69 col += (col_str[i].unicode() - 'A' + 1) * intPow(26, expn); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 expn++; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
73 return col; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 } //namespace |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 \class CellReference |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 \brief For one single cell such as "A1" |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 \inmodule QtXlsx |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 The CellReference class stores the cell location in a worksheet. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 Constructs an invalid Cell Reference |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 CellReference::CellReference() |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 : _row(-1), _column(-1) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
92 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
93 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 Constructs the Reference from the given \a row, and \a column. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 CellReference::CellReference(int row, int column) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 : _row(row), _column(column) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
98 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
99 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
100 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
101 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
102 \overload |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
103 Constructs the Reference form the given \a cell string. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
104 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
105 CellReference::CellReference(const QString &cell) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
106 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 init(cell); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
109 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
110 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
111 \overload |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
112 Constructs the Reference form the given \a cell string. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 CellReference::CellReference(const char *cell) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
115 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 init(QString::fromLatin1(cell)); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 void CellReference::init(const QString &cell_str) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
120 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
121 static QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$")); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
122 QRegularExpressionMatch match = re.match(cell_str); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
123 if (match.hasMatch()) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
124 const QString col_str = match.captured(1); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
125 const QString row_str = match.captured(2); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
126 _row = row_str.toInt(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
127 _column = col_from_name(col_str); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
128 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
129 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
130 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
131 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
132 Constructs a Reference by copying the given \a |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 other Reference. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
134 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
135 CellReference::CellReference(const CellReference &other) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
136 : _row(other._row), _column(other._column) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
137 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
138 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
139 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
140 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
141 Destroys the Reference. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
142 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
143 CellReference::~CellReference() |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
144 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
145 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
146 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
147 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
148 Convert the Reference to string notation, such as "A1" or "$A$1". |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
149 If current object is invalid, an empty string will be returned. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
150 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
151 QString CellReference::toString(bool row_abs, bool col_abs) const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
152 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
153 if (!isValid()) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
154 return QString(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
155 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
156 QString cell_str; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
157 if (col_abs) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
158 cell_str.append(QLatin1Char('$')); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
159 cell_str.append(col_to_name(_column)); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
160 if (row_abs) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
161 cell_str.append(QLatin1Char('$')); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
162 cell_str.append(QString::number(_row)); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
163 return cell_str; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
164 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
165 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
166 /*! |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
167 * Returns true if the Reference is valid. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
168 */ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
169 bool CellReference::isValid() const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
170 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
171 return _row > 0 && _column > 0; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
172 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
173 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
174 QT_END_NAMESPACE_XLSX |