Removed memory leaks at deletion of UBGraphicsGroupContainerItem.

Corrected adding items to group.
Corrected group creation.
Corrected adding items to scene - items shouldn't be added to itemsToRemove list because that list needs for cleaning undo stack.
Improved mechanism of removing "itemsToRemove".
Removed wrong deletion of mButtons list from UBGraphicsItemDelegate destructor because that buttons has Frame as parent.
Removed possible memory leak in UBBoardController::clearUndoStack. Some items was able not deleted.
tmpScene in cffReader not deletes now because ithas a proxy as parent.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent 573d6c4d68
commit 990458d187
  1. 2
      src/adaptors/UBCFFSubsetAdaptor.cpp
  2. 3
      src/board/UBBoardController.cpp
  3. 33
      src/domain/UBGraphicsGroupContainerItem.cpp
  4. 3
      src/domain/UBGraphicsGroupContainerItem.h
  5. 3
      src/domain/UBGraphicsItemDelegate.cpp
  6. 2
      src/domain/UBGraphicsScene.cpp
  7. 27
      src/frameworks/UBCoreGraphicsScene.cpp

@ -1189,8 +1189,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::persistScenes()
UBGraphicsScene *tmpScene = UBSvgSubsetAdaptor::loadScene(mProxy, i);
tmpScene->setModified(true);
UBThumbnailAdaptor::persistScene(mProxy, tmpScene, i);
delete tmpScene;
mCurrentScene->setModified(false);
}

@ -1515,7 +1515,8 @@ void UBBoardController::ClearUndoStack()
}
if(!scene)
{
mActiveScene->deleteItem(item);
if (!mActiveScene->deleteItem(item))
delete item;
}
}

@ -28,18 +28,12 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent
setUuid(QUuid::createUuid());
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
}
UBGraphicsGroupContainerItem::~UBGraphicsGroupContainerItem()
{
foreach (QGraphicsItem *item, childItems())
{
removeFromGroup(item);
if (item && item->scene())
item->scene()->removeItem(item);
}
if (mDelegate)
delete mDelegate;
}
void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
@ -83,6 +77,8 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
QTransform newItemTransform(itemTransform);
item->setPos(mapFromItem(item, 0, 0));
item->scene()->removeItem(item);
item->setParentItem(this);
// removing position from translation component of the new transform
@ -113,10 +109,12 @@ void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item)
{
if (!item) {
qDebug() << "can't specify the item because of the null pointer";
return;
}
UBGraphicsScene *groupScene = scene();
if (groupScene) {
UBCoreGraphicsScene *groupScene = corescene();
if (groupScene)
{
groupScene->addItemToDeletion(item);
}
@ -170,9 +168,9 @@ void UBGraphicsGroupContainerItem::paint(QPainter *painter, const QStyleOptionGr
// }
}
UBGraphicsScene *UBGraphicsGroupContainerItem::scene()
UBCoreGraphicsScene *UBGraphicsGroupContainerItem::corescene()
{
UBGraphicsScene *castScene = dynamic_cast<UBGraphicsScene*>(QGraphicsItem::scene());
UBCoreGraphicsScene *castScene = dynamic_cast<UBCoreGraphicsScene*>(QGraphicsItem::scene());
return castScene;
}
@ -218,15 +216,14 @@ void UBGraphicsGroupContainerItem::setUuid(const QUuid &pUuid)
void UBGraphicsGroupContainerItem::destroy() {
UBGraphicsScene *groupScene = scene();
UBCoreGraphicsScene *groupScene = corescene();
foreach (QGraphicsItem *item, childItems()) {
if (groupScene) {
groupScene->addItemToDeletion(item);
}
if (groupScene) {
// groupScene->addItemToDeletion(this);
}
foreach (QGraphicsItem *item, childItems()) {
pRemoveFromGroup(item);
item->setFlag(QGraphicsItem::ItemIsSelectable, true);
item->setFlag(QGraphicsItem::ItemIsFocusable, true);

@ -4,6 +4,7 @@
#include <QGraphicsItem>
#include "domain/UBItem.h"
#include "frameworks/UBCoreGraphicsScene.h"
class UBGraphicsGroupContainerItem : public QGraphicsItem, public UBItem, public UBGraphicsItem
{
@ -23,7 +24,7 @@ public:
virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;}
virtual UBGraphicsScene* scene();
virtual UBCoreGraphicsScene *corescene();
virtual UBGraphicsGroupContainerItem *deepCopy() const;
virtual void copyItemParameters(UBItem *copy) const;

@ -113,7 +113,6 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec
, mFlippable(false)
, mToolBarUsed(useToolBar)
{
// NOOP
connect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged()));
}
@ -167,7 +166,7 @@ void UBGraphicsItemDelegate::init()
UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
{
qDeleteAll(mButtons);
disconnect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged()));
// do not release mMimeData.
// the mMimeData is owned by QDrag since the setMimeData call as specified in the documentation
}

@ -1363,6 +1363,7 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con
UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *> items)
{
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
addItem(groupItem);
foreach (QGraphicsItem *item, items) {
if (item->type() == UBGraphicsGroupContainerItem::Type) {
@ -1379,7 +1380,6 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
}
}
addItem(groupItem);
groupItem->setVisible(true);
groupItem->setFocus();

@ -30,12 +30,23 @@ UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent)
UBCoreGraphicsScene::~UBCoreGraphicsScene()
{
//we must delete removed items that are no more in any scene
foreach (const QGraphicsItem* item, mItemsToDelete)
//at groups deleting some items can be added to mItemsToDelete, so we need to use iterators.
if (mItemsToDelete.count())
{
if (item->scene() == NULL || item->scene() == this)
QSet<QGraphicsItem *>::iterator it = mItemsToDelete.begin();
QGraphicsItem* item = *it;
do
{
delete item;
}
item = *it;
if (item && (item->scene() == NULL || item->scene() == this))
{
mItemsToDelete.remove(*it);
delete item;
}
it = mItemsToDelete.begin();
}while(mItemsToDelete.count());
}
}
@ -46,9 +57,7 @@ void UBCoreGraphicsScene::addItem(QGraphicsItem* item)
removeItemFromDeletion(curItem);
}
}
mItemsToDelete << item;
if (item->scene() != this)
QGraphicsScene::addItem(item);
}
@ -59,9 +68,7 @@ void UBCoreGraphicsScene::removeItem(QGraphicsItem* item, bool forceDelete)
QGraphicsScene::removeItem(item);
if (forceDelete)
{
mItemsToDelete.remove(item);
delete item;
item = 0;
deleteItem(item);
}
}

Loading…
Cancel
Save