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 all 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
28 changes: 27 additions & 1 deletion MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,11 @@ void MainWindow::on_treeView_doubleClicked(const QModelIndex &index) {
void MainWindow::on_actionClearRecentMenu_triggered() { _recentFiles->clear(); }

void MainWindow::CreateResource(TypeCase typeCase) {
if(this->treeModel == NULL){
qDebug() << "Attempt to add resource with NULL treeModel...";
return;
}

TreeNode child;
auto fieldNum = ResTypeFields[typeCase];
const Descriptor *desc = child.GetDescriptor();
Expand All @@ -564,10 +569,31 @@ 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);

TreeModel::Node *node = this->treeModel->IndexToNode(index);
if(node == NULL){
qDebug() << "Attempt to add resource with NULL treeModel node...";
return;
}

ProtoModel *protoModel = node->BackingModel();
if(protoModel == NULL){
qDebug() << "Attempt to add resource with NULL protoModel...";
return;
}

MessageModel *messageModel = protoModel->TryCastAsMessageModel();
// add new resource with created name, helps in creating another unique name
if(messageModel)
resourceMap->AddResource(typeCase, resourceName, messageModel);
else
qDebug() << "Attempt to add resource with NULL messageModel...";
}

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

// NOTE: There is an unhandled BUG related to order in which references are deleted,
// and following hack doesnt solve it

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

// 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