31 #include <QProgressDialog> 33 #include <QTreeWidgetItem> 34 #include <QVBoxLayout> 35 #include <QMessageBox> 37 #ifdef ENABLE_MODELTEST 38 #include "modeltest.h" 69 #ifdef ENABLE_MODELTEST 70 new ModelTest(
mModel,
this );
72 viewRules->setModel(
mModel );
100 connect( btnAddRule, SIGNAL( clicked() ),
this, SLOT(
addRule() ) );
112 connect( viewRules->header(), SIGNAL( sectionResized(
int,
int,
int ) ),
this, SLOT(
saveSectionWidth(
int,
int,
int ) ) );
141 QModelIndex currentIndex = viewRules->selectionModel()->currentIndex();
169 editRule( viewRules->selectionModel()->currentIndex() );
198 viewRules->selectionModel()->clear();
204 Q_UNUSED( previous );
205 btnEditRule->setEnabled( current.
isValid() );
214 #include <QDialogButtonBox> 215 #include <QInputDialog> 216 #include <QClipboard> 220 QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
222 if ( indexlist.isEmpty() )
228 else if ( type == 1 )
237 viewRules->expand( index );
265 connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
266 connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
296 connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
297 connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
321 if ( !initialRule->
symbol() )
323 QMessageBox::warning(
this,
tr(
"Scale refinement" ),
tr(
"Parent rule %1 must have a symbol for this operation." ).arg( initialRule->
label() ) );
329 tr(
"Scale refinement" ),
330 tr(
"Please enter scale denominators at which will split the rule, separate them by commas (e.g. 1000,5000):" ) );
338 int scale = item.
toInt( &ok );
369 for (
int row = range.
top(); row <= range.
bottom(); row++ )
371 symbolList.
append( children[row]->symbol() );
387 for (
int row = range.
top(); row <= range.
bottom(); row++ )
389 rl.
append( children[row]->clone() );
413 if ( event->
key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
419 else if ( event->
key() == Qt::Key_V &&
event->modifiers() == Qt::ControlModifier )
456 QString path =
"/Windows/RuleBasedTree/sectionWidth/";
468 QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
471 if ( indexlist.isEmpty() )
481 QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
483 if ( indexlist.isEmpty() )
486 index = indexlist.first();
503 countMap[rule].
count = 0;
504 countMap[rule].duplicateCount = 0;
537 int featuresCounted = 0;
547 countMap[rule].
count++;
548 if ( featureRuleList.
size() > 1 )
550 countMap[rule].duplicateCount++;
554 if ( duplicateRule == rule )
continue;
555 countMap[rule].duplicateCountMap[duplicateRule] += 1;
559 if ( featuresCounted % 50 == 0 )
561 if ( featuresCounted > nFeatures )
588 bool enabled = !viewRules->selectionModel()->selectedIndexes().isEmpty();
589 btnRefineRule->setEnabled( enabled );
590 btnRemoveRule->setEnabled( enabled );
596 :
QDialog( parent ), mRule( rule ),
mLayer( layer ), mSymbolSelector( nullptr ), mSymbol( nullptr ),
mMapCanvas( mapCanvas )
614 groupScale->setChecked(
true );
617 mScaleRangeWidget->setMaximumScale( 1.0 / rule->
scaleMinDenom() );
619 mScaleRangeWidget->setMinimumScale( 1.0 / rule->
scaleMaxDenom() );
621 mScaleRangeWidget->setMapCanvas(
mMapCanvas );
625 groupSymbol->setChecked(
true );
630 groupSymbol->setChecked(
false );
638 groupSymbol->setLayout( l );
674 editFilter->setText( dlg.expressionText() );
680 if ( filter.hasParserError() )
701 if ( !filter.prepare( &context ) )
712 .setExpressionContext( context );
771 return Qt::ItemIsDropEnabled;
774 Qt::ItemFlag drop = ( index.
column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
776 Qt::ItemFlag checkable = ( index.
column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
778 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
779 Qt::ItemIsEditable | checkable |
780 Qt::ItemIsDragEnabled | drop;
790 if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
795 return rule->
label();
818 if ( role == Qt::DisplayRole )
826 QString tip =
"<p style='margin:0px;'><ul>";
830 tip +=
tr(
"<li><nobr>%1 features also in rule %2</nobr></li>" ).
arg(
mFeatureCountMap[rule].duplicateCountMap[duplicateRule] ).
arg( label );
846 else if ( role == Qt::DecorationRole && index.
column() == 0 && rule->
symbol() )
850 else if ( role == Qt::TextAlignmentRole )
852 return ( index.
column() == 2 || index.
column() == 3 ) ? Qt::AlignRight : Qt::AlignLeft;
854 else if ( role == Qt::FontRole && index.
column() == 1 )
864 else if ( role == Qt::EditRole )
869 return rule->
label();
880 else if ( role == Qt::CheckStateRole )
882 if ( index.
column() != 0 )
884 return rule->
active() ? Qt::Checked : Qt::Unchecked;
892 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 7 )
895 lst <<
tr(
"Label" ) <<
tr(
"Rule" ) <<
tr(
"Min. scale" ) <<
tr(
"Max. scale" ) <<
tr(
"Count" ) <<
tr(
"Duplicate count" );
898 else if ( orientation == Qt::Horizontal && role == Qt::ToolTipRole )
902 return tr(
"Number of features in this rule." );
904 else if ( section == 5 )
906 return tr(
"Number of features in this rule which are also present in other rule(s)." );
915 if ( parent.
column() > 0 )
930 if (
hasIndex( row, column, parent ) )
963 if ( role == Qt::CheckStateRole )
970 if ( role != Qt::EditRole )
997 return Qt::MoveAction;
1003 types <<
"application/vnd.text.list";
1012 QDataStream stream( &encodedData, QIODevice::WriteOnly );
1039 mimeData->
setData(
"application/vnd.text.list", encodedData );
1053 while ( !childRuleElem.
isNull() )
1066 if ( action == Qt::IgnoreAction )
1069 if ( !data->
hasFormat(
"application/vnd.text.list" ) )
1072 if ( parent.
column() > 0 )
1075 QByteArray encodedData = data->
data(
"application/vnd.text.list" );
1076 QDataStream stream( &encodedData, QIODevice::ReadOnly );
1085 while ( !stream.
atEnd() )
1094 if ( rootElem.
tagName() !=
"rule_mime" )
1096 if ( rootElem.
attribute(
"type" ) ==
"labeling" )
1099 if ( symbolsElem.
isNull() )
1103 if ( rootElem.
attribute(
"type" ) ==
"labeling" )
1117 return static_cast<QgsRuleBasedRendererV2::Rule*>( index.
internalPointer() );
1128 QgsDebugMsg(
QString(
"Called: row %1 count %2 parent ~~%3~~" ).arg( row ).arg( count ).arg( parentRule->
dump() ) );
1132 for (
int i = 0; i < count; i++ )
1134 if ( row < parentRule->
children().count() )
1142 QgsDebugMsg(
"trying to remove invalid index - this should not happen!" );
1175 for (
int i = 0; i <
rowCount( idx ); i++ )
1190 rule->parent()->removeChild( rule );
const QgsCategoryList & categories() const
bool hasIndex(int row, int column, const QModelIndex &parent) const
bool active() const
Returns if this rule is active.
QgsRendererRulePropsDialog(QgsRuleBasedRendererV2::Rule *rule, QgsVectorLayer *layer, QgsStyleV2 *style, QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr)
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, const QString &tagName, QDomDocument &doc)
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsRuleBasedRendererV2 * mR
void setLabel(const QString &label)
Wrapper for iterator of features from vector data provider or vector layer.
static QgsSymbolV2Map loadSymbols(QDomElement &element)
QByteArray toByteArray() const
virtual QString filter(const QgsFields &fields=QgsFields()) override
If a renderer does not require all the features this method may be overridden and return an expressio...
QByteArray data(const QString &mimeType) const
QgsSymbolV2SelectorDialog * mSymbolSelector
~QgsRendererRulePropsDialog()
QModelIndex currentIndex() const
QgsMapCanvas * mMapCanvas
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 setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setActive(bool state)
Sets if this rule is active.
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 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
QgsRuleBasedRendererV2::Rule * ruleForIndex(const QModelIndex &index) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsRuleBasedRendererV2Model(QgsRuleBasedRendererV2 *r)
QDomElement nextSiblingElement(const QString &tagName) const
Qt::DropActions supportedDropActions() const override
QDomElement save(QDomDocument &doc, QgsSymbolV2Map &symbolMap) const
QDomElement documentElement() const
void updateRule(const QModelIndex &parent, int row)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool isElse()
Check if this rule is an ELSE rule.
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
void removeChildAt(int i)
delete child rule
QgsFields fields() const
Returns the list of fields of this layer.
QString description() const
A human readable description for this rule.
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
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)
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
void setValue(int progress)
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QString number(int n, int base)
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
int count(const T &value) const
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...
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
Needs to be called when a render cycle has finished to clean up.
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
const QgsRangeList & ranges() const
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.
void beginRemoveRows(const QModelIndex &parent, int first, int last)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void setOverrideCursor(const QCursor &cursor)
QList< int > QgsAttributeList
This class keeps data about a rules for rule-based renderer.
void restoreOverrideCursor()
void * internalPointer() const
Rule * clone() const
clone this rule, return new instance
QModelIndex parent() const
RuleList descendants() const
Returns all children, grand-children, grand-grand-children, grand-gra...
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
int scaleMaxDenom() const
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 void refineRuleRanges(Rule *initialRule, QgsGraduatedSymbolRendererV2 *r)
take a rule and create a list of new rules based on the ranges from graduated symbol renderer ...
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)
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
void setShortcut(const QKeySequence &shortcut)
QgsExpressionContext & expressionContext()
Gets the expression context.
QString filterExpression() const
A filter that will check if this rule applies.
QMimeData * mimeData(const QModelIndexList &indexes) const override
void setItalic(bool enable)
void beginInsertRows(const QModelIndex &parent, int first, int last)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
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.
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.
void finishedAddingRules()
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
Rule * parent()
The parent rule.
When drawing a vector layer with rule-based renderer, it goes through the rules and draws features wi...
RuleList rulesForFeature(QgsFeature &feat, QgsRenderContext *context=nullptr)
tell which rules will be used to render the feature
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
bool dependsOnScale() const
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)
QgsRuleBasedRendererV2::Rule * mRule
void setSymbol(QgsSymbolV2 *sym)
set a new symbol (or NULL). Deletes old symbol.
virtual QList< QString > usedAttributes() override
Returns a set of attributes required for this renderer.
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.
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...
void clearFeatureCounts()
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
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)
int scaleMinDenom() const
Represents a vector layer which manages a vector based data sets.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
int count(const Key &key) const
A generic dialog for building expression strings.
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, const QString &rule="") override
return a list of item text / symbol
QString dump(int indent=0) const
Dump for debug purpose.
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...