added some missing files
authorinsilmaril
Tue, 15 Jan 2008 10:54:41 +0000
changeset 65065c5a0c28d20
parent 649 4004e795b1ad
child 651 1e51ba080947
added some missing files
geometry.cpp
geometry.h
mapeditor.cpp
selection.cpp
vymmodel.cpp
vymmodel.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/geometry.cpp	Tue Jan 15 10:54:41 2008 +0000
     1.3 @@ -0,0 +1,41 @@
     1.4 +#include "geometry.h"
     1.5 +
     1.6 +
     1.7 +QRectF addBBox(QRectF r1, QRectF r2)
     1.8 +{	
     1.9 +	// Find smallest QRectF containing given rectangles
    1.10 +
    1.11 +	QRectF n;
    1.12 +	// Set left border
    1.13 +	if (r1.left() <= r2.left() )
    1.14 +		n.setLeft(r1.left() );
    1.15 +	else
    1.16 +		n.setLeft(r2.left() );
    1.17 +		
    1.18 +	// Set top border		
    1.19 +	if (r1.top() <= r2.top() )
    1.20 +		n.setTop(r1.top() );
    1.21 +	else
    1.22 +		n.setTop(r2.top() );
    1.23 +		
    1.24 +	// Set right border
    1.25 +	if (r1.right() <= r2.right() )
    1.26 +		n.setRight(r2.right() );
    1.27 +	else
    1.28 +		n.setRight(r1.right() );
    1.29 +		
    1.30 +	// Set bottom 
    1.31 +	if (r1.bottom() <= r2.bottom() )
    1.32 +		n.setBottom(r2.bottom() );
    1.33 +	else
    1.34 +		n.setBottom(r1.bottom() );
    1.35 +	return n;
    1.36 +}
    1.37 +
    1.38 +bool inBox(const QPointF &p, const QRectF &box)
    1.39 +{
    1.40 +    if (p.x() >= box.left() && p.x() <= box.right()  
    1.41 +	&& p.y() <= box.bottom() && p.y() >= box.top() )
    1.42 +		return true;
    1.43 +    return false;	
    1.44 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/geometry.h	Tue Jan 15 10:54:41 2008 +0000
     2.3 @@ -0,0 +1,10 @@
     2.4 +#ifndef GEOMETRY_H
     2.5 +#define GEOMETRY_H
     2.6 +
     2.7 +#include <QRectF>
     2.8 +
     2.9 +QRectF addBBox(QRectF r1, QRectF r2);
    2.10 +bool inBox(const QPointF &p, const QRectF &box);
    2.11 +
    2.12 +
    2.13 +#endif
     3.1 --- a/mapeditor.cpp	Mon Jan 14 16:33:13 2008 +0000
     3.2 +++ b/mapeditor.cpp	Tue Jan 15 10:54:41 2008 +0000
     3.3 @@ -4258,7 +4258,8 @@
     3.4  void MapEditor::testFunction2()
     3.5  {
     3.6  
     3.7 -	cout << "Selection: "<<xelection.getSelectString().ascii()<<endl;
     3.8 +	cout << "Selection   (org): "<<xelection.getSelectString().ascii()<<endl;
     3.9 +	cout << "Selection (model): "<<model->getSelectString(xelection.getBranch()).ascii()<<endl;
    3.10  //	model->addMapCenter();
    3.11  
    3.12  /*
     4.1 --- a/selection.cpp	Mon Jan 14 16:33:13 2008 +0000
     4.2 +++ b/selection.cpp	Tue Jan 15 10:54:41 2008 +0000
     4.3 @@ -184,7 +184,9 @@
     4.4  QString Selection::getSelectString()// TODO no multiselections yet
     4.5  {
     4.6  	if (selectList.count()==1)
     4.7 -		return selectList.first()->getSelectString();
     4.8 +	{
     4.9 +		return model->getSelectString (selectList.first() );
    4.10 +	}
    4.11  	else
    4.12  		return"";
    4.13  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/vymmodel.cpp	Tue Jan 15 10:54:41 2008 +0000
     5.3 @@ -0,0 +1,311 @@
     5.4 +#include <QApplication>
     5.5 +
     5.6 +#include "geometry.h"		// for addBBox
     5.7 +#include "vymmodel.h"
     5.8 +
     5.9 +VymModel::VymModel() 
    5.10 +{
    5.11 +//    cout << "Const VymModel\n";
    5.12 +}
    5.13 +
    5.14 +
    5.15 +VymModel::~VymModel() 
    5.16 +{
    5.17 +//    cout << "Destr VymModel\n";
    5.18 +}	
    5.19 +
    5.20 +void VymModel::clear() 
    5.21 +{
    5.22 +	for (int i=0; i<mapCenters.count(); i++)
    5.23 +		mapCenters.at(i)->clear();
    5.24 +	mapCenters.clear();	
    5.25 +}
    5.26 +
    5.27 +void VymModel::init () 
    5.28 +{
    5.29 +}
    5.30 +
    5.31 +void VymModel::setMapEditor(MapEditor *me)
    5.32 +{
    5.33 +	mapEditor=me;
    5.34 +	for (int i=0; i<mapCenters.count(); i++)
    5.35 +		mapCenters.at(i)->setMapEditor(mapEditor);
    5.36 +}
    5.37 +
    5.38 +MapEditor* VymModel::getMapEditor()
    5.39 +{
    5.40 +	return mapEditor;
    5.41 +}
    5.42 +
    5.43 +void VymModel::setVersion (const QString &s)
    5.44 +{
    5.45 +	version=s;
    5.46 +}
    5.47 +
    5.48 +void VymModel::setAuthor (const QString &s)
    5.49 +{
    5.50 +	author=s;
    5.51 +}
    5.52 +
    5.53 +QString VymModel::getAuthor()
    5.54 +{
    5.55 +	return author;
    5.56 +}
    5.57 +
    5.58 +void VymModel::setComment (const QString &s)
    5.59 +{
    5.60 +	comment=s;
    5.61 +}
    5.62 +
    5.63 +QString VymModel::getComment ()
    5.64 +{
    5.65 +	return comment;
    5.66 +}
    5.67 +
    5.68 +QString VymModel::getDate ()
    5.69 +{
    5.70 +	return QDate::currentDate().toString ("yyyy-MM-dd");
    5.71 +}
    5.72 +
    5.73 +void VymModel::setScene (QGraphicsScene *s)
    5.74 +{
    5.75 +	mapScene=s;
    5.76 +    init();	// Here we have a mapScene set, 
    5.77 +			// which is (still) needed to create MapCenters
    5.78 +}
    5.79 +
    5.80 +QGraphicsScene* VymModel::getScene ()
    5.81 +{
    5.82 +	return mapScene;
    5.83 +}
    5.84 +
    5.85 +MapCenterObj* VymModel::addMapCenter()
    5.86 +{
    5.87 +	MapCenterObj *mapCenter = new MapCenterObj(mapScene);
    5.88 +    mapCenter->setVisibility (true);
    5.89 +	mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
    5.90 +	mapCenter->setMapEditor(mapEditor);		//FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
    5.91 +	mapCenters.append(mapCenter);
    5.92 +	return mapCenter;
    5.93 +}
    5.94 +
    5.95 +MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco)
    5.96 +{
    5.97 +	int i=mapCenters.indexOf (mco);
    5.98 +	if (i>=0)
    5.99 +	{
   5.100 +		mapCenters.removeAt (i);
   5.101 +		delete (mco);
   5.102 +		if (i>0) return mapCenters.at(i-1);	// Return previous MCO
   5.103 +	}
   5.104 +	return NULL;
   5.105 +}
   5.106 +
   5.107 +// Only as long as we dont have Model/View yet
   5.108 +LinkableMapObj* VymModel::getSelection()
   5.109 +{
   5.110 +	return mapEditor->getSelection();
   5.111 +}
   5.112 +BranchObj* VymModel::getSelectedBranch()
   5.113 +{
   5.114 +	return mapEditor->getSelectedBranch();
   5.115 +}
   5.116 +
   5.117 +bool VymModel::select (const QString &s)
   5.118 +{
   5.119 +	LinkableMapObj *lmo=model->findObjBySelect(s);
   5.120 +
   5.121 +/*
   5.122 +	// Finally select the found object
   5.123 +	if (lmo)
   5.124 +	{
   5.125 +		xelection.unselect();
   5.126 +		xelection.select(lmo);
   5.127 +		xelection.update();
   5.128 +		ensureSelectionVisible();
   5.129 +		sendSelection ();
   5.130 +		return true;
   5.131 +	} 
   5.132 +	return false;
   5.133 +*/
   5.134 +}
   5.135 +
   5.136 +QString VymModel::getSelectString (LinkableMapObj *lmo)
   5.137 +{
   5.138 +	QString s;
   5.139 +	if (!lmo) return s;
   5.140 +	if (typeid(*lmo)==typeid(BranchObj) ||
   5.141 +		typeid(*lmo)==typeid(MapCenterObj) )
   5.142 +	{	
   5.143 +		LinkableMapObj *par=lmo->getParObj();
   5.144 +		if (par)
   5.145 +		{
   5.146 +			if (lmo->getDepth() ==1)
   5.147 +				// Mainbranch, return 
   5.148 +				s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
   5.149 +			else	
   5.150 +				// Branch, call myself recursively
   5.151 +				s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum());
   5.152 +		} else
   5.153 +		{
   5.154 +			// MapCenter
   5.155 +			int i=mapCenters.indexOf ((MapCenterObj*)lmo);
   5.156 +			if (i>=0) s=QString("mc:%1").arg(i);
   5.157 +		}	
   5.158 +	}	
   5.159 +	return s;
   5.160 +
   5.161 +}
   5.162 +
   5.163 +/* FIXME copied from MCO, still needed?
   5.164 +void VymModel::move (double x, double y)
   5.165 +{
   5.166 +	BranchObj::move(x,y);
   5.167 +}
   5.168 +
   5.169 +void VymModel::moveBy (double x, double y)
   5.170 +{
   5.171 +	BranchObj::moveBy(x,y);
   5.172 +}
   5.173 +
   5.174 +void VymModel::moveAll (double x, double y)
   5.175 +{
   5.176 +	// Get rel. position
   5.177 +	double dx=x-absPos.x();
   5.178 +	double dy=y-absPos.y();
   5.179 +
   5.180 +	// Move myself and branches
   5.181 +	moveAllBy (dx,dy);
   5.182 +}
   5.183 +
   5.184 +void VymModel::moveAllBy (double dx, double dy)
   5.185 +{
   5.186 +	// Move myself and childs
   5.187 +	BranchObj::moveBy(dx,dy);
   5.188 +}
   5.189 +*/
   5.190 +BranchObj* VymModel::first()
   5.191 +{
   5.192 +	if (mapCenters.count()>0) 
   5.193 +		return mapCenters.first();
   5.194 +	else	
   5.195 +		return NULL;
   5.196 +}
   5.197 +	
   5.198 +BranchObj* VymModel::next(BranchObj *bo_start)
   5.199 +{
   5.200 +	BranchObj *rbo;
   5.201 +	BranchObj *bo=bo_start;
   5.202 +	if (bo)
   5.203 +	{
   5.204 +		rbo=bo->next();
   5.205 +		if (rbo) return rbo;
   5.206 +
   5.207 +		// Try to find MapCenter of bo
   5.208 +		while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
   5.209 +
   5.210 +
   5.211 +		// Try to find next MapCenter
   5.212 +		int i=mapCenters.indexOf ((MapCenterObj*)bo);
   5.213 +		if (i+1 > mapCenters.count() || i<0) return NULL;
   5.214 +		if (mapCenters.at(i)!=bo_start)
   5.215 +			return mapCenters.at(i);
   5.216 +	} 
   5.217 +	return NULL;
   5.218 +
   5.219 +}
   5.220 +	
   5.221 +	/* FIXME copied from MCO, still needed?
   5.222 +void VymModel::updateLink()
   5.223 +{
   5.224 +	// set childPos to middle of MapCenterObj
   5.225 +	childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 );
   5.226 +	childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 );
   5.227 +	parPos=childPos;		
   5.228 +	for (int i=0; i<branch.size(); ++i)
   5.229 +		branch.at(i)->updateLink();
   5.230 +}
   5.231 +
   5.232 +*/
   5.233 +void VymModel::updateRelPositions()
   5.234 +{
   5.235 +	for (int i=0; i<mapCenters.count(); i++)
   5.236 +		mapCenters.at(i)->updateRelPositions();
   5.237 +}
   5.238 +
   5.239 +void VymModel::reposition()
   5.240 +{
   5.241 +	for (int i=0;i<mapCenters.count(); i++)
   5.242 +		mapCenters.at(i)->reposition();	//	for positioning heading
   5.243 +}
   5.244 +
   5.245 +void VymModel::setHideTmp (HideTmpMode mode)
   5.246 +{
   5.247 +	for (int i=0;i<mapCenters.count(); i++)
   5.248 +		mapCenters.at(i)->setHideTmp (mode);	
   5.249 +}
   5.250 +
   5.251 +QRectF VymModel::getTotalBBox()
   5.252 +{
   5.253 +	QRectF r;
   5.254 +	for (int i=0;i<mapCenters.count(); i++)
   5.255 +		r=addBBox (mapCenters.at(i)->getTotalBBox(), r);
   5.256 +	return r;	
   5.257 +}
   5.258 +
   5.259 +LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
   5.260 +{
   5.261 +	LinkableMapObj *lmo;
   5.262 +
   5.263 +	for (int i=0;i<mapCenters.count(); i++)
   5.264 +	{
   5.265 +		lmo=mapCenters.at(i)->findMapObj (p,excludeLMO);
   5.266 +		if (lmo) return lmo;
   5.267 +	}
   5.268 +	return NULL;
   5.269 +}
   5.270 +
   5.271 +LinkableMapObj* VymModel::findObjBySelect(const QString &s)
   5.272 +{
   5.273 +	LinkableMapObj *lmo;
   5.274 +	if (!s.isEmpty() )
   5.275 +	{
   5.276 +		QString part;
   5.277 +		QString typ;
   5.278 +		QString num;
   5.279 +		part=s.section(",",0,0);
   5.280 +		typ=part.left (3);
   5.281 +		num=part.right(part.length() - 3);
   5.282 +		if (typ=="mc" && num.toInt()>=0 && num.toInt() <mapCenters.count() )
   5.283 +			return mapCenters.at(num.toInt() );
   5.284 +	}		
   5.285 +
   5.286 +	for (int i=0; i<mapCenters.count(); i++)
   5.287 +	{
   5.288 +		lmo=mapCenters.at(i)->findObjBySelect(s);
   5.289 +		if (lmo) return lmo;
   5.290 +	}	
   5.291 +	return NULL;
   5.292 +}
   5.293 +
   5.294 +LinkableMapObj* VymModel::findID (const QString &s)
   5.295 +{
   5.296 +	LinkableMapObj *lmo;
   5.297 +	for (int i=0; i<mapCenters.count(); i++)
   5.298 +	{
   5.299 +		lmo=mapCenters.at(i)->findID (s);
   5.300 +		if (lmo) return lmo;
   5.301 +	}	
   5.302 +	return NULL;
   5.303 +}
   5.304 +
   5.305 +QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
   5.306 +{
   5.307 +    QString s;
   5.308 +
   5.309 +	for (int i=0; i<mapCenters.count(); i++)
   5.310 +		s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
   5.311 +    return s;
   5.312 +}
   5.313 +
   5.314 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/vymmodel.h	Tue Jan 15 10:54:41 2008 +0000
     6.3 @@ -0,0 +1,67 @@
     6.4 +#ifndef VYMMODEL_H
     6.5 +#define VYMMODEL_H
     6.6 +
     6.7 +#include <QGraphicsScene>
     6.8 +
     6.9 +#include "mapcenterobj.h"
    6.10 +#include "mapeditor.h"
    6.11 +
    6.12 +
    6.13 +/*! \brief This will later be divided into Model/View
    6.14 +*/
    6.15 +
    6.16 +class VymModel{
    6.17 +public:
    6.18 +	VymModel();
    6.19 +	~VymModel ();
    6.20 +    void clear();
    6.21 +    void init();
    6.22 +	void setMapEditor(MapEditor *me);	// FIXME should not be necessary in Model/View
    6.23 +	MapEditor* getMapEditor();
    6.24 +	void setVersion(const  QString &);
    6.25 +	void setAuthor  (const QString &);
    6.26 +	QString getAuthor ();
    6.27 +	void setComment (const QString &);
    6.28 +	QString getComment ();
    6.29 +	QString getDate();
    6.30 +	void setScene(QGraphicsScene *s);
    6.31 +	QGraphicsScene *getScene();
    6.32 +	MapCenterObj* addMapCenter();
    6.33 +	MapCenterObj* removeMapCenter(MapCenterObj *mco);
    6.34 +	LinkableMapObj* getSelection();
    6.35 +	BranchObj* getSelectedBranch();
    6.36 +	bool select (const QString &s);
    6.37 +	QString getSelectString (LinkableMapObj *lmo);
    6.38 +	/*
    6.39 +    void move      (double,double);		// FIXME needed at all?
    6.40 +    void moveBy    (double,double);		// FIXME needed at all?
    6.41 +    void moveAll   (double,double);		// FIXME needed at all?
    6.42 +    void moveAllBy (double,double);		// FIXME needed at all?
    6.43 +	*/
    6.44 +	BranchObj* first();					// FIXME replaced by ModelIndex later
    6.45 +	BranchObj* next(BranchObj *bo);		// FIXME replaced by ModelIndex later
    6.46 +
    6.47 +/*
    6.48 +    void updateLink();
    6.49 +*/
    6.50 +    void updateRelPositions();
    6.51 +
    6.52 +	QRectF getTotalBBox();
    6.53 +	void reposition();					//!< Call reposition for all MCOs
    6.54 +	void setHideTmp (HideTmpMode mode);	
    6.55 +    LinkableMapObj* findMapObj(QPointF,LinkableMapObj*);	// find MapObj 
    6.56 +    LinkableMapObj* findObjBySelect (const QString &s);		// find MapObj by select string
    6.57 +    LinkableMapObj* findID (const QString &s);				// find MapObj by previously set ID
    6.58 +	QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
    6.59 +private:
    6.60 +	QGraphicsScene *mapScene;
    6.61 +	MapEditor *mapEditor;
    6.62 +	QList <MapCenterObj*> mapCenters;
    6.63 +	QString version;	//!< version string saved in vym file
    6.64 +	QString author;
    6.65 +	QString comment;
    6.66 +	QDate date;
    6.67 +};
    6.68 +
    6.69 +
    6.70 +#endif