-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to delete unused categories in the categorized symbol renderer widget #60641
base: master
Are you sure you want to change the base?
Conversation
I note that #60546 also modifies qgscategorizedsymbolrendererwidget.cpp. If the other PR is merged first, I am happy to resolve any conflicts and update this PR. |
🪟 Windows buildsDownload Windows builds of this PR for testing. 🪟 Windows Qt6 buildsDownload Windows Qt6 builds of this PR for testing. |
…to delete unused categories from the model/view. I.e. any categories which are not matched in the attribute field or expression used to categorize the layer.
245a43b
to
3c94b36
Compare
@troopa81, thanks for the review- I have rebased & updated with your suggestions. I don't understand the changes to the .ui file though. All I do is add a push button to the horizontal layout below the tree view widget. Also not sure why the layout/documentation checks are failing. Any ideas? |
OK, I think I've sorted out the issues with the .ui file. Files changed is only showing the inserted tags for the new push button. I also made sure the pre-commit hooks were installed as per: https://github.com/qgis/QGIS/blob/master/CONTRIBUTING.md before my last commit, but Code Layout/ documentation checks is still failing. I'm not sure why. |
You have undocumented method. I think it's deleteUnusedCategories() even if it's not exposed to python API. You can reproduce it on your side with the following command in the build directory
|
* | ||
* Called by addCategories() and deleteUnusedCategories() | ||
*/ | ||
QList<QVariant> layerUniqueValues( const QString attrName ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QList<QVariant> layerUniqueValues( const QString attrName ); | |
QList<QVariant> layerUniqueValues( const QString& attrName ); |
Description
This PR adds an option via a button in the categorized symbol renderer widget to delete unused categories from the model/view. I.e. any categories which are not matched in the attribute field or expression used to categorize the layer.
Example use case:
I have a layer of land systems covering the entire Northern Territory and a .qml style file which categorizes this layer into some 22 classes based on an attribute "CLASS".
Now I clip this NT-wide layer to a much smaller area. The subset only contains 7 of these classes, however I still want to load the style from the same .qml style file.
With the added option, one can quickly delete all the categories which are not used by the smaller subset layer:
In the added
void QgsCategorizedSymbolRendererWidget::deleteUnusedCategories()
method, I reused a block of code from the existingaddCategories()
method to build aQList<QVariant>
of unique values in the layer based on the current classification attribute or expression. To avoid duplication & to try and keep things tidy, I moved this block to a new protected method:QList<QVariant> QgsCategorizedSymbolRendererWidget::layerUniqueValues( QString attrName )
which returns the list of unique values and is then called in bothaddCategories()
anddeleteUnusedCategories()
.