Skip to content

Commit

Permalink
store valuemap as QList instead of QMap
Browse files Browse the repository at this point in the history
because with QMap it loses the order. the two values (key and value) are in an one dimensional QMap stored.
this because QPair is not a QVariant. we desided not to stor it as DataStream, because then less powerfull platforms couldn't use it from the configuration.
  • Loading branch information
signedav authored and 3nids committed Jan 22, 2018
1 parent bbac229 commit 481b624
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
23 changes: 9 additions & 14 deletions src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp
Expand Up @@ -43,7 +43,7 @@ QgsValueMapConfigDlg::QgsValueMapConfigDlg( QgsVectorLayer *vl, int fieldIdx, QW

QVariantMap QgsValueMapConfigDlg::config()
{
QList<QPair<QString, QVariant>> valueList;
QList<QVariant> valueList;

//store data to map
for ( int i = 0; i < tableWidget->rowCount() - 1; i++ )
Expand All @@ -58,22 +58,21 @@ QVariantMap QgsValueMapConfigDlg::config()
if ( ( ks == QgsApplication::nullRepresentation() ) && !( ki->flags() & Qt::ItemIsEditable ) )
ks = QgsValueMapFieldFormatter::NULL_VALUE;

QVariantMap value;

if ( !vi || vi->text().isNull() )
{
valueList.append( qMakePair( ks, ks ) );
value.insert( ks, ks );
}
else
{
valueList.append( qMakePair( vi->text(), ks ) );
value.insert( vi->text(), ks );
}
valueList.append( value );
}

QByteArray ba;
QDataStream data( &ba, QIODevice::WriteOnly );
data << valueList;

QVariantMap cfg;
cfg.insert( QStringLiteral( "map" ), ba );
cfg.insert( QStringLiteral( "map" ), valueList );
return cfg;
}

Expand All @@ -85,17 +84,13 @@ void QgsValueMapConfigDlg::setConfig( const QVariantMap &config )
tableWidget->removeRow( i );
}

QList<QPair<QString, QVariant>> valueList;

QByteArray ba = config.value( QStringLiteral( "map" ) ).toByteArray();
QDataStream data( &ba, QIODevice::ReadOnly );
data >> valueList;
QList<QVariant> valueList = config.value( QStringLiteral( "map" ) ).toList();

if ( valueList.count() > 0 )
{
for ( int i = 0, row = 0; i < valueList.count(); i++, row++ )
{
setRow( row, valueList[i].second.toString(), valueList[i].first );
setRow( row, valueList[i].toMap().constBegin().value().toString(), valueList[i].toMap().constBegin().key() );
}
}
else
Expand Down
10 changes: 3 additions & 7 deletions src/gui/editorwidgets/qgsvaluemapwidgetwrapper.cpp
Expand Up @@ -58,17 +58,13 @@ void QgsValueMapWidgetWrapper::initWidget( QWidget *editor )

if ( mComboBox )
{
QList<QPair<QString, QVariant>> valueList;

QByteArray ba = config().value( QStringLiteral( "map" ) ).toByteArray();
QDataStream data( &ba, QIODevice::ReadOnly );
data >> valueList;
QList<QVariant> valueList = config().value( QStringLiteral( "map" ) ).toList();

if ( valueList.count() > 0 )
{
for ( int i = 0; i < valueList.count(); i++ )
for ( int i = 0, row = 0; i < valueList.count(); i++, row++ )
{
mComboBox->addItem( valueList[i].first, valueList[i].second );
mComboBox->addItem( valueList[i].toMap().constBegin().key(), valueList[i].toMap().constBegin().value() );
}
}
else
Expand Down

0 comments on commit 481b624

Please sign in to comment.