# HG changeset patch
# User insilmaril
# Date 1252337817 0
# Node ID f1006de05c5453d4d6706c498ca17f6cb38f6cb5
# Parent  133e2ed6b9c5cdc61db86af5152e02d9c13bf315
Fixed several Model errors using ModelTest

diff -r 133e2ed6b9c5 -r f1006de05c54 branchitem.cpp
--- a/branchitem.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/branchitem.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -12,6 +12,8 @@
 {
 	//cout << "Constr. BranchItem\n";
 
+	// Set type if parent is known yet 
+	// if not, type is set in insertBranch or TreeItem::appendChild
 	if (parent==rootItem)
 		setType (MapCenter);
 	else
@@ -49,7 +51,13 @@
 	if (pos>branchCounter) pos=branchCounter;
     childItems.insert(pos+branchOffset,branch);
 	branch->parentItem=this;
+	branch->rootItem=rootItem;
 	branch->setModel (model);
+	if (parentItem==rootItem)
+		setType (MapCenter);
+	else
+		setType (Branch);
+
 
 	if (branchCounter==0)
 		branchOffset=childItems.count()-1;
@@ -425,7 +433,8 @@
 	{
 		newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
 		// Set visibility depending on parents
-		if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
+		if (parentItem!=rootItem && 
+			( ((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() ) )
 			newbo->setVisibility (false);
 	}
 	newbo->setDefAttr(BranchObj::NewBranch);
diff -r 133e2ed6b9c5 -r f1006de05c54 exports.cpp
--- a/exports.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/exports.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -106,11 +106,11 @@
 	return cancelFlag;
 }
 
-QString ExportBase::getSectionString(BranchObj *bostart)
+QString ExportBase::getSectionString(TreeItem *start)
 {
 	// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
 	QString r;
-	TreeItem *ti=bostart->getTreeItem();
+	TreeItem *ti=start;
 	int depth=ti->depth();
 	while (depth>0)
 	{
@@ -148,21 +148,18 @@
 	BranchItem *cur=NULL;
 	BranchItem *prev=NULL;
 
-	BranchObj *bo;	//FIXME-3 still needed?
 	cur=model->next (cur,prev);
 	while (cur) 
 	{
 		if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter)
 		{
-			bo=(BranchObj*)(cur->getLMO());
-			std::cout << "ExportASCII::  "<<cur->getHeading().toStdString()<<std::endl;
-
 			// Make indentstring
 			curIndent="";
 			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
 
 			if (!cur->hasHiddenExportParent() )
 			{
+				//std::cout << "ExportASCII::  "<<curIndent.toStdString()<<cur->getHeading().toStdString()<<std::endl;
 				switch (cur->depth())
 				{
 					case 0:
@@ -171,7 +168,7 @@
 						break;
 					case 1:
 						ts << "\n";
-						ts << (underline (getSectionString(bo) + cur->getHeading(), QString("-") ) );
+						ts << (underline (getSectionString(cur) + cur->getHeading(), QString("-") ) );
 						ts << "\n";
 						break;
 					case 2:
diff -r 133e2ed6b9c5 -r f1006de05c54 exports.h
--- a/exports.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/exports.h	Mon Sep 07 15:36:57 2009 +0000
@@ -29,7 +29,7 @@
 	virtual bool canceled();
 protected:  
 	VymModel *model;
-	virtual QString getSectionString (BranchObj*);
+	virtual QString getSectionString (TreeItem*);
 
 	QDir tmpDir;
 	QDir outDir;
diff -r 133e2ed6b9c5 -r f1006de05c54 imageitem.cpp
--- a/imageitem.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/imageitem.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -38,6 +38,12 @@
 	return imageType;
 }
 
+void ImageItem::load(const QPixmap &pm)
+{
+	pixmap=pm;
+	if (lmo) ((FloatImageObj*)lmo)->load (pixmap);
+}
+
 bool ImageItem::load(const QString &fname)
 {
 	bool ok=pixmap.load (fname);
diff -r 133e2ed6b9c5 -r f1006de05c54 imageitem.h
--- a/imageitem.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/imageitem.h	Mon Sep 07 15:36:57 2009 +0000
@@ -19,7 +19,7 @@
 	ImageItem();
 	ImageItem(const QList<QVariant> &data, TreeItem *parent = 0);
 
-	~ImageItem();
+	virtual ~ImageItem();
 
 protected:	
 	void init();
@@ -27,6 +27,7 @@
 public:	
 	virtual ImageType getImageType();
 
+	virtual void load (const QPixmap &pm);
 	virtual bool load (const QString &fname);
 	virtual FloatImageObj* createMapObj(QGraphicsScene *scene);		//! Create classic object in GraphicsView
 
diff -r 133e2ed6b9c5 -r f1006de05c54 linkablemapobj.cpp
--- a/linkablemapobj.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/linkablemapobj.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -32,6 +32,7 @@
 
 LinkableMapObj::~LinkableMapObj()
 {
+	//cout << "Destructor LMO\n";
     delete (bottomline);
 	delLink();
 }
diff -r 133e2ed6b9c5 -r f1006de05c54 linkablemapobj.h
--- a/linkablemapobj.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/linkablemapobj.h	Mon Sep 07 15:36:57 2009 +0000
@@ -16,8 +16,7 @@
 The links are connecting the branches (BranchObj) and images (FloatImageObj) in the map.
 */
 
-class LinkableMapObj:public QObject, public MapObj {
-	Q_OBJECT		// FIXME-3 really needed here?
+class LinkableMapObj:public MapObj {
 public:
 	/*! Orientation of an object depends on the position relative to the parent */
 	enum Orientation {
@@ -50,7 +49,7 @@
     LinkableMapObj ();
     LinkableMapObj (QGraphicsScene*, TreeItem *ti=NULL);
     LinkableMapObj (LinkableMapObj*);
-    ~LinkableMapObj ();
+    virtual ~LinkableMapObj ();
 	virtual void delLink();
     virtual void init ();
     virtual void copy (LinkableMapObj*);
diff -r 133e2ed6b9c5 -r f1006de05c54 mainwindow.cpp
--- a/mainwindow.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/mainwindow.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -23,6 +23,8 @@
 #include "warningdialog.h"
 #include "xlinkitem.h"
 
+#include <modeltest.h>	// FIXME-3
+
 #if defined(Q_OS_WIN32)
 // Define only this structure as opposed to
 // including full 'windows.h'. FindWindow
@@ -1707,13 +1709,18 @@
 {
 	VymModel *vm=new VymModel;
 
+new ModelTest(vm, this);	//FIXME-3
+
+
 	VymView *vv=new VymView (vm);
 	vymViews.append (vv);
 	tabWidget->addTab (vv,tr("unnamed","MainWindow: name for new and empty file"));
 	tabWidget->setCurrentIndex (vymViews.count() );
 	vv->initFocus();
 
-	
+	// Create MapCenter for empty map
+	//vm->createMapCenter();
+
 	// For the very first map we do not have flagrows yet...
 	vm->select("mc:");
 }
@@ -2797,6 +2804,7 @@
 			|| actionSettingsAutoEditNewBranch->isOn()) 
 		{
 			m->select (bi);
+			cout << "Main::editNewBranch  prevSel="<<prevSelection.toStdString()<<endl;
 			if (actionSettingsAutoEditNewBranch->isOn())
 				currentMapEditor()->editHeading();
 		}
diff -r 133e2ed6b9c5 -r f1006de05c54 mapeditor.cpp
--- a/mapeditor.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/mapeditor.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -520,7 +520,7 @@
 	 animation->start();
  */
 
-/* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere
+/* FIXME-4 Hide hidden stuff temporary, maybe add this as regular function somewhere
 	if (hidemode==HideNone)
 	{
 		setHideTmpMode (HideExport);
@@ -809,21 +809,18 @@
 		if (model->getSelectedBranchObj() ) 
 		{
 			// Context Menu on branch or mapcenter
-			//FIXME-3 model->updateActions(); needed?
 			branchContextMenu->popup(e->globalPos() );
 		} else
 		{
 			if (model->getSelectedImage() )
 			{
 				// Context Menu on floatimage
-				// model->updateActions(); FIXME-3 needed?
 				floatimageContextMenu->popup(e->globalPos() );
 			}	
 		}	
 	} else 
 	{ // No MapObj found, we are on the Canvas itself
 		// Context Menu on scene
-		// model->updateActions(); FIXME-3 needed?
 		
 		// Open context menu synchronously to position new mapcenter
 		model->setContextPos (p);
diff -r 133e2ed6b9c5 -r f1006de05c54 mapitem.h
--- a/mapitem.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/mapitem.h	Mon Sep 07 15:36:57 2009 +0000
@@ -3,7 +3,6 @@
 
 #include <QPointF>
 
-//#include "xmlobj.h"
 #include "treeitem.h"
 
 class LinkableMapObj;
@@ -12,7 +11,7 @@
    classes.
  
 	This is done even while no QGraphicsView is availabe. This is useful
-	if e.g. on a small device like a cellphone te full map is not used,
+	if e.g. on a small device like a cellphone the full map is not used,
 	but just a treeview instead.
 */
 
diff -r 133e2ed6b9c5 -r f1006de05c54 ornamentedobj.h
--- a/ornamentedobj.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/ornamentedobj.h	Mon Sep 07 15:36:57 2009 +0000
@@ -23,7 +23,7 @@
 public:	
     OrnamentedObj (QGraphicsScene*, TreeItem *ti=NULL);
     OrnamentedObj (OrnamentedObj*);
-    ~OrnamentedObj ();
+    virtual ~OrnamentedObj ();
     virtual void init ();
     virtual void copy (OrnamentedObj*);
 
diff -r 133e2ed6b9c5 -r f1006de05c54 treeeditor.cpp
--- a/treeeditor.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/treeeditor.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -18,7 +18,7 @@
 	model=m;
 
 /*
-//	MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel(this);	// FIXME-0 trying to use proxy...
+//	MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel(this);	// FIXME-1 trying to use proxy...
 	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
 
 	proxyModel->setSourceModel(model);
diff -r 133e2ed6b9c5 -r f1006de05c54 treeitem.cpp
--- a/treeitem.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/treeitem.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -15,7 +15,7 @@
 
 TreeItem::TreeItem()
 {
-	//cout << "Constr. TI  this="<<this<<endl;
+	cout << "Constr. TI  this="<<this<<endl;
 	init();
 	itemData.clear();
 	rootItem=this;
@@ -41,27 +41,7 @@
 	while (!childItems.isEmpty())
 	{
 		ti=childItems.takeFirst();
-		switch (ti->getType() )
-		{
-			case TreeItem::MapCenter:
-				delete (BranchItem*)ti;
-				break;
-			case TreeItem::Branch:
-				delete (BranchItem*)ti;
-				break;
-			case TreeItem::Image:
-				delete (ImageItem*)ti;
-				break;
-			case TreeItem::Attribute:
-				delete (AttributeItem*)ti;
-				break;
-			case TreeItem::XLink:
-				delete (XLinkItem*)ti;
-				break;
-			default:
-				delete ti;
-				break;
-		}
+		delete ti;
 	}	
 }
 
@@ -96,17 +76,6 @@
 }
 
 
-/*
-void TreeItem::copy (OrnamentedObj* other)	//FIXME-3	probably need deep copy of branches and data!
-
-{
-	note.copy (other->note);
-	model=other->model;
-	hideExport=officially 
-	other->hideExport;
-}
-*/
-
 void TreeItem::setModel (VymModel *m)
 {
 	model=m;
@@ -238,7 +207,7 @@
 
 int TreeItem::columnCount() const
 {
-    return itemData.count();
+	return 1;
 }
 
 int TreeItem::branchCount() const
@@ -270,11 +239,6 @@
     return 0;
 }
 
-int TreeItem::column() const
-{
-    return 0;
-}
-
 int TreeItem::depth() 
 {
 	// Rootitem d=-1
@@ -291,6 +255,7 @@
 
 TreeItem *TreeItem::parent()
 {
+	//cout << "TI::parent of "<<getHeadingStd()<<"  is "<<parentItem<<endl;
     return parentItem;
 }
 
@@ -301,15 +266,8 @@
 
 int TreeItem::num()
 {
-	switch (type)
-	{
-		case MapCenter: return parentItem->childItems.indexOf (this) - parentItem->branchOffset;
-		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;
-	}
+	if (!parentItem) return -1;
+	return parentItem->num (this);
 }
 
 int TreeItem::num (TreeItem *item)
@@ -334,7 +292,7 @@
 
 TreeItem::Type TreeItem::getType()
 {
-	if (type==Branch && depth()==0) return MapCenter;	//FIXME-2 should not be necesssary
+	if (type==Branch && depth()==0) return MapCenter;	//FIXME-3 should not be necesssary
 	return type;
 }
 
@@ -439,7 +397,7 @@
 {
 	NoteObj n;
 	n.setNote(s);
-	setNoteObj (n,false);
+	setNoteObj (n);
 }
 
 void TreeItem::clearNote()
@@ -448,7 +406,7 @@
 	systemFlags.deactivate ("system-note");
 }
 
-void TreeItem::setNoteObj(const NoteObj &n, bool updateNoteEditor){
+void TreeItem::setNoteObj(const NoteObj &n){
 	note=n;
 	if (!note.isEmpty() && !systemFlags.isActive ("system-note"))
 		systemFlags.activate ("system-note");
@@ -525,11 +483,6 @@
 	return &standardFlags;
 }
 
-/* FIXME-3 void TreeItem::updateToolBar()
-{
-	standardFlags.updateToolBar();
-}
-*/
 QStringList TreeItem::activeSystemFlagNames ()
 {
 	return systemFlags.activeFlagNames();
@@ -676,49 +629,45 @@
 }
 
 
-void TreeItem::setHideTmp (HideTmpMode mode)  //FIXME-2
+void TreeItem::setHideTmp (HideTmpMode mode)  //FIXME-2	update visibility in derived objects...
 {
-	if (isBranchLikeType() )
-		((BranchItem*)this)->updateVisibility();
 		/*
 	if (type==Image)
-		//updateVisibility();
-	*/
-
-/*
+		((ImageItem*)this)->updateVisibility();
+		*/
 
 		if (mode==HideExport && (hideExport || hasHiddenExportParent() ) )
 		{
 			// Hide stuff according to hideExport flag and parents
-			//setVisibility (false);
-			updateVisibility();
-			//FIXME-2 hidden=true;
+	//		if (lmo) lmo->setVisibility (false);
+			hidden=true;
 		}else
 		{
 			// Do not hide, but still take care of scrolled status
-			
-
+			hidden=false;
+/*
 			XXXXXXXX treeItem should be THIS
 
 			move visible to TreeItem???
 
 			BranchObj now has updateContents
-
-			maybe also start "bool TreeItem::branchlikeType"
-
-
+*/
+/*
+		if (isBranchLikeType() )
+			((BranchItem*)this)->updateVisibility();
 
 			if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
 				setVisibility (false);
 			else
 				setVisibility (true);
-			//FIXME-2 hidden=false;
+*/			
 		}	
 
-*/
+/*
 		// And take care of my children
 		for (int i=0; i<branchCount(); ++i)
-			getBranchNum(i)->setHideTmp (mode);
+			getBranchNum(i)->setHideTmp (mode);	// FIXME-4 maybe also consider images and other types
+*/
 }
 
 bool TreeItem::hasHiddenExportParent()
@@ -752,6 +701,11 @@
 	return hideExport;
 }	
 
+void TreeItem::updateVisibility()
+{
+	// overloaded in derived objects
+}	
+
 bool TreeItem::isHidden()
 {
 	return hidden;
diff -r 133e2ed6b9c5 -r f1006de05c54 treeitem.h
--- a/treeitem.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/treeitem.h	Mon Sep 07 15:36:57 2009 +0000
@@ -26,7 +26,7 @@
 
     TreeItem();
     TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
-    ~TreeItem();
+    virtual ~TreeItem();
 	void init();
 
 	// General housekeeping
@@ -52,7 +52,6 @@
 	virtual int attributeCount() const;
 
     virtual int row() const;
-	virtual int column() const;
 	virtual int depth() ;
     virtual TreeItem *parent();
 
@@ -105,7 +104,7 @@
 	virtual void clearNote();
 	virtual QString getNote();
 	virtual bool hasEmptyNote();
-	virtual void setNoteObj(const NoteObj &, bool updateNoteEditor=true); //FIXME-1 setNoteObj is called for every select or so???
+	virtual void setNoteObj(const NoteObj &); //FIXME-3 setNoteObj is called for every select or so???
 
 	virtual NoteObj getNoteObj();			
 	virtual QString getNoteASCII(const QString &indent, const int &width); // returns note	(ASCII)
@@ -160,13 +159,15 @@
 	virtual XLinkObj* getXLinkObjNum(const int &n);
 
 protected:
-	bool hideExport;							//! Hide this item in export
+	bool hideExport;						//! Hide this item in export
+	bool hidden;							//! Hidden in export if true
 public:
 	virtual void setHideTmp (HideTmpMode);
 	virtual bool hasHiddenExportParent ();
 	virtual void setHideInExport(bool);		// set export of object (and children)
 	virtual bool hideInExport();
 	virtual bool isHidden ();		
+	virtual void updateVisibility();		//! Sets visibility in LinkableMapObj, if existing
 
 	virtual QString getGeneralAttr();
 	
@@ -192,7 +193,6 @@
 	int xlinkOffset;
 	int xlinkCounter;
 
-	bool hidden;	//! Hidden in export if true
 };
 
 #endif
diff -r 133e2ed6b9c5 -r f1006de05c54 treemodel.cpp
--- a/treemodel.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/treemodel.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -15,7 +15,7 @@
 {
     QList<QVariant> rootData;
     rootData << "Heading" << "Type";
-    rootItem = new TreeItem(rootData);
+    rootItem = new BranchItem(rootData);
 }
 
 TreeModel::~TreeModel()
@@ -39,7 +39,7 @@
 Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
 {
     if (!index.isValid())
-        return Qt::ItemIsEnabled;
+        return Qt::NoItemFlags;
 
     return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
 }
@@ -58,23 +58,26 @@
 	if (!ti->parent())
 		return QModelIndex();
 	else	
-		return createIndex (ti->row(),ti->column(),ti);
+		return createIndex (ti->row(),0,ti);
 }
 
 QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
             const
 {
+	// Make sure to return invalid index for invalid values (see modeltest)
+	if (row<0 || column<0) return QModelIndex();
+	if (column!=0) return QModelIndex();
+
     TreeItem *parentItem;
 
     if (!parent.isValid())
-	{	//FIXME-3 left here for testing only, seems to work now...
+	{
         parentItem = rootItem;
 		/*
 		cout << "TM::index()  no parent?! xxx\n";
 		cout << "   row="<<row<<"  col="<<column<<endl;
 		cout << "   parent.internal="<< parent.internalPointer()<<endl;
 		*/
-		//return QModelIndex();	//FIXME-3 this line is new (testing)
 		// Somehow index is requested where parentIndex is invalid.
 		// what's happening here...?
 		// Check if Qt examples also return index of rootIem then...
@@ -84,6 +87,7 @@
         parentItem = getItem (parent);
 
     TreeItem *childItem = parentItem->child(row);
+	//cout << "TM::index  parentItem="<<parentItem<<"  childItem="<<childItem<<"  row="<<row<<" col="<<column<<endl;
     if (childItem)
         return createIndex(row, column, childItem);
     else
@@ -106,10 +110,11 @@
     if (parentItem == rootItem)
         return QModelIndex();
 
+/*
 	if (!parentItem)
         return QModelIndex();	// FIXME-3 do this to avoid segfault, but why?
 		                        // see also my question on qt-interest in march
-
+*/
     return createIndex(parentItem->childNumber(), 0, parentItem);
 }
 
@@ -127,13 +132,21 @@
 
 int TreeModel::columnCount(const QModelIndex &parent) const
 {
+	int c;
     if (parent.isValid())
-        return getItem (parent)->columnCount();
+	{
+        c= getItem (parent)->columnCount();
+		//cout << "TM::colCount  c="<<c<<"  parent="<<getItem (parent)<<endl;	
+	}
     else
-        return rootItem->columnCount();
+	{
+        c= rootItem->columnCount();
+		//cout << "TM::colCount  c="<<c<<"  parent=invalid"<<endl;	
+	}
+	return c;
 }
 
-BranchItem* TreeModel::next(BranchItem* &current, BranchItem* &previous, BranchItem* start)
+BranchItem* TreeModel::next(BranchItem* &current, BranchItem* &previous, BranchItem* start)	// FIXME-3 change this to nextBranch and use "next" for all TIs
 {
 /*FIXME-3	cout << "TM::next \n"; 
 	std::string ch="()"; if (current) ch=current->getHeadingStd();
@@ -224,6 +237,8 @@
 		ti=pi->getChildNum (row);
 		cout << "   pi="<<pi<<"  ti="<<ti<<endl;
 		pi->removeChild (row);	// does not delete object!
+		delete ti;
+		/* FIXME-3
 		switch (ti->getType()) 
 		{
 			case TreeItem::MapCenter: 
@@ -245,6 +260,7 @@
 				delete ti;
 				break;
 		}
+		*/
 	}
 	return true;
 }
@@ -258,7 +274,7 @@
 //		cout << "   item="<<item<<endl;
         if (item) return item;
     }
-    return rootItem;
+    return NULL;
 }
 
 TreeItem *TreeModel::getRootItem()
diff -r 133e2ed6b9c5 -r f1006de05c54 version.h
--- a/version.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/version.h	Mon Sep 07 15:36:57 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-09-01"
+#define __VYM_BUILD_DATE "2009-09-07"
 
 
 bool checkVersion(const QString &);
diff -r 133e2ed6b9c5 -r f1006de05c54 vym.pro
--- a/vym.pro	Thu Sep 03 08:52:00 2009 +0000
+++ b/vym.pro	Mon Sep 07 15:36:57 2009 +0000
@@ -215,3 +215,4 @@
 INSTALLS += doc
 DEFINES += VYM_DOCDIR=\\\"$${DOCDIR}\\\"
 
+include(test/modeltest/modeltest.pri)
diff -r 133e2ed6b9c5 -r f1006de05c54 vymmodel.cpp
--- a/vymmodel.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/vymmodel.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -77,9 +77,6 @@
 
 void VymModel::init () 
 {
-	// We should have at least one map center to start with
-	// addMapCenter();  FIXME-2 VM create this in MapEditor as long as model is part of that
-
 	// No MapEditor yet
 	mapEditor=NULL;
 
@@ -844,11 +841,11 @@
 }
 
 
-void VymModel::importDirInt(BranchObj *dst, QDir d)
-{
-/* FIXME-2 importDirInt not ported yet
-	BranchObj *bo=getSelectedBranch();
-	if (bo)
+void VymModel::importDirInt(BranchItem *dst, QDir d)
+{
+	BranchItem *selbi=getSelectedBranch();
+	BranchItem *bi;
+	if (selbi)
 	{
 		// Traverse directories
 		d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
@@ -860,18 +857,16 @@
 			fi=list.at(i);
 			if (fi.fileName() != "." && fi.fileName() != ".." )
 			{
-				dst->addBranch();
-				bo=dst->getLastBranch();
-				BranchItem *bi=(BranchItem*)(bo->getTreeItem());
+				bi=addNewBranchInt(dst,-2);
 				bi->setHeading (fi.fileName() );	// FIXME-3 check this
-				bo->setColor (QColor("blue"));
+				bi->setHeadingColor (QColor("blue"));
 				bi->toggleScroll();
 				if ( !d.cd(fi.fileName()) ) 
 					QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
 				else 
 				{
 					// Recursively add subdirs
-					importDirInt (bo,d);
+					importDirInt (bi,d);
 					d.cdUp();
 				}
 			}	
@@ -883,36 +878,31 @@
 		for (int i = 0; i < list.size(); ++i) 
 		{
 			fi=list.at(i);
-			dst->addBranch();
-			bo=dst->getLastBranch();
-			bo->setHeading (fi.fileName() );
-			bo->setColor (QColor("black"));
+			bi=addNewBranchInt (dst,-2);
+			bi->setHeading (fi.fileName() );
+			bi->setHeadingColor (QColor("black"));
 			if (fi.fileName().right(4) == ".vym" )
-				bo->setVymLink (fi.filePath());
+				bi->setVymLink (fi.filePath());
 		}	
 	}		
-*/
 }
 
-void VymModel::importDirInt (const QString &s)	// FIXME-2
-{
-/*
-	BranchObj *bo=getSelectedBranch();
-	if (bo)
+void VymModel::importDirInt (const QString &s)	
+{
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
 	{
-		saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
+		saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
 
 		QDir d(s);
-		importDirInt (bo,d);
+		importDirInt (selbi,d);
 	}
-*/	
 }	
 
-void VymModel::importDir()	//FIXME-2
-{
-/*
-	BranchObj *bo=getSelectedBranch();
-	if (bo)
+void VymModel::importDir()	//FIXME-3 check me... (not tested yet)
+{
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
 	{
 		QStringList filters;
 		filters <<"VYM map (*.vym)";
@@ -930,7 +920,6 @@
 			//FIXME-3 VM needed? scene()->update();
 		}
 	}	
-*/
 }
 
 
@@ -1435,11 +1424,12 @@
 		parts.removeFirst();
 		if (typ=="mc" || typ=="bo")
 			ti=ti->getBranchNum (n);
-			/* FIXME-2
+			/* FIXME-2		add other types to getSelectionString and findBy...
 		else
 			if (typ="fi")
 				ti=ti->getImageNum (n);
 				*/
+		if(!ti) return NULL;		
 	}
 	return  ti;
 }
@@ -1923,7 +1913,7 @@
 	}
 }
 
-void VymModel::moveUp()	
+void VymModel::moveUp()	//FIXME-2 crashes if trying to move MCO
 {
 	BranchItem *selbi=getSelectedBranch();
 	if (selbi)
@@ -1996,8 +1986,9 @@
 		emit (layoutAboutToBeChanged() );
 
 			parix=index(dst);
+			if (!parix.isValid()) cout << "VM::createII invalid index\n";
 			n=dst->getRowNumAppend(newii);
-			beginInsertRows (parix,n,n+1);
+			beginInsertRows (parix,n,n);
 			dst->appendChild (newii);	
 			endInsertRows ();
 
@@ -2023,12 +2014,13 @@
 		cData << "new xLink"<<"undef";
 
 		XLinkItem *newxli=new XLinkItem(cData) ;	
+		newxli->setBegin (bi);
 
 		emit (layoutAboutToBeChanged() );
 
 			parix=index(bi);
 			n=bi->getRowNumAppend(newxli);
-			beginInsertRows (parix,n,n+1);
+			beginInsertRows (parix,n,n);
 			bi->appendChild (newxli);	
 			endInsertRows ();
 
@@ -2036,7 +2028,6 @@
 
 		// save scroll state. If scrolled, automatically select
 		// new branch in order to tmp unscroll parent...
-		newxli->setBegin (bi);
 		if (createMO) 
 		{
 			newxli->createMapObj(mapScene);
@@ -2060,7 +2051,7 @@
 
 		QModelIndex parix=index(selbi);
 		int n=selbi->getRowNumAppend (a);
-		beginInsertRows (parix,n,n+1);	
+		beginInsertRows (parix,n,n);	
 		selbi->appendChild (a);	
 		endInsertRows ();
 
@@ -2087,22 +2078,22 @@
 	return bi;	
 }
 
-BranchItem* VymModel::addMapCenter(QPointF absPos)	//FIXME-2 absPos not used in context menu?!
+BranchItem* VymModel::addMapCenter(QPointF absPos)	
 // createMapCenter could then probably be merged with createBranch
 {
 
 	// Create TreeItem
 	QModelIndex parix=index(rootItem);
 
-	int n=rootItem->branchCount();
-
-	emit (layoutAboutToBeChanged() );
-	beginInsertRows (parix,n,n+1);
-
 	QList<QVariant> cData;
 	cData << "VM:addMapCenter" << "undef";
 	BranchItem *newbi=new BranchItem (cData,rootItem);
 	newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
+	int n=rootItem->getRowNumAppend (newbi);
+
+	emit (layoutAboutToBeChanged() );
+	beginInsertRows (parix,n,n);
+
 	rootItem->appendChild (newbi);
 
 	endInsertRows();
@@ -2110,12 +2101,13 @@
 
 	// Create MapObj
 	newbi->setPositionMode (MapItem::Absolute);
-	newbi->createMapObj(mapScene);
+	BranchObj *bo=newbi->createMapObj(mapScene);
+	if (bo) bo->move (absPos);
 		
 	return newbi;
 }
 
-BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)	
+BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
 {
 	// Depending on pos:
 	// -3		insert in children of parent  above selection 
@@ -2140,7 +2132,7 @@
 		parbi=dst;
 		parix=index(parbi);
 		n=parbi->getRowNumAppend (newbi);
-		beginInsertRows (parix,n,n+1);	
+		beginInsertRows (parix,n,n);	
 		parbi->appendChild (newbi);	
 		endInsertRows ();
 	}else if (num==-1 || num==-3)
@@ -2350,7 +2342,7 @@
 				QString("Delete %1").arg(getObjectName(ti))
 			);
 		}
-		// FIXME-0 savestate missing for deletion of other times
+		// FIXME-1 savestate missing for deletion of other types than above
 		unselect();
 		deleteItem (ti);
 		emitDataHasChanged (pi);
@@ -2576,22 +2568,20 @@
 	}
 }
 
-void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
-{
-/*
-	BranchObj *bo=getSelectedBranch();
-	if (bo)
-  {
-	FloatImageObj *fio=bo->addFloatImage();
-    fio->load(img);
-    fio->setOriginalFilename("No original filename (image added by dropevent)");	
-	QString s=getSelectString(bo);
-	saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio  );
-	saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
-    reposition();
-    // FIXME-3 VM needed? scene()->update();
-  }
-*/
+void VymModel::addFloatImage (const QPixmap &img) 
+{
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
+	{
+		ImageItem *ii=createImage (selbi);
+		ii->load(img);
+		ii->setOriginalFilename("No original filename (image added by dropevent)");	
+		QString s=getSelectString(selbi);
+		saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii  );
+		saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
+		reposition();
+		// FIXME-3 VM needed? scene()->update();
+	}
 }
 
 
@@ -3815,7 +3805,6 @@
 
 void VymModel::exportImage(QString fname, bool askName, QString format)
 {
-/* FIXME-2 export as image, but directly from mapEditor?!
 	if (fname=="")
 	{
 		fname=getMapName()+".png";
@@ -3842,7 +3831,6 @@
 	QPixmap pix (mapEditor->getPixmap());
 	pix.save(fname, format);
 	setExportMode (false);
-*/	
 }
 
 
@@ -4596,23 +4584,6 @@
 	mapEditor->setSelectionColor (col);
 }
 
-/*
-void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
-{
-	cout << "VymModel::changeSelection (";
-	if (!newsel.indexes().isEmpty() )
-		cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
-	cout << ",";
-	if (!oldsel.indexes().isEmpty() )
-		cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
-	cout << ")\n";
-}
-*/
-
-void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel)	//FIXME-4 connected but not used so far
-{
-}
-
 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
 {
 	emit (selectionChanged(newsel,newsel));	// needed e.g. to update geometry in editor
@@ -4914,13 +4885,13 @@
 	return getSelectString (getSelectedItem());
 }
 
-QString VymModel::getSelectString (LinkableMapObj *lmo)	// FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
+QString VymModel::getSelectString (LinkableMapObj *lmo)	// only for convenience. Used in MapEditor
 {
 	if (!lmo) return QString();
 	return getSelectString (lmo->getTreeItem() );
 }
 
-QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
+QString VymModel::getSelectString (TreeItem *ti) 
 {
 	QString s;
 	if (!ti) return s;
diff -r 133e2ed6b9c5 -r f1006de05c54 vymmodel.h
--- a/vymmodel.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/vymmodel.h	Mon Sep 07 15:36:57 2009 +0000
@@ -122,7 +122,7 @@
 	void saveFloatImage ();
 
 private:	
-    void importDirInt(BranchObj *,QDir);
+    void importDirInt(BranchItem *,QDir);
     void importDirInt(const QString&);
 public:	
     void importDir();
@@ -598,9 +598,6 @@
 signals:
 	void selectionChanged(const QItemSelection &newsel, const QItemSelection &oldsel);
 
-public slots:
-	void updateSelection (const QItemSelection &newSel, const QItemSelection &delSel);
-
 public:
 	void emitSelectionChanged(const QItemSelection &oldsel);
 	void emitSelectionChanged();
diff -r 133e2ed6b9c5 -r f1006de05c54 vymview.cpp
--- a/vymview.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/vymview.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -37,10 +37,6 @@
 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
 
 	connect (
-		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
-		model,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
-
-	connect (
 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
 
diff -r 133e2ed6b9c5 -r f1006de05c54 xlinkobj.h
--- a/xlinkobj.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/xlinkobj.h	Mon Sep 07 15:36:57 2009 +0000
@@ -12,7 +12,7 @@
 class XLinkObj:public MapObj {
 public:
     XLinkObj (QGraphicsScene* scene, TreeItem* ti);
-    ~XLinkObj ();
+    virtual ~XLinkObj ();
     virtual void init ();
 	virtual void setEnd (QPointF);
 	void updateXLink();
diff -r 133e2ed6b9c5 -r f1006de05c54 xmlobj.cpp
--- a/xmlobj.cpp	Thu Sep 03 08:52:00 2009 +0000
+++ b/xmlobj.cpp	Mon Sep 07 15:36:57 2009 +0000
@@ -28,6 +28,10 @@
     indentwidth=4;
 }
 
+XMLObj::~XMLObj()
+{
+}
+
 
 // returns <s at />
 QString XMLObj::singleElement(QString s, QString at)
diff -r 133e2ed6b9c5 -r f1006de05c54 xmlobj.h
--- a/xmlobj.h	Thu Sep 03 08:52:00 2009 +0000
+++ b/xmlobj.h	Mon Sep 07 15:36:57 2009 +0000
@@ -10,6 +10,7 @@
 {
 public:
     XMLObj();
+	virtual ~XMLObj();
     QString singleElement(QString,QString);			// name,attr
     QString beginElement(QString,QString);			// name,attr
     QString beginElement(QString);					// name