# HG changeset patch # User insilmaril # Date 1237799211 0 # Node ID 2d4cc445a86aa893a25ff1bb1bc7d7cbb785ab89 # Parent 94ed4372ef08b54c1e19f1138f6d2c40773896ac still working on insert/remove of rows diff -r 94ed4372ef08 -r 2d4cc445a86a branchobj.cpp --- a/branchobj.cpp Thu Mar 19 11:45:28 2009 +0000 +++ b/branchobj.cpp Mon Mar 23 09:06:51 2009 +0000 @@ -60,7 +60,7 @@ model->stopAnimation (this); } - //cout << "Destr BranchObj of "<type == Branch || item->type ==MapCenter) { @@ -33,14 +32,17 @@ } } +#include +using namespace std; void TreeItem::removeChild(int row) { - if (row>=0) + if (row<0 || row > childItems.size()-1) + qWarning ("TreeItem::removeChild tried to remove non existing item?!\n"); + else { - delete (childItems.at(row) ); - childItems.removeAt (row); - } else - qWarning ("TreeItem::removeChild tried to remove non existing item?!\n"); + cout << "TI::removeChild this="<getHeading().toStdString()<<" pi="<row(), 0, parentItem); + if (!parentItem) + { + cout <<"TreeModel::parent ti=="<getHeading().toStdString()<childNumber(), 0, parentItem); } int TreeModel::rowCount(const QModelIndex &parent) const @@ -87,7 +94,7 @@ if (!parent.isValid()) parentItem = rootItem; else - parentItem = static_cast(parent.internalPointer()); + parentItem = getItem (parent); return parentItem->childCount(); } @@ -95,7 +102,7 @@ int TreeModel::columnCount(const QModelIndex &parent) const { if (parent.isValid()) - return static_cast(parent.internalPointer())->columnCount(); + return getItem (parent)->columnCount(); else return rootItem->columnCount(); } @@ -158,20 +165,47 @@ return current; } +bool TreeModel::insertRows ( int row, int count, const QModelIndex & parent) +{ + std::cout << "TreeModel insertRows()\n"; + int last=row+count-1; + beginInsertRows (parent,row,last); + + for (int i=row; i<=last; i++) + { + std::cout << "TreeModel::insertRows inserting i="<getHeading().toStdString()<(parent.internalPointer()); for (int i=row; i<=last; i++) { - std::cout << "TreeModel::removeRows removing i="<resetUsedCounter(); // Reset the counters before saving // TODO constr. of FIO creates lots of objects, better do this in some other way... - FloatImageObj (mapScene).resetSaveCounter(); + FloatImageObj (mapScene).resetSaveCounter();// FIXME this can be done local to vymmodel maybe... // Build xml recursivly if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj)) - // Save complete map, if saveSel not set - s+=saveToDir(tmpdir,prefix,writeflags,offset); + // Save all mapcenters as complete map, if saveSel not set + s+=saveTreeToDir(tmpdir,prefix,writeflags,offset); else { if ( typeid(*saveSel) == typeid(BranchObj) ) @@ -269,6 +269,15 @@ return s; } +QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset) +{ + QString s; + + for (int i=0; isaveToDir (tmpdir,prefix,verbose,offset); + return s; +} + void VymModel::setFilePath(QString fpath, QString destname) { if (fpath.isEmpty() || fpath=="") @@ -1409,15 +1418,6 @@ 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; -} - ////////////////////////////////////////////// // Interface ////////////////////////////////////////////// @@ -2032,6 +2032,14 @@ mapCenters.append(mapCenter); // Create TreeItem + QModelIndex parix=index(rootItem); + + int n=rootItem->branchCount(); + cout << "VM::addMapCenter n="< cData; cData << "VM:addMapCenter" << "undef"<<"undef"; TreeItem *ti=new TreeItem (cData,rootItem); @@ -2040,6 +2048,20 @@ mapCenter->setTreeItem (ti); rootItem->appendChild (ti); + endInsertRows(); + emit (newChildObject (parix)); + emit (layoutChanged() ); + + // Testing +/* + qWarning ("MW::insertRow a"); + if (!insertRow(0, parix)) + { + std::cout << " war nix...\n"; + } + qWarning ("MW::insertRow b"); +*/ + return mapCenter; } @@ -2084,12 +2106,22 @@ // Create TreeItem QList cData; - cData << "VM:createBranch" << "undef"<<"undef"; + 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) { @@ -2101,12 +2133,12 @@ { num=bo->getNum()+1; bo=(BranchObj*)bo->getParObj(); - if (bo) newbo=bo->insertBranch(num); + if (bo) newbo=bo->insertBranch(num); //FIXME VM still missing }else if (num==-3) { num=bo->getNum(); bo=(BranchObj*)bo->getParObj(); - if (bo) newbo=bo->insertBranch(num); + if (bo) newbo=bo->insertBranch(num); //FIXME VM still missing } } return newbo; @@ -2165,7 +2197,8 @@ BranchObj *parbo=(BranchObj*)(bo->getParObj()); // add below selection - newbo=parbo->insertBranch(bo->getNum()+1); + newbo=parbo->insertBranch(bo->getNum()+1); //FIXME VM still missing + if (newbo) { newbo->move2RelPos (p); @@ -2186,15 +2219,24 @@ void VymModel::deleteSelection() { - BranchObj *bo = getSelectedBranch(); + BranchObj *bo = getSelectedBranch(); // FIXME VM should not be necessary + if (!bo) return; + + QModelIndex ix=getSelectedIndex(); + if (!ix.isValid() ) return; + + QModelIndex parentIndex=parent(ix); + if (!parentIndex.isValid()) return; + TreeItem *ti=bo->getTreeItem(); - if (bo && selectionType()==TreeItem::MapCenter) + if (selectionType()==TreeItem::MapCenter) //FIXME VM still missing { // BranchObj* par=(BranchObj*)(bo->getParObj()); - selection.unselect(); - /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!) + //selection.unselect(); + /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!) saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo))); */ + /* bo=removeMapCenter ((MapCenterObj*)bo); if (bo) { @@ -2204,22 +2246,34 @@ } reposition(); return; + */ } - if (bo && selectionType()==TreeItem::Branch) + if (selectionType()==TreeItem::Branch) { - QModelIndex ix=getSelectedIndex(); + int n=ti->branchCount(); BranchObj* par=(BranchObj*)bo->getParObj(); unselect(); saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo))); + + emit (layoutAboutToBeChanged() ); + + cout << "VM::delete ti="<viewport()->setFocus(); //FIXME needed? me->setAntiAlias (mainWindow->isAliased()); @@ -64,13 +67,16 @@ } +void VymView::updateChilds (QModelIndex ix) +{ + treeview->setExpanded (ix,true); +} + void VymView::changeSelection (const QItemSelection &, const QItemSelection &) { cout << "VymView::changeSelection (newsel,delsel)\n"; //treeview->expandAll(); //FIXME only for testing - //((VymModel*)treeview->model())->select (); - // Show URL and link in statusbar QString status; QString s=model->getURL(); @@ -79,12 +85,9 @@ if (!s.isEmpty() ) status+="Link: "+s; if (!status.isEmpty() ) mainWindow->statusMessage (status); -/* FIXME, was so far in BranchObj - // Update Toolbar + // Update Toolbar // FIXME, was so far in BranchObj //updateFlagsToolbar(); -*/ - // Update actions mainWindow->updateActions(); } diff -r 94ed4372ef08 -r 2d4cc445a86a vymview.h --- a/vymview.h Thu Mar 19 11:45:28 2009 +0000 +++ b/vymview.h Mon Mar 23 09:06:51 2009 +0000 @@ -16,6 +16,7 @@ QItemSelectionModel* selectionModel(); public slots: + void updateChilds (QModelIndex ix); void changeSelection (const QItemSelection &newSel, const QItemSelection &delSel); private: