MCPcopy Create free account
hub / github.com/Kitware/VTK / setData

Method setData

Examples/GUI/Qt/CellGridSource/ArrayGroupModel.cxx:133–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133bool ArrayGroupModel::setData(const QModelIndex& index, const QVariant& value, int role)
134{
135 if (role != Qt::EditRole)
136 {
137 return false;
138 }
139 if (index.row() < 0 || index.column() < 0 || index.row() >= this->rowCount(index.parent()) ||
140 index.column() >= this->columnCount(index.parent()))
141 {
142 return false;
143 }
144 // TODO: Record edit to a journal of edits, then update the output cell-grid.
145 auto& colData(this->ColumnToArrayComponent[index.column()]);
146 auto* array = colData.Array;
147 if (auto* dataArray = vtkDataArray::SafeDownCast(array))
148 {
149 if (value.isNull() || value.toString().isEmpty())
150 {
151 return false;
152 }
153 std::vector<double> tuple;
154 tuple.resize(dataArray->GetNumberOfComponents());
155 dataArray->GetTuple(index.row(), tuple.data());
156 tuple[colData.Component] = value.toDouble();
157 dataArray->SetTuple(index.row(), tuple.data());
158 this->Data->Modified();
159 Q_EMIT dataChanged(index, index);
160 return true;
161 }
162 else if (auto* stringArray = vtkStringArray::SafeDownCast(array))
163 {
164 stringArray->SetValue(stringArray->GetNumberOfComponents() * index.row() + colData.Component,
165 value.toString().toStdString());
166 this->Data->Modified();
167 Q_EMIT dataChanged(index, index);
168 return true;
169 }
170 return false;
171}
172
173Qt::ItemFlags ArrayGroupModel::flags(const QModelIndex& index) const
174{

Callers

nothing calls this directly

Calls 14

rowCountMethod · 0.95
columnCountMethod · 0.95
isEmptyMethod · 0.80
rowMethod · 0.45
parentMethod · 0.45
isNullMethod · 0.45
toStringMethod · 0.45
resizeMethod · 0.45
GetNumberOfComponentsMethod · 0.45
GetTupleMethod · 0.45
dataMethod · 0.45
SetTupleMethod · 0.45

Tested by

no test coverage detected