Skip to content

Commit

Permalink
QField shouldn't be built against Qt < 6.6, let's remove all #ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Aug 11, 2024
1 parent 85a4f52 commit 97423d0
Show file tree
Hide file tree
Showing 23 changed files with 18 additions and 324 deletions.
4 changes: 0 additions & 4 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ void initGraphics()
format.setSamples( 4 );
QSurfaceFormat::setDefaultFormat( format );
#endif

#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
QGuiApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
#endif
}

int main( int argc, char **argv )
Expand Down
108 changes: 0 additions & 108 deletions src/core/audiorecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "audiorecorder.h"

#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
#include <QMediaFormat>

AudioRecorder::AudioRecorder( QObject *parent )
Expand All @@ -38,110 +37,3 @@ bool AudioRecorder::hasLevel() const
{
return mHasLevel;
}
#else
AudioRecorder::AudioRecorder( QObject *parent )
: QAudioRecorder( parent )
{
QAudioEncoderSettings as = audioSettings();
#ifdef Q_OS_LINUX
as.setCodec( "audio/x-vorbis" );
setEncodingSettings( as, QVideoEncoderSettings(), QString( "audio/ogg" ) );
#endif

connect( this, &QMediaRecorder::stateChanged, this, [=]() {
mLevel = 0;
emit levelChanged();
emit recordingChanged();
} );

connect( this, &QMediaRecorder::statusChanged, this, [=]() {
if ( status() == QMediaRecorder::LoadedStatus )
{
emit recordingLoaded();
}
} );

mAudioProbe = std::make_unique<QAudioProbe>();
if ( mAudioProbe->setSource( this ) )
{
connect( mAudioProbe.get(), &QAudioProbe::audioBufferProbed, this, &AudioRecorder::audioBufferProbed );
mHasLevel = true;
emit hasLevelChanged();
}
}

bool AudioRecorder::recording() const
{
return state() == QMediaRecorder::RecordingState;
}

double AudioRecorder::level() const
{
return mLevel;
}

bool AudioRecorder::hasLevel() const
{
return mHasLevel;
}

void AudioRecorder::audioBufferProbed( const QAudioBuffer &buffer )
{
double previousLevel = mLevel;
mLevel = 0;

qreal peakValue;
if ( buffer.format().sampleType() == QAudioFormat::SignedInt )
{
if ( buffer.format().sampleSize() == 32 )
peakValue = std::numeric_limits<int>::max();
else if ( buffer.format().sampleSize() == 16 )
peakValue = std::numeric_limits<short>::max();
else
peakValue = std::numeric_limits<char>::max();

const QAudioBuffer::S16S *data = buffer.data<QAudioBuffer::S16S>();
for ( int i = 0; i < buffer.frameCount(); i++ )
{
mLevel += std::max( std::abs( data[i].left ), std::abs( data[i].right ) ) / peakValue;
}
}
else if ( buffer.format().sampleType() == QAudioFormat::UnSignedInt )
{
if ( buffer.format().sampleSize() == 32 )
peakValue = std::numeric_limits<unsigned int>::max();
else if ( buffer.format().sampleSize() == 16 )
peakValue = std::numeric_limits<unsigned short>::max();
else
peakValue = std::numeric_limits<unsigned char>::max();

const QAudioBuffer::S16U *data = buffer.data<QAudioBuffer::S16U>();
for ( int i = 0; i < buffer.frameCount(); i++ )
{
mLevel += std::max( data[i].left, data[i].right ) / peakValue;
}
}
else if ( buffer.format().sampleType() == QAudioFormat::Float )
{
peakValue = 1.00003;

const QAudioBuffer::S32F *data = buffer.data<QAudioBuffer::S32F>();
for ( int i = 0; i < buffer.frameCount(); i++ )
{
mLevel += std::max( std::abs( data[i].left ), std::abs( data[i].right ) ) / peakValue;
}
}

// Smooth level to avoid dizzingly rapid changes
if ( mLevel <= previousLevel )
{
mLevel = std::max( 0.0, std::max( previousLevel - 0.025, mLevel / buffer.frameCount() ) );
}
else
{
mLevel = std::min( 1.0, std::min( previousLevel + 0.025, mLevel / buffer.frameCount() ) );
}

emit levelChanged();
}
#endif
67 changes: 1 addition & 66 deletions src/core/audiorecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
#ifndef AUDIORECORDER_H
#define AUDIORECORDER_H

#include <QObject>
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
#include <QMediaCaptureSession>
#include <QMediaRecorder>
#include <QObject>

class AudioRecorder : public QMediaRecorder
{
Expand Down Expand Up @@ -76,69 +75,5 @@ class AudioRecorder : public QMediaRecorder
bool mHasLevel = false;
double mLevel = 0.0;
};
#else
#include <QAudioProbe>
#include <QAudioRecorder>

class AudioRecorder : public QAudioRecorder
{
Q_OBJECT

Q_PROPERTY( bool recording READ recording NOTIFY recordingChanged )
Q_PROPERTY( bool hasLevel READ hasLevel NOTIFY hasLevelChanged )
Q_PROPERTY( double level READ level NOTIFY levelChanged )

public:
explicit AudioRecorder( QObject *parent = nullptr );

/**
* Returns TRUE when audio is being recorded.
*/
bool recording() const;

/**
* Returns TRUE when audio level/amplitude is available during recording.
* \note this reflects whether a given platform supports QAudioProbe
* \see level()
*/
bool hasLevel() const;

/**
* Returns the current level (0.0 to 1.0) of the audio being recorded.
* \see hasLevel()
*/
double level() const;

signals:
/**
* Emitted when the recording state has changed.
*/
void recordingChanged();

/**
* Emitted upon successfully setting up the audio probe used to return audio levels.
*/
void hasLevelChanged();

/**
* Emitted when the current audio level being recorded has changed.
*/
void levelChanged();

/**
* Emitted when a recorded audio file is finalized and loaded.
*/
void recordingLoaded();

private slots:
void audioBufferProbed( const QAudioBuffer &buffer );

private:
std::unique_ptr<QAudioProbe> mAudioProbe;

bool mHasLevel = false;
double mLevel = 0.0;
};
#endif

#endif // AUDIORECORDER_H
2 changes: 0 additions & 2 deletions src/core/barcodedecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ void BarcodeDecoder::decodeImage( const QImage &image )
return;
}

#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
QVideoSink *BarcodeDecoder::videoSink() const
{
return mVideoSink.get();
Expand Down Expand Up @@ -154,4 +153,3 @@ void BarcodeDecoder::decodeVideoFrame( const QVideoFrame &frame )
} );
mDecodingThread->start();
}
#endif
26 changes: 8 additions & 18 deletions src/core/barcodedecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@

#include <QImage>
#include <QObject>
#include <QThread>
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
#include <QPointer>
#include <QThread>
#include <QVideoSink>
#endif

class BarcodeDecoder : public QObject
{
Q_OBJECT

#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
Q_PROPERTY( QVideoSink *videoSink READ videoSink WRITE setVideoSink NOTIFY videoSinkChanged )
#endif
Q_PROPERTY( QString decodedString READ decodedString NOTIFY decodedStringChanged )

public:
Expand All @@ -52,27 +48,21 @@ class BarcodeDecoder : public QObject
*/
void decodeImage( const QImage &image );

QVideoSink *videoSink() const;
void setVideoSink( QVideoSink *sink );

public slots:
void decodeVideoFrame( const QVideoFrame &frame );

signals:
void decodedStringChanged();
void videoSinkChanged();

private:
QImage mImage;
QString mDecodedString;

#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
QThread *mDecodingThread = nullptr;
QPointer<QVideoSink> mVideoSink;

signals:
void videoSinkChanged();

public slots:
void decodeVideoFrame( const QVideoFrame &frame );

public:
QVideoSink *videoSink() const;
void setVideoSink( QVideoSink *sink );
#endif
};

#endif // BARCODEDECODER_H
8 changes: 0 additions & 8 deletions src/core/nearfieldreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,10 @@ void NearFieldReader::setActive( bool active )
#ifdef WITH_NFC
if ( mActive )
{
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
mNearFieldManager->startTargetDetection( QNearFieldTarget::AnyAccess );
#else
mNearFieldManager->setTargetAccessModes( QNearFieldManager::NdefReadTargetAccess );
mNearFieldManager->startTargetDetection();
#endif
}
else
{
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
mNearFieldManager->setTargetAccessModes( QNearFieldManager::NoTargetAccess );
#endif
mNearFieldManager->stopTargetDetection();
}
#endif
Expand Down
2 changes: 0 additions & 2 deletions src/core/platforms/platformutilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ PlatformUtilities *PlatformUtilities::instance()
return sPlatformUtils;
}

#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 )
Qt::PermissionStatus PlatformUtilities::checkCameraPermission() const
{
QCameraPermission cameraPermission;
Expand All @@ -442,4 +441,3 @@ void PlatformUtilities::requestMicrophonePermission( std::function<void( Qt::Per
QMicrophonePermission microphonePermission;
qApp->requestPermission( microphonePermission, [=]( const QPermission &permission ) { func( permission.status() ); } );
}
#endif
6 changes: 1 addition & 5 deletions src/core/platforms/platformutilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
#include "viewstatus.h"

#include <QObject>
#include <QPermission>
#include <qgsfield.h>

#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 )
#include <QPermission>
#endif

class QFieldCloudConnection;
class ProjectSource;
Expand Down Expand Up @@ -315,12 +313,10 @@ class QFIELD_CORE_EXPORT PlatformUtilities : public QObject

static PlatformUtilities *instance();

#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 )
virtual Qt::PermissionStatus checkCameraPermission() const;
virtual void requestCameraPermission( std::function<void( Qt::PermissionStatus )> func );
virtual Qt::PermissionStatus checkMicrophonePermission() const;
virtual void requestMicrophonePermission( std::function<void( Qt::PermissionStatus )> func );
#endif

signals:
//! Emitted when a resource has been received.
Expand Down
10 changes: 1 addition & 9 deletions src/core/positioning/bluetoothdevicemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

#include <QDebug>
#include <QGuiApplication>
#include <QPermissions>
#include <QSettings>
#include <qgis.h>

#if QT_VERSION >= QT_VERSION_CHECK( 6, 6, 0 )
#include <QPermissions>
#endif

BluetoothDeviceModel::BluetoothDeviceModel( QObject *parent )
: QAbstractListModel( parent )
Expand All @@ -36,11 +34,7 @@ void BluetoothDeviceModel::initiateDiscoveryAgent()
mServiceDiscoveryAgent = std::make_unique<QBluetoothServiceDiscoveryAgent>();

connect( mServiceDiscoveryAgent.get(), &QBluetoothServiceDiscoveryAgent::serviceDiscovered, this, &BluetoothDeviceModel::serviceDiscovered );
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
connect( mServiceDiscoveryAgent.get(), qOverload<QBluetoothServiceDiscoveryAgent::Error>( &QBluetoothServiceDiscoveryAgent::error ), this, [=]( QBluetoothServiceDiscoveryAgent::Error error ) {
#else
connect( mServiceDiscoveryAgent.get(), qOverload<QBluetoothServiceDiscoveryAgent::Error>( &QBluetoothServiceDiscoveryAgent::errorOccurred ), this, [=]( QBluetoothServiceDiscoveryAgent::Error error ) {
#endif
if ( error != QBluetoothServiceDiscoveryAgent::NoError )
{
setLastError( mServiceDiscoveryAgent->errorString() );
Expand All @@ -57,7 +51,6 @@ void BluetoothDeviceModel::initiateDiscoveryAgent()

void BluetoothDeviceModel::startServiceDiscovery( const bool fullDiscovery )
{
#if QT_VERSION >= QT_VERSION_CHECK( 6, 6, 0 )
if ( !mPermissionChecked )
{
QBluetoothPermission bluetoothPermission;
Expand Down Expand Up @@ -86,7 +79,6 @@ void BluetoothDeviceModel::startServiceDiscovery( const bool fullDiscovery )
return;
}
}
#endif

if ( !mServiceDiscoveryAgent )
initiateDiscoveryAgent();
Expand Down
Loading

0 comments on commit 97423d0

Please sign in to comment.