vymview.cpp
changeset 804 14f2b1b15242
parent 803 338ebdc9b947
child 806 2a33304714ba
     1.1 --- a/vymview.cpp	Fri Oct 02 14:31:03 2009 +0000
     1.2 +++ b/vymview.cpp	Fri Nov 13 08:32:03 2009 +0000
     1.3 @@ -3,6 +3,7 @@
     1.4  #include <iostream>
     1.5  using namespace std;
     1.6  
     1.7 +#include "branchitem.h"
     1.8  #include "mainwindow.h"
     1.9  #include "mapeditor.h"
    1.10  #include "treeeditor.h"
    1.11 @@ -22,11 +23,12 @@
    1.12  	treeEditor->setColumnWidth (0,150);
    1.13  	treeEditor->setAnimated (true);
    1.14  
    1.15 -	proxySelModel=treeEditor->selectionModel();
    1.16 +	// FIXME-2 use proxySelModel=treeEditor->selectionModel();
    1.17  	selModel=new QItemSelectionModel (model);
    1.18  
    1.19  	//model->setSelectionModel (proxySelModel);
    1.20  	model->setSelectionModel (selModel);
    1.21 +	treeEditor->setSelectionModel (selModel);
    1.22  
    1.23  	// Create good old MapEditor
    1.24  	mapEditor=model->getMapEditor();
    1.25 @@ -35,23 +37,27 @@
    1.26  	// Connect selections
    1.27  
    1.28  		// Proxymodel changed
    1.29 +		/*
    1.30  		connect (
    1.31  			proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.32  			this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
    1.33 +*/
    1.34  
    1.35 -		// Model changed	
    1.36 +		// Selection in Model changed	
    1.37  		connect (
    1.38  			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.39  			this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    1.40  
    1.41 -		connect (
    1.42 -			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
    1.43 -			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    1.44 -			//FIXME-3 above and below necessary???
    1.45 +		// Tell MapEditor to update selection
    1.46  		connect (
    1.47  			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.48  			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    1.49  
    1.50 +		// FIXME-2 testing, if that reenables updating selbox during animation
    1.51 +		connect (
    1.52 +			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    1.53 +			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    1.54 +
    1.55  	// Connect data changed signals	
    1.56  	connect (
    1.57  		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    1.58 @@ -70,6 +76,14 @@
    1.59  		this, SLOT (expandAll () ) );
    1.60  		
    1.61  	connect (
    1.62 +		model, SIGNAL (expandOneLevel() ),
    1.63 +		this, SLOT (expandOneLevel() ) );
    1.64 +		
    1.65 +	connect (
    1.66 +		model, SIGNAL (collapseOneLevel() ),
    1.67 +		this, SLOT (collapseOneLevel() ) );
    1.68 +		
    1.69 +	connect (
    1.70  		model, SIGNAL (showSelection() ),
    1.71  		this, SLOT (showSelection() ) );
    1.72  		
    1.73 @@ -112,10 +126,22 @@
    1.74  	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
    1.75  	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
    1.76  	// would require to also get current model in mainWindow
    1.77 -	proxySelModel->select (
    1.78 -		treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
    1.79 -		QItemSelectionModel::ClearAndSelect );
    1.80 -	showSelection();
    1.81 +
    1.82 +	cout << "VV::changeSelection   newsel.count="<<newsel.indexes().count()<<endl;
    1.83 +
    1.84 +	if (newsel.indexes().count()>0)
    1.85 +	{
    1.86 +
    1.87 +	/* FIXME-2 use proxymodel
    1.88 +		proxySelModel->select (
    1.89 +			treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
    1.90 +			QItemSelectionModel::ClearAndSelect );
    1.91 +		*/
    1.92 +		QModelIndex ix=newsel.indexes().first();
    1.93 +		selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect  );
    1.94 +		treeEditor->setCurrentIndex (ix);
    1.95 +		showSelection();
    1.96 +	}
    1.97  }
    1.98  
    1.99  void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   1.100 @@ -123,9 +149,22 @@
   1.101  	// Notify mainwindow to update satellites, but map selection to 
   1.102  	// original model first
   1.103  
   1.104 +	cout << "VV::changeProxySelection   newsel.count="<<newsel.indexes().count()<<endl;
   1.105 +	if (!newsel.indexes().isEmpty())
   1.106 +	{
   1.107 +	/* FIXME-2 need to set current, too
   1.108 +	*/
   1.109 +		proxySelModel->setCurrentIndex (
   1.110 +			newsel.indexes().first(),
   1.111 +			QItemSelectionModel::ClearAndSelect );
   1.112 +	treeEditor->setCurrentIndex (newsel.indexes().first() );
   1.113 +	}
   1.114 +
   1.115  	// Re-emit but map selection first
   1.116 -	selModel->select (treeEditor->getProxyModel()->mapSelectionToSource (newsel),
   1.117 +	selModel->select (
   1.118 +		treeEditor->getProxyModel()->mapSelectionToSource (newsel),
   1.119  		QItemSelectionModel::ClearAndSelect );
   1.120 +
   1.121  	showSelection();
   1.122  }
   1.123  
   1.124 @@ -134,6 +173,85 @@
   1.125  	treeEditor->expandAll();
   1.126  }
   1.127  
   1.128 +void VymView::expandOneLevel()
   1.129 +{
   1.130 +	int level=999999;
   1.131 +	int d;
   1.132 +	BranchItem *cur=NULL;
   1.133 +	BranchItem *prev=NULL;
   1.134 +	QModelIndex pix;
   1.135 +
   1.136 +	// Find level to expand
   1.137 +	model->nextBranch(cur,prev);
   1.138 +	while (cur) 
   1.139 +	{
   1.140 +		// FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
   1.141 +		pix=model->index (cur);
   1.142 +		d=cur->depth();
   1.143 +		if (!treeEditor->isExpanded(pix) && d < level)
   1.144 +			level=d;
   1.145 +		model->nextBranch(cur,prev);	
   1.146 +	}
   1.147 +
   1.148 +	// Expand all to level
   1.149 +	cur=NULL;
   1.150 +	prev=NULL;
   1.151 +	model->nextBranch(cur,prev);
   1.152 +	while (cur) 
   1.153 +	{
   1.154 +		// FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
   1.155 +		pix=model->index (cur);
   1.156 +		d=cur->depth();
   1.157 +		if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
   1.158 +			treeEditor->setExpanded(pix,true);
   1.159 +		model->nextBranch(cur,prev);	
   1.160 +	}
   1.161 +	/* FIXME-3 optimize expanding by using flat version of next
   1.162 +	model->nextBranch(cur,prev,false);
   1.163 +	while (cur) 
   1.164 +	{
   1.165 +		cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
   1.166 +;
   1.167 +		model->nextBranch(cur,prev,false);	
   1.168 +	}
   1.169 +	*/
   1.170 +}
   1.171 +
   1.172 +void VymView::collapseOneLevel()
   1.173 +{
   1.174 +	int level=-1;
   1.175 +	int d;
   1.176 +	BranchItem *cur=NULL;
   1.177 +	BranchItem *prev=NULL;
   1.178 +	QModelIndex pix;
   1.179 +
   1.180 +	// Find level to collapse
   1.181 +	model->nextBranch(cur,prev);
   1.182 +	while (cur) 
   1.183 +	{
   1.184 +		// FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
   1.185 +		pix=model->index (cur);
   1.186 +		d=cur->depth();
   1.187 +		if (treeEditor->isExpanded(pix) && d > level)
   1.188 +			level=d;
   1.189 +		model->nextBranch(cur,prev);	
   1.190 +	}
   1.191 +
   1.192 +	// collapse all to level
   1.193 +	cur=NULL;
   1.194 +	prev=NULL;
   1.195 +	model->nextBranch(cur,prev);
   1.196 +	while (cur) 
   1.197 +	{
   1.198 +		// FIXME-2 use proxy pix=treeEditor->getProxyModel()->mapFromSource (model->index (cur));
   1.199 +		pix=model->index (cur);
   1.200 +		d=cur->depth();
   1.201 +		if (treeEditor->isExpanded(pix) && d >= level)
   1.202 +			treeEditor->setExpanded(pix,false);
   1.203 +		model->nextBranch(cur,prev);	
   1.204 +	}
   1.205 +}
   1.206 +
   1.207  void VymView::showSelection()
   1.208  {
   1.209  	QModelIndex ix=model->getSelectedIndex();