18 #include <QMessageBox> 
   19 #include <QStandardItemModel> 
   20 #include <QStandardItem> 
   63 QgsGraduatedSymbolRendererModel::QgsGraduatedSymbolRendererModel( QObject *parent ) : QAbstractItemModel( parent )
 
   64   , mMimeFormat( QStringLiteral( 
"application/x-qgsgraduatedsymbolrendererv2model" ) )
 
   72     if ( !mRenderer->ranges().isEmpty() )
 
   74       beginRemoveRows( QModelIndex(), 0, mRenderer->ranges().size() - 1 );
 
   85     if ( !renderer->
ranges().isEmpty() )
 
   87       beginInsertRows( QModelIndex(), 0, renderer->
ranges().size() - 1 );
 
   98 void QgsGraduatedSymbolRendererModel::addClass( 
QgsSymbol *symbol )
 
  100   if ( !mRenderer ) 
return;
 
  101   int idx = mRenderer->
ranges().size();
 
  102   beginInsertRows( QModelIndex(), idx, idx );
 
  103   mRenderer->addClass( symbol );
 
  107 void QgsGraduatedSymbolRendererModel::addClass( 
const QgsRendererRange &range )
 
  113   int idx = mRenderer->ranges().size();
 
  114   beginInsertRows( QModelIndex(), idx, idx );
 
  115   mRenderer->addClass( range );
 
  119 QgsRendererRange QgsGraduatedSymbolRendererModel::rendererRange( 
const QModelIndex &index )
 
  121   if ( !index.isValid() || !mRenderer || mRenderer->ranges().size() <= index.row() )
 
  126   return mRenderer->ranges().value( index.row() );
 
  129 Qt::ItemFlags QgsGraduatedSymbolRendererModel::flags( 
const QModelIndex &index )
 const 
  131   if ( !index.isValid() )
 
  133     return Qt::ItemIsDropEnabled;
 
  136   Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;
 
  138   if ( index.column() == 2 )
 
  140     flags |= Qt::ItemIsEditable;
 
  146 Qt::DropActions QgsGraduatedSymbolRendererModel::supportedDropActions()
 const 
  148   return Qt::MoveAction;
 
  151 QVariant QgsGraduatedSymbolRendererModel::data( 
const QModelIndex &index, 
int role )
 const 
  153   if ( !index.isValid() || !mRenderer ) 
return QVariant();
 
  157   if ( role == Qt::CheckStateRole && index.column() == 0 )
 
  159     return range.
renderState() ? Qt::Checked : Qt::Unchecked;
 
  161   else if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
 
  163     switch ( index.column() )
 
  167         int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
 
  168         if ( decimalPlaces < 0 ) decimalPlaces = 0;
 
  169         return QString( QLocale().toString( range.
lowerValue(), 
'f', decimalPlaces ) + 
" - " + QLocale().toString( range.
upperValue(), 
'f', decimalPlaces ) );
 
  172         return range.
label();
 
  177   else if ( role == Qt::DecorationRole && index.column() == 0 && range.
symbol() )
 
  182   else if ( role == Qt::TextAlignmentRole )
 
  184     return ( index.column() == 0 ) ? Qt::AlignHCenter : Qt::AlignLeft;
 
  186   else if ( role == Qt::EditRole )
 
  188     switch ( index.column() )
 
  192         return range.
label();
 
  201 bool QgsGraduatedSymbolRendererModel::setData( 
const QModelIndex &index, 
const QVariant &value, 
int role )
 
  203   if ( !index.isValid() )
 
  206   if ( index.column() == 0 && role == Qt::CheckStateRole )
 
  208     mRenderer->updateRangeRenderState( index.row(), value == Qt::Checked );
 
  209     emit dataChanged( index, index );
 
  213   if ( role != Qt::EditRole )
 
  216   switch ( index.column() )
 
  221       mRenderer->updateRangeLabel( index.row(), value.toString() );
 
  227   emit dataChanged( index, index );
 
  231 QVariant QgsGraduatedSymbolRendererModel::headerData( 
int section, Qt::Orientation orientation, 
int role )
 const 
  233   if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
 
  236     lst << tr( 
"Symbol" ) << tr( 
"Values" ) << tr( 
"Legend" );
 
  237     return lst.value( section );
 
  242 int QgsGraduatedSymbolRendererModel::rowCount( 
const QModelIndex &parent )
 const 
  244   if ( parent.isValid() || !mRenderer )
 
  248   return mRenderer->ranges().size();
 
  251 int QgsGraduatedSymbolRendererModel::columnCount( 
const QModelIndex &index )
 const 
  257 QModelIndex QgsGraduatedSymbolRendererModel::index( 
int row, 
int column, 
const QModelIndex &parent )
 const 
  259   if ( hasIndex( row, column, parent ) )
 
  261     return createIndex( row, column );
 
  263   return QModelIndex();
 
  266 QModelIndex QgsGraduatedSymbolRendererModel::parent( 
const QModelIndex &index )
 const 
  269   return QModelIndex();
 
  272 QStringList QgsGraduatedSymbolRendererModel::mimeTypes()
 const 
  275   types << mMimeFormat;
 
  279 QMimeData *QgsGraduatedSymbolRendererModel::mimeData( 
const QModelIndexList &indexes )
 const 
  281   QMimeData *mimeData = 
new QMimeData();
 
  282   QByteArray encodedData;
 
  284   QDataStream stream( &encodedData, QIODevice::WriteOnly );
 
  287   const auto constIndexes = indexes;
 
  288   for ( 
const QModelIndex &index : constIndexes )
 
  290     if ( !index.isValid() || index.column() != 0 )
 
  293     stream << index.row();
 
  295   mimeData->setData( mMimeFormat, encodedData );
 
  299 bool QgsGraduatedSymbolRendererModel::dropMimeData( 
const QMimeData *data, Qt::DropAction action, 
int row, 
int column, 
const QModelIndex &parent )
 
  303   if ( action != Qt::MoveAction ) 
return true;
 
  305   if ( !data->hasFormat( mMimeFormat ) ) 
return false;
 
  307   QByteArray encodedData = data->data( mMimeFormat );
 
  308   QDataStream stream( &encodedData, QIODevice::ReadOnly );
 
  311   while ( !stream.atEnd() )
 
  318   int to = parent.row();
 
  321   if ( to == -1 ) to = mRenderer->ranges().size(); 
 
  322   for ( 
int i = rows.size() - 1; i >= 0; i-- )
 
  324     QgsDebugMsg( QStringLiteral( 
"move %1 to %2" ).arg( rows[i] ).arg( to ) );
 
  327     if ( rows[i] < t ) t--;
 
  328     mRenderer->moveClass( rows[i], t );
 
  330     for ( 
int j = 0; j < i; j++ )
 
  332       if ( to < rows[j] && rows[i] > rows[j] ) rows[j] += 1;
 
  335     if ( rows[i] < to ) to--;
 
  337   emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->ranges().size(), 0 ) );
 
  342 void QgsGraduatedSymbolRendererModel::deleteRows( QList<int> rows )
 
  344   for ( 
int i = rows.size() - 1; i >= 0; i-- )
 
  346     beginRemoveRows( QModelIndex(), rows[i], rows[i] );
 
  347     mRenderer->deleteClass( rows[i] );
 
  352 void QgsGraduatedSymbolRendererModel::removeAllRows()
 
  354   beginRemoveRows( QModelIndex(), 0, mRenderer->ranges().size() - 1 );
 
  355   mRenderer->deleteAllClasses();
 
  359 void QgsGraduatedSymbolRendererModel::sort( 
int column, Qt::SortOrder order )
 
  367     mRenderer->sortByValue( order );
 
  369   else if ( column == 2 )
 
  371     mRenderer->sortByLabel( order );
 
  374   emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->ranges().size(), 0 ) );
 
  377 void QgsGraduatedSymbolRendererModel::updateSymbology()
 
  379   emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->ranges().size(), 0 ) );
 
  382 void QgsGraduatedSymbolRendererModel::updateLabels()
 
  384   emit dataChanged( createIndex( 0, 2 ), createIndex( mRenderer->ranges().size(), 2 ) );
 
  388 QgsGraduatedSymbolRendererViewStyle::QgsGraduatedSymbolRendererViewStyle( QWidget *parent )
 
  392 void QgsGraduatedSymbolRendererViewStyle::drawPrimitive( PrimitiveElement element, 
const QStyleOption *option, QPainter *painter, 
const QWidget *widget )
 const 
  394   if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
 
  396     QStyleOption opt( *option );
 
  397     opt.rect.setLeft( 0 );
 
  399     opt.rect.setHeight( 0 );
 
  400     if ( widget ) opt.rect.setRight( widget->width() );
 
  401     QProxyStyle::drawPrimitive( element, &opt, painter, widget );
 
  404   QProxyStyle::drawPrimitive( element, option, painter, widget );
 
  429       expContext << generator->createExpressionContextScope();
 
  461     mRenderer = std::make_unique< QgsGraduatedSymbolRenderer >( QString(), 
QgsRangeList() );
 
  467   mSymmetryPointValidator = 
new QDoubleValidator( 
this );
 
  468   cboSymmetryPoint->setEditable( 
true );
 
  469   cboSymmetryPoint->setValidator( mSymmetryPointValidator );
 
  472   for ( QMap<QString, QString>::const_iterator it = methods.constBegin(); it != methods.constEnd(); ++it )
 
  475     cboGraduatedMode->addItem( icon, it.key(), it.value() );
 
  478   connect( methodComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged );
 
  479   this->layout()->setContentsMargins( 0, 0, 0, 0 );
 
  481   mModel = 
new QgsGraduatedSymbolRendererModel( 
this );
 
  484   mExpressionWidget->setLayer( 
mLayer );
 
  486   btnChangeGraduatedSymbol->setLayer( 
mLayer );
 
  487   btnChangeGraduatedSymbol->registerExpressionContextGenerator( 
this );
 
  494   spinPrecision->setClearValue( 4 );
 
  496   spinGraduatedClasses->setShowClearButton( 
false );
 
  498   btnColorRamp->setShowRandomColorRamp( 
true );
 
  501   QString defaultColorRamp = 
QgsProject::instance()->
readEntry( QStringLiteral( 
"DefaultStyles" ), QStringLiteral( 
"/ColorRamp" ), QString() );
 
  502   if ( !defaultColorRamp.isEmpty() )
 
  504     btnColorRamp->setColorRampFromName( defaultColorRamp );
 
  509     btnColorRamp->setColorRamp( ramp );
 
  514   viewGraduated->setStyle( 
new QgsGraduatedSymbolRendererViewStyle( viewGraduated ) );
 
  517   if ( mGraduatedSymbol )
 
  519     btnChangeGraduatedSymbol->setSymbolType( mGraduatedSymbol->type() );
 
  520     btnChangeGraduatedSymbol->setSymbol( mGraduatedSymbol->clone() );
 
  522     methodComboBox->blockSignals( 
true );
 
  523     methodComboBox->addItem( tr( 
"Color" ), ColorMode );
 
  524     switch ( mGraduatedSymbol->type() )
 
  528         methodComboBox->addItem( tr( 
"Size" ), SizeMode );
 
  529         minSizeSpinBox->setValue( 1 );
 
  530         maxSizeSpinBox->setValue( 8 );
 
  535         methodComboBox->addItem( tr( 
"Size" ), SizeMode );
 
  536         minSizeSpinBox->setValue( .1 );
 
  537         maxSizeSpinBox->setValue( 2 );
 
  543         methodComboBox->hide();
 
  550     methodComboBox->blockSignals( 
false );
 
  559   connect( btnChangeGraduatedSymbol, &
QgsSymbolButton::changed, 
this, &QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol );
 
  566   connect( cboGraduatedMode, qOverload<int>( &QComboBox::currentIndexChanged ), 
this, &QgsGraduatedSymbolRendererWidget::updateMethodParameters );
 
  574   mGroupBoxSymmetric->setCollapsed( 
true ); 
 
  577   QMenu *advMenu = 
new QMenu( 
this );
 
  582     QAction *actionDdsLegend = advMenu->addAction( tr( 
"Data-defined Size Legend…" ) );
 
  584     connect( actionDdsLegend, &QAction::triggered, 
this, &QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend );
 
  587   btnAdvanced->setMenu( advMenu );
 
  589   mHistogramWidget->setLayer( 
mLayer );
 
  590   mHistogramWidget->setRenderer( mRenderer.get() );
 
  594   mExpressionWidget->registerExpressionContextGenerator( 
this );
 
  597 void QgsGraduatedSymbolRendererWidget::mSizeUnitWidget_changed()
 
  599   if ( !mGraduatedSymbol )
 
  601   mGraduatedSymbol->setOutputUnit( mSizeUnitWidget->unit() );
 
  602   mGraduatedSymbol->setMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
 
  603   mRenderer->updateSymbols( mGraduatedSymbol.get() );
 
  610   mParameterWidgetWrappers.clear();
 
  615   return mRenderer.get();
 
  627   delete mActionLevels;
 
  628   mActionLevels = 
nullptr;
 
  649   connect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished, 
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
 
  651   for ( 
const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
 
  675   disconnect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished, 
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
 
  677   for ( 
const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
 
  692   int precision = spinPrecision->value() + 2;
 
  693   while ( cboSymmetryPoint->count() )
 
  694     cboSymmetryPoint->removeItem( 0 );
 
  695   for ( 
int i = 0; i < ranges.count() - 1; i++ )
 
  696     cboSymmetryPoint->addItem( QString::number( ranges.at( i ).upperValue(), 
'f', 
precision ), ranges.at( i ).upperValue() );
 
  700     int idx = cboGraduatedMode->findData( method->
id() );
 
  702       cboGraduatedMode->setCurrentIndex( idx );
 
  708       cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QLocale().toString( method->
symmetryPoint(), 
'f', method->
labelPrecision() + 2 ) );
 
  715     for ( 
const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
 
  719       ppww->setParameterValue( value, 
context );
 
  724   int nclasses = ranges.count();
 
  725   if ( nclasses && updateCount )
 
  727     spinGraduatedClasses->setValue( ranges.count() );
 
  731   QString attrName = mRenderer->classAttribute();
 
  732   mExpressionWidget->setField( attrName );
 
  733   mHistogramWidget->setSourceFieldExp( attrName );
 
  736   if ( mRenderer->sourceSymbol() )
 
  738     mGraduatedSymbol.reset( mRenderer->sourceSymbol()->clone() );
 
  739     whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
 
  742   mModel->setRenderer( mRenderer.get() );
 
  743   viewGraduated->setModel( mModel );
 
  745   connect( viewGraduated->selectionModel(), &QItemSelectionModel::selectionChanged, 
this, &QgsGraduatedSymbolRendererWidget::selectionChanged );
 
  747   if ( mGraduatedSymbol )
 
  749     mSizeUnitWidget->blockSignals( 
true );
 
  750     mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
 
  751     mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
 
  752     mSizeUnitWidget->blockSignals( 
false );
 
  756   methodComboBox->blockSignals( 
true );
 
  757   switch ( mRenderer->graduatedMethod() )
 
  761       methodComboBox->setCurrentIndex( methodComboBox->findData( ColorMode ) );
 
  762       if ( mRenderer->sourceColorRamp() )
 
  764         btnColorRamp->setColorRamp( mRenderer->sourceColorRamp() );
 
  770       methodComboBox->setCurrentIndex( methodComboBox->findData( SizeMode ) );
 
  771       if ( !mRenderer->ranges().isEmpty() ) 
 
  773         minSizeSpinBox->setValue( mRenderer->minSymbolSize() );
 
  774         maxSizeSpinBox->setValue( mRenderer->maxSymbolSize() );
 
  779   toggleMethodWidgets( 
static_cast< MethodMode
>( methodComboBox->currentData().toInt() ) );
 
  780   methodComboBox->blockSignals( 
false );
 
  782   viewGraduated->resizeColumnToContents( 0 );
 
  783   viewGraduated->resizeColumnToContents( 1 );
 
  784   viewGraduated->resizeColumnToContents( 2 );
 
  786   mHistogramWidget->refresh();
 
  794   mRenderer->setClassAttribute( 
field );
 
  797 void QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged( 
int )
 
  799   const MethodMode newMethod = 
static_cast< MethodMode 
>( methodComboBox->currentData().toInt() );
 
  800   toggleMethodWidgets( newMethod );
 
  810         QMessageBox::critical( 
this, tr( 
"Select Method" ), tr( 
"No color ramp defined." ) );
 
  813       mRenderer->setSourceColorRamp( ramp );
 
  820       lblColorRamp->setVisible( 
false );
 
  821       btnColorRamp->setVisible( 
false );
 
  822       lblSize->setVisible( 
true );
 
  823       minSizeSpinBox->setVisible( 
true );
 
  824       lblSize->setVisible( 
true );
 
  825       maxSizeSpinBox->setVisible( 
true );
 
  826       mSizeUnitWidget->setVisible( 
true );
 
  835 void QgsGraduatedSymbolRendererWidget::updateMethodParameters()
 
  837   clearParameterWidgets();
 
  839   const QString methodId = cboGraduatedMode->currentData().toString();
 
  851     QVariant value = method->
parameterValues().value( def->name(), def->defaultValueForGui() );
 
  856     mParameterWidgetWrappers.push_back( std::unique_ptr<QgsAbstractProcessingParameterWidgetWrapper>( ppww ) );
 
  860 void QgsGraduatedSymbolRendererWidget::toggleMethodWidgets( MethodMode mode )
 
  866       lblColorRamp->setVisible( 
true );
 
  867       btnColorRamp->setVisible( 
true );
 
  868       lblSize->setVisible( 
false );
 
  869       minSizeSpinBox->setVisible( 
false );
 
  870       lblSizeTo->setVisible( 
false );
 
  871       maxSizeSpinBox->setVisible( 
false );
 
  872       mSizeUnitWidget->setVisible( 
false );
 
  878       lblColorRamp->setVisible( 
false );
 
  879       btnColorRamp->setVisible( 
false );
 
  880       lblSize->setVisible( 
true );
 
  881       minSizeSpinBox->setVisible( 
true );
 
  882       lblSizeTo->setVisible( 
true );
 
  883       maxSizeSpinBox->setVisible( 
true );
 
  884       mSizeUnitWidget->setVisible( 
true );
 
  890 void QgsGraduatedSymbolRendererWidget::clearParameterWidgets()
 
  892   while ( mParametersLayout->rowCount() )
 
  894     QFormLayout::TakeRowResult row = mParametersLayout->takeRow( 0 );
 
  895     for ( QLayoutItem *item : QList<QLayoutItem *>( {row.labelItem, row.fieldItem} ) )
 
  898         if ( item->widget() )
 
  899           item->widget()->deleteLater();
 
  903   mParameterWidgetWrappers.clear();
 
  911   mModel->updateSymbology();
 
  914   spinGraduatedClasses->setValue( mRenderer->ranges().count() );
 
  927       mRenderer->setLegendSymbolItem( legendSymbol.ruleKey(), sym->
clone() );
 
  930   mRenderer->setUsingSymbolLevels( enabled );
 
  931   mModel->updateSymbology();
 
  935 void QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector( 
QgsPanelWidget *container )
 
  944 void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
 
  954   mSizeUnitWidget->blockSignals( 
true );
 
  955   mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
 
  956   mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
 
  957   mSizeUnitWidget->blockSignals( 
false );
 
  959   QItemSelectionModel *m = viewGraduated->selectionModel();
 
  960   QModelIndexList selectedIndexes = m->selectedRows( 1 );
 
  961   if ( !selectedIndexes.isEmpty() )
 
  963     const auto constSelectedIndexes = selectedIndexes;
 
  964     for ( 
const QModelIndex &idx : constSelectedIndexes )
 
  968         int rangeIdx = idx.row();
 
  969         QgsSymbol *newRangeSymbol = mGraduatedSymbol->clone();
 
  970         if ( selectedIndexes.count() > 1 )
 
  973           newRangeSymbol->
setColor( mRenderer->ranges().at( rangeIdx ).symbol()->color() );
 
  975         mRenderer->updateRangeSymbol( rangeIdx, newRangeSymbol );
 
  981     mRenderer->updateSymbols( mGraduatedSymbol.get() );
 
  988 void QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished( )
 
  990   const QString text = cboSymmetryPoint->lineEdit()->text();
 
  991   int index = cboSymmetryPoint->findText( text );
 
  994     cboSymmetryPoint->setCurrentIndex( index );
 
  998     cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), text );
 
 1008   QString attrName = mExpressionWidget->currentField();
 
 1009   int nclasses = spinGraduatedClasses->value();
 
 1011   const QString methodId = cboGraduatedMode->currentData().toString();
 
 1021   double minimum = minVal.toDouble();
 
 1022   double maximum = maxVal.toDouble();
 
 1023   mSymmetryPointValidator->setBottom( minimum );
 
 1024   mSymmetryPointValidator->setTop( maximum );
 
 1025   mSymmetryPointValidator->setDecimals( spinPrecision->value() );
 
 1033     if ( currentValue < ( minimum + ( maximum - minimum ) / 100. ) || currentValue > ( maximum - ( maximum - minimum ) / 100. ) )
 
 1034       cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QLocale().toString( minimum + ( maximum - minimum ) / 2., 
'f', method->
labelPrecision() + 2 ) );
 
 1037   if ( mGroupBoxSymmetric->isChecked() )
 
 1040     bool astride = cbxAstride->isChecked();
 
 1044   QVariantMap parameterValues;
 
 1045   for ( 
const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
 
 1050   mRenderer->setClassificationMethod( method );
 
 1053   mRenderer->setClassAttribute( attrName );
 
 1059     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 ) )
 
 1065   if ( methodComboBox->currentData() == ColorMode )
 
 1067     std::unique_ptr<QgsColorRamp> ramp( btnColorRamp->colorRamp() );
 
 1070       QMessageBox::critical( 
this, tr( 
"Apply Classification" ), tr( 
"No color ramp defined." ) );
 
 1073     mRenderer->setSourceColorRamp( ramp.release() );
 
 1077     mRenderer->setSourceColorRamp( 
nullptr );
 
 1080   mRenderer->updateClasses( 
mLayer, nclasses );
 
 1082   if ( methodComboBox->currentData() == SizeMode )
 
 1083     mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
 
 1085   mRenderer->calculateLabelPrecision();
 
 1093   std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
 
 1097   mRenderer->updateColorRamp( ramp.release() );
 
 1098   mRenderer->updateSymbols( mGraduatedSymbol.get() );
 
 1104   mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
 
 1105   mRenderer->updateSymbols( mGraduatedSymbol.get() );
 
 1110 int QgsRendererPropertiesDialog::currentRangeRow()
 
 1112   QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
 
 1113   if ( !idx.isValid() )
 
 1122   QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
 
 1124   const auto constSelectedRows = selectedRows;
 
 1125   for ( 
const QModelIndex &r : constSelectedRows )
 
 1129       rows.append( r.row() );
 
 1138   QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
 
 1139   QModelIndexList::const_iterator sIt = selectedRows.constBegin();
 
 1141   for ( ; sIt != selectedRows.constEnd(); ++sIt )
 
 1150   if ( idx.isValid() && idx.column() == 0 )
 
 1152   if ( idx.isValid() && idx.column() == 1 )
 
 1158   if ( !idx.isValid() )
 
 1161     mRowSelected = idx.row();
 
 1171   std::unique_ptr< QgsSymbol > newSymbol( range.
symbol()->
clone() );
 
 1188     if ( !dlg.exec() || !newSymbol )
 
 1193     mGraduatedSymbol = std::move( newSymbol );
 
 1194     whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
 
 1206   int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
 
 1207   if ( decimalPlaces < 0 ) decimalPlaces = 0;
 
 1211   if ( dialog.exec() == QDialog::Accepted )
 
 1220     mRenderer->updateRangeUpperValue( rangeIdx, upperValue );
 
 1221     mRenderer->updateRangeLowerValue( rangeIdx, lowerValue );
 
 1224     if ( cbxLinkBoundaries->isChecked() )
 
 1228         mRenderer->updateRangeUpperValue( rangeIdx - 1, lowerValue );
 
 1231       if ( rangeIdx < mRenderer->ranges().size() - 1 )
 
 1233         mRenderer->updateRangeLowerValue( rangeIdx + 1, upperValue );
 
 1237   mHistogramWidget->refresh();
 
 1243   mModel->addClass( mGraduatedSymbol.get() );
 
 1244   mHistogramWidget->refresh();
 
 1252   mModel->deleteRows( classIndexes );
 
 1253   mHistogramWidget->refresh();
 
 1259   mModel->removeAllRows();
 
 1260   mHistogramWidget->refresh();
 
 1267   bool ordered = 
true;
 
 1268   for ( 
int i = 1; i < ranges.size(); ++i )
 
 1270     if ( ranges[i] < ranges[i - 1] )
 
 1287       int result = QMessageBox::warning(
 
 1289                      tr( 
"Link Class Boundaries" ),
 
 1290                      tr( 
"Rows will be reordered before linking boundaries. Continue?" ),
 
 1291                      QMessageBox::Ok | QMessageBox::Cancel );
 
 1292       if ( result != QMessageBox::Ok )
 
 1294         cbxLinkBoundaries->setChecked( 
false );
 
 1297       mRenderer->sortByValue();
 
 1301     for ( 
int i = 1; i < mRenderer->ranges().size(); ++i )
 
 1303       mRenderer->updateRangeLowerValue( i, mRenderer->ranges()[i - 1].upperValue() );
 
 1311   if ( item->column() == 2 )
 
 1313     QString label = item->text();
 
 1314     int idx = item->row();
 
 1315     mRenderer->updateRangeLabel( idx, label );
 
 1321   mRenderer->classificationMethod()->setLabelFormat( txtLegendFormat->text() );
 
 1322   mRenderer->classificationMethod()->setLabelPrecision( spinPrecision->value() );
 
 1323   mRenderer->classificationMethod()->setLabelTrimTrailingZeroes( cbxTrimTrailingZeroes->isChecked() );
 
 1324   mRenderer->updateRangeLabels();
 
 1325   mModel->updateLabels();
 
 1333   QItemSelectionModel *m = viewGraduated->selectionModel();
 
 1334   QModelIndexList selectedIndexes = m->selectedRows( 1 );
 
 1335   if ( !selectedIndexes.isEmpty() )
 
 1338     QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
 
 1339     for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
 
 1341       QStringList list = m->model()->data( *indexIt ).toString().split( 
' ' );
 
 1342       if ( list.size() < 3 )
 
 1367   int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
 
 1368   if ( decimalPlaces < 0 )
 
 1370   double precision = 1.0 / std::pow( 10, decimalPlaces );
 
 1372   for ( QgsRangeList::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
 
 1376       return it->symbol();
 
 1386     mModel->updateSymbology();
 
 1388   mHistogramWidget->refresh();
 
 1399   viewGraduated->selectionModel()->clear();
 
 1402     cbxLinkBoundaries->setChecked( 
false );
 
 1419   if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
 
 1421     mCopyBuffer.clear();
 
 1424   else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
 
 1426     QgsRangeList::const_iterator rIt = mCopyBuffer.constBegin();
 
 1427     for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
 
 1429       mModel->addClass( *rIt );
 
 1435 void QgsGraduatedSymbolRendererWidget::selectionChanged( 
const QItemSelection &, 
const QItemSelection & )
 
 1438   if ( !ranges.isEmpty() )
 
 1440     whileBlocking( btnChangeGraduatedSymbol )->setSymbol( ranges.at( 0 ).symbol()->clone() );
 
 1442   else if ( mRenderer->sourceSymbol() )
 
 1444     whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mRenderer->sourceSymbol()->clone() );
 
 1446   btnChangeGraduatedSymbol->setDialogTitle( ranges.size() == 1 ? ranges.at( 0 ).label() : tr( 
"Symbol Settings" ) );
 
 1449 void QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend()
 
 1464 void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
 
 1466   mGraduatedSymbol.reset( btnChangeGraduatedSymbol->symbol()->clone() );
 
 1476   const QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
 
 1477   for ( 
const QModelIndex &index : selectedRows )
 
 1479     if ( !index.isValid() )
 
 1482     const int row = index.row();
 
 1483     if ( !mRenderer || mRenderer->ranges().size() <= row )
 
 1486     if ( mRenderer->ranges().at( row ).symbol()->type() != tempSymbol->type() )
 
 1489     std::unique_ptr< QgsSymbol > newCatSymbol( tempSymbol->clone() );
 
 1490     if ( selectedRows.count() > 1 )
 
 1493       newCatSymbol->setColor( mRenderer->ranges().at( row ).symbol()->color() );
 
 1496     mRenderer->updateRangeSymbol( row, newCatSymbol.release() );
 
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.
QgsProcessingParameterDefinitions parameterDefinitions() const
Returns the list of parameters.
bool symmetricModeAvailable() const
Returns if the method supports symmetric calculation.
static const QString METHOD_ID
Abstract base class for color ramps.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
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.
@ 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
static QgsProcessingGuiRegistry * processingGuiRegistry()
Returns the global processing gui registry, used for registering the GUI behavior of processing algor...
QString upperValue() const
QString lowerValue() const
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.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style,...
QgsSymbol * symbol() const
double upperValue() const
double lowerValue() const
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)
Sets the color for the symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this 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