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 this->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();
541 mModel =
new QgsCategorizedSymbolRendererModel(
this );
547 viewCategories->setModel(
mModel );
548 viewCategories->resizeColumnToContents( 0 );
549 viewCategories->resizeColumnToContents( 1 );
550 viewCategories->resizeColumnToContents( 2 );
552 viewCategories->setStyle(
new QgsCategorizedSymbolRendererViewStyle( viewCategories ) );
553 connect( viewCategories->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCategorizedSymbolRendererWidget::selectionChanged );
561 connect( viewCategories, &QTreeView::customContextMenuRequested,
this, &QgsCategorizedSymbolRendererWidget::showContextMenu );
563 connect( btnChangeCategorizedSymbol, &
QgsSymbolButton::changed,
this, &QgsCategorizedSymbolRendererWidget::updateSymbolsFromButton );
573 QMenu *advMenu =
new QMenu;
577 advMenu->addAction( tr(
"Symbol Levels…" ),
this, SLOT(
showSymbolLevels() ) );
580 QAction *actionDdsLegend = advMenu->addAction( tr(
"Data-defined Size Legend…" ) );
582 connect( actionDdsLegend, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend );
585 btnAdvanced->setMenu( advMenu );
587 mExpressionWidget->registerExpressionContextGenerator(
this );
589 mMergeCategoriesAction =
new QAction( tr(
"Merge Categories" ),
this );
590 connect( mMergeCategoriesAction, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::mergeSelectedCategories );
591 mUnmergeCategoriesAction =
new QAction( tr(
"Unmerge Categories" ),
this );
592 connect( mUnmergeCategoriesAction, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::unmergeSelectedCategories );
594 connect( mContextMenu, &QMenu::aboutToShow,
this, [ = ]
615 QString attrName =
mRenderer->classAttribute();
616 mExpressionWidget->setField( attrName );
628 btnColorRamp->setColorRamp(
mRenderer->sourceColorRamp() );
640 btnChangeCategorizedSymbol->setMapCanvas( context.
mapCanvas() );
641 btnChangeCategorizedSymbol->setMessageBar( context.
messageBar() );
648 if ( !selectedCats.isEmpty() )
659 const auto constSelectedCats = selectedCats;
660 for (
int idx : constSelectedCats )
666 mRenderer->updateCategorySymbol( idx, newCatSymbol );
689 if ( !dlg.exec() || !newSymbol )
712 if ( idx.isValid() && idx.column() == 0 )
720 std::unique_ptr< QgsSymbol > symbol;
745 if ( !dlg.exec() || !symbol )
758 QString attrName = mExpressionWidget->currentField();
760 QList<QVariant> uniqueValues;
771 expression->
prepare( &context );
777 QVariant value = expression->
evaluate( &context );
778 if ( uniqueValues.contains( value ) )
780 uniqueValues << value;
789 if ( uniqueValues.size() >= 1000 )
791 int res = QMessageBox::warning(
nullptr, tr(
"Classify Categories" ),
792 tr(
"High number of classes. Classification would yield %1 entries which might not be expected. Continue?" ).arg( uniqueValues.size() ),
793 QMessageBox::Ok | QMessageBox::Cancel,
794 QMessageBox::Cancel );
795 if ( res == QMessageBox::Cancel )
802 DlgAddCategories dlg(
mStyle, createDefaultSymbol(), unique_vals,
this );
808 bool deleteExisting =
false;
810 if ( !mOldClassificationAttribute.isEmpty() &&
811 attrName != mOldClassificationAttribute &&
814 int res = QMessageBox::question(
this,
815 tr(
"Delete Classification" ),
816 tr(
"The classification field was changed from '%1' to '%2'.\n" 817 "Should the existing classes be deleted before classification?" )
818 .arg( mOldClassificationAttribute, attrName ),
819 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel );
820 if ( res == QMessageBox::Cancel )
825 deleteExisting = ( res == QMessageBox::Yes );
829 bool keepExistingColors =
false;
830 if ( !deleteExisting )
833 keepExistingColors = !prevCats.isEmpty();
835 if ( keepExistingColors && btnColorRamp->isRandomColorRamp() )
837 for (
int i = 0; i < cats.size(); ++i )
839 bool contains =
false;
840 QVariant value = cats.at( i ).value();
841 for (
int j = 0; j < prevCats.size() && !contains; ++j )
843 const QVariant prevCatValue = prevCats.at( j ).value();
844 if ( prevCatValue.type() == QVariant::List )
846 const QVariantList list = prevCatValue.toList();
847 for (
const QVariant &v : list )
858 if ( prevCats.at( j ).value() == value )
869 if ( keepExistingColors && btnColorRamp->isRandomColorRamp() )
872 cats.at( i ).symbol()->setColor( randomColors.
color( i ) );
874 prevCats.append( cats.at( i ) );
880 mOldClassificationAttribute = attrName;
897 std::unique_ptr< QgsCategorizedSymbolRenderer > r = qgis::make_unique< QgsCategorizedSymbolRenderer >( attrName, cats );
899 std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
901 r->setSourceColorRamp( ramp->clone() );
905 mModel->setRenderer( r.get() );
908 if ( ! keepExistingColors && ramp )
915 if ( !btnColorRamp->isNull() )
917 mRenderer->updateColorRamp( btnColorRamp->colorRamp() );
919 mModel->updateSymbology();
924 QModelIndex idx = viewCategories->selectionModel()->currentIndex();
925 if ( !idx.isValid() )
933 QModelIndexList selectedRows = viewCategories->selectionModel()->selectedRows();
935 const auto constSelectedRows = selectedRows;
936 for (
const QModelIndex &r : constSelectedRows )
940 rows.append( r.row() );
949 mModel->deleteRows( categoryIndexes );
964 mModel->addCategory( cat );
972 QItemSelectionModel *m = viewCategories->selectionModel();
973 QModelIndexList selectedIndexes = m->selectedRows( 1 );
975 if ( m && !selectedIndexes.isEmpty() )
978 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
979 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
981 int row = ( *indexIt ).row();
985 selectedSymbols.append( s );
996 QItemSelectionModel *m = viewCategories->selectionModel();
997 QModelIndexList selectedIndexes = m->selectedRows( 1 );
999 if ( m && !selectedIndexes.isEmpty() )
1001 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
1002 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1004 cl.append(
mModel->category( *indexIt ) );
1023 viewCategories->selectionModel()->clear();
1031 QMessageBox::information(
this, tr(
"Matched Symbols" ),
1032 tr(
"Matched %1 categories to symbols." ).arg( matched ) );
1036 QMessageBox::warning(
this, tr(
"Matched Symbols" ),
1037 tr(
"No categories could be matched to symbols in library." ) );
1050 QVariantList unmatchedCategories;
1051 QStringList unmatchedSymbols;
1052 const int matched =
mRenderer->matchToSymbols( style, type, unmatchedCategories, unmatchedSymbols );
1054 mModel->updateSymbology();
1061 QString openFileDir = settings.
value( QStringLiteral(
"UI/lastMatchToSymbolsDir" ), QDir::homePath() ).toString();
1063 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Match to Symbols from File" ), openFileDir,
1064 tr(
"XML files (*.xml *.XML)" ) );
1065 if ( fileName.isEmpty() )
1070 QFileInfo openFileInfo( fileName );
1071 settings.
setValue( QStringLiteral(
"UI/lastMatchToSymbolsDir" ), openFileInfo.absolutePath() );
1074 if ( !importedStyle.
importXml( fileName ) )
1076 QMessageBox::warning(
this, tr(
"Match to Symbols from File" ),
1077 tr(
"An error occurred while reading file:\n%1" ).arg( importedStyle.
errorString() ) );
1084 QMessageBox::information(
this, tr(
"Match to Symbols from File" ),
1085 tr(
"Matched %1 categories to symbols from file." ).arg( matched ) );
1089 QMessageBox::warning(
this, tr(
"Match to Symbols from File" ),
1090 tr(
"No categories could be matched to symbols in file." ) );
1101 if ( !selectedCats.isEmpty() )
1103 for (
int idx : selectedCats )
1105 if (
mRenderer->categories().at( idx ).symbol()->type() != tempSymbol->type() )
1108 std::unique_ptr< QgsSymbol > newCatSymbol( tempSymbol->clone() );
1109 if ( selectedCats.count() > 1 )
1112 newCatSymbol->setColor(
mRenderer->categories().at( idx ).symbol()->color() );
1114 mRenderer->updateCategorySymbol( idx, newCatSymbol.release() );
1120 void QgsCategorizedSymbolRendererWidget::cleanUpSymbolSelector(
QgsPanelWidget *container )
1129 void QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget()
1137 void QgsCategorizedSymbolRendererWidget::updateSymbolsFromButton()
1147 QItemSelectionModel *m = viewCategories->selectionModel();
1148 QModelIndexList i = m->selectedRows();
1150 if ( m && !i.isEmpty() )
1154 if ( !selectedCats.isEmpty() )
1156 const auto constSelectedCats = selectedCats;
1157 for (
int idx : constSelectedCats )
1160 if ( selectedCats.count() > 1 )
1165 mRenderer->updateCategorySymbol( idx, newCatSymbol );
1174 mModel->updateSymbology();
1185 if ( event->key() == Qt::Key_C &&
event->modifiers() == Qt::ControlModifier )
1187 mCopyBuffer.clear();
1190 else if ( event->key() == Qt::Key_V &&
event->modifiers() == Qt::ControlModifier )
1192 QgsCategoryList::const_iterator rIt = mCopyBuffer.constBegin();
1193 for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
1195 mModel->addCategory( *rIt );
1230 void QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend()
1238 mRenderer->setDataDefinedSizeLegend( panel->dataDefinedSizeLegend() );
1245 void QgsCategorizedSymbolRendererWidget::mergeSelectedCategories()
1250 QList< int > categoryIndexes;
1253 for (
int i : selectedCategoryIndexes )
1255 QVariant v = categories.at( i ).value();
1257 if ( !v.isValid() || v ==
"" )
1262 categoryIndexes.append( i );
1265 if ( categoryIndexes.count() < 2 )
1269 QVariantList values;
1270 values.reserve( categoryIndexes.count() );
1271 labels.reserve( categoryIndexes.count() );
1272 for (
int i : categoryIndexes )
1274 QVariant v = categories.at( i ).value();
1276 if ( v.type() == QVariant::List )
1278 values.append( v.toList() );
1283 labels << categories.at( i ).label();
1287 mRenderer->updateCategoryLabel( categoryIndexes.at( 0 ), labels.join(
',' ) );
1288 mRenderer->updateCategoryValue( categoryIndexes.at( 0 ), values );
1290 categoryIndexes.pop_front();
1291 mModel->deleteRows( categoryIndexes );
1296 void QgsCategorizedSymbolRendererWidget::unmergeSelectedCategories()
1299 if ( categoryIndexes.isEmpty() )
1303 for (
int i : categoryIndexes )
1305 const QVariant v = categories.at( i ).value();
1306 if ( v.type() != QVariant::List )
1309 const QVariantList list = v.toList();
1310 for (
int j = 1; j < list.count(); ++j )
1312 mModel->addCategory(
QgsRendererCategory( list.at( j ), categories.at( i ).symbol()->clone(), list.at( j ).toString(), categories.at( i ).renderState() ) );
1314 mRenderer->updateCategoryValue( i, list.at( 0 ) );
1315 mRenderer->updateCategoryLabel( i, list.at( 0 ).toString() );
1321 void QgsCategorizedSymbolRendererWidget::showContextMenu( QPoint )
1323 mContextMenu->clear();
1324 const QList< QAction * > actions =
contextMenu->actions();
1325 for ( QAction *act : actions )
1327 mContextMenu->addAction( act );
1330 mContextMenu->addSeparator();
1332 if ( viewCategories->selectionModel()->selectedRows().count() > 1 )
1334 mContextMenu->addAction( mMergeCategoriesAction );
1336 if ( viewCategories->selectionModel()->selectedRows().count() == 1 )
1340 const QVariant v = categories.at( categoryIndexes.at( 0 ) ).value();
1341 if ( v.type() == QVariant::List )
1342 mContextMenu->addAction( mUnmergeCategoriesAction );
1344 else if ( viewCategories->selectionModel()->selectedRows().count() > 1 )
1346 mContextMenu->addAction( mUnmergeCategoriesAction );
1349 mContextMenu->exec( QCursor::pos() );
1352 void QgsCategorizedSymbolRendererWidget::selectionChanged(
const QItemSelection &,
const QItemSelection & )
1355 if ( !selectedCats.isEmpty() )
1357 whileBlocking( btnChangeCategorizedSymbol )->setSymbol(
mRenderer->categories().at( selectedCats.at( 0 ) ).symbol()->clone() );
1363 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.
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.