From 9628191f1fe9d381b7c4b4d2065038d49c8afcaa Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 16 Jun 2016 17:07:17 +0300 Subject: [PATCH] Fix problem with PyQt5: list of strings is passed now not as QVariant but as QVariant. --- src/Qtx/QtxPagePrefMgr.cxx | 53 ++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 4ec238be2..e4e5138a7 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -51,6 +51,30 @@ #include +namespace +{ + bool toStringList(const QVariant& value, QStringList& result) + { + bool ok = false; + if ( value.type() == QVariant::StringList ) + { + result = value.toStringList(); + ok = true; + } + else if ( value.type() == QVariant::List ) + { + QList valueList = value.toList(); + for ( QList::const_iterator it = valueList.begin(); it != valueList.end(); ++it ) + { + if ( (*it).canConvert( QVariant::String ) ) + result.append( (*it).toString() ); + } + ok = true; + } + return ok; + } +} + /*! \class QtxPagePrefMgr \brief GUI implementation of the QtxPreferenceMgr class: preferences manager. @@ -2701,7 +2725,7 @@ void QtxPagePrefSelectItem::setInputType( const int type ) QStringList QtxPagePrefSelectItem::strings() const { QStringList res; - for ( uint i = 0; i < mySelector->count(); i++ ) + for ( int i = 0; i < mySelector->count(); i++ ) res.append( mySelector->itemText( i ) ); return res; } @@ -2714,7 +2738,7 @@ QStringList QtxPagePrefSelectItem::strings() const QList QtxPagePrefSelectItem::numbers() const { QList res; - for ( uint i = 0; i < mySelector->count(); i++ ) + for ( int i = 0; i < mySelector->count(); i++ ) { if ( mySelector->hasId( i ) ) res.append( mySelector->id( i ) ); @@ -2730,7 +2754,7 @@ QList QtxPagePrefSelectItem::numbers() const QList QtxPagePrefSelectItem::icons() const { QList res; - for ( uint i = 0; i < mySelector->count(); i++ ) + for ( int i = 0; i < mySelector->count(); i++ ) res.append( mySelector->itemIcon( i ) ); return res; } @@ -2753,7 +2777,7 @@ void QtxPagePrefSelectItem::setStrings( const QStringList& lst ) */ void QtxPagePrefSelectItem::setNumbers( const QList& ids ) { - uint i = 0; + int i = 0; for ( QList::const_iterator it = ids.begin(); it != ids.end(); ++it, i++ ) { if ( i >= mySelector->count() ) mySelector->addItem(QString("") ); @@ -2772,7 +2796,7 @@ void QtxPagePrefSelectItem::setNumbers( const QList& ids ) */ void QtxPagePrefSelectItem::setIcons( const QList& icns ) { - uint i = 0; + int i = 0; for ( QList::const_iterator it = icns.begin(); it != icns.end() && i < mySelector->count(); ++it, i++ ) mySelector->setItemIcon( i, *it ); } @@ -2810,7 +2834,7 @@ void QtxPagePrefSelectItem::retrieve() idx = mySelector->index( num ); else { - for ( uint i = 0; i < mySelector->count() && idx == -1; i++ ) + for ( int i = 0; i < mySelector->count() && idx == -1; i++ ) { if ( mySelector->itemText( i ) == txt ) idx = i; @@ -2896,10 +2920,9 @@ void QtxPagePrefSelectItem::setOptionValue( const QString& name, const QVariant& */ void QtxPagePrefSelectItem::setStrings( const QVariant& var ) { - if ( var.type() != QVariant::StringList ) - return; - - setStrings( var.toStringList() ); + QStringList values; + if ( toStringList( var, values ) ) + setStrings( values ); } /*! @@ -3815,8 +3838,9 @@ void QtxPagePrefFontItem::setOptionValue( const QString& name, const QVariant& v } else if ( name == "fonts" || name == "families" ) { - if ( val.canConvert( QVariant::StringList ) ) - setFonts( val.toStringList() ); + QStringList values; + if ( toStringList( val, values ) ) + setFonts( values ); } else if ( name == "sizes" ) { @@ -4795,8 +4819,9 @@ void QtxPagePrefBackgroundItem::setOptionValue( const QString& name, const QVari setImageFormats( val.toString() ); } else if ( name == "gradient_names" ) { - if ( val.canConvert( QVariant::StringList ) ) - setGradients( val.toStringList() ); + QStringList values; + if ( toStringList( val, values ) ) + setGradients( values ); } else if ( name == "gradient_ids" ) { if ( val.canConvert( QVariant::List ) ) { -- 2.39.2