15
15
* *
16
16
***************************************************************************/
17
17
18
+
19
+ #include < QApplication>
20
+ #include < QToolButton>
21
+ #include < QHBoxLayout>
22
+
18
23
#include " qgslocatoroptionswidget.h"
19
24
25
+ #include " qgsapplication.h"
20
26
#include " qgslocatorwidget.h"
21
27
#include " qgssettings.h"
22
28
29
+
23
30
QgsLocatorOptionsWidget::QgsLocatorOptionsWidget ( QgsLocatorWidget *locator, QWidget *parent )
24
- : QWidget ( parent )
31
+ : QTreeView ( parent )
25
32
, mLocatorWidget( locator )
26
33
, mLocator( locator->locator () )
27
34
{
28
- setupUi ( this );
29
35
30
36
mModel = new QgsLocatorFiltersModel ( mLocator , this );
31
- mFiltersTreeView ->setModel ( mModel );
37
+ setModel ( mModel );
38
+
39
+ header ()->setStretchLastSection ( false );
40
+ header ()->setSectionResizeMode ( QgsLocatorFiltersModel::Name, QHeaderView::Stretch );
32
41
33
- mFiltersTreeView ->header ()->setStretchLastSection ( false );
34
- mFiltersTreeView ->header ()->setSectionResizeMode ( 0 , QHeaderView::Stretch );
42
+ setEditTriggers ( QAbstractItemView::AllEditTriggers );
43
+ setAlternatingRowColors ( true );
44
+ setSelectionMode ( QAbstractItemView::NoSelection );
35
45
36
- mConfigureFilterButton -> setEnabled ( false );
37
- connect ( mFiltersTreeView -> selectionModel (), &QItemSelectionModel::selectionChanged, this , [ = ]( const QItemSelection & selected, const QItemSelection & )
46
+ // add the config button
47
+ for ( int row = 0 ; row < mModel -> rowCount (); ++row )
38
48
{
39
- if ( selected.count () == 0 || selected.at ( 0 ).indexes ().count () == 0 )
49
+ QModelIndex index = mModel ->index ( row, QgsLocatorFiltersModel::Config );
50
+ QWidget *bt = mModel ->configButton ( index, this );
51
+ if ( bt )
40
52
{
41
- mConfigureFilterButton -> setEnabled ( false );
53
+ setIndexWidget ( index, bt );
42
54
}
43
- else
44
- {
45
- QModelIndex sel = selected.at ( 0 ).indexes ().at ( 0 );
46
- QgsLocatorFilter *filter = mModel ->filterForIndex ( sel );
47
- mConfigureFilterButton ->setEnabled ( filter->hasConfigWidget () );
48
- }
49
- } );
50
- connect ( mConfigureFilterButton , &QPushButton::clicked, this , &QgsLocatorOptionsWidget::configureCurrentFilter );
55
+ }
51
56
}
52
57
53
58
void QgsLocatorOptionsWidget::commitChanges ()
@@ -56,23 +61,23 @@ void QgsLocatorOptionsWidget::commitChanges()
56
61
mLocatorWidget ->invalidateResults ();
57
62
}
58
63
59
- void QgsLocatorOptionsWidget::configureCurrentFilter ( )
64
+ void QgsLocatorOptionsWidget::dataChanged ( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles )
60
65
{
61
- auto selected = mFiltersTreeView ->selectionModel ()->selection ();
62
- if ( selected.count () == 0 || selected.at ( 0 ).indexes ().count () == 0 )
66
+ for ( int row = topLeft.row (); row < bottomRight.row (); ++row )
63
67
{
64
- return ;
65
- }
66
- else
67
- {
68
- QModelIndex sel = selected.at ( 0 ).indexes ().at ( 0 );
69
- QgsLocatorFilter *filter = mModel ->filterForIndex ( sel );
70
- if ( filter )
71
- filter->openConfigWidget ( this );
68
+ QModelIndex index = mModel ->index ( row, QgsLocatorFiltersModel::Config );
69
+ if ( !indexWidget ( index ) )
70
+ {
71
+ QWidget *bt = mModel ->configButton ( index, this );
72
+ if ( bt )
73
+ {
74
+ setIndexWidget ( index, bt );
75
+ }
76
+ }
72
77
}
78
+ QTreeView::dataChanged ( topLeft, bottomRight, roles );
73
79
}
74
80
75
-
76
81
//
77
82
// QgsLocatorFiltersModel
78
83
//
@@ -85,6 +90,35 @@ QgsLocatorFiltersModel::QgsLocatorFiltersModel( QgsLocator *locator, QObject *pa
85
90
{
86
91
}
87
92
93
+ QWidget *QgsLocatorFiltersModel::configButton ( const QModelIndex &index, QWidget *parent ) const
94
+ {
95
+ if ( !index.isValid () )
96
+ return nullptr ;
97
+
98
+ QgsLocatorFilter *filter = filterForIndex ( index );
99
+ if ( filter && filter->hasConfigWidget () )
100
+ {
101
+ // use a layout to get the button center aligned
102
+ QWidget *w = new QWidget ( parent );
103
+ QToolButton *bt = new QToolButton ( );
104
+ QHBoxLayout *layout = new QHBoxLayout ();
105
+ layout->setContentsMargins ( 0 , 0 , 0 , 0 );
106
+ layout->addWidget ( bt );
107
+ w->setLayout ( layout );
108
+
109
+ connect ( bt, &QToolButton::clicked, this , [ = ]() {filter->openConfigWidget ( bt );} );
110
+ // bt->setMinimumSize( 24, 24 );
111
+ bt->setMaximumSize ( 24 , 24 );
112
+ bt->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
113
+ bt->setIcon ( QgsApplication::getThemeIcon ( QStringLiteral ( " /propertyicons/settings.svg" ) ) );
114
+ return w;
115
+ }
116
+ else
117
+ {
118
+ return nullptr ;
119
+ }
120
+ }
121
+
88
122
int QgsLocatorFiltersModel::rowCount ( const QModelIndex &parent ) const
89
123
{
90
124
if ( parent.isValid () )
@@ -98,7 +132,7 @@ int QgsLocatorFiltersModel::columnCount( const QModelIndex &parent ) const
98
132
if ( parent.isValid () )
99
133
return 0 ;
100
134
101
- return 4 ;
135
+ return 5 ;
102
136
}
103
137
104
138
QVariant QgsLocatorFiltersModel::data ( const QModelIndex &index, int role ) const
@@ -124,6 +158,7 @@ QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) cons
124
158
125
159
case Active:
126
160
case Default:
161
+ case Config:
127
162
return QVariant ();
128
163
}
129
164
break ;
@@ -134,6 +169,7 @@ QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) cons
134
169
{
135
170
case Name:
136
171
case Prefix:
172
+ case Config:
137
173
return QVariant ();
138
174
139
175
case Active:
@@ -153,6 +189,15 @@ QVariant QgsLocatorFiltersModel::data( const QModelIndex &index, int role ) cons
153
189
return filterForIndex ( index )->useWithoutPrefix () ? Qt::Checked : Qt::Unchecked;
154
190
}
155
191
break ;
192
+
193
+ case Qt::SizeHintRole:
194
+ return QSize ( 32 , 32 );
195
+
196
+ case Qt::TextAlignmentRole:
197
+ if ( index.column () == Config )
198
+ return Qt::AlignCenter;
199
+ break ;
200
+
156
201
}
157
202
158
203
return QVariant ();
@@ -232,6 +277,7 @@ Qt::ItemFlags QgsLocatorFiltersModel::flags( const QModelIndex &index ) const
232
277
switch ( index.column () )
233
278
{
234
279
case Name:
280
+ case Config:
235
281
break ;
236
282
237
283
case Prefix:
@@ -264,6 +310,9 @@ QVariant QgsLocatorFiltersModel::headerData( int section, Qt::Orientation orient
264
310
265
311
case Default:
266
312
return tr ( " Default" );
313
+
314
+ case Config:
315
+ return tr ( " Configuration" );
267
316
}
268
317
}
269
318
0 commit comments