Skip to content

Commit

Permalink
Merge pull request #555 from ferdnyc/fix-deprecated-endl
Browse files Browse the repository at this point in the history
Use Qt::endl with QTextStream
  • Loading branch information
ferdnyc committed Sep 10, 2020
2 parents 131e441 + 92293d3 commit 22f8968
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
2 changes: 0 additions & 2 deletions include/CacheDisk.h
Expand Up @@ -38,8 +38,6 @@
#include "Frame.h"
#include "Exceptions.h"
#include <QDir>
#include <QString>
#include <QTextStream>

namespace openshot {

Expand Down
44 changes: 44 additions & 0 deletions include/QtUtilities.h
@@ -0,0 +1,44 @@
/**
* @file
* @brief Header file for QtUtilities (compatibiity overlay)
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
*/

/* LICENSE
*
* Copyright (c) 2008-2020 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef OPENSHOT_QT_UTILITIES_H
#define OPENSHOT_QT_UTILITIES_H

#include <Qt>
#include <QTextStream>

// Fix Qt::endl for older Qt versions
// From: https://bugreports.qt.io/browse/QTBUG-82680
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
namespace Qt {
using TextStreamFunction = QTextStream& (*)(QTextStream&);
constexpr TextStreamFunction endl = ::endl;
}
#endif

#endif // OPENSHOT_QT_UTILITIES_H
14 changes: 9 additions & 5 deletions src/CacheDisk.cpp
Expand Up @@ -29,6 +29,10 @@
*/

#include "../include/CacheDisk.h"
#include "../include/QtUtilities.h"
#include <Qt>
#include <QString>
#include <QTextStream>

using namespace std;
using namespace openshot;
Expand Down Expand Up @@ -191,18 +195,18 @@ void CacheDisk::Add(std::shared_ptr<Frame> frame)

if (audio_file.open(QIODevice::WriteOnly)) {
QTextStream audio_stream(&audio_file);
audio_stream << frame->SampleRate() << endl;
audio_stream << frame->GetAudioChannelsCount() << endl;
audio_stream << frame->GetAudioSamplesCount() << endl;
audio_stream << frame->ChannelsLayout() << endl;
audio_stream << frame->SampleRate() << Qt::endl;
audio_stream << frame->GetAudioChannelsCount() << Qt::endl;
audio_stream << frame->GetAudioSamplesCount() << Qt::endl;
audio_stream << frame->ChannelsLayout() << Qt::endl;

// Loop through all samples
for (int channel = 0; channel < frame->GetAudioChannelsCount(); channel++)
{
// Get audio for this channel
float *samples = frame->GetAudioSamples(channel);
for (int sample = 0; sample < frame->GetAudioSamplesCount(); sample++)
audio_stream << samples[sample] << endl;
audio_stream << samples[sample] << Qt::endl;
}

}
Expand Down

0 comments on commit 22f8968

Please sign in to comment.