vymmodel.cpp
changeset 772 e3f722759c7e
parent 771 01f2f6d6789d
child 773 340bc29da9a0
     1.1 --- a/vymmodel.cpp	Mon May 18 11:22:41 2009 +0000
     1.2 +++ b/vymmodel.cpp	Wed May 20 15:40:14 2009 +0000
     1.3 @@ -30,6 +30,7 @@
     1.4  extern QString tmpVymDir;
     1.5  
     1.6  extern TextEditor *textEditor;
     1.7 +extern FlagRow *standardFlagsMaster;
     1.8  
     1.9  extern QString clipboardDir;
    1.10  extern QString clipboardFile;
    1.11 @@ -60,7 +61,7 @@
    1.12  
    1.13  VymModel::~VymModel() 
    1.14  {
    1.15 -//    cout << "Destr VymModel\n";
    1.16 +    cout << "Destr VymModel\n";
    1.17  	autosaveTimer->stop();
    1.18  	fileChangedTimer->stop();
    1.19  	clear();
    1.20 @@ -71,7 +72,7 @@
    1.21  	selModel->clearSelection();
    1.22  
    1.23  	//QModelIndex ri=index(rootItem);
    1.24 -	//removeRows (0, rowCount(ri),ri);		// FIXME-2 here should be at least a beginRemoveRows...
    1.25 +	//removeRows (0, rowCount(ri),ri);		// FIXME-3 here should be at least a beginRemoveRows...
    1.26  }
    1.27  
    1.28  void VymModel::init () 
    1.29 @@ -232,7 +233,7 @@
    1.30  	xml.incIndent();
    1.31  
    1.32  	// Find the used flags while traversing the tree	// FIXME-2 this can be done local to vymmodel maybe...
    1.33 -	//FIXME-2 not used any longer: standardFlagsDefault->resetUsedCounter();
    1.34 +	standardFlagsMaster->resetUsedCounter();
    1.35  	
    1.36  	// Reset the counters before saving
    1.37  	// TODO constr. of FIO creates lots of objects, better do this in some other way...
    1.38 @@ -262,7 +263,7 @@
    1.39  	xml.decIndent();
    1.40  	s+=xml.endElement("vymmap");
    1.41  
    1.42 -	// FIXME-2 if (writeflags) standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
    1.43 +	if (writeflags) standardFlagsMaster->saveToDir (tmpdir+"/flags/","",writeflags);
    1.44  	return s;
    1.45  }
    1.46  
    1.47 @@ -2008,7 +2009,6 @@
    1.48  MapCenterItem* VymModel::addMapCenter ()
    1.49  {
    1.50  	MapCenterItem *mci=addMapCenter (contextPos);
    1.51 -	//FIXME-3 selection.select (mco);
    1.52  	updateActions();
    1.53  	emitShowSelection();
    1.54  	saveState (
    1.55 @@ -2044,26 +2044,6 @@
    1.56  	// Create MapObj
    1.57  	BranchObj *newbo=mci->createMapObj(mapScene);
    1.58  		
    1.59 -	/*
    1.60 -
    1.61 -	if (!mci->getHeading().isEmpty() ) 
    1.62 -	{
    1.63 -		newbo->updateHeading();
    1.64 -		newbo->setColor (headingColor);
    1.65 -	}	
    1.66 -*/
    1.67 -		
    1.68 -	//newbo->updateLink();	//FIXME-3
    1.69 -
    1.70 -/*
    1.71 -	//mapCenter->setMapEditor(mapEditor);		//FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects
    1.72 -	mapCenter->setTreeItem (mci);	// TreeItem needs to exist before setVisibility
    1.73 -	mci->setLMO (mapCenter);
    1.74 -	mapCenter->updateHeading();
    1.75 -	mapCenter->move (absPos);
    1.76 -    mapCenter->setVisibility (true);
    1.77 -	//mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
    1.78 -*/
    1.79  	return mci;
    1.80  }
    1.81  
    1.82 @@ -2095,30 +2075,22 @@
    1.83  		beginInsertRows (parix,n,n+1);	
    1.84  		parbi->appendChild (newbi);	
    1.85  		endInsertRows ();
    1.86 -	}else if (num==-1)
    1.87 +	}else if (num==-1 || num==-3)
    1.88  	{
    1.89  		// insert below selection
    1.90  		parbi=(BranchItem*)dst->parent();
    1.91  		parix=index(parbi);
    1.92 -		n=dst->childNumber()+1;
    1.93 +		n=dst->childNumber()+ (3+num)/2;	//-1 |-> 1;-3 |-> 0
    1.94  		beginInsertRows (parix,n,n);	
    1.95  		parbi->insertBranch(n,newbi);	
    1.96  		endInsertRows ();
    1.97 -	}else if (num==-3)
    1.98 -	{
    1.99 -		// insert above selection
   1.100 -		parbi=(BranchItem*)dst->parent();
   1.101 -		parix=index(parbi);
   1.102 -		n=dst->childNumber();
   1.103 -		beginInsertRows (parix,n,n);	
   1.104 -		parbi->insertBranch(n,newbi);	
   1.105 -		endInsertRows ();
   1.106 -	} 
   1.107 +	}
   1.108  	emit (layoutChanged() );
   1.109  
   1.110  	// save scroll state. If scrolled, automatically select
   1.111  	// new branch in order to tmp unscroll parent...
   1.112  	newbi->createMapObj(mapScene);
   1.113 +	reposition();
   1.114  	select (newbi);
   1.115  	return newbi;
   1.116  }	
   1.117 @@ -2165,7 +2137,7 @@
   1.118  }
   1.119  
   1.120  
   1.121 -BranchItem* VymModel::addNewBranchBefore()	//FIXME-0
   1.122 +BranchItem* VymModel::addNewBranchBefore()	
   1.123  {
   1.124  	BranchItem *newbi=NULL;
   1.125  	BranchItem *selbi=getSelectedBranchItem();
   1.126 @@ -2315,24 +2287,29 @@
   1.127  	}	
   1.128  */}
   1.129  
   1.130 -void VymModel::deleteChildren()		//FIXME-2 VM still missing
   1.131 -
   1.132 -{
   1.133 -/*
   1.134 -	BranchObj *bo=getSelectedBranch();
   1.135 -	if (bo)
   1.136 +void VymModel::deleteChildren()		
   1.137 +
   1.138 +{
   1.139 +	BranchItem *selbi=getSelectedBranchItem();
   1.140 +	if (selbi)
   1.141  	{		
   1.142  		saveStateChangingPart(
   1.143 -			bo, 
   1.144 -			bo,
   1.145 +			selbi, 
   1.146 +			selbi,
   1.147  			"deleteChildren ()",
   1.148 -			QString( "Remove children of branch %1").arg(getObjectName(bo))
   1.149 +			QString( "Remove children of branch %1").arg(getObjectName(selbi))
   1.150  		);
   1.151 -		bo->removeChildren();
   1.152 +		emit (layoutAboutToBeChanged() );
   1.153 +
   1.154 +		QModelIndex ix=index (selbi);
   1.155 +		int n=selbi->branchCount()-1;
   1.156 +		beginRemoveRows (ix,0,n);
   1.157 +		removeRows (0,n+1,ix);
   1.158 +		endRemoveRows();
   1.159 +		emit (layoutChanged() );
   1.160  		reposition();
   1.161  	}	
   1.162 -*/}
   1.163 -
   1.164 +}
   1.165  
   1.166  bool VymModel::scrollBranch(BranchItem *bi)
   1.167  {
   1.168 @@ -4972,7 +4949,7 @@
   1.169  	return NULL;
   1.170  }
   1.171  
   1.172 -TreeItem* VymModel::getSelectedItem()
   1.173 +TreeItem* VymModel::getSelectedItem()	
   1.174  {
   1.175  	QModelIndexList list=selModel->selectedIndexes();
   1.176  	if (!list.isEmpty() )