|
@@ -15,39 +15,44 @@ |
|
|
* * |
|
|
***************************************************************************/ |
|
|
|
|
|
|
|
|
#include <QApplication> |
|
|
#include <QToolButton> |
|
|
#include <QHBoxLayout> |
|
|
|
|
|
#include "qgslocatoroptionswidget.h" |
|
|
|
|
|
#include "qgsapplication.h" |
|
|
#include "qgslocatorwidget.h" |
|
|
#include "qgssettings.h" |
|
|
|
|
|
|
|
|
QgsLocatorOptionsWidget::QgsLocatorOptionsWidget( QgsLocatorWidget *locator, QWidget *parent ) |
|
|
: QWidget( parent ) |
|
|
: QTreeView( parent ) |
|
|
, mLocatorWidget( locator ) |
|
|
, mLocator( locator->locator() ) |
|
|
{ |
|
|
setupUi( this ); |
|
|
|
|
|
mModel = new QgsLocatorFiltersModel( mLocator, this ); |
|
|
mFiltersTreeView->setModel( mModel ); |
|
|
setModel( mModel ); |
|
|
|
|
|
header()->setStretchLastSection( false ); |
|
|
header()->setSectionResizeMode( QgsLocatorFiltersModel::Name, QHeaderView::Stretch ); |
|
|
|
|
|
mFiltersTreeView->header()->setStretchLastSection( false ); |
|
|
mFiltersTreeView->header()->setSectionResizeMode( 0, QHeaderView::Stretch ); |
|
|
setEditTriggers( QAbstractItemView::AllEditTriggers ); |
|
|
setAlternatingRowColors( true ); |
|
|
setSelectionMode( QAbstractItemView::NoSelection ); |
|
|
|
|
|
mConfigureFilterButton->setEnabled( false ); |
|
|
connect( mFiltersTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [ = ]( const QItemSelection & selected, const QItemSelection & ) |
|
|
// add the config button |
|
|
for ( int row = 0; row < mModel->rowCount(); ++row ) |
|
|
{ |
|
|
if ( selected.count() == 0 || selected.at( 0 ).indexes().count() == 0 ) |
|
|
QModelIndex index = mModel->index( row, QgsLocatorFiltersModel::Config ); |
|
|
QWidget *bt = mModel->configButton( index, this ); |
|
|
if ( bt ) |
|
|
{ |
|
|
mConfigureFilterButton->setEnabled( false ); |
|
|
setIndexWidget( index, bt ); |
|
|
} |
|
|
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() |
|
@@ -56,23 +61,23 @@ void QgsLocatorOptionsWidget::commitChanges() |
|
|
mLocatorWidget->invalidateResults(); |
|
|
} |
|
|
|
|
|
void QgsLocatorOptionsWidget::configureCurrentFilter() |
|
|
void QgsLocatorOptionsWidget::dataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles ) |
|
|
{ |
|
|
auto selected = mFiltersTreeView->selectionModel()->selection(); |
|
|
if ( selected.count() == 0 || selected.at( 0 ).indexes().count() == 0 ) |
|
|
for ( int row = topLeft.row(); row < bottomRight.row(); ++row ) |
|
|
{ |
|
|
return; |
|
|
} |
|
|
else |
|
|
{ |
|
|
QModelIndex sel = selected.at( 0 ).indexes().at( 0 ); |
|
|
QgsLocatorFilter *filter = mModel->filterForIndex( sel ); |
|
|
if ( filter ) |
|
|
filter->openConfigWidget( this ); |
|
|
QModelIndex index = mModel->index( row, QgsLocatorFiltersModel::Config ); |
|
|
if ( !indexWidget( index ) ) |
|
|
{ |
|
|
QWidget *bt = mModel->configButton( index, this ); |
|
|
if ( bt ) |
|
|
{ |
|
|
setIndexWidget( index, bt ); |
|
|
} |
|
|
} |
|
|
} |
|
|
QTreeView::dataChanged( topLeft, bottomRight, roles ); |
|
|
} |
|
|
|
|
|
|
|
|
// |
|
|
// QgsLocatorFiltersModel |
|
|
// |
|
@@ -85,6 +90,35 @@ QgsLocatorFiltersModel::QgsLocatorFiltersModel( QgsLocator *locator, QObject *pa |
|
|
{ |
|
|
} |
|
|
|
|
|
QWidget *QgsLocatorFiltersModel::configButton( const QModelIndex &index, QWidget *parent ) const |
|
|
{ |
|
|
if ( !index.isValid() ) |
|
|
return nullptr; |
|
|
|
|
|
QgsLocatorFilter *filter = filterForIndex( index ); |
|
|
if ( filter && filter->hasConfigWidget() ) |
|
|
{ |
|
|
// use a layout to get the button center aligned |
|
|
QWidget *w = new QWidget( parent ); |
|
|
QToolButton *bt = new QToolButton( ); |
|
|
QHBoxLayout *layout = new QHBoxLayout(); |
|
|
layout->setContentsMargins( 0, 0, 0, 0 ); |
|
|
layout->addWidget( bt ); |
|
|
w->setLayout( layout ); |
|
|
|
|
|
connect( bt, &QToolButton::clicked, this, [ = ]() {filter->openConfigWidget( bt );} ); |
|
|
//bt->setMinimumSize( 24, 24 ); |
|
|
bt->setMaximumSize( 24, 24 ); |
|
|
bt->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); |
|
|
bt->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/propertyicons/settings.svg" ) ) ); |
|
|
return w; |
|
|
} |
|
|
else |
|
|
{ |
|
|
return nullptr; |
|
|
} |
|
|
} |
|
|
|
|
|
int QgsLocatorFiltersModel::rowCount( const QModelIndex &parent ) const |
|
|
{ |
|
|
if ( parent.isValid() ) |
|
@@ -98,7 +132,7 @@ int QgsLocatorFiltersModel::columnCount( const QModelIndex &parent ) const |
|
|
if ( parent.isValid() ) |
|
|
return 0; |
|
|
|
|
|
return 4; |
|
|
return 5; |
|
|
} |
|
|
|
|
|
QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) const |
|
@@ -124,6 +158,7 @@ QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) cons |
|
|
|
|
|
case Active: |
|
|
case Default: |
|
|
case Config: |
|
|
return QVariant(); |
|
|
} |
|
|
break; |
|
@@ -134,6 +169,7 @@ QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) cons |
|
|
{ |
|
|
case Name: |
|
|
case Prefix: |
|
|
case Config: |
|
|
return QVariant(); |
|
|
|
|
|
case Active: |
|
@@ -153,6 +189,15 @@ QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) cons |
|
|
return filterForIndex( index )->useWithoutPrefix() ? Qt::Checked : Qt::Unchecked; |
|
|
} |
|
|
break; |
|
|
|
|
|
case Qt::SizeHintRole: |
|
|
return QSize( 32, 32 ); |
|
|
|
|
|
case Qt::TextAlignmentRole: |
|
|
if ( index.column() == Config ) |
|
|
return Qt::AlignCenter; |
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
return QVariant(); |
|
@@ -232,6 +277,7 @@ Qt::ItemFlags QgsLocatorFiltersModel::flags( const QModelIndex &index ) const |
|
|
switch ( index.column() ) |
|
|
{ |
|
|
case Name: |
|
|
case Config: |
|
|
break; |
|
|
|
|
|
case Prefix: |
|
@@ -264,6 +310,9 @@ QVariant QgsLocatorFiltersModel::headerData( int section, Qt::Orientation orient |
|
|
|
|
|
case Default: |
|
|
return tr( "Default" ); |
|
|
|
|
|
case Config: |
|
|
return tr( "Configuration" ); |
|
|
} |
|
|
} |
|
|
|
|
|