Skip to content

Commit 481b624

Browse files
signedav3nids
authored andcommittedJan 22, 2018
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.
1 parent bbac229 commit 481b624

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed
 

‎src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ QgsValueMapConfigDlg::QgsValueMapConfigDlg( QgsVectorLayer *vl, int fieldIdx, QW
4343

4444
QVariantMap QgsValueMapConfigDlg::config()
4545
{
46-
QList<QPair<QString, QVariant>> valueList;
46+
QList<QVariant> valueList;
4747

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

61+
QVariantMap value;
62+
6163
if ( !vi || vi->text().isNull() )
6264
{
63-
valueList.append( qMakePair( ks, ks ) );
65+
value.insert( ks, ks );
6466
}
6567
else
6668
{
67-
valueList.append( qMakePair( vi->text(), ks ) );
69+
value.insert( vi->text(), ks );
6870
}
71+
valueList.append( value );
6972
}
7073

71-
QByteArray ba;
72-
QDataStream data( &ba, QIODevice::WriteOnly );
73-
data << valueList;
74-
7574
QVariantMap cfg;
76-
cfg.insert( QStringLiteral( "map" ), ba );
75+
cfg.insert( QStringLiteral( "map" ), valueList );
7776
return cfg;
7877
}
7978

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

88-
QList<QPair<QString, QVariant>> valueList;
89-
90-
QByteArray ba = config.value( QStringLiteral( "map" ) ).toByteArray();
91-
QDataStream data( &ba, QIODevice::ReadOnly );
92-
data >> valueList;
87+
QList<QVariant> valueList = config.value( QStringLiteral( "map" ) ).toList();
9388

9489
if ( valueList.count() > 0 )
9590
{
9691
for ( int i = 0, row = 0; i < valueList.count(); i++, row++ )
9792
{
98-
setRow( row, valueList[i].second.toString(), valueList[i].first );
93+
setRow( row, valueList[i].toMap().constBegin().value().toString(), valueList[i].toMap().constBegin().key() );
9994
}
10095
}
10196
else

‎src/gui/editorwidgets/qgsvaluemapwidgetwrapper.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,13 @@ void QgsValueMapWidgetWrapper::initWidget( QWidget *editor )
5858

5959
if ( mComboBox )
6060
{
61-
QList<QPair<QString, QVariant>> valueList;
62-
63-
QByteArray ba = config().value( QStringLiteral( "map" ) ).toByteArray();
64-
QDataStream data( &ba, QIODevice::ReadOnly );
65-
data >> valueList;
61+
QList<QVariant> valueList = config().value( QStringLiteral( "map" ) ).toList();
6662

6763
if ( valueList.count() > 0 )
6864
{
69-
for ( int i = 0; i < valueList.count(); i++ )
65+
for ( int i = 0, row = 0; i < valueList.count(); i++, row++ )
7066
{
71-
mComboBox->addItem( valueList[i].first, valueList[i].second );
67+
mComboBox->addItem( valueList[i].toMap().constBegin().key(), valueList[i].toMap().constBegin().value() );
7268
}
7369
}
7470
else

0 commit comments

Comments
 (0)
Please sign in to comment.