QGIS API Documentation  2.12.0-Lyon
qgsrulebasedrendererv2widget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrulebasedrendererv2widget.cpp - Settings widget for rule-based renderer
3  ---------------------
4  begin : May 2010
5  copyright : (C) 2010 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 
18 #include "qgsrulebasedrendererv2.h"
19 #include "qgssymbollayerv2utils.h"
20 #include "qgssymbolv2.h"
21 #include "qgsvectorlayer.h"
22 #include "qgsapplication.h"
23 #include "qgsexpression.h"
25 #include "qgslogger.h"
26 #include "qstring.h"
28 
29 #include <QKeyEvent>
30 #include <QMenu>
31 #include <QProgressDialog>
32 #include <QSettings>
33 #include <QTreeWidgetItem>
34 #include <QVBoxLayout>
35 #include <QMessageBox>
36 
37 #ifdef ENABLE_MODELTEST
38 #include "modeltest.h"
39 #endif
40 
42 {
43  return new QgsRuleBasedRendererV2Widget( layer, style, renderer );
44 }
45 
47  : QgsRendererV2Widget( layer, style )
48 {
49  mRenderer = 0;
50  // try to recognize the previous renderer
51  // (null renderer means "no previous renderer")
52 
53 
54  if ( renderer )
55  {
57  }
58  if ( !mRenderer )
59  {
60  // some default options
62 
63  mRenderer = new QgsRuleBasedRendererV2( symbol );
64  }
65 
66  setupUi( this );
67 
69 #ifdef ENABLE_MODELTEST
70  new ModelTest( mModel, this ); // for model validity checking
71 #endif
72  viewRules->setModel( mModel );
73 
74  mDeleteAction = new QAction( tr( "Remove Rule" ), this );
75  mDeleteAction->setShortcut( QKeySequence( QKeySequence::Delete ) );
76 
77  viewRules->addAction( mDeleteAction );
78  viewRules->addAction( mCopyAction );
79  viewRules->addAction( mPasteAction );
80 
81  mRefineMenu = new QMenu( tr( "Refine current rule" ), btnRefineRule );
82  mRefineMenu->addAction( tr( "Add scales to rule" ), this, SLOT( refineRuleScales() ) );
83  mRefineMenu->addAction( tr( "Add categories to rule" ), this, SLOT( refineRuleCategories() ) );
84  mRefineMenu->addAction( tr( "Add ranges to rule" ), this, SLOT( refineRuleRanges() ) );
85  btnRefineRule->setMenu( mRefineMenu );
87 
88  btnAddRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.svg" ) ) );
89  btnEditRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
90  btnRemoveRule->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.svg" ) ) );
91 
92  connect( viewRules, SIGNAL( doubleClicked( const QModelIndex & ) ), this, SLOT( editRule( const QModelIndex & ) ) );
93 
94  // support for context menu (now handled generically)
95  connect( viewRules, SIGNAL( customContextMenuRequested( const QPoint& ) ), this, SLOT( contextMenuViewCategories( const QPoint& ) ) );
96 
97  connect( viewRules->selectionModel(), SIGNAL( currentChanged( QModelIndex, QModelIndex ) ), this, SLOT( currentRuleChanged( QModelIndex, QModelIndex ) ) );
98 
99  connect( btnAddRule, SIGNAL( clicked() ), this, SLOT( addRule() ) );
100  connect( btnEditRule, SIGNAL( clicked() ), this, SLOT( editRule() ) );
101  connect( btnRemoveRule, SIGNAL( clicked() ), this, SLOT( removeRule() ) );
102  connect( mDeleteAction, SIGNAL( triggered() ), this, SLOT( removeRule() ) );
103  connect( btnCountFeatures, SIGNAL( clicked() ), this, SLOT( countFeatures() ) );
104 
105  connect( btnRenderingOrder, SIGNAL( clicked() ), this, SLOT( setRenderingOrder() ) );
106 
108 
109  // store/restore header section widths
110  connect( viewRules->header(), SIGNAL( sectionResized( int, int, int ) ), this, SLOT( saveSectionWidth( int, int, int ) ) );
111 
113 
114 }
115 
117 {
118  qDeleteAll( mCopyBuffer );
119  delete mRenderer;
120 }
121 
123 {
124  return mRenderer;
125 }
126 
128 {
131 
132  QgsRendererRulePropsDialog dlg( newrule, mLayer, mStyle, this, mMapCanvas );
133  if ( dlg.exec() )
134  {
136  if ( current )
137  {
138  // add after this rule
139  QModelIndex currentIndex = viewRules->selectionModel()->currentIndex();
140  mModel->insertRule( currentIndex.parent(), currentIndex.row() + 1, newrule );
141  }
142  else
143  {
144  // append to root rule
145  int rows = mModel->rowCount();
146  mModel->insertRule( QModelIndex(), rows, newrule );
147  }
149  }
150  else
151  {
152  delete newrule;
153  }
154 }
155 
157 {
158  QItemSelectionModel* sel = viewRules->selectionModel();
159  QModelIndex idx = sel->currentIndex();
160  if ( !idx.isValid() )
161  return NULL;
162  return mModel->ruleForIndex( idx );
163 }
164 
166 {
167  editRule( viewRules->selectionModel()->currentIndex() );
168 }
169 
171 {
172  if ( !index.isValid() )
173  return;
175 
176  QgsRendererRulePropsDialog dlg( rule, mLayer, mStyle, this, mMapCanvas );
177  if ( dlg.exec() )
178  {
179  // model should know about the change and emit dataChanged signal for the view
180  mModel->updateRule( index.parent(), index.row() );
182  }
183 }
184 
186 {
187  QItemSelection sel = viewRules->selectionModel()->selection();
188  QgsDebugMsg( QString( "REMOVE RULES!!! ranges: %1" ).arg( sel.count() ) );
189  Q_FOREACH ( const QItemSelectionRange& range, sel )
190  {
191  QgsDebugMsg( QString( "RANGE: r %1 - %2" ).arg( range.top() ).arg( range.bottom() ) );
192  if ( range.isValid() )
193  mModel->removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
194  }
195  // make sure that the selection is gone
196  viewRules->selectionModel()->clear();
198 }
199 
201 {
202  Q_UNUSED( previous );
203  btnRefineRule->setEnabled( current.isValid() );
204 }
205 
206 
212 #include <QDialogButtonBox>
213 #include <QInputDialog>
214 #include <QClipboard>
215 
217 {
218  QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
219 
220  if ( indexlist.isEmpty() )
221  return;
222 
223 
224  if ( type == 0 ) // categories
225  refineRuleCategoriesGui( indexlist );
226  else if ( type == 1 ) // ranges
227  refineRuleRangesGui( indexlist );
228  else // scales
229  refineRuleScalesGui( indexlist );
230 
231  // TODO: set initial rule's symbol to NULL (?)
232 
233  // show the newly added rules
234  Q_FOREACH ( const QModelIndex& index, indexlist )
235  viewRules->expand( index );
236 }
237 
239 {
240  refineRule( 0 );
241 }
242 
244 {
245  refineRule( 1 );
246 }
247 
249 {
250  refineRule( 2 );
251 }
252 
253 void QgsRuleBasedRendererV2Widget::refineRuleCategoriesGui( const QModelIndexList& indexList )
254 {
255  QDialog dlg;
256  dlg.setWindowTitle( tr( "Refine a rule to categories" ) );
257  QVBoxLayout* l = new QVBoxLayout();
259  w->setMapCanvas( mMapCanvas );
260  l->addWidget( w );
261  QDialogButtonBox* bb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
262  l->addWidget( bb );
263  connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
264  connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
265  dlg.setLayout( l );
266 
267  if ( !dlg.exec() )
268  return;
269 
270  // create new rules
272  Q_FOREACH ( const QModelIndex& index, indexList )
273  {
274  QgsRuleBasedRendererV2::Rule* initialRule = mModel->ruleForIndex( index );
275  mModel->willAddRules( index, r->categories().count() );
277  }
279 }
280 
281 
282 void QgsRuleBasedRendererV2Widget::refineRuleRangesGui( const QModelIndexList& indexList )
283 {
284 
285 
286  QDialog dlg;
287  dlg.setWindowTitle( tr( "Refine a rule to ranges" ) );
288  QVBoxLayout* l = new QVBoxLayout();
290  w->setMapCanvas( mMapCanvas );
291  l->addWidget( w );
292  QDialogButtonBox* bb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
293  l->addWidget( bb );
294  connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
295  connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
296  dlg.setLayout( l );
297 
298  if ( !dlg.exec() )
299  return;
300 
301  // create new rules
303  Q_FOREACH ( const QModelIndex& index, indexList )
304  {
305  QgsRuleBasedRendererV2::Rule* initialRule = mModel->ruleForIndex( index );
306  mModel->willAddRules( index, r->ranges().count() );
308  }
310 }
311 
312 void QgsRuleBasedRendererV2Widget::refineRuleScalesGui( const QModelIndexList& indexList )
313 {
314  Q_FOREACH ( const QModelIndex& index, indexList )
315  {
316  QgsRuleBasedRendererV2::Rule* initialRule = mModel->ruleForIndex( index );
317 
318  // If any of the rules don't have a symbol let the user know and exit.
319  if ( initialRule->symbol() == NULL )
320  {
321  QMessageBox::warning( this, tr( "Scale refinement" ), tr( "Parent rule %1 must have a symbol for this operation." ).arg( initialRule->label() ) );
322  return;
323  }
324  }
325 
326  QString txt = QInputDialog::getText( this,
327  tr( "Scale refinement" ),
328  tr( "Please enter scale denominators at which will split the rule, separate them by commas (e.g. 1000,5000):" ) );
329  if ( txt.isEmpty() )
330  return;
331 
332  QList<int> scales;
333  bool ok;
334  Q_FOREACH ( const QString& item, txt.split( ',' ) )
335  {
336  int scale = item.toInt( &ok );
337  if ( ok )
338  scales.append( scale );
339  else
340  QMessageBox::information( this, tr( "Error" ), QString( tr( "\"%1\" is not valid scale denominator, ignoring it." ) ).arg( item ) );
341  }
342 
343  Q_FOREACH ( const QModelIndex& index, indexList )
344  {
345  QgsRuleBasedRendererV2::Rule* initialRule = mModel->ruleForIndex( index );
346  mModel->willAddRules( index, scales.count() + 1 );
347  QgsRuleBasedRendererV2::refineRuleScales( initialRule, scales );
348  }
350 }
351 
353 {
354  QList<QgsSymbolV2*> symbolList;
355 
356  if ( !mRenderer )
357  {
358  return symbolList;
359  }
360 
361  QItemSelection sel = viewRules->selectionModel()->selection();
362  Q_FOREACH ( const QItemSelectionRange& range, sel )
363  {
364  QModelIndex parent = range.parent();
365  QgsRuleBasedRendererV2::Rule* parentRule = mModel->ruleForIndex( parent );
367  for ( int row = range.top(); row <= range.bottom(); row++ )
368  {
369  symbolList.append( children[row]->symbol() );
370  }
371  }
372 
373  return symbolList;
374 }
375 
377 {
379  QItemSelection sel = viewRules->selectionModel()->selection();
380  Q_FOREACH ( const QItemSelectionRange& range, sel )
381  {
382  QModelIndex parent = range.parent();
383  QgsRuleBasedRendererV2::Rule* parentRule = mModel->ruleForIndex( parent );
385  for ( int row = range.top(); row <= range.bottom(); row++ )
386  {
387  rl.append( children[row]->clone() );
388  }
389  }
390  return rl;
391 }
392 
394 {
395  // TODO: model/view
396  /*
397  if ( treeRules )
398  {
399  treeRules->populateRules();
400  }
401  */
402 }
403 
405 {
406  if ( !event )
407  {
408  return;
409  }
410 
411  if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
412  {
413  qDeleteAll( mCopyBuffer );
414  mCopyBuffer.clear();
416  }
417  else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
418  {
420  for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
421  {
422  int rows = mModel->rowCount();
423  mModel->insertRule( QModelIndex(), rows, ( *rIt )->clone() );
424  }
425  }
426 }
427 
428 #include "qgssymbollevelsv2dialog.h"
429 
431 {
433 
434  QgsSymbolLevelsV2Dialog dlg( lst, true, this );
435  dlg.setForceOrderingEnabled( true );
436 
437  dlg.exec();
438 }
439 
440 void QgsRuleBasedRendererV2Widget::saveSectionWidth( int section, int oldSize, int newSize )
441 {
442  Q_UNUSED( oldSize );
443  // skip last section, as it stretches
444  if ( section == 5 )
445  return;
446  QSettings settings;
447  QString path = "/Windows/RuleBasedTree/sectionWidth/" + QString::number( section );
448  settings.setValue( path, newSize );
449 }
450 
452 {
453  QSettings settings;
454  QString path = "/Windows/RuleBasedTree/sectionWidth/";
455  QHeaderView* head = viewRules->header();
456  head->resizeSection( 0, settings.value( path + QString::number( 0 ), 150 ).toInt() );
457  head->resizeSection( 1, settings.value( path + QString::number( 1 ), 150 ).toInt() );
458  head->resizeSection( 2, settings.value( path + QString::number( 2 ), 80 ).toInt() );
459  head->resizeSection( 3, settings.value( path + QString::number( 3 ), 80 ).toInt() );
460  head->resizeSection( 4, settings.value( path + QString::number( 4 ), 50 ).toInt() );
461  head->resizeSection( 5, settings.value( path + QString::number( 5 ), 50 ).toInt() );
462 }
463 
465 {
466  QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
467  QgsDebugMsg( QString( "%1" ).arg( indexlist.count() ) );
468 
469  if ( indexlist.isEmpty() )
470  return;
471 
472  QMimeData* mime = mModel->mimeData( indexlist );
474 }
475 
477 {
478  const QMimeData* mime = QApplication::clipboard()->mimeData();
479  QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
481  if ( indexlist.isEmpty() )
482  index = mModel->index( mModel->rowCount(), 0 );
483  else
484  index = indexlist.first();
485  mModel->dropMimeData( mime, Qt::CopyAction, index.row(), index.column(), index.parent() );
486 }
487 
488 
490 {
491  if ( !mLayer || !mRenderer || !mRenderer->rootRule() )
492  {
493  return;
494  }
496 
498  // insert all so that we have counts 0
499  Q_FOREACH ( QgsRuleBasedRendererV2::Rule* rule, ruleList )
500  {
501  countMap[rule].count = 0;
502  countMap[rule].duplicateCount = 0;
503  }
504 
506 
507  QgsRenderContext renderContext;
508  renderContext.setRendererScale( 0 ); // ignore scale
509 
510  QgsExpressionContext context;
514  if ( mMapCanvas )
515  {
518  }
519  else
520  {
522  }
524 
525  renderContext.setExpressionContext( context );
526 
527  mRenderer->startRender( renderContext, mLayer->fields() );
528 
529  int nFeatures = mLayer->featureCount();
530  QProgressDialog p( tr( "Calculating feature count." ), tr( "Abort" ), 0, nFeatures );
531  p.setWindowModality( Qt::WindowModal );
532  int featuresCounted = 0;
533 
534  QgsFeature f;
535  while ( fit.nextFeature( f ) )
536  {
537  renderContext.expressionContext().setFeature( f );
538  QgsRuleBasedRendererV2::RuleList featureRuleList = mRenderer->rootRule()->rulesForFeature( f, &renderContext );
539 
540  Q_FOREACH ( QgsRuleBasedRendererV2::Rule* rule, featureRuleList )
541  {
542  countMap[rule].count++;
543  if ( featureRuleList.size() > 1 )
544  {
545  countMap[rule].duplicateCount++;
546  }
547  Q_FOREACH ( QgsRuleBasedRendererV2::Rule* duplicateRule, featureRuleList )
548  {
549  if ( duplicateRule == rule ) continue;
550  countMap[rule].duplicateCountMap[duplicateRule] += 1;
551  }
552  }
553  ++featuresCounted;
554  if ( featuresCounted % 50 == 0 )
555  {
556  if ( featuresCounted > nFeatures ) //sometimes the feature count is not correct
557  {
558  p.setMaximum( 0 );
559  }
560  p.setValue( featuresCounted );
561  if ( p.wasCanceled() )
562  {
563  return;
564  }
565  }
566  }
567  p.setValue( nFeatures );
568 
569  mRenderer->stopRender( renderContext );
570 
571 #ifdef QGISDEBUG
572  Q_FOREACH ( QgsRuleBasedRendererV2::Rule *rule, countMap.keys() )
573  {
574  QgsDebugMsg( QString( "rule: %1 count %2" ).arg( rule->label() ).arg( countMap[rule].count ) );
575  }
576 #endif
577 
578  mModel->setFeatureCounts( countMap );
579 }
580 
582 
584  : QDialog( parent ), mRule( rule ), mLayer( layer ), mSymbolSelector( NULL ), mSymbol( NULL ), mMapCanvas( mapCanvas )
585 {
586  setupUi( this );
587 #ifdef Q_OS_MAC
588  setWindowModality( Qt::WindowModal );
589 #endif
590 
591  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
592  connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
593 
594  editFilter->setText( mRule->filterExpression() );
595  editFilter->setToolTip( mRule->filterExpression() );
596  editLabel->setText( mRule->label() );
597  editDescription->setText( mRule->description() );
598  editDescription->setToolTip( mRule->description() );
599 
600  if ( mRule->dependsOnScale() )
601  {
602  groupScale->setChecked( true );
603  // caution: rule uses scale denom, scale widget uses true scales
604  if ( rule->scaleMinDenom() > 0 )
605  mScaleRangeWidget->setMaximumScale( 1.0 / rule->scaleMinDenom() );
606  if ( rule->scaleMaxDenom() > 0 )
607  mScaleRangeWidget->setMinimumScale( 1.0 / rule->scaleMaxDenom() );
608  }
609  mScaleRangeWidget->setMapCanvas( mMapCanvas );
610 
611  if ( mRule->symbol() )
612  {
613  groupSymbol->setChecked( true );
614  mSymbol = mRule->symbol()->clone(); // use a clone!
615  }
616  else
617  {
618  groupSymbol->setChecked( false );
620  }
621 
622  mSymbolSelector = new QgsSymbolV2SelectorDialog( mSymbol, style, mLayer, this, true );
624  QVBoxLayout* l = new QVBoxLayout;
626  groupSymbol->setLayout( l );
627 
628  connect( btnExpressionBuilder, SIGNAL( clicked() ), this, SLOT( buildExpression() ) );
629  connect( btnTestFilter, SIGNAL( clicked() ), this, SLOT( testFilter() ) );
630 
631  QSettings settings;
632  restoreGeometry( settings.value( "/Windows/QgsRendererRulePropsDialog/geometry" ).toByteArray() );
633 }
634 
636 {
637  delete mSymbol;
638  QSettings settings;
639  settings.setValue( "/Windows/QgsRendererRulePropsDialog/geometry", saveGeometry() );
640 }
641 
643 {
644  QgsExpressionContext context;
648  if ( mMapCanvas )
649  {
652  }
653  else
654  {
656  }
658 
659  QgsExpressionBuilderDialog dlg( mLayer, editFilter->text(), this, "generic", context );
660 
661  if ( dlg.exec() )
662  editFilter->setText( dlg.expressionText() );
663 }
664 
666 {
667  QgsExpression filter( editFilter->text() );
668  if ( filter.hasParserError() )
669  {
670  QMessageBox::critical( this, tr( "Error" ), tr( "Filter expression parsing error:\n" ) + filter.parserErrorString() );
671  return;
672  }
673 
674  QgsExpressionContext context;
678  if ( mMapCanvas )
679  {
682  }
683  else
684  {
686  }
688 
689  if ( !filter.prepare( &context ) )
690  {
691  QMessageBox::critical( this, tr( "Evaluation error" ), filter.evalErrorString() );
692  return;
693  }
694 
695  QApplication::setOverrideCursor( Qt::WaitCursor );
696 
698 
699  int count = 0;
700  QgsFeature f;
701  while ( fit.nextFeature( f ) )
702  {
703  context.setFeature( f );
704 
705  QVariant value = filter.evaluate( &context );
706  if ( value.toInt() != 0 )
707  count++;
708  if ( filter.hasEvalError() )
709  break;
710  }
711 
713 
714  QMessageBox::information( this, tr( "Filter" ), tr( "Filter returned %n feature(s)", "number of filtered features", count ) );
715 }
716 
718 {
719  mRule->setFilterExpression( editFilter->text() );
720  mRule->setLabel( editLabel->text() );
721  mRule->setDescription( editDescription->text() );
722  // caution: rule uses scale denom, scale widget uses true scales
723  mRule->setScaleMinDenom( groupScale->isChecked() ? mScaleRangeWidget->minimumScaleDenom() : 0 );
724  mRule->setScaleMaxDenom( groupScale->isChecked() ? mScaleRangeWidget->maximumScaleDenom() : 0 );
725  mRule->setSymbol( groupSymbol->isChecked() ? mSymbol->clone() : NULL );
726 
727  QDialog::accept();
728 }
729 
731 
732 /*
733  setDragEnabled(true);
734  viewport()->setAcceptDrops(true);
735  setDropIndicatorShown(true);
736  setDragDropMode(QAbstractItemView::InternalMove);
737 */
738 
739 static QString _formatScale( int denom )
740 {
741  if ( denom != 0 )
742  {
743  QString txt = QString( "1:%L1" ).arg( denom );
744  return txt;
745  }
746  else
747  return QString();
748 }
749 
751 
753  : mR( r )
754 {
755 }
756 
758 {
759  if ( !index.isValid() )
760  return Qt::ItemIsDropEnabled;
761 
762  // allow drop only at first column
763  Qt::ItemFlag drop = ( index.column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
764 
765  Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
766 
767  return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
768  Qt::ItemIsEditable | checkable |
769  Qt::ItemIsDragEnabled | drop;
770 }
771 
773 {
774  if ( !index.isValid() )
775  return QVariant();
776 
778 
779  if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
780  {
781  switch ( index.column() )
782  {
783  case 0: return rule->label();
784  case 1:
785  if ( rule->isElse() )
786  {
787  return "ELSE";
788  }
789  else
790  {
791  return rule->filterExpression().isEmpty() ? tr( "(no filter)" ) : rule->filterExpression();
792  }
793  case 2: return rule->dependsOnScale() ? _formatScale( rule->scaleMaxDenom() ) : QVariant();
794  case 3: return rule->dependsOnScale() ? _formatScale( rule->scaleMinDenom() ) : QVariant();
795  case 4:
796  if ( mFeatureCountMap.count( rule ) == 1 )
797  {
798  return QVariant( mFeatureCountMap[rule].count );
799  }
800  return QVariant();
801  case 5:
802  if ( mFeatureCountMap.count( rule ) == 1 )
803  {
804  if ( role == Qt::DisplayRole )
805  {
806  return QVariant( mFeatureCountMap[rule].duplicateCount );
807  }
808  else // tooltip - detailed info about duplicates
809  {
810  if ( mFeatureCountMap[rule].duplicateCount > 0 )
811  {
812  QString tip = "<p style='margin:0px;'><ul>";
813  Q_FOREACH ( QgsRuleBasedRendererV2::Rule* duplicateRule, mFeatureCountMap[rule].duplicateCountMap.keys() )
814  {
815  QString label = duplicateRule->label().replace( "&", "&amp;" ).replace( ">", "&gt;" ).replace( "<", "&lt;" );
816  tip += tr( "<li><nobr>%1 features also in rule %2</nobr></li>" ).arg( mFeatureCountMap[rule].duplicateCountMap[duplicateRule] ).arg( label );
817  }
818  tip += "</ul>";
819  return tip;
820  }
821  else
822  {
823  return 0;
824  }
825  }
826  }
827  return QVariant();
828  default: return QVariant();
829  }
830  }
831  else if ( role == Qt::DecorationRole && index.column() == 0 && rule->symbol() )
832  {
833  return QgsSymbolLayerV2Utils::symbolPreviewIcon( rule->symbol(), QSize( 16, 16 ) );
834  }
835  else if ( role == Qt::TextAlignmentRole )
836  {
837  return ( index.column() == 2 || index.column() == 3 ) ? Qt::AlignRight : Qt::AlignLeft;
838  }
839  else if ( role == Qt::FontRole && index.column() == 1 )
840  {
841  if ( rule->isElse() )
842  {
843  QFont italicFont;
844  italicFont.setItalic( true );
845  return italicFont;
846  }
847  return QVariant();
848  }
849  else if ( role == Qt::EditRole )
850  {
851  switch ( index.column() )
852  {
853  case 0: return rule->label();
854  case 1: return rule->filterExpression();
855  case 2: return rule->scaleMaxDenom();
856  case 3: return rule->scaleMinDenom();
857  default: return QVariant();
858  }
859  }
860  else if ( role == Qt::CheckStateRole )
861  {
862  if ( index.column() != 0 )
863  return QVariant();
864  return rule->checkState() ? Qt::Checked : Qt::Unchecked;
865  }
866  else
867  return QVariant();
868 }
869 
870 QVariant QgsRuleBasedRendererV2Model::headerData( int section, Qt::Orientation orientation, int role ) const
871 {
872  if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 7 )
873  {
874  QStringList lst; lst << tr( "Label" ) << tr( "Rule" ) << tr( "Min. scale" ) << tr( "Max. scale" ) << tr( "Count" ) << tr( "Duplicate count" );
875  return lst[section];
876  }
877  else if ( orientation == Qt::Horizontal && role == Qt::ToolTipRole )
878  {
879  if ( section == 4 ) // Count
880  {
881  return tr( "Number of features in this rule." );
882  }
883  else if ( section == 5 ) // Duplicate count
884  {
885  return tr( "Number of features in this rule which are also present in other rule(s)." );
886  }
887  }
888 
889  return QVariant();
890 }
891 
893 {
894  if ( parent.column() > 0 )
895  return 0;
896 
897  QgsRuleBasedRendererV2::Rule* parentRule = ruleForIndex( parent );
898 
899  return parentRule->children().count();
900 }
901 
903 {
904  return 6;
905 }
906 
907 QModelIndex QgsRuleBasedRendererV2Model::index( int row, int column, const QModelIndex &parent ) const
908 {
909  if ( hasIndex( row, column, parent ) )
910  {
911  QgsRuleBasedRendererV2::Rule* parentRule = ruleForIndex( parent );
912  QgsRuleBasedRendererV2::Rule* childRule = parentRule->children()[row];
913  return createIndex( row, column, childRule );
914  }
915  return QModelIndex();
916 }
917 
919 {
920  if ( !index.isValid() )
921  return QModelIndex();
922 
923  QgsRuleBasedRendererV2::Rule* childRule = ruleForIndex( index );
924  QgsRuleBasedRendererV2::Rule* parentRule = childRule->parent();
925 
926  if ( parentRule == mR->rootRule() )
927  return QModelIndex();
928 
929  // this is right: we need to know row number of our parent (in our grandparent)
930  int row = parentRule->parent()->children().indexOf( parentRule );
931 
932  return createIndex( row, 0, parentRule );
933 }
934 
935 bool QgsRuleBasedRendererV2Model::setData( const QModelIndex & index, const QVariant & value, int role )
936 {
937  if ( !index.isValid() )
938  return false;
939 
941 
942  if ( role == Qt::CheckStateRole )
943  {
944  rule->setCheckState( value.toInt() == Qt::Checked );
945  emit dataChanged( index, index );
946  return true;
947  }
948 
949  if ( role != Qt::EditRole )
950  return false;
951 
952  switch ( index.column() )
953  {
954  case 0: // label
955  rule->setLabel( value.toString() );
956  break;
957  case 1: // filter
958  rule->setFilterExpression( value.toString() );
959  break;
960  case 2: // scale min
961  rule->setScaleMaxDenom( value.toInt() );
962  break;
963  case 3: // scale max
964  rule->setScaleMinDenom( value.toInt() );
965  break;
966  default:
967  return false;
968  }
969 
970  emit dataChanged( index, index );
971  return true;
972 }
973 
975 {
976  return Qt::MoveAction; // | Qt::CopyAction
977 }
978 
980 {
981  QStringList types;
982  types << "application/vnd.text.list";
983  return types;
984 }
985 
986 QMimeData *QgsRuleBasedRendererV2Model::mimeData( const QModelIndexList &indexes ) const
987 {
988  QMimeData *mimeData = new QMimeData();
989  QByteArray encodedData;
990 
991  QDataStream stream( &encodedData, QIODevice::WriteOnly );
992 
993  Q_FOREACH ( const QModelIndex &index, indexes )
994  {
995  // each item consists of several columns - let's add it with just first one
996  if ( !index.isValid() || index.column() != 0 )
997  continue;
998 
999  // we use a clone of the existing rule because it has a new unique rule key
1000  // non-unique rule keys would confuse other components using them (e.g. legend)
1001  QgsRuleBasedRendererV2::Rule* rule = ruleForIndex( index )->clone();
1002  QDomDocument doc;
1003  QgsSymbolV2Map symbols;
1004 
1005  QDomElement rootElem = doc.createElement( "rule_mime" );
1006  rootElem.setAttribute( "type", "renderer" ); // for determining whether rules are from renderer or labeling
1007  QDomElement rulesElem = rule->save( doc, symbols );
1008  rootElem.appendChild( rulesElem );
1009  QDomElement symbolsElem = QgsSymbolLayerV2Utils::saveSymbols( symbols, "symbols", doc );
1010  rootElem.appendChild( symbolsElem );
1011  doc.appendChild( rootElem );
1012 
1013  delete rule;
1014 
1015  stream << doc.toString( -1 );
1016  }
1017 
1018  mimeData->setData( "application/vnd.text.list", encodedData );
1019  return mimeData;
1020 }
1021 
1022 
1023 // manipulate DOM before dropping it so that rules are more useful
1025 {
1026  // labeling rules recognize only "description"
1027  if ( ruleElem.hasAttribute( "description" ) )
1028  ruleElem.setAttribute( "label", ruleElem.attribute( "description" ) );
1029 
1030  // run recursively
1031  QDomElement childRuleElem = ruleElem.firstChildElement( "rule" );
1032  while ( !childRuleElem.isNull() )
1033  {
1034  _labeling2rendererRules( childRuleElem );
1035  childRuleElem = childRuleElem.nextSiblingElement( "rule" );
1036  }
1037 }
1038 
1039 
1041  Qt::DropAction action, int row, int column, const QModelIndex &parent )
1042 {
1043  Q_UNUSED( column );
1044 
1045  if ( action == Qt::IgnoreAction )
1046  return true;
1047 
1048  if ( !data->hasFormat( "application/vnd.text.list" ) )
1049  return false;
1050 
1051  if ( parent.column() > 0 )
1052  return false;
1053 
1054  QByteArray encodedData = data->data( "application/vnd.text.list" );
1055  QDataStream stream( &encodedData, QIODevice::ReadOnly );
1056  int rows = 0;
1057 
1058  if ( row == -1 )
1059  {
1060  // the item was dropped at a parent - we may decide where to put the items - let's append them
1061  row = rowCount( parent );
1062  }
1063 
1064  while ( !stream.atEnd() )
1065  {
1066  QString text;
1067  stream >> text;
1068 
1069  QDomDocument doc;
1070  if ( !doc.setContent( text ) )
1071  continue;
1072  QDomElement rootElem = doc.documentElement();
1073  if ( rootElem.tagName() != "rule_mime" )
1074  continue;
1075  if ( rootElem.attribute( "type" ) == "labeling" )
1076  rootElem.appendChild( doc.createElement( "symbols" ) );
1077  QDomElement symbolsElem = rootElem.firstChildElement( "symbols" );
1078  if ( symbolsElem.isNull() )
1079  continue;
1080  QgsSymbolV2Map symbolMap = QgsSymbolLayerV2Utils::loadSymbols( symbolsElem );
1081  QDomElement ruleElem = rootElem.firstChildElement( "rule" );
1082  if ( rootElem.attribute( "type" ) == "labeling" )
1083  _labeling2rendererRules( ruleElem );
1085 
1086  insertRule( parent, row + rows, rule );
1087 
1088  ++rows;
1089  }
1090  return true;
1091 }
1092 
1094 {
1095  if ( index.isValid() )
1096  return static_cast<QgsRuleBasedRendererV2::Rule*>( index.internalPointer() );
1097  return mR->rootRule();
1098 }
1099 
1100 bool QgsRuleBasedRendererV2Model::removeRows( int row, int count, const QModelIndex & parent )
1101 {
1102  QgsRuleBasedRendererV2::Rule* parentRule = ruleForIndex( parent );
1103 
1104  if ( row < 0 || row >= parentRule->children().count() )
1105  return false;
1106 
1107  QgsDebugMsg( QString( "Called: row %1 count %2 parent ~~%3~~" ).arg( row ).arg( count ).arg( parentRule->dump() ) );
1108 
1109  beginRemoveRows( parent, row, row + count - 1 );
1110 
1111  for ( int i = 0; i < count; i++ )
1112  {
1113  if ( row < parentRule->children().count() )
1114  {
1115  //QgsRuleBasedRendererV2::Rule* r = parentRule->children()[row];
1116  parentRule->removeChildAt( row );
1117  //parentRule->takeChildAt( row );
1118  }
1119  else
1120  {
1121  QgsDebugMsg( "trying to remove invalid index - this should not happen!" );
1122  }
1123  }
1124 
1125  endRemoveRows();
1126 
1127  return true;
1128 }
1129 
1130 
1132 {
1133  beginInsertRows( parent, before, before );
1134 
1135  QgsDebugMsg( QString( "insert before %1 rule: %2" ).arg( before ).arg( newrule->dump() ) );
1136 
1137  QgsRuleBasedRendererV2::Rule* parentRule = ruleForIndex( parent );
1138  parentRule->insertChild( before, newrule );
1139 
1140  endInsertRows();
1141 }
1142 
1144 {
1145  emit dataChanged( index( row, 0, parent ),
1146  index( row, columnCount( parent ), parent ) );
1147 }
1148 
1150 {
1151  emit dataChanged( index( 0, 0, idx ),
1152  index( rowCount( idx ) - 1, columnCount( idx ) - 1, idx ) );
1153 
1154  for ( int i = 0; i < rowCount( idx ); i++ )
1155  {
1156  updateRule( index( i, 0, idx ) );
1157  }
1158 }
1159 
1160 
1162 {
1163  if ( !index.isValid() )
1164  return;
1165 
1166  beginRemoveRows( index.parent(), index.row(), index.row() );
1167 
1168  QgsRuleBasedRendererV2::Rule* rule = ruleForIndex( index );
1169  rule->parent()->removeChild( rule );
1170 
1171  endRemoveRows();
1172 }
1173 
1175 {
1176  int row = rowCount( parent ); // only consider appending
1177  beginInsertRows( parent, row, row + count - 1 );
1178 }
1179 
1181 {
1182  emit endInsertRows();
1183 }
1184 
1186 {
1187  mFeatureCountMap = theCountMap;
1188  updateRule( QModelIndex() );
1189 }
1190 
1192 {
1194  updateRule( QModelIndex() );
1195 }
bool hasIndex(int row, int column, const QModelIndex &parent) const
QString dump(int indent=0) const
Dump for debug purpose.
void customContextMenuRequested(const QPoint &pos)
QgsRuleBasedRendererV2Widget(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, const QString &tagName, QDomDocument &doc)
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:92
void setLabel(const QString &label)
QString description() const
A human readable description for this rule.
void clear()
Wrapper for iterator of features from vector data provider or vector layer.
static QgsSymbolV2Map loadSymbols(QDomElement &element)
QByteArray toByteArray() const
static unsigned index
void refineRuleScalesGui(const QModelIndexList &index)
QByteArray data(const QString &mimeType) const
void setupUi(QWidget *widget)
QgsSymbolV2SelectorDialog * mSymbolSelector
int bottom() const
virtual void reject()
void keyPressEvent(QKeyEvent *event) override
QgsRuleBasedRendererV2Model * mModel
const QgsCategoryList & categories() const
void contextMenuViewCategories(const QPoint &p)
QModelIndex currentIndex() const
const QMimeData * mimeData(Mode mode) const
QDomNode appendChild(const QDomNode &newChild)
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
void setMaximum(int maximum)
static QgsExpressionContextScope * atlasScope(const QgsAtlasComposition *atlas)
Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
QString attribute(const QString &name, const QString &defValue) const
void setWindowModality(Qt::WindowModality windowModality)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QgsFields fields() const
Returns the list of fields of this layer.
virtual bool hasFormat(const QString &mimeType) const
QString toString(int indent) const
void setScaleMaxDenom(int scaleMaxDenom)
Set the maximum denominator for which this rule shall apply.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
virtual QgsSymbolV2 * clone() const =0
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
void rejected()
void setRendererScale(double scale)
void setIcon(const QIcon &icon)
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
const QObjectList & children() const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void addAction(QAction *action)
QgsMapCanvas * mMapCanvas
QList< QgsSymbolV2 * > selectedSymbols() override
Subclasses may provide the capability of changing multiple symbols at once by implementing the follow...
void refineRuleCategoriesGui(const QModelIndexList &index)
QgsRuleBasedRendererV2Model(QgsRuleBasedRendererV2 *r)
QDomElement nextSiblingElement(const QString &tagName) const
Qt::DropActions supportedDropActions() const override
Rule * clone() const
clone this rule, return new instance
void accepted()
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
int exec()
QgsRuleBasedRendererV2::RuleList mCopyBuffer
QDomElement documentElement() const
virtual QgsFeatureRendererV2 * renderer() override
return pointer to the renderer (no transfer of ownership)
void updateRule(const QModelIndex &parent, int row)
RuleList rulesForFeature(QgsFeature &feat, QgsRenderContext *context=0)
tell which rules will be used to render the feature
void saveSectionWidth(int section, int oldSize, int newSize)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:176
virtual QgsFeatureRendererV2 * renderer() override
return pointer to the renderer (no transfer of ownership)
void clear()
QgsRuleBasedRendererV2::Rule * currentRule()
bool isElse()
Check if this rule is an ELSE rule.
QString tr(const char *sourceText, const char *disambiguation, int n)
StandardButton information(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:107
void removeChildAt(int i)
delete child rule
int size() const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
The QgsMapSettings class contains configuration for rendering of the map.
int indexOf(const T &value, int from) const
void resizeSection(int logicalIndex, int size)
virtual QgsFeatureRendererV2 * renderer() override
return pointer to the renderer (no transfer of ownership)
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
QList< Key > keys() const
void setDescription(const QString &description)
Set a human readable description for this rule.
void setValue(const QString &key, const QVariant &value)
void setValue(int progress)
QgsRendererRulePropsDialog(QgsRuleBasedRendererV2::Rule *rule, QgsVectorLayer *layer, QgsStyleV2 *style, QWidget *parent=0, QgsMapCanvas *mapCanvas=0)
bool isValid() const
void refineRuleRangesGui(const QModelIndexList &index)
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString number(int n, int base)
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
int count(const T &value) const
QgsVectorLayer * mLayer
void append(const T &value)
static void refineRuleCategories(Rule *initialRule, QgsCategorizedSymbolRendererV2 *r)
take a rule and create a list of new rules based on the categories from categorized symbol renderer ...
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
void setLayout(QLayout *layout)
int toInt(bool *ok) const
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
bool hasAttribute(const QString &name) const
virtual void stopRender(QgsRenderContext &context) override
QClipboard * clipboard()
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
bool restoreGeometry(const QByteArray &geometry)
static QString _formatScale(int denom)
void setAttribute(const QString &name, const QString &value)
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int toInt(bool *ok, int base) const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static Rule * create(QDomElement &ruleElem, QgsSymbolV2Map &symbolMap)
Create a rule from an XML definition.
bool isEmpty() const
void beginRemoveRows(const QModelIndex &parent, int first, int last)
int row() const
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setOverrideCursor(const QCursor &cursor)
QDomElement save(QDomDocument &doc, QgsSymbolV2Map &symbolMap)
This class keeps data about a rules for rule-based renderer.
void restoreOverrideCursor()
void * internalPointer() const
QModelIndex parent() const
QGis::GeometryType geometryType() const
Returns point, line or polygon.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QMap< QgsRuleBasedRendererV2::Rule *, QgsRuleBasedRendererV2Count > mFeatureCountMap
void setMimeData(QMimeData *src, Mode mode)
QModelIndex parent() const
void removeRule(const QModelIndex &index)
static QgsRendererV2Widget * create(QgsVectorLayer *layer, QgsStyleV2 *style, QgsFeatureRendererV2 *renderer)
bool atEnd() const
static void refineRuleRanges(Rule *initialRule, QgsGraduatedSymbolRendererV2 *r)
take a rule and create a list of new rules based on the ranges from graduated symbol renderer ...
virtual void accept()
void currentRuleChanged(const QModelIndex &current=QModelIndex(), const QModelIndex &previous=QModelIndex())
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
RuleList descendants() const
Returns all children, grand-children, grand-grand-children, grand-gra...
void setFeatureCounts(const QMap< QgsRuleBasedRendererV2::Rule *, QgsRuleBasedRendererV2Count > &theCountMap)
QModelIndex createIndex(int row, int column, void *ptr) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
int key() const
void setShortcut(const QKeySequence &shortcut)
QgsExpressionContext & expressionContext()
Gets the expression context.
QMimeData * mimeData(const QModelIndexList &indexes) const override
void setItalic(bool enable)
void beginInsertRows(const QModelIndex &parent, int first, int last)
bool isNull() const
QString & replace(int position, int n, QChar after)
void setForceOrderingEnabled(bool enabled)
QVariant value(const QString &key, const QVariant &defaultValue) const
QStringList mimeTypes() const override
Contains information about the context of a rendering operation.
QString filterExpression() const
A filter that will check if this rule applies.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
void insertRule(const QModelIndex &parent, int before, QgsRuleBasedRendererV2::Rule *newrule)
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
Definition: qgsmapcanvas.h:429
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
QByteArray saveGeometry() const
typedef DropActions
const QgsRangeList & ranges() const
Rule * parent()
The parent rule.
QAction * addMenu(QMenu *menu)
When drawing a vector layer with rule-based renderer, it goes through the rules and draws features wi...
QgsRuleBasedRendererV2::Rule * ruleForIndex(const QModelIndex &index) const
void setWindowTitle(const QString &)
QDomElement firstChildElement(const QString &tagName) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
provide model index for parent's child item
virtual int columnCount(const QModelIndex &=QModelIndex()) const override
QgsRuleBasedRendererV2::RuleList selectedRules()
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the dialog.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields) override
Needs to be called when a new render cycle is started.
RuleList & children()
Return all children rules of this rule.
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
int column() const
Base class for renderer settings widgets.
QgsRuleBasedRendererV2::Rule * mRule
void setSymbol(QgsSymbolV2 *sym)
set a new symbol (or NULL). Deletes old symbol.
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
static QgsRuleBasedRendererV2 * convertFromRenderer(const QgsFeatureRendererV2 *renderer)
creates a QgsRuleBasedRendererV2 from an existing renderer.
QString tagName() const
void _labeling2rendererRules(QDomElement &ruleElem)
void setData(const QString &mimeType, const QByteArray &data)
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
const_iterator constEnd() const
void insertChild(int i, Rule *rule)
add child rule, take ownership, sets this as parent
void setFilterExpression(const QString &filterExp)
Set the expression used to check if a given feature shall be rendered with this rule.
QDomElement createElement(const QString &tagName)
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
bool isValid() const
Geometry is not required. It may still be returned if e.g. required for a filter condition.
void setScaleMinDenom(int scaleMinDenom)
Set the minimum denominator for which this rule shall apply.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
int count(const Key &key) const
A generic dialog for building expression strings.
virtual void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, const QString &rule="") override
return a list of item text / symbol
void willAddRules(const QModelIndex &parent, int count)
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
static void refineRuleScales(Rule *initialRule, QList< int > scales)
take a rule and create a list of new rules with intervals of scales given by the passed scale denomin...
typedef ItemFlags