| 130 | } |
| 131 | |
| 132 | bool 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 | |
| 177 | void BinaryToolsModel::setTools(const QMap<QString, QList<ToolInfo>> &tools) |
| 178 | { |