void Variable::onClickAddTerm() { Term* window = new Term(this); window->setup(*variable); if (window->exec()) { for (int i = variable->numberOfTerms() - 1; i >= 0; --i) { delete variable->removeTerm(i); } for (int i = 0; i < window->dummyVariable->numberOfTerms(); ++i) { variable->addTerm(window->dummyVariable->getTerm(i)->copy()); } reloadModel(); } delete window; }
void Variable::onClickEditTerm() { if (ui->lvw_terms->selectedItems().size() > 1) { std::ostringstream message; message << "Do you want to edit the following terms?\n\n"; for (int i = 0; i < ui->lvw_terms->count(); ++i) { if (ui->lvw_terms->item(i)->isSelected()) { message << "- " << variable->getTerm(i)->toString(); if (i + 1 < ui->lvw_terms->selectedItems().size()) message << "\n\n"; } } QMessageBox::StandardButton clicked = QMessageBox::information(this, "Edit multiple terms", QString::fromStdString(message.str()), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (clicked == QMessageBox::No) { return; } } bool reload = false; for (int i = 0; i < ui->lvw_terms->count(); ++i) { if (ui->lvw_terms->item(i)->isSelected()) { Term* window = new Term(this); window->setup(*variable, variable->getTerm(i)); if (window->exec()) { reload |= true; for (int t = variable->numberOfTerms() - 1; t >= 0; --t) { delete variable->removeTerm(t); } for (int t = 0; t < window->dummyVariable->numberOfTerms(); ++t) { variable->addTerm(window->dummyVariable->getTerm(t)->copy()); } } delete window; } } if (reload) reloadModel(); }