# HG changeset patch
# User insilmaril
# Date 1241041237 0
# Node ID 0301e61097022ae44439f5b2ed8b7d84a764b27f
# Parent  59614eaf5fbb7ef7220bc4ddc1eb95e036a87e31
speedup

diff -r 59614eaf5fbb -r 0301e6109702 mapcenteritem.cpp
--- a/mapcenteritem.cpp	Wed Apr 29 18:46:31 2009 +0000
+++ b/mapcenteritem.cpp	Wed Apr 29 21:40:37 2009 +0000
@@ -122,7 +122,6 @@
 
 BranchObj* MapCenterItem::createMapObj(QGraphicsScene *scene)	
 {
-	cout <<"MCI  parent->model="<<parent()->getModel()<<endl;
 	// Initialize MapCenterObj, order of things is important...
     MapCenterObj* mco=new MapCenterObj(scene);
 	lmo=mco;
diff -r 59614eaf5fbb -r 0301e6109702 mapeditor.cpp
--- a/mapeditor.cpp	Wed Apr 29 18:46:31 2009 +0000
+++ b/mapeditor.cpp	Wed Apr 29 21:40:37 2009 +0000
@@ -910,7 +910,6 @@
 				// We have a destination, relink to that
 
 				BranchObj* bsel=model->getSelectedBranchObj();
-				BranchObj* bdst=(BranchObj*)dst;
 
 				QString preParStr=model->getSelectString (bsel->getParObj());
 				QString preNum=QString::number (seli->num(),10);
diff -r 59614eaf5fbb -r 0301e6109702 version.h
--- a/version.h	Wed Apr 29 18:46:31 2009 +0000
+++ b/version.h	Wed Apr 29 21:40:37 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-04-27"
+#define __VYM_BUILD_DATE "2009-04-29"
 
 
 bool checkVersion(const QString &);
diff -r 59614eaf5fbb -r 0301e6109702 vymmodel.cpp
--- a/vymmodel.cpp	Wed Apr 29 18:46:31 2009 +0000
+++ b/vymmodel.cpp	Wed Apr 29 21:40:37 2009 +0000
@@ -992,6 +992,7 @@
 	mapChanged=true;
 	mapDefault=false;
 	mapUnsaved=true;
+	latestAddedItem=NULL;
 	findReset();
 }
 
@@ -1401,28 +1402,33 @@
 	return mapScene;
 }
 
-TreeItem* VymModel::findBySelectString(const QString &s)	//FIXME-0
-{
-	return NULL;
-	if (!s.isEmpty() )
+TreeItem* VymModel::findBySelectString(QString s)
+{
+	if (s.isEmpty() ) return NULL;
+
+	// Old maps don't have multiple mapcenters and don't save full path
+	if (s.left(2) !="mc")
+		s="mc:0,"+s;
+
+	QStringList parts=s.split (",");
+	QString typ;
+	int n;
+	TreeItem *ti=rootItem;
+
+	while (!parts.isEmpty() )
 	{
-		QString part;
-		QString typ;
-		QString num;
-		part=s.section(",",0,0);
-		typ=part.left (2);
-		num=part.right(part.length() - 3);
-		if (typ=="mc" && num.toInt()>=0 && num.toInt() <rootItem->branchCount() )
-			return rootItem->getBranchNum (num.toInt() );
-	}		
-
-	TreeItem *ti;
-	for (int i=0; i<rootItem->branchCount(); i++)
-	{
-		// ti=rootItem->getBranchNum(i)->findBySelectString(s);
-		if (ti) return ti;
-	}	
-	return NULL;
+		typ=parts.first().left(2);
+		n=parts.first().right(parts.first().length() - 3).toInt();
+		parts.removeFirst();
+		if (typ=="mc" || typ=="bo")
+			ti=ti->getBranchNum (n);
+			/* FIXME-2
+		else
+			if (typ="fi")
+				ti=ti->getImageNum (n);
+				*/
+	}
+	return  ti;
 }
 
 TreeItem* VymModel::findID (const QString &s)
@@ -2044,7 +2050,7 @@
 
 MapCenterItem* VymModel::addMapCenter ()
 {
-	MapCenterItem *mci=addMapCenter (contextPos);	//FIXME-2 get rid of MCO here
+	MapCenterItem *mci=addMapCenter (contextPos);
 	//FIXME-3 selection.select (mco);
 	updateActions();
 	ensureSelectionVisible();
@@ -2186,7 +2192,7 @@
 
 			reposition();
 			// selection.update(); FIXME-3
-			latestSelectionString=getSelectString(newbi);
+			latestAddedItem=newbi;
 			// In Network mode, the client needs to know where the new branch is,
 			// so we have to pass on this information via saveState.
 			// TODO: Get rid of this positioning workaround
@@ -2268,7 +2274,6 @@
 
 void VymModel::deleteSelection()
 {
-	BranchObj *bo = getSelectedBranchObj();	// FIXME-2 VM should not be necessary
 	BranchItem *selbi=getSelectedBranchItem();
 
 	if (!selbi) return;
@@ -3351,13 +3356,13 @@
 	/////////////////////////////////////////////////////////////////////
 	} else */ if (com=="selectLatestAdded")
 	{
-		if (latestSelectionString.isEmpty() )
+		if (!latestAddedItem)
 		{
 			parser.setError (Aborted,"No latest added object");
 		} else
 		{	
-			if (!select (latestSelectionString))
-				parser.setError (Aborted,"Could not select latest added object "+latestSelectionString);
+			if (!select (latestAddedItem))
+				parser.setError (Aborted,"Could not select latest added object ");
 		}	
 	/////////////////////////////////////////////////////////////////////
 	} else if (com=="setFrameType")
@@ -3882,10 +3887,6 @@
 void VymModel::registerEditor(QWidget *me)
 {
 	mapEditor=(MapEditor*)me;
-	/* FIXME-3
-	for (int i=0; i<rootItem->branchCount(); i++)
-		rootItem->getBranchNum(i)->setMapEditor(mapEditor);
-	*/
 }
 
 void VymModel::unregisterEditor(QWidget *)
@@ -3924,9 +3925,11 @@
 		((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions();
 }
 
-void VymModel::reposition()	//FIXME-2 VM should have no need to reposition, this is done in views???
-{
-	//cout << "VM::reposition ...\n";
+void VymModel::reposition()	//FIXME-3 VM should have no need to reposition, this is done in views???
+{
+	//cout << "VM::reposition blocked="<<blockReposition<<endl;
+	if (blockReposition) return;
+
 	for (int i=0;i<rootItem->branchCount(); i++)
 		rootItem->getBranchObjNum(i)->reposition();	//	for positioning heading
 }
@@ -4998,19 +5001,6 @@
 	return NULL;
 }
 
-MapCenterItem* VymModel::getSelectedMapCenterItem()
-{
-	QModelIndexList list=selModel->selectedIndexes();
-	if (!list.isEmpty() )
-	{
-		TreeItem *ti = getItem (list.first() );
-		TreeItem::Type type=ti->getType();
-		if (ti->getType()==TreeItem::MapCenter)
-			return (MapCenterItem*)ti;
-	}
-	return NULL;
-}
-
 TreeItem* VymModel::getSelectedItem()
 {
 	QModelIndexList list=selModel->selectedIndexes();
diff -r 59614eaf5fbb -r 0301e6109702 vymmodel.h
--- a/vymmodel.h	Wed Apr 29 18:46:31 2009 +0000
+++ b/vymmodel.h	Wed Apr 29 21:40:37 2009 +0000
@@ -220,7 +220,7 @@
 	void setScene(QGraphicsScene *s);
 	QGraphicsScene *getScene();
 
-    TreeItem* findBySelectString (const QString &s);		
+    TreeItem* findBySelectString (QString s);		
     TreeItem* findID (const QString &s);				// find MapObj by previously set ID
 
 
@@ -531,7 +531,7 @@
 ////////////////////////////////////////////
 private:
 	Selection selection;
-	QString latestSelectionString;	// select string of latest added object
+	TreeItem *latestAddedItem;				// latest added object, reset on setChanged()
 
 signals:
 	void selectionChanged(const QItemSelection &, const QItemSelection &);
@@ -574,7 +574,6 @@
 	LinkableMapObj* getSelectedLMO();
 	BranchObj* getSelectedBranchObj();	// FIXME-2 replace by item...
 	BranchItem* getSelectedBranchItem();
-	MapCenterItem* getSelectedMapCenterItem();
 	TreeItem* getSelectedItem();
 	QModelIndex getSelectedIndex();
 	FloatImageObj* getSelectedFloatImage();
diff -r 59614eaf5fbb -r 0301e6109702 vymview.cpp
--- a/vymview.cpp	Wed Apr 29 18:46:31 2009 +0000
+++ b/vymview.cpp	Wed Apr 29 21:40:37 2009 +0000
@@ -17,10 +17,7 @@
 	treeview=new QTreeView;
 	treeview->setModel ((QAbstractItemModel*)model);
 	//treeview->setMinimumWidth (50);
-	QList <int> widths;
-	widths<<30;
-	widths<<150;
-	setSizes(widths);
+
 	treeview->setColumnWidth (0,350);
 
 	selModel=treeview->selectionModel();
@@ -30,11 +27,11 @@
 		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
 
 	// Create good old MapEditor
-	MapEditor* me=model->getMapEditor();
-	if (!me) me=new MapEditor (model);
+	mapEditor=model->getMapEditor();
+	if (!mapEditor) mapEditor=new MapEditor (model);
 	connect (
 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
-		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
+		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
 		/*
 	connect (
 		selModel, SIGNAL (currentChanged(const QModelIndex &, const QModelIndex &)), 
@@ -44,32 +41,36 @@
 */
 	connect (
 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
-		me,SLOT (updateData(const QModelIndex &) ) );
+		mapEditor,SLOT (updateData(const QModelIndex &) ) );
 
 	// VymModel may want to update selection or other data, e.g. during animation
 	connect (
 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
-		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
+		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
+
+		/*
 	connect (
 		model, SIGNAL (newChildObject(QModelIndex) ),
 		this,SLOT (updateChilds (QModelIndex) ) );
+*/
+
 	connect (
 		model, SIGNAL (noteHasChanged(QModelIndex) ),
 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
 		
 
-	//me->viewport()->setFocus();	//FIXME-3 needed?
-	me->setAntiAlias (mainWindow->isAliased());
-	me->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
+	//mapEditor->viewport()->setFocus();	//FIXmapEditor-3 needed?
+	mapEditor->setAntiAlias (mainWindow->isAliased());
+	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
 
 	addWidget (treeview);
-	addWidget (me);
+	addWidget (mapEditor);
 
 	// Set geometry
-	QList <int> sizes;
-	sizes.append (120);
-	sizes.append (600);
-	setSizes (sizes);
+	QList <int> widths;
+	widths<<120;
+	widths<<600;
+	setSizes(widths);
 }
 
 QItemSelectionModel* VymView::selectionModel() 
@@ -82,9 +83,10 @@
 }
 
 
-void VymView::updateChilds (QModelIndex ix)
+void VymView::updateChilds (QModelIndex ix)		//FIXME-4 not needed?
 {
-	treeview->setExpanded (ix,true);
+	cout << "VV::updateChilds \n";
+	//treeview->setExpanded (ix,true);	// This is expensive...
 }
 
 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
diff -r 59614eaf5fbb -r 0301e6109702 vymview.h
--- a/vymview.h	Wed Apr 29 18:46:31 2009 +0000
+++ b/vymview.h	Wed Apr 29 21:40:37 2009 +0000
@@ -6,6 +6,7 @@
 #include <QTreeView>
 
 class VymModel;
+class MapEditor;
 
 
 class VymView : public QSplitter 
@@ -23,6 +24,7 @@
 	VymModel *model;
 	QTreeView *treeview;
 	QItemSelectionModel *selModel;
+	MapEditor *mapEditor;
 };
 
 
diff -r 59614eaf5fbb -r 0301e6109702 xml-vym.cpp
--- a/xml-vym.cpp	Wed Apr 29 18:46:31 2009 +0000
+++ b/xml-vym.cpp	Wed Apr 29 21:40:37 2009 +0000
@@ -308,7 +308,7 @@
 
 bool parseVYMHandler::characters   ( const QString& ch)
 {
-	//cout << "characters \""<<ch<<"\"  state="<<state <<"  laststate="<<laststate<<endl;
+	//cout << "characters \""<<ch.toStdString()<<"\"  state="<<state <<"  laststate="<<laststate<<endl;
 
 	QString ch_org=quotemeta (ch);
     QString ch_simplified=ch.simplifyWhiteSpace();