1.1 --- a/vymmodel.cpp Thu Sep 03 08:52:00 2009 +0000
1.2 +++ b/vymmodel.cpp Mon Sep 07 15:36:57 2009 +0000
1.3 @@ -77,9 +77,6 @@
1.4
1.5 void VymModel::init ()
1.6 {
1.7 - // We should have at least one map center to start with
1.8 - // addMapCenter(); FIXME-2 VM create this in MapEditor as long as model is part of that
1.9 -
1.10 // No MapEditor yet
1.11 mapEditor=NULL;
1.12
1.13 @@ -844,11 +841,11 @@
1.14 }
1.15
1.16
1.17 -void VymModel::importDirInt(BranchObj *dst, QDir d)
1.18 -{
1.19 -/* FIXME-2 importDirInt not ported yet
1.20 - BranchObj *bo=getSelectedBranch();
1.21 - if (bo)
1.22 +void VymModel::importDirInt(BranchItem *dst, QDir d)
1.23 +{
1.24 + BranchItem *selbi=getSelectedBranch();
1.25 + BranchItem *bi;
1.26 + if (selbi)
1.27 {
1.28 // Traverse directories
1.29 d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
1.30 @@ -860,18 +857,16 @@
1.31 fi=list.at(i);
1.32 if (fi.fileName() != "." && fi.fileName() != ".." )
1.33 {
1.34 - dst->addBranch();
1.35 - bo=dst->getLastBranch();
1.36 - BranchItem *bi=(BranchItem*)(bo->getTreeItem());
1.37 + bi=addNewBranchInt(dst,-2);
1.38 bi->setHeading (fi.fileName() ); // FIXME-3 check this
1.39 - bo->setColor (QColor("blue"));
1.40 + bi->setHeadingColor (QColor("blue"));
1.41 bi->toggleScroll();
1.42 if ( !d.cd(fi.fileName()) )
1.43 QMessageBox::critical (0,tr("Critical Import Error"),tr("Cannot find the directory %1").arg(fi.fileName()));
1.44 else
1.45 {
1.46 // Recursively add subdirs
1.47 - importDirInt (bo,d);
1.48 + importDirInt (bi,d);
1.49 d.cdUp();
1.50 }
1.51 }
1.52 @@ -883,36 +878,31 @@
1.53 for (int i = 0; i < list.size(); ++i)
1.54 {
1.55 fi=list.at(i);
1.56 - dst->addBranch();
1.57 - bo=dst->getLastBranch();
1.58 - bo->setHeading (fi.fileName() );
1.59 - bo->setColor (QColor("black"));
1.60 + bi=addNewBranchInt (dst,-2);
1.61 + bi->setHeading (fi.fileName() );
1.62 + bi->setHeadingColor (QColor("black"));
1.63 if (fi.fileName().right(4) == ".vym" )
1.64 - bo->setVymLink (fi.filePath());
1.65 + bi->setVymLink (fi.filePath());
1.66 }
1.67 }
1.68 -*/
1.69 }
1.70
1.71 -void VymModel::importDirInt (const QString &s) // FIXME-2
1.72 -{
1.73 -/*
1.74 - BranchObj *bo=getSelectedBranch();
1.75 - if (bo)
1.76 +void VymModel::importDirInt (const QString &s)
1.77 +{
1.78 + BranchItem *selbi=getSelectedBranch();
1.79 + if (selbi)
1.80 {
1.81 - saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
1.82 + saveStateChangingPart (selbi,selbi,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s));
1.83
1.84 QDir d(s);
1.85 - importDirInt (bo,d);
1.86 + importDirInt (selbi,d);
1.87 }
1.88 -*/
1.89 }
1.90
1.91 -void VymModel::importDir() //FIXME-2
1.92 -{
1.93 -/*
1.94 - BranchObj *bo=getSelectedBranch();
1.95 - if (bo)
1.96 +void VymModel::importDir() //FIXME-3 check me... (not tested yet)
1.97 +{
1.98 + BranchItem *selbi=getSelectedBranch();
1.99 + if (selbi)
1.100 {
1.101 QStringList filters;
1.102 filters <<"VYM map (*.vym)";
1.103 @@ -930,7 +920,6 @@
1.104 //FIXME-3 VM needed? scene()->update();
1.105 }
1.106 }
1.107 -*/
1.108 }
1.109
1.110
1.111 @@ -1435,11 +1424,12 @@
1.112 parts.removeFirst();
1.113 if (typ=="mc" || typ=="bo")
1.114 ti=ti->getBranchNum (n);
1.115 - /* FIXME-2
1.116 + /* FIXME-2 add other types to getSelectionString and findBy...
1.117 else
1.118 if (typ="fi")
1.119 ti=ti->getImageNum (n);
1.120 */
1.121 + if(!ti) return NULL;
1.122 }
1.123 return ti;
1.124 }
1.125 @@ -1923,7 +1913,7 @@
1.126 }
1.127 }
1.128
1.129 -void VymModel::moveUp()
1.130 +void VymModel::moveUp() //FIXME-2 crashes if trying to move MCO
1.131 {
1.132 BranchItem *selbi=getSelectedBranch();
1.133 if (selbi)
1.134 @@ -1996,8 +1986,9 @@
1.135 emit (layoutAboutToBeChanged() );
1.136
1.137 parix=index(dst);
1.138 + if (!parix.isValid()) cout << "VM::createII invalid index\n";
1.139 n=dst->getRowNumAppend(newii);
1.140 - beginInsertRows (parix,n,n+1);
1.141 + beginInsertRows (parix,n,n);
1.142 dst->appendChild (newii);
1.143 endInsertRows ();
1.144
1.145 @@ -2023,12 +2014,13 @@
1.146 cData << "new xLink"<<"undef";
1.147
1.148 XLinkItem *newxli=new XLinkItem(cData) ;
1.149 + newxli->setBegin (bi);
1.150
1.151 emit (layoutAboutToBeChanged() );
1.152
1.153 parix=index(bi);
1.154 n=bi->getRowNumAppend(newxli);
1.155 - beginInsertRows (parix,n,n+1);
1.156 + beginInsertRows (parix,n,n);
1.157 bi->appendChild (newxli);
1.158 endInsertRows ();
1.159
1.160 @@ -2036,7 +2028,6 @@
1.161
1.162 // save scroll state. If scrolled, automatically select
1.163 // new branch in order to tmp unscroll parent...
1.164 - newxli->setBegin (bi);
1.165 if (createMO)
1.166 {
1.167 newxli->createMapObj(mapScene);
1.168 @@ -2060,7 +2051,7 @@
1.169
1.170 QModelIndex parix=index(selbi);
1.171 int n=selbi->getRowNumAppend (a);
1.172 - beginInsertRows (parix,n,n+1);
1.173 + beginInsertRows (parix,n,n);
1.174 selbi->appendChild (a);
1.175 endInsertRows ();
1.176
1.177 @@ -2087,22 +2078,22 @@
1.178 return bi;
1.179 }
1.180
1.181 -BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?!
1.182 +BranchItem* VymModel::addMapCenter(QPointF absPos)
1.183 // createMapCenter could then probably be merged with createBranch
1.184 {
1.185
1.186 // Create TreeItem
1.187 QModelIndex parix=index(rootItem);
1.188
1.189 - int n=rootItem->branchCount();
1.190 -
1.191 - emit (layoutAboutToBeChanged() );
1.192 - beginInsertRows (parix,n,n+1);
1.193 -
1.194 QList<QVariant> cData;
1.195 cData << "VM:addMapCenter" << "undef";
1.196 BranchItem *newbi=new BranchItem (cData,rootItem);
1.197 newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
1.198 + int n=rootItem->getRowNumAppend (newbi);
1.199 +
1.200 + emit (layoutAboutToBeChanged() );
1.201 + beginInsertRows (parix,n,n);
1.202 +
1.203 rootItem->appendChild (newbi);
1.204
1.205 endInsertRows();
1.206 @@ -2110,12 +2101,13 @@
1.207
1.208 // Create MapObj
1.209 newbi->setPositionMode (MapItem::Absolute);
1.210 - newbi->createMapObj(mapScene);
1.211 + BranchObj *bo=newbi->createMapObj(mapScene);
1.212 + if (bo) bo->move (absPos);
1.213
1.214 return newbi;
1.215 }
1.216
1.217 -BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
1.218 +BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num)
1.219 {
1.220 // Depending on pos:
1.221 // -3 insert in children of parent above selection
1.222 @@ -2140,7 +2132,7 @@
1.223 parbi=dst;
1.224 parix=index(parbi);
1.225 n=parbi->getRowNumAppend (newbi);
1.226 - beginInsertRows (parix,n,n+1);
1.227 + beginInsertRows (parix,n,n);
1.228 parbi->appendChild (newbi);
1.229 endInsertRows ();
1.230 }else if (num==-1 || num==-3)
1.231 @@ -2350,7 +2342,7 @@
1.232 QString("Delete %1").arg(getObjectName(ti))
1.233 );
1.234 }
1.235 - // FIXME-0 savestate missing for deletion of other times
1.236 + // FIXME-1 savestate missing for deletion of other types than above
1.237 unselect();
1.238 deleteItem (ti);
1.239 emitDataHasChanged (pi);
1.240 @@ -2576,22 +2568,20 @@
1.241 }
1.242 }
1.243
1.244 -void VymModel::addFloatImage (const QPixmap &img) //FIXME-2 drag & drop
1.245 -{
1.246 -/*
1.247 - BranchObj *bo=getSelectedBranch();
1.248 - if (bo)
1.249 - {
1.250 - FloatImageObj *fio=bo->addFloatImage();
1.251 - fio->load(img);
1.252 - fio->setOriginalFilename("No original filename (image added by dropevent)");
1.253 - QString s=getSelectString(bo);
1.254 - saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
1.255 - saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
1.256 - reposition();
1.257 - // FIXME-3 VM needed? scene()->update();
1.258 - }
1.259 -*/
1.260 +void VymModel::addFloatImage (const QPixmap &img)
1.261 +{
1.262 + BranchItem *selbi=getSelectedBranch();
1.263 + if (selbi)
1.264 + {
1.265 + ImageItem *ii=createImage (selbi);
1.266 + ii->load(img);
1.267 + ii->setOriginalFilename("No original filename (image added by dropevent)");
1.268 + QString s=getSelectString(selbi);
1.269 + saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",ii );
1.270 + saveState (ii,"delete ()", selbi,QString("paste(%1)").arg(curStep),"Pasting dropped image");
1.271 + reposition();
1.272 + // FIXME-3 VM needed? scene()->update();
1.273 + }
1.274 }
1.275
1.276
1.277 @@ -3815,7 +3805,6 @@
1.278
1.279 void VymModel::exportImage(QString fname, bool askName, QString format)
1.280 {
1.281 -/* FIXME-2 export as image, but directly from mapEditor?!
1.282 if (fname=="")
1.283 {
1.284 fname=getMapName()+".png";
1.285 @@ -3842,7 +3831,6 @@
1.286 QPixmap pix (mapEditor->getPixmap());
1.287 pix.save(fname, format);
1.288 setExportMode (false);
1.289 -*/
1.290 }
1.291
1.292
1.293 @@ -4596,23 +4584,6 @@
1.294 mapEditor->setSelectionColor (col);
1.295 }
1.296
1.297 -/*
1.298 -void VymModel::changeSelection (const QItemSelection &newsel,const QItemSelection &oldsel)
1.299 -{
1.300 - cout << "VymModel::changeSelection (";
1.301 - if (!newsel.indexes().isEmpty() )
1.302 - cout << getItem(newsel.indexes().first() )->getHeading().toStdString();
1.303 - cout << ",";
1.304 - if (!oldsel.indexes().isEmpty() )
1.305 - cout << getItem(oldsel.indexes().first() )->getHeading().toStdString();
1.306 - cout << ")\n";
1.307 -}
1.308 -*/
1.309 -
1.310 -void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far
1.311 -{
1.312 -}
1.313 -
1.314 void VymModel::emitSelectionChanged(const QItemSelection &newsel)
1.315 {
1.316 emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor
1.317 @@ -4914,13 +4885,13 @@
1.318 return getSelectString (getSelectedItem());
1.319 }
1.320
1.321 -QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...
1.322 +QString VymModel::getSelectString (LinkableMapObj *lmo) // only for convenience. Used in MapEditor
1.323 {
1.324 if (!lmo) return QString();
1.325 return getSelectString (lmo->getTreeItem() );
1.326 }
1.327
1.328 -QString VymModel::getSelectString (TreeItem *ti) //FIXME-1 does not return "mc:"
1.329 +QString VymModel::getSelectString (TreeItem *ti)
1.330 {
1.331 QString s;
1.332 if (!ti) return s;