-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[feature] adds diagram legend #1977
Conversation
@@ -94,6 +94,9 @@ class QgsDiagramSettings | |||
|
|||
void readXML( const QDomElement& elem, const QgsVectorLayer* layer ); | |||
void writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const; | |||
|
|||
//! @note caller is responsible for deletion of QStandardItems | |||
QList< QStandardItem * > legendItems() const; |
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.
I'm not 100% sure, but possibly these should be marked /Factory/ so that python will clean the created items when they go out of scope
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.
That's correct. Also it would be useful to add notes that the method was added in 2.10
Generally looks good to me, nice work! I wonder if it's worth adding an option to disable the legend for a diagram? It's also not possible to rename the legend items, which means they can't be customized in composer legends. This should be addressed as the default name looks odd given that it's always surrounded by quotation marks (or is a raw expression). |
Is there any reason to use QStandardItem instead of QgsLayerTreeModelLegendNode instances? The QStandardItem instances just seems as a means to transport icon + label. I strongly recommend using directly QgsLayerTreeModelLegendNode, otherwise it will be difficult to add further functionality to the diagram legend nodes when the legend nodes API is extended. |
@wonder-sk QgsRendererV2::legendSymbologyItems does not return QgsLayerTreeModelLegendNode(s) either and QgsLayerTreeModelLegendNode needs a QgsLayerTreeLayer. Should I pass that as an argument to QgsDiagramRendererV2::legendItems() ? I started with returning a list of QSharedPtr but the python conversion won't work well in this case. Also I tried to embed the symbol (when embeddable) and noticed that the logic in QgsLayerTreeModel won't allow that easily. |
ping @wonder-sk |
I believe those modifications take care of all the mentioned issues. |
@vmora - hmm, something's still missing which is preventing editing the item text in composer legends. @wonder-sk any ideas? |
sorry for the lag, I have been busy recently. I will try to have a look this week... |
@vmora It looks great - thanks for the updates. The missing bit for composer legend will be a missing implementation of data() for RuleKeyRole. Probably QgsSimpleLegendNode (which is used for diagram legend nodes) could be extended to keep also the "rule key" string which uniquely identifies the node within legend of layer. The PR cannot be automatically merged anymore - could you please update it? (and possibly fix the composer issue) |
added editable labels in the legend configuration
added rule key to QgsSymbolV2LegendNode
@wonder-sk I did the rebase (first commit) I also tried adding a RuleKeyRole (second commit) but it does not seem to have an effect in the composer. Do you know what I'm missing ? |
@@ -206,6 +207,16 @@ QList<QgsLayerTreeModelLegendNode*> QgsDefaultVectorLayerLegend::createLayerTree | |||
if ( nodes.count() == 1 && nodes[0]->data( Qt::EditRole ).toString().isEmpty() ) | |||
nodes[0]->setEmbeddedInParent( true ); | |||
|
|||
|
|||
if ( mLayer->diagramRenderer() ) |
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.
this should be
if ( mLayer->diagramsEnabled() )
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.
done. You're right, I avoid having the lengend appear even if the diagram is disabled. Thanks @nyalldawson
Change test for legend to diagramEnabled in map layer diagram
prepare-commit.sh added some spacing in some otherwise unmodified lines.