-
-
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
Polygon Editing Tools Improvements #1674
Conversation
I've also added an option to extend a polyline (#157). Here's a gif for demonstration: |
src/tiled/editpolygontool.cpp
Outdated
|
||
if (mapObject->shape() == MapObject::Polyline) { | ||
QAction *extendPolyline = menu.addAction(tr("Extend Polyline")); | ||
extendPolyline->setEnabled(n == 1 && firstHandle->pointIndex() == mapObject->polygon().size() - 1); |
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 found this boolean expression a bit hard to read... Maybe passing it into a variable could help here (would also shorten the line a bit). But that might be personal taste...
Now, the user can extend a polyline from both the first point and the end point. Also, the user can use right click to cancel extending the polyline. |
While 'Extending' a polyline, the user can now choose to close it as well (Basically convert it into a polygon). (#404) |
When the user selects two nodes on a polygon which are side-by-side, then the user can delete that edge which will convert that polygon into a polyline. |
My previous commit closes #1555. Delete key now deletes the selected nodes. If no nodes are selected, then the object is deleted which was previously the standard action. |
Looks nice already Maybe ESC should cancel the extension process too (not only right click). |
src/tiled/editpolygontool.cpp
Outdated
|
||
QPolygonF polygon = mapObject->polygon(); | ||
|
||
if ((polygon.last() - polygon.first()).manhattanLength() < QApplication::startDragDistance() * 1.0) |
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.
Maybe introduce a variable for the left side of the <
here, to keep the line shorter?
src/tiled/editpolygontool.cpp
Outdated
QPolygonF polygon = mapObject->polygon(); | ||
|
||
if ((polygon.last() - polygon.first()).manhattanLength() < QApplication::startDragDistance() * 1.0) { | ||
|
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.
unneeded empty line
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.
left some quick comments
src/tiled/editpolygontool.cpp
Outdated
if (mapObject->shape() == MapObject::Polyline) { | ||
QAction *extendPolyline = menu.addAction(tr("Extend Polyline")); | ||
|
||
bool indexCheck = (firstHandle->pointIndex() == mapObject->polygon().size() - 1) || |
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 find the name indexCheck
a bit weird... Maybe handleCanBeExtended
?
src/tiled/mapeditor.cpp
Outdated
@@ -479,7 +480,10 @@ void MapEditor::performStandardAction(StandardAction action) | |||
paste(ClipboardManager::PasteInPlace); | |||
break; | |||
case DeleteAction: | |||
MapDocumentActionHandler::instance()->delete_(); | |||
if (mEditPolygonTool->countSelectedHandles()) |
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 personally do not like these implicit > 0 checks on integer values in this context. I usually prefer to write > 0
here. But not sure what @bjorn. Thinks here...
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 think, since this is really checking if there are any selected handles, it should be:
if (mEditPolygonTool->hasSelectedHandles())
And
bool hasSelectedHandles() const { return !mSelectedHandles.isEmpty(); }
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.
Just two points of feedback, didn't get around to a full review yet.
src/tiled/mapeditor.cpp
Outdated
@@ -479,7 +480,10 @@ void MapEditor::performStandardAction(StandardAction action) | |||
paste(ClipboardManager::PasteInPlace); | |||
break; | |||
case DeleteAction: | |||
MapDocumentActionHandler::instance()->delete_(); | |||
if (mEditPolygonTool->countSelectedHandles()) |
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 think, since this is really checking if there are any selected handles, it should be:
if (mEditPolygonTool->hasSelectedHandles())
And
bool hasSelectedHandles() const { return !mSelectedHandles.isEmpty(); }
src/libtiled/isometricrenderer.cpp
Outdated
@@ -441,22 +441,52 @@ void IsometricRenderer::drawMapObject(QPainter *painter, | |||
const QPolygonF polygon = object->polygon().translated(pos); | |||
QPolygonF screenPolygon = pixelToScreenCoords(polygon); | |||
|
|||
if (screenPolygon.size() == 1) | |||
screenPolygon.push_back(screenPolygon[0]); |
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 prefer to use the Qt-style members instead of those provided for STL compatibility, so append
instead of push_back
and removeLast
/ removeFirst
instead of pop_back
/ pop_front
.
In general, I think this pull request is too much of a collection of different issues. It would really help if separate pull requests were opened for things that aren't directly related to each other. |
So should I close this PR, and open separate PRs for different issues? :| |
I'd say keep this one for "reduced opacity of last edge" and "add option to extend polyline" (including from first node and right-click to cancel). And create separate PRs for:
Unless inter-dependent code makes this very difficult. |
Extending can be started from both first point and last point. Escape and Delete Key can be used to cancel the extending.
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.
Don't forget to initialize mComplete
and mLastEdgeIncomplete
.
In trying this out, I'm not convinced that rendering the new edge at lower opacity is currently helpful. All it does for me is to make it less visible.
Regarding the extending of the polyline, I'm wondering why it works only for a single segment. After extending by one segment, I think it should automatically allow me to extend with another segment, until I decide to press Enter or right-click, like it is when creating a new polyline.
Also, if we snap to the other end of the polyline to create a polygon, then I'd expect this snapping to be also available when creating a new polyline. Essentially implementing both parts of issue #404.
In general, I still think all these enhancements are quite independent and it would be better to do it as separate pull requests. It's easier to provide targeted feedback that way and some parts could be merged, like the handling of the Delete key.
QPolygonF polygon = mapObject->polygon(); | ||
qreal distance = (polygon.last() - polygon.first()).manhattanLength(); | ||
|
||
if (distance < QApplication::startDragDistance() * 1.0) |
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.
What's the point of multiplying by 1.0?
Also, distance
should be measured in screen pixels. Unfortunately, there is no way to determine the screen coordinates for a polygon point without a reference to the MapView
, but for now we should at least use renderer->pixelToScreenCoords
.
Finally, when the snapping triggers, it should change pixelCoords
to match the point to which it was snapped.
@@ -566,6 +598,92 @@ 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 this function is doing.
|
||
QPolygonF polygon = mapObject->polygon(); | ||
|
||
if (mapObject->shape() == MapObject::Polygon) |
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.
There is no point in this check, is there?
So basically, merge both the tools into a single tool ? |
Alright, then I'll close the current pull request. |
The opacity for preview edge is (1/3)rd of the fixed edges. Here's a screenshot: