App: fix memory leaks in Enumeration class and simplify code

This commit is contained in:
wmayer
2022-05-10 18:47:23 +02:00
committed by wwmayer
parent d7313598aa
commit 7db925d991
12 changed files with 329 additions and 340 deletions

View File

@@ -78,17 +78,15 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare
ui->ThreadType->setCurrentIndex(pcHole->ThreadType.getValue());
ui->ThreadSize->clear();
const char** cursor = pcHole->ThreadSize.getEnums();
while (*cursor) {
ui->ThreadSize->addItem(tr(*cursor));
++cursor;
std::vector<std::string> cursor = pcHole->ThreadSize.getEnumVector();
for (const auto& it : cursor) {
ui->ThreadSize->addItem(tr(it.c_str()));
}
ui->ThreadSize->setCurrentIndex(pcHole->ThreadSize.getValue());
ui->ThreadClass->clear();
cursor = pcHole->ThreadClass.getEnums();
while (*cursor) {
ui->ThreadClass->addItem(tr(*cursor));
++cursor;
cursor = pcHole->ThreadClass.getEnumVector();
for (const auto& it : cursor) {
ui->ThreadClass->addItem(tr(it.c_str()));
}
ui->ThreadClass->setCurrentIndex(pcHole->ThreadClass.getValue());
// Class is only enabled (sensible) if threaded
@@ -109,10 +107,9 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare
ui->directionRightHand->setEnabled(pcHole->Threaded.getValue());
ui->directionLeftHand->setEnabled(pcHole->Threaded.getValue());
ui->HoleCutType->clear();
cursor = pcHole->HoleCutType.getEnums();
while (*cursor) {
ui->HoleCutType->addItem(tr(*cursor));
++cursor;
cursor = pcHole->HoleCutType.getEnumVector();
for (const auto& it : cursor) {
ui->HoleCutType->addItem(tr(it.c_str()));
}
ui->HoleCutType->setCurrentIndex(pcHole->HoleCutType.getValue());
ui->HoleCutCustomValues->setChecked(pcHole->HoleCutCustomValues.getValue());
@@ -714,10 +711,9 @@ void TaskHoleParameters::changedObject(const App::Document&, const App::Property
ui->ThreadSize->blockSignals(true);
ui->ThreadSize->clear();
const char** cursor = pcHole->ThreadSize.getEnums();
while (*cursor) {
ui->ThreadSize->addItem(QString::fromLatin1(*cursor));
++cursor;
std::vector<std::string> cursor = pcHole->ThreadSize.getEnumVector();
for (const auto& it : cursor) {
ui->ThreadSize->addItem(QString::fromStdString(it));
}
ui->ThreadSize->setCurrentIndex(pcHole->ThreadSize.getValue());
ui->ThreadSize->blockSignals(false);
@@ -725,20 +721,18 @@ void TaskHoleParameters::changedObject(const App::Document&, const App::Property
// Thread type also updates HoleCutType and ThreadClass
ui->HoleCutType->blockSignals(true);
ui->HoleCutType->clear();
cursor = pcHole->HoleCutType.getEnums();
while (*cursor) {
ui->HoleCutType->addItem(QString::fromLatin1(*cursor));
++cursor;
cursor = pcHole->HoleCutType.getEnumVector();
for (const auto& it: cursor) {
ui->HoleCutType->addItem(QString::fromStdString(it));
}
ui->HoleCutType->setCurrentIndex(pcHole->HoleCutType.getValue());
ui->HoleCutType->blockSignals(false);
ui->ThreadClass->blockSignals(true);
ui->ThreadClass->clear();
cursor = pcHole->ThreadClass.getEnums();
while (*cursor) {
ui->ThreadClass->addItem(QString::fromLatin1(*cursor));
++cursor;
cursor = pcHole->ThreadClass.getEnumVector();
for (const auto& it : cursor) {
ui->ThreadClass->addItem(QString::fromStdString(it));
}
ui->ThreadClass->setCurrentIndex(pcHole->ThreadClass.getValue());
ui->ThreadClass->blockSignals(false);