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 = qgis::make_unique< QgsGraduatedSymbolRenderer >( QString(),
QgsRangeList() );
467 mSymmetryPointValidator =
new QDoubleValidator();
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, qgis::overload<int>::of( &QComboBox::currentIndexChanged ),
this, &QgsGraduatedSymbolRendererWidget::updateMethodParameters );
574 mGroupBoxSymmetric->setCollapsed(
true );
577 QMenu *advMenu =
new QMenu(
this );
579 advMenu->addAction( tr(
"Symbol Levels…" ),
this, SLOT(
showSymbolLevels() ) );
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();
643 connect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished,
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
645 for (
const auto &ppww : qgis::as_const( mParameterWidgetWrappers ) )
669 disconnect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished,
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
671 for (
const auto &ppww : qgis::as_const( mParameterWidgetWrappers ) )
686 int precision = spinPrecision->value() + 2;
687 while ( cboSymmetryPoint->count() )
688 cboSymmetryPoint->removeItem( 0 );
689 for (
int i = 0; i < ranges.count() - 1; i++ )
690 cboSymmetryPoint->addItem( QString::number( ranges.at( i ).upperValue(),
'f',
precision ), ranges.at( i ).upperValue() );
694 int idx = cboGraduatedMode->findData( method->
id() );
696 cboGraduatedMode->setCurrentIndex( idx );
702 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QLocale().toString( method->
symmetryPoint(),
'f', method->
labelPrecision() + 2 ) );
709 for (
const auto &ppww : qgis::as_const( mParameterWidgetWrappers ) )
713 ppww->setParameterValue( value,
context );
718 int nclasses = ranges.count();
719 if ( nclasses && updateCount )
721 spinGraduatedClasses->setValue( ranges.count() );
725 QString attrName = mRenderer->classAttribute();
726 mExpressionWidget->setField( attrName );
727 mHistogramWidget->setSourceFieldExp( attrName );
730 if ( mRenderer->sourceSymbol() )
732 mGraduatedSymbol.reset( mRenderer->sourceSymbol()->clone() );
733 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
736 mModel->setRenderer( mRenderer.get() );
737 viewGraduated->setModel( mModel );
739 connect( viewGraduated->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsGraduatedSymbolRendererWidget::selectionChanged );
741 if ( mGraduatedSymbol )
743 mSizeUnitWidget->blockSignals(
true );
744 mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
745 mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
746 mSizeUnitWidget->blockSignals(
false );
750 methodComboBox->blockSignals(
true );
751 switch ( mRenderer->graduatedMethod() )
755 methodComboBox->setCurrentIndex( methodComboBox->findData( ColorMode ) );
756 if ( mRenderer->sourceColorRamp() )
758 btnColorRamp->setColorRamp( mRenderer->sourceColorRamp() );
764 methodComboBox->setCurrentIndex( methodComboBox->findData( SizeMode ) );
765 if ( !mRenderer->ranges().isEmpty() )
767 minSizeSpinBox->setValue( mRenderer->minSymbolSize() );
768 maxSizeSpinBox->setValue( mRenderer->maxSymbolSize() );
773 toggleMethodWidgets(
static_cast< MethodMode
>( methodComboBox->currentData().toInt() ) );
774 methodComboBox->blockSignals(
false );
776 viewGraduated->resizeColumnToContents( 0 );
777 viewGraduated->resizeColumnToContents( 1 );
778 viewGraduated->resizeColumnToContents( 2 );
780 mHistogramWidget->refresh();
788 mRenderer->setClassAttribute(
field );
791 void QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged(
int )
793 const MethodMode newMethod =
static_cast< MethodMode
>( methodComboBox->currentData().toInt() );
794 toggleMethodWidgets( newMethod );
804 QMessageBox::critical(
this, tr(
"Select Method" ), tr(
"No color ramp defined." ) );
807 mRenderer->setSourceColorRamp( ramp );
814 lblColorRamp->setVisible(
false );
815 btnColorRamp->setVisible(
false );
816 lblSize->setVisible(
true );
817 minSizeSpinBox->setVisible(
true );
818 lblSize->setVisible(
true );
819 maxSizeSpinBox->setVisible(
true );
820 mSizeUnitWidget->setVisible(
true );
829 void QgsGraduatedSymbolRendererWidget::updateMethodParameters()
831 clearParameterWidgets();
833 const QString methodId = cboGraduatedMode->currentData().toString();
845 QVariant value = method->
parameterValues().value( def->name(), def->defaultValueForGui() );
850 mParameterWidgetWrappers.push_back( std::unique_ptr<QgsAbstractProcessingParameterWidgetWrapper>( ppww ) );
854 void QgsGraduatedSymbolRendererWidget::toggleMethodWidgets( MethodMode mode )
860 lblColorRamp->setVisible(
true );
861 btnColorRamp->setVisible(
true );
862 lblSize->setVisible(
false );
863 minSizeSpinBox->setVisible(
false );
864 lblSizeTo->setVisible(
false );
865 maxSizeSpinBox->setVisible(
false );
866 mSizeUnitWidget->setVisible(
false );
872 lblColorRamp->setVisible(
false );
873 btnColorRamp->setVisible(
false );
874 lblSize->setVisible(
true );
875 minSizeSpinBox->setVisible(
true );
876 lblSizeTo->setVisible(
true );
877 maxSizeSpinBox->setVisible(
true );
878 mSizeUnitWidget->setVisible(
true );
884 void QgsGraduatedSymbolRendererWidget::clearParameterWidgets()
886 while ( mParametersLayout->rowCount() )
888 QFormLayout::TakeRowResult row = mParametersLayout->takeRow( 0 );
889 for ( QLayoutItem *item : QList<QLayoutItem *>( {row.labelItem, row.fieldItem} ) )
892 if ( item->widget() )
893 item->widget()->deleteLater();
897 mParameterWidgetWrappers.clear();
905 mModel->updateSymbology();
908 spinGraduatedClasses->setValue( mRenderer->ranges().count() );
914 void QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector(
QgsPanelWidget *container )
923 void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
933 mSizeUnitWidget->blockSignals(
true );
934 mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
935 mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
936 mSizeUnitWidget->blockSignals(
false );
938 QItemSelectionModel *m = viewGraduated->selectionModel();
939 QModelIndexList selectedIndexes = m->selectedRows( 1 );
940 if ( !selectedIndexes.isEmpty() )
942 const auto constSelectedIndexes = selectedIndexes;
943 for (
const QModelIndex &idx : constSelectedIndexes )
947 int rangeIdx = idx.row();
948 QgsSymbol *newRangeSymbol = mGraduatedSymbol->clone();
949 if ( selectedIndexes.count() > 1 )
952 newRangeSymbol->
setColor( mRenderer->ranges().at( rangeIdx ).symbol()->color() );
954 mRenderer->updateRangeSymbol( rangeIdx, newRangeSymbol );
960 mRenderer->updateSymbols( mGraduatedSymbol.get() );
967 void QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished( )
969 const QString text = cboSymmetryPoint->lineEdit()->text();
970 int index = cboSymmetryPoint->findText( text );
973 cboSymmetryPoint->setCurrentIndex( index );
977 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), text );
987 QString attrName = mExpressionWidget->currentField();
988 int nclasses = spinGraduatedClasses->value();
990 const QString methodId = cboGraduatedMode->currentData().toString();
997 mSymmetryPointValidator->setBottom( minimum );
998 mSymmetryPointValidator->setTop( maximum );
999 mSymmetryPointValidator->setDecimals( spinPrecision->value() );
1007 if ( currentValue < ( minimum + ( maximum - minimum ) / 100. ) || currentValue > ( maximum - ( maximum - minimum ) / 100. ) )
1008 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QLocale().toString( minimum + ( maximum - minimum ) / 2.,
'f', method->
labelPrecision() + 2 ) );
1011 if ( mGroupBoxSymmetric->isChecked() )
1014 bool astride = cbxAstride->isChecked();
1018 QVariantMap parameterValues;
1019 for (
const auto &ppww : qgis::as_const( mParameterWidgetWrappers ) )
1024 mRenderer->setClassificationMethod( method );
1027 mRenderer->setClassAttribute( attrName );
1033 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 ) )
1039 if ( methodComboBox->currentData() == ColorMode )
1041 std::unique_ptr<QgsColorRamp> ramp( btnColorRamp->colorRamp() );
1044 QMessageBox::critical(
this, tr(
"Apply Classification" ), tr(
"No color ramp defined." ) );
1047 mRenderer->setSourceColorRamp( ramp.release() );
1051 mRenderer->setSourceColorRamp(
nullptr );
1054 mRenderer->updateClasses(
mLayer, nclasses );
1056 if ( methodComboBox->currentData() == SizeMode )
1057 mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
1059 mRenderer->calculateLabelPrecision();
1067 std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
1071 mRenderer->updateColorRamp( ramp.release() );
1072 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1078 mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
1079 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1084 int QgsRendererPropertiesDialog::currentRangeRow()
1086 QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
1087 if ( !idx.isValid() )
1096 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1098 const auto constSelectedRows = selectedRows;
1099 for (
const QModelIndex &r : constSelectedRows )
1103 rows.append( r.row() );
1112 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1113 QModelIndexList::const_iterator sIt = selectedRows.constBegin();
1115 for ( ; sIt != selectedRows.constEnd(); ++sIt )
1124 if ( idx.isValid() && idx.column() == 0 )
1126 if ( idx.isValid() && idx.column() == 1 )
1132 if ( !idx.isValid() )
1135 mRowSelected = idx.row();
1145 std::unique_ptr< QgsSymbol > newSymbol( range.
symbol()->
clone() );
1162 if ( !dlg.exec() || !newSymbol )
1167 mGraduatedSymbol = std::move( newSymbol );
1168 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
1180 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
1181 if ( decimalPlaces < 0 ) decimalPlaces = 0;
1185 if ( dialog.exec() == QDialog::Accepted )
1194 mRenderer->updateRangeUpperValue( rangeIdx, upperValue );
1195 mRenderer->updateRangeLowerValue( rangeIdx, lowerValue );
1198 if ( cbxLinkBoundaries->isChecked() )
1202 mRenderer->updateRangeUpperValue( rangeIdx - 1, lowerValue );
1205 if ( rangeIdx < mRenderer->ranges().size() - 1 )
1207 mRenderer->updateRangeLowerValue( rangeIdx + 1, upperValue );
1211 mHistogramWidget->refresh();
1217 mModel->addClass( mGraduatedSymbol.get() );
1218 mHistogramWidget->refresh();
1226 mModel->deleteRows( classIndexes );
1227 mHistogramWidget->refresh();
1233 mModel->removeAllRows();
1234 mHistogramWidget->refresh();
1241 bool ordered =
true;
1242 for (
int i = 1; i < ranges.size(); ++i )
1244 if ( ranges[i] < ranges[i - 1] )
1261 int result = QMessageBox::warning(
1263 tr(
"Link Class Boundaries" ),
1264 tr(
"Rows will be reordered before linking boundaries. Continue?" ),
1265 QMessageBox::Ok | QMessageBox::Cancel );
1266 if ( result != QMessageBox::Ok )
1268 cbxLinkBoundaries->setChecked(
false );
1271 mRenderer->sortByValue();
1275 for (
int i = 1; i < mRenderer->ranges().size(); ++i )
1277 mRenderer->updateRangeLowerValue( i, mRenderer->ranges()[i - 1].upperValue() );
1285 if ( item->column() == 2 )
1287 QString label = item->text();
1288 int idx = item->row();
1289 mRenderer->updateRangeLabel( idx, label );
1295 mRenderer->classificationMethod()->setLabelFormat( txtLegendFormat->text() );
1296 mRenderer->classificationMethod()->setLabelPrecision( spinPrecision->value() );
1297 mRenderer->classificationMethod()->setLabelTrimTrailingZeroes( cbxTrimTrailingZeroes->isChecked() );
1298 mRenderer->updateRangeLabels();
1299 mModel->updateLabels();
1307 QItemSelectionModel *m = viewGraduated->selectionModel();
1308 QModelIndexList selectedIndexes = m->selectedRows( 1 );
1309 if ( !selectedIndexes.isEmpty() )
1312 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
1313 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1315 QStringList list = m->model()->data( *indexIt ).toString().split(
' ' );
1316 if ( list.size() < 3 )
1341 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
1342 if ( decimalPlaces < 0 )
1344 double precision = 1.0 / std::pow( 10, decimalPlaces );
1346 for ( QgsRangeList::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
1350 return it->symbol();
1360 mModel->updateSymbology();
1362 mHistogramWidget->refresh();
1373 viewGraduated->selectionModel()->clear();
1376 cbxLinkBoundaries->setChecked(
false );
1393 if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
1395 mCopyBuffer.clear();
1398 else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
1400 QgsRangeList::const_iterator rIt = mCopyBuffer.constBegin();
1401 for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
1403 mModel->addClass( *rIt );
1409 void QgsGraduatedSymbolRendererWidget::selectionChanged(
const QItemSelection &,
const QItemSelection & )
1412 if ( !ranges.isEmpty() )
1414 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( ranges.at( 0 ).symbol()->clone() );
1416 else if ( mRenderer->sourceSymbol() )
1418 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mRenderer->sourceSymbol()->clone() );
1420 btnChangeGraduatedSymbol->setDialogTitle( ranges.size() == 1 ? ranges.at( 0 ).label() : tr(
"Symbol Settings" ) );
1423 void QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend()
1438 void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
1440 mGraduatedSymbol.reset( btnChangeGraduatedSymbol->symbol()->clone() );
1450 const QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1451 for (
const QModelIndex &index : selectedRows )
1453 if ( !index.isValid() )
1456 const int row = index.row();
1457 if ( !mRenderer || mRenderer->ranges().size() <= row )
1460 if ( mRenderer->ranges().at( row ).symbol()->type() != tempSymbol->type() )
1463 std::unique_ptr< QgsSymbol > newCatSymbol( tempSymbol->clone() );
1464 if ( selectedRows.count() > 1 )
1467 newCatSymbol->setColor( mRenderer->ranges().at( row ).symbol()->color() );
1470 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 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.
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.
QVariant maximumValue(int index) const FINAL
Returns the maximum value for an attribute column or an invalid variant in case of error.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QVariant minimumValue(int index) const FINAL
Returns the minimum value for an attribute column or an invalid variant in case of error.
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
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< QgsRendererRange > QgsRangeList