-
Notifications
You must be signed in to change notification settings - Fork 59
[scg] Возможность изменения типа группы элементов #424
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
base: master
Are you sure you want to change the base?
Conversation
Energe-based arranger
fixed some build errors in scs plugin
removed dynamic_cast fixed code style
Done issue ostis-dev#152 + fix bug
Fixed build deb packages, issue ostis-dev#194
Fixed build deb depends, issue ostis-dev#194
Added asynchronous SCs parser. Updated SCs errors analyzer and autocompletion. Fixed: set focus on SCs editor when creating a new file or load file. Fixed some small errors.
Updated SCs code editor
Code refactoring. Add utf8 encoding
[scg] Fix problems with hotkeys (ostis-dev#387)
|
|
||
| foreach (SCgObject* object, objectList) | ||
| if (!object || (object->type() != objectList[0]->type())) | ||
| return false; |
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.
for (size_t i = 1; i < objectsList.size(); ++i)
{
SCgObject const * obj = objectList[i];
Q_ASSERT(obj); // we should not have nullptr in a list
if (obj->type() != objectList[0]->type())
return false;
}
sources/plugins/scg/scgobject.cpp
Outdated
| bool SCgObject::areObjectsOfEqualType(const SCgObject::SCgObjectList& objectList) | ||
| { | ||
| Q_ASSERT_X(!objectList.isEmpty(), "SCgObject::areObjectsOfEqualType", | ||
| "Ambiguous case: could not determine type equality for empty list of objects"); |
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.
Remove this assert
sources/plugins/scg/scgscene.cpp
Outdated
| QList<QGraphicsItem*> itemList = selectedItems(); | ||
| SCgObject::SCgObjectList objectList; | ||
|
|
||
| foreach (QGraphicsItem* item, itemList) |
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 use foreach
use C++11 instead
for (QGraphicsItem* item : itemList)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.
Also there we doesn't change item, so it should be QGraphicsItem const * item
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.
Quote from Qt Docs:
An alternative to Qt's foreach loop is the range-based for that is part of C++ 11 and newer. However, keep in mind that the range-based for might force a Qt container to detach, whereas foreach would not. But using foreach always copies the container, which is usually not cheap for STL containers. If in doubt, prefer foreach for Qt containers, and range based for for STL ones.
Detaching a container causes its deep copy. Therefore, foreach is preferable for Qt containers, that are used throughout the project (along with foreach).
Speaking about c++11, it is not yet included to the project. This should be done shortly.
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.
Add support of C++ 11 and use for (auto it : container)
| objectList.append(static_cast<SCgObject*>(item)); | ||
|
|
||
| return objectList; | ||
| } |
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.
rewrite
SCgBaseCommand* SCgScene::deleteSelObjectsCommand(SCgBaseCommand* parentCmd, bool addToStack)using this function inside
sources/plugins/scg/scgscene.cpp
Outdated
| SCgBaseCommand* cmd = new SCgBaseCommand(this, 0, parentCmd); | ||
| cmd->setText(QObject::tr("Change type of multiple objects")); | ||
|
|
||
| foreach (SCgObject* object, objList) |
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.
for (SCgObject* object : objList)| if (parentLayout) | ||
| parentLayout->addLayout(buttonLayout); | ||
| else | ||
| 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.
Strange logic. There should be exception error in this case or Q_ASSERT(parentLayout). I mean remove else return; and replace with check
sources/plugins/scg/scgview.cpp
Outdated
|
|
||
| SCgScene* SCgView::getSCgScene() const | ||
| { | ||
| QGraphicsScene* scene = QGraphicsView::scene(); |
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.
return static_cast<SCgScene*>(scene());
sources/plugins/scg/scgview.cpp
Outdated
| (*it)->setSelected(true); | ||
| } | ||
|
|
||
| bool SCgView::typeCanBeChanged() const |
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.
bool canChangeTypesOfSelection(const SCgObject::SCgObjectList & objectList)
sources/plugins/scg/scgview.cpp
Outdated
| { | ||
| if (!mContextObject) | ||
| return; | ||
| SCgObject::SCgObjectList objectList = getSCgScene()->getSelectedObjects(); |
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.
SCgObject::SCgObjectList const objectList = getSCgScene()->getSelectedObjects();
Q_ASSERT(canChangeTypes(objectList));
sources/plugins/scg/scgview.cpp
Outdated
| if (objectList.length() == 1) | ||
| changeType(objectList.first(), typeDialog.getChosenType()); | ||
| else | ||
| changeType(objectList, typeDialog.getChosenType()); |
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.
Replace to one command:
changeType(objectList, typeDialog.getChosenType());Doesn't need to process one item separately.
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 agree, that functions interface should be reduced to just
SCgScene::changeObjectTypeCommand(const SCgObject::SCgObjectList& objectList, ...)But inside it, single-object case should be separated, as it is handled differently (without creating parent QUndoCommand) and is widely used by a user.
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 not a problem, you should think, that change type of one element - is a command to change type of N elements, where N == 1.
Main goal to make code more suitable for support. This is not critical code for a memory and performance. So minimize number of code there
| Q_ASSERT(mContextObject); | ||
| if (object) | ||
| getSCgScene()->changeObjectTypeCommand(object, newType); | ||
| } |
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.
Remove this function
sources/plugins/scg/scgscene.cpp
Outdated
| } | ||
|
|
||
|
|
||
| SCgBaseCommand* SCgScene::changeObjectTypeCommand(SCgObject *object, const QString &type, SCgBaseCommand* parentCmd, bool addToStack) |
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.
Remove this function
06d9fb0 to
2c0c369
Compare
Изменения:
Close #423.