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

Invert Selection #1428

Merged
merged 4 commits into from
Jan 8, 2017
Merged

Invert Selection #1428

merged 4 commits into from
Jan 8, 2017

Conversation

MoctezumaDev
Copy link
Contributor

To fix this issue:

#1423

Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

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

Overall nice addition! I've added some inline comments for minor adjustments.

/*}*/
} else if (ObjectGroup *objectGroup = layer->asObjectGroup()) {
QList<MapObject*> allObjects = objectGroup->objects();
QList<MapObject*> selectedObjects = mMapDocument->selectedObjects();
Copy link
Member

Choose a reason for hiding this comment

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

Please use const & here since you're not going to modify these containers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean const QList<MapObject*> allObjects = objectGroup->objects(); ?

Copy link
Member

@bjorn bjorn Jan 7, 2017

Choose a reason for hiding this comment

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

No, I meant:

const QList<MapObject*> &allObjects = objectGroup->objects();

though you may also write:

const auto &allObjects = objectGroup->objects();

The point is to avoid the implicit copy, and to make sure const iterators are used (avoiding a deep copy).

QList<MapObject*> notSelectedObjects;

QList<MapObject*>::iterator i;
for(i=allObjects.begin(); i != allObjects.end(); ++i)
Copy link
Member

Choose a reason for hiding this comment

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

Please use a modern for-loop (and place opening { on the same line):

for (MapObject *mapObject : allObjects) {

selectAll();
} else if(mMapDocument->selectedArea() == all) {
selectNone();
} else {*/
Copy link
Member

Choose a reason for hiding this comment

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

These special cases need not to be made, because that's what should be happening automatically, right? Please drop the commented out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly, I forgot to remove those comments.

mMapDocument->undoStack()->push(command);
} else if (layer->asObjectGroup()) {
QList<MapObject*> emptyListOfObjects;
mMapDocument->setSelectedObjects(emptyListOfObjects);
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for fixing the unselect for object selection! Btw, you can write:

mMapDocument->setSelectedObjects(QList<MapObject*>());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree sometimes I do this kind of things for the sake of clarity.

@@ -555,7 +606,19 @@ void MapDocumentActionHandler::updateActions()
}

mActionSelectAll->setEnabled(map);
mActionSelectNone->setEnabled(!selection.isEmpty());

if(currentLayer) {
Copy link
Member

Choose a reason for hiding this comment

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

Please put a space between if and (.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

if (currentLayer->asTileLayer()) {
mActionSelectNone->setEnabled(!selection.isEmpty());
} else if (currentLayer->asObjectGroup()) {
mActionSelectNone->setEnabled(mMapDocument->selectedObjects().count() > 0);
Copy link
Member

Choose a reason for hiding this comment

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

Please also use selectedObjectsCount here, because mMapDocument may be null.

@MoctezumaDev
Copy link
Contributor Author

I made the requested changes

QList<MapObject*> selectedObjects = mMapDocument->selectedObjects();
QList<MapObject*> notSelectedObjects;

for (auto& mapObject : allObjects) {
Copy link
Member

Choose a reason for hiding this comment

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

Please don't write a & here because you're creating a reference to a pointer. Just auto is enough.

/*}*/
} else if (ObjectGroup *objectGroup = layer->asObjectGroup()) {
QList<MapObject*> allObjects = objectGroup->objects();
QList<MapObject*> selectedObjects = mMapDocument->selectedObjects();
Copy link
Member

@bjorn bjorn Jan 7, 2017

Choose a reason for hiding this comment

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

No, I meant:

const QList<MapObject*> &allObjects = objectGroup->objects();

though you may also write:

const auto &allObjects = objectGroup->objects();

The point is to avoid the implicit copy, and to make sure const iterators are used (avoiding a deep copy).

Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

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

Added two tiny further comments.

QList<MapObject*> notSelectedObjects;

for (auto& mapObject : allObjects) {
if(!selectedObjects.contains(mapObject)) {
Copy link
Member

Choose a reason for hiding this comment

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

Please put a space between if and (.

Copy link
Contributor Author

@MoctezumaDev MoctezumaDev left a comment

Choose a reason for hiding this comment

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

I did the changes as previously requested

@bjorn bjorn merged commit f3423c4 into mapeditor:master Jan 8, 2017
@bjorn
Copy link
Member

bjorn commented Jan 8, 2017

Looks good, thanks!

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