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 );
99 connect( btnAddRule, SIGNAL( clicked() ),
this, SLOT(
addRule() ) );
110 connect( viewRules->header(), SIGNAL( sectionResized(
int,
int,
int ) ),
this, SLOT(
saveSectionWidth(
int,
int,
int ) ) );
139 QModelIndex currentIndex = viewRules->selectionModel()->currentIndex();
167 editRule( viewRules->selectionModel()->currentIndex() );
196 viewRules->selectionModel()->clear();
202 Q_UNUSED( previous );
203 btnRefineRule->setEnabled( current.
isValid() );
212 #include <QDialogButtonBox>
213 #include <QInputDialog>
214 #include <QClipboard>
218 QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
220 if ( indexlist.isEmpty() )
226 else if ( type == 1 )
235 viewRules->expand( index );
263 connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
264 connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
294 connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
295 connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
319 if ( initialRule->
symbol() == NULL )
321 QMessageBox::warning(
this,
tr(
"Scale refinement" ),
tr(
"Parent rule %1 must have a symbol for this operation." ).arg( initialRule->
label() ) );
327 tr(
"Scale refinement" ),
328 tr(
"Please enter scale denominators at which will split the rule, separate them by commas (e.g. 1000,5000):" ) );
336 int scale = item.
toInt( &ok );
367 for (
int row = range.
top(); row <= range.
bottom(); row++ )
369 symbolList.
append( children[row]->symbol() );
385 for (
int row = range.
top(); row <= range.
bottom(); row++ )
387 rl.
append( children[row]->clone() );
411 if ( event->
key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
417 else if ( event->
key() == Qt::Key_V &&
event->modifiers() == Qt::ControlModifier )
454 QString path =
"/Windows/RuleBasedTree/sectionWidth/";
466 QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
469 if ( indexlist.isEmpty() )
479 QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
481 if ( indexlist.isEmpty() )
484 index = indexlist.first();
501 countMap[rule].
count = 0;
502 countMap[rule].duplicateCount = 0;
532 int featuresCounted = 0;
542 countMap[rule].
count++;
543 if ( featureRuleList.
size() > 1 )
545 countMap[rule].duplicateCount++;
549 if ( duplicateRule == rule )
continue;
550 countMap[rule].duplicateCountMap[duplicateRule] += 1;
554 if ( featuresCounted % 50 == 0 )
556 if ( featuresCounted > nFeatures )
584 :
QDialog( parent ), mRule( rule ), mLayer( layer ), mSymbolSelector( NULL ), mSymbol( NULL ), mMapCanvas( mapCanvas )
602 groupScale->setChecked(
true );
605 mScaleRangeWidget->setMaximumScale( 1.0 / rule->
scaleMinDenom() );
607 mScaleRangeWidget->setMinimumScale( 1.0 / rule->
scaleMaxDenom() );
609 mScaleRangeWidget->setMapCanvas(
mMapCanvas );
613 groupSymbol->setChecked(
true );
618 groupSymbol->setChecked(
false );
626 groupSymbol->setLayout( l );
662 editFilter->setText( dlg.expressionText() );
668 if ( filter.hasParserError() )
689 if ( !filter.prepare( &context ) )
705 QVariant value = filter.evaluate( &context );
706 if ( value.
toInt() != 0 )
708 if ( filter.hasEvalError() )
760 return Qt::ItemIsDropEnabled;
763 Qt::ItemFlag drop = ( index.
column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
765 Qt::ItemFlag checkable = ( index.
column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
767 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
768 Qt::ItemIsEditable | checkable |
769 Qt::ItemIsDragEnabled | drop;
779 if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
783 case 0:
return rule->
label();
804 if ( role == Qt::DisplayRole )
812 QString tip =
"<p style='margin:0px;'><ul>";
816 tip +=
tr(
"<li><nobr>%1 features also in rule %2</nobr></li>" ).
arg(
mFeatureCountMap[rule].duplicateCountMap[duplicateRule] ).
arg( label );
831 else if ( role == Qt::DecorationRole && index.
column() == 0 && rule->
symbol() )
835 else if ( role == Qt::TextAlignmentRole )
837 return ( index.
column() == 2 || index.
column() == 3 ) ? Qt::AlignRight : Qt::AlignLeft;
839 else if ( role == Qt::FontRole && index.
column() == 1 )
849 else if ( role == Qt::EditRole )
853 case 0:
return rule->
label();
860 else if ( role == Qt::CheckStateRole )
862 if ( index.
column() != 0 )
864 return rule->
checkState() ? Qt::Checked : Qt::Unchecked;
872 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 7 )
874 QStringList lst; lst <<
tr(
"Label" ) <<
tr(
"Rule" ) <<
tr(
"Min. scale" ) <<
tr(
"Max. scale" ) <<
tr(
"Count" ) <<
tr(
"Duplicate count" );
877 else if ( orientation == Qt::Horizontal && role == Qt::ToolTipRole )
881 return tr(
"Number of features in this rule." );
883 else if ( section == 5 )
885 return tr(
"Number of features in this rule which are also present in other rule(s)." );
894 if ( parent.
column() > 0 )
909 if (
hasIndex( row, column, parent ) )
942 if ( role == Qt::CheckStateRole )
949 if ( role != Qt::EditRole )
976 return Qt::MoveAction;
982 types <<
"application/vnd.text.list";
991 QDataStream stream( &encodedData, QIODevice::WriteOnly );
1018 mimeData->
setData(
"application/vnd.text.list", encodedData );
1032 while ( !childRuleElem.
isNull() )
1041 Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
1045 if ( action == Qt::IgnoreAction )
1048 if ( !data->
hasFormat(
"application/vnd.text.list" ) )
1051 if ( parent.
column() > 0 )
1054 QByteArray encodedData = data->
data(
"application/vnd.text.list" );
1055 QDataStream stream( &encodedData, QIODevice::ReadOnly );
1064 while ( !stream.
atEnd() )
1073 if ( rootElem.
tagName() !=
"rule_mime" )
1075 if ( rootElem.
attribute(
"type" ) ==
"labeling" )
1078 if ( symbolsElem.
isNull() )
1082 if ( rootElem.
attribute(
"type" ) ==
"labeling" )
1096 return static_cast<QgsRuleBasedRendererV2::Rule*>( index.
internalPointer() );
1107 QgsDebugMsg(
QString(
"Called: row %1 count %2 parent ~~%3~~" ).arg( row ).arg( count ).arg( parentRule->
dump() ) );
1111 for (
int i = 0; i < count; i++ )
1113 if ( row < parentRule->
children().count() )
1121 QgsDebugMsg(
"trying to remove invalid index - this should not happen!" );
1154 for (
int i = 0; i <
rowCount( idx ); i++ )
1169 rule->parent()->removeChild( rule );
bool hasIndex(int row, int column, const QModelIndex &parent) const
QString dump(int indent=0) const
Dump for debug purpose.
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.
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)
RuleList rulesForFeature(QgsFeature &feat, QgsRenderContext *context=0)
tell which rules will be used to render the feature
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
void setCheckState(bool state)
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)
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
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)
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 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
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
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)
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.
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)
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...