# HG changeset patch
# User insilmaril
# Date 1251967920 0
# Node ID 133e2ed6b9c5cdc61db86af5152e02d9c13bf315
# Parent  d85834ad8c541d04048b2bccd6172edb08db1d85
More work on xLinks

diff -r d85834ad8c54 -r 133e2ed6b9c5 branchitem.cpp
--- a/branchitem.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/branchitem.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -1,6 +1,7 @@
 #include "branchitem.h"
 #include "branchobj.h"
 #include "vymmodel.h"
+#include "xlinkitem.h"
 
 #include <iostream>
 #include <QDir>
@@ -87,15 +88,13 @@
 	} else
 		areaAttr="";
 	
-	/*	
-	// FIXME-3 Providing an ID for a branch makes export to XHTML easier
+	// Provide an ID for a branch makes export to XHTML easier
 	QString idAttr;
-	if (countXLinks()>0)
-		idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
+	if (xlinkCount()>0)
+		idAttr=attribut ("id",model->getSelectString(this)); 
 	else
 		idAttr="";
 
-	*/
 	QString elementName;
 	if (parentItem==rootItem)
 		elementName="mapcenter";
@@ -106,8 +105,8 @@
 		+getMapAttr()
 		+getGeneralAttr()
 		+scrolledAttr 
-	//	+areaAttr 
-	//	+idAttr 
+	//	+areaAttr	// FIXME-2
+		+idAttr 
 		+getIncludeImageAttr() 
 		);
     incIndent();
@@ -141,13 +140,12 @@
 		ti=getBranchNum(i);
 	}	
 
-	/*
-	// Save XLinks
+	// Save XLinks 
 	QString ol;	// old link
 	QString cl;	// current link
-	for (int i=0; i<xlink.size(); ++i)
+	for (int i=0; i<xlinkCount(); ++i)
 	{
-		cl=xlink.at(i)->saveToDir();
+		cl=getXLinkNum(i)->saveToDir();
 		if (cl!=ol)
 		{
 			s+=cl;
@@ -157,7 +155,6 @@
 			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
 		}
 	}	
-	*/
 
     decIndent();
     s+=endElement   (elementName);
@@ -373,7 +370,7 @@
 	return NULL;
 }
 
-TreeItem* BranchItem::findID (QString sid)
+TreeItem* BranchItem::findID (QString sid)	//FIXME-3 move to TreeItem	//FIXME-4 search images
 {
 	// Search branches
     TreeItem *ti;
@@ -388,7 +385,7 @@
 
 
 /*
-	// Search float images //FIXME-4
+	// Search float images 
     for (int i=0; i<floatimage.size(); ++i )
 		if (floatimage.at(i)->inBox(p) && 
 			(floatimage.at(i) != excludeLMO) && 
@@ -417,8 +414,7 @@
 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)	// FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel?
 {
 	BranchObj *newbo;
-	newbo=new BranchObj(scene);
-	newbo->setTreeItem (this);
+	newbo=new BranchObj(scene,this);
 	lmo=newbo;
 
 	if (parentItem==rootItem)
diff -r d85834ad8c54 -r 133e2ed6b9c5 branchitem.h
--- a/branchitem.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/branchitem.h	Thu Sep 03 08:52:00 2009 +0000
@@ -5,8 +5,9 @@
 
 
 class QString;
+class QGraphicsScene;
 class BranchObj;
-class QGraphicsScene;
+class XLinkItem;
 
 class BranchItem:public MapItem
 {
diff -r d85834ad8c54 -r 133e2ed6b9c5 branchobj.cpp
--- a/branchobj.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/branchobj.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -13,21 +13,16 @@
 // BranchObj
 /////////////////////////////////////////////////////////////////
 
-BranchObj::BranchObj () :OrnamentedObj()	// FIXME-3 needed at all?
-{
-//    cout << "Const BranchObj ()\n";
-    setParObj (this);	
-    init();
-}
-
-BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)// FIXME-3 needed at all?
+BranchObj::BranchObj (QGraphicsScene* s,TreeItem *ti):OrnamentedObj (s)
 {
 //    cout << "Const BranchObj (s)  \n";
 	parObj=NULL;
     scene=s;
+	treeItem=ti;
 	init();
 }
 
+/*
 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
 {
 //    cout << "Const BranchObj (s,p)\n";
@@ -41,6 +36,7 @@
 								(y() - parObj->getChildPos().y() ) ) );
     init();
 }
+*/
 
 BranchObj::~BranchObj ()
 {
@@ -210,8 +206,8 @@
 		int i;
 		for (i=0; i<treeItem->imageCount(); ++i)
 			treeItem->getImageObjNum(i)->setVisibility (v);
-		for (i=0; i<xlink.size(); ++i)	
-			xlink.at(i)->setVisibility ();	
+		for (i=0; i<treeItem->xlinkCount(); ++i)	
+			treeItem->getXLinkObjNum(i)->setVisibility ();	
 
 		// Only change children, if I am not scrolled
 		if (! bi->isScrolled() && (bi->depth() < toDepth))
@@ -299,9 +295,13 @@
 	// set the frame
 	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
 
-	// Update links to other branches
-	for (int i=0; i<xlink.size(); ++i)
-		xlink.at(i)->updateXLink();
+	//Update links to other branches
+	XLinkObj *xlo;
+	for (int i=0; i<treeItem->xlinkCount(); ++i)	
+	{
+		xlo=treeItem->getXLinkObjNum(i);
+		if (xlo) xlo->updateXLink();
+	}	
 }
 
 void BranchObj::calcBBoxSize()
@@ -472,105 +472,6 @@
 	updateContentSize();
 }
 
-
-void BranchObj::addXLink (XLinkObj *xlo)
-{
-	xlink.append (xlo);
-	
-}
-
-void BranchObj::removeXLinkRef (XLinkObj *xlo)
-{
-	xlink.removeAt (xlink.indexOf(xlo));
-}
-
-void BranchObj::deleteXLink(XLinkObj *xlo)
-{
-	xlo->deactivate();
-	if (!xlo->isUsed()) delete (xlo);
-}
-
-void BranchObj::deleteXLinkAt (int i)
-{
-	XLinkObj *xlo=xlink.at(i);
-	xlo->deactivate();
-	if (!xlo->isUsed()) delete(xlo);
-}
-
-XLinkObj* BranchObj::XLinkAt (int i)
-{
-	return xlink.at(i);
-}
-
-BranchObj* BranchObj::XLinkTargetAt (int i)
-{
-	if (i>=0 && i<xlink.size())
-	{
-		if (xlink.at(i))
-			return xlink.at(i)->otherBranch (this);
-	}
-	return NULL;
-}
-
- 
-// FIXME-3 FloatImageObj* BranchObj::addFloatImage ()
-/*
-{
-	FloatImageObj *newfi=new FloatImageObj (scene,this);
-	floatimage.append (newfi);
-	if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
-		newfi->setVisibility (false);
-	else	
-		newfi->setVisibility(visible);
-	//calcBBoxSize();
-	//positionBBox();
-	requestReposition();
-	return newfi;
-}
-*/
-
-//FIXME-3 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
-/*
-{
-	FloatImageObj *newfi=new FloatImageObj (scene,this);
-	floatimage.append (newfi);
-	newfi->copy (fio);
-	if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
-		newfi->setVisibility (false);
-	else	
-		newfi->setVisibility(visible);
-	//calcBBoxSize();
-	//positionBBox();
-	requestReposition();
-	return newfi;
-}
-*/
-
-/* FIXME-3 FloatImageObj* BranchObj::getFirstFloatImage ()
-{
-    return floatimage.first();
-}
-
-FloatImageObj* BranchObj::getLastFloatImage ()
-{
-    return floatimage.last();
-}
-
-FIXME -3 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
-{
-    return floatimage.at(i);
-}
-
-void BranchObj::removeFloatImage (FloatImageObj *fio)
-{
-	int i=floatimage.indexOf (fio);
-	if (i>-1) delete (floatimage.takeAt (i));
-	calcBBoxSize();
-	positionBBox();
-	requestReposition();
-}
-*/
-
 void BranchObj::savePosInAngle ()
 {
 	// Save position in angle
diff -r d85834ad8c54 -r 133e2ed6b9c5 branchobj.h
--- a/branchobj.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/branchobj.h	Thu Sep 03 08:52:00 2009 +0000
@@ -17,10 +17,7 @@
 	/*! New branches will get use same color for heading as parent */
 	enum BranchModification {NewBranch, MovedBranch};
 
-
-    BranchObj ();
-    BranchObj (QGraphicsScene*);
-    BranchObj (QGraphicsScene*, LinkableMapObj* parent);
+    BranchObj (QGraphicsScene*,TreeItem *ti=NULL);
     ~BranchObj ();
 	bool operator< ( const BranchObj & );
 	bool operator== ( const BranchObj & );
@@ -47,21 +44,6 @@
     
     virtual void updateData();	//! Update represantatio of heading, flags, etc.
 
-	virtual void addXLink (XLinkObj*);
-	virtual void removeXLinkRef (XLinkObj*);// Remove ref in list
-	virtual void deleteXLink (XLinkObj*);	// remove references and delete XLinkObj 
-	virtual void deleteXLinkAt (int);		// remove references and delete XLinkObj 
-	virtual XLinkObj* XLinkAt (int);		// return reference of XLinkObj 
-	virtual BranchObj* XLinkTargetAt (int);
-
-/* FIXME-3
-	virtual FloatImageObj* addFloatImage();
-	virtual FloatImageObj* addFloatImage(FloatImageObj*);
-	virtual void removeFloatImage(FloatImageObj*);
-    virtual FloatImageObj* getFirstFloatImage();
-    virtual FloatImageObj* getLastFloatImage();
-*/	
-//FIXME-3	virtual FloatImageObj* getFloatImageNum(const uint &);
 protected:	
 	virtual void savePosInAngle();					// write pos in angle for resorting			
 public:	
@@ -82,7 +64,6 @@
 	virtual bool animate();
 
 protected:
-	//FIXME-3 QList<FloatImageObj*> floatimage;// child images
 	QList<XLinkObj*> xlink;			// xlinks to other branches
 
 	AnimPoint anim;
diff -r d85834ad8c54 -r 133e2ed6b9c5 editxlinkdialog.cpp
--- a/editxlinkdialog.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/editxlinkdialog.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -3,13 +3,15 @@
 #include <typeinfo>
 #include <QColorDialog>
 
+#include "branchitem.h"
+
 EditXLinkDialog::EditXLinkDialog (QWidget *parent):QDialog (parent)
 {
 	ui.setupUi (this);
 
 	delink=false;
-	xlo=false;
-	selection=NULL;
+	xli=NULL;
+	selbi=NULL;
 
 	connect ( ui.widthBox, SIGNAL (valueChanged( int)), this, SLOT (widthChanged (int)));
 	connect ( ui.colorButton, SIGNAL (clicked( )), this, SLOT (colorButtonPressed()));
@@ -31,47 +33,43 @@
 
 void EditXLinkDialog::widthChanged( int  w)
 {
-	xlo->setWidth(w);
+	xli->setWidth(w);
 }
 
-void EditXLinkDialog::setXLink( XLinkObj * xo)
+void EditXLinkDialog::setXLink( XLinkItem * xi)
 {
-	xlo=xo;
-	ui.colorButton->setPaletteBackgroundColor (xlo->getColor() );
-	ui.widthBox->setValue(xlo->getWidth());
+	xli=xi;
+	ui.colorButton->setPaletteBackgroundColor (xli->getColor() );
+	ui.widthBox->setValue(xli->getWidth());
 }
 
-void EditXLinkDialog::setSelection(LinkableMapObj *s)
+void EditXLinkDialog::setSelection(BranchItem *bi)
 {
-	selection=s;
+	selbi=bi;
 }
 
 void EditXLinkDialog::colorButtonPressed()
 {
-	if (xlo)
+	if (xli)
 	{	
-		QColor col = QColorDialog::getColor(xlo->getColor(), this );
+		QColor col = QColorDialog::getColor(xli->getColor(), this );
 		if ( !col.isValid() ) return;
-		xlo->setColor( col );
+		xli->setColor( col );
 		ui.colorButton->setPaletteBackgroundColor (col);
 	}
 }
 
-void EditXLinkDialog::setColorHeadingButtonPressed()	//FIXME-2
+void EditXLinkDialog::setColorHeadingButtonPressed()	
 {
-/*
-	if (xlo)
+	if (xli)
 	{	
-		if (selection && 
-			(typid(*selection) == typid(BranchObj) || 
-			typid(*selection) == typid(MapCenterObj))  )
+		if (selbi)
 		{
-			QColor col=((BranchObj*)(selection))->getColor();
-			xlo->setColor(col);
+			QColor col=selbi->getHeadingColor();
+			xli->setColor(col);
 			ui.colorButton->setPaletteBackgroundColor (col);
 		}
 	}
-	*/
 }
 
 bool EditXLinkDialog::useSettingsGlobal ()
diff -r d85834ad8c54 -r 133e2ed6b9c5 editxlinkdialog.h
--- a/editxlinkdialog.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/editxlinkdialog.h	Thu Sep 03 08:52:00 2009 +0000
@@ -10,13 +10,15 @@
 where you want to have crossreferences which don't fit on the same visible area
 */
 
+class BranchItem;
+
 class EditXLinkDialog:public QDialog
 {
 	Q_OBJECT
 public:
 	EditXLinkDialog (QWidget *parent=0);
-	void setXLink (XLinkObj *);
-	void setSelection (LinkableMapObj *);
+	void setXLink (XLinkItem *);
+	void setSelection (BranchItem*);
 	bool useSettingsGlobal();
 	bool deleteXLink();
 
@@ -29,8 +31,8 @@
 private:
 	Ui::EditXLinkDialog ui;
 	bool delink;
-	XLinkObj *xlo;
-	LinkableMapObj *selection;
+	XLinkItem *xli;
+	BranchItem *selbi;
 };
 
 #endif // EDITXLINKDIALOG_H
diff -r d85834ad8c54 -r 133e2ed6b9c5 editxlinkdialog.ui
--- a/editxlinkdialog.ui	Mon Aug 24 14:39:07 2009 +0000
+++ b/editxlinkdialog.ui	Thu Sep 03 08:52:00 2009 +0000
@@ -1,126 +1,120 @@
-<ui version="4.0" >
- <author></author>
- <comment></comment>
- <exportmacro></exportmacro>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>EditXLinkDialog</class>
- <widget class="QDialog" name="EditXLinkDialog" >
-  <property name="geometry" >
+ <widget class="QDialog" name="EditXLinkDialog">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>393</width>
-    <height>206</height>
+    <width>383</width>
+    <height>167</height>
    </rect>
   </property>
-  <property name="sizePolicy" >
-   <sizepolicy>
-    <hsizetype>5</hsizetype>
-    <vsizetype>5</vsizetype>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>Edit XLink</string>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
+  <layout class="QVBoxLayout">
+   <property name="spacing">
+    <number>6</number>
+   </property>
+   <property name="margin">
     <number>11</number>
    </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
    <item>
-    <layout class="QGridLayout" >
-     <property name="margin" >
+    <layout class="QGridLayout">
+     <property name="margin">
       <number>0</number>
      </property>
-     <property name="spacing" >
+     <property name="spacing">
       <number>6</number>
      </property>
-     <item row="0" column="1" >
-      <widget class="QSpinBox" name="widthBox" >
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>0</hsizetype>
-         <vsizetype>0</vsizetype>
+     <item row="0" column="1">
+      <widget class="QSpinBox" name="widthBox">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
-       <property name="maximum" >
+       <property name="minimum">
+        <number>1</number>
+       </property>
+       <property name="maximum">
         <number>15</number>
        </property>
-       <property name="minimum" >
-        <number>1</number>
-       </property>
       </widget>
      </item>
-     <item row="0" column="0" >
-      <widget class="QLabel" name="textLabel1" >
-       <property name="text" >
+     <item row="0" column="0">
+      <widget class="QLabel" name="textLabel1">
+       <property name="text">
         <string>XLink width:</string>
        </property>
-       <property name="alignment" >
+       <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
       </widget>
      </item>
-     <item row="1" column="4" >
-      <widget class="QPushButton" name="setColorHeadingButton" >
-       <property name="maximumSize" >
+     <item row="1" column="4">
+      <widget class="QPushButton" name="setColorHeadingButton">
+       <property name="maximumSize">
         <size>
          <width>32767</width>
          <height>20</height>
         </size>
        </property>
-       <property name="text" >
+       <property name="text">
         <string>Set color of heading</string>
        </property>
       </widget>
      </item>
-     <item row="1" column="1" >
-      <widget class="QPushButton" name="colorButton" >
-       <property name="enabled" >
+     <item row="1" column="1">
+      <widget class="QPushButton" name="colorButton">
+       <property name="enabled">
         <bool>true</bool>
        </property>
-       <property name="maximumSize" >
+       <property name="maximumSize">
         <size>
          <width>50</width>
          <height>20</height>
         </size>
        </property>
-       <property name="text" >
+       <property name="text">
         <string/>
        </property>
       </widget>
      </item>
-     <item row="2" column="1" colspan="2" >
-      <widget class="QCheckBox" name="useSettings" >
-       <property name="text" >
+     <item row="2" column="1" colspan="2">
+      <widget class="QCheckBox" name="useSettings">
+       <property name="text">
         <string/>
        </property>
       </widget>
      </item>
-     <item row="1" column="0" >
-      <widget class="QLabel" name="textLabel2" >
-       <property name="text" >
+     <item row="1" column="0">
+      <widget class="QLabel" name="textLabel2">
+       <property name="text">
         <string>XLink color:</string>
        </property>
-       <property name="alignment" >
+       <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
       </widget>
      </item>
-     <item row="1" column="2" colspan="2" >
+     <item row="1" column="2" colspan="2">
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
+       <property name="sizeType">
         <enum>QSizePolicy::Expanding</enum>
        </property>
-       <property name="sizeHint" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>285</width>
          <height>20</height>
@@ -128,15 +122,15 @@
        </property>
       </spacer>
      </item>
-     <item row="0" column="2" colspan="2" >
+     <item row="0" column="2" colspan="2">
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
+       <property name="sizeType">
         <enum>QSizePolicy::Expanding</enum>
        </property>
-       <property name="sizeHint" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>280</width>
          <height>20</height>
@@ -144,25 +138,25 @@
        </property>
       </spacer>
      </item>
-     <item row="2" column="0" >
-      <widget class="QLabel" name="textLabel1_2" >
-       <property name="text" >
+     <item row="2" column="0">
+      <widget class="QLabel" name="textLabel1_2">
+       <property name="text">
         <string>Use as default:</string>
        </property>
-       <property name="alignment" >
+       <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
       </widget>
      </item>
-     <item row="2" column="3" colspan="2" >
+     <item row="2" column="3" colspan="2">
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
+       <property name="sizeType">
         <enum>QSizePolicy::Expanding</enum>
        </property>
-       <property name="sizeHint" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>241</width>
          <height>20</height>
@@ -174,13 +168,13 @@
    </item>
    <item>
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeType" >
+     <property name="sizeType">
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
        <width>20</width>
        <height>16</height>
@@ -189,29 +183,29 @@
     </spacer>
    </item>
    <item>
-    <layout class="QHBoxLayout" >
-     <property name="margin" >
+    <layout class="QHBoxLayout">
+     <property name="spacing">
+      <number>6</number>
+     </property>
+     <property name="margin">
       <number>0</number>
      </property>
-     <property name="spacing" >
-      <number>6</number>
-     </property>
      <item>
-      <widget class="QPushButton" name="deleteButton" >
-       <property name="text" >
+      <widget class="QPushButton" name="deleteButton">
+       <property name="text">
         <string>Quit and delete XLink</string>
        </property>
       </widget>
      </item>
      <item>
       <spacer>
-       <property name="orientation" >
+       <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
-       <property name="sizeType" >
+       <property name="sizeType">
         <enum>QSizePolicy::Expanding</enum>
        </property>
-       <property name="sizeHint" >
+       <property name="sizeHint" stdset="0">
         <size>
          <width>100</width>
          <height>20</height>
@@ -220,8 +214,8 @@
       </spacer>
      </item>
      <item>
-      <widget class="QPushButton" name="okButton" >
-       <property name="text" >
+      <widget class="QPushButton" name="okButton">
+       <property name="text">
         <string>Ok</string>
        </property>
       </widget>
@@ -230,11 +224,11 @@
    </item>
   </layout>
  </widget>
- <layoutdefault spacing="6" margin="11" />
+ <layoutdefault spacing="6" margin="11"/>
  <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
  <includes>
-  <include location="local" >xlinkobj.h</include>
-  <include location="local" >linkablemapobj.h</include>
+  <include location="local">xlinkitem.h</include>
+  <include location="local">linkablemapobj.h</include>
  </includes>
  <resources/>
  <connections>
@@ -244,11 +238,11 @@
    <receiver>EditXLinkDialog</receiver>
    <slot>accept()</slot>
    <hints>
-    <hint type="sourcelabel" >
+    <hint type="sourcelabel">
      <x>338</x>
      <y>180</y>
     </hint>
-    <hint type="destinationlabel" >
+    <hint type="destinationlabel">
      <x>196</x>
      <y>102</y>
     </hint>
diff -r d85834ad8c54 -r 133e2ed6b9c5 floatimageobj.cpp
--- a/floatimageobj.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/floatimageobj.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -8,25 +8,29 @@
 // FloatImageObj
 /////////////////////////////////////////////////////////////////
 
+/* FIXME-3
 FloatImageObj::FloatImageObj ():FloatObj()
 {
 //    cout << "Const FloatImageObj ()\n";
     setParObj (this);	
     init();
 }
+*/
 
-FloatImageObj::FloatImageObj (QGraphicsScene* s):FloatObj(s)
+FloatImageObj::FloatImageObj (QGraphicsScene* s,TreeItem *ti):FloatObj(s,ti)
 {
-//   cout << "Const FloatImageObj (s)  called from MapCenterObj (s)\n";
+   //cout << "Const FloatImageObj s="<<s<<"  ti="<<ti<<endl;
     setParObj (this);	
     init();
 }
 
+/* FIXME-3 needed
 FloatImageObj::FloatImageObj (QGraphicsScene *s, OrnamentedObj* p):FloatObj(s,p)
 {
  //   cout << "Const FloatImageObj (c,p)\n";
     init();
 }
+*/
 
 FloatImageObj::~FloatImageObj ()
 {
diff -r d85834ad8c54 -r 133e2ed6b9c5 floatimageobj.h
--- a/floatimageobj.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/floatimageobj.h	Thu Sep 03 08:52:00 2009 +0000
@@ -5,15 +5,16 @@
 //Added by qt3to4:
 #include <QPixmap>
 
+class TreeItem;
 /*! \brief A pixmap which can be positioned freely as FlagObj  on the map.  */
 
 
 /////////////////////////////////////////////////////////////////////////////
 class FloatImageObj:public FloatObj {
 public:
-    FloatImageObj ();
-    FloatImageObj (QGraphicsScene*);
-    FloatImageObj (QGraphicsScene*, OrnamentedObj* parent);
+    //FIXME-3 FloatImageObj ();
+    FloatImageObj (QGraphicsScene*,TreeItem *ti=NULL);
+    //FIXME-3 FloatImageObj (QGraphicsScene*, OrnamentedObj* parent);
     ~FloatImageObj ();
     virtual void init ();
     virtual void copy (FloatImageObj*);
diff -r d85834ad8c54 -r 133e2ed6b9c5 floatobj.cpp
--- a/floatobj.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/floatobj.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -1,30 +1,19 @@
 #include "floatobj.h"
 
+#include <iostream>
+using namespace std;
+
 /////////////////////////////////////////////////////////////////
 // FloatObj
 /////////////////////////////////////////////////////////////////
 
-FloatObj::FloatObj ():OrnamentedObj() 
+FloatObj::FloatObj (QGraphicsScene* s, TreeItem *ti):OrnamentedObj(s,ti)
 {
-//    cout << "Const FloatObj ()\n";
+	cout << "Const FloatObj s="<<s<<"  ti="<<ti<<"  treeItem="<<treeItem<<endl;
     setParObj (this);	
     init();
 }
 
-FloatObj::FloatObj (QGraphicsScene* s):OrnamentedObj(s)
-{
-//	cout << "Const FloatObj (s)  called from MapCenterObj (s)\n";
-    setParObj (this);	
-    init();
-}
-
-FloatObj::FloatObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
-{
-//    cout << "Const FloatObj (s,p)\n";
-    setParObj (p);	
-    init();
-}
-
 FloatObj::~FloatObj ()
 {
 //   cout << "Destr FloatObj\n";
diff -r d85834ad8c54 -r 133e2ed6b9c5 floatobj.h
--- a/floatobj.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/floatobj.h	Thu Sep 03 08:52:00 2009 +0000
@@ -9,9 +9,7 @@
 /////////////////////////////////////////////////////////////////////////////
 class FloatObj:public OrnamentedObj {
 public:
-    FloatObj ();
-    FloatObj (QGraphicsScene*);
-    FloatObj (QGraphicsScene*, LinkableMapObj* parent);
+    FloatObj (QGraphicsScene*,TreeItem *ti=NULL);
     ~FloatObj ();
     virtual void init ();
     virtual void copy (FloatObj*);
diff -r d85834ad8c54 -r 133e2ed6b9c5 imageitem.cpp
--- a/imageitem.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/imageitem.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -52,8 +52,7 @@
 
 FloatImageObj* ImageItem::createMapObj(QGraphicsScene *scene)
 {
-	FloatImageObj *fio=new FloatImageObj (scene);
-	fio->setTreeItem (this);
+	FloatImageObj *fio=new FloatImageObj (scene,this);
 	lmo=fio;
 	fio->setParObj ( ((MapItem*)parentItem)->getLMO());
 	if (((BranchItem*)parentItem)->isScrolled() || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
@@ -61,6 +60,7 @@
 	initLMO();
 	fio->setZValue(zValue);
 	fio->setRelPos (pos);
+	cout << "II::createMO   fio="<<fio<<"   tI="<<fio->getTreeItem()<<endl;
 	return fio;
 }
 
diff -r d85834ad8c54 -r 133e2ed6b9c5 linkablemapobj.cpp
--- a/linkablemapobj.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/linkablemapobj.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -11,15 +11,17 @@
 // LinkableMapObj
 /////////////////////////////////////////////////////////////////
 
+/* FIXME-3
 LinkableMapObj::LinkableMapObj():MapObj()
 {
   //  cout << "Const LinkableMapObj ()\n";
     init ();
 }
+*/
 
-LinkableMapObj::LinkableMapObj(QGraphicsScene* s) :MapObj(s)
+LinkableMapObj::LinkableMapObj(QGraphicsScene* s, TreeItem *ti) :MapObj(s,ti)
 {
-//    cout << "Const LinkableMapObj (s)\n";
+//    cout << "Const LinkableMapObj s="<<s<<"  ti="<<ti<<"  treeItem="<<treeItem<<endl;
     init ();
 }
 
@@ -86,9 +88,6 @@
 	// Rel Positions
 	relPos=QPointF(0,0);
 	useRelPos=false;
-
-	// Crossreference to treemodel
-	treeItem=NULL;
 }
 
 void LinkableMapObj::copy (LinkableMapObj* other)
@@ -101,16 +100,6 @@
 	treeItem=other->treeItem;
 }
 
-void LinkableMapObj::setTreeItem (TreeItem *ti)
-{
-	treeItem=ti;
-}
-
-TreeItem* LinkableMapObj::getTreeItem () const
-{
-	return treeItem;
-}
-
 void LinkableMapObj::setParObj(LinkableMapObj* o)
 {
     parObj=o;
diff -r d85834ad8c54 -r 133e2ed6b9c5 linkablemapobj.h
--- a/linkablemapobj.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/linkablemapobj.h	Thu Sep 03 08:52:00 2009 +0000
@@ -5,13 +5,11 @@
 #include "noteobj.h"
 #include "headingobj.h"
 #include "flagrowobj.h"
-#include "treeitem.h"
 
 #define MAX_DEPTH 999
 
 class VymModel;
-
-
+class TreeItem;
 
 /*! \brief This class adds links to MapObj 
 
@@ -50,16 +48,13 @@
 	};
 
     LinkableMapObj ();
-    LinkableMapObj (QGraphicsScene*);
+    LinkableMapObj (QGraphicsScene*, TreeItem *ti=NULL);
     LinkableMapObj (LinkableMapObj*);
     ~LinkableMapObj ();
 	virtual void delLink();
     virtual void init ();
     virtual void copy (LinkableMapObj*);
 
-	virtual void setTreeItem(TreeItem *);
-	virtual TreeItem* getTreeItem() const;
-
     void setChildObj (LinkableMapObj*);
     virtual void setParObj (LinkableMapObj*);
     virtual void setParObjTmp (LinkableMapObj*,QPointF,int);	// Only for moving Obj around
@@ -146,6 +141,5 @@
 	QPointF	 relPos;				// position relative to childPos of parent
 	bool useRelPos;
 
-	TreeItem *treeItem;				// Crossrefence to treemodel
 };
 #endif
diff -r d85834ad8c54 -r 133e2ed6b9c5 mainwindow.cpp
--- a/mainwindow.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/mainwindow.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -21,6 +21,7 @@
 #include "settings.h"
 #include "texteditor.h"
 #include "warningdialog.h"
+#include "xlinkitem.h"
 
 #if defined(Q_OS_WIN32)
 // Define only this structure as opposed to
@@ -3382,26 +3383,21 @@
 				actionFormatHideLinkUnselected->setEnabled (true);
 			}
 
-			if (selbi)	// FIXME-4 many properties of former BranchObj are in TreeItem meanwhile...
+			if (selbi)	
 			{
-				// Take care of links  // updateActions: FIXME-1
-				/*
-				if (bo->countXLinks()==0)
+				// Take care of xlinks  
+				branchXLinksContextMenuEdit->clear();
+				branchXLinksContextMenuFollow->clear();
+				if (selbi->xlinkCount()>0)
 				{
-					branchXLinksContextMenuEdit->clear();
-					branchXLinksContextMenuFollow->clear();
-				} else
-				{
-					BranchObj *bot;
+					BranchItem *bi;
 					QString s;
-					branchXLinksContextMenuEdit->clear();
-					branchXLinksContextMenuFollow->clear();
-					for (int i=0; i<=bo->countXLinks();i++)
+					for (int i=0; i<selbi->xlinkCount();++i)
 					{
-						bot=bo->XLinkTargetAt(i);
-						if (bot)
+						bi=selbi->getXLinkNum(i)->getPartnerBranch();
+						if (bi)
 						{
-							s=bot->getHeading();
+							s=bi->getHeading();
 							if (s.length()>xLinkMenuWidth)
 								s=s.left(xLinkMenuWidth)+"...";
 							branchXLinksContextMenuFollow->addAction (s);
@@ -3409,7 +3405,6 @@
 						}	
 					}
 				}
-				*/
 				//Standard Flags
 				standardFlagsMaster->updateToolBar (selbi->activeStandardFlagNames() );
 
diff -r d85834ad8c54 -r 133e2ed6b9c5 mainwindow.h
--- a/mainwindow.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/mainwindow.h	Thu Sep 03 08:52:00 2009 +0000
@@ -16,6 +16,7 @@
 #include "texteditor.h"
 #include "vymview.h"
 
+
 class Main : public QMainWindow 
 {
     Q_OBJECT
diff -r d85834ad8c54 -r 133e2ed6b9c5 mapeditor.cpp
--- a/mapeditor.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/mapeditor.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -10,6 +10,7 @@
 #include "mainwindow.h"
 #include "misc.h"
 #include "warningdialog.h"
+#include "xlinkitem.h"
 
 
 extern int statusbarTime;
@@ -881,6 +882,7 @@
     LinkableMapObj* lmo=NULL;
 	if (ti) lmo=((MapItem*)ti)->getLMO();
 	
+	
 	e->accept();
 
 	//Take care of  system flags _or_ modifier modes
@@ -923,22 +925,15 @@
 		} 
 		if (mainWindow->getModMode()==Main::ModModeXLink)
 		{	
-			BranchObj *bo_begin=NULL;
-			if (lmo)
-				bo_begin=(BranchObj*)(lmo);
-			else	
-				bo_begin=model->getSelectedBranchObj();
-			if (bo_begin)	
+			BranchItem *bi_begin=model->getSelectedBranch();
+			if (bi_begin)	
 			{
 				drawingLink=true;
-				linkingObj_src=bo_begin;
-				tmpXLink=new XLinkObj (mapScene);
-				tmpXLink->setBegin (bo_begin);
-				tmpXLink->setEnd   (p);
+				tmpXLink=model->createXLink(bi_begin,true);
 				tmpXLink->setColor(model->getMapDefXLinkColor());
 				tmpXLink->setWidth(model->getMapDefXLinkWidth());
+				tmpXLink->setEnd   (p);
 				tmpXLink->updateXLink();
-				tmpXLink->setVisibility (true);
 				return;
 			} 
 		}
@@ -1192,13 +1187,13 @@
 		// Check if we are over another branch
 		if (dsti)
 		{	
-			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
+			tmpXLink->setEnd ( ((BranchItem*)dsti) );
 			tmpXLink->updateXLink();
-			tmpXLink->activate(); //FIXME-2 savestate missing
-			//model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );	
+			tmpXLink->activate(); 
+			//FIXME-0 model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) );	
 		} else
 		{
-			delete(tmpXLink);
+			model->deleteItem(tmpXLink);
 			tmpXLink=NULL;
 		}
 		return;
diff -r d85834ad8c54 -r 133e2ed6b9c5 mapeditor.h
--- a/mapeditor.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/mapeditor.h	Thu Sep 03 08:52:00 2009 +0000
@@ -10,9 +10,10 @@
 #include "ornamentedobj.h"
 #include "settings.h"
 #include "vymmodel.h"
-#include "xlinkobj.h"
 
 
+class XLinkItem;
+
 /*! \brief Main widget in vym to display and edit a map */
 
 
@@ -112,10 +113,9 @@
 	bool pickingColor;
 	bool drawingLink;			// true while creating a link
 	bool copyingObj;			// true while creating a link
-	XLinkObj* tmpXLink;
+	XLinkItem* tmpXLink;
 
 	MapObj* movingObj;				// moving a MapObj
-	MapObj* linkingObj_src;			// part of a link
     QPointF movingObj_orgPos;		// org. pos of mouse before move
     QPointF movingObj_orgRelPos;	// org. relative pos of mouse before move
     QPointF movingObj_start;		// rel. pos of mouse to absPos 
diff -r d85834ad8c54 -r 133e2ed6b9c5 mapobj.cpp
--- a/mapobj.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/mapobj.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -12,10 +12,11 @@
     init ();
 }
 
-MapObj::MapObj (QGraphicsScene *s)
+MapObj::MapObj (QGraphicsScene *s, TreeItem *ti)
 {
 //  cout << "Const MapObj\n";
     scene=s;
+	treeItem=ti;
     init ();
 }
 
@@ -46,6 +47,17 @@
 	bbox.setSize (QSizeF(other->bbox.width(), other->bbox.height() ) );
 }
 
+void MapObj::setTreeItem (TreeItem *ti)
+{
+	treeItem=ti;
+}
+
+TreeItem* MapObj::getTreeItem () const
+{
+	return treeItem;
+}
+
+
 QGraphicsScene* MapObj::getScene()
 {
 	return scene;
diff -r d85834ad8c54 -r 133e2ed6b9c5 mapobj.h
--- a/mapobj.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/mapobj.h	Thu Sep 03 08:52:00 2009 +0000
@@ -16,17 +16,24 @@
 #define Z_TEXT     100
 #define Z_LINEEDIT 110
 
+
+class TreeItem;
+
 /*! \brief Base class for all objects visible on a map
 */
 
 class MapObj:public XMLObj {
 public:
     MapObj ();
-    MapObj (QGraphicsScene*);
+    MapObj (QGraphicsScene *scene,TreeItem *ti=NULL);
     MapObj (MapObj*);
     virtual ~MapObj ();
     virtual void init ();
     virtual void copy (MapObj*);
+
+	virtual void setTreeItem(TreeItem *);
+	virtual TreeItem* getTreeItem() const;
+
 	virtual QGraphicsScene* getScene();
     virtual qreal x();
     virtual qreal y();
@@ -51,6 +58,9 @@
 	QRectF clickBox;								// area where mouseclicks are found
     QPointF absPos;							    // Position on canvas
     bool visible;
+
+	TreeItem *treeItem;				// Crossrefence to treemodel
+
 };
 
 #endif
diff -r d85834ad8c54 -r 133e2ed6b9c5 ornamentedobj.cpp
--- a/ornamentedobj.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/ornamentedobj.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -6,13 +6,8 @@
 // OrnamentedObj
 /////////////////////////////////////////////////////////////////
 
-OrnamentedObj::OrnamentedObj():LinkableMapObj()
-{
-  //  cout << "Const OrnamentedObj ()\n";
-    init ();
-}
 
-OrnamentedObj::OrnamentedObj(QGraphicsScene* s) :LinkableMapObj(s)
+OrnamentedObj::OrnamentedObj(QGraphicsScene* s,TreeItem *ti) :LinkableMapObj(s,ti)
 {
 //    cout << "Const OrnamentedObj (s)\n";
     init ();
diff -r d85834ad8c54 -r 133e2ed6b9c5 ornamentedobj.h
--- a/ornamentedobj.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/ornamentedobj.h	Thu Sep 03 08:52:00 2009 +0000
@@ -5,6 +5,8 @@
 #include "frameobj.h"
 #include "linkablemapobj.h"
 
+class TreeItem;
+
 /*! \brief Adds various ornaments and data to the class LinkableMapObj
 
 The ornaments are:
@@ -19,8 +21,7 @@
 
 class OrnamentedObj:public LinkableMapObj {
 public:	
-    OrnamentedObj ();
-    OrnamentedObj (QGraphicsScene*);
+    OrnamentedObj (QGraphicsScene*, TreeItem *ti=NULL);
     OrnamentedObj (OrnamentedObj*);
     ~OrnamentedObj ();
     virtual void init ();
diff -r d85834ad8c54 -r 133e2ed6b9c5 treeitem.cpp
--- a/treeitem.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/treeitem.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -1,11 +1,13 @@
 #include <iostream>
 #include <QStringList>
 
-#include "treeitem.h"
-
+#include "attributeitem.h"
 #include "branchobj.h"
 #include "branchitem.h"
+#include "treeitem.h"
 #include "vymmodel.h"
+#include "xlinkitem.h"
+#include "xlinkobj.h"
 
 using namespace std;
 
@@ -53,6 +55,9 @@
 			case TreeItem::Attribute:
 				delete (AttributeItem*)ti;
 				break;
+			case TreeItem::XLink:
+				delete (XLinkItem*)ti;
+				break;
 			default:
 				delete ti;
 				break;
@@ -74,6 +79,9 @@
 	attributeCounter=0;
 	attributeOffset=0;
 
+	xlinkCounter=0;
+	xlinkOffset=0;
+
 	note.setNote(""); 
 	// note.setFontHint (textEditor->getFontHintDefault() );	//FIXME-3
 	// isNoteInEditor=false;
@@ -114,6 +122,7 @@
 	switch (item->type)
 	{
 		case Attribute: return attributeOffset + attributeCounter;
+		case XLink: return xlinkOffset + xlinkCounter;
 		case Image: return imageOffset + imageCounter;
 		case MapCenter: return branchOffset + branchCounter;
 		case Branch: return branchOffset + branchCounter;
@@ -132,6 +141,15 @@
 		// attribute are on top of list
 		childItems.insert (attributeCounter,item);
 		attributeCounter++;
+		xlinkOffset++;
+		imageOffset++;
+		branchOffset++;
+	}
+
+	if (item->type == XLink)
+	{
+		childItems.insert (xlinkCounter+xlinkOffset,item);
+		xlinkCounter++;
 		imageOffset++;
 		branchOffset++;
 	}
@@ -166,6 +184,13 @@
 		if (childItems.at(row)->type==Attribute)
 		{
 			attributeCounter--;
+			xlinkOffset--;
+			imageOffset--;
+			branchOffset--;
+		}	
+		if (childItems.at(row)->type==XLink)
+		{
+			xlinkCounter--;
 			imageOffset--;
 			branchOffset--;
 		}	
@@ -226,10 +251,9 @@
     return imageCounter; 
 }
 
-int TreeItem::xlinkCount() const // FIXME-2 check if xlinks are stored in a different way (global to model?)
+int TreeItem::xlinkCount() const
 {
-	int xlinkCounter=0;
-    return xlinkCounter; // FIXME-1 xlinkCounter needs to be calculated...
+    return xlinkCounter; 
 }
 
 int TreeItem::attributeCount() const 
@@ -283,6 +307,7 @@
 		case Branch: return parentItem->childItems.indexOf (this) - parentItem->branchOffset;
 		case Image: return parentItem->childItems.indexOf (this) - parentItem->imageOffset;
 		case Attribute: return parentItem->childItems.indexOf (this) - parentItem->attributeOffset;
+		case XLink: return parentItem->childItems.indexOf (this) - parentItem->xlinkOffset;
 		default: return -1;
 	}
 }
@@ -297,6 +322,7 @@
 		case Branch: return childItems.indexOf (item) - branchOffset;
 		case Image: return parentItem->childItems.indexOf (item) - imageOffset;
 		case Attribute: return parentItem->childItems.indexOf (item) - attributeOffset;
+		case XLink: return parentItem->childItems.indexOf (item) - xlinkOffset;
 		default: return -1;
 	}
 }
@@ -327,6 +353,7 @@
 		case Branch: return QString ("Branch");
 		case Image: return QString ("Image");
 		case Attribute: return QString ("Attribute");
+		case XLink: return QString ("XLink");
 		default: return QString ("TreeItem::getTypeName no typename defined?!");
 	}
 }
@@ -530,7 +557,6 @@
 {
 	switch (type)
 	{
-		case Undefined: return false;
 		case MapCenter: 
 		case Branch: 
 			if (!parentItem) return false;
@@ -539,7 +565,6 @@
 			else
 				return false;
 			break;	
-		case Image: return false;
 		default: return false;
 	}
 }
@@ -623,6 +648,33 @@
 		return NULL;
 }
 
+XLinkItem* TreeItem::getXLinkNum (const int &n)	
+{
+	if (n>=0 && n<xlinkCounter )
+		return (XLinkItem*)getChildNum (xlinkOffset +n);
+	else
+		return NULL;
+}
+
+
+XLinkObj* TreeItem::getXLinkObjNum (const int &n)	
+{
+	if (xlinkCounter>0 )
+	{
+		XLinkItem *xli=getXLinkNum (n);
+		if (!xli) return NULL;
+		if (xli->isBegin() )
+			return (XLinkObj*)(xli->getLMO());
+		else
+		{
+			xli=xli->getPartnerXLink();
+			if (!xli) return NULL;
+			return (XLinkObj*)(xli->getLMO());
+		}
+	}
+	return NULL;
+}
+
 
 void TreeItem::setHideTmp (HideTmpMode mode)  //FIXME-2
 {
diff -r d85834ad8c54 -r 133e2ed6b9c5 treeitem.h
--- a/treeitem.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/treeitem.h	Thu Sep 03 08:52:00 2009 +0000
@@ -6,7 +6,6 @@
 #include <QVariant>
 
 #include "flagrow.h"
-//#include "mapitem.h"
 #include "noteobj.h"
 #include "xmlobj.h"
 
@@ -16,11 +15,13 @@
 class FloatImageObj;
 class ImageItem;
 class VymModel;
+class XLinkItem;
+class XLinkObj;
 
 class TreeItem:public XMLObj
 {
 public:
-	enum Type {Undefined,MapCenter,Branch,Image,Attribute};	//FIXME-3 MapCenter still needed?
+	enum Type {Undefined,MapCenter,Branch,Image,Attribute,XLink};	//FIXME-3 MapCenter still needed?
 	enum HideTmpMode {HideNone, HideExport};
 
     TreeItem();
@@ -155,6 +156,9 @@
 	virtual ImageItem* getImageNum(const int &n);
 	virtual FloatImageObj* getImageObjNum(const int &n);
 
+	virtual XLinkItem* getXLinkNum(const int &n);
+	virtual XLinkObj* getXLinkObjNum(const int &n);
+
 protected:
 	bool hideExport;							//! Hide this item in export
 public:
@@ -185,6 +189,9 @@
 	int attributeOffset;
 	int attributeCounter;
 
+	int xlinkOffset;
+	int xlinkCounter;
+
 	bool hidden;	//! Hidden in export if true
 };
 
diff -r d85834ad8c54 -r 133e2ed6b9c5 treemodel.cpp
--- a/treemodel.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/treemodel.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -8,12 +8,13 @@
 #include "imageitem.h"
 #include "treeitem.h"
 #include "treemodel.h"
+#include "xlinkitem.h"
 
 TreeModel::TreeModel(QObject *parent)
     : QAbstractItemModel(parent)
 {
     QList<QVariant> rootData;
-    rootData << "Heading" << "Type" <<"Note";
+    rootData << "Heading" << "Type";
     rootItem = new TreeItem(rootData);
 }
 
@@ -217,13 +218,11 @@
     TreeItem *pi= getItem (parent);
 	TreeItem *ti;
 
-/* FIXME-3
 	cout << "TM::removeRows  row="<<row<<"  count="<<count<<endl;
-	cout << "                pi="<<pi<<"  ti="<<ti<<endl;
-*/	
 	for (int i=row; i<=last; i++)
 	{
 		ti=pi->getChildNum (row);
+		cout << "   pi="<<pi<<"  ti="<<ti<<endl;
 		pi->removeChild (row);	// does not delete object!
 		switch (ti->getType()) 
 		{
@@ -239,6 +238,9 @@
 			case TreeItem::Attribute:
 				delete (AttributeItem*)ti; 
 				break;
+			case TreeItem::XLink:
+				delete (XLinkItem*)ti; 
+				break;
 			default:
 				delete ti;
 				break;
diff -r d85834ad8c54 -r 133e2ed6b9c5 version.h
--- a/version.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/version.h	Thu Sep 03 08:52:00 2009 +0000
@@ -7,7 +7,7 @@
 #define __VYM_VERSION "1.13.0"
 //#define __VYM_CODENAME "Codename: RC-1"
 #define __VYM_CODENAME "Codename: development version, not for production!"
-#define __VYM_BUILD_DATE "2009-08-24"
+#define __VYM_BUILD_DATE "2009-09-01"
 
 
 bool checkVersion(const QString &);
diff -r d85834ad8c54 -r 133e2ed6b9c5 vym.pro
--- a/vym.pro	Mon Aug 24 14:39:07 2009 +0000
+++ b/vym.pro	Thu Sep 03 08:52:00 2009 +0000
@@ -81,6 +81,7 @@
 	treeeditor.h \
 	version.h \
 	vymmodel.h \
+	xlinkitem.h \
 	xlinkobj.h \
 	xml-base.h \
 	xml-vym.h \
@@ -147,6 +148,7 @@
 	treemodel.cpp \
 	version.cpp \
 	vymmodel.cpp \
+	xlinkitem.cpp \
 	xlinkobj.cpp \
 	xml-base.cpp \
 	xml-vym.cpp \
diff -r d85834ad8c54 -r 133e2ed6b9c5 vymmodel.cpp
--- a/vymmodel.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/vymmodel.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -16,6 +16,7 @@
 #include "parser.h"
 
 #include "warningdialog.h"
+#include "xlinkitem.h"
 #include "xml-freemind.h"
 #include "xmlobj.h"
 #include "xml-vym.h"
@@ -238,7 +239,7 @@
 	s+=xml.beginElement("vymmap",mapAttr);
 	xml.incIndent();
 
-	// Find the used flags while traversing the tree	// FIXME-2 this can be done local to vymmodel maybe...
+	// Find the used flags while traversing the tree	// FIXME-3 this can be done local to vymmodel maybe...
 	standardFlagsMaster->resetUsedCounter();
 	
 	// Build xml recursivly
@@ -261,7 +262,8 @@
 				// Save Image
 				s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
 				break;
-			default://FIXME-4 other types shouldn't be safed...
+			default: 
+				// other types shouldn't be safed directly...
 				break;
 		}
 	}
@@ -1444,12 +1446,14 @@
 
 TreeItem* VymModel::findID (const QString &s)
 {
-	TreeItem *ti;
-	for (int i=0; i<rootItem->branchCount(); i++)
+	BranchItem *cur=NULL;
+	BranchItem *prev=NULL;
+	next(cur,prev);
+	while (cur) 
 	{
-		ti=rootItem->getBranchNum(i)->findID (s);
-		if (ti) return ti;
-	}	
+		if (s==cur->getID() ) return cur;
+		next(cur,prev);
+	}
 	return NULL;
 }
 
@@ -1984,7 +1988,7 @@
 		int n;
 
 		QList<QVariant> cData;
-		cData << "new" << "undef"<<"undef";
+		cData << "new" << "undef";
 
 		ImageItem *newii=new ImageItem(cData) ;	
 		//newii->setHeading (QApplication::translate("Heading of new image in map", "new image"));
@@ -2008,13 +2012,48 @@
 	return NULL;
 }
 
+XLinkItem* VymModel::createXLink(BranchItem *bi,bool createMO)
+{
+	if (bi)
+	{
+		QModelIndex parix;
+		int n;
+
+		QList<QVariant> cData;
+		cData << "new xLink"<<"undef";
+
+		XLinkItem *newxli=new XLinkItem(cData) ;	
+
+		emit (layoutAboutToBeChanged() );
+
+			parix=index(bi);
+			n=bi->getRowNumAppend(newxli);
+			beginInsertRows (parix,n,n+1);
+			bi->appendChild (newxli);	
+			endInsertRows ();
+
+		emit (layoutChanged() );
+
+		// save scroll state. If scrolled, automatically select
+		// new branch in order to tmp unscroll parent...
+		newxli->setBegin (bi);
+		if (createMO) 
+		{
+			newxli->createMapObj(mapScene);
+			reposition();
+		}
+		return newxli;
+	} 
+	return NULL;
+}
+
 AttributeItem* VymModel::addAttribute()	// FIXME-2 savestate missing
 {
 	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
 	{
 		QList<QVariant> cData;
-		cData << "new attribute" << "undef"<<"undef";
+		cData << "new attribute" << "undef";
 		AttributeItem *a=new AttributeItem (cData);
 
 		emit (layoutAboutToBeChanged() );
@@ -2061,7 +2100,7 @@
 	beginInsertRows (parix,n,n+1);
 
 	QList<QVariant> cData;
-	cData << "VM:addMapCenter" << "undef"<<"undef";
+	cData << "VM:addMapCenter" << "undef";
 	BranchItem *newbi=new BranchItem (cData,rootItem);
 	newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
 	rootItem->appendChild (newbi);
@@ -2086,7 +2125,7 @@
 
 	// Create TreeItem
 	QList<QVariant> cData;
-	cData << "new" << "undef"<<"undef";
+	cData << "new" << "undef";
 
 	BranchItem *parbi;
 	QModelIndex parix;
@@ -2298,15 +2337,20 @@
 		return;
 	}
 	TreeItem *ti=getSelectedItem();
-	if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
+	if (ti)
 	{
 		TreeItem *pi=ti->parent();
-		saveStateChangingPart(
-			pi, 
-			ti,
-			"delete ()",
-			QString("Delete %1").arg(getObjectName(ti))
-		);
+		if (!pi) return;
+		if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
+		{
+			saveStateChangingPart(
+				pi, 
+				ti,
+				"delete ()",
+				QString("Delete %1").arg(getObjectName(ti))
+			);
+		}
+		// FIXME-0 savestate missing for deletion of other times
 		unselect();
 		deleteItem (ti);
 		emitDataHasChanged (pi);
@@ -2393,6 +2437,7 @@
 
 TreeItem* VymModel::deleteItem (TreeItem *ti)
 {
+	cout << "VM::deleteItem "<<ti<<endl;
 	if (ti)
 	{
 		TreeItem *pi=ti->parent();
@@ -2764,49 +2809,40 @@
 }
 
 
-void VymModel::followXLink(int i)	// FIXME-2
+void VymModel::followXLink(int i)	
 {
 	i=0;
-	/*
-	BranchObj *bo=getSelectedBranch();
-	if (bo)
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
 	{
-		bo=bo->XLinkTargetAt(i);
-		if (bo) 
-		{
-			selection.select(bo);
-			emitShowSelection();
-		}
+		selbi=selbi->getXLinkNum(i)->getPartnerBranch();
+		if (selbi) select (selbi);
 	}
-	*/
 }
 
-void VymModel::editXLink(int i)	// FIXME-2 VM missing saveState
+void VymModel::editXLink(int i)	
 {
 	i=0;
-	/*
-	BranchObj *bo=getSelectedBranch();
-	if (bo)
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
 	{
-		XLinkObj *xlo=bo->XLinkAt(i);
-		if (xlo) 
+		XLinkItem *xli=selbi->getXLinkNum(i);
+		if (xli) 
 		{
 			EditXLinkDialog dia;
-			dia.setXLink (xlo);
-			dia.setSelection(bo);
+			dia.setXLink (xli);
+			dia.setSelection(selbi);
 			if (dia.exec() == QDialog::Accepted)
 			{
 				if (dia.useSettingsGlobal() )
 				{
-					setMapDefXLinkColor (xlo->getColor() );
-					setMapDefXLinkWidth (xlo->getWidth() );
+					setMapDefXLinkColor (xli->getColor() );
+					setMapDefXLinkWidth (xli->getWidth() );
 				}
-				if (dia.deleteXLink())
-					bo->deleteXLinkAt(i);
+				if (dia.deleteXLink()) deleteItem (xli);
 			}
 		}	
 	}
-*/	
 }
 
 
diff -r d85834ad8c54 -r 133e2ed6b9c5 vymmodel.h
--- a/vymmodel.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/vymmodel.h	Thu Sep 03 08:52:00 2009 +0000
@@ -18,6 +18,7 @@
 class AttributeItem;
 class BranchItem;
 class MapEditor;
+class XLinkItem;
 
 class VymModel :  public TreeModel {		
 	Q_OBJECT
@@ -291,6 +292,7 @@
 	BranchItem* createMapCenter();				//!< Create MapCenter 
 	BranchItem* createBranch(BranchItem *dst);	//!< Create Branch
 	ImageItem* createImage(BranchItem *dst);	//!< Create image
+	XLinkItem* createXLink(BranchItem *dst,bool createMO=false);	//!< Create XLink starting at dst
 
 	AttributeItem* addAttribute();
 
@@ -338,7 +340,6 @@
 	void deleteKeepChildren();			//!< remove branch, but keep children
 	void deleteChildren();				//!< keep branch, but remove children
 
-private:	
 	TreeItem* deleteItem(TreeItem*);	//!< Delete item and return parent (if parent!= rootItem)
 	bool scrollBranch(BranchItem *);
 	bool unscrollBranch(BranchItem *);
diff -r d85834ad8c54 -r 133e2ed6b9c5 xlinkobj.cpp
--- a/xlinkobj.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/xlinkobj.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -1,31 +1,28 @@
 #include "xlinkobj.h"
+
 #include "branchobj.h"
+#include "branchitem.h"
+#include "xlinkitem.h"
 
+#include <iostream>
+using namespace std;
 
 /////////////////////////////////////////////////////////////////
 // XLinkObj
 /////////////////////////////////////////////////////////////////
 
-int XLinkObj::arrowSize=10;						// make instances 
+int XLinkObj::arrowSize=10;					// make instances
 
-XLinkObj::XLinkObj ():MapObj() 
+XLinkObj::XLinkObj (QGraphicsScene* scene, TreeItem* ti):MapObj(scene,ti)
 {
-	//	cout << "Const XLinkObj ()\n";
+	//cout << "Const XLinkObj (s)\n";
 	init();
 }
 
-XLinkObj::XLinkObj (QGraphicsScene* s):MapObj(s)
-{
-	//	cout << "Const XLinkObj (s)  called from MapCenterObj (s)\n";
-	init();
-}
-
 
 XLinkObj::~XLinkObj ()
 {
-//	cout << "Destr XLinkObj\n";
-	if (xLinkState!=undefinedXLink)
-		deactivate();
+	//cout << "Destr XLinkObj\n";
 	delete (line);
 	delete (poly);
 }
@@ -33,87 +30,17 @@
 
 void XLinkObj::init () 
 {
-	beginBranch=NULL;
-	endBranch=NULL;
+	XLinkItem *xli=(XLinkItem*)treeItem;
 	visBranch=NULL;
-	xLinkState=undefinedXLink;
 
-	color=QColor (180,180,180);
-	width=1;
-	pen.setColor (color);
-	pen.setWidth (width);
+	pen.setColor ( xli->getColor() );
+	pen.setWidth ( xli->getWidth() );
 	pen.setCapStyle (  Qt::RoundCap );
 	line=scene->addLine(QLineF(1,1,1,1),pen);
     line->setZValue (Z_XLINK);
-	poly=scene->addPolygon(QPolygonF(),pen,color);
+	poly=scene->addPolygon(QPolygonF(),pen, xli->getColor());
     poly->setZValue (Z_XLINK);
-	setVisibility (false);
-}
-
-void XLinkObj::copy (XLinkObj* other)
-{
-	// TODO copy not used yet
-	MapObj::copy (other);
-	setVisibility (other->visible);
-	beginBranch=other->beginBranch;
-	endBranch=other->endBranch;
-	width=other->width;
-
-}
-
-void XLinkObj::setBegin (BranchObj *bo)
-{
-	if (bo) 
-	{
-		xLinkState=initXLink;
-		beginBranch=bo;
-		beginPos=beginBranch->getChildPos();
-	}	
-}
-
-BranchObj* XLinkObj::getBegin ()
-{
-	return beginBranch;
-}
-
-void XLinkObj::setEnd (BranchObj *bo)
-{
-	if (bo) 
-	{
-		xLinkState=initXLink;
-		endBranch=bo;
-		endPos=endBranch->getChildPos();
-	}		
-}
-
-BranchObj* XLinkObj::getEnd()
-{
-	return endBranch;
-}
-
-void XLinkObj::setWidth (int w)
-{
-	width=w;
-	pen.setWidth (w);
-	setColor (color);
-}
-
-int XLinkObj::getWidth()
-{
-	return pen.width();
-}
-
-void XLinkObj::setColor(QColor c)
-{
-	color=c;
-	pen.setColor (c);
-	line->setPen (pen);
-	poly->setBrush( color );
-}
-
-QColor XLinkObj::getColor()
-{
-	return pen.color();
+	setVisibility (true);
 }
 
 void XLinkObj::setEnd (QPointF p)
@@ -121,41 +48,6 @@
 	endPos=p;
 }
 
-bool XLinkObj::activate ()
-{
-	if (beginBranch && endBranch)
-	{
-		if (beginBranch==endBranch) return false;
-		xLinkState=activeXLink;
-		beginBranch->addXLink (this);
-		endBranch->addXLink (this);
-		setVisibility ();
-		return true;
-	} else
-		return false;
-}
-
-void XLinkObj::deactivate ()
-{
-	if (beginBranch)
-		beginBranch->removeXLinkRef (this);
-	beginBranch=NULL;	
-	if (endBranch)
-		endBranch->removeXLinkRef (this);
-	endBranch=NULL;	
-	visBranch=NULL;
-	xLinkState=undefinedXLink;
-
-	line->hide();
-}
-
-bool XLinkObj::isUsed()
-{
-	if (beginBranch || endBranch || xLinkState!=undefinedXLink)
-		return true;
-	else
-		return false;
-}
 
 void XLinkObj::updateXLink()
 {
@@ -164,8 +56,11 @@
 	if (visBranch)
 	{
 		// Only one of the linked branches is visible
-		a=b=visBranch->getChildPos();
-		if (visBranch->getOrientation()==LinkableMapObj::RightOfCenter)
+		BranchObj *bo=(BranchObj*)(visBranch->getLMO());
+		if (!bo) return;
+
+		a=b=bo->getChildPos();
+		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
 		{
 			b.setX (b.x()+25);
 			
@@ -186,43 +81,43 @@
 	} else
 	{
 		// Both linked branches are visible
-		if (beginBranch)
+		BranchItem *bi=((XLinkItem*)treeItem)->getBegin();
+		if ( bi)
+		{
 			// If a link is just drawn in the editor,
 			// we have already a beginBranch
-			a=beginBranch->getChildPos();
+			BranchObj *bo=(BranchObj*)(bi->getLMO());
+			if (bo)	
+				a=bo->getChildPos();
+			else 
+				return;	
+		}	
 		else
 			// This shouldn't be reached normally...
 			a=beginPos;
-		if (xLinkState==activeXLink && endBranch)
-			b=endBranch->getChildPos();
+
+		// FIXME-3 try to get rid of xLinkstate if (xLinkState==activeXLink && endBranch)
+		bi=((XLinkItem*)treeItem)->getEnd();
+		if (bi)
+		{
+			BranchObj *bo=(BranchObj*)(bi->getLMO());
+			if (bo)	
+				b=bo->getChildPos();
+			else 
+				return;	
+		}
 		else
 			b=endPos;
 	}
 
-
-	if (line->line().p1()==a && line->line().p2()==b && !visBranch)
-	{
-		// update is called from both branches, so only
-		// update if something has changed
-		return;
-	}	
-	else
-	{
-		beginPos=a;
-		endPos=b;
-		line->setPen (pen);
-		line->setLine(a.x(), a.y(), b.x(), b.y());
-	}
-}
-
-BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
-{
-	if (!beginBranch && !endBranch)
-		return NULL;
-	if (thisBranch==beginBranch)
-		return endBranch;
-	else	
-		return beginBranch;
+	beginPos=a;
+	endPos=b;
+	XLinkItem *xli=(XLinkItem*)treeItem;
+	pen.setColor ( xli->getColor() );
+	pen.setWidth ( xli->getWidth() );
+	poly->setBrush (xli->getColor() );
+	line->setPen (pen);
+	line->setLine(a.x(), a.y(), b.x(), b.y());
 }
 
 void XLinkObj::positionBBox()
@@ -253,49 +148,36 @@
 
 void XLinkObj::setVisibility ()
 {
-	if (beginBranch && endBranch)
+	BranchItem* beginBI=((XLinkItem*)treeItem)->getBegin();
+	BranchObj* beginBO=NULL;
+	if (beginBI) beginBO=(BranchObj*)(beginBI->getLMO());
+
+	BranchObj* endBO=NULL;
+	BranchItem* endBI=((XLinkItem*)treeItem)->getEnd();
+	if (endBI) endBO=(BranchObj*)(endBI->getLMO());
+	if (beginBO && endBO)
 	{
-		if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
+		if(beginBO->isVisibleObj() && endBO->isVisibleObj())
 		{	// Both ends are visible
 			visBranch=NULL;
 			setVisibility (true);
 		} else
 		{
-			if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
+			if(!beginBO->isVisibleObj() && !endBO->isVisibleObj())
 			{	//None of the ends is visible
 				visBranch=NULL;
 				setVisibility (false);
 			} else
 			{	// Just one end is visible, draw a symbol that shows
 				// that there is a link to a scrolled branch
-				if (beginBranch->isVisibleObj())
-					visBranch=beginBranch;
+				if (beginBO->isVisibleObj())
+					visBranch=beginBI;
 				else
-					visBranch=endBranch;
+					visBranch=endBI;
 				setVisibility (true);
 			}
 		}
 	}
 }
 
-QString XLinkObj::saveToDir ()
-{
-	QString s="";
-	if (beginBranch && endBranch &&xLinkState==activeXLink)
-	{
-		if (beginBranch==endBranch && xLinkState)
-			s="";
-		else
-		{
-			QString colAttr=attribut ("color",color.name());
-			QString widAttr=attribut ("width",QString().setNum(width,10));
-			QString begSelAttr=attribut ("beginID",beginBranch->getSelectString());
-			QString endSelAttr=attribut ("endID",  endBranch->getSelectString());
-			s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
 
-			s+=endElement ("xlink");
-		}
-	}
-	return s;
-}
-
diff -r d85834ad8c54 -r 133e2ed6b9c5 xlinkobj.h
--- a/xlinkobj.h	Mon Aug 24 14:39:07 2009 +0000
+++ b/xlinkobj.h	Thu Sep 03 08:52:00 2009 +0000
@@ -1,55 +1,35 @@
 #ifndef XLINKOBJ_H
 #define XLINKOBJ_H
 
-#include "linkablemapobj.h"
+#include "mapobj.h"
 
 class BranchObj;
-
-enum XLinkState {undefinedXLink,initXLink,activeXLink,deleteXLink};
+class BranchItem;
 
 /*! \brief xlinks are used to draw arbitrary connections between branches (BranchObj) in the map. */
 
 /////////////////////////////////////////////////////////////////////////////
 class XLinkObj:public MapObj {
 public:
-    XLinkObj ();
-    XLinkObj (QGraphicsScene*);
+    XLinkObj (QGraphicsScene* scene, TreeItem* ti);
     ~XLinkObj ();
     virtual void init ();
-    virtual void copy (XLinkObj*);
-	void setBegin (BranchObj*);
-	BranchObj* getBegin();
-	void setEnd   (BranchObj*);
-	void setEnd   (QPointF);
-	BranchObj* getEnd();
-	void setColor(QColor);
-	QColor getColor();
-	void setWidth (int);
-	int getWidth ();
-	bool activate ();			// Sets pointers in branchObjects
-	void deactivate();			// removes those pointers
-	bool isUsed();				// true, if at least on branch uses it
+	virtual void setEnd (QPointF);
 	void updateXLink();
-	BranchObj* otherBranch (BranchObj*);
 	void positionBBox();
 	void calcBBoxSize();
 	void setVisibility (bool);
 	void setVisibility ();
-	QString saveToDir ();
 
 private:
 	static int arrowSize;
 	QPen pen;
-	QColor color;
-	int width;
 	QGraphicsLineItem *line;
 	QGraphicsPolygonItem *poly;
-	BranchObj *beginBranch;
-	BranchObj *endBranch;
-	BranchObj *visBranch;	// the "visible" part of a partially scrolled link
-	XLinkState xLinkState;	// init during drawing or active
 	QPointF beginPos;
 	QPointF   endPos;
+
+	BranchItem *visBranch;	// the "visible" part of a partially scrolled li
 };
 
 #endif
diff -r d85834ad8c54 -r 133e2ed6b9c5 xml-vym.cpp
--- a/xml-vym.cpp	Mon Aug 24 14:39:07 2009 +0000
+++ b/xml-vym.cpp	Thu Sep 03 08:52:00 2009 +0000
@@ -12,6 +12,7 @@
 #include "linkablemapobj.h"
 #include "mainwindow.h"
 #include "version.h"
+#include "xlinkitem.h"
 
 static ImageItem *lastImageItem;
 static MapItem *lastMI;
@@ -450,8 +451,8 @@
 					return false;   // Couldn't read absPos
 			}           
 		}           
-		//if (!a.value( "id").isEmpty() ) 
-		//	lastMI->setID (a.value ("id"));		// FIXME-3
+		if (!a.value( "id").isEmpty() ) 
+			lastMI->setID (a.value ("id"));		
 			
 		if (!a.value( "url").isEmpty() ) 
 			lastMI->setURL (a.value ("url"));
@@ -550,67 +551,39 @@
 	return true;
 }
 
-bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a)
+bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a)	
 {
-	QColor col;
-	bool okx;
-	bool success=false;
-	XLinkObj *xlo=new XLinkObj (model->getScene());
-	if (!a.value( "color").isEmpty() ) 
-	{
-		col.setNamedColor(a.value("color"));
-		xlo->setColor (col);
-	}
-
-	if (!a.value( "width").isEmpty() ) 
-	{
-		xlo->setWidth(a.value ("width").toInt (&okx, 10));
-	}
-
-	// Connecting by select string for compatibility with version < 1.8.76
-	if (!a.value( "beginBranch").isEmpty() ) 
-	{ 
-		if (!a.value( "endBranch").isEmpty() ) 
-		{
-			TreeItem *ti=model->findBySelectString (a.value( "beginBranch"));
-			if (ti && ti->isBranchLikeType())
-			{
-			/* FIXME-2 xLinks
-				xlo->setBegin ((BranchObj*)lmo);
-				lmo=model->findBySelectString (a.value( "endBranch"));
-				if (lmo && typid (*lmo)==typid (BranchObj))
-				{
-					xlo->setEnd ((BranchObj*)(lmo));
-					xlo->activate();
-					success=true;
-				}
-			*/
-			}
-		}           
-	}	
-
 	// object ID is used starting in version 1.8.76
-	/* FIXME-2 xLinks
+	// (before there was beginBranch and endBranch)
 	if (!a.value( "beginID").isEmpty() ) 
 	{ 
 		if (!a.value( "endID").isEmpty() ) 
 		{
-			LinkableMapObj *lmo=model->findID (a.value( "beginID"));
-			if (lmo && typid (*lmo)==typid (BranchObj))
+			TreeItem *beginBI=model->findID (a.value( "beginID"));
+			TreeItem   *endBI=model->findID (a.value( "endID"));
+			if (beginBI && endBI && beginBI->isBranchLikeType() && endBI->isBranchLikeType() )
 			{
-				xlo->setBegin ((BranchObj*)lmo);
-				lmo=model->findID (a.value( "endID"));
-				if (lmo && typid (*lmo)==typid (BranchObj))
+				XLinkItem *xli=model->createXLink (lastBranch,true);
+				xli->setBegin ( (BranchItem*)beginBI );
+				xli->setEnd ( (BranchItem*)endBI);
+				xli->activate();
+
+				if (!a.value( "color").isEmpty() ) 
 				{
-					xlo->setEnd ((BranchObj*)(lmo));
-					xlo->activate();
-					success=true;
+					QColor col;
+					col.setNamedColor(a.value("color"));
+					xli->setColor (col);
 				}
+
+				if (!a.value( "width").isEmpty() ) 
+				{
+					bool okx;
+					xli->setWidth(a.value ("width").toInt (&okx, 10));
+				}
+				xli->updateXLink();
 			}
 		}           
 	}	
-	*/
-	if (!success) delete (xlo);
 	return true;	// xLinks can only be established at the "end branch", return true
 }