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

clean: deprecations that won't break Qt5 compatibility #1433

Merged
merged 2 commits into from
Mar 22, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/audioplayerfactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ void AudioPlayerFactory::reset()
#endif
}

QScopedPointer< ExternalAudioPlayer > externalPlayer( new ExternalAudioPlayer );
std::unique_ptr< ExternalAudioPlayer > externalPlayer( new ExternalAudioPlayer );
setAudioPlaybackProgram( *externalPlayer );
playerPtr.reset( externalPlayer.take() );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They realize that .take() makes the existence of this pointer type pointless, so it is removed.

qt/qtbase@612a01b

playerPtr.reset( externalPlayer.release() );
}

void AudioPlayerFactory::setAudioPlaybackProgram( ExternalAudioPlayer & externalPlayer )
Expand Down
2 changes: 1 addition & 1 deletion src/dict/sources.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Sources::Sources( QWidget * parent, Config::Class const & cfg ):
// anyone?
QItemEditorCreatorBase * programTypeEditorCreator = new QStandardItemEditorCreator< ProgramTypeEditor >();

itemEditorFactory->registerEditor( QVariant::Int, programTypeEditorCreator );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

itemEditorFactory->registerEditor( QMetaType::Int, programTypeEditorCreator );

itemDelegate->setItemEditorFactory( itemEditorFactory.get() );

Expand Down
10 changes: 5 additions & 5 deletions src/externalaudioplayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ExternalAudioPlayer::~ExternalAudioPlayer()

// Set viewer to null first and foremost to make sure that onViewerDestroyed()
// doesn't attempt to start viewer or mess the smart pointer up.
stopAndDestroySynchronously( viewer.take() );
stopAndDestroySynchronously( viewer.release() );

stopAndDestroySynchronously( exitingViewer );
}
Expand Down Expand Up @@ -56,7 +56,7 @@ void ExternalAudioPlayer::stop()
// 1) the process gets a chance to clean up and save its state;
// 2) there is no event loop blocking and consequently no (short) UI freeze
// while synchronously waiting for the external process to exit.
exitingViewer = viewer.take();
exitingViewer = viewer.release();
}
else // viewer is either not started or already stopped -> simply destroy it.
viewer.reset();
Expand All @@ -72,14 +72,14 @@ void ExternalAudioPlayer::onViewerDestroyed( QObject * destroyedViewer )
emit error( errorMessage );
}
}
else if ( viewer.data() == destroyedViewer )
viewer.take(); // viewer finished and died -> release ownership.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take() by nothing is reset to null.

else if ( viewer.get() == destroyedViewer )
viewer.reset( nullptr ); // viewer finished and died -> reset
}

QString ExternalAudioPlayer::startViewer()
{
Q_ASSERT( !exitingViewer && viewer );
connect( viewer.data(), &QObject::destroyed, this, &ExternalAudioPlayer::onViewerDestroyed );
connect( viewer.get(), &QObject::destroyed, this, &ExternalAudioPlayer::onViewerDestroyed );
try {
viewer->start();
}
Expand Down
9 changes: 4 additions & 5 deletions src/externalaudioplayer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#ifndef EXTERNALAUDIOPLAYER_HH_INCLUDED
#define EXTERNALAUDIOPLAYER_HH_INCLUDED

#include <QScopedPointer>
#include <QString>
#include "audioplayerinterface.hh"
#include <memory>

class ExternalViewer;

Expand Down Expand Up @@ -34,16 +33,16 @@ private:
///< the current viewer (if any) is not started yet
///< and waits for exitingViewer to be destroyed first.

struct ScopedPointerDeleteLater
struct QObjectDeleteLater
{
static void cleanup( QObject * p )
void operator()( QObject * p )
{
if ( p )
p->deleteLater();
}
};
// deleteLater() is safer because viewer actively participates in the QEventLoop.
QScopedPointer< ExternalViewer, ScopedPointerDeleteLater > viewer;
std::unique_ptr< ExternalViewer, QObjectDeleteLater > viewer;
};

#endif // EXTERNALAUDIOPLAYER_HH_INCLUDED
2 changes: 1 addition & 1 deletion src/headwordsmodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void HeadwordListModel::fetchMore( const QModelIndex & parent )
}

QSet< QString > filtered;
for ( const auto & word : qAsConst( headword ) ) {
for ( const auto & word : std::as_const( headword ) ) {
if ( !containWord( word ) )
filtered.insert( word );
}
Expand Down
Loading