Fixed sort children and addMapReplaceInt
authorinsilmaril
Thu, 17 Sep 2009 09:41:09 +0000
changeset 7956b0a5f4923d3
parent 794 d922fb6ea482
child 796 cf634bbf9e04
Fixed sort children and addMapReplaceInt
attributeitem.cpp
attributeitem.h
branchitem.cpp
branchitem.h
branchobj.cpp
branchobj.h
mainwindow.cpp
mainwindow.h
mapeditor.cpp
mysortfilterproxymodel.cpp
mysortfilterproxymodel.h
treeitem.cpp
treeitem.h
treemodel.cpp
vymmodel.cpp
vymmodel.h
xlinkitem.cpp
xlinkitem.h
xml-vym.cpp
xml-vym.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/attributeitem.cpp	Thu Sep 17 09:41:09 2009 +0000
     1.3 @@ -0,0 +1,156 @@
     1.4 +
     1.5 +#include "attributeitem.h"
     1.6 +
     1.7 +#include <iostream>
     1.8 +using namespace std;
     1.9 +
    1.10 +extern bool debug;
    1.11 +
    1.12 +AttributeItem::AttributeItem(const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
    1.13 +{
    1.14 +	TreeItem::setType (Attribute);
    1.15 +	//table=NULL;
    1.16 +	//definition=NULL;
    1.17 +	type=Attribute;
    1.18 +
    1.19 +	internal=false;
    1.20 +}
    1.21 +
    1.22 +AttributeItem::~AttributeItem()
    1.23 +{
    1.24 +}
    1.25 +
    1.26 +void AttributeItem::setKey (const QString &k, const Type &t)
    1.27 +{
    1.28 +/*
    1.29 +	if (!table)
    1.30 +	{
    1.31 +		qWarning (QString("AttributeItem::setKey (%1)  No table defined!\n").arg(k).ascii());
    1.32 +		return;	
    1.33 +	}
    1.34 +	
    1.35 +	if (!definition)
    1.36 +	{
    1.37 +		definition=table->getDef(k);
    1.38 +		if (!definition)
    1.39 +		{
    1.40 +			table->addKey (k,t);
    1.41 +			return;	
    1.42 +		}
    1.43 +	}	
    1.44 +	qWarning (QString("AttributeItem::setKey (%1)  attribute already defined!\n").arg(k).ascii());
    1.45 +	*/
    1.46 +}
    1.47 +
    1.48 +QString AttributeItem::getKey ()
    1.49 +{
    1.50 +/*
    1.51 +	if (!table)
    1.52 +	{
    1.53 +		qWarning ("AttributeItem::getKey ()  No table defined!");
    1.54 +		return QString();	
    1.55 +	}
    1.56 +	if (!definition)
    1.57 +	{
    1.58 +		qWarning ("AttributeItem::getKey ()  No attribute defined!");
    1.59 +		return QString ();	
    1.60 +	}	
    1.61 +	return definition->getKey();
    1.62 +	*/
    1.63 +}
    1.64 +
    1.65 +void AttributeItem::setValue(const QString &v)
    1.66 +{
    1.67 +/*
    1.68 +	if (!table)
    1.69 +	{
    1.70 +		qWarning (QString ("AttributeItem::setValue (%1)  No table defined!").arg(v));
    1.71 +		return;	
    1.72 +	}
    1.73 +	if (!definition)
    1.74 +	{
    1.75 +		qWarning (QString ("AttributeItem::setValue (%1)  No attribute defined!").arg(v));
    1.76 +		return;	
    1.77 +	}	
    1.78 +	definition->setValue (v);
    1.79 +*/
    1.80 +}
    1.81 +
    1.82 +QVariant AttributeItem::getValue()
    1.83 +{
    1.84 +/*
    1.85 +	if (!table)
    1.86 +	{
    1.87 +		qWarning ("AttributeItem::getValue  No table defined!");
    1.88 +		return QString();	
    1.89 +	}
    1.90 +	if (!definition)
    1.91 +	{
    1.92 +		qWarning ("AttributeItem::getValue  No attribute defined!");
    1.93 +		return QString();	
    1.94 +	}	
    1.95 +	QVariant v= definition->getValue();
    1.96 +	return v;
    1.97 +	*/
    1.98 +}
    1.99 +
   1.100 +void AttributeItem::setType (const Type &t)
   1.101 +{
   1.102 +/*
   1.103 +	if (!table)
   1.104 +	{
   1.105 +		qWarning ("AttributeItem::setType  No table defined!");
   1.106 +		return;
   1.107 +	}
   1.108 +	if (!definition)
   1.109 +	{
   1.110 +		qWarning ("Attribute::setType  No attribute defined!");
   1.111 +		return; 
   1.112 +	}	
   1.113 +	definition->setType (t);
   1.114 +*/
   1.115 +}
   1.116 +
   1.117 +AttributeItem::Type AttributeItem::getAttributeType()
   1.118 +{
   1.119 +/*
   1.120 +	if (!table)
   1.121 +	{
   1.122 +		qWarning ("AttributeItem::getType  No table defined!");
   1.123 +		return Undefined;	
   1.124 +	}
   1.125 +	if (!definition)
   1.126 +	{
   1.127 +		qWarning ("AttributeItem::getType  No attribute defined!");
   1.128 +		return Undefined;	
   1.129 +	}	
   1.130 +	return definition->getType();
   1.131 +*/
   1.132 +}
   1.133 +
   1.134 +QString AttributeItem::getTypeString()
   1.135 +{
   1.136 +/*
   1.137 +	if (!table)
   1.138 +	{
   1.139 +		qWarning ("AttributeItem::getTypeString  No table defined!");
   1.140 +		return "Undefined";	
   1.141 +	}
   1.142 +	if (!definition)
   1.143 +	{
   1.144 +		qWarning ("Attribute::getTypeString  No AttributeItem defined!");
   1.145 +		return "Undefined";	
   1.146 +	}	
   1.147 +	return definition->getTypeString();
   1.148 +*/	
   1.149 +}
   1.150 +
   1.151 +QString AttributeItem::getDataXML()
   1.152 +{
   1.153 +	QString a=beginElement ("attribute");
   1.154 +	a+=attribut ("key",getKey());
   1.155 +	a+=attribut ("value",getValue().toString() );
   1.156 +	a+=attribut ("type",getTypeString () );
   1.157 +	return a;
   1.158 +}
   1.159 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/attributeitem.h	Thu Sep 17 09:41:09 2009 +0000
     2.3 @@ -0,0 +1,41 @@
     2.4 +#ifndef ATTRIBUTEITEM_H
     2.5 +#define ATTRIBUTEITEM_H
     2.6 +
     2.7 +#include <QStringList>
     2.8 +#include <QVariant>
     2.9 +
    2.10 +#include "treeitem.h"
    2.11 +
    2.12 +/*! \brief A key and a value 
    2.13 +    The data itself is stored in Attribute Definitions (AttributeDef). 
    2.14 +	A list of these tables AttributeTable is maintained for every MapEditor.
    2.15 +*/
    2.16 +class AttributeItem:public TreeItem {
    2.17 +
    2.18 +enum Type {
    2.19 +	Undefined,	//!< Undefined type
    2.20 +	IntList,	//!< Free integer
    2.21 +	FreeInt,	//!< Free integer
    2.22 +	StringList, //!< List of strings, one can be attribute value
    2.23 +	FreeString,	//!< Any string can be attribute value, not unique
    2.24 +	UniqueString//!< UniqueString, e.g. for IDs
    2.25 +};
    2.26 +
    2.27 +public:
    2.28 +	AttributeItem(const QList<QVariant> &data, TreeItem *parent = 0);
    2.29 +	virtual ~AttributeItem();
    2.30 +	void setKey (const QString &k, const Type &t);
    2.31 +	QString getKey ();
    2.32 +	void setValue (const QString &v);
    2.33 +	QVariant getValue ();
    2.34 +	void setType (const Type &t);
    2.35 +	AttributeItem::Type getAttributeType ();
    2.36 +	QString getTypeString ();
    2.37 +	QString getDataXML();
    2.38 +protected:
    2.39 +	QString freeString;		//!< String value for type FreeString
    2.40 +	bool internal;			//!< Internal attributes cannot be edited by user
    2.41 +};
    2.42 +
    2.43 +#endif
    2.44 +
     3.1 --- a/branchitem.cpp	Fri Sep 11 12:56:15 2009 +0000
     3.2 +++ b/branchitem.cpp	Thu Sep 17 09:41:09 2009 +0000
     3.3 @@ -45,6 +45,11 @@
     3.4  	tmpUnscrolled=other->tmpUnscrolled;
     3.5  }
     3.6  
     3.7 +BranchItem* BranchItem::parentBranch ()
     3.8 +{
     3.9 +	return (BranchItem*) parentItem;
    3.10 +}
    3.11 +
    3.12  void BranchItem::insertBranch (int pos, BranchItem *branch)
    3.13  {
    3.14  	if (pos<0) pos=0;
    3.15 @@ -216,7 +221,7 @@
    3.16  			}
    3.17  		}
    3.18  	}
    3.19 -	model->reposition();	// FIXME-3 we don't really want to update view from here...
    3.20 +	//model->reposition();	// FIXME-3 we don't really want to update view from here...
    3.21  	return true;
    3.22  }
    3.23  
    3.24 @@ -273,10 +278,30 @@
    3.25  	}	
    3.26  }
    3.27  
    3.28 +void BranchItem::sortChildren()
    3.29 +{
    3.30 +	int childCount=branchCounter; 
    3.31 +	int curChildIndex;
    3.32 +	bool madeChanges=false;
    3.33 +	do
    3.34 +	{
    3.35 +		madeChanges=false;
    3.36 +		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
    3.37 +			BranchItem* curChild =getBranchNum(curChildIndex);
    3.38 +			BranchItem* prevChild=getBranchNum(curChildIndex-1);
    3.39 +			if(prevChild->getHeading().compare(curChild->getHeading())>0)
    3.40 +			{
    3.41 +				model->moveUp(curChild);
    3.42 +				madeChanges=true;
    3.43 +			}
    3.44 +		}
    3.45 +	}while(madeChanges);
    3.46 +}
    3.47 +
    3.48  void BranchItem::setIncludeImagesVer(bool b)
    3.49  {
    3.50  	includeImagesVer=b;
    3.51 -	/* calcBBoxSize(); FIXME-2
    3.52 +	/* calcBBoxSize(); FIXME-3
    3.53  	positionBBox();
    3.54  	requestReposition();
    3.55  	*/
    3.56 @@ -290,7 +315,7 @@
    3.57  void BranchItem::setIncludeImagesHor(bool b)
    3.58  {
    3.59  	includeImagesHor=b;
    3.60 -	/* calcBBoxSize(); FIXME-2
    3.61 +	/* calcBBoxSize(); FIXME-3
    3.62  	positionBBox();
    3.63  	requestReposition();
    3.64  	*/
    3.65 @@ -377,7 +402,7 @@
    3.66  	}
    3.67  	return NULL;
    3.68  }
    3.69 -
    3.70 +/*
    3.71  TreeItem* BranchItem::findID (QString sid)	//FIXME-3 move to TreeItem	//FIXME-4 search images
    3.72  {
    3.73  	// Search branches
    3.74 @@ -392,7 +417,6 @@
    3.75  	if (sid==objID) return this;
    3.76  
    3.77  
    3.78 -/*
    3.79  	// Search float images 
    3.80      for (int i=0; i<floatimage.size(); ++i )
    3.81  		if (floatimage.at(i)->inBox(p) && 
    3.82 @@ -400,10 +424,9 @@
    3.83  			floatimage.at(i)->getParObj()!= excludeLMO &&
    3.84  			floatimage.at(i)->isVisibleObj() 
    3.85  		) return floatimage.at(i);
    3.86 -*/
    3.87      return NULL;
    3.88  }
    3.89 -
    3.90 +*/
    3.91  void BranchItem::updateStyles()
    3.92  {
    3.93  	// FIXME-5 compare also MapItem::initLMO...
     4.1 --- a/branchitem.h	Fri Sep 11 12:56:15 2009 +0000
     4.2 +++ b/branchitem.h	Thu Sep 17 09:41:09 2009 +0000
     4.3 @@ -15,6 +15,7 @@
     4.4      BranchItem(const QList<QVariant> &data, TreeItem *parent = 0);
     4.5      virtual ~BranchItem();
     4.6  	virtual void copy (BranchItem *item);
     4.7 +	virtual BranchItem* parentBranch();
     4.8  
     4.9  	virtual void insertBranch (int pos,BranchItem *branch);
    4.10  
    4.11 @@ -34,7 +35,7 @@
    4.12  	virtual bool hasScrolledParent(BranchItem*);	// true, if any of the parents is scrolled
    4.13  	virtual void tmpUnscroll();				// unscroll scrolled parents temporary e.g. during "find" process
    4.14  	virtual void resetTmpUnscroll();		// scroll all tmp scrolled parents again e.g. when unselecting
    4.15 -
    4.16 +	virtual void sortChildren();		//! Sort children 
    4.17  
    4.18  protected:
    4.19  	bool includeImagesVer;			//! include floatimages in bbox vertically
    4.20 @@ -57,7 +58,7 @@
    4.21  
    4.22  public:
    4.23  	TreeItem* findMapItem (QPointF p,TreeItem* excludeTI);	//! search map for branches or images. Ignore excludeTI, where search is started 
    4.24 -	virtual TreeItem* findID (QString sid);	//! search map for object with ID string
    4.25 +//	virtual TreeItem* findID (QString sid);	//! search map for object with ID string
    4.26  
    4.27  	virtual void updateStyles ();			//! update related fonts, parObjects, links, ...
    4.28  	virtual BranchObj* getBranchObj();	
     5.1 --- a/branchobj.cpp	Fri Sep 11 12:56:15 2009 +0000
     5.2 +++ b/branchobj.cpp	Thu Sep 17 09:41:09 2009 +0000
     5.3 @@ -505,28 +505,6 @@
     5.4  	calcBBoxSize();
     5.5  }
     5.6  
     5.7 -void BranchObj::sortChildren() //FIXME-3 not moved to model yet 
     5.8 -{
     5.9 -/*
    5.10 -	int childCount=branch.count(); 
    5.11 -	int curChildIndex;
    5.12 -	bool madeChanges=false;
    5.13 -	do
    5.14 -	{
    5.15 -		madeChanges=false;
    5.16 -		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
    5.17 -			BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
    5.18 -			BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
    5.19 -			if(prevChild->heading->text().compare(curChild->heading->text())>0)
    5.20 -			{
    5.21 -				this->moveBranchUp(curChild);
    5.22 -				madeChanges=true;
    5.23 -			}
    5.24 -		}
    5.25 -	}while(madeChanges);
    5.26 -*/
    5.27 -}
    5.28 -
    5.29  void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
    5.30  {
    5.31  	qreal th = bboxTotal.height();	
    5.32 @@ -545,10 +523,10 @@
    5.33  //cout<<  "  ref="<<ref<<
    5.34        	"  bbox.tL="<<bboxTotal.topLeft()<<
    5.35  		"  absPos="<<absPos<<
    5.36 -//		"  relPos="<<relPos<<
    5.37 +		"  relPos="<<relPos<<
    5.38  //		"  parPos="<<pp<<
    5.39 -		"  w="<<bbox.width()<<
    5.40 -		"  h="<<bbox.height()<<
    5.41 +//		"  w="<<bbox.width()<<
    5.42 +//		"  h="<<bbox.height()<<
    5.43  //		"  orient="<<orientation<<
    5.44  //		"  alignSelf="<<alignSelf<<
    5.45  //		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
     6.1 --- a/branchobj.h	Fri Sep 11 12:56:15 2009 +0000
     6.2 +++ b/branchobj.h	Thu Sep 17 09:41:09 2009 +0000
     6.3 @@ -48,7 +48,6 @@
     6.4  public:	
     6.5  	virtual void setDefAttr (BranchModification);	// set default attributes (font, size, ...)
     6.6  
     6.7 -    virtual void sortChildren();
     6.8      virtual void alignRelativeTo(const QPointF, bool alignSelf=false );
     6.9  	virtual void reposition();
    6.10  	virtual void unsetAllRepositionRequests();
     7.1 --- a/mainwindow.cpp	Fri Sep 11 12:56:15 2009 +0000
     7.2 +++ b/mainwindow.cpp	Thu Sep 17 09:41:09 2009 +0000
     7.3 @@ -23,7 +23,7 @@
     7.4  #include "warningdialog.h"
     7.5  #include "xlinkitem.h"
     7.6  
     7.7 -#include <modeltest.h>	// FIXME-3
     7.8 +//#include <modeltest.h>	// FIXME-3
     7.9  
    7.10  #if defined(Q_OS_WIN32)
    7.11  // Define only this structure as opposed to
    7.12 @@ -665,6 +665,13 @@
    7.13  	editMenu->addAction (a);
    7.14  	actionMoveDown=a;
    7.15  	
    7.16 +    a = new QAction(QPixmap(), tr( "&Detach","Context menu" ),this);
    7.17 +	a->setStatusTip ( tr( "Detach branch and use as mapcenter","Context menu" ) );
    7.18 +	a->setShortcut ( Qt::Key_D );					// Detach branch
    7.19 +	editMenu->addAction (a);
    7.20 +    connect( a, SIGNAL( triggered() ), this, SLOT( editDetach() ) );
    7.21 +	actionDetach=a;
    7.22 +	
    7.23  	a = new QAction( QPixmap(iconPath+"editsort.png" ), tr( "Sort children","Edit menu" ), this );
    7.24  	connect( a, SIGNAL( activated() ), this, SLOT( editSortChildren() ) );
    7.25  	a->setEnabled (true);
    7.26 @@ -1547,6 +1554,7 @@
    7.27  
    7.28  	actionSaveBranch->addTo( branchContextMenu );
    7.29  	actionFileNewCopy->addTo (branchContextMenu );
    7.30 +	actionDetach->addTo (branchContextMenu );
    7.31  
    7.32  	branchContextMenu->addSeparator();	
    7.33  	branchContextMenu->addAction ( actionLoadImage);
    7.34 @@ -1710,7 +1718,7 @@
    7.35  {
    7.36  	VymModel *vm=new VymModel;
    7.37  
    7.38 -new ModelTest(vm, this);	//FIXME-3
    7.39 +//new ModelTest(vm, this);	//FIXME-3
    7.40  
    7.41  
    7.42  	VymView *vv=new VymView (vm);
    7.43 @@ -2699,6 +2707,7 @@
    7.44  void Main::editMapInfo()
    7.45  {
    7.46  	VymModel *m=currentModel();
    7.47 +	if (!m) return;
    7.48  
    7.49  	ExtraInfoDialog dia;
    7.50  	dia.setMapName (m->getFileName() );
    7.51 @@ -2707,27 +2716,27 @@
    7.52  
    7.53  	// Calc some stats
    7.54  	QString stats;
    7.55 -/* FIXME-2 no stats at the moment (view dependent...)
    7.56 -    stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
    7.57 +    stats+=tr("%1 items on map\n","Info about map").arg (m->getScene()->items().size(),6);
    7.58  
    7.59  	uint b=0;
    7.60  	uint f=0;
    7.61  	uint n=0;
    7.62  	uint xl=0;
    7.63 -	BranchObj *bo;
    7.64 -	bo=m->first();
    7.65 -	while (bo) 
    7.66 +	BranchItem *cur=NULL;
    7.67 +	BranchItem *prev=NULL;
    7.68 +	m->next(cur,prev);
    7.69 +	while (cur) 
    7.70  	{
    7.71 -		if (!bo->getNote().isEmpty() ) n++;
    7.72 -		f+= bo->countFloatImages();
    7.73 +		if (!cur->getNote().isEmpty() ) n++;
    7.74 +		f+= cur->imageCount();
    7.75  		b++;
    7.76 -		xl+=bo->countXLinks();
    7.77 -		bo=m->next(bo);
    7.78 +		xl+=cur->xlinkCount();
    7.79 +		m->next(cur,prev);
    7.80  	}
    7.81 +
    7.82      stats+=QString ("%1 xLinks \n").arg (xl,6);
    7.83      stats+=QString ("%1 notes\n").arg (n,6);
    7.84      stats+=QString ("%1 images\n").arg (f,6);
    7.85 -*/
    7.86      stats+=QString ("%1 branches\n").arg (m->branchCount(),6);
    7.87  	dia.setStats (stats);
    7.88  
    7.89 @@ -2751,6 +2760,12 @@
    7.90  	if (m) m->moveDown();
    7.91  }
    7.92  
    7.93 +void Main::editDetach()
    7.94 +{
    7.95 +	VymModel *m=currentModel();
    7.96 +	if (m) m->detach();
    7.97 +}
    7.98 +
    7.99  void Main::editSortChildren()
   7.100  {
   7.101  	VymModel *m=currentModel();
   7.102 @@ -3591,6 +3606,11 @@
   7.103  {
   7.104  	if (!currentMapEditor()) return;
   7.105  	currentMapEditor()->testFunction1();
   7.106 +	/*
   7.107 +	VymModel *m=currentModel();
   7.108 +	if (!m) return;
   7.109 +	m->clearItem (m->getSelectedItem());
   7.110 +	*/
   7.111  }
   7.112  
   7.113  void Main::testFunction2()
     8.1 --- a/mainwindow.h	Fri Sep 11 12:56:15 2009 +0000
     8.2 +++ b/mainwindow.h	Thu Sep 17 09:41:09 2009 +0000
     8.3 @@ -144,6 +144,7 @@
     8.4  	void editMapInfo();
     8.5      void editMoveUp();	
     8.6      void editMoveDown();	
     8.7 +    void editDetach();	
     8.8  	void editSortChildren();
     8.9      void editToggleScroll();
    8.10      void editExpandAll();
    8.11 @@ -278,6 +279,7 @@
    8.12  	QAction *actionPaste;
    8.13  	QAction *actionMoveUp;
    8.14  	QAction *actionMoveDown;
    8.15 +	QAction *actionDetach;
    8.16  	QAction *actionSortChildren;
    8.17  	QAction *actionToggleScroll;
    8.18  	QAction *actionExpandAll;
     9.1 --- a/mapeditor.cpp	Fri Sep 11 12:56:15 2009 +0000
     9.2 +++ b/mapeditor.cpp	Thu Sep 17 09:41:09 2009 +0000
     9.3 @@ -186,6 +186,8 @@
     9.4  
     9.5  void MapEditor::scrollTo (const QModelIndex &index)
     9.6  {
     9.7 +	//cout <<"ME::scrollTo aborted\n";
     9.8 +	//return;
     9.9  	if (index.isValid())
    9.10  	{
    9.11  		LinkableMapObj* lmo=NULL;
    9.12 @@ -454,6 +456,7 @@
    9.13  
    9.14  void MapEditor::testFunction1()
    9.15  {
    9.16 +	cout << "ME::test1  selected TI="<<model->getSelectedItem()<<endl;
    9.17  	/*
    9.18  	// Code copied from Qt sources
    9.19  	QRectF rect=model->getSelectedBranchObj()->getBBox();
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/mysortfilterproxymodel.cpp	Thu Sep 17 09:41:09 2009 +0000
    10.3 @@ -0,0 +1,99 @@
    10.4 +/****************************************************************************
    10.5 +**
    10.6 +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
    10.7 +** Contact: Qt Software Information (qt-info@nokia.com)
    10.8 +**
    10.9 +** This file is part of the example classes of the Qt Toolkit.
   10.10 +**
   10.11 +** Commercial Usage
   10.12 +** Licensees holding valid Qt Commercial licenses may use this file in
   10.13 +** accordance with the Qt Commercial License Agreement provided with the
   10.14 +** Software or, alternatively, in accordance with the terms contained in
   10.15 +** a written agreement between you and Nokia.
   10.16 +**
   10.17 +**
   10.18 +** GNU General Public License Usage
   10.19 +** Alternatively, this file may be used under the terms of the GNU
   10.20 +** General Public License versions 2.0 or 3.0 as published by the Free
   10.21 +** Software Foundation and appearing in the file LICENSE.GPL included in
   10.22 +** the packaging of this file.  Please review the following information
   10.23 +** to ensure GNU General Public Licensing requirements will be met:
   10.24 +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
   10.25 +** http://www.gnu.org/copyleft/gpl.html.  In addition, as a special
   10.26 +** exception, Nokia gives you certain additional rights. These rights
   10.27 +** are described in the Nokia Qt GPL Exception version 1.3, included in
   10.28 +** the file GPL_EXCEPTION.txt in this package.
   10.29 +**
   10.30 +** Qt for Windows(R) Licensees
   10.31 +** As a special exception, Nokia, as the sole copyright holder for Qt
   10.32 +** Designer, grants users of the Qt/Eclipse Integration plug-in the
   10.33 +** right for the Qt/Eclipse Integration to link to functionality
   10.34 +** provided by Qt Designer and its related libraries.
   10.35 +**
   10.36 +** If you are unsure which license is appropriate for your use, please
   10.37 +** contact the sales department at qt-sales@nokia.com.
   10.38 +**
   10.39 +****************************************************************************/
   10.40 +
   10.41 +#include <QtGui>
   10.42 +
   10.43 +#include "mysortfilterproxymodel.h"
   10.44 +
   10.45 +MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
   10.46 +    : QSortFilterProxyModel(parent)
   10.47 +{
   10.48 +}
   10.49 +/*
   10.50 +void MySortFilterProxyModel::setFilterMinimumDate(const QDate &date)
   10.51 +{
   10.52 +    minDate = date;
   10.53 +    invalidateFilter();
   10.54 +}
   10.55 +void MySortFilterProxyModel::setFilterMaximumDate(const QDate &date)
   10.56 +{
   10.57 +    maxDate = date;
   10.58 +    invalidateFilter();
   10.59 +}
   10.60 +*/
   10.61 +
   10.62 +#include <iostream>
   10.63 +using namespace std;
   10.64 +bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
   10.65 +        const QModelIndex &sourceParent) const
   10.66 +{
   10.67 +	return true;
   10.68 +cout << "MSFPM  sM="<<sourceModel()<<endl;
   10.69 +    QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
   10.70 +    QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
   10.71 +
   10.72 +    return (sourceModel()->data(index0).toString().contains(filterRegExp()) );
   10.73 +}
   10.74 +
   10.75 +/*
   10.76 +bool MySortFilterProxyModel::lessThan(const QModelIndex &left,
   10.77 +                                      const QModelIndex &right) const
   10.78 +{
   10.79 +    QVariant leftData = sourceModel()->data(left);
   10.80 +    QVariant rightData = sourceModel()->data(right);
   10.81 +    if (leftData.type() == QVariant::DateTime) {
   10.82 +        return leftData.toDateTime() < rightData.toDateTime();
   10.83 +    } else {
   10.84 +        QRegExp *emailPattern = new QRegExp("([\\w\\.]*@[\\w\\.]*)");
   10.85 +
   10.86 +        QString leftString = leftData.toString();
   10.87 +        if(left.column() == 1 && emailPattern->indexIn(leftString) != -1)
   10.88 +            leftString = emailPattern->cap(1);
   10.89 +
   10.90 +        QString rightString = rightData.toString();
   10.91 +        if(right.column() == 1 && emailPattern->indexIn(rightString) != -1)
   10.92 +            rightString = emailPattern->cap(1);
   10.93 +
   10.94 +        return QString::localeAwareCompare(leftString, rightString) < 0;
   10.95 +    }
   10.96 +}
   10.97 +bool MySortFilterProxyModel::dateInRange(const QDate &date) const
   10.98 +{
   10.99 +    return (!minDate.isValid() || date > minDate)
  10.100 +           && (!maxDate.isValid() || date < maxDate);
  10.101 +}
  10.102 +*/
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/mysortfilterproxymodel.h	Thu Sep 17 09:41:09 2009 +0000
    11.3 @@ -0,0 +1,70 @@
    11.4 +/****************************************************************************
    11.5 +**
    11.6 +** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
    11.7 +** Contact: Qt Software Information (qt-info@nokia.com)
    11.8 +**
    11.9 +** This file is part of the example classes of the Qt Toolkit.
   11.10 +**
   11.11 +** Commercial Usage
   11.12 +** Licensees holding valid Qt Commercial licenses may use this file in
   11.13 +** accordance with the Qt Commercial License Agreement provided with the
   11.14 +** Software or, alternatively, in accordance with the terms contained in
   11.15 +** a written agreement between you and Nokia.
   11.16 +**
   11.17 +**
   11.18 +** GNU General Public License Usage
   11.19 +** Alternatively, this file may be used under the terms of the GNU
   11.20 +** General Public License versions 2.0 or 3.0 as published by the Free
   11.21 +** Software Foundation and appearing in the file LICENSE.GPL included in
   11.22 +** the packaging of this file.  Please review the following information
   11.23 +** to ensure GNU General Public Licensing requirements will be met:
   11.24 +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
   11.25 +** http://www.gnu.org/copyleft/gpl.html.  In addition, as a special
   11.26 +** exception, Nokia gives you certain additional rights. These rights
   11.27 +** are described in the Nokia Qt GPL Exception version 1.3, included in
   11.28 +** the file GPL_EXCEPTION.txt in this package.
   11.29 +**
   11.30 +** Qt for Windows(R) Licensees
   11.31 +** As a special exception, Nokia, as the sole copyright holder for Qt
   11.32 +** Designer, grants users of the Qt/Eclipse Integration plug-in the
   11.33 +** right for the Qt/Eclipse Integration to link to functionality
   11.34 +** provided by Qt Designer and its related libraries.
   11.35 +**
   11.36 +** If you are unsure which license is appropriate for your use, please
   11.37 +** contact the sales department at qt-sales@nokia.com.
   11.38 +**
   11.39 +****************************************************************************/
   11.40 +
   11.41 +#ifndef MYSORTFILTERPROXYMODEL_H
   11.42 +#define MYSORTFILTERPROXYMODEL_H
   11.43 +
   11.44 +#include <QDate>
   11.45 +#include <QSortFilterProxyModel>
   11.46 +
   11.47 +//! [0]
   11.48 +class MySortFilterProxyModel : public QSortFilterProxyModel
   11.49 +{
   11.50 +    Q_OBJECT
   11.51 +
   11.52 +public:
   11.53 +    MySortFilterProxyModel(QObject *parent = 0);
   11.54 +
   11.55 + //   QDate filterMinimumDate() const { return minDate; }
   11.56 +//    void setFilterMinimumDate(const QDate &date);
   11.57 +
   11.58 +//    QDate filterMaximumDate() const { return maxDate; }
   11.59 +//    void setFilterMaximumDate(const QDate &date);
   11.60 +
   11.61 +protected:
   11.62 +    bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
   11.63 +//    bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
   11.64 +
   11.65 +private:
   11.66 +    bool dateInRange(const QDate &date) const;
   11.67 +
   11.68 +    QDate minDate;
   11.69 +    QDate maxDate;
   11.70 +};
   11.71 +//! [0]
   11.72 +
   11.73 +#endif
    12.1 --- a/treeitem.cpp	Fri Sep 11 12:56:15 2009 +0000
    12.2 +++ b/treeitem.cpp	Thu Sep 17 09:41:09 2009 +0000
    12.3 @@ -175,18 +175,6 @@
    12.4  	}
    12.5  }
    12.6  
    12.7 -/*
    12.8 -void TreeItem::clear()	// FIXME-2 used in vymmodel addMapInsert, but needs to be used via model and emit layout changes...
    12.9 -{
   12.10 -	cout << "TI::clear\n";
   12.11 -	while ( childItems.size()>0)
   12.12 -	{
   12.13 -		branchCounter--;
   12.14 -		childItems.removeAt (0);
   12.15 -	}
   12.16 -}
   12.17 -*/
   12.18 -
   12.19  TreeItem *TreeItem::child(int row)
   12.20  {
   12.21      return childItems.value(row);
    13.1 --- a/treeitem.h	Fri Sep 11 12:56:15 2009 +0000
    13.2 +++ b/treeitem.h	Thu Sep 17 09:41:09 2009 +0000
    13.3 @@ -41,7 +41,6 @@
    13.4  
    13.5      virtual void appendChild (TreeItem *child);
    13.6  	virtual void removeChild (int row);
    13.7 -//	virtual void clear();
    13.8  
    13.9      virtual TreeItem *child(int row);
   13.10      virtual int childCount() const;
    14.1 --- a/treemodel.cpp	Fri Sep 11 12:56:15 2009 +0000
    14.2 +++ b/treemodel.cpp	Thu Sep 17 09:41:09 2009 +0000
    14.3 @@ -235,36 +235,12 @@
    14.4  		pi=rootItem;
    14.5  	TreeItem *ti;
    14.6  
    14.7 -	cout << "TM::removeRows  pi="<<pi<<"  row="<<row<<"  count="<<count<<endl;
    14.8 +	//cout << "TM::removeRows  pi="<<pi<<"  row="<<row<<"  count="<<count<<endl;
    14.9  	for (int i=row; i<=last; i++)
   14.10  	{
   14.11  		ti=pi->getChildNum (row);
   14.12 -		cout << "   pi="<<pi<<"  ti="<<ti<<endl;
   14.13  		pi->removeChild (row);	// does not delete object!
   14.14  		delete ti;
   14.15 -		/* FIXME-3
   14.16 -		switch (ti->getType()) 
   14.17 -		{
   14.18 -			case TreeItem::MapCenter: 
   14.19 -				delete (BranchItem*)ti; 
   14.20 -				break;
   14.21 -			case TreeItem::Branch:
   14.22 -				delete (BranchItem*)ti; 
   14.23 -				break;
   14.24 -			case TreeItem::Image:
   14.25 -				delete (ImageItem*)ti; 
   14.26 -				break;
   14.27 -			case TreeItem::Attribute:
   14.28 -				delete (AttributeItem*)ti; 
   14.29 -				break;
   14.30 -			case TreeItem::XLink:
   14.31 -				delete (XLinkItem*)ti; 
   14.32 -				break;
   14.33 -			default:
   14.34 -				delete ti;
   14.35 -				break;
   14.36 -		}
   14.37 -		*/
   14.38  	}
   14.39  	return true;
   14.40  }
    15.1 --- a/vymmodel.cpp	Fri Sep 11 12:56:15 2009 +0000
    15.2 +++ b/vymmodel.cpp	Thu Sep 17 09:41:09 2009 +0000
    15.3 @@ -640,7 +640,7 @@
    15.4  	return err;
    15.5  }
    15.6  
    15.7 -void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)	// FIXME-1 test e.g. with undo color subtree
    15.8 +void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path)	
    15.9  {
   15.10  	QString pathDir=path.left(path.findRev("/"));
   15.11  	QDir d(pathDir);
   15.12 @@ -1077,7 +1077,6 @@
   15.13  
   15.14  
   15.15  	parseAtom (redoCommand);
   15.16 -	reposition();
   15.17  
   15.18  	blockSaveState=blockSaveStateOrg;
   15.19  
   15.20 @@ -1156,7 +1155,6 @@
   15.21  		cout << "    ---------------------------"<<endl<<endl;
   15.22  	}	
   15.23  	parseAtom (undoCommand);
   15.24 -	reposition();
   15.25  
   15.26  	undosAvail--;
   15.27  	curStep--; 
   15.28 @@ -1180,7 +1178,7 @@
   15.29  
   15.30  	mainWindow->updateHistory (undoSet);
   15.31  	updateActions();
   15.32 -	emitSelectionChanged();
   15.33 +	//emitSelectionChanged();
   15.34  }
   15.35  
   15.36  bool VymModel::isUndoAvailable()
   15.37 @@ -1439,7 +1437,7 @@
   15.38  	return  ti;
   15.39  }
   15.40  
   15.41 -TreeItem* VymModel::findID (const QString &s)
   15.42 +TreeItem* VymModel::findID (const QString &s)	//FIXME-4 Search also other types...
   15.43  {
   15.44  	BranchItem *cur=NULL;
   15.45  	BranchItem *prev=NULL;
   15.46 @@ -1602,9 +1600,7 @@
   15.47  
   15.48  void VymModel::setScene (QGraphicsScene *s)
   15.49  {
   15.50 -	mapScene=s;	// FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor
   15.51 -    //init();	// Here we have a mapScene set, 
   15.52 -			// which is (still) needed to create MapCenters
   15.53 +	mapScene=s;	
   15.54  }
   15.55  
   15.56  void VymModel::setURL(const QString &url) 
   15.57 @@ -1918,47 +1914,80 @@
   15.58  	}
   15.59  }
   15.60  
   15.61 -void VymModel::moveUp()	//FIXME-2 crashes if trying to move MCO
   15.62 +bool VymModel::moveUp(BranchItem *bi)	//FIXME-2 crashes if trying to move MCO
   15.63 +{
   15.64 +	if (bi && bi->canMoveUp()) 
   15.65 +		return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1);
   15.66 +	else	
   15.67 +		return false;
   15.68 +}
   15.69 +
   15.70 +void VymModel::moveUp()	
   15.71  {
   15.72  	BranchItem *selbi=getSelectedBranch();
   15.73  	if (selbi)
   15.74  	{
   15.75 -		if (!selbi->canMoveUp()) return;
   15.76  		QString oldsel=getSelectString();
   15.77 -		if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) )
   15.78 -
   15.79 -			saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi)));
   15.80 +		if (moveUp (selbi))
   15.81 +			saveState (
   15.82 +				getSelectString(),"moveDown ()",
   15.83 +				oldsel,"moveUp ()",
   15.84 +				QString("Move up %1").arg(getObjectName(selbi)));
   15.85  	}
   15.86  }
   15.87  
   15.88 +bool VymModel::moveDown(BranchItem *bi)	
   15.89 +{
   15.90 +	if (bi && bi->canMoveDown())
   15.91 +		return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1);
   15.92 +	else
   15.93 +		return false;
   15.94 +}
   15.95 +
   15.96  void VymModel::moveDown()	
   15.97  {
   15.98  	BranchItem *selbi=getSelectedBranch();
   15.99  	if (selbi)
  15.100  	{
  15.101 -		if (!selbi->canMoveDown()) return;
  15.102  		QString oldsel=getSelectString();
  15.103 -		if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) )
  15.104 -
  15.105 -			saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi)));
  15.106 +		if ( moveDown(selbi))
  15.107 +			saveState (
  15.108 +				getSelectString(),"moveUp ()",
  15.109 +				oldsel,"moveDown ()",
  15.110 +				QString("Move down %1").arg(getObjectName(selbi)));
  15.111  	}
  15.112  }
  15.113  
  15.114 -void VymModel::sortChildren()	// FIXME-2 not implemented yet
  15.115 -{
  15.116 -/*
  15.117 -	BranchObj* bo=getSelectedBranch();
  15.118 -	if (bo)
  15.119 +void VymModel::detach()	
  15.120 +{
  15.121 +	BranchItem *selbi=getSelectedBranch();
  15.122 +	if (selbi && selbi->depth()>0)
  15.123  	{
  15.124 -		if(treeItem->branchCount()>1)
  15.125 +		//QString oldsel=getSelectString();
  15.126 +		if ( relinkBranch (selbi,rootItem,-1) )
  15.127 +			saveState (
  15.128 +				selbi,QString("relink()"), //FIXME-1 add paramters
  15.129 +				selbi,"detach ()",
  15.130 +				QString("Detach %1").arg(getObjectName(selbi))
  15.131 +			);
  15.132 +	}
  15.133 +}
  15.134 +
  15.135 +void VymModel::sortChildren()
  15.136 +{
  15.137 +	BranchItem* selbi=getSelectedBranch();
  15.138 +	if (selbi)
  15.139 +	{
  15.140 +		if(selbi->branchCount()>1)
  15.141  		{
  15.142 -			saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo)));
  15.143 -			bo->sortChildren();
  15.144 +			saveStateChangingPart(
  15.145 +				selbi,selbi, "sortChildren ()",
  15.146 +				QString("Sort children of %1").arg(getObjectName(selbi)));
  15.147 +			selbi->sortChildren();
  15.148  			reposition();
  15.149  			emitShowSelection();
  15.150  		}
  15.151  	}
  15.152 -*/
  15.153  }
  15.154  
  15.155  BranchItem* VymModel::createMapCenter()
  15.156 @@ -2437,7 +2466,6 @@
  15.157  
  15.158  TreeItem* VymModel::deleteItem (TreeItem *ti)
  15.159  {
  15.160 -	cout << "VM::deleteItem "<<ti<<"  "<<getSelectString(ti).toStdString()<<endl;
  15.161  	if (ti)
  15.162  	{
  15.163  		TreeItem *pi=ti->parent();
  15.164 @@ -2457,6 +2485,29 @@
  15.165  	return NULL;
  15.166  }
  15.167  
  15.168 +void VymModel::clearItem (TreeItem *ti)
  15.169 +{
  15.170 +	if (ti)
  15.171 +	{
  15.172 +		QModelIndex parentIndex=index(ti);
  15.173 +		if (!parentIndex.isValid()) return;
  15.174 +
  15.175 +		int n=ti->childCount();
  15.176 +		if (n==0) return;
  15.177 +
  15.178 +		emit (layoutAboutToBeChanged() );
  15.179 +
  15.180 +		beginRemoveRows (parentIndex,0,n-1);
  15.181 +		removeRows (0,n,parentIndex);
  15.182 +		endRemoveRows();
  15.183 +		reposition();
  15.184 +
  15.185 +		emit (layoutChanged() );
  15.186 +
  15.187 +	}	
  15.188 +	return ;
  15.189 +}
  15.190 +
  15.191  bool VymModel::scrollBranch(BranchItem *bi)
  15.192  {
  15.193  	if (bi)	
  15.194 @@ -2478,7 +2529,7 @@
  15.195  			);
  15.196  			emitDataHasChanged(bi);
  15.197  			emitSelectionChanged();
  15.198 -			mapScene->update(); //Needed for _quick_ update,  even in 1.13.x //FIXME-3 force update via signal...
  15.199 +			mapScene->update(); //Needed for _quick_ update,  even in 1.13.x 
  15.200  			return true;
  15.201  		}
  15.202  	}	
  15.203 @@ -2492,7 +2543,9 @@
  15.204  		if (!bi->isScrolled()) return false;
  15.205  		if (bi->branchCount()==0) return false;
  15.206  		if (bi->depth()==0) return false;
  15.207 -
  15.208 +		if (bi->toggleScroll())
  15.209 +		{
  15.210 +			reposition();
  15.211  		QString u,r;
  15.212  		u="scroll";
  15.213  		r="unscroll";
  15.214 @@ -2503,13 +2556,12 @@
  15.215  			QString ("%1 ()").arg(r),
  15.216  			QString ("%1 %2").arg(r).arg(getObjectName(bi))
  15.217  		);
  15.218 -		bi->toggleScroll();
  15.219  		emitDataHasChanged(bi);
  15.220  		emitSelectionChanged();
  15.221 -
  15.222 -		mapScene->update(); //Needed for _quick_ update,  even in 1.13.x //FIXME-3 force update via signal...
  15.223 +			mapScene->update(); //Needed for _quick_ update,  even in 1.13.x 
  15.224  		return true;
  15.225  	}	
  15.226 +	}	
  15.227  	return false;
  15.228  }
  15.229  
  15.230 @@ -2523,24 +2575,34 @@
  15.231  		else
  15.232  			scrollBranch (bi);
  15.233  	}
  15.234 -	// saveState is called in above functions
  15.235 +	// saveState & reposition are called in above functions
  15.236  }
  15.237  
  15.238 -void VymModel::unscrollChildren() 	// FIXME-2	first, next moved to vymmodel
  15.239 -
  15.240 -{
  15.241 -/*
  15.242 -	BranchObj *bo=getSelectedBranch();
  15.243 -	if (bo)
  15.244 +void VymModel::unscrollChildren() 	//FIXME-2 does not update flag yet, possible segfault
  15.245 +{
  15.246 +	BranchItem *selbi=getSelectedBranch();
  15.247 +	BranchItem *prev=NULL;
  15.248 +	BranchItem *cur=selbi;
  15.249 +	if (selbi)
  15.250  	{
  15.251 -		bo->first();
  15.252 -		while (bo) 
  15.253 +		saveStateChangingPart(
  15.254 +			selbi,
  15.255 +			selbi,
  15.256 +			QString ("unscrollChildren ()"),
  15.257 +			QString ("unscroll all children of %1").arg(getObjectName(selbi))
  15.258 +		);	
  15.259 +		while (cur) 
  15.260  		{
  15.261 -			if (bo->isScrolled()) unscrollBranch (bo);
  15.262 -			bo=bo->next();
  15.263 +			if (cur->isScrolled())
  15.264 +			{
  15.265 +				cur->toggleScroll(); 
  15.266 +				emitDataHasChanged (cur);
  15.267  		}
  15.268 +			cur=next (cur,prev,selbi);
  15.269 +		}	
  15.270 +		updateActions();
  15.271 +		reposition();
  15.272  	}	
  15.273 -*/	
  15.274  }
  15.275  
  15.276  void VymModel::emitExpandAll()
  15.277 @@ -2606,6 +2668,7 @@
  15.278  			QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name())
  15.279  		);	
  15.280  		selbi->setHeadingColor(c); // color branch
  15.281 +		mapScene->update();
  15.282  	}
  15.283  }
  15.284  
  15.285 @@ -2627,7 +2690,7 @@
  15.286  			cur->setHeadingColor(c); // color links, color children
  15.287  			cur=next (cur,prev,selbi);
  15.288  		}	
  15.289 -
  15.290 +	mapScene->update();
  15.291  	}
  15.292  }
  15.293  
  15.294 @@ -4057,82 +4120,16 @@
  15.295  	*/
  15.296  }
  15.297  
  15.298 -void VymModel::reposition()	//FIXME-3 VM should have no need to reposition, this is done in views???
  15.299 +void VymModel::reposition()	//FIXME-4 VM should have no need to reposition, but the views...
  15.300  {
  15.301  	//cout << "VM::reposition blocked="<<blockReposition<<endl;
  15.302  	if (blockReposition) return;
  15.303  
  15.304  	for (int i=0;i<rootItem->branchCount(); i++)
  15.305  		rootItem->getBranchObjNum(i)->reposition();	//	for positioning heading
  15.306 -	emitSelectionChanged();	
  15.307 +	//emitSelectionChanged();	
  15.308  }
  15.309  
  15.310 -/*
  15.311 -QPolygonF VymModel::shape(BranchObj *bo)	//FIXME-4
  15.312 -{
  15.313 -	return QPolygonF ();
  15.314 -	// Creating (arbitrary) shapes
  15.315 -
  15.316 -	QPolygonF p;
  15.317 -	QRectF rb=bo->getBBox();
  15.318 -	if (bo->getDepth()==0)
  15.319 -	{
  15.320 -		// Just take BBox of this mapCenter
  15.321 -		p<<rb.topLeft()<<rb.topRight()<<rb.bottomRight()<<rb.bottomLeft();
  15.322 -		return p;
  15.323 -	}
  15.324 -
  15.325 -	// Take union of BBox and TotalBBox 
  15.326 -
  15.327 -	QRectF ra=bo->getTotalBBox();
  15.328 -	if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
  15.329 -		p   <<ra.bottomLeft()
  15.330 -			<<ra.topLeft()
  15.331 -			<<QPointF (rb.topLeft().x(), ra.topLeft().y() )
  15.332 -			<<rb.topRight()
  15.333 -			<<rb.bottomRight()
  15.334 -			<<QPointF (rb.bottomLeft().x(), ra.bottomLeft().y() ) ;
  15.335 -	else		
  15.336 -		p   <<ra.bottomRight()
  15.337 -			<<ra.topRight()
  15.338 -			<<QPointF (rb.topRight().x(), ra.topRight().y() )
  15.339 -			<<rb.topLeft()
  15.340 -			<<rb.bottomLeft()
  15.341 -			<<QPointF (rb.bottomRight().x(), ra.bottomRight().y() ) ;
  15.342 -	return p;		
  15.343 -}
  15.344 -*/
  15.345 -
  15.346 -/*
  15.347 -void VymModel::moveAway(LinkableMapObj *lmo)	//FIXME-5
  15.348 -{
  15.349 -	// Autolayout:
  15.350 -	//
  15.351 -	// Move all branches and MapCenters away from lmo 
  15.352 -	// to avoid collisions 
  15.353 -
  15.354 -	QPolygonF pA;
  15.355 -	QPolygonF pB;
  15.356 -
  15.357 -	BranchObj *boA=(BranchObj*)lmo;
  15.358 -	BranchObj *boB;
  15.359 -	for (int i=0; i<rootItem->branchCount(); i++)
  15.360 -	{
  15.361 -		boB=rootItem->getBranchNum(i);
  15.362 -		pA=shape (boA);
  15.363 -		pB=shape (boB);
  15.364 -		PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0));
  15.365 -		cout <<"------->"
  15.366 -			<<"="<<r.intersect
  15.367 -			<<"  ("<<qPrintable(boA->getHeading() )<<")"
  15.368 -			<<"  with ("<< qPrintable (boB->getHeading() )
  15.369 -			<<")  willIntersect"
  15.370 -			<<r.willIntersect 
  15.371 -			<<"  minT="<<r.minTranslation<<endl<<endl;
  15.372 -	}
  15.373 -}
  15.374 -*/
  15.375 -
  15.376  
  15.377  void VymModel::setMapLinkStyle (const QString & s)
  15.378  {
  15.379 @@ -4274,7 +4271,7 @@
  15.380  	}
  15.381  }	
  15.382  
  15.383 -void VymModel::setMapBackgroundImage (const QString &fn)	//FIXME-2 missing savestate, move to ME
  15.384 +void VymModel::setMapBackgroundImage (const QString &fn)	//FIXME-3 missing savestate, move to ME
  15.385  {
  15.386  	QColor oldcol=mapScene->backgroundBrush().color();
  15.387  	/*
  15.388 @@ -4753,24 +4750,6 @@
  15.389  }
  15.390  
  15.391  
  15.392 -//bool VymModel::selectInt (LinkableMapObj *lmo)	// FIXME-3 still needed?
  15.393 -/*
  15.394 -{
  15.395 -	if (selection.select(lmo))
  15.396 -	{
  15.397 -		//emitSelectionChanged();
  15.398 -	}
  15.399 -}
  15.400 -
  15.401 -bool VymModel::selectInt (TreeItem *ti)	
  15.402 -{
  15.403 -	if (selection.select(lmo))
  15.404 -	{
  15.405 -		//emitSelectionChanged();
  15.406 -	}
  15.407 -}
  15.408 -*/
  15.409 -
  15.410  bool VymModel::selectFirstBranch()
  15.411  {
  15.412  	TreeItem *ti=getSelectedBranch();
    16.1 --- a/vymmodel.h	Fri Sep 11 12:56:15 2009 +0000
    16.2 +++ b/vymmodel.h	Thu Sep 17 09:41:09 2009 +0000
    16.3 @@ -190,12 +190,6 @@
    16.4  		const QString &comment, 
    16.5  		TreeItem *saveSelection);
    16.6  	/*! Overloaded for convenience */
    16.7 -    void saveStateComplete(
    16.8 -		TreeItem *undoSelection, 
    16.9 -		TreeItem* redoSelection, 
   16.10 -		const QString &redoCommand, 
   16.11 -		const QString &comment);
   16.12 -	/*! Overloaded for convenience */
   16.13      void saveStateChangingPart(
   16.14  		TreeItem *undoSelection, 
   16.15  		TreeItem* redoSelection, 
   16.16 @@ -290,8 +284,11 @@
   16.17      void paste();			//!< Paste clipboard to branch and backup
   16.18      void cut();				//!< Cut to clipboard (and copy)
   16.19  
   16.20 -    void moveUp();			//!< Move branch up
   16.21 +    bool moveUp(BranchItem *bi);	//!< Move branch up without saving state
   16.22 +    void moveUp();					//!< Move branch up with saving state
   16.23 +    bool moveDown(BranchItem *bi);	//!< Move branch down without saving state
   16.24      void moveDown();		//!< Move branch down
   16.25 +	void detach();					//!< Detach branch and use as new mapcenter
   16.26  	void sortChildren();	//!< Sort children lexically
   16.27  
   16.28  	// The create methods are used to quickly parse a XML file
   16.29 @@ -347,6 +344,7 @@
   16.30  	void deleteChildren();				//!< keep branch, but remove children
   16.31  
   16.32  	TreeItem* deleteItem(TreeItem*);	//!< Delete item and return parent (if parent!= rootItem)
   16.33 +	void clearItem (TreeItem* ti);		//!< Remove all children of TreeItem ti
   16.34  	bool scrollBranch(BranchItem *);
   16.35  	bool unscrollBranch(BranchItem *);
   16.36  public:	
   16.37 @@ -441,9 +439,6 @@
   16.38  	void reposition();					//!< Call reposition for all MCOs
   16.39  	void setHideTmpMode (TreeItem::HideTmpMode mode);	
   16.40  
   16.41 -	//FIXME-5 QPolygonF shape(BranchObj *bo);		//!< Returns arbitrary shape of subtree
   16.42 -	//FIXME-5 void moveAway (LinkableMapObj *lmo);//!< Autolayout: Move all out of the way
   16.43 -
   16.44  	void emitNoteHasChanged (TreeItem *ti);
   16.45  	void emitDataHasChanged (TreeItem *ti);
   16.46  
   16.47 @@ -579,8 +574,6 @@
   16.48  signals:
   16.49  	void showSelection();
   16.50  
   16.51 -//	bool selectInt(LinkableMapObj*);	//FIXME-4
   16.52 -
   16.53  public:	
   16.54      bool selectFirstBranch();
   16.55      bool selectLastBranch();
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/xlinkitem.cpp	Thu Sep 17 09:41:09 2009 +0000
    17.3 @@ -0,0 +1,210 @@
    17.4 +#include <QGraphicsScene>
    17.5 +#include "xlinkitem.h"
    17.6 +
    17.7 +#include "branchitem.h"
    17.8 +#include "linkablemapobj.h"
    17.9 +#include "vymmodel.h"
   17.10 +#include "xlinkobj.h"
   17.11 +
   17.12 +#include <iostream>
   17.13 +using namespace std;
   17.14 +
   17.15 +/////////////////////////////////////////////////////////////////
   17.16 +// XLinkItem
   17.17 +/////////////////////////////////////////////////////////////////
   17.18 +
   17.19 +XLinkItem::XLinkItem (const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
   17.20 +
   17.21 +{
   17.22 +	//cout << "Const XLinkItem () "<<this<<endl;
   17.23 +	init();
   17.24 +}
   17.25 +
   17.26 +XLinkItem::~XLinkItem ()
   17.27 +{
   17.28 +	cout << "Destr XLinkItem "<<this<<"  lmo="<<lmo<<endl;
   17.29 +	if (lmo){cout <<" calling delete\n"; delete (lmo);}
   17.30 +	if (partnerXLink)
   17.31 +	{
   17.32 +		// Also delete partner 
   17.33 +		cout << "  deleting partner="<<partnerXLink<<endl;
   17.34 +		partnerXLink->partnerXLink=NULL;	// avoid endless recusion
   17.35 +		model->deleteItem (partnerXLink);
   17.36 +	}
   17.37 +}
   17.38 +
   17.39 +
   17.40 +void XLinkItem::init () 
   17.41 +{
   17.42 +	setType (XLink);
   17.43 +	beginBranch=NULL;
   17.44 +	endBranch=NULL;
   17.45 +	partnerXLink=NULL;
   17.46 +	isBeginXLink=true;
   17.47 +	xLinkState=XLinkItem::undefinedXLink;
   17.48 +
   17.49 +	color=QColor (180,180,180);
   17.50 +	width=1;
   17.51 +}
   17.52 +
   17.53 +void XLinkItem::setBegin (BranchItem *bi)
   17.54 +{
   17.55 +	if (bi) 
   17.56 +	{
   17.57 +		xLinkState=initXLink;
   17.58 +		beginBranch=bi;
   17.59 +	}	
   17.60 +}
   17.61 +
   17.62 +BranchItem* XLinkItem::getBegin ()
   17.63 +{
   17.64 +	return beginBranch;
   17.65 +}
   17.66 +
   17.67 +void XLinkItem::setEnd (BranchItem *bi)
   17.68 +{
   17.69 +	if (bi) 
   17.70 +	{
   17.71 +		xLinkState=initXLink;
   17.72 +		endBranch=bi;
   17.73 +	}		
   17.74 +}
   17.75 +
   17.76 +BranchItem* XLinkItem::getEnd()
   17.77 +{
   17.78 +	return endBranch;
   17.79 +}
   17.80 +
   17.81 +void XLinkItem::setWidth (int w)
   17.82 +{
   17.83 +	if (isBeginXLink)
   17.84 +	{
   17.85 +		width=w;
   17.86 +		if (lmo) ((XLinkObj*)lmo)->updateXLink();
   17.87 +		return;
   17.88 +	}
   17.89 +	if (partnerXLink)
   17.90 +		partnerXLink->setWidth (w);
   17.91 +}
   17.92 +
   17.93 +int XLinkItem::getWidth()
   17.94 +{
   17.95 +	if (isBeginXLink) return width;
   17.96 +	if (partnerXLink)
   17.97 +		return partnerXLink->getWidth();
   17.98 +	else
   17.99 +		return -1;
  17.100 +}
  17.101 +
  17.102 +void XLinkItem::setColor(QColor c)
  17.103 +{
  17.104 +	if (isBeginXLink)
  17.105 +	{
  17.106 +		color=c;
  17.107 +		if (lmo) ((XLinkObj*)lmo)->updateXLink();
  17.108 +		return;
  17.109 +	}	
  17.110 +	if (partnerXLink)
  17.111 +		partnerXLink->setColor (c);
  17.112 +}
  17.113 +
  17.114 +QColor XLinkItem::getColor()
  17.115 +{
  17.116 +	if (isBeginXLink) return color;
  17.117 +	if (partnerXLink)
  17.118 +		return partnerXLink->getColor();
  17.119 +	else
  17.120 +		return QColor();
  17.121 +}
  17.122 +
  17.123 +void XLinkItem::setEnd (QPointF p)
  17.124 +{
  17.125 +	if (lmo) ((XLinkObj*)lmo)->setEnd (p);
  17.126 +}
  17.127 +
  17.128 +bool XLinkItem::activate ()	
  17.129 +{
  17.130 +	if (beginBranch && endBranch)
  17.131 +	{
  17.132 +		if (beginBranch==endBranch) return false;
  17.133 +
  17.134 +		partnerXLink=model->createXLink (endBranch);
  17.135 +		partnerXLink->setBegin (beginBranch);
  17.136 +		partnerXLink->setEnd (endBranch);
  17.137 +		partnerXLink->partnerXLink=this;
  17.138 +		partnerXLink->isBeginXLink=false;
  17.139 +
  17.140 +		xLinkState=activeXLink;
  17.141 +		partnerXLink->xLinkState=activeXLink;
  17.142 +		partnerXLink->setHeading ("xLink to: "+beginBranch->getHeading());
  17.143 +		setHeading ("xLink to: "+endBranch->getHeading());
  17.144 +
  17.145 +		model->updateActions();
  17.146 +		return true;
  17.147 +	} else
  17.148 +		return false;
  17.149 +}
  17.150 +
  17.151 +bool XLinkItem::isBegin()
  17.152 +{
  17.153 +	return isBeginXLink;
  17.154 +}
  17.155 +
  17.156 +void XLinkItem::updateXLink()
  17.157 +{
  17.158 +	if(lmo && isBeginXLink) 
  17.159 +		((XLinkObj*)lmo)->updateXLink();
  17.160 +	else 
  17.161 +		if (partnerXLink) partnerXLink->updateXLink();
  17.162 +}
  17.163 +
  17.164 +void XLinkItem::updateVisibility()
  17.165 +{
  17.166 +	if (lmo) lmo->updateVisibility();
  17.167 +}
  17.168 +
  17.169 +BranchItem* XLinkItem::getPartnerBranch()
  17.170 +{
  17.171 +	if (!beginBranch && !endBranch)
  17.172 +		return NULL;
  17.173 +	if (isBeginXLink)
  17.174 +		return endBranch;
  17.175 +	else	
  17.176 +		return beginBranch;
  17.177 +}
  17.178 +
  17.179 +
  17.180 +XLinkItem* XLinkItem::getPartnerXLink()
  17.181 +{
  17.182 +	return partnerXLink;
  17.183 +}
  17.184 +
  17.185 +
  17.186 +QString XLinkItem::saveToDir ()
  17.187 +{
  17.188 +	QString s="";
  17.189 +	if (beginBranch && endBranch && xLinkState==activeXLink)
  17.190 +	{
  17.191 +		if (beginBranch==endBranch )
  17.192 +			qWarning ("XLI::saveToDir  beginBranch==endBranch"); //FIXME-3	s=""
  17.193 +		else
  17.194 +		{
  17.195 +			QString colAttr=attribut ("color",color.name());
  17.196 +			QString widAttr=attribut ("width",QString().setNum(width,10));
  17.197 +			QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
  17.198 +			QString endSelAttr=attribut ("endID",  model->getSelectString(endBranch));
  17.199 +			s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
  17.200 +
  17.201 +			s+=endElement ("xlink");
  17.202 +		}
  17.203 +	}
  17.204 +	return s;
  17.205 +}
  17.206 +
  17.207 +XLinkObj* XLinkItem::createMapObj(QGraphicsScene *scene)  
  17.208 +{
  17.209 +	XLinkObj* xlo=new XLinkObj (scene,this);
  17.210 +	lmo=(LinkableMapObj*)xlo;
  17.211 +	return xlo;
  17.212 +}
  17.213 +
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/xlinkitem.h	Thu Sep 17 09:41:09 2009 +0000
    18.3 @@ -0,0 +1,48 @@
    18.4 +#ifndef XLINKITEM_H
    18.5 +#define XLINKITEM_H
    18.6 +
    18.7 +class BranchItem;
    18.8 +class XLinkObj;
    18.9 +class QGraphicsScene;
   18.10 +
   18.11 +#include "mapitem.h"
   18.12 +
   18.13 +/*! \brief xlinks are used to draw arbitrary connections between branches (BranchObj) in the map. */
   18.14 +
   18.15 +/////////////////////////////////////////////////////////////////////////////
   18.16 +class XLinkItem:public MapItem {
   18.17 +public:
   18.18 +	enum XLinkState {undefinedXLink,initXLink,activeXLink,deleteXLink};	
   18.19 +
   18.20 +	XLinkItem (const QList<QVariant> &data, TreeItem *parent=NULL);
   18.21 +    virtual ~XLinkItem ();
   18.22 +    virtual void init ();
   18.23 +	void setBegin (BranchItem*);
   18.24 +	BranchItem* getBegin();
   18.25 +	void setEnd   (BranchItem*);
   18.26 +	void setEnd   (QPointF);
   18.27 +	BranchItem* getEnd();
   18.28 +	void setColor(QColor);
   18.29 +	QColor getColor();
   18.30 +	void setWidth (int);
   18.31 +	int getWidth ();
   18.32 +	bool activate ();			//! Creates a 2nd XLink (without a XLinkObj attached) 
   18.33 +	bool isBegin();		//! true, if this is master xLink, which may have an XLinkObj attached
   18.34 +	void updateXLink();
   18.35 +	virtual void updateVisibility();	// FIXME-3 not really needed atm...
   18.36 +	BranchItem* getPartnerBranch ();
   18.37 +	XLinkItem *getPartnerXLink();	//! Partner XLink
   18.38 +	QString saveToDir ();
   18.39 +	virtual XLinkObj* createMapObj(QGraphicsScene *scene);
   18.40 +
   18.41 +private:
   18.42 +	XLinkState xLinkState;	// init during drawing or active
   18.43 +	QColor color;
   18.44 +	int width;
   18.45 +	BranchItem *beginBranch;
   18.46 +	BranchItem *endBranch;
   18.47 +	XLinkItem *partnerXLink;
   18.48 +	bool isBeginXLink;
   18.49 +};
   18.50 +
   18.51 +#endif
    19.1 --- a/xml-vym.cpp	Fri Sep 11 12:56:15 2009 +0000
    19.2 +++ b/xml-vym.cpp	Thu Sep 17 09:41:09 2009 +0000
    19.3 @@ -14,8 +14,6 @@
    19.4  #include "version.h"
    19.5  #include "xlinkitem.h"
    19.6  
    19.7 -static ImageItem *lastImageItem;
    19.8 -static MapItem *lastMI;
    19.9  
   19.10  extern Main *mainWindow;
   19.11  extern Settings settings;
   19.12 @@ -145,7 +143,8 @@
   19.13  		{
   19.14  			// Treat the found mapcenter as a branch 
   19.15  			// in an existing map
   19.16 -			BranchItem *bi=model->getSelectedBranch();	//FIXME-2 selection is no longer used here... 
   19.17 +			BranchItem *bi=model->getSelectedBranch();	
   19.18 +			cout << "xml-vym  bi="<<bi->getHeadingStd()<<"  loadMode="<<loadMode<<endl;
   19.19  			if (bi)
   19.20  			{
   19.21  				lastBranch=bi;
   19.22 @@ -153,7 +152,7 @@
   19.23  				{
   19.24  					lastBranch=model->createBranch(lastBranch);
   19.25  				} //else
   19.26 -					//lastBranch->clear(); //FIXME-2 clear not really defined!
   19.27 +					model->clearItem(lastBranch); 
   19.28  			} else
   19.29  				// add mapCenter without parent
   19.30  				lastBranch=model->createMapCenter(); 
   19.31 @@ -190,9 +189,9 @@
   19.32  		if (!readImageAttr(atts)) return false;
   19.33  	} else if ( (eName == "branch"||eName=="floatimage") && state == StateMap) 
   19.34  	{
   19.35 -		// This is used in vymparts, which have no mapcenter!
   19.36 +		// This is used in vymparts, which have no mapcenter or for undo
   19.37  		isVymPart=true;
   19.38 -		TreeItem *ti=model->getSelectedItem();	//FIXME-3 selection is no longer used here...
   19.39 +		TreeItem *ti=model->getSelectedItem();
   19.40  		if (!ti)
   19.41  		{
   19.42  			// If a vym part is _loaded_ (not imported), 
   19.43 @@ -202,6 +201,7 @@
   19.44  			// FIXME-3 lmo=model->first()->getLMO();		
   19.45  			// Do we really have no MCO when loading?????
   19.46  			cout << "xml-vym aborted\n";
   19.47 +			return false;
   19.48  		}	
   19.49  		if (ti && ti->isBranchLikeType() )
   19.50  		{
   19.51 @@ -212,9 +212,8 @@
   19.52  				if (loadMode==ImportAdd)
   19.53  				{
   19.54  					lastBranch=model->createBranch(lastBranch);
   19.55 -					
   19.56  				} else
   19.57 -					//FIXME-2 lastBranch->clear();
   19.58 +					model->clearItem (lastBranch);
   19.59  				readBranchAttr (atts);
   19.60  			} else if (eName=="floatimage")
   19.61  			{
    20.1 --- a/xml-vym.h	Fri Sep 11 12:56:15 2009 +0000
    20.2 +++ b/xml-vym.h	Thu Sep 17 09:41:09 2009 +0000
    20.3 @@ -55,5 +55,6 @@
    20.4  
    20.5  	BranchItem* lastBranch;
    20.6  	ImageItem* lastImage;
    20.7 +	MapItem* lastMI;
    20.8  }; 
    20.9  #endif