1.1 --- a/branchobj.cpp Thu Mar 19 11:45:28 2009 +0000
1.2 +++ b/branchobj.cpp Mon Mar 23 09:06:51 2009 +0000
1.3 @@ -60,7 +60,7 @@
1.4 model->stopAnimation (this);
1.5 }
1.6
1.7 - //cout << "Destr BranchObj of "<<this<<endl;
1.8 + cout << "Destr BranchObj of "<<this<<endl;
1.9 // Check, if this branch was the last child to be deleted
1.10 // If so, unset the scrolled flags
1.11
2.1 --- a/treeitem.cpp Thu Mar 19 11:45:28 2009 +0000
2.2 +++ b/treeitem.cpp Mon Mar 23 09:06:51 2009 +0000
2.3 @@ -23,7 +23,6 @@
2.4 void TreeItem::appendChild(TreeItem *item)
2.5 {
2.6 childItems.append(item);
2.7 -
2.8
2.9 if (item->type == Branch || item->type ==MapCenter)
2.10 {
2.11 @@ -33,14 +32,17 @@
2.12 }
2.13 }
2.14
2.15 +#include <iostream>
2.16 +using namespace std;
2.17 void TreeItem::removeChild(int row)
2.18 {
2.19 - if (row>=0)
2.20 + if (row<0 || row > childItems.size()-1)
2.21 + qWarning ("TreeItem::removeChild tried to remove non existing item?!\n");
2.22 + else
2.23 {
2.24 - delete (childItems.at(row) );
2.25 - childItems.removeAt (row);
2.26 - } else
2.27 - qWarning ("TreeItem::removeChild tried to remove non existing item?!\n");
2.28 + cout << "TI::removeChild this="<<this<<" row="<<row<<endl;
2.29 + delete childItems.takeAt (row);
2.30 + }
2.31 }
2.32
2.33 TreeItem *TreeItem::child(int row)
2.34 @@ -53,6 +55,14 @@
2.35 return childItems.count();
2.36 }
2.37
2.38 +int TreeItem::childNumber() const
2.39 +{
2.40 + if (parentItem)
2.41 + return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
2.42 +
2.43 + return 0;
2.44 +}
2.45 +
2.46 int TreeItem::columnCount() const
2.47 {
2.48 return itemData.count();
3.1 --- a/treeitem.h Thu Mar 19 11:45:28 2009 +0000
3.2 +++ b/treeitem.h Mon Mar 23 09:06:51 2009 +0000
3.3 @@ -19,6 +19,7 @@
3.4
3.5 TreeItem *child(int row);
3.6 int childCount() const;
3.7 + int childNumber() const;
3.8 int columnCount() const;
3.9 int branchCount() const;
3.10
4.1 --- a/treemodel.cpp Thu Mar 19 11:45:28 2009 +0000
4.2 +++ b/treemodel.cpp Mon Mar 23 09:06:51 2009 +0000
4.3 @@ -27,7 +27,7 @@
4.4 if (role != Qt::DisplayRole)
4.5 return QVariant();
4.6
4.7 - TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
4.8 + TreeItem *item = getItem (index);
4.9
4.10 return item->data(index.column());
4.11 }
4.12 @@ -57,7 +57,7 @@
4.13 if (!parent.isValid())
4.14 parentItem = rootItem;
4.15 else
4.16 - parentItem = static_cast<TreeItem*>(parent.internalPointer());
4.17 + parentItem = getItem (parent);
4.18
4.19 TreeItem *childItem = parentItem->child(row);
4.20 if (childItem)
4.21 @@ -71,13 +71,20 @@
4.22 if (!index.isValid())
4.23 return QModelIndex();
4.24
4.25 - TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
4.26 - TreeItem *parentItem = childItem->parent();
4.27 + TreeItem *ti= getItem (index);
4.28 + TreeItem *parentItem = ti->parent();
4.29
4.30 + //cout << "TreeModel::parent ti="<<ti<<" "<<ti->getHeading().toStdString()<<" pi="<<parentItem<<" "<<endl;
4.31 if (parentItem == rootItem)
4.32 return QModelIndex();
4.33
4.34 - return createIndex(parentItem->row(), 0, parentItem);
4.35 + if (!parentItem)
4.36 + {
4.37 + cout <<"TreeModel::parent ti=="<<ti<<" "<<ti->getHeading().toStdString()<<endl;
4.38 + return QModelIndex(); // FIXME do this to avoid segfault, but why?
4.39 + }
4.40 +
4.41 + return createIndex(parentItem->childNumber(), 0, parentItem);
4.42 }
4.43
4.44 int TreeModel::rowCount(const QModelIndex &parent) const
4.45 @@ -87,7 +94,7 @@
4.46 if (!parent.isValid())
4.47 parentItem = rootItem;
4.48 else
4.49 - parentItem = static_cast<TreeItem*>(parent.internalPointer());
4.50 + parentItem = getItem (parent);
4.51
4.52 return parentItem->childCount();
4.53 }
4.54 @@ -95,7 +102,7 @@
4.55 int TreeModel::columnCount(const QModelIndex &parent) const
4.56 {
4.57 if (parent.isValid())
4.58 - return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
4.59 + return getItem (parent)->columnCount();
4.60 else
4.61 return rootItem->columnCount();
4.62 }
4.63 @@ -158,20 +165,47 @@
4.64 return current;
4.65 }
4.66
4.67 +bool TreeModel::insertRows ( int row, int count, const QModelIndex & parent)
4.68 +{
4.69 + std::cout << "TreeModel insertRows()\n";
4.70 + int last=row+count-1;
4.71 + beginInsertRows (parent,row,last);
4.72 +
4.73 + for (int i=row; i<=last; i++)
4.74 + {
4.75 + std::cout << "TreeModel::insertRows inserting i="<<i<<std::endl;
4.76 + }
4.77 + endInsertRows ();
4.78 + return true;
4.79 +}
4.80 +
4.81 bool TreeModel::removeRows ( int row, int count, const QModelIndex & parent)
4.82 {
4.83 int last=row+count-1;
4.84 + cout << "TreeModel::removeRows row="<<row<<" count="<<count<<" last="<<last<<endl;
4.85 + TreeItem *pi= getItem (parent);
4.86 + cout << " pi="<<pi<<" "<<pi->getHeading().toStdString()<<endl;
4.87 + cout << " ok0\n";
4.88 beginRemoveRows (parent,row,last);
4.89 + cout << " ok1\n";
4.90
4.91 - TreeItem *pi= static_cast<TreeItem*>(parent.internalPointer());
4.92 for (int i=row; i<=last; i++)
4.93 {
4.94 - std::cout << "TreeModel::removeRows removing i="<<i<<std::endl;
4.95 + cout << "TreeModel::removeRows removing i="<<i<<std::endl;
4.96 pi->removeChild (row);
4.97 }
4.98 + endRemoveRows ();
4.99 + return true;
4.100 +}
4.101
4.102 - endRemoveRows ();
4.103 -
4.104 +TreeItem *TreeModel::getItem(const QModelIndex &index) const
4.105 +{
4.106 + if (index.isValid()) {
4.107 + TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
4.108 +
4.109 + if (item) return item;
4.110 + }
4.111 + return rootItem;
4.112 }
4.113
4.114 QModelIndex TreeModel::index (TreeItem* ti)
5.1 --- a/treemodel.h Thu Mar 19 11:45:28 2009 +0000
5.2 +++ b/treemodel.h Mon Mar 23 09:06:51 2009 +0000
5.3 @@ -29,9 +29,12 @@
5.4
5.5 TreeItem* next(TreeItem* ¤t, TreeItem* &previous, int &d0);
5.6
5.7 + bool insertRows ( int row, int count,
5.8 + const QModelIndex & parent = QModelIndex() );
5.9 bool removeRows ( int row, int count,
5.10 const QModelIndex & parent = QModelIndex() );
5.11
5.12 + TreeItem* getItem (const QModelIndex &index) const;
5.13 QModelIndex index (TreeItem* ti);
5.14
5.15 protected:
6.1 --- a/vymmodel.cpp Thu Mar 19 11:45:28 2009 +0000
6.2 +++ b/vymmodel.cpp Mon Mar 23 09:06:51 2009 +0000
6.3 @@ -73,7 +73,7 @@
6.4 delete mapCenters.takeFirst();
6.5
6.6 QModelIndex ri=index(rootItem);
6.7 - removeRows (0, rowCount(ri),ri);
6.8 + //removeRows (0, rowCount(ri),ri); // FIXME here should be at least a beginRemoveRows...
6.9 }
6.10
6.11 void VymModel::init ()
6.12 @@ -233,17 +233,17 @@
6.13 s+=xml.beginElement("vymmap",mapAttr);
6.14 xml.incIndent();
6.15
6.16 - // Find the used flags while traversing the tree
6.17 + // Find the used flags while traversing the tree // FIXME this can be done local to vymmodel maybe...
6.18 standardFlagsDefault->resetUsedCounter();
6.19
6.20 // Reset the counters before saving
6.21 // TODO constr. of FIO creates lots of objects, better do this in some other way...
6.22 - FloatImageObj (mapScene).resetSaveCounter();
6.23 + FloatImageObj (mapScene).resetSaveCounter();// FIXME this can be done local to vymmodel maybe...
6.24
6.25 // Build xml recursivly
6.26 if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
6.27 - // Save complete map, if saveSel not set
6.28 - s+=saveToDir(tmpdir,prefix,writeflags,offset);
6.29 + // Save all mapcenters as complete map, if saveSel not set
6.30 + s+=saveTreeToDir(tmpdir,prefix,writeflags,offset);
6.31 else
6.32 {
6.33 if ( typeid(*saveSel) == typeid(BranchObj) )
6.34 @@ -269,6 +269,15 @@
6.35 return s;
6.36 }
6.37
6.38 +QString VymModel::saveTreeToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
6.39 +{
6.40 + QString s;
6.41 +
6.42 + for (int i=0; i<mapCenters.count(); i++)
6.43 + s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
6.44 + return s;
6.45 +}
6.46 +
6.47 void VymModel::setFilePath(QString fpath, QString destname)
6.48 {
6.49 if (fpath.isEmpty() || fpath=="")
6.50 @@ -1409,15 +1418,6 @@
6.51 return NULL;
6.52 }
6.53
6.54 -QString VymModel::saveToDir (const QString &tmpdir,const QString &prefix, int verbose, const QPointF &offset)
6.55 -{
6.56 - QString s;
6.57 -
6.58 - for (int i=0; i<mapCenters.count(); i++)
6.59 - s+=mapCenters.at(i)->saveToDir (tmpdir,prefix,verbose,offset);
6.60 - return s;
6.61 -}
6.62 -
6.63 //////////////////////////////////////////////
6.64 // Interface
6.65 //////////////////////////////////////////////
6.66 @@ -2032,6 +2032,14 @@
6.67 mapCenters.append(mapCenter);
6.68
6.69 // Create TreeItem
6.70 + QModelIndex parix=index(rootItem);
6.71 +
6.72 + int n=rootItem->branchCount();
6.73 + cout << "VM::addMapCenter n="<<n<<endl;
6.74 +
6.75 + emit (layoutAboutToBeChanged() );
6.76 + beginInsertRows (parix,n,n+1);
6.77 +
6.78 QList<QVariant> cData;
6.79 cData << "VM:addMapCenter" << "undef"<<"undef";
6.80 TreeItem *ti=new TreeItem (cData,rootItem);
6.81 @@ -2040,6 +2048,20 @@
6.82 mapCenter->setTreeItem (ti);
6.83 rootItem->appendChild (ti);
6.84
6.85 + endInsertRows();
6.86 + emit (newChildObject (parix));
6.87 + emit (layoutChanged() );
6.88 +
6.89 + // Testing
6.90 +/*
6.91 + qWarning ("MW::insertRow a");
6.92 + if (!insertRow(0, parix))
6.93 + {
6.94 + std::cout << " war nix...\n";
6.95 + }
6.96 + qWarning ("MW::insertRow b");
6.97 +*/
6.98 +
6.99 return mapCenter;
6.100 }
6.101
6.102 @@ -2084,12 +2106,22 @@
6.103
6.104 // Create TreeItem
6.105 QList<QVariant> cData;
6.106 - cData << "VM:createBranch" << "undef"<<"undef";
6.107 + cData << "new" << "undef"<<"undef";
6.108 +
6.109 TreeItem *parti=bo->getTreeItem();
6.110 + QModelIndex parix=index(parti);
6.111 + int n=parti->branchCount();
6.112 +
6.113 + emit (layoutAboutToBeChanged() );
6.114 + beginInsertRows (parix,n,n+1);
6.115 TreeItem *ti=new TreeItem (cData,parti);
6.116 ti->setLMO (newbo);
6.117 ti->setType (TreeItem::Branch);
6.118 +
6.119 parti->appendChild (ti);
6.120 + endInsertRows ();
6.121 + emit (newChildObject (parix));
6.122 + emit (layoutChanged() );
6.123
6.124 if (newbo)
6.125 {
6.126 @@ -2101,12 +2133,12 @@
6.127 {
6.128 num=bo->getNum()+1;
6.129 bo=(BranchObj*)bo->getParObj();
6.130 - if (bo) newbo=bo->insertBranch(num);
6.131 + if (bo) newbo=bo->insertBranch(num); //FIXME VM still missing
6.132 }else if (num==-3)
6.133 {
6.134 num=bo->getNum();
6.135 bo=(BranchObj*)bo->getParObj();
6.136 - if (bo) newbo=bo->insertBranch(num);
6.137 + if (bo) newbo=bo->insertBranch(num); //FIXME VM still missing
6.138 }
6.139 }
6.140 return newbo;
6.141 @@ -2165,7 +2197,8 @@
6.142 BranchObj *parbo=(BranchObj*)(bo->getParObj());
6.143
6.144 // add below selection
6.145 - newbo=parbo->insertBranch(bo->getNum()+1);
6.146 + newbo=parbo->insertBranch(bo->getNum()+1); //FIXME VM still missing
6.147 +
6.148 if (newbo)
6.149 {
6.150 newbo->move2RelPos (p);
6.151 @@ -2186,15 +2219,24 @@
6.152
6.153 void VymModel::deleteSelection()
6.154 {
6.155 - BranchObj *bo = getSelectedBranch();
6.156 + BranchObj *bo = getSelectedBranch(); // FIXME VM should not be necessary
6.157 + if (!bo) return;
6.158 +
6.159 + QModelIndex ix=getSelectedIndex();
6.160 + if (!ix.isValid() ) return;
6.161 +
6.162 + QModelIndex parentIndex=parent(ix);
6.163 + if (!parentIndex.isValid()) return;
6.164 + TreeItem *ti=bo->getTreeItem();
6.165
6.166 - if (bo && selectionType()==TreeItem::MapCenter)
6.167 + if (selectionType()==TreeItem::MapCenter) //FIXME VM still missing
6.168 {
6.169 // BranchObj* par=(BranchObj*)(bo->getParObj());
6.170 - selection.unselect();
6.171 - /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!)
6.172 + //selection.unselect();
6.173 + /* FIXME VM Note: does saveStateRemovingPart work for MCO? (No parent!)
6.174 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
6.175 */
6.176 + /*
6.177 bo=removeMapCenter ((MapCenterObj*)bo);
6.178 if (bo)
6.179 {
6.180 @@ -2204,22 +2246,34 @@
6.181 }
6.182 reposition();
6.183 return;
6.184 + */
6.185 }
6.186 - if (bo && selectionType()==TreeItem::Branch)
6.187 + if (selectionType()==TreeItem::Branch)
6.188 {
6.189 - QModelIndex ix=getSelectedIndex();
6.190 + int n=ti->branchCount();
6.191
6.192 BranchObj* par=(BranchObj*)bo->getParObj();
6.193 unselect();
6.194 saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo)));
6.195 +
6.196 + emit (layoutAboutToBeChanged() );
6.197 +
6.198 + cout << "VM::delete ti="<<ti<<" row="<<ix.row()<<endl;
6.199 + parentIndex=parent(index(ti));
6.200 + cout << " valid parentIndex="<<parentIndex.isValid()<<endl;
6.201 + beginRemoveRows (parentIndex,n,n);
6.202 + removeRows (ix.row(),1,parentIndex);
6.203 + endRemoveRows();
6.204 par->removeBranch(bo);
6.205 select (par);
6.206 ensureSelectionVisible();
6.207 reposition();
6.208 - selection.update();
6.209 +
6.210 + emit (layoutChanged() );
6.211 return;
6.212 }
6.213 - FloatImageObj *fio=selection.getFloatImage();
6.214 + FloatImageObj *fio=selection.getFloatImage(); //FIXME VM still missing
6.215 +
6.216 if (fio)
6.217 {
6.218 BranchObj* par=(BranchObj*)fio->getParObj();
6.219 @@ -2233,13 +2287,13 @@
6.220 par->removeFloatImage(fio);
6.221 select (par);
6.222 reposition();
6.223 - selection.update();
6.224 ensureSelectionVisible();
6.225 return;
6.226 }
6.227 }
6.228
6.229 -void VymModel::deleteKeepChildren()
6.230 +void VymModel::deleteKeepChildren() //FIXME VM still missing
6.231 +
6.232 {
6.233 BranchObj *bo=getSelectedBranch();
6.234 BranchObj *par;
6.235 @@ -2275,7 +2329,8 @@
6.236 }
6.237 }
6.238
6.239 -void VymModel::deleteChildren()
6.240 +void VymModel::deleteChildren() //FIXME VM still missing
6.241 +
6.242 {
6.243 BranchObj *bo=getSelectedBranch();
6.244 if (bo)
6.245 @@ -4439,7 +4494,7 @@
6.246 {
6.247 QModelIndex index=selModel->selectedIndexes().first(); // TODO no multiselections yet
6.248
6.249 - TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
6.250 + TreeItem *item = getItem (index);
6.251 return select (item->getLMO() );
6.252 }
6.253
6.254 @@ -4848,7 +4903,7 @@
6.255 {
6.256 QModelIndexList list=selModel->selectedIndexes();
6.257 if (list.isEmpty()) return TreeItem::Undefined;
6.258 - TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
6.259 + TreeItem *ti = getItem (list.first() );
6.260 return ti->getType();
6.261
6.262 }
6.263 @@ -4858,7 +4913,7 @@
6.264 QModelIndexList list=selModel->selectedIndexes();
6.265 if (!list.isEmpty() )
6.266 {
6.267 - TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
6.268 + TreeItem *ti = getItem (list.first() );
6.269 TreeItem::Type type=ti->getType();
6.270 if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image)
6.271 {
6.272 @@ -4882,7 +4937,7 @@
6.273 QModelIndexList list=selModel->selectedIndexes();
6.274 if (!list.isEmpty() )
6.275 {
6.276 - TreeItem *ti = static_cast<TreeItem*>(list.first().internalPointer());
6.277 + TreeItem *ti = getItem (list.first() );
6.278 TreeItem::Type type=ti->getType();
6.279 if (type ==TreeItem::Branch || type==TreeItem::MapCenter)
6.280 return ti;
7.1 --- a/vymmodel.h Thu Mar 19 11:45:28 2009 +0000
7.2 +++ b/vymmodel.h Mon Mar 23 09:06:51 2009 +0000
7.3 @@ -68,6 +68,10 @@
7.4 */
7.5 QString saveToDir (const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel);
7.6
7.7 + /*! Save all data in tree*/
7.8 + QString saveTreeToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
7.9 +
7.10 +
7.11 /*! \brief Sets filepath, filename and mapname
7.12
7.13 If the filepath is "/home/tux/map.xml", then the filename will be set
7.14 @@ -216,8 +220,6 @@
7.15 LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
7.16 LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
7.17
7.18 - QString saveToDir (const QString&,const QString&,int, const QPointF&);// Save data recursivly to tempdir
7.19 -
7.20
7.21 ////////////////////////////////////////////
7.22 // Interface
7.23 @@ -415,6 +417,9 @@
7.24
7.25 //void ensureSelectionVisible(); //!< Show selection in all views
7.26
7.27 +signals:
7.28 + void newChildObject(QModelIndex ix);
7.29 +
7.30 private:
7.31 MapEditor *mapEditor;
7.32
8.1 --- a/vymview.cpp Thu Mar 19 11:45:28 2009 +0000
8.2 +++ b/vymview.cpp Mon Mar 23 09:06:51 2009 +0000
8.3 @@ -39,6 +39,9 @@
8.4 connect (
8.5 model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
8.6 me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
8.7 + connect (
8.8 + model, SIGNAL (newChildObject(QModelIndex) ),
8.9 + this,SLOT (updateChilds (QModelIndex) ) );
8.10
8.11 //me->viewport()->setFocus(); //FIXME needed?
8.12 me->setAntiAlias (mainWindow->isAliased());
8.13 @@ -64,13 +67,16 @@
8.14 }
8.15
8.16
8.17 +void VymView::updateChilds (QModelIndex ix)
8.18 +{
8.19 + treeview->setExpanded (ix,true);
8.20 +}
8.21 +
8.22 void VymView::changeSelection (const QItemSelection &, const QItemSelection &)
8.23 {
8.24 cout << "VymView::changeSelection (newsel,delsel)\n";
8.25 //treeview->expandAll(); //FIXME only for testing
8.26
8.27 - //((VymModel*)treeview->model())->select ();
8.28 -
8.29 // Show URL and link in statusbar
8.30 QString status;
8.31 QString s=model->getURL();
8.32 @@ -79,12 +85,9 @@
8.33 if (!s.isEmpty() ) status+="Link: "+s;
8.34 if (!status.isEmpty() ) mainWindow->statusMessage (status);
8.35
8.36 -/* FIXME, was so far in BranchObj
8.37 - // Update Toolbar
8.38 + // Update Toolbar // FIXME, was so far in BranchObj
8.39 //updateFlagsToolbar();
8.40
8.41 -*/
8.42 -
8.43 // Update actions
8.44 mainWindow->updateActions();
8.45 }
9.1 --- a/vymview.h Thu Mar 19 11:45:28 2009 +0000
9.2 +++ b/vymview.h Mon Mar 23 09:06:51 2009 +0000
9.3 @@ -16,6 +16,7 @@
9.4 QItemSelectionModel* selectionModel();
9.5
9.6 public slots:
9.7 + void updateChilds (QModelIndex ix);
9.8 void changeSelection (const QItemSelection &newSel, const QItemSelection &delSel);
9.9
9.10 private: