From 07f928cba72783894b432f2b8e43cd97f2512192 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Thu, 17 Sep 2015 03:46:05 +0300 Subject: [PATCH] Fixed memory leaks for labels --HG-- branch : develop --- src/app/valentina/mainwindow.cpp | 18 ++++++++++++++---- src/app/valentina/mainwindow.h | 5 ++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 672f783d4..af59bd5ea 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1199,18 +1199,28 @@ void MainWindow::ToolBarOption() delete gradationSizes; gradationSizes = nullptr; } + if (not gradationHeightsLabel.isNull()) + { + gradationHeightsLabel.clear(); + } + if (not gradationSizesLabel.isNull()) + { + gradationSizesLabel.clear(); + } if (qApp->patternType() == MeasurementsType::Standard) { const QStringList listHeights = VMeasurement::ListHeights(doc->GetGradationHeights(), qApp->patternUnit()); const QStringList listSizes = VMeasurement::ListSizes(doc->GetGradationSizes(), qApp->patternUnit()); - gradationHeights = SetGradationList(tr("Height: "), listHeights); + gradationHeightsLabel = new QLabel(tr("Height: "), this); + gradationHeights = SetGradationList(gradationHeightsLabel, listHeights); SetDefaultHeight(static_cast(pattern->height())); connect(gradationHeights, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::ChangedHeight); - gradationSizes = SetGradationList(tr("Size: "), listSizes); + gradationSizesLabel = new QLabel(tr("Size: "), this); + gradationSizes = SetGradationList(gradationSizesLabel, listSizes); SetDefaultSize(static_cast(pattern->size())); connect(gradationSizes, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::ChangedSize); @@ -1223,9 +1233,9 @@ void MainWindow::ToolBarOption() } //--------------------------------------------------------------------------------------------------------------------- -QComboBox *MainWindow::SetGradationList(const QString &label, const QStringList &list) +QComboBox *MainWindow::SetGradationList(QPointer &label, const QStringList &list) { - ui->toolBarOption->addWidget(new QLabel(label, this)); + ui->toolBarOption->addWidget(label.data()); QComboBox *comboBox = new QComboBox(this); comboBox->addItems(list); diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index d934cfa93..436d5e0c5 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -38,6 +38,7 @@ #include "tools/drawTools/drawtools.h" #include "core/vcmdexport.h" #include +#include #include @@ -229,6 +230,8 @@ private: bool guiEnabled; QComboBox *gradationHeights; QComboBox *gradationSizes; + QPointer gradationHeightsLabel; + QPointer gradationSizesLabel; VToolOptionsPropertyBrowser *toolOptions; #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) QLockFile *lock; @@ -276,7 +279,7 @@ private: void InitAutoSave(); QString PatternPieceName(const QString &text); QString CheckPathToMeasurements(const QString &patternPath, const QString &path); - QComboBox *SetGradationList(const QString &label, const QStringList &list); + QComboBox *SetGradationList(QPointer &label, const QStringList &list); void ChangePP(int index, bool zoomBestFit = true); /** * @brief EndVisualization try show dialog after and working with tool visualization.