45 #include <QMessageBox> 46 #include <QStandardItemModel> 47 #include <QStandardItem> 50 #include <QFileDialog> 55 QgsCategorizedSymbolRendererModel::QgsCategorizedSymbolRendererModel( QObject *parent ) : QAbstractItemModel( parent )
56 , mMimeFormat( QStringLiteral(
"application/x-qgscategorizedsymbolrendererv2model" ) )
64 beginRemoveRows( QModelIndex(), 0, std::max( mRenderer->categories().size() - 1, 0 ) );
73 beginInsertRows( QModelIndex(), 0, renderer->
categories().size() - 1 );
81 if ( !mRenderer )
return;
82 int idx = mRenderer->categories().size();
83 beginInsertRows( QModelIndex(), idx, idx );
84 mRenderer->addCategory( cat );
95 int row = index.row();
96 if ( row >= catList.size() )
100 return catList.at( row );
104 Qt::ItemFlags QgsCategorizedSymbolRendererModel::flags(
const QModelIndex &index )
const 106 if ( !index.isValid() || !mRenderer )
108 return Qt::ItemIsDropEnabled;
111 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;
112 if ( index.column() == 1 )
115 if ( category.
value().type() != QVariant::List )
117 flags |= Qt::ItemIsEditable;
120 else if ( index.column() == 2 )
122 flags |= Qt::ItemIsEditable;
127 Qt::DropActions QgsCategorizedSymbolRendererModel::supportedDropActions()
const 129 return Qt::MoveAction;
132 QVariant QgsCategorizedSymbolRendererModel::data(
const QModelIndex &index,
int role )
const 134 if ( !index.isValid() || !mRenderer )
141 case Qt::CheckStateRole:
143 if ( index.column() == 0 )
145 return category.
renderState() ? Qt::Checked : Qt::Unchecked;
150 case Qt::DisplayRole:
151 case Qt::ToolTipRole:
153 switch ( index.column() )
157 if ( category.
value().type() == QVariant::List )
160 const QVariantList list = category.
value().toList();
161 res.reserve( list.size() );
162 for (
const QVariant &v : list )
165 if ( role == Qt::DisplayRole )
166 return res.join(
';' );
168 return res.join(
'\n' );
170 else if ( !category.
value().isValid() || category.
value().isNull() || category.
value().toString().isEmpty() )
172 return tr(
"all other values" );
176 return category.
value().toString();
180 return category.
label();
187 if ( index.column() == 1 && category.
value().type() != QVariant::List && ( !category.
value().isValid() || category.
value().isNull() || category.
value().toString().isEmpty() ) )
190 italicFont.setItalic(
true );
196 case Qt::DecorationRole:
198 if ( index.column() == 0 && category.
symbol() )
206 case Qt::ForegroundRole:
208 QBrush brush( qApp->palette().color( QPalette::Text ), Qt::SolidPattern );
209 if ( index.column() == 1 && ( category.
value().type() == QVariant::List
210 || !category.
value().isValid() || category.
value().isNull() || category.
value().toString().isEmpty() ) )
212 QColor fadedTextColor = brush.color();
213 fadedTextColor.setAlpha( 128 );
214 brush.setColor( fadedTextColor );
219 case Qt::TextAlignmentRole:
221 return ( index.column() == 0 ) ? Qt::AlignHCenter : Qt::AlignLeft;
226 switch ( index.column() )
230 if ( category.
value().type() == QVariant::List )
233 const QVariantList list = category.
value().toList();
234 res.reserve( list.size() );
235 for (
const QVariant &v : list )
238 return res.join(
';' );
242 return category.
value();
247 return category.
label();
256 bool QgsCategorizedSymbolRendererModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
258 if ( !index.isValid() )
261 if ( index.column() == 0 && role == Qt::CheckStateRole )
263 mRenderer->updateCategoryRenderState( index.row(), value == Qt::Checked );
264 emit dataChanged( index, index );
268 if ( role != Qt::EditRole )
271 switch ( index.column() )
277 switch ( mRenderer->categories().value( index.row() ).value().type() )
282 case QVariant::Double:
283 val = value.toDouble();
287 const QStringList parts = value.toString().split(
';' );
289 list.reserve( parts.count() );
290 for (
const QString &p : parts )
293 if ( list.count() == 1 )
300 val = value.toString();
303 mRenderer->updateCategoryValue( index.row(), val );
307 mRenderer->updateCategoryLabel( index.row(), value.toString() );
313 emit dataChanged( index, index );
317 QVariant QgsCategorizedSymbolRendererModel::headerData(
int section, Qt::Orientation orientation,
int role )
const 319 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
322 lst << tr(
"Symbol" ) << tr(
"Value" ) << tr(
"Legend" );
323 return lst.value( section );
328 int QgsCategorizedSymbolRendererModel::rowCount(
const QModelIndex &parent )
const 330 if ( parent.isValid() || !mRenderer )
334 return mRenderer->categories().size();
337 int QgsCategorizedSymbolRendererModel::columnCount(
const QModelIndex &index )
const 343 QModelIndex QgsCategorizedSymbolRendererModel::index(
int row,
int column,
const QModelIndex &parent )
const 345 if ( hasIndex( row, column, parent ) )
347 return createIndex( row, column );
349 return QModelIndex();
352 QModelIndex QgsCategorizedSymbolRendererModel::parent(
const QModelIndex &index )
const 355 return QModelIndex();
358 QStringList QgsCategorizedSymbolRendererModel::mimeTypes()
const 361 types << mMimeFormat;
365 QMimeData *QgsCategorizedSymbolRendererModel::mimeData(
const QModelIndexList &indexes )
const 367 QMimeData *mimeData =
new QMimeData();
368 QByteArray encodedData;
370 QDataStream stream( &encodedData, QIODevice::WriteOnly );
373 const auto constIndexes = indexes;
374 for (
const QModelIndex &index : constIndexes )
376 if ( !index.isValid() || index.column() != 0 )
379 stream << index.row();
381 mimeData->setData( mMimeFormat, encodedData );
385 bool QgsCategorizedSymbolRendererModel::dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
389 if ( action != Qt::MoveAction )
return true;
391 if ( !data->hasFormat( mMimeFormat ) )
return false;
393 QByteArray encodedData = data->data( mMimeFormat );
394 QDataStream stream( &encodedData, QIODevice::ReadOnly );
397 while ( !stream.atEnd() )
404 int to = parent.row();
407 if ( to == -1 ) to = mRenderer->categories().size();
408 for (
int i = rows.size() - 1; i >= 0; i-- )
410 QgsDebugMsg( QStringLiteral(
"move %1 to %2" ).arg( rows[i] ).arg( to ) );
413 if ( rows[i] < t ) t--;
414 mRenderer->moveCategory( rows[i], t );
416 for (
int j = 0; j < i; j++ )
418 if ( to < rows[j] && rows[i] > rows[j] ) rows[j] += 1;
421 if ( rows[i] < to ) to--;
423 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->categories().size(), 0 ) );
428 void QgsCategorizedSymbolRendererModel::deleteRows( QList<int> rows )
430 std::sort( rows.begin(), rows.end() );
431 for (
int i = rows.size() - 1; i >= 0; i-- )
433 beginRemoveRows( QModelIndex(), rows[i], rows[i] );
434 mRenderer->deleteCategory( rows[i] );
439 void QgsCategorizedSymbolRendererModel::removeAllRows()
441 beginRemoveRows( QModelIndex(), 0, mRenderer->categories().size() - 1 );
442 mRenderer->deleteAllCategories();
446 void QgsCategorizedSymbolRendererModel::sort(
int column, Qt::SortOrder order )
454 mRenderer->sortByValue( order );
456 else if ( column == 2 )
458 mRenderer->sortByLabel( order );
460 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->categories().size(), 0 ) );
463 void QgsCategorizedSymbolRendererModel::updateSymbology()
465 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->categories().size(), 0 ) );
469 QgsCategorizedSymbolRendererViewStyle::QgsCategorizedSymbolRendererViewStyle( QWidget *parent )
473 void QgsCategorizedSymbolRendererViewStyle::drawPrimitive( PrimitiveElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget )
const 475 if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
477 QStyleOption opt( *option );
478 opt.rect.setLeft( 0 );
480 opt.rect.setHeight( 0 );
481 if ( widget ) opt.rect.setRight( widget->width() );
482 QProxyStyle::drawPrimitive( element, &opt, painter, widget );
485 QProxyStyle::drawPrimitive( element, option, painter, widget );
493 return new QgsCategorizedSymbolRendererWidget( layer, style, renderer );
498 , mContextMenu( new QMenu( this ) )
512 QString attrName =
mRenderer->classAttribute();
513 mOldClassificationAttribute = attrName;
517 layout()->setContentsMargins( 0, 0, 0, 0 );
519 mExpressionWidget->setLayer(
mLayer );
520 btnChangeCategorizedSymbol->setLayer(
mLayer );
521 btnChangeCategorizedSymbol->registerExpressionContextGenerator(
this );
524 btnColorRamp->setShowRandomColorRamp(
true );
527 QString defaultColorRamp =
QgsProject::instance()->
readEntry( QStringLiteral(
"DefaultStyles" ), QStringLiteral(
"/ColorRamp" ), QString() );
528 if ( !defaultColorRamp.isEmpty() )
530 btnColorRamp->setColorRampFromName( defaultColorRamp );
534 btnColorRamp->setRandomColorRamp();
544 mModel =
new QgsCategorizedSymbolRendererModel(
this );
550 viewCategories->setModel(
mModel );
551 viewCategories->resizeColumnToContents( 0 );
552 viewCategories->resizeColumnToContents( 1 );
553 viewCategories->resizeColumnToContents( 2 );
555 viewCategories->setStyle(
new QgsCategorizedSymbolRendererViewStyle( viewCategories ) );
556 connect( viewCategories->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCategorizedSymbolRendererWidget::selectionChanged );
564 connect( viewCategories, &QTreeView::customContextMenuRequested,
this, &QgsCategorizedSymbolRendererWidget::showContextMenu );
566 connect( btnChangeCategorizedSymbol, &
QgsSymbolButton::changed,
this, &QgsCategorizedSymbolRendererWidget::updateSymbolsFromButton );
576 QMenu *advMenu =
new QMenu;
580 advMenu->addAction( tr(
"Symbol Levels…" ),
this, SLOT(
showSymbolLevels() ) );
583 QAction *actionDdsLegend = advMenu->addAction( tr(
"Data-defined Size Legend…" ) );
585 connect( actionDdsLegend, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend );
588 btnAdvanced->setMenu( advMenu );
590 mExpressionWidget->registerExpressionContextGenerator(
this );
592 mMergeCategoriesAction =
new QAction( tr(
"Merge Categories" ),
this );
593 connect( mMergeCategoriesAction, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::mergeSelectedCategories );
594 mUnmergeCategoriesAction =
new QAction( tr(
"Unmerge Categories" ),
this );
595 connect( mUnmergeCategoriesAction, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::unmergeSelectedCategories );
597 connect( mContextMenu, &QMenu::aboutToShow,
this, [ = ]
618 QString attrName =
mRenderer->classAttribute();
619 mExpressionWidget->setField( attrName );
631 btnColorRamp->setColorRamp(
mRenderer->sourceColorRamp() );
643 btnChangeCategorizedSymbol->setMapCanvas( context.
mapCanvas() );
644 btnChangeCategorizedSymbol->setMessageBar( context.
messageBar() );
651 if ( !selectedCats.isEmpty() )
662 const auto constSelectedCats = selectedCats;
663 for (
int idx : constSelectedCats )
669 mRenderer->updateCategorySymbol( idx, newCatSymbol );
692 if ( !dlg.exec() || !newSymbol )
715 if ( idx.isValid() && idx.column() == 0 )
723 std::unique_ptr< QgsSymbol > symbol;
748 if ( !dlg.exec() || !symbol )
761 QString attrName = mExpressionWidget->currentField();
763 QList<QVariant> uniqueValues;
774 expression->
prepare( &context );
780 QVariant value = expression->
evaluate( &context );
781 if ( uniqueValues.contains( value ) )
783 uniqueValues << value;
792 if ( uniqueValues.size() >= 1000 )
794 int res = QMessageBox::warning(
nullptr, tr(
"Classify Categories" ),
795 tr(
"High number of classes. Classification would yield %1 entries which might not be expected. Continue?" ).arg( uniqueValues.size() ),
796 QMessageBox::Ok | QMessageBox::Cancel,
797 QMessageBox::Cancel );
798 if ( res == QMessageBox::Cancel )
805 DlgAddCategories dlg(
mStyle, createDefaultSymbol(), unique_vals,
this );
811 bool deleteExisting =
false;
813 if ( !mOldClassificationAttribute.isEmpty() &&
814 attrName != mOldClassificationAttribute &&
817 int res = QMessageBox::question(
this,
818 tr(
"Delete Classification" ),
819 tr(
"The classification field was changed from '%1' to '%2'.\n" 820 "Should the existing classes be deleted before classification?" )
821 .arg( mOldClassificationAttribute, attrName ),
822 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel );
823 if ( res == QMessageBox::Cancel )
828 deleteExisting = ( res == QMessageBox::Yes );
832 bool keepExistingColors =
false;
833 if ( !deleteExisting )
836 keepExistingColors = !prevCats.isEmpty();
838 if ( keepExistingColors && btnColorRamp->isRandomColorRamp() )
840 for (
int i = 0; i < cats.size(); ++i )
842 bool contains =
false;
843 QVariant value = cats.at( i ).value();
844 for (
int j = 0; j < prevCats.size() && !contains; ++j )
846 const QVariant prevCatValue = prevCats.at( j ).value();
847 if ( prevCatValue.type() == QVariant::List )
849 const QVariantList list = prevCatValue.toList();
850 for (
const QVariant &v : list )
861 if ( prevCats.at( j ).value() == value )
872 if ( keepExistingColors && btnColorRamp->isRandomColorRamp() )
875 cats.at( i ).symbol()->setColor( randomColors.
color( i ) );
877 prevCats.append( cats.at( i ) );
883 mOldClassificationAttribute = attrName;
900 std::unique_ptr< QgsCategorizedSymbolRenderer > r = qgis::make_unique< QgsCategorizedSymbolRenderer >( attrName, cats );
902 std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
904 r->setSourceColorRamp( ramp->clone() );
908 mModel->setRenderer( r.get() );
911 if ( ! keepExistingColors && ramp )
918 if ( !btnColorRamp->isNull() )
920 mRenderer->updateColorRamp( btnColorRamp->colorRamp() );
922 mModel->updateSymbology();
927 QModelIndex idx = viewCategories->selectionModel()->currentIndex();
928 if ( !idx.isValid() )
936 QModelIndexList selectedRows = viewCategories->selectionModel()->selectedRows();
938 const auto constSelectedRows = selectedRows;
939 for (
const QModelIndex &r : constSelectedRows )
943 rows.append( r.row() );
952 mModel->deleteRows( categoryIndexes );
967 mModel->addCategory( cat );
975 QItemSelectionModel *m = viewCategories->selectionModel();
976 QModelIndexList selectedIndexes = m->selectedRows( 1 );
978 if ( m && !selectedIndexes.isEmpty() )
981 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
982 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
984 int row = ( *indexIt ).row();
988 selectedSymbols.append( s );
999 QItemSelectionModel *m = viewCategories->selectionModel();
1000 QModelIndexList selectedIndexes = m->selectedRows( 1 );
1002 if ( m && !selectedIndexes.isEmpty() )
1004 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
1005 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1007 cl.append(
mModel->category( *indexIt ) );
1026 viewCategories->selectionModel()->clear();
1034 QMessageBox::information(
this, tr(
"Matched Symbols" ),
1035 tr(
"Matched %1 categories to symbols." ).arg( matched ) );
1039 QMessageBox::warning(
this, tr(
"Matched Symbols" ),
1040 tr(
"No categories could be matched to symbols in library." ) );
1053 QVariantList unmatchedCategories;
1054 QStringList unmatchedSymbols;
1055 const int matched =
mRenderer->matchToSymbols( style, type, unmatchedCategories, unmatchedSymbols );
1057 mModel->updateSymbology();
1064 QString openFileDir = settings.
value( QStringLiteral(
"UI/lastMatchToSymbolsDir" ), QDir::homePath() ).toString();
1066 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Match to Symbols from File" ), openFileDir,
1067 tr(
"XML files (*.xml *.XML)" ) );
1068 if ( fileName.isEmpty() )
1073 QFileInfo openFileInfo( fileName );
1074 settings.
setValue( QStringLiteral(
"UI/lastMatchToSymbolsDir" ), openFileInfo.absolutePath() );
1077 if ( !importedStyle.
importXml( fileName ) )
1079 QMessageBox::warning(
this, tr(
"Match to Symbols from File" ),
1080 tr(
"An error occurred while reading file:\n%1" ).arg( importedStyle.
errorString() ) );
1087 QMessageBox::information(
this, tr(
"Match to Symbols from File" ),
1088 tr(
"Matched %1 categories to symbols from file." ).arg( matched ) );
1092 QMessageBox::warning(
this, tr(
"Match to Symbols from File" ),
1093 tr(
"No categories could be matched to symbols in file." ) );
1104 if ( !selectedCats.isEmpty() )
1106 for (
int idx : selectedCats )
1108 if (
mRenderer->categories().at( idx ).symbol()->type() != tempSymbol->type() )
1111 std::unique_ptr< QgsSymbol > newCatSymbol( tempSymbol->clone() );
1112 if ( selectedCats.count() > 1 )
1115 newCatSymbol->setColor(
mRenderer->categories().at( idx ).symbol()->color() );
1117 mRenderer->updateCategorySymbol( idx, newCatSymbol.release() );
1123 void QgsCategorizedSymbolRendererWidget::cleanUpSymbolSelector(
QgsPanelWidget *container )
1132 void QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget()
1140 void QgsCategorizedSymbolRendererWidget::updateSymbolsFromButton()
1150 QItemSelectionModel *m = viewCategories->selectionModel();
1151 QModelIndexList i = m->selectedRows();
1153 if ( m && !i.isEmpty() )
1157 if ( !selectedCats.isEmpty() )
1159 const auto constSelectedCats = selectedCats;
1160 for (
int idx : constSelectedCats )
1163 if ( selectedCats.count() > 1 )
1168 mRenderer->updateCategorySymbol( idx, newCatSymbol );
1177 mModel->updateSymbology();
1188 if ( event->key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
1190 mCopyBuffer.clear();
1193 else if ( event->key() == Qt::Key_V &&
event->modifiers() == Qt::ControlModifier )
1195 QgsCategoryList::const_iterator rIt = mCopyBuffer.constBegin();
1196 for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
1198 mModel->addCategory( *rIt );
1233 void QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend()
1241 mRenderer->setDataDefinedSizeLegend( panel->dataDefinedSizeLegend() );
1248 void QgsCategorizedSymbolRendererWidget::mergeSelectedCategories()
1253 QList< int > categoryIndexes;
1256 for (
int i : selectedCategoryIndexes )
1258 QVariant v = categories.at( i ).value();
1260 if ( !v.isValid() || v ==
"" )
1265 categoryIndexes.append( i );
1268 if ( categoryIndexes.count() < 2 )
1272 QVariantList values;
1273 values.reserve( categoryIndexes.count() );
1274 labels.reserve( categoryIndexes.count() );
1275 for (
int i : categoryIndexes )
1277 QVariant v = categories.at( i ).value();
1279 if ( v.type() == QVariant::List )
1281 values.append( v.toList() );
1286 labels << categories.at( i ).label();
1290 mRenderer->updateCategoryLabel( categoryIndexes.at( 0 ), labels.join(
',' ) );
1291 mRenderer->updateCategoryValue( categoryIndexes.at( 0 ), values );
1293 categoryIndexes.pop_front();
1294 mModel->deleteRows( categoryIndexes );
1299 void QgsCategorizedSymbolRendererWidget::unmergeSelectedCategories()
1302 if ( categoryIndexes.isEmpty() )
1306 for (
int i : categoryIndexes )
1308 const QVariant v = categories.at( i ).value();
1309 if ( v.type() != QVariant::List )
1312 const QVariantList list = v.toList();
1313 for (
int j = 1; j < list.count(); ++j )
1315 mModel->addCategory(
QgsRendererCategory( list.at( j ), categories.at( i ).symbol()->clone(), list.at( j ).toString(), categories.at( i ).renderState() ) );
1317 mRenderer->updateCategoryValue( i, list.at( 0 ) );
1318 mRenderer->updateCategoryLabel( i, list.at( 0 ).toString() );
1324 void QgsCategorizedSymbolRendererWidget::showContextMenu( QPoint )
1326 mContextMenu->clear();
1327 const QList< QAction * > actions =
contextMenu->actions();
1328 for ( QAction *act : actions )
1330 mContextMenu->addAction( act );
1333 mContextMenu->addSeparator();
1335 if ( viewCategories->selectionModel()->selectedRows().count() > 1 )
1337 mContextMenu->addAction( mMergeCategoriesAction );
1339 if ( viewCategories->selectionModel()->selectedRows().count() == 1 )
1343 const QVariant v = categories.at( categoryIndexes.at( 0 ) ).value();
1344 if ( v.type() == QVariant::List )
1345 mContextMenu->addAction( mUnmergeCategoriesAction );
1347 else if ( viewCategories->selectionModel()->selectedRows().count() > 1 )
1349 mContextMenu->addAction( mUnmergeCategoriesAction );
1352 mContextMenu->exec( QCursor::pos() );
1355 void QgsCategorizedSymbolRendererWidget::selectionChanged(
const QItemSelection &,
const QItemSelection & )
1358 if ( !selectedCats.isEmpty() )
1360 whileBlocking( btnChangeCategorizedSymbol )->setSymbol(
mRenderer->categories().at( selectedCats.at( 0 ) ).symbol()->clone() );
1366 btnChangeCategorizedSymbol->setDialogTitle( selectedCats.size() == 1 ?
mRenderer->categories().at( selectedCats.at( 0 ) ).label() : tr(
"Symbol Settings" ) );
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
QString label() const
Returns the label for this category, which is used to represent the category within legends and the l...
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Abstract base class for all rendered symbols.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QgsSymbol * symbol() const
Returns the symbol which will be used to render this category.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
QVariant evaluate()
Evaluate the feature and return the result.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QColor color(double value) const override
Returns the color corresponding to a specified value.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
A QProxyStyle subclass which correctly sets the base style to match the QGIS application style...
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
A marker symbol type, for rendering Point and MultiPoint geometries.
static QgsStyle * defaultStyle()
Returns default application-wide style.
The QgsMapSettings class contains configuration for rendering of the map.
QList< QgsRendererCategory > QgsCategoryList
SymbolType
Type of the symbol.
static QgsCategoryList createCategories(const QVariantList &values, const QgsSymbol *symbol, QgsVectorLayer *layer=nullptr, const QString &fieldName=QString())
Create categories for a list of values.
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.
bool importXml(const QString &filename)
Imports the symbols and colorramps into the default style database from the given XML file...
const QgsCategoryList & categories() const
Returns a list of all categories recognized by the renderer.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Single scope for storing variables and functions for use within a QgsExpressionContext.
virtual void setTotalColorCount(int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
bool renderState() const
Returns true if the category is currently enabled and should be rendered.
Totally random color ramp.
QVariant value() const
Returns the value corresponding to this category.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
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...
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
static QgsCategorizedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
creates a QgsCategorizedSymbolRenderer from an existing renderer.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QString errorString()
Returns last error from load/save operation.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer...
void setColor(const QColor &color)
Sets the color for the symbol.