]> granicus.if.org Git - graphviz/commitdiff
gvedit: use a 'unique_ptr' to avoid manually managing 'previewFrm'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 9 Apr 2022 17:12:56 +0000 (10:12 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 28 Apr 2022 01:54:13 +0000 (18:54 -0700)
cmd/gvedit/csettings.cpp
cmd/gvedit/mdichild.cpp
cmd/gvedit/mdichild.h

index ac3a7842d2e87db8aea765adb3f9ef07dd7882aa..212bf026aa0edb4081ac6b29ca280b710b240e16 100644 (file)
@@ -357,10 +357,9 @@ static QString buildTempFile()
 
 void CFrmSettings::doPreview(QString fileName)
 {
-    if (getActiveWindow()->previewFrm) {
+    if (getActiveWindow()->previewFrm != nullptr) {
        getActiveWindow()->parentFrm->mdiArea->
            removeSubWindow(getActiveWindow()->previewFrm->subWindowRef);
-       delete getActiveWindow()->previewFrm;
        getActiveWindow()->previewFrm = NULL;
     }
 
index 0b520e19b5a82246b99d93daf19f98f6e5ff88ac..3b41ce55c2b65f267e1caf0d23dfa0b0d775de26 100644 (file)
@@ -8,7 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
-
+#include <memory>
 #include <QtWidgets>
 
 #include "mdichild.h"
@@ -22,7 +22,6 @@ MdiChild::MdiChild()
     renderIdx = 0;
     preview = true;
     applyCairo = false;
-    previewFrm = NULL;
     settingsSet = false;
 }
 
@@ -156,10 +155,10 @@ QString MdiChild::strippedName(const QString & fullFileName)
 
 bool MdiChild::loadPreview(QString fileName)
 {
-    if (!this->previewFrm) {
-       previewFrm = new ImageViewer();
+    if (previewFrm == nullptr) {
+       previewFrm = std::unique_ptr<ImageViewer>(new ImageViewer());
        previewFrm->graphWindow = this;
-       QMdiSubWindow *s = parentFrm->mdiArea->addSubWindow(previewFrm);
+       QMdiSubWindow *s = parentFrm->mdiArea->addSubWindow(previewFrm.get());
 
        s->resize(600, 400);
        s->move(parentFrm->mdiArea->subWindowList().count() * 5,
index f1da1d0d06e9ddef5f272dbf300768c3fe9d3241..ce21f55597220cd242ba15a6659cf5eb932f48aa 100644 (file)
@@ -10,6 +10,7 @@
 
 #pragma once
 
+#include <memory>
 #include <QTextEdit>
 #include "imageviewer.h"
 class CMainWindow;
@@ -34,7 +35,7 @@ public:
     bool preview;
     bool applyCairo;
     QString attributes;
-    ImageViewer* previewFrm;
+    std::unique_ptr<ImageViewer> previewFrm;
     CMainWindow* parentFrm;
     bool loadPreview(QString fileName);
     bool firstTime();