32 #include "qgssettings.h" 
   37 #include <QProgressDialog> 
   38 #include <QTreeWidgetItem> 
   39 #include <QVBoxLayout> 
   40 #include <QMessageBox> 
   43 #ifdef ENABLE_MODELTEST 
   44 #include "modeltest.h" 
   55   , mContextMenu( new QMenu( this ) )
 
   71     mRenderer = std::make_unique< QgsRuleBasedRenderer >( symbol );
 
   75   this->layout()->setContentsMargins( 0, 0, 0, 0 );
 
   78 #ifdef ENABLE_MODELTEST 
   79   new ModelTest( 
mModel, 
this ); 
 
   81   viewRules->setModel( 
mModel );
 
   84   mDeleteAction->setShortcut( QKeySequence( QKeySequence::Delete ) );
 
   90   mRefineMenu = 
new QMenu( tr( 
"Refine Current Rule" ), btnRefineRule );
 
  103   connect( viewRules, &QWidget::customContextMenuRequested,  
this, &QgsRuleBasedRendererWidget::showContextMenu );
 
  165     QModelIndex currentIndex = viewRules->selectionModel()->currentIndex();
 
  166     mModel->
insertRule( currentIndex.parent(), currentIndex.row() + 1, newrule );
 
  167     QModelIndex newindex = 
mModel->
index( currentIndex.row() + 1, 0, currentIndex.parent() );
 
  168     viewRules->selectionModel()->setCurrentIndex( newindex, QItemSelectionModel::ClearAndSelect );
 
  176     viewRules->selectionModel()->setCurrentIndex( newindex, QItemSelectionModel::ClearAndSelect );
 
  183   QItemSelectionModel *sel = viewRules->selectionModel();
 
  184   QModelIndex idx = sel->currentIndex();
 
  185   if ( !idx.isValid() )
 
  192   editRule( viewRules->selectionModel()->currentIndex() );
 
  197   if ( !index.isValid() )
 
  224   QItemSelection sel = viewRules->selectionModel()->selection();
 
  225   QgsDebugMsg( QStringLiteral( 
"REMOVE RULES!!! ranges: %1" ).arg( sel.count() ) );
 
  226   const auto constSel = sel;
 
  227   for ( 
const QItemSelectionRange &range : constSel )
 
  229     QgsDebugMsg( QStringLiteral( 
"RANGE: r %1 - %2" ).arg( range.top() ).arg( range.bottom() ) );
 
  230     if ( range.isValid() )
 
  231       mModel->
removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
 
  234   viewRules->selectionModel()->clear();
 
  241   btnEditRule->setEnabled( current.isValid() );
 
  250 #include <QDialogButtonBox> 
  251 #include <QInputDialog> 
  252 #include <QClipboard> 
  256   QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
 
  258   if ( indexlist.isEmpty() )
 
  264   else if ( type == 1 ) 
 
  272   const auto constIndexlist = indexlist;
 
  273   for ( 
const QModelIndex &index : constIndexlist )
 
  274     viewRules->expand( index );
 
  312   for ( 
const QModelIndex &index : indexList )
 
  317     if ( !initialRule->
symbol() )
 
  319       QMessageBox::warning( 
this, tr( 
"Scale Refinement" ), tr( 
"Parent rule %1 must have a symbol for this operation." ).arg( initialRule->
label() ) );
 
  324   QString txt = QInputDialog::getText( 
this,
 
  325                                        tr( 
"Scale Refinement" ),
 
  326                                        tr( 
"Please enter scale denominators at which will split the rule, separate them by commas (e.g. 1000,5000):" ) );
 
  332   const auto constSplit = txt.split( 
',' );
 
  333   for ( 
const QString &item : constSplit )
 
  335     int scale = item.toInt( &ok );
 
  337       scales.append( scale );
 
  339       QMessageBox::information( 
this, tr( 
"Scale Refinement" ), tr( 
"\"%1\" is not valid scale denominator, ignoring it." ).arg( item ) );
 
  342   for ( 
const QModelIndex &index : indexList )
 
  361       mRenderer->setLegendSymbolItem( legendSymbol.ruleKey(), sym->
clone() );
 
  370   QList<QgsSymbol *> symbolList;
 
  377   QItemSelection sel = viewRules->selectionModel()->selection();
 
  378   const auto constSel = sel;
 
  379   for ( 
const QItemSelectionRange &range : constSel )
 
  381     QModelIndex parent = range.parent();
 
  384     for ( 
int row = range.top(); row <= range.bottom(); row++ )
 
  386       symbolList.append( children.at( row )->symbol() );
 
  396   QItemSelection sel = viewRules->selectionModel()->selection();
 
  397   const auto constSel = sel;
 
  398   for ( 
const QItemSelectionRange &range : constSel )
 
  400     QModelIndex parent = range.parent();
 
  403     for ( 
int row = range.top(); row <= range.bottom(); row++ )
 
  405       rl.append( children.at( row )->clone() );
 
  430   if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
 
  436   else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
 
  438     QgsRuleBasedRenderer::RuleList::const_iterator rIt = 
mCopyBuffer.constBegin();
 
  480   QgsSettings settings;
 
  481   QString path = 
"/Windows/RuleBasedTree/sectionWidth/" + QString::number( section );
 
  482   settings.setValue( path, newSize );
 
  487   QgsSettings settings;
 
  488   QString path = QStringLiteral( 
"/Windows/RuleBasedTree/sectionWidth/" );
 
  489   QHeaderView *head = viewRules->header();
 
  490   head->resizeSection( 0, settings.value( path + QString::number( 0 ), 150 ).toInt() );
 
  491   head->resizeSection( 1, settings.value( path + QString::number( 1 ), 150 ).toInt() );
 
  492   head->resizeSection( 2, settings.value( path + QString::number( 2 ), 80 ).toInt() );
 
  493   head->resizeSection( 3, settings.value( path + QString::number( 3 ), 80 ).toInt() );
 
  494   head->resizeSection( 4, settings.value( path + QString::number( 4 ), 50 ).toInt() );
 
  495   head->resizeSection( 5, settings.value( path + QString::number( 5 ), 50 ).toInt() );
 
  500   QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
 
  503   if ( indexlist.isEmpty() )
 
  507   QApplication::clipboard()->setMimeData( mime );
 
  512   const QMimeData *mime = QApplication::clipboard()->mimeData();
 
  513   QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
 
  515   if ( indexlist.isEmpty() )
 
  518     index = indexlist.first();
 
  519   mModel->
dropMimeData( mime, Qt::CopyAction, index.row(), index.column(), index.parent() );
 
  528   const QModelIndexList indexList = viewRules->selectionModel()->selectedRows();
 
  529   for ( 
const QModelIndex &index : indexList )
 
  533       if ( !rule->symbol() || rule->symbol()->type() != tempSymbol->type() )
 
  542 void QgsRuleBasedRendererWidget::refineRuleCategoriesAccepted( 
QgsPanelWidget *panel )
 
  548   QModelIndexList indexList = viewRules->selectionModel()->selectedRows();
 
  549   const auto constIndexList = indexList;
 
  550   for ( 
const QModelIndex &index : constIndexList )
 
  559 void QgsRuleBasedRendererWidget::refineRuleRangesAccepted( 
QgsPanelWidget *panel )
 
  564   QModelIndexList indexList = viewRules->selectionModel()->selectedRows();
 
  565   const auto constIndexList = indexList;
 
  566   for ( 
const QModelIndex &index : constIndexList )
 
  575 void QgsRuleBasedRendererWidget::ruleWidgetPanelAccepted( 
QgsPanelWidget *panel )
 
  584   QModelIndex index = viewRules->selectionModel()->currentIndex();
 
  589 void QgsRuleBasedRendererWidget::liveUpdateRuleFromPanel()
 
  591   ruleWidgetPanelAccepted( qobject_cast<QgsPanelWidget *>( sender() ) );
 
  594 void QgsRuleBasedRendererWidget::showContextMenu( QPoint )
 
  600   const QList< QAction * > actions = 
contextMenu->actions();
 
  601   for ( QAction *act : actions )
 
  618   QHash<QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount> countMap;
 
  622   const auto constRuleList = ruleList;
 
  625     countMap[rule].count = 0;
 
  626     countMap[rule].duplicateCount = 0;
 
  651   QProgressDialog p( tr( 
"Calculating feature count." ), tr( 
"Abort" ), 0, 100 );
 
  652   p.setWindowModality( Qt::WindowModal );
 
  653   long long featuresCounted = 0;
 
  661     const auto constFeatureRuleList = featureRuleList;
 
  664       countMap[rule].count++;
 
  665       if ( featureRuleList.size() > 1 )
 
  667         countMap[rule].duplicateCount++;
 
  669       const auto constFeatureRuleList = featureRuleList;
 
  672         if ( duplicateRule == rule ) 
continue;
 
  673         countMap[rule].duplicateCountMap[duplicateRule] += 1;
 
  677     if ( featuresCounted % 50 == 0 )
 
  679       if ( featuresCounted > nFeatures ) 
 
  683       p.setValue( 
static_cast< double >( featuresCounted ) / nFeatures * 100.0 );
 
  684       if ( p.wasCanceled() )
 
  690   p.setValue( nFeatures );
 
  695   const auto constKeys = countMap.keys();
 
  698     QgsDebugMsg( QStringLiteral( 
"rule: %1 count %2" ).arg( rule->label() ).arg( countMap[rule].count ) );
 
  707   bool enabled = !viewRules->selectionModel()->selectedIndexes().isEmpty();
 
  708   btnRefineRule->setEnabled( enabled );
 
  709   btnRemoveRule->setEnabled( enabled );
 
  718   , mContext( context )
 
  721   layout()->setContentsMargins( 0, 0, 0, 0 );
 
  733     groupScale->setChecked( 
true );
 
  741     groupSymbol->setChecked( 
true );
 
  746     groupSymbol->setChecked( 
false );
 
  755   QVBoxLayout *l = 
new QVBoxLayout;
 
  757   groupSymbol->setLayout( l );
 
  767   connect( mFilterRadio, &QRadioButton::toggled, 
this, [ = ]( 
bool toggled ) { filterFrame->setEnabled( toggled ) ; } );
 
  768   connect( mElseRadio, &QRadioButton::toggled, 
this, [ = ]( 
bool toggled ) { 
if ( toggled ) editFilter->setText( QStringLiteral( 
"ELSE" ) );} );
 
  778   setWindowModality( Qt::WindowModal );
 
  781   QVBoxLayout *layout = 
new QVBoxLayout( 
this );
 
  783   scrollArea->setFrameShape( QFrame::NoFrame );
 
  784   layout->addWidget( scrollArea );
 
  786   buttonBox = 
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
 
  789   scrollArea->setWidget( mPropsWidget );
 
  790   layout->addWidget( buttonBox );
 
  791   this->setWindowTitle( 
"Edit Rule" );
 
  795   connect( buttonBox, &QDialogButtonBox::rejected, 
this, &QDialog::reject );
 
  796   connect( buttonBox, &QDialogButtonBox::helpRequested, 
this, &QgsRendererRulePropsDialog::showHelp );
 
  811   mPropsWidget->
apply();
 
  815 void QgsRendererRulePropsDialog::showHelp()
 
  817   QgsHelp::openHelp( QStringLiteral( 
"working_with_vector/vector_properties.html#rule-based-rendering" ) );
 
  840   if ( !mFilterRadio->isChecked() )
 
  846     QMessageBox::critical( 
this, tr( 
"Test Filter" ),  tr( 
"Filter expression parsing error:\n" ) + filter.
parserErrorString() );
 
  859   if ( !filter.
prepare( &context ) )
 
  861     QMessageBox::critical( 
this, tr( 
"Test Filter" ), filter.
evalErrorString() );
 
  865   QApplication::setOverrideCursor( Qt::WaitCursor );
 
  881   QApplication::restoreOverrideCursor();
 
  883   QMessageBox::information( 
this, tr( 
"Test Filter" ), tr( 
"Filter returned %n feature(s)", 
"number of filtered features", count ) );
 
  888   QString filter = mElseRadio->isChecked() ? QStringLiteral( 
"ELSE" ) : editFilter->text();
 
  916   : QAbstractItemModel( parent )
 
  923   if ( !
index.isValid() )
 
  924     return Qt::ItemIsDropEnabled;
 
  927   Qt::ItemFlag drop = ( 
index.column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
 
  929   Qt::ItemFlag checkable = ( 
index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
 
  931   return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
 
  932          Qt::ItemIsEditable | checkable |
 
  933          Qt::ItemIsDragEnabled | drop;
 
  938   if ( !
index.isValid() )
 
  943   if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
 
  945     switch ( 
index.column() )
 
  948         return rule->
label();
 
  971           if ( role == Qt::DisplayRole )
 
  979               QString tip = QStringLiteral( 
"<p style='margin:0px;'><ul>" );
 
  981               for ( 
auto it = duplicateMap.constBegin(); it != duplicateMap.constEnd(); ++it )
 
  983                 QString label = it.key()->label().replace( 
'&', QLatin1String( 
"&" ) ).replace( 
'>', QLatin1String( 
">" ) ).replace( 
'<', QLatin1String( 
"<" ) );
 
  984                 tip += tr( 
"<li><nobr>%1 features also in rule %2</nobr></li>" ).arg( it.value() ).arg( label );
 
  986               tip += QLatin1String( 
"</ul>" );
 
 1000   else if ( role == Qt::DecorationRole && 
index.column() == 0 && rule->
symbol() )
 
 1005   else if ( role == Qt::TextAlignmentRole )
 
 1007     return ( 
index.column() == 2 || 
index.column() == 3 ) ? Qt::AlignRight : Qt::AlignLeft;
 
 1009   else if ( role == Qt::FontRole && 
index.column() == 1 )
 
 1014       italicFont.setItalic( 
true );
 
 1019   else if ( role == Qt::EditRole )
 
 1021     switch ( 
index.column() )
 
 1024         return rule->
label();
 
 1035   else if ( role == Qt::CheckStateRole )
 
 1037     if ( 
index.column() != 0 )
 
 1039     return rule->
active() ? Qt::Checked : Qt::Unchecked;
 
 1047   if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 7 )
 
 1050     lst << tr( 
"Label" ) << tr( 
"Rule" ) << tr( 
"Min. Scale" ) << tr( 
"Max. Scale" ) << tr( 
"Count" ) << tr( 
"Duplicate Count" );
 
 1051     return lst[section];
 
 1053   else if ( orientation == Qt::Horizontal && role == Qt::ToolTipRole )
 
 1057       return tr( 
"Number of features in this rule." );
 
 1059     else if ( section == 5 )  
 
 1061       return tr( 
"Number of features in this rule which are also present in other rule(s)." );
 
 1070   if ( 
parent.column() > 0 )
 
 1075   return parentRule->
children().count();
 
 1085   if ( hasIndex( row, column, 
parent ) )
 
 1089     return createIndex( row, column, childRule );
 
 1091   return QModelIndex();
 
 1096   if ( !
index.isValid() )
 
 1097     return QModelIndex();
 
 1103     return QModelIndex();
 
 1106   int row = parentRule->
parent()->
children().indexOf( parentRule );
 
 1108   return createIndex( row, 0, parentRule );
 
 1113   if ( !
index.isValid() )
 
 1118   if ( role == Qt::CheckStateRole )
 
 1120     rule->
setActive( value.toInt() == Qt::Checked );
 
 1125   if ( role != Qt::EditRole )
 
 1128   switch ( 
index.column() )
 
 1131       rule->
setLabel( value.toString() );
 
 1152   return Qt::MoveAction; 
 
 1158   types << QStringLiteral( 
"application/vnd.text.list" );
 
 1164   QMimeData *
mimeData = 
new QMimeData();
 
 1165   QByteArray encodedData;
 
 1167   QDataStream stream( &encodedData, QIODevice::WriteOnly );
 
 1169   const auto constIndexes = indexes;
 
 1170   for ( 
const QModelIndex &
index : constIndexes )
 
 1173     if ( !
index.isValid() || 
index.column() != 0 )
 
 1182     QDomElement rootElem = doc.createElement( QStringLiteral( 
"rule_mime" ) );
 
 1183     rootElem.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"renderer" ) ); 
 
 1184     QDomElement rulesElem = rule->
save( doc, symbols );
 
 1185     rootElem.appendChild( rulesElem );
 
 1187     rootElem.appendChild( symbolsElem );
 
 1188     doc.appendChild( rootElem );
 
 1192     stream << doc.toString( -1 );
 
 1195   mimeData->setData( QStringLiteral( 
"application/vnd.text.list" ), encodedData );
 
 1204   if ( ruleElem.hasAttribute( QStringLiteral( 
"description" ) ) )
 
 1205     ruleElem.setAttribute( QStringLiteral( 
"label" ), ruleElem.attribute( QStringLiteral( 
"description" ) ) );
 
 1208   QDomElement childRuleElem = ruleElem.firstChildElement( QStringLiteral( 
"rule" ) );
 
 1209   while ( !childRuleElem.isNull() )
 
 1212     childRuleElem = childRuleElem.nextSiblingElement( QStringLiteral( 
"rule" ) );
 
 1218     Qt::DropAction action, 
int row, 
int column, 
const QModelIndex &parent )
 
 1222   if ( action == Qt::IgnoreAction )
 
 1225   if ( !
data->hasFormat( QStringLiteral( 
"application/vnd.text.list" ) ) )
 
 1228   if ( 
parent.column() > 0 )
 
 1231   QByteArray encodedData = 
data->data( QStringLiteral( 
"application/vnd.text.list" ) );
 
 1232   QDataStream stream( &encodedData, QIODevice::ReadOnly );
 
 1241   while ( !stream.atEnd() )
 
 1247     if ( !doc.setContent( text ) )
 
 1249     QDomElement rootElem = doc.documentElement();
 
 1250     if ( rootElem.tagName() != QLatin1String( 
"rule_mime" ) )
 
 1252     if ( rootElem.attribute( QStringLiteral( 
"type" ) ) == QLatin1String( 
"labeling" ) )
 
 1253       rootElem.appendChild( doc.createElement( QStringLiteral( 
"symbols" ) ) );
 
 1254     QDomElement symbolsElem = rootElem.firstChildElement( QStringLiteral( 
"symbols" ) );
 
 1255     if ( symbolsElem.isNull() )
 
 1258     QDomElement ruleElem = rootElem.firstChildElement( QStringLiteral( 
"rule" ) );
 
 1259     if ( rootElem.attribute( QStringLiteral( 
"type" ) ) == QLatin1String( 
"labeling" ) )
 
 1272   if ( 
index.isValid() )
 
 1281   if ( row < 0 || row >= parentRule->
children().count() )
 
 1284   QgsDebugMsg( QStringLiteral( 
"Called: row %1 count %2 parent ~~%3~~" ).arg( row ).arg( count ).arg( parentRule->
dump() ) );
 
 1286   beginRemoveRows( 
parent, row, row + count - 1 );
 
 1288   for ( 
int i = 0; i < count; i++ )
 
 1290     if ( row < parentRule->children().count() )
 
 1298       QgsDebugMsg( QStringLiteral( 
"trying to remove invalid index - this should not happen!" ) );
 
 1310   beginInsertRows( 
parent, before, before );
 
 1312   QgsDebugMsg( QStringLiteral( 
"insert before %1 rule: %2" ).arg( before ).arg( newrule->
dump() ) );
 
 1328   emit dataChanged( 
index( 0, 0, idx ),
 
 1331   for ( 
int i = 0; i < 
rowCount( idx ); i++ )
 
 1340   if ( !
index.isValid() )
 
 1361   beginInsertRows( 
parent, row, row + count - 1 );
 
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
const QgsCategoryList & categories() const
Returns a list of all categories recognized by the renderer.
A generic dialog for building expression strings.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QString evalErrorString() const
Returns evaluation error.
QString parserErrorString() const
Returns parser error.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
const QgsRangeList & ranges() const
static QgsGui * instance()
Returns a pointer to the singleton instance.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void setRendererScale(double scale)
Sets the renderer map scale.
QgsRuleBasedRenderer::Rule * rule()
QgsRendererRulePropsDialog(QgsRuleBasedRenderer::Rule *rule, QgsVectorLayer *layer, QgsStyle *style, QWidget *parent=nullptr, const QgsSymbolWidgetContext &context=QgsSymbolWidgetContext())
Constructor for QgsRendererRulePropsDialog.
Tree model for the rules:
QgsRuleBasedRenderer::Rule * ruleForIndex(const QModelIndex &index) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
void updateRule(const QModelIndex &parent, int row)
void willAddRules(const QModelIndex &parent, int count)
Qt::ItemFlags flags(const QModelIndex &index) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setSymbol(const QModelIndex &index, QgsSymbol *symbol)
Sets the symbol for the rule at the specified index.
void clearFeatureCounts()
QStringList mimeTypes() const override
void removeRule(const QModelIndex &index)
int columnCount(const QModelIndex &=QModelIndex()) const override
Qt::DropActions supportedDropActions() const override
void setFeatureCounts(const QHash< QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount > &countMap)
QgsRuleBasedRenderer * mR
QModelIndex parent(const QModelIndex &index) const override
QHash< QgsRuleBasedRenderer::Rule *, QgsRuleBasedRendererCount > mFeatureCountMap
QMimeData * mimeData(const QModelIndexList &indexes) const override
QgsRuleBasedRendererModel(QgsRuleBasedRenderer *renderer, QObject *parent)
Constructor for QgsRuleBasedRendererModel, for the specified renderer.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void insertRule(const QModelIndex &parent, int before, QgsRuleBasedRenderer::Rule *newrule)
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void finishedAddingRules()
This class keeps data about a rules for rule-based renderer.
void setSymbol(QgsSymbol *sym)
Sets a new symbol (or nullptr). Deletes old symbol.
void removeChild(QgsRuleBasedRenderer::Rule *rule)
delete child rule
void insertChild(int i, QgsRuleBasedRenderer::Rule *rule)
add child rule, take ownership, sets this as parent
void setDescription(const QString &description)
Set a human readable description for this rule.
bool dependsOnScale() const
double maximumScale() const
Returns the maximum map scale (i.e.
bool isElse() const
Check if this rule is an ELSE rule.
QgsRuleBasedRenderer::Rule * clone() const
clone this rule, return new instance
static QgsRuleBasedRenderer::Rule * create(QDomElement &ruleElem, QgsSymbolMap &symbolMap)
Create a rule from an XML definition.
QgsRuleBasedRenderer::Rule * parent()
The parent rule.
void removeChildAt(int i)
delete child rule
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
void setActive(bool state)
Sets if this rule is active.
QDomElement save(QDomDocument &doc, QgsSymbolMap &symbolMap) const
double minimumScale() const
Returns the minimum map scale (i.e.
QString description() const
A human readable description for this rule.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
const QgsRuleBasedRenderer::RuleList & children()
Returns all children rules of this rule.
void setFilterExpression(const QString &filterExp)
Set the expression used to check if a given feature shall be rendered with this rule.
void setLabel(const QString &label)
QString dump(int indent=0) const
Dump for debug purpose.
QString filterExpression() const
A filter that will check if this rule applies.
bool active() const
Returns if this rule is active.
static void refineRuleCategories(QgsRuleBasedRenderer::Rule *initialRule, QgsCategorizedSymbolRenderer *r)
take a rule and create a list of new rules based on the categories from categorized symbol renderer
static void refineRuleRanges(QgsRuleBasedRenderer::Rule *initialRule, QgsGraduatedSymbolRenderer *r)
take a rule and create a list of new rules based on the ranges from graduated symbol renderer
QgsRuleBasedRenderer::Rule * rootRule()
static QgsRuleBasedRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer, QgsVectorLayer *layer=nullptr)
Creates a new QgsRuleBasedRenderer from an existing renderer.
static void refineRuleScales(QgsRuleBasedRenderer::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...
QList< QgsRuleBasedRenderer::Rule * > RuleList
static QString toString(double scale)
Helper function to convert a scale double to scale string.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
static QgsSymbolMap loadSymbols(QDomElement &element, const QgsReadWriteContext &context)
Reads a collection of symbols from XML and returns them in a map. Caller is responsible for deleting ...
static QDomElement saveSymbols(QgsSymbolMap &symbols, const QString &tagName, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a collection of symbols to XML with specified tagName for the top-level element.
A dialog which allows the user to modify the rendering order of symbol layers.
QgsLegendSymbolList symbolLevels() const
Returns the current legend symbols with rendering passes set, as defined in the widget.
bool usingLevels() const
Returns whether the level ordering is enabled.
void setForceOrderingEnabled(bool enabled)
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
Abstract base class for all rendered symbols.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
long long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
#define QgsDebugMsgLevel(str, level)
QMap< QString, QgsSymbol * > QgsSymbolMap