Fix for segfault when deleting MCO (invalid QModelIndex needs to be returned in index(TreeItem*) )
authorinsilmaril
Tue, 18 Aug 2009 12:39:07 +0000
changeset 78878ba80b54bc4
parent 787 c6bb4fdcc55f
child 789 d85834ad8c54
Fix for segfault when deleting MCO (invalid QModelIndex needs to be returned in index(TreeItem*) )
branchitem.cpp
branchobj.cpp
imageitem.cpp
imageitem.h
mainwindow.cpp
mapeditor.cpp
treeeditor.cpp
treeeditor.h
treeitem.cpp
treeitem.h
treemodel.cpp
treemodel.h
vym.pro
vymmodel.cpp
vymmodel.h
vymview.cpp
vymview.h
xml-vym.cpp
     1.1 --- a/branchitem.cpp	Sat Aug 08 21:58:26 2009 +0000
     1.2 +++ b/branchitem.cpp	Tue Aug 18 12:39:07 2009 +0000
     1.3 @@ -11,9 +11,13 @@
     1.4  {
     1.5  	//cout << "Constr. BranchItem\n";
     1.6  
     1.7 +	if (parent==rootItem)
     1.8 +		setType (MapCenter);
     1.9 +	else
    1.10 +		setType (Branch);
    1.11 +
    1.12  	scrolled=false;
    1.13  	tmpUnscrolled=false;
    1.14 -	type=Branch;
    1.15  
    1.16  	includeImagesVer=false;
    1.17  	includeImagesHor=false;
    1.18 @@ -24,7 +28,7 @@
    1.19  
    1.20  BranchItem::~BranchItem()
    1.21  {
    1.22 -	cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
    1.23 +	//cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
    1.24  	if (lmo) 
    1.25  	{
    1.26  		delete lmo;
     2.1 --- a/branchobj.cpp	Sat Aug 08 21:58:26 2009 +0000
     2.2 +++ b/branchobj.cpp	Tue Aug 18 12:39:07 2009 +0000
     2.3 @@ -598,7 +598,7 @@
     2.4  	calcBBoxSize();
     2.5  }
     2.6  
     2.7 -void BranchObj::sortChildren() //FIXME-2  
     2.8 +void BranchObj::sortChildren() //FIXME-3 not moved to model yet 
     2.9  {
    2.10  /*
    2.11  	int childCount=branch.count(); 
     3.1 --- a/imageitem.cpp	Sat Aug 08 21:58:26 2009 +0000
     3.2 +++ b/imageitem.cpp	Tue Aug 18 12:39:07 2009 +0000
     3.3 @@ -7,8 +7,6 @@
     3.4  #include <iostream>
     3.5  using namespace std;
     3.6  
     3.7 -uint ImageItem::saveCounter=0;		// create instance 
     3.8 -
     3.9  ImageItem::ImageItem()
    3.10  {
    3.11  	init();
    3.12 @@ -27,7 +25,7 @@
    3.13  
    3.14  void ImageItem::init()
    3.15  {
    3.16 -	type=Image;
    3.17 +	setType (Image);
    3.18  	imageType=Undefined;
    3.19  	hideLinkUnselected=true;
    3.20  	originalFilename="no original name available";
    3.21 @@ -87,11 +85,6 @@
    3.22  	return originalFilename;
    3.23  }
    3.24  
    3.25 -void ImageItem::resetSaveCounter()
    3.26 -{
    3.27 -	saveCounter=0;
    3.28 -}
    3.29 -
    3.30  void ImageItem::save(const QString &fn, const QString &format)
    3.31  {
    3.32  	pixmap.save (fn,qPrintable (format));
    3.33 @@ -101,13 +94,12 @@
    3.34  {
    3.35  	if (hidden) return "";
    3.36  
    3.37 -	saveCounter++;
    3.38 -	
    3.39 -	
    3.40  	QString zAttr=attribut ("zValue",QString().setNum(zValue));
    3.41  	QString url;
    3.42  
    3.43 -	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + ".png" ;
    3.44 +	ulong n=reinterpret_cast <ulong> (this);
    3.45 +
    3.46 +	url="images/"+prefix+"image-" + QString().number(n,10) + ".png" ;
    3.47  
    3.48  	// And really save the image
    3.49  	pixmap.save (tmpdir +"/"+ url, "PNG");
     4.1 --- a/imageitem.h	Sat Aug 08 21:58:26 2009 +0000
     4.2 +++ b/imageitem.h	Tue Aug 18 12:39:07 2009 +0000
     4.3 @@ -33,14 +33,12 @@
     4.4  protected:	
     4.5  	QPixmap pixmap;
     4.6  	QString originalFilename;
     4.7 -	static uint saveCounter;	// numerate the files during saveToDir
     4.8  	int zValue;
     4.9  
    4.10  public:	
    4.11  	virtual void setZValue(int z);
    4.12  	virtual void setOriginalFilename(const QString &);
    4.13  	virtual QString getOriginalFilename();
    4.14 -	virtual void resetSaveCounter();
    4.15  	virtual void save (const QString &fn, const QString &format);
    4.16  	virtual QString saveToDir(const QString &,const QString&);
    4.17  
     5.1 --- a/mainwindow.cpp	Sat Aug 08 21:58:26 2009 +0000
     5.2 +++ b/mainwindow.cpp	Tue Aug 18 12:39:07 2009 +0000
     5.3 @@ -3359,7 +3359,7 @@
     5.4  	if (m && m->hasChanged() )
     5.5  		actionFileSave->setEnabled( true);
     5.6  	else	
     5.7 -		actionFileSave->setEnabled( true);
     5.8 +		actionFileSave->setEnabled( false);
     5.9  	if (m && m->isUndoAvailable())
    5.10  		actionUndo->setEnabled( true);
    5.11  	else	
    5.12 @@ -3376,7 +3376,13 @@
    5.13  		BranchItem *selbi=m->getSelectedBranch();
    5.14  		if (selti)
    5.15  		{
    5.16 -			if (selbi)
    5.17 +			if (selbi || selti->getType()==TreeItem::Image)
    5.18 +			{
    5.19 +				actionFormatHideLinkUnselected->setOn (((MapItem*)selti)->getHideLinkUnselected());
    5.20 +				actionFormatHideLinkUnselected->setEnabled (true);
    5.21 +			}
    5.22 +
    5.23 +			if (selbi)	// FIXME-4 many properties of former BranchObj are in TreeItem meanwhile...
    5.24  			{
    5.25  				// Take care of links  // updateActions: FIXME-1
    5.26  				/*
    5.27 @@ -3448,7 +3454,6 @@
    5.28  				actionToggleHideExport->setEnabled (true);	
    5.29  				actionToggleHideExport->setOn (selbi->hideInExport() );	
    5.30  
    5.31 -				actionFileSave->setEnabled (true);	
    5.32  				actionCopy->setEnabled (true);	
    5.33  				actionCut->setEnabled (true);	
    5.34  				if (!clipboardEmpty)
    5.35 @@ -3458,8 +3463,7 @@
    5.36  				for (int i=0; i<actionListBranches.size(); ++i)	
    5.37  					actionListBranches.at(i)->setEnabled(true);
    5.38  				actionDelete->setEnabled (true);
    5.39 -				//FIXME-2 actionFormatHideLinkUnselected->setOn (selection->getHideLinkUnselected());
    5.40 -			}
    5.41 +			}	// Branch
    5.42  			if ( selti->getType()==TreeItem::Image)
    5.43  			{
    5.44  				actionOpenURL->setEnabled (false);
    5.45 @@ -3475,15 +3479,12 @@
    5.46  				for (int i=0; i<actionListBranches.size(); ++i)	
    5.47  					actionListBranches.at(i)->setEnabled(false);
    5.48  				actionDelete->setEnabled (true);
    5.49 -				// FIXME-2 actionFormatHideLinkUnselected->setOn
    5.50 -				//	( selection->getHideLinkUnselected());
    5.51  				actionMoveUp->setEnabled (false);
    5.52  				actionMoveDown->setEnabled (false);
    5.53 -			}	//image
    5.54 +			}	// Image
    5.55  
    5.56  		} else
    5.57  		{	// !selti
    5.58 -			actionFileSave->setEnabled (false);	
    5.59  			actionCopy->setEnabled (false);	
    5.60  			actionCut->setEnabled (false);	
    5.61  			actionPaste->setEnabled (false);	
    5.62 @@ -3498,6 +3499,7 @@
    5.63  			actionDelete->setEnabled (false);
    5.64  			actionMoveUp->setEnabled (false);
    5.65  			actionMoveDown->setEnabled (false);
    5.66 +			actionFormatHideLinkUnselected->setEnabled (false);
    5.67  			actionSortChildren->setEnabled (false);
    5.68  			actionToggleHideExport->setEnabled (false);	
    5.69  		}	
     6.1 --- a/mapeditor.cpp	Sat Aug 08 21:58:26 2009 +0000
     6.2 +++ b/mapeditor.cpp	Tue Aug 18 12:39:07 2009 +0000
     6.3 @@ -452,7 +452,7 @@
     6.4  
     6.5  void MapEditor::testFunction1()
     6.6  {
     6.7 -	
     6.8 +	/*
     6.9  	// Code copied from Qt sources
    6.10  	QRectF rect=model->getSelectedBranchObj()->getBBox();
    6.11  	int xmargin=50;
    6.12 @@ -490,6 +490,8 @@
    6.13  	cout << "test1:  hor="<<horizontalScrollBar()->value()<<endl;
    6.14  	cout << "test1:  ver="<<verticalScrollBar()->value()<<endl;
    6.15  }
    6.16 +
    6.17 +*/
    6.18  /*
    6.19  	 QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
    6.20  	 animation->setDuration(5000);
    6.21 @@ -542,6 +544,7 @@
    6.22  	}	
    6.23  	cout <<"  hidemode="<<hidemode<<endl;
    6.24  	*/
    6.25 +}
    6.26  	
    6.27  void MapEditor::testFunction2()
    6.28  {
     7.1 --- a/treeeditor.cpp	Sat Aug 08 21:58:26 2009 +0000
     7.2 +++ b/treeeditor.cpp	Tue Aug 18 12:39:07 2009 +0000
     7.3 @@ -1,35 +1,47 @@
     7.4  #include "treeeditor.h"
     7.5  
     7.6  #include <QAction>
     7.7 +#include <QSortFilterProxyModel>
     7.8 +#include <QRegExp>
     7.9 +
    7.10  #include <iostream>
    7.11  using namespace std;
    7.12  
    7.13  #include "vymmodel.h"
    7.14  
    7.15 +#include "mysortfilterproxymodel.h"
    7.16 +
    7.17  ///////////////////////////////////////////////////////////////////////
    7.18  ///////////////////////////////////////////////////////////////////////
    7.19  TreeEditor::TreeEditor(VymModel *m)
    7.20  {
    7.21 -	//cout << "Constructor TreeEditor "<<this<<endl;
    7.22 -	
    7.23  	model=m;
    7.24  
    7.25 +/*
    7.26 +//	MySortFilterProxyModel *proxyModel = new MySortFilterProxyModel(this);	// FIXME-0 trying to use proxy...
    7.27 +	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
    7.28 +
    7.29 +	proxyModel->setSourceModel(model);
    7.30 +
    7.31 +	proxyModel->setFilterRegExp(QRegExp("x", Qt::CaseInsensitive));
    7.32 +	proxyModel->setFilterKeyColumn(0);
    7.33 +	proxyModel->setDynamicSortFilter (true);
    7.34 +//	setModel(proxyModel);
    7.35 +*/
    7.36 +	setModel(model);
    7.37 +
    7.38  	QAction *a;
    7.39  	// Shortcuts for navigating with cursor:
    7.40      a = new QAction(tr( "Select upper object","Tree Editor" ), this);
    7.41  	a->setStatusTip ( tr( "Select upper object" ));
    7.42  	a->setShortcut (Qt::Key_Up );
    7.43 -//	a->setShortcutContext (Qt::WindowShortcut);
    7.44  	a->setShortcutContext (Qt::WidgetShortcut);
    7.45 -//	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
    7.46  	addAction (a);
    7.47      connect( a, SIGNAL( triggered() ), this, SLOT( cursorUp() ) );
    7.48  
    7.49      a = new QAction( tr( "Select lower object","Tree Editor" ),this);
    7.50  	a->setStatusTip (tr( "Select lower object" ));
    7.51  	a->setShortcut ( Qt::Key_Down );
    7.52 -//	a->setShortcutContext (Qt::WindowShortcut);
    7.53 -//	a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
    7.54  	a->setShortcutContext (Qt::WidgetShortcut);
    7.55  	addAction (a);
    7.56      connect( a, SIGNAL( triggered() ), this, SLOT( cursorDown() ) );
     8.1 --- a/treeeditor.h	Sat Aug 08 21:58:26 2009 +0000
     8.2 +++ b/treeeditor.h	Tue Aug 18 12:39:07 2009 +0000
     8.3 @@ -22,6 +22,7 @@
     8.4  
     8.5  private:
     8.6  	VymModel *model;
     8.7 +	VymModel *proxyModel;
     8.8  };
     8.9  
    8.10  #endif
     9.1 --- a/treeitem.cpp	Sat Aug 08 21:58:26 2009 +0000
     9.2 +++ b/treeitem.cpp	Tue Aug 18 12:39:07 2009 +0000
     9.3 @@ -13,7 +13,7 @@
     9.4  
     9.5  TreeItem::TreeItem()
     9.6  {
     9.7 -	//cout << "Constr. TI\n";
     9.8 +	//cout << "Constr. TI  this="<<this<<endl;
     9.9  	init();
    9.10  	itemData.clear();
    9.11  	rootItem=this;
    9.12 @@ -47,6 +47,12 @@
    9.13  			case TreeItem::Branch:
    9.14  				delete (BranchItem*)ti;
    9.15  				break;
    9.16 +			case TreeItem::Image:
    9.17 +				delete (ImageItem*)ti;
    9.18 +				break;
    9.19 +			case TreeItem::Attribute:
    9.20 +				delete (AttributeItem*)ti;
    9.21 +				break;
    9.22  			default:
    9.23  				delete ti;
    9.24  				break;
    9.25 @@ -59,12 +65,6 @@
    9.26  {
    9.27  	model=NULL;
    9.28  
    9.29 -    parentItem = NULL;
    9.30 -    itemData.clear();
    9.31 -	QList<QVariant> cData;
    9.32 -	itemData<< "VM:addMapCenter" << "undef"<<"undef";
    9.33 -
    9.34 -
    9.35  	branchOffset=0;
    9.36  	branchCounter=0;
    9.37  
    9.38 @@ -148,6 +148,12 @@
    9.39  		// branches are on bottom of list
    9.40  		childItems.append(item);
    9.41  		branchCounter++;
    9.42 +
    9.43 +		// Set correct type		//FIXME-3 DUP in constr branchitem
    9.44 +		if (this==rootItem)
    9.45 +			item->setType(MapCenter);
    9.46 +		else
    9.47 +			item->setType (Branch);
    9.48  	}
    9.49  }
    9.50  
    9.51 @@ -175,14 +181,17 @@
    9.52  	}
    9.53  }
    9.54  
    9.55 -void TreeItem::removeChildBranches()
    9.56 +/*
    9.57 +void TreeItem::clear()	// FIXME-2 used in vymmodel addMapInsert, but needs to be used via model and emit layout changes...
    9.58  {
    9.59 +	cout << "TI::clear\n";
    9.60  	while ( childItems.size()>0)
    9.61  	{
    9.62  		branchCounter--;
    9.63  		childItems.removeAt (0);
    9.64  	}
    9.65  }
    9.66 +*/
    9.67  
    9.68  TreeItem *TreeItem::child(int row)
    9.69  {
    9.70 @@ -233,6 +242,7 @@
    9.71      if (parentItem)
    9.72          return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
    9.73  
    9.74 +	cout << "TI::row() pI=NULL this="<<this<<"  ***************\n";
    9.75      return 0;
    9.76  }
    9.77  
    9.78 @@ -298,7 +308,7 @@
    9.79  
    9.80  TreeItem::Type TreeItem::getType()
    9.81  {
    9.82 -	if (type==Branch && depth()==0) return MapCenter;
    9.83 +	if (type==Branch && depth()==0) return MapCenter;	//FIXME-2 should not be necesssary
    9.84  	return type;
    9.85  }
    9.86  
    9.87 @@ -316,6 +326,7 @@
    9.88  		case MapCenter: return QString ("MapCenter");
    9.89  		case Branch: return QString ("Branch");
    9.90  		case Image: return QString ("Image");
    9.91 +		case Attribute: return QString ("Attribute");
    9.92  		default: return QString ("TreeItem::getTypeName no typename defined?!");
    9.93  	}
    9.94  }
    10.1 --- a/treeitem.h	Sat Aug 08 21:58:26 2009 +0000
    10.2 +++ b/treeitem.h	Tue Aug 18 12:39:07 2009 +0000
    10.3 @@ -39,7 +39,7 @@
    10.4  
    10.5      virtual void appendChild (TreeItem *child);
    10.6  	virtual void removeChild (int row);
    10.7 -	virtual void removeChildBranches ();
    10.8 +//	virtual void clear();
    10.9  
   10.10      virtual TreeItem *child(int row);
   10.11      virtual int childCount() const;
    11.1 --- a/treemodel.cpp	Sat Aug 08 21:58:26 2009 +0000
    11.2 +++ b/treemodel.cpp	Tue Aug 18 12:39:07 2009 +0000
    11.3 @@ -3,9 +3,10 @@
    11.4  #include <iostream>
    11.5  using namespace std;
    11.6  
    11.7 +#include "attributeitem.h"
    11.8  #include "branchitem.h"
    11.9 +#include "imageitem.h"
   11.10  #include "treeitem.h"
   11.11 -#include "imageitem.h"
   11.12  #include "treemodel.h"
   11.13  
   11.14  TreeModel::TreeModel(QObject *parent)
   11.15 @@ -51,13 +52,33 @@
   11.16      return QVariant();
   11.17  }
   11.18  
   11.19 +QModelIndex TreeModel::index (TreeItem* ti)
   11.20 +{
   11.21 +	if (!ti->parent())
   11.22 +		return QModelIndex();
   11.23 +	else	
   11.24 +		return createIndex (ti->row(),ti->column(),ti);
   11.25 +}
   11.26 +
   11.27  QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
   11.28              const
   11.29  {
   11.30      TreeItem *parentItem;
   11.31  
   11.32      if (!parent.isValid())
   11.33 +	{	//FIXME-1
   11.34          parentItem = rootItem;
   11.35 +		/*
   11.36 +		cout << "TM::index()  no parent?! xxx\n";
   11.37 +		cout << "   row="<<row<<"  col="<<column<<endl;
   11.38 +		cout << "   parent.internal="<< parent.internalPointer()<<endl;
   11.39 +		*/
   11.40 +		//return QModelIndex();	//FIXME-0 this line is new (testing)
   11.41 +		// Somehow index is requested where parentIndex is invalid.
   11.42 +		// what's happening here...?
   11.43 +		// Check if Qt examples also return index of rootIem then...
   11.44 +
   11.45 +	}	
   11.46      else
   11.47          parentItem = getItem (parent);
   11.48  
   11.49 @@ -73,8 +94,12 @@
   11.50      if (!index.isValid())
   11.51          return QModelIndex();
   11.52  
   11.53 +	//FIXME-3 cout << "TM::parent  ri="<<rootItem<< "  row="<<index.row()<<"  col="<<index.column()<<endl;
   11.54      TreeItem *ti= getItem (index);
   11.55 +	//cout << "            ti="<<ti<<endl;
   11.56 +	//cout << "               "<<ti->getHeadingStd()<<endl;
   11.57      TreeItem *parentItem = ti->parent();
   11.58 +	//cout << "            pi="<<parentItem<<endl;
   11.59  
   11.60  	//cout << "TreeModel::parent  ti="<<ti<<" "<<ti->getHeading().toStdString()<<"  pi="<<parentItem<<"  "<<endl;
   11.61      if (parentItem == rootItem)
   11.62 @@ -192,6 +217,10 @@
   11.63      TreeItem *pi= getItem (parent);
   11.64  	TreeItem *ti;
   11.65  
   11.66 +/* FIXME-3
   11.67 +	cout << "TM::removeRows  row="<<row<<"  count="<<count<<endl;
   11.68 +	cout << "                pi="<<pi<<"  ti="<<ti<<endl;
   11.69 +*/	
   11.70  	for (int i=row; i<=last; i++)
   11.71  	{
   11.72  		ti=pi->getChildNum (row);
   11.73 @@ -207,6 +236,9 @@
   11.74  			case TreeItem::Image:
   11.75  				delete (ImageItem*)ti; 
   11.76  				break;
   11.77 +			case TreeItem::Attribute:
   11.78 +				delete (AttributeItem*)ti; 
   11.79 +				break;
   11.80  			default:
   11.81  				delete ti;
   11.82  				break;
   11.83 @@ -217,9 +249,11 @@
   11.84  
   11.85  TreeItem *TreeModel::getItem(const QModelIndex &index) const
   11.86  {
   11.87 +//FIXME-3	cout << "TM::getItem  "<<index.internalPointer()<<endl;
   11.88      if (index.isValid()) {
   11.89  		TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
   11.90  
   11.91 +//		cout << "   item="<<item<<endl;
   11.92          if (item) return item;
   11.93      }
   11.94      return rootItem;
   11.95 @@ -230,8 +264,3 @@
   11.96  	return rootItem;
   11.97  }
   11.98  
   11.99 -QModelIndex TreeModel::index (TreeItem* ti)
  11.100 -{
  11.101 -	return createIndex (ti->row(),ti->column(),ti);
  11.102 -}
  11.103 -
    12.1 --- a/treemodel.h	Sat Aug 08 21:58:26 2009 +0000
    12.2 +++ b/treemodel.h	Tue Aug 18 12:39:07 2009 +0000
    12.3 @@ -22,6 +22,7 @@
    12.4      Qt::ItemFlags flags(const QModelIndex &index) const;
    12.5      QVariant headerData(int section, Qt::Orientation orientation,
    12.6                          int role = Qt::DisplayRole) const;
    12.7 +	QModelIndex index (TreeItem* ti);
    12.8      QModelIndex index(int row, int column,
    12.9                        const QModelIndex &parent = QModelIndex()) const;
   12.10      QModelIndex parent(const QModelIndex &index) const;
   12.11 @@ -35,7 +36,6 @@
   12.12  
   12.13  	TreeItem* getItem (const QModelIndex &index) const;
   12.14  	TreeItem* getRootItem();
   12.15 -	QModelIndex index (TreeItem* ti);
   12.16  
   12.17  
   12.18  protected:
    13.1 --- a/vym.pro	Sat Aug 08 21:58:26 2009 +0000
    13.2 +++ b/vym.pro	Tue Aug 18 12:39:07 2009 +0000
    13.3 @@ -69,6 +69,7 @@
    13.4  	mapitem.h \
    13.5  	mapobj.h \
    13.6  	misc.h \
    13.7 +	mysortfilterproxymodel.h \
    13.8  	noteobj.h \
    13.9  	options.h \
   13.10  	ornamentedobj.h \
   13.11 @@ -132,6 +133,7 @@
   13.12  	mapitem.cpp \
   13.13  	mapobj.cpp \
   13.14  	misc.cpp \
   13.15 +	mysortfilterproxymodel.cpp \
   13.16  	noteobj.cpp \
   13.17  	options.cpp \
   13.18  	ornamentedobj.cpp \
    14.1 --- a/vymmodel.cpp	Sat Aug 08 21:58:26 2009 +0000
    14.2 +++ b/vymmodel.cpp	Tue Aug 18 12:39:07 2009 +0000
    14.3 @@ -241,22 +241,29 @@
    14.4  	// Find the used flags while traversing the tree	// FIXME-2 this can be done local to vymmodel maybe...
    14.5  	standardFlagsMaster->resetUsedCounter();
    14.6  	
    14.7 -	// Reset the counters before saving
    14.8 -	// TODO constr. of FIO creates lots of objects, better do this in some other way...
    14.9 -	ImageItem().resetSaveCounter();// FIXME-2 this can be done local to vymmodel maybe...
   14.10 -
   14.11  	// Build xml recursivly
   14.12 -	if (!saveSel || saveSel->getType()==TreeItem::MapCenter)
   14.13 +	if (!saveSel)
   14.14  		// Save all mapcenters as complete map, if saveSel not set
   14.15  		s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
   14.16  	else
   14.17  	{
   14.18 -		if (saveSel->isBranchLikeType())
   14.19 -			// Save Subtree
   14.20 -			s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
   14.21 -		//FIXME-2 else if (saveSel->getType()==TreeItem::Image)
   14.22 -			// Save image
   14.23 -			//s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix);
   14.24 +		switch (saveSel->getType())
   14.25 +		{
   14.26 +			case TreeItem::Branch:
   14.27 +				// Save Subtree
   14.28 +				s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
   14.29 +				break;
   14.30 +			case TreeItem::MapCenter:
   14.31 +				// Save Subtree
   14.32 +				s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset);
   14.33 +				break;
   14.34 +			case TreeItem::Image:
   14.35 +				// Save Image
   14.36 +				s+=((ImageItem*)saveSel)->saveToDir(tmpdir,prefix);
   14.37 +				break;
   14.38 +			default://FIXME-4 other types shouldn't be safed...
   14.39 +				break;
   14.40 +		}
   14.41  	}
   14.42  
   14.43  	// Save local settings
   14.44 @@ -673,42 +680,55 @@
   14.45  		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
   14.46  }
   14.47  
   14.48 -void VymModel::addMapInsertInt (const QString &path, int pos)
   14.49 -{
   14.50 -/* FIXME-2  addMapInsertInt not ported yet
   14.51 -	BranchObj *sel=getSelectedBranch();
   14.52 -	if (sel)
   14.53 +bool VymModel::addMapInsertInt (const QString &path)
   14.54 +{
   14.55 +	QString pathDir=path.left(path.findRev("/"));
   14.56 +	QDir d(pathDir);
   14.57 +	QFile file (path);
   14.58 +
   14.59 +	if (d.exists() )
   14.60  	{
   14.61 -		QString pathDir=path.left(path.findRev("/"));
   14.62 -		QDir d(pathDir);
   14.63 -		QFile file (path);
   14.64 -
   14.65 -		if (d.exists() )
   14.66 +		// We need to parse saved XML data
   14.67 +		parseVYMHandler handler;
   14.68 +		QXmlInputSource source( file);
   14.69 +		QXmlSimpleReader reader;
   14.70 +		reader.setContentHandler( &handler );
   14.71 +		reader.setErrorHandler( &handler );
   14.72 +		handler.setModel (this);
   14.73 +		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
   14.74 +		handler.setLoadMode (ImportAdd);
   14.75 +		blockReposition=true;
   14.76 +		bool ok = reader.parse( source );
   14.77 +		blockReposition=false;
   14.78 +		if ( ok ) return true;
   14.79 +		{	
   14.80 +			// This should never ever happen
   14.81 +			QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
   14.82 +									handler.errorProtocol());
   14.83 +		}
   14.84 +	} else	
   14.85 +		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
   14.86 +	return false;
   14.87 +}
   14.88 +
   14.89 +bool VymModel::addMapInsertInt (const QString &path, int pos)
   14.90 +{
   14.91 +	BranchItem *selbi=getSelectedBranch();
   14.92 +	if (selbi)
   14.93 +	{
   14.94 +		if (addMapInsertInt (path))
   14.95  		{
   14.96 -			// We need to parse saved XML data
   14.97 -			parseVYMHandler handler;
   14.98 -			QXmlInputSource source( file);
   14.99 -			QXmlSimpleReader reader;
  14.100 -			reader.setContentHandler( &handler );
  14.101 -			reader.setErrorHandler( &handler );
  14.102 -			handler.setModel (this);
  14.103 -			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
  14.104 -			handler.setLoadMode (ImportAdd);
  14.105 -			blockReposition=true;
  14.106 -			bool ok = reader.parse( source );
  14.107 -			blockReposition=false;
  14.108 -			if (! ok ) 
  14.109 -			{	
  14.110 -				// This should never ever happen
  14.111 -				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
  14.112 -										handler.errorProtocol());
  14.113 -			}
  14.114 -			if (sel->getDepth()>0)
  14.115 -				sel->getLastBranch()->linkTo (sel,pos);
  14.116 -		} else	
  14.117 +			if (selbi->depth()>0)
  14.118 +				relinkBranch (selbi->getLastBranch(), selbi,pos);
  14.119 +			return true;	
  14.120 +		} else
  14.121 +		{
  14.122  			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
  14.123 +			return false;
  14.124 +		}	
  14.125  	}		
  14.126 -*/
  14.127 +	qWarning ("ME::addMapInsertInt nothing selected");
  14.128 +	return false;
  14.129  }
  14.130  
  14.131  ImageItem* VymModel::loadFloatImageInt (BranchItem *dst,QString fn)
  14.132 @@ -1013,11 +1033,7 @@
  14.133  	s=ti->getHeading();
  14.134  	if (s=="") s="unnamed";
  14.135  
  14.136 -	if (ti->isBranchLikeType() )	//FIXME-3 shouldnt there also be mapcenter??
  14.137 -		return QString("branch (%1)").arg(s);
  14.138 -	if (ti->getType()==TreeItem::Image)
  14.139 -		return QString ("image (%1)").arg(ti->getHeading());
  14.140 -	return QString("Unknown type has no name!");
  14.141 +	return QString ("%1 (%2)").arg(ti->getTypeName()).arg(s);
  14.142  }
  14.143  
  14.144  void VymModel::redo()
  14.145 @@ -1128,8 +1144,7 @@
  14.146  	QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
  14.147  
  14.148  	// select  object before undo
  14.149 -	if (!undoSelection.isEmpty())
  14.150 -		select (undoSelection);
  14.151 +	select (undoSelection);
  14.152  
  14.153  	if (debug)
  14.154  	{
  14.155 @@ -1155,7 +1170,7 @@
  14.156  	redosAvail++;
  14.157  
  14.158  	blockSaveState=blockSaveStateOrg;
  14.159 -/* TODO remove testing
  14.160 +/* testing only
  14.161  	cout << "VymModel::undo() end\n";
  14.162  	cout << "    undosAvail="<<undosAvail<<endl;
  14.163  	cout << "    redosAvail="<<redosAvail<<endl;
  14.164 @@ -1327,10 +1342,11 @@
  14.165  		qWarning ("VymModel::saveStateRemovingPart  no redoSel given!");
  14.166  		return;
  14.167  	}
  14.168 -	QString undoSelection=getSelectString (redoSel->parent() );
  14.169 +	QString undoSelection;
  14.170  	QString redoSelection=getSelectString(redoSel);
  14.171  	if (redoSel->getType()==TreeItem::Branch) 
  14.172  	{
  14.173 +		undoSelection=getSelectString (redoSel->parent());
  14.174  		// save the selected branch of the map, Undo will insert part of map 
  14.175  		saveState (PartOfMap,
  14.176  			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->num()),
  14.177 @@ -1338,6 +1354,15 @@
  14.178  			comment, 
  14.179  			redoSel);
  14.180  	}
  14.181 +	if (redoSel->getType()==TreeItem::MapCenter) 
  14.182 +	{
  14.183 +		// save the selected branch of the map, Undo will insert part of map 
  14.184 +		saveState (PartOfMap,
  14.185 +			undoSelection, QString("addMapInsert (\"PATH\")"),
  14.186 +			redoSelection, "delete ()", 
  14.187 +			comment, 
  14.188 +			redoSel);
  14.189 +	}
  14.190  }
  14.191  
  14.192  
  14.193 @@ -1983,10 +2008,10 @@
  14.194  	return NULL;
  14.195  }
  14.196  
  14.197 -AttributeItem* VymModel::addAttribute()
  14.198 -{
  14.199 -	TreeItem *selti=getSelectedItem();
  14.200 -	if (selti)
  14.201 +AttributeItem* VymModel::addAttribute()	// FIXME-2 savestate missing
  14.202 +{
  14.203 +	BranchItem *selbi=getSelectedBranch();
  14.204 +	if (selbi)
  14.205  	{
  14.206  		QList<QVariant> cData;
  14.207  		cData << "new attribute" << "undef"<<"undef";
  14.208 @@ -1994,10 +2019,10 @@
  14.209  
  14.210  		emit (layoutAboutToBeChanged() );
  14.211  
  14.212 -		QModelIndex parix=index(selti);
  14.213 -		int n=selti->getRowNumAppend (a);
  14.214 +		QModelIndex parix=index(selbi);
  14.215 +		int n=selbi->getRowNumAppend (a);
  14.216  		beginInsertRows (parix,n,n+1);	
  14.217 -		selti->appendChild (a);	
  14.218 +		selbi->appendChild (a);	
  14.219  		endInsertRows ();
  14.220  
  14.221  		emit (layoutChanged() );
  14.222 @@ -2037,7 +2062,7 @@
  14.223  
  14.224  	QList<QVariant> cData;
  14.225  	cData << "VM:addMapCenter" << "undef"<<"undef";
  14.226 -	BranchItem *newbi=new BranchItem (cData);
  14.227 +	BranchItem *newbi=new BranchItem (cData,rootItem);
  14.228  	newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
  14.229  	rootItem->appendChild (newbi);
  14.230  
  14.231 @@ -2197,6 +2222,10 @@
  14.232  		dst->insertBranch (pos,branch);
  14.233  		endInsertRows();
  14.234  
  14.235 +		// Correct type if necessesary
  14.236 +		if (branch->getType()==TreeItem::MapCenter) 
  14.237 +			branch->setType(TreeItem::Branch);
  14.238 +
  14.239  		// reset parObj, fonts, frame, etc in related LMO or other view-objects
  14.240  		branch->updateStyles();
  14.241  
  14.242 @@ -2251,11 +2280,11 @@
  14.243  	return false;
  14.244  }
  14.245  
  14.246 -void VymModel::deleteSelection()	// FIXME-2 include fix for deleted mapcenters from 1.12.4
  14.247 +void VymModel::deleteSelection()	
  14.248  {
  14.249  	BranchItem *selbi=getSelectedBranch();
  14.250  
  14.251 -	if (selbi && selbi->isBranchLikeType() )
  14.252 +	if (selbi)
  14.253  	{
  14.254  		unselect();
  14.255  		saveStateRemovingPart (selbi, QString ("Delete %1").arg(getObjectName(selbi)));
  14.256 @@ -2268,7 +2297,7 @@
  14.257  		}
  14.258  		return;
  14.259  	}
  14.260 -	TreeItem *ti=getSelectedImage();
  14.261 +	TreeItem *ti=getSelectedItem();
  14.262  	if (ti->getType()==TreeItem::Image || ti->getType()==TreeItem::Attribute)
  14.263  	{
  14.264  		TreeItem *pi=ti->parent();
  14.265 @@ -2378,7 +2407,7 @@
  14.266  		reposition();
  14.267  
  14.268  		emit (layoutChanged() );
  14.269 -		if (pi->depth()>0) return pi;
  14.270 +		if (pi->depth()>=0) return pi;
  14.271  	}	
  14.272  	return NULL;
  14.273  }
  14.274 @@ -2873,22 +2902,29 @@
  14.275  	/////////////////////////////////////////////////////////////////////
  14.276  	} else if (com==QString("addMapInsert"))
  14.277  	{
  14.278 -		if (!selti)
  14.279 +		if (parser.parCount()==2)
  14.280  		{
  14.281 -			parser.setError (Aborted,"Nothing selected");
  14.282 -		} else if (! selbi )
  14.283 -		{				  
  14.284 -			parser.setError (Aborted,"Type of selection is not a branch");
  14.285 -		} else 
  14.286 -		{	
  14.287 -			if (parser.checkParCount(2))
  14.288 +
  14.289 +			if (!selti)
  14.290  			{
  14.291 +				parser.setError (Aborted,"Nothing selected");
  14.292 +			} else if (! selbi )
  14.293 +			{				  
  14.294 +				parser.setError (Aborted,"Type of selection is not a branch");
  14.295 +			} else 
  14.296 +			{	
  14.297  				t=parser.parString (ok,0);	// path to map
  14.298  				n=parser.parInt(ok,1);		// position
  14.299  				if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
  14.300  				addMapInsertInt(t,n);	
  14.301  			}
  14.302 -		}
  14.303 +		} else if (parser.parCount()==1)
  14.304 +		{
  14.305 +			t=parser.parString (ok,0);	// path to map
  14.306 +			if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
  14.307 +			addMapInsertInt(t);	
  14.308 +		} else
  14.309 +			parser.setError (Aborted,"Wrong number of parameters");
  14.310  	/////////////////////////////////////////////////////////////////////
  14.311  	} else if (com=="clearFlags")	
  14.312  	{
  14.313 @@ -4610,6 +4646,11 @@
  14.314  
  14.315  bool VymModel::select (const QString &s)
  14.316  {
  14.317 +	if (s.isEmpty())
  14.318 +	{
  14.319 +		unselect();
  14.320 +		return true;
  14.321 +	}
  14.322  	TreeItem *ti=findBySelectString(s);
  14.323  	if (ti) return select (index(ti));
  14.324  	return false;
    15.1 --- a/vymmodel.h	Sat Aug 08 21:58:26 2009 +0000
    15.2 +++ b/vymmodel.h	Tue Aug 18 12:39:07 2009 +0000
    15.3 @@ -111,7 +111,8 @@
    15.4  
    15.5  private:
    15.6      void addMapReplaceInt(const QString & undoSel, const QString & path);
    15.7 -    void addMapInsertInt (const QString & path, int pos);
    15.8 +    bool addMapInsertInt (const QString & path);
    15.9 +    bool addMapInsertInt (const QString & path, int pos);
   15.10  
   15.11  	ImageItem* loadFloatImageInt (BranchItem *dst,QString);
   15.12  	void saveFloatImageInt (ImageItem*, const QString &, const QString &);
    16.1 --- a/vymview.cpp	Sat Aug 08 21:58:26 2009 +0000
    16.2 +++ b/vymview.cpp	Tue Aug 18 12:39:07 2009 +0000
    16.3 @@ -16,11 +16,13 @@
    16.4  
    16.5  	// Create TreeView
    16.6  	treeEditor=new TreeEditor (model);
    16.7 -	treeEditor->setModel ((QAbstractItemModel*)model);
    16.8 +	//treeEditor->setModel ((QAbstractItemModel*)model);
    16.9  	//treeEditor->setMinimumWidth (50);
   16.10  
   16.11 -	treeEditor->setColumnWidth (0,350);
   16.12 +	treeEditor->setColumnWidth (0,150);
   16.13 +	treeEditor->setAnimated (true);
   16.14  
   16.15 +	
   16.16  	selModel=treeEditor->selectionModel();
   16.17  	model->setSelectionModel (selModel);
   16.18  	connect (
   16.19 @@ -66,10 +68,22 @@
   16.20  	addWidget (treeEditor);
   16.21  	addWidget (mapEditor);
   16.22  
   16.23 +/*
   16.24 +	tv=new QTreeView;
   16.25 +	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
   16.26 +	proxyModel->setDynamicSortFilter (true);
   16.27 +	proxyModel->setSourceModel(model);
   16.28 +	//proxyModel->setFilterFixedString ("a",Qt::CaseInsensitive,QRegExp::FixedString);
   16.29 +	proxyModel->setFilterRegExp(QRegExp("e", Qt::CaseInsensitive));
   16.30 +	proxyModel->setFilterKeyColumn(0);
   16.31 +	tv->setModel (proxyModel);
   16.32 +	addWidget (tv);
   16.33 +*/
   16.34  	// Set geometry
   16.35  	QList <int> widths;
   16.36 -	widths<<120;
   16.37 +	widths<<200;
   16.38  	widths<<600;
   16.39 +//	widths<<200;
   16.40  	setSizes(widths);
   16.41  }
   16.42  
   16.43 @@ -114,6 +128,7 @@
   16.44  void VymView::expandAll()
   16.45  {
   16.46  	treeEditor->expandAll();
   16.47 +	//tv->expandAll();
   16.48  }
   16.49  
   16.50  void VymView::showSelection()
    17.1 --- a/vymview.h	Sat Aug 08 21:58:26 2009 +0000
    17.2 +++ b/vymview.h	Tue Aug 18 12:39:07 2009 +0000
    17.3 @@ -9,6 +9,7 @@
    17.4  class MapEditor;
    17.5  class TreeEditor;
    17.6  
    17.7 +class QTreeView;
    17.8  
    17.9  class VymView : public QSplitter 
   17.10  {
   17.11 @@ -29,6 +30,7 @@
   17.12  private:
   17.13  	VymModel *model;
   17.14  	TreeEditor *treeEditor;
   17.15 +	QTreeView *tv;	//FIXME-3 testing only
   17.16  	QItemSelectionModel *selModel;
   17.17  	MapEditor *mapEditor;
   17.18  };
    18.1 --- a/xml-vym.cpp	Sat Aug 08 21:58:26 2009 +0000
    18.2 +++ b/xml-vym.cpp	Tue Aug 18 12:39:07 2009 +0000
    18.3 @@ -139,13 +139,12 @@
    18.4  		if (loadMode==NewMap)
    18.5  		{	
    18.6  			// Really use the found mapcenter as MCO in a new map
    18.7 -
    18.8  			lastBranch=model->createMapCenter(); 
    18.9  		} else
   18.10  		{
   18.11  			// Treat the found mapcenter as a branch 
   18.12  			// in an existing map
   18.13 -			BranchItem *bi=model->getSelectedBranch();	//FIXME-3 selection is no longer used here...
   18.14 +			BranchItem *bi=model->getSelectedBranch();	//FIXME-3 selection is no longer used here... //FIXME-2 really? we are adding to a map...
   18.15  			if (bi)
   18.16  			{
   18.17  				lastBranch=bi;
   18.18 @@ -153,10 +152,11 @@
   18.19  				{
   18.20  					lastBranch=model->createBranch(lastBranch);
   18.21  				} //else
   18.22 -					//FIXME-3 lastBranch->clear();
   18.23 +					//lastBranch->clear(); //FIXME-1 clear not really defined!
   18.24  			} else
   18.25 -				return false;
   18.26 -		}
   18.27 +				// add mapCenter without parent
   18.28 +				lastBranch=model->createMapCenter(); 
   18.29 +		}		
   18.30  		readBranchAttr (atts);
   18.31  	} else if ( 
   18.32  		(eName == "standardflag" ||eName == "standardFlag") && 
   18.33 @@ -438,7 +438,7 @@
   18.34  					return false;   // Couldn't read relPos
   18.35  			}           
   18.36  		}           
   18.37 -		if (!a.value( "absPosX").isEmpty() && loadMode==NewMap ) 
   18.38 +		if (!a.value( "absPosX").isEmpty() ) 
   18.39  		{
   18.40  			if (!a.value( "absPosY").isEmpty() ) 
   18.41  			{