MCPcopy Create free account
hub / github.com/KDE/labplot / setData

Method setData

src/backend/spreadsheet/SpreadsheetModel.cpp:258–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258bool SpreadsheetModel::setData(const QModelIndex& index, const QVariant& value, int role) {
259 if (!index.isValid())
260 return false;
261
262 int row = index.row();
263 auto* column = m_spreadsheet->column(index.column());
264
265 // DEBUG("SpreadsheetModel::setData() value = " << STDSTRING(value.toString()))
266
267 // don't do anything if no new value was provided
268 if (column->columnMode() == AbstractColumn::ColumnMode::Double) {
269 bool ok;
270 double new_value = QLocale().toDouble(value.toString(), &ok);
271 if (ok) {
272 if (column->valueAt(row) == new_value)
273 return false;
274 } else {
275 // an empty (non-numeric value) was provided
276 if (std::isnan(column->valueAt(row)))
277 return false;
278 }
279 } else {
280 if (column->asStringColumn()->textAt(row) == value.toString())
281 return false;
282 }
283
284 switch (role) {
285 case Qt::EditRole:
286 // remark: the validity of the cell is determined by the input filter
287 if (m_formula_mode)
288 column->setFormula(row, value.toString());
289 else
290 column->asStringColumn()->setTextAt(row, value.toString());
291 return true;
292 case static_cast<int>(CustomDataRole::MaskingRole):
293 m_spreadsheet->column(index.column())->setMasked(row, value.toBool());
294 return true;
295 case static_cast<int>(CustomDataRole::FormulaRole):
296 m_spreadsheet->column(index.column())->setFormula(row, value.toString());
297 return true;
298 }
299
300 return false;
301}
302
303QModelIndex SpreadsheetModel::index(int row, int column, const QModelIndex& /*parent*/) const {
304 return createIndex(row, column);

Callers 1

prepareImportMethod · 0.45

Calls 11

asStringColumnMethod · 0.80
setMaskedMethod · 0.80
isValidMethod · 0.45
rowMethod · 0.45
columnMethod · 0.45
columnModeMethod · 0.45
toStringMethod · 0.45
valueAtMethod · 0.45
textAtMethod · 0.45
setFormulaMethod · 0.45
setTextAtMethod · 0.45

Tested by

no test coverage detected