18 #include <QMessageBox> 19 #include <QStandardItemModel> 20 #include <QStandardItem> 54 QgsGraduatedSymbolRendererModel::QgsGraduatedSymbolRendererModel( QObject *parent ) : QAbstractItemModel( parent )
55 , mMimeFormat( QStringLiteral(
"application/x-qgsgraduatedsymbolrendererv2model" ) )
63 if ( !mRenderer->
ranges().isEmpty() )
65 beginRemoveRows( QModelIndex(), 0, mRenderer->
ranges().size() - 1 );
76 if ( !renderer->
ranges().isEmpty() )
78 beginInsertRows( QModelIndex(), 0, renderer->
ranges().size() - 1 );
89 void QgsGraduatedSymbolRendererModel::addClass(
QgsSymbol *symbol )
91 if ( !mRenderer )
return;
92 int idx = mRenderer->
ranges().size();
93 beginInsertRows( QModelIndex(), idx, idx );
98 void QgsGraduatedSymbolRendererModel::addClass(
const QgsRendererRange &range )
104 int idx = mRenderer->
ranges().size();
105 beginInsertRows( QModelIndex(), idx, idx );
110 QgsRendererRange QgsGraduatedSymbolRendererModel::rendererRange(
const QModelIndex &index )
112 if ( !index.isValid() || !mRenderer || mRenderer->
ranges().size() <= index.row() )
117 return mRenderer->
ranges().value( index.row() );
120 Qt::ItemFlags QgsGraduatedSymbolRendererModel::flags(
const QModelIndex &index )
const 122 if ( !index.isValid() )
124 return Qt::ItemIsDropEnabled;
127 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;
129 if ( index.column() == 2 )
131 flags |= Qt::ItemIsEditable;
137 Qt::DropActions QgsGraduatedSymbolRendererModel::supportedDropActions()
const 139 return Qt::MoveAction;
142 QVariant QgsGraduatedSymbolRendererModel::data(
const QModelIndex &index,
int role )
const 144 if ( !index.isValid() || !mRenderer )
return QVariant();
148 if ( role == Qt::CheckStateRole && index.column() == 0 )
150 return range.
renderState() ? Qt::Checked : Qt::Unchecked;
152 else if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
154 switch ( index.column() )
159 if ( decimalPlaces < 0 ) decimalPlaces = 0;
160 return QLocale().toString( range.
lowerValue(),
'f', decimalPlaces ) +
" - " + QLocale().toString( range.
upperValue(),
'f', decimalPlaces );
163 return range.
label();
168 else if ( role == Qt::DecorationRole && index.column() == 0 && range.
symbol() )
173 else if ( role == Qt::TextAlignmentRole )
175 return ( index.column() == 0 ) ? Qt::AlignHCenter : Qt::AlignLeft;
177 else if ( role == Qt::EditRole )
179 switch ( index.column() )
183 return range.
label();
192 bool QgsGraduatedSymbolRendererModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
194 if ( !index.isValid() )
197 if ( index.column() == 0 && role == Qt::CheckStateRole )
200 emit dataChanged( index, index );
204 if ( role != Qt::EditRole )
207 switch ( index.column() )
218 emit dataChanged( index, index );
222 QVariant QgsGraduatedSymbolRendererModel::headerData(
int section, Qt::Orientation orientation,
int role )
const 224 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
227 lst << tr(
"Symbol" ) << tr(
"Values" ) << tr(
"Legend" );
228 return lst.value( section );
233 int QgsGraduatedSymbolRendererModel::rowCount(
const QModelIndex &parent )
const 235 if ( parent.isValid() || !mRenderer )
239 return mRenderer->
ranges().size();
242 int QgsGraduatedSymbolRendererModel::columnCount(
const QModelIndex &index )
const 248 QModelIndex QgsGraduatedSymbolRendererModel::index(
int row,
int column,
const QModelIndex &parent )
const 250 if ( hasIndex( row, column, parent ) )
252 return createIndex( row, column );
254 return QModelIndex();
257 QModelIndex QgsGraduatedSymbolRendererModel::parent(
const QModelIndex &index )
const 260 return QModelIndex();
263 QStringList QgsGraduatedSymbolRendererModel::mimeTypes()
const 266 types << mMimeFormat;
270 QMimeData *QgsGraduatedSymbolRendererModel::mimeData(
const QModelIndexList &indexes )
const 272 QMimeData *mimeData =
new QMimeData();
273 QByteArray encodedData;
275 QDataStream stream( &encodedData, QIODevice::WriteOnly );
278 const auto constIndexes = indexes;
279 for (
const QModelIndex &index : constIndexes )
281 if ( !index.isValid() || index.column() != 0 )
284 stream << index.row();
286 mimeData->setData( mMimeFormat, encodedData );
290 bool QgsGraduatedSymbolRendererModel::dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
294 if ( action != Qt::MoveAction )
return true;
296 if ( !data->hasFormat( mMimeFormat ) )
return false;
298 QByteArray encodedData = data->data( mMimeFormat );
299 QDataStream stream( &encodedData, QIODevice::ReadOnly );
302 while ( !stream.atEnd() )
309 int to = parent.row();
312 if ( to == -1 ) to = mRenderer->
ranges().size();
313 for (
int i = rows.size() - 1; i >= 0; i-- )
315 QgsDebugMsg( QStringLiteral(
"move %1 to %2" ).arg( rows[i] ).arg( to ) );
318 if ( rows[i] < t ) t--;
321 for (
int j = 0; j < i; j++ )
323 if ( to < rows[j] && rows[i] > rows[j] ) rows[j] += 1;
326 if ( rows[i] < to ) to--;
328 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->
ranges().size(), 0 ) );
333 void QgsGraduatedSymbolRendererModel::deleteRows( QList<int> rows )
335 for (
int i = rows.size() - 1; i >= 0; i-- )
337 beginRemoveRows( QModelIndex(), rows[i], rows[i] );
343 void QgsGraduatedSymbolRendererModel::removeAllRows()
345 beginRemoveRows( QModelIndex(), 0, mRenderer->
ranges().size() - 1 );
350 void QgsGraduatedSymbolRendererModel::sort(
int column, Qt::SortOrder order )
360 else if ( column == 2 )
365 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->
ranges().size(), 0 ) );
368 void QgsGraduatedSymbolRendererModel::updateSymbology(
bool resetModel )
376 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->
ranges().size(), 0 ) );
380 void QgsGraduatedSymbolRendererModel::updateLabels()
382 emit dataChanged( createIndex( 0, 2 ), createIndex( mRenderer->
ranges().size(), 2 ) );
386 QgsGraduatedSymbolRendererViewStyle::QgsGraduatedSymbolRendererViewStyle( QWidget *parent )
390 void QgsGraduatedSymbolRendererViewStyle::drawPrimitive( PrimitiveElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget )
const 392 if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
394 QStyleOption opt( *option );
395 opt.rect.setLeft( 0 );
397 opt.rect.setHeight( 0 );
398 if ( widget ) opt.rect.setRight( widget->width() );
399 QProxyStyle::drawPrimitive( element, &opt, painter, widget );
402 QProxyStyle::drawPrimitive( element, option, painter, widget );
411 return new QgsGraduatedSymbolRendererWidget( layer, style, renderer );
421 if ( mContext.mapCanvas() )
435 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
455 mRenderer = qgis::make_unique< QgsGraduatedSymbolRenderer >( QString(),
QgsRangeList() );
461 mSymmetryPointValidator =
new QDoubleValidator();
462 cboSymmetryPoint->setEditable(
true );
463 cboSymmetryPoint->setValidator( mSymmetryPointValidator );
466 for ( QMap<QString, QString>::const_iterator it = methods.constBegin(); it != methods.constEnd(); ++it )
469 cboGraduatedMode->addItem( icon, it.key(), it.value() );
472 connect( methodComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged );
473 this->layout()->setContentsMargins( 0, 0, 0, 0 );
475 mModel =
new QgsGraduatedSymbolRendererModel(
this );
478 mExpressionWidget->setLayer(
mLayer );
480 btnChangeGraduatedSymbol->setLayer(
mLayer );
481 btnChangeGraduatedSymbol->registerExpressionContextGenerator(
this );
489 spinGraduatedClasses->setShowClearButton(
false );
491 btnColorRamp->setShowRandomColorRamp(
true );
494 QString defaultColorRamp =
QgsProject::instance()->
readEntry( QStringLiteral(
"DefaultStyles" ), QStringLiteral(
"/ColorRamp" ), QString() );
495 if ( !defaultColorRamp.isEmpty() )
497 btnColorRamp->setColorRampFromName( defaultColorRamp );
502 btnColorRamp->setColorRamp( ramp );
507 viewGraduated->setStyle(
new QgsGraduatedSymbolRendererViewStyle( viewGraduated ) );
510 btnChangeGraduatedSymbol->setSymbolType( mGraduatedSymbol->type() );
511 btnChangeGraduatedSymbol->setSymbol( mGraduatedSymbol->clone() );
513 methodComboBox->blockSignals(
true );
514 methodComboBox->addItem( tr(
"Color" ), ColorMode );
515 switch ( mGraduatedSymbol->type() )
519 methodComboBox->addItem( tr(
"Size" ), SizeMode );
520 minSizeSpinBox->setValue( 1 );
521 maxSizeSpinBox->setValue( 8 );
526 methodComboBox->addItem( tr(
"Size" ), SizeMode );
527 minSizeSpinBox->setValue( .1 );
528 maxSizeSpinBox->setValue( 2 );
534 methodComboBox->hide();
541 methodComboBox->blockSignals(
false );
549 connect( btnChangeGraduatedSymbol, &
QgsSymbolButton::changed,
this, &QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol );
562 mGroupBoxSymmetric->setCollapsed(
true );
565 QMenu *advMenu =
new QMenu(
this );
567 advMenu->addAction( tr(
"Symbol Levels…" ),
this, SLOT(
showSymbolLevels() ) );
570 QAction *actionDdsLegend = advMenu->addAction( tr(
"Data-defined Size Legend…" ) );
572 connect( actionDdsLegend, &QAction::triggered,
this, &QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend );
575 btnAdvanced->setMenu( advMenu );
577 mHistogramWidget->setLayer(
mLayer );
578 mHistogramWidget->setRenderer( mRenderer.get() );
582 mExpressionWidget->registerExpressionContextGenerator(
this );
585 void QgsGraduatedSymbolRendererWidget::mSizeUnitWidget_changed()
587 if ( !mGraduatedSymbol )
589 mGraduatedSymbol->setOutputUnit( mSizeUnitWidget->unit() );
590 mGraduatedSymbol->setMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
591 mRenderer->updateSymbols( mGraduatedSymbol.get() );
602 return mRenderer.get();
608 btnChangeGraduatedSymbol->setMapCanvas( context.
mapCanvas() );
609 btnChangeGraduatedSymbol->setMessageBar( context.
messageBar() );
630 connect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished,
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
651 disconnect( cboSymmetryPoint->lineEdit(), &QLineEdit::editingFinished,
this, &QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished );
663 int precision = spinPrecision->value() + 2;
664 while ( cboSymmetryPoint->count() )
665 cboSymmetryPoint->removeItem( 0 );
666 for (
int i = 0; i < ranges.count() - 1; i++ )
667 cboSymmetryPoint->addItem( QString::number( ranges.at( i ).upperValue(),
'f',
precision ), ranges.at( i ).upperValue() );
671 int idx = cboGraduatedMode->findData( method->
id() );
673 cboGraduatedMode->setCurrentIndex( idx );
679 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QString::number( method->
symmetryPoint(),
'f', method->
labelPrecision() + 2 ) );
687 int nclasses = ranges.count();
688 if ( nclasses && updateCount )
690 spinGraduatedClasses->setValue( ranges.count() );
694 QString attrName = mRenderer->classAttribute();
695 mExpressionWidget->setField( attrName );
696 mHistogramWidget->setSourceFieldExp( attrName );
699 if ( mRenderer->sourceSymbol() )
701 mGraduatedSymbol.reset( mRenderer->sourceSymbol()->clone() );
702 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
705 mModel->setRenderer( mRenderer.get() );
706 viewGraduated->setModel( mModel );
708 connect( viewGraduated->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsGraduatedSymbolRendererWidget::selectionChanged );
710 if ( mGraduatedSymbol )
712 mSizeUnitWidget->blockSignals(
true );
713 mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
714 mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
715 mSizeUnitWidget->blockSignals(
false );
719 methodComboBox->blockSignals(
true );
720 switch ( mRenderer->graduatedMethod() )
724 methodComboBox->setCurrentIndex( methodComboBox->findData( ColorMode ) );
725 if ( mRenderer->sourceColorRamp() )
727 btnColorRamp->setColorRamp( mRenderer->sourceColorRamp() );
733 methodComboBox->setCurrentIndex( methodComboBox->findData( SizeMode ) );
734 if ( !mRenderer->ranges().isEmpty() )
736 minSizeSpinBox->setValue( mRenderer->minSymbolSize() );
737 maxSizeSpinBox->setValue( mRenderer->maxSymbolSize() );
742 toggleMethodWidgets( static_cast< MethodMode>( methodComboBox->currentData().toInt() ) );
743 methodComboBox->blockSignals(
false );
745 viewGraduated->resizeColumnToContents( 0 );
746 viewGraduated->resizeColumnToContents( 1 );
747 viewGraduated->resizeColumnToContents( 2 );
749 mHistogramWidget->refresh();
757 mRenderer->setClassAttribute( field );
760 void QgsGraduatedSymbolRendererWidget::methodComboBox_currentIndexChanged(
int )
762 const MethodMode newMethod =
static_cast< MethodMode
>( methodComboBox->currentData().toInt() );
763 toggleMethodWidgets( newMethod );
773 QMessageBox::critical(
this, tr(
"Select Method" ), tr(
"No color ramp defined." ) );
776 mRenderer->setSourceColorRamp( ramp );
783 lblColorRamp->setVisible(
false );
784 btnColorRamp->setVisible(
false );
785 lblSize->setVisible(
true );
786 minSizeSpinBox->setVisible(
true );
787 lblSize->setVisible(
true );
788 maxSizeSpinBox->setVisible(
true );
789 mSizeUnitWidget->setVisible(
true );
798 void QgsGraduatedSymbolRendererWidget::toggleMethodWidgets( MethodMode mode )
804 lblColorRamp->setVisible(
true );
805 btnColorRamp->setVisible(
true );
806 lblSize->setVisible(
false );
807 minSizeSpinBox->setVisible(
false );
808 lblSizeTo->setVisible(
false );
809 maxSizeSpinBox->setVisible(
false );
810 mSizeUnitWidget->setVisible(
false );
816 lblColorRamp->setVisible(
false );
817 btnColorRamp->setVisible(
false );
818 lblSize->setVisible(
true );
819 minSizeSpinBox->setVisible(
true );
820 lblSizeTo->setVisible(
true );
821 maxSizeSpinBox->setVisible(
true );
822 mSizeUnitWidget->setVisible(
true );
833 mModel->updateSymbology( reset );
836 spinGraduatedClasses->setValue( mRenderer->ranges().count() );
842 void QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector(
QgsPanelWidget *container )
851 void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
861 mSizeUnitWidget->blockSignals(
true );
862 mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
863 mSizeUnitWidget->setMapUnitScale( mGraduatedSymbol->mapUnitScale() );
864 mSizeUnitWidget->blockSignals(
false );
866 QItemSelectionModel *m = viewGraduated->selectionModel();
867 QModelIndexList selectedIndexes = m->selectedRows( 1 );
868 if ( m && !selectedIndexes.isEmpty() )
870 const auto constSelectedIndexes = selectedIndexes;
871 for (
const QModelIndex &idx : constSelectedIndexes )
875 int rangeIdx = idx.row();
876 QgsSymbol *newRangeSymbol = mGraduatedSymbol->clone();
877 if ( selectedIndexes.count() > 1 )
880 newRangeSymbol->
setColor( mRenderer->ranges().at( rangeIdx ).symbol()->color() );
882 mRenderer->updateRangeSymbol( rangeIdx, newRangeSymbol );
888 mRenderer->updateSymbols( mGraduatedSymbol.get() );
895 void QgsGraduatedSymbolRendererWidget::symmetryPointEditingFinished( )
897 const QString text = cboSymmetryPoint->lineEdit()->text();
898 int index = cboSymmetryPoint->findText( text );
901 cboSymmetryPoint->setCurrentIndex( index );
905 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), text );
915 QString attrName = mExpressionWidget->currentField();
916 int nclasses = spinGraduatedClasses->value();
918 const QString methodId = cboGraduatedMode->currentData().toString();
925 mSymmetryPointValidator->setBottom( minimum );
926 mSymmetryPointValidator->setTop( maximum );
927 mSymmetryPointValidator->setDecimals( spinPrecision->value() );
934 double currentValue = cboSymmetryPoint->currentText().toDouble();
935 if ( currentValue < ( minimum + ( maximum - minimum ) / 100. ) || currentValue > ( maximum - ( maximum - minimum ) / 100. ) )
936 cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QString::number( minimum + ( maximum - minimum ) / 2.,
'f', method->
labelPrecision() + 2 ) );
939 if ( mGroupBoxSymmetric->isChecked() )
941 double symmetryPoint = cboSymmetryPoint->currentText().toDouble();
942 bool astride = cbxAstride->isChecked();
947 mRenderer->setClassificationMethod( method );
950 mRenderer->setClassAttribute( attrName );
956 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 ) )
962 if ( methodComboBox->currentData() == ColorMode )
964 std::unique_ptr<QgsColorRamp> ramp( btnColorRamp->colorRamp() );
967 QMessageBox::critical(
this, tr(
"Apply Classification" ), tr(
"No color ramp defined." ) );
970 mRenderer->setSourceColorRamp( ramp.release() );
974 mRenderer->setSourceColorRamp(
nullptr );
977 mRenderer->updateClasses(
mLayer, nclasses );
979 if ( methodComboBox->currentData() == SizeMode )
980 mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
982 mRenderer->calculateLabelPrecision();
990 std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
994 mRenderer->updateColorRamp( ramp.release() );
995 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1001 mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
1002 mRenderer->updateSymbols( mGraduatedSymbol.get() );
1007 int QgsRendererPropertiesDialog::currentRangeRow()
1009 QModelIndex idx = viewGraduated->selectionModel()->currentIndex();
1010 if ( !idx.isValid() )
1019 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1021 const auto constSelectedRows = selectedRows;
1022 for (
const QModelIndex &r : constSelectedRows )
1026 rows.append( r.row() );
1035 QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1036 QModelIndexList::const_iterator sIt = selectedRows.constBegin();
1038 for ( ; sIt != selectedRows.constEnd(); ++sIt )
1040 selectedRanges.append( mModel->rendererRange( *sIt ) );
1047 if ( idx.isValid() && idx.column() == 0 )
1049 if ( idx.isValid() && idx.column() == 1 )
1055 if ( !idx.isValid() )
1058 mRowSelected = idx.row();
1068 std::unique_ptr< QgsSymbol > newSymbol( range.
symbol()->
clone() );
1070 if ( panel && panel->dockMode() )
1085 if ( !dlg.exec() || !newSymbol )
1090 mGraduatedSymbol = std::move( newSymbol );
1091 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mGraduatedSymbol->clone() );
1103 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
1104 if ( decimalPlaces < 0 ) decimalPlaces = 0;
1108 if ( dialog.exec() == QDialog::Accepted )
1117 mRenderer->updateRangeUpperValue( rangeIdx, upperValue );
1118 mRenderer->updateRangeLowerValue( rangeIdx, lowerValue );
1121 if ( cbxLinkBoundaries->isChecked() )
1125 mRenderer->updateRangeUpperValue( rangeIdx - 1, lowerValue );
1128 if ( rangeIdx < mRenderer->ranges().size() - 1 )
1130 mRenderer->updateRangeLowerValue( rangeIdx + 1, upperValue );
1134 mHistogramWidget->refresh();
1140 mModel->addClass( mGraduatedSymbol.get() );
1141 mHistogramWidget->refresh();
1149 mModel->deleteRows( classIndexes );
1150 mHistogramWidget->refresh();
1156 mModel->removeAllRows();
1157 mHistogramWidget->refresh();
1164 bool ordered =
true;
1165 for (
int i = 1; i < ranges.size(); ++i )
1167 if ( ranges[i] < ranges[i - 1] )
1184 int result = QMessageBox::warning(
1186 tr(
"Link Class Boundaries" ),
1187 tr(
"Rows will be reordered before linking boundaries. Continue?" ),
1188 QMessageBox::Ok | QMessageBox::Cancel );
1189 if ( result != QMessageBox::Ok )
1191 cbxLinkBoundaries->setChecked(
false );
1194 mRenderer->sortByValue();
1198 for (
int i = 1; i < mRenderer->ranges().size(); ++i )
1200 mRenderer->updateRangeLowerValue( i, mRenderer->ranges()[i - 1].upperValue() );
1208 if ( item->column() == 2 )
1210 QString label = item->text();
1211 int idx = item->row();
1212 mRenderer->updateRangeLabel( idx, label );
1218 mRenderer->classificationMethod()->setLabelFormat( txtLegendFormat->text() );
1219 mRenderer->classificationMethod()->setLabelPrecision( spinPrecision->value() );
1220 mRenderer->classificationMethod()->setLabelTrimTrailingZeroes( cbxTrimTrailingZeroes->isChecked() );
1221 mRenderer->updateRangeLabels();
1222 mModel->updateLabels();
1230 QItemSelectionModel *m = viewGraduated->selectionModel();
1231 QModelIndexList selectedIndexes = m->selectedRows( 1 );
1232 if ( m && !selectedIndexes.isEmpty() )
1235 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
1236 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1238 QStringList list = m->model()->data( *indexIt ).toString().split(
' ' );
1239 if ( list.size() < 3 )
1255 selectedSymbols.append( s );
1264 int decimalPlaces = mRenderer->classificationMethod()->labelPrecision() + 2;
1265 if ( decimalPlaces < 0 )
1267 double precision = 1.0 / std::pow( 10, decimalPlaces );
1269 for ( QgsRangeList::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
1273 return it->symbol();
1283 mModel->updateSymbology();
1285 mHistogramWidget->refresh();
1296 viewGraduated->selectionModel()->clear();
1299 cbxLinkBoundaries->setChecked(
false );
1316 if ( event->key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
1318 mCopyBuffer.clear();
1321 else if ( event->key() == Qt::Key_V &&
event->modifiers() == Qt::ControlModifier )
1323 QgsRangeList::const_iterator rIt = mCopyBuffer.constBegin();
1324 for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
1326 mModel->addClass( *rIt );
1332 void QgsGraduatedSymbolRendererWidget::selectionChanged(
const QItemSelection &,
const QItemSelection & )
1335 if ( !ranges.isEmpty() )
1337 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( ranges.at( 0 ).symbol()->clone() );
1339 else if ( mRenderer->sourceSymbol() )
1341 whileBlocking( btnChangeGraduatedSymbol )->setSymbol( mRenderer->sourceSymbol()->clone() );
1343 btnChangeGraduatedSymbol->setDialogTitle( ranges.size() == 1 ? ranges.at( 0 ).label() : tr(
"Symbol Settings" ) );
1346 void QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend()
1354 mRenderer->setDataDefinedSizeLegend( panel->dataDefinedSizeLegend() );
1361 void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
1363 mGraduatedSymbol.reset( btnChangeGraduatedSymbol->symbol()->clone() );
1373 const QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
1374 for (
const QModelIndex &index : selectedRows )
1376 if ( !index.isValid() )
1379 const int row = index.row();
1380 if ( !mRenderer || mRenderer->ranges().size() <= row )
1383 if ( mRenderer->ranges().at( row ).symbol()->type() != tempSymbol->type() )
1386 std::unique_ptr< QgsSymbol > newCatSymbol( tempSymbol->clone() );
1387 if ( selectedRows.count() > 1 )
1390 newCatSymbol->setColor( mRenderer->ranges().at( row ).symbol()->color() );
1393 mRenderer->updateRangeSymbol( row, newCatSymbol.release() );
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QgsClassificationMethod * method(const QString &id)
Returns a new instance of the method for the given id.
static QgsGraduatedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsGraduatedSymbolRenderer from an existing renderer.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
QList< QgsRendererRange > QgsRangeList
static const QString METHOD_ID
Temporarily sets a cursor override for the QApplication for the lifetime of the object.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Abstract base class for all rendered symbols.
bool symmetricModeAvailable() const
Returns if the method supports symmetric calculation.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
QgsClassificationMethod * classificationMethod() const
Returns the classification method.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double qgsPermissiveToDouble(QString string, bool &ok)
Converts a string to a double in a permissive way, e.g., allowing for incorrect numbers of digits bet...
Abstract base class for color ramps.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
int codeComplexity() const
Code complexity as the exponent in Big O notation.
bool symmetryAstride() const
Returns if the symmetric mode is astride if true, it will remove the symmetry point break so that the...
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
virtual QString id() const =0
The id of the method as saved in the project, must be unique in registry.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style...
void setLowerValue(const QString &val)
void addClass(QgsSymbol *symbol)
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
A marker symbol type, for rendering Point and MultiPoint geometries.
static const int MAX_PRECISION
The QgsMapSettings class contains configuration for rendering of the map.
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
double lowerValue() const
void setSymmetricMode(bool enabled, double symmetryPoint=0, bool symmetryAstride=false)
Defines if the symmetric mode is enables and configures its parameters.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QgsFields fields() const FINAL
Returns the list of fields of this layer.
double symmetryPoint() const
Returns the symmetry point for symmetric mode.
int labelPrecision() const
Returns the precision for the formatting of the labels.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool labelTrimTrailingZeroes() const
Returns if the trailing 0 are trimmed in the label.
QIcon icon(const QString &id) const
Returns the icon for a given method id.
QgsSymbol * symbol() const
QVariant minimumValue(int index) const FINAL
Returns the minimum value for an attribute column or an invalid variant in case of error...
Single scope for storing variables and functions for use within a QgsExpressionContext.
static const QString METHOD_ID
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
static const int MIN_PRECISION
bool symmetricModeEnabled() const
Returns if the symmetric mode is enabled.
void moveClass(int from, int to)
Moves the category at index position from to index position to.
QString labelFormat() const
Returns the format of the label for the classes.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
void sortByLabel(Qt::SortOrder order=Qt::AscendingOrder)
Points (e.g., for font sizes)
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
static QgsClassificationMethodRegistry * classificationMethodRegistry()
Returns the application's classification methods registry, used in graduated renderer.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setUpperValue(const QString &val)
double upperValue() const
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
bool updateRangeRenderState(int rangeIndex, bool render)
QString lowerValue() const
bool updateRangeLabel(int rangeIndex, const QString &label)
QString upperValue() const
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Gradient color ramp, which smoothly interpolates between two colors and also supports optional extra ...
QVariant maximumValue(int index) const FINAL
Returns the maximum value for an attribute column or an invalid variant in case of error...
Represents a vector layer which manages a vector based data sets.
const QgsRangeList & ranges() const
QgsClassificationMethod is an abstract class for implementations of classification methods...
void deleteClass(int idx)
QMap< QString, QString > methodNames() const
Returns a map <name, id> of all registered methods.
void setColor(const QColor &color)
Sets the color for the symbol.