fix an options dialog search crasher (#5978)

This commit is contained in:
Mathieu Pellerin 2018-01-04 10:48:42 +07:00 committed by GitHub
parent d69f932c31
commit 13ad7608e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -35,7 +35,7 @@
#include <QAbstractItemModel>
#include "qgsfilterlineedit.h"
#include "qgsmessagebaritem.h"
#include "qgslogger.h"
QgsOptionsDialogBase::QgsOptionsDialogBase( const QString &settingsKey, QWidget *parent, Qt::WindowFlags fl, QgsSettings *settings )
@ -265,6 +265,10 @@ void QgsOptionsDialogBase::registerTextSearchWidgets()
{
Q_FOREACH ( QWidget *w, mOptStackedWidget->widget( i )->findChildren<QWidget *>() )
{
// do not register message bar content, items disappear and causes QGIS to crash
if ( qobject_cast< QgsMessageBarItem * >( w ) || qobject_cast< QgsMessageBarItem * >( w->parentWidget() ) )
continue;
QgsSearchHighlightOptionWidget *shw = new QgsSearchHighlightOptionWidget( w );
if ( shw->isValid() )
{
@ -471,7 +475,7 @@ bool QgsSearchHighlightOptionWidget::searchHighlight( const QString &searchText
void QgsSearchHighlightOptionWidget::reset()
{
if ( mValid && mChangedStyle )
if ( mWidget && mValid && mChangedStyle )
{
QString ss = mWidget->styleSheet();
ss.remove( mStyleSheet );
@ -482,5 +486,6 @@ void QgsSearchHighlightOptionWidget::reset()
void QgsSearchHighlightOptionWidget::widgetDestroyed()
{
mWidget = nullptr;
mValid = false;
}

View File

@ -62,7 +62,7 @@ class GUI_EXPORT QgsSearchHighlightOptionWidget : public QObject
/**
* Returns if it valid: if the widget type is handled and if the widget is not still available
*/
bool isValid() {return mValid;}
bool isValid() { return mWidget && mValid; }
/**
* search for a text pattern and highlight the widget if the text is found
@ -78,13 +78,13 @@ class GUI_EXPORT QgsSearchHighlightOptionWidget : public QObject
/**
* return the widget
*/
QWidget *widget() {return mWidget;}
QWidget *widget() { return mWidget; }
private slots:
void widgetDestroyed();
private:
QWidget *mWidget = nullptr;
QPointer< QWidget > mWidget;
QString mStyleSheet;
bool mValid = true;
bool mChangedStyle = false;