-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Allows extending of the polyline #1683
Conversation
src/tiled/editpolygontool.cpp
Outdated
@@ -566,6 +596,59 @@ void EditPolygonTool::updateMovingItems(const QPointF &pos, | |||
} | |||
} | |||
|
|||
void EditPolygonTool::addNode(const QPointF &pos, |
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.
The name addNode
does not seem to reflect what the function is doing. I think updateAddingNode
would be better, but it still leaves two kinds of terminology for the same thing. Since you're already using the mode Extending
and have mExtendingFirst
, I would suggest to rename all the other functions as follows:
updateExtending
finishExtending
cancelExtending
src/tiled/editpolygontool.h
Outdated
void addNode(const QPointF &pos, Qt::KeyboardModifiers modifiers); | ||
|
||
void finishAddingNode(); | ||
|
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.
Coding style: I'd suggest to leave out these empty lines so that the related functions are grouped together.
src/tiled/editpolygontool.h
Outdated
@@ -98,6 +108,7 @@ private slots: | |||
QPointF mStart; | |||
QPoint mScreenStart; | |||
Qt::KeyboardModifiers mModifiers; | |||
bool mExtendingFirst; |
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 know this variable isn't expected to be used before being set, but please anyway initialize the variable.
Hm. Could you rebase this instead of merging the master? For example you reordered the WangTool declaration as it is. |
Wait, I'll rebase this. |
mOverlayPolygonItem->setPolygon(next); | ||
|
||
if (mExtending) |
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.
Coding style: since the body wraps multiple lines, this should have braces.
@@ -75,15 +82,24 @@ void CreateMultipointObjectTool::mousePressedWhileCreatingObject(QGraphicsSceneM | |||
QPolygonF next = mOverlayPolygonObject->polygon(); | |||
|
|||
// If the last position is still the same, ignore the click | |||
if (next.last() == current.last()) | |||
if (next.last() == current.last() && !mExtending) |
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.
Why is this check irrelevant while extending? I think it was introduced to avoid inserting overlapping points in case the user double-clicks. It seems to me like it would be useful to check the first or last point, depending on mExtendingFirst
.
src/tiled/createobjecttool.h
Outdated
@@ -66,6 +69,8 @@ class CreateObjectTool : public AbstractObjectTool | |||
ObjectGroupItem *mObjectGroupItem; | |||
MapObjectItem *mNewMapObjectItem; | |||
MapObjectItem *mOverlayPolygonItem; | |||
bool mExtending; | |||
bool mExtendingFirst; |
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.
You can't in general extend an object so I'd prefer these variables to be in the CreateMultipointObjectTool
. At least mExtendingFirst
could easily be moved there since it isn't used in the base class. Regarding mExtending
, are there any functions that couldn't be just overridden?
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 tried overriding the functions cancelNewMapObject()
and finishNewMapObject()
, but apparently, the parent function gets called only and not the child one.
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 makes no sense, so I quickly searched where these functions are being called.
Turns out it's because the CreatePolylineObjectTool
is explicitly calling the functions of the CreateObjectTool
class here:
void CreatePolylineObjectTool::finishNewMapObject()
{
if (mNewMapObjectItem->mapObject()->polygon().size() >= 2)
CreateObjectTool::finishNewMapObject();
else
CreateObjectTool::cancelNewMapObject();
}
I see no reason why it should be doing that. There are no existing overrides that would need to be skipped. So please just remove the CreateObjectTool::
part there.
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.
Oh, right 🤦♂️
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 removed CreateObjectTool::
but added CreateMultipointObjectTool::
, because without any className::
, their was some runtime error (the window wasn't responding at all). I wasn't able to understand why this happened.
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.
Well, I missed it too, but this is obviously because we're in CreatePolylineObjectTool::finishNewMapObject
there, so we should at least avoid calling that exact function recursively.
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.
Oh, right 🤦♂️
src/tiled/mapeditor.cpp
Outdated
@@ -673,6 +677,17 @@ void MapEditor::setWangFill(bool value) | |||
mBucketFillTool->setWangFill(value); | |||
} | |||
|
|||
void MapEditor::extend(MapObjectItem *mapObjectItem, bool extendingFirst) | |||
{ | |||
setSelectedTool(mPolylineObjectsTool); |
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.
Using this instead of mToolManager->selectTool(mPolylineObjectsTool)
makes the tool switch without this being visible on the "Tools" tool bar. Was that a conscious decision? I think it wouldn't hurt for the user to see the active tool changing. Same for extendingFinished
.
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.
It looks like I got interrupted since I just found these comments still pending. :-/
src/tiled/createobjecttool.cpp
Outdated
@@ -88,7 +88,6 @@ void CreateObjectTool::keyPressed(QKeyEvent *event) | |||
case Qt::Key_Escape: | |||
if (mNewMapObjectItem) { | |||
cancelNewMapObject(); | |||
return; |
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.
Please don't remove this return, since it will cause the event to be ignored.
src/tiled/createobjecttool.cpp
Outdated
@@ -203,6 +202,7 @@ void CreateObjectTool::finishNewMapObject() | |||
} | |||
|
|||
MapObject *newMapObject = mNewMapObjectItem->mapObject(); | |||
|
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.
No point in adding a newline here.
@@ -52,7 +52,7 @@ MapObject *CreatePolygonObjectTool::createNewMapObject() | |||
void CreatePolygonObjectTool::finishNewMapObject() | |||
{ | |||
if (mNewMapObjectItem->mapObject()->polygon().size() >= 3) | |||
CreateObjectTool::finishNewMapObject(); | |||
finishNewMapObject(); |
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.
Should be CreateMultipointObjectTool::finishNewMapObject();
due to the problem you noticed in the polyline object tool.
mExtendingFirst = extendingFirst; | ||
|
||
mNewMapObjectItem = mapObjectItem; | ||
mOverlayPolygonObject = mapObjectItem->mapObject()->clone(); |
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.
The overlay polygon object is created already in the constructor of the CreateMultipointObjectTool
, so you can't just assign another object to it (causes leaking of the other object). I think you could just use the object that is already there, since it's only for showing a polygon preview anyway.
Extending can be done from first node as well
After we start extending the polyline, since we've shifted to the Create Polyline Tool, the color changes back to blue. Is this fine? |
The mExtendingFirst variable wasn't being reset.
The shape and position were not being set on the overlay object when extending a polyline, so it only worked when those were still set from the last created polyline.
I hoped it may be fine, but while checking it out it felt strange and it'd probably be better for just the new segment to be blue. I've pushed two bugfixes for things I noticed while testing. In addition to not coloring the whole line blue, I think we need to find a way to have the new segment show up immediately. Currently, you have to move your mouse at least once after clicking "Extend Polyline" to make the new segment show up. |
So probably, when the user clicks on the first/last node, the extending should begin? |
Well, then it would work mostly like Vectr, right? But if it's just activated on click, then we can't switch tools because we'd need it to not interfere with just trying to select some nodes. Or, it would need to work like Inkscape, where the nodes to click for extending the polyline are only visible in the "Insert Polyline" tool. Or we find some way to place the new node based on the current mouse position before we get the next mouse move event. |
@bjorn what exactly was wrong here? I'd like to get this one merged. |
@ketanhwr The main issues I seem to have ran into was that you need to move the mouse for the line to show up when extending the polyline, and that the whole thing turns blue rather than just the new line. For the overal implementation, I'd have to take a detailed look again and consider alternatives, but right now I'm trying to finish some stuff people have been paying for. Either this week or the next I'm also going to look at making some improvements to the polygon editing in general. |
Alright 🙂 |
Conflicts: src/tiled/editpolygontool.cpp
Hmm, I realized another problem with this implementation. Since it goes through the I'm considering a rather big rewrite of the whole polygon editing functionality, or at least to re-think it all from scratch based on the wishlist of functionality, because of the difficulties with putting such small functions on top of the current implementation. |
Interested in helping with this. |
This way, the "Extend Polyline" action also works in the Tile Collision Editor. Also, it no longer appears in the Template view, because with the current implementation it can't work there since the "Insert Polyline" tool is not available there.
Don't switch to EditPolygonTool when user selected another tool. This isn't what the user wants and it broke stuff.
There appears to be no difference between finishing or canceling the extending of a polyline. In both cases we switch back to the "Edit Polygons" tool and in both cases we should also make sure the object we were extending is selected. There shouldn't actually be a reason to touch the selection at all when starting or stopping to extend a polyline, but currently the selection outline does not update as expected while extending a polyline.
A few more fixes later, I think we can merge this, but I'll still be looking at redoing the general setup.
That is appreciated, but I'm under some time pressure to improve this aspect of Tiled and I don't currently see how we can do this together. |
#157
TODOs: