Skip to content

Commit 9e5357c

Browse files
committed
Correctly sort identify results when url links are shown
1 parent 39b3e72 commit 9e5357c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/app/qgsidentifyresultsdialog.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "qgswebview.h"
4242
#include "qgswebframe.h"
4343
#include "qgsstringutils.h"
44+
#include "qgstreewidgetitem.h"
4445

4546
#include <QCloseEvent>
4647
#include <QLabel>
@@ -412,8 +413,9 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
412413

413414
if ( derivedAttributes.size() >= 0 )
414415
{
415-
QTreeWidgetItem *derivedItem = new QTreeWidgetItem( QStringList() << tr( "(Derived)" ) );
416+
QgsTreeWidgetItem *derivedItem = new QgsTreeWidgetItem( QStringList() << tr( "(Derived)" ) );
416417
derivedItem->setData( 0, Qt::UserRole, "derived" );
418+
derivedItem->setAlwaysOnTopPriority( 0 );
417419
featItem->addChild( derivedItem );
418420

419421
for ( QMap< QString, QString>::const_iterator it = derivedAttributes.begin(); it != derivedAttributes.end(); ++it )
@@ -427,8 +429,9 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
427429

428430
if ( !vlayer->fields().isEmpty() || vlayer->actions()->size() || !registeredActions.isEmpty() )
429431
{
430-
QTreeWidgetItem *actionItem = new QTreeWidgetItem( QStringList() << tr( "(Actions)" ) );
432+
QgsTreeWidgetItem *actionItem = new QgsTreeWidgetItem( QStringList() << tr( "(Actions)" ) );
431433
actionItem->setData( 0, Qt::UserRole, "actions" );
434+
actionItem->setAlwaysOnTopPriority( 1 );
432435
featItem->addChild( actionItem );
433436

434437
if ( vlayer->fields().size() > 0 )
@@ -485,7 +488,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
485488
defVal = vlayer->dataProvider()->defaultValue( fields.fieldOriginIndex( i ) ).toString();
486489

487490
QString value = defVal == attrs.at( i ) ? defVal : fields.at( i ).displayString( attrs.at( i ) );
488-
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << value );
491+
QgsTreeWidgetItem *attrItem = new QgsTreeWidgetItem( QStringList() << QString::number( i ) << value );
489492
featItem->addChild( attrItem );
490493

491494
attrItem->setData( 0, Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
@@ -495,14 +498,15 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
495498
attrItem->setData( 1, Qt::UserRole, value );
496499

497500
value = representValue( vlayer, fields.at( i ).name(), attrs.at( i ) );
501+
attrItem->setSortData( 1, value );
498502
bool foundLinks = false;
499503
QString links = QgsStringUtils::insertLinks( value, &foundLinks );
500504
if ( foundLinks )
501505
{
502506
QLabel* valueLabel = new QLabel( links );
503507
valueLabel->setOpenExternalLinks( true );
504-
attrItem->treeWidget()->setItemWidget( attrItem, 1, valueLabel );
505508
attrItem->setData( 1, Qt::DisplayRole, QString() );
509+
attrItem->treeWidget()->setItemWidget( attrItem, 1, valueLabel );
506510
}
507511
else
508512
{
@@ -785,8 +789,9 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,
785789

786790
if ( derivedAttributes.size() >= 0 )
787791
{
788-
QTreeWidgetItem *derivedItem = new QTreeWidgetItem( QStringList() << tr( "(Derived)" ) );
792+
QgsTreeWidgetItem *derivedItem = new QgsTreeWidgetItem( QStringList() << tr( "(Derived)" ) );
789793
derivedItem->setData( 0, Qt::UserRole, "derived" );
794+
derivedItem->setAlwaysOnTopPriority( 0 );
790795
featItem->addChild( derivedItem );
791796

792797
for ( QMap< QString, QString>::const_iterator it = derivedAttributes.begin(); it != derivedAttributes.end(); ++it )
@@ -1495,19 +1500,22 @@ void QgsIdentifyResultsDialog::attributeValueChanged( QgsFeatureId fid, int idx,
14951500
{
14961501
value = representValue( vlayer, fld.name(), val );
14971502

1503+
QgsTreeWidgetItem* treeItem = static_cast< QgsTreeWidgetItem* >( item );
1504+
treeItem->setSortData( 1, value );
1505+
14981506
bool foundLinks = false;
14991507
QString links = QgsStringUtils::insertLinks( value, &foundLinks );
15001508
if ( foundLinks )
15011509
{
15021510
QLabel* valueLabel = new QLabel( links );
15031511
valueLabel->setOpenExternalLinks( true );
1504-
item->treeWidget()->setItemWidget( item, 1, valueLabel );
1505-
item->setData( 1, Qt::DisplayRole, QString() );
1512+
treeItem->setData( 1, Qt::DisplayRole, QString() );
1513+
treeItem->treeWidget()->setItemWidget( item, 1, valueLabel );
15061514
}
15071515
else
15081516
{
1509-
item->treeWidget()->setItemWidget( item, 1, nullptr );
1510-
item->setData( 1, Qt::DisplayRole, value );
1517+
treeItem->setData( 1, Qt::DisplayRole, value );
1518+
treeItem->treeWidget()->setItemWidget( item, 1, nullptr );
15111519
}
15121520
return;
15131521
}

0 commit comments

Comments
 (0)