relinking branches and removing branches works
authorinsilmaril
Mon, 27 Apr 2009 12:07:15 +0000
changeset 756a8a5c7288f57
parent 755 ed5b407975b3
child 757 c6908bc17d78
relinking branches and removing branches works
branchitem.cpp
branchitem.h
branchobj.cpp
mainwindow.cpp
mapcenteritem.h
mapeditor.cpp
treeitem.cpp
treeitem.h
treemodel.cpp
version.h
vymmodel.cpp
xml-vym.cpp
     1.1 --- a/branchitem.cpp	Thu Apr 23 12:15:31 2009 +0000
     1.2 +++ b/branchitem.cpp	Mon Apr 27 12:07:15 2009 +0000
     1.3 @@ -17,8 +17,12 @@
     1.4  
     1.5  BranchItem::~BranchItem()
     1.6  {
     1.7 -	cout << "Destr. BranchItem\n";
     1.8 -    qDeleteAll(childItems);
     1.9 +//	cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
    1.10 +	if (lmo) 
    1.11 +	{
    1.12 +		delete lmo;
    1.13 +		lmo=NULL;
    1.14 +	}
    1.15  }
    1.16  
    1.17  void BranchItem::copy (BranchItem *other)
    1.18 @@ -27,6 +31,19 @@
    1.19  	tmpUnscrolled=other->tmpUnscrolled;
    1.20  }
    1.21  
    1.22 +void BranchItem::insertBranch (int pos, BranchItem *branch)
    1.23 +{
    1.24 +	if (pos<0) pos=0;
    1.25 +	if (pos>branchCounter) pos=branchCounter;
    1.26 +    childItems.insert(pos+branchOffset,branch);
    1.27 +	branch->parentItem=this;
    1.28 +	branch->setModel (model);
    1.29 +
    1.30 +	if (branchCounter==0)
    1.31 +		branchOffset=childItems.count()-1;
    1.32 +	branchCounter++;
    1.33 +}
    1.34 +
    1.35  QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
    1.36  {
    1.37  	// Cloudy stuff can be hidden during exports
    1.38 @@ -310,12 +327,11 @@
    1.39  BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)	
    1.40  {
    1.41  	// Initialize BranchObj, order of things is important...
    1.42 -	cout << "BI::createMO scene="<<scene<<endl;
    1.43      BranchObj* newbo=new BranchObj(scene);
    1.44      newbo->setParObj(parent()->getLMO() );
    1.45  	newbo->setTreeItem (this);
    1.46  	newbo->setDefAttr(BranchObj::NewBranch);
    1.47 -	//newbo->updateLink();
    1.48 +	//newbo->updateLink();	//FIXME-3
    1.49  
    1.50  	lmo=newbo;
    1.51  	return newbo;
     2.1 --- a/branchitem.h	Thu Apr 23 12:15:31 2009 +0000
     2.2 +++ b/branchitem.h	Mon Apr 27 12:07:15 2009 +0000
     2.3 @@ -12,11 +12,14 @@
     2.4  {
     2.5  public:
     2.6      BranchItem(const QList<QVariant> &data, TreeItem *parent = 0);
     2.7 -    ~BranchItem();
     2.8 +    virtual ~BranchItem();
     2.9  	void copy (BranchItem *item);
    2.10  
    2.11 +	void insertBranch (int pos,BranchItem *branch);
    2.12 +
    2.13  	QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset);
    2.14  
    2.15 +	
    2.16  	virtual void updateVisibility();
    2.17  
    2.18  protected:
     3.1 --- a/branchobj.cpp	Thu Apr 23 12:15:31 2009 +0000
     3.2 +++ b/branchobj.cpp	Mon Apr 27 12:07:15 2009 +0000
     3.3 @@ -430,7 +430,6 @@
     3.4  		qWarning ("BranchObj::udpateHeading treeItem==NULL");
     3.5  		return;
     3.6  	}
     3.7 -	cout << "BO::updateHeading: "<<treeItem->getHeading().toStdString()<<endl;
     3.8  	heading->setText (treeItem->getHeading() );
     3.9  	updateContentSize();
    3.10  }
     4.1 --- a/mainwindow.cpp	Thu Apr 23 12:15:31 2009 +0000
     4.2 +++ b/mainwindow.cpp	Mon Apr 27 12:07:15 2009 +0000
     4.3 @@ -2252,7 +2252,7 @@
     4.4  	if (m) m->exportASCII();
     4.5  }
     4.6  
     4.7 -void Main::fileExportCSV()	//FIXME-2 not scriptable yet
     4.8 +void Main::fileExportCSV()	//FIXME-3 not scriptable yet
     4.9  {
    4.10  	VymModel *m=currentModel();
    4.11  	if (m)
    4.12 @@ -2271,7 +2271,7 @@
    4.13  	}
    4.14  }
    4.15  
    4.16 -void Main::fileExportLaTeX()	//FIXME-2 not scriptable yet
    4.17 +void Main::fileExportLaTeX()	//FIXME-3 not scriptable yet
    4.18  {
    4.19  	VymModel *m=currentModel();
    4.20  	if (m)
    4.21 @@ -2290,7 +2290,7 @@
    4.22  	}
    4.23  }
    4.24  
    4.25 -void Main::fileExportKDE3Bookmarks()	//FIXME-2 not scriptable yet
    4.26 +void Main::fileExportKDE3Bookmarks()	//FIXME-3 not scriptable yet
    4.27  {
    4.28  	ExportKDE3Bookmarks ex;
    4.29  	VymModel *m=currentModel();
    4.30 @@ -2301,7 +2301,7 @@
    4.31  	}	
    4.32  }
    4.33  
    4.34 -void Main::fileExportKDE4Bookmarks()	//FIXME-2 not scriptable yet
    4.35 +void Main::fileExportKDE4Bookmarks()	//FIXME-3 not scriptable yet
    4.36  {
    4.37  	ExportKDE4Bookmarks ex;
    4.38  	VymModel *m=currentModel();
    4.39 @@ -2312,7 +2312,7 @@
    4.40  	}	
    4.41  }
    4.42  
    4.43 -void Main::fileExportTaskjuggler()	//FIXME-2 not scriptable yet
    4.44 +void Main::fileExportTaskjuggler()	//FIXME-3 not scriptable yet
    4.45  {
    4.46  	ExportTaskjuggler ex;
    4.47  	VymModel *m=currentModel();
    4.48 @@ -2331,7 +2331,7 @@
    4.49  	}	
    4.50  }
    4.51  
    4.52 -void Main::fileExportOOPresentation()	//FIXME-2 not scriptable yet
    4.53 +void Main::fileExportOOPresentation()	//FIXME-3 not scriptable yet
    4.54  {
    4.55  	ExportOOFileDialog *fd=new ExportOOFileDialog( this,vymName+" - "+tr("Export to")+" Open Office");
    4.56  	// TODO add preview in dialog
     5.1 --- a/mapcenteritem.h	Thu Apr 23 12:15:31 2009 +0000
     5.2 +++ b/mapcenteritem.h	Mon Apr 27 12:07:15 2009 +0000
     5.3 @@ -8,7 +8,7 @@
     5.4  {
     5.5  public:
     5.6      MapCenterItem(const QList<QVariant> &data, TreeItem *parent = 0);
     5.7 -    ~MapCenterItem();
     5.8 +    virtual ~MapCenterItem();
     5.9  
    5.10  	QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset);
    5.11  };
     6.1 --- a/mapeditor.cpp	Thu Apr 23 12:15:31 2009 +0000
     6.2 +++ b/mapeditor.cpp	Mon Apr 27 12:07:15 2009 +0000
     6.3 @@ -918,17 +918,19 @@
     6.4  				if (e->state() & Qt::ShiftModifier && dst->getParObj())
     6.5  				{	// Link above dst
     6.6  					preDstParStr=model->getSelectString (dst->getParObj());
     6.7 -					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), seli->num());
     6.8 +					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), seli->num());	//FIXME-2 not needed
     6.9 +					model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)dsti)->num());
    6.10  				} else 
    6.11  				if (e->state() & Qt::ControlModifier && dst->getParObj())
    6.12  				{
    6.13  					// Link below dst
    6.14  					preDstParStr=model->getSelectString (dst->getParObj());
    6.15 -					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), seli->num()+1);
    6.16 +					bsel->linkTo ( (BranchObj*)(bdst->getParObj()), seli->num()+1);//FIXME-2 not needed
    6.17 +					model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti->parent(),((BranchItem*)seli)->num()+1);
    6.18  				} else	
    6.19  				{	// Append to dst
    6.20  					preDstParStr=model->getSelectString(dst);
    6.21 -					bsel->linkTo (bdst,-1);
    6.22 +					bsel->linkTo (bdst,-1);//FIXME-2 not needed
    6.23  					model->relinkBranch ((BranchItem*)seli,(BranchItem*)dsti);
    6.24  					if (dsti->depth()==0) bsel->move (savePos);
    6.25  				} 
    6.26 @@ -955,7 +957,6 @@
    6.27  
    6.28  				if (seli->depth()==1)
    6.29  				{
    6.30 -					cout << "ME::releaseMouse d=1\n"; // FIXME_1    better use depth
    6.31  					// The select string might be different _after_ moving around.
    6.32  					// Therefor reposition and then use string of old selection, too
    6.33  					model->reposition();
     7.1 --- a/treeitem.cpp	Thu Apr 23 12:15:31 2009 +0000
     7.2 +++ b/treeitem.cpp	Mon Apr 27 12:07:15 2009 +0000
     7.3 @@ -11,11 +11,41 @@
     7.4  
     7.5  TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
     7.6  {
     7.7 +	init();
     7.8 +    parentItem = parent;
     7.9 +    itemData = data;
    7.10 +}
    7.11 +
    7.12 +TreeItem::~TreeItem()
    7.13 +{
    7.14 +	//cout << "Destructor TreeItem "<<getHeadingStd()<<endl;
    7.15 +	TreeItem *ti;
    7.16 +	while (!childItems.isEmpty())
    7.17 +	{
    7.18 +		ti=childItems.takeFirst();
    7.19 +		switch (ti->getType() )
    7.20 +		{
    7.21 +			case TreeItem::MapCenter:
    7.22 +				delete (MapCenterItem*)ti;
    7.23 +				break;
    7.24 +			case TreeItem::Branch:
    7.25 +				delete (BranchItem*)ti;
    7.26 +				break;
    7.27 +			default:
    7.28 +				delete ti;
    7.29 +				break;
    7.30 +		}
    7.31 +	}	
    7.32 +}
    7.33 +
    7.34 +
    7.35 +void TreeItem::init()
    7.36 +{
    7.37  	model=NULL;
    7.38  
    7.39 -    parentItem = parent;
    7.40 -    itemData = data;
    7.41 -	lmo=NULL;
    7.42 +    parentItem = NULL;
    7.43 +    itemData.clear();
    7.44 +	lmo=NULL;	
    7.45  
    7.46  	branchOffset=0;
    7.47  	branchCounter=0;
    7.48 @@ -33,13 +63,6 @@
    7.49  
    7.50  }
    7.51  
    7.52 -TreeItem::~TreeItem()
    7.53 -{
    7.54 -	cout << "Destructor TreeItem\n";
    7.55 -	//if (lmo) delete (lmo);
    7.56 -    qDeleteAll(childItems);
    7.57 -}
    7.58 -
    7.59  QString TreeItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
    7.60  {
    7.61  	cout << "TreeItem::saveToDir called directly for ("<<getHeadingStd()<<"), instead of inherited type...\n";	//FIXME-1 triggered on save
    7.62 @@ -71,6 +94,7 @@
    7.63  void TreeItem::appendChild(TreeItem *item)
    7.64  {
    7.65      childItems.append(item);
    7.66 +	item->parentItem=this;
    7.67  	item->setModel (model);
    7.68  
    7.69  	if (item->type == Branch || item->type ==MapCenter)
     8.1 --- a/treeitem.h	Thu Apr 23 12:15:31 2009 +0000
     8.2 +++ b/treeitem.h	Mon Apr 27 12:07:15 2009 +0000
     8.3 @@ -22,6 +22,8 @@
     8.4  
     8.5      TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
     8.6      ~TreeItem();
     8.7 +	void init();
     8.8 +
     8.9  	QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset);
    8.10  
    8.11  
     9.1 --- a/treemodel.cpp	Thu Apr 23 12:15:31 2009 +0000
     9.2 +++ b/treemodel.cpp	Mon Apr 27 12:07:15 2009 +0000
     9.3 @@ -80,11 +80,8 @@
     9.4          return QModelIndex();
     9.5  
     9.6  	if (!parentItem)
     9.7 -	{
     9.8 -		cout <<"TreeModel::parent      ti=="<<ti<<"  "<<ti->getHeading().toStdString()<<endl;
     9.9          return QModelIndex();	// FIXME-3 do this to avoid segfault, but why?
    9.10  		                        // see also my question on qt-interest in march
    9.11 -	}	
    9.12  
    9.13      return createIndex(parentItem->childNumber(), 0, parentItem);
    9.14  }
    9.15 @@ -195,7 +192,18 @@
    9.16  		cout << "TreeModel::removeRows removing i="<<i<<std::endl;
    9.17  		ti=pi->getChildNum (row);
    9.18  		pi->removeChild (row);	// does not delete object!
    9.19 -		delete (ti);
    9.20 +		switch (ti->getType()) 
    9.21 +		{
    9.22 +			case TreeItem::MapCenter: 
    9.23 +				delete (BranchItem*)ti; 
    9.24 +				break;
    9.25 +			case TreeItem::Branch:
    9.26 +				delete (BranchItem*)ti; 
    9.27 +				break;
    9.28 +			default:
    9.29 +				delete ti;
    9.30 +				break;
    9.31 +		}
    9.32  	}
    9.33  	endRemoveRows ();
    9.34  	return true;
    10.1 --- a/version.h	Thu Apr 23 12:15:31 2009 +0000
    10.2 +++ b/version.h	Mon Apr 27 12:07:15 2009 +0000
    10.3 @@ -7,7 +7,7 @@
    10.4  #define __VYM_VERSION "1.13.0"
    10.5  //#define __VYM_CODENAME "Codename: RC-1"
    10.6  #define __VYM_CODENAME "Codename: development version, not for production!"
    10.7 -#define __VYM_BUILD_DATE "2009-04-23"
    10.8 +#define __VYM_BUILD_DATE "2009-04-27"
    10.9  
   10.10  
   10.11  bool checkVersion(const QString &);
    11.1 --- a/vymmodel.cpp	Thu Apr 23 12:15:31 2009 +0000
    11.2 +++ b/vymmodel.cpp	Mon Apr 27 12:07:15 2009 +0000
    11.3 @@ -176,7 +176,7 @@
    11.4  
    11.5  void VymModel::updateActions()	// FIXME-2  maybe don't update if blockReposition is set
    11.6  {
    11.7 -	cout << "VymModel::updateActions \n";
    11.8 +	//cout << "VM::updateActions \n";
    11.9  	// Tell mainwindow to update states of actions
   11.10  	mainWindow->updateActions();
   11.11  }
   11.12 @@ -984,7 +984,6 @@
   11.13  
   11.14  void VymModel::setChanged()
   11.15  {
   11.16 -	cout << "VM::setChanged()\n";
   11.17  	if (!mapChanged)
   11.18  	{
   11.19  		autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
   11.20 @@ -2071,7 +2070,6 @@
   11.21  	QList<QVariant> cData;
   11.22  	cData << "VM:addMapCenter" << "undef"<<"undef";
   11.23  	MapCenterItem *mci=new MapCenterItem (cData,rootItem);
   11.24 -	cout << "VM::addMapCenter  mci="<<mci<<endl;
   11.25  	mci->setType (TreeItem::MapCenter);
   11.26  	mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
   11.27  	rootItem->appendChild (mci);
   11.28 @@ -2142,15 +2140,15 @@
   11.29  
   11.30  			BranchItem *parbi=bi;
   11.31  			QModelIndex parix=index(parbi);
   11.32 -			int n=parbi->branchCount();
   11.33 +			int n=parbi->childCount();
   11.34  
   11.35  			emit (layoutAboutToBeChanged() );
   11.36 -			beginInsertRows (parix,n,n+1);
   11.37 -			bi=new BranchItem (cData,parbi);
   11.38 +			beginInsertRows (parix,n,n+1);	//FIXME-1 check if n is correct: should be index below _last_ branch...
   11.39 +			bi=new BranchItem (cData);	
   11.40  			bi->setType (TreeItem::Branch);
   11.41  			bi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
   11.42  
   11.43 -			parbi->appendChild (bi);
   11.44 +			parbi->appendChild (bi);	
   11.45  			endInsertRows ();
   11.46  			emit (newChildObject (parix));
   11.47  			emit (layoutChanged() );
   11.48 @@ -2158,18 +2156,7 @@
   11.49  			// save scroll state. If scrolled, automatically select
   11.50  			// new branch in order to tmp unscroll parent...
   11.51  			newbo=bi->createMapObj(mapScene);
   11.52 -			/*
   11.53 -			newbo=bo->addBranch();
   11.54 -
   11.55 -			if (newbo)
   11.56 -			{
   11.57 -				bi->setLMO (newbo);
   11.58 -				newbo->setTreeItem (bi);
   11.59 -				select (bi); 
   11.60 -			}
   11.61 -			*/
   11.62  			select (bi);
   11.63 -			
   11.64  		}else if (num==-1)
   11.65  		{
   11.66  		/*
   11.67 @@ -2271,14 +2258,29 @@
   11.68  	cout << "VM::relinkBranch  "<<branch->getHeadingStd()<<"  to "<<dst->getHeadingStd()<<"  at pos="<<pos<<endl;
   11.69  	if (branch && dst)
   11.70  	{
   11.71 +		emit (layoutAboutToBeChanged() );
   11.72  		BranchItem *branchpi=(BranchItem*)branch->parent();
   11.73 -		BranchItem *dstpi=(BranchItem*)dst->parent();
   11.74 -		if (pos<0)
   11.75 -		{
   11.76 -			// Append as last branch to dst
   11.77 -			branchpi->removeChild (branch->childNum() );
   11.78 -			dst->appendChild (branch);
   11.79 -		}
   11.80 +		// Remove at current position
   11.81 +		int n=branch->childNum();
   11.82 +		beginRemoveRows (index(branchpi),n,n);
   11.83 +		branchpi->removeChild (n);
   11.84 +		endRemoveRows();
   11.85 +
   11.86 +		if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
   11.87 +
   11.88 +		// Append as last branch to dst
   11.89 +		if (dst->branchCount()==0)
   11.90 +			n=0;
   11.91 +		else	
   11.92 +			n=dst->getFirstBranch()->childNumber(); 
   11.93 +	cout << "***  dst->bCount="<<dst->branchCount()<<"  n="<<n<<"  pos="<<pos<<endl;		
   11.94 +		beginInsertRows (index(dst),n+pos,n+pos);
   11.95 +		dst->insertBranch (pos,branch);
   11.96 +		endInsertRows();
   11.97 +
   11.98 +		branch->getLMO()->setParObj(dst->getLMO());	//FIXME-5 update parObj in View
   11.99 +		emit (layoutChanged() );
  11.100 +		select (branch);
  11.101  	}
  11.102  }
  11.103  
  11.104 @@ -2343,7 +2345,6 @@
  11.105  		beginRemoveRows (parentIndex,n,n);
  11.106  		removeRows (n,1,parentIndex);
  11.107  		endRemoveRows();
  11.108 -		//	delete (selbi->getLMO() );	// FIXME-0 selbi is removed implicetely, destructor is called. from there BO is deleted, but somhow still segfaulting :-(
  11.109  		select (par);
  11.110  		ensureSelectionVisible();
  11.111  		reposition();
  11.112 @@ -3983,7 +3984,7 @@
  11.113  
  11.114  void VymModel::reposition()	//FIXME-2 VM should have no need to reposition, this is done in views???
  11.115  {
  11.116 -	cout << "VM::reposition ...\n";
  11.117 +	//cout << "VM::reposition ...\n";
  11.118  	for (int i=0;i<rootItem->branchCount(); i++)
  11.119  		rootItem->getBranchObjNum(i)->reposition();	//	for positioning heading
  11.120  }
    12.1 --- a/xml-vym.cpp	Thu Apr 23 12:15:31 2009 +0000
    12.2 +++ b/xml-vym.cpp	Mon Apr 27 12:07:15 2009 +0000
    12.3 @@ -356,8 +356,8 @@
    12.4  	//lastOO=lastBranch;
    12.5  	//lastBranchItem=(BranchItem*)(lastBranch->getTreeItem());
    12.6  
    12.7 +	if (!readOOAttr(a)) return false;
    12.8  /*
    12.9 -	if (!readOOAttr(a)) return false;
   12.10  
   12.11  	if (!a.value( "scrolled").isEmpty() )
   12.12  		lastBranchItem->toggleScroll();
   12.13 @@ -410,7 +410,8 @@
   12.14  
   12.15  bool parseVYMHandler::readOOAttr (const QXmlAttributes& a)
   12.16  {
   12.17 -	if (lastOO)
   12.18 +	BranchObj *bo=(BranchObj*)lastBranchItem->getLMO();
   12.19 +	if (bo)
   12.20  	{
   12.21  		bool okx,oky;
   12.22  		float x,y;
   12.23 @@ -422,8 +423,8 @@
   12.24  				y=a.value("relPosY").toFloat (&oky);
   12.25  				if (okx && oky  )
   12.26  				{
   12.27 -					lastOO->setUseRelPos (true);
   12.28 -					lastOO->move2RelPos (x,y);
   12.29 +					bo->setUseRelPos (true);
   12.30 +					bo->move2RelPos (x,y);
   12.31  				}	
   12.32  				else
   12.33  					return false;   // Couldn't read relPos
   12.34 @@ -436,11 +437,12 @@
   12.35  				x=a.value("absPosX").toFloat (&okx);
   12.36  				y=a.value("absPosY").toFloat (&oky);
   12.37  				if (okx && oky  )
   12.38 -					lastOO->move(x,y);
   12.39 +					bo->move(x,y);
   12.40  				else
   12.41  					return false;   // Couldn't read absPos
   12.42  			}           
   12.43  		}           
   12.44 +		/* FIXME-2
   12.45  		if (!a.value( "id").isEmpty() ) 
   12.46  			lastBranchItem->setID (a.value ("id"));
   12.47  		if (!a.value( "url").isEmpty() ) 
   12.48 @@ -458,6 +460,7 @@
   12.49  			else	
   12.50  				lastOO->setHideLinkUnselected(false);
   12.51  		}	
   12.52 +		*/
   12.53  	}
   12.54  	return true;	
   12.55  }