34 #include <QMessageBox>
35 #include <QStandardItemModel>
36 #include <QStandardItem>
44 , mMimeFormat(
"application/x-qgsgraduatedsymbolrendererv2model" )
66 if ( !mRenderer )
return;
99 return Qt::ItemIsDropEnabled;
102 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;
104 if ( index.
column() == 2 )
106 flags |= Qt::ItemIsEditable;
114 return Qt::MoveAction;
123 if ( role == Qt::CheckStateRole && index.
column() == 0 )
125 return range.
renderState() ? Qt::Checked : Qt::Unchecked;
127 else if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
134 if ( decimalPlaces < 0 ) decimalPlaces = 0;
137 case 2:
return range.
label();
141 else if ( role == Qt::DecorationRole && index.
column() == 0 && range.
symbol() )
145 else if ( role == Qt::TextAlignmentRole )
147 return ( index.
column() == 0 ) ? Qt::AlignHCenter : Qt::AlignLeft;
149 else if ( role == Qt::EditRole )
154 case 2:
return range.
label();
167 if ( index.
column() == 0 && role == Qt::CheckStateRole )
174 if ( role != Qt::EditRole )
195 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
198 return lst.
value( section );
205 if ( parent.
isValid() || !mRenderer )
220 if (
hasIndex( row, column, parent ) )
236 types << mMimeFormat;
245 QDataStream stream( &encodedData, QIODevice::WriteOnly );
253 stream << index.
row();
255 mimeData->
setData( mMimeFormat, encodedData );
263 if ( action != Qt::MoveAction )
return true;
265 if ( !data->
hasFormat( mMimeFormat ) )
return false;
268 QDataStream stream( &encodedData, QIODevice::ReadOnly );
271 while ( !stream.
atEnd() )
278 int to = parent.
row();
281 if ( to == -1 ) to = mRenderer->
ranges().
size();
282 for (
int i = rows.
size() - 1; i >= 0; i-- )
287 if ( rows[i] < t ) t--;
290 for (
int j = 0; j < i; j++ )
292 if ( to < rows[j] && rows[i] > rows[j] ) rows[j] += 1;
295 if ( rows[i] < to ) to--;
304 for (
int i = rows.
size() - 1; i >= 0; i-- )
330 else if ( column == 2 )
363 if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
366 opt.rect.setLeft( 0 );
368 opt.rect.setHeight( 0 );
369 if ( widget ) opt.rect.setRight( widget->
width() );
431 mExpressionWidget->setLayer(
mLayer );
435 cboGraduatedColorRamp->populate(
mStyle );
442 if ( defaultColorRamp !=
"" )
444 int index = cboGraduatedColorRamp->findText( defaultColorRamp, Qt::MatchCaseSensitive );
446 cboGraduatedColorRamp->setCurrentIndex( index );
454 methodComboBox->blockSignals(
true );
455 methodComboBox->addItem(
"Color" );
458 methodComboBox->addItem(
"Size" );
459 minSizeSpinBox->setValue( 1 );
460 maxSizeSpinBox->setValue( 8 );
464 methodComboBox->addItem(
"Size" );
465 minSizeSpinBox->setValue( .1 );
466 maxSizeSpinBox->setValue( 2 );
468 methodComboBox->blockSignals(
false );
479 connect( btnGraduatedAdd, SIGNAL( clicked() ),
this, SLOT(
addClass() ) );
494 btnAdvanced->setMenu( advMenu );
496 mHistogramWidget->setLayer(
mLayer );
497 mHistogramWidget->setRenderer(
mRenderer );
498 connect( mHistogramWidget, SIGNAL( rangesModified(
bool ) ),
this, SLOT(
refreshRanges(
bool ) ) );
499 connect( mExpressionWidget, SIGNAL( fieldChanged(
QString ) ), mHistogramWidget, SLOT( setSourceFieldExp(
QString ) ) );
534 connect( mButtonEditRamp, SIGNAL( clicked() ), cboGraduatedColorRamp, SLOT( editSourceRamp() ) );
554 disconnect( mButtonEditRamp, SIGNAL( clicked() ), cboGraduatedColorRamp, SLOT( editSourceRamp() ) );
578 if ( nclasses && updateCount )
583 mExpressionWidget->setField( attrName );
584 mHistogramWidget->setSourceFieldExp( attrName );
595 viewGraduated->setModel(
mModel );
599 mSizeUnitWidget->blockSignals(
true );
602 mSizeUnitWidget->blockSignals(
false );
606 methodComboBox->blockSignals(
true );
609 methodComboBox->setCurrentIndex( 0 );
616 methodComboBox->setCurrentIndex( 1 );
623 mMethodStackedWidget->setCurrentIndex( methodComboBox->currentIndex() );
624 methodComboBox->blockSignals(
false );
627 txtLegendFormat->setText( labelFormat.
format() );
628 spinPrecision->setValue( labelFormat.
precision() );
631 viewGraduated->resizeColumnToContents( 0 );
632 viewGraduated->resizeColumnToContents( 1 );
633 viewGraduated->resizeColumnToContents( 2 );
635 mHistogramWidget->refresh();
647 mMethodStackedWidget->setCurrentIndex( idx );
655 if ( cboGraduatedColorRamp->count() == 0 )
656 QMessageBox::critical(
this,
tr(
"Error" ),
tr(
"There are no available color ramps. You can add them in Style Manager." ) );
681 QString attrName = mExpressionWidget->currentField();
683 int nclasses = spinGraduatedClasses->value();
688 if ( cboGraduatedColorRamp->count() == 0 )
689 QMessageBox::critical(
this,
tr(
"Error" ),
tr(
"There are no available color ramps. You can add them in Style Manager." ) );
696 if ( cboGraduatedMode->currentIndex() == 0 )
698 else if ( cboGraduatedMode->currentIndex() == 2 )
700 else if ( cboGraduatedMode->currentIndex() == 3 )
702 else if ( cboGraduatedMode->currentIndex() == 4 )
711 if ( QMessageBox::Cancel ==
QMessageBox::question(
this,
tr(
"Warning" ),
tr(
"Natural break classification (Jenks) is O(n2) complexity, your classification may take a long time.\nPress cancel to abort breaks calculation or OK to continue." ), QMessageBox::Cancel, QMessageBox::Ok ) )
720 if ( methodComboBox->currentIndex() == 0 )
726 if ( cboGraduatedColorRamp->count() == 0 )
727 QMessageBox::critical(
this,
tr(
"Error" ),
tr(
"There are no available color ramps. You can add them in Style Manager." ) );
742 if ( methodComboBox->currentIndex() == 1 )
775 if ( m && i.size() > 0 )
795 mSizeUnitWidget->blockSignals(
true );
798 mSizeUnitWidget->blockSignals(
false );
811 btnChangeGraduatedSymbol->setIcon( icon );
815 int QgsRendererV2PropertiesDialog::currentRangeRow()
817 QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
827 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
842 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
843 QModelIndexList::const_iterator sIt = selectedRows.
constBegin();
845 for ( ; sIt != selectedRows.constEnd(); ++sIt )
872 if ( m && selectedIndexes.size() > 0 )
883 Q_FOREACH (
const QModelIndex& idx, selectedIndexes )
887 int rangeIdx = idx.
row();
910 mHistogramWidget->refresh();
921 if ( decimalPlaces < 0 ) decimalPlaces = 0;
925 if ( dialog.
exec() == QDialog::Accepted )
933 if ( cbxLinkBoundaries->isChecked() )
940 if ( rangeIdx < mRenderer->ranges().
size() - 1 )
946 mHistogramWidget->refresh();
952 mHistogramWidget->refresh();
959 mHistogramWidget->refresh();
965 mHistogramWidget->refresh();
972 for (
int i = 1;i < ranges.
size();++i )
974 if ( ranges[i] < ranges[i-1] )
993 tr(
"Linked range warning" ),
994 tr(
"Rows will be reordered before linking boundaries. Continue?" ),
995 QMessageBox::Ok | QMessageBox::Cancel );
996 if ( result != QMessageBox::Ok )
998 cbxLinkBoundaries->setChecked(
false );
1015 if ( item->
column() == 2 )
1018 int idx = item->
row();
1036 txtLegendFormat->text(),
1037 spinPrecision->value(),
1038 cbxTrimTrailingZeroes->isChecked() );
1049 QModelIndexList selectedIndexes = m->
selectedRows( 1 );
1050 if ( m && selectedIndexes.size() > 0 )
1053 QModelIndexList::const_iterator indexIt = selectedIndexes.
constBegin();
1054 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1057 if ( list.
size() < 3 )
1062 double lowerBound = list.
at( 0 ).toDouble();
1063 double upperBound = list.
at( 2 ).toDouble();
1067 selectedSymbols.
append( s );
1081 return it->symbol();
1093 mHistogramWidget->refresh();
1103 viewGraduated->selectionModel()->clear();
1106 cbxLinkBoundaries->setChecked(
false );
1121 if ( event->
key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
1126 else if ( event->
key() == Qt::Key_V &&
event->modifiers() == Qt::ControlModifier )
bool hasIndex(int row, int column, const QModelIndex &parent) const
QList< QgsRendererRangeV2 > QgsRangeList
void setSymbolSizes(double minSize, double maxSize)
set varying symbol size for classes
QByteArray data(const QString &mimeType) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
void setLabelFormat(const QgsRendererRangeV2LabelFormat &labelFormat, bool updateRanges=false)
Set the label format used to generate default classification labels.
static QgsGraduatedSymbolRendererV2 * convertFromRenderer(const QgsFeatureRendererV2 *renderer)
creates a QgsGraduatedSymbolRendererV2 from an existing renderer.
void updateClasses(QgsVectorLayer *vlayer, Mode mode, int nclasses)
Recalculate classes for a layer.
QString upperValue() const
void append(const T &value)
static QgsExpressionContextScope * atlasScope(const QgsAtlasComposition *atlas)
Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
void updateSymbols(QgsSymbolV2 *sym)
Update all the symbols but leave breaks and colors.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString classAttribute() const
virtual QgsSymbolV2 * clone() const =0
bool updateRangeRenderState(int rangeIndex, bool render)
The output shall be in pixels.
const T & at(int i) const
void setSizeScaleField(const QString &fieldOrExpression)
QgsMapUnitScale mapUnitScale() const
QgsGraduatedSymbolRendererV2ViewStyle(QStyle *style=0)
void deleteRows(QList< int > rows)
double minSymbolSize() const
return the min symbol size when graduated by size
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
void calculateLabelPrecision(bool updateRanges=true)
Reset the label decimal places to a numberbased on the minimum class interval.
virtual void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
void setLowerValue(const QString &val)
double toDouble(bool *ok) const
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
QgsVectorColorRampV2 * sourceColorRamp()
void setRenderer(QgsGraduatedSymbolRendererV2 *renderer)
void setMapUnitScale(const QgsMapUnitScale &scale)
The QgsMapSettings class contains configuration for rendering of the map.
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
Qt::ItemFlags flags(const QModelIndex &index) const override
double upperValue() const
void setColor(const QColor &color)
The output shall be in millimeters.
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
QString number(int n, int base)
QVariant data(const QModelIndex &index, int role) const override
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
int count(const T &value) const
void setGraduatedMethod(GraduatedMethod method)
set the method used for graduation (either size or color)
void append(const T &value)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
int columnCount(const QModelIndex &=QModelIndex()) const override
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
StandardButton question(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
QgsRendererRangeV2 rendererRange(const QModelIndex &index)
void addClass(QgsSymbolV2 *symbol)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void beginRemoveRows(const QModelIndex &parent, int first, int last)
QModelIndexList selectedRows(int column) const
QgsSymbolV2 * sourceSymbol()
QgsSymbolV2 * symbol() const
GraduatedMethod graduatedMethod() const
return the method used for graduation (either size or color)
The output shall be in map unitx.
void setOverrideCursor(const QCursor &cursor)
bool updateRangeLowerValue(int rangeIndex, double value)
void restoreOverrideCursor()
QMimeData * mimeData(const QModelIndexList &indexes) const override
QGis::GeometryType geometryType() const
Returns point, line or polygon.
virtual QVariant data(const QModelIndex &index, int role) const =0
Qt::DropActions supportedDropActions() const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Single scope for storing variables and functions for use within a QgsExpressionContext.
QModelIndex createIndex(int row, int column, void *ptr) const
bool setData(const QModelIndex &index, const QVariant &value, int role) override
const QgsRendererRangeV2LabelFormat & labelFormat() const
Return the label format used to generate default classification labels.
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
void beginInsertRows(const QModelIndex &parent, int first, int last)
QStringList mimeTypes() const override
void moveClass(int from, int to)
Moves the category at index position from to index position to.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=0) const override
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
double lowerValue() const
double maxSymbolSize() const
return the max symbol size when graduated by size
const QgsRangeList & ranges() const
void setClassAttribute(const QString &attr)
static QgsProject * instance()
access to canonical QgsProject instance
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the dialog.
void setUpperValue(const QString &val)
bool updateRangeSymbol(int rangeIndex, QgsSymbolV2 *symbol)
QgsSymbolV2::OutputUnit outputUnit() const
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void setSourceColorRamp(QgsVectorColorRampV2 *ramp)
Sets the source color ramp.
bool updateRangeUpperValue(int rangeIndex, double value)
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
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...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
const_iterator constEnd() const
const_iterator constBegin() const
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.
void deleteClass(int idx)
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
const QAbstractItemModel * model() const
void setOutputUnit(QgsSymbolV2::OutputUnit u)
QString lowerValue() const
void updateColorRamp(QgsVectorColorRampV2 *ramp=0, bool inverted=false)
Update the color ramp used.
QgsGraduatedSymbolRendererV2Model(QObject *parent=0)
void addClass(QgsSymbolV2 *symbol)
void updateSymbology(bool resetModel=false)
bool updateRangeLabel(int rangeIndex, const QString &label)