diff -r 338ebdc9b947 -r 14f2b1b15242 vymview.cpp --- a/vymview.cpp Fri Oct 02 14:31:03 2009 +0000 +++ b/vymview.cpp Fri Nov 13 08:32:03 2009 +0000 @@ -3,6 +3,7 @@ #include using namespace std; +#include "branchitem.h" #include "mainwindow.h" #include "mapeditor.h" #include "treeeditor.h" @@ -22,11 +23,12 @@ treeEditor->setColumnWidth (0,150); treeEditor->setAnimated (true); - proxySelModel=treeEditor->selectionModel(); + // FIXME-2 use proxySelModel=treeEditor->selectionModel(); selModel=new QItemSelectionModel (model); //model->setSelectionModel (proxySelModel); model->setSelectionModel (selModel); + treeEditor->setSelectionModel (selModel); // Create good old MapEditor mapEditor=model->getMapEditor(); @@ -35,23 +37,27 @@ // Connect selections // Proxymodel changed + /* connect ( proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &))); +*/ - // Model changed + // Selection in Model changed connect ( selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &))); - connect ( - model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), - mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &))); - //FIXME-3 above and below necessary??? + // Tell MapEditor to update selection connect ( selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &))); + // FIXME-2 testing, if that reenables updating selbox during animation + connect ( + model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), + mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &))); + // Connect data changed signals connect ( model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), @@ -70,6 +76,14 @@ this, SLOT (expandAll () ) ); connect ( + model, SIGNAL (expandOneLevel() ), + this, SLOT (expandOneLevel() ) ); + + connect ( + model, SIGNAL (collapseOneLevel() ), + this, SLOT (collapseOneLevel() ) ); + + connect ( model, SIGNAL (showSelection() ), this, SLOT (showSelection() ) ); @@ -112,10 +126,22 @@ // Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...) mainWindow->changeSelection (model,newsel,oldsel); // FIXME-5 maybe connect VymModel <-> MainWindow directly? // would require to also get current model in mainWindow - proxySelModel->select ( - treeEditor->getProxyModel()->mapSelectionFromSource (newsel), - QItemSelectionModel::ClearAndSelect ); - showSelection(); + + cout << "VV::changeSelection newsel.count="<0) + { + + /* FIXME-2 use proxymodel + proxySelModel->select ( + treeEditor->getProxyModel()->mapSelectionFromSource (newsel), + QItemSelectionModel::ClearAndSelect ); + */ + QModelIndex ix=newsel.indexes().first(); + selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect ); + treeEditor->setCurrentIndex (ix); + showSelection(); + } } void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel) @@ -123,9 +149,22 @@ // Notify mainwindow to update satellites, but map selection to // original model first + cout << "VV::changeProxySelection newsel.count="<setCurrentIndex ( + newsel.indexes().first(), + QItemSelectionModel::ClearAndSelect ); + treeEditor->setCurrentIndex (newsel.indexes().first() ); + } + // Re-emit but map selection first - selModel->select (treeEditor->getProxyModel()->mapSelectionToSource (newsel), + selModel->select ( + treeEditor->getProxyModel()->mapSelectionToSource (newsel), QItemSelectionModel::ClearAndSelect ); + showSelection(); } @@ -134,6 +173,85 @@ treeEditor->expandAll(); } +void VymView::expandOneLevel() +{ + int level=999999; + int d; + BranchItem *cur=NULL; + BranchItem *prev=NULL; + QModelIndex pix; + + // Find level to expand + model->nextBranch(cur,prev); + while (cur) + { + // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur)); + pix=model->index (cur); + d=cur->depth(); + if (!treeEditor->isExpanded(pix) && d < level) + level=d; + model->nextBranch(cur,prev); + } + + // Expand all to level + cur=NULL; + prev=NULL; + model->nextBranch(cur,prev); + while (cur) + { + // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur)); + pix=model->index (cur); + d=cur->depth(); + if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0) + treeEditor->setExpanded(pix,true); + model->nextBranch(cur,prev); + } + /* FIXME-3 optimize expanding by using flat version of next + model->nextBranch(cur,prev,false); + while (cur) + { + cout << "ok: "<getHeadingStd()<nextBranch(cur,prev,false); + } + */ +} + +void VymView::collapseOneLevel() +{ + int level=-1; + int d; + BranchItem *cur=NULL; + BranchItem *prev=NULL; + QModelIndex pix; + + // Find level to collapse + model->nextBranch(cur,prev); + while (cur) + { + // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur)); + pix=model->index (cur); + d=cur->depth(); + if (treeEditor->isExpanded(pix) && d > level) + level=d; + model->nextBranch(cur,prev); + } + + // collapse all to level + cur=NULL; + prev=NULL; + model->nextBranch(cur,prev); + while (cur) + { + // FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur)); + pix=model->index (cur); + d=cur->depth(); + if (treeEditor->isExpanded(pix) && d >= level) + treeEditor->setExpanded(pix,false); + model->nextBranch(cur,prev); + } +} + void VymView::showSelection() { QModelIndex ix=model->getSelectedIndex();