From 8267fa3ddd16d93f57961be68821ae3642467741 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 17 May 2017 21:32:30 +1000 Subject: [PATCH] Allow filters to provide configuration dialogs --- python/gui/locator/qgslocatorfilter.sip | 17 +++++++++++ src/app/locator/qgsinbuiltlocatorfilters.h | 0 src/app/locator/qgslocatoroptionswidget.cpp | 32 +++++++++++++++++++++ src/app/locator/qgslocatoroptionswidget.h | 6 ++-- src/app/qgssettingstree.cpp | 4 +-- src/gui/locator/qgslocatorfilter.cpp | 10 +++++++ src/gui/locator/qgslocatorfilter.h | 14 +++++++++ src/ui/qgslocatoroptionswidgetbase.ui | 32 ++++++++++++++++++--- 8 files changed, 107 insertions(+), 8 deletions(-) mode change 100644 => 100755 src/app/locator/qgsinbuiltlocatorfilters.h mode change 100644 => 100755 src/app/qgssettingstree.cpp diff --git a/python/gui/locator/qgslocatorfilter.sip b/python/gui/locator/qgslocatorfilter.sip index 81025548b65..dc685aed8ee 100644 --- a/python/gui/locator/qgslocatorfilter.sip +++ b/python/gui/locator/qgslocatorfilter.sip @@ -186,6 +186,23 @@ class QgsLocatorFilter : QObject .. seealso:: enabled() %End + virtual bool hasConfigWidget() const; +%Docstring + Should return true if the filter has a configuration widget. +.. seealso:: createConfigWidget() + :rtype: bool +%End + + virtual void openConfigWidget( QWidget *parent = 0 ); +%Docstring + Opens the configuration widget for the filter (if it has one), with the specified ``parent`` widget. + The base class implementation does nothing. Subclasses can override this to show their own + custom configuration widget. +.. note:: + + hasConfigWidget() must return true to indicate that the filter supports configuration. +%End + signals: void resultFetched( const QgsLocatorResult &result ); diff --git a/src/app/locator/qgsinbuiltlocatorfilters.h b/src/app/locator/qgsinbuiltlocatorfilters.h old mode 100644 new mode 100755 diff --git a/src/app/locator/qgslocatoroptionswidget.cpp b/src/app/locator/qgslocatoroptionswidget.cpp index aa74e4ee64e..a5b6899e301 100644 --- a/src/app/locator/qgslocatoroptionswidget.cpp +++ b/src/app/locator/qgslocatoroptionswidget.cpp @@ -31,6 +31,22 @@ QgsLocatorOptionsWidget::QgsLocatorOptionsWidget( QgsLocatorWidget *locator, QWi mFiltersTreeView->header()->setStretchLastSection( false ); mFiltersTreeView->header()->setResizeMode( 0, QHeaderView::Stretch ); + + mConfigureFilterButton->setEnabled( false ); + connect( mFiltersTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [ = ]( const QItemSelection & selected, const QItemSelection & ) + { + if ( selected.count() == 0 || selected.at( 0 ).indexes().count() == 0 ) + { + mConfigureFilterButton->setEnabled( false ); + } + else + { + QModelIndex sel = selected.at( 0 ).indexes().at( 0 ); + QgsLocatorFilter *filter = mModel->filterForIndex( sel ); + mConfigureFilterButton->setEnabled( filter->hasConfigWidget() ); + } + } ); + connect( mConfigureFilterButton, &QPushButton::clicked, this, &QgsLocatorOptionsWidget::configureCurrentFilter ); } void QgsLocatorOptionsWidget::commitChanges() @@ -39,6 +55,22 @@ void QgsLocatorOptionsWidget::commitChanges() mLocatorWidget->invalidateResults(); } +void QgsLocatorOptionsWidget::configureCurrentFilter() +{ + auto selected = mFiltersTreeView->selectionModel()->selection(); + if ( selected.count() == 0 || selected.at( 0 ).indexes().count() == 0 ) + { + return; + } + else + { + QModelIndex sel = selected.at( 0 ).indexes().at( 0 ); + QgsLocatorFilter *filter = mModel->filterForIndex( sel ); + if ( filter ) + filter->openConfigWidget(); + } +} + // // QgsLocatorFiltersModel diff --git a/src/app/locator/qgslocatoroptionswidget.h b/src/app/locator/qgslocatoroptionswidget.h index e90099db06e..f080ebd6be5 100644 --- a/src/app/locator/qgslocatoroptionswidget.h +++ b/src/app/locator/qgslocatoroptionswidget.h @@ -36,6 +36,7 @@ class QgsLocatorOptionsWidget : public QWidget, private Ui::QgsLocatorOptionsWid public slots: void commitChanges(); + void configureCurrentFilter(); private: @@ -84,14 +85,15 @@ class QgsLocatorFiltersModel : public QAbstractTableModel QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; + + QgsLocatorFilter *filterForIndex( const QModelIndex &index ) const; + public slots: void commitChanges(); private: - QgsLocatorFilter *filterForIndex( const QModelIndex &index ) const; - QgsLocator *mLocator = nullptr; // changes are defered to support cancelation diff --git a/src/app/qgssettingstree.cpp b/src/app/qgssettingstree.cpp old mode 100644 new mode 100755 index bbbca360bea..f0895c03b75 --- a/src/app/qgssettingstree.cpp +++ b/src/app/qgssettingstree.cpp @@ -256,10 +256,10 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text, item->setFlags( item->flags() | Qt::ItemIsEditable ); QString key = itemKey( item ); - QgsDebugMsg( key ); + QgsDebugMsgLevel( key , 4); if ( settingsMap.contains( key ) ) { - QgsDebugMsg( "contains!!!!" ); + QgsDebugMsgLevel( "contains!!!!", 4 ); QStringList values = settingsMap[ key ]; item->setText( 3, values.at( 0 ) ); item->setToolTip( 0, values.at( 1 ) ); diff --git a/src/gui/locator/qgslocatorfilter.cpp b/src/gui/locator/qgslocatorfilter.cpp index f2cee84aad5..03448d24a57 100644 --- a/src/gui/locator/qgslocatorfilter.cpp +++ b/src/gui/locator/qgslocatorfilter.cpp @@ -40,6 +40,16 @@ void QgsLocatorFilter::setEnabled( bool enabled ) mEnabled = enabled; } +bool QgsLocatorFilter::hasConfigWidget() const +{ + return false; +} + +void QgsLocatorFilter::openConfigWidget( QWidget *parent ) +{ + Q_UNUSED( parent ); +} + bool QgsLocatorFilter::useWithoutPrefix() const { return mUseWithoutPrefix; diff --git a/src/gui/locator/qgslocatorfilter.h b/src/gui/locator/qgslocatorfilter.h index a696533a5d8..4225bfa1755 100644 --- a/src/gui/locator/qgslocatorfilter.h +++ b/src/gui/locator/qgslocatorfilter.h @@ -202,6 +202,20 @@ class GUI_EXPORT QgsLocatorFilter : public QObject */ void setEnabled( bool enabled ); + /** + * Should return true if the filter has a configuration widget. + * \see createConfigWidget() + */ + virtual bool hasConfigWidget() const; + + /** + * Opens the configuration widget for the filter (if it has one), with the specified \a parent widget. + * The base class implementation does nothing. Subclasses can override this to show their own + * custom configuration widget. + * \note hasConfigWidget() must return true to indicate that the filter supports configuration. + */ + virtual void openConfigWidget( QWidget *parent = nullptr ); + signals: /** diff --git a/src/ui/qgslocatoroptionswidgetbase.ui b/src/ui/qgslocatoroptionswidgetbase.ui index 7989502dc80..65c83445359 100755 --- a/src/ui/qgslocatoroptionswidgetbase.ui +++ b/src/ui/qgslocatoroptionswidgetbase.ui @@ -6,14 +6,14 @@ 0 0 - 424 - 334 + 647 + 393 Spatial Bookmarks Panel - + 0 @@ -26,13 +26,37 @@ 0 - + false + + + + + + Configure + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + +