18 #include <QMessageBox> 19 #include <QStandardItemModel> 20 #include <QStandardItem> 62 QgsGraduatedSymbolRendererModel::QgsGraduatedSymbolRendererModel( QObject *parent ) : QAbstractItemModel( parent )
63 , mMimeFormat( QStringLiteral(
"application/x-qgsgraduatedsymbolrendererv2model" ) )
71 if ( !mRenderer->
ranges().isEmpty() )
73 beginRemoveRows( QModelIndex(), 0, mRenderer->
ranges().size() - 1 );
84 if ( !renderer->
ranges().isEmpty() )
86 beginInsertRows( QModelIndex(), 0, renderer->
ranges().size() - 1 );
97 void QgsGraduatedSymbolRendererModel::addClass(
QgsSymbol *symbol )
99 if ( !mRenderer )
return;
100 int idx = mRenderer->
ranges().size();
101 beginInsertRows( QModelIndex(), idx, idx );
106 void QgsGraduatedSymbolRendererModel::addClass(
const QgsRendererRange &range )
112 int idx = mRenderer->
ranges().size();
113 beginInsertRows( QModelIndex(), idx, idx );
118 QgsRendererRange QgsGraduatedSymbolRendererModel::rendererRange(
const QModelIndex &index )
120 if ( !index.isValid() || !mRenderer || mRenderer->
ranges().size() <= index.row() )
125 return mRenderer->
ranges().value( index.row() );
128 Qt::ItemFlags QgsGraduatedSymbolRendererModel::flags(
const QModelIndex &index )
const 130 if ( !index.isValid() )
132 return Qt::ItemIsDropEnabled;
135 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;
137 if ( index.column() == 2 )
139 flags |= Qt::ItemIsEditable;
145 Qt::DropActions QgsGraduatedSymbolRendererModel::supportedDropActions()
const 147 return Qt::MoveAction;
150 QVariant QgsGraduatedSymbolRendererModel::data(
const QModelIndex &index,
int role )
const 152 if ( !index.isValid() || !mRenderer )
return QVariant();
156 if ( role == Qt::CheckStateRole && index.column() == 0 )
158 return range.
renderState() ? Qt::Checked : Qt::Unchecked;
160 else if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
162 switch ( index.column() )
167 if ( decimalPlaces < 0 ) decimalPlaces = 0;
168 return QLocale().toString( range.
lowerValue(),
'f', decimalPlaces ) +
" - " + QLocale().toString( range.
upperValue(),
'f', decimalPlaces );
171 return range.
label();
176 else if ( role == Qt::DecorationRole && index.column() == 0 && range.
symbol() )
181 else if ( role == Qt::TextAlignmentRole )
183 return ( index.column() == 0 ) ? Qt::AlignHCenter : Qt::AlignLeft;
185 else if ( role == Qt::EditRole )
187 switch ( index.column() )
191 return range.
label();
200 bool QgsGraduatedSymbolRendererModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
202 if ( !index.isValid() )
205 if ( index.column() == 0 && role == Qt::CheckStateRole )
208 emit dataChanged( index, index );
212 if ( role != Qt::EditRole )
215 switch ( index.column() )
226 emit dataChanged( index, index );
230 QVariant QgsGraduatedSymbolRendererModel::headerData(
int section, Qt::Orientation orientation,
int role )
const 232 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
235 lst << tr(
"Symbol" ) << tr(
"Values" ) << tr(
"Legend" );
236 return lst.value( section );
241 int QgsGraduatedSymbolRendererModel::rowCount(
const QModelIndex &parent )
const 243 if ( parent.isValid() || !mRenderer )
247 return mRenderer->
ranges().size();
250 int QgsGraduatedSymbolRendererModel::columnCount(
const QModelIndex &index )
const 256 QModelIndex QgsGraduatedSymbolRendererModel::index(
int row,
int column,
const QModelIndex &parent )
const 258 if ( hasIndex( row, column, parent ) )
260 return createIndex( row, column );
262 return QModelIndex();
265 QModelIndex QgsGraduatedSymbolRendererModel::parent(
const QModelIndex &index )
const 268 return QModelIndex();
271 QStringList QgsGraduatedSymbolRendererModel::mimeTypes()
const 274 types << mMimeFormat;
278 QMimeData *QgsGraduatedSymbolRendererModel::mimeData(
const QModelIndexList &indexes )
const 280 QMimeData *mimeData =
new QMimeData();
281 QByteArray encodedData;
283 QDataStream stream( &encodedData, QIODevice::WriteOnly );
286 const auto constIndexes = indexes;
287 for (
const QModelIndex &index : constIndexes )
289 if ( !index.isValid() || index.column() != 0 )
292 stream << index.row();
294 mimeData->setData( mMimeFormat, encodedData );
298 bool QgsGraduatedSymbolRendererModel::dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
302 if ( action != Qt::MoveAction )
return true;
304 if ( !data->hasFormat( mMimeFormat ) )
return false;
306 QByteArray encodedData = data->data( mMimeFormat );
307 QDataStream stream( &encodedData, QIODevice::ReadOnly );
310 while ( !stream.atEnd() )
317 int to = parent.row();
320 if ( to == -1 ) to = mRenderer->
ranges().size();
321 for (
int i = rows.size() - 1; i >= 0; i-- )
323 QgsDebugMsg( QStringLiteral(
"move %1 to %2" ).arg( rows[i] ).arg( to ) );
326 if ( rows[i] < t ) t--;
329 for (
int j = 0; j < i; j++ )
331 if ( to < rows[j] && rows[i] > rows[j] ) rows[j] += 1;
334 if ( rows[i] < to ) to--;
336 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->
ranges().size(), 0 ) );
341 void QgsGraduatedSymbolRendererModel::deleteRows( QList<int> rows )
343 for (
int i = rows.size() - 1; i >= 0; i-- )
345 beginRemoveRows( QModelIndex(), rows[i], rows[i] );
351 void QgsGraduatedSymbolRendererModel::removeAllRows()
353 beginRemoveRows( QModelIndex(), 0, mRenderer->
ranges().size() - 1 );
358 void QgsGraduatedSymbolRendererModel::sort(
int column, Qt::SortOrder order )
368 else if ( column == 2 )
373 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->
ranges().size(), 0 ) );
376 void QgsGraduatedSymbolRendererModel::updateSymbology()
378 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->
ranges().size(), 0 ) );
381 void QgsGraduatedSymbolRendererModel::updateLabels()
383 emit dataChanged( createIndex( 0, 2 ), createIndex( mRenderer->
ranges().size(), 2 ) );
387 QgsGraduatedSymbolRendererViewStyle::QgsGraduatedSymbolRendererViewStyle( QWidget *parent )
391 void QgsGraduatedSymbolRendererViewStyle::drawPrimitive( PrimitiveElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget )
const 393 if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
395 QStyleOption opt( *option );
396 opt.rect.setLeft( 0 );
398 opt.rect.setHeight( 0 );
399 if ( widget ) opt.rect.setRight( widget->width() );
400 QProxyStyle::drawPrimitive( element, &opt, painter, widget );
403 QProxyStyle::drawPrimitive( element, option, painter, widget );
412 return new QgsGraduatedSymbolRendererWidget( layer, style, renderer );
422 if ( mContext.mapCanvas() )
436 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
456 mRenderer = qgis::make_unique< QgsGraduatedSymbolRenderer >( QString(),
QgsRangeList() );
462 mSymmetryPointValidator =
new QDoubleValidator();
463 cboSymmetryPoint->setEditable(
true );
464 cboSymmetryPoint->setValidator( mSymmetryPointValidator );
467 for ( QMap<QString, QString>::const_iterator it = methods.constBegin(); it != methods.constEnd(); ++it )
470 cboGraduatedMode->addItem( icon, it.key(), it.value() );
473 connect( methodComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged );
474 this->layout()->setContentsMargins( 0, 0, 0, 0 );
476 mModel =
new QgsGraduatedSymbolRendererModel(
this );
479 mExpressionWidget->setLayer(
mLayer );
481 btnChangeGraduatedSymbol->setLayer(
mLayer );
482 btnChangeGraduatedSymbol->registerExpressionContextGenerator(
this );
490 spinGraduatedClasses->setShowClearButton(
false );
492 btnColorRamp->setShowRandomColorRamp(
true );
495 QString defaultColorRamp =
QgsProject::instance()->
readEntry( QStringLiteral(
"DefaultStyles" ), QStringLiteral(
"/ColorRamp" ), QString() );
496 if ( !defaultColorRamp.isEmpty() )
498 btnColorRamp->setColorRampFromName( defaultColorRamp );
503 btnColorRamp->setColorRamp( ramp );
508 viewGraduated->setStyle(
new QgsGraduatedSymbolRendererViewStyle( viewGraduated ) );
511 if ( mGraduatedSymbol )
513 btnChangeGraduatedSymbol->setSymbolType( mGraduatedSymbol->type() );
514 btnChangeGraduatedSymbol->setSymbol( mGraduatedSymbol->clone() );
516 methodComboBox->blockSignals(
true );
517 methodComboBox->addItem( tr(
"Color" ), ColorMode );
518 switch ( mGraduatedSymbol->type() )
522 methodComboBox->addItem( tr(
"Size" ), SizeMode );
523 minSizeSpinBox->setValue( 1 );
524 maxSizeSpinBox->setValue( 8 );
529 methodComboBox->addItem( tr(
"Size" ), SizeMode );
530 minSizeSpinBox->setValue( .1 );
531 maxSizeSpinBox->setValue( 2 );
537 methodComboBox->hide();
544 methodComboBox->blockSignals(
false );
553 connect( btnChangeGraduatedSymbol, &
QgsSymbolButton::changed,
this, &QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol );
560 connect( cboGraduatedMode, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, &QgsGraduatedSymbolRendererWidget::updateMethodParameters );
568 mGroupBoxSymmetric->setCollapsed(
true );
571 QMenu *advMenu =
new QMenu(
this );
573 advMenu->addAction( tr(
"Symbol Levels…" ),
this, SLOT(
showSymbolLevels() ) );
576 QAction *actionDdsLegend = advMenu->addAction( tr(
"Data-defined Size Legend…" ) );
578 connect( actionDdsLegend, &QAction::triggered,
this, &QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend );
581 btnAdvanced->setMenu( advMenu );
583 mHistogramWidget->setLayer(
mLayer );
584 mHistogramWidget->setRenderer( mRenderer.get() );
588 mExpressionWidget->registerExpressionContextGenerator(
this );
591 void QgsGraduatedSymbolRendererWidget::mSizeUnitWidget_changed()
593 if ( !mGraduatedSymbol )
595 mGraduatedSymbol->setOutputUnit( mSizeUnitWidget->unit() );
596 mGraduatedSymbol->setMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
597 mRenderer->updateSymbols( mGraduatedSymbol.get() );
604 mParameterWidgetWrappers.clear();
609 return mRenderer.get();
615 btnChangeGraduatedSymbol->setMapCanvas( context.
mapCanvas() );
616 btnChangeGraduatedSymbol->setMessageBar( context.
messageBar() );
637 connect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished,
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
639 for (
const auto &ppww : qgis::as_const( mParameterWidgetWrappers ) )
663 disconnect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished,
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
665 for (
const auto &ppww : qgis::as_const( mParameterWidgetWrappers ) )
680 int precision = spinPrecision->value() + 2;
681 while ( cboSymmetryPoint->count() )
682 cboSymmetryPoint->removeItem( 0 );
683 for (
int i = 0; i < ranges.count() - 1; i++ )
684 cboSymmetryPoint->addItem( QString::number( ranges.at( i ).upperValue(),
'f',
precision ), ranges.at( i ).upperValue() );
688 int idx = cboGraduatedMode->findData( method->
id() );
690 cboGraduatedMode->setCurrentIndex( idx );
696 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QString::number( method->
symmetryPoint(),
'f', method->
labelPrecision() + 2 ) );
703 for (
const auto &ppww : qgis::as_const( mParameterWidgetWrappers ) )
707 ppww->setParameterValue( value, context );
712 int nclasses = ranges.count();
713 if ( nclasses && updateCount )
715 spinGraduatedClasses->setValue( ranges.count() );
719 QString attrName = mRenderer->classAttribute();
720 mExpressionWidget->setField( attrName );
721 mHistogramWidget->setSourceFieldExp( attrName );
724 if ( mRenderer->sourceSymbol() )
726 mGraduatedSymbol.reset( mRenderer->sourceSymbol()->clone() );
727 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
730 mModel->setRenderer( mRenderer.get() );
731 viewGraduated->setModel( mModel );
733 connect( viewGraduated->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsGraduatedSymbolRendererWidget::selectionChanged );
735 if ( mGraduatedSymbol )
737 mSizeUnitWidget->blockSignals(
true );
738 mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
739 mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
740 mSizeUnitWidget->blockSignals(
false );
744 methodComboBox->blockSignals(
true );
745 switch ( mRenderer->graduatedMethod() )
749 methodComboBox->setCurrentIndex( methodComboBox->findData( ColorMode ) );
750 if ( mRenderer->sourceColorRamp() )
752 btnColorRamp->setColorRamp( mRenderer->sourceColorRamp() );
758 methodComboBox->setCurrentIndex( methodComboBox->findData( SizeMode ) );
759 if ( !mRenderer->ranges().isEmpty() )
761 minSizeSpinBox->setValue( mRenderer->minSymbolSize() );
762 maxSizeSpinBox->setValue( mRenderer->maxSymbolSize() );
767 toggleMethodWidgets( static_cast< MethodMode>( methodComboBox->currentData().toInt() ) );
768 methodComboBox->blockSignals(
false );
770 viewGraduated->resizeColumnToContents( 0 );
771 viewGraduated->resizeColumnToContents( 1 );
772 viewGraduated->resizeColumnToContents( 2 );
774 mHistogramWidget->refresh();
782 mRenderer->setClassAttribute( field );
785 void QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged(
int )
787 const MethodMode newMethod =
static_cast< MethodMode
>( methodComboBox->currentData().toInt() );
788 toggleMethodWidgets( newMethod );
798 QMessageBox::critical(
this, tr(
"Select Method" ), tr(
"No color ramp defined." ) );
801 mRenderer->setSourceColorRamp( ramp );
808 lblColorRamp->setVisible(
false );
809 btnColorRamp->setVisible(
false );
810 lblSize->setVisible(
true );
811 minSizeSpinBox->setVisible(
true );
812 lblSize->setVisible(
true );
813 maxSizeSpinBox->setVisible(
true );
814 mSizeUnitWidget->setVisible(
true );
823 void QgsGraduatedSymbolRendererWidget::updateMethodParameters()
825 clearParameterWidgets();
827 const QString methodId = cboGraduatedMode->currentData().toString();
839 QVariant value = method->
parameterValues().value( def->name(), def->defaultValue() );
844 mParameterWidgetWrappers.push_back( std::unique_ptr<QgsAbstractProcessingParameterWidgetWrapper>( ppww ) );
848 void QgsGraduatedSymbolRendererWidget::toggleMethodWidgets( MethodMode mode )
854 lblColorRamp->setVisible(
true );
855 btnColorRamp->setVisible(
true );
856 lblSize->setVisible(
false );
857 minSizeSpinBox->setVisible(
false );
858 lblSizeTo->setVisible(
false );
859 maxSizeSpinBox->setVisible(
false );
860 mSizeUnitWidget->setVisible(
false );
866 lblColorRamp->setVisible(
false );
867 btnColorRamp->setVisible(
false );
868 lblSize->setVisible(
true );
869 minSizeSpinBox->setVisible(
true );
870 lblSizeTo->setVisible(
true );
871 maxSizeSpinBox->setVisible(
true );
872 mSizeUnitWidget->setVisible(
true );
878 void QgsGraduatedSymbolRendererWidget::clearParameterWidgets()
880 while ( mParametersLayout->rowCount() )
882 QFormLayout::TakeRowResult row = mParametersLayout->takeRow( 0 );
883 for ( QLayoutItem *item : QList<QLayoutItem *>( {row.labelItem, row.fieldItem} ) )
886 if ( item->widget() )
887 item->widget()->deleteLater();
891 mParameterWidgetWrappers.clear();
899 mModel->updateSymbology();
902 spinGraduatedClasses->setValue( mRenderer->ranges().count() );
908 void QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector(
QgsPanelWidget *container )
917 void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
927 mSizeUnitWidget->blockSignals(
true );
928 mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
929 mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
930 mSizeUnitWidget->blockSignals(
false );
932 QItemSelectionModel *m = viewGraduated->selectionModel();
933 QModelIndexList selectedIndexes = m->selectedRows( 1 );
934 if ( m && !selectedIndexes.isEmpty() )
936 const auto constSelectedIndexes = selectedIndexes;
937 for (
const QModelIndex &idx : constSelectedIndexes )
941 int rangeIdx = idx.row();
942 QgsSymbol *newRangeSymbol = mGraduatedSymbol->clone();
943 if ( selectedIndexes.count() > 1 )
946 newRangeSymbol->
setColor( mRenderer->ranges().at( rangeIdx ).symbol()->color() );
948 mRenderer->updateRangeSymbol( rangeIdx, newRangeSymbol );
954 mRenderer->updateSymbols( mGraduatedSymbol.get() );
961 void QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished( )
963 const QString text = cboSymmetryPoint->lineEdit()->text();
964 int index = cboSymmetryPoint->findText( text );
967 cboSymmetryPoint->setCurrentIndex( index );
971 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), text );
981 QString attrName = mExpressionWidget->currentField();
982 int nclasses = spinGraduatedClasses->value();
984 const QString methodId = cboGraduatedMode->currentData().toString();
991 mSymmetryPointValidator->setBottom( minimum );
992 mSymmetryPointValidator->setTop( maximum );
993 mSymmetryPointValidator->setDecimals( spinPrecision->value() );
1000 double currentValue = cboSymmetryPoint->currentText().toDouble();
1001 if ( currentValue < ( minimum + ( maximum - minimum ) / 100. ) || currentValue > ( maximum - ( maximum - minimum ) / 100. ) )
1002 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QString::number( minimum + ( maximum - minimum ) / 2.,
'f', method->
labelPrecision() + 2 ) );
1005 if ( mGroupBoxSymmetric->isChecked() )
1007 double symmetryPoint = cboSymmetryPoint->currentText().toDouble();
1008 bool astride = cbxAstride->isChecked();
1012 QVariantMap parameterValues;
1013 for (
const auto &ppww : qgis::as_const( mParameterWidgetWrappers ) )
1014 parameterValues.insert( ppww->parameterDefinition()->name(), ppww->parameterValue() );
1018 mRenderer->setClassificationMethod( method );
1021 mRenderer->setClassAttribute( attrName );
1027 if ( QMessageBox::Cancel == QMessageBox::question(
this, tr(
"Apply Classification" ), 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 ) )
1033 if ( methodComboBox->currentData() == ColorMode )
1035 std::unique_ptr<QgsColorRamp> ramp( btnColorRamp->colorRamp() );
1038 QMessageBox::critical(
this, tr(
"Apply Classification" ), tr(
"No color ramp defined." ) );
1041 mRenderer->setSourceColorRamp( ramp.release() );
1045 mRenderer->setSourceColorRamp(
nullptr );
1048 mRenderer->updateClasses(
mLayer, nclasses );
1050 if ( methodComboBox->currentData() == SizeMode )
1051 mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
1053 mRenderer->calculateLabelPrecision();
1061 std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
1065 mRenderer->updateColorRamp( ramp.release() );
1066 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1072 mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
1073 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1078 int QgsRendererPropertiesDialog::currentRangeRow()
1080 QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
1081 if ( !idx.isValid() )
1090 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1092 const auto constSelectedRows = selectedRows;
1093 for (
const QModelIndex &r : constSelectedRows )
1097 rows.append( r.row() );
1106 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1107 QModelIndexList::const_iterator sIt = selectedRows.constBegin();
1109 for ( ; sIt != selectedRows.constEnd(); ++sIt )
1111 selectedRanges.append( mModel->rendererRange( *sIt ) );
1118 if ( idx.isValid() && idx.column() == 0 )
1120 if ( idx.isValid() && idx.column() == 1 )
1126 if ( !idx.isValid() )
1129 mRowSelected = idx.row();
1139 std::unique_ptr< QgsSymbol > newSymbol( range.
symbol()->
clone() );
1141 if ( panel && panel->dockMode() )
1156 if ( !dlg.exec() || !newSymbol )
1161 mGraduatedSymbol = std::move( newSymbol );
1162 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
1174 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
1175 if ( decimalPlaces < 0 ) decimalPlaces = 0;
1179 if ( dialog.exec() == QDialog::Accepted )
1188 mRenderer->updateRangeUpperValue( rangeIdx, upperValue );
1189 mRenderer->updateRangeLowerValue( rangeIdx, lowerValue );
1192 if ( cbxLinkBoundaries->isChecked() )
1196 mRenderer->updateRangeUpperValue( rangeIdx - 1, lowerValue );
1199 if ( rangeIdx < mRenderer->ranges().size() - 1 )
1201 mRenderer->updateRangeLowerValue( rangeIdx + 1, upperValue );
1205 mHistogramWidget->refresh();
1211 mModel->addClass( mGraduatedSymbol.get() );
1212 mHistogramWidget->refresh();
1220 mModel->deleteRows( classIndexes );
1221 mHistogramWidget->refresh();
1227 mModel->removeAllRows();
1228 mHistogramWidget->refresh();
1235 bool ordered =
true;
1236 for (
int i = 1; i < ranges.size(); ++i )
1238 if ( ranges[i] < ranges[i - 1] )
1255 int result = QMessageBox::warning(
1257 tr(
"Link Class Boundaries" ),
1258 tr(
"Rows will be reordered before linking boundaries. Continue?" ),
1259 QMessageBox::Ok | QMessageBox::Cancel );
1260 if ( result != QMessageBox::Ok )
1262 cbxLinkBoundaries->setChecked(
false );
1265 mRenderer->sortByValue();
1269 for (
int i = 1; i < mRenderer->ranges().size(); ++i )
1271 mRenderer->updateRangeLowerValue( i, mRenderer->ranges()[i - 1].upperValue() );
1279 if ( item->column() == 2 )
1281 QString label = item->text();
1282 int idx = item->row();
1283 mRenderer->updateRangeLabel( idx, label );
1289 mRenderer->classificationMethod()->setLabelFormat( txtLegendFormat->text() );
1290 mRenderer->classificationMethod()->setLabelPrecision( spinPrecision->value() );
1291 mRenderer->classificationMethod()->setLabelTrimTrailingZeroes( cbxTrimTrailingZeroes->isChecked() );
1292 mRenderer->updateRangeLabels();
1293 mModel->updateLabels();
1301 QItemSelectionModel *m = viewGraduated->selectionModel();
1302 QModelIndexList selectedIndexes = m->selectedRows( 1 );
1303 if ( m && !selectedIndexes.isEmpty() )
1306 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
1307 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1309 QStringList list = m->model()->data( *indexIt ).toString().split(
' ' );
1310 if ( list.size() < 3 )
1326 selectedSymbols.append( s );
1335 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
1336 if ( decimalPlaces < 0 )
1338 double precision = 1.0 / std::pow( 10, decimalPlaces );
1340 for ( QgsRangeList::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
1344 return it->symbol();
1354 mModel->updateSymbology();
1356 mHistogramWidget->refresh();
1367 viewGraduated->selectionModel()->clear();
1370 cbxLinkBoundaries->setChecked(
false );
1387 if ( event->key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
1389 mCopyBuffer.clear();
1392 else if ( event->key() == Qt::Key_V &&
event->modifiers() == Qt::ControlModifier )
1394 QgsRangeList::const_iterator rIt = mCopyBuffer.constBegin();
1395 for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
1397 mModel->addClass( *rIt );
1403 void QgsGraduatedSymbolRendererWidget::selectionChanged(
const QItemSelection &,
const QItemSelection & )
1406 if ( !ranges.isEmpty() )
1408 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( ranges.at( 0 ).symbol()->clone() );
1410 else if ( mRenderer->sourceSymbol() )
1412 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mRenderer->sourceSymbol()->clone() );
1414 btnChangeGraduatedSymbol->setDialogTitle( ranges.size() == 1 ? ranges.at( 0 ).label() : tr(
"Symbol Settings" ) );
1417 void QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend()
1425 mRenderer->setDataDefinedSizeLegend( panel->dataDefinedSizeLegend() );
1432 void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
1434 mGraduatedSymbol.reset( btnChangeGraduatedSymbol->symbol()->clone() );
1444 const QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1445 for (
const QModelIndex &index : selectedRows )
1447 if ( !index.isValid() )
1450 const int row = index.row();
1451 if ( !mRenderer || mRenderer->ranges().size() <= row )
1454 if ( mRenderer->ranges().at( row ).symbol()->type() != tempSymbol->type() )
1457 std::unique_ptr< QgsSymbol > newCatSymbol( tempSymbol->clone() );
1458 if ( selectedRows.count() > 1 )
1461 newCatSymbol->setColor( mRenderer->ranges().at( row ).symbol()->color() );
1464 mRenderer->updateRangeSymbol( row, newCatSymbol.release() );
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsClassificationMethod * method(const QString &id)
Returns a new instance of the method for the given id.
static QgsGraduatedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsGraduatedSymbolRenderer from an existing renderer.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
static QgsProcessingGuiRegistry * processingGuiRegistry()
Returns the global processing gui registry, used for registering the GUI behavior of processing algor...
QList< QgsRendererRange > QgsRangeList
static const QString METHOD_ID
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Abstract base class for all rendered symbols.
bool symmetricModeAvailable() const
Returns if the method supports symmetric calculation.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
QgsClassificationMethod * classificationMethod() const
Returns the classification method.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsProcessingParameterDefinitions parameterDefinitions() const
Returns the list of parameters.
double qgsPermissiveToDouble(QString string, bool &ok)
Converts a string to a double in a permissive way, e.g., allowing for incorrect numbers of digits bet...
Abstract base class for color ramps.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
int codeComplexity() const
Code complexity as the exponent in Big O notation.
bool symmetryAstride() const
Returns if the symmetric mode is astride if true, it will remove the symmetry point break so that the...
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
virtual QString id() const =0
The id of the method as saved in the project, must be unique in registry.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style...
void setLowerValue(const QString &val)
void addClass(QgsSymbol *symbol)
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
A marker symbol type, for rendering Point and MultiPoint geometries.
static const int MAX_PRECISION
The QgsMapSettings class contains configuration for rendering of the map.
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
double lowerValue() const
void setSymmetricMode(bool enabled, double symmetryPoint=0, bool symmetryAstride=false)
Defines if the symmetric mode is enables and configures its parameters.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QgsFields fields() const FINAL
Returns the list of fields of this layer.
double symmetryPoint() const
Returns the symmetry point for symmetric mode.
int labelPrecision() const
Returns the precision for the formatting of the labels.
QVariant defaultValue() const
Returns the default value for the parameter.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool labelTrimTrailingZeroes() const
Returns if the trailing 0 are trimmed in the label.
QIcon icon(const QString &id) const
Returns the icon for a given method id.
QgsSymbol * symbol() const
QVariant minimumValue(int index) const FINAL
Returns the minimum value for an attribute column or an invalid variant in case of error...
Single scope for storing variables and functions for use within a QgsExpressionContext.
QgsAbstractProcessingParameterWidgetWrapper * createParameterWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)
Creates a new parameter widget wrapper for the given parameter.
static const QString METHOD_ID
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
static const int MIN_PRECISION
bool symmetricModeEnabled() const
Returns if the symmetric mode is enabled.
void moveClass(int from, int to)
Moves the category at index position from to index position to.
QString name() const
Returns the name of the parameter.
QString labelFormat() const
Returns the format of the label for the classes.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
Points (e.g., for font sizes)
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
static QgsClassificationMethodRegistry * classificationMethodRegistry()
Returns the application's classification methods registry, used in graduated renderer.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Base class for the definition of processing parameters.
QVariantMap parameterValues() const
Returns the values of the processing parameters.
void setUpperValue(const QString &val)
double upperValue() const
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
bool updateRangeRenderState(int rangeIndex, bool render)
QString lowerValue() const
bool updateRangeLabel(int rangeIndex, const QString &label)
void setParameterValues(const QVariantMap &values)
Defines the values of the additional parameters.
QString upperValue() const
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
QVariant maximumValue(int index) const FINAL
Returns the maximum value for an attribute column or an invalid variant in case of error...
Represents a vector layer which manages a vector based data sets.
Contains information about the context in which a processing algorithm is executed.
const QgsRangeList & ranges() const
QgsClassificationMethod is an abstract class for implementations of classification methods...
void deleteClass(int idx)
QMap< QString, QString > methodNames() const
Returns a map <name, id> of all registered methods.
void setColor(const QColor &color)
Sets the color for the symbol.
Standard algorithm dialog.