Skip to content
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

Added drag and drop functionalities to the map. You can drag items fr… #50

Closed
wants to merge 0 commits into from

Conversation

leonardooyama
Copy link
Contributor

…om a QTreeWidget to the map in order to position it on the map. Unfortunately, the anchor parameter was removed from the setGeometry method in QGVIcon and QGVImage. I would like to see it back to the code.

@AmonRaNet
Copy link
Owner

There is few issues with code:

  • QDropEvent::position() was introduced since Qt 6.0 and as QGV provide supports for version 5.0 it should be wrapped to needed ifdef
  • pre-commit validation is failing (https://github.com/AmonRaNet/QGeoView/actions/runs/8950433982/job/24585798292?pr=50):
    • "Mixed line ending" - \n and \r\n not allowed in same file (check other files, but I am sure but project mostly uses UNIX style)
    • "clang-format" - simply check result of failed run or apply clang-format
    • "Update legacy headers" - all files in project should have same legacy header. You can copy it from other file

Easiest way to fix all pre-commit issues is to run pre-commit under root of repo locally - it will fix all issues for you (https://pre-commit.com/):

  • pre-commit run --all

Sorry, but I very pedantic around coding conventions :)

private:
QScopedPointer<QGVProjection> mProjection;
QScopedPointer<QGVMapQGView> mQGView;
QScopedPointer<QGVItem> mRootItem;
QList<QGVWidget*> mWidgets;
QSet<QGVItem*> mSelections;

private slots:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use keywords reserved by Qt directly - it can collide with other frameworks. if you need slots please use instead Q_SLOTS.

Since Qt 5.0 is no need to declare methods as slots as any method can be act as slot for signal connection. Only if you need to call method over QMetaObject::invokeMethod it becomes as mandatory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will remove it.

private:
QScopedPointer<QGVProjection> mProjection;
QScopedPointer<QGVMapQGView> mQGView;
QScopedPointer<QGVItem> mRootItem;
QList<QGVWidget*> mWidgets;
QSet<QGVItem*> mSelections;

private slots:
void handleDropDataOnQGVMapQGView(QPointF position, const QMimeData *dropData);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit more pedantic :) issues - please keep member variables at the end of class declaration - it mean all your declarations would be better to locate above member variables section.
Ideally:

class
{
public:
..
Q_SIGNALS:
..
protected:
..
private:
...
member variables
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

@@ -102,4 +113,6 @@ class QGV_LIB_DECL QGVMapQGView : public QGraphicsView
QScopedPointer<QGraphicsScene> mQGScene;
QScopedPointer<QGVMapRubberBand> mSelectionRect;
QScopedPointer<QMenu> mContextMenu;
signals:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

{
if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist"))
{
emit dropData(event->position(), event->mimeData());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto please use Q_EMIT

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I wounder if we can simply propagate QDropEvent to map. As you have ignored event it should be propagated to parent of item (probably QGraphicsView::dropEvent(event) need to be called before return). In this case we can remove need of signal and instead write logic directly in
QGVMap::dropEvent(QDropEvent* event)

It will give more freedom for future development as QGVMap::dropEvent can be overwritten by anybody and more complex handling can be added (new mime types, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first thing I tried was to subclass QGVMap to add the accept drop functionality, because I didn't want to change your library. However QGVMap inherits from QWidget. It looks that QWidget doesn't send the drop event to a child QGraphicsView inside of it. I think this is a limitation of QWidget or QGraphicsView, not sure (maybe this is the correct behavior).
Then I realized that I would need to change QGVMapQGView class to achieve the intended behavior.

Well... I didn't restricted the mime types, so there is a plenty of freedom for new implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong. I really restricted the type of mime-data on the QGVMapQGView class. Sorry. I just fixed all the remaining errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I did my best to fix clang-forma error on pre-commit. Unfortunately, I could not fix it locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants