@@ -39,6 +39,8 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
39
39
mAtlasCoverageLayerComboBox ->insertItem ( idx++, it.value ()->name (), /* userdata */ qVariantFromValue (( void * )it.value () ) );
40
40
}
41
41
}
42
+ // update sort columns
43
+ fillSortColumns ();
42
44
43
45
// Connect to addition / removal of layers
44
46
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance ();
@@ -58,6 +60,13 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
58
60
mComposerMapComboBox ->addItem ( tr ( " Map %1" ).arg (( *mapItemIt )->id () ), qVariantFromValue (( void * )*mapItemIt ) );
59
61
}
60
62
63
+ // Sort direction
64
+ mAtlasSortFeatureDirectionComboBox ->insertItem ( 0 , tr (" Ascending" ) );
65
+ mAtlasSortFeatureDirectionComboBox ->insertItem ( 1 , tr (" Descending" ) );
66
+ mAtlasSortFeatureDirectionComboBox ->setEnabled ( false );
67
+
68
+ mAtlasSortFeatureKeyComboBox ->setEnabled ( false );
69
+
61
70
// Connect to addition / removal of maps
62
71
connect ( mComposition , SIGNAL ( composerMapAdded ( QgsComposerMap* ) ), this , SLOT ( onComposerMapAdded ( QgsComposerMap* ) ) );
63
72
connect ( mComposition , SIGNAL ( itemRemoved ( QgsComposerItem* ) ), this , SLOT ( onItemRemoved ( QgsComposerItem* ) ) );
@@ -159,11 +168,17 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
159
168
if ( index == -1 )
160
169
{
161
170
atlasMap->setCoverageLayer ( 0 );
171
+
172
+ // clean up the sorting columns
173
+ mAtlasSortFeatureKeyComboBox ->clear ();
162
174
}
163
175
else
164
176
{
165
177
QgsVectorLayer* layer = reinterpret_cast <QgsVectorLayer*>( mAtlasCoverageLayerComboBox ->itemData ( index ).value <void *>() );
166
178
atlasMap->setCoverageLayer ( layer );
179
+
180
+ // update sorting columns
181
+ fillSortColumns ();
167
182
}
168
183
}
169
184
@@ -257,6 +272,99 @@ void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int st
257
272
atlasMap->setSingleFile ( state == Qt::Checked );
258
273
}
259
274
275
+ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureCheckBox_stateChanged ( int state )
276
+ {
277
+ QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
278
+ if ( !atlasMap )
279
+ {
280
+ return ;
281
+ }
282
+
283
+ if ( state == Qt::Checked ) {
284
+ mAtlasSortFeatureDirectionComboBox ->setEnabled ( true );
285
+ mAtlasSortFeatureKeyComboBox ->setEnabled ( true );
286
+ }
287
+ else {
288
+ mAtlasSortFeatureDirectionComboBox ->setEnabled ( false );
289
+ mAtlasSortFeatureKeyComboBox ->setEnabled ( false );
290
+ }
291
+ atlasMap->setSortFeatures ( state == Qt::Checked );
292
+ }
293
+
294
+ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureKeyComboBox_currentIndexChanged ( int index )
295
+ {
296
+ QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
297
+ if ( !atlasMap )
298
+ {
299
+ return ;
300
+ }
301
+
302
+ if ( index != -1 ) {
303
+ atlasMap->setSortKeyAttributeIndex ( index );
304
+ }
305
+ }
306
+
307
+ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureDirectionComboBox_currentIndexChanged ( int index )
308
+ {
309
+ QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
310
+ if ( !atlasMap )
311
+ {
312
+ return ;
313
+ }
314
+
315
+ if ( index != -1 ) {
316
+ atlasMap->setSortAscending ( index == 0 ? true : false );
317
+ }
318
+ }
319
+
320
+ void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterEdit_textChanged ( const QString& text )
321
+ {
322
+ QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
323
+ if ( !atlasMap )
324
+ {
325
+ return ;
326
+ }
327
+
328
+ atlasMap->setFeatureFilter ( text );
329
+ }
330
+
331
+ void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterButton_clicked ()
332
+ {
333
+ QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
334
+ if ( !atlasMap || !atlasMap->coverageLayer () )
335
+ {
336
+ return ;
337
+ }
338
+
339
+ QgsExpressionBuilderDialog exprDlg ( atlasMap->coverageLayer (), mAtlasFeatureFilterEdit ->text (), this );
340
+ exprDlg.setWindowTitle ( tr ( " Expression based filter" ) );
341
+ if ( exprDlg.exec () == QDialog::Accepted )
342
+ {
343
+ QString expression = exprDlg.expressionText ();
344
+ if ( !expression.isEmpty () )
345
+ {
346
+ // will emit a textChanged signal
347
+ mAtlasFeatureFilterEdit ->setText ( expression );
348
+ }
349
+ }
350
+ }
351
+
352
+ void QgsAtlasCompositionWidget::fillSortColumns ()
353
+ {
354
+ QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
355
+ if ( !atlasMap || !atlasMap->coverageLayer () )
356
+ {
357
+ return ;
358
+ }
359
+
360
+ mAtlasSortFeatureKeyComboBox ->clear ();
361
+ // Get fields of the selected coverage layer
362
+ const QgsFields& fields = atlasMap->coverageLayer ()->pendingFields ();
363
+ for ( int i = 0 ; i < fields.count (); ++i ) {
364
+ mAtlasSortFeatureKeyComboBox ->insertItem ( i, fields.at (i).name () );
365
+ }
366
+ }
367
+
260
368
void QgsAtlasCompositionWidget::updateGuiElements ()
261
369
{
262
370
QgsAtlasComposition* atlasMap = &mComposition ->atlasComposition ();
@@ -285,6 +393,10 @@ void QgsAtlasCompositionWidget::updateGuiElements()
285
393
mAtlasFixedScaleCheckBox ->setCheckState ( atlasMap->fixedScale () ? Qt::Checked : Qt::Unchecked );
286
394
mAtlasHideCoverageCheckBox ->setCheckState ( atlasMap->hideCoverage () ? Qt::Checked : Qt::Unchecked );
287
395
mAtlasSingleFileCheckBox ->setCheckState ( atlasMap->singleFile () ? Qt::Checked : Qt::Unchecked );
396
+ mAtlasSortFeatureCheckBox ->setCheckState ( atlasMap->sortFeatures () ? Qt::Checked : Qt::Unchecked );
397
+ mAtlasSortFeatureKeyComboBox ->setCurrentIndex ( atlasMap->sortKeyAttributeIndex () );
398
+ mAtlasSortFeatureDirectionComboBox ->setCurrentIndex ( atlasMap->sortAscending () ? 0 : 1 );
399
+ mAtlasFeatureFilterEdit ->setText ( atlasMap->featureFilter () );
288
400
}
289
401
290
402
void QgsAtlasCompositionWidget::blockAllSignals ( bool b )
0 commit comments