1.1 --- a/vymmodel.cpp Thu Mar 19 11:45:28 2009 +0000
1.2 +++ b/vymmodel.cpp Mon Mar 23 09:06:51 2009 +0000
1.3 @@ -73,7 +73,7 @@
1.4 delete mapCenters.takeFirst();
1.5
1.6 QModelIndex ri=index(rootItem);
1.7 - removeRows (0, rowCount(ri),ri);
1.8 + //removeRows (0, rowCount(ri),ri); // FIXME here should be at least a beginRemoveRows...
1.9 }
1.10
1.11 void VymModel::init ()
1.12 @@ -233,17 +233,17 @@
1.13 s+=xml.beginElement("vymmap",mapAttr);
1.14 xml.incIndent();
1.15
1.16 - // Find the used flags while traversing the tree
1.17 + // Find the used flags while traversing the tree // FIXME this can be done local to vymmodel maybe...
1.18 standardFlagsDefault->resetUsedCounter();
1.19
1.20 // Reset the counters before saving
1.21 // TODO constr. of FIO creates lots of objects, better do this in some other way...
1.22 - FloatImageObj (mapScene).resetSaveCounter();
1.23 + FloatImageObj (mapScene).resetSaveCounter();// FIXME this can be done local to vymmodel maybe...
1.24
1.25 // Build xml recursivly
1.26 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
1.27 - // Save complete map, if saveSel not set
1.28 - s+=saveToDir(tmpdir,prefix,writeflags,offset);
1.29 + // Save all mapcenters as complete map, if saveSel not set
1.30 + s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
1.31 else
1.32 {
1.33 if ( typeid(*saveSel) == typeid(BranchObj) )
1.34 @@ -269,6 +269,15 @@
1.35 return s;
1.36 }
1.37
1.38 +QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
1.39 +{
1.40 + QString s;
1.41 +
1.42 + for (int i=0; i<mapCenters.count(); i++)
1.43 + s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
1.44 + return s;
1.45 +}
1.46 +
1.47 void VymModel::setFilePath(QString fpath, QString destname)
1.48 {
1.49 if (fpath.isEmpty() || fpath=="")
1.50 @@ -1409,15 +1418,6 @@
1.51 return NULL;
1.52 }
1.53
1.54 -QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
1.55 -{
1.56 - QString s;
1.57 -
1.58 - for (int i=0; i<mapCenters.count(); i++)
1.59 - s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
1.60 - return s;
1.61 -}
1.62 -
1.63 //////////////////////////////////////////////
1.64 // Interface
1.65 //////////////////////////////////////////////
1.66 @@ -2032,6 +2032,14 @@
1.67 mapCenters.append(mapCenter);
1.68
1.69 // Create TreeItem
1.70 + QModelIndex parix=index(rootItem);
1.71 +
1.72 + int n=rootItem->branchCount();
1.73 + cout << "VM::addMapCenter n="<<n<<endl;
1.74 +
1.75 + emit (layoutAboutToBeChanged() );
1.76 + beginInsertRows (parix,n,n+1);
1.77 +
1.78 QList<QVariant> cData;
1.79 cData << "VM:addMapCenter" << "undef"<<"undef";
1.80 TreeItem *ti=new TreeItem (cData,rootItem);
1.81 @@ -2040,6 +2048,20 @@
1.82 mapCenter->setTreeItem (ti);
1.83 rootItem->appendChild (ti);
1.84
1.85 + endInsertRows();
1.86 + emit (newChildObject (parix));
1.87 + emit (layoutChanged() );
1.88 +
1.89 + // Testing
1.90 +/*
1.91 + qWarning ("MW::insertRow a");
1.92 + if (!insertRow(0, parix))
1.93 + {
1.94 + std::cout << " war nix...\n";
1.95 + }
1.96 + qWarning ("MW::insertRow b");
1.97 +*/
1.98 +
1.99 return mapCenter;
1.100 }
1.101
1.102 @@ -2084,12 +2106,22 @@
1.103
1.104 // Create TreeItem
1.105 QList<QVariant> cData;
1.106 - cData << "VM:createBranch" << "undef"<<"undef";
1.107 + cData << "new" << "undef"<<"undef";
1.108 +
1.109 TreeItem *parti=bo->getTreeItem();
1.110 + QModelIndex parix=index(parti);
1.111 + int n=parti->branchCount();
1.112 +
1.113 + emit (layoutAboutToBeChanged() );
1.114 + beginInsertRows (parix,n,n+1);
1.115 TreeItem *ti=new TreeItem (cData,parti);
1.116 ti->setLMO (newbo);
1.117 ti->setType (TreeItem::Branch);
1.118 +
1.119 parti->appendChild (ti);
1.120 + endInsertRows ();
1.121 + emit (newChildObject (parix));
1.122 + emit (layoutChanged() );
1.123
1.124 if (newbo)
1.125 {
1.126 @@ -2101,12 +2133,12 @@
1.127 {
1.128 num=bo->getNum()+1;
1.129 bo=(BranchObj*)bo->getParObj();
1.130 - if (bo) newbo=bo->insertBranch(num);
1.131 + if (bo) newbo=bo->insertBranch(num); //FIXME VM still missing
1.132 }else if (num==-3)
1.133 {
1.134 num=bo->getNum();
1.135 bo=(BranchObj*)bo->getParObj();
1.136 - if (bo) newbo=bo->insertBranch(num);
1.137 + if (bo) newbo=bo->insertBranch(num); //FIXME VM still missing
1.138 }
1.139 }
1.140 return newbo;
1.141 @@ -2165,7 +2197,8 @@
1.142 BranchObj *parbo=(BranchObj*)(bo->getParObj());
1.143
1.144 // add below selection
1.145 - newbo=parbo->insertBranch(bo->getNum()+1);
1.146 + newbo=parbo->insertBranch(bo->getNum()+1); //FIXME VM still missing
1.147 +
1.148 if (newbo)
1.149 {
1.150 newbo->move2RelPos (p);
1.151 @@ -2186,15 +2219,24 @@
1.152
1.153 void VymModel::deleteSelection()
1.154 {
1.155 - BranchObj *bo = getSelectedBranch();
1.156 + BranchObj *bo = getSelectedBranch(); // FIXME VM should not be necessary
1.157 + if (!bo) return;
1.158 +
1.159 + QModelIndex ix=getSelectedIndex();
1.160 + if (!ix.isValid() ) return;
1.161 +
1.162 + QModelIndex parentIndex=parent(ix);
1.163 + if (!parentIndex.isValid()) return;
1.164 + TreeItem *ti=bo->getTreeItem();
1.165
1.166 - if (bo && selectionType()==TreeItem::MapCenter)
1.167 + if (selectionType()==TreeItem::MapCenter) //FIXME VM still missing
1.168 {
1.169 // BranchObj* par=(BranchObj*)(bo->getParObj());
1.170 - selection.unselect();
1.171 - /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!)
1.172 + //selection.unselect();
1.173 + /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!)
1.174 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
1.175 */
1.176 + /*
1.177 bo=removeMapCenter ((MapCenterObj*)bo);
1.178 if (bo)
1.179 {
1.180 @@ -2204,22 +2246,34 @@
1.181 }
1.182 reposition();
1.183 return;
1.184 + */
1.185 }
1.186 - if (bo && selectionType()==TreeItem::Branch)
1.187 + if (selectionType()==TreeItem::Branch)
1.188 {
1.189 - QModelIndex ix=getSelectedIndex();
1.190 + int n=ti->branchCount();
1.191
1.192 BranchObj* par=(BranchObj*)bo->getParObj();
1.193 unselect();
1.194 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
1.195 +
1.196 + emit (layoutAboutToBeChanged() );
1.197 +
1.198 + cout << "VM::delete ti="<<ti<<" row="<<ix.row()<<endl;
1.199 + parentIndex=parent(index(ti));
1.200 + cout << " valid parentIndex="<<parentIndex.isValid()<<endl;
1.201 + beginRemoveRows (parentIndex,n,n);
1.202 + removeRows (ix.row(),1,parentIndex);
1.203 + endRemoveRows();
1.204 par->removeBranch(bo);
1.205 select (par);
1.206 ensureSelectionVisible();
1.207 reposition();
1.208 - selection.update();
1.209 +
1.210 + emit (layoutChanged() );
1.211 return;
1.212 }
1.213 - FloatImageObj *fio=selection.getFloatImage();
1.214 + FloatImageObj *fio=selection.getFloatImage(); //FIXME VM still missing
1.215 +
1.216 if (fio)
1.217 {
1.218 BranchObj* par=(BranchObj*)fio->getParObj();
1.219 @@ -2233,13 +2287,13 @@
1.220 par->removeFloatImage(fio);
1.221 select (par);
1.222 reposition();
1.223 - selection.update();
1.224 ensureSelectionVisible();
1.225 return;
1.226 }
1.227 }
1.228
1.229 -void VymModel::deleteKeepChildren()
1.230 +void VymModel::deleteKeepChildren() //FIXME VM still missing
1.231 +
1.232 {
1.233 BranchObj *bo=getSelectedBranch();
1.234 BranchObj *par;
1.235 @@ -2275,7 +2329,8 @@
1.236 }
1.237 }
1.238
1.239 -void VymModel::deleteChildren()
1.240 +void VymModel::deleteChildren() //FIXME VM still missing
1.241 +
1.242 {
1.243 BranchObj *bo=getSelectedBranch();
1.244 if (bo)
1.245 @@ -4439,7 +4494,7 @@
1.246 {
1.247 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
1.248
1.249 - TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
1.250 + TreeItem *item = getItem (index);
1.251 return select (item->getLMO() );
1.252 }
1.253
1.254 @@ -4848,7 +4903,7 @@
1.255 {
1.256 QModelIndexList list=selModel->selectedIndexes();
1.257 if (list.isEmpty()) return TreeItem::Undefined;
1.258 - TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
1.259 + TreeItem *ti = getItem (list.first() );
1.260 return ti->getType();
1.261
1.262 }
1.263 @@ -4858,7 +4913,7 @@
1.264 QModelIndexList list=selModel->selectedIndexes();
1.265 if (!list.isEmpty() )
1.266 {
1.267 - TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
1.268 + TreeItem *ti = getItem (list.first() );
1.269 TreeItem::Type type=ti->getType();
1.270 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
1.271 {
1.272 @@ -4882,7 +4937,7 @@
1.273 QModelIndexList list=selModel->selectedIndexes();
1.274 if (!list.isEmpty() )
1.275 {
1.276 - TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
1.277 + TreeItem *ti = getItem (list.first() );
1.278 TreeItem::Type type=ti->getType();
1.279 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
1.280 return ti;