Skip to content

Commit

Permalink
Fix handling of "hide deprecated" in projection selector widget
Browse files Browse the repository at this point in the history
Fixes #18896
  • Loading branch information
nyalldawson committed May 5, 2018
1 parent f48aaea commit a022ad2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 78 deletions.
120 changes: 44 additions & 76 deletions src/gui/qgsprojectionselectiontreewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}


Expand Down
9 changes: 7 additions & 2 deletions src/gui/qgsprojectionselectiontreewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.