##// END OF EJS Templates
Fixes crashes on release when duplicating/renaming a variable
Alexandre Leroux -
r722:1590606c0dcd
parent child
Show More
@@ -184,22 +184,29 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
184 if (selectedVariables.size() == 1) {
184 if (selectedVariables.size() == 1) {
185 auto selectedVariable = selectedVariables.front();
185 auto selectedVariable = selectedVariables.front();
186
186
187 auto duplicateFun = [&selectedVariable]() {
187 auto duplicateFun = [varW = std::weak_ptr<Variable>(selectedVariable)]()
188 sqpApp->variableController().cloneVariable(selectedVariable);
188 {
189 if (auto var = varW.lock()) {
190 sqpApp->variableController().cloneVariable(var);
191 }
189 };
192 };
190
193
191 tableMenu.addAction(tr("Duplicate"), duplicateFun);
194 tableMenu.addAction(tr("Duplicate"), duplicateFun);
192
195
193 auto renameFun = [&selectedVariable, &model, this]() {
196 auto renameFun = [ varW = std::weak_ptr<Variable>(selectedVariable), &model, this ]()
194 // Generates forbidden names (names associated to existing variables)
197 {
195 auto allVariables = model->variables();
198 if (auto var = varW.lock()) {
196 auto forbiddenNames = QVector<QString>(allVariables.size());
199 // Generates forbidden names (names associated to existing variables)
197 std::transform(allVariables.cbegin(), allVariables.cend(), forbiddenNames.begin(),
200 auto allVariables = model->variables();
198 [](const auto &variable) { return variable->name(); });
201 auto forbiddenNames = QVector<QString>(allVariables.size());
199
202 std::transform(allVariables.cbegin(), allVariables.cend(),
200 RenameVariableDialog dialog{selectedVariable->name(), forbiddenNames, this};
203 forbiddenNames.begin(),
201 if (dialog.exec() == QDialog::Accepted) {
204 [](const auto &variable) { return variable->name(); });
202 selectedVariable->setName(dialog.name());
205
206 RenameVariableDialog dialog{var->name(), forbiddenNames, this};
207 if (dialog.exec() == QDialog::Accepted) {
208 var->setName(dialog.name());
209 }
203 }
210 }
204 };
211 };
205
212
General Comments 0
You need to be logged in to leave comments. Login now