MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / setData

Method setData

src/plugins/binarytools/models/binarytoolsmodel.cpp:132–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132bool BinaryToolsModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
133{
134 if (role != Qt::EditRole)
135 return false;
136
137 QString string = value.toString();
138 if (auto tool = toolForIndex(modelIndex)) {
139 if (string.isEmpty() || tool->name == string)
140 return false;
141
142 // rename tool
143 tool->name = string;
144 emit dataChanged(modelIndex, modelIndex);
145 return true;
146 } else {
147 bool found;
148 QString group = groupForIndex(modelIndex, &found);
149 if (found) {
150 if (string.isEmpty() || binaryTools.contains(string))
151 return false;
152
153 // rename group
154 QList<QString> groupList = binaryTools.keys();
155 int previousIndex = groupList.indexOf(group);
156 groupList.removeAt(previousIndex);
157 groupList.append(string);
158 std::stable_sort(std::begin(groupList), std::end(groupList));
159 int newIndex = groupList.indexOf(string);
160 if (newIndex != previousIndex) {
161 // we have same parent so we have to do special stuff for beginMoveRows...
162 int beginMoveRowsSpecialIndex = (previousIndex < newIndex ? newIndex + 1 : newIndex);
163 beginMoveRows(QModelIndex(), previousIndex, previousIndex, QModelIndex(), beginMoveRowsSpecialIndex);
164 }
165
166 auto items = binaryTools.take(group);
167 binaryTools.insert(string, items);
168 if (newIndex != previousIndex)
169 endMoveRows();
170 return true;
171 }
172 }
173
174 return false;
175}
176
177void BinaryToolsModel::setTools(const QMap<QString, QList<ToolInfo>> &tools)
178{

Callers 2

setModelDataMethod · 0.45
notifyBuildStateMethod · 0.45

Calls 9

takeMethod · 0.80
insertMethod · 0.80
QModelIndexClass · 0.50
toStringMethod · 0.45
isEmptyMethod · 0.45
containsMethod · 0.45
keysMethod · 0.45
indexOfMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected