21#include "manipulator_data.h"
25#include "kspread_cell.h"
26#include "kspread_sheet.h"
30AbstractDataManipulator::AbstractDataManipulator ()
35AbstractDataManipulator::~AbstractDataManipulator ()
40bool AbstractDataManipulator::process (Element* element)
42 TQRect range = element->rect().normalize();
43 for (
int col = range.left(); col <= range.right(); ++col)
44 for (
int row = range.top(); row <= range.bottom(); ++row) {
48 FormatType fmtType = No_format;
51 if (oldData.contains (col) && oldData[col].contains (row)) {
52 val = oldData[col][row].val;
53 text = oldData[col][row].text;
54 fmtType = oldData[col][row].
format;
58 val = newValue (element, col, row, &parse, &fmtType);
65 Cell *cell = m_sheet->nonDefaultCell (col, row);
68 Cell *cell = m_sheet->cellAt (col, row);
72 Cell *cell = m_sheet->nonDefaultCell (col, row);
80bool AbstractDataManipulator::preProcessing ()
83 if (!m_firstrun)
return true;
85 Region::Iterator endOfList(cells().end());
86 for (Region::Iterator it = cells().begin(); it != endOfList; ++it)
88 TQRect range = (*it)->rect().normalize();
89 for (
int col = range.left(); col <= range.right(); ++col)
90 for (
int row = range.top(); row <= range.bottom(); ++row)
92 Cell* cell = m_sheet->cellAt(col, row);
93 if (cell != m_sheet->defaultCell())
98 st.text = cell->
text();
99 st.val = m_sheet->value (col, row);
101 oldData[col][row] = st;
108DataManipulator::DataManipulator ()
109 : m_format (No_format),
113 m_name = i18n (
"Change Value");
116DataManipulator::~DataManipulator ()
120Value DataManipulator::newValue (Element *element,
int col,
int row,
121 bool *parsing, FormatType *formatType)
123 *parsing = m_parsing;
124 if (m_format != No_format)
125 *formatType = m_format;
126 TQRect range = element->rect().normalize();
127 int colidx = range.left() - col;
128 int rowidx = range.top() - row;
129 return data.
element (colidx, rowidx);
132ArrayFormulaManipulator::ArrayFormulaManipulator ()
134 m_name = i18n (
"Set Array Formula");
137ArrayFormulaManipulator::~ArrayFormulaManipulator ()
141Value ArrayFormulaManipulator::newValue (Element *element,
int col,
int row,
142 bool *parsing, FormatType *)
145 TQRect range = element->rect().normalize();
146 int colidx = col - range.left();
147 int rowidx = row - range.top();
151 if (colidx || rowidx) {
152 return (cellRef + TQString::number (rowidx+1) +
";" +
153 TQString::number (colidx+1) +
")");
155 Cell *cell = m_sheet->nonDefaultCell (col, row);
156 cellRef =
"=INDEX(" + cell->
name() +
";";
161ProtectedCheck::ProtectedCheck ()
165ProtectedCheck::~ProtectedCheck ()
169bool ProtectedCheck::check ()
171 if (!m_sheet->isProtected())
175 Region::Iterator endOfList(
cells().end());
176 for (Region::Iterator it =
cells().begin(); it != endOfList; ++it)
179 TQRect range = element->rect().normalize();
181 for (
int col = range.left(); col <= range.right(); ++col)
183 for (
int row = range.top(); row <= range.bottom(); ++row)
185 Cell *cell = m_sheet->cellAt (col, row);
186 if (!cell->
format()->notProtected (col, row))
For every cell in the spread sheet there is a Cell object.
FormatType formatType() const
Return the format of this cell.
TQString text() const
Return the text the user entered.
TQString name() const
Returns the name of the cell.
void setCellValue(const Value &value, FormatType fmtType=No_format, const TQString &inputText=TQString())
Sets the value for this cell and its formatting and input text, if appropriate.
bool isFormula() const
Returns true if this cell holds a formula.
void setCellText(const TQString &_text, bool asString=false)
The high-level method for setting text, when the user inputs it.
Format * format() const
Returns the format object of this cell.
bool isDefault() const
Returns true if this is a default cell (with row and column equal to zero).
Base class for region elements, which can be points or ranges.
TQValueList< Element * > & cells() const
Provides a wrapper for cell value.
Value element(unsigned column, unsigned row) const
Return an element in the array value.
Format format() const
Returns the format of the value (i.e.
bool isEmpty() const
Returns true if empty.
TQString asString() const
Returns the string value of this value.
AbstractDataManipulator - provides storage of old cell data (for undo) and has an abstract method for...