Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Qt::endl with QTextStream #555

Merged
merged 3 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/CacheDisk.h
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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