@@ -31,6 +31,12 @@ QVariant FeatureCheckListModelBase::data( const QModelIndex &index, int role ) c
3131 {
3232 return mCheckedEntries .isEmpty ();
3333 }
34+
35+ if ( keyField ().isEmpty () )
36+ {
37+ return mCheckedEntries .contains ( FeatureListModel::data ( index, FeatureListModel::FeatureIdRole ).toString () );
38+ }
39+
3440 return mCheckedEntries .contains ( FeatureListModel::data ( index, FeatureListModel::KeyFieldRole ).toString () );
3541 }
3642 else
@@ -49,9 +55,13 @@ bool FeatureCheckListModelBase::setData( const QModelIndex &index, const QVarian
4955 case CheckedRole:
5056 {
5157 if ( value.toBool () )
58+ {
5259 setChecked ( index );
60+ }
5361 else
62+ {
5463 setUnchecked ( index );
64+ }
5565 break ;
5666 }
5767 }
@@ -94,14 +104,21 @@ QVariant FeatureCheckListModelBase::attributeValue() const
94104 {
95105 if ( mAllowMulti )
96106 {
97- if ( mAttributeField .type () == QMetaType::QVariantMap || mAttributeField .type () == QMetaType::QVariantList || mAttributeField .type () == QMetaType::QStringList )
107+ if ( ! mAttributeField .name (). isEmpty () && ( mAttributeField . type () == QMetaType::QVariantMap || mAttributeField .type () == QMetaType::QVariantList || mAttributeField .type () == QMetaType::QStringList ) )
98108 {
99109 value = vl;
100110 }
101111 else
102112 {
103- // make string
104- value = QgsPostgresStringUtils::buildArray ( vl );
113+ if ( mAttributeField .name ().isEmpty () )
114+ {
115+ value = mCheckedEntries ;
116+ }
117+ else
118+ {
119+ // make string
120+ value = QgsPostgresStringUtils::buildArray ( vl );
121+ }
105122 }
106123 }
107124 else
@@ -119,7 +136,7 @@ void FeatureCheckListModelBase::setAttributeValue( const QVariant &attributeValu
119136
120137 if ( mAllowMulti )
121138 {
122- if ( mAttributeField .type () == QMetaType::QVariantMap || mAttributeField .type () == QMetaType::QVariantList || mAttributeField .type () == QMetaType::QStringList )
139+ if ( mAttributeField .name (). isEmpty () || ( mAttributeField . type () == QMetaType::QVariantMap || mAttributeField .type () == QMetaType::QVariantList || mAttributeField .type () == QMetaType::QStringList ) )
123140 {
124141 if ( attributeValue.canConvert <QString>() )
125142 {
@@ -152,11 +169,12 @@ void FeatureCheckListModelBase::setAttributeValue( const QVariant &attributeValu
152169 }
153170
154171 if ( mCheckedEntries == checkedEntries )
172+ {
155173 return ;
174+ }
156175
157- beginResetModel ();
158176 mCheckedEntries = checkedEntries;
159- endResetModel ( );
177+ emit dataChanged ( index ( 0 , 0 , QModelIndex () ), index ( rowCount () - 1 , 0 , QModelIndex () ), QList< int >() << CheckedRole );
160178
161179 emit attributeValueChanged ();
162180}
@@ -194,24 +212,30 @@ void FeatureCheckListModelBase::toggleCheckAll( const bool toggleChecked )
194212 if ( toggleChecked )
195213 {
196214 QStringList checkedEntries;
197-
198215 for ( int i = 0 ; i < rowCount (); i++ )
199- checkedEntries.append ( FeatureListModel::data ( createIndex ( i, 0 ), FeatureListModel::KeyFieldRole ).toString () );
216+ {
217+ if ( keyField ().isEmpty () )
218+ {
219+ checkedEntries.append ( FeatureListModel::data ( createIndex ( i, 0 ), FeatureListModel::FeatureIdRole ).toString () );
220+ }
221+ else
222+ {
223+ checkedEntries.append ( FeatureListModel::data ( createIndex ( i, 0 ), FeatureListModel::KeyFieldRole ).toString () );
224+ }
225+ }
200226
201227 if ( checkedEntries != mCheckedEntries )
202228 {
203- beginResetModel ();
204229 mCheckedEntries = checkedEntries;
205- endResetModel ( );
230+ emit dataChanged ( index ( 0 , 0 , QModelIndex () ), index ( rowCount () - 1 , 0 , QModelIndex () ), QList< int >() << CheckedRole );
206231 }
207232 }
208233 else
209234 {
210235 if ( !mCheckedEntries .isEmpty () )
211236 {
212- beginResetModel ();
213237 mCheckedEntries = QStringList ();
214- endResetModel ( );
238+ emit dataChanged ( index ( 0 , 0 , QModelIndex () ), index ( rowCount () - 1 , 0 , QModelIndex () ), QList< int >() << CheckedRole );
215239 }
216240 }
217241}
@@ -225,8 +249,16 @@ void FeatureCheckListModelBase::setChecked( const QModelIndex &idx )
225249 emit dataChanged ( index ( 0 , 0 , QModelIndex () ), index ( rowCount () - 1 , 0 , QModelIndex () ), QList<int >() << CheckedRole );
226250 }
227251
228- mCheckedEntries .append ( FeatureListModel::data ( idx, FeatureListModel::KeyFieldRole ).toString () );
252+ if ( keyField ().isEmpty () )
253+ {
254+ mCheckedEntries .append ( FeatureListModel::data ( idx, FeatureListModel::FeatureIdRole ).toString () );
255+ }
256+ else
257+ {
258+ mCheckedEntries .append ( FeatureListModel::data ( idx, FeatureListModel::KeyFieldRole ).toString () );
259+ }
229260 emit dataChanged ( idx, idx, QList<int >() << CheckedRole );
261+
230262 if ( addNull () && wasEmpty )
231263 {
232264 QModelIndex nullIdx = index ( 0 , 0 , QModelIndex () );
@@ -238,8 +270,16 @@ void FeatureCheckListModelBase::setChecked( const QModelIndex &idx )
238270void FeatureCheckListModelBase::setUnchecked ( const QModelIndex &idx )
239271{
240272 const bool wasEmpty = mCheckedEntries .isEmpty ();
241- mCheckedEntries .removeAll ( FeatureListModel::data ( idx, FeatureListModel::KeyFieldRole ).toString () );
273+ if ( keyField ().isEmpty () )
274+ {
275+ mCheckedEntries .removeAll ( FeatureListModel::data ( idx, FeatureListModel::FeatureIdRole ).toString () );
276+ }
277+ else
278+ {
279+ mCheckedEntries .removeAll ( FeatureListModel::data ( idx, FeatureListModel::KeyFieldRole ).toString () );
280+ }
242281 emit dataChanged ( idx, idx, QList<int >() << CheckedRole );
282+
243283 if ( addNull () && !wasEmpty && mCheckedEntries .isEmpty () )
244284 {
245285 QModelIndex nullIdx = index ( 0 , 0 , QModelIndex () );
0 commit comments