# HG changeset patch # User insilmaril # Date 1200394481 0 # Node ID 65c5a0c28d2000dfedc9ba2b3540d8e0e419ba74 # Parent 4004e795b1ad9bbb21a32d8d65a387045196e4e2 added some missing files diff -r 4004e795b1ad -r 65c5a0c28d20 geometry.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geometry.cpp Tue Jan 15 10:54:41 2008 +0000 @@ -0,0 +1,41 @@ +#include "geometry.h" + + +QRectF addBBox(QRectF r1, QRectF r2) +{ + // Find smallest QRectF containing given rectangles + + QRectF n; + // Set left border + if (r1.left() <= r2.left() ) + n.setLeft(r1.left() ); + else + n.setLeft(r2.left() ); + + // Set top border + if (r1.top() <= r2.top() ) + n.setTop(r1.top() ); + else + n.setTop(r2.top() ); + + // Set right border + if (r1.right() <= r2.right() ) + n.setRight(r2.right() ); + else + n.setRight(r1.right() ); + + // Set bottom + if (r1.bottom() <= r2.bottom() ) + n.setBottom(r2.bottom() ); + else + n.setBottom(r1.bottom() ); + return n; +} + +bool inBox(const QPointF &p, const QRectF &box) +{ + if (p.x() >= box.left() && p.x() <= box.right() + && p.y() <= box.bottom() && p.y() >= box.top() ) + return true; + return false; +} diff -r 4004e795b1ad -r 65c5a0c28d20 geometry.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/geometry.h Tue Jan 15 10:54:41 2008 +0000 @@ -0,0 +1,10 @@ +#ifndef GEOMETRY_H +#define GEOMETRY_H + +#include + +QRectF addBBox(QRectF r1, QRectF r2); +bool inBox(const QPointF &p, const QRectF &box); + + +#endif diff -r 4004e795b1ad -r 65c5a0c28d20 mapeditor.cpp --- a/mapeditor.cpp Mon Jan 14 16:33:13 2008 +0000 +++ b/mapeditor.cpp Tue Jan 15 10:54:41 2008 +0000 @@ -4258,7 +4258,8 @@ void MapEditor::testFunction2() { - cout << "Selection: "<getSelectString(xelection.getBranch()).ascii()<addMapCenter(); /* diff -r 4004e795b1ad -r 65c5a0c28d20 selection.cpp --- a/selection.cpp Mon Jan 14 16:33:13 2008 +0000 +++ b/selection.cpp Tue Jan 15 10:54:41 2008 +0000 @@ -184,7 +184,9 @@ QString Selection::getSelectString()// TODO no multiselections yet { if (selectList.count()==1) - return selectList.first()->getSelectString(); + { + return model->getSelectString (selectList.first() ); + } else return""; } diff -r 4004e795b1ad -r 65c5a0c28d20 vymmodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vymmodel.cpp Tue Jan 15 10:54:41 2008 +0000 @@ -0,0 +1,311 @@ +#include + +#include "geometry.h" // for addBBox +#include "vymmodel.h" + +VymModel::VymModel() +{ +// cout << "Const VymModel\n"; +} + + +VymModel::~VymModel() +{ +// cout << "Destr VymModel\n"; +} + +void VymModel::clear() +{ + for (int i=0; iclear(); + mapCenters.clear(); +} + +void VymModel::init () +{ +} + +void VymModel::setMapEditor(MapEditor *me) +{ + mapEditor=me; + for (int i=0; isetMapEditor(mapEditor); +} + +MapEditor* VymModel::getMapEditor() +{ + return mapEditor; +} + +void VymModel::setVersion (const QString &s) +{ + version=s; +} + +void VymModel::setAuthor (const QString &s) +{ + author=s; +} + +QString VymModel::getAuthor() +{ + return author; +} + +void VymModel::setComment (const QString &s) +{ + comment=s; +} + +QString VymModel::getComment () +{ + return comment; +} + +QString VymModel::getDate () +{ + return QDate::currentDate().toString ("yyyy-MM-dd"); +} + +void VymModel::setScene (QGraphicsScene *s) +{ + mapScene=s; + init(); // Here we have a mapScene set, + // which is (still) needed to create MapCenters +} + +QGraphicsScene* VymModel::getScene () +{ + return mapScene; +} + +MapCenterObj* VymModel::addMapCenter() +{ + MapCenterObj *mapCenter = new MapCenterObj(mapScene); + mapCenter->setVisibility (true); + mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); + mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects + mapCenters.append(mapCenter); + return mapCenter; +} + +MapCenterObj *VymModel::removeMapCenter(MapCenterObj* mco) +{ + int i=mapCenters.indexOf (mco); + if (i>=0) + { + mapCenters.removeAt (i); + delete (mco); + if (i>0) return mapCenters.at(i-1); // Return previous MCO + } + return NULL; +} + +// Only as long as we dont have Model/View yet +LinkableMapObj* VymModel::getSelection() +{ + return mapEditor->getSelection(); +} +BranchObj* VymModel::getSelectedBranch() +{ + return mapEditor->getSelectedBranch(); +} + +bool VymModel::select (const QString &s) +{ + LinkableMapObj *lmo=model->findObjBySelect(s); + +/* + // Finally select the found object + if (lmo) + { + xelection.unselect(); + xelection.select(lmo); + xelection.update(); + ensureSelectionVisible(); + sendSelection (); + return true; + } + return false; +*/ +} + +QString VymModel::getSelectString (LinkableMapObj *lmo) +{ + QString s; + if (!lmo) return s; + if (typeid(*lmo)==typeid(BranchObj) || + typeid(*lmo)==typeid(MapCenterObj) ) + { + LinkableMapObj *par=lmo->getParObj(); + if (par) + { + if (lmo->getDepth() ==1) + // Mainbranch, return + s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); + else + // Branch, call myself recursively + s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); + } else + { + // MapCenter + int i=mapCenters.indexOf ((MapCenterObj*)lmo); + if (i>=0) s=QString("mc:%1").arg(i); + } + } + return s; + +} + +/* FIXME copied from MCO, still needed? +void VymModel::move (double x, double y) +{ + BranchObj::move(x,y); +} + +void VymModel::moveBy (double x, double y) +{ + BranchObj::moveBy(x,y); +} + +void VymModel::moveAll (double x, double y) +{ + // Get rel. position + double dx=x-absPos.x(); + double dy=y-absPos.y(); + + // Move myself and branches + moveAllBy (dx,dy); +} + +void VymModel::moveAllBy (double dx, double dy) +{ + // Move myself and childs + BranchObj::moveBy(dx,dy); +} +*/ +BranchObj* VymModel::first() +{ + if (mapCenters.count()>0) + return mapCenters.first(); + else + return NULL; +} + +BranchObj* VymModel::next(BranchObj *bo_start) +{ + BranchObj *rbo; + BranchObj *bo=bo_start; + if (bo) + { + rbo=bo->next(); + if (rbo) return rbo; + + // Try to find MapCenter of bo + while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj(); + + + // Try to find next MapCenter + int i=mapCenters.indexOf ((MapCenterObj*)bo); + if (i+1 > mapCenters.count() || i<0) return NULL; + if (mapCenters.at(i)!=bo_start) + return mapCenters.at(i); + } + return NULL; + +} + + /* FIXME copied from MCO, still needed? +void VymModel::updateLink() +{ + // set childPos to middle of MapCenterObj + childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 ); + childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 ); + parPos=childPos; + for (int i=0; iupdateLink(); +} + +*/ +void VymModel::updateRelPositions() +{ + for (int i=0; iupdateRelPositions(); +} + +void VymModel::reposition() +{ + for (int i=0;ireposition(); // for positioning heading +} + +void VymModel::setHideTmp (HideTmpMode mode) +{ + for (int i=0;isetHideTmp (mode); +} + +QRectF VymModel::getTotalBBox() +{ + QRectF r; + for (int i=0;igetTotalBBox(), r); + return r; +} + +LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO) +{ + LinkableMapObj *lmo; + + for (int i=0;ifindMapObj (p,excludeLMO); + if (lmo) return lmo; + } + return NULL; +} + +LinkableMapObj* VymModel::findObjBySelect(const QString &s) +{ + LinkableMapObj *lmo; + if (!s.isEmpty() ) + { + QString part; + QString typ; + QString num; + part=s.section(",",0,0); + typ=part.left (3); + num=part.right(part.length() - 3); + if (typ=="mc" && num.toInt()>=0 && num.toInt() findObjBySelect(s); + if (lmo) return lmo; + } + return NULL; +} + +LinkableMapObj* VymModel::findID (const QString &s) +{ + LinkableMapObj *lmo; + for (int i=0; ifindID (s); + if (lmo) return lmo; + } + return NULL; +} + +QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) +{ + QString s; + + for (int i=0; isaveToDir (tmpdir,prefix,verbose,offset); + return s; +} + + diff -r 4004e795b1ad -r 65c5a0c28d20 vymmodel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vymmodel.h Tue Jan 15 10:54:41 2008 +0000 @@ -0,0 +1,67 @@ +#ifndef VYMMODEL_H +#define VYMMODEL_H + +#include + +#include "mapcenterobj.h" +#include "mapeditor.h" + + +/*! \brief This will later be divided into Model/View +*/ + +class VymModel{ +public: + VymModel(); + ~VymModel (); + void clear(); + void init(); + void setMapEditor(MapEditor *me); // FIXME should not be necessary in Model/View + MapEditor* getMapEditor(); + void setVersion(const QString &); + void setAuthor (const QString &); + QString getAuthor (); + void setComment (const QString &); + QString getComment (); + QString getDate(); + void setScene(QGraphicsScene *s); + QGraphicsScene *getScene(); + MapCenterObj* addMapCenter(); + MapCenterObj* removeMapCenter(MapCenterObj *mco); + LinkableMapObj* getSelection(); + BranchObj* getSelectedBranch(); + bool select (const QString &s); + QString getSelectString (LinkableMapObj *lmo); + /* + void move (double,double); // FIXME needed at all? + void moveBy (double,double); // FIXME needed at all? + void moveAll (double,double); // FIXME needed at all? + void moveAllBy (double,double); // FIXME needed at all? + */ + BranchObj* first(); // FIXME replaced by ModelIndex later + BranchObj* next(BranchObj *bo); // FIXME replaced by ModelIndex later + +/* + void updateLink(); +*/ + void updateRelPositions(); + + QRectF getTotalBBox(); + void reposition(); //!< Call reposition for all MCOs + void setHideTmp (HideTmpMode mode); + LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj + LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string + LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID + QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir +private: + QGraphicsScene *mapScene; + MapEditor *mapEditor; + QList mapCenters; + QString version; //!< version string saved in vym file + QString author; + QString comment; + QDate date; +}; + + +#endif