From 04140bef0b2cc2f1c55840b938ce5895aaec46f5 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 16 Nov 2019 11:38:35 +0200 Subject: [PATCH] Remove an unnecessary indirection in ComicFlow The timer pointer forced error-prone manual memory management without any benefits. --- YACReaderLibrary/comic_flow.cpp | 14 ++++---------- YACReaderLibrary/comic_flow.h | 3 ++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/YACReaderLibrary/comic_flow.cpp b/YACReaderLibrary/comic_flow.cpp index dd0b4402..f6bf38ae 100644 --- a/YACReaderLibrary/comic_flow.cpp +++ b/YACReaderLibrary/comic_flow.cpp @@ -3,14 +3,11 @@ #include "yacreader_global.h" -#include - ComicFlow::ComicFlow(QWidget *parent, FlowType flowType) : YACReaderFlow(parent, flowType), worker(new WorkerThread) { resetWorkerIndex(); - updateTimer = new QTimer; - connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateImageData())); + connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateImageData())); connect(this, SIGNAL(centerIndexChanged(int)), this, SLOT(preload())); connect(this, SIGNAL(centerIndexChangedSilent(int)), this, SLOT(preload())); @@ -18,10 +15,7 @@ ComicFlow::ComicFlow(QWidget *parent, FlowType flowType) setReflectionEffect(PlainReflection); } -ComicFlow::~ComicFlow() -{ - delete updateTimer; -} +ComicFlow::~ComicFlow() = default; void ComicFlow::setImagePaths(const QStringList &paths) { @@ -55,7 +49,7 @@ void ComicFlow::setImagePaths(const QStringList &paths) void ComicFlow::preload() { if (numImagesLoaded < imagesLoaded.size()) - updateTimer->start(30); //TODO comprobar rendimiento, originalmente era 70 + updateTimer.start(30); //TODO comprobar rendimiento, originalmente era 70 } void ComicFlow::updateImageData() @@ -101,7 +95,7 @@ void ComicFlow::updateImageData() } // no need to generate anything? stop polling... - updateTimer->stop(); + updateTimer.stop(); } void ComicFlow::keyPressEvent(QKeyEvent *event) diff --git a/YACReaderLibrary/comic_flow.h b/YACReaderLibrary/comic_flow.h index eff0b433..a7f0627f 100644 --- a/YACReaderLibrary/comic_flow.h +++ b/YACReaderLibrary/comic_flow.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -38,7 +39,7 @@ private: QVector imagesSetted; int numImagesLoaded; int workerIndex; - QTimer *updateTimer; + QTimer updateTimer; std::unique_ptr> worker; virtual void wheelEvent(QWheelEvent *event); };