19#include <QStandardItemModel>
20#include <QStandardItem>
64QgsGraduatedSymbolRendererModel::QgsGraduatedSymbolRendererModel( QObject *parent ) : QAbstractItemModel( parent )
65 , mMimeFormat( QStringLiteral(
"application/x-qgsgraduatedsymbolrendererv2model" ) )
73 if ( !mRenderer->ranges().isEmpty() )
75 beginRemoveRows( QModelIndex(), 0, mRenderer->ranges().size() - 1 );
86 if ( !renderer->
ranges().isEmpty() )
88 beginInsertRows( QModelIndex(), 0, renderer->
ranges().size() - 1 );
99void QgsGraduatedSymbolRendererModel::addClass(
QgsSymbol *symbol )
101 if ( !mRenderer )
return;
102 int idx = mRenderer->
ranges().size();
103 beginInsertRows( QModelIndex(), idx, idx );
104 mRenderer->addClass( symbol );
108void QgsGraduatedSymbolRendererModel::addClass(
const QgsRendererRange &range )
114 int idx = mRenderer->ranges().size();
115 beginInsertRows( QModelIndex(), idx, idx );
116 mRenderer->addClass( range );
120QgsRendererRange QgsGraduatedSymbolRendererModel::rendererRange(
const QModelIndex &index )
122 if ( !index.isValid() || !mRenderer || mRenderer->ranges().size() <= index.row() )
127 return mRenderer->ranges().value( index.row() );
130Qt::ItemFlags QgsGraduatedSymbolRendererModel::flags(
const QModelIndex &index )
const
132 if ( !index.isValid() )
134 return Qt::ItemIsDropEnabled;
137 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;
139 if ( index.column() == 2 )
141 flags |= Qt::ItemIsEditable;
147Qt::DropActions QgsGraduatedSymbolRendererModel::supportedDropActions()
const
149 return Qt::MoveAction;
152QVariant QgsGraduatedSymbolRendererModel::data(
const QModelIndex &index,
int role )
const
154 if ( !index.isValid() || !mRenderer )
return QVariant();
158 if ( role == Qt::CheckStateRole && index.column() == 0 )
160 return range.
renderState() ? Qt::Checked : Qt::Unchecked;
162 else if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
164 switch ( index.column() )
168 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
169 if ( decimalPlaces < 0 ) decimalPlaces = 0;
170 return QString( QLocale().toString( range.
lowerValue(),
'f', decimalPlaces ) +
" - " + QLocale().toString( range.
upperValue(),
'f', decimalPlaces ) );
173 return range.
label();
178 else if ( role == Qt::DecorationRole && index.column() == 0 && range.
symbol() )
183 else if ( role == Qt::TextAlignmentRole )
185 return ( index.column() == 0 ) ?
static_cast<Qt::Alignment::Int
>( Qt::AlignHCenter ) : static_cast<Qt::Alignment::Int>( Qt::AlignLeft );
187 else if ( role == Qt::EditRole )
189 switch ( index.column() )
193 return range.
label();
202bool QgsGraduatedSymbolRendererModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
204 if ( !index.isValid() )
207 if ( index.column() == 0 && role == Qt::CheckStateRole )
209 mRenderer->updateRangeRenderState( index.row(), value == Qt::Checked );
210 emit dataChanged( index, index );
214 if ( role != Qt::EditRole )
217 switch ( index.column() )
222 mRenderer->updateRangeLabel( index.row(), value.toString() );
228 emit dataChanged( index, index );
232QVariant QgsGraduatedSymbolRendererModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
234 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
237 lst << tr(
"Symbol" ) << tr(
"Values" ) << tr(
"Legend" );
238 return lst.value( section );
243int QgsGraduatedSymbolRendererModel::rowCount(
const QModelIndex &parent )
const
245 if ( parent.isValid() || !mRenderer )
249 return mRenderer->ranges().size();
252int QgsGraduatedSymbolRendererModel::columnCount(
const QModelIndex &index )
const
258QModelIndex QgsGraduatedSymbolRendererModel::index(
int row,
int column,
const QModelIndex &parent )
const
260 if ( hasIndex( row, column, parent ) )
262 return createIndex( row, column );
264 return QModelIndex();
267QModelIndex QgsGraduatedSymbolRendererModel::parent(
const QModelIndex &index )
const
270 return QModelIndex();
273QStringList QgsGraduatedSymbolRendererModel::mimeTypes()
const
276 types << mMimeFormat;
280QMimeData *QgsGraduatedSymbolRendererModel::mimeData(
const QModelIndexList &indexes )
const
282 QMimeData *mimeData =
new QMimeData();
283 QByteArray encodedData;
285 QDataStream stream( &encodedData, QIODevice::WriteOnly );
288 const auto constIndexes = indexes;
289 for (
const QModelIndex &index : constIndexes )
291 if ( !index.isValid() || index.column() != 0 )
294 stream << index.row();
296 mimeData->setData( mMimeFormat, encodedData );
300bool QgsGraduatedSymbolRendererModel::dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
304 if ( action != Qt::MoveAction )
return true;
306 if ( !data->hasFormat( mMimeFormat ) )
return false;
308 QByteArray encodedData = data->data( mMimeFormat );
309 QDataStream stream( &encodedData, QIODevice::ReadOnly );
312 while ( !stream.atEnd() )
319 int to = parent.row();
322 if ( to == -1 ) to = mRenderer->ranges().size();
323 for (
int i = rows.size() - 1; i >= 0; i-- )
325 QgsDebugMsg( QStringLiteral(
"move %1 to %2" ).arg( rows[i] ).arg( to ) );
328 if ( rows[i] < t ) t--;
329 mRenderer->moveClass( rows[i], t );
331 for (
int j = 0; j < i; j++ )
333 if ( to < rows[j] && rows[i] > rows[j] ) rows[j] += 1;
336 if ( rows[i] < to ) to--;
338 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->ranges().size(), 0 ) );
343void QgsGraduatedSymbolRendererModel::deleteRows( QList<int> rows )
345 for (
int i = rows.size() - 1; i >= 0; i-- )
347 beginRemoveRows( QModelIndex(), rows[i], rows[i] );
348 mRenderer->deleteClass( rows[i] );
353void QgsGraduatedSymbolRendererModel::removeAllRows()
355 beginRemoveRows( QModelIndex(), 0, mRenderer->ranges().size() - 1 );
356 mRenderer->deleteAllClasses();
360void QgsGraduatedSymbolRendererModel::sort(
int column, Qt::SortOrder order )
368 mRenderer->sortByValue( order );
370 else if ( column == 2 )
372 mRenderer->sortByLabel( order );
375 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->ranges().size(), 0 ) );
378void QgsGraduatedSymbolRendererModel::updateSymbology()
380 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->ranges().size(), 0 ) );
383void QgsGraduatedSymbolRendererModel::updateLabels()
385 emit dataChanged( createIndex( 0, 2 ), createIndex( mRenderer->ranges().size(), 2 ) );
389QgsGraduatedSymbolRendererViewStyle::QgsGraduatedSymbolRendererViewStyle( QWidget *parent )
393void QgsGraduatedSymbolRendererViewStyle::drawPrimitive( PrimitiveElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget )
const
395 if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
397 QStyleOption opt( *option );
398 opt.rect.setLeft( 0 );
400 opt.rect.setHeight( 0 );
401 if ( widget ) opt.rect.setRight( widget->width() );
402 QProxyStyle::drawPrimitive( element, &opt, painter, widget );
405 QProxyStyle::drawPrimitive( element, option, painter, widget );
430 expContext << generator->createExpressionContextScope();
462 mRenderer = std::make_unique< QgsGraduatedSymbolRenderer >( QString(),
QgsRangeList() );
471 cboSymmetryPoint->setEditable(
true );
472 cboSymmetryPoint->setValidator( mSymmetryPointValidator );
475 for ( QMap<QString, QString>::const_iterator it = methods.constBegin(); it != methods.constEnd(); ++it )
478 cboGraduatedMode->addItem( icon, it.key(), it.value() );
481 connect( methodComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged );
482 this->layout()->setContentsMargins( 0, 0, 0, 0 );
484 mModel =
new QgsGraduatedSymbolRendererModel(
this );
487 mExpressionWidget->setLayer(
mLayer );
489 btnChangeGraduatedSymbol->setLayer(
mLayer );
490 btnChangeGraduatedSymbol->registerExpressionContextGenerator(
this );
497 spinPrecision->setClearValue( 4 );
499 spinGraduatedClasses->setShowClearButton(
false );
501 btnColorRamp->setShowRandomColorRamp(
true );
504 std::unique_ptr< QgsColorRamp > colorRamp(
QgsProject::instance()->styleSettings()->defaultColorRamp() );
507 btnColorRamp->setColorRamp( colorRamp.get() );
512 btnColorRamp->setColorRamp( ramp );
517 viewGraduated->setStyle(
new QgsGraduatedSymbolRendererViewStyle( viewGraduated ) );
520 if ( mGraduatedSymbol )
522 btnChangeGraduatedSymbol->setSymbolType( mGraduatedSymbol->type() );
523 btnChangeGraduatedSymbol->setSymbol( mGraduatedSymbol->clone() );
525 methodComboBox->blockSignals(
true );
526 methodComboBox->addItem( tr(
"Color" ), ColorMode );
527 switch ( mGraduatedSymbol->type() )
531 methodComboBox->addItem( tr(
"Size" ), SizeMode );
532 minSizeSpinBox->setValue( 1 );
533 maxSizeSpinBox->setValue( 8 );
538 methodComboBox->addItem( tr(
"Size" ), SizeMode );
539 minSizeSpinBox->setValue( .1 );
540 maxSizeSpinBox->setValue( 2 );
546 methodComboBox->hide();
553 methodComboBox->blockSignals(
false );
562 connect( btnChangeGraduatedSymbol, &
QgsSymbolButton::changed,
this, &QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol );
569 connect( cboGraduatedMode, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsGraduatedSymbolRendererWidget::updateMethodParameters );
572 updateMethodParameters();
580 mGroupBoxSymmetric->setCollapsed(
true );
583 QMenu *advMenu =
new QMenu(
this );
588 QAction *actionDdsLegend = advMenu->addAction( tr(
"Data-defined Size Legend…" ) );
590 connect( actionDdsLegend, &QAction::triggered,
this, &QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend );
593 btnAdvanced->setMenu( advMenu );
595 mHistogramWidget->setLayer(
mLayer );
596 mHistogramWidget->setRenderer( mRenderer.get() );
600 mExpressionWidget->registerExpressionContextGenerator(
this );
603void QgsGraduatedSymbolRendererWidget::mSizeUnitWidget_changed()
605 if ( !mGraduatedSymbol )
607 mGraduatedSymbol->setOutputUnit( mSizeUnitWidget->unit() );
608 mGraduatedSymbol->setMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
609 mRenderer->updateSymbols( mGraduatedSymbol.get() );
616 mParameterWidgetWrappers.clear();
621 return mRenderer.get();
633 delete mActionLevels;
634 mActionLevels =
nullptr;
655 connect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished,
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
657 for (
const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
681 disconnect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished,
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
683 for (
const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
699 int precision = spinPrecision->value() + 2;
700 while ( cboSymmetryPoint->count() )
701 cboSymmetryPoint->removeItem( 0 );
702 for (
int i = 0; i < ranges.count() - 1; i++ )
703 cboSymmetryPoint->addItem( QLocale().toString( ranges.at( i ).upperValue(),
'f',
precision ), ranges.at( i ).upperValue() );
707 int idx = cboGraduatedMode->findData( method->
id() );
709 cboGraduatedMode->setCurrentIndex( idx );
715 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QLocale().toString( method->
symmetryPoint(),
'f', method->
labelPrecision() + 2 ) );
722 for (
const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
726 ppww->setParameterValue( value,
context );
731 int nclasses = ranges.count();
734 spinGraduatedClasses->setValue( ranges.count() );
742 spinGraduatedClasses->setEnabled(
true );
746 QString attrName = mRenderer->classAttribute();
747 mExpressionWidget->setField( attrName );
748 mHistogramWidget->setSourceFieldExp( attrName );
751 if ( mRenderer->sourceSymbol() )
753 mGraduatedSymbol.reset( mRenderer->sourceSymbol()->clone() );
754 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
757 mModel->setRenderer( mRenderer.get() );
758 viewGraduated->setModel( mModel );
760 connect( viewGraduated->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsGraduatedSymbolRendererWidget::selectionChanged );
762 if ( mGraduatedSymbol )
764 mSizeUnitWidget->blockSignals(
true );
765 mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
766 mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
767 mSizeUnitWidget->blockSignals(
false );
771 methodComboBox->blockSignals(
true );
772 switch ( mRenderer->graduatedMethod() )
776 methodComboBox->setCurrentIndex( methodComboBox->findData( ColorMode ) );
777 if ( mRenderer->sourceColorRamp() )
779 btnColorRamp->setColorRamp( mRenderer->sourceColorRamp() );
785 methodComboBox->setCurrentIndex( methodComboBox->findData( SizeMode ) );
786 if ( !mRenderer->ranges().isEmpty() )
788 minSizeSpinBox->setValue( mRenderer->minSymbolSize() );
789 maxSizeSpinBox->setValue( mRenderer->maxSymbolSize() );
794 toggleMethodWidgets(
static_cast< MethodMode
>( methodComboBox->currentData().toInt() ) );
795 methodComboBox->blockSignals(
false );
797 viewGraduated->resizeColumnToContents( 0 );
798 viewGraduated->resizeColumnToContents( 1 );
799 viewGraduated->resizeColumnToContents( 2 );
801 mHistogramWidget->refresh();
811 mRenderer->setClassAttribute(
field );
814void QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged(
int )
816 const MethodMode newMethod =
static_cast< MethodMode
>( methodComboBox->currentData().toInt() );
817 toggleMethodWidgets( newMethod );
827 QMessageBox::critical(
this, tr(
"Select Method" ), tr(
"No color ramp defined." ) );
830 mRenderer->setSourceColorRamp( ramp );
837 lblColorRamp->setVisible(
false );
838 btnColorRamp->setVisible(
false );
839 lblSize->setVisible(
true );
840 minSizeSpinBox->setVisible(
true );
841 lblSize->setVisible(
true );
842 maxSizeSpinBox->setVisible(
true );
843 mSizeUnitWidget->setVisible(
true );
852void QgsGraduatedSymbolRendererWidget::updateMethodParameters()
854 clearParameterWidgets();
856 const QString methodId = cboGraduatedMode->currentData().toString();
868 QVariant value = method->
parameterValues().value( def->name(), def->defaultValueForGui() );
873 mParameterWidgetWrappers.push_back( std::unique_ptr<QgsAbstractProcessingParameterWidgetWrapper>( ppww ) );
879void QgsGraduatedSymbolRendererWidget::toggleMethodWidgets( MethodMode mode )
885 lblColorRamp->setVisible(
true );
886 btnColorRamp->setVisible(
true );
887 lblSize->setVisible(
false );
888 minSizeSpinBox->setVisible(
false );
889 lblSizeTo->setVisible(
false );
890 maxSizeSpinBox->setVisible(
false );
891 mSizeUnitWidget->setVisible(
false );
897 lblColorRamp->setVisible(
false );
898 btnColorRamp->setVisible(
false );
899 lblSize->setVisible(
true );
900 minSizeSpinBox->setVisible(
true );
901 lblSizeTo->setVisible(
true );
902 maxSizeSpinBox->setVisible(
true );
903 mSizeUnitWidget->setVisible(
true );
909void QgsGraduatedSymbolRendererWidget::clearParameterWidgets()
911 while ( mParametersLayout->rowCount() )
913 QFormLayout::TakeRowResult row = mParametersLayout->takeRow( 0 );
914 for ( QLayoutItem *item : QList<QLayoutItem *>( {row.labelItem, row.fieldItem} ) )
917 QWidget *widget = item->widget();
923 mParameterWidgetWrappers.clear();
931 mModel->updateSymbology();
934 spinGraduatedClasses->setValue( mRenderer->ranges().count() );
947 mRenderer->setLegendSymbolItem( legendSymbol.ruleKey(), sym->
clone() );
950 mRenderer->setUsingSymbolLevels( enabled );
951 mModel->updateSymbology();
955void QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector(
QgsPanelWidget *container )
964void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
974 mSizeUnitWidget->blockSignals(
true );
975 mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
976 mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
977 mSizeUnitWidget->blockSignals(
false );
979 QItemSelectionModel *m = viewGraduated->selectionModel();
980 QModelIndexList selectedIndexes = m->selectedRows( 1 );
981 if ( !selectedIndexes.isEmpty() )
983 const auto constSelectedIndexes = selectedIndexes;
984 for (
const QModelIndex &idx : constSelectedIndexes )
988 int rangeIdx = idx.row();
989 QgsSymbol *newRangeSymbol = mGraduatedSymbol->clone();
990 if ( selectedIndexes.count() > 1 )
993 newRangeSymbol->
setColor( mRenderer->ranges().at( rangeIdx ).symbol()->color() );
995 mRenderer->updateRangeSymbol( rangeIdx, newRangeSymbol );
1001 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1008void QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished( )
1010 const QString text = cboSymmetryPoint->lineEdit()->text();
1011 int index = cboSymmetryPoint->findText( text );
1014 cboSymmetryPoint->setCurrentIndex( index );
1018 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), text );
1026 if ( mBlockUpdates )
1030 QString attrName = mExpressionWidget->currentField();
1031 int nclasses = spinGraduatedClasses->value();
1033 const QString methodId = cboGraduatedMode->currentData().toString();
1043 double minimum = minVal.toDouble();
1044 double maximum = maxVal.toDouble();
1045 mSymmetryPointValidator->
setBottom( minimum );
1046 mSymmetryPointValidator->
setTop( maximum );
1047 mSymmetryPointValidator->
setMaxDecimals( spinPrecision->value() );
1055 if ( currentValue < ( minimum + ( maximum - minimum ) / 100. ) || currentValue > ( maximum - ( maximum - minimum ) / 100. ) )
1056 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QLocale().toString( minimum + ( maximum - minimum ) / 2.,
'f', method->
labelPrecision() + 2 ) );
1059 if ( mGroupBoxSymmetric->isChecked() )
1062 bool astride = cbxAstride->isChecked();
1066 QVariantMap parameterValues;
1067 for (
const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
1072 mRenderer->setClassificationMethod( method );
1075 mRenderer->setClassAttribute( attrName );
1081 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 ) )
1087 if ( methodComboBox->currentData() == ColorMode )
1089 std::unique_ptr<QgsColorRamp> ramp( btnColorRamp->colorRamp() );
1092 QMessageBox::critical(
this, tr(
"Apply Classification" ), tr(
"No color ramp defined." ) );
1095 mRenderer->setSourceColorRamp( ramp.release() );
1099 mRenderer->setSourceColorRamp(
nullptr );
1102 mRenderer->updateClasses(
mLayer, nclasses );
1104 if ( methodComboBox->currentData() == SizeMode )
1105 mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
1107 mRenderer->calculateLabelPrecision();
1115 std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
1119 mRenderer->updateColorRamp( ramp.release() );
1120 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1126 mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
1127 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1132int QgsRendererPropertiesDialog::currentRangeRow()
1134 QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
1135 if ( !idx.isValid() )
1144 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1146 const auto constSelectedRows = selectedRows;
1147 for (
const QModelIndex &r : constSelectedRows )
1151 rows.append( r.row() );
1160 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1161 QModelIndexList::const_iterator sIt = selectedRows.constBegin();
1163 for ( ; sIt != selectedRows.constEnd(); ++sIt )
1172 if ( idx.isValid() && idx.column() == 0 )
1174 if ( idx.isValid() && idx.column() == 1 )
1180 if ( !idx.isValid() )
1183 mRowSelected = idx.row();
1193 std::unique_ptr< QgsSymbol > newSymbol( range.
symbol()->
clone() );
1210 if ( !dlg.exec() || !newSymbol )
1215 mGraduatedSymbol = std::move( newSymbol );
1216 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
1228 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
1229 if ( decimalPlaces < 0 ) decimalPlaces = 0;
1233 if ( dialog.exec() == QDialog::Accepted )
1239 if ( cbxLinkBoundaries->isChecked() )
1243 mRenderer->updateRangeUpperValue( rangeIdx - 1, dialog.
lowerValueDouble() );
1246 if ( rangeIdx < mRenderer->ranges().size() - 1 )
1248 mRenderer->updateRangeLowerValue( rangeIdx + 1, dialog.
upperValueDouble() );
1252 mHistogramWidget->refresh();
1258 mModel->addClass( mGraduatedSymbol.get() );
1259 mHistogramWidget->refresh();
1267 mModel->deleteRows( classIndexes );
1268 mHistogramWidget->refresh();
1274 mModel->removeAllRows();
1275 mHistogramWidget->refresh();
1282 bool ordered =
true;
1283 for (
int i = 1; i < ranges.size(); ++i )
1285 if ( ranges[i] < ranges[i - 1] )
1302 int result = QMessageBox::warning(
1304 tr(
"Link Class Boundaries" ),
1305 tr(
"Rows will be reordered before linking boundaries. Continue?" ),
1306 QMessageBox::Ok | QMessageBox::Cancel );
1307 if ( result != QMessageBox::Ok )
1309 cbxLinkBoundaries->setChecked(
false );
1312 mRenderer->sortByValue();
1316 for (
int i = 1; i < mRenderer->ranges().size(); ++i )
1318 mRenderer->updateRangeLowerValue( i, mRenderer->ranges()[i - 1].upperValue() );
1326 if ( item->column() == 2 )
1328 QString label = item->text();
1329 int idx = item->row();
1330 mRenderer->updateRangeLabel( idx, label );
1336 mRenderer->classificationMethod()->setLabelFormat( txtLegendFormat->text() );
1337 mRenderer->classificationMethod()->setLabelPrecision( spinPrecision->value() );
1338 mRenderer->classificationMethod()->setLabelTrimTrailingZeroes( cbxTrimTrailingZeroes->isChecked() );
1339 mRenderer->updateRangeLabels();
1340 mModel->updateLabels();
1348 QItemSelectionModel *m = viewGraduated->selectionModel();
1349 QModelIndexList selectedIndexes = m->selectedRows( 1 );
1350 if ( !selectedIndexes.isEmpty() )
1353 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
1354 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1356 QStringList list = m->model()->data( *indexIt ).toString().split(
' ' );
1357 if ( list.size() < 3 )
1382 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
1383 if ( decimalPlaces < 0 )
1385 double precision = 1.0 / std::pow( 10, decimalPlaces );
1387 for ( QgsRangeList::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
1391 return it->symbol();
1401 mModel->updateSymbology();
1403 mHistogramWidget->refresh();
1414 viewGraduated->selectionModel()->clear();
1417 cbxLinkBoundaries->setChecked(
false );
1434 if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
1436 mCopyBuffer.clear();
1439 else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
1441 QgsRangeList::const_iterator rIt = mCopyBuffer.constBegin();
1442 for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
1444 mModel->addClass( *rIt );
1450void QgsGraduatedSymbolRendererWidget::selectionChanged(
const QItemSelection &,
const QItemSelection & )
1453 if ( !ranges.isEmpty() )
1455 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( ranges.at( 0 ).symbol()->clone() );
1457 else if ( mRenderer->sourceSymbol() )
1459 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mRenderer->sourceSymbol()->clone() );
1461 btnChangeGraduatedSymbol->setDialogTitle( ranges.size() == 1 ? ranges.at( 0 ).label() : tr(
"Symbol Settings" ) );
1464void QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend()
1479void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
1481 mGraduatedSymbol.reset( btnChangeGraduatedSymbol->symbol()->clone() );
1491 const QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1492 for (
const QModelIndex &index : selectedRows )
1494 if ( !index.isValid() )
1497 const int row = index.row();
1498 if ( !mRenderer || mRenderer->ranges().size() <= row )
1501 if ( mRenderer->ranges().at( row ).symbol()->type() != tempSymbol->type() )
1504 std::unique_ptr< QgsSymbol > newCatSymbol( tempSymbol->clone() );
1505 if ( selectedRows.count() > 1 )
1508 newCatSymbol->setColor( mRenderer->ranges().at( row ).symbol()->color() );
1511 mRenderer->updateRangeSymbol( row, newCatSymbol.release() );
@ Size
Alter size of symbols.
@ Color
Alter color of symbols.
static QgsClassificationMethodRegistry * classificationMethodRegistry()
Returns the application's classification methods registry, used in graduated renderer.
static const QString METHOD_ID
QgsClassificationMethod * method(const QString &id)
Returns a new instance of the method for the given id.
QIcon icon(const QString &id) const
Returns the icon for a given method id.
QMap< QString, QString > methodNames() const
Returns a map <name, id> of all registered methods.
QgsClassificationMethod is an abstract class for implementations of classification methods.
double symmetryPoint() const
Returns the symmetry point for symmetric mode.
int codeComplexity() const
Code complexity as the exponent in Big O notation.
bool symmetricModeEnabled() const
Returns if the symmetric mode is enabled.
int labelPrecision() const
Returns the precision for the formatting of the labels.
virtual QString id() const =0
The id of the method as saved in the project, must be unique in registry.
QVariantMap parameterValues() const
Returns the values of the processing parameters.
void setSymmetricMode(bool enabled, double symmetryPoint=0, bool symmetryAstride=false)
Defines if the symmetric mode is enables and configures its parameters.
bool symmetryAstride() const
Returns if the symmetric mode is astride if true, it will remove the symmetry point break so that the...
static const int MIN_PRECISION
QString labelFormat() const
Returns the format of the label for the classes.
void setParameterValues(const QVariantMap &values)
Defines the values of the additional parameters.
static const int MAX_PRECISION
bool labelTrimTrailingZeroes() const
Returns if the trailing 0 are trimmed in the label.
@ IgnoresClassCount
The classification method does not compute classes based on a class count (since QGIS 3....
bool symmetricModeAvailable() const
Returns if the method supports symmetric calculation.
QgsClassificationMethod::MethodProperties flags() const
Returns the classification flags.
static const QString METHOD_ID
Abstract base class for color ramps.
QgsDoubleValidator is a QLineEdit Validator that combines QDoubleValidator and QRegularExpressionVali...
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
void setTop(double top)
Set top range limit.
void setMaxDecimals(int maxDecimals)
Sets the number of decimals accepted by the validator to maxDecimals.
void setBottom(double bottom)
Set top range limit.
Abstract interface for generating an expression context scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
@ Date
Date or datetime fields.
@ Numeric
All numeric fields.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
static QgsGraduatedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsGraduatedSymbolRenderer from an existing renderer.
const QgsRangeList & ranges() const
Returns a list of all ranges used in the classification.
static QgsProcessingGuiRegistry * processingGuiRegistry()
Returns the global processing gui registry, used for registering the GUI behavior of processing algor...
double upperValueDouble() const
Returns the upper value.
double lowerValueDouble() const
Returns the lower value.
void setLowerValue(const QString &val)
void setUpperValue(const QString &val)
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
The QgsMapSettings class contains configuration for rendering of the map.
A marker symbol type, for rendering Point and MultiPoint geometries.
Contains information about the context in which a processing algorithm is executed.
QgsAbstractProcessingParameterWidgetWrapper * createParameterWidgetWrapper(const QgsProcessingParameterDefinition *parameter, QgsProcessingGui::WidgetType type)
Creates a new parameter widget wrapper for the given parameter.
@ Standard
Standard algorithm dialog.
Base class for the definition of processing parameters.
QVariant defaultValueForGui() const
Returns the default value to use for the parameter in a GUI.
QString name() const
Returns the name of the parameter.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
QString label() const
Returns the label used for the range.
QgsSymbol * symbol() const
Returns the symbol used for the range.
bool renderState() const
Returns true if the range should be rendered.
double upperValue() const
Returns the upper bound of the range.
double lowerValue() const
Returns the lower bound of the range.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
Abstract base class for all rendered symbols.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
void setColor(const QColor &color) const
Sets the color for the symbol.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
@ RenderMapUnits
Map units.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
long long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
void minimumAndMaximumValue(int index, QVariant &minimum, QVariant &maximum) const
Calculates both the minimum and maximum value for an attribute column.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
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...
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QList< QgsRendererRange > QgsRangeList