Remove an unnecessary indirection in ComicFlow

The timer pointer forced error-prone manual memory management without
any benefits.
This commit is contained in:
Igor Kushnir 2019-11-16 11:38:35 +02:00 committed by Luis Ángel San Martín
parent cb7c967252
commit 04140bef0b
2 changed files with 6 additions and 11 deletions

View File

@ -3,14 +3,11 @@
#include "yacreader_global.h" #include "yacreader_global.h"
#include <QTimer>
ComicFlow::ComicFlow(QWidget *parent, FlowType flowType) ComicFlow::ComicFlow(QWidget *parent, FlowType flowType)
: YACReaderFlow(parent, flowType), worker(new WorkerThread<QImage>) : YACReaderFlow(parent, flowType), worker(new WorkerThread<QImage>)
{ {
resetWorkerIndex(); 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(centerIndexChanged(int)), this, SLOT(preload()));
connect(this, SIGNAL(centerIndexChangedSilent(int)), this, SLOT(preload())); connect(this, SIGNAL(centerIndexChangedSilent(int)), this, SLOT(preload()));
@ -18,10 +15,7 @@ ComicFlow::ComicFlow(QWidget *parent, FlowType flowType)
setReflectionEffect(PlainReflection); setReflectionEffect(PlainReflection);
} }
ComicFlow::~ComicFlow() ComicFlow::~ComicFlow() = default;
{
delete updateTimer;
}
void ComicFlow::setImagePaths(const QStringList &paths) void ComicFlow::setImagePaths(const QStringList &paths)
{ {
@ -55,7 +49,7 @@ void ComicFlow::setImagePaths(const QStringList &paths)
void ComicFlow::preload() void ComicFlow::preload()
{ {
if (numImagesLoaded < imagesLoaded.size()) 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() void ComicFlow::updateImageData()
@ -101,7 +95,7 @@ void ComicFlow::updateImageData()
} }
// no need to generate anything? stop polling... // no need to generate anything? stop polling...
updateTimer->stop(); updateTimer.stop();
} }
void ComicFlow::keyPressEvent(QKeyEvent *event) void ComicFlow::keyPressEvent(QKeyEvent *event)

View File

@ -6,6 +6,7 @@
#include <QtCore> #include <QtCore>
#include <QImage> #include <QImage>
#include <QString> #include <QString>
#include <QTimer>
#include <QWheelEvent> #include <QWheelEvent>
#include <memory> #include <memory>
@ -38,7 +39,7 @@ private:
QVector<bool> imagesSetted; QVector<bool> imagesSetted;
int numImagesLoaded; int numImagesLoaded;
int workerIndex; int workerIndex;
QTimer *updateTimer; QTimer updateTimer;
std::unique_ptr<WorkerThread<QImage>> worker; std::unique_ptr<WorkerThread<QImage>> worker;
virtual void wheelEvent(QWheelEvent *event); virtual void wheelEvent(QWheelEvent *event);
}; };