Skip to content

Commit

Permalink
fix an options dialog search crasher (#5978)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 4, 2018
1 parent d69f932 commit 13ad760
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/gui/qgsoptionsdialogbase.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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 );
Expand All @@ -482,5 +486,6 @@ void QgsSearchHighlightOptionWidget::reset()

void QgsSearchHighlightOptionWidget::widgetDestroyed()
{
mWidget = nullptr;
mValid = false;
}
6 changes: 3 additions & 3 deletions src/gui/qgsoptionsdialogbase.h
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 13ad760

Please sign in to comment.