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;
534 int featuresCounted = 0;
544 countMap[rule].
count++;
545 if ( featureRuleList.
size() > 1 )
547 countMap[rule].duplicateCount++;
551 if ( duplicateRule == rule )
continue;
552 countMap[rule].duplicateCountMap[duplicateRule] += 1;
556 if ( featuresCounted % 50 == 0 )
558 if ( featuresCounted > nFeatures )
585 bool enabled = !viewRules->selectionModel()->selectedIndexes().isEmpty();
586 btnRefineRule->setEnabled( enabled );
587 btnRemoveRule->setEnabled( enabled );
593 :
QDialog( parent ), mRule( rule ),
mLayer( layer ), mSymbolSelector( nullptr ), mSymbol( nullptr ),
mMapCanvas( mapCanvas )
611 groupScale->setChecked(
true );
614 mScaleRangeWidget->setMaximumScale( 1.0 / rule->
scaleMinDenom() );
616 mScaleRangeWidget->setMinimumScale( 1.0 / rule->
scaleMaxDenom() );
618 mScaleRangeWidget->setMapCanvas(
mMapCanvas );
622 groupSymbol->setChecked(
true );
627 groupSymbol->setChecked(
false );
635 groupSymbol->setLayout( l );
671 editFilter->setText( dlg.expressionText() );
677 if ( filter.hasParserError() )
698 if ( !filter.prepare( &context ) )
714 QVariant value = filter.evaluate( &context );
715 if ( value.
toInt() != 0 )
717 if ( filter.hasEvalError() )
769 return Qt::ItemIsDropEnabled;
772 Qt::ItemFlag drop = ( index.
column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
774 Qt::ItemFlag checkable = ( index.
column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
776 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
777 Qt::ItemIsEditable | checkable |
778 Qt::ItemIsDragEnabled | drop;
788 if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
793 return rule->
label();
816 if ( role == Qt::DisplayRole )
824 QString tip =
"<p style='margin:0px;'><ul>";
828 tip +=
tr(
"<li><nobr>%1 features also in rule %2</nobr></li>" ).
arg(
mFeatureCountMap[rule].duplicateCountMap[duplicateRule] ).
arg( label );
844 else if ( role == Qt::DecorationRole && index.
column() == 0 && rule->
symbol() )
848 else if ( role == Qt::TextAlignmentRole )
850 return ( index.
column() == 2 || index.
column() == 3 ) ? Qt::AlignRight : Qt::AlignLeft;
852 else if ( role == Qt::FontRole && index.
column() == 1 )
862 else if ( role == Qt::EditRole )
867 return rule->
label();
878 else if ( role == Qt::CheckStateRole )
880 if ( index.
column() != 0 )
882 return rule->
active() ? Qt::Checked : Qt::Unchecked;
890 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 7 )
893 lst <<
tr(
"Label" ) <<
tr(
"Rule" ) <<
tr(
"Min. scale" ) <<
tr(
"Max. scale" ) <<
tr(
"Count" ) <<
tr(
"Duplicate count" );
896 else if ( orientation == Qt::Horizontal && role == Qt::ToolTipRole )
900 return tr(
"Number of features in this rule." );
902 else if ( section == 5 )
904 return tr(
"Number of features in this rule which are also present in other rule(s)." );
913 if ( parent.
column() > 0 )
928 if (
hasIndex( row, column, parent ) )
961 if ( role == Qt::CheckStateRole )
968 if ( role != Qt::EditRole )
995 return Qt::MoveAction;
1001 types <<
"application/vnd.text.list";
1010 QDataStream stream( &encodedData, QIODevice::WriteOnly );
1037 mimeData->
setData(
"application/vnd.text.list", encodedData );
1051 while ( !childRuleElem.
isNull() )
1064 if ( action == Qt::IgnoreAction )
1067 if ( !data->
hasFormat(
"application/vnd.text.list" ) )
1070 if ( parent.
column() > 0 )
1073 QByteArray encodedData = data->
data(
"application/vnd.text.list" );
1074 QDataStream stream( &encodedData, QIODevice::ReadOnly );
1083 while ( !stream.
atEnd() )
1092 if ( rootElem.
tagName() !=
"rule_mime" )
1094 if ( rootElem.
attribute(
"type" ) ==
"labeling" )
1097 if ( symbolsElem.
isNull() )
1101 if ( rootElem.
attribute(
"type" ) ==
"labeling" )
1115 return static_cast<QgsRuleBasedRendererV2::Rule*>( index.
internalPointer() );
1126 QgsDebugMsg(
QString(
"Called: row %1 count %2 parent ~~%3~~" ).arg( row ).arg( count ).arg( parentRule->
dump() ) );
1130 for (
int i = 0; i < count; i++ )
1132 if ( row < parentRule->
children().count() )
1140 QgsDebugMsg(
"trying to remove invalid index - this should not happen!" );
1173 for (
int i = 0; i <
rowCount( idx ); i++ )
1188 rule->parent()->removeChild( rule );
bool hasIndex(int row, int column, const QModelIndex &parent) const
QString dump(int indent=0) const
Dump for debug purpose.
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)
QString description() const
A human readable description for this rule.
Wrapper for iterator of features from vector data provider or vector layer.
static QgsSymbolV2Map loadSymbols(QDomElement &element)
QByteArray toByteArray() const
QByteArray data(const QString &mimeType) const
QgsSymbolV2SelectorDialog * mSymbolSelector
const QgsCategoryList & categories() const
~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.
QgsFields fields() const
Returns the list of fields of this layer.
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
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QgsRuleBasedRendererV2Model(QgsRuleBasedRendererV2 *r)
QDomElement nextSiblingElement(const QString &tagName) const
Qt::DropActions supportedDropActions() const override
Rule * clone() const
clone this rule, return new instance
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
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
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)
void setValue(int progress)
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 scaleMinDenom() const
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
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)
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 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)
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
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 dependsOnScale() const
QString & replace(int position, int n, QChar after)
void setForceOrderingEnabled(bool enabled)
QVariant value(const QString &key, const QVariant &defaultValue) const
int scaleMaxDenom() 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.
void finishedAddingRules()
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
const QgsRangeList & ranges() const
Rule * parent()
The parent rule.
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
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
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.
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)
Represents a vector layer which manages a vector based data sets.
bool active() const
Returns if this rule is active.
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
void willAddRules(const QModelIndex &parent, int count)
QDomElement save(QDomDocument &doc, QgsSymbolV2Map &symbolMap) const
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...