33 #include <QMessageBox>
34 #include <QStandardItemModel>
35 #include <QStandardItem>
43 , mMimeFormat(
"application/x-qgsgraduatedsymbolrendererv2model" )
65 if ( !mRenderer )
return;
98 return Qt::ItemIsDropEnabled;
101 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;
103 if ( index.
column() == 2 )
105 flags |= Qt::ItemIsEditable;
113 return Qt::MoveAction;
122 if ( role == Qt::CheckStateRole && index.
column() == 0 )
124 return range.
renderState() ? Qt::Checked : Qt::Unchecked;
126 else if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
133 if ( decimalPlaces < 0 ) decimalPlaces = 0;
136 case 2:
return range.
label();
140 else if ( role == Qt::DecorationRole && index.
column() == 0 && range.
symbol() )
144 else if ( role == Qt::TextAlignmentRole )
146 return ( index.
column() == 0 ) ? Qt::AlignHCenter : Qt::AlignLeft;
148 else if ( role == Qt::EditRole )
153 case 2:
return range.
label();
166 if ( index.
column() == 0 && role == Qt::CheckStateRole )
173 if ( role != Qt::EditRole )
194 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
197 return lst.
value( section );
204 if ( parent.
isValid() || !mRenderer )
219 if (
hasIndex( row, column, parent ) )
235 types << mMimeFormat;
244 QDataStream stream( &encodedData, QIODevice::WriteOnly );
252 stream << index.
row();
254 mimeData->
setData( mMimeFormat, encodedData );
262 if ( action != Qt::MoveAction )
return true;
264 if ( !data->
hasFormat( mMimeFormat ) )
return false;
267 QDataStream stream( &encodedData, QIODevice::ReadOnly );
270 while ( !stream.
atEnd() )
277 int to = parent.
row();
280 if ( to == -1 ) to = mRenderer->
ranges().
size();
281 for (
int i = rows.
size() - 1; i >= 0; i-- )
286 if ( rows[i] < t ) t--;
289 for (
int j = 0; j < i; j++ )
291 if ( to < rows[j] && rows[i] > rows[j] ) rows[j] += 1;
294 if ( rows[i] < to ) to--;
303 for (
int i = rows.
size() - 1; i >= 0; i-- )
329 else if ( column == 2 )
362 if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
365 opt.rect.setLeft( 0 );
367 opt.rect.setHeight( 0 );
368 if ( widget ) opt.rect.setRight( widget->
width() );
405 mExpressionWidget->setLayer(
mLayer );
410 cboGraduatedColorRamp->populate(
mStyle );
417 if ( defaultColorRamp !=
"" )
419 int index = cboGraduatedColorRamp->findText( defaultColorRamp, Qt::MatchCaseSensitive );
421 cboGraduatedColorRamp->setCurrentIndex( index );
429 methodComboBox->blockSignals(
true );
430 methodComboBox->addItem(
"Color" );
433 methodComboBox->addItem(
"Size" );
434 minSizeSpinBox->setValue( 1 );
435 maxSizeSpinBox->setValue( 8 );
439 methodComboBox->addItem(
"Size" );
440 minSizeSpinBox->setValue( .1 );
441 maxSizeSpinBox->setValue( 2 );
443 methodComboBox->blockSignals(
false );
454 connect( btnGraduatedAdd, SIGNAL( clicked() ),
this, SLOT(
addClass() ) );
474 btnAdvanced->setMenu( advMenu );
476 mHistogramWidget->setLayer(
mLayer );
477 mHistogramWidget->setRenderer(
mRenderer );
478 connect( mHistogramWidget, SIGNAL( rangesModified(
bool ) ),
this, SLOT(
refreshRanges(
bool ) ) );
479 connect( mExpressionWidget, SIGNAL( fieldChanged(
QString ) ), mHistogramWidget, SLOT( setSourceFieldExp(
QString ) ) );
551 if ( nclasses && updateCount )
556 mExpressionWidget->setField( attrName );
557 mHistogramWidget->setSourceFieldExp( attrName );
568 viewGraduated->setModel(
mModel );
572 mSizeUnitWidget->blockSignals(
true );
575 mSizeUnitWidget->blockSignals(
false );
579 methodComboBox->blockSignals(
true );
582 methodComboBox->setCurrentIndex( 0 );
589 methodComboBox->setCurrentIndex( 1 );
596 mMethodStackedWidget->setCurrentIndex( methodComboBox->currentIndex() );
597 methodComboBox->blockSignals(
false );
600 txtLegendFormat->setText( labelFormat.
format() );
601 spinPrecision->setValue( labelFormat.
precision() );
604 viewGraduated->resizeColumnToContents( 0 );
605 viewGraduated->resizeColumnToContents( 1 );
606 viewGraduated->resizeColumnToContents( 2 );
608 mHistogramWidget->refresh();
620 mMethodStackedWidget->setCurrentIndex( idx );
628 if ( cboGraduatedColorRamp->count() == 0 )
629 QMessageBox::critical(
this,
tr(
"Error" ),
tr(
"There are no available color ramps. You can add them in Style Manager." ) );
654 QString attrName = mExpressionWidget->currentField();
656 int nclasses = spinGraduatedClasses->value();
661 if ( cboGraduatedColorRamp->count() == 0 )
662 QMessageBox::critical(
this,
tr(
"Error" ),
tr(
"There are no available color ramps. You can add them in Style Manager." ) );
669 if ( cboGraduatedMode->currentIndex() == 0 )
671 else if ( cboGraduatedMode->currentIndex() == 2 )
673 else if ( cboGraduatedMode->currentIndex() == 3 )
675 else if ( cboGraduatedMode->currentIndex() == 4 )
684 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 ) )
693 if ( methodComboBox->currentIndex() == 0 )
699 if ( cboGraduatedColorRamp->count() == 0 )
700 QMessageBox::critical(
this,
tr(
"Error" ),
tr(
"There are no available color ramps. You can add them in Style Manager." ) );
715 if ( methodComboBox->currentIndex() == 1 )
748 if ( m && i.size() > 0 )
766 mSizeUnitWidget->blockSignals(
true );
769 mSizeUnitWidget->blockSignals(
false );
779 btnChangeGraduatedSymbol->setIcon( icon );
783 int QgsRendererV2PropertiesDialog::currentRangeRow()
785 QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
795 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
810 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
811 QModelIndexList::const_iterator sIt = selectedRows.
constBegin();
813 for ( ; sIt != selectedRows.constEnd(); ++sIt )
840 if ( m && selectedIndexes.size() > 0 )
854 int rangeIdx = idx.
row();
876 mHistogramWidget->refresh();
887 if ( decimalPlaces < 0 ) decimalPlaces = 0;
891 if ( dialog.
exec() == QDialog::Accepted )
899 if ( cbxLinkBoundaries->isChecked() )
906 if ( rangeIdx < mRenderer->ranges().
size() - 1 )
912 mHistogramWidget->refresh();
918 mHistogramWidget->refresh();
925 mHistogramWidget->refresh();
931 mHistogramWidget->refresh();
938 for (
int i = 1;i < ranges.
size();++i )
940 if ( ranges[i] < ranges[i-1] )
959 tr(
"Linked range warning" ),
960 tr(
"Rows will be reordered before linking boundaries. Continue?" ),
961 QMessageBox::Ok | QMessageBox::Cancel );
962 if ( result != QMessageBox::Ok )
964 cbxLinkBoundaries->setChecked(
false );
981 if ( item->
column() == 2 )
984 int idx = item->
row();
1007 txtLegendFormat->text(),
1008 spinPrecision->value(),
1009 cbxTrimTrailingZeroes->isChecked() );
1020 QModelIndexList selectedIndexes = m->
selectedRows( 1 );
1021 if ( m && selectedIndexes.size() > 0 )
1024 QModelIndexList::const_iterator indexIt = selectedIndexes.
constBegin();
1025 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1028 if ( list.
size() < 3 )
1033 double lowerBound = list.
at( 0 ).toDouble();
1034 double upperBound = list.
at( 2 ).toDouble();
1038 selectedSymbols.
append( s );
1052 return it->symbol();
1064 mHistogramWidget->refresh();
1074 viewGraduated->selectionModel()->clear();
1077 cbxLinkBoundaries->setChecked(
false );
1092 if ( event->
key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
1097 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 setRotationField(QString fieldOrExpression) override
sets rotation field of renderer (if supported by the renderer)
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.
bool updateRangeLabel(int rangeIndex, QString label)
QString upperValue() const
void append(const T &value)
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)
const T & at(int i) const
void setSizeScaleField(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
void setUpperValue(QString val)
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)
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)
Qt::ItemFlags flags(const QModelIndex &index) const override
double upperValue() const
void setColor(const QColor &color)
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)
QgsSymbolV2::ScaleMethod scaleMethod() const
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)
virtual QgsVectorColorRampV2 * clone() const =0
QgsRendererRangeV2 rendererRange(const QModelIndex &index)
void addClass(QgsSymbolV2 *symbol)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
QModelIndexList selectedRows(int column) const
QgsSymbolV2 * sourceSymbol()
QString rotationField() const override
return rotation field name (or empty string if not set or not supported by renderer) ...
QgsSymbolV2 * symbol() const
GraduatedMethod graduatedMethod() const
return the method used for graduation (either size or color)
void setOverrideCursor(const QCursor &cursor)
bool updateRangeLowerValue(int rangeIndex, double value)
void restoreOverrideCursor()
void setClassAttribute(QString attr)
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
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
virtual long featureCount() const
Number of features in the layer.
void setLowerValue(QString val)
void moveClass(int from, int to)
Moves the category at index position from to index position to.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
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
QString sizeScaleField() const
static QgsProject * instance()
access to canonical QgsProject instance
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)
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)
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)