47 #include <QMessageBox>
48 #include <QStandardItemModel>
49 #include <QStandardItem>
52 #include <QFileDialog>
57 QgsCategorizedSymbolRendererModel::QgsCategorizedSymbolRendererModel( QObject *parent ) : QAbstractItemModel( parent )
58 , mMimeFormat( QStringLiteral(
"application/x-qgscategorizedsymbolrendererv2model" ) )
66 beginRemoveRows( QModelIndex(), 0, std::max< int >( mRenderer->categories().size() - 1, 0 ) );
75 beginInsertRows( QModelIndex(), 0, renderer->
categories().size() - 1 );
83 if ( !mRenderer )
return;
84 const int idx = mRenderer->categories().size();
85 beginInsertRows( QModelIndex(), idx, idx );
86 mRenderer->addCategory( cat );
97 const int row = index.row();
98 if ( row >= catList.size() )
102 return catList.at( row );
106 Qt::ItemFlags QgsCategorizedSymbolRendererModel::flags(
const QModelIndex &index )
const
108 if ( !index.isValid() || !mRenderer )
110 return Qt::ItemIsDropEnabled;
113 Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable;
114 if ( index.column() == 1 )
117 if ( category.
value().type() != QVariant::List )
119 flags |= Qt::ItemIsEditable;
122 else if ( index.column() == 2 )
124 flags |= Qt::ItemIsEditable;
129 Qt::DropActions QgsCategorizedSymbolRendererModel::supportedDropActions()
const
131 return Qt::MoveAction;
134 QVariant QgsCategorizedSymbolRendererModel::data(
const QModelIndex &index,
int role )
const
136 if ( !index.isValid() || !mRenderer )
143 case Qt::CheckStateRole:
145 if ( index.column() == 0 )
147 return category.
renderState() ? Qt::Checked : Qt::Unchecked;
152 case Qt::DisplayRole:
153 case Qt::ToolTipRole:
155 switch ( index.column() )
159 if ( category.
value().type() == QVariant::List )
162 const QVariantList list = category.
value().toList();
163 res.reserve( list.size() );
164 for (
const QVariant &v : list )
167 if ( role == Qt::DisplayRole )
168 return res.join(
';' );
170 return res.join(
'\n' );
172 else if ( !category.
value().isValid() || category.
value().isNull() || category.
value().toString().isEmpty() )
174 return tr(
"all other values" );
178 return category.
value().toString();
182 return category.
label();
189 if ( index.column() == 1 && category.
value().type() != QVariant::List && ( !category.
value().isValid() || category.
value().isNull() || category.
value().toString().isEmpty() ) )
192 italicFont.setItalic(
true );
198 case Qt::DecorationRole:
200 if ( index.column() == 0 && category.
symbol() )
208 case Qt::ForegroundRole:
210 QBrush brush( qApp->palette().color( QPalette::Text ), Qt::SolidPattern );
211 if ( index.column() == 1 && ( category.
value().type() == QVariant::List
212 || !category.
value().isValid() || category.
value().isNull() || category.
value().toString().isEmpty() ) )
214 QColor fadedTextColor = brush.color();
215 fadedTextColor.setAlpha( 128 );
216 brush.setColor( fadedTextColor );
221 case Qt::TextAlignmentRole:
223 return ( index.column() == 0 ) ?
static_cast<Qt::Alignment::Int
>( Qt::AlignHCenter ) :
static_cast<Qt::Alignment::Int
>( Qt::AlignLeft );
228 switch ( index.column() )
232 if ( category.
value().type() == QVariant::List )
235 const QVariantList list = category.
value().toList();
236 res.reserve( list.size() );
237 for (
const QVariant &v : list )
240 return res.join(
';' );
244 return category.
value();
249 return category.
label();
258 bool QgsCategorizedSymbolRendererModel::setData(
const QModelIndex &index,
const QVariant &value,
int role )
260 if ( !index.isValid() )
263 if ( index.column() == 0 && role == Qt::CheckStateRole )
265 mRenderer->updateCategoryRenderState( index.row(), value == Qt::Checked );
266 emit dataChanged( index, index );
270 if ( role != Qt::EditRole )
273 switch ( index.column() )
279 switch ( mRenderer->categories().value( index.row() ).value().type() )
284 case QVariant::Double:
285 val = value.toDouble();
289 const QStringList parts = value.toString().split(
';' );
291 list.reserve( parts.count() );
292 for (
const QString &p : parts )
295 if ( list.count() == 1 )
302 val = value.toString();
305 mRenderer->updateCategoryValue( index.row(), val );
309 mRenderer->updateCategoryLabel( index.row(), value.toString() );
315 emit dataChanged( index, index );
319 QVariant QgsCategorizedSymbolRendererModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
321 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
324 lst << tr(
"Symbol" ) << tr(
"Value" ) << tr(
"Legend" );
325 return lst.value( section );
330 int QgsCategorizedSymbolRendererModel::rowCount(
const QModelIndex &parent )
const
332 if ( parent.isValid() || !mRenderer )
336 return mRenderer->categories().size();
339 int QgsCategorizedSymbolRendererModel::columnCount(
const QModelIndex &index )
const
345 QModelIndex QgsCategorizedSymbolRendererModel::index(
int row,
int column,
const QModelIndex &parent )
const
347 if ( hasIndex( row, column, parent ) )
349 return createIndex( row, column );
351 return QModelIndex();
354 QModelIndex QgsCategorizedSymbolRendererModel::parent(
const QModelIndex &index )
const
357 return QModelIndex();
360 QStringList QgsCategorizedSymbolRendererModel::mimeTypes()
const
363 types << mMimeFormat;
367 QMimeData *QgsCategorizedSymbolRendererModel::mimeData(
const QModelIndexList &indexes )
const
369 QMimeData *mimeData =
new QMimeData();
370 QByteArray encodedData;
372 QDataStream stream( &encodedData, QIODevice::WriteOnly );
375 const auto constIndexes = indexes;
376 for (
const QModelIndex &index : constIndexes )
378 if ( !index.isValid() || index.column() != 0 )
381 stream << index.row();
383 mimeData->setData( mMimeFormat, encodedData );
387 bool QgsCategorizedSymbolRendererModel::dropMimeData(
const QMimeData *data, Qt::DropAction action,
int row,
int column,
const QModelIndex &parent )
391 if ( action != Qt::MoveAction )
return true;
393 if ( !data->hasFormat( mMimeFormat ) )
return false;
395 QByteArray encodedData = data->data( mMimeFormat );
396 QDataStream stream( &encodedData, QIODevice::ReadOnly );
399 while ( !stream.atEnd() )
406 int to = parent.row();
409 if ( to == -1 ) to = mRenderer->categories().size();
410 for (
int i = rows.size() - 1; i >= 0; i-- )
412 QgsDebugMsg( QStringLiteral(
"move %1 to %2" ).arg( rows[i] ).arg( to ) );
415 if ( rows[i] < t ) t--;
416 mRenderer->moveCategory( rows[i], t );
418 for (
int j = 0; j < i; j++ )
420 if ( to < rows[j] && rows[i] > rows[j] ) rows[j] += 1;
423 if ( rows[i] < to ) to--;
425 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->categories().size(), 0 ) );
430 void QgsCategorizedSymbolRendererModel::deleteRows( QList<int> rows )
432 std::sort( rows.begin(), rows.end() );
433 for (
int i = rows.size() - 1; i >= 0; i-- )
435 beginRemoveRows( QModelIndex(), rows[i], rows[i] );
436 mRenderer->deleteCategory( rows[i] );
441 void QgsCategorizedSymbolRendererModel::removeAllRows()
443 beginRemoveRows( QModelIndex(), 0, mRenderer->categories().size() - 1 );
444 mRenderer->deleteAllCategories();
448 void QgsCategorizedSymbolRendererModel::sort(
int column, Qt::SortOrder order )
456 mRenderer->sortByValue( order );
458 else if ( column == 2 )
460 mRenderer->sortByLabel( order );
462 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->categories().size(), 0 ) );
465 void QgsCategorizedSymbolRendererModel::updateSymbology()
467 emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->categories().size(), 0 ) );
471 QgsCategorizedSymbolRendererViewStyle::QgsCategorizedSymbolRendererViewStyle( QWidget *parent )
475 void QgsCategorizedSymbolRendererViewStyle::drawPrimitive( PrimitiveElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget )
const
477 if ( element == QStyle::PE_IndicatorItemViewItemDrop && !option->rect.isNull() )
479 QStyleOption opt( *option );
480 opt.rect.setLeft( 0 );
482 opt.rect.setHeight( 0 );
483 if ( widget ) opt.rect.setRight( widget->width() );
484 QProxyStyle::drawPrimitive( element, &opt, painter, widget );
487 QProxyStyle::drawPrimitive( element, option, painter, widget );
500 , mContextMenu( new QMenu( this ) )
516 const QString attrName =
mRenderer->classAttribute();
517 mOldClassificationAttribute = attrName;
521 layout()->setContentsMargins( 0, 0, 0, 0 );
523 mExpressionWidget->setLayer(
mLayer );
524 btnChangeCategorizedSymbol->setLayer(
mLayer );
525 btnChangeCategorizedSymbol->registerExpressionContextGenerator(
this );
528 btnColorRamp->setShowRandomColorRamp(
true );
531 const QString defaultColorRamp =
QgsProject::instance()->
readEntry( QStringLiteral(
"DefaultStyles" ), QStringLiteral(
"/ColorRamp" ), QString() );
532 if ( !defaultColorRamp.isEmpty() )
534 btnColorRamp->setColorRampFromName( defaultColorRamp );
538 btnColorRamp->setRandomColorRamp();
548 mModel =
new QgsCategorizedSymbolRendererModel(
this );
554 viewCategories->setModel(
mModel );
555 viewCategories->resizeColumnToContents( 0 );
556 viewCategories->resizeColumnToContents( 1 );
557 viewCategories->resizeColumnToContents( 2 );
559 viewCategories->setStyle(
new QgsCategorizedSymbolRendererViewStyle( viewCategories ) );
560 connect( viewCategories->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsCategorizedSymbolRendererWidget::selectionChanged );
568 connect( viewCategories, &QTreeView::customContextMenuRequested,
this, &QgsCategorizedSymbolRendererWidget::showContextMenu );
570 connect( btnChangeCategorizedSymbol, &
QgsSymbolButton::changed,
this, &QgsCategorizedSymbolRendererWidget::updateSymbolsFromButton );
580 QMenu *advMenu =
new QMenu;
587 QAction *actionDdsLegend = advMenu->addAction( tr(
"Data-defined Size Legend…" ) );
589 connect( actionDdsLegend, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend );
592 btnAdvanced->setMenu( advMenu );
594 mExpressionWidget->registerExpressionContextGenerator(
this );
596 mMergeCategoriesAction =
new QAction( tr(
"Merge Categories" ),
this );
597 connect( mMergeCategoriesAction, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::mergeSelectedCategories );
598 mUnmergeCategoriesAction =
new QAction( tr(
"Unmerge Categories" ),
this );
599 connect( mUnmergeCategoriesAction, &QAction::triggered,
this, &QgsCategorizedSymbolRendererWidget::unmergeSelectedCategories );
601 connect( mContextMenu, &QMenu::aboutToShow,
this, [ = ]
622 const QString attrName =
mRenderer->classAttribute();
623 mExpressionWidget->setField( attrName );
635 btnColorRamp->setColorRamp(
mRenderer->sourceColorRamp() );
653 delete mActionLevels;
654 mActionLevels =
nullptr;
661 if ( !selectedCats.isEmpty() )
672 const auto constSelectedCats = selectedCats;
673 for (
const int idx : constSelectedCats )
679 mRenderer->updateCategorySymbol( idx, newCatSymbol );
702 if ( !dlg.exec() || !newSymbol )
725 if ( idx.isValid() && idx.column() == 0 )
733 std::unique_ptr< QgsSymbol > symbol;
735 if (
auto *lSymbol = category.
symbol() )
737 symbol.reset( lSymbol->clone() );
758 if ( !dlg.exec() || !symbol )
771 const QString attrName = mExpressionWidget->currentField();
773 QList<QVariant> uniqueValues;
791 if ( uniqueValues.contains( value ) )
793 uniqueValues << value;
802 if ( uniqueValues.size() >= 1000 )
804 const int res = QMessageBox::warning(
nullptr, tr(
"Classify Categories" ),
805 tr(
"High number of classes. Classification would yield %1 entries which might not be expected. Continue?" ).arg( uniqueValues.size() ),
806 QMessageBox::Ok | QMessageBox::Cancel,
807 QMessageBox::Cancel );
808 if ( res == QMessageBox::Cancel )
815 DlgAddCategories dlg(
mStyle, createDefaultSymbol(), unique_vals,
this );
821 bool deleteExisting =
false;
823 if ( !mOldClassificationAttribute.isEmpty() &&
824 attrName != mOldClassificationAttribute &&
827 const int res = QMessageBox::question(
this,
828 tr(
"Delete Classification" ),
829 tr(
"The classification field was changed from '%1' to '%2'.\n"
830 "Should the existing classes be deleted before classification?" )
831 .arg( mOldClassificationAttribute, attrName ),
832 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel );
833 if ( res == QMessageBox::Cancel )
838 deleteExisting = ( res == QMessageBox::Yes );
842 bool keepExistingColors =
false;
843 if ( !deleteExisting )
846 keepExistingColors = !prevCats.isEmpty();
848 if ( keepExistingColors && btnColorRamp->isRandomColorRamp() )
850 for (
int i = 0; i < cats.size(); ++i )
852 bool contains =
false;
853 const QVariant value = cats.at( i ).value();
854 for (
int j = 0; j < prevCats.size() && !contains; ++j )
856 const QVariant prevCatValue = prevCats.at( j ).value();
857 if ( prevCatValue.type() == QVariant::List )
859 const QVariantList list = prevCatValue.toList();
860 for (
const QVariant &v : list )
871 if ( prevCats.at( j ).value() == value )
882 if ( keepExistingColors && btnColorRamp->isRandomColorRamp() )
885 cats.at( i ).symbol()->setColor( randomColors.
color( i ) );
887 prevCats.append( cats.at( i ) );
893 mOldClassificationAttribute = attrName;
910 std::unique_ptr< QgsCategorizedSymbolRenderer > r = std::make_unique< QgsCategorizedSymbolRenderer >( attrName, cats );
912 std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
914 r->setSourceColorRamp( ramp->clone() );
918 mModel->setRenderer( r.get() );
921 if ( ! keepExistingColors && ramp )
928 if ( !btnColorRamp->isNull() )
930 mRenderer->updateColorRamp( btnColorRamp->colorRamp() );
932 mModel->updateSymbology();
937 const QModelIndex idx = viewCategories->selectionModel()->currentIndex();
938 if ( !idx.isValid() )
946 const QModelIndexList selectedRows = viewCategories->selectionModel()->selectedRows();
948 const auto constSelectedRows = selectedRows;
949 for (
const QModelIndex &r : constSelectedRows )
953 rows.append( r.row() );
962 mModel->deleteRows( categoryIndexes );
977 mModel->addCategory( cat );
985 QItemSelectionModel *m = viewCategories->selectionModel();
986 const QModelIndexList selectedIndexes = m->selectedRows( 1 );
988 if ( !selectedIndexes.isEmpty() )
991 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
992 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
994 const int row = ( *indexIt ).row();
1009 QItemSelectionModel *m = viewCategories->selectionModel();
1010 const QModelIndexList selectedIndexes = m->selectedRows( 1 );
1012 if ( !selectedIndexes.isEmpty() )
1014 QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
1015 for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
1017 cl.append(
mModel->category( *indexIt ) );
1036 viewCategories->selectionModel()->clear();
1044 QMessageBox::information(
this, tr(
"Matched Symbols" ),
1045 tr(
"Matched %1 categories to symbols." ).arg( matched ) );
1049 QMessageBox::warning(
this, tr(
"Matched Symbols" ),
1050 tr(
"No categories could be matched to symbols in library." ) );
1063 QVariantList unmatchedCategories;
1064 QStringList unmatchedSymbols;
1065 const int matched =
mRenderer->matchToSymbols( style, type, unmatchedCategories, unmatchedSymbols );
1067 mModel->updateSymbology();
1074 const QString openFileDir = settings.
value( QStringLiteral(
"UI/lastMatchToSymbolsDir" ), QDir::homePath() ).toString();
1076 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Match to Symbols from File" ), openFileDir,
1077 tr(
"XML files (*.xml *.XML)" ) );
1078 if ( fileName.isEmpty() )
1083 const QFileInfo openFileInfo( fileName );
1084 settings.
setValue( QStringLiteral(
"UI/lastMatchToSymbolsDir" ), openFileInfo.absolutePath() );
1087 if ( !importedStyle.
importXml( fileName ) )
1089 QMessageBox::warning(
this, tr(
"Match to Symbols from File" ),
1090 tr(
"An error occurred while reading file:\n%1" ).arg( importedStyle.
errorString() ) );
1097 QMessageBox::information(
this, tr(
"Match to Symbols from File" ),
1098 tr(
"Matched %1 categories to symbols from file." ).arg( matched ) );
1102 QMessageBox::warning(
this, tr(
"Match to Symbols from File" ),
1103 tr(
"No categories could be matched to symbols in file." ) );
1114 mRenderer->setLegendSymbolItem( legendSymbol.ruleKey(), sym->
clone() );
1117 mRenderer->setUsingSymbolLevels( enabled );
1118 mModel->updateSymbology();
1129 if ( !selectedCats.isEmpty() )
1131 for (
const int idx : selectedCats )
1133 if (
mRenderer->categories().at( idx ).symbol()->type() != tempSymbol->type() )
1136 std::unique_ptr< QgsSymbol > newCatSymbol( tempSymbol->clone() );
1137 if ( selectedCats.count() > 1 )
1140 newCatSymbol->setColor(
mRenderer->categories().at( idx ).symbol()->color() );
1142 mRenderer->updateCategorySymbol( idx, newCatSymbol.release() );
1148 void QgsCategorizedSymbolRendererWidget::cleanUpSymbolSelector(
QgsPanelWidget *container )
1157 void QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget()
1165 void QgsCategorizedSymbolRendererWidget::updateSymbolsFromButton()
1175 QItemSelectionModel *m = viewCategories->selectionModel();
1176 const QModelIndexList i = m->selectedRows();
1182 if ( !selectedCats.isEmpty() )
1184 const auto constSelectedCats = selectedCats;
1185 for (
const int idx : constSelectedCats )
1188 if ( selectedCats.count() > 1 )
1193 mRenderer->updateCategorySymbol( idx, newCatSymbol );
1202 mModel->updateSymbology();
1213 if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
1215 mCopyBuffer.clear();
1218 else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
1220 QgsCategoryList::const_iterator rIt = mCopyBuffer.constBegin();
1221 for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
1223 mModel->addCategory( *rIt );
1241 expContext << generator->createExpressionContextScope();
1262 void QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend()
1277 void QgsCategorizedSymbolRendererWidget::mergeSelectedCategories()
1282 QList< int > categoryIndexes;
1285 for (
const int i : selectedCategoryIndexes )
1287 const QVariant v = categories.at( i ).value();
1289 if ( !v.isValid() || v ==
"" )
1294 categoryIndexes.append( i );
1297 if ( categoryIndexes.count() < 2 )
1301 QVariantList values;
1302 values.reserve( categoryIndexes.count() );
1303 labels.reserve( categoryIndexes.count() );
1304 for (
const int i : categoryIndexes )
1306 const QVariant v = categories.at( i ).value();
1308 if ( v.type() == QVariant::List )
1310 values.append( v.toList() );
1315 labels << categories.at( i ).label();
1319 mRenderer->updateCategoryLabel( categoryIndexes.at( 0 ), labels.join(
',' ) );
1320 mRenderer->updateCategoryValue( categoryIndexes.at( 0 ), values );
1322 categoryIndexes.pop_front();
1323 mModel->deleteRows( categoryIndexes );
1328 void QgsCategorizedSymbolRendererWidget::unmergeSelectedCategories()
1331 if ( categoryIndexes.isEmpty() )
1335 for (
const int i : categoryIndexes )
1337 const QVariant v = categories.at( i ).value();
1338 if ( v.type() != QVariant::List )
1341 const QVariantList list = v.toList();
1342 for (
int j = 1; j < list.count(); ++j )
1344 mModel->addCategory(
QgsRendererCategory( list.at( j ), categories.at( i ).symbol()->clone(), list.at( j ).toString(), categories.at( i ).renderState() ) );
1346 mRenderer->updateCategoryValue( i, list.at( 0 ) );
1347 mRenderer->updateCategoryLabel( i, list.at( 0 ).toString() );
1353 void QgsCategorizedSymbolRendererWidget::showContextMenu( QPoint )
1355 mContextMenu->clear();
1356 const QList< QAction * > actions =
contextMenu->actions();
1357 for ( QAction *act : actions )
1359 mContextMenu->addAction( act );
1362 mContextMenu->addSeparator();
1364 if ( viewCategories->selectionModel()->selectedRows().count() > 1 )
1366 mContextMenu->addAction( mMergeCategoriesAction );
1368 if ( viewCategories->selectionModel()->selectedRows().count() == 1 )
1372 const QVariant v = categories.at( categoryIndexes.at( 0 ) ).value();
1373 if ( v.type() == QVariant::List )
1374 mContextMenu->addAction( mUnmergeCategoriesAction );
1376 else if ( viewCategories->selectionModel()->selectedRows().count() > 1 )
1378 mContextMenu->addAction( mUnmergeCategoriesAction );
1381 mContextMenu->exec( QCursor::pos() );
1384 void QgsCategorizedSymbolRendererWidget::selectionChanged(
const QItemSelection &,
const QItemSelection & )
1387 if ( !selectedCats.isEmpty() )
1389 whileBlocking( btnChangeCategorizedSymbol )->setSymbol(
mRenderer->categories().at( selectedCats.at( 0 ) ).symbol()->clone() );
1395 btnChangeCategorizedSymbol->setDialogTitle( selectedCats.size() == 1 ?
mRenderer->categories().at( selectedCats.at( 0 ) ).label() : tr(
"Symbol Settings" ) );
const QgsCategoryList & categories() const
Returns a list of all categories recognized by the renderer.
static QgsCategorizedSymbolRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer, QgsVectorLayer *layer=nullptr)
Creates a new QgsCategorizedSymbolRenderer from an existing renderer.
static QgsCategoryList createCategories(const QVariantList &values, const QgsSymbol *symbol, QgsVectorLayer *layer=nullptr, const QString &fieldName=QString())
Create categories for a list of values.
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.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QVariant evaluate()
Evaluate the feature and return the result.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
The QgsMapSettings class contains configuration for rendering of the map.
A marker symbol type, for rendering Point and MultiPoint geometries.
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,...
Totally random color ramp.
virtual void setTotalColorCount(int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
QColor color(double value) const override
Returns the color corresponding to a specified value.
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
QgsSymbol * symbol() const
Returns the symbol which will be used to render this category.
bool renderState() const
Returns true if the category is currently enabled and should be rendered.
QVariant value() const
Returns the value corresponding to this category.
QString label() const
Returns the label for this category, which is used to represent the category within legends and the l...
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.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QString errorString()
Returns last error from load/save operation.
static QgsStyle * defaultStyle()
Returns default application-wide style.
bool importXml(const QString &filename)
Imports the symbols and colorramps into the default style database from the given XML file.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
Abstract base class for all rendered symbols.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
void setColor(const QColor &color)
Sets the color for the symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const FINAL
Calculates a list of unique values contained within an attribute in the layer.
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,...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
QList< QgsRendererCategory > QgsCategoryList
QList< QgsLegendSymbolItem > QgsLegendSymbolList