Fix crash on exploding sub-xsheet (#305)

* fix crash on exploding sub xsheet

* call onselectionchanged in mousepressevent
This commit is contained in:
shun-iwasawa 2016-05-20 18:20:30 +09:00 committed by Keisuke Ogaki
parent 5ea53c8c6b
commit 0a9e80ffa1
4 changed files with 47 additions and 43 deletions

View file

@ -520,7 +520,7 @@ TFx *explodeFxSubTree(TFx *innerFx, QMap<TFx *, QPair<TFx *, int>> &fxs, FxDag *
overFx->getInputPort(1)->setFx(root);
outerDag->removeFromXsheet(fx);
TPointD pos = root->getAttributes()->getDagNodePos();
overFx->getAttributes()->setDagNodePos(TPointD(pos.x + 150, pos.y));
overFx->getAttributes()->setDagNodePos((pos == TConst::nowhere) ? TConst::nowhere : TPointD(pos.x + 150, pos.y));
root = overFx;
//e' brutto... mi serve solo per mettere gli over dentro il gruppo
fxs[overFx] = QPair<TFx *, int>(overFx, -1);
@ -632,7 +632,11 @@ set<int> explodeStageObjects(TXsheet *xsh, TXsheet *subXsh, int index, const TSt
}
obj->assignParams(params);
delete params;
obj->setParent(parentId);
// a pegbar cannot be a child of column
if (parentId.isColumn())
obj->setParent(TStageObjectId::TableId);
else
obj->setParent(parentId);
//Put in the right StageObject group if needed
obj->removeFromAllGroup();
@ -655,6 +659,7 @@ set<int> explodeStageObjects(TXsheet *xsh, TXsheet *subXsh, int index, const TSt
//add colums;
FxDag *innerDag = subXsh->getFxDag();
FxDag *outerDag = xsh->getFxDag();
TStageObjectId tmpParentId = parentId;
set<int> indexes;
int i;
for (i = 0; i < subXsh->getColumnCount(); i++) {
@ -665,6 +670,12 @@ set<int> explodeStageObjects(TXsheet *xsh, TXsheet *subXsh, int index, const TSt
TFx *outerFx = outerColumn->getFx();
xsh->insertColumn(index, outerColumn);
// the above insertion operation may increment the parentId, in case that
// 1, the parent object is column, and
// 2, the parent column is placed on the right side of the inserted column
// ( i.e. index of the parent column is equal to or higher than "index")
if (onlyColumn && tmpParentId.isColumn() && tmpParentId.getIndex() >= index)
tmpParentId = TStageObjectId::ColumnId(tmpParentId.getIndex() + 1);
if (innerFx && outerFx) {
outerFx->getAttributes()->setDagNodePos(innerFx->getAttributes()->getDagNodePos());
@ -701,7 +712,7 @@ set<int> explodeStageObjects(TXsheet *xsh, TXsheet *subXsh, int index, const TSt
}
if (onlyColumn)
outerCol->setParent(parentId);
outerCol->setParent(tmpParentId);
//Put in the right StageObject group if needed
if (!objGroupData.m_groupIds.empty()) {
@ -830,7 +841,7 @@ void explodeFxs(TXsheet *xsh, TXsheet *subXsh,
}
//cerco il punto medio tra tutti i nodi
TPointD middlePoint;
TPointD middlePoint(0.0,0.0);
int fxsCount = 0;
QMap<TFx *, QPair<TFx *, int>>::iterator it;
@ -849,6 +860,8 @@ void explodeFxs(TXsheet *xsh, TXsheet *subXsh,
}
if (fxsCount > 0)
middlePoint = TPointD(middlePoint.x / fxsCount, middlePoint.y / fxsCount);
else
middlePoint = TPointD(25000, 25000);//center of the scene
//faccio in modo che tutti i nodi estratti siano centrati in middlePoint
//Li metto poi in un gruppo
@ -2472,6 +2485,12 @@ void SubsceneCmd::explode(int index)
// Remove column
xsh->removeColumn(index);
// The above removing operation may decrement the parentId, in case that
// 1, the parent object is column, and
// 2, the parent column is placed on the right side of the removed column
// ( i.e. index of the parent column is higher than "index")
if (parentId.isColumn() && parentId.getIndex() > index)
parentId = TStageObjectId::ColumnId(parentId.getIndex() - 1);
// Explode
set<int> newIndexes = ::explode(xsh, childLevel->getXsheet(), index, parentId,

View file

@ -3397,14 +3397,19 @@ void FxGroupNode::updateFxsDagPosition(const TPointD &pos) const
TPointD delta = pos - oldPos;
int i;
for (i = 0; i < m_groupedFxs.size(); i++) {
m_groupedFxs[i]->getAttributes()->setDagNodePos(m_groupedFxs[i]->getAttributes()->getDagNodePos() + delta);
TMacroFx *macro = dynamic_cast<TMacroFx *>(m_groupedFxs[i].getPointer());
if (macro) {
std::vector<TFxP> fxs = macro->getFxs();
int i;
for (i = 0; i < (int)fxs.size(); i++) {
TPointD oldP = fxs[i]->getAttributes()->getDagNodePos();
fxs[i]->getAttributes()->setDagNodePos(oldP + delta);
// If the node position is unidentified, then leave the placement of it to placeNode() function.
//if (m_groupedFxs[i]->getAttributes()->getDagNodePos() != TConst::nowhere)
{
m_groupedFxs[i]->getAttributes()->setDagNodePos(m_groupedFxs[i]->getAttributes()->getDagNodePos() + delta);
TMacroFx *macro = dynamic_cast<TMacroFx *>(m_groupedFxs[i].getPointer());
if (macro) {
std::vector<TFxP> fxs = macro->getFxs();
int i;
for (i = 0; i < (int)fxs.size(); i++) {
TPointD oldP = fxs[i]->getAttributes()->getDagNodePos();
//if (oldP != TConst::nowhere)
fxs[i]->getAttributes()->setDagNodePos(oldP + delta);
}
}
}
}

View file

@ -1539,23 +1539,6 @@ TFx *FxSchematicScene::getCurrentFx()
void FxSchematicScene::mousePressEvent(QGraphicsSceneMouseEvent *me)
{
// avoid clear of selection by middle-click
if (me->button() != Qt::MidButton)
SchematicScene::mousePressEvent(me);
if (me->button() == Qt::RightButton) {
QList<QGraphicsItem *> pointedItems = items(me->scenePos());
for (int i = 0; i < pointedItems.size(); i++) {
FxSchematicNode *sn = dynamic_cast<FxSchematicNode *>(pointedItems[i]);
if (sn) {
m_fxHandle->setFx(sn->getFx(), false);
if (!m_selection->isSelected(sn->getFx()))
m_selection->select(sn->getFx());
m_selection->makeCurrent();
}
}
}
QList<QGraphicsItem *> items = selectedItems();
#if QT_VERSION >= 0x050000
QGraphicsItem *item = itemAt(me->scenePos(), QTransform());
@ -1564,25 +1547,17 @@ void FxSchematicScene::mousePressEvent(QGraphicsSceneMouseEvent *me)
#endif
FxSchematicPort *port = dynamic_cast<FxSchematicPort *>(item);
FxSchematicLink *link = dynamic_cast<FxSchematicLink *>(item);
SchematicScene::mousePressEvent(me);
onSelectionChanged();
if (me->button() == Qt::MidButton) {
int i;
for (i = 0; i < items.size(); i++)
items[i]->setSelected(true);
}
/*
SchematicScene::mousePressEvent(me)
SchematicNode::mousePressEvent内でsetSelected(this)
QGraphicsScene::selectionChanged()
FxSchematticScene::onSelectionChanged()
selectNone()
m_selectionが正しく更新される保障が無い
Fx無しと勘違いしてFxSettingsが更新されないおそれがある
m_selection->isEmpty()QGraphicsScene::selectedItems()
*/
m_selection may not be updated here, so I use QGraphicsScene::selectedItems()
instead of m_selection->isEmpty() to check whether any node is selected or not.
*/
if (selectedItems().isEmpty()) {
if (me->button() != Qt::MidButton && !item)
m_fxHandle->setFx(0, false);

View file

@ -6,6 +6,7 @@
#include "tconvert.h"
#include "tvectorimage.h"
#include "tundo.h"
#include "tconst.h"
// TnzLib includes
#include "toonz/tstageobjectid.h"
@ -2401,7 +2402,11 @@ void StageSchematicGroupNode::updateObjsDagPosition(const TPointD &pos) const
TPointD delta = pos - oldPos;
int i;
for (i = 0; i < m_groupedObj.size(); i++)
m_groupedObj[i]->setDagNodePos(m_groupedObj[i]->getDagNodePos() + delta);
{
// If the node position is unidentified, then leave the placement of it to placeNode() function.
if (m_groupedObj[i]->getDagNodePos() != TConst::nowhere)
m_groupedObj[i]->setDagNodePos(m_groupedObj[i]->getDagNodePos() + delta);
}
}
//--------------------------------------------------------