mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Allow filters to provide configuration dialogs
This commit is contained in:
parent
df9d9f6748
commit
8267fa3ddd
@ -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 );
|
||||
|
0
src/app/locator/qgsinbuiltlocatorfilters.h
Normal file → Executable file
0
src/app/locator/qgsinbuiltlocatorfilters.h
Normal file → Executable file
@ -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
|
||||
|
@ -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
|
||||
|
4
src/app/qgssettingstree.cpp
Normal file → Executable file
4
src/app/qgssettingstree.cpp
Normal file → Executable file
@ -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 ) );
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
||||
/**
|
||||
|
@ -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>
|
||||
@ -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/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user