1.1 --- a/vymmodel.cpp Tue Sep 08 12:15:39 2009 +0000
1.2 +++ b/vymmodel.cpp Fri Sep 11 12:56:15 2009 +0000
1.3 @@ -1135,7 +1135,11 @@
1.4 QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
1.5
1.6 // select object before undo
1.7 - select (undoSelection);
1.8 + if (!select (undoSelection))
1.9 + {
1.10 + qWarning ("VymModel::undo() Could not select object for undo");
1.11 + return;
1.12 + }
1.13
1.14 if (debug)
1.15 {
1.16 @@ -1424,11 +1428,12 @@
1.17 parts.removeFirst();
1.18 if (typ=="mc" || typ=="bo")
1.19 ti=ti->getBranchNum (n);
1.20 - /* FIXME-2 add other types to getSelectionString and findBy...
1.21 - else
1.22 - if (typ="fi")
1.23 - ti=ti->getImageNum (n);
1.24 - */
1.25 + else if (typ=="fi")
1.26 + ti=ti->getImageNum (n);
1.27 + else if (typ=="ai")
1.28 + ti=ti->getAttributeNum (n);
1.29 + else if (typ=="xl")
1.30 + ti=ti->getXLinkNum (n);
1.31 if(!ti) return NULL;
1.32 }
1.33 return ti;
1.34 @@ -2347,7 +2352,12 @@
1.35 select (pi);
1.36 reposition();
1.37 emitShowSelection();
1.38 - }
1.39 + } else if (ti->getType()==TreeItem::XLink)
1.40 + {
1.41 + //FIXME-2 savestate missing
1.42 + deleteItem (ti);
1.43 + } else
1.44 + qWarning ("VymmModel::deleteSelection() unknown type?!");
1.45 }
1.46 }
1.47
1.48 @@ -2427,7 +2437,7 @@
1.49
1.50 TreeItem* VymModel::deleteItem (TreeItem *ti)
1.51 {
1.52 - cout << "VM::deleteItem "<<ti<<endl;
1.53 + cout << "VM::deleteItem "<<ti<<" "<<getSelectString(ti).toStdString()<<endl;
1.54 if (ti)
1.55 {
1.56 TreeItem *pi=ti->parent();
1.57 @@ -2950,6 +2960,34 @@
1.58 } else
1.59 parser.setError (Aborted,"Wrong number of parameters");
1.60 /////////////////////////////////////////////////////////////////////
1.61 + } else if (com==QString("addXLink"))
1.62 + {
1.63 + if (parser.parCount()>1)
1.64 + {
1.65 + s=parser.parString (ok,0); // begin
1.66 + t=parser.parString (ok,1); // end
1.67 + BranchItem *begin=(BranchItem*)findBySelectString(s);
1.68 + BranchItem *end=(BranchItem*)findBySelectString(t);
1.69 + if (begin && end)
1.70 + {
1.71 + if (begin->isBranchLikeType() && end->isBranchLikeType())
1.72 + {
1.73 + XLinkItem *xl=createXLink (begin,true);
1.74 + if (xl)
1.75 + {
1.76 + xl->setEnd (end);
1.77 + xl->activate();
1.78 + } else
1.79 + parser.setError (Aborted,"Failed to create xLink");
1.80 + }
1.81 + else
1.82 + parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
1.83 +
1.84 + } else
1.85 + parser.setError (Aborted,"Couldn't select begin or end of xLink");
1.86 + } else
1.87 + parser.setError (Aborted,"Need at least 2 parameters for begin and end");
1.88 + /////////////////////////////////////////////////////////////////////
1.89 } else if (com=="clearFlags")
1.90 {
1.91 if (!selti )
1.92 @@ -4306,64 +4344,59 @@
1.93 return defXLinkWidth;
1.94 }
1.95
1.96 -void VymModel::move(const double &x, const double &y) // FIXME-3
1.97 +void VymModel::move(const double &x, const double &y)
1.98 {
1.99 int i=x; i=y;
1.100 -/*
1.101 - BranchObj *bo = getSelectedBranch();
1.102 - if (bo &&
1.103 - (selectionType()==TreeItem::Branch ||
1.104 - selectionType()==TreeItem::MapCenter ||
1.105 - selectionType()==TreeItem::Image
1.106 - ))
1.107 + MapItem *seli = (MapItem*)getSelectedItem();
1.108 + if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
1.109 {
1.110 - QPointF ap(bo->getAbsPos());
1.111 - QPointF to(x, y);
1.112 - if (ap != to)
1.113 - {
1.114 - QString ps=qpointfToString(ap);
1.115 - QString s=getSelectString();
1.116 - saveState(
1.117 - s, "move "+ps,
1.118 - s, "move "+qpointfToString(to),
1.119 - QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps));
1.120 - bo->move(x,y);
1.121 - reposition();
1.122 - emitSelectionChanged();
1.123 - }
1.124 + LinkableMapObj *lmo=seli->getLMO();
1.125 + if (lmo)
1.126 + {
1.127 + QPointF ap(lmo->getAbsPos());
1.128 + QPointF to(x, y);
1.129 + if (ap != to)
1.130 + {
1.131 + QString ps=qpointFToString(ap);
1.132 + QString s=getSelectString(seli);
1.133 + saveState(
1.134 + s, "move "+ps,
1.135 + s, "move "+qpointFToString(to),
1.136 + QString("Move %1 to %2").arg(getObjectName(seli)).arg(ps));
1.137 + lmo->move(x,y);
1.138 + reposition();
1.139 + emitSelectionChanged();
1.140 + }
1.141 + }
1.142 }
1.143 -*/
1.144 }
1.145
1.146 -void VymModel::moveRel (const double &x, const double &y) // FIXME-3
1.147 +void VymModel::moveRel (const double &x, const double &y)
1.148 {
1.149 int i=x; i=y;
1.150 -/*
1.151 - BranchObj *bo = getSelectedBranch();
1.152 - if (bo &&
1.153 - (selectionType()==TreeItem::Branch ||
1.154 - selectionType()==TreeItem::MapCenter ||
1.155 - selectionType()==TreeItem::Image
1.156 - ))
1.157 - if (bo)
1.158 + MapItem *seli = (MapItem*)getSelectedItem();
1.159 + if (seli && (seli->isBranchLikeType() || seli->getType()==TreeItem::Image))
1.160 {
1.161 - QPointF rp(bo->getRelPos());
1.162 - QPointF to(x, y);
1.163 - if (rp != to)
1.164 - {
1.165 - QString ps=qpointfToString (bo->getRelPos());
1.166 - QString s=getSelectString(bo);
1.167 - saveState(
1.168 - s, "moveRel "+ps,
1.169 - s, "moveRel "+qpointfToString(to),
1.170 - QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps));
1.171 - ((OrnamentedObj*)bo)->move2RelPos (x,y);
1.172 - reposition();
1.173 - bo->updateLinkGeometry();
1.174 - emitSelectionChanged();
1.175 - }
1.176 + LinkableMapObj *lmo=seli->getLMO();
1.177 + if (lmo)
1.178 + {
1.179 + QPointF rp(lmo->getRelPos());
1.180 + QPointF to(x, y);
1.181 + if (rp != to)
1.182 + {
1.183 + QString ps=qpointFToString (lmo->getRelPos());
1.184 + QString s=getSelectString(seli);
1.185 + saveState(
1.186 + s, "moveRel "+ps,
1.187 + s, "moveRel "+qpointFToString(to),
1.188 + QString("Move %1 to relative position %2").arg(getObjectName(seli)).arg(ps));
1.189 + ((OrnamentedObj*)lmo)->move2RelPos (x,y);
1.190 + reposition();
1.191 + lmo->updateLinkGeometry();
1.192 + emitSelectionChanged();
1.193 + }
1.194 + }
1.195 }
1.196 -*/
1.197 }
1.198
1.199
1.200 @@ -4900,7 +4933,10 @@
1.201 case TreeItem::Branch: s="bo:";break;
1.202 case TreeItem::Image: s="fi:";break;
1.203 case TreeItem::Attribute: s="ai:";break;
1.204 - default:break;
1.205 + case TreeItem::XLink: s="xl:";break;
1.206 + default:
1.207 + s="unknown type in VymModel::getSelectString()";
1.208 + break;
1.209 }
1.210 s= s + QString("%1").arg(ti->num());
1.211 if (ti->depth() >0)