Skip to content
Permalink
Browse files

store valuemap as QList instead of QMap

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 17, 2018
1 parent bbac229 commit 481b6247377beed128b0f77edce0a1f72bdccbe3
Showing with 12 additions and 21 deletions.
  1. +9 −14 src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp
  2. +3 −7 src/gui/editorwidgets/qgsvaluemapwidgetwrapper.cpp
@@ -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++ )
@@ -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;
}

@@ -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
@@ -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

0 comments on commit 481b624

Please sign in to comment.
You can’t perform that action at this time.