| 240 | } |
| 241 | |
| 242 | void InstanceList::setInstanceGroup(const InstanceId& id, GroupId name) |
| 243 | { |
| 244 | if (name.isEmpty() && !name.isNull()) |
| 245 | name = QString(); |
| 246 | |
| 247 | auto inst = getInstanceById(id); |
| 248 | if (!inst) { |
| 249 | qDebug() << "Attempt to set a null instance's group"; |
| 250 | return; |
| 251 | } |
| 252 | |
| 253 | bool changed = false; |
| 254 | auto iter = m_instanceGroupIndex.find(inst->id()); |
| 255 | if (iter != m_instanceGroupIndex.end()) { |
| 256 | if (*iter != name) { |
| 257 | decreaseGroupCount(*iter); |
| 258 | *iter = name; |
| 259 | changed = true; |
| 260 | } |
| 261 | } else { |
| 262 | changed = true; |
| 263 | m_instanceGroupIndex[id] = name; |
| 264 | } |
| 265 | |
| 266 | if (changed) { |
| 267 | increaseGroupCount(name); |
| 268 | auto idx = getInstIndex(inst.get()); |
| 269 | emit dataChanged(index(idx), index(idx), { GroupRole }); |
| 270 | saveGroupList(); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | QStringList InstanceList::getGroups() |
| 275 | { |