# HG changeset patch # User insilmaril # Date 1238598417 0 # Node ID 9ff3329640157cef06c757000f0c6509f9c38e5b # Parent edb78a44240b006c751e0a8fbd57e12a540909d0 moved scroll functions from BranchObj to BranchItem diff -r edb78a44240b -r 9ff332964015 branchitem.cpp --- a/branchitem.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/branchitem.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -6,7 +6,10 @@ BranchItem::BranchItem(const QList &data, TreeItem *parent):TreeItem (data,parent) { - cout << "Constr. BranchItem\n"; + //cout << "Constr. BranchItem\n"; + + scrolled=false; + tmpUnscrolled=false; } BranchItem::~BranchItem() @@ -15,6 +18,12 @@ qDeleteAll(childItems); } +void BranchItem::copy (BranchItem *other) +{ + scrolled=other->scrolled; + tmpUnscrolled=other->tmpUnscrolled; +} + QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) { // Cloudy stuff can be hidden during exports @@ -113,4 +122,87 @@ return s; } +void BranchItem::unScroll() +{ + if (tmpUnscrolled) resetTmpUnscroll(); + if (scrolled) toggleScroll(); +} +void BranchItem::toggleScroll() +{ + if (scrolled) + { + scrolled=false; + //FIXME-1 systemFlags->deactivate("scrolledright"); + /* + for (int i=0; isetVisibility(true); + */ + } else + { + scrolled=true; + /* + //FIXME-1 systemFlags->activate("scrolledright"); + for (int i=0; isetVisibility(false); + */ + } + /* + calcBBoxSize(); + positionBBox(); + move (absPos.x(), absPos.y() ); + forceReposition(); + */ +} + +bool BranchItem::isScrolled() +{ + return scrolled; +} + +bool BranchItem::hasScrolledParent(BranchItem *start) +{ + // Calls parents recursivly to + // find out, if we are scrolled at all. + // But ignore myself, just look at parents. + + if (this !=start && scrolled) return true; + + BranchItem* bi=(BranchItem*)parentItem; + if (bi) + return bi->hasScrolledParent(start); + else + return false; +} + +void BranchItem::tmpUnscroll() +{ + // Unscroll parent (recursivly) + BranchItem * bi=(BranchItem*)parentItem; + if (bi) bi->tmpUnscroll(); + + // Unscroll myself + if (scrolled) + { + tmpUnscrolled=true; + // FIXME-1 systemFlags->activate("tmpUnscrolledright"); + toggleScroll(); + } +} + +void BranchItem::resetTmpUnscroll() +{ + // Unscroll parent (recursivly) + BranchItem * bi=(BranchItem*)parentItem; + if (bi) bi->resetTmpUnscroll(); + + // Unscroll myself + if (tmpUnscrolled) + { + tmpUnscrolled=false; + // FIXME-1 systemFlags->deactivate("tmpUnscrolledright"); + toggleScroll(); + } +} + + diff -r edb78a44240b -r 9ff332964015 branchitem.h --- a/branchitem.h Tue Mar 31 15:36:10 2009 +0000 +++ b/branchitem.h Wed Apr 01 15:06:57 2009 +0000 @@ -10,9 +10,22 @@ public: BranchItem(const QList &data, TreeItem *parent = 0); ~BranchItem(); + void copy (BranchItem *item); QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset); + virtual void unScroll(); + virtual void toggleScroll(); // scroll or unscroll + virtual bool isScrolled(); // returns scroll state + virtual bool hasScrolledParent(BranchItem*); // true, if any of the parents is scrolled + virtual void tmpUnscroll(); // unscroll scrolled parents temporary e.g. during "find" process + virtual void resetTmpUnscroll(); // scroll all tmp scrolled parents again e.g. when unselecting + + +protected: + bool scrolled; // true if all children are scrolled and thus invisible + bool tmpUnscrolled; // can only be true (temporary) for a scrolled subtree + }; #endif diff -r edb78a44240b -r 9ff332964015 branchobj.cpp --- a/branchobj.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/branchobj.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -1,6 +1,7 @@ #include "branchobj.h" // #include "texteditor.h" +#include "branchitem.h" #include "geometry.h" #include "mapeditor.h" #include "mainwindow.h" @@ -58,8 +59,9 @@ cout << "Destr BranchObj of "<getLastBranch(); if (bo) po->unScroll(); } + */ clear(); } @@ -90,9 +93,6 @@ setChildObj(this); - scrolled=false; - tmpUnscrolled=false; - includeImagesVer=false; includeImagesHor=false; } @@ -110,8 +110,7 @@ for (int i=0; ifloatimage.size(); ++i) addFloatImage (other->floatimage.at(i)); - scrolled=other->scrolled; - tmpUnscrolled=other->tmpUnscrolled; + setVisibility (other->visible); angle=other->angle; @@ -141,39 +140,6 @@ return false; } -int BranchObj::getNum() -{ - if (parObj) - return ((BranchObj*)parObj)->getNum (this); - else - return 0; -} - -int BranchObj::getNum(BranchObj *bo) -{ - return branch.indexOf (bo); -} - -int BranchObj::getFloatImageNum(FloatImageObj *fio) -{ - return floatimage.indexOf(fio); -} - -int BranchObj::countBranches() -{ - return branch.count(); -} - -int BranchObj::countFloatImages() -{ - return floatimage.count(); -} - -int BranchObj::countXLinks() -{ - return xlink.count(); -} - void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off) { // Temporary link to lmo @@ -256,86 +222,9 @@ } } -void BranchObj::unScroll() -{ - if (tmpUnscrolled) resetTmpUnscroll(); - if (scrolled) toggleScroll(); -} - -void BranchObj::toggleScroll() -{ - if (scrolled) - { - scrolled=false; - systemFlags->deactivate("scrolledright"); - for (int i=0; isetVisibility(true); - } else - { - scrolled=true; - systemFlags->activate("scrolledright"); - for (int i=0; isetVisibility(false); - } - calcBBoxSize(); - positionBBox(); - move (absPos.x(), absPos.y() ); - forceReposition(); -} - -bool BranchObj::isScrolled() -{ - return scrolled; -} - -bool BranchObj::hasScrolledParent(BranchObj *start) -{ - // Calls parents recursivly to - // find out, if we are scrolled at all. - // But ignore myself, just look at parents. - - if (this !=start && scrolled) return true; - - BranchObj* bo=(BranchObj*)(parObj); - if (bo) - return bo->hasScrolledParent(start); - else - return false; -} - -void BranchObj::tmpUnscroll() -{ - // Unscroll parent (recursivly) - BranchObj* bo=(BranchObj*)(parObj); - if (bo) bo->tmpUnscroll(); - - // Unscroll myself - if (scrolled) - { - tmpUnscrolled=true; - systemFlags->activate("tmpUnscrolledright"); - toggleScroll(); - } -} - -void BranchObj::resetTmpUnscroll() -{ - // Unscroll parent (recursivly) - BranchObj* bo=(BranchObj*)(parObj); - if (bo) - bo->resetTmpUnscroll(); - - // Unscroll myself - if (tmpUnscrolled) - { - tmpUnscrolled=false; - systemFlags->deactivate("tmpUnscrolledright"); - toggleScroll(); - } -} - void BranchObj::setVisibility(bool v, int toDepth) { + BranchItem *bi=(BranchItem*)treeItem; if (depth <= toDepth) { frame->setVisibility(v); @@ -343,7 +232,6 @@ systemFlags->setVisibility(v); standardFlags->setVisibility(v); LinkableMapObj::setVisibility (v); - int i; for (i=0; isetVisibility (v); @@ -351,7 +239,7 @@ xlink.at(i)->setVisibility (); // Only change children, if I am not scrolled - if (!scrolled && (depth < toDepth)) + if (! bi->isScrolled() && (bi->depth() < toDepth)) { // Now go recursivly through all children for (i=0; i0) + if (treeItem->imageCount()>0) { for (int i=0; ihasScrolledParent((BranchItem*)treeItem)) setVisibility (false); else setVisibility (true); @@ -638,14 +526,14 @@ QString s,a; QString scrolledAttr; - if (scrolled) + if ( ((BranchItem*)treeItem)->isScrolled() ) scrolledAttr=attribut ("scrolled","yes"); else scrolledAttr=""; // save area, if not scrolled QString areaAttr; - if (!((BranchObj*)(parObj))->isScrolled() ) + if (!((BranchItem*) (treeItem->parent()) )->isScrolled() ) { areaAttr= attribut("x1",QString().setNum(absPos.x()-offset.x())) + @@ -658,7 +546,7 @@ // Providing an ID for a branch makes export to XHTML easier QString idAttr; - if (countXLinks()>0) + if (treeItem->xlinkCount()>0) idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model else idAttr=""; @@ -744,12 +632,6 @@ return xlink.at(i); } -int BranchObj::countXLink() -{ - return xlink.count(); -} - - BranchObj* BranchObj::XLinkTargetAt (int i) { if (i>=0 && ihasScrolledParent((BranchItem*)treeItem) ) newfi->setVisibility (false); else newfi->setVisibility(visible); @@ -821,7 +703,7 @@ FloatImageObj *newfi=new FloatImageObj (scene,this); floatimage.append (newfi); newfi->copy (fio); - if (hasScrolledParent(this) ) + if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) ) newfi->setVisibility (false); else newfi->setVisibility(visible); @@ -893,10 +775,12 @@ newbo->setParObj(this); newbo->setDefAttr(NewBranch); newbo->setHeading ("new"); - if (scrolled) + /* FIXME-2 treeItem not set yet!!! + if ( ((BranchItem*)treeItem)->isScrolled() ) newbo->setVisibility (false); else newbo->setVisibility(visible); + */ newbo->updateLink(); requestReposition(); return newbo; @@ -909,7 +793,7 @@ newbo->copy(bo); newbo->setParObj(this); newbo->setDefAttr(MovedBranch); - if (scrolled) + if ( ((BranchItem*)treeItem)->isScrolled() ) newbo->setVisibility (false); else newbo->setVisibility(bo->visible); @@ -924,7 +808,8 @@ bo->setParObj (this); bo->depth=depth+1; bo->setDefAttr(MovedBranch); - if (scrolled) tmpUnscroll(); + BranchItem *bi=(BranchItem*)treeItem; + if ( bi->isScrolled() ) bi->tmpUnscroll(); //setLastSelectedBranch (bo); //FIXME-3 needed? return bo; } @@ -958,14 +843,16 @@ bo->setParObj (this); bo->depth=depth+1; bo->setDefAttr (MovedBranch); - if (scrolled) tmpUnscroll(); + BranchItem *bi=(BranchItem*)treeItem; + if ( bi->isScrolled() ) bi->tmpUnscroll(); //setLastSelectedBranch (bo); //FIXME-3 needed? qSort (branch.begin(),branch.end(), isAbove); return bo; } -void BranchObj::removeBranchHere(BranchObj* borem) +void BranchObj::removeBranchHere(BranchObj* borem) // FIXME-1 getNum no longer available { +/* // This removes the branch bo from list, but // inserts its children at the place of bo BranchObj *bo; @@ -977,6 +864,7 @@ bo=borem->getLastBranch(); } removeBranch (borem); + */ } void BranchObj::removeChildren() @@ -1084,9 +972,10 @@ return NULL; } -void BranchObj::sortChildren() +void BranchObj::sortChildren() //FIXME-1 { - int childCount=branch.count(); +/* + int childCount=branch.count(); int curChildIndex; bool madeChanges=false; do @@ -1102,6 +991,7 @@ } } }while(madeChanges); +*/ } @@ -1206,7 +1096,7 @@ } } - if (scrolled) return; + if ( ((BranchItem*)treeItem)->isScrolled() ) return; // Set reference point for alignment of children QPointF ref2; @@ -1301,7 +1191,7 @@ { QRectF r=bbox; - if (scrolled) return r; + if ( ((BranchItem*)treeItem)->isScrolled() ) return r; for (int i=0; iisHidden()) @@ -1332,7 +1222,7 @@ bboxTotal.setY(bbox.y() ); // if branch is scrolled, ignore children, but still consider floatimages - if (scrolled) + if ( ((BranchItem*)treeItem)->isScrolled() ) { bboxTotal.setWidth (bbox.width()); bboxTotal.setHeight(bbox.height()); diff -r edb78a44240b -r 9ff332964015 branchobj.h --- a/branchobj.h Tue Mar 31 15:36:10 2009 +0000 +++ b/branchobj.h Wed Apr 01 15:06:57 2009 +0000 @@ -31,22 +31,10 @@ virtual void init (); virtual void copy (BranchObj*); void clear(); - virtual int getNum(); // return number of this in parent - virtual int getNum(BranchObj*); // return number of this in parent - virtual int getFloatImageNum(FloatImageObj*); - virtual int countBranches(); - virtual int countFloatImages(); - virtual int countXLinks(); + virtual void setParObjTmp (LinkableMapObj*,QPointF,int);// Only for moving Obj around virtual void unsetParObjTmp(); // reuse original ParObj - virtual void unScroll(); - virtual void toggleScroll(); // scroll or unscroll - virtual bool isScrolled(); // returns scroll state - virtual bool hasScrolledParent(BranchObj*); // true, if any of the parents is scrolled - virtual void tmpUnscroll(); // unscroll scrolled parents temporary e.g. during "find" process - virtual void resetTmpUnscroll(); // scroll all tmp scrolled parents again e.g. when unselecting - virtual void setVisibility(bool,int); // set visibility virtual void setVisibility(bool); // set vis. for w virtual void setLinkColor(); // set the color of link @@ -68,18 +56,20 @@ virtual bool hasHiddenExportParent (); virtual QString saveToDir (const QString&,const QString&, const QPointF&);// Save data recursivly to tempdir + virtual void addXLink (XLinkObj*); virtual void removeXLinkRef (XLinkObj*);// Remove ref in list virtual void deleteXLink (XLinkObj*); // remove references and delete XLinkObj virtual void deleteXLinkAt (int); // remove references and delete XLinkObj virtual XLinkObj* XLinkAt (int); // return reference of XLinkObj - virtual int countXLink (); virtual BranchObj* XLinkTargetAt (int); + void setIncludeImagesVer(bool); bool getIncludeImagesVer(); void setIncludeImagesHor(bool); bool getIncludeImagesHor(); QString getIncludeImageAttr(); + virtual FloatImageObj* addFloatImage(); virtual FloatImageObj* addFloatImage(FloatImageObj*); virtual void removeFloatImage(FloatImageObj*); @@ -100,13 +90,16 @@ virtual void removeChildren(); virtual void removeBranch(BranchObj*); virtual void removeBranchPtr (BranchObj*); + virtual BranchObj* getFirstBranch(); virtual BranchObj* getLastBranch(); virtual BranchObj* getBranchNum(int); + virtual bool canMoveBranchUp(); virtual BranchObj* moveBranchUp(BranchObj*); virtual bool canMoveBranchDown(); virtual BranchObj* moveBranchDown(BranchObj*); + virtual void sortChildren(); virtual BranchObj* linkTo (BranchObj*, int); virtual void alignRelativeTo(const QPointF, bool alignSelf=false ); @@ -134,11 +127,10 @@ public: float angle; // used in mainbranch to reorder mainbranches protected: - bool scrolled; // true if all children are scrolled and thus invisible - bool tmpUnscrolled; // can only be true (temporary) for a scrolled subtree +// bool scrolled; // true if all children are scrolled and thus invisible +// bool tmpUnscrolled; // can only be true (temporary) for a scrolled subtree bool includeImagesVer; // include floatimages in bbox vertically bool includeImagesHor; // include floatimages in bbox horizontally - }; diff -r edb78a44240b -r 9ff332964015 demos/vym-projectplan.vym Binary file demos/vym-projectplan.vym has changed diff -r edb78a44240b -r 9ff332964015 exports.cpp --- a/exports.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/exports.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -108,13 +108,13 @@ { // Make prefix like "2.5.3" for "bo:2,bo:5,bo:3" QString r; - BranchObj *bo=bostart; - int depth=bo->getDepth(); + TreeItem *ti=bostart->getTreeItem(); + int depth=ti->depth(); while (depth>0) { - r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r; - bo=(BranchObj*)(bo->getParObj()); - depth=bo->getDepth(); + r=QString("%1").arg(1+ti->num(),0,10)+"." + r; + ti=ti->parent(); + depth=ti->depth(); } if (r.isEmpty()) return r; diff -r edb78a44240b -r 9ff332964015 mainwindow.cpp --- a/mainwindow.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/mainwindow.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -8,6 +8,7 @@ #include "aboutdialog.h" #include "branchpropwindow.h" +#include "branchitem.h" #include "exportoofiledialog.h" #include "exports.h" #include "file.h" @@ -2888,7 +2889,7 @@ stats+=QString ("%1 notes\n").arg (n,6); stats+=QString ("%1 images\n").arg (f,6); */ - stats+=QString ("%1 branches\n").arg (m->countBranches(),6); + stats+=QString ("%1 branches\n").arg (m->branchCount(),6); dia.setStats (stats); // Finally show dialog @@ -3608,8 +3609,10 @@ if ( (typeid(*selection) == typeid(BranchObj)) || (typeid(*selection) == typeid(MapCenterObj)) ) { + BranchItem *bi=(BranchItem*)(selection->getTreeItem() ); BranchObj *bo=(BranchObj*)selection; - // Take care of links + // Take care of links // FIXME-1 + /* if (bo->countXLinks()==0) { branchXLinksContextMenuEdit->clear(); @@ -3633,11 +3636,12 @@ } } } + */ standardFlagsDefault->setEnabled (true); actionToggleScroll->setEnabled (true); - if ( bo->isScrolled() ) + if ( bi->isScrolled() ) actionToggleScroll->setOn(true); else actionToggleScroll->setOn(false); diff -r edb78a44240b -r 9ff332964015 mapcenteritem.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mapcenteritem.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -0,0 +1,118 @@ +#include "mapcenteritem.h" +#include "mapcenterobj.h" + +#include +using namespace std; + +MapCenterItem::MapCenterItem(const QList &data, TreeItem *parent):BranchItem (data,parent) +{ + scrolled=false; + tmpUnscrolled=false; +} + +MapCenterItem::~MapCenterItem() +{ + cout << "Destr. MapCenterItem\n"; + qDeleteAll(childItems); +} + +QString MapCenterItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) +{ + // Cloudy stuff can be hidden during exports + if (hidden) return QString(); + + QString s,a; + BranchObj *bo=(BranchObj*)lmo; + + /* FIXME-1 + // Update of note is usually done while unselecting a branch + if (isNoteInEditor) getNoteFromTextEditor(); + + QString scrolledAttr; + if (scrolled) + scrolledAttr=attribut ("scrolled","yes"); + else + scrolledAttr=""; + + // save area, if not scrolled + QString areaAttr; + if (!((BranchObj*)(parObj))->isScrolled() ) + { + areaAttr= + attribut("x1",QString().setNum(absPos.x()-offset.x())) + + attribut("y1",QString().setNum(absPos.y()-offset.y())) + + attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) + + attribut("y2",QString().setNum(absPos.y()+height()-offset.y())); + + } else + areaAttr=""; + + // Providing an ID for a branch makes export to XHTML easier + QString idAttr; + if (countXLinks()>0) + idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model + else + idAttr=""; + + */ + s=beginElement ("branch" + // +getOrnXMLAttr() + // +scrolledAttr + // +areaAttr + // +idAttr + // +getIncludeImageAttr() + ); + incIndent(); + + // save heading + s+=valueElement("heading", getHeading(), + attribut ("textColor",QColor( bo->getColor()).name())); + +/* + // Save frame + if (frame->getFrameType()!=FrameObj::NoFrame) + s+=frame->saveToDir (); + + // save names of flags set + s+=standardFlags->saveToDir(tmpdir,prefix,0); + + // Save FloatImages + for (int i=0; isaveToDir (tmpdir,prefix); +*/ + + // save note + if (!note.isEmpty() ) + s+=note.saveToDir(); + + // Save branches + TreeItem *ti=getFirstBranch(); + TreeItem *last=getLastBranch(); + while (ti && ti!=last) + s+=ti->saveToDir(tmpdir,prefix,offset); + + /* + // Save XLinks + QString ol; // old link + QString cl; // current link + for (int i=0; isaveToDir(); + if (cl!=ol) + { + s+=cl; + ol=cl; + } else + { + qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading())); + } + } + */ + + decIndent(); + s+=endElement ("branch"); + return s; +} + + + diff -r edb78a44240b -r 9ff332964015 mapcenteritem.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mapcenteritem.h Wed Apr 01 15:06:57 2009 +0000 @@ -0,0 +1,16 @@ +#ifndef MAPCENTERITEM_H +#define MAPCENTERITEM_H + +#include "branchitem.h" + + +class MapCenterItem:public BranchItem +{ +public: + MapCenterItem(const QList &data, TreeItem *parent = 0); + ~MapCenterItem(); + + QString saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset); +}; + +#endif diff -r edb78a44240b -r 9ff332964015 mapcenterobj.cpp --- a/mapcenterobj.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/mapcenterobj.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -145,7 +145,7 @@ // Providing an ID for a branch makes export to XHTML easier QString idAttr; - if (countXLinks()>0) + if (treeItem->xlinkCount()>0) idAttr=attribut ("id",mapEditor->getModel()->getSelectString(this)); //TODO directly access model else diff -r edb78a44240b -r 9ff332964015 mapeditor.cpp --- a/mapeditor.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/mapeditor.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -870,22 +870,24 @@ // We have a destination, relink to that BranchObj* bsel=model->getSelectedBranch(); + TreeItem * tisel=model->getSelectedItem(); BranchObj* bdst=(BranchObj*)dst; + TreeItem* tidst=dst->getTreeItem(); QString preParStr=model->getSelectString (bsel->getParObj()); - QString preNum=QString::number (bsel->getNum(),10); + QString preNum=QString::number (tisel->num(),10); QString preDstParStr; if (e->state() & Qt::ShiftModifier && dst->getParObj()) { // Link above dst preDstParStr=model->getSelectString (dst->getParObj()); - bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()); + bsel->linkTo ( (BranchObj*)(bdst->getParObj()), tidst->num()); } else if (e->state() & Qt::ControlModifier && dst->getParObj()) { // Link below dst preDstParStr=model->getSelectString (dst->getParObj()); - bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1); + bsel->linkTo ( (BranchObj*)(bdst->getParObj()), tidst->num()+1); } else { // Append to dst preDstParStr=model->getSelectString(dst); @@ -893,7 +895,7 @@ if (dst->getDepth()==0) bsel->move (savePos); } QString postSelStr=model->getSelectString(lmosel); - QString postNum=QString::number (bsel->getNum(),10); + QString postNum=QString::number (tisel->num(),10); QString undoCom="linkTo (\""+ preParStr+ "\"," + preNum +"," + diff -r edb78a44240b -r 9ff332964015 treeitem.cpp --- a/treeitem.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/treeitem.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -22,8 +22,6 @@ note.setNote(""); // note.setFontHint (textEditor->getFontHintDefault() ); //FIXME-2 // isNoteInEditor=false; - - } TreeItem::~TreeItem() @@ -108,6 +106,19 @@ { return branchCounter; } + +int TreeItem::imageCount() const +{ + int imageCounter=0; + return imageCounter; // FIXME-1 imageCounter needs to be calculated... +} + +int TreeItem::xlinkCount() const // FIXME-2 check if xlinks are stored in a different way (global to model?) +{ + int xlinkCounter=0; + return xlinkCounter; // FIXME-1 xlinkCounter needs to be calculated... +} + int TreeItem::row() const { if (parentItem) @@ -148,7 +159,19 @@ case Image: return -1; // FIXME-2 default: return -1; } - +} + +int TreeItem::num (TreeItem *item) +{ + if (!item) return -1; + switch (item->getType()) + { + case Undefined: return -1; + case MapCenter: return childItems.indexOf (this) - branchOffset; + case Branch: return childItems.indexOf (this) - branchOffset; + case Image: return -1; // FIXME-2 + default: return -1; + } } QVariant TreeItem::data(int column) const diff -r edb78a44240b -r 9ff332964015 treeitem.h --- a/treeitem.h Tue Mar 31 15:36:10 2009 +0000 +++ b/treeitem.h Wed Apr 01 15:06:57 2009 +0000 @@ -31,12 +31,18 @@ int childNumber() const; int columnCount() const; int branchCount() const; + int imageCount() const; + int xlinkCount() const; int row() const; int column() const; int depth() ; TreeItem *parent(); - int num(); // object index, e.g. branch number + + /*! Return number of item in parent by type, + e.g. first branch has number 0 */ + int num(); + int num (TreeItem *item); //! Return number of item by type // Accessing data QVariant data(int column) const; diff -r edb78a44240b -r 9ff332964015 vym.pro --- a/vym.pro Tue Mar 31 15:36:10 2009 +0000 +++ b/vym.pro Wed Apr 01 15:06:57 2009 +0000 @@ -55,6 +55,7 @@ linkablemapobj.h \ mainwindow.h \ mapcenterobj.h \ + mapcenteritem.h \ mapeditor.h \ mapobj.h \ misc.h \ @@ -112,6 +113,7 @@ linkablemapobj.cpp \ main.cpp \ mainwindow.cpp \ + mapcenteritem.cpp \ mapcenterobj.cpp \ mapeditor.cpp \ mapobj.cpp \ diff -r edb78a44240b -r 9ff332964015 vymmodel.cpp --- a/vymmodel.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/vymmodel.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -3,6 +3,8 @@ #include "vymmodel.h" +#include "branchitem.h" +#include "mapcenteritem.h" #include "editxlinkdialog.h" #include "exports.h" #include "exportxhtmldialog.h" @@ -223,7 +225,7 @@ mapAttr+= xml.attribut("author",author) + xml.attribut("comment",comment) + xml.attribut("date",getDate()) + - xml.attribut("countBranches", QString().number(countBranches())) + + xml.attribut("branchCount", QString().number(branchCount())) + xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + xml.attribut("selectionColor", mapEditor->getSelectionColor().name() ) + xml.attribut("linkStyle", ls ) + @@ -830,9 +832,10 @@ { dst->addBranch(); bo=dst->getLastBranch(); - bo->setHeading (fi.fileName() ); + BranchItem *bi=(BranchItem*)(bo->getTreeItem()); + bi->setHeading (fi.fileName() ); // FIXME-3 check this bo->setColor (QColor("blue")); - bo->toggleScroll(); + bi->toggleScroll(); if ( !d.cd(fi.fileName()) ) QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName())); else @@ -1318,7 +1321,7 @@ { // save the selected branch of the map, Undo will insert part of map saveState (PartOfMap, - undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()), + undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(redoSel->getTreeItem()->num()), redoSelection, "delete ()", comment, redoSel); @@ -1464,7 +1467,7 @@ return QDate::currentDate().toString ("yyyy-MM-dd"); } -int VymModel::countBranches() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time... +int VymModel::branchCount() // FIXME-2 Optimize this: use internal counter instead of going through whole map each time... { int c=0; TreeItem *cur=NULL; @@ -1955,12 +1958,13 @@ } } -void VymModel::sortChildren() -{ +void VymModel::sortChildren() // FIXME-1 not implemented yet +{ +/* BranchObj* bo=getSelectedBranch(); if (bo) { - if(bo->countBranches()>1) + if(treeItem->branchCount()>1) { saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo))); bo->sortChildren(); @@ -1968,6 +1972,7 @@ ensureSelectionVisible(); } } +*/ } void VymModel::createMapCenter() @@ -2026,33 +2031,35 @@ MapCenterObj* VymModel::addMapCenter(QPointF absPos) { + + // Create TreeItem + QModelIndex parix=index(rootItem); + + int n=rootItem->branchCount(); + + emit (layoutAboutToBeChanged() ); + beginInsertRows (parix,n,n+1); + + QList cData; + cData << "VM:addMapCenter" << "undef"<<"undef"; + MapCenterItem *ti=new MapCenterItem (cData,rootItem); + cout << "VM::addMapCenter ti="<setType (TreeItem::MapCenter); + rootItem->appendChild (ti); + + endInsertRows(); + emit (newChildObject (parix)); + emit (layoutChanged() ); + + // Create MapObj MapCenterObj *mapCenter = new MapCenterObj(mapScene,this); mapCenter->setMapEditor(mapEditor); //FIXME-3 VM needed to get defLinkStyle, mapLinkColorHint ... for later added objects + mapCenter->setTreeItem (ti); // TreeItem needs to exist before setVisibility + ti->setLMO (mapCenter); mapCenter->move (absPos); mapCenter->setVisibility (true); mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); mapCenters.append(mapCenter); - - // Create TreeItem - QModelIndex parix=index(rootItem); - - int n=rootItem->branchCount(); - - emit (layoutAboutToBeChanged() ); - beginInsertRows (parix,n,n+1); - - QList cData; - cData << "VM:addMapCenter" << "undef"<<"undef"; - TreeItem *ti=new TreeItem (cData,rootItem); - ti->setLMO (mapCenter); - ti->setType (TreeItem::MapCenter); - mapCenter->setTreeItem (ti); - rootItem->appendChild (ti); - - endInsertRows(); - emit (newChildObject (parix)); - emit (layoutChanged() ); - // Testing /* qWarning ("MW::insertRow a"); @@ -2097,47 +2104,48 @@ // 0..n insert in children of parent at pos BranchObj *newbo=NULL; BranchObj *bo=getSelectedBranch(); + BranchItem *bi=getSelectedBranchItem(); if (bo) { if (num==-2) { + // Create TreeItem + QList cData; + cData << "new" << "undef"<<"undef"; + + BranchItem *parbi=bi; + QModelIndex parix=index(parbi); + int n=parbi->branchCount(); + + emit (layoutAboutToBeChanged() ); + beginInsertRows (parix,n,n+1); + bi=new BranchItem (cData,parbi); + bi->setType (TreeItem::Branch); + + parbi->appendChild (bi); + endInsertRows (); + emit (newChildObject (parix)); + emit (layoutChanged() ); + // save scroll state. If scrolled, automatically select // new branch in order to tmp unscroll parent... newbo=bo->addBranch(); - // Create TreeItem - QList cData; - cData << "new" << "undef"<<"undef"; - - TreeItem *parti=bo->getTreeItem(); - QModelIndex parix=index(parti); - int n=parti->branchCount(); - - emit (layoutAboutToBeChanged() ); - beginInsertRows (parix,n,n+1); - TreeItem *ti=new TreeItem (cData,parti); - ti->setLMO (newbo); - ti->setType (TreeItem::Branch); - - parti->appendChild (ti); - endInsertRows (); - emit (newChildObject (parix)); - emit (layoutChanged() ); - if (newbo) { - newbo->setTreeItem (ti); + bi->setLMO (newbo); + newbo->setTreeItem (bi); select (newbo); // FIXME-2 VM really needed here? } }else if (num==-1) { - num=bo->getNum()+1; + num=bi->num()+1; bo=(BranchObj*)bo->getParObj(); if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing }else if (num==-3) { - num=bo->getNum(); + num=bi->num(); bo=(BranchObj*)bo->getParObj(); if (bo) newbo=bo->insertBranch(num); //FIXME-1 VM still missing } @@ -2156,7 +2164,7 @@ if (bo) { - // FIXME-1 VM do we still need this in model? setCursor (Qt::ArrowCursor); + // FIXME-2 VM do we still need this in model? setCursor (Qt::ArrowCursor); newbo=addNewBranchInt (pos-2); @@ -2198,7 +2206,7 @@ BranchObj *parbo=(BranchObj*)(bo->getParObj()); // add below selection - newbo=parbo->insertBranch(bo->getNum()+1); //FIXME-1 VM still missing + newbo=parbo->insertBranch(bo->getTreeItem()->num()+1); //FIXME-1 VM still missing if (newbo) { @@ -2276,8 +2284,8 @@ int n=ix.row(); beginRemoveRows (parentIndex,n,n); removeRows (n,1,parentIndex); + endRemoveRows(); par->removeBranch(bo); // remove from BranchObj lists... - endRemoveRows(); select (par); ensureSelectionVisible(); reposition(); @@ -2285,7 +2293,7 @@ emit (layoutChanged() ); return; } - FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing + //FloatImageObj *fio=selection.getFloatImage(); //FIXME-1 VM still missing /* if (fio) @@ -2320,7 +2328,7 @@ if (!par) return; // Check if we have childs at all to keep - if (bo->countBranches()==0) + if (bo->getTreeItem()->branchCount()==0) { deleteSelection(); return; @@ -2362,16 +2370,17 @@ } -bool VymModel::scrollBranch(BranchObj *bo) -{ - if (bo) +bool VymModel::scrollBranch(BranchItem *bi) +{ + if (bi) { - if (bo->isScrolled()) return false; - if (bo->countBranches()==0) return false; - if (bo->getDepth()==0) return false; + if (bi->isScrolled()) return false; + if (bi->branchCount()==0) return false; + if (bi->depth()==0) return false; QString u,r; r="scroll"; u="unscroll"; + /* FIXME-1 no savestate yet saveState( bo, QString ("%1 ()").arg(u), @@ -2379,24 +2388,27 @@ QString ("%1 ()").arg(r), QString ("%1 %2").arg(r).arg(getObjectName(bo)) ); - bo->toggleScroll(); - selection.update(); + */ + bi->toggleScroll(); + //selection.update(); // FIXME-3 VM needed? scene()->update(); return true; } return false; } -bool VymModel::unscrollBranch(BranchObj *bo) -{ - if (bo) +bool VymModel::unscrollBranch(BranchItem *bi) +{ + if (bi) { - if (!bo->isScrolled()) return false; - if (bo->countBranches()==0) return false; - if (bo->getDepth()==0) return false; + if (bi->isScrolled()) return false; + if (bi->branchCount()==0) return false; + if (bi->depth()==0) return false; + QString u,r; u="scroll"; r="unscroll"; + /* FIXME-1 no savestate yet saveState( bo, QString ("%1 ()").arg(u), @@ -2404,8 +2416,9 @@ QString ("%1 ()").arg(r), QString ("%1 %2").arg(r).arg(getObjectName(bo)) ); - bo->toggleScroll(); - selection.update(); + */ + bi->toggleScroll(); + // selection.update(); // FIXME-3 VM needed? scene()->update(); return true; } @@ -2414,13 +2427,13 @@ void VymModel::toggleScroll() { - BranchObj *bo=getSelectedBranch(); - if (selectionType()==TreeItem::Branch ) + BranchItem *bi=(BranchItem*)getSelectedBranchItem(); + if (bi && bi->getType()==TreeItem::Branch ) { - if (bo->isScrolled()) - unscrollBranch (bo); + if (bi->isScrolled()) + unscrollBranch (bi); else - scrollBranch (bo); + scrollBranch (bi); } } @@ -2722,6 +2735,7 @@ void VymModel::parseAtom(const QString &atom) { BranchObj *selb=getSelectedBranch(); + BranchItem *bi=getSelectedBranchItem(); QString s,t; double x,y; int n; @@ -3260,7 +3274,7 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParCount(0)) { - if (!scrollBranch (selb)) + if (!scrollBranch (bi)) parser.setError (Aborted,"Could not scroll branch"); } ///////////////////////////////////////////////////////////////////// @@ -3611,7 +3625,7 @@ parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParCount(0)) { - if (!unscrollBranch (selb)) + if (!unscrollBranch (bi)) parser.setError (Aborted,"Could not unscroll branch"); } ///////////////////////////////////////////////////////////////////// @@ -4669,7 +4683,7 @@ b=select (s); if (b) { - if ( getSelectedBranch()->countBranches()>0) + if ( getSelectedItem()->branchCount()>0) s+=",bo:0"; else break; @@ -4749,8 +4763,8 @@ { b=select (s); if (b) - if ( getSelectedBranch()->countBranches()>0) - s+=",bo:"+ QString ("%1").arg( getSelectedBranch()->countBranches()-1 ); + if ( getSelectedItem()->branchCount()>0) + s+=",bo:"+ QString ("%1").arg( getSelectedItem()->branchCount()-1 ); else break; else @@ -4974,7 +4988,7 @@ return NULL; } -TreeItem* VymModel::getSelectedBranchItem() +BranchItem* VymModel::getSelectedBranchItem() { QModelIndexList list=selModel->selectedIndexes(); if (!list.isEmpty() ) @@ -4982,7 +4996,7 @@ TreeItem *ti = getItem (list.first() ); TreeItem::Type type=ti->getType(); if (type ==TreeItem::Branch || type==TreeItem::MapCenter) - return ti; + return (BranchItem*)ti; } return NULL; } @@ -5019,26 +5033,32 @@ return QString(); } -QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel +QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below... +{ + if (!lmo) return QString(); + return getSelectString (lmo->getTreeItem() ); +} + +QString VymModel::getSelectString (TreeItem *ti) { QString s; - if (!lmo) return s; - if (typeid(*lmo)==typeid(BranchObj) || - typeid(*lmo)==typeid(MapCenterObj) ) + if (!ti) return s; + if (ti->getType() == TreeItem::Branch || + ti->getType() == TreeItem::MapCenter) { - LinkableMapObj *par=lmo->getParObj(); + TreeItem *par=ti->parent(); if (par) { - if (lmo->getDepth() ==1) + if (ti->depth() ==1) // Mainbranch, return - s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); + s= "bo:" + QString("%1").arg(ti->num() ); else // Branch, call myself recursively - s= getSelectString(par) + ",bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); + s= getSelectString(par) + ",bo:" + QString("%1").arg(ti->num()); } else { // MapCenter - int i=mapCenters.indexOf ((MapCenterObj*)lmo); + int i=rootItem->num(ti); if (i>=0) s=QString("mc:%1").arg(i); } } diff -r edb78a44240b -r 9ff332964015 vymmodel.h --- a/vymmodel.h Tue Mar 31 15:36:10 2009 +0000 +++ b/vymmodel.h Wed Apr 01 15:06:57 2009 +0000 @@ -12,6 +12,8 @@ #include "treeitem.h" #include "treemodel.h" +class BranchItem; + class VymModel : public TreeModel { Q_OBJECT @@ -231,7 +233,7 @@ void setComment (const QString &); QString getComment (); QString getDate(); - int countBranches(); + int branchCount(); public: void setHeading(const QString &); //!< Set heading of branch @@ -322,8 +324,8 @@ void deleteChildren(); //!< keep branch, but remove children private: - bool scrollBranch(BranchObj*); - bool unscrollBranch(BranchObj*); + bool scrollBranch(BranchItem *); + bool unscrollBranch(BranchItem *); public: void toggleScroll(); void unscrollChildren(); @@ -568,12 +570,13 @@ TreeItem::Type selectionType(); LinkableMapObj* getSelectedLMO(); BranchObj* getSelectedBranch(); - TreeItem* getSelectedBranchItem(); + BranchItem* getSelectedBranchItem(); TreeItem* getSelectedItem(); QModelIndex getSelectedIndex(); FloatImageObj* getSelectedFloatImage(); QString getSelectString (); QString getSelectString (LinkableMapObj *lmo); + QString getSelectString (TreeItem *item); /* diff -r edb78a44240b -r 9ff332964015 xml-freemind.cpp --- a/xml-freemind.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/xml-freemind.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -5,12 +5,12 @@ #include #include +#include "branchitem.h" #include "misc.h" #include "settings.h" #include "linkablemapobj.h" #include "version.h" -static BranchObj *lastBranch; //static FloatObj *lastFloat; static OrnamentedObj *lastOO; @@ -266,9 +266,10 @@ bool parseFreemindHandler::readNodeAttr (const QXmlAttributes& a) { lastOO=lastBranch; + lastBranchItem=(BranchItem*)(lastBranch->getTreeItem() ); if (a.value( "FOLDED")=="true" ) - lastBranch->toggleScroll(); + lastBranchItem->toggleScroll(); if (!a.value( "TEXT").isEmpty() ) lastBranch->setHeading (a.value ("TEXT")); diff -r edb78a44240b -r 9ff332964015 xml-freemind.h --- a/xml-freemind.h Tue Mar 31 15:36:10 2009 +0000 +++ b/xml-freemind.h Wed Apr 01 15:06:57 2009 +0000 @@ -37,5 +37,7 @@ State state; State laststate; QList stateStack; + BranchItem *lastBranchItem; + BranchObj *lastBranch; }; #endif diff -r edb78a44240b -r 9ff332964015 xml-vym.cpp --- a/xml-vym.cpp Tue Mar 31 15:36:10 2009 +0000 +++ b/xml-vym.cpp Wed Apr 01 15:06:57 2009 +0000 @@ -6,13 +6,13 @@ #include #include +#include "branchitem.h" #include "misc.h" #include "settings.h" #include "linkablemapobj.h" #include "mainwindow.h" #include "version.h" -static BranchObj *lastBranch; static FloatObj *lastFloat; static OrnamentedObj *lastOO; @@ -55,14 +55,15 @@ // Create mapCenter model->clear(); lastBranch=NULL; + lastBranchItem=NULL; if (!atts.value( "author").isEmpty() ) model->setAuthor(atts.value( "author" ) ); if (!atts.value( "comment").isEmpty() ) model->setComment (atts.value( "comment" ) ); - if (!atts.value( "countBranches").isEmpty() ) + if (!atts.value( "branchCount").isEmpty() ) { - branchesTotal=atts.value("countBranches").toInt(); + branchesTotal=atts.value("branchCount").toInt(); if (branchesTotal>10) { mainWindow->setProgressMinimum (0); @@ -356,10 +357,12 @@ branchesCurrent++; mainWindow->setProgressValue (branchesCurrent); lastOO=lastBranch; + lastBranchItem=(BranchItem*)(lastBranch->getTreeItem()); + if (!readOOAttr(a)) return false; if (!a.value( "scrolled").isEmpty() ) - lastBranch->toggleScroll(); + lastBranchItem->toggleScroll(); if (!a.value( "frameType").isEmpty() ) lastOO->setFrameType (a.value("frameType")); //Compatibility 1.8.1 diff -r edb78a44240b -r 9ff332964015 xml-vym.h --- a/xml-vym.h Tue Mar 31 15:36:10 2009 +0000 +++ b/xml-vym.h Wed Apr 01 15:06:57 2009 +0000 @@ -3,6 +3,8 @@ #include "xml-base.h" +class BranchItem; + /*! \brief Parsing VYM maps from XML documents */ class parseVYMHandler : public parseBaseHandler @@ -50,5 +52,8 @@ QList stateStack; QString htmldata; NoteObj no; + + BranchObj* lastBranch; + BranchItem* lastBranchItem; }; #endif