@@ -276,6 +276,7 @@ QgsIdentifyResultsDialog::QgsIdentifyResultsDialog( QgsMapCanvas *canvas, QWidge
276
276
mExpandNewToolButton ->setChecked ( mySettings.value ( " /Map/identifyExpand" , false ).toBool () );
277
277
mCopyToolButton ->setEnabled ( false );
278
278
lstResults->setColumnCount ( 2 );
279
+ lstResults->sortByColumn ( -1 );
279
280
setColumnText ( 0 , tr ( " Feature" ) );
280
281
setColumnText ( 1 , tr ( " Value" ) );
281
282
@@ -396,49 +397,6 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
396
397
mFeatures << f;
397
398
layItem->addChild ( featItem );
398
399
399
- const QgsFields &fields = vlayer->pendingFields ();
400
- const QgsAttributes& attrs = f.attributes ();
401
- bool featureLabeled = false ;
402
- for ( int i = 0 ; i < attrs.count (); ++i )
403
- {
404
- if ( i >= fields.count () )
405
- continue ;
406
-
407
- QString value = fields[i].displayString ( attrs[i] );
408
- QTreeWidgetItem *attrItem = new QTreeWidgetItem ( QStringList () << QString::number ( i ) << value );
409
-
410
- attrItem->setData ( 0 , Qt::DisplayRole, vlayer->attributeDisplayName ( i ) );
411
- attrItem->setData ( 0 , Qt::UserRole, fields[i].name () );
412
- attrItem->setData ( 0 , Qt::UserRole + 1 , i );
413
-
414
- attrItem->setData ( 1 , Qt::UserRole, value );
415
-
416
- if ( vlayer->editorWidgetV2 ( i ) == " Hidden" )
417
- {
418
- delete attrItem;
419
- continue ;
420
- }
421
-
422
- value = representValue ( vlayer, fields[i].name (), attrs[i] );
423
-
424
- attrItem->setData ( 1 , Qt::DisplayRole, value );
425
-
426
- if ( fields[i].name () == vlayer->displayField () )
427
- {
428
- featItem->setText ( 0 , attrItem->text ( 0 ) );
429
- featItem->setText ( 1 , attrItem->text ( 1 ) );
430
- featureLabeled = true ;
431
- }
432
-
433
- featItem->addChild ( attrItem );
434
- }
435
-
436
- if ( !featureLabeled )
437
- {
438
- featItem->setText ( 0 , tr ( " feature id" ) );
439
- featItem->setText ( 1 , QString::number ( f.id () ) );
440
- }
441
-
442
400
if ( derivedAttributes.size () >= 0 )
443
401
{
444
402
QTreeWidgetItem *derivedItem = new QTreeWidgetItem ( QStringList () << tr ( " (Derived)" ) );
@@ -496,6 +454,49 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
496
454
}
497
455
}
498
456
457
+ const QgsFields &fields = vlayer->pendingFields ();
458
+ const QgsAttributes& attrs = f.attributes ();
459
+ bool featureLabeled = false ;
460
+ for ( int i = 0 ; i < attrs.count (); ++i )
461
+ {
462
+ if ( i >= fields.count () )
463
+ continue ;
464
+
465
+ QString value = fields[i].displayString ( attrs[i] );
466
+ QTreeWidgetItem *attrItem = new QTreeWidgetItem ( QStringList () << QString::number ( i ) << value );
467
+
468
+ attrItem->setData ( 0 , Qt::DisplayRole, vlayer->attributeDisplayName ( i ) );
469
+ attrItem->setData ( 0 , Qt::UserRole, fields[i].name () );
470
+ attrItem->setData ( 0 , Qt::UserRole + 1 , i );
471
+
472
+ attrItem->setData ( 1 , Qt::UserRole, value );
473
+
474
+ if ( vlayer->editorWidgetV2 ( i ) == " Hidden" )
475
+ {
476
+ delete attrItem;
477
+ continue ;
478
+ }
479
+
480
+ value = representValue ( vlayer, fields[i].name (), attrs[i] );
481
+
482
+ attrItem->setData ( 1 , Qt::DisplayRole, value );
483
+
484
+ if ( fields[i].name () == vlayer->displayField () )
485
+ {
486
+ featItem->setText ( 0 , attrItem->text ( 0 ) );
487
+ featItem->setText ( 1 , attrItem->text ( 1 ) );
488
+ featureLabeled = true ;
489
+ }
490
+
491
+ featItem->addChild ( attrItem );
492
+ }
493
+
494
+ if ( !featureLabeled )
495
+ {
496
+ featItem->setText ( 0 , tr ( " feature id" ) );
497
+ featItem->setText ( 1 , QString::number ( f.id () ) );
498
+ }
499
+
499
500
// table
500
501
int j = tblResults->rowCount ();
501
502
for ( int i = 0 ; i < attrs.count (); ++i )
@@ -833,11 +834,6 @@ void QgsIdentifyResultsDialog::editingToggled()
833
834
// Call to show the dialog box.
834
835
void QgsIdentifyResultsDialog::show ()
835
836
{
836
- // Enforce a few things before showing the dialog box
837
- lstResults->sortItems ( 0 , Qt::AscendingOrder );
838
- // column width is now stored in settings
839
- // expandColumnsToFit();
840
-
841
837
bool showFeatureForm = false ;
842
838
843
839
if ( lstResults->topLevelItemCount () > 0 )
@@ -1071,6 +1067,7 @@ void QgsIdentifyResultsDialog::clear()
1071
1067
}
1072
1068
1073
1069
lstResults->clear ();
1070
+ lstResults->sortByColumn ( -1 );
1074
1071
clearHighlights ();
1075
1072
1076
1073
tblResults->clearContents ();
0 commit comments