Fix uses of deprecated Qt methods

There are still a few leftovers from the Qt 3 to Qt 4 migration that can
be found by defining QT_NO_DEPRECATED. Here is a summary of the changes:

* QDir::convertSeparators was changed to QDir::toNativeSeparators with Qt 4

* QRexExp::numCaptures was changed to captureCount with Qt 4

* QTextIStream/QTextOStream was merged into QTextStream with Qt 4

* QFileDialog::selectFilter/filters was changed to
  selectNameFilter/nameFilters with Qt 4.4

* qVariantCanConvert/qVariantValue was changed to canConvert/value with Qt
  4

Note that if a conversion to Qt 5 will happen someday, this will have to
be done since Qt 5 removes these deprecations.
This commit is contained in:
Carl Simonson 2014-03-16 11:16:25 -05:00
parent 1c0d5e2f21
commit 3e0e0edec7
8 changed files with 28 additions and 29 deletions

View File

@ -516,7 +516,7 @@ int main( int argc, char *argv[] )
} }
else if ( i + 1 < argc && ( arg == "--snapshot" || arg == "-s" ) ) else if ( i + 1 < argc && ( arg == "--snapshot" || arg == "-s" ) )
{ {
mySnapshotFileName = QDir::convertSeparators( QFileInfo( args[++i] ).absoluteFilePath() ); mySnapshotFileName = QDir::toNativeSeparators( QFileInfo( args[++i] ).absoluteFilePath() );
} }
else if ( i + 1 < argc && ( arg == "--width" || arg == "-w" ) ) else if ( i + 1 < argc && ( arg == "--width" || arg == "-w" ) )
{ {
@ -532,7 +532,7 @@ int main( int argc, char *argv[] )
} }
else if ( i + 1 < argc && ( arg == "--project" || arg == "-p" ) ) else if ( i + 1 < argc && ( arg == "--project" || arg == "-p" ) )
{ {
myProjectFileName = QDir::convertSeparators( QFileInfo( args[++i] ).absoluteFilePath() ); myProjectFileName = QDir::toNativeSeparators( QFileInfo( args[++i] ).absoluteFilePath() );
} }
else if ( i + 1 < argc && ( arg == "--extent" || arg == "-e" ) ) else if ( i + 1 < argc && ( arg == "--extent" || arg == "-e" ) )
{ {
@ -540,23 +540,23 @@ int main( int argc, char *argv[] )
} }
else if ( i + 1 < argc && ( arg == "--optionspath" || arg == "-o" ) ) else if ( i + 1 < argc && ( arg == "--optionspath" || arg == "-o" ) )
{ {
optionpath = QDir::convertSeparators( QDir( args[++i] ).absolutePath() ); optionpath = QDir::toNativeSeparators( QDir( args[++i] ).absolutePath() );
} }
else if ( i + 1 < argc && ( arg == "--configpath" || arg == "-c" ) ) else if ( i + 1 < argc && ( arg == "--configpath" || arg == "-c" ) )
{ {
configpath = QDir::convertSeparators( QDir( args[++i] ).absolutePath() ); configpath = QDir::toNativeSeparators( QDir( args[++i] ).absolutePath() );
} }
else if ( i + 1 < argc && ( arg == "--code" || arg == "-f" ) ) else if ( i + 1 < argc && ( arg == "--code" || arg == "-f" ) )
{ {
pythonfile = QDir::convertSeparators( QFileInfo( args[++i] ).absoluteFilePath() ); pythonfile = QDir::toNativeSeparators( QFileInfo( args[++i] ).absoluteFilePath() );
} }
else if ( i + 1 < argc && ( arg == "--customizationfile" || arg == "-z" ) ) else if ( i + 1 < argc && ( arg == "--customizationfile" || arg == "-z" ) )
{ {
customizationfile = QDir::convertSeparators( QFileInfo( args[++i] ).absoluteFilePath() ); customizationfile = QDir::toNativeSeparators( QFileInfo( args[++i] ).absoluteFilePath() );
} }
else else
{ {
myFileList.append( QDir::convertSeparators( QFileInfo( args[i] ).absoluteFilePath() ) ); myFileList.append( QDir::toNativeSeparators( QFileInfo( args[i] ).absoluteFilePath() ) );
} }
} }
} }
@ -572,7 +572,7 @@ int main( int argc, char *argv[] )
// check for a .qgs // check for a .qgs
for ( int i = 0; i < args.size(); i++ ) for ( int i = 0; i < args.size(); i++ )
{ {
QString arg = QDir::convertSeparators( QFileInfo( args[i] ).absoluteFilePath() ); QString arg = QDir::toNativeSeparators( QFileInfo( args[i] ).absoluteFilePath() );
if ( arg.contains( ".qgs" ) ) if ( arg.contains( ".qgs" ) )
{ {
myProjectFileName = arg; myProjectFileName = arg;

View File

@ -287,12 +287,12 @@ void QgsAttributeTypeDialog::loadFromCSVButtonPushed()
QString l = s.readLine().trimmed(); QString l = s.readLine().trimmed();
QString key, val; QString key, val;
if ( re0.indexIn( l ) >= 0 && re0.numCaptures() == 2 ) if ( re0.indexIn( l ) >= 0 && re0.captureCount() == 2 )
{ {
key = re0.cap( 1 ).trimmed(); key = re0.cap( 1 ).trimmed();
val = re0.cap( 2 ).trimmed(); val = re0.cap( 2 ).trimmed();
} }
else if ( re1.indexIn( l ) >= 0 && re1.numCaptures() == 2 ) else if ( re1.indexIn( l ) >= 0 && re1.captureCount() == 2 )
{ {
key = re1.cap( 1 ).trimmed(); key = re1.cap( 1 ).trimmed();
val = re1.cap( 2 ).trimmed(); val = re1.cap( 2 ).trimmed();

View File

@ -16,8 +16,7 @@
#include "qgscredentials.h" #include "qgscredentials.h"
#include "qgslogger.h" #include "qgslogger.h"
#include <QTextIStream> #include <QTextStream>
#include <QTextOStream>
QgsCredentials *QgsCredentials::smInstance = 0; QgsCredentials *QgsCredentials::smInstance = 0;

View File

@ -49,7 +49,7 @@ namespace QgisGui
if ( !lastUsedFilter.isEmpty() ) if ( !lastUsedFilter.isEmpty() )
{ {
openFileDialog->selectFilter( lastUsedFilter ); openFileDialog->selectNameFilter( lastUsedFilter );
} }
openFileDialog->addCancelAll(); openFileDialog->addCancelAll();
if ( openFileDialog->exec() == QDialog::Accepted ) if ( openFileDialog->exec() == QDialog::Accepted )
@ -146,7 +146,7 @@ namespace QgisGui
if ( !lastUsedFilter.isEmpty() ) // set the filter to the last one used if ( !lastUsedFilter.isEmpty() ) // set the filter to the last one used
{ {
fileDialog->selectFilter( lastUsedFilter ); fileDialog->selectNameFilter( lastUsedFilter );
} }
//prompt the user for a fileName //prompt the user for a fileName

View File

@ -49,10 +49,10 @@ void QgsDetailedItemDelegate::paint( QPainter * thepPainter,
{ {
// After painting we need to restore the painter to its original state // After painting we need to restore the painter to its original state
thepPainter->save(); thepPainter->save();
if ( qVariantCanConvert<QgsDetailedItemData>( theIndex.data( Qt::UserRole ) ) ) if ( theIndex.data( Qt::UserRole ).canConvert<QgsDetailedItemData>() )
{ {
QgsDetailedItemData myData = QgsDetailedItemData myData =
qVariantValue<QgsDetailedItemData>( theIndex.data( Qt::UserRole ) ); theIndex.data( Qt::UserRole ).value<QgsDetailedItemData>();
if ( myData.isRenderedAsWidget() ) if ( myData.isRenderedAsWidget() )
{ {
paintAsWidget( thepPainter, theOption, myData ); paintAsWidget( thepPainter, theOption, myData );
@ -71,10 +71,10 @@ QSize QgsDetailedItemDelegate::sizeHint(
const QStyleOptionViewItem & theOption, const QStyleOptionViewItem & theOption,
const QModelIndex & theIndex ) const const QModelIndex & theIndex ) const
{ {
if ( qVariantCanConvert<QgsDetailedItemData>( theIndex.data( Qt::UserRole ) ) ) if ( theIndex.data( Qt::UserRole ).canConvert<QgsDetailedItemData>() )
{ {
QgsDetailedItemData myData = QgsDetailedItemData myData =
qVariantValue<QgsDetailedItemData>( theIndex.data( Qt::UserRole ) ); theIndex.data( Qt::UserRole ).value<QgsDetailedItemData>();
if ( myData.isRenderedAsWidget() ) if ( myData.isRenderedAsWidget() )
{ {
return QSize( 378, mpWidget->height() ); return QSize( 378, mpWidget->height() );

View File

@ -61,7 +61,7 @@ QgsEncodingFileDialog::QgsEncodingFileDialog( QWidget * parent,
// need to force selection of the first filter since that corresponds to // need to force selection of the first filter since that corresponds to
// the file name we're looking for; even if we're not here from // the file name we're looking for; even if we're not here from
// findFiles_(), it won't hurt to force selection of the first file filter // findFiles_(), it won't hurt to force selection of the first file filter
selectFilter( filters().at( 0 ) ); selectNameFilter( nameFilters().at( 0 ) );
// Connect our slot to get a signal when the user is done with the file dialog // Connect our slot to get a signal when the user is done with the file dialog
connect( this, SIGNAL( accepted() ), this, SLOT( saveUsedEncoding() ) ); connect( this, SIGNAL( accepted() ), this, SLOT( saveUsedEncoding() ) );

View File

@ -209,11 +209,11 @@ int main( int argc, char *argv[] )
break; break;
case 's': case 's':
mySnapshotFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() ); mySnapshotFileName = QDir::toNativeSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() );
break; break;
case 'l': case 'l':
myLogFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() ); myLogFileName = QDir::toNativeSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() );
break; break;
case 'w': case 'w':
@ -225,7 +225,7 @@ int main( int argc, char *argv[] )
break; break;
case 'p': case 'p':
myProjectFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() ); myProjectFileName = QDir::toNativeSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() );
break; break;
case 'e': case 'e':
@ -278,7 +278,7 @@ int main( int argc, char *argv[] )
int idx = optind; int idx = optind;
QgsDebugMsg( QString( "%1: %2" ).arg( idx ).arg( argv[idx] ) ); QgsDebugMsg( QString( "%1: %2" ).arg( idx ).arg( argv[idx] ) );
#endif #endif
myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[optind++] ) ).absoluteFilePath() ) ); myFileList.append( QDir::toNativeSeparators( QFileInfo( QFile::decodeName( argv[optind++] ) ).absoluteFilePath() ) );
} }
} }
#else #else
@ -297,11 +297,11 @@ int main( int argc, char *argv[] )
} }
else if ( i + 1 < argc && ( arg == "--snapshot" || arg == "-s" ) ) else if ( i + 1 < argc && ( arg == "--snapshot" || arg == "-s" ) )
{ {
mySnapshotFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() ); mySnapshotFileName = QDir::toNativeSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() );
} }
else if ( i + 1 < argc && ( arg == "--log" || arg == "-l" ) ) else if ( i + 1 < argc && ( arg == "--log" || arg == "-l" ) )
{ {
myLogFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() ); myLogFileName = QDir::toNativeSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() );
} }
else if ( i + 1 < argc && ( arg == "--width" || arg == "-w" ) ) else if ( i + 1 < argc && ( arg == "--width" || arg == "-w" ) )
{ {
@ -313,7 +313,7 @@ int main( int argc, char *argv[] )
} }
else if ( i + 1 < argc && ( arg == "--project" || arg == "-p" ) ) else if ( i + 1 < argc && ( arg == "--project" || arg == "-p" ) )
{ {
myProjectFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() ); myProjectFileName = QDir::toNativeSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() );
} }
else if ( i + 1 < argc && ( arg == "--extent" || arg == "-e" ) ) else if ( i + 1 < argc && ( arg == "--extent" || arg == "-e" ) )
{ {
@ -346,7 +346,7 @@ int main( int argc, char *argv[] )
} }
else else
{ {
myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) ); myFileList.append( QDir::toNativeSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
} }
} }
#endif //WIN32 #endif //WIN32
@ -457,7 +457,7 @@ int main( int argc, char *argv[] )
// check for a .qgs // check for a .qgs
for ( int i = 0; i < argc; i++ ) for ( int i = 0; i < argc; i++ )
{ {
QString arg = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ); QString arg = QDir::toNativeSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() );
if ( arg.contains( ".qgs" ) ) if ( arg.contains( ".qgs" ) )
{ {
myProjectFileName = arg; myProjectFileName = arg;

View File

@ -982,7 +982,7 @@ int main( int argc, char *argv[] )
return 1; return 1;
} }
QString myCacheDirPath = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[optind] ) ).absoluteFilePath() ) ; QString myCacheDirPath = QDir::toNativeSeparators( QFileInfo( QFile::decodeName( argv[optind] ) ).absoluteFilePath() ) ;
QgsDebugMsg( "myCacheDirPath = " + myCacheDirPath ); QgsDebugMsg( "myCacheDirPath = " + myCacheDirPath );