Fixed SANKORE-850 Problem Importing Exporting to iwb.

Also fixed too many memory leaks and fixed behavior for strokes and groups.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
commit 477dc3d15e
  1. 8
      src/adaptors/UBCFFSubsetAdaptor.cpp
  2. 8
      src/board/UBBoardController.cpp
  3. 36
      src/domain/UBGraphicsGroupContainerItem.cpp
  4. 3
      src/domain/UBGraphicsGroupContainerItem.h
  5. 3
      src/domain/UBGraphicsItemDelegate.cpp
  6. 30
      src/domain/UBGraphicsScene.cpp
  7. 25
      src/frameworks/UBCoreGraphicsScene.cpp

@ -174,9 +174,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &ele
QDomElement currentSvgElement = element.firstChildElement(); QDomElement currentSvgElement = element.firstChildElement();
while (!currentSvgElement.isNull()) { while (!currentSvgElement.isNull()) {
if (!parseSvgElement(currentSvgElement)) parseSvgElement(currentSvgElement);
return false;
currentSvgElement = currentSvgElement.nextSiblingElement(); currentSvgElement = currentSvgElement.nextSiblingElement();
} }
@ -187,8 +185,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &ele
else else
{ {
delete mGSectionContainer; delete mGSectionContainer;
mGSectionContainer = NULL;
} }
mGSectionContainer = NULL;
return true; return true;
} }
@ -1189,8 +1187,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::persistScenes()
UBGraphicsScene *tmpScene = UBSvgSubsetAdaptor::loadScene(mProxy, i); UBGraphicsScene *tmpScene = UBSvgSubsetAdaptor::loadScene(mProxy, i);
tmpScene->setModified(true); tmpScene->setModified(true);
UBThumbnailAdaptor::persistScene(mProxy, tmpScene, i); UBThumbnailAdaptor::persistScene(mProxy, tmpScene, i);
delete tmpScene;
mCurrentScene->setModified(false); mCurrentScene->setModified(false);
} }

@ -1482,11 +1482,12 @@ void UBBoardController::ClearUndoStack()
UBGraphicsItemUndoCommand *cmd = (UBGraphicsItemUndoCommand*)UBApplication::undoStack->command(i); UBGraphicsItemUndoCommand *cmd = (UBGraphicsItemUndoCommand*)UBApplication::undoStack->command(i);
// go through all added and removed objects, for create list of unique objects // go through all added and removed objects, for create list of unique objects
// grouped items will be deleted by groups, so we don't need do delete that items.
QSetIterator<QGraphicsItem*> itAdded(cmd->GetAddedList()); QSetIterator<QGraphicsItem*> itAdded(cmd->GetAddedList());
while (itAdded.hasNext()) while (itAdded.hasNext())
{ {
QGraphicsItem* item = itAdded.next(); QGraphicsItem* item = itAdded.next();
if( !uniqueItems.contains(item) ) if( !uniqueItems.contains(item) && !(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type()))
uniqueItems.insert(item); uniqueItems.insert(item);
} }
@ -1494,7 +1495,7 @@ void UBBoardController::ClearUndoStack()
while (itRemoved.hasNext()) while (itRemoved.hasNext())
{ {
QGraphicsItem* item = itRemoved.next(); QGraphicsItem* item = itRemoved.next();
if( !uniqueItems.contains(item) ) if( !uniqueItems.contains(item) && !(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type()))
uniqueItems.insert(item); uniqueItems.insert(item);
} }
} }
@ -1515,7 +1516,8 @@ void UBBoardController::ClearUndoStack()
} }
if(!scene) if(!scene)
{ {
mActiveScene->deleteItem(item); if (!mActiveScene->deleteItem(item))
delete item;
} }
} }

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

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

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

@ -305,7 +305,10 @@ UBGraphicsScene::~UBGraphicsScene()
{ {
if (mCurrentStroke) if (mCurrentStroke)
if (mCurrentStroke->polygons().empty()) if (mCurrentStroke->polygons().empty())
{
delete mCurrentStroke; delete mCurrentStroke;
mCurrentStroke = NULL;
}
if (mZLayerController) if (mZLayerController)
delete mZLayerController; delete mZLayerController;
@ -433,6 +436,11 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre
} }
} }
if (mCurrentStroke && mCurrentStroke->polygons().empty()){
delete mCurrentStroke;
mCurrentStroke = NULL;
}
return accepted; return accepted;
} }
@ -474,6 +482,10 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon); UBCoreGraphicsScene::removeItemFromDeletion(mpLastPolygon);
mAddedItems.remove(mpLastPolygon); mAddedItems.remove(mpLastPolygon);
mCurrentStroke->remove(mpLastPolygon); mCurrentStroke->remove(mpLastPolygon);
if (mCurrentStroke->polygons().empty()){
delete mCurrentStroke;
mCurrentStroke = NULL;
}
removeItem(mpLastPolygon); removeItem(mpLastPolygon);
mPreviousPolygonItems.removeAll(mpLastPolygon); mPreviousPolygonItems.removeAll(mpLastPolygon);
} }
@ -1363,6 +1375,7 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con
UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *> items) UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *> items)
{ {
UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem();
addItem(groupItem);
foreach (QGraphicsItem *item, items) { foreach (QGraphicsItem *item, items) {
if (item->type() == UBGraphicsGroupContainerItem::Type) { if (item->type() == UBGraphicsGroupContainerItem::Type) {
@ -1373,13 +1386,14 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
} }
foreach (QGraphicsItem *chItem, childItems) { foreach (QGraphicsItem *chItem, childItems) {
groupItem->addToGroup(chItem); groupItem->addToGroup(chItem);
mFastAccessItems.removeAll(item);
} }
} else { } else {
groupItem->addToGroup(item); groupItem->addToGroup(item);
mFastAccessItems.removeAll(item);
} }
} }
addItem(groupItem);
groupItem->setVisible(true); groupItem->setVisible(true);
groupItem->setFocus(); groupItem->setFocus();
@ -1396,6 +1410,15 @@ UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList<QGraphicsItem *
void UBGraphicsScene::addGroup(UBGraphicsGroupContainerItem *groupItem) void UBGraphicsScene::addGroup(UBGraphicsGroupContainerItem *groupItem)
{ {
addItem(groupItem); addItem(groupItem);
for (int i = 0; i < groupItem->childItems().count(); i++)
{
QGraphicsItem *it = qgraphicsitem_cast<QGraphicsItem *>(groupItem->childItems().at(i));
if (it)
{
mFastAccessItems.removeAll(it);
}
}
groupItem->setVisible(true); groupItem->setVisible(true);
groupItem->setFocus(); groupItem->setFocus();
@ -2274,6 +2297,11 @@ void UBGraphicsScene::setToolCursor(int tool)
{ {
deselectAllItems(); deselectAllItems();
} }
if (mCurrentStroke && mCurrentStroke->polygons().empty()){
delete mCurrentStroke;
}
mCurrentStroke = NULL;
} }
void UBGraphicsScene::initStroke(){ void UBGraphicsScene::initStroke(){

@ -30,12 +30,23 @@ UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent)
UBCoreGraphicsScene::~UBCoreGraphicsScene() UBCoreGraphicsScene::~UBCoreGraphicsScene()
{ {
//we must delete removed items that are no more in any scene //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());
} }
} }
@ -47,8 +58,6 @@ void UBCoreGraphicsScene::addItem(QGraphicsItem* item)
} }
} }
mItemsToDelete << item;
if (item->scene() != this) if (item->scene() != this)
QGraphicsScene::addItem(item); QGraphicsScene::addItem(item);
} }
@ -59,9 +68,7 @@ void UBCoreGraphicsScene::removeItem(QGraphicsItem* item, bool forceDelete)
QGraphicsScene::removeItem(item); QGraphicsScene::removeItem(item);
if (forceDelete) if (forceDelete)
{ {
mItemsToDelete.remove(item); deleteItem(item);
delete item;
item = 0;
} }
} }

Loading…
Cancel
Save