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 );
262 connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
263 connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
292 connect( bb, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
293 connect( bb, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
317 if ( initialRule->
symbol() == NULL )
319 QMessageBox::warning(
this,
tr(
"Scale refinement" ),
tr(
"Parent rule %1 must have a symbol for this operation." ).arg( initialRule->
label() ) );
325 tr(
"Scale refinement" ),
326 tr(
"Please enter scale denominators at which will split the rule, separate them by commas (e.g. 1000,5000):" ) );
334 int scale = item.
toInt( &ok );
365 for (
int row = range.
top(); row <= range.
bottom(); row++ )
367 symbolList.
append( children[row]->symbol() );
383 for (
int row = range.
top(); row <= range.
bottom(); row++ )
385 rl.
append( children[row]->clone() );
409 if ( event->
key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
415 else if ( event->
key() == Qt::Key_V &&
event->modifiers() == Qt::ControlModifier )
452 QString path =
"/Windows/RuleBasedTree/sectionWidth/";
464 QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
467 if ( indexlist.isEmpty() )
477 QModelIndexList indexlist = viewRules->selectionModel()->selectedRows();
479 if ( indexlist.isEmpty() )
482 index = indexlist.first();
499 countMap[rule].
count = 0;
500 countMap[rule].duplicateCount = 0;
512 int featuresCounted = 0;
521 countMap[rule].
count++;
522 if ( featureRuleList.
size() > 1 )
524 countMap[rule].duplicateCount++;
528 if ( duplicateRule == rule )
continue;
529 countMap[rule].duplicateCountMap[duplicateRule] += 1;
533 if ( featuresCounted % 50 == 0 )
535 if ( featuresCounted > nFeatures )
563 :
QDialog( parent ), mRule( rule ), mLayer( layer ), mSymbolSelector( NULL ), mSymbol( NULL )
581 groupScale->setChecked(
true );
584 mScaleRangeWidget->setMaximumScale( 1.0 / rule->
scaleMinDenom() );
586 mScaleRangeWidget->setMinimumScale( 1.0 / rule->
scaleMaxDenom() );
591 groupSymbol->setChecked(
true );
596 groupSymbol->setChecked(
false );
603 groupSymbol->setLayout( l );
624 editFilter->setText( dlg.expressionText() );
630 if ( filter.hasParserError() )
638 if ( !filter.prepare( fields ) )
652 QVariant value = filter.evaluate( &f );
653 if ( value.
toInt() != 0 )
655 if ( filter.hasEvalError() )
707 return Qt::ItemIsDropEnabled;
710 Qt::ItemFlag drop = ( index.
column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
712 Qt::ItemFlag checkable = ( index.
column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
714 return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
715 Qt::ItemIsEditable | checkable |
716 Qt::ItemIsDragEnabled | drop;
726 if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
730 case 0:
return rule->
label();
751 if ( role == Qt::DisplayRole )
759 QString tip =
"<p style='margin:0px;'><ul>";
763 tip +=
tr(
"<li><nobr>%1 features also in rule %2</nobr></li>" ).
arg(
mFeatureCountMap[rule].duplicateCountMap[duplicateRule] ).
arg( label );
778 else if ( role == Qt::DecorationRole && index.
column() == 0 && rule->
symbol() )
782 else if ( role == Qt::TextAlignmentRole )
784 return ( index.
column() == 2 || index.
column() == 3 ) ? Qt::AlignRight : Qt::AlignLeft;
786 else if ( role == Qt::FontRole && index.
column() == 1 )
796 else if ( role == Qt::EditRole )
800 case 0:
return rule->
label();
807 else if ( role == Qt::CheckStateRole )
809 if ( index.
column() != 0 )
811 return rule->
checkState() ? Qt::Checked : Qt::Unchecked;
819 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 7 )
821 QStringList lst; lst <<
tr(
"Label" ) <<
tr(
"Rule" ) <<
tr(
"Min. scale" ) <<
tr(
"Max. scale" ) <<
tr(
"Count" ) <<
tr(
"Duplicate count" );
824 else if ( orientation == Qt::Horizontal && role == Qt::ToolTipRole )
828 return tr(
"Number of features in this rule." );
830 else if ( section == 5 )
832 return tr(
"Number of features in this rule which are also present in other rule(s)." );
841 if ( parent.
column() > 0 )
856 if (
hasIndex( row, column, parent ) )
889 if ( role == Qt::CheckStateRole )
896 if ( role != Qt::EditRole )
923 return Qt::MoveAction;
929 types <<
"application/vnd.text.list";
938 QDataStream stream( &encodedData, QIODevice::WriteOnly );
964 mimeData->
setData(
"application/vnd.text.list", encodedData );
969 Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
973 if ( action == Qt::IgnoreAction )
976 if ( !data->
hasFormat(
"application/vnd.text.list" ) )
979 if ( parent.
column() > 0 )
982 QByteArray encodedData = data->
data(
"application/vnd.text.list" );
983 QDataStream stream( &encodedData, QIODevice::ReadOnly );
992 while ( !stream.
atEnd() )
1001 if ( rootElem.
tagName() !=
"rule_mime" )
1004 if ( symbolsElem.
isNull() )
1020 return static_cast<QgsRuleBasedRendererV2::Rule*>( index.
internalPointer() );
1031 QgsDebugMsg(
QString(
"Called: row %1 count %2 parent ~~%3~~" ).arg( row ).arg( count ).arg( parentRule->
dump() ) );
1035 for (
int i = 0; i < count; i++ )
1037 if ( row < parentRule->
children().count() )
1045 QgsDebugMsg(
"trying to remove invalid index - this should not happen!" );
1078 for (
int i = 0; i <
rowCount( idx ); i++ )
1093 rule->parent()->removeChild( rule );
bool hasIndex(int row, int column, const QModelIndex &parent) const
Class for parsing and evaluation of expressions (formerly called "search strings").
QgsRuleBasedRendererV2 * mR
QString description() const
Wrapper for iterator of features from vector data provider or vector layer.
static QgsSymbolV2Map loadSymbols(QDomElement &element)
QByteArray toByteArray() const
void setFeatureCounts(QMap< QgsRuleBasedRendererV2::Rule *, QgsRuleBasedRendererV2Count > theCountMap)
QByteArray data(const QString &mimeType) const
QgsSymbolV2SelectorDialog * mSymbolSelector
const QgsCategoryList & categories() const
~QgsRendererRulePropsDialog()
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 QString iconPath(QString iconFile)
Returns path to the desired icon file.
QString toString(int indent) const
void setScaleMaxDenom(int scaleMaxDenom)
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)
const QObjectList & children() const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void setLabel(QString label)
QgsRuleBasedRendererV2Model(QgsRuleBasedRendererV2 *r)
Qt::DropActions supportedDropActions() const override
Rule * clone() const
clone this rule, return new instance
RuleList rulesForFeature(QgsFeature &feat)
tell which rules will be used to render the feature
Container of fields for a vector layer.
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...
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="") override
return a list of item text / symbol
QString tr(const char *sourceText, const char *disambiguation, int n)
void removeChildAt(int i)
delete child rule
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const override
int indexOf(const T &value, int from) const
void setCheckState(bool state)
QList< Key > keys() const
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 ...
int scaleMinDenom() const
int toInt(bool *ok) const
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
virtual void stopRender(QgsRenderContext &context) override
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int toInt(bool *ok, int base) const
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, QString tagName, QDomDocument &doc)
static Rule * create(QDomElement &ruleElem, QgsSymbolV2Map &symbolMap)
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)
int pendingFeatureCount()
returns feature count after commit
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.
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 dump(int offset=0) const
QgsRendererRulePropsDialog(QgsRuleBasedRendererV2::Rule *rule, QgsVectorLayer *layer, QgsStyleV2 *style, QWidget *parent=0)
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
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)
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
void insertRule(const QModelIndex &parent, int before, QgsRuleBasedRendererV2::Rule *newrule)
void finishedAddingRules()
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
const QgsRangeList & ranges() const
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
virtual void startRender(QgsRenderContext &context, const QgsFields &fields) override
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
QgsRuleBasedRendererV2::Rule * mRule
void setDescription(QString description)
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)
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
void clearFeatureCounts()
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
const_iterator constEnd() const
void insertChild(int i, Rule *rule)
add child rule, take ownership, sets this as parent
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)
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
void setFilterExpression(QString filterExp)
int count(const Key &key) const
A generic dialog for building expression strings.
void willAddRules(const QModelIndex &parent, int count)
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...