Skip to content
Permalink
Browse files

Fix handling of "hide deprecated" in projection selector widget

Fixes #18896
  • Loading branch information
nyalldawson committed May 3, 2018
1 parent f48aaea commit a022ad21d4ff5ede1800c8605b8bcae730c80da4
Showing with 51 additions and 78 deletions.
  1. +44 −76 src/gui/qgsprojectionselectiontreewidget.cpp
  2. +7 −2 src/gui/qgsprojectionselectiontreewidget.h
@@ -37,12 +37,14 @@ QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget *par
{
setupUi( this );

leSearch->setShowSearchIcon( true );

connect( lstCoordinateSystems, &QTreeWidget::itemDoubleClicked, this, &QgsProjectionSelectionTreeWidget::lstCoordinateSystems_itemDoubleClicked );
connect( lstRecent, &QTreeWidget::itemDoubleClicked, this, &QgsProjectionSelectionTreeWidget::lstRecent_itemDoubleClicked );
connect( lstCoordinateSystems, &QTreeWidget::currentItemChanged, this, &QgsProjectionSelectionTreeWidget::lstCoordinateSystems_currentItemChanged );
connect( lstRecent, &QTreeWidget::currentItemChanged, this, &QgsProjectionSelectionTreeWidget::lstRecent_currentItemChanged );
connect( cbxHideDeprecated, &QCheckBox::stateChanged, this, &QgsProjectionSelectionTreeWidget::cbxHideDeprecated_stateChanged );
connect( leSearch, &QgsFilterLineEdit::textChanged, this, &QgsProjectionSelectionTreeWidget::leSearch_textChanged );
connect( cbxHideDeprecated, &QCheckBox::stateChanged, this, &QgsProjectionSelectionTreeWidget::updateFilter );
connect( leSearch, &QgsFilterLineEdit::textChanged, this, &QgsProjectionSelectionTreeWidget::updateFilter );

mPreviewBand = new QgsRubberBand( mAreaCanvas, QgsWkbTypes::PolygonGeometry );
mPreviewBand->setWidth( 4 );
@@ -736,7 +738,7 @@ void QgsProjectionSelectionTreeWidget::loadCrsList( QSet<QString> *crsFilter )
}

// display the qgis deprecated in the user data of the item
newItem->setData( 0, Qt::UserRole, QString::fromUtf8( ( char * )sqlite3_column_text( stmt, 6 ) ) );
newItem->setData( 0, RoleDeprecated, QString::fromUtf8( ( char * )sqlite3_column_text( stmt, 6 ) ) );
newItem->setHidden( cbxHideDeprecated->isChecked() );
}
mProjList->setExpanded( true );
@@ -848,96 +850,62 @@ void QgsProjectionSelectionTreeWidget::lstRecent_itemDoubleClicked( QTreeWidgetI
emit projectionDoubleClicked();
}

void QgsProjectionSelectionTreeWidget::hideDeprecated( QTreeWidgetItem *item )
{
if ( item->data( 0, Qt::UserRole ).toBool() )
{
item->setHidden( cbxHideDeprecated->isChecked() );
if ( item->isSelected() && item->isHidden() )
{
item->setSelected( false );
teProjection->clear();
teSelected->clear();
}
}

for ( int i = 0; i < item->childCount(); i++ )
hideDeprecated( item->child( i ) );
}

void QgsProjectionSelectionTreeWidget::cbxHideDeprecated_stateChanged()
{
for ( int i = 0; i < lstCoordinateSystems->topLevelItemCount(); i++ )
hideDeprecated( lstCoordinateSystems->topLevelItem( i ) );
}

void QgsProjectionSelectionTreeWidget::leSearch_textChanged( const QString &filterTxt )
void QgsProjectionSelectionTreeWidget::updateFilter()
{
QString filterTxtCopy = filterTxt;
QString filterTxtCopy = leSearch->text();
filterTxtCopy.replace( QRegExp( "\\s+" ), QStringLiteral( ".*" ) );
QRegExp re( filterTxtCopy, Qt::CaseInsensitive );

// filter recent crs's
QTreeWidgetItemIterator itr( lstRecent );
while ( *itr )
const bool hideDeprecated = cbxHideDeprecated->isChecked();

auto filterTreeWidget = [ = ]( QTreeWidget * tree )
{
if ( ( *itr )->childCount() == 0 ) // it's an end node aka a projection
QTreeWidgetItemIterator itr( tree );
while ( *itr )
{
if ( ( *itr )->text( NameColumn ).contains( re )
|| ( *itr )->text( AuthidColumn ).contains( re )
)
if ( ( *itr )->childCount() == 0 ) // it's an end node aka a projection
{
( *itr )->setHidden( false );
QTreeWidgetItem *parent = ( *itr )->parent();
while ( parent )
if ( hideDeprecated && ( *itr )->data( 0, RoleDeprecated ).toBool() )
{
parent->setExpanded( true );
parent->setHidden( false );
parent = parent->parent();
( *itr )->setHidden( true );
if ( ( *itr )->isSelected() )
{
( *itr )->setSelected( false );
teProjection->clear();
teSelected->clear();
}
}
else if ( ( *itr )->text( NameColumn ).contains( re )
|| ( *itr )->text( AuthidColumn ).contains( re )
)
{
( *itr )->setHidden( false );
QTreeWidgetItem *parent = ( *itr )->parent();
while ( parent )
{
parent->setExpanded( true );
parent->setHidden( false );
parent = parent->parent();
}
}
else
{
( *itr )->setHidden( true );
}
}
else
{
( *itr )->setHidden( true );
}
++itr;
}
else
{
( *itr )->setHidden( true );
}
++itr;
}
};

// filter recent crs's
filterTreeWidget( lstRecent );

// filter crs's
QTreeWidgetItemIterator it( lstCoordinateSystems );
while ( *it )
{
if ( ( *it )->childCount() == 0 ) // it's an end node aka a projection
{
if ( ( *it )->text( NameColumn ).contains( re )
|| ( *it )->text( AuthidColumn ).contains( re )
)
{
( *it )->setHidden( false );
QTreeWidgetItem *parent = ( *it )->parent();
while ( parent )
{
parent->setExpanded( true );
parent->setHidden( false );
parent = parent->parent();
}
}
else
{
( *it )->setHidden( true );
}
}
else
{
( *it )->setHidden( true );
}
++it;
}
filterTreeWidget( lstCoordinateSystems );
}


@@ -235,6 +235,12 @@ class GUI_EXPORT QgsProjectionSelectionTreeWidget : public QWidget, private Ui::

//! Show the user a warning if the srs database could not be found
void showDBMissingWarning( const QString &fileName );

enum Roles
{
RoleDeprecated = Qt::UserRole,
};

// List view nodes for the tree view of projections
//! User defined projections node
QTreeWidgetItem *mUserProjList = nullptr;
@@ -302,8 +308,7 @@ class GUI_EXPORT QgsProjectionSelectionTreeWidget : public QWidget, private Ui::
void lstRecent_itemDoubleClicked( QTreeWidgetItem *current, int column );
void lstCoordinateSystems_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev );
void lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev );
void cbxHideDeprecated_stateChanged();
void leSearch_textChanged( const QString & );
void updateFilter();
};

#endif

0 comments on commit a022ad2

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