Skip to content

Commit

Permalink
improve: replace all the deprecated method before 5.15
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Jan 8, 2022
1 parent 0c55c85 commit 46b4151
Show file tree
Hide file tree
Showing 29 changed files with 66 additions and 64 deletions.
3 changes: 1 addition & 2 deletions aard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
quint16 volumes = qFromBigEndian( dictHeader.totalVolumes );
if( volumes > 1 )
{
QString ss;
ss.sprintf( " (%i/%i)", qFromBigEndian( dictHeader.volume ), volumes );
QString ss=QString( " (%1/%2)").arg( qFromBigEndian( dictHeader.volume ), volumes );
dictName += ss.toLocal8Bit().data();
}

Expand Down
16 changes: 8 additions & 8 deletions article_netmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using std::string;

connect( baseReply, SIGNAL( metaDataChanged() ), this, SLOT( applyMetaData() ) );

connect( baseReply, SIGNAL( error( QNetworkReply::NetworkError) ),
connect( baseReply, SIGNAL( errorOccurred( QNetworkReply::NetworkError) ),
this, SLOT( applyError( QNetworkReply::NetworkError ) ) );

connect( baseReply, SIGNAL( readyRead() ), this, SLOT( readDataFromBase() ) );
Expand Down Expand Up @@ -113,8 +113,8 @@ using std::string;
baseReply->attribute( QNetworkRequest::HttpPipeliningWasUsedAttribute ) );
setAttribute( QNetworkRequest::BackgroundRequestAttribute,
baseReply->attribute( QNetworkRequest::BackgroundRequestAttribute ) );
setAttribute( QNetworkRequest::SpdyWasUsedAttribute,
baseReply->attribute( QNetworkRequest::SpdyWasUsedAttribute ) );
setAttribute( QNetworkRequest::Http2WasUsedAttribute,
baseReply->attribute( QNetworkRequest::Http2WasUsedAttribute ) );

emit metaDataChanged();
}
Expand All @@ -133,7 +133,7 @@ using std::string;
void AllowFrameReply::applyError( QNetworkReply::NetworkError code )
{
setError( code, baseReply->errorString() );
emit error( code );
emit errorOccurred( code );
}

void AllowFrameReply::readDataFromBase()
Expand Down Expand Up @@ -275,7 +275,7 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
if ( hideGoldenDictHeader && req.url().scheme().startsWith("http", Qt::CaseInsensitive))
{
QNetworkRequest newReq( req );
newReq.setRawHeader("User-Agent", req.rawHeader("User-Agent").replace(qApp->applicationName(), ""));
newReq.setRawHeader("User-Agent", req.rawHeader("User-Agent").replace(qApp->applicationName().toUtf8(), ""));
reply = QNetworkAccessManager::createRequest( op, newReq, outgoingData );
}

Expand Down Expand Up @@ -332,8 +332,8 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(

// See if we have some dictionaries muted

QSet< QString > mutedDicts =
QSet< QString >::fromList( Utils::Url::queryItemValue( url, "muted" ).split( ',' ) );
QStringList mutedDictLists=Utils::Url::queryItemValue( url, "muted" ).split( ',' );
QSet< QString > mutedDicts ( mutedDictLists.begin(),mutedDictLists.end());

// Unpack contexts

Expand Down Expand Up @@ -521,7 +521,7 @@ void ArticleResourceReply::readyReadSlot()
void ArticleResourceReply::finishedSlot()
{
if (req->dataSize() < 0) {
emit error(ContentNotFoundError);
emit errorOccurred(ContentNotFoundError);
setError(ContentNotFoundError, "content not found");
}

Expand Down
6 changes: 4 additions & 2 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -864,15 +864,17 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
int delta = result == Gestures::SWIPE_UP ? -120 : 120;
QWidget *widget = static_cast< QWidget * >( obj );

QPoint angleDelta(0, delta);
QPoint pixelDetal;
QWidget *child = widget->childAt( widget->mapFromGlobal( pt ) );
if( child )
{
QWheelEvent whev( child->mapFromGlobal( pt ), pt, delta, Qt::NoButton, Qt::NoModifier );
QWheelEvent whev( child->mapFromGlobal( pt ), pt, pixelDetal,angleDelta, Qt::NoButton, Qt::NoModifier,Qt::NoScrollPhase,false);
qApp->sendEvent( child, &whev );
}
else
{
QWheelEvent whev( widget->mapFromGlobal( pt ), pt, delta, Qt::NoButton, Qt::NoModifier );
QWheelEvent whev( widget->mapFromGlobal( pt ), pt,pixelDetal, angleDelta,Qt::NoButton, Qt::NoModifier,Qt::NoScrollPhase,false );
qApp->sendEvent( widget, &whev );
}
}
Expand Down
9 changes: 5 additions & 4 deletions btreeidx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1437,16 +1437,17 @@ void BtreeIndex::getHeadwordsFromOffsets( QList<uint32_t> & offsets,

for( unsigned i = 0; i < result.size(); i++ )
{
QList< uint32_t >::Iterator it = qBinaryFind( begOffsets, endOffsets,
result.at( i ).articleOffset );
uint32_t articleOffset = result.at(i).articleOffset;
QList<uint32_t>::Iterator it = std::lower_bound( begOffsets, endOffsets,
articleOffset );

if( it != offsets.end() )
if( it!=offsets.end())
{
if( isCancelled && Utils::AtomicInt::loadAcquire( *isCancelled ) )
return;

headwords.append( QString::fromUtf8( ( result[ i ].prefix + result[ i ].word ).c_str() ) );
offsets.erase( it );
offsets.erase( it);
begOffsets = offsets.begin();
endOffsets = offsets.end();
}
Expand Down
6 changes: 3 additions & 3 deletions dictionary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,13 @@ bool needToRebuildIndex( vector< string > const & dictionaryFiles,
ZipFile::SplitZipFile zf( name );
if( !zf.exists() )
return true;
ts = zf.lastModified().toTime_t();
ts = zf.lastModified().toSecsSinceEpoch();
}
else
{
if ( !fileInfo.exists() )
return true;
ts = fileInfo.lastModified().toTime_t();
ts = fileInfo.lastModified().toSecsSinceEpoch();
}

if ( ts > lastModified )
Expand All @@ -505,7 +505,7 @@ bool needToRebuildIndex( vector< string > const & dictionaryFiles,
if ( !fileInfo.exists() )
return true;

return fileInfo.lastModified().toTime_t() < lastModified;
return fileInfo.lastModified().toSecsSinceEpoch() < lastModified;
}

QString generateRandomDictionaryId()
Expand Down
2 changes: 1 addition & 1 deletion dictionarybar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void DictionaryBar::showContextMenu( QContextMenuEvent * event, bool extended )
{
QString command( editDictionaryCommand );
command.replace( "%GDDICT%", "\"" + dictFilename + "\"" );
if( !QProcess::startDetached( command ) )
if( !QProcess::startDetached( command ,QStringList()) )
QApplication::beep();
}

Expand Down
4 changes: 1 addition & 3 deletions epwing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
vector< sptr< Dictionary::Class > > dictionaries;

vector< string > dictFiles;
QByteArray catName;
catName += QDir::separator();
catName += "catalogs";
QByteArray catName = QString("%1catalogs").arg(QDir::separator()).toUtf8();

for( vector< string >::const_iterator i = fileNames.begin(); i != fileNames.end();
++i )
Expand Down
5 changes: 2 additions & 3 deletions epwing_book.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1732,8 +1732,7 @@ QByteArray EpwingBook::handleReference( EB_Hook_Code code, const unsigned int *
if( refOpenCount > refCloseCount )
return QByteArray();

QString str;
str.sprintf( "<R%i>", refOpenCount );
QString str=QString( "<R%1>").arg( refOpenCount );
refOpenCount += 1;
return str.toUtf8();
}
Expand All @@ -1747,7 +1746,7 @@ QByteArray EpwingBook::handleReference( EB_Hook_Code code, const unsigned int *
refOffsets.append( argv[ 2 ] );

QString str;
str.sprintf( "</R%i>", refCloseCount );
str.asprintf( "</R%i>", refCloseCount );
refCloseCount += 1;

return str.toUtf8();
Expand Down
10 changes: 4 additions & 6 deletions extlineedit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ void ExtLineEdit::updateButtonPositions()
iconPos = (iconPos == Left ? Right : Left);

if (iconPos == ExtLineEdit::Right) {
int right;
getTextMargins(0, 0, &right, 0);
const int iconoffset = right + 4;
QMargins qm=textMargins();
const int iconoffset = qm.right() + 4;
iconButtons[i]->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0));
} else {
int left;
getTextMargins(&left, 0, 0, 0);
const int iconoffset = left + 4;
QMargins qm=textMargins();
const int iconoffset = qm.left() + 4;
iconButtons[i]->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0));
}
}
Expand Down
4 changes: 3 additions & 1 deletion favoritespanewidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,9 @@ void FavoritesModel::removeItemsForIndexes( const QModelIndexList & idxList )
for( int i = lowestLevel; i >= 0; i-- )
{
QModelIndexList idxSublist = itemsToDelete[ i ];
std::sort( idxSublist.begin(), idxSublist.end(), qGreater< QModelIndex >() );
//std::greater does not work ,operator < not implemented ,use std:less first ,then std::reverse.
std::sort(idxSublist.begin(), idxSublist.end(), std::less<QModelIndex>());
std::reverse(idxSublist.begin(), idxSublist.end());

it = idxSublist.begin();
for( ; it != idxSublist.end(); ++it )
Expand Down
2 changes: 1 addition & 1 deletion fulltextsearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ Q_UNUSED( parent );

for( int x = 0; x < hws.length(); x++ )
{
QList< FtsHeadword >::iterator it = qBinaryFind( headwords.begin(), headwords.end(), hws.at( x ) );
QList< FtsHeadword >::iterator it = std::lower_bound( headwords.begin(), headwords.end(), hws.at( x ) );
if( it != headwords.end() )
{
it->dictIDs.push_back( hws.at( x ).dictIDs.front() );
Expand Down
4 changes: 2 additions & 2 deletions gddebug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ QTextCodec *localeCodec = 0;
QTextCodec::setCodecForLocale( utf8Codec );
}

qWarning( "%s", QString().vsprintf( msg, ap ).toUtf8().data() );
qWarning( "%s", QString().vasprintf( msg, ap ).toUtf8().data() );

if( logFilePtr && logFilePtr->isOpen() )
{
Expand All @@ -48,7 +48,7 @@ QTextCodec *localeCodec = 0;
QTextCodec::setCodecForLocale( utf8Codec );
}

qDebug( "%s", QString().vsprintf( msg, ap ).toUtf8().data() );
qDebug( "%s", QString().vasprintf( msg, ap ).toUtf8().data() );

if( logFilePtr && logFilePtr->isOpen() )
{
Expand Down
2 changes: 1 addition & 1 deletion goldendict.pro
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ QT += widgets \
printsupport \
help

#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00

# QMediaPlayer is not available in Qt4.
!CONFIG( no_qtmultimedia_player ) {
Expand Down
4 changes: 2 additions & 2 deletions groups_widgets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,8 @@ void DictGroupsWidget::addAutoGroups()
dictMap[ name ] = vd;
}

QStringList groupList = dictMap.uniqueKeys();
QStringList morphoList = morphoMap.uniqueKeys();
QStringList groupList = dictMap.keys();
QStringList morphoList = morphoMap.keys();

// Insert morphology dictionaries into corresponding lists

Expand Down
9 changes: 6 additions & 3 deletions helpwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "helpwindow.hh"
#include "gddebug.hh"
#include <QHelpLink>

namespace Help {

Expand All @@ -25,9 +26,11 @@ void HelpBrowser::showHelpForKeyword( QString const & id )
{
if ( helpEngine )
{
QMap< QString, QUrl > links = helpEngine->linksForIdentifier( id );
if( !links.isEmpty() )
setSource( links.constBegin().value() );
QList<QHelpLink> links = helpEngine->documentsForIdentifier(id);
if (!links.isEmpty()) {
QHelpLink link=links.constFirst();
setSource(link.url);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion hotkeyedit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void HotKeyEdit::keyPressEvent( QKeyEvent * event )
// Delete current combo
currentKey1 = 0;
currentKey2 = 0;
currentModifiers = 0;
currentModifiers = Qt::NoModifier;
continuingCombo = false;
}
else
Expand Down
4 changes: 2 additions & 2 deletions mainstatusbar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ MainStatusBar::MainStatusBar( QWidget *parent ) : QWidget( parent )

bool MainStatusBar::hasImage() const
{
return !picWidget->pixmap()->isNull();
return !picWidget->pixmap().isNull();
}

void MainStatusBar::clearMessage()
Expand Down Expand Up @@ -92,7 +92,7 @@ void MainStatusBar::refresh()
{
adjustSize();

if ( !picWidget->pixmap()->isNull() )
if ( !picWidget->pixmap().isNull() )
{
picWidget->setFixedSize( textWidget->height(), textWidget->height() );
}
Expand Down
2 changes: 1 addition & 1 deletion maintabwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool MainTabWidget::eventFilter( QObject * obj, QEvent * ev )
if( obj == tabBar() && ev->type() == QEvent::MouseButtonPress )
{
QMouseEvent * mev = static_cast< QMouseEvent *>( ev );
if( mev->button() == Qt::MidButton )
if( mev->button() == Qt::MiddleButton )
{
emit tabCloseRequested( tabBar()->tabAt( mev->pos() ) );
return true;
Expand Down
9 changes: 4 additions & 5 deletions mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ void MainWindow::mousePressEvent( QMouseEvent *event)
return;
}

if (event->button() != Qt::MidButton)
if (event->button() != Qt::MiddleButton)
return QMainWindow::mousePressEvent(event);

// middle clicked
Expand Down Expand Up @@ -1199,11 +1199,11 @@ void MainWindow::wheelEvent( QWheelEvent *ev )
{
if ( ev->modifiers().testFlag( Qt::ControlModifier ) )
{
if ( ev->delta() > 0 )
if ( ev->angleDelta().y() > 0 )
{
zoomin();
}
else if ( ev->delta() < 0 )
else if ( ev->angleDelta().y() < 0 )
{
zoomout();
}
Expand Down Expand Up @@ -4344,12 +4344,11 @@ void MainWindow::editDictionary( Dictionary::Class * dict )
QString headword = unescapeTabHeader( ui.tabWidget->tabText( ui.tabWidget->currentIndex() ) );
command.replace( "%GDWORD%", headword );
}
if( !QProcess::startDetached( command ) )
if( !QProcess::startDetached( command,QStringList() ) )
QApplication::beep();
}
}


void MainWindow::openDictionaryFolder( const QString & id )
{
for( unsigned x = 0; x < dictionaries.size(); x++ )
Expand Down
2 changes: 1 addition & 1 deletion mainwindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ class ArticleSaveProgressDialog : public QProgressDialog
Q_OBJECT

public:
explicit ArticleSaveProgressDialog( QWidget * parent = 0, Qt::WindowFlags f = 0 ):
explicit ArticleSaveProgressDialog( QWidget * parent = 0, Qt::WindowFlags f = Qt::Widget ):
QProgressDialog( parent, f )
{
setAutoReset( false );
Expand Down
2 changes: 1 addition & 1 deletion mdictparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ bool MdictParser::readHeader( QDataStream & in )
if ( headerAttributes.contains( "StyleSheet" ) )
{
QString styleSheets = headerAttributes.namedItem( "StyleSheet" ).toAttr().value();
QStringList lines = styleSheets.split( QRegularExpression( "[\r\n]" ), QString::KeepEmptyParts );
QStringList lines = styleSheets.split( QRegularExpression( "[\r\n]" ), Qt::KeepEmptyParts );

for ( int i = 0; i < lines.size() - 3; i += 3 )
{
Expand Down
4 changes: 2 additions & 2 deletions preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
if ( lang == "qt" )
continue; // We skip qt's own localizations

sortedLocs.insertMulti(
sortedLocs.insert(
Language::localizedNameForId( LangCoder::code2toInt( lang.toLatin1().data() ) ),
QPair< QIcon, QString >(
QIcon( QString( ":/flags/%1.png" ).arg( i->mid( 3, 2 ).toLower() ) ),
Expand Down Expand Up @@ -122,7 +122,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
reg = lang.toUpper();
}

sortedHelps.insertMulti(
sortedHelps.insert(
Language::localizedNameForId( LangCoder::code2toInt( lang.toLatin1().data() ) ),
QPair< QIcon, QString >(
QIcon( QString( ":/flags/%1.png" ).arg( reg.toLower() ) ), lang + "_" + reg ) );
Expand Down
3 changes: 2 additions & 1 deletion scanflag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "scanflag.hh"
#include "ui_scanflag.h"
#include <QScreen>

static Qt::WindowFlags popupWindowFlags =

Expand Down Expand Up @@ -53,7 +54,7 @@ void ScanFlag::showScanFlag()

QPoint currentPos = QCursor::pos();

QRect desktop = QApplication::desktop()->screenGeometry();
QRect desktop = QGuiApplication::primaryScreen()->geometry();

QSize windowSize = geometry().size();

Expand Down
Loading

0 comments on commit 46b4151

Please sign in to comment.