diff -r 67cfa6e6b863 -r 7ced3733ba60 mapeditor.cpp --- a/mapeditor.cpp Tue Oct 24 15:36:38 2006 +0000 +++ b/mapeditor.cpp Mon Oct 30 12:39:37 2006 +0000 @@ -85,7 +85,6 @@ printer=NULL; - actColor=Qt::black; setColor (actColor); defLinkColor=QColor (0,0,255); defXLinkColor=QColor (180,180,180); linkcolorhint=DefaultColor; @@ -163,11 +162,6 @@ //cout <<"Destructor MapEditor\n"; } -QColor MapEditor::getColor() -{ - return actColor; -} - QColor MapEditor::getBackgroundColor() { return mapCanvas->backgroundColor(); @@ -372,15 +366,24 @@ mapCenter); } -void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, const QString &comment) +void MapEditor::saveStateChangingPart(LinkableMapObj *undoSel, LinkableMapObj* redoSel, const QString &rc, const QString &comment) { // save the selected part of the map, Undo will replace part of map QString undoSelection=""; - if (undoSel) undoSelection=undoSel->getSelectString(); + if (undoSel) + undoSelection=undoSel->getSelectString(); + else + qWarning ("MapEditor::saveStateChangingPart no undoSel given!"); + QString redoSelection=""; + if (redoSel) + redoSelection=undoSel->getSelectString(); + else + qWarning ("MapEditor::saveStateChangingPart no redoSel given!"); + saveState (PartOfMap, undoSelection, "", - "", "", + redoSelection, rc, comment, undoSel); } @@ -407,8 +410,6 @@ // save the selected mainbranch 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,%2)").arg(((BranchObj*)redoSel)->getNum()) -// .arg(((BranchObj*)redoSel)->x()).arg(((BranchObj*)redoSel)->y()), redoSelection, "delete ()", comment, redoSel); @@ -416,21 +417,6 @@ } } -void MapEditor::saveStateConstSelection(const QString &uc, const QString &rc, const QString &comment) -{ - // selection does not change during action, - // so just save commands for undo and redo - // and use current selection - - QString sel; - if (selection) sel=selection->getSelectString(); - - saveState (UndoCommand, - sel, uc, - sel, rc, - comment, - NULL); -} void MapEditor::saveState(LinkableMapObj *undoSel, const QString &uc, LinkableMapObj *redoSel, const QString &rc, const QString &comment) { @@ -473,8 +459,6 @@ */ cout << "ME::saveState() "<activateStandardFlag(s); - bo->updateFlagsToolbar(); - } - } - } else if (com=="setFlag") { if (!selection) @@ -1007,7 +1054,22 @@ // (map state is set later at end of load...) } else { - saveStateChangingPart(selection,"Load map"); + if (!selection || (typeid(*selection) != typeid(BranchObj) && + typeid(*selection) != typeid (MapCenterObj))) + return aborted; + BranchObj *bo=(BranchObj*)selection; + if (lmode==ImportAdd) + saveStateChangingPart( + selection, + selection, + QString("addMapInsert (%1)").arg(fname), + QString("Add map %1 to %2").arg(fname).arg(getName(bo))); + else + saveStateChangingPart( + selection, + selection, + QString("addMapReplace(%1)").arg(fname), + QString("Add map %1 to %2").arg(fname).arg(getName(bo))); } @@ -1412,6 +1474,12 @@ QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); + QString version=undoSet.readEntry ("/history/version"); + + if (!checkVersion(version)) + QMessageBox::warning(0,tr("Warning"), + tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(__VYM_VERSION)); + // Find out current undo directory QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep)); @@ -1485,6 +1553,11 @@ QString redoCommand= undoSet.readEntry (QString("/history/step-%1/redoCommand").arg(curStep)); QString redoSelection=undoSet.readEntry (QString("/history/step-%1/redoSelection").arg(curStep)); QString comment=undoSet.readEntry (QString("/history/step-%1/comment").arg(curStep)); + QString version=undoSet.readEntry ("/history/version"); + + if (!checkVersion(version)) + QMessageBox::warning(0,tr("Warning"), + tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(__VYM_VERSION)); // Find out current undo directory QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep)); @@ -1655,8 +1728,13 @@ if (selection && (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj))) { - saveStateChangingPart(selection,QString("Paste to %1").arg( getName(selection))); pasteNoSave(); + saveStateChangingPart( + selection, + selection, + "paste ()", + QString("Paste to %1").arg( getName(selection)) + ); mapCenter->reposition(); adjustCanvasSize(); } @@ -1664,7 +1742,12 @@ void MapEditor::cut() { - saveStateChangingPart(selection->getParObj(),QString("Cut %1").arg(getName(selection))); + saveStateChangingPart( + selection->getParObj(), + selection, + "cut ()", + QString("Cut %1").arg(getName(selection)) + ); copy(); cutNoSave(); mapCenter->reposition(); @@ -1766,8 +1849,10 @@ typeid(*selection) == typeid(MapCenterObj) ) ) { editingBO=(BranchObj*)selection; - saveStateConstSelection( + saveState( + selection, "setHeading (\""+editingBO->getHeading()+"\")", + selection, "setHeading (\""+s+"\")", QString("Set heading of %1 to \"%2\"").arg(getName(editingBO)).arg(s) ); editingBO->setHeading(s ); @@ -1870,11 +1955,12 @@ if (newbo) { - saveStateConstSelection ( - //QString ("delete (\"%1\")").arg(newbo->getSelectString()), + saveState( + selection, // FIXME sholdnt newbo be deleted here??? "delete ()", + selection, QString ("addBranch (%1)").arg(pos-2), - QString ("Add new branch to %1").arg(getName(bo))); //TODO undoCommand + QString ("Add new branch to %1").arg(getName(bo))); mapCenter->reposition(); adjustCanvasSize(); @@ -1936,7 +2022,12 @@ { FloatImageObj* fio=(FloatImageObj*)selection; BranchObj* par=(BranchObj*)(fio->getParObj()); - saveStateChangingPart(par, QString("Delete %1").arg(getName(fio))); + saveStateChangingPart( + par, + fio, + "delete ()", + QString("Delete %1").arg(getName(fio)) + ); fio->unselect(); selection=NULL; par->removeFloatImage(fio); @@ -2363,11 +2454,6 @@ } } -void MapEditor::setColor(QColor c) -{ - actColor=c; -} - void MapEditor::selectBackgroundColor() { QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this ); @@ -2382,7 +2468,7 @@ mapCanvas->setBackgroundColor (c); } -QColor MapEditor::pickColor() +QColor MapEditor::getCurrentHeadingColor() { if (selection) { @@ -2390,13 +2476,15 @@ typeid(*selection) == typeid(MapCenterObj)) { BranchObj *bo=(BranchObj*)selection; - actColor=bo->getColor(); + return bo->getColor(); } } - return actColor; + + QMessageBox::warning(0,tr("Warning"),tr("Can't get color of heading,\nthere's no branch selected")); + return Qt::black; } -void MapEditor::colorItem() +void MapEditor::colorItem(QColor c) { if (selection) { @@ -2404,13 +2492,18 @@ typeid(*selection) == typeid(MapCenterObj)) { BranchObj *bo=(BranchObj*)selection; - saveStateChangingPart(selection, QString("Set color of %1 to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand - bo->setColor(actColor); // color branch + saveStateChangingPart( + selection, + selection, + QString ("colorItem (%1)").arg(c.name()), + QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name()) + ); //TODO with complete API: undoCommand + bo->setColor(c); // color branch } } } -void MapEditor::colorBranch() +void MapEditor::colorBranch(QColor c) { if (selection) { @@ -2418,8 +2511,13 @@ typeid(*selection) == typeid(MapCenterObj)) { BranchObj *bo=(BranchObj*)selection; - saveStateChangingPart(selection, QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(actColor.name())); //TODO undoCommand - bo->setColorChilds(actColor); // color links, color childs + saveStateChangingPart( + selection, + selection, + QString ("colorBranch (%1)").arg(c.name()), + QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name()) + ); + bo->setColorChilds(c); // color links, color childs } } } @@ -2444,7 +2542,10 @@ u="unsetFlag"; r="setFlag"; } - saveStateConstSelection(QString("%1 (\"%2\")").arg(u).arg(f), + saveState( + selection, + QString("%1 (\"%2\")").arg(u).arg(f), + selection, QString("%1 (\"%2\")").arg(r).arg(f), QString("Toggling standard flag \"%1\" of %2").arg(f).arg(getName(bo))); bo->toggleStandardFlag (f,mainWindow->useFlagGroups()); @@ -2526,6 +2627,24 @@ itFind=NULL; EOFind=false; } +void MapEditor::setURL(const QString &url) +{ + if (selection && (typeid(*selection) == typeid(BranchObj) || + typeid(*selection) == typeid(MapCenterObj)) ) + { + BranchObj *bo=(BranchObj*)selection; + QString oldurl=bo->getURL(); + bo->setURL (url); + saveState ( + selection, + QString ("setURL (\"%1\")").arg(oldurl), + selection, + QString ("setURL (\"%1\")").arg(url), + QString ("set URL of %1 to %2").arg(getName(bo)).arg(url) + ); + updateActions(); + } +} void MapEditor::editURL() { @@ -2538,12 +2657,8 @@ "VYM", tr("Enter URL:"), QLineEdit::Normal, bo->getURL(), &ok, this ); if ( ok) - { // user entered something and pressed OK - saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+text+"\")", QString("Set URL of %1 to %21").arg(getName(bo)).arg(text)); - bo->setURL (text); - updateActions(); - } + setURL (text); } } @@ -2578,12 +2693,7 @@ { if (selection && (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj)) ) - { - BranchObj *bo=(BranchObj*)selection; - saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+bo->getHeading()+"\")",QString("Copy heading of %1 to URL").arg(getName(bo))); - bo->setURL (bo->getHeading()); - updateActions(); - } + setURL (((BranchObj*)selection)->getHeading()); } void MapEditor::editBugzilla2URL() @@ -2593,9 +2703,7 @@ { BranchObj *bo=(BranchObj*)selection; QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); - saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to Novell Bugzilla").arg(getName(bo))); - bo->setURL (url); - updateActions(); + setURL (url); } } @@ -2606,7 +2714,13 @@ { BranchObj *bo=(BranchObj*)selection; QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); - saveStateConstSelection("setURL (\""+bo->getURL()+"\")","setURL (\""+url+"\")",QString("Use heading of %1 as link to FATE").arg(getName(bo))); + saveState( + selection, + "setURL (\""+bo->getURL()+"\")", + selection, + "setURL (\""+url+"\")", + QString("Use heading of %1 as link to FATE").arg(getName(bo)) + ); bo->setURL (url); updateActions(); } @@ -2628,7 +2742,13 @@ QString fn; if ( fd->exec() == QDialog::Accepted ) { - saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\""+fd->selectedFile()+"\")",QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile())); + saveState( + selection, + "setVymLink (\""+bo->getVymLink()+"\")", + selection, + "setVymLink (\""+fd->selectedFile()+"\")", + QString("Set vymlink of %1 to %2").arg(getName(bo)).arg(fd->selectedFile()) + ); bo->setVymLink (fd->selectedFile() ); updateActions(); mapCenter->reposition(); @@ -2644,7 +2764,13 @@ typeid(*selection) == typeid(MapCenterObj)) ) { BranchObj *bo=(BranchObj*)selection; - saveStateConstSelection("setVymLink (\""+bo->getVymLink()+"\")","setVymLink (\"\")",QString("Unset vymlink of %1").arg(getName(bo))); + saveState( + selection, + "setVymLink (\""+bo->getVymLink()+"\")", + selection, + "setVymLink (\"\")", + QString("Unset vymlink of %1").arg(getName(bo)) + ); bo->setVymLink ("" ); updateActions(); mapCenter->reposition(); @@ -2653,26 +2779,23 @@ } } -void MapEditor::toggleHideExport() +void MapEditor::setHideExport(bool b) { if (selection && (typeid(*selection) == typeid(BranchObj) || - typeid(*selection) == typeid(MapCenterObj)) || - (typeid(*selection)==typeid(FloatImageObj)) - ) - { + typeid(*selection)==typeid(FloatImageObj))) + { OrnamentedObj *oo=(OrnamentedObj*)selection; - QString s; - if (oo->hideInExport()) - { - oo->setHideInExport(false); - s="Unset"; - } - else - { - oo->setHideInExport(true); - s="Set"; - } - saveStateComplete(QString ("%1 hide export flag of %2").arg(s).arg(getName(selection))); //TODO undoCommand + oo->setHideInExport (b); + QString u= b ? "false" : "true"; + QString r=!b ? "false" : "true"; + + saveState( + selection, + QString ("setHideExport (%1)").arg(u), + selection, + QString ("setHideExport (%1)").arg(r), + QString ("Set HideExport flag of %1 to %2").arg(getName(oo)).arg (r) + ); updateActions(); mapCenter->reposition(); adjustCanvasSize(); @@ -2680,6 +2803,13 @@ } } +void MapEditor::toggleHideExport() +{ + if (selection && (typeid(*selection) == typeid(BranchObj) || + typeid(*selection)==typeid(FloatImageObj))) + setHideExport ( !((OrnamentedObj*)selection)->hideInExport() ); +} + QString MapEditor::getVymLink() { if (selection && (typeid(*selection) == typeid(BranchObj) || @@ -2709,18 +2839,19 @@ } -void MapEditor::removeBranchKeepChilds() +void MapEditor::deleteKeepChilds() { if (selection && (typeid(*selection) == typeid(BranchObj) )) { BranchObj* bo=(BranchObj*)selection; BranchObj* par=(BranchObj*)(bo->getParObj()); QPoint p=bo->getRelPos(); - QString s=QString("Remove %1 and keep its childs").arg(getName(bo)); - if (bo->getDepth()==1) - saveStateComplete(s); - else - saveStateChangingPart(selection->getParObj(),s); // TODO undoCommand + saveStateChangingPart( + selection->getParObj(), + selection, + "deleteKeepChilds ()", + QString("Remove %1 and keep its childs").arg(getName(bo)) + ); QString sel=selection->getSelectString(); unselect(); @@ -2733,12 +2864,17 @@ } } -void MapEditor::removeChilds() +void MapEditor::deleteChilds() { - if (selection && (typeid(*selection) == typeid(BranchObj) )) + if (selection && (typeid(*selection) == typeid(BranchObj) || + typeid(*selection)==typeid(MapCenterObj))) { - // TODO undoCommand - saveStateChangingPart(selection->getParObj(), QString("Remove childs of branch %1").arg(getName(selection))); + saveStateChangingPart( + selection->getParObj(), + selection, + "deleteChilds ()", + QString( "Remove childs of branch %1").arg(getName(selection)) + ); ((BranchObj*)selection)->removeChilds(); mapCenter->reposition(); } @@ -2908,12 +3044,24 @@ BranchObj *bo=((BranchObj*)selection); if (bo->countBranches()==0) return; if (bo->getDepth()==0) return; - QString s; + QString u,r; if (bo->isScrolled()) - s="Unscroll"; + { + r="unscroll"; + u="scroll"; + } else - s="Scroll"; - saveStateChangingPart(selection, QString ("%1 %2").arg(s).arg(getName(bo))); + { + u="scroll"; + r="unscroll"; + } + saveState( + selection, + QString ("%1 ()").arg(u), + selection, + QString ("%1 ()").arg(r), + QString ("%1 %2").arg(r).arg(getName(bo)) + ); bo->toggleScroll(); adjustCanvasSize(); canvas()->update(); @@ -2953,17 +3101,25 @@ QString fn; if ( fd->exec() == QDialog::Accepted ) { - saveStateChangingPart(selection, QString("Add floatimage to %1").arg(getName(selection))); // FIXME in QT4 use: lastImageDir=fd->directory(); lastImageDir=QDir (fd->dirPath()); QStringList flist = fd->selectedFiles(); QStringList::Iterator it = flist.begin(); + FloatImageObj *fio; while( it != flist.end() ) { fn = *it; bo->addFloatImage(); - // TODO check if load was successful - bo->getLastFloatImage()->load(*it); + fio=bo->getLastFloatImage(); + fio->load(*it); + // FIXME check if load of fio was successful + saveState( + (LinkableMapObj*)fio, + "delete ()", + selection, + QString ("loadFloatImage (%1)").arg(*it), + QString("Add floatimage %1 to %2").arg(*it).arg(getName(selection)) + ); bo->getLastFloatImage()->setOriginalFilename(fn); ++it; } @@ -3618,8 +3774,10 @@ FloatImageObj *fo=(FloatImageObj*)selection; QString pold=qpointToString(movingObj_orgRelPos); QString pnow=qpointToString(fo->getRelPos()); - saveStateConstSelection( + saveState( + selection, "moveRel "+pold, + selection, "moveRel "+pnow, QString("Move %1 to relativ position %2").arg(getName(selection)).arg(pnow)); @@ -3815,7 +3973,7 @@ QPixmap pix; if (Q3ImageDrag::decode(event, pix)) { - addFloatImage(pix); + addFloatImageInt(pix); event->accept(); update=true; } else @@ -3914,20 +4072,19 @@ } } -void MapEditor::addFloatImage(const QPixmap &img) +void MapEditor::addFloatImageInt (const QPixmap &img) { if (selection && (typeid(*selection) == typeid(BranchObj)) || (typeid(*selection) == typeid(MapCenterObj)) ) { BranchObj *bo=((BranchObj*)selection); - saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo))); + //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo))); //QString fn=fd->selectedFile(); //lastImageDir=fn.left(fn.findRev ("/")); - bo->addFloatImage(); - // FIXME check if load was successful - bo->getLastFloatImage()->load(img); - //bo->getLastFloatImage()->setOriginalFilename(fn); + FloatImageObj *fio=bo->addFloatImage(); + fio->load(img); + fio->setOriginalFilename("Image added by Drag and Drop"); mapCenter->reposition(); adjustCanvasSize(); canvas()->update(); @@ -3949,7 +4106,7 @@ { if (nop->state()==Q3NetworkProtocol::StDone) { QPixmap img(imageBuffer->buffer()); - addFloatImage(img); + addFloatImageInt (img); } if (imageBuffer) {