Skip to content

Commit caa54a2

Browse files
committed
Use a QScopePointer in Anaylsis::run()
1 parent e90c1a7 commit caa54a2

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

analysis/analysisrunner.cpp

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,62 +61,56 @@ void AnalysisRunner::run()
6161

6262
QFileInfo fileInfo(mFilename);
6363

64-
QIODevice * file = nullptr;
6564
QFile rawFile(mFilename);
65+
QScopedPointer<QIODevice> uncompressFile;
6666

6767
if (is_gz(&rawFile))
6868
{
69-
file = new KCompressionDevice(&rawFile,true,KCompressionDevice::GZip);
70-
if (!is_fastq(file))
71-
{
72-
delete file;
73-
file = nullptr;
74-
}
69+
uncompressFile.reset(new KCompressionDevice(&rawFile,false,KCompressionDevice::GZip));
70+
if (!is_fastq(uncompressFile.data()))
71+
return;
72+
7573
}
7674
else if (is_bz2(&rawFile))
7775
{
78-
file = new KCompressionDevice(&rawFile, true, KCompressionDevice::BZip2);
79-
if (!is_fastq(file))
80-
{
81-
delete file;
82-
file = nullptr;
83-
}
76+
uncompressFile.reset(new KCompressionDevice(&rawFile, false, KCompressionDevice::BZip2));
77+
if (!is_fastq(uncompressFile.data()))
78+
return;
8479
}
8580
else if (is_xz(&rawFile))
8681
{
87-
file = new KCompressionDevice(&rawFile,true, KCompressionDevice::Xz);
88-
if (!is_fastq(file))
89-
{
90-
delete file;
91-
file = nullptr;
92-
}
82+
uncompressFile.reset(new KCompressionDevice(&rawFile,false, KCompressionDevice::Xz));
83+
if (!is_fastq(uncompressFile.data()))
84+
return;
9385
}
9486
else if (is_fastq(&rawFile))
9587
{
96-
file = &rawFile;
88+
uncompressFile.reset(new KCompressionDevice(&rawFile,false, KCompressionDevice::None));
89+
if (!is_fastq(uncompressFile.data()))
90+
return;
91+
9792
}
9893

99-
if (file == nullptr)
94+
if (uncompressFile.isNull())
10095
{
10196
qDebug()<<Q_FUNC_INFO<<fileInfo.suffix()<< " file is not supported";
10297
setStatus(Canceled);
103-
delete file;
10498
return;
10599
}
106100

107101
if (fileInfo.size() == 0)
108102
{
109103
setStatus(Canceled);
110-
delete file;
111104
return;
112105
}
113106

114-
if (file->open(QIODevice::ReadOnly))
107+
108+
if (uncompressFile.data()->open(QIODevice::ReadOnly))
115109
{
116110
mSequenceCount = 0;
117111
mProgression = 0;
118112

119-
FastqReader reader(file);
113+
FastqReader reader(uncompressFile.data());
120114
mStartTime.start();
121115

122116

@@ -134,7 +128,6 @@ void AnalysisRunner::run()
134128
{
135129
qCritical()<<Q_FUNC_INFO<<"Cannot read sequence. Are you sure it's a Fastq file ?";
136130
setStatus(Canceled);
137-
delete file;
138131
return ;
139132
}
140133
}
@@ -177,8 +170,6 @@ void AnalysisRunner::run()
177170
qDebug()<<Q_FUNC_INFO<<"Cannot open file";
178171
}
179172

180-
file->close();
181-
file->deleteLater();
182173

183174

184175
}

0 commit comments

Comments
 (0)