vymmodel.cpp
changeset 756 a8a5c7288f57
parent 755 ed5b407975b3
child 757 c6908bc17d78
     1.1 --- a/vymmodel.cpp	Thu Apr 23 12:15:31 2009 +0000
     1.2 +++ b/vymmodel.cpp	Mon Apr 27 12:07:15 2009 +0000
     1.3 @@ -176,7 +176,7 @@
     1.4  
     1.5  void VymModel::updateActions()	// FIXME-2  maybe don't update if blockReposition is set
     1.6  {
     1.7 -	cout << "VymModel::updateActions \n";
     1.8 +	//cout << "VM::updateActions \n";
     1.9  	// Tell mainwindow to update states of actions
    1.10  	mainWindow->updateActions();
    1.11  }
    1.12 @@ -984,7 +984,6 @@
    1.13  
    1.14  void VymModel::setChanged()
    1.15  {
    1.16 -	cout << "VM::setChanged()\n";
    1.17  	if (!mapChanged)
    1.18  	{
    1.19  		autosaveTimer->start(settings.value("/mainwindow/autosave/ms/",300000).toInt());
    1.20 @@ -2071,7 +2070,6 @@
    1.21  	QList<QVariant> cData;
    1.22  	cData << "VM:addMapCenter" << "undef"<<"undef";
    1.23  	MapCenterItem *mci=new MapCenterItem (cData,rootItem);
    1.24 -	cout << "VM::addMapCenter  mci="<<mci<<endl;
    1.25  	mci->setType (TreeItem::MapCenter);
    1.26  	mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
    1.27  	rootItem->appendChild (mci);
    1.28 @@ -2142,15 +2140,15 @@
    1.29  
    1.30  			BranchItem *parbi=bi;
    1.31  			QModelIndex parix=index(parbi);
    1.32 -			int n=parbi->branchCount();
    1.33 +			int n=parbi->childCount();
    1.34  
    1.35  			emit (layoutAboutToBeChanged() );
    1.36 -			beginInsertRows (parix,n,n+1);
    1.37 -			bi=new BranchItem (cData,parbi);
    1.38 +			beginInsertRows (parix,n,n+1);	//FIXME-1 check if n is correct: should be index below _last_ branch...
    1.39 +			bi=new BranchItem (cData);	
    1.40  			bi->setType (TreeItem::Branch);
    1.41  			bi->setHeading (QApplication::translate("Heading of new branch in map", "new"));
    1.42  
    1.43 -			parbi->appendChild (bi);
    1.44 +			parbi->appendChild (bi);	
    1.45  			endInsertRows ();
    1.46  			emit (newChildObject (parix));
    1.47  			emit (layoutChanged() );
    1.48 @@ -2158,18 +2156,7 @@
    1.49  			// save scroll state. If scrolled, automatically select
    1.50  			// new branch in order to tmp unscroll parent...
    1.51  			newbo=bi->createMapObj(mapScene);
    1.52 -			/*
    1.53 -			newbo=bo->addBranch();
    1.54 -
    1.55 -			if (newbo)
    1.56 -			{
    1.57 -				bi->setLMO (newbo);
    1.58 -				newbo->setTreeItem (bi);
    1.59 -				select (bi); 
    1.60 -			}
    1.61 -			*/
    1.62  			select (bi);
    1.63 -			
    1.64  		}else if (num==-1)
    1.65  		{
    1.66  		/*
    1.67 @@ -2271,14 +2258,29 @@
    1.68  	cout << "VM::relinkBranch  "<<branch->getHeadingStd()<<"  to "<<dst->getHeadingStd()<<"  at pos="<<pos<<endl;
    1.69  	if (branch && dst)
    1.70  	{
    1.71 +		emit (layoutAboutToBeChanged() );
    1.72  		BranchItem *branchpi=(BranchItem*)branch->parent();
    1.73 -		BranchItem *dstpi=(BranchItem*)dst->parent();
    1.74 -		if (pos<0)
    1.75 -		{
    1.76 -			// Append as last branch to dst
    1.77 -			branchpi->removeChild (branch->childNum() );
    1.78 -			dst->appendChild (branch);
    1.79 -		}
    1.80 +		// Remove at current position
    1.81 +		int n=branch->childNum();
    1.82 +		beginRemoveRows (index(branchpi),n,n);
    1.83 +		branchpi->removeChild (n);
    1.84 +		endRemoveRows();
    1.85 +
    1.86 +		if (pos<0 ||pos>dst->branchCount() ) pos=dst->branchCount();
    1.87 +
    1.88 +		// Append as last branch to dst
    1.89 +		if (dst->branchCount()==0)
    1.90 +			n=0;
    1.91 +		else	
    1.92 +			n=dst->getFirstBranch()->childNumber(); 
    1.93 +	cout << "***  dst->bCount="<<dst->branchCount()<<"  n="<<n<<"  pos="<<pos<<endl;		
    1.94 +		beginInsertRows (index(dst),n+pos,n+pos);
    1.95 +		dst->insertBranch (pos,branch);
    1.96 +		endInsertRows();
    1.97 +
    1.98 +		branch->getLMO()->setParObj(dst->getLMO());	//FIXME-5 update parObj in View
    1.99 +		emit (layoutChanged() );
   1.100 +		select (branch);
   1.101  	}
   1.102  }
   1.103  
   1.104 @@ -2343,7 +2345,6 @@
   1.105  		beginRemoveRows (parentIndex,n,n);
   1.106  		removeRows (n,1,parentIndex);
   1.107  		endRemoveRows();
   1.108 -		//	delete (selbi->getLMO() );	// FIXME-0 selbi is removed implicetely, destructor is called. from there BO is deleted, but somhow still segfaulting :-(
   1.109  		select (par);
   1.110  		ensureSelectionVisible();
   1.111  		reposition();
   1.112 @@ -3983,7 +3984,7 @@
   1.113  
   1.114  void VymModel::reposition()	//FIXME-2 VM should have no need to reposition, this is done in views???
   1.115  {
   1.116 -	cout << "VM::reposition ...\n";
   1.117 +	//cout << "VM::reposition ...\n";
   1.118  	for (int i=0;i<rootItem->branchCount(); i++)
   1.119  		rootItem->getBranchObjNum(i)->reposition();	//	for positioning heading
   1.120  }