Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow filters to provide configuration dialogs
  • Loading branch information
nyalldawson committed May 17, 2017
1 parent df9d9f6 commit 8267fa3
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 8 deletions.
17 changes: 17 additions & 0 deletions python/gui/locator/qgslocatorfilter.sip
Expand Up @@ -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 );
Expand Down
Empty file modified src/app/locator/qgsinbuiltlocatorfilters.h 100644 → 100755
Empty file.
32 changes: 32 additions & 0 deletions src/app/locator/qgslocatoroptionswidget.cpp
Expand Up @@ -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()
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/app/locator/qgslocatoroptionswidget.h
Expand Up @@ -36,6 +36,7 @@ class QgsLocatorOptionsWidget : public QWidget, private Ui::QgsLocatorOptionsWid
public slots:

void commitChanges();
void configureCurrentFilter();

private:

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgssettingstree.cpp 100644 → 100755
Expand Up @@ -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 ) );
Expand Down
10 changes: 10 additions & 0 deletions src/gui/locator/qgslocatorfilter.cpp
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/gui/locator/qgslocatorfilter.h
Expand Up @@ -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:

/**
Expand Down
32 changes: 28 additions & 4 deletions src/ui/qgslocatoroptionswidgetbase.ui
Expand Up @@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>424</width>
<height>334</height>
<width>647</width>
<height>393</height>
</rect>
</property>
<property name="windowTitle">
<string>Spatial Bookmarks Panel</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0">
<property name="leftMargin">
<number>0</number>
</property>
Expand All @@ -26,13 +26,37 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<item row="0" column="0">
<widget class="QTreeView" name="mFiltersTreeView">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="mConfigureFilterButton">
<property name="text">
<string>Configure</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit 8267fa3

Please sign in to comment.