Conversation
|
I am very curious about what are you implementing with the Node Editor :-) I'll look through this PR Dmitry |
| void setNormalColor(QColor); | ||
| void setSelectedColor(QColor); | ||
| void setSelectedHaloColor(QColor); | ||
| void setHoveredColor(QColor); |
There was a problem hiding this comment.
Should we go further with the Qt-kung-fu and describe all the members in the class with Q_PROPERTY ?
As I understand, something like this
Q_PROPERTY(QColor color MEMBER m_color NOTIFY colorChanged)
would define a private member and generate setters and getters.
There was a problem hiding this comment.
Not a bad idea. E.g. when we implement a QML frontend, that could come in handy. IIUC, Q_PROPERTY only has meaning inside something that inherits from QObject, which the FooStyles currently don't. QObjects can't be copied, so there are some options:
- Pass around
std::unique_ptr<FooStyle>instead ofFooStyledirectly. - Make
FooStyletake aQObject* parent = Q_NULLPTRin its constructor. - Maybe this could work?: Write explicit copy constructors for
FooStyles
| ConnectionState _connectionState; | ||
| ConnectionGeometry _connectionGeometry; | ||
|
|
||
| ConnectionStyle const *_connectionStyle; |
There was a problem hiding this comment.
Sorry, maybe a stupid question -- why pointer?
There was a problem hiding this comment.
What other options were you thinking of?
ConnectionStyle _connectionStyle;This is expensive. We don't need a copy of theConnectionStyleobject for eachConnection, especially when they're all going to be the samestd::shared_ptr<ConnectionStyle const> _connectionStyle;This is unnecessary. TheConnectionStyleoutlives the connections anyway (correction: they can, but currently don't; that's something I will fix).ConnectionStyle const &_connectionStyle;I don't use references as class members, as references can't be rebound (they are effectively const). It doesn't matter here, asConnectioncan't be copied anyway, but I used a pointer instead for consistency.
There was a problem hiding this comment.
Here ConnectionStyle const & connectionStyle() const we convert this pointer back to a reference.
There was a problem hiding this comment.
True. The member is stored as a pointer, but is semantically a reference (that's the style I use anyway).
There was a problem hiding this comment.
- I did not see any setter function
- The copy constructor for
Connectionis deleted.
Therefore I suggested that this member shouldn't be rebound.
I'd simply use a const ref.
BTW, we should explicitly delete move constructor and move assignment operator for this class
| #include <QtGui/QColor> | ||
|
|
||
| #include <QString> | ||
| #include <QByteArray> |
There was a problem hiding this comment.
Too much pedantry but I write full paths for Qt includes: #include <QtCore/QString>
| ConnectionStyle:: | ||
| setConstructionColor(QColor color) | ||
| { | ||
| _constructionColor = std::move(color); |
There was a problem hiding this comment.
Ah, I couldn't tell from the documentation.
TBH, I tend to use std::move on anything that isn't a primitive (int, long, etc). I forget whether it has a benefit for a lot of types, so just using std::move means I don't have to go look up the documentation.
I'll remove these std::moves
There was a problem hiding this comment.
Sorry, I am not against this moves, it was just a note. No worries.
|
Maybe I am missing something. Before, it was possible to define a style per Can we repeat the same trick now? |
|
I removed Instead, users that want to customize the style per model (or internal model data) should implement |
| computeStyle(NodeStyle const *preferredStyle, NodeStyle const &backupStyle) | ||
| { | ||
| return preferredStyle ? preferredStyle : &backupStyle; | ||
| } |
| , _nodeDataModel(std::move(dataModel)) | ||
| , _nodeState(_nodeDataModel) | ||
| , _nodeGeometry(_nodeDataModel) | ||
| , _nodeStyle(computeStyle(_nodeDataModel->nodeStyle(), style)) |
There was a problem hiding this comment.
And this is maybe a reason to have a pointer.
There was a problem hiding this comment.
If computeStyle returns a NodeStyle const&, then _nodeStyle could also be a NodeStyle const&:
NodeStyle const&
computeStyle(NodeStyle const *preferredStyle, NodeStyle const &backupStyle)
{
return preferredStyle ? *preferredStyle : backupStyle;
}I'll change the style members from being const * to const &, unless you say otherwise
|
Should I bump the library version to 3? |
|
This would indeed be a breaking change. However, it might be beneficial to instead create something like a |
|
With this commit, note that I did not address the |
|
I haven't looked through the full usage of styles to see if this breaks something, but if these changes are being saved for a future breaking update, could the const be dropped from the StyleCollection getters in the meantime? In my local branch I dropped the consts and forwarded the getters through the NodeStyle/etc. classes. Things seem to be working normally and style properties can be set individually without using json strings. If I am understanding the current version, you can only set styles via json strings? This seems very awkward to me. |
Addresses #149
This PR makes a rather large amount of changes, as the singletons were used in many places.
Changes:
FlowViewStylebecomes a property ofFlowView, andConnectionStyleandNodeStyle(the default one, at least) become a property ofFlowScene.FlowView, the style can be passed as a parameter to the constructor, or via callingmyFlowView->setStyle(...).FlowScene, I chose not to allow the styles to be passed as parameters to the constructor. I am not sure of this decision. The problem was that I couldn't think of any reason to have the styles passed in one order or the other. Styles can still be set viascene->setConnectionStyle(...)andscene->setNodeStyle(...)*Styles are reworked.FooStyleobject, rather than solely through parsing JSONStyleImportclass are used.NodeDataModel::setStyleis removed.NodeDataModelis not in charge of managing the style, butNodeis. To use a custom style, one would override the newvirtual NodeStyle const* nodeStyle() const;function.std::functions, but if we made them our ownNodeModelCreator, there could be a way to set the style on the creator.Concerns: