# HG changeset patch
# User insilmaril
# Date 1250599147 0
# Node ID 78ba80b54bc4ced34f0acc7909bf1c1d46c06754
# Parent  c6bb4fdcc55fd582c887c67a98f1ad08821dcf25
Fix for segfault when deleting MCO (invalid QModelIndex needs to be returned in index(TreeItem*) )

diff -r c6bb4fdcc55f -r 78ba80b54bc4 branchitem.cpp
--- a/branchitem.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/branchitem.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -11,9 +11,13 @@
 {
 	//cout << "Constr. BranchItem\n";
 
+	if (parent==rootItem)
+		setType (MapCenter);
+	else
+		setType (Branch);
+
 	scrolled=false;
 	tmpUnscrolled=false;
-	type=Branch;
 
 	includeImagesVer=false;
 	includeImagesHor=false;
@@ -24,7 +28,7 @@
 
 BranchItem::~BranchItem()
 {
-	cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
+	//cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
 	if (lmo) 
 	{
 		delete lmo;
diff -r c6bb4fdcc55f -r 78ba80b54bc4 branchobj.cpp
--- a/branchobj.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/branchobj.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -598,7 +598,7 @@
 	calcBBoxSize();
 }
 
-void BranchObj::sortChildren() //FIXME-2  
+void BranchObj::sortChildren() //FIXME-3 not moved to model yet 
 {
 /*
 	int childCount=branch.count(); 
diff -r c6bb4fdcc55f -r 78ba80b54bc4 imageitem.cpp
--- a/imageitem.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/imageitem.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -7,8 +7,6 @@
 #include <iostream>
 using namespace std;
 
-uint ImageItem::saveCounter=0;		// create instance 
-
 ImageItem::ImageItem()
 {
 	init();
@@ -27,7 +25,7 @@
 
 void ImageItem::init()
 {
-	type=Image;
+	setType (Image);
 	imageType=Undefined;
 	hideLinkUnselected=true;
 	originalFilename="no original name available";
@@ -87,11 +85,6 @@
 	return originalFilename;
 }
 
-void ImageItem::resetSaveCounter()
-{
-	saveCounter=0;
-}
-
 void ImageItem::save(const QString &fn, const QString &format)
 {
 	pixmap.save (fn,qPrintable (format));
@@ -101,13 +94,12 @@
 {
 	if (hidden) return "";
 
-	saveCounter++;
-	
-	
 	QString zAttr=attribut ("zValue",QString().setNum(zValue));
 	QString url;
 
-	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + ".png" ;
+	ulong n=reinterpret_cast <ulong> (this);
+
+	url="images/"+prefix+"image-" + QString().number(n,10) + ".png" ;
 
 	// And really save the image
 	pixmap.save (tmpdir +"/"+ url, "PNG");
diff -r c6bb4fdcc55f -r 78ba80b54bc4 imageitem.h
--- a/imageitem.h	Sat Aug 08 21:58:26 2009 +0000
+++ b/imageitem.h	Tue Aug 18 12:39:07 2009 +0000
@@ -33,14 +33,12 @@
 protected:	
 	QPixmap pixmap;
 	QString originalFilename;
-	static uint saveCounter;	// numerate the files during saveToDir
 	int zValue;
 
 public:	
 	virtual void setZValue(int z);
 	virtual void setOriginalFilename(const QString &);
 	virtual QString getOriginalFilename();
-	virtual void resetSaveCounter();
 	virtual void save (const QString &fn, const QString &format);
 	virtual QString saveToDir(const QString &,const QString&);
 
diff -r c6bb4fdcc55f -r 78ba80b54bc4 mainwindow.cpp
--- a/mainwindow.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/mainwindow.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -3359,7 +3359,7 @@
 	if (m && m->hasChanged() )
 		actionFileSave->setEnabled( true);
 	else	
-		actionFileSave->setEnabled( true);
+		actionFileSave->setEnabled( false);
 	if (m && m->isUndoAvailable())
 		actionUndo->setEnabled( true);
 	else	
@@ -3376,7 +3376,13 @@
 		BranchItem *selbi=m->getSelectedBranch();
 		if (selti)
 		{
-			if (selbi)
+			if (selbi || selti->getType()==TreeItem::Image)
+			{
+				actionFormatHideLinkUnselected->setOn (((MapItem*)selti)->getHideLinkUnselected());
+				actionFormatHideLinkUnselected->setEnabled (true);
+			}
+
+			if (selbi)	// FIXME-4 many properties of former BranchObj are in TreeItem meanwhile...
 			{
 				// Take care of links  // updateActions: FIXME-1
 				/*
@@ -3448,7 +3454,6 @@
 				actionToggleHideExport->setEnabled (true);	
 				actionToggleHideExport->setOn (selbi->hideInExport() );	
 
-				actionFileSave->setEnabled (true);	
 				actionCopy->setEnabled (true);	
 				actionCut->setEnabled (true);	
 				if (!clipboardEmpty)
@@ -3458,8 +3463,7 @@
 				for (int i=0; i<actionListBranches.size(); ++i)	
 					actionListBranches.at(i)->setEnabled(true);
 				actionDelete->setEnabled (true);
-				//FIXME-2 actionFormatHideLinkUnselected->setOn (selection->getHideLinkUnselected());
-			}
+			}	// Branch
 			if ( selti->getType()==TreeItem::Image)
 			{
 				actionOpenURL->setEnabled (false);
@@ -3475,15 +3479,12 @@
 				for (int i=0; i<actionListBranches.size(); ++i)	
 					actionListBranches.at(i)->setEnabled(false);
 				actionDelete->setEnabled (true);
-				// FIXME-2 actionFormatHideLinkUnselected->setOn
-				//	( selection->getHideLinkUnselected());
 				actionMoveUp->setEnabled (false);
 				actionMoveDown->setEnabled (false);
-			}	//image
+			}	// Image
 
 		} else
 		{	// !selti
-			actionFileSave->setEnabled (false);	
 			actionCopy->setEnabled (false);	
 			actionCut->setEnabled (false);	
 			actionPaste->setEnabled (false);	
@@ -3498,6 +3499,7 @@
 			actionDelete->setEnabled (false);
 			actionMoveUp->setEnabled (false);
 			actionMoveDown->setEnabled (false);
+			actionFormatHideLinkUnselected->setEnabled (false);
 			actionSortChildren->setEnabled (false);
 			actionToggleHideExport->setEnabled (false);	
 		}	
diff -r c6bb4fdcc55f -r 78ba80b54bc4 mapeditor.cpp
--- a/mapeditor.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/mapeditor.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -452,7 +452,7 @@
 
 void MapEditor::testFunction1()
 {
-	
+	/*
 	// Code copied from Qt sources
 	QRectF rect=model->getSelectedBranchObj()->getBBox();
 	int xmargin=50;
@@ -490,6 +490,8 @@
 	cout << "test1:  hor="<<horizontalScrollBar()->value()<<endl;
 	cout << "test1:  ver="<<verticalScrollBar()->value()<<endl;
 }
+
+*/
 /*
 	 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
 	 animation->setDuration(5000);
@@ -542,6 +544,7 @@
 	}	
 	cout <<"  hidemode="<<hidemode<<endl;
 	*/
+}
 	
 void MapEditor::testFunction2()
 {
diff -r c6bb4fdcc55f -r 78ba80b54bc4 treeeditor.cpp
--- a/treeeditor.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/treeeditor.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -1,35 +1,47 @@
 #include "treeeditor.h"
 
 #include <QAction>
+#include <QSortFilterProxyModel>
+#include <QRegExp>
+
 #include <iostream>
 using namespace std;
 
 #include "vymmodel.h"
 
+#include "mysortfilterproxymodel.h"
+
 ///////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////
 TreeEditor::TreeEditor(VymModel *m)
 {
-	//cout << "Constructor TreeEditor "<<this<<endl;
-	
 	model=m;
 
+/*
+//	MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel(this);	// FIXME-0 trying to use proxy...
+	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
+
+	proxyModel->setSourceModel(model);
+
+	proxyModel->setFilterRegExp(QRegExp("x", Qt::CaseInsensitive));
+	proxyModel->setFilterKeyColumn(0);
+	proxyModel->setDynamicSortFilter (true);
+//	setModel(proxyModel);
+*/
+	setModel(model);
+
 	QAction *a;
 	// Shortcuts for navigating with cursor:
     a = new QAction(tr( "Select upper object","Tree Editor" ), this);
 	a->setStatusTip ( tr( "Select upper object" ));
 	a->setShortcut (Qt::Key_Up );
-//	a->setShortcutContext (Qt::WindowShortcut);
 	a->setShortcutContext (Qt::WidgetShortcut);
-//	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
 	addAction (a);
     connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
 
     a = new QAction( tr( "Select lower object","Tree Editor" ),this);
 	a->setStatusTip (tr( "Select lower object" ));
 	a->setShortcut ( Qt::Key_Down );
-//	a->setShortcutContext (Qt::WindowShortcut);
-//	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
 	a->setShortcutContext (Qt::WidgetShortcut);
 	addAction (a);
     connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
diff -r c6bb4fdcc55f -r 78ba80b54bc4 treeeditor.h
--- a/treeeditor.h	Sat Aug 08 21:58:26 2009 +0000
+++ b/treeeditor.h	Tue Aug 18 12:39:07 2009 +0000
@@ -22,6 +22,7 @@
 
 private:
 	VymModel *model;
+	VymModel *proxyModel;
 };
 
 #endif
diff -r c6bb4fdcc55f -r 78ba80b54bc4 treeitem.cpp
--- a/treeitem.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/treeitem.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -13,7 +13,7 @@
 
 TreeItem::TreeItem()
 {
-	//cout << "Constr. TI\n";
+	//cout << "Constr. TI  this="<<this<<endl;
 	init();
 	itemData.clear();
 	rootItem=this;
@@ -47,6 +47,12 @@
 			case TreeItem::Branch:
 				delete (BranchItem*)ti;
 				break;
+			case TreeItem::Image:
+				delete (ImageItem*)ti;
+				break;
+			case TreeItem::Attribute:
+				delete (AttributeItem*)ti;
+				break;
 			default:
 				delete ti;
 				break;
@@ -59,12 +65,6 @@
 {
 	model=NULL;
 
-    parentItem = NULL;
-    itemData.clear();
-	QList<QVariant> cData;
-	itemData<< "VM:addMapCenter" << "undef"<<"undef";
-
-
 	branchOffset=0;
 	branchCounter=0;
 
@@ -148,6 +148,12 @@
 		// branches are on bottom of list
 		childItems.append(item);
 		branchCounter++;
+
+		// Set correct type		//FIXME-3 DUP in constr branchitem
+		if (this==rootItem)
+			item->setType(MapCenter);
+		else
+			item->setType (Branch);
 	}
 }
 
@@ -175,14 +181,17 @@
 	}
 }
 
-void TreeItem::removeChildBranches()
+/*
+void TreeItem::clear()	// FIXME-2 used in vymmodel addMapInsert, but needs to be used via model and emit layout changes...
 {
+	cout << "TI::clear\n";
 	while ( childItems.size()>0)
 	{
 		branchCounter--;
 		childItems.removeAt (0);
 	}
 }
+*/
 
 TreeItem *TreeItem::child(int row)
 {
@@ -233,6 +242,7 @@
     if (parentItem)
         return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
 
+	cout << "TI::row() pI=NULL this="<<this<<"  ***************\n";
     return 0;
 }
 
@@ -298,7 +308,7 @@
 
 TreeItem::Type TreeItem::getType()
 {
-	if (type==Branch && depth()==0) return MapCenter;
+	if (type==Branch && depth()==0) return MapCenter;	//FIXME-2 should not be necesssary
 	return type;
 }
 
@@ -316,6 +326,7 @@
 		case MapCenter: return QString ("MapCenter");
 		case Branch: return QString ("Branch");
 		case Image: return QString ("Image");
+		case Attribute: return QString ("Attribute");
 		default: return QString ("TreeItem::getTypeName no typename defined?!");
 	}
 }
diff -r c6bb4fdcc55f -r 78ba80b54bc4 treeitem.h
--- a/treeitem.h	Sat Aug 08 21:58:26 2009 +0000
+++ b/treeitem.h	Tue Aug 18 12:39:07 2009 +0000
@@ -39,7 +39,7 @@
 
     virtual void appendChild (TreeItem *child);
 	virtual void removeChild (int row);
-	virtual void removeChildBranches ();
+//	virtual void clear();
 
     virtual TreeItem *child(int row);
     virtual int childCount() const;
diff -r c6bb4fdcc55f -r 78ba80b54bc4 treemodel.cpp
--- a/treemodel.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/treemodel.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -3,9 +3,10 @@
 #include <iostream>
 using namespace std;
 
+#include "attributeitem.h"
 #include "branchitem.h"
+#include "imageitem.h"
 #include "treeitem.h"
-#include "imageitem.h"
 #include "treemodel.h"
 
 TreeModel::TreeModel(QObject *parent)
@@ -51,13 +52,33 @@
     return QVariant();
 }
 
+QModelIndex TreeModel::index (TreeItem* ti)
+{
+	if (!ti->parent())
+		return QModelIndex();
+	else	
+		return createIndex (ti->row(),ti->column(),ti);
+}
+
 QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
             const
 {
     TreeItem *parentItem;
 
     if (!parent.isValid())
+	{	//FIXME-1
         parentItem = rootItem;
+		/*
+		cout << "TM::index()  no parent?! xxx\n";
+		cout << "   row="<<row<<"  col="<<column<<endl;
+		cout << "   parent.internal="<< parent.internalPointer()<<endl;
+		*/
+		//return QModelIndex();	//FIXME-0 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...
+
+	}	
     else
         parentItem = getItem (parent);
 
@@ -73,8 +94,12 @@
     if (!index.isValid())
         return QModelIndex();
 
+	//FIXME-3 cout << "TM::parent  ri="<<rootItem<< "  row="<<index.row()<<"  col="<<index.column()<<endl;
     TreeItem *ti= getItem (index);
+	//cout << "            ti="<<ti<<endl;
+	//cout << "               "<<ti->getHeadingStd()<<endl;
     TreeItem *parentItem = ti->parent();
+	//cout << "            pi="<<parentItem<<endl;
 
 	//cout << "TreeModel::parent  ti="<<ti<<" "<<ti->getHeading().toStdString()<<"  pi="<<parentItem<<"  "<<endl;
     if (parentItem == rootItem)
@@ -192,6 +217,10 @@
     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);
@@ -207,6 +236,9 @@
 			case TreeItem::Image:
 				delete (ImageItem*)ti; 
 				break;
+			case TreeItem::Attribute:
+				delete (AttributeItem*)ti; 
+				break;
 			default:
 				delete ti;
 				break;
@@ -217,9 +249,11 @@
 
 TreeItem *TreeModel::getItem(const QModelIndex &index) const
 {
+//FIXME-3	cout << "TM::getItem  "<<index.internalPointer()<<endl;
     if (index.isValid()) {
 		TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
 
+//		cout << "   item="<<item<<endl;
         if (item) return item;
     }
     return rootItem;
@@ -230,8 +264,3 @@
 	return rootItem;
 }
 
-QModelIndex TreeModel::index (TreeItem* ti)
-{
-	return createIndex (ti->row(),ti->column(),ti);
-}
-
diff -r c6bb4fdcc55f -r 78ba80b54bc4 treemodel.h
--- a/treemodel.h	Sat Aug 08 21:58:26 2009 +0000
+++ b/treemodel.h	Tue Aug 18 12:39:07 2009 +0000
@@ -22,6 +22,7 @@
     Qt::ItemFlags flags(const QModelIndex &index) const;
     QVariant headerData(int section, Qt::Orientation orientation,
                         int role = Qt::DisplayRole) const;
+	QModelIndex index (TreeItem* ti);
     QModelIndex index(int row, int column,
                       const QModelIndex &parent = QModelIndex()) const;
     QModelIndex parent(const QModelIndex &index) const;
@@ -35,7 +36,6 @@
 
 	TreeItem* getItem (const QModelIndex &index) const;
 	TreeItem* getRootItem();
-	QModelIndex index (TreeItem* ti);
 
 
 protected:
diff -r c6bb4fdcc55f -r 78ba80b54bc4 vym.pro
--- a/vym.pro	Sat Aug 08 21:58:26 2009 +0000
+++ b/vym.pro	Tue Aug 18 12:39:07 2009 +0000
@@ -69,6 +69,7 @@
 	mapitem.h \
 	mapobj.h \
 	misc.h \
+	mysortfilterproxymodel.h \
 	noteobj.h \
 	options.h \
 	ornamentedobj.h \
@@ -132,6 +133,7 @@
 	mapitem.cpp \
 	mapobj.cpp \
 	misc.cpp \
+	mysortfilterproxymodel.cpp \
 	noteobj.cpp \
 	options.cpp \
 	ornamentedobj.cpp \
diff -r c6bb4fdcc55f -r 78ba80b54bc4 vymmodel.cpp
--- a/vymmodel.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/vymmodel.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -241,22 +241,29 @@
 	// Find the used flags while traversing the tree	// FIXME-2 this can be done local to vymmodel maybe...
 	standardFlagsMaster->resetUsedCounter();
 	
-	// Reset the counters before saving
-	// TODO constr. of FIO creates lots of objects, better do this in some other way...
-	ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
-
 	// Build xml recursivly
-	if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
+	if (!saveSel)
 		// Save all mapcenters as complete map, if saveSel not set
 		s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
 	else
 	{
-		if (saveSel->isBranchLikeType())
-			// Save Subtree
-			s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
-		//FIXME-2 else if (saveSel->getType()==TreeItem::Image)
-			// Save image
-			//s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
+		switch (saveSel->getType())
+		{
+			case TreeItem::Branch:
+				// Save Subtree
+				s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
+				break;
+			case TreeItem::MapCenter:
+				// Save Subtree
+				s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
+				break;
+			case TreeItem::Image:
+				// Save Image
+				s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
+				break;
+			default://FIXME-4 other types shouldn't be safed...
+				break;
+		}
 	}
 
 	// Save local settings
@@ -673,42 +680,55 @@
 		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
 }
 
-void VymModel::addMapInsertInt (const QString &path, int pos)
-{
-/* FIXME-2  addMapInsertInt not ported yet
-	BranchObj *sel=getSelectedBranch();
-	if (sel)
+bool VymModel::addMapInsertInt (const QString &path)
+{
+	QString pathDir=path.left(path.findRev("/"));
+	QDir d(pathDir);
+	QFile file (path);
+
+	if (d.exists() )
 	{
-		QString pathDir=path.left(path.findRev("/"));
-		QDir d(pathDir);
-		QFile file (path);
-
-		if (d.exists() )
+		// We need to parse saved XML data
+		parseVYMHandler handler;
+		QXmlInputSource source( file);
+		QXmlSimpleReader reader;
+		reader.setContentHandler( &handler );
+		reader.setErrorHandler( &handler );
+		handler.setModel (this);
+		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
+		handler.setLoadMode (ImportAdd);
+		blockReposition=true;
+		bool ok = reader.parse( source );
+		blockReposition=false;
+		if ( ok ) return true;
+		{	
+			// This should never ever happen
+			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
+									handler.errorProtocol());
+		}
+	} else	
+		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
+	return false;
+}
+
+bool VymModel::addMapInsertInt (const QString &path, int pos)
+{
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
+	{
+		if (addMapInsertInt (path))
 		{
-			// We need to parse saved XML data
-			parseVYMHandler handler;
-			QXmlInputSource source( file);
-			QXmlSimpleReader reader;
-			reader.setContentHandler( &handler );
-			reader.setErrorHandler( &handler );
-			handler.setModel (this);
-			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
-			handler.setLoadMode (ImportAdd);
-			blockReposition=true;
-			bool ok = reader.parse( source );
-			blockReposition=false;
-			if (! ok ) 
-			{	
-				// This should never ever happen
-				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
-										handler.errorProtocol());
-			}
-			if (sel->getDepth()>0)
-				sel->getLastBranch()->linkTo (sel,pos);
-		} else	
+			if (selbi->depth()>0)
+				relinkBranch (selbi->getLastBranch(), selbi,pos);
+			return true;	
+		} else
+		{
 			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
+			return false;
+		}	
 	}		
-*/
+	qWarning ("ME::addMapInsertInt nothing selected");
+	return false;
 }
 
 ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
@@ -1013,11 +1033,7 @@
 	s=ti->getHeading();
 	if (s=="") s="unnamed";
 
-	if (ti->isBranchLikeType() )	//FIXME-3 shouldnt there also be mapcenter??
-		return QString("branch (%1)").arg(s);
-	if (ti->getType()==TreeItem::Image)
-		return QString ("image (%1)").arg(ti->getHeading());
-	return QString("Unknown type has no name!");
+	return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
 }
 
 void VymModel::redo()
@@ -1128,8 +1144,7 @@
 	QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
 
 	// select  object before undo
-	if (!undoSelection.isEmpty())
-		select (undoSelection);
+	select (undoSelection);
 
 	if (debug)
 	{
@@ -1155,7 +1170,7 @@
 	redosAvail++;
 
 	blockSaveState=blockSaveStateOrg;
-/* TODO remove testing
+/* testing only
 	cout << "VymModel::undo() end\n";
 	cout << "    undosAvail="<<undosAvail<<endl;
 	cout << "    redosAvail="<<redosAvail<<endl;
@@ -1327,10 +1342,11 @@
 		qWarning ("VymModel::saveStateRemovingPart  no redoSel given!");
 		return;
 	}
-	QString undoSelection=getSelectString (redoSel->parent() );
+	QString undoSelection;
 	QString redoSelection=getSelectString(redoSel);
 	if (redoSel->getType()==TreeItem::Branch) 
 	{
+		undoSelection=getSelectString (redoSel->parent());
 		// save the selected branch of the map, Undo will insert part of map 
 		saveState (PartOfMap,
 			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
@@ -1338,6 +1354,15 @@
 			comment, 
 			redoSel);
 	}
+	if (redoSel->getType()==TreeItem::MapCenter) 
+	{
+		// save the selected branch of the map, Undo will insert part of map 
+		saveState (PartOfMap,
+			undoSelection, QString("addMapInsert (\"PATH\")"),
+			redoSelection, "delete ()", 
+			comment, 
+			redoSel);
+	}
 }
 
 
@@ -1983,10 +2008,10 @@
 	return NULL;
 }
 
-AttributeItem* VymModel::addAttribute()
-{
-	TreeItem *selti=getSelectedItem();
-	if (selti)
+AttributeItem* VymModel::addAttribute()	// FIXME-2 savestate missing
+{
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
 	{
 		QList<QVariant> cData;
 		cData << "new attribute" << "undef"<<"undef";
@@ -1994,10 +2019,10 @@
 
 		emit (layoutAboutToBeChanged() );
 
-		QModelIndex parix=index(selti);
-		int n=selti->getRowNumAppend (a);
+		QModelIndex parix=index(selbi);
+		int n=selbi->getRowNumAppend (a);
 		beginInsertRows (parix,n,n+1);	
-		selti->appendChild (a);	
+		selbi->appendChild (a);	
 		endInsertRows ();
 
 		emit (layoutChanged() );
@@ -2037,7 +2062,7 @@
 
 	QList<QVariant> cData;
 	cData << "VM:addMapCenter" << "undef"<<"undef";
-	BranchItem *newbi=new BranchItem (cData);
+	BranchItem *newbi=new BranchItem (cData,rootItem);
 	newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
 	rootItem->appendChild (newbi);
 
@@ -2197,6 +2222,10 @@
 		dst->insertBranch (pos,branch);
 		endInsertRows();
 
+		// Correct type if necessesary
+		if (branch->getType()==TreeItem::MapCenter) 
+			branch->setType(TreeItem::Branch);
+
 		// reset parObj, fonts, frame, etc in related LMO or other view-objects
 		branch->updateStyles();
 
@@ -2251,11 +2280,11 @@
 	return false;
 }
 
-void VymModel::deleteSelection()	// FIXME-2 include fix for deleted mapcenters from 1.12.4
+void VymModel::deleteSelection()	
 {
 	BranchItem *selbi=getSelectedBranch();
 
-	if (selbi && selbi->isBranchLikeType() )
+	if (selbi)
 	{
 		unselect();
 		saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
@@ -2268,7 +2297,7 @@
 		}
 		return;
 	}
-	TreeItem *ti=getSelectedImage();
+	TreeItem *ti=getSelectedItem();
 	if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
 	{
 		TreeItem *pi=ti->parent();
@@ -2378,7 +2407,7 @@
 		reposition();
 
 		emit (layoutChanged() );
-		if (pi->depth()>0) return pi;
+		if (pi->depth()>=0) return pi;
 	}	
 	return NULL;
 }
@@ -2873,22 +2902,29 @@
 	/////////////////////////////////////////////////////////////////////
 	} else if (com==QString("addMapInsert"))
 	{
-		if (!selti)
+		if (parser.parCount()==2)
 		{
-			parser.setError (Aborted,"Nothing selected");
-		} else if (! selbi )
-		{				  
-			parser.setError (Aborted,"Type of selection is not a branch");
-		} else 
-		{	
-			if (parser.checkParCount(2))
+
+			if (!selti)
 			{
+				parser.setError (Aborted,"Nothing selected");
+			} else if (! selbi )
+			{				  
+				parser.setError (Aborted,"Type of selection is not a branch");
+			} else 
+			{	
 				t=parser.parString (ok,0);	// path to map
 				n=parser.parInt(ok,1);		// position
 				if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
 				addMapInsertInt(t,n);	
 			}
-		}
+		} else if (parser.parCount()==1)
+		{
+			t=parser.parString (ok,0);	// path to map
+			if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
+			addMapInsertInt(t);	
+		} else
+			parser.setError (Aborted,"Wrong number of parameters");
 	/////////////////////////////////////////////////////////////////////
 	} else if (com=="clearFlags")	
 	{
@@ -4610,6 +4646,11 @@
 
 bool VymModel::select (const QString &s)
 {
+	if (s.isEmpty())
+	{
+		unselect();
+		return true;
+	}
 	TreeItem *ti=findBySelectString(s);
 	if (ti) return select (index(ti));
 	return false;
diff -r c6bb4fdcc55f -r 78ba80b54bc4 vymmodel.h
--- a/vymmodel.h	Sat Aug 08 21:58:26 2009 +0000
+++ b/vymmodel.h	Tue Aug 18 12:39:07 2009 +0000
@@ -111,7 +111,8 @@
 
 private:
     void addMapReplaceInt(const QString & undoSel, const QString & path);
-    void addMapInsertInt (const QString & path, int pos);
+    bool addMapInsertInt (const QString & path);
+    bool addMapInsertInt (const QString & path, int pos);
 
 	ImageItem* loadFloatImageInt (BranchItem *dst,QString);
 	void saveFloatImageInt (ImageItem*, const QString &, const QString &);
diff -r c6bb4fdcc55f -r 78ba80b54bc4 vymview.cpp
--- a/vymview.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/vymview.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -16,11 +16,13 @@
 
 	// Create TreeView
 	treeEditor=new TreeEditor (model);
-	treeEditor->setModel ((QAbstractItemModel*)model);
+	//treeEditor->setModel ((QAbstractItemModel*)model);
 	//treeEditor->setMinimumWidth (50);
 
-	treeEditor->setColumnWidth (0,350);
+	treeEditor->setColumnWidth (0,150);
+	treeEditor->setAnimated (true);
 
+	
 	selModel=treeEditor->selectionModel();
 	model->setSelectionModel (selModel);
 	connect (
@@ -66,10 +68,22 @@
 	addWidget (treeEditor);
 	addWidget (mapEditor);
 
+/*
+	tv=new QTreeView;
+	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
+	proxyModel->setDynamicSortFilter (true);
+	proxyModel->setSourceModel(model);
+	//proxyModel->setFilterFixedString ("a",Qt::CaseInsensitive,QRegExp::FixedString);
+	proxyModel->setFilterRegExp(QRegExp("e", Qt::CaseInsensitive));
+	proxyModel->setFilterKeyColumn(0);
+	tv->setModel (proxyModel);
+	addWidget (tv);
+*/
 	// Set geometry
 	QList <int> widths;
-	widths<<120;
+	widths<<200;
 	widths<<600;
+//	widths<<200;
 	setSizes(widths);
 }
 
@@ -114,6 +128,7 @@
 void VymView::expandAll()
 {
 	treeEditor->expandAll();
+	//tv->expandAll();
 }
 
 void VymView::showSelection()
diff -r c6bb4fdcc55f -r 78ba80b54bc4 vymview.h
--- a/vymview.h	Sat Aug 08 21:58:26 2009 +0000
+++ b/vymview.h	Tue Aug 18 12:39:07 2009 +0000
@@ -9,6 +9,7 @@
 class MapEditor;
 class TreeEditor;
 
+class QTreeView;
 
 class VymView : public QSplitter 
 {
@@ -29,6 +30,7 @@
 private:
 	VymModel *model;
 	TreeEditor *treeEditor;
+	QTreeView *tv;	//FIXME-3 testing only
 	QItemSelectionModel *selModel;
 	MapEditor *mapEditor;
 };
diff -r c6bb4fdcc55f -r 78ba80b54bc4 xml-vym.cpp
--- a/xml-vym.cpp	Sat Aug 08 21:58:26 2009 +0000
+++ b/xml-vym.cpp	Tue Aug 18 12:39:07 2009 +0000
@@ -139,13 +139,12 @@
 		if (loadMode==NewMap)
 		{	
 			// Really use the found mapcenter as MCO in a new map
-
 			lastBranch=model->createMapCenter(); 
 		} else
 		{
 			// Treat the found mapcenter as a branch 
 			// in an existing map
-			BranchItem *bi=model->getSelectedBranch();	//FIXME-3 selection is no longer used here...
+			BranchItem *bi=model->getSelectedBranch();	//FIXME-3 selection is no longer used here... //FIXME-2 really? we are adding to a map...
 			if (bi)
 			{
 				lastBranch=bi;
@@ -153,10 +152,11 @@
 				{
 					lastBranch=model->createBranch(lastBranch);
 				} //else
-					//FIXME-3 lastBranch->clear();
+					//lastBranch->clear(); //FIXME-1 clear not really defined!
 			} else
-				return false;
-		}
+				// add mapCenter without parent
+				lastBranch=model->createMapCenter(); 
+		}		
 		readBranchAttr (atts);
 	} else if ( 
 		(eName == "standardflag" ||eName == "standardFlag") && 
@@ -438,7 +438,7 @@
 					return false;   // Couldn't read relPos
 			}           
 		}           
-		if (!a.value( "absPosX").isEmpty() && loadMode==NewMap ) 
+		if (!a.value( "absPosX").isEmpty() ) 
 		{
 			if (!a.value( "absPosY").isEmpty() ) 
 			{