Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for naming index bug #223 #226

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,19 @@ void MainWindow::CreateResource(TypeCase typeCase) {
refl->MutableMessage(&child, field);

// find a unique name for the new resource
child.set_name(resourceMap->CreateResourceName(&child).toStdString());
QString resourceName = resourceMap->CreateResourceName(&child);
child.set_name(resourceName.toStdString());

// release ownership of the new child to its parent and the tree
auto index = this->treeModel->addNode(child, _ui->treeView->currentIndex());
treeModel->triggerNodeEdit(index, _ui->treeView);

// add new resource with created name, helps in creating another unique name
MessageModel* messageModel = treeModel->IndexToNode(index)->BackingModel()->TryCastAsMessageModel();
KartikShrivastava marked this conversation as resolved.
Show resolved Hide resolved
if(messageModel)
resourceMap->AddResource(typeCase, resourceName, messageModel);
else
qDebug() << "Attempt to add resource with NULL messageModel...";
}

void MainWindow::ResourceModelDeleted(MessageModel *m) {
Expand Down
5 changes: 3 additions & 2 deletions Models/ResourceModelMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ void ResourceModelMap::ResourceRemoved(TypeCase type, const QString& name,
}
}

// Remove an references to this resource
emit ResourceRenamed(ResTypeAsString(type), name, "");
KartikShrivastava marked this conversation as resolved.
Show resolved Hide resolved
// Remove references to this resource
_resources[type].remove(name);
emit DataChanged();
KartikShrivastava marked this conversation as resolved.
Show resolved Hide resolved
}

QString ResourceModelMap::CreateResourceName(TreeNode* node) {
Expand Down